KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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, 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
30
31// Code under test
32#include <sch_shape.h>
33#include <sch_pin.h>
34#include <lib_symbol.h>
35
37
39{
40public:
42 m_part_no_data( "part_name", nullptr )
43 {
44 }
45
48};
49
50
54BOOST_FIXTURE_TEST_SUITE( LibPart, TEST_LIB_SYMBOL_FIXTURE )
55
56
57
60BOOST_AUTO_TEST_CASE( DefaultProperties )
61{
62 BOOST_CHECK_EQUAL( m_part_no_data.GetName(), "part_name" );
63
64 // Didn't set a library, so this is empty
65 BOOST_CHECK_EQUAL( m_part_no_data.GetLibraryName(), "" );
66 BOOST_CHECK_EQUAL( m_part_no_data.GetLib(), nullptr );
67
68 // only get the root
69 BOOST_CHECK_EQUAL( m_part_no_data.IsRoot(), true );
70 BOOST_CHECK_EQUAL( m_part_no_data.IsDerived(), false );
71 BOOST_CHECK_EQUAL( m_part_no_data.SharedPtr().use_count(), 2 );
72
73 // no sub units
74 BOOST_CHECK_EQUAL( m_part_no_data.GetUnitCount(), 1 );
75 BOOST_CHECK_EQUAL( m_part_no_data.IsMulti(), false );
76
77 // no conversion
78 BOOST_CHECK_EQUAL( m_part_no_data.HasAlternateBodyStyle(), false );
79}
80
81
85BOOST_AUTO_TEST_CASE( DefaultDrawings )
86{
87 // default drawings exist
88 BOOST_CHECK_EQUAL( m_part_no_data.GetDrawItems().size(), 5 );
89 BOOST_CHECK_EQUAL( m_part_no_data.GetPins().size(), 0 );
90}
91
92
96BOOST_AUTO_TEST_CASE( DefaultFields )
97{
98 std::vector<SCH_FIELD> fields;
99 m_part_no_data.CopyFields( fields );
100
101 // Should get the 4 default fields
103
104 // but no more (we didn't set them)
105 BOOST_CHECK_EQUAL( fields.size(), 5 );
106
107 // also check the default field accessors
109 ( m_part_no_data.GetReferenceField() )( "Reference" )( (int) FIELD_T::REFERENCE ) );
111 ( m_part_no_data.GetValueField() )( "Value" )( (int) FIELD_T::VALUE ) );
113 ( m_part_no_data.GetFootprintField() )( "Footprint" )( (int) FIELD_T::FOOTPRINT ) );
115 ( m_part_no_data.GetDatasheetField() )( "Datasheet" )( (int) FIELD_T::DATASHEET ) );
117 ( m_part_no_data.GetDescriptionField() )( "Description" )( (int) FIELD_T::DESCRIPTION ) );
118}
119
120
125{
126 std::vector<SCH_FIELD> fields;
127 m_part_no_data.CopyFields( fields );
128
129 // Ctor takes non-const ref (?!)
130 const std::string newFieldName = "new_field";
131 wxString nonConstNewFieldName = newFieldName;
132 fields.push_back( SCH_FIELD( nullptr, FIELD_T::USER, nonConstNewFieldName ) );
133
134 // fairly roundabout way to add a field, but it is what it is
135 m_part_no_data.SetFields( fields );
136
137 // Should get the 4 default fields
139
140 // and our new one
141 BOOST_REQUIRE_EQUAL( fields.size(), 6 );
142
143 // Check by-name lookup
144
145 SCH_FIELD* gotNewField = m_part_no_data.GetField( newFieldName );
146
147 BOOST_REQUIRE_NE( gotNewField, nullptr );
148 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 0 ) );
149}
150
151
155BOOST_AUTO_TEST_CASE( AddedDrawItems )
156{
157}
158
159
161{
164 std::string m_expSubRef;
165};
166
167
171BOOST_AUTO_TEST_CASE( SubReference )
172{
173 const std::vector<TEST_LIB_SYMBOL_SUBREF_CASE> cases = {
174 {
175 1,
176 false,
177 "A",
178 },
179 {
180 2,
181 false,
182 "B",
183 },
184 {
185 26,
186 false,
187 "Z",
188 },
189 {
190 27,
191 false,
192 "AA",
193 },
194 {
195 28,
196 false,
197 "AB",
198 },
199 {
200 53,
201 false,
202 "BA",
203 },
204 {
205 79,
206 false,
207 "CA",
208 },
209 {
210 105,
211 false,
212 "DA",
213 },
214 {
215 131,
216 false,
217 "EA",
218 },
219 {
220 157,
221 false,
222 "FA",
223 },
224 {
225 183,
226 false,
227 "GA",
228 },
229 {
230 209,
231 false,
232 "HA",
233 },
234 {
235 235,
236 false,
237 "IA",
238 },
239 {
240 261,
241 false,
242 "JA",
243 },
244 {
245 287,
246 false,
247 "KA",
248 },
249 {
250 313,
251 false,
252 "LA",
253 },
254 {
255 339,
256 false,
257 "MA",
258 },
259 {
260 365,
261 false,
262 "NA",
263 },
264 {
265 391,
266 false,
267 "OA",
268 },
269 {
270 417,
271 false,
272 "PA",
273 },
274 {
275 443,
276 false,
277 "QA",
278 },
279 {
280 469,
281 false,
282 "RA",
283 },
284 {
285 495,
286 false,
287 "SA",
288 },
289 {
290 521,
291 false,
292 "TA",
293 },
294 {
295 547,
296 false,
297 "UA",
298 },
299 {
300 573,
301 false,
302 "VA",
303 },
304 {
305 599,
306 false,
307 "WA",
308 },
309 {
310 625,
311 false,
312 "XA",
313 },
314 {
315 651,
316 false,
317 "YA",
318 },
319 {
320 677,
321 false,
322 "ZA",
323 },
324 {
325 702,
326 false,
327 "ZZ",
328 },
329 {
330 703,
331 false,
332 "AAA",
333 },
334 {
335 728,
336 false,
337 "AAZ",
338 },
339 };
340
341 for( const auto& c : cases )
342 {
344 "Subref: " << c.m_index << ", " << c.m_addSep << " -> '" << c.m_expSubRef << "'" )
345 {
346 const auto subref = LIB_SYMBOL::LetterSubReference( c.m_index, 'A' );
347 BOOST_CHECK_EQUAL( subref, c.m_expSubRef );
348 }
349 }
350}
351
352
357{
358 // Identical root part to m_part_no_data sans time stamp.
359 LIB_SYMBOL testPart( "part_name" );
360
361 // Self comparison test.
362 BOOST_CHECK_EQUAL( m_part_no_data.Compare( m_part_no_data ), 0 );
363
364 // Test for identical LIB_SYMBOL.
365 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
366
367 // Test name.
368 testPart.SetName( "tart_name" );
369 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
370 testPart.SetName( "cart_name" );
371 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
372 testPart.SetName( "part_name" );
373
374 // LIB_ID comparison tests.
375 LIB_ID id = testPart.GetLibId();
376 id.SetLibItemName( "tart_name" );
377 testPart.SetLibId( id );
378 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
379 id.SetLibItemName( "cart_name" );
380 testPart.SetLibId( id );
381 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
382 id.SetLibItemName( "part_name" );
383 testPart.SetLibId( id );
384
385 // Unit count comparison tests.
386 testPart.SetUnitCount( 2 );
387 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
388 testPart.SetUnitCount( 1 );
389 m_part_no_data.SetUnitCount( 2 );
390 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
391 m_part_no_data.SetUnitCount( 1 );
392
393 // Options flag comparison tests.
394 testPart.SetGlobalPower();
395 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
396 testPart.SetNormal();
397 m_part_no_data.SetGlobalPower();
398 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
399 m_part_no_data.SetNormal();
400
401 // Draw item list size comparison tests.
403 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
404 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
405 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
406 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
407 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
408 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
409 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
410 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
411
412 // Draw item list contents comparison tests.
414 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::ARC, LAYER_DEVICE ) );
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_SHAPE_T].front() );
417 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
418 m_part_no_data.AddDrawItem( new SCH_PIN( &m_part_no_data ) );
419 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
420 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_PIN_T].front() );
421
422 // Footprint filter array comparison tests.
423 wxArrayString footPrintFilters;
424 BOOST_CHECK( m_part_no_data.GetFPFilters() == footPrintFilters );
425 footPrintFilters.Add( "b" );
426 testPart.SetFPFilters( footPrintFilters );
427 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
428 m_part_no_data.SetFPFilters( footPrintFilters );
429 footPrintFilters.Clear();
430 testPart.SetFPFilters( footPrintFilters );
431 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
432 footPrintFilters.Clear();
433 m_part_no_data.SetFPFilters( footPrintFilters );
434 testPart.SetFPFilters( footPrintFilters );
435
436 // Description string tests.
437 m_part_no_data.SetDescription( "b" );
438 testPart.SetDescription( "b" );
439 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
440 m_part_no_data.SetDescription( "a" );
441 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
442 m_part_no_data.SetDescription( "c" );
443 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
444 m_part_no_data.SetDescription( wxEmptyString );
445 testPart.SetDescription( wxEmptyString );
446
447 // Key word string tests.
448 m_part_no_data.SetKeyWords( "b" );
449 testPart.SetKeyWords( "b" );
450 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
451 m_part_no_data.SetKeyWords( "a" );
452 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
453 m_part_no_data.SetKeyWords( "c" );
454 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
455 m_part_no_data.SetKeyWords( wxEmptyString );
456 testPart.SetKeyWords( wxEmptyString );
457
458 // Pin name offset comparison tests.
459 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
460 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
461 testPart.SetPinNameOffset( testPart.GetPinNameOffset() - 2 );
462 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
463 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
464
465 // Units locked flag comparison tests.
466 testPart.LockUnits( true );
467 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
468 testPart.LockUnits( false );
469 m_part_no_data.LockUnits( true );
470 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
471 m_part_no_data.LockUnits( false );
472
473 // Include in BOM support tests.
474 testPart.SetExcludedFromBOM( true );
475 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
476 testPart.SetExcludedFromBOM( false );
477 m_part_no_data.SetExcludedFromBOM( true );
478 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
479 m_part_no_data.SetExcludedFromBOM( false );
480
481 // Include on board support tests.
482 testPart.SetExcludedFromBoard( true );
483 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
484 testPart.SetExcludedFromBoard( false );
485 m_part_no_data.SetExcludedFromBoard( true );
486 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
487 m_part_no_data.SetExcludedFromBoard( false );
488
489 // Show pin names flag comparison tests.
490 m_part_no_data.SetShowPinNames( false );
491 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
492 m_part_no_data.SetShowPinNames( true );
493 testPart.SetShowPinNames( false );
494 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
495 testPart.SetShowPinNames( true );
496
497 // Show pin numbers flag comparison tests.
498 m_part_no_data.SetShowPinNumbers( false );
499 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
500 m_part_no_data.SetShowPinNumbers( true );
501 testPart.SetShowPinNumbers( false );
502 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
503 testPart.SetShowPinNumbers( true );
504
505 // Time stamp comparison tests.
506
507 // Check to see if we broke the copy ctor.
508 LIB_SYMBOL copy( testPart );
509 BOOST_CHECK( testPart.Compare( copy ) == 0 );
510}
511
512
516BOOST_AUTO_TEST_CASE( GetUnitItems )
517{
518 // There are no unit draw items in the empty LIB_SYMBOL object.
519 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
520
521 // A single unique unit with 1 pin common to all units and all body styles.
522 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
523 m_part_no_data.AddDrawItem( pin1 );
524 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 0, 0 ).size() == 1 );
525
526 // A single unique unit with 1 pin in unit 1 and common to all body styles.
527 pin1->SetUnit( 1 );
528 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 0 ).size() == 1 );
529
530 // A single unique unit with 1 pin in unit 1 and body style 1.
531 pin1->SetBodyStyle( 1 );
532 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 1 );
533
534 // Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assigned to
535 // unit 2 and body style 1.
536 SCH_PIN* pin2 = new SCH_PIN( &m_part_no_data );
537 m_part_no_data.SetUnitCount( 2 );
538 pin2->SetUnit( 2 );
539 pin2->SetBodyStyle( 2 );
540 pin2->SetNumber( "4" );
541 m_part_no_data.AddDrawItem( pin2 );
542 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 2 ).size() == 1 );
543
544 // Make pin 1 body style common to all units.
545 pin1->SetBodyStyle( 0 );
546 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
547 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 1 ).size() == 1 );
548
549 m_part_no_data.RemoveDrawItem( pin2 );
550 m_part_no_data.RemoveDrawItem( pin1 );
551 m_part_no_data.RemoveDrawItem( &*m_part_no_data.GetDrawItems().begin() );
552}
553
554
558BOOST_AUTO_TEST_CASE( GetUnitDrawItems )
559{
560 // There are no unit draw items in the empty LIB_SYMBOL object.
561 BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 );
562
563 // A single unique unit with 1 pin common to all units and all body styles.
564 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
565 pin1->SetNumber( "1" );
566 m_part_no_data.AddDrawItem( pin1 );
567 std::vector<struct LIB_SYMBOL_UNIT> units = m_part_no_data.GetUnitDrawItems();
568 BOOST_CHECK( units.size() == 1 );
569 BOOST_CHECK( units[0].m_unit == 0 );
570 BOOST_CHECK( units[0].m_bodyStyle == 0 );
571 BOOST_CHECK( units[0].m_items[0] == pin1 );
572}
573
574
579{
580 std::unique_ptr<LIB_SYMBOL> parent = std::make_unique<LIB_SYMBOL>( "parent" );
581 BOOST_CHECK( parent->IsRoot() );
582 BOOST_CHECK_EQUAL( parent->GetInheritanceDepth(), 0 );
583
584 std::unique_ptr<LIB_SYMBOL> ref = std::make_unique<LIB_SYMBOL>( *parent );
585
586 std::unique_ptr<LIB_SYMBOL> child = std::make_unique<LIB_SYMBOL>( "child", parent.get() );
587 BOOST_CHECK( child->IsDerived() );
588 BOOST_CHECK_EQUAL( child->GetInheritanceDepth(), 1 );
589
590 std::unique_ptr<LIB_SYMBOL> grandChild = std::make_unique<LIB_SYMBOL>( "grandchild",
591 child.get() );
592 BOOST_CHECK( grandChild->IsDerived() );
593 BOOST_CHECK_EQUAL( grandChild->GetInheritanceDepth(), 2 );
594
595 BOOST_CHECK( parent->GetRootSymbol().get() == parent.get() );
596 BOOST_CHECK( child->GetRootSymbol().get() == parent.get() );
597 BOOST_CHECK( grandChild->GetRootSymbol().get() == parent.get() );
598
599 LIB_SYMBOL_SPTR parentRef = child->GetParent().lock();
600 BOOST_CHECK( parentRef );
601 BOOST_CHECK( parentRef == parent->SharedPtr() );
602 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 3 );
603
604 LIB_SYMBOL_SPTR childRef = grandChild->GetParent().lock();
605 BOOST_CHECK( childRef );
606 BOOST_CHECK( childRef == child->SharedPtr() );
607 BOOST_CHECK_EQUAL( child->SharedPtr().use_count(), 3 );
608
609 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
610 parent->SetUnitCount( 4 );
611 BOOST_CHECK_EQUAL( child->GetUnitCount(), 4 );
612 parent->SetUnitCount( 1 );
613
614 parent->GetField( FIELD_T::DATASHEET )->SetText( "https://kicad/resistors.pdf" );
615 ref->GetField( FIELD_T::DATASHEET )->SetText( "https://kicad/resistors.pdf" );
616
617 BOOST_CHECK( *parent == *ref );
618
619 ref->SetName( "child" );
620 SCH_FIELD* field = new SCH_FIELD( nullptr, FIELD_T::USER, "Manufacturer" );
621 field->SetText( "KiCad" );
622 child->AddField( field );
623 field->SetParent( child.get() );
624
625 field = new SCH_FIELD( nullptr, FIELD_T::USER, "Manufacturer" );
626 field->SetText( "KiCad" );
627 ref->AddField( field );
628 field->SetParent( ref.get() );
629
630 BOOST_CHECK( *ref == *child->Flatten() );
631
632 ref->SetName( "grandchild" );
633 field = new SCH_FIELD( nullptr, FIELD_T::USER, "MPN" );
634 field->SetText( "123456" );
635 grandChild->AddField( field );
636 field->SetParent( grandChild.get() );
637
638 field = new SCH_FIELD( nullptr, FIELD_T::USER, "MPN" );
639 field->SetText( "123456" );
640 ref->AddField( field );
641 field->SetParent( ref.get() );
642
643 BOOST_CHECK( *ref == *grandChild->Flatten() );
644
645 BOOST_CHECK_EQUAL( grandChild->Flatten()->GetField( FIELD_T::DATASHEET )->GetText(),
646 "https://kicad/resistors.pdf" );
647
648 child->SetParent();
649 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
650
651 parentRef.reset();
652 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 2 );
653}
654
655
659BOOST_AUTO_TEST_CASE( CopyConstructor )
660{
661 std::shared_ptr<LIB_SYMBOL> copy = std::make_shared<LIB_SYMBOL>( m_part_no_data );
662 BOOST_CHECK( m_part_no_data == *copy.get() );
663}
664
665
670{
671 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( "power" );
672 SCH_PIN* pin = new SCH_PIN( symbol.get() );
673 pin->SetNumber( "1" );
675 pin->SetVisible( false );
676 symbol->AddDrawItem( pin );
677
678 BOOST_CHECK( !symbol->IsPower() );
679 BOOST_CHECK( symbol->IsNormal() );
680
681 symbol->SetGlobalPower();
682 BOOST_CHECK( symbol->IsPower() );
683 BOOST_CHECK( !symbol->IsNormal() );
684
685 // symbol->SetNormal();
686 // symbol->GetReferenceField().SetText( wxS( "#PWR" ) );
687 // BOOST_CHECK( symbol->IsPower() );
688
689 // Legacy power symbols are limited to a single pin.
690 // pin = new LIB_PIN( symbol.get() );
691 // pin->SetNumber( "2" );
692 // pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
693 // pin->SetVisible( false );
694 // symbol->AddDrawItem( pin );
695 // BOOST_CHECK( !symbol->IsPower() );
696}
697
698
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:110
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:111
Define a library symbol object.
Definition: lib_symbol.h:85
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:155
void SetGlobalPower()
Definition: lib_symbol.cpp:473
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
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, int aFirstId)
Definition: lib_symbol.cpp:515
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
Definition: lib_symbol.h:283
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:519
void SetDescription(const wxString &aDescription)
Gets the Description field text value *‍/.
Definition: lib_symbol.h:164
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:181
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:758
void SetFPFilters(const wxArrayString &aFilters)
Definition: lib_symbol.h:216
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:156
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:783
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:326
void SetNormal()
Definition: lib_symbol.cpp:501
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1069
virtual void SetBodyStyle(int aBodyStyle)
Definition: sch_item.h:242
@ EQUALITY
Definition: sch_item.h:638
virtual void SetUnit(int aUnit)
Definition: sch_item.h:239
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:545
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: symbol.h:164
int GetPinNameOffset() const
Definition: symbol.h:153
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition: symbol.h:158
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
Definition: symbol.h:180
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition: symbol.h:152
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
Definition: symbol.h:186
TEST_LIB_SYMBOL_FIXTURE()
Part with no extra data set.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ LAYER_DEVICE
Definition: layer_ids.h:455
Test utils (e.g.
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:52
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.
@ 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_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_AUTO_TEST_SUITE_END()
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")
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_PIN_T
Definition: typeinfo.h:153