KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_netlist_exporter_kicad.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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#include <eeschema_test_utils.h>
22#include <advanced_config.h>
23#include <scoped_set_reset.h>
24
25
27{
28public:
29 void CompareNetlists() override
30 {
31 NETLIST golden;
33
34 {
35 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
36 &golden, GetNetlistPath(), wxEmptyString ) );
37
38 BOOST_ASSERT( netlistReader );
39 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
40 }
41
42 {
43 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
44 &test, GetNetlistPath( true ), wxEmptyString ) );
45
46 BOOST_ASSERT( netlistReader );
47 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
48 }
49
50 // Number of components should match
51 BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
52
53 for( unsigned i = 0; i < golden.GetCount(); i++ )
54 {
55 COMPONENT* goldenComp = golden.GetComponent( i );
56 COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
57
58 // Retrieval by reference
59 BOOST_REQUIRE_NE( refComp, nullptr );
60
61 // Retrieval by KIID
62 KIID_PATH path = goldenComp->GetPath();
63
64 BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
65
66 path.push_back( goldenComp->GetKIIDs().front() );
67
68 COMPONENT* pathComp = test.GetComponentByPath( path );
69 BOOST_REQUIRE_NE( pathComp, nullptr );
70
71 // We should have found the same component
72 BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
73
74 // And that component should have the same number of attached nets
75 BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
76
77 for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
78 {
79 const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
80 const COMPONENT_NET& testNet = refComp->GetNet( net );
81
82 // The video test has a bunch of unconnected RESERVED pins which cause duplicate
83 // auto-generated netnames. The connectivity algo disambiguates these with "_n"
84 // suffixes, but since the algorithm is multi-threaded, which ones get which suffix
85 // is not deterministic. So skip these.
86 if( testNet.GetPinFunction().Contains( "RESERVED" ) )
87 continue;
88
89 // The two nets at the same index should be identical
90 BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
91 BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
92 BOOST_REQUIRE_EQUAL( goldenNet.GetPinType(), testNet.GetPinType() );
93 }
94
95 // And the resolved component class is the same
97 == refComp->GetComponentClassNames() );
98 }
99 }
100};
101
102
103BOOST_FIXTURE_TEST_SUITE( Netlists, TEST_NETLIST_EXPORTER_KICAD_FIXTURE )
104
105
107{
108 BOOST_CHECK_NE( m_pi.get(), nullptr );
109}
110
111
112BOOST_AUTO_TEST_CASE( GlobalPromotion )
113{
114 TestNetlist( "test_global_promotion" );
115}
116
117
118BOOST_AUTO_TEST_CASE( GlobalPromotion2 )
119{
120 TestNetlist( "test_global_promotion_2" );
121}
122
123
125{
126 TestNetlist( "video" );
127}
128
129
130BOOST_AUTO_TEST_CASE( ComplexHierarchy )
131{
132 TestNetlist( "complex_hierarchy" );
133}
134
135
136BOOST_AUTO_TEST_CASE( WeakVectorBusDisambiguation )
137{
138 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
139 SCOPED_SET_RESET restore( enabled, enabled );
140
141 for( bool useEngine : { false, true } )
142 {
143 BOOST_TEST_CONTEXT( "engine=" << useEngine )
144 {
145 enabled = useEngine;
146 TestNetlist( "weak_vector_bus_disambiguation" );
147 }
148 }
149}
150
151
152BOOST_AUTO_TEST_CASE( BusJunctions )
153{
154 TestNetlist( "bus_junctions" );
155}
156
157
158BOOST_AUTO_TEST_CASE( HierRenaming )
159{
160 TestNetlist( "test_hier_renaming" );
161}
162
163
165{
166 TestNetlist( "noconnects" );
167}
168
169
170BOOST_AUTO_TEST_CASE( PrefixBusAlias )
171{
172 TestNetlist( "prefix_bus_alias" );
173}
174
175
176BOOST_AUTO_TEST_CASE( GroupBusMatching )
177{
178 TestNetlist( "group_bus_matching" );
179}
180
181
182BOOST_AUTO_TEST_CASE( TopLevelHierPins )
183{
184 TestNetlist( "top_level_hier_pins" );
185}
186
187
189{
190 TestNetlist( "bus_entries" );
191}
192
193
194BOOST_AUTO_TEST_CASE( HierNoConnect )
195{
196 TestNetlist( "test_hier_no_connect" );
197}
198
199
200BOOST_AUTO_TEST_CASE( BusConnection )
201{
202 TestNetlist( "bus_connection" );
203}
204
206{
207 TestNetlist( "issue14657" );
208}
209
210BOOST_AUTO_TEST_CASE( HierarchyAliases )
211{
212 TestNetlist( "hierarchy_aliases" );
213}
214
216{
217 TestNetlist( "issue14818" );
218}
219
221{
222 TestNetlist( "issue16003" );
223}
224
226{
227 TestNetlist( "issue16439" );
228}
229
230BOOST_AUTO_TEST_CASE( ComponentClasses )
231{
232 TestNetlist( "component_classes" );
233}
234
235BOOST_AUTO_TEST_CASE( HierarchicalComponentClasses )
236{
237 TestNetlist( "hierarchical_component_classes" );
238}
239
240
242{
243 TestNetlist( "jumpers" );
244}
245
246
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetNetName() const
const wxString & GetPinFunction() const
const wxString & GetPinName() const
const wxString & GetPinType() const
Store all of the related component information found in a netlist.
const COMPONENT_NET & GetNet(unsigned aIndex) const
const KIID_PATH & GetPath() const
const wxString & GetReference() const
const std::vector< KIID > & GetKIIDs() const
unsigned GetNetCount() const
std::unordered_set< wxString > & GetComponentClassNames()
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_RE...
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
unsigned GetCount() const
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
RAII class that sets an value at construction and resets it to the original value at destruction.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_AUTO_TEST_CASE(FindPlugin)
BOOST_TEST_CONTEXT("Test Clearance")