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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <array_pad_number_provider.h> // UUT
23
24#include <common.h> // make_unique
25
26#include <footprint.h>
27#include <pad.h>
28
29
33BOOST_AUTO_TEST_SUITE( ArrayPadNumberProv )
34
35
37{
38 std::string m_case_name;
39 std::set<wxString> m_existing_pad_numbers;
40 std::unique_ptr<ARRAY_OPTIONS> m_arr_opts;
41 std::vector<wxString> m_expected_numbers;
42};
43
44
49std::vector<APNP_CASE> GetFootprintAPNPCases()
50{
51 std::vector<APNP_CASE> cases;
52
53 auto opts = std::make_unique<ARRAY_GRID_OPTIONS>();
54
55 // simple linear numbering
56 opts->m_2dArrayNumbering = false;
57 opts->m_pri_axis.SetOffset( 1 );
58 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
59
60 cases.push_back( {
61 "Simple linear, skip some",
62 { "1", "3" },
63 std::move( opts ),
64 { "2", "4", "5", "6", "7" },
65 } );
66
67 // one without a footprint
68 opts = std::make_unique<ARRAY_GRID_OPTIONS>();
69
70 // simple linear numbering (again)
71 opts->m_2dArrayNumbering = false;
72 opts->m_pri_axis.SetOffset( 1 );
73 opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
74
75 cases.push_back( {
76 "Simple linear, no footprint",
77 {}, // not used
78 std::move( opts ),
79 { "1", "2", "3", "4", "5" },
80 } );
81
82 // Grid numberings with skips don't make a lot of sense, there is
83 // no particular contract made for them
84
85 return cases;
86}
87
88
95 std::vector<wxString> aExpectedNumbers )
96{
97 std::vector<wxString> got_numbers;
98
99 for( unsigned i = 0; i < aExpectedNumbers.size(); ++i )
100 got_numbers.push_back( aProvider.GetNextPadNumber() );
101
102 BOOST_CHECK_EQUAL_COLLECTIONS( aExpectedNumbers.begin(), aExpectedNumbers.end(),
103 got_numbers.begin(), got_numbers.end() );
104}
105
106
107BOOST_AUTO_TEST_CASE( FootprintCases )
108{
109 for( const auto& c : GetFootprintAPNPCases() )
110 {
111 BOOST_TEST_CONTEXT( c.m_case_name )
112 {
113 std::unique_ptr<FOOTPRINT> footprint;
114
115 ARRAY_PAD_NUMBER_PROVIDER apnp( c.m_existing_pad_numbers, *c.m_arr_opts );
116
117 CheckPadNumberProvider( apnp, c.m_expected_numbers );
118 }
119 }
120}
121
@ NUMBERING_NUMERIC
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
Definition array_axis.h:40
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")