KiCad PCB EDA Suite
test_array_pad_name_provider.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <array_pad_number_provider.h>
#include <common.h>
#include <footprint.h>
#include <pad.h>

Go to the source code of this file.

Classes

struct  APNP_CASE
 Declare the test suite. More...
 

Functions

static std::unique_ptr< FOOTPRINTFootprintWithPads (const std::vector< wxString > aNames)
 Make a footprint with a given list of named pads. More...
 
std::vector< APNP_CASEGetFootprintAPNPCases ()
 Get Array Pad Name Provider cases when a footprint is looked at to determine what names are available. More...
 
void CheckPadNumberProvider (ARRAY_PAD_NUMBER_PROVIDER &aProvider, std::vector< wxString > aExpectedNumbers)
 Check that an ARRAY_PAD_NUMBER_PROVIDER provides the right names. More...
 
 BOOST_AUTO_TEST_CASE (FootprintCases)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( FootprintCases  )

Definition at line 132 of file test_array_pad_name_provider.cpp.

133{
134 for( const auto& c : GetFootprintAPNPCases() )
135 {
136 BOOST_TEST_CONTEXT( c.m_case_name )
137 {
138 std::unique_ptr<FOOTPRINT> footprint;
139
140 if( c.m_using_footprint )
141 footprint = FootprintWithPads( c.m_existing_pads );
142
143 ARRAY_PAD_NUMBER_PROVIDER apnp( footprint.get(), *c.m_arr_opts );
144
145 CheckPadNumberProvider( apnp, c.m_expected_numbers );
146 }
147 }
148}
Simple class that sequentially provides numbers from an ARRAY_OPTIONS object, making sure that they d...
std::vector< APNP_CASE > GetFootprintAPNPCases()
Get Array Pad Name Provider cases when a footprint is looked at to determine what names are available...
void CheckPadNumberProvider(ARRAY_PAD_NUMBER_PROVIDER &aProvider, std::vector< wxString > aExpectedNumbers)
Check that an ARRAY_PAD_NUMBER_PROVIDER provides the right names.
static std::unique_ptr< FOOTPRINT > FootprintWithPads(const std::vector< wxString > aNames)
Make a footprint with a given list of named pads.
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, CheckPadNumberProvider(), FootprintWithPads(), and GetFootprintAPNPCases().

◆ CheckPadNumberProvider()

void CheckPadNumberProvider ( ARRAY_PAD_NUMBER_PROVIDER aProvider,
std::vector< wxString >  aExpectedNumbers 
)

Check that an ARRAY_PAD_NUMBER_PROVIDER provides the right names.

Parameters
aProviderthe provider
aExpNamesordered list of expected names

Definition at line 119 of file test_array_pad_name_provider.cpp.

121{
122 std::vector<wxString> got_numbers;
123
124 for( unsigned i = 0; i < aExpectedNumbers.size(); ++i )
125 got_numbers.push_back( aProvider.GetNextPadNumber() );
126
127 BOOST_CHECK_EQUAL_COLLECTIONS( aExpectedNumbers.begin(), aExpectedNumbers.end(),
128 got_numbers.begin(), got_numbers.end() );
129}
wxString GetNextPadNumber()
Get the next available pad name.

References ARRAY_PAD_NUMBER_PROVIDER::GetNextPadNumber().

Referenced by BOOST_AUTO_TEST_CASE().

◆ FootprintWithPads()

static std::unique_ptr< FOOTPRINT > FootprintWithPads ( const std::vector< wxString >  aNames)
static

Make a footprint with a given list of named pads.

Definition at line 36 of file test_array_pad_name_provider.cpp.

37{
38 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( nullptr );
39
40 for( const wxString& name : aNames )
41 {
42 std::unique_ptr<PAD> pad = std::make_unique<PAD>( footprint.get() );
43
44 pad->SetNumber( name );
45
46 footprint->Add( pad.release() );
47 }
48
49 return footprint;
50}
const char * name
Definition: DXF_plotter.cpp:56

References name, and pad.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetFootprintAPNPCases()

std::vector< APNP_CASE > GetFootprintAPNPCases ( )

Get Array Pad Name Provider cases when a footprint is looked at to determine what names are available.

Definition at line 72 of file test_array_pad_name_provider.cpp.

73{
74 std::vector<APNP_CASE> cases;
75
76 auto opts = std::make_unique<ARRAY_GRID_OPTIONS>();
77
78 // simple linear numbering
79 opts->m_2dArrayNumbering = false;
80 opts->m_pri_axis.SetOffset( 1 );
81 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
82
83 cases.push_back( {
84 "Simple linear, skip some",
85 true,
86 { "1", "3" },
87 std::move( opts ),
88 { "2", "4", "5", "6", "7" },
89 } );
90
91 // one without a footprint
92 opts = std::make_unique<ARRAY_GRID_OPTIONS>();
93
94 // simple linear numbering (again)
95 opts->m_2dArrayNumbering = false;
96 opts->m_pri_axis.SetOffset( 1 );
97 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
98
99 cases.push_back( {
100 "Simple linear, no footprint",
101 false,
102 {}, // not used
103 std::move( opts ),
104 { "1", "2", "3", "4", "5" },
105 } );
106
107 // Grid numberings with skips don't make a lot of sense, there is
108 // no particular contract made for them
109
110 return cases;
111}

Referenced by BOOST_AUTO_TEST_CASE().