KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eagle_plugin.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) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Alejandro García Montoro <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
23
24#include <map>
25#include <set>
26
27#include <core/ignore.h>
28#include <kiway.h>
29#include <pgm_base.h>
30#include <lib_symbol.h>
31#include <sch_io/sch_io.h>
32#include <schematic.h>
33#include <sch_sheet.h>
34#include <sch_screen.h>
35#include <sch_symbol.h>
36#include <sch_pin.h>
37#include <sch_label.h>
38#include <sch_line.h>
39#include <sch_sheet_path.h>
42#include <wx/filename.h>
43#include <wx/stdpaths.h>
44#include <wx/utils.h>
46
51{
52 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
53 BOOST_CHECK_NE( pi.get(), nullptr );
54}
55
56
60static wxFileName getEagleTestSchematic( const wxString& sch_file )
61{
62 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
63 fn.AppendDir( "io" );
64 fn.AppendDir( "eagle" );
65 fn.SetFullName( sch_file );
66
67 return fn;
68}
69
70
79static SCH_SHEET* loadEagleSchematic( const wxFileName& aEagleFn,
80 const wxString& aProjectStem,
81 std::unique_ptr<SCHEMATIC>& aSchematic )
82{
83 // Stage the project in a private, freshly-emptied directory. The Eagle importer writes a
84 // "<stem>-eagle-import.kicad_sym" library plus a sym-lib-table into the project directory and
85 // keys duplicate-symbol-name disambiguation off the on-disk library, so leftover files from a
86 // previous run in the shared temp directory would make the imported symbol names
87 // non-deterministic.
88 wxString sep = wxFileName::GetPathSeparator();
89 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
90 + wxT( "-eagle-qa" );
91
92 if( wxDirExists( projectDir ) )
93 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
94
95 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
96
97 wxString projectPath = projectDir + sep + aProjectStem + wxT( ".kicad_pro" );
98
99 Pgm().GetSettingsManager().LoadProject( projectPath );
101 Pgm().GetLibraryManager().LoadProjectTables( project.GetProjectDirectory() );
102
103 aSchematic = std::make_unique<SCHEMATIC>( &project );
104 aSchematic->Reset();
105
106 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
107 BOOST_REQUIRE( pi.get() != nullptr );
108
109 SCH_SHEET* loadedSheet = nullptr;
110
111 try
112 {
113 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
114 }
115 catch( const std::exception& e )
116 {
117 BOOST_FAIL( std::string( "LoadSchematicFile threw: " ) + e.what() );
118 }
119 catch( ... )
120 {
121 BOOST_FAIL( "LoadSchematicFile threw unknown exception" );
122 }
123
124 BOOST_REQUIRE( loadedSheet != nullptr );
125 return loadedSheet;
126}
127
128
137BOOST_AUTO_TEST_CASE( ImportHierarchy )
138{
139 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
140 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
141
142 std::unique_ptr<SCHEMATIC> schematic;
143 SCH_SHEET* loadedSheet = loadEagleSchematic( eagleFn, wxS( "eagle_test" ), schematic );
144
145 // The returned sheet must be the virtual root (niluuid).
146 BOOST_CHECK( loadedSheet->m_Uuid == niluuid );
147
148 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
149
150 // The test file has exactly 2 Eagle pages; there must be no spurious default sheet.
151 BOOST_CHECK_EQUAL( topSheets.size(), 2 );
152
153 for( SCH_SHEET* sheet : topSheets )
154 {
155 // No top-level sheet should be the virtual root.
156 BOOST_CHECK( sheet != nullptr );
157 BOOST_CHECK( sheet->m_Uuid != niluuid );
158
159 // Every page must have a screen with a non-empty filename so SaveProject can
160 // write it to disk.
161 BOOST_REQUIRE( sheet->GetScreen() != nullptr );
162 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
163 }
164
165 // Verify the hierarchy paths match the symbol instance paths so PCB update works.
166 // Each symbol's hierarchical reference must have a path matching one of the top-level
167 // sheet paths in the hierarchy.
168 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
169 BOOST_CHECK_EQUAL( hierarchy.size(), 2 );
170
171 std::set<KIID_PATH> hierPaths;
172
173 for( const SCH_SHEET_PATH& path : hierarchy )
174 hierPaths.insert( path.Path() );
175
176 int totalSymbols = 0;
177 int orphanedSymbols = 0;
178
179 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
180 {
181 SCH_SCREEN* screen = sheetPath.LastScreen();
182
183 if( !screen )
184 continue;
185
186 for( const EDA_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
187 {
188 const SCH_SYMBOL* sym = static_cast<const SCH_SYMBOL*>( item );
189 ++totalSymbols;
190
191 bool foundMatch = false;
192
193 for( const SCH_SYMBOL_INSTANCE& inst : sym->GetInstances() )
194 {
195 if( hierPaths.count( inst.m_Path ) )
196 {
197 foundMatch = true;
198 break;
199 }
200 }
201
202 if( !foundMatch )
203 ++orphanedSymbols;
204 }
205 }
206
207 BOOST_CHECK_GT( totalSymbols, 0 );
208 BOOST_CHECK_EQUAL( orphanedSymbols, 0 );
209}
210
211
225BOOST_AUTO_TEST_CASE( LabelsRemainGlobalForFlatNamespace )
226{
227 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
228 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
229
230 std::unique_ptr<SCHEMATIC> schematic;
231 loadEagleSchematic( eagleFn, wxS( "eagle_label_kind" ), schematic );
232
233 // Bucket every label in the imported schematic by kind + text so we can verify that
234 // each named Eagle net produced a global label and no leftover local SCH_LABEL exists
235 // with that name. Bus labels (e.g. "A[1..3]") must stay local.
236 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
237
238 std::unordered_set<wxString> globalTexts;
239 std::unordered_set<wxString> localTexts;
240
241 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
242 {
243 SCH_SCREEN* screen = sheetPath.LastScreen();
244
245 if( !screen )
246 continue;
247
248 for( SCH_ITEM* item : screen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
249 globalTexts.insert( static_cast<SCH_LABEL_BASE*>( item )->GetText() );
250
251 for( SCH_ITEM* item : screen->Items().OfType( SCH_LABEL_T ) )
252 localTexts.insert( static_cast<SCH_LABEL_BASE*>( item )->GetText() );
253 }
254
255 // Named Eagle nets must produce at least one global label each, and none of these
256 // names may appear as a local SCH_LABEL — that would reintroduce the "/X" sheet-path
257 // prefix that broke board update.
258 const std::vector<wxString> expectedGlobalNets = {
259 wxS( "A1" ), wxS( "A2" ), wxS( "A3" ),
260 wxS( "B1" ), wxS( "B2" ), wxS( "B3" )
261 };
262
263 for( const wxString& netName : expectedGlobalNets )
264 {
265 BOOST_CHECK_MESSAGE( globalTexts.count( netName ) > 0,
266 "Missing global Eagle net label '" << netName.ToStdString()
267 << "' — flat namespace requires SCH_GLOBALLABEL." );
268 BOOST_CHECK_MESSAGE( localTexts.count( netName ) == 0,
269 "Found local SCH_LABEL '" << netName.ToStdString()
270 << "' — Eagle net should be global." );
271 }
272
273 // Bus labels (e.g. "A[1..3]") must stay local: Eagle buses are visual groupings, not
274 // electrical signals, so globalizing them would merge same-named buses project-wide.
275 const std::vector<wxString> expectedLocalBuses = {
276 wxS( "A[1..3]" ), wxS( "B[1..3]" )
277 };
278
279 for( const wxString& busName : expectedLocalBuses )
280 {
281 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
282 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
283 << "' — Eagle bus should remain a local SCH_LABEL." );
284 }
285}
286
287
298BOOST_AUTO_TEST_CASE( PinNameTagStripped )
299{
300 const wxFileName eagleFn = getEagleTestSchematic( "issue24483_pin_tag.sch" );
301 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
302
303 std::unique_ptr<SCHEMATIC> schematic;
304 loadEagleSchematic( eagleFn, wxS( "eagle_pin_tag" ), schematic );
305
306 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
307
308 // Key symbols by their library item name (e.g. "MYDEV"); the annotated reference is
309 // unreliable here because the no-connect device is annotated with a '#' power prefix. A
310 // single Eagle library imports without a library-name prefix on the symbol; the prefix is
311 // only added to disambiguate duplicate names across multiple Eagle libraries.
312 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
313
314 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
315 {
316 SCH_SCREEN* screen = sheetPath.LastScreen();
317
318 if( !screen )
319 continue;
320
321 for( const EDA_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
322 {
323 const SCH_SYMBOL* sym = static_cast<const SCH_SYMBOL*>( item );
324 symbolByLibItem[sym->GetLibId().GetLibItemName().wx_str()] = sym;
325 }
326 }
327
328 // The connected device maps pins to pads through <connect>; the no-connect device has no
329 // <connect> so pins are auto-numbered. Both paths must strip the tag from the display name.
330 BOOST_REQUIRE( symbolByLibItem.count( wxS( "MYDEV" ) ) == 1 );
331 BOOST_REQUIRE( symbolByLibItem.count( wxS( "MYDEV_NC" ) ) == 1 );
332
333 auto collectNames = []( const SCH_SYMBOL* aSym )
334 {
335 std::multiset<wxString> names;
336
337 for( const SCH_PIN* pin : aSym->GetAllLibPins() )
338 names.insert( pin->GetName() );
339
340 return names;
341 };
342
343 // No display name on either symbol may retain the "@<tag>" suffix.
344 for( const auto& [libItem, sym] : symbolByLibItem )
345 {
346 for( const SCH_PIN* pin : sym->GetAllLibPins() )
347 {
348 BOOST_CHECK_MESSAGE( pin->GetName().Find( '@' ) == wxNOT_FOUND,
349 libItem.ToStdString() << " pin kept Eagle tag '"
350 << pin->GetName().ToStdString() << "'." );
351 }
352 }
353
354 // For the connected device, the two "IN@n" pins must both display as "IN" yet keep their
355 // distinct pad mapping, and "NC@3" must strip to "NC".
356 std::map<wxString, wxString> nameByPad;
357
358 for( const SCH_PIN* pin : symbolByLibItem[wxS( "MYDEV" )]->GetAllLibPins() )
359 nameByPad[pin->GetNumber()] = pin->GetName();
360
361 BOOST_CHECK_EQUAL( nameByPad["1"], wxString( wxS( "IN" ) ) );
362 BOOST_CHECK_EQUAL( nameByPad["2"], wxString( wxS( "IN" ) ) );
363 BOOST_CHECK_EQUAL( nameByPad["3"], wxString( wxS( "GND" ) ) );
364 BOOST_CHECK_EQUAL( nameByPad["4"], wxString( wxS( "NC" ) ) );
365
366 // The no-connect device keeps every pin, so both tagged "IN" pins survive the strip.
367 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS( "MYDEV_NC" )] );
368 BOOST_CHECK_EQUAL( ncNames.count( wxS( "IN" ) ), 2 );
369 BOOST_CHECK_EQUAL( ncNames.count( wxS( "GND" ) ), 1 );
370 BOOST_CHECK_EQUAL( ncNames.count( wxS( "NC" ) ), 1 );
371}
372
373
385BOOST_AUTO_TEST_CASE( DetachedLabelProjectsOntoWire )
386{
387 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
388 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
389
390 std::unique_ptr<SCHEMATIC> schematic;
391 loadEagleSchematic( eagleFn, wxS( "eagle_detached_label" ), schematic );
392
393 SCH_LABEL_BASE* detached = nullptr;
394 SCH_SCREEN* screen = nullptr;
395
396 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
397 {
398 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
399
400 if( !sheetScreen )
401 continue;
402
403 for( SCH_ITEM* item : sheetScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
404 {
405 if( static_cast<SCH_LABEL_BASE*>( item )->GetText() == wxS( "DETACHEDLABEL" ) )
406 {
407 detached = static_cast<SCH_LABEL_BASE*>( item );
408 screen = sheetScreen;
409 }
410 }
411 }
412
413 BOOST_REQUIRE_MESSAGE( detached, "DETACHEDLABEL global label not imported" );
414
415 // Positions carry an import-time sheet translation, so all checks are made relative to
416 // the wire's own endpoints.
417 const VECTOR2I labelPos = detached->GetPosition();
418 SEG wire;
419 double wireDist = std::numeric_limits<double>::max();
420
421 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
422 {
423 SCH_LINE* line = static_cast<SCH_LINE*>( item );
424
425 if( !line->IsWire() )
426 continue;
427
428 SEG seg( line->GetStartPoint(), line->GetEndPoint() );
429 double d = seg.Distance( labelPos );
430
431 if( d < wireDist )
432 {
433 wireDist = d;
434 wire = seg;
435 }
436 }
437
438 // The label must be on the wire.
439 BOOST_CHECK_MESSAGE( wireDist <= schIUScale.MilsToIU( 1 ),
440 "Label is " << ( wireDist / schIUScale.IU_PER_MM )
441 << " mm from its wire" );
442
443 // The wire is 40 mm long and the label sat 10 mm from the left end. Perpendicular
444 // projection preserves that; the old endpoint/midpoint snap would put it at 0 mm
445 // (endpoint) or 20 mm (midpoint) from the left end.
446 const VECTOR2I leftEnd = wire.A.x <= wire.B.x ? wire.A : wire.B;
447 const double offsetMM = std::abs( labelPos.x - leftEnd.x ) / (double) schIUScale.IU_PER_MM;
448
449 BOOST_CHECK_MESSAGE( std::abs( offsetMM - 10.0 ) < 1.0,
450 "Label projected to " << offsetMM
451 << " mm from the wire's left end, expected 10 mm" );
452}
453
454
455// issue 24829 dropped net labels under the raw netbuslabel element name
456// and lost symbols whose variant ordinal above 127 sign-extended negative
457BOOST_AUTO_TEST_CASE( BinaryNetLabelAndHighVariantImported )
458{
459 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
460 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
461
462 std::unique_ptr<SCHEMATIC> schematic;
463 loadEagleSchematic( eagleFn, wxS( "eagle_brenner_24829" ), schematic );
464
465 int symbolCount = 0;
466 SCH_SYMBOL* c4 = nullptr;
467 SCH_LABEL_BASE* netLabel = nullptr;
468
469 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
470 {
471 SCH_SCREEN* screen = sheetPath.LastScreen();
472
473 if( !screen )
474 continue;
475
476 for( SCH_ITEM* item : screen->Items() )
477 {
478 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T
479 || item->Type() == SCH_HIER_LABEL_T )
480 {
481 netLabel = static_cast<SCH_LABEL_BASE*>( item );
482 }
483 else if( item->Type() == SCH_SYMBOL_T )
484 {
485 ++symbolCount;
486 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
487
488 if( sym->GetField( FIELD_T::REFERENCE )->GetText() == wxS( "C4" ) )
489 c4 = sym;
490 }
491 }
492 }
493
494 // single placed net label on VSS, previously dropped entirely
495 BOOST_REQUIRE_MESSAGE( netLabel, "placed net label was not imported" );
496 BOOST_CHECK_EQUAL( netLabel->GetText(), wxS( "VSS" ) );
497
498 // 36 placed instances, C4 is CPOL-EU with variant ordinal 131
499 BOOST_CHECK_EQUAL( symbolCount, 36 );
500 BOOST_REQUIRE_MESSAGE( c4, "CPOL-EU symbol C4 (variant ordinal 131) was not imported" );
501 BOOST_CHECK( c4->GetLibSymbolRef() != nullptr );
502}
503
504
509BOOST_AUTO_TEST_CASE( LibrarySymbolFieldsKeepTheirText )
510{
511 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
512 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
513
514 std::unique_ptr<SCHEMATIC> schematic;
515 loadEagleSchematic( eagleFn, wxS( "eagle_field_text" ), schematic );
516
517 std::map<wxString, LIB_SYMBOL*> libSymbolByRef;
518
519 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
520 {
521 SCH_SCREEN* screen = sheetPath.LastScreen();
522
523 if( !screen )
524 continue;
525
526 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
527 {
528 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
529
530 if( sym->GetLibSymbolRef() )
531 libSymbolByRef[sym->GetField( FIELD_T::REFERENCE )->GetText()] = sym->GetLibSymbolRef().get();
532 }
533 }
534
535 BOOST_REQUIRE_GT( libSymbolByRef.size(), 0 );
536
537 int prefixCount = 0;
538
539 for( const auto& [ref, libSymbol] : libSymbolByRef )
540 {
541 const wxString libRef = libSymbol->GetReferenceField().GetText();
542 const wxString libValue = libSymbol->GetValueField().GetText();
543
544 BOOST_CHECK_MESSAGE( !libRef.Contains( wxS( "${" ) ),
545 ref.ToStdString() << " library reference prefix is '"
546 << libRef.ToStdString() << "'" );
547 BOOST_CHECK_MESSAGE( !libValue.Contains( wxS( "${" ) ),
548 ref.ToStdString() << " library value is '"
549 << libValue.ToStdString() << "'" );
550
551 // A deviceset can declare no prefix, which correctly leaves the field empty
552 if( libRef.IsEmpty() )
553 continue;
554
555 // Eagle names each part from the deviceset prefix and a number
556 wxString expectedPrefix = ref;
557
558 while( !expectedPrefix.IsEmpty() && wxIsdigit( expectedPrefix.Last() ) )
559 expectedPrefix.RemoveLast();
560
561 BOOST_CHECK_MESSAGE( libRef == expectedPrefix,
562 ref.ToStdString() << " library reference prefix is '"
563 << libRef.ToStdString() << "', expected '"
564 << expectedPrefix.ToStdString() << "'" );
565
566 ++prefixCount;
567 }
568
569 // Keep the prefix check from becoming vacuous if the fields come back empty
570 BOOST_CHECK_GT( prefixCount, 30 );
571}
572
573
574// A binary schematic's free-text blob can pass 32 KiB, and losing it drops every package name
575BOOST_AUTO_TEST_CASE( BinaryLargeFreeTextKeepsPackages )
576{
577 wxString corpus;
578
579 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
580 {
581 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
582 return;
583 }
584
585 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-MICRO/2. Older hardware "
586 "revisions/Hardware revision L1/T2-OLINUXINO-MICRO_Rev_L1.sch" ) );
587
588 if( !eagleFn.FileExists() )
589 {
590 BOOST_TEST_MESSAGE( "T2-OLINUXINO-MICRO_Rev_L1.sch is not in KICAD_IMPORT_CORPUS" );
591 return;
592 }
593
594 std::unique_ptr<SCHEMATIC> schematic;
595 loadEagleSchematic( eagleFn, wxS( "eagle_large_free_text" ), schematic );
596
597 SCH_SYMBOL* c1 = nullptr;
598
599 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
600 {
601 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
602 {
603 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
604
605 if( sym->GetField( FIELD_T::REFERENCE )->GetText() == wxS( "C1" ) )
606 c1 = sym;
607 }
608 }
609
610 BOOST_REQUIRE( c1 );
611 BOOST_CHECK( !c1->GetField( FIELD_T::FOOTPRINT )->GetText().IsEmpty() );
612}
613
614
615BOOST_AUTO_TEST_CASE( BinaryBusNamesKeepLongStringsAligned )
616{
617 wxString corpus;
618
619 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
620 {
621 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
622 return;
623 }
624
625 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
626 "revisions/A20-OLinuXino-LIME2 hardware revision G2/"
627 "A20-OLinuXino-Lime2_Rev_G2.sch" ) );
628
629 if( !eagleFn.FileExists() )
630 {
631 BOOST_TEST_MESSAGE( "A20-OLinuXino-Lime2_Rev_G2.sch is not in KICAD_IMPORT_CORPUS" );
632 return;
633 }
634
635 std::unique_ptr<SCHEMATIC> schematic;
636 loadEagleSchematic( eagleFn, wxS( "eagle_bus_names" ), schematic );
637
638 int symbols = 0;
639
640 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
641 {
642 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
643 {
644 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
645
646 // Missing bus names shift the strings so GND supplies take a capacitor value
647 BOOST_CHECK_MESSAGE( !sym->GetField( FIELD_T::REFERENCE )->GetText().Contains( wxS( "22uF" ) ),
649 symbols++;
650 }
651 }
652
653 BOOST_CHECK_GT( symbols, 0 );
654}
655
656
657BOOST_AUTO_TEST_CASE( BinaryLongStringsFollowRecordOrder )
658{
659 wxString corpus;
660
661 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
662 {
663 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
664 return;
665 }
666
667 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
668 "revisions/A20-OLinuXino-LIME2 hardware revision K2/"
669 "A20-OLinuXino-Lime2_Rev_K2.sch" ) );
670
671 if( !eagleFn.FileExists() )
672 {
673 BOOST_TEST_MESSAGE( "A20-OLinuXino-Lime2_Rev_K2.sch is not in KICAD_IMPORT_CORPUS" );
674 return;
675 }
676
677 std::unique_ptr<SCHEMATIC> schematic;
678 loadEagleSchematic( eagleFn, wxS( "eagle_long_string_order" ), schematic );
679
680 SCH_SYMBOL* led = nullptr;
681
682 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
683 {
684 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
685 {
686 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
687
688 if( sym->GetField( FIELD_T::VALUE )->GetText() == wxS( "LED/RED/0603" ) )
689 led = sym;
690 }
691 }
692
693 // The blob holds a part's long value before its long name
694 BOOST_REQUIRE( led );
695 BOOST_CHECK( led->GetField( FIELD_T::REFERENCE )->GetText().StartsWith( wxS( "PWR_LED" ) ) );
696}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:125
Container for project specific data.
Definition project.h:63
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
Definition sch_line.h:145
VECTOR2I GetStartPoint() const
Definition sch_line.h:136
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
Schematic symbol object.
Definition sch_symbol.h:75
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:135
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:165
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
Definition sch_text.h:143
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition seg.cpp:668
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
wxString wx_str() const
Definition utf8.cpp:41
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
KIID niluuid(0)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
A simple container for schematic symbol instance information.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(FindPlugin)
Checks that the SCH_IO manager finds the Eagle plugin.
static wxFileName getEagleTestSchematic(const wxString &sch_file)
Get a schematic file from the test data eagle subdir.
static SCH_SHEET * loadEagleSchematic(const wxFileName &aEagleFn, const wxString &aProjectStem, std::unique_ptr< SCHEMATIC > &aSchematic)
Common Eagle-import scaffolding: stage a fresh project under tempDir, configure the library manager,...
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
KIBIS_PIN * pin
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
Definition of file extensions used in Kicad.