20#include <boost/test/unit_test.hpp>
34#include <api/schematic/schematic_rules.pb.h>
41#include <wx/filename.h>
58struct SCOPED_NATIVE_LIBRARY
71 return table && *
table ? wxFileName( ( *table )->Path() ).GetPath() : wxString();
74 explicit SCOPED_NATIVE_LIBRARY(
PROJECT& aProject ) :
80 wxFile tableFile(
directory +
"/sym-lib-table", wxFile::write );
82 BOOST_REQUIRE( tableFile.Write(
"(sym_lib_table (version 7))\n" ) );
87 row = &
table->InsertRow();
88 row->SetNickname(
"NativeCapturedLibrary" );
90 row->SetType(
"KiCad" );
92 adapter->LoadOne( row->Nickname() );
94 external = adapter->LoadSymbol( row->Nickname(),
"4001" );
99 TABLE_RESTORE restore;
114 std::vector<SCH_SHEET_PATH> paths;
116 for(
const auto&
path : m_schematic->Hierarchy() )
118 if(
path.LastScreen()->GetFileName().EndsWith(
"LEDs.kicad_sch" ) )
119 paths.push_back(
path );
122 BOOST_REQUIRE_EQUAL( paths.size(), 2u );
123 SCH_SCREEN* screen = paths.front().LastScreen();
127 auto* symbol =
static_cast<SCH_SYMBOL*
>( *symbols.begin() );
129 SCOPED_NATIVE_LIBRARY
library( m_schematic->Project() );
130 const auto native =
library.external->Flatten();
131 symbol->SetLibSymbol(
new LIB_SYMBOL( *native ) );
132 symbol->GetLibSymbolRef()->SetKeyWords(
"Native shared mismatch" );
134 auto& exclusions = m_schematic->ErcSettings().m_ErcExclusions;
135 const auto markers = [&](
int aCode )
137 std::vector<SCH_MARKER*>
result;
141 auto* marker =
static_cast<SCH_MARKER*
>( item );
144 if( error->GetErrorCode() == aCode && error->GetMainItemID() == symbol->m_Uuid )
145 result.push_back( marker );
156 for(
bool backend : {
true,
false } )
159 m_schematic->RebuildConnectivity();
161 for(
bool historical : {
false,
true } )
166 BOOST_REQUIRE_EQUAL( markers( code ).size(), 2u );
167 std::set<KIID_PATH> seen;
171 const auto error = std::static_pointer_cast<ERC_ITEM>( marker->GetRCItem() );
174 const auto& markerPath = error->GetSpecificSheetPath().PathRef();
175 BOOST_CHECK( error->GetMainItemSheetPath().PathRef() == markerPath );
176 BOOST_CHECK( seen.insert( markerPath ).second );
178 if( markerPath == paths.front().PathRef() )
184 proto.mutable_marker()->clear_sheet_specific_path();
185 proto.mutable_marker()->clear_main_item_sheet_path();
189 exclusion.SetComment(
"Retained library exclusion" );
190 exclusions.insert( exclusion );
196 const std::set<KIID_PATH> expectedPaths{ paths.front().PathRef(), paths.back().PathRef() };
197 BOOST_CHECK( seen == expectedPaths );
198 BOOST_REQUIRE_EQUAL( exclusions.size(), 1u );
200 m_schematic->ResolveERCExclusionsPostUpdate();
201 BOOST_REQUIRE_EQUAL( markers( code ).size(), 2u );
205 const auto error = std::static_pointer_cast<ERC_ITEM>( marker->GetRCItem() );
207 || error->GetSpecificSheetPath().PathRef() == paths.front().PathRef();
226 std::vector<SCH_SHEET_PATH> paths;
228 for(
const auto&
path : m_schematic->Hierarchy() )
230 if(
path.LastScreen()->GetFileName().EndsWith(
"LEDs.kicad_sch" ) )
231 paths.push_back(
path );
234 BOOST_REQUIRE_EQUAL( paths.size(), 2u );
235 SCH_SCREEN* screen = paths.front().LastScreen();
239 auto* symbol =
static_cast<SCH_SYMBOL*
>( *symbols.begin() );
240 SCOPED_NATIVE_LIBRARY
library( m_schematic->Project() );
241 const auto native =
library.external->Flatten();
242 symbol->SetLibSymbol(
new LIB_SYMBOL( *native ) );
243 symbol->SetLibId(
LIB_ID(
"Embedded",
"Base" ) );
245 const LIB_ID missing(
library.row->Nickname(),
"MissingVariantSymbol" );
246 const wxString variant = wxS(
"Captured variant" );
247 m_schematic->AddVariant( variant );
248 symbol->SetVariantSymbolOverride( paths[0], variant, alternate );
249 symbol->SetVariantSymbolOverride( paths[1], variant, missing );
252 m_schematic->RebuildConnectivity();
254 symbol->GetLibSymbolRef()->SetUnitCount( native->GetUnitCount() + 1,
false );
259 BOOST_REQUIRE_GT( count, 1 );
260 std::vector<SCH_MARKER*> legacy;
263 legacy.push_back(
static_cast<SCH_MARKER*
>( item ) );
268 proto.mutable_marker()->clear_main_item_sheet_path();
274 m_schematic->ResolveERCExclusionsPostUpdate();
279 BOOST_CHECK(
static_cast<SCH_MARKER*
>( item )->IsExcluded() );
294 wxString legacyLibPath = wxString( dataDir +
"issue22371/lib.sch/74xx.lib" );
300 auto it = symbols.find(
"74LS00" );
301 BOOST_REQUIRE_MESSAGE( it != symbols.end(),
"74LS00 not found in legacy library" );
303 std::unique_ptr<LIB_SYMBOL> flattenedLibSymbol = it->second->Flatten();
314 if( !libSymbolInSchematic )
320 int flags =
~SCH_ITEM::COMPARE_FLAGS::UUID;
322 flags &=
~SCH_ITEM::COMPARE_FLAGS::IDENTITY;
324 int result = flattenedLibSymbol->Compare( *libSymbolInSchematic, flags );
332 result = flattenedLibSymbol->Compare( *libSymbolInSchematic, defaultFlags );
339 BOOST_FAIL(
"No 74LS00 symbol found in schematic" );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
EE_TYPE OfType(KICAD_T aType) const
const kiapi::schematic::ErcExclusion & ToProto() const
static ERC_EXCLUSION FromMarker(const SCH_MARKER &aMarker)
static ERC_EXCLUSION FromProto(const kiapi::schematic::ErcExclusion &aMessage)
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
int TestVariantSymbols()
Test all variant symbol overrides for resolution and pin compatibility.
wxString AsString() const
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
Define a library symbol object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
std::shared_ptr< RC_ITEM > GetRCItem() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
These are loaded from Eeschema settings but then overwritten by the project settings.
A cache assistant for KiCad legacy symbol libraries.
const LIB_SYMBOL_MAP & GetSymbolMap() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
void DeleteItem(SCH_ITEM *aItem)
Remove aItem from the linked list and deletes the object.
const LIB_ID & GetLibId() const override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
RAII class that sets an value at construction and resets it to the original value at destruction.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
@ ERCE_VARIANT_SYMBOL_INCOMPATIBLE
Variant symbol override fails pin compatibility.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
@ ERCE_VARIANT_SYMBOL_INVALID
Variant symbol override LIB_ID cannot be resolved.
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< SCHEMATIC > m_schematic
ERC_LIB_SYMBOL_MISMATCH_FIXTURE()
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol library map sorted by the symbol name.
BOOST_FIXTURE_TEST_CASE(ServerStartsAndResponds, API_SERVER_E2E_FIXTURE)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_FIXTURE_TEST_CASE(LibraryIssuesPreserveSharedPathsAndExclusions, ERC_LIB_SYMBOL_MISMATCH_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")