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 (C) 2019-2024 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>
43#include <tool/tool_manager.h>
44
45#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
46 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
47
48
49namespace KI_TEST
50{
51
53 m_dump_boards( true )
54{
55}
56
57
58void BOARD_DUMPER::DumpBoardToFile( BOARD& aBoard, const std::string& aName ) const
59{
60 if( !m_dump_boards )
61 return;
62
63 auto path = std::filesystem::temp_directory_path() / aName;
64 path += ".kicad_pcb";
65
66 BOOST_TEST_MESSAGE( "Dumping board file: " << path.string() );
67 ::KI_TEST::DumpBoardToFile( aBoard, path.string() );
68}
69
70
71void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath,
72 std::unique_ptr<BOARD>& aBoard )
73{
74 if( aBoard )
75 {
76 aBoard->SetProject( nullptr );
77 aBoard = nullptr;
78 }
79
80 std::string absPath = GetPcbnewTestDataDir() + aRelPath.ToStdString();
81 wxFileName projectFile( absPath + ".kicad_pro" );
82 wxFileName legacyProject( absPath + ".pro" );
83 std::string boardPath = absPath + ".kicad_pcb";
84 wxFileName rulesFile( absPath + ".kicad_dru" );
85
86 if( projectFile.Exists() )
87 aSettingsManager.LoadProject( projectFile.GetFullPath() );
88 else if( legacyProject.Exists() )
89 aSettingsManager.LoadProject( legacyProject.GetFullPath() );
90
91 BOOST_TEST_MESSAGE( "Loading board file: " << boardPath );
92
93 try {
94 aBoard = ReadBoardFromFileOrStream( boardPath );
95 }
96 catch( const IO_ERROR& ioe )
97 {
98 BOOST_TEST_ERROR( ioe.What() );
99 }
100
101 BOOST_REQUIRE( aBoard );
102
103 if( projectFile.Exists() || legacyProject.Exists() )
104 aBoard->SetProject( &aSettingsManager.Prj() );
105
106 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
107
108 if( rulesFile.Exists() )
109 m_DRCEngine->InitEngine( rulesFile );
110 else
111 m_DRCEngine->InitEngine( wxFileName() );
112
113 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
114 aBoard->BuildListOfNets();
115 aBoard->BuildConnectivity();
116}
117
118
119BOARD_ITEM& RequireBoardItemWithTypeAndId( const BOARD& aBoard, KICAD_T aItemType, const KIID& aID )
120{
121 BOARD_ITEM* item = aBoard.GetItem( aID );
122
123 BOOST_REQUIRE( item );
124 BOOST_REQUIRE_EQUAL( item->Type(), aItemType );
125
126 return *item;
127}
128
129
130void LoadAndTestBoardFile( const wxString aRelativePath, bool aRoundtrip,
131 std::function<void( BOARD& )> aBoardTestFunction,
132 std::optional<int> aExpectedBoardVersion )
133{
134 const std::string absBoardPath =
135 KI_TEST::GetPcbnewTestDataDir() + aRelativePath.ToStdString() + ".kicad_pcb";
136
137 BOOST_TEST_MESSAGE( "Loading board to test: " << absBoardPath );
138 std::unique_ptr<BOARD> board1 = KI_TEST::ReadBoardFromFileOrStream( absBoardPath );
139
140 // Should load - if it doesn't we're done for
141 BOOST_REQUIRE( board1 );
142
143 BOOST_TEST_MESSAGE( "Testing loaded board" );
144 aBoardTestFunction( *board1 );
145
146 // If we care about the board version, check it now - but not after a roundtrip
147 // (as the version will be updated to the current version)
148 if( aExpectedBoardVersion )
149 {
150 BOOST_CHECK_EQUAL( board1->GetFileFormatVersionAtLoad(), *aExpectedBoardVersion );
151 }
152
153 if( aRoundtrip )
154 {
155 const auto savePath = std::filesystem::temp_directory_path()
156 / ( aRelativePath.ToStdString() + ".kicad_pcb" );
157 KI_TEST::DumpBoardToFile( *board1, savePath.string() );
158
159 std::unique_ptr<BOARD> board2 = KI_TEST::ReadBoardFromFileOrStream( savePath.string() );
160
161 // Should load again
162 BOOST_REQUIRE( board2 );
163
164 BOOST_TEST_MESSAGE( "Testing roundtripped (saved/reloaded) file" );
165 aBoardTestFunction( *board2 );
166 }
167}
168
169
170void FillZones( BOARD* m_board )
171{
172 TOOL_MANAGER toolMgr;
173 toolMgr.SetEnvironment( m_board, nullptr, nullptr, nullptr, nullptr );
174
175 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
176 toolMgr.RegisterTool( dummyTool );
177
178 BOARD_COMMIT commit( dummyTool );
179 ZONE_FILLER filler( m_board, &commit );
180 std::vector<ZONE*> toFill;
181
182 for( ZONE* zone : m_board->Zones() )
183 toFill.push_back( zone );
184
185 if( filler.Fill( toFill, false, nullptr ) )
186 commit.Push( _( "Fill Zone(s)" ), SKIP_UNDO | SKIP_SET_DIRTY | ZONE_FILL_OP | SKIP_CONNECTIVITY );
187
188 m_board->BuildConnectivity();
189}
190
191
192#define TEST( a, b ) \
193 { \
194 if( a != b ) \
195 return a < b; \
196 }
197#define TEST_PT( a, b ) \
198 { \
199 if( a.x != b.x ) \
200 return a.x < b.x; \
201 if( a.y != b.y ) \
202 return a.y < b.y; \
203 }
204
205
207{
209
210 bool operator()( const BOARD_ITEM* itemA, const BOARD_ITEM* itemB ) const
211 {
212 TEST( itemA->Type(), itemB->Type() );
213
214 if( itemA->GetLayerSet() != itemB->GetLayerSet() )
215 return itemA->GetLayerSet().Seq() < itemB->GetLayerSet().Seq();
216
217 if( itemA->Type() == PCB_TEXT_T )
218 {
219 const PCB_TEXT* textA = static_cast<const PCB_TEXT*>( itemA );
220 const PCB_TEXT* textB = static_cast<const PCB_TEXT*>( itemB );
221
222 TEST_PT( textA->GetPosition(), textB->GetPosition() );
223 TEST( textA->GetTextAngle(), textB->GetTextAngle() );
224 }
225
226 return fp_comp( itemA, itemB );
227 }
228};
229
230
232{
233 CHECK_ENUM_CLASS_EQUAL( expected->Type(), fp->Type() );
234
235 // TODO: validate those informations match the importer
236 BOOST_CHECK_EQUAL( expected->GetPosition(), fp->GetPosition() );
237 BOOST_CHECK_EQUAL( expected->GetOrientation(), fp->GetOrientation() );
238
239 BOOST_CHECK_EQUAL( expected->GetReference(), fp->GetReference() );
240 BOOST_CHECK_EQUAL( expected->GetValue(), fp->GetValue() );
241 BOOST_CHECK_EQUAL( expected->GetLibDescription(), fp->GetLibDescription() );
242 BOOST_CHECK_EQUAL( expected->GetKeywords(), fp->GetKeywords() );
243 BOOST_CHECK_EQUAL( expected->GetAttributes(), fp->GetAttributes() );
244 BOOST_CHECK_EQUAL( expected->GetFlag(), fp->GetFlag() );
245 //BOOST_CHECK_EQUAL( expected->GetProperties(), fp->GetProperties() );
246 BOOST_CHECK_EQUAL( expected->GetTypeName(), fp->GetTypeName() );
247
248 // simple test if count matches
249 BOOST_CHECK_EQUAL( expected->Fields().size(), fp->Fields().size() );
250 BOOST_CHECK_EQUAL( expected->Pads().size(), fp->Pads().size() );
251 BOOST_CHECK_EQUAL( expected->GraphicalItems().size(), fp->GraphicalItems().size() );
252 BOOST_CHECK_EQUAL( expected->Zones().size(), fp->Zones().size() );
253 BOOST_CHECK_EQUAL( expected->Groups().size(), fp->Groups().size() );
254 BOOST_CHECK_EQUAL( expected->Models().size(), fp->Models().size() );
255
256 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads( expected->Pads().begin(),
257 expected->Pads().end() );
258 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->Pads().begin(), fp->Pads().end() );
259
260 for( auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
261 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
262 {
263 CheckFpPad( *itExpected, *itFp );
264 }
265
266 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems( expected->GraphicalItems().begin(),
267 expected->GraphicalItems().end() );
268 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->GraphicalItems().begin(),
269 fp->GraphicalItems().end() );
270
271 for( auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
272 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
273 itExpected++, itFp++ )
274 {
275 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
276
277 switch( ( *itExpected )->Type() )
278 {
279 case PCB_TEXT_T:
280 {
281 const PCB_TEXT* expectedText = static_cast<const PCB_TEXT*>( *itExpected );
282 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( *itFp );
283
284 CheckFpText( expectedText, text );
285 break;
286 }
287
288 case PCB_SHAPE_T:
289 {
290 const PCB_SHAPE* expectedShape = static_cast<const PCB_SHAPE*>( *itExpected );
291 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( *itFp );
292
293 CheckFpShape( expectedShape, shape );
294 break;
295 }
296
298 case PCB_DIM_LEADER_T:
299 case PCB_DIM_CENTER_T:
300 case PCB_DIM_RADIAL_T:
302 // TODO
303 break;
304
305 default:
306 BOOST_ERROR( "KICAD_T not known" );
307 break;
308 }
309 }
310
311 std::set<ZONE*, FOOTPRINT::cmp_zones> expectedZones( expected->Zones().begin(),
312 expected->Zones().end() );
313 std::set<ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->Zones().begin(), fp->Zones().end() );
314
315 for( auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
316 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
317 {
318 CheckFpZone( *itExpected, *itFp );
319 }
320
321 // TODO: Groups
322
323 // Use FootprintNeedsUpdate as sanity check (which should do the same thing as our manually coded checks)
324 // If we get the reporter working, and COMPARE_FLAGS::DRC is enough for us, we can remove the old code
325 BOOST_CHECK( !const_cast<FOOTPRINT*>(expected)->FootprintNeedsUpdate(fp, BOARD_ITEM::COMPARE_FLAGS::DRC, nullptr) );
326}
327
328
329void CheckFpPad( const PAD* expected, const PAD* pad )
330{
331 // TODO(JE) padstacks
332 BOOST_TEST_CONTEXT( "Assert PAD with KIID=" << expected->m_Uuid.AsString() )
333 {
334 CHECK_ENUM_CLASS_EQUAL( expected->Type(), pad->Type() );
335
336 BOOST_CHECK_EQUAL( expected->GetNumber(), pad->GetNumber() );
337 CHECK_ENUM_CLASS_EQUAL( expected->GetAttribute(), pad->GetAttribute() );
338 CHECK_ENUM_CLASS_EQUAL( expected->GetProperty(), pad->GetProperty() );
340 pad->GetShape( PADSTACK::ALL_LAYERS ) );
341
342 BOOST_CHECK_EQUAL( expected->IsLocked(), pad->IsLocked() );
343
344 BOOST_CHECK_EQUAL( expected->GetPosition(), pad->GetPosition() );
345 BOOST_CHECK_EQUAL( expected->GetSize( PADSTACK::ALL_LAYERS ),
346 pad->GetSize( PADSTACK::ALL_LAYERS ) );
347 BOOST_CHECK_EQUAL( expected->GetOrientation(), pad->GetOrientation() );
348 BOOST_CHECK_EQUAL( expected->GetDelta( PADSTACK::ALL_LAYERS ),
349 pad->GetDelta( PADSTACK::ALL_LAYERS ) );
350 BOOST_CHECK_EQUAL( expected->GetOffset( PADSTACK::ALL_LAYERS ),
351 pad->GetOffset( PADSTACK::ALL_LAYERS ) );
352 BOOST_CHECK_EQUAL( expected->GetDrillSize(), pad->GetDrillSize() );
353 CHECK_ENUM_CLASS_EQUAL( expected->GetDrillShape(), pad->GetDrillShape() );
354
355 BOOST_CHECK_EQUAL( expected->GetLayerSet(), pad->GetLayerSet() );
356
357 BOOST_CHECK_EQUAL( expected->GetNetCode(), pad->GetNetCode() );
358 BOOST_CHECK_EQUAL( expected->GetPinFunction(), pad->GetPinFunction() );
359 BOOST_CHECK_EQUAL( expected->GetPinType(), pad->GetPinType() );
360 BOOST_CHECK_EQUAL( expected->GetPadToDieLength(), pad->GetPadToDieLength() );
361 BOOST_CHECK_EQUAL( expected->GetLocalSolderMaskMargin().value_or( 0 ),
362 pad->GetLocalSolderMaskMargin().value_or( 0 ) );
363 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMargin().value_or( 0 ),
364 pad->GetLocalSolderPasteMargin().value_or( 0 ) );
365 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMarginRatio().value_or( 0 ),
366 pad->GetLocalSolderPasteMarginRatio().value_or( 0 ) );
367 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
368 pad->GetLocalClearance().value_or( 0 ) );
369 CHECK_ENUM_CLASS_EQUAL( expected->GetLocalZoneConnection(), pad->GetLocalZoneConnection() );
370 BOOST_CHECK_EQUAL( expected->GetThermalSpokeWidth(), pad->GetThermalSpokeWidth() );
371 BOOST_CHECK_EQUAL( expected->GetThermalSpokeAngle(), pad->GetThermalSpokeAngle() );
372 BOOST_CHECK_EQUAL( expected->GetThermalGap(), pad->GetThermalGap() );
373 BOOST_CHECK_EQUAL( expected->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ),
374 pad->GetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS ) );
375 BOOST_CHECK_EQUAL( expected->GetChamferRectRatio( PADSTACK::ALL_LAYERS ),
376 pad->GetChamferRectRatio( PADSTACK::ALL_LAYERS ) );
377 BOOST_CHECK_EQUAL( expected->GetChamferPositions( PADSTACK::ALL_LAYERS ),
378 pad->GetChamferPositions( PADSTACK::ALL_LAYERS ) );
379 BOOST_CHECK_EQUAL( expected->GetRemoveUnconnected(), pad->GetRemoveUnconnected() );
380 BOOST_CHECK_EQUAL( expected->GetKeepTopBottom(), pad->GetKeepTopBottom() );
381
382 // TODO: did we check everything for complex pad shapes?
384 pad->GetAnchorPadShape( PADSTACK::ALL_LAYERS ) );
385 CHECK_ENUM_CLASS_EQUAL( expected->GetCustomShapeInZoneOpt(),
386 pad->GetCustomShapeInZoneOpt() );
387
388 BOOST_CHECK_EQUAL( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(),
389 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() );
390
391 if( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size()
392 == pad->GetPrimitives( PADSTACK::ALL_LAYERS ).size() )
393 {
394 for( size_t i = 0; i < expected->GetPrimitives( PADSTACK::ALL_LAYERS ).size(); ++i )
395 {
396 CheckFpShape( expected->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get(),
397 pad->GetPrimitives( PADSTACK::ALL_LAYERS ).at( i ).get() );
398 }
399 }
400
401 }
402}
403
404
406{
407 BOOST_TEST_CONTEXT( "Assert PCB_TEXT with KIID=" << expected->m_Uuid.AsString() )
408 {
409 CHECK_ENUM_CLASS_EQUAL( expected->Type(), text->Type() );
410
411 BOOST_CHECK_EQUAL( expected->IsLocked(), text->IsLocked() );
412
413 BOOST_CHECK_EQUAL( expected->GetText(), text->GetText() );
414 BOOST_CHECK_EQUAL( expected->GetPosition(), text->GetPosition() );
415 BOOST_CHECK_EQUAL( expected->GetTextAngle(), text->GetTextAngle() );
416 BOOST_CHECK_EQUAL( expected->IsKeepUpright(), text->IsKeepUpright() );
417
418 BOOST_CHECK_EQUAL( expected->GetLayerSet(), text->GetLayerSet() );
419 BOOST_CHECK_EQUAL( expected->IsVisible(), text->IsVisible() );
420
421 BOOST_CHECK_EQUAL( expected->GetTextSize(), text->GetTextSize() );
422 BOOST_CHECK_EQUAL( expected->GetLineSpacing(), text->GetLineSpacing() );
423 BOOST_CHECK_EQUAL( expected->GetTextThickness(), text->GetTextThickness() );
424 BOOST_CHECK_EQUAL( expected->IsBold(), text->IsBold() );
425 BOOST_CHECK_EQUAL( expected->IsItalic(), text->IsItalic() );
426 BOOST_CHECK_EQUAL( expected->GetHorizJustify(), text->GetHorizJustify() );
427 BOOST_CHECK_EQUAL( expected->GetVertJustify(), text->GetVertJustify() );
428 BOOST_CHECK_EQUAL( expected->IsMirrored(), text->IsMirrored() );
429 BOOST_CHECK_EQUAL( expected->GetFontName(),
430 text->GetFontName() ); // TODO: bold/italic setting?
431
432 // TODO: render cache?
433 }
434}
435
436
437void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape )
438{
439 BOOST_TEST_CONTEXT( "Assert PCB_SHAPE with KIID=" << expected->m_Uuid.AsString() )
440 {
441 CHECK_ENUM_CLASS_EQUAL( expected->Type(), shape->Type() );
442
443 CHECK_ENUM_CLASS_EQUAL( expected->GetShape(), shape->GetShape() );
444
445 BOOST_CHECK_EQUAL( expected->IsLocked(), shape->IsLocked() );
446
447 BOOST_CHECK_EQUAL( expected->GetStart(), shape->GetStart() );
448 BOOST_CHECK_EQUAL( expected->GetEnd(), shape->GetEnd() );
449
450 if( expected->GetShape() == SHAPE_T::ARC )
451 {
452 // center and position might differ as they are calculated from start/mid/end -> compare mid instead
453 BOOST_CHECK_EQUAL( expected->GetArcMid(), shape->GetArcMid() );
454 }
455 else
456 {
457 BOOST_CHECK_EQUAL( expected->GetCenter(), shape->GetCenter() );
458 BOOST_CHECK_EQUAL( expected->GetPosition(), shape->GetPosition() );
459 }
460
461 BOOST_CHECK_EQUAL( expected->GetBezierC1(), shape->GetBezierC1() );
462 BOOST_CHECK_EQUAL( expected->GetBezierC2(), shape->GetBezierC2() );
463
464 CheckShapePolySet( &expected->GetPolyShape(), &shape->GetPolyShape() );
465
466 BOOST_CHECK_EQUAL( expected->GetLayerSet(), shape->GetLayerSet() );
467
468 BOOST_CHECK_EQUAL( expected->GetStroke().GetWidth(), shape->GetStroke().GetWidth() );
469 CHECK_ENUM_CLASS_EQUAL( expected->GetStroke().GetLineStyle(),
470 shape->GetStroke().GetLineStyle() );
471 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), shape->GetFillMode() );
472 }
473}
474
475
476void CheckFpZone( const ZONE* expected, const ZONE* zone )
477{
478 BOOST_TEST_CONTEXT( "Assert ZONE with KIID=" << expected->m_Uuid.AsString() )
479 {
480 CHECK_ENUM_CLASS_EQUAL( expected->Type(), zone->Type() );
481
482 BOOST_CHECK_EQUAL( expected->IsLocked(), zone->IsLocked() );
483
484 BOOST_CHECK_EQUAL( expected->GetNetCode(), zone->GetNetCode() );
485 BOOST_CHECK_EQUAL( expected->GetAssignedPriority(), zone->GetAssignedPriority() );
486 CHECK_ENUM_CLASS_EQUAL( expected->GetPadConnection(), zone->GetPadConnection() );
487 BOOST_CHECK_EQUAL( expected->GetLocalClearance().value_or( 0 ),
488 zone->GetLocalClearance().value_or( 0 ) );
489 BOOST_CHECK_EQUAL( expected->GetMinThickness(), zone->GetMinThickness() );
490
491 BOOST_CHECK_EQUAL( expected->GetLayerSet(), zone->GetLayerSet() );
492
493 BOOST_CHECK_EQUAL( expected->IsFilled(), zone->IsFilled() );
494 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), zone->GetFillMode() );
495 BOOST_CHECK_EQUAL( expected->GetHatchThickness(), zone->GetHatchThickness() );
496 BOOST_CHECK_EQUAL( expected->GetHatchGap(), zone->GetHatchGap() );
497 BOOST_CHECK_EQUAL( expected->GetHatchOrientation(), zone->GetHatchOrientation() );
498 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingLevel(), zone->GetHatchSmoothingLevel() );
499 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingValue(), zone->GetHatchSmoothingValue() );
500 BOOST_CHECK_EQUAL( expected->GetHatchBorderAlgorithm(), zone->GetHatchBorderAlgorithm() );
501 BOOST_CHECK_EQUAL( expected->GetHatchHoleMinArea(), zone->GetHatchHoleMinArea() );
502 BOOST_CHECK_EQUAL( expected->GetThermalReliefGap(), zone->GetThermalReliefGap() );
503 BOOST_CHECK_EQUAL( expected->GetThermalReliefSpokeWidth(),
505 BOOST_CHECK_EQUAL( expected->GetCornerSmoothingType(), zone->GetCornerSmoothingType() );
506 BOOST_CHECK_EQUAL( expected->GetCornerRadius(), zone->GetCornerRadius() );
507 CHECK_ENUM_CLASS_EQUAL( expected->GetIslandRemovalMode(), zone->GetIslandRemovalMode() );
508 BOOST_CHECK_EQUAL( expected->GetMinIslandArea(), zone->GetMinIslandArea() );
509
510 BOOST_CHECK_EQUAL( expected->GetIsRuleArea(), zone->GetIsRuleArea() );
511 BOOST_CHECK_EQUAL( expected->GetDoNotAllowCopperPour(), zone->GetDoNotAllowCopperPour() );
512 BOOST_CHECK_EQUAL( expected->GetDoNotAllowVias(), zone->GetDoNotAllowVias() );
513 BOOST_CHECK_EQUAL( expected->GetDoNotAllowTracks(), zone->GetDoNotAllowTracks() );
514 BOOST_CHECK_EQUAL( expected->GetDoNotAllowPads(), zone->GetDoNotAllowPads() );
515 BOOST_CHECK_EQUAL( expected->GetDoNotAllowFootprints(), zone->GetDoNotAllowFootprints() );
516
517 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
518 CHECK_ENUM_CLASS_EQUAL( expected->GetTeardropAreaType(), zone->GetTeardropAreaType() );
519 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
520
521 CheckShapePolySet( expected->Outline(), zone->Outline() );
522 // TODO: filled zones
523 }
524}
525
526
528{
529 BOOST_TEST_CONTEXT( "Assert SHAPE_POLY_SET" )
530 {
531 BOOST_CHECK_EQUAL( expected->OutlineCount(), polyset->OutlineCount() );
532 BOOST_CHECK_EQUAL( expected->TotalVertices(), polyset->TotalVertices() );
533
534 if( expected->OutlineCount() != polyset->OutlineCount() )
535 return; // don't check the rest
536
537 if( expected->TotalVertices() != polyset->TotalVertices() )
538 return; // don't check the rest
539
540 // TODO: check all outlines and holes (just checking outlines for now)
541 for( int i = 0; i < expected->OutlineCount(); ++i )
542 {
543 BOOST_TEST_CONTEXT( "Outline " << i )
544 {
545 BOOST_CHECK_EQUAL( expected->Outline( i ).ArcCount(),
546 polyset->Outline( i ).ArcCount() );
547 BOOST_CHECK_EQUAL( expected->Outline( i ).PointCount(),
548 polyset->Outline( i ).PointCount() );
549
550
551 if( expected->Outline( i ).PointCount() != polyset->Outline( i ).PointCount() )
552 return; // don't check the rest
553
554 for( int j = 0; j < expected->Outline( i ).PointCount(); ++j )
555 {
556 BOOST_CHECK_EQUAL( expected->Outline( i ).GetPoint( j ),
557 polyset->Outline( i ).GetPoint( j ) );
558 }
559 }
560 }
561 }
562}
563
564} // namespace KI_TEST
#define SKIP_CONNECTIVITY
Definition: board_commit.h:42
#define ZONE_FILL_OP
Definition: board_commit.h:43
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
Revert the commit by restoring the modified items state.
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:257
virtual bool IsLocked() const
Definition: board_item.cpp:75
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1412
const ZONES & Zones() const
Definition: board.h:335
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:187
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:213
FILL_T GetFillMode() const
Definition: eda_shape.h:114
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:286
SHAPE_T GetShape() const
Definition: eda_shape.h:132
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:210
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:796
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:1243
GROUPS & Groups()
Definition: footprint.h:215
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:220
PCB_FIELDS & Fields()
Definition: footprint.h:203
const wxString & GetValue() const
Definition: footprint.h:644
const wxString & GetReference() const
Definition: footprint.h:622
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
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:420
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:218
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)
Loads 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
Definition: stroke_params.h:89
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:92
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:73
int GetHatchBorderAlgorithm() const
Definition: zone.h:306
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:724
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:714
bool GetDoNotAllowVias() const
Definition: zone.h:732
bool GetDoNotAllowPads() const
Definition: zone.h:734
bool GetDoNotAllowTracks() const
Definition: zone.h:733
bool IsFilled() const
Definition: zone.h:264
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:753
SHAPE_POLY_SET * Outline()
Definition: zone.h:340
long long int GetMinIslandArea() const
Definition: zone.h:756
const wxString & GetZoneName() const
Definition: zone.h:135
int GetMinThickness() const
Definition: zone.h:273
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:270
int GetHatchThickness() const
Definition: zone.h:288
double GetHatchHoleMinArea() const
Definition: zone.h:303
int GetThermalReliefSpokeWidth() const
Definition: zone.h:217
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:294
bool GetDoNotAllowFootprints() const
Definition: zone.h:735
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:196
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
bool GetDoNotAllowCopperPour() const
Definition: zone.h:731
int GetHatchGap() const
Definition: zone.h:291
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:710
double GetHatchSmoothingValue() const
Definition: zone.h:300
int GetHatchSmoothingLevel() const
Definition: zone.h:297
unsigned int GetCornerRadius() const
Definition: zone.h:670
int GetCornerSmoothingType() const
Definition: zone.h:666
int GetThermalReliefGap() const
Definition: zone.h:206
unsigned GetAssignedPriority() const
Definition: zone.h:123
#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)
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 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
FOOTPRINT::cmp_drawings fp_comp
bool operator()(const BOARD_ITEM *itemA, const BOARD_ITEM *itemB) const
VECTOR3I expected(15, 30, 45)
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