File: testanthy.cpp

package info (click to toggle)
fcitx5-anthy 5.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 800 kB
  • sloc: cpp: 7,629; makefile: 4; sh: 1
file content (102 lines) | stat: -rw-r--r-- 3,772 bytes parent folder | download
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
/*
 * SPDX-FileCopyrightText: 2021-2021 CSSlayer <wengxt@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 */
#include "testdir.h"
#include "testfrontend_public.h"
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/eventdispatcher.h>
#include <fcitx-utils/key.h>
#include <fcitx-utils/log.h>
#include <fcitx-utils/macros.h>
#include <fcitx-utils/testing.h>
#include <fcitx/addonmanager.h>
#include <fcitx/inputmethodgroup.h>
#include <fcitx/inputmethodmanager.h>
#include <fcitx/instance.h>

using namespace fcitx;

void setup(Instance *instance) {
    instance->eventDispatcher().schedule([instance]() {
        auto *anthy = instance->addonManager().addon("anthy", true);
        FCITX_ASSERT(anthy);

        auto defaultGroup = instance->inputMethodManager().currentGroup();
        defaultGroup.inputMethodList().clear();
        defaultGroup.inputMethodList().push_back(InputMethodGroupItem("anthy"));
        defaultGroup.setDefaultInputMethod("");
        instance->inputMethodManager().setGroup(defaultGroup);
    });
}

void testSpace(Instance *instance) {
    instance->eventDispatcher().schedule([instance]() {
        auto *anthy = instance->addonManager().addon("anthy", true);
        FCITX_ASSERT(anthy);
        auto *testfrontend = instance->addonManager().addon("testfrontend");
        auto uuid =
            testfrontend->call<ITestFrontend::createInputContext>("testapp");
        auto *ic = instance->inputContextManager().findByUUID(uuid);
        FCITX_ASSERT(ic);

        RawConfig config;
        config.setValueByPath("General/SpaceType", "Wide");
        anthy->setConfig(config);

        testfrontend->call<ITestFrontend::pushCommitExpectation>(" ");
        FCITX_ASSERT(testfrontend->call<ITestFrontend::sendKeyEvent>(
            uuid, Key("space"), false));

        config.setValueByPath("General/SpaceType", "Half");
        anthy->setConfig(config);

        FCITX_ASSERT(!testfrontend->call<ITestFrontend::sendKeyEvent>(
            uuid, Key("space"), false));
    });
}

void testNicola(Instance *instance) {
    instance->eventDispatcher().schedule([instance]() {
        auto *anthy = instance->addonManager().addon("anthy", true);
        FCITX_ASSERT(anthy);
        auto *testfrontend = instance->addonManager().addon("testfrontend");
        auto uuid =
            testfrontend->call<ITestFrontend::createInputContext>("testapp");
        auto *ic = instance->inputContextManager().findByUUID(uuid);
        FCITX_ASSERT(ic);

        RawConfig config;
        config.setValueByPath("General/TypingMethod", "Nicola");
        anthy->setConfig(config);

        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Muhenkan"),
                                                    false);
        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false);
        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), true);
        testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Muhenkan"),
                                                    true);
    });
}

int main() {
    setupTestingEnvironment(TESTING_BINARY_DIR, {"bin"},
                            {TESTING_BINARY_DIR "/test"});
    // fcitx::Log::setLogRule("default=5,table=5,libime-table=5");
    char arg0[] = "testanthy";
    char arg1[] = "--disable=all";
    char arg2[] = "--enable=testim,testfrontend,anthy,testui";
    char *argv[] = {arg0, arg1, arg2};
    fcitx::Log::setLogRule("default=5,anthy=5");
    Instance instance(FCITX_ARRAY_SIZE(argv), argv);
    instance.addonManager().registerDefaultLoader(nullptr);
    setup(&instance);
    testSpace(&instance);
    testNicola(&instance);
    instance.eventDispatcher().schedule([&instance]() { instance.exit(); });
    instance.exec();

    return 0;
}