KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
38{
40 m_settingsManager( true /* headless */ )
41 { }
42
44 std::unique_ptr<BOARD> m_board;
45};
46
47
49{
50 KI_TEST::LoadBoard( m_settingsManager, "component_classes", m_board );
51
52 std::vector<DRC_ITEM> violations;
53 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
54
55 std::vector<wxString> allClasses{ "ANY", "CAP_1", "CAP_2", "CLASS_1",
56 "CLASS_2", "CLASS_3", "CLASS_4", "MULTI_REF",
57 "REF_WILDCARD", "REF_WILDCARD2", "RES_1", "RES_2",
58 "RES_3", "RES_4" };
59
60 auto testClasses = [&allClasses](const wxString& ref, const COMPONENT_CLASS* compClass, std::vector<wxString> assignedClasses)
61 {
62 std::vector<wxString> unassignedClasses;
63 std::ranges::set_difference(allClasses, assignedClasses, std::back_inserter(unassignedClasses));
64
65 for( const wxString& className : assignedClasses )
66 {
67 if( !compClass->ContainsClassName( className ) )
68 {
69 BOOST_ERROR( wxString::Format(
70 "%s component class failed (%s expected but not found - full class %s)",
71 ref, className, compClass->GetName() ) );
72 }
73 }
74
75 for( const wxString& className : unassignedClasses )
76 {
77 if( compClass->ContainsClassName( className ) )
78 {
79 BOOST_ERROR( wxString::Format(
80 "%s component class failed (%s found but not expected - full class %s)",
81 ref, className, compClass->GetName() ) );
82 }
83 }
84 };
85
86 for( const auto fp : m_board->Footprints() )
87 {
88 if( fp->Reference().GetText() == wxT( "C1" ) )
89 {
90 testClasses( "C1", fp->GetComponentClass(), {"CAP_1", "CLASS_3", "CLASS_4"});
91 }
92
93 if( fp->Reference().GetText() == wxT( "C2" ) )
94 {
95 testClasses( "C2", fp->GetComponentClass(), {"CAP_2", "CLASS_3"});
96 }
97
98 if( fp->Reference().GetText() == wxT( "C3" ) )
99 {
100 testClasses( "C2", fp->GetComponentClass(), {});
101 }
102
103 if( fp->Reference().GetText() == wxT( "R8" ) )
104 {
105 testClasses( "R8", fp->GetComponentClass(), {"RES_1", "RES_2"});
106 }
107
108 if( fp->Reference().GetText() == wxT( "R88" ) )
109 {
110 testClasses( "R88", fp->GetComponentClass(), {"RES_2"});
111 }
112
113 if( fp->Reference().GetText() == wxT( "R2" ) )
114 {
115 testClasses( "R2", fp->GetComponentClass(), {"CLASS_1", "RES_1", "RES_2", "RES_3"});
116 }
117
118 if( fp->Reference().GetText() == wxT( "R1" ) )
119 {
120 testClasses( "R1", fp->GetComponentClass(), {"CLASS_1", "CLASS_2", "RES_1", "RES_2", "RES_4"});
121 }
122
123 if( fp->Reference().GetText() == wxT( "U1" ) )
124 {
125 testClasses( "U1", fp->GetComponentClass(), { "ANY" } );
126 }
127
128 if( fp->Reference().GetText() == wxT( "U2" ) )
129 {
130 testClasses( "U2", fp->GetComponentClass(), { "ANY" } );
131 }
132
133 if( fp->Reference().GetText() == wxT( "U3" ) )
134 {
135 testClasses( "U3", fp->GetComponentClass(), { "MULTI_REF" } );
136 }
137
138 if( fp->Reference().GetText() == wxT( "U4" ) )
139 {
140 testClasses( "U4", fp->GetComponentClass(), { "MULTI_REF" } );
141 }
142
143 if( fp->Reference().GetText() == wxT( "U55" ) )
144 {
145 testClasses( "U55", fp->GetComponentClass(), { "REF_WILDCARD", "REF_WILDCARD2" } );
146 }
147
148 if( fp->Reference().GetText() == wxT( "U555" ) )
149 {
150 testClasses( "U555", fp->GetComponentClass(), { "REF_WILDCARD2" } );
151 }
152
153 if( fp->Reference().GetText() == wxT( "R3" ) )
154 {
155 testClasses( "R3", fp->GetComponentClass(), { "/SHEET1/", "RES_1", "RES_2" } );
156 }
157 }
158
159}
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)
std::unique_ptr< BOARD > m_board
BOOST_FIXTURE_TEST_CASE(ComponentClasses, PCB_COMPONENT_CLASS_FIXTURE)