KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sprint_layout_import.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
23
26
27#include <set>
28
29#include <board.h>
30#include <footprint.h>
31#include <pad.h>
32#include <pcb_shape.h>
33#include <geometry/seg.h>
34#include <pcb_track.h>
35#include <netinfo.h>
36#include <zone.h>
37
38
45
46
47BOOST_FIXTURE_TEST_SUITE( SprintLayoutImport, SPRINT_LAYOUT_IMPORT_FIXTURE )
48
49
50// ============================================================================
51// File discrimination tests
52// ============================================================================
53
54BOOST_AUTO_TEST_CASE( CanReadLay6File )
55{
56 std::string path = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
57 BOOST_CHECK( m_plugin.CanReadBoard( path ) );
58}
59
60
61BOOST_AUTO_TEST_CASE( RejectsNonSprintLayoutFile )
62{
63 std::string kicadPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/geda/minimal_test.pcb";
64 BOOST_CHECK( !m_plugin.CanReadBoard( kicadPath ) );
65}
66
67
68BOOST_AUTO_TEST_CASE( RejectsNonExistentFile )
69{
70 BOOST_CHECK( !m_plugin.CanReadBoard( wxT( "/nonexistent/path/file.lay6" ) ) );
71}
72
73
74// ============================================================================
75// Basic board loading tests
76// ============================================================================
77
78BOOST_AUTO_TEST_CASE( Gpio2nescBoardLoad )
79{
80 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
81
82 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
83
84 BOOST_REQUIRE( board );
85 BOOST_CHECK( board->Footprints().size() > 0 );
86}
87
88
89BOOST_AUTO_TEST_CASE( ReedDoorbellBoardLoad )
90{
91 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
92 + "/plugins/sprint_layout/cacazi-a8-zigbee_cr2032_1.2mm.lay6";
93
94 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
95
96 BOOST_REQUIRE( board );
97 BOOST_CHECK( board->Footprints().size() > 0 );
98}
99
100
101BOOST_AUTO_TEST_CASE( MdbRs232BoardLoad )
102{
103 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
104 + "/plugins/sprint_layout/mdb-rs232.lay6";
105
106 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
107
108 BOOST_REQUIRE( board );
109 BOOST_CHECK( board->Footprints().size() > 0 );
110}
111
112
113BOOST_AUTO_TEST_CASE( LoadBoardAppendToExisting )
114{
115 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
116
117 // Load first into a fresh board
118 std::unique_ptr<BOARD> baseBoard = m_plugin.LoadBoard( dataPath );
119
120 BOOST_REQUIRE( baseBoard );
121
122 size_t originalFootprints = baseBoard->Footprints().size();
123 size_t originalDrawings = baseBoard->Drawings().size();
124
125 BOOST_REQUIRE( originalFootprints > 0 );
126
127 // Load again, appending into the existing board
128 PCB_IO_SPRINT_LAYOUT plugin2;
129 plugin2.LoadAndAppendBoard( dataPath, *baseBoard );
130
131 BOOST_CHECK( baseBoard->Footprints().size() >= originalFootprints * 2 );
132 BOOST_CHECK( baseBoard->Drawings().size() >= originalDrawings * 2 );
133}
134
135
136// ============================================================================
137// Board outline tests
138// ============================================================================
139
140BOOST_AUTO_TEST_CASE( BoardHasOutline )
141{
142 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
143
144 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
145
146 BOOST_REQUIRE( board );
147
148 int edgeCutsCount = 0;
149
150 for( BOARD_ITEM* item : board->Drawings() )
151 {
152 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
153
154 if( shape && shape->GetLayer() == Edge_Cuts )
155 edgeCutsCount++;
156 }
157
158 BOOST_CHECK_MESSAGE( edgeCutsCount > 0, "Board should have Edge.Cuts outline shapes" );
159}
160
161
162// ============================================================================
163// Pad tests
164// ============================================================================
165
166BOOST_AUTO_TEST_CASE( PadsInsideBoardOutline )
167{
168 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
169
170 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
171
172 BOOST_REQUIRE( board );
173
174 // Get the board bounding box from Edge.Cuts shapes
175 BOX2I boardBox;
176 bool first = true;
177
178 for( BOARD_ITEM* item : board->Drawings() )
179 {
180 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
181
182 if( !shape || shape->GetLayer() != Edge_Cuts )
183 continue;
184
185 BOX2I shapeBox = shape->GetBoundingBox();
186
187 if( first )
188 {
189 boardBox = shapeBox;
190 first = false;
191 }
192 else
193 {
194 boardBox.Merge( shapeBox );
195 }
196 }
197
198 if( first )
199 {
200 BOOST_TEST_MESSAGE( "No Edge.Cuts found, skipping pad containment test" );
201 return;
202 }
203
204 // Expand for tolerance -- edge connector pads can extend past the board boundary
205 boardBox.Inflate( pcbIUScale.mmToIU( 2.0 ) );
206
207 int outsideCount = 0;
208
209 for( FOOTPRINT* fp : board->Footprints() )
210 {
211 for( PAD* pad : fp->Pads() )
212 {
213 if( !boardBox.Contains( pad->GetPosition() ) )
214 outsideCount++;
215 }
216 }
217
218 BOOST_CHECK_MESSAGE( outsideCount == 0,
219 wxString::Format( "%d pads found outside board outline", outsideCount ) );
220}
221
222
223// ============================================================================
224// Component and layer tests
225// ============================================================================
226
227BOOST_AUTO_TEST_CASE( BoardHasCopperLayers )
228{
229 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
230
231 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
232
233 BOOST_REQUIRE( board );
234 BOOST_CHECK( board->GetCopperLayerCount() >= 2 );
235}
236
237
238BOOST_AUTO_TEST_CASE( CachedLibraryFootprints )
239{
240 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
241
242 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
243
244 BOOST_REQUIRE( board );
245
246 std::vector<FOOTPRINT*> cached = m_plugin.GetImportedCachedLibraryFootprints();
247
248 // We should have at least some cached footprints
249 BOOST_CHECK( cached.size() > 0 );
250
251 for( FOOTPRINT* fp : cached )
252 delete fp;
253}
254
255
256BOOST_AUTO_TEST_CASE( PadsHaveAttributes )
257{
258 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
259
260 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
261
262 BOOST_REQUIRE( board );
263
264 int thtCount = 0;
265 int smdCount = 0;
266
267 for( FOOTPRINT* fp : board->Footprints() )
268 {
269 for( PAD* pad : fp->Pads() )
270 {
271 if( pad->GetAttribute() == PAD_ATTRIB::PTH )
272 thtCount++;
273 else if( pad->GetAttribute() == PAD_ATTRIB::SMD )
274 smdCount++;
275 }
276 }
277
278 // This board should have at least some through-hole pads
279 BOOST_CHECK_MESSAGE( thtCount > 0 || smdCount > 0,
280 "Board should have at least some pads" );
281}
282
283
284// ============================================================================
285// Format-specific feature tests
286// ============================================================================
287
288BOOST_AUTO_TEST_CASE( PadPositionsHavePositiveY )
289{
290 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
291
292 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
293
294 BOOST_REQUIRE( board );
295
296 // After Y-flip conversion, all pads should have non-negative Y coordinates
297 int negativeCount = 0;
298
299 for( FOOTPRINT* fp : board->Footprints() )
300 {
301 for( PAD* pad : fp->Pads() )
302 {
303 if( pad->GetPosition().y < 0 )
304 negativeCount++;
305 }
306 }
307
308 BOOST_CHECK_MESSAGE( negativeCount == 0,
309 wxString::Format( "%d pads have negative Y (Y-flip error)", negativeCount ) );
310}
311
312
313BOOST_AUTO_TEST_CASE( DrawingsExistOnCopperAndSilk )
314{
315 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/gpio2nesc.lay6";
316
317 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
318
319 BOOST_REQUIRE( board );
320
321 int copperDrawings = 0;
322 int silkDrawings = 0;
323
324 for( BOARD_ITEM* item : board->Drawings() )
325 {
326 PCB_LAYER_ID layer = item->GetLayer();
327
328 if( layer == F_Cu || layer == B_Cu || layer == In1_Cu || layer == In2_Cu )
329 copperDrawings++;
330 else if( layer == F_SilkS || layer == B_SilkS )
331 silkDrawings++;
332 }
333
334 BOOST_CHECK_MESSAGE( copperDrawings > 0 || silkDrawings > 0,
335 "Board should have drawings on copper or silkscreen layers" );
336}
337
338
339// ============================================================================
340// Multi-file consistency
341// ============================================================================
342
343BOOST_AUTO_TEST_CASE( AllTestFilesLoadWithoutCrash )
344{
345 std::vector<std::string> files = {
346 "/plugins/sprint_layout/gpio2nesc.lay6",
347 "/plugins/sprint_layout/cacazi-a8-zigbee_cr2032_1.2mm.lay6",
348 "/plugins/sprint_layout/mdb-rs232.lay6",
349 "/plugins/sprint_layout/mdb-master-rev2a.lay6",
350 "/plugins/sprint_layout/smalldualrgb-withmask.lay6",
351 "/plugins/sprint_layout/amiga2000-remake.lay6",
352 "/plugins/sprint_layout/karpaty-rx-pcb1-bpf-orig.lay6",
353 "/plugins/sprint_layout/karpaty-rx-pcb2-rfamp-1st-mixer-orig.lay6",
354 "/plugins/sprint_layout/karpaty-rx-pcb3-vfo-orig.lay6",
355 "/plugins/sprint_layout/karpaty-rx-pcb5-buffer-freq-doubler-orig.lay6",
356 "/plugins/sprint_layout/karpaty-rx-pcb6-mainboard-orig.lay6",
357 "/plugins/sprint_layout/karpaty-rx-pcb7-power-supply-orig.lay6",
358 "/plugins/sprint_layout/ku14194revb.lay6",
359 "/plugins/sprint_layout/pcb100x40_v5.lay6",
360 "/plugins/sprint_layout/tfcc.lay6",
361 "/plugins/sprint_layout/12F629_SM.lay6",
362 };
363
364 for( const auto& file : files )
365 {
366 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + file;
367
368 BOOST_TEST_CONTEXT( "Loading " << file )
369 {
370 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
371 BOOST_CHECK( board != nullptr );
372 }
373 }
374}
375
376
377// Outline edges drawn more than once must come out once, or DRC calls the outline malformed
378BOOST_AUTO_TEST_CASE( OutlineEdgesAreNotRepeated )
379{
380 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/karpaty-rx-pcb6-mainboard-orig.lay6";
381
382 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
383
384 BOOST_REQUIRE( board );
385
386 std::set<SEG> edges;
387
388 for( BOARD_ITEM* item : board->Drawings() )
389 {
390 if( item->GetLayer() != Edge_Cuts || item->Type() != PCB_SHAPE_T )
391 continue;
392
393 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
394
395 SEG edge( shape->GetStart(), shape->GetEnd() );
396
397 // either direction of an edge is the same edge
398 BOOST_CHECK( edges.insert( std::min( edge, edge.Reversed() ) ).second );
399 }
400}
401
402
403// A board without ground planes must not gain a zone that has no layer
404BOOST_AUTO_TEST_CASE( ZonesHaveLayers )
405{
406 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "/plugins/sprint_layout/tfcc.lay6";
407
408 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
409
410 BOOST_REQUIRE( board );
411
412 for( ZONE* zone : board->Zones() )
413 BOOST_CHECK( zone->GetFirstLayer() != UNDEFINED_LAYER );
414}
415
416
417// ============================================================================
418// Complex board tests
419// ============================================================================
420
421BOOST_AUTO_TEST_CASE( MmJoy2BoardLoad )
422{
423 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
424 + "/plugins/sprint_layout/mmjoy2-74hc165.lay6";
425
426 std::map<std::string, UTF8> props;
427 props["pcb_id"] = "0";
428
429 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath, &props );
430
431 BOOST_REQUIRE( board );
432 BOOST_CHECK( board->Footprints().size() > 0 );
433
434 int padCount = 0;
435
436 for( FOOTPRINT* fp : board->Footprints() )
437 padCount += static_cast<int>( fp->Pads().size() );
438
439 BOOST_CHECK_MESSAGE( padCount > 0, "MMJoy2 board should have pads" );
440}
441
442
443BOOST_AUTO_TEST_CASE( SmallDualRgbBoardLoad )
444{
445 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
446 + "/plugins/sprint_layout/smalldualrgb-withmask.lay6";
447
448 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
449
450 BOOST_REQUIRE( board );
451 BOOST_CHECK( board->Footprints().size() > 0 );
452}
453
454
455BOOST_AUTO_TEST_CASE( MdbMasterRev2aBoardLoad )
456{
457 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
458 + "/plugins/sprint_layout/mdb-master-rev2a.lay6";
459
460 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
461
462 BOOST_REQUIRE( board );
463 BOOST_CHECK( board->Footprints().size() > 0 );
464 BOOST_CHECK( board->GetCopperLayerCount() >= 2 );
465}
466
467
468// ============================================================================
469// Karpaty-RX HAM receiver boards (6-board set from github.com/UT8IFG/karpaty-rx)
470// ============================================================================
471
472BOOST_AUTO_TEST_CASE( KarpatyBpfBoardLoad )
473{
474 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
475 + "/plugins/sprint_layout/karpaty-rx-pcb1-bpf-orig.lay6";
476
477 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
478
479 BOOST_REQUIRE( board );
480 BOOST_CHECK( board->Footprints().size() > 0 );
481}
482
483
484BOOST_AUTO_TEST_CASE( KarpatyRfAmpBoardLoad )
485{
486 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
487 + "/plugins/sprint_layout/karpaty-rx-pcb2-rfamp-1st-mixer-orig.lay6";
488
489 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
490
491 BOOST_REQUIRE( board );
492 BOOST_CHECK( board->Footprints().size() > 0 );
493}
494
495
496BOOST_AUTO_TEST_CASE( KarpatyVfoBoardLoad )
497{
498 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
499 + "/plugins/sprint_layout/karpaty-rx-pcb3-vfo-orig.lay6";
500
501 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
502
503 BOOST_REQUIRE( board );
504 BOOST_CHECK( board->Footprints().size() > 0 );
505}
506
507
508BOOST_AUTO_TEST_CASE( KarpatyBufferBoardLoad )
509{
510 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
511 + "/plugins/sprint_layout/karpaty-rx-pcb5-buffer-freq-doubler-orig.lay6";
512
513 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
514
515 BOOST_REQUIRE( board );
516 BOOST_CHECK( board->Footprints().size() > 0 );
517}
518
519
520BOOST_AUTO_TEST_CASE( KarpatyMainboardBoardLoad )
521{
522 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
523 + "/plugins/sprint_layout/karpaty-rx-pcb6-mainboard-orig.lay6";
524
525 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
526
527 BOOST_REQUIRE( board );
528 BOOST_CHECK( board->Footprints().size() > 0 );
529}
530
531
532BOOST_AUTO_TEST_CASE( KarpatyPowerSupplyBoardLoad )
533{
534 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
535 + "/plugins/sprint_layout/karpaty-rx-pcb7-power-supply-orig.lay6";
536
537 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
538
539 BOOST_REQUIRE( board );
540 BOOST_CHECK( board->Footprints().size() > 0 );
541}
542
543
544// ============================================================================
545// Additional real-world boards
546// ============================================================================
547
548BOOST_AUTO_TEST_CASE( Ku14194RevBBoardLoad )
549{
550 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
551 + "/plugins/sprint_layout/ku14194revb.lay6";
552
553 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
554
555 BOOST_REQUIRE( board );
556 BOOST_CHECK( board->Footprints().size() > 0 );
557}
558
559
560BOOST_AUTO_TEST_CASE( AntennaSwitchBoardLoad )
561{
562 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
563 + "/plugins/sprint_layout/pcb100x40_v5.lay6";
564
565 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
566
567 BOOST_REQUIRE( board );
568 BOOST_CHECK( board->Footprints().size() > 0 );
569}
570
571
572BOOST_AUTO_TEST_CASE( TfccBoardLoad )
573{
574 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
575 + "/plugins/sprint_layout/tfcc.lay6";
576
577 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
578
579 BOOST_REQUIRE( board );
580 BOOST_CHECK( board->Footprints().size() > 0 );
581}
582
583
584// ============================================================================
585// Large board stress test (Amiga 2000 -- full motherboard recreation, ~4.3MB)
586// ============================================================================
587
588BOOST_AUTO_TEST_CASE( Amiga2000BoardLoad )
589{
590 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
591 + "/plugins/sprint_layout/amiga2000-remake.lay6";
592
593 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
594
595 BOOST_REQUIRE( board );
596
597 BOOST_CHECK_MESSAGE( board->Footprints().size() > 50,
598 wxString::Format( "Amiga 2000 should have many footprints, got %zu",
599 board->Footprints().size() ) );
600
601 BOOST_CHECK( board->GetCopperLayerCount() >= 2 );
602}
603
604
605// ============================================================================
606// Cross-board consistency checks
607// ============================================================================
608
609BOOST_AUTO_TEST_CASE( AllBoardsHaveConsistentPadCoordinates )
610{
611 std::vector<std::string> files = {
612 "/plugins/sprint_layout/gpio2nesc.lay6",
613 "/plugins/sprint_layout/mdb-rs232.lay6",
614 "/plugins/sprint_layout/mdb-master-rev2a.lay6",
615 "/plugins/sprint_layout/smalldualrgb-withmask.lay6",
616 "/plugins/sprint_layout/amiga2000-remake.lay6",
617 "/plugins/sprint_layout/karpaty-rx-pcb1-bpf-orig.lay6",
618 "/plugins/sprint_layout/karpaty-rx-pcb2-rfamp-1st-mixer-orig.lay6",
619 "/plugins/sprint_layout/karpaty-rx-pcb3-vfo-orig.lay6",
620 "/plugins/sprint_layout/karpaty-rx-pcb5-buffer-freq-doubler-orig.lay6",
621 "/plugins/sprint_layout/karpaty-rx-pcb6-mainboard-orig.lay6",
622 "/plugins/sprint_layout/karpaty-rx-pcb7-power-supply-orig.lay6",
623 "/plugins/sprint_layout/ku14194revb.lay6",
624 "/plugins/sprint_layout/pcb100x40_v5.lay6",
625 "/plugins/sprint_layout/tfcc.lay6",
626 "/plugins/sprint_layout/12F629_SM.lay6",
627 };
628
629 for( const auto& file : files )
630 {
631 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + file;
632
633 BOOST_TEST_CONTEXT( "Checking coordinate consistency in " << file )
634 {
635 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
636
637 BOOST_REQUIRE( board );
638
639 // All pad coordinates should be finite and within a reasonable range
640 // (no overflow, no NaN from bad float conversion)
641 const int MAX_COORD = pcbIUScale.mmToIU( 1000.0 );
642 int badCount = 0;
643
644 for( FOOTPRINT* fp : board->Footprints() )
645 {
646 for( PAD* pad : fp->Pads() )
647 {
648 VECTOR2I pos = pad->GetPosition();
649
650 if( std::abs( pos.x ) > MAX_COORD || std::abs( pos.y ) > MAX_COORD )
651 badCount++;
652 }
653 }
654
655 BOOST_CHECK_MESSAGE( badCount == 0,
656 wxString::Format( "%d pads have coordinates outside +-10m in %s",
657 badCount, wxString::FromUTF8( file ) ) );
658 }
659 }
660}
661
662
663// ============================================================================
664// Multi-board selection tests
665// ============================================================================
666
667BOOST_AUTO_TEST_CASE( MultiBoardFileHasFiveBoards )
668{
669 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
670 + "/plugins/sprint_layout/mmjoy2-74hc165.lay6";
671
673 BOOST_REQUIRE( parser.ParseBoard( dataPath ) );
674
675 const auto& fileData = parser.GetFileData();
676 BOOST_CHECK_EQUAL( fileData.boards.size(), 5 );
677}
678
679
680BOOST_AUTO_TEST_CASE( MultiBoardSelectByIndex )
681{
682 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
683 + "/plugins/sprint_layout/mmjoy2-74hc165.lay6";
684
686 BOOST_REQUIRE( parser.ParseBoard( dataPath ) );
687
688 const auto& fileData = parser.GetFileData();
689 BOOST_REQUIRE( fileData.boards.size() == 5 );
690
691 for( size_t i = 0; i < fileData.boards.size(); i++ )
692 {
693 BOOST_TEST_CONTEXT( "Board index " << i )
694 {
695 std::map<std::string, UTF8> props;
696 props["pcb_id"] = std::to_string( i );
697
699 std::unique_ptr<BOARD> board = plugin.LoadBoard( dataPath, &props );
700
701 BOOST_REQUIRE( board );
702 }
703 }
704}
705
706
707BOOST_AUTO_TEST_CASE( MultiBoardCallbackInvoked )
708{
709 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
710 + "/plugins/sprint_layout/mmjoy2-74hc165.lay6";
711
713 bool callbackInvoked = false;
714 size_t optionCount = 0;
715
716 plugin.RegisterCallback(
717 [&]( const std::vector<IMPORT_PROJECT_DESC>& aOptions )
718 {
719 callbackInvoked = true;
720 optionCount = aOptions.size();
721
722 // Select the second board
723 std::vector<IMPORT_PROJECT_DESC> chosen;
724 chosen.push_back( aOptions[1] );
725 return chosen;
726 } );
727
728 std::unique_ptr<BOARD> board = plugin.LoadBoard( dataPath );
729
730 BOOST_CHECK( callbackInvoked );
731 BOOST_CHECK_EQUAL( optionCount, 5 );
732 BOOST_REQUIRE( board );
733}
734
735
736BOOST_AUTO_TEST_CASE( MultiBoardCallbackCancelThrows )
737{
738 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
739 + "/plugins/sprint_layout/mmjoy2-74hc165.lay6";
740
742
743 plugin.RegisterCallback(
744 [&]( const std::vector<IMPORT_PROJECT_DESC>& aOptions )
745 {
746 return std::vector<IMPORT_PROJECT_DESC>();
747 } );
748
749 BOOST_CHECK_THROW( plugin.LoadBoard( dataPath ), IO_ERROR );
750}
751
752
753BOOST_AUTO_TEST_CASE( SingleBoardFileSkipsCallback )
754{
755 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
756 + "/plugins/sprint_layout/gpio2nesc.lay6";
757
759 bool callbackInvoked = false;
760
761 plugin.RegisterCallback(
762 [&]( const std::vector<IMPORT_PROJECT_DESC>& aOptions )
763 {
764 callbackInvoked = true;
765 return aOptions;
766 } );
767
768 std::unique_ptr<BOARD> board = plugin.LoadBoard( dataPath );
769
770 BOOST_CHECK( !callbackInvoked );
771 BOOST_REQUIRE( board );
772}
773
774
775// ============================================================================
776// Regression tests
777// ============================================================================
778
779BOOST_AUTO_TEST_CASE( Pic12F629SmdPadPositions )
780{
781 // GitLab #23538: SMD pad x,y fields in some Sprint Layout files store
782 // component-relative offsets rather than absolute positions, causing
783 // all SMD pads to pile up near (0,0).
784 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
785 + "/plugins/sprint_layout/12F629_SM.lay6";
786
787 std::unique_ptr<BOARD> board = m_plugin.LoadBoard( dataPath );
788
789 BOOST_REQUIRE( board );
790
791 // The PIC12F629 is an 8-pin SOIC. After import, its pads should be
792 // spread across the board, not clustered at the origin.
793 BOX2I boardBox;
794 bool first = true;
795
796 for( BOARD_ITEM* item : board->Drawings() )
797 {
798 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
799
800 if( shape && shape->GetLayer() == Edge_Cuts )
801 {
802 if( first )
803 {
804 boardBox = shape->GetBoundingBox();
805 first = false;
806 }
807 else
808 {
809 boardBox.Merge( shape->GetBoundingBox() );
810 }
811 }
812 }
813
814 BOOST_REQUIRE( !first );
815
816 boardBox.Inflate( pcbIUScale.mmToIU( 2.0 ) );
817
818 int outsideCount = 0;
819 int smdCount = 0;
820
821 for( FOOTPRINT* fp : board->Footprints() )
822 {
823 for( PAD* pad : fp->Pads() )
824 {
825 if( pad->GetAttribute() == PAD_ATTRIB::SMD )
826 {
827 smdCount++;
828
829 if( !boardBox.Contains( pad->GetPosition() ) )
830 outsideCount++;
831 }
832 }
833 }
834
835 BOOST_CHECK_MESSAGE( smdCount > 0,
836 "PIC12F629 board should have SMD pads" );
837
838 BOOST_CHECK_MESSAGE( outsideCount == 0,
839 wxString::Format( "%d of %d SMD pads outside board outline",
840 outsideCount, smdCount ) );
841}
842
843
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
General utilities for PCB file IO for QA programs.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition pad.h:61
void LoadAndAppendBoard(const wxString &aFileName, BOARD &aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Same as LoadBoard(), but appends the loaded board to an existing board, which must already exist.
Definition pcb_io.cpp:85
std::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
Definition pcb_io.cpp:72
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
virtual void RegisterCallback(CHOOSE_PROJECT_HANDLER aChooseProjectHandler)
Register a different handler to be called when a non-KiCad project contains multiple PCB+Schematic co...
Definition seg.h:38
SEG Reversed() const
Definition seg.h:391
const SPRINT_LAYOUT::FILE_DATA & GetFileData() const
bool ParseBoard(const wxString &aFileName)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ F_SilkS
Definition layer_ids.h:96
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ In1_Cu
Definition layer_ids.h:62
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_AUTO_TEST_CASE(CanReadLay6File)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708