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 The 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
33
37BOOST_AUTO_TEST_SUITE( ArrayPadNumberProv )
38
39
41{
42 std::string m_case_name;
43 std::set<wxString> m_existing_pad_numbers;
44 std::unique_ptr<ARRAY_OPTIONS> m_arr_opts;
45 std::vector<wxString> m_expected_numbers;
46};
47
48
53std::vector<APNP_CASE> GetFootprintAPNPCases()
54{
55 std::vector<APNP_CASE> cases;
56
57 auto opts = std::make_unique<ARRAY_GRID_OPTIONS>();
58
59 // simple linear numbering
60 opts->m_2dArrayNumbering = false;
61 opts->m_pri_axis.SetOffset( 1 );
62 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
63
64 cases.push_back( {
65 "Simple linear, skip some",
66 { "1", "3" },
67 std::move( opts ),
68 { "2", "4", "5", "6", "7" },
69 } );
70
71 // one without a footprint
72 opts = std::make_unique<ARRAY_GRID_OPTIONS>();
73
74 // simple linear numbering (again)
75 opts->m_2dArrayNumbering = false;
76 opts->m_pri_axis.SetOffset( 1 );
77 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
78
79 cases.push_back( {
80 "Simple linear, no footprint",
81 {}, // not used
82 std::move( opts ),
83 { "1", "2", "3", "4", "5" },
84 } );
85
86 // Grid numberings with skips don't make a lot of sense, there is
87 // no particular contract made for them
88
89 return cases;
90}
91
92
99 std::vector<wxString> aExpectedNumbers )
100{
101 std::vector<wxString> got_numbers;
102
103 for( unsigned i = 0; i < aExpectedNumbers.size(); ++i )
104 got_numbers.push_back( aProvider.GetNextPadNumber() );
105
106 BOOST_CHECK_EQUAL_COLLECTIONS( aExpectedNumbers.begin(), aExpectedNumbers.end(),
107 got_numbers.begin(), got_numbers.end() );
108}
109
110
111BOOST_AUTO_TEST_CASE( FootprintCases )
112{
113 for( const auto& c : GetFootprintAPNPCases() )
114 {
115 BOOST_TEST_CONTEXT( c.m_case_name )
116 {
117 std::unique_ptr<FOOTPRINT> footprint;
118
119 ARRAY_PAD_NUMBER_PROVIDER apnp( c.m_existing_pad_numbers, *c.m_arr_opts );
120
121 CheckPadNumberProvider( apnp, c.m_expected_numbers );
122 }
123 }
124}
125
@ 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::set< wxString > m_existing_pad_numbers
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.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")