KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_array_pad_name_provider.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <array_pad_number_provider.h> // UUT
27
28#include <common.h> // make_unique
29
30#include <footprint.h>
31#include <pad.h>
32
36static std::unique_ptr<FOOTPRINT> FootprintWithPads( const std::vector<wxString> aNames )
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}
51
55BOOST_AUTO_TEST_SUITE( ArrayPadNumberProv )
56
57
59{
60 std::string m_case_name;
62 std::vector<wxString> m_existing_pads;
63 std::unique_ptr<ARRAY_OPTIONS> m_arr_opts;
64 std::vector<wxString> m_expected_numbers;
65};
66
67
72std::vector<APNP_CASE> GetFootprintAPNPCases()
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}
112
113
120 std::vector<wxString> aExpectedNumbers )
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}
130
131
132BOOST_AUTO_TEST_CASE( FootprintCases )
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}
149
const char * name
Definition: DXF_plotter.cpp:57
@ NUMBERING_NUMERIC
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
Definition: array_axis.h:44
Simple class that sequentially provides numbers from an ARRAY_OPTIONS object, making sure that they d...
wxString GetNextPadNumber()
Get the next available pad name.
The common library.
Declare the test suite.
std::unique_ptr< ARRAY_OPTIONS > m_arr_opts
std::vector< wxString > m_expected_numbers
std::vector< wxString > m_existing_pads
std::vector< APNP_CASE > GetFootprintAPNPCases()
Get Array Pad Name Provider cases when a footprint is looked at to determine what names are available...
BOOST_AUTO_TEST_CASE(FootprintCases)
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.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()