1 /*
2 * SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-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 #include <thread>
18
19 using namespace fcitx;
20
scheduleEvent(EventDispatcher * dispatcher,Instance * instance)21 void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
22 dispatcher->schedule([instance]() {
23 auto *pinyin = instance->addonManager().addon("pinyin", true);
24 FCITX_ASSERT(pinyin);
25 });
26 dispatcher->schedule([dispatcher, instance]() {
27 auto defaultGroup = instance->inputMethodManager().currentGroup();
28 defaultGroup.inputMethodList().clear();
29 defaultGroup.inputMethodList().push_back(
30 InputMethodGroupItem("keyboard-us"));
31 defaultGroup.inputMethodList().push_back(
32 InputMethodGroupItem("pinyin"));
33 defaultGroup.setDefaultInputMethod("");
34 instance->inputMethodManager().setGroup(defaultGroup);
35 auto *testfrontend = instance->addonManager().addon("testfrontend");
36 auto uuid =
37 testfrontend->call<ITestFrontend::createInputContext>("testapp");
38 testfrontend->call<ITestFrontend::pushCommitExpectation>("俺");
39 testfrontend->call<ITestFrontend::pushCommitExpectation>("ni");
40 testfrontend->call<ITestFrontend::pushCommitExpectation>("ni");
41 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Control+space"),
42 false);
43 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false);
44 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("`"), false);
45 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
46 testfrontend->call<ITestFrontend::keyEvent>(
47 uuid, Key(FcitxKey_BackSpace), false);
48 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
49 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("s"), false);
50 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("h"), false);
51 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
52 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
53 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("1"), false);
54 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
55 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("i"), false);
56 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Return"), false);
57 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
58 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("i"), false);
59 testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("KP_Enter"),
60 false);
61
62 dispatcher->schedule([dispatcher, instance]() {
63 dispatcher->detach();
64 instance->exit();
65 });
66 });
67 }
68
runInstance()69 void runInstance() {}
70
main()71 int main() {
72 setupTestingEnvironment(TESTING_BINARY_DIR,
73 {TESTING_BINARY_DIR "/modules/pinyinhelper",
74 TESTING_BINARY_DIR "/modules/punctuation",
75 TESTING_BINARY_DIR "/im/pinyin"},
76 {TESTING_BINARY_DIR "/test",
77 TESTING_BINARY_DIR "/modules",
78 StandardPath::fcitxPath("pkgdatadir")});
79 // fcitx::Log::setLogRule("default=5,table=5,libime-table=5");
80 char arg0[] = "testpinyin";
81 char arg1[] = "--disable=all";
82 char arg2[] = "--enable=testim,testfrontend,pinyin,punctuation,"
83 "pinyinhelper";
84 char *argv[] = {arg0, arg1, arg2};
85 fcitx::Log::setLogRule("default=5,pinyin=5");
86 Instance instance(FCITX_ARRAY_SIZE(argv), argv);
87 instance.addonManager().registerDefaultLoader(nullptr);
88 EventDispatcher dispatcher;
89 dispatcher.attach(&instance.eventLoop());
90 std::thread thread(scheduleEvent, &dispatcher, &instance);
91 instance.exec();
92 thread.join();
93
94 return 0;
95 }
96