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 );
88 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
90 board->BuildConnectivity();
94 if( net && net->GetNetname().StartsWith( wxS(
"/NET_" ) ) )
95 net->SetNetChain( wxS(
"SIG" ) );
100 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
101 wxFileName ruleFile( druPath.string() );
102 drcEngine->InitEngine( ruleFile );
113 size_t lengthViolations = 0;
115 drcEngine->SetViolationHandler(
116 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
126 fs::remove( druPath, ec );
128 return lengthViolations;
142 static const char* boardFile =
"net_chains/chain_bridging_3pad_2net.kicad_pcb";
146 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"26" ),
147 "kicad_drc_chain_bridging_3pad_pass" );
148 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 26 mm budget, got "
154 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"22" ),
155 "kicad_drc_chain_bridging_3pad_fail" );
156 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 22 mm budget, got "
166 static const char* boardFile =
"net_chains/chain_bridging_3pad_3net.kicad_pcb";
170 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"36" ),
171 "kicad_drc_chain_bridging_3net_pass" );
172 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 36 mm budget, got "
178 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"32" ),
179 "kicad_drc_chain_bridging_3net_fail" );
180 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 32 mm budget, got "
190 static const char* boardFile =
"net_chains/chain_bridging_4pad.kicad_pcb";
194 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"27" ),
195 "kicad_drc_chain_bridging_4pad_pass" );
196 BOOST_CHECK_MESSAGE( pass == 0,
"Expected no length violation under 27 mm budget, got "
201 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Fail",
"0",
"24" ),
202 "kicad_drc_chain_bridging_4pad_fail" );
203 BOOST_CHECK_MESSAGE( fail == 1,
"Expected one length violation under 24 mm budget, got "
211 static const char* boardFile =
"net_chains/chain_bridging_3pad_1net.kicad_pcb";
215 runChainLengthDrc( boardFile, makeChainBudgetRule(
"Pass",
"0",
"21" ),
216 "kicad_drc_chain_bridging_singlenet_pass" );
217 BOOST_CHECK_MESSAGE( pass == 0,
"Single-net 3-pad footprint must not contribute bridging; "
218 "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.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
@ 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