20#include <boost/test/unit_test.hpp>
54static const char* DRU_HEADER =
"(version 1)\n";
57std::string makeChainBudgetRule(
const wxString& aName,
const wxString& aMinMM,
58 const wxString& aMaxMM )
60 return wxString::Format(
"%s(rule \"%s\"\n"
61 " (condition \"A.NetClass == 'Default'\")\n"
62 " (constraint net_chain_length (min %smm) (max %smm))\n"
64 DRU_HEADER, aName, aMinMM, aMaxMM )
72size_t runChainLengthDrc(
const std::string& aBoardFile,
const std::string& aRuleText,
73 const std::string& aTmpSubdir )
75 namespace fs = std::filesystem;
77 fs::path tmpDir = fs::temp_directory_path() / aTmpSubdir;
78 fs::create_directories( tmpDir );
80 fs::path druPath = tmpDir /
"chain_bridge.kicad_dru";
83 std::ofstream druOut( druPath );
89 board->BuildConnectivity();
93 if( net && net->GetNetname().StartsWith( wxS(
"/NET_" ) ) )
94 net->SetNetChain( wxS(
"SIG" ) );
99 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
100 wxFileName ruleFile( druPath.string() );
101 drcEngine->InitEngine( ruleFile );
112 size_t lengthViolations = 0;
114 drcEngine->SetViolationHandler(
115 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
125 fs::remove( druPath, ec );
127 return lengthViolations;
141 static const char* boardFile =
"net_chains/chain_bridging_3pad_2net.kicad_pcb";
145 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"26" ),
146 "kicad_drc_chain_bridging_3pad_pass" );
147 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 26 mm budget, got "
153 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"22" ),
154 "kicad_drc_chain_bridging_3pad_fail" );
155 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 22 mm budget, got "
165 static const char* boardFile =
"net_chains/chain_bridging_3pad_3net.kicad_pcb";
169 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"36" ),
170 "kicad_drc_chain_bridging_3net_pass" );
171 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 36 mm budget, got "
177 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"32" ),
178 "kicad_drc_chain_bridging_3net_fail" );
179 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 32 mm budget, got "
189 static const char* boardFile =
"net_chains/chain_bridging_4pad.kicad_pcb";
193 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"27" ),
194 "kicad_drc_chain_bridging_4pad_pass" );
195 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 27 mm budget, got "
200 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"24" ),
201 "kicad_drc_chain_bridging_4pad_fail" );
202 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 24 mm budget, got "
210 static const char* boardFile =
"net_chains/chain_bridging_3pad_1net.kicad_pcb";
214 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"21" ),
215 "kicad_drc_chain_bridging_singlenet_pass" );
216 BOOST_CHECK_MESSAGE( pass == 0,
"Single-net 3-pad footprint must not contribute bridging; "
217 "got " << pass <<
" violations under 21 mm budget" );
General utilities for PCB file IO for QA programs.
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Handle the data for a net.
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
std::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
@ DRCE_LIB_FOOTPRINT_ISSUES
@ DRCE_DRILL_OUT_OF_RANGE
@ DRCE_LENGTH_OUT_OF_RANGE
@ DRCE_LIB_FOOTPRINT_MISMATCH
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(ThreePadTwoNetFootprintContributesMaxPairwiseSpan)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2< int32_t > VECTOR2I