KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_connectivity_refresh.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 <advanced_config.h>
24#include <erc/erc.h>
25#include <erc/erc_settings.h>
26#include <locale_io.h>
27#include <sch_label.h>
28#include <sch_marker.h>
29#include <schematic.h>
31#include <scoped_set_reset.h>
32
33
34BOOST_AUTO_TEST_CASE( ERCHeadlessRunRefreshesJobTextOverrides )
35{
36 LOCALE_IO locale;
37 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
38 SCOPED_SET_RESET restore( enabled, enabled );
39
40 for( bool useEngine : { false, true } )
41 {
42 BOOST_TEST_CONTEXT( "engine=" << useEngine )
43 {
44 enabled = useEngine;
45 SETTINGS_MANAGER settings;
46 std::unique_ptr<SCHEMATIC> schematic;
47 KI_TEST::LoadSchematic( settings, "issue24201/issue24201", schematic );
48 SCH_LABEL_BASE* label = nullptr;
49
50 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
51 {
52 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
53 label = static_cast<SCH_LABEL_BASE*>( item );
54 }
55
56 BOOST_REQUIRE( label );
57 const wxString original = label->GetText();
58 label->SetText( "${ERC_JOB_PORT}" );
59 schematic->Project().ApplyTextVars( { { "ERC_JOB_PORT", original } } );
60
61 for( auto& [code, severity] : schematic->ErcSettings().m_ERCSeverities )
63
64 schematic->RebuildConnectivity();
65 const auto countMarkers = [&]()
66 {
67 size_t count = 0;
68
69 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
70 {
71 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_MARKER_T ) )
72 {
73 auto* marker = static_cast<SCH_MARKER*>( item );
74 BOOST_CHECK_EQUAL( marker->GetRCItem()->GetErrorCode(), ERCE_HIERACHICAL_LABEL );
75 ++count;
76 }
77 }
78
79 return count;
80 };
81 ERC_TESTER tester( schematic.get() );
82 tester.RunTests( nullptr, nullptr, nullptr, &schematic->Project(), nullptr );
83 BOOST_REQUIRE_EQUAL( countMarkers(), 0 );
84 schematic->Project().ApplyTextVars( { { "ERC_JOB_PORT", "ERC_CHANGED_PORT" } } );
85 tester.RunTests( nullptr, nullptr, nullptr, &schematic->Project(), nullptr );
86 BOOST_CHECK_EQUAL( countMarkers(), 2 );
87 tester.RunTests( nullptr, nullptr, nullptr, &schematic->Project(), nullptr );
88 BOOST_CHECK_EQUAL( countMarkers(), 2 );
89
90 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
91 {
92 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_MARKER_T ) )
93 static_cast<SCH_MARKER*>( item )->SetExcluded( true, "Retained job exclusion" );
94 }
95
96 tester.RunTests( nullptr, nullptr, nullptr, &schematic->Project(), nullptr );
97 BOOST_CHECK_EQUAL( countMarkers(), 2 );
98
99 for( const SCH_SHEET_PATH& path : schematic->Hierarchy() )
100 {
101 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_MARKER_T ) )
102 {
103 auto* marker = static_cast<SCH_MARKER*>( item );
104 BOOST_CHECK( marker->IsExcluded() );
105 BOOST_CHECK_EQUAL( marker->GetComment(), wxString( "Retained job exclusion" ) );
106 marker->SetExcluded( false );
107 }
108 }
109
110 schematic->Project().ApplyTextVars( { { "ERC_JOB_PORT", original } } );
111 tester.RunTests( nullptr, nullptr, nullptr, &schematic->Project(), nullptr );
112 BOOST_CHECK_EQUAL( countMarkers(), 0 );
113 }
114 }
115}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:231
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:3265
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
RAII class that sets an value at construction and resets it to the original value at destruction.
@ ERCE_HIERACHICAL_LABEL
Mismatch between hierarchical labels and pins sheets.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_AUTO_TEST_CASE(ERCHeadlessRunRefreshesJobTextOverrides)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_MARKER_T
Definition typeinfo.h:154
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165