KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_connectivity_algo.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
24
27
28#include <connection_graph.h>
29#include <schematic.h>
30#include <sch_sheet.h>
31#include <sch_screen.h>
32#include <sch_symbol.h>
33#include <sch_pin.h>
35#include <locale_io.h>
36
45
47{
49
50 std::vector<std::pair<wxString, int>> tests =
51 {
52 { "issue18092/issue18092", 1 }
53 };
54
55 for( auto&[ name, nets] : tests )
56 {
57 KI_TEST::LoadSchematic( m_settingsManager, name, m_schematic );
58
59 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
60 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
61
62 BOOST_CHECK( nets == graph->GetNetMap().size() );
63
64 }
65}
66
67
80{
82
83 KI_TEST::LoadSchematic( m_settingsManager, "issue17771/issue1771", m_schematic );
84
85 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
86 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
87
88 // Find test points and their net connections
89 // TP101 and TP401 should be on the same net (m.X.Y.Z1)
90 // TP102 and TP402 should be on the same net (m.X.Y.Z2)
91 std::map<wxString, int> tpNetCodes; // Test point reference -> net code
92
93 for( const auto& [key, subgraphs] : graph->GetNetMap() )
94 {
95 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
96 {
97 for( SCH_ITEM* item : subgraph->GetItems() )
98 {
99 if( item->Type() == SCH_PIN_T )
100 {
101 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
102 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
103
104 if( symbol )
105 {
106 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
107
108 if( ref == "TP101" || ref == "TP102" ||
109 ref == "TP401" || ref == "TP402" )
110 {
111 tpNetCodes[ref] = key.Netcode;
112 }
113 }
114 }
115 }
116 }
117 }
118
119 // Verify we found all test points
120 BOOST_REQUIRE_MESSAGE( tpNetCodes.count( "TP101" ),
121 "TP101 should be found in netlist" );
122 BOOST_REQUIRE_MESSAGE( tpNetCodes.count( "TP102" ),
123 "TP102 should be found in netlist" );
124 BOOST_REQUIRE_MESSAGE( tpNetCodes.count( "TP401" ),
125 "TP401 should be found in netlist" );
126 BOOST_REQUIRE_MESSAGE( tpNetCodes.count( "TP402" ),
127 "TP402 should be found in netlist" );
128
129 // TP101 and TP401 should be on the same net (m.X.Y.Z1 path)
130 BOOST_CHECK_MESSAGE( tpNetCodes["TP101"] == tpNetCodes["TP401"],
131 "TP101 and TP401 should be on the same net (m.X.Y.Z1)" );
132
133 // TP102 and TP402 should be on the same net (m.X.Y.Z2 path)
134 // This is the bug - without the fix, these will be on different nets
135 BOOST_CHECK_MESSAGE( tpNetCodes["TP102"] == tpNetCodes["TP402"],
136 "TP102 and TP402 should be on the same net (m.X.Y.Z2)" );
137}
const char * name
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:76
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
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(CheckNetCounts, CONNECTIVITY_TEST_FIXTURE)
KIBIS_PIN * pin
@ SCH_PIN_T
Definition typeinfo.h:157