KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_four_way.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 <erc/erc_settings.h>
26#include <erc/erc.h>
27#include <erc/erc_report.h>
29#include <locale_io.h>
30#include <advanced_config.h>
31#include <sch_screen.h>
32#include <sch_marker.h>
33#include <scoped_set_reset.h>
34
35namespace
36{
37struct ERC_REGRESSION_TEST_FIXTURE
38{
39 ERC_REGRESSION_TEST_FIXTURE()
40 { }
41
42 SETTINGS_MANAGER m_settingsManager;
43 std::unique_ptr<SCHEMATIC> m_schematic;
44};
45} // namespace
46
47
48BOOST_FIXTURE_TEST_CASE( ERCFourWayJunctions, ERC_REGRESSION_TEST_FIXTURE )
49{
51
52 // Check for Errors when using global labels
53 std::vector<std::pair<wxString, int>> tests =
54 {
55 { "issue17870", 6 }
56 };
57
58 for( const std::pair<wxString, int>& test : tests )
59 {
60 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
61
62 ERC_SETTINGS& settings = m_schematic->ErcSettings();
63 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
64
66
67 ERC_TESTER tester( m_schematic.get() );
68 tester.TestFourWayJunction();
69
71
72 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
73
74 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
75 "Expected " << test.second << " errors in " << test.first.ToStdString()
76 << " but got " << errors.GetCount() << "\n"
77 << reportWriter.GetTextReport() );
78
79 }
80}
81
82
83BOOST_AUTO_TEST_CASE( ERCFourWayExclusionsSurviveCanonicalWitnesses )
84{
85 LOCALE_IO locale;
86 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
87 SCOPED_SET_RESET restore( enabled, false );
88 SETTINGS_MANAGER settings;
89 std::unique_ptr<SCHEMATIC> schematic;
90 KI_TEST::LoadSchematic( settings, "issue17870", schematic );
91 SCH_SCREEN* screen = schematic->RootScreen();
92 ERC_TESTER tester( schematic.get() );
93 BOOST_REQUIRE_EQUAL( tester.TestFourWayJunction(), 6 );
94 std::vector<SCH_ITEM*> markers;
95
96 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
97 {
98 auto* marker = static_cast<SCH_MARKER*>( item );
99
100 if( marker->GetRCItem()->GetErrorCode() != ERCE_FOUR_WAY_JUNCTION )
101 continue;
102
103 marker->SetExcluded( true, "Retained junction" );
104 markers.push_back( item );
105 }
106
107 BOOST_REQUIRE_EQUAL( markers.size(), 6 );
108 schematic->RecordERCExclusions();
109
110 for( SCH_ITEM* item : markers )
111 screen->DeleteItem( item );
112
113 enabled = true;
114 schematic->RebuildConnectivity();
115 BOOST_REQUIRE_EQUAL( tester.TestFourWayJunction(), 6 );
116 schematic->ResolveERCExclusionsPostUpdate();
117 size_t count = 0;
118
119 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
120 {
121 const auto* marker = static_cast<SCH_MARKER*>( item );
122
123 if( marker->GetRCItem()->GetErrorCode() != ERCE_FOUR_WAY_JUNCTION )
124 continue;
125
126 BOOST_CHECK( marker->IsExcluded() );
127 BOOST_CHECK_EQUAL( marker->GetComment(), wxString( "Retained junction" ) );
128 ++count;
129 }
130
131 BOOST_CHECK_EQUAL( count, 6 );
132}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
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
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition erc.cpp:1250
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
Definition marker_base.h:91
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
void DeleteItem(SCH_ITEM *aItem)
Remove aItem from the linked list and deletes the object.
RAII class that sets an value at construction and resets it to the original value at destruction.
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
@ ERCE_FOUR_WAY_JUNCTION
A four-way junction was found.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(ERCFourWayJunctions, ERC_REGRESSION_TEST_FIXTURE)
BOOST_AUTO_TEST_CASE(ERCFourWayExclusionsSurviveCanonicalWitnesses)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_MARKER_T
Definition typeinfo.h:154