|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2021-2021 CSSlayer <[email protected]> |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | + * |
| 6 | + */ |
| 7 | +#include "testdir.h" |
| 8 | +#include "testfrontend_public.h" |
| 9 | +#include <fcitx-utils/eventdispatcher.h> |
| 10 | +#include <fcitx-utils/log.h> |
| 11 | +#include <fcitx-utils/standardpath.h> |
| 12 | +#include <fcitx-utils/testing.h> |
| 13 | +#include <fcitx/addonmanager.h> |
| 14 | +#include <fcitx/inputcontextmanager.h> |
| 15 | +#include <fcitx/inputmethodmanager.h> |
| 16 | +#include <fcitx/instance.h> |
| 17 | +#include <iostream> |
| 18 | +#include <thread> |
| 19 | + |
| 20 | +using namespace fcitx; |
| 21 | + |
| 22 | +void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { |
| 23 | + dispatcher->schedule([dispatcher, instance]() { |
| 24 | + auto *m17n = instance->addonManager().addon("m17n", true); |
| 25 | + FCITX_ASSERT(m17n); |
| 26 | + auto defaultGroup = instance->inputMethodManager().currentGroup(); |
| 27 | + defaultGroup.inputMethodList().clear(); |
| 28 | + defaultGroup.inputMethodList().push_back( |
| 29 | + InputMethodGroupItem("keyboard-us")); |
| 30 | + defaultGroup.inputMethodList().push_back( |
| 31 | + InputMethodGroupItem("m17n_si_wijesekera")); |
| 32 | + defaultGroup.setDefaultInputMethod(""); |
| 33 | + instance->inputMethodManager().setGroup(defaultGroup); |
| 34 | + auto *testfrontend = instance->addonManager().addon("testfrontend"); |
| 35 | + auto uuid = |
| 36 | + testfrontend->call<ITestFrontend::createInputContext>("testapp"); |
| 37 | + auto ic = instance->inputContextManager().findByUUID(uuid); |
| 38 | + ic->focusIn(); |
| 39 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("ඳ"); |
| 40 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("ඟ"); |
| 41 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("ග"); |
| 42 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("ඤ"); |
| 43 | + testfrontend->call<ITestFrontend::pushCommitExpectation>("ඥ"); |
| 44 | + testfrontend->call<ITestFrontend::pushCommitExpectation>(":"); |
| 45 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Control+space"), |
| 46 | + false); |
| 47 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+o"), false); |
| 48 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+period"), |
| 49 | + false); |
| 50 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("period"), false); |
| 51 | + testfrontend->call<ITestFrontend::keyEvent>( |
| 52 | + uuid, Key(FcitxKey_bracketleft), false); |
| 53 | + testfrontend->call<ITestFrontend::keyEvent>( |
| 54 | + uuid, Key(FcitxKey_braceleft), false); |
| 55 | + testfrontend->call<ITestFrontend::keyEvent>( |
| 56 | + uuid, Key(FcitxKey_braceright), false); |
| 57 | + testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Control+space"), |
| 58 | + false); |
| 59 | + |
| 60 | + dispatcher->schedule([dispatcher, instance]() { |
| 61 | + dispatcher->detach(); |
| 62 | + instance->exit(); |
| 63 | + }); |
| 64 | + }); |
| 65 | +} |
| 66 | + |
| 67 | +void runInstance() {} |
| 68 | + |
| 69 | +int main() { |
| 70 | + setupTestingEnvironment(TESTING_BINARY_DIR, {TESTING_BINARY_DIR "/im"}, |
| 71 | + {TESTING_BINARY_DIR "/test"}); |
| 72 | + // fcitx::Log::setLogRule("default=5,table=5,libime-table=5"); |
| 73 | + char arg0[] = "testm17n"; |
| 74 | + char arg1[] = "--disable=all"; |
| 75 | + char arg2[] = "--enable=testim,testfrontend,m17n,testui"; |
| 76 | + char *argv[] = {arg0, arg1, arg2}; |
| 77 | + fcitx::Log::setLogRule("default=5,m17n=5"); |
| 78 | + Instance instance(FCITX_ARRAY_SIZE(argv), argv); |
| 79 | + instance.addonManager().registerDefaultLoader(nullptr); |
| 80 | + EventDispatcher dispatcher; |
| 81 | + dispatcher.attach(&instance.eventLoop()); |
| 82 | + std::thread thread(scheduleEvent, &dispatcher, &instance); |
| 83 | + instance.exec(); |
| 84 | + thread.join(); |
| 85 | + |
| 86 | + return 0; |
| 87 | +} |
0 commit comments