KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_lib_part.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
24
26
27// Code under test
28#include <sch_shape.h>
29#include <sch_pin.h>
30#include <lib_symbol.h>
31
33
35{
36public:
38 m_part_no_data( "part_name", nullptr )
39 {
40 }
41
44};
45
46
50BOOST_FIXTURE_TEST_SUITE( LibPart, TEST_LIB_SYMBOL_FIXTURE )
51
52
53
56BOOST_AUTO_TEST_CASE( DefaultProperties )
57{
58 BOOST_CHECK_EQUAL( m_part_no_data.GetName(), "part_name" );
59
60 // Didn't set a library, so this is empty
61 BOOST_CHECK_EQUAL( m_part_no_data.GetLibraryName(), "" );
62 BOOST_CHECK_EQUAL( m_part_no_data.GetLib(), nullptr );
63
64 // only get the root
65 BOOST_CHECK_EQUAL( m_part_no_data.IsRoot(), true );
66 BOOST_CHECK_EQUAL( m_part_no_data.IsDerived(), false );
67 BOOST_CHECK_EQUAL( m_part_no_data.SharedPtr().use_count(), 2 );
68
69 // no sub units
70 BOOST_CHECK_EQUAL( m_part_no_data.GetUnitCount(), 1 );
71 BOOST_CHECK_EQUAL( m_part_no_data.IsMultiUnit(), false );
72
73 // single body style
74 BOOST_CHECK_EQUAL( m_part_no_data.HasDeMorganBodyStyles(), false );
75}
76
77
81BOOST_AUTO_TEST_CASE( DefaultDrawings )
82{
83 // default drawings exist
84 BOOST_CHECK_EQUAL( m_part_no_data.GetDrawItems().size(), 5 );
85 BOOST_CHECK_EQUAL( m_part_no_data.GetGraphicalPins( 0, 0 ).size(), 0 );
86}
87
88
92BOOST_AUTO_TEST_CASE( DefaultFields )
93{
94 std::vector<SCH_FIELD> fields;
95 m_part_no_data.CopyFields( fields );
96
97 // Should get the 4 default fields
99
100 // but no more (we didn't set them)
101 BOOST_CHECK_EQUAL( fields.size(), 5 );
102
103 // also check the default field accessors
105 ( m_part_no_data.GetReferenceField() )( "Reference" )( (int) FIELD_T::REFERENCE ) );
107 ( m_part_no_data.GetValueField() )( "Value" )( (int) FIELD_T::VALUE ) );
109 ( m_part_no_data.GetFootprintField() )( "Footprint" )( (int) FIELD_T::FOOTPRINT ) );
111 ( m_part_no_data.GetDatasheetField() )( "Datasheet" )( (int) FIELD_T::DATASHEET ) );
113 ( m_part_no_data.GetDescriptionField() )( "Description" )( (int) FIELD_T::DESCRIPTION ) );
114}
115
116
121{
122 std::vector<SCH_FIELD> fields;
123 m_part_no_data.CopyFields( fields );
124
125 // Ctor takes non-const ref (?!)
126 const std::string newFieldName = "new_field";
127 wxString nonConstNewFieldName = newFieldName;
128 fields.push_back( SCH_FIELD( nullptr, FIELD_T::USER, nonConstNewFieldName ) );
129
130 // fairly roundabout way to add a field, but it is what it is
131 m_part_no_data.SetFields( fields );
132
133 // Should get the 4 default fields
135
136 // and our new one
137 BOOST_REQUIRE_EQUAL( fields.size(), 6 );
138
139 // Check by-name lookup
140
141 SCH_FIELD* gotNewField = m_part_no_data.GetField( newFieldName );
142
143 BOOST_REQUIRE_NE( gotNewField, nullptr );
144 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 0 ) );
145}
146
147
151BOOST_AUTO_TEST_CASE( AddedDrawItems )
152{
153}
154
155
157{
160 std::string m_expSubRef;
161};
162
163
167BOOST_AUTO_TEST_CASE( SubReference )
168{
169 const std::vector<TEST_LIB_SYMBOL_SUBREF_CASE> cases = {
170 {
171 1,
172 false,
173 "A",
174 },
175 {
176 2,
177 false,
178 "B",
179 },
180 {
181 26,
182 false,
183 "Z",
184 },
185 {
186 27,
187 false,
188 "AA",
189 },
190 {
191 28,
192 false,
193 "AB",
194 },
195 {
196 53,
197 false,
198 "BA",
199 },
200 {
201 79,
202 false,
203 "CA",
204 },
205 {
206 105,
207 false,
208 "DA",
209 },
210 {
211 131,
212 false,
213 "EA",
214 },
215 {
216 157,
217 false,
218 "FA",
219 },
220 {
221 183,
222 false,
223 "GA",
224 },
225 {
226 209,
227 false,
228 "HA",
229 },
230 {
231 235,
232 false,
233 "IA",
234 },
235 {
236 261,
237 false,
238 "JA",
239 },
240 {
241 287,
242 false,
243 "KA",
244 },
245 {
246 313,
247 false,
248 "LA",
249 },
250 {
251 339,
252 false,
253 "MA",
254 },
255 {
256 365,
257 false,
258 "NA",
259 },
260 {
261 391,
262 false,
263 "OA",
264 },
265 {
266 417,
267 false,
268 "PA",
269 },
270 {
271 443,
272 false,
273 "QA",
274 },
275 {
276 469,
277 false,
278 "RA",
279 },
280 {
281 495,
282 false,
283 "SA",
284 },
285 {
286 521,
287 false,
288 "TA",
289 },
290 {
291 547,
292 false,
293 "UA",
294 },
295 {
296 573,
297 false,
298 "VA",
299 },
300 {
301 599,
302 false,
303 "WA",
304 },
305 {
306 625,
307 false,
308 "XA",
309 },
310 {
311 651,
312 false,
313 "YA",
314 },
315 {
316 677,
317 false,
318 "ZA",
319 },
320 {
321 702,
322 false,
323 "ZZ",
324 },
325 {
326 703,
327 false,
328 "AAA",
329 },
330 {
331 728,
332 false,
333 "AAZ",
334 },
335 };
336
337 for( const auto& c : cases )
338 {
340 "Subref: " << c.m_index << ", " << c.m_addSep << " -> '" << c.m_expSubRef << "'" )
341 {
342 const auto subref = LIB_SYMBOL::LetterSubReference( c.m_index, 'A' );
343 BOOST_CHECK_EQUAL( subref, c.m_expSubRef );
344 }
345 }
346}
347
348
353{
354 // Identical root part to m_part_no_data sans time stamp.
355 LIB_SYMBOL testPart( "part_name" );
356
357 // Self comparison test.
358 BOOST_CHECK_EQUAL( m_part_no_data.Compare( m_part_no_data ), 0 );
359
360 // Test for identical LIB_SYMBOL.
361 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
362
363 // Test name.
364 testPart.SetName( "tart_name" );
365 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
366 testPart.SetName( "cart_name" );
367 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
368 testPart.SetName( "part_name" );
369
370 // LIB_ID comparison tests.
371 LIB_ID id = testPart.GetLibId();
372 id.SetLibItemName( "tart_name" );
373 testPart.SetLibId( id );
374 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
375 id.SetLibItemName( "cart_name" );
376 testPart.SetLibId( id );
377 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
378 id.SetLibItemName( "part_name" );
379 testPart.SetLibId( id );
380
381 // Unit count comparison tests.
382 testPart.SetUnitCount( 2, true );
383 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
384 testPart.SetUnitCount( 1, true );
385 m_part_no_data.SetUnitCount( 2, true );
386 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
387 m_part_no_data.SetUnitCount( 1, true );
388
389 // Options flag comparison tests.
390 testPart.SetGlobalPower();
391 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
392 testPart.SetNormal();
393 m_part_no_data.SetGlobalPower();
394 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
395 m_part_no_data.SetNormal();
396
397 // Draw item list size comparison tests.
399 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
400 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
401 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
402 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
403 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
404 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
405 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
406 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
407
408 // Draw item list contents comparison tests.
410 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::ARC, LAYER_DEVICE ) );
411 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
412 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
413 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
414 m_part_no_data.AddDrawItem( new SCH_PIN( &m_part_no_data ) );
415 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
416 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_PIN_T].front() );
417
418 // Footprint filter array comparison tests.
419 wxArrayString footPrintFilters;
420 BOOST_CHECK( m_part_no_data.GetFPFilters() == footPrintFilters );
421 footPrintFilters.Add( "b" );
422 testPart.SetFPFilters( footPrintFilters );
423 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
424 m_part_no_data.SetFPFilters( footPrintFilters );
425 footPrintFilters.Clear();
426 testPart.SetFPFilters( footPrintFilters );
427 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
428 footPrintFilters.Clear();
429 m_part_no_data.SetFPFilters( footPrintFilters );
430 testPart.SetFPFilters( footPrintFilters );
431
432 // Description string tests.
433 m_part_no_data.SetDescription( "b" );
434 testPart.SetDescription( "b" );
435 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
436 m_part_no_data.SetDescription( "a" );
437 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
438 m_part_no_data.SetDescription( "c" );
439 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
440 m_part_no_data.SetDescription( wxEmptyString );
441 testPart.SetDescription( wxEmptyString );
442
443 // Key word string tests.
444 m_part_no_data.SetKeyWords( "b" );
445 testPart.SetKeyWords( "b" );
446 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
447 m_part_no_data.SetKeyWords( "a" );
448 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
449 m_part_no_data.SetKeyWords( "c" );
450 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
451 m_part_no_data.SetKeyWords( wxEmptyString );
452 testPart.SetKeyWords( wxEmptyString );
453
454 // Pin name offset comparison tests.
455 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
456 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
457 testPart.SetPinNameOffset( testPart.GetPinNameOffset() - 2 );
458 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
459 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
460
461 // Units locked flag comparison tests.
462 testPart.LockUnits( true );
463 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
464 testPart.LockUnits( false );
465 m_part_no_data.LockUnits( true );
466 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
467 m_part_no_data.LockUnits( false );
468
469 // Include in BOM support tests.
470 testPart.SetExcludedFromBOM( true );
471 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
472 testPart.SetExcludedFromBOM( false );
473 m_part_no_data.SetExcludedFromBOM( true );
474 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
475 m_part_no_data.SetExcludedFromBOM( false );
476
477 // Include on board support tests.
478 testPart.SetExcludedFromBoard( true );
479 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
480 testPart.SetExcludedFromBoard( false );
481 m_part_no_data.SetExcludedFromBoard( true );
482 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
483 m_part_no_data.SetExcludedFromBoard( false );
484
485 // Include in position files support tests.
486 testPart.SetExcludedFromPosFiles( true );
487 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
488 testPart.SetExcludedFromPosFiles( false );
489 m_part_no_data.SetExcludedFromPosFiles( true );
490 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
491 m_part_no_data.SetExcludedFromPosFiles( false );
492
493 // Show pin names flag comparison tests.
494 m_part_no_data.SetShowPinNames( false );
495 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
496 m_part_no_data.SetShowPinNames( true );
497 testPart.SetShowPinNames( false );
498 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
499 testPart.SetShowPinNames( true );
500
501 // Show pin numbers flag comparison tests.
502 m_part_no_data.SetShowPinNumbers( false );
503 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
504 m_part_no_data.SetShowPinNumbers( true );
505 testPart.SetShowPinNumbers( false );
506 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
507 testPart.SetShowPinNumbers( true );
508
509 // Time stamp comparison tests.
510
511 // Check to see if we broke the copy ctor.
512 LIB_SYMBOL copy( testPart );
513 BOOST_CHECK( testPart.Compare( copy ) == 0 );
514}
515
516
520BOOST_AUTO_TEST_CASE( GetUnitItems )
521{
522 // There are no unit draw items in the empty LIB_SYMBOL object.
523 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
524
525 // A single unique unit with 1 pin common to all units and all body styles.
526 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
527 m_part_no_data.AddDrawItem( pin1 );
528 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 0, 0 ).size() == 1 );
529
530 // A single unique unit with 1 pin in unit 1 and common to all body styles.
531 pin1->SetUnit( 1 );
532 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 0 ).size() == 1 );
533
534 // A single unique unit with 1 pin in unit 1 and body style 1.
535 pin1->SetBodyStyle( 1 );
536 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 1 );
537
538 // Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assigned to
539 // unit 2 and body style 1.
540 SCH_PIN* pin2 = new SCH_PIN( &m_part_no_data );
541 m_part_no_data.SetUnitCount( 2, true );
542 pin2->SetUnit( 2 );
543 pin2->SetBodyStyle( 2 );
544 pin2->SetNumber( "4" );
545 m_part_no_data.AddDrawItem( pin2 );
546 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 2 ).size() == 1 );
547
548 // Make pin 1 body style common to all units.
549 pin1->SetBodyStyle( 0 );
550 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
551 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 1 ).size() == 1 );
552
553 m_part_no_data.RemoveDrawItem( pin2 );
554 m_part_no_data.RemoveDrawItem( pin1 );
555 m_part_no_data.RemoveDrawItem( &*m_part_no_data.GetDrawItems().begin() );
556}
557
558
562BOOST_AUTO_TEST_CASE( GetUnitDrawItems )
563{
564 // There are no unit draw items in the empty LIB_SYMBOL object.
565 BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 );
566
567 // A single unique unit with 1 pin common to all units and all body styles.
568 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
569 pin1->SetNumber( "1" );
570 m_part_no_data.AddDrawItem( pin1 );
571 std::vector<struct LIB_SYMBOL_UNIT> units = m_part_no_data.GetUnitDrawItems();
572 BOOST_CHECK( units.size() == 1 );
573 BOOST_CHECK( units[0].m_unit == 0 );
574 BOOST_CHECK( units[0].m_bodyStyle == 0 );
575 BOOST_CHECK( units[0].m_items[0] == pin1 );
576}
577
578
583{
584 std::unique_ptr<LIB_SYMBOL> parent = std::make_unique<LIB_SYMBOL>( "parent" );
585 BOOST_CHECK( parent->IsRoot() );
586 BOOST_CHECK_EQUAL( parent->GetInheritanceDepth(), 0 );
587
588 std::unique_ptr<LIB_SYMBOL> ref = std::make_unique<LIB_SYMBOL>( *parent );
589
590 std::unique_ptr<LIB_SYMBOL> child = std::make_unique<LIB_SYMBOL>( "child", parent.get() );
591 BOOST_CHECK( child->IsDerived() );
592 BOOST_CHECK_EQUAL( child->GetInheritanceDepth(), 1 );
593
594 std::unique_ptr<LIB_SYMBOL> grandChild = std::make_unique<LIB_SYMBOL>( "grandchild", child.get() );
595 BOOST_CHECK( grandChild->IsDerived() );
596 BOOST_CHECK_EQUAL( grandChild->GetInheritanceDepth(), 2 );
597
598 BOOST_CHECK( parent->GetRootSymbol().get() == parent.get() );
599 BOOST_CHECK( child->GetRootSymbol().get() == parent.get() );
600 BOOST_CHECK( grandChild->GetRootSymbol().get() == parent.get() );
601
602 std::shared_ptr<LIB_SYMBOL> parentRef = child->GetParent().lock();
603 BOOST_CHECK( parentRef );
604 BOOST_CHECK( parentRef == parent->SharedPtr() );
605 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 3 );
606
607 std::shared_ptr<LIB_SYMBOL> childRef = grandChild->GetParent().lock();
608 BOOST_CHECK( childRef );
609 BOOST_CHECK( childRef == child->SharedPtr() );
610 BOOST_CHECK_EQUAL( child->SharedPtr().use_count(), 3 );
611
612 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
613 parent->SetUnitCount( 4, true );
614 BOOST_CHECK_EQUAL( child->GetUnitCount(), 4 );
615 parent->SetUnitCount( 1, true );
616
617 parent->GetField( FIELD_T::DATASHEET )->SetText( "https://kicad/resistors.pdf" );
618 ref->GetField( FIELD_T::DATASHEET )->SetText( "https://kicad/resistors.pdf" );
619
620 BOOST_CHECK( *parent == *ref );
621
622 ref->SetName( "child" );
623 SCH_FIELD* field = new SCH_FIELD( nullptr, FIELD_T::USER, "Manufacturer" );
624 field->SetText( "KiCad" );
625 child->AddField( field );
626 field->SetParent( child.get() );
627
628 field = new SCH_FIELD( nullptr, FIELD_T::USER, "Manufacturer" );
629 field->SetText( "KiCad" );
630 ref->AddField( field );
631 field->SetParent( ref.get() );
632
633 BOOST_CHECK( *ref == *child->Flatten() );
634
635 ref->SetName( "grandchild" );
636 field = new SCH_FIELD( nullptr, FIELD_T::USER, "MPN" );
637 field->SetText( "123456" );
638 grandChild->AddField( field );
639 field->SetParent( grandChild.get() );
640
641 field = new SCH_FIELD( nullptr, FIELD_T::USER, "MPN" );
642 field->SetText( "123456" );
643 ref->AddField( field );
644 field->SetParent( ref.get() );
645
646 BOOST_CHECK( *ref == *grandChild->Flatten() );
647
648 BOOST_CHECK_EQUAL( grandChild->Flatten()->GetField( FIELD_T::DATASHEET )->GetText(),
649 "https://kicad/resistors.pdf" );
650
651 child->SetParent();
652 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
653
654 parentRef.reset();
655 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 2 );
656}
657
658
662BOOST_AUTO_TEST_CASE( CopyConstructor )
663{
664 std::shared_ptr<LIB_SYMBOL> copy = std::make_shared<LIB_SYMBOL>( m_part_no_data );
665 BOOST_CHECK( m_part_no_data == *copy.get() );
666}
667
668
673{
674 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( "power" );
675 SCH_PIN* pin = new SCH_PIN( symbol.get() );
676 pin->SetNumber( "1" );
678 pin->SetVisible( false );
679 symbol->AddDrawItem( pin );
680
681 BOOST_CHECK( !symbol->IsPower() );
682 BOOST_CHECK( symbol->IsNormal() );
683
684 symbol->SetGlobalPower();
685 BOOST_CHECK( symbol->IsPower() );
686 BOOST_CHECK( !symbol->IsNormal() );
687
688 // symbol->SetNormal();
689 // symbol->GetReferenceField().SetText( wxS( "#PWR" ) );
690 // BOOST_CHECK( symbol->IsPower() );
691
692 // Legacy power symbols are limited to a single pin.
693 // pin = new LIB_PIN( symbol.get() );
694 // pin->SetNumber( "2" );
695 // pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
696 // pin->SetVisible( false );
697 // symbol->AddDrawItem( pin );
698 // BOOST_CHECK( !symbol->IsPower() );
699}
700
701
711BOOST_AUTO_TEST_CASE( SetUnitCountRejectsInvalidValues )
712{
713 auto checkMandatoryFields = []( LIB_SYMBOL& aSymbol )
714 {
715 BOOST_CHECK_EQUAL( aSymbol.GetUnitCount(), 1 );
716 BOOST_CHECK_NE( aSymbol.GetField( FIELD_T::REFERENCE ), nullptr );
717 BOOST_CHECK_NE( aSymbol.GetField( FIELD_T::VALUE ), nullptr );
718 BOOST_CHECK_NE( aSymbol.GetField( FIELD_T::FOOTPRINT ), nullptr );
719 BOOST_CHECK_NE( aSymbol.GetField( FIELD_T::DATASHEET ), nullptr );
720 BOOST_CHECK_NE( aSymbol.GetField( FIELD_T::DESCRIPTION ), nullptr );
721
722 // Reading the reference field text must not crash. This was the original SIGSEGV
723 // path through CONNECTION_SUBGRAPH::GetDriverPriority() reported in issue 23788.
724 BOOST_CHECK_NO_THROW( (void) aSymbol.GetReferenceField().GetText() );
725 };
726
727 // Sanity check the freshly constructed symbol.
728 LIB_SYMBOL baseline( wxS( "test_part" ) );
729 checkMandatoryFields( baseline );
730
731 // When wxDEBUG_LEVEL > 0 the wxCHECK fires (caught by CHECK_WX_ASSERT) and the function
732 // does not modify the symbol. With wxDEBUG_LEVEL == 0 the wxCHECK is silent and the
733 // function returns early without modification. Cover both call paths so the test
734 // exercises the actual SetUnitCount entry on every build configuration.
735 LIB_SYMBOL zeroCount( wxS( "test_part" ) );
736 CHECK_WX_ASSERT( zeroCount.SetUnitCount( 0, true ) );
737#if wxDEBUG_LEVEL == 0
738 zeroCount.SetUnitCount( 0, true );
739#endif
740 checkMandatoryFields( zeroCount );
741
742 LIB_SYMBOL negativeCount( wxS( "test_part" ) );
743 CHECK_WX_ASSERT( negativeCount.SetUnitCount( -1, true ) );
744#if wxDEBUG_LEVEL == 0
745 negativeCount.SetUnitCount( -1, true );
746#endif
747 checkMandatoryFields( negativeCount );
748}
749
750
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition lib_id.cpp:107
Define a library symbol object.
Definition lib_symbol.h:79
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:148
void SetGlobalPower()
int Compare(const LIB_SYMBOL &aRhs, int aCompareFlags=0, REPORTER *aReporter=nullptr) const
Comparison test that can be used for operators.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
Definition lib_symbol.h:277
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:709
void SetUnitCount(int aCount, bool aDuplicateDrawItems)
Set the units per symbol count.
void SetDescription(const wxString &aDescription)
Gets the Description field text value *‍/.
void SetKeyWords(const wxString &aKeyWords)
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
void SetFPFilters(const wxArrayString &aFilters)
Definition lib_symbol.h:205
void SetLibId(const LIB_ID &aLibId)
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
virtual void SetName(const wxString &aName)
void SetNormal()
void SetText(const wxString &aText) override
virtual void SetBodyStyle(int aBodyStyle)
Definition sch_item.h:241
virtual void SetUnit(int aUnit)
Definition sch_item.h:232
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:734
void SetExcludedFromBoard(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from board netlist flag.
Definition symbol.h:206
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition symbol.h:170
int GetPinNameOffset() const
Definition symbol.h:159
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition symbol.h:164
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition symbol.h:158
void SetExcludedFromPosFiles(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from position files flag.
Definition symbol.h:221
virtual void SetExcludedFromBOM(bool aExcludeFromBOM, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
Definition symbol.h:191
TEST_LIB_SYMBOL_FIXTURE()
Part with no extra data set.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:47
@ LAYER_DEVICE
Definition layer_ids.h:464
Test utils (e.g.
bool AreDefaultFieldsCorrect(const std::vector< SCH_FIELD > &aFields)
Predicate to check that the mandatory fields look sensible.
bool FieldNameIdMatches(const SCH_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ USER
The field ID hasn't been set yet; field is invalid.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
KIBIS_PIN * pin1
KIBIS_PIN * pin
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SHAPE_T
Definition typeinfo.h:146
@ SCH_PIN_T
Definition typeinfo.h:150
#define CHECK_WX_ASSERT(STATEMENT)
A test macro to check a wxASSERT is thrown.