KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_pin_context.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
23#include <schematic.h>
24#include <sch_screen.h>
25#include <sch_symbol.h>
27#include <locale_io.h>
28#include <algorithm>
29#include <map>
30#include <set>
31
32BOOST_AUTO_TEST_CASE( ERCPinContextOrderUsesInstanceAndPinIdentity )
33{
34 LOCALE_IO locale;
35 SETTINGS_MANAGER firstSettings;
36 SETTINGS_MANAGER secondSettings;
37 std::unique_ptr<SCHEMATIC> first;
38 std::unique_ptr<SCHEMATIC> second;
39 KI_TEST::LoadSchematic( firstSettings, "issue23840/BusAndVectors", first );
40 KI_TEST::LoadSchematic( secondSettings, "issue23840/BusAndVectors", second );
41 using KEY = std::pair<KIID_PATH, KIID>;
42 const auto contexts = []( SCHEMATIC& schematic )
43 {
44 std::map<KEY, ERC_SCH_PIN_CONTEXT> result;
45
46 for( const SCH_SHEET_PATH& path : schematic.Hierarchy() )
47 {
48 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
49 {
50 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &path ) )
51 {
52 const bool inserted = result.emplace( KEY{ path.Path(), pin->m_Uuid },
53 ERC_SCH_PIN_CONTEXT( pin, path ) ).second;
54 BOOST_REQUIRE( inserted );
55 }
56 }
57 }
58
59 return result;
60 };
61 const auto originals = contexts( *first );
62 const auto reloaded = contexts( *second );
63 BOOST_REQUIRE_GT( originals.size(), 1 );
64 BOOST_REQUIRE_EQUAL( originals.size(), reloaded.size() );
66 const ERC_SCH_PIN_CONTEXT missing( nullptr, originals.begin()->second.Sheet() );
67 BOOST_CHECK( empty == ERC_SCH_PIN_CONTEXT() );
68 BOOST_CHECK( !( empty < empty ) );
69 BOOST_CHECK( empty < missing );
70 BOOST_CHECK( !( missing < empty ) );
71 BOOST_CHECK( !( empty == missing ) );
72 BOOST_CHECK( missing < originals.begin()->second );
73 BOOST_CHECK( !( originals.begin()->second < missing ) );
74 BOOST_CHECK( !( missing == originals.begin()->second ) );
75 std::map<SCH_PIN*, std::set<KIID_PATH>> instances;
76 std::vector<ERC_SCH_PIN_CONTEXT> shuffled;
77
78 for( const auto& [key, context] : originals )
79 {
80 const auto other = reloaded.find( key );
81 BOOST_REQUIRE( other != reloaded.end() );
82 BOOST_CHECK( context.Pin() != other->second.Pin() );
83 BOOST_CHECK( context == other->second );
84 BOOST_CHECK( !( context < other->second ) );
85 BOOST_CHECK( !( other->second < context ) );
86 instances[context.Pin()].insert( key.first );
87 shuffled.push_back( context );
88 }
89
90 BOOST_REQUIRE( std::any_of( instances.begin(), instances.end(),
91 []( const auto& entry ) { return entry.second.size() > 1; } ) );
92 std::reverse( shuffled.begin(), shuffled.end() );
93 std::sort( shuffled.begin(), shuffled.end() );
94 auto expected = originals.begin();
95
96 for( const ERC_SCH_PIN_CONTEXT& context : shuffled )
97 {
98 BOOST_CHECK( context.Sheet().PathRef() == expected->first.first );
99 BOOST_CHECK( context.Pin()->m_Uuid == expected->first.second );
100 ++expected;
101 }
102}
A class used to associate a SCH_PIN with its owning SCH_SHEET_PATH, in order to handle ERC checks acr...
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Holds all the data relating to one schematic.
Definition schematic.h:148
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:75
static bool empty(const wxTextEntryBase *aCtrl)
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
BOOST_AUTO_TEST_CASE(ERCPinContextOrderUsesInstanceAndPinIdentity)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
wxString result
Test unit parsing edge cases and error handling.
@ SCH_SYMBOL_T
Definition typeinfo.h:168