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, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
21#include <boost/test/unit_test.hpp>
24#include <locale_io.h>
25#include <lib_symbol.h>
26#include <sch_screen.h>
27#include <sch_symbol.h>
28#include <reporter.h>
31#include <wx/string.h>
32
40
41
42BOOST_AUTO_TEST_SUITE( ERCLibSymbolMismatch )
43
44
46{
48
49 KI_TEST::LoadSchematic( m_settingsManager, wxString( "issue22371/issue22371" ), m_schematic );
50
51 std::string dataDir = KI_TEST::GetEeschemaTestDataDir();
52 wxString legacyLibPath = wxString( dataDir + "issue22371/lib.sch/74xx.lib" );
53
54 SCH_IO_KICAD_LEGACY_LIB_CACHE legacyCache( legacyLibPath );
55 legacyCache.Load();
56
57 const LIB_SYMBOL_MAP& symbols = legacyCache.GetSymbolMap();
58 auto it = symbols.find( "74LS00" );
59 BOOST_REQUIRE_MESSAGE( it != symbols.end(), "74LS00 not found in legacy library" );
60
61 std::unique_ptr<LIB_SYMBOL> flattenedLibSymbol = it->second->Flatten();
62
63 SCH_SCREENS screens( m_schematic->Root() );
64
65 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
66 {
67 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
68 {
69 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
70 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
71
72 if( !libSymbolInSchematic )
73 continue;
74
75 if( symbol->GetLibId().GetLibItemName() != "74LS00" )
76 continue;
77
78 constexpr int flags = SCH_ITEM::COMPARE_FLAGS::EQUALITY
80
81 int result = flattenedLibSymbol->Compare( *libSymbolInSchematic, flags );
82
84 return;
85 }
86 }
87
88 BOOST_FAIL( "No 74LS00 symbol found in schematic" );
89}
90
91
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
Define a library symbol object.
Definition lib_symbol.h:83
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
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:166
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:750
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Schematic symbol object.
Definition sch_symbol.h:73
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:162
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:181
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:173