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
|
/*
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#include "fcitx-utils/eventdispatcher.h"
#include "fcitx-utils/key.h"
#include "fcitx-utils/keysym.h"
#include "fcitx-utils/log.h"
#include "fcitx-utils/macros.h"
#include "fcitx-utils/testing.h"
#include "fcitx/addonmanager.h"
#include "fcitx/instance.h"
#include "testdir.h"
#include "testfrontend_public.h"
using namespace fcitx;
void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
dispatcher->schedule([instance]() {
auto *unicode = instance->addonManager().addon("unicode", true);
FCITX_ASSERT(unicode);
});
dispatcher->schedule([dispatcher, instance]() {
auto *testfrontend = instance->addonManager().addon("testfrontend");
testfrontend->call<ITestFrontend::pushCommitExpectation>("🍏");
testfrontend->call<ITestFrontend::pushCommitExpectation>("’");
auto uuid =
testfrontend->call<ITestFrontend::createInputContext>("testapp");
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key("Control+Alt+Shift+u"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key(FcitxKey_BackSpace), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("l"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key(" "), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("g"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("r"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+1"), false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key("Control+Shift+u"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("2"), false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key(FcitxKey_BackSpace), false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key(FcitxKey_BackSpace), false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key("Control+Shift+u"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("2"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"),
false); // ignored
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("0"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"),
false); // ignored
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("1"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key(FcitxKey_KP_8),
false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key(FcitxKey_BackSpace), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("9"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("space"), false);
dispatcher->schedule([dispatcher, instance]() {
dispatcher->detach();
instance->exit();
});
});
}
int main() {
setupTestingEnvironmentPath(
FCITX5_BINARY_DIR, {"bin"},
{"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"});
char arg0[] = "testunicode";
char arg1[] = "--disable=all";
char arg2[] = "--enable=testim,testfrontend,unicode,testui";
char *argv[] = {arg0, arg1, arg2};
Instance instance(FCITX_ARRAY_SIZE(argv), argv);
instance.addonManager().registerDefaultLoader(nullptr);
EventDispatcher dispatcher;
dispatcher.attach(&instance.eventLoop());
scheduleEvent(&dispatcher, &instance);
instance.exec();
return 0;
}
|