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, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
26
29
30#include <connection_graph.h>
31#include <schematic.h>
32#include <sch_rule_area.h>
33#include <sch_symbol.h>
34#include <erc/erc_settings.h>
35#include <erc/erc.h>
37#include <locale_io.h>
38
39
49
50
60{
62
63 KI_TEST::LoadSchematic( m_settingsManager, "issue22854/test", m_schematic );
64
65 ERC_TESTER tester( m_schematic.get() );
66
67 // First ERC run populates the rule area caches
68 tester.RunTests( nullptr, nullptr, nullptr, &m_schematic->Project(), nullptr );
69
70 // Find a symbol to delete and recreate (simulating a move operation)
71 SCH_SCREEN* rootScreen = m_schematic->RootScreen();
72 SCH_SYMBOL* symbolToModify = nullptr;
73
74 for( SCH_ITEM* item : rootScreen->Items().OfType( SCH_SYMBOL_T ) )
75 {
76 symbolToModify = static_cast<SCH_SYMBOL*>( item );
77 break;
78 }
79
80 BOOST_REQUIRE( symbolToModify != nullptr );
81
82 // Clone the symbol, delete the original, then add the clone
83 // This simulates what happens during a move operation
84 SCH_SYMBOL* clonedSymbol = static_cast<SCH_SYMBOL*>( symbolToModify->Clone() );
85
86 rootScreen->Remove( symbolToModify );
87 delete symbolToModify;
88 symbolToModify = nullptr;
89
90 rootScreen->Append( clonedSymbol );
91
92 // Second ERC run should not crash. Before the fix, the rule area still held
93 // a pointer to the deleted symbol and would crash when clearing caches.
94 BOOST_CHECK_NO_THROW( tester.RunTests( nullptr, nullptr, nullptr, &m_schematic->Project(), nullptr ) );
95}
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:1985
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Schematic symbol object.
Definition sch_symbol.h:76
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:176