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 ) )
88 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
89 wxString& aTempBoardStemName );
111 m_board = std::make_unique<BOARD>();
117 boost::uuids::uuid uuid = boost::uuids::random_generator()();
118 return boost::uuids::to_string( uuid );
122 int aExpectedInitialExclusions )
125 BOOST_REQUIRE_MESSAGE(
m_board,
126 "Could not load board " + aBoardNameStem );
128 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
135 BOOST_CHECK_EQUAL( initialExclusionsCount, (
size_t) aExpectedInitialExclusions );
136 BOOST_TEST_MESSAGE(
"Initial DRC exclusion comments count: " << initialExclusionsCommentsCount );
137 BOOST_CHECK_EQUAL( initialExclusionsCommentsCount, (
size_t) aExpectedInitialExclusions );
143 std::vector<PCB_MARKER*> markers;
151 markers.push_back( marker );
156 size_t initialExclusionsCount = markers.size();
158 BOOST_TEST_MESSAGE( std::string(
"Actual DRC exclusions count: " ) + std::to_string( actualExclusionsCount )
159 +
" after adding initial markers." );
163 int aInitialExclusions )
165 for(
int i = 0; i < aAdditionalExclusions; ++i )
170 drcItem->SetItems(
KIID( id1 ),
KIID( id2 ) );
178 marker->
SetExcluded(
true, wxString::Format(
"Exclusion %d", i ) );
183 m_board->RecordDRCExclusions();
187 const int expectedExclusions =
188 aInitialExclusions + aAdditionalExclusions / 2;
190 BOOST_TEST_MESSAGE( std::string(
"New actual DRC exclusions count: " ) + std::to_string( newActualExclusionsCount )
191 +
" after adding unconnected items." );
193 return expectedExclusions;
201 m_board->RecordDRCExclusions();
203 bool runDRCOnAllLayers =
true;
204 bds.
m_DRCEngine->RunTests( EDA_UNITS::MM, runDRC, runDRCOnAllLayers );
205 m_board->ResolveDRCExclusions(
false );
210 wxString& aTempBoardFullPath, wxString& aTempProjectFullPath,
211 wxString& aTempBoardStemName )
213 wxString tempPrefix =
"tmp_test_drc_";
214 aTempBoardStemName = tempPrefix + aBoardNameStem.ToStdString();
216 aCleaner.
AddFile( aTempBoardFullPath );
217 wxString tempProjectStemName = tempPrefix + aBoardNameStem.ToStdString();
219 aCleaner.
AddFile( aTempProjectFullPath );
222 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << aTempBoardFullPath );
225 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( aTempProjectFullPath ),
226 "Save project to temporary file: " << aTempProjectFullPath );
235 BOOST_REQUIRE_MESSAGE(
m_board,
"Could not load board from tempfile:"
236 + aTempBoardStemName );
238 BOOST_REQUIRE_MESSAGE( pcb_project,
"Get project pointer after initial loading." );
251 pi->SaveBoard( filename, board,
nullptr );
265 std::vector<std::pair<wxString, int>> tests = {
266 {
"issue17429", 10 },
269 const int NUM_DRC_RUNS = 2;
271 for(
const std::pair<wxString, int>& test_params : tests )
273 wxString boardNameStem = test_params.first;
274 int expectedInitialExclusions = test_params.second;
276 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
277 createAndVerifyInitialExclusionMarkers();
278 const int additionalExclusions = 5;
279 int expectedExclusions =
280 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
285 BOOST_TEST_MESSAGE( std::string(
"DRC exclusions count after DRC run: " ) + std::to_string( expectedExclusions )
286 +
" after adding unconnected items." );
293 namespace fs = std::filesystem;
298 std::vector<std::pair<wxString, int>> tests = {
299 {
"issue17429", 10 },
303 for(
const std::pair<wxString, int>& test_params : tests )
306 wxString boardNameStem = test_params.first;
307 int expectedInitialExclusions = test_params.second;
309 loadBoardAndVerifyInitialExclusions( boardNameStem, expectedInitialExclusions );
311 wxString tempBoardFullPath, tempProjectFullPath, tempBoardStemName;
312 saveBoardAndProjectToTempFiles( boardNameStem, tempFileCleaner, tempBoardFullPath, tempProjectFullPath,
315 createAndVerifyInitialExclusionMarkers();
317 const int additionalExclusions = 5;
318 int expectedExclusions =
319 createAndVerifyAdditionalUnconnectedExclusions( additionalExclusions, expectedInitialExclusions );
321 bool boardSaved = SaveBoardToFile( m_board->GetBoard(), tempBoardFullPath );
322 BOOST_REQUIRE_MESSAGE( boardSaved,
"Save board to temporary file: " << tempBoardFullPath );
324 m_settingsManager.SaveProjectAs( tempProjectFullPath, m_board->GetProject() );
325 BOOST_REQUIRE_MESSAGE( wxFileName::Exists( tempProjectFullPath ),
326 "Save project to temporary file: " << tempProjectFullPath );
328 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.
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)
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
@ KICAD_SEXP
S-expression Pcbnew file format.
static PCB_MARKER * DeserializeFromString(const wxString &data)
Container for project specific data.
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
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_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_FIXTURE_TEST_CASE(DRCUnconnectedExclusionsLoss, DRC_UNCONNECTED_SAVE_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I