29#include <boost/test/unit_test.hpp>
41#include <wx/filename.h>
42#include <wx/stdpaths.h>
51 wxString tempDir = wxStandardPaths::Get().GetTempDir();
52 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT(
"test_project.kicad_pro");
56 m_schematic = std::make_unique<SCHEMATIC>(
nullptr );
66 if( wxFileExists( file ) )
75 wxString tempDir = wxStandardPaths::Get().GetTempDir();
76 wxString fileName = wxFileName::CreateTempFileName( tempDir + wxFileName::GetPathSeparator() + aPrefix );
98 m_schematic->CreateDefaultScreens();
101 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
104 SCH_SCREEN* screen = topSheets[0]->GetScreen();
109 topSheets[0]->SetName(
"Main Sheet" );
113 BOOST_CHECK( !currentSheet.
empty() );
114 if( !currentSheet.
empty() )
116 BOOST_CHECK( currentSheet.
Last() != &m_schematic->Root() );
121 wxString fileName = GetTempFileName(
"test_schematic" );
122 fileName +=
".kicad_sch";
123 m_tempFiles.push_back( fileName );
126 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( fileName, topSheets[0], m_schematic.get() ) );
129 BOOST_CHECK( wxFileExists( fileName ) );
132 m_schematic->Reset();
134 BOOST_CHECK_NO_THROW( loadedSheet = io.
LoadSchematicFile( fileName, m_schematic.get() ) );
135 BOOST_CHECK( loadedSheet !=
nullptr );
140 m_schematic->SetRoot( loadedSheet );
143 BOOST_CHECK( m_schematic->IsValid() );
147 BOOST_CHECK( !currentSheet2.
empty() );
148 if( !currentSheet2.
empty() )
150 BOOST_CHECK( currentSheet2.
Last() != &m_schematic->Root() );
155 wxString fileName2 = GetTempFileName(
"test_schematic_resave" );
156 fileName2 +=
".kicad_sch";
157 m_tempFiles.push_back( fileName2 );
159 std::vector<SCH_SHEET*> topSheets2 = m_schematic->GetTopLevelSheets();
164 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( fileName2, topSheets2[0], m_schematic.get() ) );
167 BOOST_CHECK( wxFileExists( fileName2 ) );
178 m_schematic->CreateDefaultScreens();
180 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
183 SCH_SCREEN* screen = topSheets[0]->GetScreen();
188 subSheet->
SetName(
"SubSheet" );
193 screen->
Append( subSheet );
196 wxString mainFileName = GetTempFileName(
"test_main" );
197 mainFileName +=
".kicad_sch";
198 m_tempFiles.push_back( mainFileName );
201 wxString subFileName = GetTempFileName(
"test_sub" );
202 subFileName +=
".kicad_sch";
203 m_tempFiles.push_back( subFileName );
206 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( mainFileName, topSheets[0], m_schematic.get() ) );
207 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( subFileName, subSheet, m_schematic.get() ) );
210 m_schematic->Reset();
212 BOOST_CHECK_NO_THROW( loadedSheet = io.
LoadSchematicFile( mainFileName, m_schematic.get() ) );
213 BOOST_CHECK( loadedSheet !=
nullptr );
217 m_schematic->SetRoot( loadedSheet );
220 m_schematic->RefreshHierarchy();
227 wxString mainFileName2 = GetTempFileName(
"test_main_resave" );
228 mainFileName2 +=
".kicad_sch";
229 m_tempFiles.push_back( mainFileName2 );
231 std::vector<SCH_SHEET*> topSheets2 = m_schematic->GetTopLevelSheets();
235 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( mainFileName2, topSheets2[0], m_schematic.get() ) );
238 BOOST_CHECK( wxFileExists( mainFileName2 ) );
252 fn.AppendDir(
"legacy_hierarchy" );
253 fn.SetName(
"legacy_hierarchy" );
255 wxString mainFile = fn.GetFullPath();
264 BOOST_CHECK_NO_THROW( loadedSheet = io.
LoadSchematicFile( mainFile, m_schematic.get() ) );
270 m_schematic->SetRoot( loadedSheet );
273 m_schematic->RefreshHierarchy();
279 BOOST_REQUIRE_EQUAL( hierarchy.size(), 3 );
282 for(
size_t i = 0; i < hierarchy.size(); i++ )
285 BOOST_TEST_MESSAGE(
"\nSheet path [" + std::to_string(i) +
"]: " +
path.PathHumanReadable(
false ).ToStdString() );
291 BOOST_CHECK(
path.LastScreen() !=
nullptr );
293 if(
path.LastScreen() )
310 std::map<wxString, int> referenceCount;
311 int totalInstances = 0;
316 if( !
path.LastScreen() )
334 if( symbolInstance.
m_Path.empty() )
338 " has EMPTY instance path!" );
344 " -> " + symbolInstance.
m_Reference.ToStdString() +
345 " (path: " + symbolInstance.
m_Path.
AsString().ToStdString() +
")" );
351 " has NO instance for path " +
path.Path().AsString().ToStdString() );
359 BOOST_TEST_MESSAGE(
" Unique references: " + std::to_string( referenceCount.size() ) );
365 BOOST_CHECK( totalInstances > 0 );
369 for(
const auto& pair : referenceCount )
371 BOOST_TEST_MESSAGE(
" " + pair.first.ToStdString() +
": " + std::to_string( pair.second ) );
376 wxString saveFile = GetTempFileName(
"legacy_hierarchy_resave" );
378 m_tempFiles.push_back( saveFile );
380 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
384 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( saveFile, topSheets[0], m_schematic.get() ) );
385 BOOST_CHECK( wxFileExists( saveFile ) );
wxString AsString() const
wxString AsString() const
Container for project specific data.
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,...
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void CheckForMissingSymbolInstances(const wxString &aProjectName)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool empty() const
Forwarded method from std::vector.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
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)
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
std::vector< wxString > m_tempFiles
wxString GetTempFileName(const wxString &aPrefix)
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< SCHEMATIC > m_schematic
A simple container for schematic symbol instance information.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TestSaveLoadSimpleSchematic)
Test that we can save and reload a schematic with the virtual root pattern and that symbol instances ...
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")