KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue15792_bus_breakout_hierarchy.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
22
23#include <advanced_config.h>
24#include <locale_io.h>
25#include <sch_pin.h>
26#include <sch_screen.h>
27#include <sch_symbol.h>
28#include <schematic.h>
29#include <scoped_set_reset.h>
31
32#include <map>
33
34
35// Members of different buses joined by breakout wires in subsheets reach the parent buses, so R1
36// shares nets with R3 (issue 15792)
37BOOST_AUTO_TEST_CASE( Issue15792BusBreakoutsJoinAcrossHierarchy )
38{
39 LOCALE_IO locale;
40 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
41 SCOPED_SET_RESET restore( enabled, enabled );
42
43 for( bool useEngine : { false, true } )
44 {
45 BOOST_TEST_CONTEXT( "engine=" << useEngine )
46 {
47 enabled = useEngine;
48 SETTINGS_MANAGER settings;
49 std::unique_ptr<SCHEMATIC> schematic;
50 KI_TEST::LoadSchematic( settings, "issue15792/bustests", schematic );
51 schematic->RebuildConnectivity();
52 std::map<wxString, wxString> nets;
53
54 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
55 {
56 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
57 {
58 auto* symbol = static_cast<SCH_SYMBOL*>( item );
59 const wxString ref = symbol->GetRef( &path );
60
61 if( ref != wxS( "R1" ) && ref != wxS( "R3" ) )
62 continue;
63
64 for( SCH_PIN* pin : symbol->GetPins( &path ) )
65 {
66 nets[ref + wxS( "." ) + pin->GetNumber()] =
67 pin->GetConnectionName( &path ).value_or( wxString() );
68 }
69 }
70 }
71
72 for( const wxString& key : { wxS( "R1.1" ), wxS( "R1.2" ), wxS( "R3.1" ), wxS( "R3.2" ) } )
73 {
74 BOOST_REQUIRE_MESSAGE( nets.contains( key ), "Missing pin " << key );
75 BOOST_CHECK_MESSAGE( !nets[key].IsEmpty(), "Pin " << key << " has no net" );
76 }
77
78 BOOST_CHECK_EQUAL( nets[wxS( "R1.1" )], nets[wxS( "R3.1" )] );
79 BOOST_CHECK_EQUAL( nets[wxS( "R1.2" )], nets[wxS( "R3.2" )] );
80 BOOST_CHECK_NE( nets[wxS( "R1.1" )], nets[wxS( "R1.2" )] );
81 }
82 }
83}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
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:74
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
RAII class that sets an value at construction and resets it to the original value at destruction.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
BOOST_AUTO_TEST_CASE(Issue15792BusBreakoutsJoinAcrossHierarchy)
std::string path
KIBIS_PIN * pin
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:168