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 <filesystem>
27
28#include <wx/filename.h>
29
30#include <boost/test/unit_test.hpp>
31
32#include <board.h>
33#include <board_commit.h>
35#include <footprint.h>
36#include <kiid.h>
37#include <pad.h>
38#include <pcb_shape.h>
39#include <zone.h>
40#include <zone_filler.h>
45#include <tool/tool_manager.h>
46
47#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
48 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
49
50
51namespace KI_TEST
52{
53
55 m_dump_boards( true )
56{
57}
58
59
60void BOARD_DUMPER::DumpBoardToFile( BOARD& aBoard, const std::string& aName ) const
61{
62 if( !m_dump_boards )
63 return;
64
65 auto path = std::filesystem::temp_directory_path() / aName;
66 path += ".kicad_pcb";
67
68 BOOST_TEST_MESSAGE( "Dumping board file: " << path.string() );
69 ::KI_TEST::DumpBoardToFile( aBoard, path.string() );
70}
71
72
73void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath,
74 std::unique_ptr<BOARD>& aBoard )
75{
76 if( aBoard )
77 {
78 aBoard->SetProject( nullptr );
79 aBoard = nullptr;
80 }
81
82 std::string absPath = GetPcbnewTestDataDir() + aRelPath.ToStdString();
83 wxFileName projectFile( absPath + ".kicad_pro" );
84 wxFileName legacyProject( absPath + ".pro" );
85 std::string boardPath = absPath + ".kicad_pcb";
86 wxFileName rulesFile( absPath + ".kicad_dru" );
87
88 if( projectFile.Exists() )
89 aSettingsManager.LoadProject( projectFile.GetFullPath() );
90 else if( legacyProject.Exists() )
91 aSettingsManager.LoadProject( legacyProject.GetFullPath() );
92
93 BOOST_TEST_MESSAGE( "Loading board file: " << boardPath );
94
95 try {
96 aBoard = ReadBoardFromFileOrStream( boardPath );
97 }
98 catch( const IO_ERROR& ioe )
99 {
100 BOOST_TEST_ERROR( ioe.What() );
101 }
102
103 BOOST_REQUIRE( aBoard );
104
105 if( projectFile.Exists() || legacyProject.Exists() )
106 aBoard->SetProject( &aSettingsManager.Prj() );
107
108 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
109
110 BOOST_TEST_CHECKPOINT( "Init drc engine" );
111
112 if( rulesFile.Exists() )
113 m_DRCEngine->InitEngine( rulesFile );
114 else
115 m_DRCEngine->InitEngine( wxFileName() );
116
117 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
118
119 BOOST_TEST_CHECKPOINT( "Build list of nets" );
120 aBoard->BuildListOfNets();
121
122 BOOST_TEST_CHECKPOINT( "Build connectivity" );
123 aBoard->BuildConnectivity();
124
125 BOOST_TEST_CHECKPOINT( "Synchronize Time Domain Properties" );
126 aBoard->GetLengthCalculation()->SynchronizeTimeDomainProperties();
127
128 if( aBoard->GetProject() )
129 {
130 std::unordered_set<wxString> dummy;
131 BOOST_TEST_CHECKPOINT( "Synchronize Component Classes" );
132 aBoard->SynchronizeComponentClasses( dummy );
133
134 BOOST_TEST_CHECKPOINT( "Run DRC cache generator" );
135 DRC_CACHE_GENERATOR cacheGenerator;
136 cacheGenerator.SetDRCEngine( m_DRCEngine.get() );
137 cacheGenerator.Run();
138 }
139}
140
141
142BOARD_ITEM& RequireBoardItemWithTypeAndId( const BOARD& aBoard, KICAD_T aItemType, const KIID& aID )
143{
144 BOARD_ITEM* item = aBoard.ResolveItem( aID, true );
145
146 BOOST_REQUIRE( item );
147 BOOST_REQUIRE_EQUAL( item->Type(), aItemType );
148
149 return *item;
150}
151
152
157{
158public:
163 TEMPORARY_DIRECTORY( const std::string& aNamePrefix, const std::string aSuffix )
164 {
165 int i = 0;
166
167 // Find a unique directory name
168 while( true )
169 {
170 m_path = std::filesystem::temp_directory_path()
171 / ( aNamePrefix + std::to_string( i ) + aSuffix );
172
173 if( !std::filesystem::exists( m_path ) )
174 break;
175
176 i++;
177 }
178
179 wxASSERT( !std::filesystem::exists( m_path ) );
180 std::filesystem::create_directories( m_path );
181 }
182
183 ~TEMPORARY_DIRECTORY() { std::filesystem::remove_all( m_path ); }
184
185 const std::filesystem::path& GetPath() const { return m_path; }
186
187private:
188 std::filesystem::path m_path;
189};
190
191
192void LoadAndTestBoardFile( const wxString aRelativePath, bool aRoundtrip,
193 std::function<void( BOARD& )> aBoardTestFunction,
194 std::optional<int> aExpectedBoardVersion )
195{
196 const std::string absBoardPath =
197 KI_TEST::GetPcbnewTestDataDir() + aRelativePath.ToStdString() + ".kicad_pcb";
198
199 BOOST_TEST_MESSAGE( "Loading board to test: " << absBoardPath );
200 std::unique_ptr<BOARD> board1 = KI_TEST::ReadBoardFromFileOrStream( absBoardPath );
201
202 // Should load - if it doesn't we're done for
203 BOOST_REQUIRE( board1 );
204
205 BOOST_TEST_MESSAGE( "Testing loaded board" );
206 aBoardTestFunction( *board1 );
207
208 // If we care about the board version, check it now - but not after a roundtrip
209 // (as the version will be updated to the current version)
210 if( aExpectedBoardVersion )
211 {
212 BOOST_CHECK_EQUAL( board1->GetFileFormatVersionAtLoad(), *aExpectedBoardVersion );
213 }
214
215 if( aRoundtrip )
216 {
217 TEMPORARY_DIRECTORY tempLib( "kicad_qa_brd_roundtrip", "" );
218
219 const auto savePath = tempLib.GetPath() / ( aRelativePath.ToStdString() + ".kicad_pcb" );
220 KI_TEST::DumpBoardToFile( *board1, savePath.string() );
221
222 std::unique_ptr<BOARD> board2 = KI_TEST::ReadBoardFromFileOrStream( savePath.string() );
223
224 // Should load again
225 BOOST_REQUIRE( board2 );
226
227 BOOST_TEST_MESSAGE( "Testing roundtripped (saved/reloaded) file" );
228 aBoardTestFunction( *board2 );
229 }
230}
231
232
233void LoadAndTestFootprintFile( const wxString& aLibRelativePath, const wxString& aFpName,
234 bool aRoundtrip,
235 std::function<void( FOOTPRINT& )> aFootprintTestFunction,
236 std::optional<int> aExpectedFootprintVersion )
237{
238 const std::string absFootprintPath = KI_TEST::GetPcbnewTestDataDir()
239 + aLibRelativePath.ToStdString() + "/"
240 + aFpName.ToStdString() + ".kicad_mod";
241
242 BOOST_TEST_MESSAGE( "Loading footprint to test: " << absFootprintPath );
243 std::unique_ptr<FOOTPRINT> fp1 = KI_TEST::ReadFootprintFromFileOrStream( absFootprintPath );
244
245 // Should load - if it doesn't we're done for
246 BOOST_REQUIRE( fp1 );
247
248 BOOST_TEST_MESSAGE( "Testing loaded footprint (value: " << fp1->GetValue() << ")" );
249 aFootprintTestFunction( *fp1 );
250
251 // If we care about the board version, check it now - but not after a roundtrip
252 // (as the version will be updated to the current version)
253 if( aExpectedFootprintVersion )
254 {
255 BOOST_CHECK_EQUAL( fp1->GetFileFormatVersionAtLoad(), *aExpectedFootprintVersion );
256 }
257
258 if( aRoundtrip )
259 {
265 TEMPORARY_DIRECTORY tempLib( "kicad_qa_fp_roundtrip", ".pretty" );
266 const wxString fpFilename = fp1->GetFPID().GetLibItemName() + wxString( ".kicad_mod" );
267
268 BOOST_TEST_MESSAGE( "Resaving footprint: " << fpFilename << " in " << tempLib.GetPath() );
269
270 KI_TEST::DumpFootprintToFile( *fp1, tempLib.GetPath().string() );
271
272 const auto fp2Path = tempLib.GetPath() / fpFilename.ToStdString();
273
274 BOOST_TEST_MESSAGE( "Re-reading footprint: " << fpFilename << " in " << tempLib.GetPath() );
275
276 std::unique_ptr<FOOTPRINT> fp2 = KI_TEST::ReadFootprintFromFileOrStream( fp2Path.string() );
277
278 // Should load again
279 BOOST_REQUIRE( fp2 );
280
281 BOOST_TEST_MESSAGE( "Testing roundtripped (saved/reloaded) file" );
282 aFootprintTestFunction( *fp2 );
283 }
284}
285
286
287void FillZones( BOARD* m_board )
288{
289 BOOST_TEST_CHECKPOINT( "Filling zones" );
290
291 TOOL_MANAGER toolMgr;
292 toolMgr.SetEnvironment( m_board, nullptr, nullptr, nullptr, nullptr );
293
294 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
295 toolMgr.RegisterTool( dummyTool );
296
297 BOARD_COMMIT commit( dummyTool );
298 ZONE_FILLER filler( m_board, &commit );
299 std::vector<ZONE*> toFill;
300
301 for( ZONE* zone : m_board->Zones() )
302 toFill.push_back( zone );
303
304 if( filler.Fill( toFill, false, nullptr ) )
305 commit.Push( _( "Fill Zone(s)" ), SKIP_UNDO | SKIP_SET_DIRTY | ZONE_FILL_OP | SKIP_CONNECTIVITY );
306
307 BOOST_TEST_CHECKPOINT( "Building connectivity (after zone fill)" );
308 m_board->BuildConnectivity();
309}
310
311
312#define TEST( a, b ) \
313 { \
314 if( a != b ) \
315 return a < b; \
316 }
317#define TEST_PT( a, b ) \
318 { \
319 if( a.x != b.x ) \
320 return a.x < b.x; \
321 if( a.y != b.y ) \
322 return a.y < b.y; \
323 }
324
325
327{
329
330 bool operator()( const BOARD_ITEM* itemA, const BOARD_ITEM* itemB ) const
331 {
332 TEST( itemA->Type(), itemB->Type() );
333
334 if( itemA->GetLayerSet() != itemB->GetLayerSet() )
335 return itemA->GetLayerSet().Seq() < itemB->GetLayerSet().Seq();
336
337 if( itemA->Type() == PCB_TEXT_T )
338 {
339 const PCB_TEXT* textA = static_cast<const PCB_TEXT*>( itemA );
340 const PCB_TEXT* textB = static_cast<const PCB_TEXT*>( itemB );
341
342 TEST_PT( textA->GetPosition(), textB->GetPosition() );
343 TEST( textA->GetTextAngle(), textB->GetTextAngle() );
344 }
345
346 return fp_comp( itemA, itemB );
347 }
348};
349
350
352{
353 CHECK_ENUM_CLASS_EQUAL( expected->Type(), fp->Type() );
354
355 // TODO: validate those informations match the importer
356 BOOST_CHECK_EQUAL( expected->GetPosition(), fp->GetPosition() );
357 BOOST_CHECK_EQUAL( expected->GetOrientation(), fp->GetOrientation() );
358
359 BOOST_CHECK_EQUAL( expected->GetReference(), fp->GetReference() );
360 BOOST_CHECK_EQUAL( expected->GetValue(), fp->GetValue() );
361 BOOST_CHECK_EQUAL( expected->GetLibDescription(), fp->GetLibDescription() );
362 BOOST_CHECK_EQUAL( expected->GetKeywords(), fp->GetKeywords() );
363 BOOST_CHECK_EQUAL( expected->GetAttributes(), fp->GetAttributes() );
364 BOOST_CHECK_EQUAL( expected->GetFlag(), fp->GetFlag() );
365 //BOOST_CHECK_EQUAL( expected->GetProperties(), fp->GetProperties() );
366 BOOST_CHECK_EQUAL( expected->GetTypeName(), fp->GetTypeName() );
367
368 // simple test if count matches
369 BOOST_CHECK_EQUAL( expected->GetFields().size(), fp->GetFields().size() );
370 BOOST_CHECK_EQUAL( expected->Pads().size(), fp->Pads().size() );
371 BOOST_CHECK_EQUAL( expected->GraphicalItems().size(), fp->GraphicalItems().size() );
372 BOOST_CHECK_EQUAL( expected->Zones().size(), fp->Zones().size() );
373 BOOST_CHECK_EQUAL( expected->Groups().size(), fp->Groups().size() );
374 BOOST_CHECK_EQUAL( expected->Models().size(), fp->Models().size() );
375
376 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads( expected->Pads().begin(),
377 expected->Pads().end() );
378 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->Pads().begin(), fp->Pads().end() );
379
380 for( auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
381 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
382 {
383 CheckFpPad( *itExpected, *itFp );
384 }
385
386 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems( expected->GraphicalItems().begin(),
387 expected->GraphicalItems().end() );
388 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->GraphicalItems().begin(),
389 fp->GraphicalItems().end() );
390
391 for( auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
392 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
393 itExpected++, itFp++ )
394 {
395 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
396
397 switch( ( *itExpected )->Type() )
398 {
399 case PCB_TEXT_T:
400 {
401 const PCB_TEXT* expectedText = static_cast<const PCB_TEXT*>( *itExpected );
402 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( *itFp );
403
404 CheckFpText( expectedText, text );
405 break;
406 }
407
408 case PCB_SHAPE_T:
409 {
410 const PCB_SHAPE* expectedShape = static_cast<const PCB_SHAPE*>( *itExpected );
411 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( *itFp );
412
413 CheckFpShape( expectedShape, shape );
414 break;
415 }
416
418 case PCB_DIM_LEADER_T:
419 case PCB_DIM_CENTER_T:
420 case PCB_DIM_RADIAL_T:
422 // TODO
423 break;
424
425 default:
426 BOOST_ERROR( "KICAD_T not known" );
427 break;
428 }
429 }
430
431 std::set<ZONE*, FOOTPRINT::cmp_zones> expectedZones( expected->Zones().begin(),
432 expected->Zones().end() );
433 std::set<ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->Zones().begin(), fp->Zones().end() );
434
435 for( auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
436 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
437 {
438 CheckFpZone( *itExpected, *itFp );
439 }
440
441 // TODO: Groups
442
443 // Use FootprintNeedsUpdate as sanity check (which should do many of the same checks as above,
444 // but neither is guaranteed to be complete).
445 WX_STRING_REPORTER reporter;
446
447 if( const_cast<FOOTPRINT*>(expected)->FootprintNeedsUpdate(fp, BOARD_ITEM::COMPARE_FLAGS::DRC, &reporter) )
448 BOOST_REQUIRE_MESSAGE( false, reporter.GetMessages() );
449}
450
451
452void CheckFpPad( const PAD* expected, const PAD* pad )
453{
454 // TODO(JE) padstacks
455 BOOST_TEST_CONTEXT( "Assert PAD with KIID=" << expected->m_Uuid.AsString() )
456 {
457 CHECK_ENUM_CLASS_EQUAL( expected->Type(), pad->Type() );
458
459 BOOST_CHECK_EQUAL( expected->GetNumber(), pad->GetNumber() );
460 CHECK_ENUM_CLASS_EQUAL( expected->GetAttribute(), pad->GetAttribute() );
461 CHECK_ENUM_CLASS_EQUAL( expected->GetProperty(), pad->GetProperty() );
463 pad->GetShape( PADSTACK::ALL_LAYERS ) );
464
465 BOOST_CHECK_EQUAL( expected->IsLocked(), pad->IsLocked() );
466
467 BOOST_CHECK_EQUAL( expected->GetPosition(), pad->GetPosition() );
469 pad->GetSize( PADSTACK::ALL_LAYERS ) );
470 BOOST_CHECK_EQUAL( expected->GetOrientation(), pad->GetOrientation() );
472 pad->GetDelta( PADSTACK::ALL_LAYERS ) );
474 pad->GetOffset( PADSTACK::ALL_LAYERS ) );
475 BOOST_CHECK_EQUAL( expected->GetDrillSize(), pad->GetDrillSize() );
476 CHECK_ENUM_CLASS_EQUAL( expected->GetDrillShape(), pad->GetDrillShape() );
477
478 BOOST_CHECK_EQUAL( expected->GetLayerSet(), pad->GetLayerSet() );
479
480 BOOST_CHECK_EQUAL( expected->GetNetCode(), pad->GetNetCode() );
481 BOOST_CHECK_EQUAL( expected->GetPinFunction(), pad->GetPinFunction() );
482 BOOST_CHECK_EQUAL( expected->GetPinType(), pad->GetPinType() );
483 BOOST_CHECK_EQUAL( expected->GetPadToDieLength(), pad->GetPadToDieLength() );
484 BOOST_CHECK_EQUAL( expected->GetPadToDieDelay(), pad->GetPadToDieDelay() );
485 BOOST_CHECK_EQUAL( expected->GetLocalSolderMaskMargin().value_or( 0 ),
486 pad->GetLocalSolderMaskMargin().value_or( 0 ) );
487 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMargin().value_or( 0 ),
488 pad->GetLocalSolderPasteMargin().value_or( 0 ) );
489 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMarginRatio().value_or( 0 ),
490 pad->GetLocalSolderPasteMarginRatio().value_or( 0 ) );
491 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
492 pad->GetLocalClearance().value_or( 0 ) );
493 CHECK_ENUM_CLASS_EQUAL( expected->GetLocalZoneConnection(), pad->GetLocalZoneConnection() );
494 BOOST_CHECK_EQUAL( expected->GetLocalThermalSpokeWidthOverride().value_or( 0 ),
495 pad->GetLocalThermalSpokeWidthOverride().value_or( 0 ) );
496 BOOST_CHECK_EQUAL( expected->GetThermalSpokeAngle(), pad->GetThermalSpokeAngle() );
497 BOOST_CHECK_EQUAL( expected->GetThermalGap(), pad->GetThermalGap() );
498 BOOST_CHECK_EQUAL( expected->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ),
499 pad->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ) );
500 BOOST_CHECK_EQUAL( expected->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
501 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ) );
502 BOOST_CHECK_EQUAL( expected->GetChamferPositions( PADSTACK::ALL_LAYERS ),
503 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ) );
504 BOOST_CHECK_EQUAL( expected->GetRemoveUnconnected(), pad->GetRemoveUnconnected() );
505 BOOST_CHECK_EQUAL( expected->GetKeepTopBottom(), pad->GetKeepTopBottom() );
506
507 // TODO: did we check everything for complex pad shapes?
509 pad->GetAnchorPadShape( PADSTACK::ALL_LAYERS ) );
510 CHECK_ENUM_CLASS_EQUAL( expected->GetCustomShapeInZoneOpt(),
511 pad->GetCustomShapeInZoneOpt() );
512
513 BOOST_CHECK_EQUAL( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(),
514 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() );
515
516 if( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size()
517 == pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() )
518 {
519 for( size_t i = 0; i < expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(); ++i )
520 {
521 CheckFpShape( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get(),
522 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get() );
523 }
524 }
525 }
526}
527
528
530{
531 BOOST_TEST_CONTEXT( "Assert PCB_TEXT with KIID=" << expected->m_Uuid.AsString() )
532 {
533 CHECK_ENUM_CLASS_EQUAL( expected->Type(), text->Type() );
534
535 BOOST_CHECK_EQUAL( expected->IsLocked(), text->IsLocked() );
536
537 BOOST_CHECK_EQUAL( expected->GetText(), text->GetText() );
538 BOOST_CHECK_EQUAL( expected->GetPosition(), text->GetPosition() );
539 BOOST_CHECK_EQUAL( expected->GetTextAngle(), text->GetTextAngle() );
540 BOOST_CHECK_EQUAL( expected->IsKeepUpright(), text->IsKeepUpright() );
541
542 BOOST_CHECK_EQUAL( expected->GetLayerSet(), text->GetLayerSet() );
543 BOOST_CHECK_EQUAL( expected->IsVisible(), text->IsVisible() );
544
545 BOOST_CHECK_EQUAL( expected->GetTextSize(), text->GetTextSize() );
546 BOOST_CHECK_EQUAL( expected->GetLineSpacing(), text->GetLineSpacing() );
547 BOOST_CHECK_EQUAL( expected->GetTextThickness(), text->GetTextThickness() );
548 BOOST_CHECK_EQUAL( expected->IsBold(), text->IsBold() );
549 BOOST_CHECK_EQUAL( expected->IsItalic(), text->IsItalic() );
550 BOOST_CHECK_EQUAL( expected->GetHorizJustify(), text->GetHorizJustify() );
551 BOOST_CHECK_EQUAL( expected->GetVertJustify(), text->GetVertJustify() );
552 BOOST_CHECK_EQUAL( expected->IsMirrored(), text->IsMirrored() );
553 BOOST_CHECK_EQUAL( expected->GetFontName(), text->GetFontName() );
554
555 // TODO: render cache?
556 }
557}
558
559
560void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape )
561{
562 BOOST_TEST_CONTEXT( "Assert PCB_SHAPE with KIID=" << expected->m_Uuid.AsString() )
563 {
564 CHECK_ENUM_CLASS_EQUAL( expected->Type(), shape->Type() );
565
566 CHECK_ENUM_CLASS_EQUAL( expected->GetShape(), shape->GetShape() );
567
568 BOOST_CHECK_EQUAL( expected->IsLocked(), shape->IsLocked() );
569
570 BOOST_CHECK_EQUAL( expected->GetStart(), shape->GetStart() );
571 BOOST_CHECK_EQUAL( expected->GetEnd(), shape->GetEnd() );
572
573 if( expected->GetShape() == SHAPE_T::ARC )
574 {
575 // center and position might differ as they are calculated from start/mid/end -> compare mid instead
576 BOOST_CHECK_EQUAL( expected->GetArcMid(), shape->GetArcMid() );
577 }
578 else
579 {
580 BOOST_CHECK_EQUAL( expected->GetCenter(), shape->GetCenter() );
581 BOOST_CHECK_EQUAL( expected->GetPosition(), shape->GetPosition() );
582 }
583
584 BOOST_CHECK_EQUAL( expected->GetBezierC1(), shape->GetBezierC1() );
585 BOOST_CHECK_EQUAL( expected->GetBezierC2(), shape->GetBezierC2() );
586
587 CheckShapePolySet( &expected->GetPolyShape(), &shape->GetPolyShape() );
588
589 BOOST_CHECK_EQUAL( expected->GetLayerSet(), shape->GetLayerSet() );
590
591 BOOST_CHECK_EQUAL( expected->GetStroke().GetWidth(), shape->GetStroke().GetWidth() );
592 CHECK_ENUM_CLASS_EQUAL( expected->GetStroke().GetLineStyle(),
593 shape->GetStroke().GetLineStyle() );
594 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), shape->GetFillMode() );
595 }
596}
597
598
599void CheckFpZone( const ZONE* expected, const ZONE* zone )
600{
601 BOOST_TEST_CONTEXT( "Assert ZONE with KIID=" << expected->m_Uuid.AsString() )
602 {
603 CHECK_ENUM_CLASS_EQUAL( expected->Type(), zone->Type() );
604
605 BOOST_CHECK_EQUAL( expected->IsLocked(), zone->IsLocked() );
606
607 BOOST_CHECK_EQUAL( expected->GetNetCode(), zone->GetNetCode() );
608 BOOST_CHECK_EQUAL( expected->GetAssignedPriority(), zone->GetAssignedPriority() );
609 CHECK_ENUM_CLASS_EQUAL( expected->GetPadConnection(), zone->GetPadConnection() );
610 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
611 zone->GetLocalClearance().value_or( 0 ) );
612 BOOST_CHECK_EQUAL( expected->GetMinThickness(), zone->GetMinThickness() );
613
614 BOOST_CHECK_EQUAL( expected->GetLayerSet(), zone->GetLayerSet() );
615
616 BOOST_CHECK_EQUAL( expected->IsFilled(), zone->IsFilled() );
617 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), zone->GetFillMode() );
618 BOOST_CHECK_EQUAL( expected->GetHatchThickness(), zone->GetHatchThickness() );
619 BOOST_CHECK_EQUAL( expected->GetHatchGap(), zone->GetHatchGap() );
620 BOOST_CHECK_EQUAL( expected->GetHatchOrientation(), zone->GetHatchOrientation() );
621 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingLevel(), zone->GetHatchSmoothingLevel() );
622 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingValue(), zone->GetHatchSmoothingValue() );
623 BOOST_CHECK_EQUAL( expected->GetHatchBorderAlgorithm(), zone->GetHatchBorderAlgorithm() );
624 BOOST_CHECK_EQUAL( expected->GetHatchHoleMinArea(), zone->GetHatchHoleMinArea() );
625 BOOST_CHECK_EQUAL( expected->GetThermalReliefGap(), zone->GetThermalReliefGap() );
626 BOOST_CHECK_EQUAL( expected->GetThermalReliefSpokeWidth(),
628 BOOST_CHECK_EQUAL( expected->GetCornerSmoothingType(), zone->GetCornerSmoothingType() );
629 BOOST_CHECK_EQUAL( expected->GetCornerRadius(), zone->GetCornerRadius() );
630 CHECK_ENUM_CLASS_EQUAL( expected->GetIslandRemovalMode(), zone->GetIslandRemovalMode() );
631 BOOST_CHECK_EQUAL( expected->GetMinIslandArea(), zone->GetMinIslandArea() );
632
633 BOOST_CHECK_EQUAL( expected->GetIsRuleArea(), zone->GetIsRuleArea() );
634 BOOST_CHECK_EQUAL( expected->GetDoNotAllowZoneFills(), zone->GetDoNotAllowZoneFills() );
635 BOOST_CHECK_EQUAL( expected->GetDoNotAllowVias(), zone->GetDoNotAllowVias() );
636 BOOST_CHECK_EQUAL( expected->GetDoNotAllowTracks(), zone->GetDoNotAllowTracks() );
637 BOOST_CHECK_EQUAL( expected->GetDoNotAllowPads(), zone->GetDoNotAllowPads() );
638 BOOST_CHECK_EQUAL( expected->GetDoNotAllowFootprints(), zone->GetDoNotAllowFootprints() );
639
640 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
641 CHECK_ENUM_CLASS_EQUAL( expected->GetTeardropAreaType(), zone->GetTeardropAreaType() );
642 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
643
644 CheckShapePolySet( expected->Outline(), zone->Outline() );
645 // TODO: filled zones
646 }
647}
648
649
651{
652 BOOST_TEST_CONTEXT( "Assert SHAPE_POLY_SET" )
653 {
654 BOOST_CHECK_EQUAL( expected->OutlineCount(), polyset->OutlineCount() );
655 BOOST_CHECK_EQUAL( expected->TotalVertices(), polyset->TotalVertices() );
656
657 if( expected->OutlineCount() != polyset->OutlineCount() )
658 return; // don't check the rest
659
660 if( expected->TotalVertices() != polyset->TotalVertices() )
661 return; // don't check the rest
662
663 // TODO: check all outlines and holes (just checking outlines for now)
664 for( int i = 0; i < expected->OutlineCount(); ++i )
665 {
666 BOOST_TEST_CONTEXT( "Outline " << i )
667 {
668 BOOST_CHECK_EQUAL( expected->Outline( i ).ArcCount(),
669 polyset->Outline( i ).ArcCount() );
670 BOOST_CHECK_EQUAL( expected->Outline( i ).PointCount(),
671 polyset->Outline( i ).PointCount() );
672
673
674 if( expected->Outline( i ).PointCount() != polyset->Outline( i ).PointCount() )
675 return; // don't check the rest
676
677 for( int j = 0; j < expected->Outline( i ).PointCount(); ++j )
678 {
679 BOOST_CHECK_EQUAL( expected->Outline( i ).GetPoint( j ),
680 polyset->Outline( i ).GetPoint( j ) );
681 }
682 }
683 }
684 }
685}
686
687} // 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:185
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition: board.cpp:1498
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:109
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:974
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:1286
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:634
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:223
const wxString & GetValue() const
Definition: footprint.h:647
const wxString & GetReference() const
Definition: footprint.h:625
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:297
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
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:699
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:769
bool GetDoNotAllowVias() const
Definition: zone.h:715
bool GetDoNotAllowPads() const
Definition: zone.h:717
bool GetDoNotAllowTracks() const
Definition: zone.h:716
bool IsFilled() const
Definition: zone.h:292
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:726
SHAPE_POLY_SET * Outline()
Definition: zone.h:335
long long int GetMinIslandArea() const
Definition: zone.h:729
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:718
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:685
double GetHatchSmoothingValue() const
Definition: zone.h:322
bool GetDoNotAllowZoneFills() const
Definition: zone.h:714
int GetHatchSmoothingLevel() const
Definition: zone.h:319
unsigned int GetCornerRadius() const
Definition: zone.h:645
int GetCornerSmoothingType() const
Definition: zone.h:641
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