28#include <wx/filename.h>
30#include <boost/test/unit_test.hpp>
45#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
46 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
63 auto path = std::filesystem::temp_directory_path() / aName;
66 BOOST_TEST_MESSAGE(
"Dumping board file: " <<
path.string() );
72 std::unique_ptr<BOARD>& aBoard )
76 aBoard->SetProject(
nullptr );
81 wxFileName projectFile( absPath +
".kicad_pro" );
82 wxFileName legacyProject( absPath +
".pro" );
83 std::string boardPath = absPath +
".kicad_pcb";
84 wxFileName rulesFile( absPath +
".kicad_dru" );
86 if( projectFile.Exists() )
87 aSettingsManager.
LoadProject( projectFile.GetFullPath() );
88 else if( legacyProject.Exists() )
89 aSettingsManager.
LoadProject( legacyProject.GetFullPath() );
91 BOOST_TEST_MESSAGE(
"Loading board file: " << boardPath );
98 BOOST_TEST_ERROR( ioe.
What() );
101 BOOST_REQUIRE( aBoard );
103 if( projectFile.Exists() || legacyProject.Exists() )
104 aBoard->SetProject( &aSettingsManager.
Prj() );
106 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
108 if( rulesFile.Exists() )
109 m_DRCEngine->InitEngine( rulesFile );
111 m_DRCEngine->InitEngine( wxFileName() );
113 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
114 aBoard->BuildListOfNets();
115 aBoard->BuildConnectivity();
123 BOOST_REQUIRE( item );
124 BOOST_REQUIRE_EQUAL( item->
Type(), aItemType );
131 std::function<
void(
BOARD& )> aBoardTestFunction,
132 std::optional<int> aExpectedBoardVersion )
134 const std::string absBoardPath =
137 BOOST_TEST_MESSAGE(
"Loading board to test: " << absBoardPath );
141 BOOST_REQUIRE( board1 );
143 BOOST_TEST_MESSAGE(
"Testing loaded board" );
144 aBoardTestFunction( *board1 );
148 if( aExpectedBoardVersion )
150 BOOST_CHECK_EQUAL( board1->GetFileFormatVersionAtLoad(), *aExpectedBoardVersion );
155 const auto savePath = std::filesystem::temp_directory_path()
156 / ( aRelativePath.ToStdString() +
".kicad_pcb" );
162 BOOST_REQUIRE( board2 );
164 BOOST_TEST_MESSAGE(
"Testing roundtripped (saved/reloaded) file" );
165 aBoardTestFunction( *board2 );
173 toolMgr.
SetEnvironment( m_board,
nullptr,
nullptr,
nullptr,
nullptr );
180 std::vector<ZONE*> toFill;
183 toFill.push_back( zone );
185 if( filler.
Fill( toFill,
false,
nullptr ) )
192#define TEST( a, b ) \
197#define TEST_PT( a, b ) \
226 return fp_comp( itemA, itemB );
249 BOOST_CHECK_EQUAL(
expected->Fields().size(), fp->
Fields().size() );
250 BOOST_CHECK_EQUAL(
expected->Pads().size(), fp->
Pads().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() );
256 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads(
expected->Pads().begin(),
258 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->
Pads().begin(), fp->
Pads().end() );
260 for(
auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
261 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
266 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems(
expected->GraphicalItems().begin(),
268 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->
GraphicalItems().begin(),
271 for(
auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
272 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
273 itExpected++, itFp++ )
275 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
277 switch( ( *itExpected )->Type() )
306 BOOST_ERROR(
"KICAD_T not known" );
311 std::set<ZONE*, FOOTPRINT::cmp_zones> expectedZones(
expected->Zones().begin(),
313 std::set<ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->
Zones().begin(), fp->
Zones().end() );
315 for(
auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
316 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
332 BOOST_TEST_CONTEXT(
"Assert PAD with KIID=" <<
expected->m_Uuid.AsString() )
336 BOOST_CHECK_EQUAL(
expected->GetNumber(),
pad->GetNumber() );
342 BOOST_CHECK_EQUAL(
expected->IsLocked(),
pad->IsLocked() );
344 BOOST_CHECK_EQUAL(
expected->GetPosition(),
pad->GetPosition() );
347 BOOST_CHECK_EQUAL(
expected->GetOrientation(),
pad->GetOrientation() );
352 BOOST_CHECK_EQUAL(
expected->GetDrillSize(),
pad->GetDrillSize() );
355 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
pad->GetLayerSet() );
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 ) );
370 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeWidth(),
pad->GetThermalSpokeWidth() );
371 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeAngle(),
pad->GetThermalSpokeAngle() );
372 BOOST_CHECK_EQUAL(
expected->GetThermalGap(),
pad->GetThermalGap() );
379 BOOST_CHECK_EQUAL(
expected->GetRemoveUnconnected(),
pad->GetRemoveUnconnected() );
380 BOOST_CHECK_EQUAL(
expected->GetKeepTopBottom(),
pad->GetKeepTopBottom() );
386 pad->GetCustomShapeInZoneOpt() );
407 BOOST_TEST_CONTEXT(
"Assert PCB_TEXT with KIID=" <<
expected->m_Uuid.AsString() )
411 BOOST_CHECK_EQUAL(
expected->IsLocked(),
text->IsLocked() );
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() );
418 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
text->GetLayerSet() );
419 BOOST_CHECK_EQUAL(
expected->IsVisible(),
text->IsVisible() );
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() );
439 BOOST_TEST_CONTEXT(
"Assert PCB_SHAPE with KIID=" <<
expected->m_Uuid.AsString() )
450 if(
expected->GetShape() == SHAPE_T::ARC )
478 BOOST_TEST_CONTEXT(
"Assert ZONE with KIID=" <<
expected->m_Uuid.AsString() )
487 BOOST_CHECK_EQUAL(
expected->GetLocalClearance().value_or( 0 ),
503 BOOST_CHECK_EQUAL(
expected->GetThermalReliefSpokeWidth(),
529 BOOST_TEST_CONTEXT(
"Assert SHAPE_POLY_SET" )
541 for(
int i = 0; i <
expected->OutlineCount(); ++i )
543 BOOST_TEST_CONTEXT(
"Outline " << i )
545 BOOST_CHECK_EQUAL(
expected->Outline( i ).ArcCount(),
547 BOOST_CHECK_EQUAL(
expected->Outline( i ).PointCount(),
554 for(
int j = 0; j <
expected->Outline( i ).PointCount(); ++j )
556 BOOST_CHECK_EQUAL(
expected->Outline( i ).GetPoint( j ),
#define SKIP_CONNECTIVITY
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...
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
virtual bool IsLocked() const
Information pertinent to a Pcbnew printed circuit board.
BOARD_ITEM * GetItem(const KIID &aID) const
const ZONES & Zones() const
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
KICAD_T Type() const
Returns the type of object.
const VECTOR2I & GetBezierC2() const
FILL_T GetFillMode() const
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
const VECTOR2I & GetBezierC1() const
VECTOR2I GetArcMid() const
const EDA_ANGLE & GetTextAngle() const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
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.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
STROKE_PARAMS GetStroke() const override
VECTOR2I GetPosition() const override
virtual VECTOR2I GetPosition() const override
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.
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.
LINE_STYLE GetLineStyle() const
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.
int GetHatchBorderAlgorithm() const
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
std::optional< int > GetLocalClearance() const override
bool GetDoNotAllowVias() const
bool GetDoNotAllowPads() const
bool GetDoNotAllowTracks() const
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
SHAPE_POLY_SET * Outline()
long long int GetMinIslandArea() const
const wxString & GetZoneName() const
int GetMinThickness() const
ZONE_CONNECTION GetPadConnection() const
int GetHatchThickness() const
double GetHatchHoleMinArea() const
int GetThermalReliefSpokeWidth() const
EDA_ANGLE GetHatchOrientation() const
bool GetDoNotAllowFootprints() const
ZONE_FILL_MODE GetFillMode() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool GetDoNotAllowCopperPour() const
TEARDROP_TYPE GetTeardropAreaType() const
double GetHatchSmoothingValue() const
int GetHatchSmoothingLevel() const
unsigned int GetCornerRadius() const
int GetCornerSmoothingType() const
int GetThermalReliefGap() const
unsigned GetAssignedPriority() const
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.
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.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension