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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 */
20
21#include <boost/test/unit_test.hpp>
22
25#include <connection_graph.h>
26#include <schematic.h>
27#include <sch_symbol.h>
28#include <locale_io.h>
30
31#include <set>
32#include <algorithm>
33#include <vector>
34
41
42static void loadFixture( const wxString& name, std::unique_ptr<SCHEMATIC>& schematic,
43 SETTINGS_MANAGER& settings )
44{
45 settings.LoadProject( wxString() );
46 KI_TEST::LoadSchematic( settings, name, schematic );
47 SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
48 schematic->ConnectionGraph()->Recalculate( sheets, true );
49}
50
52{
54 AVOID_GND, // Ensure no net named GND appears in the grouped signal nets
55 NET_TAIL_EQUAL // For 2‑net signals ensure final character matches (naming consistency)
56};
57
59{
60 const char* fixtureName;
63 BRANCH_EXTRA_CHECK extra; // Additional per‑fixture validations
64};
65
66// Table describing the four core branching scenarios previously expressed as individual tests.
68 { "net_chains_branching_longer", 1, 4, BRANCH_EXTRA_CHECK::NONE },
69 { "net_chains_branching_no_power", 2, 4, BRANCH_EXTRA_CHECK::AVOID_GND },
70 { "net_chains_branching_named", 1, 2, BRANCH_EXTRA_CHECK::NONE },
71 { "net_chains_branching_named2", 2, 2, BRANCH_EXTRA_CHECK::NET_TAIL_EQUAL }
72};
73
74BOOST_FIXTURE_TEST_CASE( SignalBuilder_BranchingVariants, SIGNALS_BRANCH_TEST_FIXTURE )
75{
77
78 for( const BRANCH_TEST_PARAM& p : BRANCH_PARAMS )
79 {
80 BOOST_TEST_CONTEXT( "fixture=" << p.fixtureName )
81 {
82 loadFixture( wxString( p.fixtureName ), m_schematic, m_settingsManager );
83
84 size_t count = 0;
85 size_t maxNets = 0;
86
87 // Use potential net chains (auto-inferred, not yet user-created).
88 for( const auto& sig : m_schematic->ConnectionGraph()->GetPotentialNetChains() )
89 {
90 if( !sig )
91 continue;
92
93 ++count;
94 maxNets = std::max( maxNets, sig->GetNets().size() );
95
96 if( p.extra == BRANCH_EXTRA_CHECK::AVOID_GND )
97 {
98 for( const wxString& net : sig->GetNets() )
99 BOOST_CHECK_NE( net, wxS( "GND" ) );
100 }
101 else if( p.extra == BRANCH_EXTRA_CHECK::NET_TAIL_EQUAL && sig->GetNets().size() == 2 )
102 {
103 const auto& it1 = *sig->GetNets().begin();
104 const auto& it2 = *std::next( sig->GetNets().begin() );
105 int tail1 = it1.Last();
106 int tail2 = it2.Last();
107 BOOST_CHECK_EQUAL( tail1, tail2 );
108 }
109 }
110
111 BOOST_CHECK_EQUAL( (int) count, p.expectedSignalCount );
112 BOOST_CHECK_EQUAL( (int) maxNets, p.expectedMaxNets );
113 }
114 }
115}
116
117// EOF
const char * name
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
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:76
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")