|
29 | 29 |
|
30 | 30 | using namespace fcitx; |
31 | 31 |
|
| 32 | +void testKeyEventResult(AddonInstance *testfrontend, AddonInstance *luaaddon, |
| 33 | + ICUUID uuid, InputContext *ic) { |
| 34 | + auto sendKey = [&](const std::string &key) { |
| 35 | + return testfrontend->call<ITestFrontend::sendKeyEvent>(uuid, Key(key), |
| 36 | + false); |
| 37 | + }; |
| 38 | + auto getLastCommit = [&]() { |
| 39 | + return luaaddon |
| 40 | + ->call<ILuaAddon::invokeLuaFunction>(ic, "getLastCommit", |
| 41 | + RawConfig{}) |
| 42 | + .value(); |
| 43 | + }; |
| 44 | + |
| 45 | + // Test KeyEventResult enum values |
| 46 | + |
| 47 | + FCITX_ASSERT(sendKey("x")) << "NotHandled: should accept the event"; |
| 48 | + FCITX_ASSERT(getLastCommit() == "x") << "NotHandled: should commit 'x'"; |
| 49 | + |
| 50 | + FCITX_ASSERT(sendKey("y")) << "Handled: should accept the event"; |
| 51 | + FCITX_ASSERT(getLastCommit() == "x") << "Handled: should still be 'x'"; |
| 52 | + |
| 53 | + FCITX_ASSERT(!sendKey("z")) << "Passthrough: should not accept the event"; |
| 54 | + FCITX_ASSERT(getLastCommit() == "x") << "Passthrough: should still be 'x'"; |
| 55 | + |
| 56 | + // Legacy boolean/nil return values |
| 57 | + |
| 58 | + FCITX_ASSERT(sendKey("e")) << "false: should accept the event"; |
| 59 | + FCITX_ASSERT(getLastCommit() == "e") << "false: should commit 'e'"; |
| 60 | + |
| 61 | + FCITX_ASSERT(sendKey("f")) << "nil: should accept the event"; |
| 62 | + FCITX_ASSERT(getLastCommit() == "f") << "nil: should commit 'f'"; |
| 63 | + |
| 64 | + FCITX_ASSERT(sendKey("g")) << "true: should accept the event"; |
| 65 | + FCITX_ASSERT(getLastCommit() == "f") << "true: should still be 'f'"; |
| 66 | +} |
| 67 | + |
32 | 68 | void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { |
33 | 69 | dispatcher->schedule([instance]() { |
34 | 70 | auto *luaaddonloader = |
@@ -126,6 +162,8 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { |
126 | 162 | ic, "testUtf8Conversion", strConfig); |
127 | 163 | FCITX_ASSERT(ret.value() == testString) << ret; |
128 | 164 |
|
| 165 | + testKeyEventResult(testfrontend, luaaddon, uuid, ic); |
| 166 | + |
129 | 167 | dispatcher->detach(); |
130 | 168 | instance->exit(); |
131 | 169 | }); |
|
0 commit comments