22#include <boost/test/data/test_case.hpp>
44#include <wx/filename.h>
49struct DRC_REGRESSION_TEST_FIXTURE
51 DRC_REGRESSION_TEST_FIXTURE()
54 ~DRC_REGRESSION_TEST_FIXTURE()
57 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
59 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
64 m_board->SetProject(
nullptr );
69 SETTINGS_MANAGER m_settingsManager;
70 std::unique_ptr<BOARD> m_board;
74nlohmann::json writeAndReadJsonReport(
BOARD* aBoard )
76 auto markersProvider =
82 markersProvider->SetSeverities( allSeverities );
83 ratsnestProvider->SetSeverities( allSeverities );
84 fpWarningsProvider->SetSeverities( allSeverities );
88 wxString
jsonPath = wxFileName::CreateTempFileName( wxT(
"kicad-drc-json-" ) );
89 bool written = report.WriteJsonReport(
jsonPath );
91 nlohmann::json reportJson;
95 std::ifstream reportStream(
jsonPath.fn_str() );
97 if( reportStream.is_open() )
98 reportStream >> reportJson;
115 {
"issue14549_2", 0 },
133 std::vector<DRC_ITEM> violations;
147 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
148 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
151 violations.push_back( *aItem );
154 BOOST_TEST_CHECKPOINT(
"Running copper sliver drc" );
162 std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
164 BOOST_TEST_CHECKPOINT(
"DRC engine run completed successfully" );
166 catch(
const std::exception& e )
168 BOOST_ERROR( wxString::Format(
"DRC copper sliver: %s, exception during RunTests: %s",
169 test.first, e.what() ) );
174 BOOST_ERROR( wxString::Format(
"DRC copper sliver: %s, unknown exception during RunTests",
180 BOOST_TEST_CHECKPOINT(
"Clearing violation handler" );
183 if( violations.size() ==
test.second )
195 for(
size_t i = 0; i < violations.size() && i < 100; ++i )
199 const DRC_ITEM& item = violations[i];
202 catch(
const std::exception& e )
204 BOOST_TEST_MESSAGE( wxString::Format(
"Error reporting violation %zu: %s", i, e.what() ) );
212 BOOST_ERROR( wxString::Format(
"DRC copper sliver: %s, failed (violations found %d "
215 (
int) violations.size(),
241 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
242 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
248 expectedLayer = aLayer;
254 aPathGenerator( marker );
256 m_board->Add( marker );
265 nlohmann::json reportJson = writeAndReadJsonReport( m_board.get() );
267 bool foundSliver =
false;
269 for(
const auto& violation : reportJson[
"violations"] )
271 if( violation.value(
"type", std::string() ) !=
"copper_sliver" )
279 const double expectedX =
pcbIUScale.IUTomm( expectedPos.
x );
280 const double expectedY =
pcbIUScale.IUTomm( expectedPos.
y );
281 const double actualX = violation[
"pos"][
"x"].get<
double>();
282 const double actualY = violation[
"pos"][
"y"].get<
double>();
284 BOOST_CHECK_SMALL( actualX - expectedX, 1e-9 );
285 BOOST_CHECK_SMALL( actualY - expectedY, 1e-9 );
307 drcItem->SetErrorMessage( wxT(
"Missing footprint" ) );
310 nlohmann::json reportJson = writeAndReadJsonReport( m_board.get() );
312 bool foundMissingFootprint =
false;
314 for(
const auto& violation : reportJson[
"schematic_parity"] )
316 if( violation.value(
"type", std::string() ) !=
"missing_footprint" )
319 foundMissingFootprint =
true;
constexpr EDA_IU_SCALE pcbIUScale
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode) const
Return the severity of a given DRC error code.
Implements the RC_ITEM_RESOLVER interface to resolve PCB items by their KIID.
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 SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
void ClearViolationHandler()
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
virtual wxString ShowReport(UNITS_PROVIDER *aUnitsProvider, SEVERITY aSeverity, const RC_ITEM_RESOLVER &aResolver) const
Translate this object into a text string suitable for saving to disk in a report.
static bool empty(const wxTextEntryBase *aCtrl)
static std::string ToStdString(const wxString &aStr)
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_FIXTURE_TEST_CASE(DRCCopperSliverJsonReportsMarkerLocation, DRC_REGRESSION_TEST_FIXTURE)
static const std::vector< std::pair< wxString, int > > DRCCopperSliver_cases
BOOST_DATA_TEST_CASE_F(DRC_REGRESSION_TEST_FIXTURE, DRCCopperSliver, boost::unit_test::data::make(DRCCopperSliver_cases), test)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I