Skip to content

Commit 4594aab

Browse files
authored
Add basic test for anthy (#16)
Prepare for investigating #15 issue
1 parent c0e09c3 commit 4594aab

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ option(ENABLE_TEST "Build Test" On)
1212
option(ENABLE_COVERAGE "Build the project with gcov support (Need ENABLE_TEST=On)" Off)
1313

1414
find_package(Fcitx5Core 5.1.2 REQUIRED)
15-
find_package(Fcitx5Module REQUIRED COMPONENTS Clipboard)
15+
find_package(Fcitx5Module REQUIRED COMPONENTS Clipboard TestFrontend)
1616
find_package(Gettext REQUIRED)
1717
find_package(PkgConfig REQUIRED)
1818

src/engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AnthyEngine : public fcitx::InputMethodEngineV3 {
5050
void setConfig(const fcitx::RawConfig &config) override {
5151
config_.load(config, true);
5252
saveConfig();
53-
reloadConfig();
53+
populateConfig();
5454
}
5555

5656
void saveConfig() { fcitx::safeSaveAsIni(config_, "conf/anthy.conf"); }

test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
33
add_executable(teststylefile teststylefile.cpp)
44
target_link_libraries(teststylefile stylefile Fcitx5::Core)
55
add_test(teststylefile teststylefile)
6+
7+
add_subdirectory(addon)
8+
add_subdirectory(inputmethod)
9+
add_executable(testanthy testanthy.cpp)
10+
target_link_libraries(testanthy Fcitx5::Core Fcitx5::Module::TestFrontend)
11+
add_dependencies(testanthy anthy copy-addon copy-im)
12+
add_test(testanthy testanthy)

test/addon/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_custom_target(copy-addon DEPENDS anthy-addon.conf.in-fmt)
2+
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/anthy-addon.conf ${CMAKE_CURRENT_BINARY_DIR}/anthy.conf)

test/inputmethod/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_custom_target(copy-im DEPENDS anthy.conf.in-fmt)
2+
add_custom_command(TARGET copy-im COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/anthy.conf ${CMAKE_CURRENT_BINARY_DIR}/anthy.conf)

test/testanthy.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)