KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_tool_dispatcher.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
#include <
tool/tool_dispatcher.h
>
22
27
28
BOOST_AUTO_TEST_SUITE
( ToolDispatcherAutoRepeat )
29
30
// A single key press whose key has already been released (a quick tap) must always run.
31
BOOST_AUTO_TEST_CASE
( LeadingEdgeAlwaysRuns )
32
{
33
int
lastKey = 0;
34
wxLongLong lastTime = 0;
35
36
bool
drop =
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
,
/*now*/
1000,
/*keyIsDown*/
false
,
37
lastKey, lastTime );
38
39
BOOST_CHECK( !drop );
40
BOOST_CHECK_EQUAL
( lastKey,
'R'
);
41
BOOST_CHECK( lastTime == 1000 );
42
}
43
44
// Repeats that arrive within the burst window while the key is still held keep running.
45
BOOST_AUTO_TEST_CASE
( HeldKeyRepeatsRun )
46
{
47
int
lastKey = 0;
48
wxLongLong lastTime = 0;
49
50
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1000,
true
, lastKey, lastTime ) );
51
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1030,
true
, lastKey, lastTime ) );
52
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1060,
true
, lastKey, lastTime ) );
53
}
54
55
// The defect: repeats from the same burst that arrive after release must be dropped.
56
BOOST_AUTO_TEST_CASE
( StaleRepeatAfterReleaseDropped )
57
{
58
int
lastKey = 0;
59
wxLongLong lastTime = 0;
60
61
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1000,
true
, lastKey, lastTime ) );
62
63
// Backlogged events still in the queue after the key came up.
64
BOOST_CHECK(
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1030,
false
, lastKey, lastTime ) );
65
BOOST_CHECK(
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1060,
false
, lastKey, lastTime ) );
66
}
67
68
// A second deliberate tap after a human-scale gap is a new burst and must run again.
69
BOOST_AUTO_TEST_CASE
( SecondDeliberateTapRuns )
70
{
71
int
lastKey = 0;
72
wxLongLong lastTime = 0;
73
74
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1000,
false
, lastKey, lastTime ) );
75
76
// Well beyond the auto-repeat window, so this is treated as a fresh press, not stale backlog.
77
wxLongLong later = 1000 +
TOOL_DISPATCHER::AutoRepeatWindowMs
+ 1;
78
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, later,
false
, lastKey, lastTime ) );
79
}
80
81
// Switching to a different key starts a new burst whose leading edge runs.
82
BOOST_AUTO_TEST_CASE
( DifferentKeyIsNewBurst )
83
{
84
int
lastKey = 0;
85
wxLongLong lastTime = 0;
86
87
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'R'
, 1000,
true
, lastKey, lastTime ) );
88
89
// A different hotkey arriving immediately is not part of the R burst.
90
BOOST_CHECK( !
TOOL_DISPATCHER::ShouldDropAutoRepeat
(
'F'
, 1010,
false
, lastKey, lastTime ) );
91
}
92
93
BOOST_AUTO_TEST_SUITE_END
()
TOOL_DISPATCHER::AutoRepeatWindowMs
static const int AutoRepeatWindowMs
The maximum gap (ms) between two events of the same key for them to count as one OS auto-repeat burst...
Definition
tool_dispatcher.h:79
TOOL_DISPATCHER::ShouldDropAutoRepeat
static bool ShouldDropAutoRepeat(int aKeyCode, wxLongLong aNowMs, bool aKeyIsDown, int &aLastKey, wxLongLong &aLastTimeMs)
Pure decision used to discard backlogged OS key auto-repeat events.
Definition
tool_dispatcher.cpp:500
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(LeadingEdgeAlwaysRuns)
Tests for TOOL_DISPATCHER::ShouldDropAutoRepeat, the pure decision that discards backlogged OS key au...
Definition
test_tool_dispatcher.cpp:31
tool_dispatcher.h
src
qa
tests
common
test_tool_dispatcher.cpp
Generated on Fri Jun 26 2026 00:05:43 for KiCad PCB EDA Suite by
1.13.2