42#include <wx/filename.h>
50 m_tempDir = wxFileName::CreateTempFileName( wxS(
"kicad_test_" ) );
62 wxFileName::Rmdir(
m_tempDir, wxPATH_RMDIR_RECURSIVE );
73 const std::string& aContent )
113 std::unique_ptr<LIB_SYMBOL> parentSymbol = std::make_unique<LIB_SYMBOL>( wxS(
"ParentSymbol" ) );
114 parentSymbol->GetValueField().SetText( wxS(
"ParentSymbol" ) );
115 parentSymbol->GetReferenceField().SetText( wxS(
"U" ) );
119 CreateTestEmbeddedFile( wxS(
"parent_datasheet.pdf" ),
"Parent datasheet content" );
120 parentSymbol->AddFile( parentFile );
122 BOOST_CHECK( parentSymbol->HasFile( wxS(
"parent_datasheet.pdf" ) ) );
128 plugin->CreateLibrary( GetLibPath() );
129 plugin->SaveSymbol( GetLibPath(),
new LIB_SYMBOL( *parentSymbol ) );
130 plugin->SaveLibrary( GetLibPath() );
136 LIB_SYMBOL* loadedParent = plugin->LoadSymbol( GetLibPath(), wxS(
"ParentSymbol" ) );
138 BOOST_CHECK( loadedParent->
HasFile( wxS(
"parent_datasheet.pdf" ) ) );
144 LIB_SYMBOL* loadedParent = plugin->LoadSymbol( GetLibPath(), wxS(
"ParentSymbol" ) );
147 std::unique_ptr<LIB_SYMBOL> derivedSymbol = std::make_unique<LIB_SYMBOL>( wxS(
"DerivedSymbol" ) );
148 derivedSymbol->GetValueField().SetText( wxS(
"DerivedSymbol" ) );
149 derivedSymbol->SetParent( loadedParent );
151 plugin->SaveSymbol( GetLibPath(),
new LIB_SYMBOL( *derivedSymbol ) );
152 plugin->SaveLibrary( GetLibPath() );
158 LIB_SYMBOL* loadedDerived = plugin->LoadSymbol( GetLibPath(), wxS(
"DerivedSymbol" ) );
162 BOOST_CHECK( !loadedDerived->
HasFile( wxS(
"parent_datasheet.pdf" ) ) );
170 LIB_SYMBOL* loadedParent = plugin->LoadSymbol( GetLibPath(), wxS(
"ParentSymbol" ) );
171 LIB_SYMBOL* loadedDerived = plugin->LoadSymbol( GetLibPath(), wxS(
"DerivedSymbol" ) );
173 loadedDerived->
SetParent( loadedParent );
176 CreateTestEmbeddedFile( wxS(
"derived_datasheet.pdf" ),
"Derived datasheet content" );
177 loadedDerived->
AddFile( derivedFile );
179 BOOST_CHECK( loadedDerived->
HasFile( wxS(
"derived_datasheet.pdf" ) ) );
181 plugin->SaveSymbol( GetLibPath(),
new LIB_SYMBOL( *loadedDerived ) );
182 plugin->SaveLibrary( GetLibPath() );
188 LIB_SYMBOL* loadedDerived = plugin->LoadSymbol( GetLibPath(), wxS(
"DerivedSymbol" ) );
190 BOOST_CHECK( loadedDerived->
HasFile( wxS(
"derived_datasheet.pdf" ) ) );
198 SCH_SHEET* defaultSheet = schematic.GetTopLevelSheet( 0 );
204 schematic.AddTopLevelSheet( rootSheet );
205 schematic.RemoveTopLevelSheet( defaultSheet );
209 LIB_SYMBOL* loadedParent = plugin->LoadSymbol( GetLibPath(), wxS(
"ParentSymbol" ) );
210 LIB_SYMBOL* loadedDerived = plugin->LoadSymbol( GetLibPath(), wxS(
"DerivedSymbol" ) );
212 loadedDerived->
SetParent( loadedParent );
220 screen->
Append( schSymbol );
237 std::unique_ptr<LIB_SYMBOL> original = std::make_unique<LIB_SYMBOL>( wxS(
"Original" ) );
238 original->GetValueField().SetText( wxS(
"Original" ) );
241 CreateTestEmbeddedFile( wxS(
"test.pdf" ),
"Test content" );
242 original->AddFile( file );
247 std::unique_ptr<LIB_SYMBOL>
copy = std::make_unique<LIB_SYMBOL>( *original );
251 BOOST_CHECK(
copy->HasFile( wxS(
"test.pdf" ) ) );
255 BOOST_CHECK( copiedFile->
Validate() );
265 std::unique_ptr<LIB_SYMBOL> source = std::make_unique<LIB_SYMBOL>( wxS(
"Source" ) );
266 source->GetValueField().SetText( wxS(
"Source" ) );
269 CreateTestEmbeddedFile( wxS(
"source.pdf" ),
"Source content" );
270 source->AddFile( file );
273 std::unique_ptr<LIB_SYMBOL> dest = std::make_unique<LIB_SYMBOL>( wxS(
"Dest" ) );
274 dest->GetValueField().SetText( wxS(
"Dest" ) );
281 BOOST_CHECK( dest->HasFile( wxS(
"source.pdf" ) ) );
285 BOOST_CHECK( destFile->
Validate() );
299 wxString projectPath = wxFileName( GetTempDir(), wxS(
"test_project.kicad_pro" ) ).GetFullPath();
300 settingsManager.
LoadProject( projectPath.ToStdString() );
302 auto schematic = std::make_unique<SCHEMATIC>(
nullptr );
303 schematic->SetProject( &settingsManager.
Prj() );
306 SCH_SHEET* defaultSheet = schematic->GetTopLevelSheet( 0 );
311 schematic->AddTopLevelSheet( rootSheet );
312 schematic->RemoveTopLevelSheet( defaultSheet );
316 std::unique_ptr<LIB_SYMBOL> libSymbol = std::make_unique<LIB_SYMBOL>( wxS(
"EmbeddedSymbol" ) );
317 libSymbol->GetValueField().SetText( wxS(
"EmbeddedSymbol" ) );
318 libSymbol->GetReferenceField().SetText( wxS(
"U" ) );
319 libSymbol->AddFile( CreateTestEmbeddedFile( wxS(
"datasheet.pdf" ),
"Original datasheet" ) );
322 rootPath.
push_back( &schematic->Root() );
330 new SCH_SYMBOL( *libSymbol,
LIB_ID(
"test_lib",
"EmbeddedSymbol" ), &rootPath, 0 );
331 schSymbol->
SetRef( &rootPath, wxS(
"U1" ) );
332 screen->
Append( schSymbol );
335 new SCH_SYMBOL( *libSymbol,
LIB_ID(
"test_lib",
"EmbeddedSymbol" ), &rootPath, 0 );
336 otherSymbol->
SetRef( &rootPath, wxS(
"U2" ) );
338 screen->
Append( otherSymbol );
350 screen->
Append( schSymbol );
352 wxString fileName = wxFileName( GetTempDir(), wxS(
"embedded_roundtrip.kicad_sch" ) ).GetFullPath();
359 SCH_SHEET* newDefaultSheet = schematic->GetTopLevelSheet( 0 );
363 schematic->AddTopLevelSheet( loadedSheet );
364 schematic->RemoveTopLevelSheet( newDefaultSheet );
365 delete newDefaultSheet;
370 bool foundSymbol =
false;
374 if( cachedSymbol->GetName() == wxS(
"EmbeddedSymbol" ) )
377 BOOST_CHECK( cachedSymbol->HasFile( wxS(
"datasheet.pdf" ) ) );
378 BOOST_CHECK( cachedSymbol->HasFile( wxS(
"extra.pdf" ) ) );
382 BOOST_CHECK( foundSymbol );
bool HasFile(const wxString &name) const
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
static RETURN_CODE CompressAndEncode(EMBEDDED_FILE &aFile)
Take data from the #decompressedData buffer and compresses it using ZSTD into the #compressedEncodedD...
A logical library item identifier and consists of various portions much like a URI.
Define a library symbol object.
void SetParent(LIB_SYMBOL *aParent=nullptr)
A streaming C++ equivalent for MurmurHash3_x64_128.
FORCE_INLINE void add(const std::string &input)
FORCE_INLINE HASH_128 digest()
Holds all the data relating to one schematic.
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,...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const std::map< wxString, LIB_SYMBOL * > & GetLibSymbols() const
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
EMBEDDED_FILES::EMBEDDED_FILE * CreateTestEmbeddedFile(const wxString &aName, const std::string &aContent)
Create a test embedded file with the given name and content.
~SYMBOL_EMBEDDED_FILES_TEST_FIXTURE()
wxString GetTempDir() const
SYMBOL_EMBEDDED_FILES_TEST_FIXTURE()
wxString GetLibPath() const
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< char > decompressedData
std::string ToString() const
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(DerivedSymbolEmbeddedFiles)
Test embedded files in parent and derived symbols: 1) Create a symbol and add an embedded file and sa...
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I