|  | 
|  | 1 | +/* | 
|  | 2 | + * SPDX-FileCopyrightText: 2021-2021 CSSlayer <wengxt@gmail.com> | 
|  | 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/inputmethodmanager.h> | 
|  | 15 | +#include <fcitx/instance.h> | 
|  | 16 | +#include <iostream> | 
|  | 17 | + | 
|  | 18 | +using namespace fcitx; | 
|  | 19 | + | 
|  | 20 | +void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { | 
|  | 21 | +    dispatcher->schedule([dispatcher, instance]() { | 
|  | 22 | +        auto *anthy = instance->addonManager().addon("anthy", true); | 
|  | 23 | +        FCITX_ASSERT(anthy); | 
|  | 24 | + | 
|  | 25 | +        auto defaultGroup = instance->inputMethodManager().currentGroup(); | 
|  | 26 | +        defaultGroup.inputMethodList().clear(); | 
|  | 27 | +        defaultGroup.inputMethodList().push_back(InputMethodGroupItem("anthy")); | 
|  | 28 | +        defaultGroup.setDefaultInputMethod(""); | 
|  | 29 | +        instance->inputMethodManager().setGroup(defaultGroup); | 
|  | 30 | +        auto *testfrontend = instance->addonManager().addon("testfrontend"); | 
|  | 31 | +        auto uuid = | 
|  | 32 | +            testfrontend->call<ITestFrontend::createInputContext>("testapp"); | 
|  | 33 | +        auto ic = instance->inputContextManager().findByUUID(uuid); | 
|  | 34 | + | 
|  | 35 | +        RawConfig config; | 
|  | 36 | +        config.setValueByPath("General/TypingMethod", "Nicola"); | 
|  | 37 | +        anthy->setConfig(config); | 
|  | 38 | + | 
|  | 39 | +        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Muhenkan"), | 
|  | 40 | +                                                    false); | 
|  | 41 | +        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false); | 
|  | 42 | +        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), true); | 
|  | 43 | +        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Muhenkan"), | 
|  | 44 | +                                                    true); | 
|  | 45 | + | 
|  | 46 | +        instance->exit(); | 
|  | 47 | +    }); | 
|  | 48 | +} | 
|  | 49 | + | 
|  | 50 | +int main() { | 
|  | 51 | +    setupTestingEnvironment(TESTING_BINARY_DIR, {TESTING_BINARY_DIR "/src"}, | 
|  | 52 | +                            {TESTING_BINARY_DIR "/test"}); | 
|  | 53 | +    // fcitx::Log::setLogRule("default=5,table=5,libime-table=5"); | 
|  | 54 | +    char arg0[] = "testanthy"; | 
|  | 55 | +    char arg1[] = "--disable=all"; | 
|  | 56 | +    char arg2[] = "--enable=testim,testfrontend,anthy,testui"; | 
|  | 57 | +    char *argv[] = {arg0, arg1, arg2}; | 
|  | 58 | +    fcitx::Log::setLogRule("default=5,anthy=5"); | 
|  | 59 | +    Instance instance(FCITX_ARRAY_SIZE(argv), argv); | 
|  | 60 | +    instance.addonManager().registerDefaultLoader(nullptr); | 
|  | 61 | +    EventDispatcher dispatcher; | 
|  | 62 | +    dispatcher.attach(&instance.eventLoop()); | 
|  | 63 | +    scheduleEvent(&dispatcher, &instance); | 
|  | 64 | +    instance.exec(); | 
|  | 65 | + | 
|  | 66 | +    return 0; | 
|  | 67 | +} | 
0 commit comments