26#include <wx/filename.h>
39#include <boost/filesystem.hpp>
40#include <boost/test/unit_test.hpp>
44#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
45 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
52 m_dump_boards(
std::getenv(
"KICAD_TEST_DUMP_BOARD_FILES" ) )
62 auto path = boost::filesystem::temp_directory_path() / aName;
65 BOOST_TEST_MESSAGE(
"Dumping board file: " <<
path.string() );
71 std::unique_ptr<BOARD>& aBoard )
75 aBoard->SetProject(
nullptr );
80 wxFileName projectFile( absPath +
".kicad_pro" );
81 wxFileName legacyProject( absPath +
".pro" );
82 std::string boardPath = absPath +
".kicad_pcb";
83 wxFileName rulesFile( absPath +
".kicad_dru" );
85 if( projectFile.Exists() )
86 aSettingsManager.
LoadProject( projectFile.GetFullPath() );
87 else if( legacyProject.Exists() )
88 aSettingsManager.
LoadProject( legacyProject.GetFullPath() );
92 if( projectFile.Exists() || legacyProject.Exists() )
93 aBoard->SetProject( &aSettingsManager.
Prj() );
95 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
97 if( rulesFile.Exists() )
98 m_DRCEngine->InitEngine( rulesFile );
100 m_DRCEngine->InitEngine( wxFileName() );
102 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
103 aBoard->BuildListOfNets();
104 aBoard->BuildConnectivity();
111 toolMgr.
SetEnvironment( m_board,
nullptr,
nullptr,
nullptr,
nullptr );
115 std::vector<ZONE*> toFill;
118 toFill.push_back( zone );
120 if( filler.
Fill( toFill,
false,
nullptr ) )
127#define TEST( a, b ) \
132#define TEST_PT( a, b ) \
162 return fp_comp( itemA, itemB );
185 BOOST_CHECK_EQUAL(
expected->Pads().size(), fp->
Pads().size() );
187 BOOST_CHECK_EQUAL(
expected->Zones().size(), fp->
Zones().size() );
188 BOOST_CHECK_EQUAL(
expected->Groups().size(), fp->
Groups().size() );
189 BOOST_CHECK_EQUAL(
expected->Models().size(), fp->
Models().size() );
191 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads(
expected->Pads().begin(),
193 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->
Pads().begin(), fp->
Pads().end() );
194 for(
auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
195 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
200 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems(
202 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->
GraphicalItems().begin(),
204 for(
auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
205 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
206 itExpected++, itFp++ )
208 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
209 switch( ( *itExpected )->Type() )
213 const FP_TEXT* expectedText =
static_cast<const FP_TEXT*
>( *itExpected );
221 const FP_SHAPE* expectedShape =
static_cast<const FP_SHAPE*
>( *itExpected );
232 default: BOOST_ERROR(
"KICAD_T not known" );
break;
236 std::set<FP_ZONE*, FOOTPRINT::cmp_zones> expectedZones(
expected->Zones().begin(),
238 std::set<FP_ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->
Zones().begin(), fp->
Zones().end() );
239 for(
auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
240 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
255 BOOST_CHECK_EQUAL(
expected->GetNumber(),
pad->GetNumber() );
260 BOOST_CHECK_EQUAL(
expected->IsLocked(),
pad->IsLocked() );
262 BOOST_CHECK_EQUAL(
expected->GetPosition(),
pad->GetPosition() );
263 BOOST_CHECK_EQUAL(
expected->GetSize(),
pad->GetSize() );
264 BOOST_CHECK_EQUAL(
expected->GetOrientation(),
pad->GetOrientation() );
265 BOOST_CHECK_EQUAL(
expected->GetDelta(),
pad->GetDelta() );
266 BOOST_CHECK_EQUAL(
expected->GetOffset(),
pad->GetOffset() );
267 BOOST_CHECK_EQUAL(
expected->GetDrillSize(),
pad->GetDrillSize() );
270 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
pad->GetLayerSet() );
272 BOOST_CHECK_EQUAL(
expected->GetNetCode(),
pad->GetNetCode() );
273 BOOST_CHECK_EQUAL(
expected->GetPinFunction(),
pad->GetPinFunction() );
274 BOOST_CHECK_EQUAL(
expected->GetPinType(),
pad->GetPinType() );
275 BOOST_CHECK_EQUAL(
expected->GetPadToDieLength(),
pad->GetPadToDieLength() );
276 BOOST_CHECK_EQUAL(
expected->GetLocalSolderMaskMargin(),
pad->GetLocalSolderMaskMargin() );
277 BOOST_CHECK_EQUAL(
expected->GetLocalSolderPasteMargin(),
278 pad->GetLocalSolderPasteMargin() );
279 BOOST_CHECK_EQUAL(
expected->GetLocalSolderPasteMarginRatio(),
280 pad->GetLocalSolderPasteMarginRatio() );
281 BOOST_CHECK_EQUAL(
expected->GetLocalClearance(),
pad->GetLocalClearance() );
283 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeWidth(),
pad->GetThermalSpokeWidth() );
284 BOOST_CHECK_EQUAL(
expected->GetThermalSpokeAngle(),
pad->GetThermalSpokeAngle() );
285 BOOST_CHECK_EQUAL(
expected->GetThermalGap(),
pad->GetThermalGap() );
286 BOOST_CHECK_EQUAL(
expected->GetRoundRectRadiusRatio(),
pad->GetRoundRectRadiusRatio() );
287 BOOST_CHECK_EQUAL(
expected->GetChamferRectRatio(),
pad->GetChamferRectRatio() );
288 BOOST_CHECK_EQUAL(
expected->GetChamferPositions(),
pad->GetChamferPositions() );
289 BOOST_CHECK_EQUAL(
expected->GetRemoveUnconnected(),
pad->GetRemoveUnconnected() );
290 BOOST_CHECK_EQUAL(
expected->GetKeepTopBottom(),
pad->GetKeepTopBottom() );
295 pad->GetCustomShapeInZoneOpt() );
308 BOOST_CHECK_EQUAL(
expected->IsLocked(),
text->IsLocked() );
310 BOOST_CHECK_EQUAL(
expected->GetText(),
text->GetText() );
311 BOOST_CHECK_EQUAL(
expected->GetPosition(),
text->GetPosition() );
312 BOOST_CHECK_EQUAL(
expected->GetTextAngle(),
text->GetTextAngle() );
313 BOOST_CHECK_EQUAL(
expected->IsKeepUpright(),
text->IsKeepUpright() );
315 BOOST_CHECK_EQUAL(
expected->GetLayerSet(),
text->GetLayerSet() );
316 BOOST_CHECK_EQUAL(
expected->IsVisible(),
text->IsVisible() );
318 BOOST_CHECK_EQUAL(
expected->GetTextSize(),
text->GetTextSize() );
319 BOOST_CHECK_EQUAL(
expected->GetLineSpacing(),
text->GetLineSpacing() );
320 BOOST_CHECK_EQUAL(
expected->GetTextThickness(),
text->GetTextThickness() );
321 BOOST_CHECK_EQUAL(
expected->IsBold(),
text->IsBold() );
322 BOOST_CHECK_EQUAL(
expected->IsItalic(),
text->IsItalic() );
323 BOOST_CHECK_EQUAL(
expected->GetHorizJustify(),
text->GetHorizJustify() );
324 BOOST_CHECK_EQUAL(
expected->GetVertJustify(),
text->GetVertJustify() );
325 BOOST_CHECK_EQUAL(
expected->IsMirrored(),
text->IsMirrored() );
326 BOOST_CHECK_EQUAL(
expected->GetFontName(),
327 text->GetFontName() );
397 BOOST_CHECK_EQUAL(
expected->GetThermalReliefSpokeWidth(),
#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=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
virtual VECTOR2I GetPosition() const override
TEXT_TYPE GetType() const
A specialization of ZONE for use in footprints.
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
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.
Represent a set of closed polygons.
int TotalVertices() const
Delete aIdx-th polygon from the set.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
bool GetDoNotAllowPads() const
bool GetDoNotAllowTracks() const
SHAPE_POLY_SET * Outline()
long long int GetMinIslandArea() const
wxString GetZoneName() const
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
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)
void CheckFpZone(const FP_ZONE *expected, const FP_ZONE *zone)
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
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 CheckFpShape(const FP_SHAPE *expected, const FP_SHAPE *shape)
void CheckFpText(const FP_TEXT *expected, const FP_TEXT *text)
void CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
FOOTPRINT::cmp_drawings fp_comp
bool operator()(const BOARD_ITEM *itemA, const BOARD_ITEM *itemB) const
VECTOR3I expected(15, 30, 45)
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
#define BOOST_TEST_CONTEXT(A)