KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_variant_symbol_compatibility.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 <lib_symbol.h>
27#include <sch_pin.h>
28#include <sch_symbol.h>
31
32
33namespace
34{
35
40void AddPin( LIB_SYMBOL& aSymbol, const wxString& aNumber, const VECTOR2I& aPos,
42 int aUnit = 1, int aBodyStyle = 1 )
43{
44 SCH_PIN* pin = new SCH_PIN( &aSymbol );
45 pin->SetNumber( aNumber );
46 pin->SetPosition( aPos );
47 pin->SetType( aType );
48 pin->SetUnit( aUnit );
49 pin->SetBodyStyle( aBodyStyle );
50 aSymbol.AddDrawItem( pin );
51}
52
53
57std::unique_ptr<LIB_SYMBOL> MakeTwoPinPassive( const wxString& aName )
58{
59 auto sym = std::make_unique<LIB_SYMBOL>( aName );
60 AddPin( *sym, wxS( "1" ), VECTOR2I( 0, 0 ) );
61 AddPin( *sym, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
62 return sym;
63}
64
65
66std::vector<VARIANT_COMPAT_RESULT> CheckCompatibility( const LIB_SYMBOL& aBase, const LIB_SYMBOL& aCandidate )
67{
68 const auto expected = ValidateVariantSymbolCompatibility( aBase, aCandidate );
69 const auto captured = SCH_CONNECTIVITY::ExtractLibrarySymbolFact( aBase );
70 const auto actual = ValidateVariantSymbolCompatibility( captured, aCandidate );
71 BOOST_REQUIRE_EQUAL( actual.size(), expected.size() );
72
73 for( size_t i = 0; i < expected.size(); ++i )
74 {
75 BOOST_CHECK( actual[i].error == expected[i].error );
77 BOOST_CHECK_EQUAL( actual[i].pinNumber, expected[i].pinNumber );
78 BOOST_CHECK_EQUAL( actual[i].unit, expected[i].unit );
79 BOOST_CHECK_EQUAL( actual[i].bodyStyle, expected[i].bodyStyle );
80 }
81
82 return actual;
83}
84
85
86bool HasError( const std::vector<VARIANT_COMPAT_RESULT>& aResults, VARIANT_COMPAT_ERROR aError )
87{
88 for( const VARIANT_COMPAT_RESULT& r : aResults )
89 {
90 if( r.error == aError )
91 return true;
92 }
93
94 return false;
95}
96
97
98bool HasErrorForPin( const std::vector<VARIANT_COMPAT_RESULT>& aResults, VARIANT_COMPAT_ERROR aError,
99 const wxString& aPin )
100{
101 for( const VARIANT_COMPAT_RESULT& r : aResults )
102 {
103 if( r.error == aError && r.pinNumber == aPin )
104 return true;
105 }
106
107 return false;
108}
109
110} // anonymous namespace
111
112
113BOOST_AUTO_TEST_SUITE( VariantSymbolCompatibility )
114
115
116BOOST_AUTO_TEST_CASE( UnresolvedLibraryPinTypeIsUnspecified )
117{
118 auto base = MakeTwoPinPassive( wxS( "Base" ) );
119 auto candidate = MakeTwoPinPassive( wxS( "Candidate" ) );
120 base->GetGraphicalPins().front()->SetType( ELECTRICAL_PINTYPE::PT_INHERIT );
121 candidate->GetGraphicalPins().front()->SetType( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
122 BOOST_CHECK( CheckCompatibility( *base, *candidate ).empty() );
123}
124
125
126BOOST_AUTO_TEST_CASE( IdenticalSymbols_Compatible )
127{
128 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
129 auto candidate = MakeTwoPinPassive( wxS( "R_100R" ) );
130
131 auto results = CheckCompatibility( *base, *candidate );
132
133 BOOST_CHECK( results.empty() );
134}
135
136
137BOOST_AUTO_TEST_CASE( SamePinLayout_Compatible )
138{
139 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
140 auto candidate = MakeTwoPinPassive( wxS( "R_1K" ) );
141
142 auto results = CheckCompatibility( *base, *candidate );
143
144 BOOST_CHECK( results.empty() );
145}
146
147
148BOOST_AUTO_TEST_CASE( SamePinLayout_DifferentFootprint_Compatible )
149{
150 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
151 base->GetFootprintField().SetText( wxS( "R_0402" ) );
152
153 auto candidate = MakeTwoPinPassive( wxS( "R_10K" ) );
154 candidate->GetFootprintField().SetText( wxS( "R_0603" ) );
155
156 auto results = CheckCompatibility( *base, *candidate );
157
158 BOOST_CHECK( results.empty() );
159}
160
161
162BOOST_AUTO_TEST_CASE( CandidateHasExtraPins_Incompatible )
163{
164 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
165
166 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_3PIN" ) );
167 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
168 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
169 AddPin( *candidate, wxS( "3" ), VECTOR2I( 2540000, 2540000 ) );
170
171 auto results = CheckCompatibility( *base, *candidate );
172
173 BOOST_CHECK( !results.empty() );
174}
175
176
177BOOST_AUTO_TEST_CASE( DuplicatePinNumbersAtMatchingPositions_Compatible )
178{
179 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
180 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
181 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
182
183 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
184 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
185 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
186
187 BOOST_CHECK( CheckCompatibility( base, candidate ).empty() );
188}
189
190
191BOOST_AUTO_TEST_CASE( DuplicatePinNumbersMissingOccurrence_Incompatible )
192{
193 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
194 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
195 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
196
197 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
198 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
199
200 BOOST_CHECK( !CheckCompatibility( base, candidate ).empty() );
201}
202
203
204BOOST_AUTO_TEST_CASE( DuplicatePinNumbersMapByPosition )
205{
206 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
207 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
208 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
209
211 SCH_SYMBOL symbol( base, base.GetLibId(), &path, 1 );
212
213 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
214 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
215 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
216
217 std::vector<SCH_PIN*> candidatePins = candidate.GetGraphicalPins( 1, 1 );
218 std::vector<SCH_PIN*> mapped = symbol.MapLibPins( candidatePins, true );
219
220 BOOST_REQUIRE_EQUAL( mapped.size(), 2 );
221 BOOST_REQUIRE( mapped[0] );
222 BOOST_REQUIRE( mapped[1] );
223 BOOST_CHECK_NE( mapped[0], mapped[1] );
224 BOOST_CHECK_EQUAL( mapped[0]->GetLibPin()->GetPosition(), candidatePins[0]->GetPosition() );
225 BOOST_CHECK_EQUAL( mapped[1]->GetLibPin()->GetPosition(), candidatePins[1]->GetPosition() );
226}
227
228
229BOOST_AUTO_TEST_CASE( CandidateMissingPin_Incompatible )
230{
231 auto base = std::make_unique<LIB_SYMBOL>( wxS( "R_3PIN" ) );
232 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ) );
233 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
234 AddPin( *base, wxS( "3" ), VECTOR2I( 2540000, 2540000 ) );
235
236 auto candidate = MakeTwoPinPassive( wxS( "R_100R" ) );
237
238 auto results = CheckCompatibility( *base, *candidate );
239
240 BOOST_CHECK( !results.empty() );
241 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "3" ) ) );
242}
243
244
245BOOST_AUTO_TEST_CASE( PinPositionMismatch_Incompatible )
246{
247 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
248
249 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_WRONG_POS" ) );
250 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
251 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 7620000 ) );
252
253 auto results = CheckCompatibility( *base, *candidate );
254
255 BOOST_CHECK( !results.empty() );
256 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH, wxS( "2" ) ) );
257}
258
259
260BOOST_AUTO_TEST_CASE( PinTypeMismatch_Incompatible )
261{
262 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
263
264 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_WRONG_TYPE" ) );
265 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT );
266 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
267
268 auto results = CheckCompatibility( *base, *candidate );
269
270 BOOST_CHECK( !results.empty() );
271 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_TYPE_MISMATCH, wxS( "1" ) ) );
272}
273
274
275BOOST_AUTO_TEST_CASE( DifferentSymbolType_Incompatible )
276{
277 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
278
279 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "C_100nF" ) );
280 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
281 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, -2540000 ) );
282
283 auto results = CheckCompatibility( *base, *candidate );
284
285 BOOST_CHECK( !results.empty() );
286 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH ) );
287}
288
289
290BOOST_AUTO_TEST_CASE( MultiUnit_AllUnitsMatch_Compatible )
291{
292 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_BASE" ) );
293 base->SetUnitCount( 2, false );
294 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
295 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
296 AddPin( *base, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
297 AddPin( *base, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
298 AddPin( *base, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
299 AddPin( *base, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
300
301 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_CAND" ) );
302 candidate->SetUnitCount( 2, false );
303 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
304 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
305 AddPin( *candidate, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
306 AddPin( *candidate, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
307 AddPin( *candidate, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
308 AddPin( *candidate, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
309
310 auto results = CheckCompatibility( *base, *candidate );
311
312 BOOST_CHECK( results.empty() );
313}
314
315
316BOOST_AUTO_TEST_CASE( MultiUnit_OneUnitMismatch_Incompatible )
317{
318 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_BASE" ) );
319 base->SetUnitCount( 2, false );
320 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
321 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
322 AddPin( *base, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
323 AddPin( *base, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
324 AddPin( *base, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
325 AddPin( *base, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
326
327 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_CAND" ) );
328 candidate->SetUnitCount( 2, false );
329 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
330 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
331 AddPin( *candidate, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
332 // Unit 2 is missing pin "7"
333 AddPin( *candidate, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
334 AddPin( *candidate, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
335
336 auto results = CheckCompatibility( *base, *candidate );
337
338 BOOST_CHECK( !results.empty() );
339 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "7" ) ) );
340}
341
342
343BOOST_AUTO_TEST_CASE( CandidateFewerUnits_Incompatible )
344{
345 auto base = std::make_unique<LIB_SYMBOL>( wxS( "QUAD_OPAMP" ) );
346 base->SetUnitCount( 4, false );
347 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
348 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
349 AddPin( *base, wxS( "3" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 3 );
350 AddPin( *base, wxS( "4" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 4 );
351
352 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP" ) );
353 candidate->SetUnitCount( 2, false );
354 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
355 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
356
357 auto results = CheckCompatibility( *base, *candidate );
358
359 BOOST_CHECK( !results.empty() );
360 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::INSUFFICIENT_UNITS ) );
361}
362
363
364BOOST_AUTO_TEST_CASE( CandidateMoreUnits_Incompatible )
365{
366 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP" ) );
367 base->SetUnitCount( 2, false );
368 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
369 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
370
371 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "QUAD_OPAMP" ) );
372 candidate->SetUnitCount( 4, false );
373 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
374 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
375 AddPin( *candidate, wxS( "3" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 3 );
376 AddPin( *candidate, wxS( "4" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 4 );
377
378 auto results = CheckCompatibility( *base, *candidate );
379
380 BOOST_CHECK( !results.empty() );
381}
382
383
384BOOST_AUTO_TEST_CASE( BodyStyle_BothHave_Compatible )
385{
386 auto base = std::make_unique<LIB_SYMBOL>( wxS( "GATE_BASE" ) );
387 base->SetHasDeMorganBodyStyles( true );
388 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
389 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
390 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
391 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
392
393 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "GATE_CAND" ) );
394 candidate->SetHasDeMorganBodyStyles( true );
395 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
396 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
397 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
398 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
399
400 auto results = CheckCompatibility( *base, *candidate );
401
402 BOOST_CHECK( results.empty() );
403}
404
405
406BOOST_AUTO_TEST_CASE( BodyStyle_CandidateMissing_Incompatible )
407{
408 auto base = std::make_unique<LIB_SYMBOL>( wxS( "GATE_BASE" ) );
409 base->SetHasDeMorganBodyStyles( true );
410 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
411 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
412 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
413 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
414
415 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "GATE_CAND" ) );
416 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
417 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
418
419 auto results = CheckCompatibility( *base, *candidate );
420
421 BOOST_CHECK( !results.empty() );
422 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::MISSING_BODY_STYLE ) );
423}
424
425
426BOOST_AUTO_TEST_CASE( EmptySymbols_Compatible )
427{
428 LIB_SYMBOL base( wxS( "EMPTY_A" ) );
429 LIB_SYMBOL candidate( wxS( "EMPTY_B" ) );
430
431 auto results = CheckCompatibility( base, candidate );
432
433 BOOST_CHECK( results.empty() );
434}
435
436
437BOOST_AUTO_TEST_CASE( MultipleErrors_AllReported )
438{
439 auto base = std::make_unique<LIB_SYMBOL>( wxS( "BASE" ) );
440 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
441 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 5080000 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
442 AddPin( *base, wxS( "3" ), VECTOR2I( 2540000, 0 ), ELECTRICAL_PINTYPE::PT_INPUT );
443
444 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "CAND" ) );
445 // Pin 1 has wrong type
446 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_OUTPUT );
447 // Pin 2 has wrong position
448 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 7620000 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
449 // Pin 3 is missing
450
451 auto results = CheckCompatibility( *base, *candidate );
452
453 BOOST_CHECK_EQUAL( results.size(), 3 );
454 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_TYPE_MISMATCH, wxS( "1" ) ) );
455 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH, wxS( "2" ) ) );
456 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "3" ) ) );
457}
458
459
Define a library symbol object.
Definition lib_symbol.h:114
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:190
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const override
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:73
std::vector< SCH_PIN * > MapLibPins(const std::vector< SCH_PIN * > &aLibPins, bool aByNumber) const
Map pins of an effective library symbol to this symbol's instance pins.
static bool empty(const wxTextEntryBase *aCtrl)
LIBRARY_SYMBOL_FACT ExtractLibrarySymbolFact(const LIB_SYMBOL &aSymbol)
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
int actual
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(UnresolvedLibraryPinTypeIsUnspecified)
std::vector< VARIANT_COMPAT_RESULT > ValidateVariantSymbolCompatibility(const LIB_SYMBOL &aBase, const LIB_SYMBOL &aCandidate)
Check whether aCandidate can be used as a variant symbol override for aBase.
VARIANT_COMPAT_ERROR
Describes a single pin compatibility problem found when comparing a candidate symbol against a base s...
@ PIN_POSITION_MISMATCH
A matching pin number has a different position in library coordinates.
@ PIN_TYPE_MISMATCH
A matching pin number has a different electrical type.
@ MISSING_BODY_STYLE
Base uses alternate body styles but candidate does not.
@ MISSING_PIN_NUMBER
A base pin number is absent from the candidate for a given unit/body style.
@ INSUFFICIENT_UNITS
Candidate has fewer units than the base.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708