34#include <boost/test/unit_test.hpp>
39#include <wx/filename.h>
40#include <wx/stdpaths.h>
56 wxString tempDir = wxStandardPaths::Get().GetTempDir();
57 wxString projectPath =
58 tempDir + wxFileName::GetPathSeparator() + wxT(
"issue24403_project.kicad_pro" );
62 m_schematic = std::make_unique<SCHEMATIC>(
nullptr );
70 if( wxFileExists( file ) )
81 wxString tempDir = wxStandardPaths::Get().GetTempDir();
82 wxString baseName = wxFileName::CreateTempFileName(
83 tempDir + wxFileName::GetPathSeparator() + aPrefix );
86 wxString fileName = baseName + wxT(
".kicad_sch" );
92 const wxString& aNetClassName )
94 std::vector<SCH_SHEET*> topSheets =
m_schematic->GetTopLevelSheets();
97 SCH_SCREEN* screen = topSheets[0]->GetScreen();
102 label->
GetFields().back().SetText( aNetClassName );
124 m_schematic->CreateDefaultScreens();
128 AddDirectiveLabel( wxT(
"Netzklasse" ), wxT(
"HighSpeed" ) );
130 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
132 wxString outFile = MakeTempSchematicPath(
"issue24403_de" );
134 BOOST_REQUIRE_NO_THROW( io.
SaveSchematicFile( outFile, topSheets[0], m_schematic.get() ) );
136 wxFFile read( outFile,
"rb" );
138 BOOST_REQUIRE( read.IsOpened() && read.ReadAll( &contents ) );
140 BOOST_CHECK_MESSAGE( contents.Contains( wxT(
"\"Netclass\"" ) ),
141 "Saved schematic must contain canonical \"Netclass\" token" );
142 BOOST_CHECK_MESSAGE( !contents.Contains( wxT(
"\"Netzklasse\"" ) ),
143 "Saved schematic must not contain translated \"Netzklasse\" token" );
144 BOOST_CHECK_MESSAGE( contents.Contains( wxT(
"HighSpeed" ) ),
145 "Saved schematic must preserve the net class value" );
156 m_schematic->CreateDefaultScreens();
162 + wxS(
"issue24403_legacy_de.kicad_sch" );
166 BOOST_REQUIRE_NO_THROW( loaded = io.
LoadSchematicFile( legacyFile, m_schematic.get() ) );
170 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
171 m_schematic->AddTopLevelSheet( loaded );
172 m_schematic->RemoveTopLevelSheet( defaultSheet );
178 int directiveCount = 0;
179 int netclassFieldCount = 0;
189 if( field.GetCanonicalName() == wxT(
"Netclass" ) )
191 netclassFieldCount++;
202 wxString resaved = MakeTempSchematicPath(
"issue24403_legacy_de_resave" );
203 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
206 BOOST_REQUIRE_NO_THROW( io.
SaveSchematicFile( resaved, topSheets[0], m_schematic.get() ) );
208 wxFFile resavedFile( resaved,
"rb" );
209 wxString resavedContents;
210 BOOST_REQUIRE( resavedFile.IsOpened() && resavedFile.ReadAll( &resavedContents ) );
212 BOOST_CHECK_MESSAGE( resavedContents.Contains( wxT(
"\"Netclass\"" ) ),
213 "Re-saved schematic must use canonical \"Netclass\" token" );
214 BOOST_CHECK_MESSAGE( !resavedContents.Contains( wxT(
"\"Netzklasse\"" ) ),
215 "Re-saved schematic must drop the translated form" );
EE_TYPE OfType(KICAD_T aType) const
static bool IsNetclassLabelFieldName(const wxString &aName)
Test whether aName is one of the known translations of the directive-label net class field name (used...
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,...
std::vector< SCH_FIELD > & GetFields()
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
~DIRECTIVE_LABEL_I18N_FIXTURE()
std::unique_ptr< SCHEMATIC > m_schematic
std::vector< wxString > m_tempFiles
DIRECTIVE_LABEL_I18N_FIXTURE()
SETTINGS_MANAGER m_settingsManager
SCH_DIRECTIVE_LABEL * AddDirectiveLabel(const wxString &aFieldName, const wxString &aNetClassName)
wxString MakeTempSchematicPath(const wxString &aPrefix)
@ USER
The field ID hasn't been set yet; field is invalid.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CanonicalNetclassEmittedForTranslatedFieldName)
The serializer must always emit the canonical "Netclass" token for the directive-label net class fiel...
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I