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>
22
27
28BOOST_AUTO_TEST_SUITE( ToolDispatcherAutoRepeat )
29
30// A single key press whose key has already been released (a quick tap) must always run.
31BOOST_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.
45BOOST_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.
56BOOST_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.
69BOOST_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.
82BOOST_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
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...
static bool ShouldDropAutoRepeat(int aKeyCode, wxLongLong aNowMs, bool aKeyIsDown, int &aLastKey, wxLongLong &aLastTimeMs)
Pure decision used to discard backlogged OS key auto-repeat events.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(LeadingEdgeAlwaysRuns)
Tests for TOOL_DISPATCHER::ShouldDropAutoRepeat, the pure decision that discards backlogged OS key au...