KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_rule_area.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
25
28
29#include <connection_graph.h>
30#include <schematic.h>
31#include <sch_rule_area.h>
32#include <sch_symbol.h>
33#include <erc/erc_settings.h>
34#include <erc/erc.h>
36#include <locale_io.h>
37
38
48
49
59{
61
62 KI_TEST::LoadSchematic( m_settingsManager, "issue22854/test", m_schematic );
63
64 ERC_TESTER tester( m_schematic.get() );
65
66 // First ERC run populates the rule area caches
67 tester.RunTests( nullptr, nullptr, nullptr, &m_schematic->Project(), nullptr );
68
69 // Find a symbol to delete and recreate (simulating a move operation)
70 SCH_SCREEN* rootScreen = m_schematic->RootScreen();
71 SCH_SYMBOL* symbolToModify = nullptr;
72
73 for( SCH_ITEM* item : rootScreen->Items().OfType( SCH_SYMBOL_T ) )
74 {
75 symbolToModify = static_cast<SCH_SYMBOL*>( item );
76 break;
77 }
78
79 BOOST_REQUIRE( symbolToModify != nullptr );
80
81 // Clone the symbol, delete the original, then add the clone
82 // This simulates what happens during a move operation
83 SCH_SYMBOL* clonedSymbol = static_cast<SCH_SYMBOL*>( symbolToModify->Clone() );
84
85 rootScreen->Remove( symbolToModify );
86 delete symbolToModify;
87 symbolToModify = nullptr;
88
89 rootScreen->Append( clonedSymbol );
90
91 // ERC_TESTER::RunTests only forces a connection graph rebuild when given an edit
92 // frame (production goes through SCH_EDIT_FRAME::RecalculateConnections). The
93 // headless test path doesn't, so the connection graph still holds raw pointers
94 // to the deleted symbol's pins. Force the rebuild here to match what production
95 // does after a delete/append cycle.
96 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
97 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
98
99 // Second ERC run should not crash. Before the fix, the rule area still held
100 // a pointer to the deleted symbol and would crash when clearing caches.
101 BOOST_CHECK_NO_THROW( tester.RunTests( nullptr, nullptr, nullptr, &m_schematic->Project(), nullptr ) );
102}
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:2276
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:162
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:69
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(ERCRuleAreaItemDeletion, ERC_RULE_AREA_TEST_FIXTURE)
Regression test for issue 22854.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
@ SCH_SYMBOL_T
Definition typeinfo.h:169