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