30#include <boost/test/unit_test.hpp>
31#include <boost/uuid/uuid_generators.hpp>
32#include <boost/uuid/uuid_io.hpp>
33#include <boost/uuid/uuid.hpp>
61 if( wxFileName::Exists( f_path ) )
63 if( !wxRemoveFile( f_path ) )
87 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
88 wxString& aTempBoardStemName );
110 m_board = std::make_unique<BOARD>();
116 boost::uuids::uuid uuid = boost::uuids::random_generator()();
117 return boost::uuids::to_string( uuid );
121 int aExpectedInitialExclusions )
124 BOOST_REQUIRE_MESSAGE(
m_board,
125 "Could not load board " + aBoardNameStem );
127 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
134 BOOST_CHECK_EQUAL( initialExclusionsCount, (
size_t) aExpectedInitialExclusions );
135 BOOST_TEST_MESSAGE(
"Initial DRC exclusion comments count: " << initialExclusionsCommentsCount );
136 BOOST_CHECK_EQUAL( initialExclusionsCommentsCount, (
size_t) aExpectedInitialExclusions );
142 std::vector<PCB_MARKER*> markers;
150 markers.push_back( marker );
155 size_t initialExclusionsCount = markers.size();
157 BOOST_TEST_MESSAGE( std::string(
"Actual DRC exclusions count: " ) + std::to_string( actualExclusionsCount )
158 +
" after adding initial markers." );
162 int aInitialExclusions )
164 for(
int i = 0; i < aAdditionalExclusions; ++i )
169 drcItem->SetItems(
KIID( id1 ),
KIID( id2 ) );
177 marker->
SetExcluded(
true, wxString::Format(
"Exclusion %d", i ) );
182 m_board->RecordDRCExclusions();
186 const int expectedExclusions =
187 aInitialExclusions + aAdditionalExclusions / 2;
189 BOOST_TEST_MESSAGE( std::string(
"New actual DRC exclusions count: " ) + std::to_string( newActualExclusionsCount )
190 +
" after adding unconnected items." );
192 return expectedExclusions;
200 m_board->RecordDRCExclusions();
202 bool runDRCOnAllLayers =
true;
204 m_board->ResolveDRCExclusions(
false );
209 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
210 wxString& aTempBoardStemName )
212 wxString tempPrefix =
"tmp_test_drc_";
213 aTempBoardStemName = tempPrefix + aBoardNameStem.ToStdString();
215 aCleaner.
AddFile( aTempBoardFullPath );
216 wxString tempProjectStemName = tempPrefix + aBoardNameStem.ToStdString();
218 aCleaner.
AddFile( aTempProjectFullPath );
221 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << aTempBoardFullPath );
224 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( aTempProjectFullPath ),
225 "Save project to temporary file: " << aTempProjectFullPath );
234 BOOST_REQUIRE_MESSAGE(
m_board,
"Could not load board from tempfile:"
235 + aTempBoardStemName );
237 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
250 pi->SaveBoard( filename, board,
nullptr );
264 std::vector<std::pair<wxString, int>> tests = {
265 {
"issue17429", 10 },
268 const int NUM_DRC_RUNS = 2;
270 for(
const std::pair<wxString, int>& test_params : tests )
272 wxString boardNameStem = test_params.first;
273 int expectedInitialExclusions = test_params.second;
275 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
276 createAndVerifyInitialExclusionMarkers();
277 const int additionalExclusions = 5;
278 int expectedExclusions =
279 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
284 BOOST_TEST_MESSAGE( std::string(
"DRC exclusions count after DRC run: " ) + std::to_string( expectedExclusions )
285 +
" after adding unconnected items." );
292 namespace fs = std::filesystem;
297 std::vector<std::pair<wxString, int>> tests = {
298 {
"issue17429", 10 },
302 for(
const std::pair<wxString, int>& test_params : tests )
305 wxString boardNameStem = test_params.first;
306 int expectedInitialExclusions = test_params.second;
308 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
310 wxString tempBoardFullPath, tempProjectFullPath, tempBoardStemName;
311 saveBoardAndProjectToTempFiles( boardNameStem, tempFileCleaner, tempBoardFullPath, tempProjectFullPath,
314 createAndVerifyInitialExclusionMarkers();
316 const int additionalExclusions = 5;
317 int expectedExclusions =
318 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
320 bool boardSaved = SaveBoardToFile( m_board->GetBoard(), tempBoardFullPath );
321 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << tempBoardFullPath );
323 m_settingsManager.SaveProjectAs( tempProjectFullPath, m_board->GetProject() );
324 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( tempProjectFullPath ),
325 "Save project to temporary file: " << tempProjectFullPath );
327 reloadBoardAndVerifyExclusions( tempBoardStemName, expectedExclusions );
General utilities for PCB file IO for QA programs.
Container for design settings for a BOARD object.
std::map< wxString, wxString > m_DrcExclusionComments
std::shared_ptr< DRC_ENGINE > m_DRCEngine
std::set< wxString > m_DrcExclusions
Information pertinent to a Pcbnew printed circuit board.
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
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 SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
@ KICAD_SEXP
S-expression Pcbnew file format.
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
static PCB_MARKER * DeserializeFromString(const wxString &data)
Container for project specific data.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
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)
std::string generate_uuid()
void saveBoardAndProjectToTempFiles(const wxString &aBoardNameStem, FileCleaner &aCleaner, wxString &aTempBoardFullPath, wxString &aTempProjectFullPath, wxString &aTempBoardStemName)
std::unique_ptr< BOARD > m_board
int createAndVerifyAdditionalUnconnectedExclusions(int aAdditionalExclusions, int aInitialExclusions)
void createAndVerifyInitialExclusionMarkers()
void reloadBoardAndVerifyExclusions(const wxString &aTempBoardStemName, int aExpectedExclusions)
void loadBoardAndVerifyInitialExclusions(const wxString &aBoardNameStem, int aExpectedInitialExclusions)
SETTINGS_MANAGER m_settingsManager
bool SaveBoardToFile(BOARD *board, const wxString &filename)
DRC_REGRESSION_TEST_FIXTURE()
std::unique_ptr< BOARD > m_board
DRC_UNCONNECTED_SAVE_FIXTURE()
void AddFile(const wxString &f_path)
std::vector< wxString > m_files_to_delete
BOOST_FIXTURE_TEST_CASE(DRCUnconnectedExclusionsLoss, DRC_UNCONNECTED_SAVE_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I