KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24220_hierarchical_bus_netclass.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
34
37
38#include <wx/filename.h>
39#include <wx/xml/xml.h>
40
44#include <schematic.h>
46#include <string_utils.h>
47
48
56
57
58BOOST_FIXTURE_TEST_SUITE( Issue24220HierarchicalBusNetclass, ISSUE24220_FIXTURE )
59
60
61// The schematic ships with patterns "*AD.1*", "*AD.2*", "*AD*" all assigned to the
62// "ADI" netclass. Verify that the live NET_SETTINGS lookup (the same one the
63// schematic painter uses) returns the expected ADI class for the bus member nets.
64BOOST_AUTO_TEST_CASE( NetSettingsResolvesBusMemberToAdi )
65{
66 KI_TEST::LoadSchematic( m_settingsManager, wxT( "netlists/issue24220/issue24220" ),
67 m_schematic );
68
69 std::shared_ptr<NET_SETTINGS>& netSettings =
70 m_schematic->Project().GetProjectFile().m_NetSettings;
71
72 BOOST_REQUIRE( netSettings );
73
74 // The "ADI" netclass in the project only specifies some parameters, so
75 // GetEffectiveNetClass composites it with the Default netclass to fill in
76 // the rest. The composite's name leads with "ADI" so users still see the
77 // matching class in netlist/UI output.
78 BOOST_CHECK( netSettings->GetEffectiveNetClass( wxT( "/AD.1" ) )
79 ->GetName()
80 .StartsWith( wxT( "ADI" ) ) );
81 BOOST_CHECK( netSettings->GetEffectiveNetClass( wxT( "/AD.2" ) )
82 ->GetName()
83 .StartsWith( wxT( "ADI" ) ) );
84}
85
86
87// Regression for the reported bug: the XML exporter must emit class="ADI" for
88// the bus member nets, matching what the schematic editor displays. Before the
89// fix, the exporter emitted class="Default" because the bus-member subgraph's
90// driver SCH_ITEM is null and the lookup was falling back via that path.
91BOOST_AUTO_TEST_CASE( XmlExportClassMatchesNetSettings )
92{
93 KI_TEST::LoadSchematic( m_settingsManager, wxT( "netlists/issue24220/issue24220" ),
94 m_schematic );
95
96 std::shared_ptr<NET_SETTINGS>& netSettings =
97 m_schematic->Project().GetProjectFile().m_NetSettings;
98
99 BOOST_REQUIRE( netSettings );
100
101 wxFileName netFile = m_schematic->Project().GetProjectFullName();
102 netFile.SetName( netFile.GetName() + wxT( "_issue24220_test" ) );
103 netFile.SetExt( wxT( "xml" ) );
104
105 if( wxFileExists( netFile.GetFullPath() ) )
106 wxRemoveFile( netFile.GetFullPath() );
107
109 std::unique_ptr<NETLIST_EXPORTER_XML> exporter =
110 std::make_unique<NETLIST_EXPORTER_XML>( m_schematic.get() );
111
112 bool success = exporter->WriteNetlist( netFile.GetFullPath(), 0, reporter );
113 BOOST_REQUIRE( success );
114
115 wxXmlDocument xdoc;
116 BOOST_REQUIRE( xdoc.Load( netFile.GetFullPath() ) );
117
118 wxXmlNode* root = xdoc.GetRoot();
119 BOOST_REQUIRE( root );
120
121 wxXmlNode* nets = nullptr;
122
123 for( wxXmlNode* child = root->GetChildren(); child; child = child->GetNext() )
124 {
125 if( child->GetName() == wxT( "nets" ) )
126 {
127 nets = child;
128 break;
129 }
130 }
131
132 BOOST_REQUIRE( nets );
133
134 bool matchedAd1 = false;
135 bool matchedAd2 = false;
136
137 for( wxXmlNode* net = nets->GetChildren(); net; net = net->GetNext() )
138 {
139 if( net->GetName() != wxT( "net" ) )
140 continue;
141
142 wxString netName = net->GetAttribute( wxT( "name" ), wxEmptyString );
143 wxString netClass = net->GetAttribute( wxT( "class" ), wxEmptyString );
144
145 if( netName != wxT( "/AD.1" ) && netName != wxT( "/AD.2" ) )
146 continue;
147
148 std::shared_ptr<NETCLASS> expected =
149 netSettings->GetEffectiveNetClass( netName );
150
152 BOOST_TEST_INFO( "net=" << netName );
153 BOOST_CHECK_EQUAL( netClass, UnescapeString( expected->GetName() ) );
154 // The painter shows the ADI color; the exporter should now agree.
155 BOOST_CHECK_NE( netClass, wxString( wxT( "Default" ) ) );
156 BOOST_CHECK( netClass.StartsWith( wxT( "ADI" ) ) );
157
158 if( netName == wxT( "/AD.1" ) )
159 matchedAd1 = true;
160 else if( netName == wxT( "/AD.2" ) )
161 matchedAd2 = true;
162 }
163
164 BOOST_CHECK( matchedAd1 );
165 BOOST_CHECK( matchedAd2 );
166
167 wxRemoveFile( netFile.GetFullPath() );
168}
169
170
A wrapper for reporting to a wxString object.
Definition reporter.h:193
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
wxString UnescapeString(const wxString &aSource)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(NetSettingsResolvesBusMemberToAdi)
IbisParser parser & reporter
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")