KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_component_classes.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 2
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 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <board.h>
29#include <pad.h>
30#include <pcb_track.h>
31#include <pcb_marker.h>
32#include <footprint.h>
33#include <drc/drc_item.h>
35
36
45
46
48{
49 KI_TEST::LoadBoard( m_settingsManager, "component_classes", m_board );
50
51 std::vector<DRC_ITEM> violations;
52 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
53
54 std::vector<wxString> allClasses{ "ANY", "CAP_1", "CAP_2", "CLASS_1",
55 "CLASS_2", "CLASS_3", "CLASS_4", "MULTI_REF",
56 "REF_WILDCARD", "REF_WILDCARD2", "RES_1", "RES_2",
57 "RES_3", "RES_4" };
58
59 auto testClasses = [&allClasses](const wxString& ref, const COMPONENT_CLASS* compClass, std::vector<wxString> assignedClasses)
60 {
61 std::vector<wxString> unassignedClasses;
62 std::ranges::set_difference(allClasses, assignedClasses, std::back_inserter(unassignedClasses));
63
64 for( const wxString& className : assignedClasses )
65 {
66 if( !compClass->ContainsClassName( className ) )
67 {
68 BOOST_ERROR( wxString::Format(
69 "%s component class failed (%s expected but not found - full class %s)",
70 ref, className, compClass->GetName() ) );
71 }
72 }
73
74 for( const wxString& className : unassignedClasses )
75 {
76 if( compClass->ContainsClassName( className ) )
77 {
78 BOOST_ERROR( wxString::Format(
79 "%s component class failed (%s found but not expected - full class %s)",
80 ref, className, compClass->GetName() ) );
81 }
82 }
83 };
84
85 for( const auto fp : m_board->Footprints() )
86 {
87 if( fp->Reference().GetText() == wxT( "C1" ) )
88 {
89 testClasses( "C1", fp->GetComponentClass(), {"CAP_1", "CLASS_3", "CLASS_4"});
90 }
91
92 if( fp->Reference().GetText() == wxT( "C2" ) )
93 {
94 testClasses( "C2", fp->GetComponentClass(), {"CAP_2", "CLASS_3"});
95 }
96
97 if( fp->Reference().GetText() == wxT( "C3" ) )
98 {
99 testClasses( "C2", fp->GetComponentClass(), {});
100 }
101
102 if( fp->Reference().GetText() == wxT( "R8" ) )
103 {
104 testClasses( "R8", fp->GetComponentClass(), {"RES_1", "RES_2"});
105 }
106
107 if( fp->Reference().GetText() == wxT( "R88" ) )
108 {
109 testClasses( "R88", fp->GetComponentClass(), {"RES_2"});
110 }
111
112 if( fp->Reference().GetText() == wxT( "R2" ) )
113 {
114 testClasses( "R2", fp->GetComponentClass(), {"CLASS_1", "RES_1", "RES_2", "RES_3"});
115 }
116
117 if( fp->Reference().GetText() == wxT( "R1" ) )
118 {
119 testClasses( "R1", fp->GetComponentClass(), {"CLASS_1", "CLASS_2", "RES_1", "RES_2", "RES_4"});
120 }
121
122 if( fp->Reference().GetText() == wxT( "U1" ) )
123 {
124 testClasses( "U1", fp->GetComponentClass(), { "ANY" } );
125 }
126
127 if( fp->Reference().GetText() == wxT( "U2" ) )
128 {
129 testClasses( "U2", fp->GetComponentClass(), { "ANY" } );
130 }
131
132 if( fp->Reference().GetText() == wxT( "U3" ) )
133 {
134 testClasses( "U3", fp->GetComponentClass(), { "MULTI_REF" } );
135 }
136
137 if( fp->Reference().GetText() == wxT( "U4" ) )
138 {
139 testClasses( "U4", fp->GetComponentClass(), { "MULTI_REF" } );
140 }
141
142 if( fp->Reference().GetText() == wxT( "U55" ) )
143 {
144 testClasses( "U55", fp->GetComponentClass(), { "REF_WILDCARD", "REF_WILDCARD2" } );
145 }
146
147 if( fp->Reference().GetText() == wxT( "U555" ) )
148 {
149 testClasses( "U555", fp->GetComponentClass(), { "REF_WILDCARD2" } );
150 }
151
152 if( fp->Reference().GetText() == wxT( "R3" ) )
153 {
154 testClasses( "R3", fp->GetComponentClass(), { "/SHEET1/", "RES_1", "RES_2" } );
155 }
156 }
157
158}
Container for design settings for a BOARD object.
A lightweight representation of a component class.
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOOST_FIXTURE_TEST_CASE(ComponentClasses, PCB_COMPONENT_CLASS_FIXTURE)