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>
30
31
32namespace
33{
34
39void AddPin( LIB_SYMBOL& aSymbol, const wxString& aNumber, const VECTOR2I& aPos,
41 int aUnit = 1, int aBodyStyle = 1 )
42{
43 SCH_PIN* pin = new SCH_PIN( &aSymbol );
44 pin->SetNumber( aNumber );
45 pin->SetPosition( aPos );
46 pin->SetType( aType );
47 pin->SetUnit( aUnit );
48 pin->SetBodyStyle( aBodyStyle );
49 aSymbol.AddDrawItem( pin );
50}
51
52
56std::unique_ptr<LIB_SYMBOL> MakeTwoPinPassive( const wxString& aName )
57{
58 auto sym = std::make_unique<LIB_SYMBOL>( aName );
59 AddPin( *sym, wxS( "1" ), VECTOR2I( 0, 0 ) );
60 AddPin( *sym, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
61 return sym;
62}
63
64
65bool HasError( const std::vector<VARIANT_COMPAT_RESULT>& aResults, VARIANT_COMPAT_ERROR aError )
66{
67 for( const VARIANT_COMPAT_RESULT& r : aResults )
68 {
69 if( r.error == aError )
70 return true;
71 }
72
73 return false;
74}
75
76
77bool HasErrorForPin( const std::vector<VARIANT_COMPAT_RESULT>& aResults,
78 VARIANT_COMPAT_ERROR aError, const wxString& aPin )
79{
80 for( const VARIANT_COMPAT_RESULT& r : aResults )
81 {
82 if( r.error == aError && r.pinNumber == aPin )
83 return true;
84 }
85
86 return false;
87}
88
89} // anonymous namespace
90
91
92BOOST_AUTO_TEST_SUITE( VariantSymbolCompatibility )
93
94
95BOOST_AUTO_TEST_CASE( UnresolvedLibraryPinTypeIsUnspecified )
96{
97 auto base = MakeTwoPinPassive( wxS( "Base" ) );
98 auto candidate = MakeTwoPinPassive( wxS( "Candidate" ) );
99 base->GetGraphicalPins().front()->SetType( ELECTRICAL_PINTYPE::PT_INHERIT );
100 candidate->GetGraphicalPins().front()->SetType( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
101 BOOST_CHECK( ValidateVariantSymbolCompatibility( *base, *candidate ).empty() );
102}
103
104
105BOOST_AUTO_TEST_CASE( IdenticalSymbols_Compatible )
106{
107 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
108 auto candidate = MakeTwoPinPassive( wxS( "R_100R" ) );
109
110 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
111
112 BOOST_CHECK( results.empty() );
113}
114
115
116BOOST_AUTO_TEST_CASE( SamePinLayout_Compatible )
117{
118 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
119 auto candidate = MakeTwoPinPassive( wxS( "R_1K" ) );
120
121 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
122
123 BOOST_CHECK( results.empty() );
124}
125
126
127BOOST_AUTO_TEST_CASE( SamePinLayout_DifferentFootprint_Compatible )
128{
129 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
130 base->GetFootprintField().SetText( wxS( "R_0402" ) );
131
132 auto candidate = MakeTwoPinPassive( wxS( "R_10K" ) );
133 candidate->GetFootprintField().SetText( wxS( "R_0603" ) );
134
135 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
136
137 BOOST_CHECK( results.empty() );
138}
139
140
141BOOST_AUTO_TEST_CASE( CandidateHasExtraPins_Incompatible )
142{
143 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
144
145 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_3PIN" ) );
146 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
147 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
148 AddPin( *candidate, wxS( "3" ), VECTOR2I( 2540000, 2540000 ) );
149
150 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
151
152 BOOST_CHECK( !results.empty() );
153}
154
155
156BOOST_AUTO_TEST_CASE( DuplicatePinNumbersAtMatchingPositions_Compatible )
157{
158 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
159 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
160 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
161
162 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
163 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
164 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
165
166 BOOST_CHECK( ValidateVariantSymbolCompatibility( base, candidate ).empty() );
167}
168
169
170BOOST_AUTO_TEST_CASE( DuplicatePinNumbersMissingOccurrence_Incompatible )
171{
172 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
173 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
174 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
175
176 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
177 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
178
179 BOOST_CHECK( !ValidateVariantSymbolCompatibility( base, candidate ).empty() );
180}
181
182
183BOOST_AUTO_TEST_CASE( DuplicatePinNumbersMapByPosition )
184{
185 LIB_SYMBOL base( wxS( "STACKED_BASE" ) );
186 AddPin( base, wxS( "1" ), VECTOR2I( 0, 0 ) );
187 AddPin( base, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
188
190 SCH_SYMBOL symbol( base, base.GetLibId(), &path, 1 );
191
192 LIB_SYMBOL candidate( wxS( "STACKED_CANDIDATE" ) );
193 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
194 AddPin( candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
195
196 const LIB_SYMBOL& constCandidate = candidate;
197 std::vector<const SCH_PIN*> candidatePins = constCandidate.GetGraphicalPins( 1, 1 );
198 std::vector<SCH_PIN*> mapped = symbol.MapLibPins( candidatePins, true );
199
200 BOOST_REQUIRE_EQUAL( mapped.size(), 2 );
201 BOOST_REQUIRE( mapped[0] );
202 BOOST_REQUIRE( mapped[1] );
203 BOOST_CHECK_NE( mapped[0], mapped[1] );
204 BOOST_CHECK_EQUAL( mapped[0]->GetLibPin()->GetPosition(), candidatePins[0]->GetPosition() );
205 BOOST_CHECK_EQUAL( mapped[1]->GetLibPin()->GetPosition(), candidatePins[1]->GetPosition() );
206}
207
208
209BOOST_AUTO_TEST_CASE( CandidateMissingPin_Incompatible )
210{
211 auto base = std::make_unique<LIB_SYMBOL>( wxS( "R_3PIN" ) );
212 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ) );
213 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
214 AddPin( *base, wxS( "3" ), VECTOR2I( 2540000, 2540000 ) );
215
216 auto candidate = MakeTwoPinPassive( wxS( "R_100R" ) );
217
218 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
219
220 BOOST_CHECK( !results.empty() );
221 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "3" ) ) );
222}
223
224
225BOOST_AUTO_TEST_CASE( PinPositionMismatch_Incompatible )
226{
227 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
228
229 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_WRONG_POS" ) );
230 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ) );
231 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 7620000 ) );
232
233 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
234
235 BOOST_CHECK( !results.empty() );
236 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH,
237 wxS( "2" ) ) );
238}
239
240
241BOOST_AUTO_TEST_CASE( PinTypeMismatch_Incompatible )
242{
243 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
244
245 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "R_WRONG_TYPE" ) );
246 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT );
247 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 5080000 ) );
248
249 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
250
251 BOOST_CHECK( !results.empty() );
252 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_TYPE_MISMATCH,
253 wxS( "1" ) ) );
254}
255
256
257BOOST_AUTO_TEST_CASE( DifferentSymbolType_Incompatible )
258{
259 auto base = MakeTwoPinPassive( wxS( "R_100R" ) );
260
261 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "C_100nF" ) );
262 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 2540000 ) );
263 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, -2540000 ) );
264
265 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
266
267 BOOST_CHECK( !results.empty() );
268 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH ) );
269}
270
271
272BOOST_AUTO_TEST_CASE( MultiUnit_AllUnitsMatch_Compatible )
273{
274 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_BASE" ) );
275 base->SetUnitCount( 2, false );
276 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
277 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
278 AddPin( *base, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
279 AddPin( *base, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
280 AddPin( *base, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
281 AddPin( *base, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
282
283 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_CAND" ) );
284 candidate->SetUnitCount( 2, false );
285 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
286 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
287 AddPin( *candidate, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
288 AddPin( *candidate, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
289 AddPin( *candidate, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
290 AddPin( *candidate, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
291
292 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
293
294 BOOST_CHECK( results.empty() );
295}
296
297
298BOOST_AUTO_TEST_CASE( MultiUnit_OneUnitMismatch_Incompatible )
299{
300 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_BASE" ) );
301 base->SetUnitCount( 2, false );
302 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
303 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
304 AddPin( *base, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
305 AddPin( *base, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
306 AddPin( *base, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
307 AddPin( *base, wxS( "7" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 2 );
308
309 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP_CAND" ) );
310 candidate->SetUnitCount( 2, false );
311 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
312 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
313 AddPin( *candidate, wxS( "3" ), VECTOR2I( 5080000, 1270000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1 );
314 // Unit 2 is missing pin "7"
315 AddPin( *candidate, wxS( "5" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
316 AddPin( *candidate, wxS( "6" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
317
318 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
319
320 BOOST_CHECK( !results.empty() );
321 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "7" ) ) );
322}
323
324
325BOOST_AUTO_TEST_CASE( CandidateFewerUnits_Incompatible )
326{
327 auto base = std::make_unique<LIB_SYMBOL>( wxS( "QUAD_OPAMP" ) );
328 base->SetUnitCount( 4, false );
329 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
330 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
331 AddPin( *base, wxS( "3" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 3 );
332 AddPin( *base, wxS( "4" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 4 );
333
334 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP" ) );
335 candidate->SetUnitCount( 2, false );
336 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
337 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
338
339 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
340
341 BOOST_CHECK( !results.empty() );
342 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::INSUFFICIENT_UNITS ) );
343}
344
345
346BOOST_AUTO_TEST_CASE( CandidateMoreUnits_Incompatible )
347{
348 auto base = std::make_unique<LIB_SYMBOL>( wxS( "DUAL_OPAMP" ) );
349 base->SetUnitCount( 2, false );
350 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
351 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
352
353 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "QUAD_OPAMP" ) );
354 candidate->SetUnitCount( 4, false );
355 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1 );
356 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 2 );
357 AddPin( *candidate, wxS( "3" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 3 );
358 AddPin( *candidate, wxS( "4" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 4 );
359
360 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
361
362 BOOST_CHECK( !results.empty() );
363}
364
365
366BOOST_AUTO_TEST_CASE( BodyStyle_BothHave_Compatible )
367{
368 auto base = std::make_unique<LIB_SYMBOL>( wxS( "GATE_BASE" ) );
369 base->SetHasDeMorganBodyStyles( true );
370 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
371 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
372 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
373 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
374
375 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "GATE_CAND" ) );
376 candidate->SetHasDeMorganBodyStyles( true );
377 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
378 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
379 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
380 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
381
382 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
383
384 BOOST_CHECK( results.empty() );
385}
386
387
388BOOST_AUTO_TEST_CASE( BodyStyle_CandidateMissing_Incompatible )
389{
390 auto base = std::make_unique<LIB_SYMBOL>( wxS( "GATE_BASE" ) );
391 base->SetHasDeMorganBodyStyles( true );
392 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
393 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
394 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 2 );
395 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 2 );
396
397 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "GATE_CAND" ) );
398 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_INPUT, 1, 1 );
399 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 2540000 ), ELECTRICAL_PINTYPE::PT_OUTPUT, 1, 1 );
400
401 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
402
403 BOOST_CHECK( !results.empty() );
404 BOOST_CHECK( HasError( results, VARIANT_COMPAT_ERROR::MISSING_BODY_STYLE ) );
405}
406
407
408BOOST_AUTO_TEST_CASE( EmptySymbols_Compatible )
409{
410 LIB_SYMBOL base( wxS( "EMPTY_A" ) );
411 LIB_SYMBOL candidate( wxS( "EMPTY_B" ) );
412
413 auto results = ValidateVariantSymbolCompatibility( base, candidate );
414
415 BOOST_CHECK( results.empty() );
416}
417
418
419BOOST_AUTO_TEST_CASE( MultipleErrors_AllReported )
420{
421 auto base = std::make_unique<LIB_SYMBOL>( wxS( "BASE" ) );
422 AddPin( *base, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
423 AddPin( *base, wxS( "2" ), VECTOR2I( 0, 5080000 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
424 AddPin( *base, wxS( "3" ), VECTOR2I( 2540000, 0 ), ELECTRICAL_PINTYPE::PT_INPUT );
425
426 auto candidate = std::make_unique<LIB_SYMBOL>( wxS( "CAND" ) );
427 // Pin 1 has wrong type
428 AddPin( *candidate, wxS( "1" ), VECTOR2I( 0, 0 ), ELECTRICAL_PINTYPE::PT_OUTPUT );
429 // Pin 2 has wrong position
430 AddPin( *candidate, wxS( "2" ), VECTOR2I( 0, 7620000 ), ELECTRICAL_PINTYPE::PT_PASSIVE );
431 // Pin 3 is missing
432
433 auto results = ValidateVariantSymbolCompatibility( *base, *candidate );
434
435 BOOST_CHECK_EQUAL( results.size(), 3 );
436 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_TYPE_MISMATCH, wxS( "1" ) ) );
437 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::PIN_POSITION_MISMATCH,
438 wxS( "2" ) ) );
439 BOOST_CHECK( HasErrorForPin( results, VARIANT_COMPAT_ERROR::MISSING_PIN_NUMBER, wxS( "3" ) ) );
440}
441
442
Define a library symbol object.
Definition lib_symbol.h:119
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:188
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
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:75
std::vector< SCH_PIN * > MapLibPins(const std::vector< const 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)
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
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:683