28#include <wx/filename.h>
40#include <boost/test/unit_test.hpp>
43#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
44 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
61 auto path = std::filesystem::temp_directory_path() / aName;
64 BOOST_TEST_MESSAGE(
"Dumping board file: " <<
path.string() );
70 std::unique_ptr<BOARD>& aBoard )
74 aBoard->SetProject(
nullptr );
79 wxFileName projectFile( absPath +
".kicad_pro" );
80 wxFileName legacyProject( absPath +
".pro" );
81 std::string boardPath = absPath +
".kicad_pcb";
82 wxFileName rulesFile( absPath +
".kicad_dru" );
84 if( projectFile.Exists() )
85 aSettingsManager.
LoadProject( projectFile.GetFullPath() );
86 else if( legacyProject.Exists() )
87 aSettingsManager.
LoadProject( legacyProject.GetFullPath() );
91 if( projectFile.Exists() || legacyProject.Exists() )
92 aBoard->SetProject( &aSettingsManager.
Prj() );
94 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
96 if( rulesFile.Exists() )
97 m_DRCEngine->InitEngine( rulesFile );
99 m_DRCEngine->InitEngine( wxFileName() );
101 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
102 aBoard->BuildListOfNets();
103 aBoard->BuildConnectivity();
110 toolMgr.
SetEnvironment( m_board,
nullptr,
nullptr,
nullptr,
nullptr );
117 std::vector<ZONE*> toFill;
120 toFill.push_back( zone );
122 if( filler.
Fill( toFill,
false,
nullptr ) )
129#define TEST( a, b ) \
134#define TEST_PT( a, b ) \
163 return fp_comp( itemA, itemB );
186 BOOST_CHECK_EQUAL(
expected->Fields().size(), fp->
Fields().size() );
187 BOOST_CHECK_EQUAL(
expected->Pads().size(), fp->
Pads().size() );
189 BOOST_CHECK_EQUAL(
expected->Zones().size(), fp->
Zones().size() );
190 BOOST_CHECK_EQUAL(
expected->Groups().size(), fp->
Groups().size() );
191 BOOST_CHECK_EQUAL(
expected->Models().size(), fp->
Models().size() );
193 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads(
expected->Pads().begin(),
195 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->
Pads().begin(), fp->
Pads().end() );
197 for(
auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
198 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
203 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems(
expected->GraphicalItems().begin(),
205 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->
GraphicalItems().begin(),
208 for(
auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
209 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
210 itExpected++, itFp++ )
212 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
214 switch( ( *itExpected )->Type() )
243 BOOST_ERROR(
"KICAD_T not known" );
248 std::set<ZONE*, FOOTPRINT::cmp_zones> expectedZones(
expected->Zones().begin(),
250 std::set<ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->
Zones().begin(), fp->
Zones().end() );
252 for(
auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
253 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
268 BOOST_CHECK_EQUAL(
expected->GetNumber(),
pad->GetNumber() );
273 BOOST_CHECK_EQUAL(
expected->IsLocked(),
pad->IsLocked() );
275 BOOST_CHECK_EQUAL(
expected->GetPosition(),
pad->GetPosition() );
276 BOOST_CHECK_EQUAL(
expected->GetSize(),
pad->GetSize() );
277 BOOST_CHECK_EQUAL(
expected->GetOrientation(),
pad->GetOrientation() );
278 BOOST_CHECK_EQUAL(
expected->GetDelta(),
pad->GetDelta() );
279 BOOST_CHECK_EQUAL(
expected->GetOffset(),
pad->GetOffset() );
280 BOOST_CHECK_EQUAL(
expected->GetDrillSize(),
pad->GetDrillSize() );
283 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
pad->GetLayerSet() );
285 BOOST_CHECK_EQUAL(
expected->GetNetCode(),
pad->GetNetCode() );
286 BOOST_CHECK_EQUAL(
expected->GetPinFunction(),
pad->GetPinFunction() );
287 BOOST_CHECK_EQUAL(
expected->GetPinType(),
pad->GetPinType() );
288 BOOST_CHECK_EQUAL(
expected->GetPadToDieLength(),
pad->GetPadToDieLength() );
289 BOOST_CHECK_EQUAL(
expected->GetLocalSolderMaskMargin(),
pad->GetLocalSolderMaskMargin() );
290 BOOST_CHECK_EQUAL(
expected->GetLocalSolderPasteMargin(),
291 pad->GetLocalSolderPasteMargin() );
292 BOOST_CHECK_EQUAL(
expected->GetLocalSolderPasteMarginRatio(),
293 pad->GetLocalSolderPasteMarginRatio() );
294 BOOST_CHECK_EQUAL(
expected->GetLocalClearance(),
pad->GetLocalClearance() );
296 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeWidth(),
pad->GetThermalSpokeWidth() );
297 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeAngle(),
pad->GetThermalSpokeAngle() );
298 BOOST_CHECK_EQUAL(
expected->GetThermalGap(),
pad->GetThermalGap() );
299 BOOST_CHECK_EQUAL(
expected->GetRoundRectRadiusRatio(),
pad->GetRoundRectRadiusRatio() );
300 BOOST_CHECK_EQUAL(
expected->GetChamferRectRatio(),
pad->GetChamferRectRatio() );
301 BOOST_CHECK_EQUAL(
expected->GetChamferPositions(),
pad->GetChamferPositions() );
302 BOOST_CHECK_EQUAL(
expected->GetRemoveUnconnected(),
pad->GetRemoveUnconnected() );
303 BOOST_CHECK_EQUAL(
expected->GetKeepTopBottom(),
pad->GetKeepTopBottom() );
308 pad->GetCustomShapeInZoneOpt() );
310 BOOST_CHECK_EQUAL(
expected->GetPrimitives().size(),
pad->GetPrimitives().size() );
312 if(
expected->GetPrimitives().size() ==
pad->GetPrimitives().size() )
314 for(
size_t i = 0; i <
expected->GetPrimitives().size(); ++i )
317 pad->GetPrimitives().at( i ).get() );
331 BOOST_CHECK_EQUAL(
expected->IsLocked(),
text->IsLocked() );
333 BOOST_CHECK_EQUAL(
expected->GetText(),
text->GetText() );
334 BOOST_CHECK_EQUAL(
expected->GetPosition(),
text->GetPosition() );
335 BOOST_CHECK_EQUAL(
expected->GetTextAngle(),
text->GetTextAngle() );
336 BOOST_CHECK_EQUAL(
expected->IsKeepUpright(),
text->IsKeepUpright() );
338 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
text->GetLayerSet() );
339 BOOST_CHECK_EQUAL(
expected->IsVisible(),
text->IsVisible() );
341 BOOST_CHECK_EQUAL(
expected->GetTextSize(),
text->GetTextSize() );
342 BOOST_CHECK_EQUAL(
expected->GetLineSpacing(),
text->GetLineSpacing() );
343 BOOST_CHECK_EQUAL(
expected->GetTextThickness(),
text->GetTextThickness() );
344 BOOST_CHECK_EQUAL(
expected->IsBold(),
text->IsBold() );
345 BOOST_CHECK_EQUAL(
expected->IsItalic(),
text->IsItalic() );
346 BOOST_CHECK_EQUAL(
expected->GetHorizJustify(),
text->GetHorizJustify() );
347 BOOST_CHECK_EQUAL(
expected->GetVertJustify(),
text->GetVertJustify() );
348 BOOST_CHECK_EQUAL(
expected->IsMirrored(),
text->IsMirrored() );
349 BOOST_CHECK_EQUAL(
expected->GetFontName(),
350 text->GetFontName() );
370 if(
expected->GetShape() == SHAPE_T::ARC )
422 BOOST_CHECK_EQUAL(
expected->GetThermalReliefSpokeWidth(),
460 for(
int i = 0; i <
expected->OutlineCount(); ++i )
464 BOOST_CHECK_EQUAL(
expected->Outline( i ).ArcCount(),
466 BOOST_CHECK_EQUAL(
expected->Outline( i ).PointCount(),
473 for(
int j = 0; j <
expected->Outline( i ).PointCount(); ++j )
475 BOOST_CHECK_EQUAL(
expected->Outline( i ).GetPoint( j ),
General utilities for PCB file IO for QA programs.
#define CHECK_ENUM_CLASS_EQUAL(L, R)
virtual void Push(const wxString &aMessage=wxT("A commit"), 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.
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
void DumpBoardToFile(BOARD &aBoard, const std::string &aName) const
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
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.
PLOT_DASH_TYPE GetPlotStyle() const
bool Fill(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:
bool GetDoNotAllowVias() const
bool GetDoNotAllowPads() const
bool GetDoNotAllowTracks() const
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
SHAPE_POLY_SET * Outline()
long long int GetMinIslandArea() const
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
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 CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
#define SKIP_CONNECTIVITY
FOOTPRINT::cmp_drawings fp_comp
bool operator()(const BOARD_ITEM *itemA, const BOARD_ITEM *itemB) const
VECTOR3I expected(15, 30, 45)
@ 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
#define BOOST_TEST_CONTEXT(A)