KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_net_chains_branching.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
20#include <boost/test/unit_test.hpp>
21
24#include <connection_graph.h>
25#include <schematic.h>
26#include <sch_symbol.h>
27#include <locale_io.h>
29
30#include <set>
31#include <algorithm>
32#include <vector>
33
40
41static void loadFixture( const wxString& name, std::unique_ptr<SCHEMATIC>& schematic,
42 SETTINGS_MANAGER& settings )
43{
44 settings.LoadProject( wxString() );
45 KI_TEST::LoadSchematic( settings, name, schematic );
46 SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
47 schematic->ConnectionGraph()->Recalculate( sheets, true );
48}
49
51{
53 AVOID_GND, // Ensure no net named GND appears in the grouped signal nets
54 NET_TAIL_EQUAL // For 2‑net signals ensure final character matches (naming consistency)
55};
56
58{
59 const char* fixtureName;
62 BRANCH_EXTRA_CHECK extra; // Additional per‑fixture validations
63};
64
65// Table describing the four core branching scenarios previously expressed as individual tests.
67 { "net_chains_branching_longer", 1, 4, BRANCH_EXTRA_CHECK::NONE },
68 { "net_chains_branching_no_power", 2, 4, BRANCH_EXTRA_CHECK::AVOID_GND },
69 { "net_chains_branching_named", 1, 2, BRANCH_EXTRA_CHECK::NONE },
70 { "net_chains_branching_named2", 2, 2, BRANCH_EXTRA_CHECK::NET_TAIL_EQUAL }
71};
72
73BOOST_FIXTURE_TEST_CASE( SignalBuilder_BranchingVariants, SIGNALS_BRANCH_TEST_FIXTURE )
74{
76
77 for( const BRANCH_TEST_PARAM& p : BRANCH_PARAMS )
78 {
79 BOOST_TEST_CONTEXT( "fixture=" << p.fixtureName )
80 {
81 loadFixture( wxString( p.fixtureName ), m_schematic, m_settingsManager );
82
83 size_t count = 0;
84 size_t maxNets = 0;
85
86 // Use potential net chains (auto-inferred, not yet user-created).
87 for( const auto& sig : m_schematic->ConnectionGraph()->GetPotentialNetChains() )
88 {
89 if( !sig )
90 continue;
91
92 ++count;
93 maxNets = std::max( maxNets, sig->GetNets().size() );
94
95 if( p.extra == BRANCH_EXTRA_CHECK::AVOID_GND )
96 {
97 for( const wxString& net : sig->GetNets() )
98 BOOST_CHECK_NE( net, wxS( "GND" ) );
99 }
100 else if( p.extra == BRANCH_EXTRA_CHECK::NET_TAIL_EQUAL && sig->GetNets().size() == 2 )
101 {
102 const auto& it1 = *sig->GetNets().begin();
103 const auto& it2 = *std::next( sig->GetNets().begin() );
104 int tail1 = it1.Last();
105 int tail2 = it2.Last();
106 BOOST_CHECK_EQUAL( tail1, tail2 );
107 }
108 }
109
110 BOOST_CHECK_EQUAL( (int) count, p.expectedSignalCount );
111 BOOST_CHECK_EQUAL( (int) maxNets, p.expectedMaxNets );
112 }
113 }
114}
115
116// EOF
const char * name
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
@ NONE
Definition eda_shape.h:72
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
static void loadFixture(const wxString &name, std::unique_ptr< SCHEMATIC > &schematic, SETTINGS_MANAGER &settings)
static const BRANCH_TEST_PARAM BRANCH_PARAMS[]
BOOST_FIXTURE_TEST_CASE(SignalBuilder_BranchingVariants, SIGNALS_BRANCH_TEST_FIXTURE)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")