KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24961_group_promotion.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <sch_symbol.h>
23#include <sch_group.h>
24#include <sch_collectors.h>
26#include <tool/tool_manager.h>
27#include <view/view.h>
28
29// Issue 24961: requesting a symbols-only selection over a grouped symbol
30// returned the group instead, and callers crashed casting it to SCH_SYMBOL
31
33{
36 {
37 m_mgr.SetEnvironment( nullptr, &m_view, nullptr, nullptr, nullptr );
38 m_mgr.RegisterTool( m_tool );
39
40 m_group.AddItem( &m_symbol );
41 }
42
44
45 SCH_COLLECTOR makeCollector( const std::vector<KICAD_T>& aScanTypes )
46 {
47 SCH_COLLECTOR collector;
48 collector.SetScanTypes( aScanTypes );
49 collector.Append( &m_symbol );
50 return collector;
51 }
52
58};
59
60BOOST_FIXTURE_TEST_SUITE( Issue24961GroupPromotion, GROUP_PROMOTION_FIXTURE )
61
62BOOST_AUTO_TEST_CASE( SymbolOnlyScanTypesDoNotPromote )
63{
64 SCH_COLLECTOR collector = makeCollector( { SCH_SYMBOL_T } );
65
66 m_tool->FilterCollectorForHierarchy( collector, false );
67
68 BOOST_REQUIRE_EQUAL( collector.GetCount(), 1 );
69 BOOST_CHECK( collector[0] == &m_symbol );
70}
71
72BOOST_AUTO_TEST_CASE( LocateAnyPromotesToGroup )
73{
74 SCH_COLLECTOR collector = makeCollector( { SCH_LOCATE_ANY_T } );
75
76 m_tool->FilterCollectorForHierarchy( collector, false );
77
78 BOOST_REQUIRE_EQUAL( collector.GetCount(), 1 );
79 BOOST_CHECK( collector[0] == &m_group );
80}
81
82BOOST_AUTO_TEST_CASE( EmptyScanTypesPromoteToGroup )
83{
84 // SelectAll and box selection build collectors by hand with no scan types
85 SCH_COLLECTOR collector = makeCollector( {} );
86
87 m_tool->FilterCollectorForHierarchy( collector, false );
88
89 BOOST_REQUIRE_EQUAL( collector.GetCount(), 1 );
90 BOOST_CHECK( collector[0] == &m_group );
91}
92
93BOOST_AUTO_TEST_CASE( GroupScanTypesPromoteToGroup )
94{
95 SCH_COLLECTOR collector = makeCollector( SCH_COLLECTOR::MovableItems );
96
97 m_tool->FilterCollectorForHierarchy( collector, false );
98
99 BOOST_REQUIRE_EQUAL( collector.GetCount(), 1 );
100 BOOST_CHECK( collector[0] == &m_group );
101}
102
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
void SetScanTypes(const std::vector< KICAD_T > &aTypes)
Record the list of KICAD_T types to consider for collection by the Inspect() function.
Definition collector.h:209
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition collector.h:97
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
static const std::vector< KICAD_T > MovableItems
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Schematic symbol object.
Definition sch_symbol.h:69
Master controller class:
Class to handle a set of SCH_ITEMs.
SCH_COLLECTOR makeCollector(const std::vector< KICAD_T > &aScanTypes)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SymbolOnlyScanTypesDoNotPromote)
@ SCH_SYMBOL_T
Definition typeinfo.h:169
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:196