1919
2020using  namespace  fcitx ; 
2121
22- void  scheduleEvent (EventDispatcher *dispatcher,  Instance *instance) {
23-     dispatcher-> schedule ([instance]() {
22+ void  setup ( Instance *instance) {
23+     instance-> eventDispatcher (). schedule ([instance]() {
2424        auto  *anthy = instance->addonManager ().addon (" anthy" true );
2525        FCITX_ASSERT (anthy);
2626
@@ -29,6 +29,39 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
2929        defaultGroup.inputMethodList ().push_back (InputMethodGroupItem (" anthy" 
3030        defaultGroup.setDefaultInputMethod (" " 
3131        instance->inputMethodManager ().setGroup (defaultGroup);
32+     });
33+ }
34+ 
35+ void  testSpace (Instance *instance) {
36+     instance->eventDispatcher ().schedule ([instance]() {
37+         auto  *anthy = instance->addonManager ().addon (" anthy" true );
38+         FCITX_ASSERT (anthy);
39+         auto  *testfrontend = instance->addonManager ().addon (" testfrontend" 
40+         auto  uuid =
41+             testfrontend->call <ITestFrontend::createInputContext>(" testapp" 
42+         auto  *ic = instance->inputContextManager ().findByUUID (uuid);
43+         FCITX_ASSERT (ic);
44+ 
45+         RawConfig config;
46+         config.setValueByPath (" General/SpaceType" " Wide" 
47+         anthy->setConfig (config);
48+ 
49+         testfrontend->call <ITestFrontend::pushCommitExpectation>("  " 
50+         FCITX_ASSERT (testfrontend->call <ITestFrontend::sendKeyEvent>(
51+             uuid, Key (" space" false ));
52+ 
53+         config.setValueByPath (" General/SpaceType" " Half" 
54+         anthy->setConfig (config);
55+ 
56+         FCITX_ASSERT (!testfrontend->call <ITestFrontend::sendKeyEvent>(
57+             uuid, Key (" space" false ));
58+     });
59+ }
60+ 
61+ void  testNicola (Instance *instance) {
62+     instance->eventDispatcher ().schedule ([instance]() {
63+         auto  *anthy = instance->addonManager ().addon (" anthy" true );
64+         FCITX_ASSERT (anthy);
3265        auto  *testfrontend = instance->addonManager ().addon (" testfrontend" 
3366        auto  uuid =
3467            testfrontend->call <ITestFrontend::createInputContext>(" testapp" 
@@ -45,13 +78,11 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
4578        testfrontend->call <ITestFrontend::keyEvent>(uuid, Key (" a" true );
4679        testfrontend->call <ITestFrontend::keyEvent>(uuid, Key (" Muhenkan" 
4780                                                    true );
48- 
49-         instance->exit ();
5081    });
5182}
5283
5384int  main () {
54-     setupTestingEnvironment (TESTING_BINARY_DIR, {TESTING_BINARY_DIR  " /src " 
85+     setupTestingEnvironment (TESTING_BINARY_DIR, {" bin " 
5586                            {TESTING_BINARY_DIR " /test" 
5687    //  fcitx::Log::setLogRule("default=5,table=5,libime-table=5");
5788    char  arg0[] = " testanthy" 
@@ -61,9 +92,10 @@ int main() {
6192    fcitx::Log::setLogRule (" default=5,anthy=5" 
6293    Instance instance (FCITX_ARRAY_SIZE (argv), argv);
6394    instance.addonManager ().registerDefaultLoader (nullptr );
64-     EventDispatcher dispatcher;
65-     dispatcher.attach (&instance.eventLoop ());
66-     scheduleEvent (&dispatcher, &instance);
95+     setup (&instance);
96+     testSpace (&instance);
97+     testNicola (&instance);
98+     instance.eventDispatcher ().schedule ([&instance]() { instance.exit (); });
6799    instance.exec ();
68100
69101    return  0 ;
0 commit comments