KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_symbol_library_manager.cpp File Reference

Test suite for SYMBOL_LIBRARY_MANAGER object. More...

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 (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.
 

Detailed Description

Test suite for SYMBOL_LIBRARY_MANAGER object.

Definition in file test_symbol_library_manager.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/8]

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 234 of file test_symbol_library_manager.cpp.

References BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), LIB_BUFFER::ClearDeletedBuffer(), 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() [2/8]

◆ BOOST_AUTO_TEST_CASE() [3/8]

◆ BOOST_AUTO_TEST_CASE() [4/8]

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 525 of file test_symbol_library_manager.cpp.

References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::IsDerived(), SCH_IO_KICAD_SEXPR::PropBuffering, LIB_SYMBOL::SetParent(), and LIB_SYMBOL::SetParentName().

◆ BOOST_AUTO_TEST_CASE() [5/8]

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 372 of file test_symbol_library_manager.cpp.

References BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), LIB_SYMBOL::IsDerived(), SCH_IO_KICAD_SEXPR::PropBuffering, and LIB_SYMBOL::SetParent().

◆ BOOST_AUTO_TEST_CASE() [6/8]

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 491 of file test_symbol_library_manager.cpp.

References BOOST_CHECK_MESSAGE(), 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() [7/8]

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 460 of file test_symbol_library_manager.cpp.

References BOOST_CHECK_EQUAL(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::GetParentName(), LIB_SYMBOL::IsDerived(), and LIB_SYMBOL::SetParent().

◆ BOOST_AUTO_TEST_CASE() [8/8]