43#include <wx/filename.h>
44#include <wx/stdpaths.h>
55const wxString CHAIN_1 = wxS(
"CHAIN_1" );
56const wxString CHAIN_2 = wxS(
"CHAIN_2" );
57const wxString CHAIN_1_NETCLASS = wxS(
"CHAIN_NC_1" );
58const wxString CHAIN_2_NETCLASS = wxS(
"CHAIN_NC_2" );
60const std::vector<wxString> CHAIN_1_NETS = { wxS(
"Net-(R1-Pad1)" ), wxS(
"Net-(R1-Pad2)" ),
61 wxS(
"Net-(R2-Pad2)" ) };
62const std::vector<wxString> CHAIN_2_NETS = { wxS(
"Net-(R3-Pad1)" ), wxS(
"Net-(R3-Pad2)" ),
63 wxS(
"Net-(R4-Pad2)" ) };
67const wxString
LABEL_NET = wxS(
"Net-(R5-Pad1)" );
68const wxString LABEL_NETCLASS = wxS(
"NC_3" );
79 m_dir.AssignDir( wxStandardPaths::Get().GetTempDir() );
80 m_dir.AppendDir( wxS(
"kicad-qa-issue25065" ) );
81 m_dir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
84 m_boardPath = m_dir.GetPathWithSep() + wxS(
"issue25065.kicad_pcb" );
85 m_projectPath = m_dir.GetPathWithSep() + wxS(
"issue25065.kicad_pro" );
87 BOOST_REQUIRE( wxCopyFile( srcDir + wxS(
"issue25065.kicad_pcb" ), m_boardPath ) );
88 BOOST_REQUIRE( wxCopyFile( srcDir + wxS(
"issue25065.kicad_pro" ), m_projectPath ) );
94 m_dir.Rmdir( wxPATH_RMDIR_RECURSIVE );
105 m_board->SetProject( &m_manager.Prj() );
106 m_board->BuildListOfNets();
110 void SaveAndReopenBoard()
119 void UpdateFromNetlist(
const NETLIST& aNetlist )
123 m_board->SynchronizeNetsAndNetClasses(
true );
126 NET_SETTINGS& NetSettings()
const {
return *m_board->GetDesignSettings().m_NetSettings; }
129 wxString ResolvedNetclass(
const wxString& aNetname )
const
131 NETINFO_ITEM* net = m_board->FindNet( aNetname );
136 bool ResolvesTo(
const wxString& aNetname,
const wxString& aNetclass )
const
138 NETINFO_ITEM* net = m_board->FindNet( aNetname );
139 BOOST_REQUIRE_MESSAGE( net,
"net " << aNetname <<
" missing from the board" );
148 m_board->SetProject(
nullptr );
152 m_manager.UnloadProject( &m_manager.Prj(),
false );
155 SETTINGS_MANAGER m_manager;
156 std::unique_ptr<BOARD> m_board;
158 wxString m_boardPath;
159 wxString m_projectPath;
165void AddChain(
NETLIST& aNetlist,
const wxString& aChain,
const wxString& aNetclass,
166 const std::vector<wxString>& aNets )
170 for(
const wxString& net : aNets )
185 BOOST_REQUIRE_MESSAGE( ResolvesTo(
LABEL_NET, LABEL_NETCLASS ),
189 AddChain(
netlist, CHAIN_1, CHAIN_1_NETCLASS, CHAIN_1_NETS );
190 AddChain(
netlist, CHAIN_2, CHAIN_2_NETCLASS, CHAIN_2_NETS );
194 for(
const wxString& net : CHAIN_1_NETS )
196 BOOST_REQUIRE_MESSAGE( ResolvesTo( net, CHAIN_1_NETCLASS ),
197 net <<
" resolved to " << ResolvedNetclass( net )
198 <<
" straight after the netlist update" );
201 SaveAndReopenBoard();
203 for(
const wxString& net : CHAIN_1_NETS )
205 BOOST_CHECK_MESSAGE( ResolvesTo( net, CHAIN_1_NETCLASS ),
206 net <<
" resolved to " << ResolvedNetclass( net ) <<
" after reload" );
209 for(
const wxString& net : CHAIN_2_NETS )
211 BOOST_CHECK_MESSAGE( ResolvesTo( net, CHAIN_2_NETCLASS ),
212 net <<
" resolved to " << ResolvedNetclass( net ) <<
" after reload" );
215 BOOST_CHECK_MESSAGE( ResolvesTo(
LABEL_NET, LABEL_NETCLASS ),
217 <<
" after reload" );
220 BOOST_CHECK( !ResolvesTo( wxS(
"Net-(R6-Pad2)" ), CHAIN_1_NETCLASS ) );
231 AddChain(
netlist, CHAIN_1, CHAIN_1_NETCLASS, CHAIN_1_NETS );
232 AddChain(
netlist, CHAIN_2, CHAIN_2_NETCLASS, CHAIN_2_NETS );
235 SaveAndReopenBoard();
236 BOOST_REQUIRE( ResolvesTo( CHAIN_1_NETS[0], CHAIN_1_NETCLASS ) );
239 AddChain( withoutChain1, CHAIN_2, CHAIN_2_NETCLASS, CHAIN_2_NETS );
241 UpdateFromNetlist( withoutChain1 );
243 BOOST_CHECK( NetSettings().GetNetChainNetClass( CHAIN_1 ).IsEmpty() );
244 BOOST_CHECK_MESSAGE( !ResolvesTo( CHAIN_1_NETS[0], CHAIN_1_NETCLASS ),
245 CHAIN_1_NETS[0] <<
" still resolved to "
246 << ResolvedNetclass( CHAIN_1_NETS[0] ) );
247 BOOST_CHECK( ResolvesTo( CHAIN_2_NETS[0], CHAIN_2_NETCLASS ) );
251 SaveAndReopenBoard();
253 BOOST_CHECK( !ResolvesTo( CHAIN_1_NETS[0], CHAIN_1_NETCLASS ) );
254 BOOST_CHECK( ResolvesTo( CHAIN_2_NETS[0], CHAIN_2_NETCLASS ) );
General utilities for PCB file IO for QA programs.
static void ApplyChainAssignments(BOARD *aBoard, const NETLIST &aNetlist, REPORTER *aReporter, bool aDryRun)
Apply the netlist's chain assignments to every NETINFO_ITEM on the board.
static void ApplyChainNetclasses(BOARD *aBoard, const NETLIST &aNetlist)
Mirror the netlist's chain-to-class and chain-to-netclass maps into the project's NET_SETTINGS.
const wxString GetHumanReadableName() const
Gets the consolidated name of this netclass (which may be an aggregate).
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
void SetSignalNetClass(const wxString &aNetChain, const wxString &aNetClass)
void SetNetChainFor(const wxString &aNet, const wxString &aNetChain)
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(ChainNetclassSurvivesReload, FIXTURE)