KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_rule_area_destruction.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
30
32
33#include <sch_line.h>
34#include <sch_rule_area.h>
35
36
37BOOST_AUTO_TEST_SUITE( SchRuleAreaDestruction )
38
39
40
46BOOST_AUTO_TEST_CASE( RuleAreaDestroyedBeforeContainedItems )
47{
48 auto ruleArea = std::make_unique<SCH_RULE_AREA>();
49 auto line1 = std::make_unique<SCH_LINE>( VECTOR2I( 0, 0 ), LAYER_WIRE );
50 auto line2 = std::make_unique<SCH_LINE>( VECTOR2I( 100, 0 ), LAYER_WIRE );
51
52 // Simulate what RefreshContainedItemsAndDirectives does
53 ruleArea->m_items.insert( line1.get() );
54 line1->AddRuleAreaToCache( ruleArea.get() );
55
56 ruleArea->m_items.insert( line2.get() );
57 line2->AddRuleAreaToCache( ruleArea.get() );
58
59 BOOST_CHECK_EQUAL( line1->GetRuleAreaCache().size(), 1u );
60 BOOST_CHECK_EQUAL( line2->GetRuleAreaCache().size(), 1u );
61
62 // Destroy rule area first (the problematic ordering from FreeDrawList)
63 ruleArea.reset();
64
65 // Contained items should no longer reference the destroyed rule area
66 BOOST_CHECK_EQUAL( line1->GetRuleAreaCache().size(), 0u );
67 BOOST_CHECK_EQUAL( line2->GetRuleAreaCache().size(), 0u );
68
69 // Destroying items should not crash (previously called RemoveItem on freed memory)
70 line1.reset();
71 line2.reset();
72}
73
74
81BOOST_AUTO_TEST_CASE( ContainedItemsDestroyedBeforeRuleArea )
82{
83 auto ruleArea = std::make_unique<SCH_RULE_AREA>();
84 auto line1 = std::make_unique<SCH_LINE>( VECTOR2I( 0, 0 ), LAYER_WIRE );
85 auto line2 = std::make_unique<SCH_LINE>( VECTOR2I( 100, 0 ), LAYER_WIRE );
86
87 ruleArea->m_items.insert( line1.get() );
88 line1->AddRuleAreaToCache( ruleArea.get() );
89
90 ruleArea->m_items.insert( line2.get() );
91 line2->AddRuleAreaToCache( ruleArea.get() );
92
93 BOOST_CHECK_EQUAL( ruleArea->m_items.size(), 2u );
94
95 // Destroy items first (the normal ordering)
96 line1.reset();
97 line2.reset();
98
99 // Rule area should have had items removed by their destructors
100 BOOST_CHECK_EQUAL( ruleArea->m_items.size(), 0u );
101
102 ruleArea.reset();
103}
104
105
@ LAYER_WIRE
Definition layer_ids.h:452
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(RuleAreaDestroyedBeforeContainedItems)
Verify that destroying a rule area before its contained items does not crash.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695