Skip to content

Commit 38a1d36

Browse files
committed
Add test for keyboard / spell.
1 parent 951ec5a commit 38a1d36

File tree

6 files changed

+123
-30
lines changed

6 files changed

+123
-30
lines changed

src/modules/spell/CMakeLists.txt

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (TARGET PkgConfig::Enchant)
55
set(SPELL_SOURCES ${SPELL_SOURCES} spell-enchant.cpp)
66
endif()
77

8-
add_subdirectory(dict)
98
add_library(spell MODULE ${SPELL_SOURCES})
109
target_link_libraries(spell Fcitx5::Core)
1110
if (TARGET PkgConfig::Enchant)
@@ -17,3 +16,33 @@ fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/spell.conf.in spell.co
1716
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/spell.conf" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/addon"
1817
COMPONENT config)
1918
fcitx5_export_module(Spell TARGET spell BUILD_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}" HEADERS spell_public.h INSTALL)
19+
20+
set(DICT_COMP_SRC
21+
comp_spell_dict.cpp
22+
)
23+
24+
add_executable(comp-spell-dict ${DICT_COMP_SRC})
25+
add_executable(Fcitx5::comp-spell-dict ALIAS comp-spell-dict)
26+
target_link_libraries(comp-spell-dict Fcitx5::Utils)
27+
install(TARGETS comp-spell-dict
28+
DESTINATION "${FCITX_INSTALL_ADDONDIR}/libexec")
29+
30+
set(SPELL_EN_DICT_VER 20121020)
31+
set(SPELL_EN_DICT "${CMAKE_CURRENT_BINARY_DIR}/en_dict.fscd")
32+
set(SPELL_EN_DICT_SRC "${CMAKE_CURRENT_BINARY_DIR}/en_dict.txt")
33+
set(SPELL_EN_DICT_TAR "en_dict-${SPELL_EN_DICT_VER}.tar.gz")
34+
set(SPELL_EN_DICT_URL
35+
"https://download.fcitx-im.org/data/en_dict-${SPELL_EN_DICT_VER}.tar.gz")
36+
37+
fcitx5_download(spell-en-download ${SPELL_EN_DICT_URL} ${SPELL_EN_DICT_TAR}
38+
c44a5d7847925eea9e4d2d04748d442cd28dd9299a0b572ef7d91eac4f5a6ceb)
39+
fcitx5_extract(spell-en-extract "${SPELL_EN_DICT_TAR}" DEPENDS spell-en-download
40+
OUTPUT ${SPELL_EN_DICT_SRC})
41+
42+
add_custom_command(
43+
OUTPUT "${SPELL_EN_DICT}"
44+
DEPENDS "${SPELL_EN_DICT_SRC}" Fcitx5::comp-spell-dict spell-en-extract
45+
COMMAND Fcitx5::comp-spell-dict --comp-dict
46+
"${SPELL_EN_DICT_SRC}" "${SPELL_EN_DICT}")
47+
add_custom_target(spell_en_dict ALL DEPENDS "${SPELL_EN_DICT}")
48+
install(FILES "${SPELL_EN_DICT}" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/spell")

src/modules/spell/dict/CMakeLists.txt

-29
This file was deleted.

test/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ target_link_libraries(testunicode Fcitx5::Core Fcitx5::Module::TestFrontend Fcit
128128
add_dependencies(testunicode copy-addon unicode testui testfrontend testim)
129129
add_test(NAME testunicode COMMAND testunicode)
130130

131+
132+
if (ENABLE_KEYBOARD)
133+
add_executable(testspell testspell.cpp)
134+
target_link_libraries(testspell Fcitx5::Core Fcitx5::Module::TestFrontend keyboard)
135+
add_dependencies(testspell copy-addon spell testui testfrontend spell_en_dict)
136+
add_test(NAME testspell COMMAND testspell)
137+
endif()
138+
131139
add_executable(testquickphrase testquickphrase.cpp)
132140
target_link_libraries(testquickphrase Fcitx5::Core Fcitx5::Module::QuickPhrase Fcitx5::Module::TestFrontend Fcitx5::Module::TestIM)
133141
add_dependencies(testquickphrase copy-addon quickphrase testui testfrontend testim)

test/addon/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_
66
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/modules/quickphrase/quickphrase.conf ${CMAKE_CURRENT_BINARY_DIR}/quickphrase.conf)
77
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/frontend/xim/xim.conf ${CMAKE_CURRENT_BINARY_DIR}/xim.conf)
88
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/modules/xcb/xcb.conf ${CMAKE_CURRENT_BINARY_DIR}/xcb.conf)
9+
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/modules/spell/spell.conf ${CMAKE_CURRENT_BINARY_DIR}/spell.conf)
910
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/src/im/keyboard/keyboard.conf ${CMAKE_CURRENT_BINARY_DIR}/keyboard.conf)
1011
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/testing/testfrontend/testfrontend.conf ${CMAKE_CURRENT_BINARY_DIR}/testfrontend.conf)
1112
add_custom_command(TARGET copy-addon COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/testing/testim/testim.conf ${CMAKE_CURRENT_BINARY_DIR}/testim.conf)

test/testspell.cpp

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <[email protected]>
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 "keyboard.h"
13+
#include "testdir.h"
14+
#include "testfrontend_public.h"
15+
16+
using namespace fcitx;
17+
18+
void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
19+
dispatcher->schedule([instance]() {
20+
auto *spell = instance->addonManager().addon("spell", true);
21+
FCITX_ASSERT(spell);
22+
InputMethodGroup group("Test");
23+
// Make sure custom xkb does not kick in.
24+
group.setDefaultLayout("us");
25+
group.inputMethodList().push_back(InputMethodGroupItem("keyboard-us"));
26+
instance->inputMethodManager().addEmptyGroup("Test");
27+
instance->inputMethodManager().setGroup(group);
28+
instance->inputMethodManager().setCurrentGroup("Test");
29+
});
30+
dispatcher->schedule([dispatcher, instance]() {
31+
auto *testfrontend = instance->addonManager().addon("testfrontend");
32+
testfrontend->call<ITestFrontend::pushCommitExpectation>("apple-green");
33+
auto uuid =
34+
testfrontend->call<ITestFrontend::createInputContext>("testapp");
35+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Control+Alt+h"),
36+
false);
37+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), false);
38+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
39+
testfrontend->call<ITestFrontend::keyEvent>(
40+
uuid, Key(FcitxKey_BackSpace), false);
41+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
42+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"), false);
43+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("l"), false);
44+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
45+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("-"), false);
46+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("g"), false);
47+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("r"), false);
48+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
49+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("e"), false);
50+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("n"), false);
51+
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Alt+1"), false);
52+
53+
dispatcher->schedule([dispatcher, instance]() {
54+
dispatcher->detach();
55+
instance->exit();
56+
});
57+
});
58+
}
59+
60+
int main() {
61+
setupTestingEnvironment(
62+
FCITX5_BINARY_DIR,
63+
{"src/modules/spell", "testing/testfrontend", "testing/testui",
64+
"testing/testim"},
65+
{"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"});
66+
67+
static KeyboardEngineFactory keyboardFactory;
68+
69+
StaticAddonRegistry staticAddon = {
70+
std::make_pair<std::string, AddonFactory *>("keyboard",
71+
&keyboardFactory)};
72+
73+
char arg0[] = "testspell";
74+
char arg1[] = "--disable=all";
75+
char arg2[] = "--enable=keyboard,testfrontend,spell,testui";
76+
char *argv[] = {arg0, arg1, arg2};
77+
Instance instance(FCITX_ARRAY_SIZE(argv), argv);
78+
instance.addonManager().registerDefaultLoader(&staticAddon);
79+
EventDispatcher dispatcher;
80+
dispatcher.attach(&instance.eventLoop());
81+
scheduleEvent(&dispatcher, &instance);
82+
instance.exec();
83+
return 0;
84+
}

0 commit comments

Comments
 (0)