KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_netlist_exporter_xml_nested_groups.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/*
21 * Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/24766
22 *
23 * The XML netlist must list a nested child group's uuid among its parent group's members.
24 *
25 * Fixture nested_groups.kicad_sch has group OUTER containing symbol R3 and group INNER.
26 */
27
30
32#include <schematic.h>
34#include <locale_io.h>
35
36#include <set>
37
38#include <wx/filename.h>
39#include <wx/xml/xml.h>
40
41
49
50
51static wxXmlNode* find_child( wxXmlNode* aParent, const wxString& aName )
52{
53 for( wxXmlNode* child = aParent->GetChildren(); child; child = child->GetNext() )
54 {
55 if( child->GetName() == aName )
56 return child;
57 }
58
59 return nullptr;
60}
61
62
63BOOST_FIXTURE_TEST_CASE( NetlistExporterXML_NestedGroupMembershipPreserved, XML_NESTED_GROUPS_FIXTURE )
64{
66 KI_TEST::LoadSchematic( m_settingsManager, wxT( "nested_groups" ), m_schematic );
67
68 wxFileName netFile = m_schematic->Project().GetProjectFullName();
69 netFile.SetName( netFile.GetName() + wxT( "_nested_groups_test" ) );
70 netFile.SetExt( wxT( "xml" ) );
71
72 if( wxFileExists( netFile.GetFullPath() ) )
73 wxRemoveFile( netFile.GetFullPath() );
74
76 std::unique_ptr<NETLIST_EXPORTER_XML> exporter = std::make_unique<NETLIST_EXPORTER_XML>( m_schematic.get() );
77
78 // Groups are only emitted for the KiCad-internal netlist.
79 BOOST_REQUIRE( exporter->WriteNetlist( netFile.GetFullPath(), GNL_OPT_KICAD, reporter ) );
80
81 wxXmlDocument xdoc;
82 BOOST_REQUIRE( xdoc.Load( netFile.GetFullPath() ) );
83
84 wxXmlNode* root = xdoc.GetRoot();
85 BOOST_REQUIRE( root );
86
87 wxXmlNode* xgroups = find_child( root, wxT( "groups" ) );
88 BOOST_REQUIRE_MESSAGE( xgroups, "expected a <groups> block in the netlist" );
89
90 std::set<wxString> groupUuids;
91 std::vector<std::set<wxString>> groupMembers;
92
93 for( wxXmlNode* xgroup = xgroups->GetChildren(); xgroup; xgroup = xgroup->GetNext() )
94 {
95 if( xgroup->GetName() != wxT( "group" ) )
96 continue;
97
98 groupUuids.insert( xgroup->GetAttribute( wxT( "uuid" ), wxEmptyString ) );
99
100 std::set<wxString> members;
101
102 if( wxXmlNode* xmembers = find_child( xgroup, wxT( "members" ) ) )
103 {
104 for( wxXmlNode* xm = xmembers->GetChildren(); xm; xm = xm->GetNext() )
105 {
106 if( xm->GetName() == wxT( "member" ) )
107 members.insert( xm->GetAttribute( wxT( "uuid" ), wxEmptyString ) );
108 }
109 }
110
111 groupMembers.push_back( std::move( members ) );
112 }
113
114 BOOST_REQUIRE_MESSAGE( groupUuids.size() >= 2, "fixture must contain a parent and a nested child group" );
115
116 bool nestedReferenceFound = false;
117
118 for( const std::set<wxString>& members : groupMembers )
119 {
120 for( const wxString& member : members )
121 {
122 if( groupUuids.count( member ) )
123 {
124 nestedReferenceFound = true;
125 break;
126 }
127 }
128
129 if( nestedReferenceFound )
130 break;
131 }
132
133 BOOST_CHECK_MESSAGE( nestedReferenceFound, "no group lists another group's UUID as a member; nested group "
134 "membership was dropped during XML export" );
135
136 wxRemoveFile( netFile.GetFullPath() );
137}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
A wrapper for reporting to a wxString object.
Definition reporter.h:189
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ GNL_OPT_KICAD
std::vector< FAB_LAYER_COLOR > dummy
XML_NESTED_GROUPS_FIXTURE()=default
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
IbisParser parser & reporter
static wxXmlNode * find_child(wxXmlNode *aParent, const wxString &aName)
BOOST_FIXTURE_TEST_CASE(NetlistExporterXML_NestedGroupMembershipPreserved, XML_NESTED_GROUPS_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")