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