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
22
23#include <connection_graph.h>
24#include <schematic.h>
25#include <sch_marker.h>
26#include <erc/erc_settings.h>
27#include <erc/erc.h>
29#include <locale_io.h>
30
31
37
38
45{
47
48 KI_TEST::LoadSchematic( m_settingsManager, "issue10430", m_schematic );
49
50 ERC_SETTINGS& settings = m_schematic->ErcSettings();
51
54
55 m_schematic->ConnectionGraph()->RunERC();
56
57 ERC_TESTER tester( m_schematic.get() );
60 tester.TestNoConnectPins();
61 tester.TestPinToPin();
62 tester.TestSimilarLabels();
63 tester.TestTextVars( nullptr );
64
66
67 SHEETLIST_ERC_ITEMS_PROVIDER provider( m_schematic.get() );
68 provider.SetSeverities( allSeverities );
69
70 BOOST_REQUIRE( provider.GetCount() > 0 );
71
72 const int errorsBefore = provider.GetCount( RPT_SEVERITY_ERROR );
73 const int warningsBefore = provider.GetCount( RPT_SEVERITY_WARNING );
74 const int exclusionsBefore = provider.GetCount( RPT_SEVERITY_EXCLUSION );
75
76 // Pick a displayed, non-excluded marker to exclude.
77 SCH_MARKER* marker = nullptr;
78 SEVERITY markerSeverity = RPT_SEVERITY_UNDEFINED;
79
80 for( int i = 0; i < provider.GetCount(); ++i )
81 {
82 SCH_MARKER* candidate = static_cast<SCH_MARKER*>( provider.GetItem( i )->GetParent() );
83
84 if( !candidate->IsExcluded() )
85 {
86 marker = candidate;
87 markerSeverity = settings.GetSeverity( candidate->GetRCItem()->GetErrorCode() );
88 break;
89 }
90 }
91
92 BOOST_REQUIRE( marker != nullptr );
93 BOOST_REQUIRE( markerSeverity == RPT_SEVERITY_ERROR || markerSeverity == RPT_SEVERITY_WARNING );
94
95 provider.SetMarkerExcluded( marker, true );
96
97 // The exclusion bucket gains one; the marker's original bucket loses one. Total is unchanged.
98 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_EXCLUSION ), exclusionsBefore + 1 );
99
100 if( markerSeverity == RPT_SEVERITY_ERROR )
101 {
102 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore - 1 );
103 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore );
104 }
105 else
106 {
107 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore - 1 );
108 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore );
109 }
110
111 // The incrementally maintained counts must match a fresh authoritative recompute.
112 SHEETLIST_ERC_ITEMS_PROVIDER fresh( m_schematic.get() );
113 fresh.SetSeverities( allSeverities );
114
120
121 // Restoring the marker must move it back and keep counts consistent with a recompute.
122 provider.SetMarkerExcluded( marker, false );
123
124 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_ERROR ), errorsBefore );
125 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_WARNING ), warningsBefore );
126 BOOST_CHECK_EQUAL( provider.GetCount( RPT_SEVERITY_EXCLUSION ), exclusionsBefore );
127}
Container for ERC settings.
SEVERITY GetSeverity(int aErrorCode) const
std::map< int, SEVERITY > m_ERCSeverities
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:387
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1184
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1951
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1630
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1093
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:711
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:89
std::shared_ptr< RC_ITEM > GetRCItem() const
int GetErrorCode() const
Definition rc_item.h:157
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")