27#include <boost/test/unit_test.hpp>
28#include <boost/uuid/uuid_generators.hpp>
29#include <boost/uuid/uuid_io.hpp>
30#include <boost/uuid/uuid.hpp>
59 if( wxFileName::Exists( f_path ) )
61 if( !wxRemoveFile( f_path ) )
85 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
86 wxString& aTempBoardStemName );
108 m_board = std::make_unique<BOARD>();
114 boost::uuids::uuid uuid = boost::uuids::random_generator()();
115 return boost::uuids::to_string( uuid );
119 int aExpectedInitialExclusions )
122 BOOST_REQUIRE_MESSAGE(
m_board,
123 "Could not load board " + aBoardNameStem );
125 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
132 BOOST_CHECK_EQUAL( initialExclusionsCount, (
size_t) aExpectedInitialExclusions );
133 BOOST_TEST_MESSAGE(
"Initial DRC exclusion comments count: " << initialExclusionsCommentsCount );
134 BOOST_CHECK_EQUAL( initialExclusionsCommentsCount, (
size_t) aExpectedInitialExclusions );
140 std::vector<PCB_MARKER*> markers;
148 markers.push_back( marker );
153 size_t initialExclusionsCount = markers.size();
155 BOOST_TEST_MESSAGE( std::string(
"Actual DRC exclusions count: " ) + std::to_string( actualExclusionsCount )
156 +
" after adding initial markers." );
160 int aInitialExclusions )
162 for(
int i = 0; i < aAdditionalExclusions; ++i )
167 drcItem->SetItems(
KIID( id1 ),
KIID( id2 ) );
175 marker->
SetExcluded(
true, wxString::Format(
"Exclusion %d", i ) );
180 m_board->RecordDRCExclusions();
184 const int expectedExclusions =
185 aInitialExclusions + aAdditionalExclusions / 2;
187 BOOST_TEST_MESSAGE( std::string(
"New actual DRC exclusions count: " ) + std::to_string( newActualExclusionsCount )
188 +
" after adding unconnected items." );
190 return expectedExclusions;
198 m_board->RecordDRCExclusions();
200 bool runDRCOnAllLayers =
true;
202 m_board->ResolveDRCExclusions(
false );
207 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
208 wxString& aTempBoardStemName )
210 wxString tempPrefix =
"tmp_test_drc_";
211 aTempBoardStemName = tempPrefix + aBoardNameStem.ToStdString();
213 aCleaner.
AddFile( aTempBoardFullPath );
214 wxString tempProjectStemName = tempPrefix + aBoardNameStem.ToStdString();
216 aCleaner.
AddFile( aTempProjectFullPath );
219 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << aTempBoardFullPath );
222 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( aTempProjectFullPath ),
223 "Save project to temporary file: " << aTempProjectFullPath );
232 BOOST_REQUIRE_MESSAGE(
m_board,
"Could not load board from tempfile:"
233 + aTempBoardStemName );
235 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
248 pi->SaveBoard( filename, board,
nullptr );
262 std::vector<std::pair<wxString, int>> tests = {
263 {
"issue17429", 10 },
266 const int NUM_DRC_RUNS = 2;
268 for(
const std::pair<wxString, int>& test_params : tests )
270 wxString boardNameStem = test_params.first;
271 int expectedInitialExclusions = test_params.second;
273 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
274 createAndVerifyInitialExclusionMarkers();
275 const int additionalExclusions = 5;
276 int expectedExclusions =
277 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
282 BOOST_TEST_MESSAGE( std::string(
"DRC exclusions count after DRC run: " ) + std::to_string( expectedExclusions )
283 +
" after adding unconnected items." );
290 namespace fs = std::filesystem;
295 std::vector<std::pair<wxString, int>> tests = {
296 {
"issue17429", 10 },
300 for(
const std::pair<wxString, int>& test_params : tests )
303 wxString boardNameStem = test_params.first;
304 int expectedInitialExclusions = test_params.second;
306 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
308 wxString tempBoardFullPath, tempProjectFullPath, tempBoardStemName;
309 saveBoardAndProjectToTempFiles( boardNameStem, tempFileCleaner, tempBoardFullPath, tempProjectFullPath,
312 createAndVerifyInitialExclusionMarkers();
314 const int additionalExclusions = 5;
315 int expectedExclusions =
316 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
318 bool boardSaved = SaveBoardToFile( m_board->GetBoard(), tempBoardFullPath );
319 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << tempBoardFullPath );
321 m_settingsManager.SaveProjectAs( tempProjectFullPath, m_board->GetProject() );
322 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( tempProjectFullPath ),
323 "Save project to temporary file: " << tempProjectFullPath );
325 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("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I