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 (C) 2019-2023 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.IsAlias(), 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(), MANDATORY_FIELDS );
89 BOOST_CHECK_EQUAL( m_part_no_data.GetAllLibPins().size(), 0 );
90}
91
92
96BOOST_AUTO_TEST_CASE( DefaultFields )
97{
98 std::vector<SCH_FIELD> fields;
99 m_part_no_data.GetFields( fields );
100
101 // Should get the 4 default fields
102 BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
103
104 // but no more (we didn't set them)
105 BOOST_CHECK_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS );
106
107 // also check the default field accessors
108 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
109 ( m_part_no_data.GetReferenceField() )( "Reference" )( MANDATORY_FIELD_T::REFERENCE_FIELD ) );
110 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
111 ( m_part_no_data.GetValueField() )( "Value" )( MANDATORY_FIELD_T::VALUE_FIELD ) );
112 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
113 ( m_part_no_data.GetFootprintField() )( "Footprint" )( MANDATORY_FIELD_T::FOOTPRINT_FIELD ) );
114 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
115 ( m_part_no_data.GetDatasheetField() )( "Datasheet" )( MANDATORY_FIELD_T::DATASHEET_FIELD) );
116 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
117 ( m_part_no_data.GetDescriptionField() )( "Description" )( MANDATORY_FIELD_T::DESCRIPTION_FIELD) );
118}
119
120
125{
126 std::vector<SCH_FIELD> fields;
127 m_part_no_data.GetFields( 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, 42, 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
138 BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
139
140 // and our new one
141 BOOST_REQUIRE_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS + 1 );
142
143 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
144 ( fields[MANDATORY_FIELD_T::MANDATORY_FIELDS] )( newFieldName )( 42 ) );
145
146 // Check by-id lookup
147
148 SCH_FIELD* gotNewField = m_part_no_data.GetFieldById( 42 );
149
150 BOOST_REQUIRE_NE( gotNewField, nullptr );
151
152 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 42 ) );
153
154 // Check by-name lookup
155
156 gotNewField = m_part_no_data.FindField( newFieldName );
157
158 BOOST_REQUIRE_NE( gotNewField, nullptr );
159 BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 42 ) );
160}
161
162
166BOOST_AUTO_TEST_CASE( AddedDrawItems )
167{
168}
169
170
172{
175 std::string m_expSubRef;
176};
177
178
182BOOST_AUTO_TEST_CASE( SubReference )
183{
184 const std::vector<TEST_LIB_SYMBOL_SUBREF_CASE> cases = {
185 {
186 1,
187 false,
188 "A",
189 },
190 {
191 2,
192 false,
193 "B",
194 },
195 {
196 26,
197 false,
198 "Z",
199 },
200 {
201 27,
202 false,
203 "AA",
204 },
205 {
206 28,
207 false,
208 "AB",
209 },
210 {
211 53,
212 false,
213 "BA",
214 },
215 {
216 79,
217 false,
218 "CA",
219 },
220 {
221 105,
222 false,
223 "DA",
224 },
225 {
226 131,
227 false,
228 "EA",
229 },
230 {
231 157,
232 false,
233 "FA",
234 },
235 {
236 183,
237 false,
238 "GA",
239 },
240 {
241 209,
242 false,
243 "HA",
244 },
245 {
246 235,
247 false,
248 "IA",
249 },
250 {
251 261,
252 false,
253 "JA",
254 },
255 {
256 287,
257 false,
258 "KA",
259 },
260 {
261 313,
262 false,
263 "LA",
264 },
265 {
266 339,
267 false,
268 "MA",
269 },
270 {
271 365,
272 false,
273 "NA",
274 },
275 {
276 391,
277 false,
278 "OA",
279 },
280 {
281 417,
282 false,
283 "PA",
284 },
285 {
286 443,
287 false,
288 "QA",
289 },
290 {
291 469,
292 false,
293 "RA",
294 },
295 {
296 495,
297 false,
298 "SA",
299 },
300 {
301 521,
302 false,
303 "TA",
304 },
305 {
306 547,
307 false,
308 "UA",
309 },
310 {
311 573,
312 false,
313 "VA",
314 },
315 {
316 599,
317 false,
318 "WA",
319 },
320 {
321 625,
322 false,
323 "XA",
324 },
325 {
326 651,
327 false,
328 "YA",
329 },
330 {
331 677,
332 false,
333 "ZA",
334 },
335 {
336 702,
337 false,
338 "ZZ",
339 },
340 {
341 703,
342 false,
343 "AAA",
344 },
345 {
346 728,
347 false,
348 "AAZ",
349 },
350 };
351
352 for( const auto& c : cases )
353 {
354 BOOST_TEST_CONTEXT(
355 "Subref: " << c.m_index << ", " << c.m_addSep << " -> '" << c.m_expSubRef << "'" )
356 {
357 const auto subref = LIB_SYMBOL::LetterSubReference( c.m_index, 'A' );
358 BOOST_CHECK_EQUAL( subref, c.m_expSubRef );
359 }
360 }
361}
362
363
368{
369 // Identical root part to m_part_no_data sans time stamp.
370 LIB_SYMBOL testPart( "part_name" );
371
372 // Self comparison test.
373 BOOST_CHECK_EQUAL( m_part_no_data.Compare( m_part_no_data ), 0 );
374
375 // Test for identical LIB_SYMBOL.
376 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
377
378 // Test name.
379 testPart.SetName( "tart_name" );
380 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
381 testPart.SetName( "cart_name" );
382 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
383 testPart.SetName( "part_name" );
384
385 // LIB_ID comparison tests.
386 LIB_ID id = testPart.GetLibId();
387 id.SetLibItemName( "tart_name" );
388 testPart.SetLibId( id );
389 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
390 id.SetLibItemName( "cart_name" );
391 testPart.SetLibId( id );
392 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
393 id.SetLibItemName( "part_name" );
394 testPart.SetLibId( id );
395
396 // Unit count comparison tests.
397 testPart.SetUnitCount( 2 );
398 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
399 testPart.SetUnitCount( 1 );
400 m_part_no_data.SetUnitCount( 2 );
401 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
402 m_part_no_data.SetUnitCount( 1 );
403
404 // Options flag comparison tests.
405 testPart.SetPower();
406 BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
407 testPart.SetNormal();
408 m_part_no_data.SetPower();
409 BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
410 m_part_no_data.SetNormal();
411
412 // Draw item list size comparison tests.
414 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
415 BOOST_CHECK_EQUAL( 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 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
418 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
419 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE ) );
420 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
421 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
422
423 // Draw item list contents comparison tests.
425 m_part_no_data.AddDrawItem( new SCH_SHAPE( SHAPE_T::ARC, LAYER_DEVICE ) );
426 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
427 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() );
428 testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() );
429 m_part_no_data.AddDrawItem( new SCH_PIN( &m_part_no_data ) );
430 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
431 m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_PIN_T].front() );
432
433 // Footprint filter array comparison tests.
434 wxArrayString footPrintFilters;
435 BOOST_CHECK( m_part_no_data.GetFPFilters() == footPrintFilters );
436 footPrintFilters.Add( "b" );
437 testPart.SetFPFilters( footPrintFilters );
438 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
439 m_part_no_data.SetFPFilters( footPrintFilters );
440 footPrintFilters.Clear();
441 testPart.SetFPFilters( footPrintFilters );
442 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
443 footPrintFilters.Clear();
444 m_part_no_data.SetFPFilters( footPrintFilters );
445 testPart.SetFPFilters( footPrintFilters );
446
447 // Description string tests.
448 m_part_no_data.SetDescription( "b" );
449 testPart.SetDescription( "b" );
450 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
451 m_part_no_data.SetDescription( "a" );
452 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
453 m_part_no_data.SetDescription( "c" );
454 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
455 m_part_no_data.SetDescription( wxEmptyString );
456 testPart.SetDescription( wxEmptyString );
457
458 // Key word string tests.
459 m_part_no_data.SetKeyWords( "b" );
460 testPart.SetKeyWords( "b" );
461 BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
462 m_part_no_data.SetKeyWords( "a" );
463 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
464 m_part_no_data.SetKeyWords( "c" );
465 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
466 m_part_no_data.SetKeyWords( wxEmptyString );
467 testPart.SetKeyWords( wxEmptyString );
468
469 // Pin name offset comparison tests.
470 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
471 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
472 testPart.SetPinNameOffset( testPart.GetPinNameOffset() - 2 );
473 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
474 testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
475
476 // Units locked flag comparison tests.
477 testPart.LockUnits( true );
478 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
479 testPart.LockUnits( false );
480 m_part_no_data.LockUnits( true );
481 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
482 m_part_no_data.LockUnits( false );
483
484 // Include in BOM support tests.
485 testPart.SetExcludedFromBOM( true );
486 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
487 testPart.SetExcludedFromBOM( false );
488 m_part_no_data.SetExcludedFromBOM( true );
489 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
490 m_part_no_data.SetExcludedFromBOM( false );
491
492 // Include on board support tests.
493 testPart.SetExcludedFromBoard( true );
494 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
495 testPart.SetExcludedFromBoard( false );
496 m_part_no_data.SetExcludedFromBoard( true );
497 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
498 m_part_no_data.SetExcludedFromBoard( false );
499
500 // Show pin names flag comparison tests.
501 m_part_no_data.SetShowPinNames( false );
502 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
503 m_part_no_data.SetShowPinNames( true );
504 testPart.SetShowPinNames( false );
505 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
506 testPart.SetShowPinNames( true );
507
508 // Show pin numbers flag comparison tests.
509 m_part_no_data.SetShowPinNumbers( false );
510 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
511 m_part_no_data.SetShowPinNumbers( true );
512 testPart.SetShowPinNumbers( false );
513 BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
514 testPart.SetShowPinNumbers( true );
515
516 // Time stamp comparison tests.
517
518 // Check to see if we broke the copy ctor.
519 LIB_SYMBOL copy( testPart );
520 BOOST_CHECK( testPart.Compare( copy ) == 0 );
521}
522
523
527BOOST_AUTO_TEST_CASE( GetUnitItems )
528{
529 // There are no unit draw items in the empty LIB_SYMBOL object.
530 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
531
532 // A single unique unit with 1 pin common to all units and all body styles.
533 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
534 m_part_no_data.AddDrawItem( pin1 );
535 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 0, 0 ).size() == 1 );
536
537 // A single unique unit with 1 pin in unit 1 and common to all body styles.
538 pin1->SetUnit( 1 );
539 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 0 ).size() == 1 );
540
541 // A single unique unit with 1 pin in unit 1 and body style 1.
542 pin1->SetBodyStyle( 1 );
543 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 1 );
544
545 // Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assigned to
546 // unit 2 and body style 1.
547 SCH_PIN* pin2 = new SCH_PIN( &m_part_no_data );
548 m_part_no_data.SetUnitCount( 2 );
549 pin2->SetUnit( 2 );
550 pin2->SetBodyStyle( 2 );
551 pin2->SetNumber( "4" );
552 m_part_no_data.AddDrawItem( pin2 );
553 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 2 ).size() == 1 );
554
555 // Make pin 1 body style common to all units.
556 pin1->SetBodyStyle( 0 );
557 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
558 BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 1 ).size() == 1 );
559
560 m_part_no_data.RemoveDrawItem( pin2 );
561 m_part_no_data.RemoveDrawItem( pin1 );
562 m_part_no_data.RemoveDrawItem( &*m_part_no_data.GetDrawItems().begin() );
563}
564
565
569BOOST_AUTO_TEST_CASE( GetUnitDrawItems )
570{
571 // There are no unit draw items in the empty LIB_SYMBOL object.
572 BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 );
573
574 // A single unique unit with 1 pin common to all units and all body styles.
575 SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data );
576 pin1->SetNumber( "1" );
577 m_part_no_data.AddDrawItem( pin1 );
578 std::vector<struct LIB_SYMBOL_UNIT> units = m_part_no_data.GetUnitDrawItems();
579 BOOST_CHECK( units.size() == 1 );
580 BOOST_CHECK( units[0].m_unit == 0 );
581 BOOST_CHECK( units[0].m_bodyStyle == 0 );
582 BOOST_CHECK( units[0].m_items[0] == pin1 );
583}
584
585
590{
591 std::unique_ptr<LIB_SYMBOL> parent = std::make_unique<LIB_SYMBOL>( "parent" );
592 BOOST_CHECK( parent->IsRoot() );
593 BOOST_CHECK_EQUAL( parent->GetInheritanceDepth(), 0 );
594
595 std::unique_ptr<LIB_SYMBOL> ref = std::make_unique<LIB_SYMBOL>( *parent );
596
597 std::unique_ptr<LIB_SYMBOL> child = std::make_unique<LIB_SYMBOL>( "child", parent.get() );
598 BOOST_CHECK( child->IsAlias() );
599 BOOST_CHECK_EQUAL( child->GetInheritanceDepth(), 1 );
600
601 std::unique_ptr<LIB_SYMBOL> grandChild = std::make_unique<LIB_SYMBOL>( "grandchild",
602 child.get() );
603 BOOST_CHECK( grandChild->IsAlias() );
604 BOOST_CHECK_EQUAL( grandChild->GetInheritanceDepth(), 2 );
605
606 BOOST_CHECK( parent->GetRootSymbol().get() == parent.get() );
607 BOOST_CHECK( child->GetRootSymbol().get() == parent.get() );
608 BOOST_CHECK( grandChild->GetRootSymbol().get() == parent.get() );
609
610 LIB_SYMBOL_SPTR parentRef = child->GetParent().lock();
611 BOOST_CHECK( parentRef );
612 BOOST_CHECK( parentRef == parent->SharedPtr() );
613 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 3 );
614
615 LIB_SYMBOL_SPTR childRef = grandChild->GetParent().lock();
616 BOOST_CHECK( childRef );
617 BOOST_CHECK( childRef == child->SharedPtr() );
618 BOOST_CHECK_EQUAL( child->SharedPtr().use_count(), 3 );
619
620 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
621 parent->SetUnitCount( 4 );
622 BOOST_CHECK_EQUAL( child->GetUnitCount(), 4 );
623 parent->SetUnitCount( 1 );
624
625 parent->GetDatasheetField().SetText( "https://kicad/resistors.pdf" );
626 ref->GetDatasheetField().SetText( "https://kicad/resistors.pdf" );
627
628 BOOST_CHECK( *parent == *ref );
629
630 ref->SetName( "child" );
631 SCH_FIELD* field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
632 field->SetText( "KiCad" );
633 child->AddField( field );
634 field->SetParent( child.get() );
635
636 field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
637 field->SetText( "KiCad" );
638 ref->AddField( field );
639 field->SetParent( ref.get() );
640
641 BOOST_CHECK( *ref == *child->Flatten() );
642
643 ref->SetName( "grandchild" );
644 field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
645 field->SetText( "123456" );
646 grandChild->AddField( field );
647 field->SetParent( grandChild.get() );
648
649 field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
650 field->SetText( "123456" );
651 ref->AddField( field );
652 field->SetParent( ref.get() );
653
654 BOOST_CHECK( *ref == *grandChild->Flatten() );
655
656 BOOST_CHECK_EQUAL( grandChild->Flatten()->GetDatasheetField().GetText(),
657 "https://kicad/resistors.pdf" );
658
659 child->SetParent();
660 BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
661
662 parentRef.reset();
663 BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 2 );
664}
665
666
670BOOST_AUTO_TEST_CASE( CopyConstructor )
671{
672 std::shared_ptr<LIB_SYMBOL> copy = std::make_shared<LIB_SYMBOL>( m_part_no_data );
673 BOOST_CHECK( m_part_no_data == *copy.get() );
674}
675
676
681{
682 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( "power" );
683 SCH_PIN* pin = new SCH_PIN( symbol.get() );
684 pin->SetNumber( "1" );
686 pin->SetVisible( false );
687 symbol->AddDrawItem( pin );
688
689 BOOST_CHECK( !symbol->IsPower() );
690 BOOST_CHECK( symbol->IsNormal() );
691
692 symbol->SetPower();
693 BOOST_CHECK( symbol->IsPower() );
694 BOOST_CHECK( !symbol->IsNormal() );
695
696 // symbol->SetNormal();
697 // symbol->GetReferenceField().SetText( wxS( "#PWR" ) );
698 // BOOST_CHECK( symbol->IsPower() );
699
700 // Legacy power symbols are limited to a single pin.
701 // pin = new LIB_PIN( symbol.get() );
702 // pin->SetNumber( "2" );
703 // pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
704 // pin->SetVisible( false );
705 // symbol->AddDrawItem( pin );
706 // BOOST_CHECK( !symbol->IsPower() );
707}
708
709
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
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:110
Define a library symbol object.
Definition: lib_symbol.h:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
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:447
void SetPower()
Definition: lib_symbol.cpp:405
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
Definition: lib_symbol.h:258
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:499
void SetDescription(const wxString &aDescription)
Gets the Description field text value *‍/.
Definition: lib_symbol.h:152
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:169
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:783
void SetFPFilters(const wxArrayString &aFilters)
Definition: lib_symbol.h:204
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:144
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:808
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:288
void SetNormal()
Definition: lib_symbol.cpp:433
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1213
virtual void SetBodyStyle(int aBodyStyle)
Definition: sch_item.h:231
@ EQUALITY
Definition: sch_item.h:660
virtual void SetUnit(int aUnit)
Definition: sch_item.h:228
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:520
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: symbol.h:129
int GetPinNameOffset() const
Definition: symbol.h:118
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition: symbol.h:123
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
Definition: symbol.h:141
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition: symbol.h:117
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
Definition: symbol.h:147
TEST_LIB_SYMBOL_FIXTURE()
Part with no extra data set.
@ ARC
use RECTANGLE instead of RECT to avoid collision in a Windows header
@ LAYER_DEVICE
Definition: layer_ids.h:370
Test utils (e.g.
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:46
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.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ DESCRIPTION_FIELD
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_PIN_T
Definition: typeinfo.h:153