|
KiCad PCB EDA Suite
|
Test suite for SYMBOL_LIBRARY_MANAGER object. More...
#include <qa_utils/wx_utils/unit_test_utils.h>#include <symbol_library_manager.h>#include <symbol_editor/lib_symbol_library_manager.h>#include <sch_field.h>#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.h>#include <sch_io/sch_io_mgr.h>#include <richio.h>#include <wx/ffile.h>#include <wx/filename.h>Go to the source code of this file.
Classes | |
| class | SYMBOL_LIBRARY_MANAGER_TEST_FIXTURE |
Functions | |
| BOOST_AUTO_TEST_CASE (SymbolBuffer) | |
| Test the SYMBOL_BUFFER object. | |
| BOOST_AUTO_TEST_CASE (LibBuffer) | |
| Test the LIB_BUFFER object. | |
| BOOST_AUTO_TEST_CASE (NewSymbolCreation) | |
| Test new symbol creation routines. | |
| BOOST_AUTO_TEST_CASE (NewPowerSymbolSeedsValueFromName) | |
| A power symbol's Value field is its net name, and the symbol properties dialog no longer forces that field to match the symbol name. | |
| BOOST_AUTO_TEST_CASE (DeletedSymbolsAreRemovedFromFile) | |
| Test that LIB_BUFFER correctly deletes symbols from the library file when saved. | |
| BOOST_AUTO_TEST_CASE (SaveLibraryAsToNewFile) | |
| Test that saving symbols to a new file using buffered mode works when the target file does not yet exist. | |
| BOOST_AUTO_TEST_CASE (SetParentKeepsParentNameInSync) | |
| Test that SetParent keeps the recorded parent name in sync. | |
| BOOST_AUTO_TEST_CASE (SerializeDerivedSymbolUsesParentName) | |
| Test that serializing a derived symbol uses the recorded parent name rather than dereferencing the live parent pointer. | |
| BOOST_AUTO_TEST_CASE (SaveCopyAsDerivedSymbolToNewLibrary) | |
| Test that "Save Copy As" of a derived symbol to a new library produces a valid, round-trippable result where the copied child keeps a valid parent link and parent name. | |
| BOOST_AUTO_TEST_CASE (DerivedSymbolNamesForUnbufferedSymbol) | |
| Test that querying the derived symbols of a name that is not in the buffer is harmless. | |
| BOOST_AUTO_TEST_CASE (DerivedSymbolNamesAcrossRebufferedParent) | |
| Test that the inheritance walk follows symbol names rather than parent object identity. | |
| BOOST_AUTO_TEST_CASE (DerivedSymbolNamesExcludeRootFromNameCycle) | |
| Test that a symbol is never reported as derived from itself. | |
| BOOST_AUTO_TEST_CASE (SwappedSymbolNamesSurviveSave) | |
| Two symbols that trade names must both survive the save. | |
| BOOST_AUTO_TEST_CASE (RenamedSymbolLosesItsOldName) | |
| An ordinary rename must still drop the old name, which is what the delete exists for. | |
| BOOST_AUTO_TEST_CASE (SaveKeepsChangesMadeUnderTheBuffer) | |
Test suite for SYMBOL_LIBRARY_MANAGER object.
Definition in file test_symbol_library_manager.cpp.
| BOOST_AUTO_TEST_CASE | ( | DeletedSymbolsAreRemovedFromFile | ) |
Test that LIB_BUFFER correctly deletes symbols from the library file when saved.
This test verifies the fix for the bug where deleting a derived symbol from the symbol editor tree and saving would result in the symbol reappearing as a non-derived symbol when the library was reloaded. The root cause was that SaveBuffer only saved existing symbols but never called DeleteSymbol on the plugin for symbols in the m_deleted list.
Definition at line 264 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_BUFFER::ClearAddedAndDeletedBufferLists(), LIB_BUFFER::CreateBuffer(), LIB_BUFFER::DeleteBuffer(), LIB_BUFFER::GetBuffer(), LIB_BUFFER::GetBuffers(), LIB_BUFFER::GetDeletedBuffers(), LIB_BUFFER::GetSymbol(), LIB_SYMBOL::IsDerived(), SCH_IO_KICAD_SEXPR::PropBuffering, LIB_BUFFER::SaveBuffer(), and LIB_SYMBOL::SetParent().
| BOOST_AUTO_TEST_CASE | ( | DerivedSymbolNamesAcrossRebufferedParent | ) |
Test that the inheritance walk follows symbol names rather than parent object identity.
SYMBOL_LIBRARY_MANAGER::getLibraryBuffer() copies the original symbols in an unspecified order, so a buffered child can point at a copy of its parent that is not the buffered one.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24970
Definition at line 659 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), LIB_BUFFER::CreateBuffer(), LIB_BUFFER::GetDerivedSymbolNames(), and LIB_BUFFER::HasDerivedSymbols().
| BOOST_AUTO_TEST_CASE | ( | DerivedSymbolNamesExcludeRootFromNameCycle | ) |
Test that a symbol is never reported as derived from itself.
A hand-edited library can name a cycle, and reporting the root as its own descendant would have removeChildSymbols() erase the buffer DeleteBuffer() is in the middle of removing.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24970
Definition at line 714 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), BOOST_REQUIRE_EQUAL(), LIB_BUFFER::CreateBuffer(), LIB_BUFFER::DeleteBuffer(), LIB_BUFFER::GetBuffer(), LIB_BUFFER::GetBuffers(), and LIB_BUFFER::GetDerivedSymbolNames().
| BOOST_AUTO_TEST_CASE | ( | DerivedSymbolNamesForUnbufferedSymbol | ) |
Test that querying the derived symbols of a name that is not in the buffer is harmless.
The symbol editor evaluates its context menu conditions against whatever LIB_ID the library tree or the open symbol names, and that symbol need not be buffered.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24970
Definition at line 620 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_BUFFER::CreateBuffer(), LIB_BUFFER::DeleteBuffer(), LIB_BUFFER::GetBuffer(), LIB_BUFFER::GetDerivedSymbolNames(), and LIB_BUFFER::GetSymbol().
| BOOST_AUTO_TEST_CASE | ( | LibBuffer | ) |
Test the LIB_BUFFER object.
Definition at line 86 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), LIB_BUFFER::CreateBuffer(), LIB_BUFFER::DeleteBuffer(), DERIVED_ONLY, LIB_BUFFER::GetBuffer(), LIB_BUFFER::GetBuffers(), LIB_BUFFER::GetDerivedSymbolNames(), LIB_SYMBOL::GetDescriptionField(), LIB_BUFFER::GetHash(), LIB_SYMBOL::GetName(), LIB_BUFFER::GetSymbol(), LIB_BUFFER::GetSymbolNames(), LIB_BUFFER::HasDerivedSymbols(), LIB_BUFFER::IsModified(), ROOT_ONLY, LIB_SYMBOL::SetParent(), SCH_FIELD::SetText(), and LIB_BUFFER::UpdateBuffer().
| BOOST_AUTO_TEST_CASE | ( | NewPowerSymbolSeedsValueFromName | ) |
A power symbol's Value field is its net name, and the symbol properties dialog no longer forces that field to match the symbol name.
Creation is the only place left that fills it in, so a new power symbol arriving with an empty Value would place an unnamed net.
Definition at line 232 of file test_symbol_library_manager.cpp.
References NEW_SYMBOL_PROPERTIES::alternateBodyStyle, BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_SYMBOL_LIBRARY_MANAGER::CreateSymbol(), NEW_SYMBOL_PROPERTIES::includeInBom, NEW_SYMBOL_PROPERTIES::includeOnBoard, NEW_SYMBOL_PROPERTIES::name, NEW_SYMBOL_PROPERTIES::pinNameInside, NEW_SYMBOL_PROPERTIES::pinTextPosition, NEW_SYMBOL_PROPERTIES::powerSymbol, NEW_SYMBOL_PROPERTIES::reference, NEW_SYMBOL_PROPERTIES::showPinName, NEW_SYMBOL_PROPERTIES::showPinNumber, NEW_SYMBOL_PROPERTIES::unitCount, and NEW_SYMBOL_PROPERTIES::unitsInterchangeable.
| BOOST_AUTO_TEST_CASE | ( | NewSymbolCreation | ) |
Test new symbol creation routines.
Definition at line 165 of file test_symbol_library_manager.cpp.
References NEW_SYMBOL_PROPERTIES::alternateBodyStyle, BOOST_CHECK(), BOOST_CHECK_EQUAL(), LIB_SYMBOL_LIBRARY_MANAGER::CreateSymbol(), NEW_SYMBOL_PROPERTIES::includeInBom, NEW_SYMBOL_PROPERTIES::includeOnBoard, NEW_SYMBOL_PROPERTIES::keepContentUserFields, NEW_SYMBOL_PROPERTIES::keepDatasheet, NEW_SYMBOL_PROPERTIES::keepFootprint, NEW_SYMBOL_PROPERTIES::name, NEW_SYMBOL_PROPERTIES::parentSymbolName, NEW_SYMBOL_PROPERTIES::pinNameInside, NEW_SYMBOL_PROPERTIES::pinTextPosition, NEW_SYMBOL_PROPERTIES::powerSymbol, NEW_SYMBOL_PROPERTIES::reference, SCH_FIELD::SetText(), NEW_SYMBOL_PROPERTIES::showPinName, NEW_SYMBOL_PROPERTIES::showPinNumber, NEW_SYMBOL_PROPERTIES::transferUserFields, NEW_SYMBOL_PROPERTIES::unitCount, NEW_SYMBOL_PROPERTIES::unitsInterchangeable, and USER.
| BOOST_AUTO_TEST_CASE | ( | RenamedSymbolLosesItsOldName | ) |
An ordinary rename must still drop the old name, which is what the delete exists for.
Definition at line 838 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_REQUIRE(), and path.
| BOOST_AUTO_TEST_CASE | ( | SaveCopyAsDerivedSymbolToNewLibrary | ) |
Test that "Save Copy As" of a derived symbol to a new library produces a valid, round-trippable result where the copied child keeps a valid parent link and parent name.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24412
Definition at line 556 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::IsDerived(), and SCH_IO_KICAD_SEXPR::PropBuffering.
| BOOST_AUTO_TEST_CASE | ( | SaveKeepsChangesMadeUnderTheBuffer | ) |
Definition at line 864 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), copy, LIB_BUFFER::CreateBuffer(), LIB_BUFFER::GetBuffer(), LIB_SYMBOL::GetDescription(), KI_TEST::GetEeschemaTestDataDir(), LIB_BUFFER::GetSymbol(), LIB_SYMBOL::IsDerived(), LIB_BUFFER::SaveModifiedBuffers(), and text.
| BOOST_AUTO_TEST_CASE | ( | SaveLibraryAsToNewFile | ) |
Test that saving symbols to a new file using buffered mode works when the target file does not yet exist.
This exercises the same code path as "Save Library As" in the symbol editor: a fresh SCH_IO plugin instance buffers symbols and then flushes to a new file path. Before the fix, cacheLib() would call Load() on the non-existent target file and throw, resulting in an empty library (header only).
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23337
Definition at line 402 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_REQUIRE(), LIB_SYMBOL::IsDerived(), and SCH_IO_KICAD_SEXPR::PropBuffering.
| BOOST_AUTO_TEST_CASE | ( | SerializeDerivedSymbolUsesParentName | ) |
Test that serializing a derived symbol uses the recorded parent name rather than dereferencing the live parent pointer.
This guards the "Save As" / "Save Copy As" crash from the symbol editor: a derived symbol (e.g. an STM32 part inheriting from a base symbol) is copied to another library and the buffered parent can be freed before the child is written out. In release builds the writer dereferenced the (dangling) parent pointer and crashed; debug builds only tripped a wxASSERT, which is why the issue was "not reproducible" for testers using debug builds.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24412
Definition at line 522 of file test_symbol_library_manager.cpp.
References BOOST_REQUIRE(), STRING_FORMATTER::GetString(), LIB_SYMBOL::GetValueField(), LIB_SYMBOL::IsDerived(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), LIB_SYMBOL::SetParent(), LIB_SYMBOL::SetParentName(), and SCH_FIELD::SetText().
| BOOST_AUTO_TEST_CASE | ( | SetParentKeepsParentNameInSync | ) |
Test that SetParent keeps the recorded parent name in sync.
The "Save As" / "Save Copy As" crash (issue #24412) happened because the SEXPR writer dereferenced the live parent pointer to obtain the parent name. That pointer can dangle (the parent LIB_SYMBOL uses a null_deleter shared_ptr whose control block can outlive the object), so the writer now serializes the recorded parent name instead. For that to be correct, the recorded name must track the live parent.
Definition at line 491 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_CHECK_EQUAL(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::GetParentName(), LIB_SYMBOL::IsDerived(), and LIB_SYMBOL::SetParent().
| BOOST_AUTO_TEST_CASE | ( | SwappedSymbolNamesSurviveSave | ) |
Two symbols that trade names must both survive the save.
Definition at line 808 of file test_symbol_library_manager.cpp.
References BOOST_CHECK(), BOOST_REQUIRE(), and path.
| BOOST_AUTO_TEST_CASE | ( | SymbolBuffer | ) |
Test the SYMBOL_BUFFER object.
Definition at line 55 of file test_symbol_library_manager.cpp.
References BOOST_AUTO_TEST_CASE(), BOOST_CHECK(), SYMBOL_BUFFER::GetOriginal(), SYMBOL_BUFFER::GetScreen(), SYMBOL_BUFFER::GetSymbol(), SYMBOL_BUFFER::IsModified(), BASE_SCREEN::SetContentModified(), and SYMBOL_BUFFER::SetOriginal().