1 /*
2  * SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
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 "testdir.h"
13 #include "testfrontend_public.h"
14 
15 using namespace fcitx;
16 
scheduleEvent(EventDispatcher * dispatcher,Instance * instance)17 void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
18     dispatcher->schedule([instance]() {
19         auto *unicode = instance->addonManager().addon("unicode", true);
20         FCITX_ASSERT(unicode);
21     });
22     dispatcher->schedule([dispatcher, instance]() {
23         auto *testfrontend = instance->addonManager().addon("testfrontend");
24         testfrontend->call<ITestFrontend::pushCommitExpectation>("��");
25         auto uuid =
26             testfrontend->call<ITestFrontend::createInputContext>("testapp");
27         testfrontend->call<ITestFrontend::keyEvent>(
28             uuid, Key("Control+Alt+Shift+u"), false);
29         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false);
30         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
31         testfrontend->call<ITestFrontend::keyEvent>(
32             uuid, Key(FcitxKey_BackSpace), false);
33         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
34         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
35         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("l"), false);
36         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
37         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key(" "), false);
38         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("g"), false);
39         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("r"), false);
40         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
41         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
42         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
43         testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+1"), false);
44 
45         dispatcher->schedule([dispatcher, instance]() {
46             dispatcher->detach();
47             instance->exit();
48         });
49     });
50 }
51 
main()52 int main() {
53     setupTestingEnvironment(
54         FCITX5_BINARY_DIR,
55         {"src/modules/unicode", "testing/testfrontend", "testing/testui",
56          "testing/testim"},
57         {"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"});
58 
59     char arg0[] = "testunicode";
60     char arg1[] = "--disable=all";
61     char arg2[] = "--enable=testim,testfrontend,unicode,testui";
62     char *argv[] = {arg0, arg1, arg2};
63     Instance instance(FCITX_ARRAY_SIZE(argv), argv);
64     instance.addonManager().registerDefaultLoader(nullptr);
65     EventDispatcher dispatcher;
66     dispatcher.attach(&instance.eventLoop());
67     scheduleEvent(&dispatcher, &instance);
68     instance.exec();
69     return 0;
70 }
71