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, see <https://www.gnu.org/licenses/>.
18 */
19
29
31
32#include <sch_line.h>
33#include <sch_rule_area.h>
34
35
36BOOST_AUTO_TEST_SUITE( SchRuleAreaDestruction )
37
38
39
45BOOST_AUTO_TEST_CASE( RuleAreaDestroyedBeforeContainedItems )
46{
47 auto ruleArea = std::make_unique<SCH_RULE_AREA>();
48 auto line1 = std::make_unique<SCH_LINE>( VECTOR2I( 0, 0 ), LAYER_WIRE );
49 auto line2 = std::make_unique<SCH_LINE>( VECTOR2I( 100, 0 ), LAYER_WIRE );
50
51 // Simulate what RefreshContainedItemsAndDirectives does
52 ruleArea->m_items.insert( line1.get() );
53 line1->AddRuleAreaToCache( ruleArea.get() );
54
55 ruleArea->m_items.insert( line2.get() );
56 line2->AddRuleAreaToCache( ruleArea.get() );
57
58 BOOST_CHECK_EQUAL( line1->GetRuleAreaCache().size(), 1u );
59 BOOST_CHECK_EQUAL( line2->GetRuleAreaCache().size(), 1u );
60
61 // Destroy rule area first (the problematic ordering from FreeDrawList)
62 ruleArea.reset();
63
64 // Contained items should no longer reference the destroyed rule area
65 BOOST_CHECK_EQUAL( line1->GetRuleAreaCache().size(), 0u );
66 BOOST_CHECK_EQUAL( line2->GetRuleAreaCache().size(), 0u );
67
68 // Destroying items should not crash (previously called RemoveItem on freed memory)
69 line1.reset();
70 line2.reset();
71}
72
73
80BOOST_AUTO_TEST_CASE( ContainedItemsDestroyedBeforeRuleArea )
81{
82 auto ruleArea = std::make_unique<SCH_RULE_AREA>();
83 auto line1 = std::make_unique<SCH_LINE>( VECTOR2I( 0, 0 ), LAYER_WIRE );
84 auto line2 = std::make_unique<SCH_LINE>( VECTOR2I( 100, 0 ), LAYER_WIRE );
85
86 ruleArea->m_items.insert( line1.get() );
87 line1->AddRuleAreaToCache( ruleArea.get() );
88
89 ruleArea->m_items.insert( line2.get() );
90 line2->AddRuleAreaToCache( ruleArea.get() );
91
92 BOOST_CHECK_EQUAL( ruleArea->m_items.size(), 2u );
93
94 // Destroy items first (the normal ordering)
95 line1.reset();
96 line2.reset();
97
98 // Rule area should have had items removed by their destructors
99 BOOST_CHECK_EQUAL( ruleArea->m_items.size(), 0u );
100
101 ruleArea.reset();
102}
103
104
@ LAYER_WIRE
Definition layer_ids.h:450
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:683