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, see <https://www.gnu.org/licenses/>.
18 */
19
29
32
33#include <connection_graph.h>
34#include <schematic.h>
35#include <sch_sheet.h>
36#include <sch_screen.h>
37#include <sch_symbol.h>
38#include <sch_pin.h>
40#include <locale_io.h>
41
50
51
62BOOST_FIXTURE_TEST_CASE( ShortedBusNetsHaveDeterministicName, BUS_NET_NAME_DETERMINISM_FIXTURE )
63{
65
66 // Load the test schematic multiple times to verify determinism
67 for( int iteration = 0; iteration < 3; ++iteration )
68 {
69 KI_TEST::LoadSchematic( m_settingsManager, "issue18606/issue18606", m_schematic );
70
71 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
72
73 // Find the resistor R201 in the child sheet and check its pin's net name
74 wxString foundNetName;
75 bool foundResistor = false;
76
77 for( const SCH_SHEET_PATH& path : sheets )
78 {
79 SCH_SCREEN* screen = path.LastScreen();
80
81 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
82 {
83 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
84
85 if( symbol->GetRef( &path ) == "R201" )
86 {
87 foundResistor = true;
88
89 for( SCH_PIN* pin : symbol->GetPins( &path ) )
90 {
91 SCH_CONNECTION* conn = pin->Connection( &path );
92
93 if( conn )
94 {
95 foundNetName = conn->Name();
96 break;
97 }
98 }
99
100 break;
101 }
102 }
103
104 if( foundResistor )
105 break;
106 }
107
108 BOOST_CHECK_MESSAGE( foundResistor, "R201 should be found in the schematic" );
109
110 // The net name should be deterministic - alphabetically "A0" should win
111 // when A0, A1, A2, A3 are shorted together.
112 // The path is "/" (not "/test/") because the net name is inherited from the
113 // parent sheet's bus A[0..3] during hierarchical propagation.
114 BOOST_CHECK_MESSAGE( foundNetName == "/A0",
115 "Net name should be '/A0' (alphabetically first bus member), "
116 "but got '" << foundNetName.ToStdString() << "' on iteration "
117 << iteration );
118 }
119}
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
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:162
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
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:69
std::vector< const 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
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_SYMBOL_T
Definition typeinfo.h:169