KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_test_utils.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <iostream>
27#include <filesystem>
28
29#include <wx/filename.h>
30
31#include <boost/test/unit_test.hpp>
32
33#include <board.h>
34#include <board_commit.h>
36#include <footprint.h>
37#include <kiid.h>
38#include <pad.h>
39#include <pcb_shape.h>
40#include <zone.h>
41#include <zone_filler.h>
46#include <tool/tool_manager.h>
47
48#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
49 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
50
51
52namespace KI_TEST
53{
54
56 m_dump_boards( true )
57{
58}
59
60
61void BOARD_DUMPER::DumpBoardToFile( BOARD& aBoard, const std::string& aName ) const
62{
63 if( !m_dump_boards )
64 return;
65
66 auto path = std::filesystem::temp_directory_path() / aName;
67 path += ".kicad_pcb";
68
69 BOOST_TEST_MESSAGE( "Dumping board file: " << path.string() );
70 ::KI_TEST::DumpBoardToFile( aBoard, path.string() );
71}
72
73
74void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath,
75 std::unique_ptr<BOARD>& aBoard )
76{
77 if( aBoard )
78 {
79 aBoard->SetProject( nullptr );
80 aBoard = nullptr;
81 }
82
83 std::string absPath = GetPcbnewTestDataDir() + aRelPath.ToStdString();
84 wxFileName projectFile( absPath + ".kicad_pro" );
85 wxFileName legacyProject( absPath + ".pro" );
86 std::string boardPath = absPath + ".kicad_pcb";
87 wxFileName rulesFile( absPath + ".kicad_dru" );
88
89 if( projectFile.Exists() )
90 {
91 aSettingsManager.LoadProject( projectFile.GetFullPath() );
92 BOOST_TEST_MESSAGE( "Loading project file: " << projectFile.GetFullPath() );
93 }
94 else if( legacyProject.Exists() )
95 {
96 aSettingsManager.LoadProject( legacyProject.GetFullPath() );
97 BOOST_TEST_MESSAGE( "Loading project file: " << projectFile.GetFullPath() );
98 }
99 else
100 BOOST_TEST_MESSAGE( "Could not load project: " << projectFile.GetFullPath() );
101
102 BOOST_TEST_MESSAGE( "Loading board file: " << boardPath );
103
104 try {
105 aBoard = ReadBoardFromFileOrStream( boardPath );
106 }
107 catch( const IO_ERROR& ioe )
108 {
109 BOOST_TEST_ERROR( ioe.What() );
110 }
111
112 BOOST_REQUIRE_MESSAGE( aBoard, "aBoard is null or invalid" );
113
114 if( projectFile.Exists() || legacyProject.Exists() )
115 aBoard->SetProject( &aSettingsManager.Prj() );
116
117 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
118
119 BOOST_TEST_CHECKPOINT( "Init drc engine" );
120
121 if( rulesFile.Exists() )
122 m_DRCEngine->InitEngine( rulesFile );
123 else
124 m_DRCEngine->InitEngine( wxFileName() );
125
126 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
127
128 BOOST_TEST_CHECKPOINT( "Build list of nets" );
129 aBoard->BuildListOfNets();
130
131 BOOST_TEST_CHECKPOINT( "Build connectivity" );
132 aBoard->BuildConnectivity();
133
134 BOOST_TEST_CHECKPOINT( "Synchronize Time Domain Properties" );
135 aBoard->GetLengthCalculation()->SynchronizeTimeDomainProperties();
136
137 if( aBoard->GetProject() )
138 {
139 std::unordered_set<wxString> dummy;
140 BOOST_TEST_CHECKPOINT( "Synchronize Component Classes" );
141 aBoard->SynchronizeComponentClasses( dummy );
142
143 BOOST_TEST_CHECKPOINT( "Run DRC cache generator" );
144 DRC_CACHE_GENERATOR cacheGenerator;
145 cacheGenerator.SetDRCEngine( m_DRCEngine.get() );
146 cacheGenerator.Run();
147 }
148}
149
150
151BOARD_ITEM& RequireBoardItemWithTypeAndId( const BOARD& aBoard, KICAD_T aItemType, const KIID& aID )
152{
153 BOARD_ITEM* item = aBoard.ResolveItem( aID, true );
154
155 BOOST_REQUIRE( item );
156 BOOST_REQUIRE_EQUAL( item->Type(), aItemType );
157
158 return *item;
159}
160
161
166{
167public:
172 TEMPORARY_DIRECTORY( const std::string& aNamePrefix, const std::string aSuffix )
173 {
174 int i = 0;
175
176 // Find a unique directory name
177 while( true )
178 {
179 m_path = std::filesystem::temp_directory_path()
180 / ( aNamePrefix + std::to_string( i ) + aSuffix );
181
182 if( !std::filesystem::exists( m_path ) )
183 break;
184
185 i++;
186 }
187
188 wxASSERT( !std::filesystem::exists( m_path ) );
189 std::filesystem::create_directories( m_path );
190 }
191
192 ~TEMPORARY_DIRECTORY() { std::filesystem::remove_all( m_path ); }
193
194 const std::filesystem::path& GetPath() const { return m_path; }
195
196private:
197 std::filesystem::path m_path;
198};
199
200
201void LoadAndTestBoardFile( const wxString aRelativePath, bool aRoundtrip,
202 std::function<void( BOARD& )> aBoardTestFunction,
203 std::optional<int> aExpectedBoardVersion )
204{
205 const std::string absBoardPath =
206 KI_TEST::GetPcbnewTestDataDir() + aRelativePath.ToStdString() + ".kicad_pcb";
207
208 BOOST_TEST_MESSAGE( "Loading board to test: " << absBoardPath );
209 std::unique_ptr<BOARD> board1 = KI_TEST::ReadBoardFromFileOrStream( absBoardPath );
210
211 // Should load - if it doesn't we're done for
212 BOOST_REQUIRE( board1 );
213
214 BOOST_TEST_MESSAGE( "Testing loaded board" );
215 aBoardTestFunction( *board1 );
216
217 // If we care about the board version, check it now - but not after a roundtrip
218 // (as the version will be updated to the current version)
219 if( aExpectedBoardVersion )
220 {
221 BOOST_CHECK_EQUAL( board1->GetFileFormatVersionAtLoad(), *aExpectedBoardVersion );
222 }
223
224 if( aRoundtrip )
225 {
226 TEMPORARY_DIRECTORY tempLib( "kicad_qa_brd_roundtrip", "" );
227
228 const auto savePath = tempLib.GetPath() / ( aRelativePath.ToStdString() + ".kicad_pcb" );
229 KI_TEST::DumpBoardToFile( *board1, savePath.string() );
230
231 std::unique_ptr<BOARD> board2 = KI_TEST::ReadBoardFromFileOrStream( savePath.string() );
232
233 // Should load again
234 BOOST_REQUIRE( board2 );
235
236 BOOST_TEST_MESSAGE( "Testing roundtripped (saved/reloaded) file" );
237 aBoardTestFunction( *board2 );
238 }
239}
240
241
242void LoadAndTestFootprintFile( const wxString& aLibRelativePath, const wxString& aFpName,
243 bool aRoundtrip,
244 std::function<void( FOOTPRINT& )> aFootprintTestFunction,
245 std::optional<int> aExpectedFootprintVersion )
246{
247 const std::string absFootprintPath = KI_TEST::GetPcbnewTestDataDir()
248 + aLibRelativePath.ToStdString() + "/"
249 + aFpName.ToStdString() + ".kicad_mod";
250
251 BOOST_TEST_MESSAGE( "Loading footprint to test: " << absFootprintPath );
252 std::unique_ptr<FOOTPRINT> fp1 = KI_TEST::ReadFootprintFromFileOrStream( absFootprintPath );
253
254 // Should load - if it doesn't we're done for
255 BOOST_REQUIRE( fp1 );
256
257 BOOST_TEST_MESSAGE( "Testing loaded footprint (value: " << fp1->GetValue() << ")" );
258 aFootprintTestFunction( *fp1 );
259
260 // If we care about the board version, check it now - but not after a roundtrip
261 // (as the version will be updated to the current version)
262 if( aExpectedFootprintVersion )
263 {
264 BOOST_CHECK_EQUAL( fp1->GetFileFormatVersionAtLoad(), *aExpectedFootprintVersion );
265 }
266
267 if( aRoundtrip )
268 {
274 TEMPORARY_DIRECTORY tempLib( "kicad_qa_fp_roundtrip", ".pretty" );
275 const wxString fpFilename = fp1->GetFPID().GetLibItemName() + wxString( ".kicad_mod" );
276
277 BOOST_TEST_MESSAGE( "Resaving footprint: " << fpFilename << " in " << tempLib.GetPath() );
278
279 KI_TEST::DumpFootprintToFile( *fp1, tempLib.GetPath().string() );
280
281 const auto fp2Path = tempLib.GetPath() / fpFilename.ToStdString();
282
283 BOOST_TEST_MESSAGE( "Re-reading footprint: " << fpFilename << " in " << tempLib.GetPath() );
284
285 std::unique_ptr<FOOTPRINT> fp2 = KI_TEST::ReadFootprintFromFileOrStream( fp2Path.string() );
286
287 // Should load again
288 BOOST_REQUIRE( fp2 );
289
290 BOOST_TEST_MESSAGE( "Testing roundtripped (saved/reloaded) file" );
291 aFootprintTestFunction( *fp2 );
292 }
293}
294
295
296void FillZones( BOARD* m_board )
297{
298 BOOST_TEST_CHECKPOINT( "Filling zones" );
299
300 TOOL_MANAGER toolMgr;
301 toolMgr.SetEnvironment( m_board, nullptr, nullptr, nullptr, nullptr );
302
303 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
304 toolMgr.RegisterTool( dummyTool );
305
306 BOARD_COMMIT commit( dummyTool );
307 ZONE_FILLER filler( m_board, &commit );
308 std::vector<ZONE*> toFill;
309
310 for( ZONE* zone : m_board->Zones() )
311 toFill.push_back( zone );
312
313 if( filler.Fill( toFill, false, nullptr ) )
314 commit.Push( _( "Fill Zone(s)" ), SKIP_UNDO | SKIP_SET_DIRTY | ZONE_FILL_OP | SKIP_CONNECTIVITY );
315
316 BOOST_TEST_CHECKPOINT( "Building connectivity (after zone fill)" );
317 m_board->BuildConnectivity();
318}
319
320
321#define TEST( a, b ) \
322 { \
323 if( a != b ) \
324 return a < b; \
325 }
326#define TEST_PT( a, b ) \
327 { \
328 if( a.x != b.x ) \
329 return a.x < b.x; \
330 if( a.y != b.y ) \
331 return a.y < b.y; \
332 }
333
334
336{
338
339 bool operator()( const BOARD_ITEM* itemA, const BOARD_ITEM* itemB ) const
340 {
341 TEST( itemA->Type(), itemB->Type() );
342
343 if( itemA->GetLayerSet() != itemB->GetLayerSet() )
344 return itemA->GetLayerSet().Seq() < itemB->GetLayerSet().Seq();
345
346 if( itemA->Type() == PCB_TEXT_T )
347 {
348 const PCB_TEXT* textA = static_cast<const PCB_TEXT*>( itemA );
349 const PCB_TEXT* textB = static_cast<const PCB_TEXT*>( itemB );
350
351 TEST_PT( textA->GetPosition(), textB->GetPosition() );
352 TEST( textA->GetTextAngle(), textB->GetTextAngle() );
353 }
354
355 return fp_comp( itemA, itemB );
356 }
357};
358
359
361{
362 CHECK_ENUM_CLASS_EQUAL( expected->Type(), fp->Type() );
363
364 // TODO: validate those informations match the importer
365 BOOST_CHECK_EQUAL( expected->GetPosition(), fp->GetPosition() );
366 BOOST_CHECK_EQUAL( expected->GetOrientation(), fp->GetOrientation() );
367
368 BOOST_CHECK_EQUAL( expected->GetReference(), fp->GetReference() );
369 BOOST_CHECK_EQUAL( expected->GetValue(), fp->GetValue() );
370 BOOST_CHECK_EQUAL( expected->GetLibDescription(), fp->GetLibDescription() );
371 BOOST_CHECK_EQUAL( expected->GetKeywords(), fp->GetKeywords() );
372 BOOST_CHECK_EQUAL( expected->GetAttributes(), fp->GetAttributes() );
373 BOOST_CHECK_EQUAL( expected->GetFlag(), fp->GetFlag() );
374 //BOOST_CHECK_EQUAL( expected->GetProperties(), fp->GetProperties() );
375 BOOST_CHECK_EQUAL( expected->GetTypeName(), fp->GetTypeName() );
376
377 // simple test if count matches
378 BOOST_CHECK_EQUAL( expected->GetFields().size(), fp->GetFields().size() );
379 BOOST_CHECK_EQUAL( expected->Pads().size(), fp->Pads().size() );
380 BOOST_CHECK_EQUAL( expected->GraphicalItems().size(), fp->GraphicalItems().size() );
381 BOOST_CHECK_EQUAL( expected->Zones().size(), fp->Zones().size() );
382 BOOST_CHECK_EQUAL( expected->Groups().size(), fp->Groups().size() );
383 BOOST_CHECK_EQUAL( expected->Models().size(), fp->Models().size() );
384
385 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads( expected->Pads().begin(),
386 expected->Pads().end() );
387 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->Pads().begin(), fp->Pads().end() );
388
389 for( auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
390 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
391 {
392 CheckFpPad( *itExpected, *itFp );
393 }
394
395 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems( expected->GraphicalItems().begin(),
396 expected->GraphicalItems().end() );
397 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->GraphicalItems().begin(),
398 fp->GraphicalItems().end() );
399
400 for( auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
401 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
402 itExpected++, itFp++ )
403 {
404 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
405
406 switch( ( *itExpected )->Type() )
407 {
408 case PCB_TEXT_T:
409 {
410 const PCB_TEXT* expectedText = static_cast<const PCB_TEXT*>( *itExpected );
411 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( *itFp );
412
413 CheckFpText( expectedText, text );
414 break;
415 }
416
417 case PCB_SHAPE_T:
418 {
419 const PCB_SHAPE* expectedShape = static_cast<const PCB_SHAPE*>( *itExpected );
420 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( *itFp );
421
422 CheckFpShape( expectedShape, shape );
423 break;
424 }
425
427 case PCB_DIM_LEADER_T:
428 case PCB_DIM_CENTER_T:
429 case PCB_DIM_RADIAL_T:
431 // TODO
432 break;
433
434 default:
435 BOOST_ERROR( "KICAD_T not known" );
436 break;
437 }
438 }
439
440 std::set<ZONE*, FOOTPRINT::cmp_zones> expectedZones( expected->Zones().begin(),
441 expected->Zones().end() );
442 std::set<ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->Zones().begin(), fp->Zones().end() );
443
444 for( auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
445 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
446 {
447 CheckFpZone( *itExpected, *itFp );
448 }
449
450 // TODO: Groups
451
452 // Use FootprintNeedsUpdate as sanity check (which should do many of the same checks as above,
453 // but neither is guaranteed to be complete).
454 WX_STRING_REPORTER reporter;
455
456 if( const_cast<FOOTPRINT*>(expected)->FootprintNeedsUpdate(fp, BOARD_ITEM::COMPARE_FLAGS::DRC, &reporter) )
457 BOOST_REQUIRE_MESSAGE( false, reporter.GetMessages() );
458}
459
460
461void CheckFpPad( const PAD* expected, const PAD* pad )
462{
463 // TODO(JE) padstacks
464 BOOST_TEST_CONTEXT( "Assert PAD with KIID=" << expected->m_Uuid.AsString() )
465 {
466 CHECK_ENUM_CLASS_EQUAL( expected->Type(), pad->Type() );
467
468 BOOST_CHECK_EQUAL( expected->GetNumber(), pad->GetNumber() );
469 CHECK_ENUM_CLASS_EQUAL( expected->GetAttribute(), pad->GetAttribute() );
470 CHECK_ENUM_CLASS_EQUAL( expected->GetProperty(), pad->GetProperty() );
472 pad->GetShape( PADSTACK::ALL_LAYERS ) );
473
474 BOOST_CHECK_EQUAL( expected->IsLocked(), pad->IsLocked() );
475
476 BOOST_CHECK_EQUAL( expected->GetPosition(), pad->GetPosition() );
478 pad->GetSize( PADSTACK::ALL_LAYERS ) );
479 BOOST_CHECK_EQUAL( expected->GetOrientation(), pad->GetOrientation() );
481 pad->GetDelta( PADSTACK::ALL_LAYERS ) );
483 pad->GetOffset( PADSTACK::ALL_LAYERS ) );
484 BOOST_CHECK_EQUAL( expected->GetDrillSize(), pad->GetDrillSize() );
485 CHECK_ENUM_CLASS_EQUAL( expected->GetDrillShape(), pad->GetDrillShape() );
486
487 BOOST_CHECK_EQUAL( expected->GetLayerSet(), pad->GetLayerSet() );
488
489 BOOST_CHECK_EQUAL( expected->GetNetCode(), pad->GetNetCode() );
490 BOOST_CHECK_EQUAL( expected->GetPinFunction(), pad->GetPinFunction() );
491 BOOST_CHECK_EQUAL( expected->GetPinType(), pad->GetPinType() );
492 BOOST_CHECK_EQUAL( expected->GetPadToDieLength(), pad->GetPadToDieLength() );
493 BOOST_CHECK_EQUAL( expected->GetPadToDieDelay(), pad->GetPadToDieDelay() );
494 BOOST_CHECK_EQUAL( expected->GetLocalSolderMaskMargin().value_or( 0 ),
495 pad->GetLocalSolderMaskMargin().value_or( 0 ) );
496 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMargin().value_or( 0 ),
497 pad->GetLocalSolderPasteMargin().value_or( 0 ) );
498 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMarginRatio().value_or( 0 ),
499 pad->GetLocalSolderPasteMarginRatio().value_or( 0 ) );
500 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
501 pad->GetLocalClearance().value_or( 0 ) );
502 CHECK_ENUM_CLASS_EQUAL( expected->GetLocalZoneConnection(), pad->GetLocalZoneConnection() );
503 BOOST_CHECK_EQUAL( expected->GetLocalThermalSpokeWidthOverride().value_or( 0 ),
504 pad->GetLocalThermalSpokeWidthOverride().value_or( 0 ) );
505 BOOST_CHECK_EQUAL( expected->GetThermalSpokeAngle(), pad->GetThermalSpokeAngle() );
506 BOOST_CHECK_EQUAL( expected->GetThermalGap(), pad->GetThermalGap() );
507 BOOST_CHECK_EQUAL( expected->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ),
508 pad->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ) );
509 BOOST_CHECK_EQUAL( expected->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
510 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ) );
511 BOOST_CHECK_EQUAL( expected->GetChamferPositions( PADSTACK::ALL_LAYERS ),
512 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ) );
513 BOOST_CHECK_EQUAL( expected->GetRemoveUnconnected(), pad->GetRemoveUnconnected() );
514 BOOST_CHECK_EQUAL( expected->GetKeepTopBottom(), pad->GetKeepTopBottom() );
515
516 // TODO: did we check everything for complex pad shapes?
518 pad->GetAnchorPadShape( PADSTACK::ALL_LAYERS ) );
519 CHECK_ENUM_CLASS_EQUAL( expected->GetCustomShapeInZoneOpt(),
520 pad->GetCustomShapeInZoneOpt() );
521
522 BOOST_CHECK_EQUAL( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(),
523 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() );
524
525 if( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size()
526 == pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() )
527 {
528 for( size_t i = 0; i < expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(); ++i )
529 {
530 CheckFpShape( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get(),
531 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get() );
532 }
533 }
534 }
535}
536
537
539{
540 BOOST_TEST_CONTEXT( "Assert PCB_TEXT with KIID=" << expected->m_Uuid.AsString() )
541 {
542 CHECK_ENUM_CLASS_EQUAL( expected->Type(), text->Type() );
543
544 BOOST_CHECK_EQUAL( expected->IsLocked(), text->IsLocked() );
545
546 BOOST_CHECK_EQUAL( expected->GetText(), text->GetText() );
547 BOOST_CHECK_EQUAL( expected->GetPosition(), text->GetPosition() );
548 BOOST_CHECK_EQUAL( expected->GetTextAngle(), text->GetTextAngle() );
549 BOOST_CHECK_EQUAL( expected->IsKeepUpright(), text->IsKeepUpright() );
550
551 BOOST_CHECK_EQUAL( expected->GetLayerSet(), text->GetLayerSet() );
552 BOOST_CHECK_EQUAL( expected->IsVisible(), text->IsVisible() );
553
554 BOOST_CHECK_EQUAL( expected->GetTextSize(), text->GetTextSize() );
555 BOOST_CHECK_EQUAL( expected->GetLineSpacing(), text->GetLineSpacing() );
556 BOOST_CHECK_EQUAL( expected->GetTextThickness(), text->GetTextThickness() );
557 BOOST_CHECK_EQUAL( expected->IsBold(), text->IsBold() );
558 BOOST_CHECK_EQUAL( expected->IsItalic(), text->IsItalic() );
559 BOOST_CHECK_EQUAL( expected->GetHorizJustify(), text->GetHorizJustify() );
560 BOOST_CHECK_EQUAL( expected->GetVertJustify(), text->GetVertJustify() );
561 BOOST_CHECK_EQUAL( expected->IsMirrored(), text->IsMirrored() );
562 BOOST_CHECK_EQUAL( expected->GetFontName(), text->GetFontName() );
563
564 // TODO: render cache?
565 }
566}
567
568
569void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape )
570{
571 BOOST_TEST_CONTEXT( "Assert PCB_SHAPE with KIID=" << expected->m_Uuid.AsString() )
572 {
573 CHECK_ENUM_CLASS_EQUAL( expected->Type(), shape->Type() );
574
575 CHECK_ENUM_CLASS_EQUAL( expected->GetShape(), shape->GetShape() );
576
577 BOOST_CHECK_EQUAL( expected->IsLocked(), shape->IsLocked() );
578
579 BOOST_CHECK_EQUAL( expected->GetStart(), shape->GetStart() );
580 BOOST_CHECK_EQUAL( expected->GetEnd(), shape->GetEnd() );
581
582 if( expected->GetShape() == SHAPE_T::ARC )
583 {
584 // center and position might differ as they are calculated from start/mid/end -> compare mid instead
585 BOOST_CHECK_EQUAL( expected->GetArcMid(), shape->GetArcMid() );
586 }
587 else
588 {
589 BOOST_CHECK_EQUAL( expected->GetCenter(), shape->GetCenter() );
590 BOOST_CHECK_EQUAL( expected->GetPosition(), shape->GetPosition() );
591 }
592
593 BOOST_CHECK_EQUAL( expected->GetBezierC1(), shape->GetBezierC1() );
594 BOOST_CHECK_EQUAL( expected->GetBezierC2(), shape->GetBezierC2() );
595
596 CheckShapePolySet( &expected->GetPolyShape(), &shape->GetPolyShape() );
597
598 BOOST_CHECK_EQUAL( expected->GetLayerSet(), shape->GetLayerSet() );
599
600 BOOST_CHECK_EQUAL( expected->GetStroke().GetWidth(), shape->GetStroke().GetWidth() );
601 CHECK_ENUM_CLASS_EQUAL( expected->GetStroke().GetLineStyle(),
602 shape->GetStroke().GetLineStyle() );
603 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), shape->GetFillMode() );
604 }
605}
606
607
608void CheckFpZone( const ZONE* expected, const ZONE* zone )
609{
610 BOOST_TEST_CONTEXT( "Assert ZONE with KIID=" << expected->m_Uuid.AsString() )
611 {
612 CHECK_ENUM_CLASS_EQUAL( expected->Type(), zone->Type() );
613
614 BOOST_CHECK_EQUAL( expected->IsLocked(), zone->IsLocked() );
615
616 BOOST_CHECK_EQUAL( expected->GetNetCode(), zone->GetNetCode() );
617 BOOST_CHECK_EQUAL( expected->GetAssignedPriority(), zone->GetAssignedPriority() );
618 CHECK_ENUM_CLASS_EQUAL( expected->GetPadConnection(), zone->GetPadConnection() );
619 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
620 zone->GetLocalClearance().value_or( 0 ) );
621 BOOST_CHECK_EQUAL( expected->GetMinThickness(), zone->GetMinThickness() );
622
623 BOOST_CHECK_EQUAL( expected->GetLayerSet(), zone->GetLayerSet() );
624
625 BOOST_CHECK_EQUAL( expected->IsFilled(), zone->IsFilled() );
626 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), zone->GetFillMode() );
627 BOOST_CHECK_EQUAL( expected->GetHatchThickness(), zone->GetHatchThickness() );
628 BOOST_CHECK_EQUAL( expected->GetHatchGap(), zone->GetHatchGap() );
629 BOOST_CHECK_EQUAL( expected->GetHatchOrientation(), zone->GetHatchOrientation() );
630 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingLevel(), zone->GetHatchSmoothingLevel() );
631 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingValue(), zone->GetHatchSmoothingValue() );
632 BOOST_CHECK_EQUAL( expected->GetHatchBorderAlgorithm(), zone->GetHatchBorderAlgorithm() );
633 BOOST_CHECK_EQUAL( expected->GetHatchHoleMinArea(), zone->GetHatchHoleMinArea() );
634 BOOST_CHECK_EQUAL( expected->GetThermalReliefGap(), zone->GetThermalReliefGap() );
635 BOOST_CHECK_EQUAL( expected->GetThermalReliefSpokeWidth(),
637 BOOST_CHECK_EQUAL( expected->GetCornerSmoothingType(), zone->GetCornerSmoothingType() );
638 BOOST_CHECK_EQUAL( expected->GetCornerRadius(), zone->GetCornerRadius() );
639 CHECK_ENUM_CLASS_EQUAL( expected->GetIslandRemovalMode(), zone->GetIslandRemovalMode() );
640 BOOST_CHECK_EQUAL( expected->GetMinIslandArea(), zone->GetMinIslandArea() );
641
642 BOOST_CHECK_EQUAL( expected->GetIsRuleArea(), zone->GetIsRuleArea() );
643 BOOST_CHECK_EQUAL( expected->GetDoNotAllowZoneFills(), zone->GetDoNotAllowZoneFills() );
644 BOOST_CHECK_EQUAL( expected->GetDoNotAllowVias(), zone->GetDoNotAllowVias() );
645 BOOST_CHECK_EQUAL( expected->GetDoNotAllowTracks(), zone->GetDoNotAllowTracks() );
646 BOOST_CHECK_EQUAL( expected->GetDoNotAllowPads(), zone->GetDoNotAllowPads() );
647 BOOST_CHECK_EQUAL( expected->GetDoNotAllowFootprints(), zone->GetDoNotAllowFootprints() );
648
649 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
650 CHECK_ENUM_CLASS_EQUAL( expected->GetTeardropAreaType(), zone->GetTeardropAreaType() );
651 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
652
653 CheckShapePolySet( expected->Outline(), zone->Outline() );
654 // TODO: filled zones
655 }
656}
657
658
660{
661 BOOST_TEST_CONTEXT( "Assert SHAPE_POLY_SET" )
662 {
663 BOOST_CHECK_EQUAL( expected->OutlineCount(), polyset->OutlineCount() );
664 BOOST_CHECK_EQUAL( expected->TotalVertices(), polyset->TotalVertices() );
665
666 if( expected->OutlineCount() != polyset->OutlineCount() )
667 return; // don't check the rest
668
669 if( expected->TotalVertices() != polyset->TotalVertices() )
670 return; // don't check the rest
671
672 // TODO: check all outlines and holes (just checking outlines for now)
673 for( int i = 0; i < expected->OutlineCount(); ++i )
674 {
675 BOOST_TEST_CONTEXT( "Outline " << i )
676 {
677 BOOST_CHECK_EQUAL( expected->Outline( i ).ArcCount(),
678 polyset->Outline( i ).ArcCount() );
679 BOOST_CHECK_EQUAL( expected->Outline( i ).PointCount(),
680 polyset->Outline( i ).PointCount() );
681
682
683 if( expected->Outline( i ).PointCount() != polyset->Outline( i ).PointCount() )
684 return; // don't check the rest
685
686 for( int j = 0; j < expected->Outline( i ).PointCount(); ++j )
687 {
688 BOOST_CHECK_EQUAL( expected->Outline( i ).GetPoint( j ),
689 polyset->Outline( i ).GetPoint( j ) );
690 }
691 }
692 }
693 }
694}
695
696} // namespace KI_TEST
#define SKIP_CONNECTIVITY
Definition: board_commit.h:44
#define ZONE_FILL_OP
Definition: board_commit.h:45
General utilities for PCB file IO for QA programs.
#define CHECK_ENUM_CLASS_EQUAL(L, R)
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
bool IsLocked() const override
Definition: board_item.cpp:103
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:252
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
const ZONES & Zones() const
Definition: board.h:362
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:186
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition: board.cpp:1583
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
void SetDRCEngine(DRC_ENGINE *engine)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:258
FILL_T GetFillMode() const
Definition: eda_shape.h:142
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:337
SHAPE_T GetShape() const
Definition: eda_shape.h:168
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:215
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:173
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:255
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:975
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:144
wxString GetLibDescription() const
Definition: footprint.h:260
EDA_ANGLE GetOrientation() const
Definition: footprint.h:230
ZONES & Zones()
Definition: footprint.h:215
std::deque< PAD * > & Pads()
Definition: footprint.h:209
int GetAttributes() const
Definition: footprint.h:293
wxString GetTypeName() const
Get the type of footprint.
Definition: footprint.cpp:1299
GROUPS & Groups()
Definition: footprint.h:218
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
Definition: footprint.cpp:638
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:223
const wxString & GetValue() const
Definition: footprint.h:649
const wxString & GetReference() const
Definition: footprint.h:627
int GetFlag() const
Definition: footprint.h:304
wxString GetKeywords() const
Definition: footprint.h:263
VECTOR2I GetPosition() const override
Definition: footprint.h:227
DRAWINGS & GraphicalItems()
Definition: footprint.h:212
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Definition: kiid.h:49
void DumpBoardToFile(BOARD &aBoard, const std::string &aName) const
A temporary directory that will be deleted when it goes out of scope.
const std::filesystem::path & GetPath() const
TEMPORARY_DIRECTORY(const std::string &aNamePrefix, const std::string aSuffix)
Create a temporary directory with a given prefix and suffix.
std::filesystem::path m_path
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:296
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:145
Definition: pad.h:54
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:81
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_shape.cpp:230
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:91
VECTOR2I GetPosition() const override
Definition: pcb_shape.h:79
virtual VECTOR2I GetPosition() const override
Definition: pcb_text.h:84
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.
virtual const VECTOR2I GetPoint(int aIndex) const override
int PointCount() const
Return the number of points (vertices) in this line chain.
size_t ArcCount() const
Represent a set of closed polygons.
int TotalVertices() const
Return total number of vertices stored in the set.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
int GetWidth() const
LINE_STYLE GetLineStyle() const
Master controller class:
Definition: tool_manager.h:62
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
A wrapper for reporting to a wxString object.
Definition: reporter.h:190
const wxString & GetMessages() const
Definition: reporter.cpp:83
bool Fill(const std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
Handle a list of polygons defining a copper zone.
Definition: zone.h:74
int GetHatchBorderAlgorithm() const
Definition: zone.h:328
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:704
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:814
bool GetDoNotAllowVias() const
Definition: zone.h:720
bool GetDoNotAllowPads() const
Definition: zone.h:722
bool GetDoNotAllowTracks() const
Definition: zone.h:721
bool IsFilled() const
Definition: zone.h:292
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:731
SHAPE_POLY_SET * Outline()
Definition: zone.h:335
long long int GetMinIslandArea() const
Definition: zone.h:734
const wxString & GetZoneName() const
Definition: zone.h:163
int GetMinThickness() const
Definition: zone.h:301
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:298
int GetHatchThickness() const
Definition: zone.h:310
double GetHatchHoleMinArea() const
Definition: zone.h:325
int GetThermalReliefSpokeWidth() const
Definition: zone.h:245
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:316
bool GetDoNotAllowFootprints() const
Definition: zone.h:723
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:224
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:136
int GetHatchGap() const
Definition: zone.h:313
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:690
double GetHatchSmoothingValue() const
Definition: zone.h:322
bool GetDoNotAllowZoneFills() const
Definition: zone.h:719
int GetHatchSmoothingLevel() const
Definition: zone.h:319
unsigned int GetCornerRadius() const
Definition: zone.h:650
int GetCornerSmoothingType() const
Definition: zone.h:646
int GetThermalReliefGap() const
Definition: zone.h:234
unsigned GetAssignedPriority() const
Definition: zone.h:126
#define _(s)
#define TEST_PT(a, b)
#define TEST(a, b)
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void CheckFootprint(const FOOTPRINT *expected, const FOOTPRINT *fp)
Helper method to check if two footprints are semantically the same.
void FillZones(BOARD *m_board)
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
void CheckFpShape(const PCB_SHAPE *expected, const PCB_SHAPE *shape)
std::unique_ptr< FOOTPRINT > ReadFootprintFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
void LoadAndTestFootprintFile(const wxString &aLibRelativePath, const wxString &aFpName, bool aRoundtrip, std::function< void(FOOTPRINT &)> aFootprintTestFunction, std::optional< int > aExpectedFootprintVersion)
Same as LoadAndTestBoardFile, but for footprints.
void DumpBoardToFile(BOARD &board, const std::string &aFilename)
Utility function to simply write a Board out to a file.
void CheckFpPad(const PAD *expected, const PAD *pad)
void CheckFpZone(const ZONE *expected, const ZONE *zone)
void CheckFpText(const PCB_TEXT *expected, const PCB_TEXT *text)
void DumpFootprintToFile(const FOOTPRINT &aFootprint, const std::string &aLibraryPath)
Same as DumpBoardToFile, but for footprints.
void LoadAndTestBoardFile(const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion)
Perform "some test" on a board file loaded from the path, then optionally save and reload and run the...
void CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
#define SKIP_SET_DIRTY
Definition: sch_commit.h:43
#define SKIP_UNDO
Definition: sch_commit.h:41
std::vector< FAB_LAYER_COLOR > dummy
FOOTPRINT::cmp_drawings fp_comp
bool operator()(const BOARD_ITEM *itemA, const BOARD_ITEM *itemB) const
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:101
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:104