|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2020~2020 CSSlayer <[email protected]> |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | + * |
| 6 | + */ |
| 7 | +#include "fcitx-utils/eventdispatcher.h" |
| 8 | +#include "fcitx-utils/testing.h" |
| 9 | +#include "fcitx/addonmanager.h" |
| 10 | +#include "fcitx/inputmethodmanager.h" |
| 11 | +#include "fcitx/instance.h" |
| 12 | +#include "keyboard.h" |
| 13 | +#include "testdir.h" |
| 14 | +#include "testfrontend_public.h" |
| 15 | + |
| 16 | +using namespace fcitx; |
| 17 | + |
| 18 | +void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { |
| 19 | + dispatcher->schedule([instance]() { |
| 20 | + auto *spell = instance->addonManager().addon("spell", true); |
| 21 | + FCITX_ASSERT(spell); |
| 22 | + InputMethodGroup group("Test"); |
| 23 | + // Make sure custom xkb does not kick in. |
| 24 | + group.setDefaultLayout("us"); |
| 25 | + group.inputMethodList().push_back(InputMethodGroupItem("keyboard-us")); |
| 26 | + instance->inputMethodManager().addEmptyGroup("Test"); |
| 27 | + instance->inputMethodManager().setGroup(group); |
| 28 | + instance->inputMethodManager().setCurrentGroup("Test"); |
| 29 | + }); |
| 30 | + dispatcher->schedule([dispatcher, instance]() { |
| 31 | + auto *testfrontend = instance->addonManager().addon("testfrontend"); |
| 32 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("apple-green"); |
| 33 | + auto uuid = |
| 34 | + testfrontend->call<ITestFrontend::createInputContext>("testapp"); |
| 35 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Control+Alt+h"), |
| 36 | + false); |
| 37 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false); |
| 38 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false); |
| 39 | + testfrontend->call<ITestFrontend::keyEvent>( |
| 40 | + uuid, Key(FcitxKey_BackSpace), false); |
| 41 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false); |
| 42 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false); |
| 43 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("l"), false); |
| 44 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false); |
| 45 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("-"), false); |
| 46 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("g"), false); |
| 47 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("r"), false); |
| 48 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false); |
| 49 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false); |
| 50 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false); |
| 51 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+1"), false); |
| 52 | + |
| 53 | + dispatcher->schedule([dispatcher, instance]() { |
| 54 | + dispatcher->detach(); |
| 55 | + instance->exit(); |
| 56 | + }); |
| 57 | + }); |
| 58 | +} |
| 59 | + |
| 60 | +int main() { |
| 61 | + setupTestingEnvironment( |
| 62 | + FCITX5_BINARY_DIR, |
| 63 | + {"src/modules/spell", "testing/testfrontend", "testing/testui", |
| 64 | + "testing/testim"}, |
| 65 | + {"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"}); |
| 66 | + |
| 67 | + static KeyboardEngineFactory keyboardFactory; |
| 68 | + |
| 69 | + StaticAddonRegistry staticAddon = { |
| 70 | + std::make_pair<std::string, AddonFactory *>("keyboard", |
| 71 | + &keyboardFactory)}; |
| 72 | + |
| 73 | + char arg0[] = "testspell"; |
| 74 | + char arg1[] = "--disable=all"; |
| 75 | + char arg2[] = "--enable=keyboard,testfrontend,spell,testui"; |
| 76 | + char *argv[] = {arg0, arg1, arg2}; |
| 77 | + Instance instance(FCITX_ARRAY_SIZE(argv), argv); |
| 78 | + instance.addonManager().registerDefaultLoader(&staticAddon); |
| 79 | + EventDispatcher dispatcher; |
| 80 | + dispatcher.attach(&instance.eventLoop()); |
| 81 | + scheduleEvent(&dispatcher, &instance); |
| 82 | + instance.exec(); |
| 83 | + return 0; |
| 84 | +} |
0 commit comments