KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_marker_counts.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
21#include <advanced_config.h>
24
25#include <connection_graph.h>
26#include <schematic.h>
27#include <sch_marker.h>
28#include <erc/erc_settings.h>
29#include <erc/erc.h>
31#include <locale_io.h>
32
33
39
40
47{
49
50 KI_TEST::LoadSchematic( m_settingsManager, "issue10430", m_schematic );
51
52 ERC_SETTINGS& settings = m_schematic->ErcSettings();
53
56
57 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
58 {
59 m_schematic->RebuildConnectivity();
60 m_schematic->Connectivity().PrepareTextChecks( *m_schematic );
61 }
62
63 m_schematic->ConnectionGraph()->RunERC();
64
65 ERC_TESTER tester( m_schematic.get() );
68 tester.TestNoConnectPins();
69 tester.TestPinToPin();
70 tester.TestSimilarLabels();
71 tester.TestTextVars( nullptr );
72
74
75 SHEETLIST_ERC_ITEMS_PROVIDER provider( m_schematic.get() );
76 provider.SetSeverities( allSeverities );
77
78 BOOST_REQUIRE( provider.GetCount() > 0 );
79
80 const int errorsBefore = provider.GetCount( RPT_SEVERITY_ERROR );
81 const int warningsBefore = provider.GetCount( RPT_SEVERITY_WARNING );
82 const int exclusionsBefore = provider.GetCount( RPT_SEVERITY_EXCLUSION );
83
84 // Pick a displayed, non-excluded marker to exclude.
85 SCH_MARKER* marker = nullptr;
86 SEVERITY markerSeverity = RPT_SEVERITY_UNDEFINED;
87
88 for( int i = 0; i < provider.GetCount(); ++i )
89 {
90 SCH_MARKER* candidate = static_cast<SCH_MARKER*>( provider.GetItem( i )->GetParent() );
91
92 if( !candidate->IsExcluded() )
93 {
94 marker = candidate;
95 markerSeverity = settings.GetSeverity( candidate->GetRCItem()->GetErrorCode() );
96 break;
97 }
98 }
99
100 BOOST_REQUIRE( marker != nullptr );
101 BOOST_REQUIRE( markerSeverity == RPT_SEVERITY_ERROR || markerSeverity == RPT_SEVERITY_WARNING );
102
103 provider.SetMarkerExcluded( marker, true );
104
105 // The exclusion bucket gains one; the marker's original bucket loses one. Total is unchanged.
106 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_EXCLUSION ), exclusionsBefore + 1 );
107
108 if( markerSeverity == RPT_SEVERITY_ERROR )
109 {
110 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore - 1 );
111 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore );
112 }
113 else
114 {
115 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore - 1 );
116 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore );
117 }
118
119 // The incrementally maintained counts must match a fresh authoritative recompute.
120 SHEETLIST_ERC_ITEMS_PROVIDER fresh( m_schematic.get() );
121 fresh.SetSeverities( allSeverities );
122
128
129 // Restoring the marker must move it back and keep counts consistent with a recompute.
130 provider.SetMarkerExcluded( marker, false );
131
132 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore );
133 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore );
134 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_EXCLUSION ), exclusionsBefore );
135}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Container for ERC settings.
SEVERITY GetSeverity(int aErrorCode) const
std::map< int, SEVERITY > m_ERCSeverities
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:648
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1709
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2696
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:2145
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1288
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:923
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
bool IsExcluded() const
Definition marker_base.h:90
std::shared_ptr< RC_ITEM > GetRCItem() const
int GetErrorCode() const
Definition rc_item.h:158
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
void SetMarkerExcluded(SCH_MARKER *aMarker, bool aExcluded, const wxString &aComment=wxEmptyString)
Set the exclusion state of a marker while keeping the cached severity counts in sync.
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
@ 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)
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(ERCMarkerCountsExclusion, ERC_MARKER_COUNT_FIXTURE)
SHEETLIST_ERC_ITEMS_PROVIDER caches per-severity counts.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_EQUAL(result, "25.4")