Repository navigation
Expand file tree
/
Copy pathinput_bindings_ut.cpp
More file actions
110 lines (90 loc) · 3.89 KB
/
Copy pathinput_bindings_ut.cpp
File metadata and controls
110 lines (90 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (C) 2026 Shitty team
* MIT licensed
* See the file LICENSE.MIT for the full license.
*/
#include "input_bindings.h"
#include "composer.h"
#include "listener.h"
#include <std/mem/obj_pool.h>
#include <std/tst/ut.h>
using namespace stl;
namespace {
struct CountBinding final: public Listener {
void onListen(void*) override;
size_t calls = 0;
};
}
void CountBinding::onListen(void*) {
++calls;
}
STD_TEST_SUITE(InputBindings) {
STD_TEST(MatchesNormalizedModifiersAndPublishes) {
auto pool = ObjPool::fromMemory();
Composer composer(pool.mutPtr());
IntrusiveList listeners;
CountBinding listener;
listeners.pushBack(&listener);
composer.inputBindings->add({InputKey::Printable, InputControl, 'a', 'a'}, &listeners);
const bool consumed = composer.input->key({
.key = InputKey::Printable,
.action = InputAction::Press,
.modifiers = InputControl | InputCapsLock | InputNumLock,
.baseCodepoint = 'a',
});
STD_INSIST(consumed);
STD_INSIST(listener.calls == 1);
STD_INSIST(composer.input->text({'a', InputControl}));
STD_INSIST(composer.input->key({InputKey::Printable, InputAction::Release, InputControl, 0, 'a'}));
}
STD_TEST(DoesNotConsumeMismatchedBinding) {
auto pool = ObjPool::fromMemory();
Composer composer(pool.mutPtr());
IntrusiveList listeners;
CountBinding listener;
listeners.pushBack(&listener);
composer.inputBindings->add({InputKey::Printable, InputControl, 'a', 0}, &listeners);
STD_INSIST(!composer.input->key({InputKey::Printable, InputAction::Press, InputShift, 0, 'a'}));
STD_INSIST(!composer.input->key({InputKey::Printable, InputAction::Press, InputControl, 0, 'b'}));
STD_INSIST(listener.calls == 0);
}
STD_TEST(TracksRepeatedPendingText) {
auto pool = ObjPool::fromMemory();
Composer composer(pool.mutPtr());
IntrusiveList listeners;
CountBinding listener;
listeners.pushBack(&listener);
composer.inputBindings->add({InputKey::Printable, InputControl, '=', '+'}, &listeners);
const KeyInput input{InputKey::Printable, InputAction::Press, InputControl, '=', '='};
STD_INSIST(composer.input->key(input));
STD_INSIST(composer.input->key(input));
STD_INSIST(listener.calls == 2);
STD_INSIST(composer.input->text({'+', InputControl}));
STD_INSIST(composer.input->text({'+', InputControl}));
STD_INSIST(!composer.input->text({'+', InputControl}));
}
STD_TEST(FlushDropsPendingTextButReleaseRemainsConsumed) {
auto pool = ObjPool::fromMemory();
Composer composer(pool.mutPtr());
IntrusiveList listeners;
CountBinding listener;
listeners.pushBack(&listener);
composer.inputBindings->add({InputKey::Printable, InputControl, '=', '+'}, &listeners);
composer.input->key({InputKey::Printable, InputAction::Press, InputControl, '=', '='});
composer.input->flush();
STD_INSIST(!composer.input->text({'+', InputControl}));
STD_INSIST(composer.input->key({InputKey::Printable, InputAction::Release, InputControl, '=', '='}));
}
STD_TEST(FocusLossClearsConsumedAndPendingState) {
auto pool = ObjPool::fromMemory();
Composer composer(pool.mutPtr());
IntrusiveList listeners;
CountBinding listener;
listeners.pushBack(&listener);
composer.inputBindings->add({InputKey::Printable, InputControl, '=', '+'}, &listeners);
composer.input->key({InputKey::Printable, InputAction::Press, InputControl, '=', '='});
composer.input->focus(false);
STD_INSIST(!composer.input->text({'+', InputControl}));
STD_INSIST(!composer.input->key({InputKey::Printable, InputAction::Release, InputControl, '=', '='}));
}
}