KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_label_names.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, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
23
24#include <connection_graph.h>
25#include <schematic.h>
26#include <erc/erc_settings.h>
27#include <erc/erc.h>
28#include <erc/erc_report.h>
30#include <locale_io.h>
31
33{
35
37 std::unique_ptr<SCHEMATIC> m_schematic;
38};
39
40
41static int CountErrorCode( SHEETLIST_ERC_ITEMS_PROVIDER& aErrors, int aErrorCode )
42{
43 int count = 0;
44
45 for( int i = 0; i < aErrors.GetCount(); ++i )
46 {
47 std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( aErrors.GetItem( i ) );
48
49 if( ercItem && ercItem->GetErrorCode() == aErrorCode )
50 ++count;
51 }
52
53 return count;
54}
55
56
58{
60
61 // Check for Errors when using rule area netclass directives
62 std::vector<std::pair<wxString, int>> tests = { { "issue16897", 3 } };
63
64 for( const std::pair<wxString, int>& test : tests )
65 {
66 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
67
68 ERC_SETTINGS& settings = m_schematic->ErcSettings();
69 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
70
71 // Skip the "Modified symbol" warning
74
75 // Configure the rules under test
79
80 m_schematic->ConnectionGraph()->RunERC();
81
82 ERC_TESTER tester( m_schematic.get() );
83 tester.TestSimilarLabels();
84
86
87 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
88
89 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
90 "Expected " << test.second << " errors in " << test.first.ToStdString()
91 << " but got " << errors.GetCount() << "\n"
92 << reportWriter.GetTextReport() );
93 }
94}
95
96
98{
100
101 // Check for Errors when using rule area netclass directives
102 std::vector<std::pair<wxString, int>> tests = { { "same_local_global_label", 1 } };
103
104 for( const std::pair<wxString, int>& test : tests )
105 {
106 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
107
108 ERC_SETTINGS& settings = m_schematic->ErcSettings();
109 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
110
111 // Skip the "Modified symbol" warning
114
115 // Configure the rules under test
117
118 m_schematic->ConnectionGraph()->RunERC();
119
120 ERC_TESTER tester( m_schematic.get() );
122
124
125 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
126
127 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
128 "Expected " << test.second << " errors in " << test.first.ToStdString()
129 << " but got " << errors.GetCount() << "\n"
130 << reportWriter.GetTextReport() );
131 }
132}
133
134
136{
138
139 KI_TEST::LoadSchematic( m_settingsManager, "same_local_global_power", m_schematic );
140
141 ERC_SETTINGS& settings = m_schematic->ErcSettings();
142 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
143
146
149
150 m_schematic->ConnectionGraph()->RunERC();
151
152 ERC_TESTER tester( m_schematic.get() );
154
156
157 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
158
160 "Expected 2 ERCE_SAME_LOCAL_GLOBAL_POWER violations\n"
161 << reportWriter.GetTextReport() );
162
164 "Expected 0 ERCE_SAME_LOCAL_GLOBAL_LABEL violations\n"
165 << reportWriter.GetTextReport() );
166}
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format in the C-locale.
Container for ERC settings.
std::map< int, SEVERITY > m_ERCSeverities
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1561
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:1477
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
@ ERCE_SIMILAR_POWER
2 power pins are equal for case insensitive comparisons.
@ ERCE_SIMILAR_LABELS
2 labels are equal for case insensitive comparisons.
@ ERCE_SAME_LOCAL_GLOBAL_LABEL
2 labels are equal for case insensitive comparisons.
@ ERCE_SIMILAR_LABEL_AND_POWER
label and pin are equal for case insensitive comparisons.
@ ERCE_SAME_LOCAL_GLOBAL_POWER
Local power port and global power port have the same name.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
static int CountErrorCode(SHEETLIST_ERC_ITEMS_PROVIDER &aErrors, int aErrorCode)
BOOST_FIXTURE_TEST_CASE(ERCLabelCapitalization, ERC_REGRESSION_TEST_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")