KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_lib_symbol_mismatch.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
23#include <locale_io.h>
24#include <lib_symbol.h>
25#include <sch_screen.h>
26#include <sch_symbol.h>
27#include <reporter.h>
30#include <wx/string.h>
31
39
40
41BOOST_AUTO_TEST_SUITE( ERCLibSymbolMismatch )
42
43
45{
47
48 KI_TEST::LoadSchematic( m_settingsManager, wxString( "issue22371/issue22371" ), m_schematic );
49
50 std::string dataDir = KI_TEST::GetEeschemaTestDataDir();
51 wxString legacyLibPath = wxString( dataDir + "issue22371/lib.sch/74xx.lib" );
52
53 SCH_IO_KICAD_LEGACY_LIB_CACHE legacyCache( legacyLibPath );
54 legacyCache.Load();
55
56 const LIB_SYMBOL_MAP& symbols = legacyCache.GetSymbolMap();
57 auto it = symbols.find( "74LS00" );
58 BOOST_REQUIRE_MESSAGE( it != symbols.end(), "74LS00 not found in legacy library" );
59
60 std::unique_ptr<LIB_SYMBOL> flattenedLibSymbol = it->second->Flatten();
61
62 SCH_SCREENS screens( m_schematic->Root() );
63
64 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
65 {
66 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
67 {
68 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
69 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
70
71 if( !libSymbolInSchematic )
72 continue;
73
74 if( symbol->GetLibId().GetLibItemName() != "74LS00" )
75 continue;
76
77 constexpr int flags = SCH_ITEM::COMPARE_FLAGS::EQUALITY
79
80 int result = flattenedLibSymbol->Compare( *libSymbolInSchematic, flags );
81
83 return;
84 }
85 }
86
87 BOOST_FAIL( "No 74LS00 symbol found in schematic" );
88}
89
90
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
Define a library symbol object.
Definition lib_symbol.h:79
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
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,...
Definition sch_item.h:162
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:746
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:69
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:158
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:177
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
std::vector< FAB_LAYER_COLOR > dummy
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
BOOST_FIXTURE_TEST_CASE(ServerStartsAndResponds, API_SERVER_E2E_FIXTURE)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:169