|
KiCad PCB EDA Suite
|
#include <algorithm>#include <filesystem>#include <fstream>#include <ranges>#include <utility>#include <vector>#include <wx/ffile.h>#include <mock_pgm_base.h>#include <richio.h>#include <io/kicad/kicad_io_utils.h>#include <qa_utils/wx_utils/unit_test_utils.h>#include <settings/settings_manager.h>#include <pegtl/contrib/analyze.hpp>#include <env_vars.h>#include <pgm_base.h>#include <settings/common_settings.h>#include <libraries/library_manager.h>#include <libraries/library_table.h>#include <libraries/library_table_parser.h>#include <libraries/library_table_grammar.h>#include <settings/kicad_settings.h>#include <startwizard/startwizard_provider_libraries.h>Go to the source code of this file.
Functions | |
| BOOST_AUTO_TEST_CASE (Grammar) | |
| BOOST_AUTO_TEST_CASE (EmptyString) | |
| BOOST_AUTO_TEST_CASE (ParseFromFile) | |
| BOOST_AUTO_TEST_CASE (ParseAndConstruct) | |
| BOOST_AUTO_TEST_CASE (Manager) | |
| BOOST_AUTO_TEST_CASE (ManagerTableReturnsNulloptForUnloadedType) | |
| BOOST_AUTO_TEST_CASE (NestedTablesDisabledHidden) | |
| BOOST_AUTO_TEST_CASE (InsertRowPreservesExistingRowPointers) | |
| Regression test: inserting rows into a loaded LIBRARY_TABLE must not invalidate pointers or references to previously-captured rows. | |
| BOOST_AUTO_TEST_CASE (IsPcmManagedRow_URITemplateMatching) | |
| Regression test for the PCM auto-remove identification predicate. | |
| BOOST_AUTO_TEST_CASE (ReadOnlyTable) | |
| BOOST_AUTO_TEST_CASE (LibOverrideSettings) | |
| BOOST_AUTO_TEST_CASE (CreateGlobalTableEmptyWhenNoStockTable) | |
| Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24626. | |
| BOOST_AUTO_TEST_CASE (StockTableReferenceURIHonorsExternalDefinition) | |
| The stock-table reference URI written into a freshly created global table must only use the env-var token when the template-dir variable is defined externally (the relocatable-install case from https://gitlab.com/kicad/code/kicad/-/issues/23081). | |
| static LIBRARY_TABLE | makeImportedSymbolTable (const std::vector< std::pair< wxString, wxString > > &aUserRows) |
| Builds an in-memory symbol library table seeded with the given user rows. | |
| static size_t | countChainedKiCadRows (const LIBRARY_TABLE &aTable) |
| BOOST_AUTO_TEST_CASE (MigrateBuiltInLibraries_NoStockRefsAddsNothing) | |
| Regression test for issue 24594. | |
| BOOST_AUTO_TEST_CASE (MigrateBuiltInLibraries_DirectStockRowsBecomeChained) | |
| Direct stock rows are removed and replaced by a single chained reference to the latest stock. | |
| BOOST_AUTO_TEST_CASE (MigrateBuiltInLibraries_ChainedRowMigratedInPlace) | |
| An existing chained reference is repointed at the latest stock without a second one being added. | |
| BOOST_AUTO_TEST_CASE | ( | CreateGlobalTableEmptyWhenNoStockTable | ) |
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24626.
When KiCad ships no stock design-block-lib-table, CreateGlobalTable must produce a valid empty table rather than a table with a dangling row pointing at the missing file.
Definition at line 454 of file test_library_tables.cpp.
References BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), BOOST_TEST_MESSAGE(), LIBRARY_MANAGER::CreateGlobalTable(), LIBRARY_MANAGER::DefaultGlobalTablePath(), DESIGN_BLOCK, GLOBAL, LIBRARY_TABLE::IsOk(), path, LIBRARY_TABLE::Rows(), and LIBRARY_MANAGER::StockTablePath().
| BOOST_AUTO_TEST_CASE | ( | EmptyString | ) |
Definition at line 57 of file test_library_tables.cpp.
References BOOST_REQUIRE(), LIBRARY_TABLE_PARSER::ParseBuffer(), and result.
| BOOST_AUTO_TEST_CASE | ( | Grammar | ) |
Definition at line 51 of file test_library_tables.cpp.
References BOOST_AUTO_TEST_CASE(), and BOOST_REQUIRE().
| BOOST_AUTO_TEST_CASE | ( | InsertRowPreservesExistingRowPointers | ) |
Regression test: inserting rows into a loaded LIBRARY_TABLE must not invalidate pointers or references to previously-captured rows.
The remote symbol import path (EnsureRemoteLibraryEntry) calls InsertRow() at runtime while LIB_DATA instances and LIBRARY_MANAGER::m_rowCache hold raw pointers into the rows container. A std::vector-backed container would reallocate on growth and leave those pointers dangling, which produced an intermittent std::bad_alloc crash deep in KIwxExpandEnvVars when the next symbol placement tried to read the stale URI.
Definition at line 260 of file test_library_tables.cpp.
References PROJECT, LIBRARY_TABLE_ROW::SetNickname(), LIBRARY_TABLE_ROW::SetType(), LIBRARY_TABLE_ROW::SetURI(), SYMBOL, table, and LIBRARY_TABLE_ROW::URI().
| BOOST_AUTO_TEST_CASE | ( | IsPcmManagedRow_URITemplateMatching | ) |
Regression test for the PCM auto-remove identification predicate.
Rows inserted by the PCM traverser reference ${KICADn_3RD_PARTY} directly, so matching on the URI template uniquely identifies them and avoids cleaning up user-added libraries whose expanded absolute paths happen to be descendants of the 3RD_PARTY directory via a different env var (e.g. ${KICAD_USER_LIB} pointing to ${KICAD10_3RD_PARTY}/V10).
Prior to this fix, cleanupRemovedPCMLibraries did a raw prefix check on the expanded path, mis-identifying overlapping user libraries as PCM-managed and silently deleting their rows any time the file was temporarily absent. The user-visible symptom was "Could not create the library file" when adding a new library through the symbol editor.
Definition at line 316 of file test_library_tables.cpp.
References actual, BOOST_CHECK_MESSAGE(), LIBRARY_MANAGER::IsPcmManagedRow(), and LIBRARY_TABLE_ROW::SetURI().
| BOOST_AUTO_TEST_CASE | ( | LibOverrideSettings | ) |
Definition at line 406 of file test_library_tables.cpp.
References BOOST_REQUIRE(), LIBRARY_MANAGER::ClearLibOverride(), SETTINGS_MANAGER::GetAppSettings(), PGM_BASE::GetSettingsManager(), KICAD_SETTINGS::m_LibOverrides, Pgm(), and LIBRARY_MANAGER::SetLibOverride().
| BOOST_AUTO_TEST_CASE | ( | Manager | ) |
Definition at line 161 of file test_library_tables.cpp.
References BOOST_REQUIRE(), FOOTPRINT, LIBRARY_MANAGER::LoadGlobalTables(), LIBRARY_MANAGER::Rows(), and SYMBOL.
| BOOST_AUTO_TEST_CASE | ( | ManagerTableReturnsNulloptForUnloadedType | ) |
Definition at line 180 of file test_library_tables.cpp.
References BOOST_REQUIRE(), GLOBAL, result, SYMBOL, LIBRARY_MANAGER::Table(), and table.
| BOOST_AUTO_TEST_CASE | ( | MigrateBuiltInLibraries_ChainedRowMigratedInPlace | ) |
An existing chained reference is repointed at the latest stock without a second one being added.
Definition at line 627 of file test_library_tables.cpp.
References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), countChainedKiCadRows(), GLOBAL, STARTWIZARD_PROVIDER_LIBRARIES::MigrateBuiltInLibraries(), LIBRARY_TABLE_ROW::SetNickname(), LIBRARY_TABLE_ROW::SetType(), LIBRARY_TABLE_ROW::SetURI(), SYMBOL, table, and LIBRARY_TABLE_ROW::TABLE_TYPE_NAME.
| BOOST_AUTO_TEST_CASE | ( | MigrateBuiltInLibraries_DirectStockRowsBecomeChained | ) |
Direct stock rows are removed and replaced by a single chained reference to the latest stock.
Definition at line 605 of file test_library_tables.cpp.
References BOOST_CHECK_EQUAL(), countChainedKiCadRows(), makeImportedSymbolTable(), STARTWIZARD_PROVIDER_LIBRARIES::MigrateBuiltInLibraries(), SYMBOL, and table.
| BOOST_AUTO_TEST_CASE | ( | MigrateBuiltInLibraries_NoStockRefsAddsNothing | ) |
Regression test for issue 24594.
A user who removed every built-in KiCad library in the previous version selected "Import tables" + "Migrate built-in libraries"; migration must not silently add the stock libraries back into their table.
Definition at line 584 of file test_library_tables.cpp.
References BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), countChainedKiCadRows(), makeImportedSymbolTable(), STARTWIZARD_PROVIDER_LIBRARIES::MigrateBuiltInLibraries(), SYMBOL, and table.
| BOOST_AUTO_TEST_CASE | ( | NestedTablesDisabledHidden | ) |
Definition at line 192 of file test_library_tables.cpp.
References BOOST_REQUIRE(), KI_TEST::GetTestDataRootDir(), GLOBAL, LIBRARY_TABLE::IsOk(), LIBRARY_TABLE::Rows(), and LIBRARY_TABLE_ROW::TABLE_TYPE_NAME.
| BOOST_AUTO_TEST_CASE | ( | ParseAndConstruct | ) |
Definition at line 89 of file test_library_tables.cpp.
References BOOST_REQUIRE(), BOOST_TEST_CONTEXT(), BOOST_TEST_MESSAGE(), STRING_FORMATTER::GetString(), KI_TEST::GetTestDataRootDir(), GLOBAL, STRING_FORMATTER::MutableString(), KICAD_FORMAT::Prettify(), and table.
| BOOST_AUTO_TEST_CASE | ( | ParseFromFile | ) |
Definition at line 65 of file test_library_tables.cpp.
References BOOST_REQUIRE(), KI_TEST::GetTestDataRootDir(), LIBRARY_TABLE_PARSER::Parse(), path, and result.
| BOOST_AUTO_TEST_CASE | ( | ReadOnlyTable | ) |
Definition at line 360 of file test_library_tables.cpp.
References BOOST_REQUIRE(), BOOST_TEST_MESSAGE(), KI_TEST::GetTestDataRootDir(), GLOBAL, LIBRARY_TABLE::IsOk(), LIBRARY_TABLE::IsReadOnly(), result, and LIBRARY_TABLE::Save().
| BOOST_AUTO_TEST_CASE | ( | StockTableReferenceURIHonorsExternalDefinition | ) |
The stock-table reference URI written into a freshly created global table must only use the env-var token when the template-dir variable is defined externally (the relocatable-install case from https://gitlab.com/kicad/code/kicad/-/issues/23081).
When the variable is at its built-in default the standard, resolved absolute path is preserved.
Definition at line 516 of file test_library_tables.cpp.
References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), DESIGN_BLOCK, FOOTPRINT, PGM_BASE::GetCommonSettings(), ENV_VAR::GetVersionedEnvVarName(), COMMON_SETTINGS::m_Env, Pgm(), ENV_VAR_ITEM::SetDefinedExternally(), LIBRARY_MANAGER::StockTablePath(), LIBRARY_MANAGER::StockTableReferenceURI(), LIBRARY_MANAGER::StockTableTokenizedURI(), SYMBOL, and COMMON_SETTINGS::ENVIRONMENT::vars.
|
static |
Definition at line 568 of file test_library_tables.cpp.
References LIBRARY_TABLE::Rows().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
static |
Builds an in-memory symbol library table seeded with the given user rows.
Definition at line 551 of file test_library_tables.cpp.
References GLOBAL, LIBRARY_TABLE_ROW::SetNickname(), LIBRARY_TABLE_ROW::SetType(), LIBRARY_TABLE_ROW::SetURI(), SYMBOL, and table.
Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().