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
43
44
46{
48
49 // Check for Errors when using global labels
50 std::vector<std::pair<wxString, int>> tests =
51 {
52 { "issue17870", 6 }
53 };
54
55 for( const std::pair<wxString, int>& test : tests )
56 {
57 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
58
59 ERC_SETTINGS& settings = m_schematic->ErcSettings();
60 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
61
63
64 ERC_TESTER tester( m_schematic.get() );
65 tester.TestFourWayJunction();
66
68
69 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
70
71 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
72 "Expected " << test.second << " errors in " << test.first.ToStdString()
73 << " but got " << errors.GetCount() << "\n"
74 << reportWriter.GetTextReport() );
75
76 }
77}
78
79
80BOOST_AUTO_TEST_CASE( ERCFourWayExclusionsSurviveCanonicalWitnesses )
81{
82 LOCALE_IO locale;
83 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
84 SCOPED_SET_RESET restore( enabled, false );
85 SETTINGS_MANAGER settings;
86 std::unique_ptr<SCHEMATIC> schematic;
87 KI_TEST::LoadSchematic( settings, "issue17870", schematic );
88 SCH_SCREEN* screen = schematic->RootScreen();
89 ERC_TESTER tester( schematic.get() );
90 BOOST_REQUIRE_EQUAL( tester.TestFourWayJunction(), 6 );
91 std::vector<SCH_ITEM*> markers;
92
93 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
94 {
95 auto* marker = static_cast<SCH_MARKER*>( item );
96
97 if( marker->GetRCItem()->GetErrorCode() != ERCE_FOUR_WAY_JUNCTION )
98 continue;
99
100 marker->SetExcluded( true, "Retained junction" );
101 markers.push_back( item );
102 }
103
104 BOOST_REQUIRE_EQUAL( markers.size(), 6 );
105 schematic->RecordERCExclusions();
106
107 for( SCH_ITEM* item : markers )
108 screen->DeleteItem( item );
109
110 enabled = true;
111 schematic->RebuildConnectivity();
112 BOOST_REQUIRE_EQUAL( tester.TestFourWayJunction(), 6 );
113 schematic->ResolveERCExclusionsPostUpdate();
114 size_t count = 0;
115
116 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
117 {
118 const auto* marker = static_cast<SCH_MARKER*>( item );
119
120 if( marker->GetRCItem()->GetErrorCode() != ERCE_FOUR_WAY_JUNCTION )
121 continue;
122
123 BOOST_CHECK( marker->IsExcluded() );
124 BOOST_CHECK_EQUAL( marker->GetComment(), wxString( "Retained junction" ) );
125 ++count;
126 }
127
128 BOOST_CHECK_EQUAL( count, 6 );
129}
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:1195
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
std::unique_ptr< SCHEMATIC > m_schematic
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