KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bus_net_name_determinism.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 here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 * or you may search the http://www.gnu.org website for the version 32 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
33
36
37#include <connection_graph.h>
38#include <schematic.h>
39#include <sch_sheet.h>
40#include <sch_screen.h>
41#include <sch_symbol.h>
42#include <sch_pin.h>
44#include <locale_io.h>
45
54
55
66BOOST_FIXTURE_TEST_CASE( ShortedBusNetsHaveDeterministicName, BUS_NET_NAME_DETERMINISM_FIXTURE )
67{
69
70 // Load the test schematic multiple times to verify determinism
71 for( int iteration = 0; iteration < 3; ++iteration )
72 {
73 KI_TEST::LoadSchematic( m_settingsManager, "issue18606/issue18606", m_schematic );
74
75 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
76
77 // Find the resistor R201 in the child sheet and check its pin's net name
78 wxString foundNetName;
79 bool foundResistor = false;
80
81 for( const SCH_SHEET_PATH& path : sheets )
82 {
83 SCH_SCREEN* screen = path.LastScreen();
84
85 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
86 {
87 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
88
89 if( symbol->GetRef( &path ) == "R201" )
90 {
91 foundResistor = true;
92
93 for( SCH_PIN* pin : symbol->GetPins( &path ) )
94 {
95 SCH_CONNECTION* conn = pin->Connection( &path );
96
97 if( conn )
98 {
99 foundNetName = conn->Name();
100 break;
101 }
102 }
103
104 break;
105 }
106 }
107
108 if( foundResistor )
109 break;
110 }
111
112 BOOST_CHECK_MESSAGE( foundResistor, "R201 should be found in the schematic" );
113
114 // The net name should be deterministic - alphabetically "A0" should win
115 // when A0, A1, A2, A3 are shorted together.
116 // The path is "/" (not "/test/") because the net name is inherited from the
117 // parent sheet's bus A[0..3] during hierarchical propagation.
118 BOOST_CHECK_MESSAGE( foundNetName == "/A0",
119 "Net name should be '/A0' (alphabetically first bus member), "
120 "but got '" << foundNetName.ToStdString() << "' on iteration "
121 << iteration );
122 }
123}
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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:76
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(ShortedBusNetsHaveDeterministicName, BUS_NET_NAME_DETERMINISM_FIXTURE)
Test that when bus member nets (A0, A1, A2, A3) are shorted together, the resulting net name is deter...
std::string path
KIBIS_PIN * pin
@ SCH_SYMBOL_T
Definition typeinfo.h:176