KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_action_manager.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
22#include <vector>
23
24#include <tool/action_manager.h>
25#include <tool/tool_action.h>
26
27BOOST_AUTO_TEST_SUITE( ActionManagerDispatch )
28
29BOOST_AUTO_TEST_CASE( UserBoundDetection_DefaultUntouched )
30{
31 TOOL_ACTION action(
32 TOOL_ACTION_ARGS().Name( "common.test" ).FriendlyName( "Test" ).Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
33
34 BOOST_CHECK( !action.IsHotKeyUserBound( 'A' ) );
35}
36
37BOOST_AUTO_TEST_CASE( UserBoundDetection_CustomValue )
38{
39 TOOL_ACTION action(
40 TOOL_ACTION_ARGS().Name( "common.test" ).FriendlyName( "Test" ).Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
41
42 action.SetHotKey( 'B' );
43
44 BOOST_CHECK( action.IsHotKeyUserBound( 'B' ) );
45 BOOST_CHECK( !action.IsHotKeyUserBound( 'A' ) );
46}
47
48BOOST_AUTO_TEST_CASE( UserBoundDetection_IdentityRebindIsIndistinguishable )
49{
50 // Known heuristic limit: explicitly assigning the default value cannot
51 // be distinguished from never touching the action. Document via test.
52 TOOL_ACTION action(
53 TOOL_ACTION_ARGS().Name( "common.test" ).FriendlyName( "Test" ).Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
54
55 action.SetHotKey( 'A' );
56
57 BOOST_CHECK( !action.IsHotKeyUserBound( 'A' ) );
58}
59
60BOOST_AUTO_TEST_CASE( UserBoundDetection_AltSlotIndependent )
61{
62 TOOL_ACTION action(
63 TOOL_ACTION_ARGS().Name( "common.test" ).FriendlyName( "Test" ).Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
64
65 action.SetHotKey( 'A', 'B' );
66
67 BOOST_CHECK( !action.IsHotKeyUserBound( 'A' ) );
68 BOOST_CHECK( action.IsHotKeyUserBound( 'B' ) );
69}
70
71BOOST_AUTO_TEST_CASE( UserBoundDetection_SharedDefaultCollisionPreserved )
72{
73 // common.* vs frame.* both shipped with the same default key (e.g. 'D'
74 // for common.showDatasheet and pcbnew.Drag45Degree). Neither is
75 // user-bound, so promotion must not fire and original ordering stays.
76 TOOL_ACTION commonAction( TOOL_ACTION_ARGS()
77 .Name( "common.showDatasheet" )
78 .FriendlyName( "Show Datasheet" )
79 .Scope( AS_GLOBAL )
80 .DefaultHotkey( 'D' ) );
81 TOOL_ACTION frameAction( TOOL_ACTION_ARGS()
82 .Name( "pcbnew.dragMove45" )
83 .FriendlyName( "Drag 45" )
84 .Scope( AS_GLOBAL )
85 .DefaultHotkey( 'D' ) );
86
87 BOOST_CHECK( !commonAction.IsHotKeyUserBound( 'D' ) );
88 BOOST_CHECK( !frameAction.IsHotKeyUserBound( 'D' ) );
89}
90
91BOOST_AUTO_TEST_CASE( Promotion_UserBoundFrameActionWins )
92{
93 TOOL_ACTION commonCopy( TOOL_ACTION_ARGS()
94 .Name( "common.Interactive.copy" )
95 .FriendlyName( "Copy" )
96 .Scope( AS_GLOBAL )
97 .DefaultHotkey( 'C' ) );
98 TOOL_ACTION frameCopy( TOOL_ACTION_ARGS()
99 .Name( "pcbnew.InteractiveMove.copyWithReference" )
100 .FriendlyName( "Copy With Reference" )
101 .Scope( AS_GLOBAL )
102 .DefaultHotkey( 'X' ) );
103
104 // User re-binds the frame action onto the key common.Interactive.copy ships with.
105 frameCopy.SetHotKey( 'C' );
106
107 std::vector<const TOOL_ACTION*> global{ &commonCopy, &frameCopy };
108
110
111 BOOST_CHECK_EQUAL( global.front()->GetName(), "pcbnew.InteractiveMove.copyWithReference" );
112}
113
114BOOST_AUTO_TEST_CASE( Promotion_OtherFrameLeavesOrderUnchanged )
115{
116 TOOL_ACTION commonCopy( TOOL_ACTION_ARGS()
117 .Name( "common.Interactive.copy" )
118 .FriendlyName( "Copy" )
119 .Scope( AS_GLOBAL )
120 .DefaultHotkey( 'C' ) );
121 TOOL_ACTION frameCopy( TOOL_ACTION_ARGS()
122 .Name( "pcbnew.InteractiveMove.copyWithReference" )
123 .FriendlyName( "Copy With Reference" )
124 .Scope( AS_GLOBAL )
125 .DefaultHotkey( 'X' ) );
126
127 frameCopy.SetHotKey( 'C' );
128
129 std::vector<const TOOL_ACTION*> global{ &commonCopy, &frameCopy };
130
132
133 BOOST_CHECK_EQUAL( global.front()->GetName(), "common.Interactive.copy" );
134}
135
136BOOST_AUTO_TEST_CASE( Promotion_DefaultBindingLeavesOrderUnchanged )
137{
138 TOOL_ACTION commonCopy( TOOL_ACTION_ARGS()
139 .Name( "common.Interactive.copy" )
140 .FriendlyName( "Copy" )
141 .Scope( AS_GLOBAL )
142 .DefaultHotkey( 'C' ) );
143 TOOL_ACTION frameCopy( TOOL_ACTION_ARGS()
144 .Name( "pcbnew.InteractiveMove.copyWithReference" )
145 .FriendlyName( "Copy With Reference" )
146 .Scope( AS_GLOBAL )
147 .DefaultHotkey( 'C' ) );
148
149 std::vector<const TOOL_ACTION*> global{ &commonCopy, &frameCopy };
150
152
153 BOOST_CHECK_EQUAL( global.front()->GetName(), "common.Interactive.copy" );
154}
155
static void PromoteUserBoundFrameAction(std::vector< const TOOL_ACTION * > &aGlobalActions, FRAME_T aFrameType, int aMatchedHotKey)
Reorder global actions sharing a hotkey so that one native to the given frame is tried first when the...
Build up the properties of a TOOL_ACTION in an incremental manner that is static-construction safe.
Represent a single user action.
bool IsHotKeyUserBound(int aMatchedHotKey) const
Return true if the matched hotkey slot (primary or alternate) holds a value different from its compil...
void SetHotKey(int aKeycode, int aKeycodeAlt=0)
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_SCH
Definition frame_type.h:30
BOOST_AUTO_TEST_CASE(UserBoundDetection_DefaultUntouched)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition tool_action.h:45