31#include <boost/test/unit_test.hpp>
32#include <boost/uuid/uuid_generators.hpp>
33#include <boost/uuid/uuid_io.hpp>
34#include <boost/uuid/uuid.hpp>
63 if( wxFileName::Exists( f_path ) )
65 if( !wxRemoveFile( f_path ) )
89 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
90 wxString& aTempBoardStemName );
112 m_board = std::make_unique<BOARD>();
118 boost::uuids::uuid uuid = boost::uuids::random_generator()();
119 return boost::uuids::to_string( uuid );
123 int aExpectedInitialExclusions )
126 BOOST_REQUIRE_MESSAGE(
m_board,
127 "Could not load board " + aBoardNameStem );
129 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
136 BOOST_CHECK_EQUAL( initialExclusionsCount, (
size_t) aExpectedInitialExclusions );
137 BOOST_TEST_MESSAGE(
"Initial DRC exclusion comments count: " << initialExclusionsCommentsCount );
138 BOOST_CHECK_EQUAL( initialExclusionsCommentsCount, (
size_t) aExpectedInitialExclusions );
144 std::vector<PCB_MARKER*> markers;
152 markers.push_back( marker );
157 size_t initialExclusionsCount = markers.size();
159 BOOST_TEST_MESSAGE( std::string(
"Actual DRC exclusions count: " ) + std::to_string( actualExclusionsCount )
160 +
" after adding initial markers." );
164 int aInitialExclusions )
166 for(
int i = 0; i < aAdditionalExclusions; ++i )
171 drcItem->SetItems(
KIID( id1 ),
KIID( id2 ) );
179 marker->
SetExcluded(
true, wxString::Format(
"Exclusion %d", i ) );
184 m_board->RecordDRCExclusions();
188 const int expectedExclusions =
189 aInitialExclusions + aAdditionalExclusions / 2;
191 BOOST_TEST_MESSAGE( std::string(
"New actual DRC exclusions count: " ) + std::to_string( newActualExclusionsCount )
192 +
" after adding unconnected items." );
194 return expectedExclusions;
202 m_board->RecordDRCExclusions();
204 bool runDRCOnAllLayers =
true;
206 m_board->ResolveDRCExclusions(
false );
211 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
212 wxString& aTempBoardStemName )
214 wxString tempPrefix =
"tmp_test_drc_";
215 aTempBoardStemName = tempPrefix + aBoardNameStem.ToStdString();
217 aCleaner.
AddFile( aTempBoardFullPath );
218 wxString tempProjectStemName = tempPrefix + aBoardNameStem.ToStdString();
220 aCleaner.
AddFile( aTempProjectFullPath );
223 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << aTempBoardFullPath );
226 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( aTempProjectFullPath ),
227 "Save project to temporary file: " << aTempProjectFullPath );
236 BOOST_REQUIRE_MESSAGE(
m_board,
"Could not load board from tempfile:"
237 + aTempBoardStemName );
239 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
252 pi->SaveBoard( filename, board,
nullptr );
266 std::vector<std::pair<wxString, int>> tests = {
267 {
"issue17429", 10 },
270 const int NUM_DRC_RUNS = 2;
272 for(
const std::pair<wxString, int>& test_params : tests )
274 wxString boardNameStem = test_params.first;
275 int expectedInitialExclusions = test_params.second;
277 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
278 createAndVerifyInitialExclusionMarkers();
279 const int additionalExclusions = 5;
280 int expectedExclusions =
281 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
286 BOOST_TEST_MESSAGE( std::string(
"DRC exclusions count after DRC run: " ) + std::to_string( expectedExclusions )
287 +
" after adding unconnected items." );
294 namespace fs = std::filesystem;
299 std::vector<std::pair<wxString, int>> tests = {
300 {
"issue17429", 10 },
304 for(
const std::pair<wxString, int>& test_params : tests )
307 wxString boardNameStem = test_params.first;
308 int expectedInitialExclusions = test_params.second;
310 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
312 wxString tempBoardFullPath, tempProjectFullPath, tempBoardStemName;
313 saveBoardAndProjectToTempFiles( boardNameStem, tempFileCleaner, tempBoardFullPath, tempProjectFullPath,
316 createAndVerifyInitialExclusionMarkers();
318 const int additionalExclusions = 5;
319 int expectedExclusions =
320 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
322 bool boardSaved = SaveBoardToFile( m_board->GetBoard(), tempBoardFullPath );
323 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << tempBoardFullPath );
325 m_settingsManager.SaveProjectAs( tempProjectFullPath, m_board->GetProject() );
326 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( tempProjectFullPath ),
327 "Save project to temporary file: " << tempProjectFullPath );
329 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