20#include <boost/test/unit_test.hpp>
33#include <wx/filename.h>
34#include <wx/stdpaths.h>
40 std::unique_ptr<SCH_NETCHAIN> aChain )
51 wxString tempDir = wxStandardPaths::Get().GetTempDir();
52 wxString projectPath =
53 tempDir + wxFileName::GetPathSeparator() + wxT(
"test_netchain_save.kicad_pro" );
57 m_schematic = std::make_unique<SCHEMATIC>(
nullptr );
66 if( wxFileExists( file ) )
75 wxString tempDir = wxStandardPaths::Get().GetTempDir();
76 wxString fileName = wxFileName::CreateTempFileName(
77 tempDir + wxFileName::GetPathSeparator() + aPrefix );
100 m_schematic->CreateDefaultScreens();
102 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
111 subSheet->
SetName(
"SubSheet" );
115 topScreen->
Append( subSheet );
117 m_schematic->RefreshHierarchy();
119 auto chain = std::make_unique<SCH_NETCHAIN>();
120 chain->SetName( wxT(
"TEST_CHAIN" ) );
121 chain->AddNet( wxT(
"/NET_A" ) );
122 chain->AddNet( wxT(
"/NET_B" ) );
123 chain->SetTerminalRefs( wxT(
"U1" ), wxT(
"1" ), wxT(
"U2" ), wxT(
"2" ) );
127 BOOST_REQUIRE_EQUAL( m_schematic->ConnectionGraph()->GetCommittedNetChains().size(), 1u );
129 wxString topFileName = GetTempFileName(
"netchain_main" );
130 topFileName +=
".kicad_sch";
131 m_tempFiles.push_back( topFileName );
133 wxString subFileName = GetTempFileName(
"netchain_sub" );
134 subFileName +=
".kicad_sch";
135 m_tempFiles.push_back( subFileName );
138 BOOST_CHECK_NO_THROW(
140 BOOST_CHECK_NO_THROW(
146 auto countOccurrences = [](
const wxString& aHaystack,
const wxString& aNeedle )
151 while( ( pos = aHaystack.find( aNeedle, pos ) ) != wxString::npos )
154 pos += aNeedle.length();
160 wxString topContents;
162 wxFFile readback( topFileName,
"rb" );
163 BOOST_REQUIRE( readback.IsOpened() && readback.ReadAll( &topContents ) );
166 wxString subContents;
168 wxFFile readback( subFileName,
"rb" );
169 BOOST_REQUIRE( readback.IsOpened() && readback.ReadAll( &subContents ) );
173 BOOST_CHECK_MESSAGE( topContents.Contains( wxT(
"TEST_CHAIN" ) ),
174 "Top-level sheet file is missing the chain name" );
177 BOOST_CHECK_MESSAGE( !subContents.Contains( wxT(
"TEST_CHAIN" ) ),
178 "Sub-sheet file unexpectedly contains the chain name" );
CONNECTION_GRAPH(SCHEMATIC *aSchematic=nullptr, SCH_CONNECTIVITY::NETCHAIN_MANAGER *aNetChains=nullptr)
SCH_CONNECTIVITY::NETCHAIN_MANAGER * m_netChains
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Container for project specific data.
std::vector< std::unique_ptr< SCH_NETCHAIN > > m_committedNetChains
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
std::vector< FAB_LAYER_COLOR > dummy
SETTINGS_MANAGER m_settingsManager
NETCHAIN_SAVE_ROOT_FIXTURE()
std::unique_ptr< SCHEMATIC > m_schematic
wxString GetTempFileName(const wxString &aPrefix)
std::vector< wxString > m_tempFiles
~NETCHAIN_SAVE_ROOT_FIXTURE()
static size_t countOccurrences(const std::string &aHaystack, const std::string &aNeedle)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
void boost_test_inject_committed_net_chain(CONNECTION_GRAPH &aGraph, std::unique_ptr< SCH_NETCHAIN > aChain)
BOOST_FIXTURE_TEST_CASE(NetChainSavedOnlyOnRootSheetFile, NETCHAIN_SAVE_ROOT_FIXTURE)
Regression: net_chain emission is schematic-level state owned by the connection graph.
const SHAPE_LINE_CHAIN chain
BOOST_CHECK_EQUAL(result, "25.4")