Blame SOURCES/add-a-gui-test.patch

b67caa
diff -Nru ibus-table-1.9.18/configure.ac ibus-table-1.9.18.new/configure.ac
b67caa
--- ibus-table-1.9.18/configure.ac	2020-07-22 15:02:24.341755774 +0200
b67caa
+++ ibus-table-1.9.18.new/configure.ac	2020-07-22 15:03:04.097344610 +0200
b67caa
@@ -54,6 +54,15 @@
b67caa
 AM_GNU_GETTEXT([external])
b67caa
 AM_GNU_GETTEXT_VERSION(0.16.1)
b67caa
 
b67caa
+AC_ARG_ENABLE([installed-tests],
b67caa
+    [AS_HELP_STRING([--enable-installed-tests],
b67caa
+                   [Enable to install tests])],
b67caa
+    [enable_installed_tests=$enableval],
b67caa
+    [enable_installed_tests=no]
b67caa
+)
b67caa
+
b67caa
+AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], [test x"$enable_installed_tests" = x"yes"])
b67caa
+
b67caa
 # OUTPUT files
b67caa
 AC_CONFIG_FILES([po/Makefile.in
b67caa
     Makefile
b67caa
diff -Nru ibus-table-1.9.18/tests/.gitignore ibus-table-1.9.18.new/tests/.gitignore
b67caa
--- ibus-table-1.9.18/tests/.gitignore	2020-07-22 15:02:24.349755691 +0200
b67caa
+++ ibus-table-1.9.18.new/tests/.gitignore	2020-07-22 15:11:24.740159555 +0200
b67caa
@@ -1,5 +1,5 @@
b67caa
 run_tests
b67caa
-run_tests.log
b67caa
-run_tests.trs
b67caa
-test-suite.log
b67caa
+*.log
b67caa
+*.trs
b67caa
+*.tap
b67caa
 __pycache__/
b67caa
diff -Nru ibus-table-1.9.18/tests/Makefile.am ibus-table-1.9.18.new/tests/Makefile.am
b67caa
--- ibus-table-1.9.18/tests/Makefile.am	2020-07-22 15:02:24.349755691 +0200
b67caa
+++ ibus-table-1.9.18.new/tests/Makefile.am	2020-07-22 15:04:28.298473415 +0200
b67caa
@@ -19,20 +19,58 @@
b67caa
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
b67caa
 #
b67caa
 
b67caa
-TESTS = run_tests
b67caa
+TESTS = \
b67caa
+	test_it.py \
b67caa
+	test_0_gtk.py \
b67caa
+	$(NULL)
b67caa
+
b67caa
+check_SCRIPTS = run_tests
b67caa
+
b67caa
+LOG_COMPILER = $(builddir)/run_tests
b67caa
+
b67caa
+TESTS_ENVIRONMENT = \
b67caa
+	IBUS_TABLE_LOCATION=../
b67caa
+
b67caa
+test_meta_in = meta.test.in
b67caa
+test_metas =
b67caa
+
b67caa
+if ENABLE_INSTALLED_TESTS
b67caa
+test_metas += $(patsubst %.py, %.test, $(TESTS))
b67caa
+test_source_DATA = $(test_metas)
b67caa
+test_sourcedir = $(datadir)/installed-tests/ibus-table
b67caa
+test_exec_SCRIPTS = \
b67caa
+	$(TESTS) \
b67caa
+	gtkcases.py \
b67caa
+	mock_engine.py \
b67caa
+	run_tests \
b67caa
+	$(NULL)
b67caa
+test_execdir = $(libexecdir)/installed-tests/ibus-table
b67caa
+
b67caa
+$(test_metas): $(test_meta_in)
b67caa
+	@TEST_EXEC=`echo $@ | sed -e 's&\.test&\.py&';; \
b67caa
+	sed -e "s&@TEST_EXECDIR@&$(test_execdir)&g" \
b67caa
+	    -e "s&@TEST_EXEC@&$$TEST_EXEC&g" $< > $@.tmp; \
b67caa
+	mv $@.tmp $@; \
b67caa
+	$(NULL)
b67caa
+endif
b67caa
 
b67caa
 run_tests: run_tests.in
b67caa
 	sed -e 's&@PYTHON_BIN@&$(PYTHON)&g' \
b67caa
+	    -e 's&@PKGDATADIR@&$(pkgdatadir)&g' \
b67caa
 	    -e 's&@SRCDIR@&$(srcdir)&g' $< > $@
b67caa
 	chmod +x $@
b67caa
 
b67caa
 EXTRA_DIST = \
b67caa
-	run_tests.in \
b67caa
-	test_it.py \
b67caa
+	$(test_meta_in) \
b67caa
 	__init__.py \
b67caa
+	gtkcases.py \
b67caa
+	mock_engine.py \
b67caa
+	run_tests.in \
b67caa
+	$(TESTS) \
b67caa
 	$(NULL)
b67caa
 
b67caa
 CLEANFILES = \
b67caa
+	$(test_metas) \
b67caa
 	run_tests \
b67caa
 	$(NULL)
b67caa
 
b67caa
diff -Nru ibus-table-1.9.18/tests/gtkcases.py ibus-table-1.9.18.new/tests/gtkcases.py
b67caa
--- ibus-table-1.9.18/tests/gtkcases.py	1970-01-01 01:00:00.000000000 +0100
b67caa
+++ ibus-table-1.9.18.new/tests/gtkcases.py	2020-07-22 15:03:04.097344610 +0200
b67caa
@@ -0,0 +1,38 @@
b67caa
+#!/usr/bin/python3
b67caa
+# -*- coding: utf-8 -*-
b67caa
+
b67caa
+# 'init' has one array which is [keysym, keycode, modifier] and to be run
b67caa
+# before the main tests. E.g.
b67caa
+# Ctrl-space to enable Hiragana mode
b67caa
+#
b67caa
+# 'tests' cases are the main test cases.
b67caa
+# 'preedit' case runs to create a preedit text.
b67caa
+# 'lookup' case runs to update a lookup table.
b67caa
+# 'commit' case runs to commit the preedit text.
b67caa
+# 'result' case is the expected output.
b67caa
+# 'preedit', 'lookup', 'commit' can choose the type of either 'string' or 'keys'
b67caa
+# 'string' type is a string sequence which does not need modifiers
b67caa
+
b67caa
+from gi import require_version as gi_require_version
b67caa
+gi_require_version('IBus', '1.0')
b67caa
+from gi.repository import IBus
b67caa
+
b67caa
+TestCases = {
b67caa
+    #'init': [IBus.KEY_j, 0, IBus.ModifierType.CONTROL_MASK],
b67caa
+    'tests': [
b67caa
+                {'preedit': {'string': 'a'},
b67caa
+                 'lookup': {'keys': [[IBus.KEY_Down, 0, 0]]},
b67caa
+                 'commit': {'keys': [[IBus.KEY_space, 0, 0]]},
b67caa
+                 'result': {'string': '区'}
b67caa
+                },
b67caa
+                {'preedit': {'string': 'ijgl'},
b67caa
+                 'commit': {'keys': [[IBus.KEY_space, 0, 0]]},
b67caa
+                 'result': {'string': '漫画'}
b67caa
+                },
b67caa
+                {'preedit': {'string': 'wgl'},
b67caa
+                 'lookup': {'keys': [[IBus.KEY_Down, 0, 0]]},
b67caa
+                 'commit': {'keys': [[IBus.KEY_space, 0, 0]]},
b67caa
+                 'result': {'string': '全国'}
b67caa
+                },
b67caa
+            ]
b67caa
+}
b67caa
diff -Nru ibus-table-1.9.18/tests/meta.test.in ibus-table-1.9.18.new/tests/meta.test.in
b67caa
--- ibus-table-1.9.18/tests/meta.test.in	1970-01-01 01:00:00.000000000 +0100
b67caa
+++ ibus-table-1.9.18.new/tests/meta.test.in	2020-07-22 15:03:04.097344610 +0200
b67caa
@@ -0,0 +1,4 @@
b67caa
+[Test]
b67caa
+Type=session
b67caa
+Exec=@TEST_EXECDIR@/run_tests @TEST_EXEC@
b67caa
+Output=TAP
b67caa
diff -Nru ibus-table-1.9.18/tests/mock_engine.py ibus-table-1.9.18.new/tests/mock_engine.py
b67caa
--- ibus-table-1.9.18/tests/mock_engine.py	1970-01-01 01:00:00.000000000 +0100
b67caa
+++ ibus-table-1.9.18.new/tests/mock_engine.py	2020-07-22 15:07:00.649895226 +0200
b67caa
@@ -0,0 +1,241 @@
b67caa
+# ibus-table - The Tables engine for IBus
b67caa
+#
b67caa
+# Copyright (c) 2018-2020 Mike FABIAN <mfabian@redhat.com>
b67caa
+#
b67caa
+# This library is free software; you can redistribute it and/or
b67caa
+# modify it under the terms of the GNU Lesser General Public
b67caa
+# License as published by the Free Software Foundation; either
b67caa
+# version 2.1 of the License, or (at your option) any later version.
b67caa
+#
b67caa
+# This library is distributed in the hope that it will be useful,
b67caa
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b67caa
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b67caa
+# Lesser General Public License for more details.
b67caa
+#
b67caa
+# You should have received a copy of the GNU Lesser General Public
b67caa
+# License along with this library; if not, write to the Free Software
b67caa
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
b67caa
+#
b67caa
+
b67caa
+'''
b67caa
+Define some mock classes for the unittests.
b67caa
+'''
b67caa
+
b67caa
+from gi import require_version
b67caa
+require_version('IBus', '1.0')
b67caa
+from gi.repository import IBus
b67caa
+
b67caa
+class MockEngine:
b67caa
+    def __init__(self, engine_name = '', connection = None, object_path = ''):
b67caa
+        self.mock_auxiliary_text = ''
b67caa
+        self.mock_preedit_text = ''
b67caa
+        self.mock_preedit_text_cursor_pos = 0
b67caa
+        self.mock_preedit_text_visible = True
b67caa
+        self.mock_committed_text = ''
b67caa
+        self.mock_committed_text_cursor_pos = 0
b67caa
+        self.client_capabilities = (
b67caa
+            IBus.Capabilite.PREEDIT_TEXT
b67caa
+            | IBus.Capabilite.AUXILIARY_TEXT
b67caa
+            | IBus.Capabilite.LOOKUP_TABLE
b67caa
+            | IBus.Capabilite.FOCUS
b67caa
+            | IBus.Capabilite.PROPERTY)
b67caa
+        # There are lots of weird problems with surrounding text
b67caa
+        # which makes this hard to test. Therefore this mock
b67caa
+        # engine does not try to support surrounding text, i.e.
b67caa
+        # we omit “| IBus.Capabilite.SURROUNDING_TEXT” here.
b67caa
+
b67caa
+    def update_auxiliary_text(self, text, visible):
b67caa
+        self.mock_auxiliary_text = text.text
b67caa
+
b67caa
+    def hide_auxiliary_text(self):
b67caa
+        pass
b67caa
+
b67caa
+    def hide_preedit_text(self):
b67caa
+        pass
b67caa
+
b67caa
+    def commit_text(self, text):
b67caa
+        self.mock_committed_text = (
b67caa
+            self.mock_committed_text[
b67caa
+                :self.mock_committed_text_cursor_pos]
b67caa
+            + text.text
b67caa
+            + self.mock_committed_text[
b67caa
+                self.mock_committed_text_cursor_pos:])
b67caa
+        self.mock_committed_text_cursor_pos += len(text.text)
b67caa
+
b67caa
+    def forward_key_event(self, val, code, state):
b67caa
+        if (val == IBus.KEY_Left
b67caa
+            and self.mock_committed_text_cursor_pos > 0):
b67caa
+            self.mock_committed_text_cursor_pos -= 1
b67caa
+            return
b67caa
+        unicode = IBus.keyval_to_unicode(val)
b67caa
+        if unicode:
b67caa
+            self.mock_committed_text = (
b67caa
+            self.mock_committed_text[
b67caa
+                :self.mock_committed_text_cursor_pos]
b67caa
+            + unicode
b67caa
+            + self.mock_committed_text[
b67caa
+                self.mock_committed_text_cursor_pos:])
b67caa
+            self.mock_committed_text_cursor_pos += len(unicode)
b67caa
+
b67caa
+    def update_lookup_table(self, table, visible):
b67caa
+        pass
b67caa
+
b67caa
+    def update_preedit_text(self, text, cursor_pos, visible):
b67caa
+        self.mock_preedit_text = text.get_text()
b67caa
+        self.mock_preedit_text_cursor_pos = cursor_pos
b67caa
+        self.mock_preedit_text_visible = visible
b67caa
+
b67caa
+    def register_properties(self, property_list):
b67caa
+        pass
b67caa
+
b67caa
+    def update_property(self, property):
b67caa
+        pass
b67caa
+
b67caa
+    def hide_lookup_table(self):
b67caa
+        pass
b67caa
+
b67caa
+class MockLookupTable:
b67caa
+    def __init__(self, page_size = 9, cursor_pos = 0, cursor_visible = False, round = True):
b67caa
+        self.clear()
b67caa
+        self.mock_page_size = page_size
b67caa
+        self.mock_cursor_pos = cursor_pos
b67caa
+        self.mock_cursor_visible = cursor_visible
b67caa
+        self.cursor_visible = cursor_visible
b67caa
+        self.mock_round = round
b67caa
+        self.mock_candidates = []
b67caa
+        self.mock_labels = []
b67caa
+        self.mock_page_number = 0
b67caa
+
b67caa
+    def clear(self):
b67caa
+        self.mock_candidates = []
b67caa
+        self.mock_cursor_pos = 0
b67caa
+
b67caa
+    def set_page_size(self, size):
b67caa
+        self.mock_page_size = size
b67caa
+
b67caa
+    def get_page_size(self):
b67caa
+        return self.mock_page_size
b67caa
+
b67caa
+    def set_round(self, round):
b67caa
+        self.mock_round = round
b67caa
+
b67caa
+    def set_cursor_pos(self, pos):
b67caa
+        self.mock_cursor_pos = pos
b67caa
+
b67caa
+    def get_cursor_pos(self):
b67caa
+        return self.mock_cursor_pos
b67caa
+
b67caa
+    def get_cursor_in_page(self):
b67caa
+        return (self.mock_cursor_pos
b67caa
+                - self.mock_page_size * self.mock_page_number)
b67caa
+
b67caa
+    def set_cursor_visible(self, visible):
b67caa
+        self.mock_cursor_visible = visible
b67caa
+        self.cursor_visible = visible
b67caa
+
b67caa
+    def cursor_down(self):
b67caa
+        if len(self.mock_candidates):
b67caa
+            self.mock_cursor_pos += 1
b67caa
+            self.mock_cursor_pos %= len(self.mock_candidates)
b67caa
+
b67caa
+    def cursor_up(self):
b67caa
+        if len(self.mock_candidates):
b67caa
+            if self.mock_cursor_pos > 0:
b67caa
+                self.mock_cursor_pos -= 1
b67caa
+            else:
b67caa
+                self.mock_cursor_pos = len(self.mock_candidates) - 1
b67caa
+
b67caa
+    def page_down(self):
b67caa
+        if len(self.mock_candidates):
b67caa
+            self.mock_page_number += 1
b67caa
+            self.mock_cursor_pos += self.mock_page_size
b67caa
+
b67caa
+    def page_up(self):
b67caa
+        if len(self.mock_candidates):
b67caa
+            if self.mock_page_number > 0:
b67caa
+                self.mock_page_number -= 1
b67caa
+                self.mock_cursor_pos -= self.mock_page_size
b67caa
+
b67caa
+    def set_orientation(self, orientation):
b67caa
+        self.mock_orientation = orientation
b67caa
+
b67caa
+    def get_number_of_candidates(self):
b67caa
+        return len(self.mock_candidates)
b67caa
+
b67caa
+    def append_candidate(self, candidate):
b67caa
+        self.mock_candidates.append(candidate.get_text())
b67caa
+
b67caa
+    def get_candidate(self, index):
b67caa
+        return self.mock_candidates[index]
b67caa
+
b67caa
+    def get_number_of_candidates(self):
b67caa
+        return len(self.mock_candidates)
b67caa
+
b67caa
+    def append_label(self, label):
b67caa
+        self.mock_labels.append(label.get_text())
b67caa
+
b67caa
+class MockPropList:
b67caa
+    def __init__(self, *args, **kwargs):
b67caa
+        self._mock_proplist = []
b67caa
+
b67caa
+    def append(self, property):
b67caa
+        self._mock_proplist.append(property)
b67caa
+
b67caa
+    def get(self, index):
b67caa
+        if index >= 0 and index < len(self._mock_proplist):
b67caa
+            return self._mock_proplist[index]
b67caa
+        else:
b67caa
+            return None
b67caa
+
b67caa
+    def update_property(self, property):
b67caa
+        pass
b67caa
+
b67caa
+class MockProperty:
b67caa
+    def __init__(self,
b67caa
+                 key='',
b67caa
+                 prop_type=IBus.PropType.RADIO,
b67caa
+                 label=IBus.Text.new_from_string(''),
b67caa
+                 symbol=IBus.Text.new_from_string(''),
b67caa
+                 icon='',
b67caa
+                 tooltip=IBus.Text.new_from_string(''),
b67caa
+                 sensitive=True,
b67caa
+                 visible=True,
b67caa
+                 state=IBus.PropState.UNCHECKED,
b67caa
+                 sub_props=None):
b67caa
+        self.mock_property_key = key
b67caa
+        self.mock_property_prop_type = prop_type
b67caa
+        self.mock_property_label = label.get_text()
b67caa
+        self.mock_property_symbol = symbol.get_text()
b67caa
+        self.mock_property_icon = icon
b67caa
+        self.mock_property_tooltip = tooltip.get_text()
b67caa
+        self.mock_property_sensitive = sensitive
b67caa
+        self.mock_property_visible = visible
b67caa
+        self.mock_property_state = state
b67caa
+        self.mock_property_sub_props = sub_props
b67caa
+
b67caa
+    def set_label(self, ibus_text):
b67caa
+        self.mock_property_label = ibus_text.get_text()
b67caa
+
b67caa
+    def set_symbol(self, ibus_text):
b67caa
+        self.mock_property_symbol = ibus_text.get_text()
b67caa
+
b67caa
+    def set_tooltip(self, ibus_text):
b67caa
+        self.mock_property_tooltip = ibus_text.get_text()
b67caa
+
b67caa
+    def set_icon(self, icon_path):
b67caa
+        self.mock_property_icon = icon_path
b67caa
+
b67caa
+    def set_sensitive(self, sensitive):
b67caa
+        self.mock_property_sensitive = sensitive
b67caa
+
b67caa
+    def set_visible(self, visible):
b67caa
+        self.mock_property_visible = visible
b67caa
+
b67caa
+    def set_state(self, state):
b67caa
+        self.mock_property_state = state
b67caa
+
b67caa
+    def set_sub_props(self, proplist):
b67caa
+        self.mock_property_sub_props = proplist
b67caa
+
b67caa
+    def get_key(self):
b67caa
+        return self.mock_property_key
b67caa
diff -Nru ibus-table-1.9.18/tests/run_tests.in ibus-table-1.9.18.new/tests/run_tests.in
b67caa
--- ibus-table-1.9.18/tests/run_tests.in	2020-07-22 15:02:24.349755691 +0200
b67caa
+++ ibus-table-1.9.18.new/tests/run_tests.in	2020-07-22 15:04:42.505326247 +0200
b67caa
@@ -15,239 +15,47 @@
b67caa
 # Lesser General Public License for more details.
b67caa
 #
b67caa
 # You should have received a copy of the GNU Lesser General Public
b67caa
-# License along with this library; if not, write to the Free Software
b67caa
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
b67caa
-#
b67caa
+# License along with this library.  If not, see  <http://www.gnu.org/licenses/>
b67caa
 
b67caa
-import os
b67caa
 import sys
b67caa
+import os
b67caa
 import unittest
b67caa
 
b67caa
-from gi import require_version
b67caa
-require_version('IBus', '1.0')
b67caa
-from gi.repository import IBus
b67caa
-
b67caa
-# -- Define some mock classes for the tests ----------------------------------
b67caa
-class MockEngine:
b67caa
-    def __init__(self, engine_name = '', connection = None, object_path = ''):
b67caa
-        self.mock_auxiliary_text = ''
b67caa
-        self.mock_preedit_text = ''
b67caa
-        self.mock_preedit_text_cursor_pos = 0
b67caa
-        self.mock_preedit_text_visible = True
b67caa
-        self.mock_committed_text = ''
b67caa
-        self.mock_committed_text_cursor_pos = 0
b67caa
-        self.client_capabilities = (
b67caa
-            IBus.Capabilite.PREEDIT_TEXT
b67caa
-            | IBus.Capabilite.AUXILIARY_TEXT
b67caa
-            | IBus.Capabilite.LOOKUP_TABLE
b67caa
-            | IBus.Capabilite.FOCUS
b67caa
-            | IBus.Capabilite.PROPERTY)
b67caa
-        # There are lots of weird problems with surrounding text
b67caa
-        # which makes this hard to test. Therefore this mock
b67caa
-        # engine does not try to support surrounding text, i.e.
b67caa
-        # we omit “| IBus.Capabilite.SURROUNDING_TEXT” here.
b67caa
-
b67caa
-    def update_auxiliary_text(self, text, visible):
b67caa
-        self.mock_auxiliary_text = text.text
b67caa
-
b67caa
-    def hide_auxiliary_text(self):
b67caa
-        pass
b67caa
-
b67caa
-    def commit_text(self, text):
b67caa
-        self.mock_committed_text = (
b67caa
-            self.mock_committed_text[
b67caa
-                :self.mock_committed_text_cursor_pos]
b67caa
-            + text.text
b67caa
-            + self.mock_committed_text[
b67caa
-                self.mock_committed_text_cursor_pos:])
b67caa
-        self.mock_committed_text_cursor_pos += len(text.text)
b67caa
-
b67caa
-    def forward_key_event(self, val, code, state):
b67caa
-        if (val == IBus.KEY_Left
b67caa
-            and self.mock_committed_text_cursor_pos > 0):
b67caa
-            self.mock_committed_text_cursor_pos -= 1
b67caa
-            return
b67caa
-        unicode = IBus.keyval_to_unicode(val)
b67caa
-        if unicode:
b67caa
-            self.mock_committed_text = (
b67caa
-            self.mock_committed_text[
b67caa
-                :self.mock_committed_text_cursor_pos]
b67caa
-            + unicode
b67caa
-            + self.mock_committed_text[
b67caa
-                self.mock_committed_text_cursor_pos:])
b67caa
-            self.mock_committed_text_cursor_pos += len(unicode)
b67caa
-
b67caa
-    def update_lookup_table(self, table, visible):
b67caa
-        pass
b67caa
-
b67caa
-    def update_preedit_text(self, text, cursor_pos, visible):
b67caa
-        self.mock_preedit_text = text.get_text()
b67caa
-        self.mock_preedit_text_cursor_pos = cursor_pos
b67caa
-        self.mock_preedit_text_visible = visible
b67caa
-
b67caa
-    def register_properties(self, property_list):
b67caa
-        pass
b67caa
-
b67caa
-    def update_property(self, property):
b67caa
-        pass
b67caa
-
b67caa
-    def hide_lookup_table(self):
b67caa
-        pass
b67caa
-
b67caa
-class MockLookupTable:
b67caa
-    def __init__(self, page_size = 9, cursor_pos = 0, cursor_visible = False, round = True):
b67caa
-        self.clear()
b67caa
-        self.mock_page_size = page_size
b67caa
-        self.mock_cursor_pos = cursor_pos
b67caa
-        self.mock_cursor_visible = cursor_visible
b67caa
-        self.cursor_visible = cursor_visible
b67caa
-        self.mock_round = round
b67caa
-        self.mock_candidates = []
b67caa
-        self.mock_labels = []
b67caa
-        self.mock_page_number = 0
b67caa
-
b67caa
-    def clear(self):
b67caa
-        self.mock_candidates = []
b67caa
-        self.mock_cursor_pos = 0
b67caa
-
b67caa
-    def set_page_size(self, size):
b67caa
-        self.mock_page_size = size
b67caa
-
b67caa
-    def get_page_size(self):
b67caa
-        return self.mock_page_size
b67caa
-
b67caa
-    def set_round(self, round):
b67caa
-        self.mock_round = round
b67caa
-
b67caa
-    def set_cursor_pos(self, pos):
b67caa
-        self.mock_cursor_pos = pos
b67caa
-
b67caa
-    def get_cursor_pos(self):
b67caa
-        return self.mock_cursor_pos
b67caa
-
b67caa
-    def get_cursor_in_page(self):
b67caa
-        return (self.mock_cursor_pos
b67caa
-                - self.mock_page_size * self.mock_page_number)
b67caa
-
b67caa
-    def set_cursor_visible(self, visible):
b67caa
-        self.mock_cursor_visible = visible
b67caa
-        self.cursor_visible = visible
b67caa
-
b67caa
-    def cursor_down(self):
b67caa
-        if len(self.mock_candidates):
b67caa
-            self.mock_cursor_pos += 1
b67caa
-            self.mock_cursor_pos %= len(self.mock_candidates)
b67caa
-
b67caa
-    def cursor_up(self):
b67caa
-        if len(self.mock_candidates):
b67caa
-            if self.mock_cursor_pos > 0:
b67caa
-                self.mock_cursor_pos -= 1
b67caa
-            else:
b67caa
-                self.mock_cursor_pos = len(self.mock_candidates) - 1
b67caa
-
b67caa
-    def page_down(self):
b67caa
-        if len(self.mock_candidates):
b67caa
-            self.mock_page_number += 1
b67caa
-            self.mock_cursor_pos += self.mock_page_size
b67caa
-
b67caa
-    def page_up(self):
b67caa
-        if len(self.mock_candidates):
b67caa
-            if self.mock_page_number > 0:
b67caa
-                self.mock_page_number -= 1
b67caa
-                self.mock_cursor_pos -= self.mock_page_size
b67caa
-
b67caa
-    def set_orientation(self, orientation):
b67caa
-        self.mock_orientation = orientation
b67caa
-
b67caa
-    def get_number_of_candidates(self):
b67caa
-        return len(self.mock_candidates)
b67caa
-
b67caa
-    def append_candidate(self, candidate):
b67caa
-        self.mock_candidates.append(candidate.get_text())
b67caa
-
b67caa
-    def get_candidate(self, index):
b67caa
-        return self.mock_candidates[index]
b67caa
-
b67caa
-    def get_number_of_candidates(self):
b67caa
-        return len(self.mock_candidates)
b67caa
-
b67caa
-    def append_label(self, label):
b67caa
-        self.mock_labels.append(label.get_text())
b67caa
-
b67caa
-class MockPropList:
b67caa
-    def __init__(self, *args, **kwargs):
b67caa
-        self._mock_proplist = []
b67caa
-
b67caa
-    def append(self, property):
b67caa
-        self._mock_proplist.append(property)
b67caa
-
b67caa
-    def get(self, index):
b67caa
-        if index >= 0 and index < len(self._mock_proplist):
b67caa
-            return self._mock_proplist[index]
b67caa
-        else:
b67caa
-            return None
b67caa
-
b67caa
-    def update_property(self, property):
b67caa
-        pass
b67caa
-
b67caa
-class MockProperty:
b67caa
-    def __init__(self,
b67caa
-                 key='',
b67caa
-                 prop_type=IBus.PropType.RADIO,
b67caa
-                 label=IBus.Text.new_from_string(''),
b67caa
-                 symbol=IBus.Text.new_from_string(''),
b67caa
-                 icon='',
b67caa
-                 tooltip=IBus.Text.new_from_string(''),
b67caa
-                 sensitive=True,
b67caa
-                 visible=True,
b67caa
-                 state=IBus.PropState.UNCHECKED,
b67caa
-                 sub_props=None):
b67caa
-        self.mock_property_key = key
b67caa
-        self.mock_property_prop_type = prop_type
b67caa
-        self.mock_property_label = label.get_text()
b67caa
-        self.mock_property_symbol = symbol.get_text()
b67caa
-        self.mock_property_icon = icon
b67caa
-        self.mock_property_tooltip = tooltip.get_text()
b67caa
-        self.mock_property_sensitive = sensitive
b67caa
-        self.mock_property_visible = visible
b67caa
-        self.mock_property_state = state
b67caa
-        self.mock_property_sub_props = sub_props
b67caa
-
b67caa
-    def set_label(self, ibus_text):
b67caa
-        self.mock_property_label = ibus_text.get_text()
b67caa
-
b67caa
-    def set_symbol(self, ibus_text):
b67caa
-        self.mock_property_symbol = ibus_text.get_text()
b67caa
-
b67caa
-    def set_tooltip(self, ibus_text):
b67caa
-        self.mock_property_tooltip = ibus_text.get_text()
b67caa
-
b67caa
-    def set_sensitive(self, sensitive):
b67caa
-        self.mock_property_sensitive = sensitive
b67caa
-
b67caa
-    def set_visible(self, visible):
b67caa
-        self.mock_property_visible = visible
b67caa
-
b67caa
-    def set_state(self, state):
b67caa
-        self.mock_property_state = state
b67caa
-
b67caa
-    def set_sub_props(self, proplist):
b67caa
-        self.mock_property_sub_props = proplist
b67caa
-
b67caa
-    def get_key(self):
b67caa
-        return self.mock_property_key
b67caa
-
b67caa
-# -- Monkey patch the environment with the mock classes ----------------------
b67caa
-sys.modules["gi.repository.IBus"].Engine = MockEngine
b67caa
-sys.modules["gi.repository.IBus"].LookupTable = MockLookupTable
b67caa
-sys.modules["gi.repository.IBus"].Property = MockProperty
b67caa
-sys.modules["gi.repository.IBus"].PropList = MockPropList
b67caa
+# pip3 install tap.py --user
b67caa
+IMPORT_TAP_SUCCESSFUL = False
b67caa
+try:
b67caa
+    from tap import TAPTestRunner
b67caa
+    IMPORT_TAP_SUCCESSFUL = True
b67caa
+except (ImportError,):
b67caa
+    pass
b67caa
+
b67caa
+if 'IBUS_TABLE_LOCATION' in os.environ:
b67caa
+    location_path = os.environ['IBUS_TABLE_LOCATION']
b67caa
+    if location_path != None and location_path != '':
b67caa
+        engine_path = os.path.join(location_path, 'engine')
b67caa
+        sys.path.append(engine_path)
b67caa
+sys.path.append('@PKGDATADIR@/engine')
b67caa
 
b67caa
 # -- Load and run our unit tests ---------------------------------------------
b67caa
-os.environ['IBUS_TABLE_DEBUG_LEVEL'] = '255'
b67caa
+pattern = 'test*.py'
b67caa
+start_dir = os.path.dirname(__file__)
b67caa
+if len(sys.argv) > 1:
b67caa
+    pattern = sys.argv[-1]
b67caa
+    dir = os.path.dirname(pattern)
b67caa
+    pattern = os.path.basename(pattern)
b67caa
+    if dir != '.':
b67caa
+        start_dir = os.path.join(start_dir, dir)
b67caa
 loader = unittest.TestLoader()
b67caa
-suite = loader.discover(".")
b67caa
-runner = unittest.TextTestRunner(stream = sys.stderr, verbosity = 255)
b67caa
+suite = loader.discover(start_dir=start_dir, pattern=pattern)
b67caa
+
b67caa
+if IMPORT_TAP_SUCCESSFUL:
b67caa
+    runner = TAPTestRunner(stream=sys.stderr, verbosity=255)
b67caa
+    runner.set_outdir('.')
b67caa
+    runner.set_format('Hi: {method_name} - {short_description}')
b67caa
+    runner.set_combined(True)
b67caa
+else:
b67caa
+    runner = unittest.TextTestRunner(stream=sys.stderr, verbosity=255)
b67caa
+
b67caa
 result = runner.run(suite)
b67caa
 
b67caa
 if result.failures or result.errors:
b67caa
diff -Nru ibus-table-1.9.18/tests/test_0_gtk.py ibus-table-1.9.18.new/tests/test_0_gtk.py
b67caa
--- ibus-table-1.9.18/tests/test_0_gtk.py	1970-01-01 01:00:00.000000000 +0100
b67caa
+++ ibus-table-1.9.18.new/tests/test_0_gtk.py	2020-07-22 15:09:02.734630566 +0200
b67caa
@@ -0,0 +1,441 @@
b67caa
+#!/usr/bin/python3
b67caa
+# -*- coding: utf-8 -*-
b67caa
+#
b67caa
+# ibus-table - The Tables engine for IBus
b67caa
+#
b67caa
+# Copyright (c) 2020 Takao Fujiwara <takao.fujiwara1@gmail.com>
b67caa
+# Copyright (c) 2020 Mike FABIAN <mfabian@redhat.com>
b67caa
+#
b67caa
+# This library is free software; you can redistribute it and/or
b67caa
+# modify it under the terms of the GNU Lesser General Public
b67caa
+# License as published by the Free Software Foundation; either
b67caa
+# version 2.1 of the License, or (at your option) any later version.
b67caa
+#
b67caa
+# This library is distributed in the hope that it will be useful,
b67caa
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b67caa
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b67caa
+# Lesser General Public License for more details.
b67caa
+#
b67caa
+# You should have received a copy of the GNU Lesser General Public
b67caa
+# License along with this library.  If not, see  <http://www.gnu.org/licenses/>
b67caa
+'''
b67caa
+This file implements the test cases using GTK GUI
b67caa
+'''
b67caa
+# “Wrong continued indentation”: pylint: disable=bad-continuation
b67caa
+# pylint: disable=attribute-defined-outside-init
b67caa
+# pylint: disable=missing-function-docstring
b67caa
+# pylint: disable=missing-class-docstring
b67caa
+# pylint: disable=global-statement
b67caa
+# pylint: disable=wrong-import-order
b67caa
+# pylint: disable=wrong-import-position
b67caa
+
b67caa
+import argparse
b67caa
+import os
b67caa
+import signal
b67caa
+import sys
b67caa
+import unittest
b67caa
+
b67caa
+from gi import require_version as gi_require_version
b67caa
+gi_require_version('GLib', '2.0')
b67caa
+gi_require_version('Gdk', '3.0')
b67caa
+gi_require_version('Gio', '2.0')
b67caa
+gi_require_version('Gtk', '3.0')
b67caa
+gi_require_version('IBus', '1.0')
b67caa
+from gi.repository import GLib
b67caa
+from gi.repository import Gdk
b67caa
+from gi.repository import Gio
b67caa
+from gi.repository import Gtk
b67caa
+from gi.repository import IBus
b67caa
+
b67caa
+# Get more verbose output in the test log:
b67caa
+os.environ['IBUS_TABLE_DEBUG_LEVEL'] = '255'
b67caa
+
b67caa
+sys.path.insert(0, "../engine")
b67caa
+IMPORT_TABLE_SUCCESSFUL = False
b67caa
+try:
b67caa
+    import table
b67caa
+    IMPORT_TABLE_SUCCESSFUL = True
b67caa
+except (ImportError,):
b67caa
+    pass
b67caa
+IMPORT_TABSQLITEDB_SUCCESSFUL = False
b67caa
+try:
b67caa
+    import tabsqlitedb
b67caa
+    IMPORT_TABSQLITEDB_SUCCESSFUL = True
b67caa
+except (ImportError,):
b67caa
+    pass
b67caa
+# FIXME:
b67caa
+#sys.path.pop(0)
b67caa
+
b67caa
+DONE_EXIT = True
b67caa
+ENGINE_NAME = 'wubi-jidian86'
b67caa
+
b67caa
+from gtkcases import TestCases
b67caa
+
b67caa
+# Need to flush the output against Gtk.main()
b67caa
+def printflush(sentence):
b67caa
+    try:
b67caa
+        print(sentence, flush=True)
b67caa
+    except IOError:
b67caa
+        pass
b67caa
+
b67caa
+def printerr(sentence):
b67caa
+    try:
b67caa
+        print(sentence, flush=True, file=sys.stderr)
b67caa
+    except IOError:
b67caa
+        pass
b67caa
+
b67caa
+@unittest.skipUnless(
b67caa
+    os.path.isfile(
b67caa
+        os.path.join('/usr/share/ibus-table/tables', ENGINE_NAME + '.db')),
b67caa
+    '%s.db is not installed.' % ENGINE_NAME + '.db')
b67caa
+@unittest.skipUnless(
b67caa
+    'XDG_SESSION_TYPE' in os.environ
b67caa
+    and os.environ['XDG_SESSION_TYPE'] in ('x11', 'wayland'),
b67caa
+    'XDG_SESSION_TYPE is neither "x11" nor "wayland".')
b67caa
+@unittest.skipIf(Gdk.Display.open('') is None, 'Display cannot be opened.')
b67caa
+class SimpleGtkTestCase(unittest.TestCase):
b67caa
+    global DONE_EXIT
b67caa
+    global ENGINE_NAME
b67caa
+    ENGINE_PATH = '/com/redhat/IBus/engines/table/Test/Engine'
b67caa
+
b67caa
+    @classmethod
b67caa
+    def setUpClass(cls):
b67caa
+        cls._flag = False
b67caa
+        IBus.init()
b67caa
+        cls._gsettings = Gio.Settings(
b67caa
+            schema='org.freedesktop.ibus.engine.table',
b67caa
+            path='/org/freedesktop/ibus/engine/table/%s/' % ENGINE_NAME)
b67caa
+        cls._orig_chinesemode = cls._gsettings.get_int('chinesemode')
b67caa
+        signums = [getattr(signal, s, None) for s in
b67caa
+                   'SIGINT SIGTERM SIGHUP'.split()]
b67caa
+        for signum in filter(None, signums):
b67caa
+            original_handler = signal.getsignal(signum)
b67caa
+            GLib.unix_signal_add(GLib.PRIORITY_HIGH,
b67caa
+                                 signum,
b67caa
+                                 cls.signal_handler,
b67caa
+                                 (signum, original_handler))
b67caa
+    @classmethod
b67caa
+    def tearDownClass(cls):
b67caa
+        cls._gsettings.set_int('chinesemode', cls._orig_chinesemode)
b67caa
+
b67caa
+    @classmethod
b67caa
+    def signal_handler(cls, user_data):
b67caa
+        (signum, original_handler) = user_data
b67caa
+        cls.tearDownClass()
b67caa
+        Gtk.main_quit()
b67caa
+        signal.signal(signum, original_handler)
b67caa
+        cls._flag = True
b67caa
+        assert False, 'signal received: ' + str(signum)
b67caa
+
b67caa
+    def setUp(self):
b67caa
+        self.__id = 0
b67caa
+        self.__rerun = False
b67caa
+        self.__test_index = 0
b67caa
+        self.__preedit_index = 0
b67caa
+        self.__lookup_index = 0
b67caa
+        self.__inserted_text = ''
b67caa
+        self.__commit_done = False
b67caa
+        self.__reset_coming = False
b67caa
+        self._gsettings.set_int('chinesemode', 4)
b67caa
+
b67caa
+    def register_ibus_engine(self):
b67caa
+        self.__bus = IBus.Bus()
b67caa
+        if not self.__bus.is_connected():
b67caa
+            self.fail('ibus-daemon is not running')
b67caa
+            return False
b67caa
+        self.__bus.get_connection().signal_subscribe(
b67caa
+            'org.freedesktop.DBus',
b67caa
+            'org.freedesktop.DBus',
b67caa
+            'NameOwnerChanged',
b67caa
+            '/org/freedesktop/DBus',
b67caa
+            None,
b67caa
+            0,
b67caa
+            self.__bus_signal_cb,
b67caa
+            self.__bus)
b67caa
+        self.__factory = IBus.Factory(
b67caa
+            object_path=IBus.PATH_FACTORY,
b67caa
+            connection=self.__bus.get_connection())
b67caa
+        self.__factory.connect('create-engine', self.__create_engine_cb)
b67caa
+        self.__component = IBus.Component(
b67caa
+            name='org.freedesktop.IBus.Table.Test',
b67caa
+            description='Test Table Component',
b67caa
+            version='1.0',
b67caa
+            license='GPL',
b67caa
+            author=('Mike FABIAN <mfabian@redhat.com>, '
b67caa
+                    + 'Caius "kaio" CHANCE <caius.chance@gmail.com>'),
b67caa
+            homepage='http://mike-fabian.github.io/ibus-table/',
b67caa
+            command_line='',
b67caa
+            textdomain='ibus-table')
b67caa
+        desc = IBus.EngineDesc(
b67caa
+            name=ENGINE_NAME,
b67caa
+            longname='Test Table %s' % ENGINE_NAME,
b67caa
+            description='Test Table Component',
b67caa
+            language='t',
b67caa
+            license='GPL',
b67caa
+            author=('Mike FABIAN <mfabian@redonat.com>, '
b67caa
+                    + 'Caius "kaio" CHANCE <caius.chance@gmail.com>'),
b67caa
+            icon='',
b67caa
+            symbol='T')
b67caa
+        self.__component.add_engine(desc)
b67caa
+        self.__bus.register_component(self.__component)
b67caa
+        self.__bus.request_name('org.freedesktop.IBus.Table.Test', 0)
b67caa
+        return True
b67caa
+
b67caa
+    def __bus_signal_cb(self, connection, sender_name, object_path,
b67caa
+                        interface_name, signal_name, parameters,
b67caa
+                        user_data):
b67caa
+        if signal_name == 'NameOwnerChanged':
b67caa
+            pass
b67caa
+        if signal_name == 'UpdateLookupTable':
b67caa
+            table = self.__engine._editor.get_lookup_table()
b67caa
+            if table.get_number_of_candidates() == 0:
b67caa
+                return
b67caa
+            self.__lookup_test()
b67caa
+
b67caa
+    def __create_engine_cb(self, factory, engine_name):
b67caa
+        if engine_name != ENGINE_NAME:
b67caa
+            return None
b67caa
+        if (not IMPORT_TABLE_SUCCESSFUL
b67caa
+            or not IMPORT_TABSQLITEDB_SUCCESSFUL):
b67caa
+            with self.subTest(i='create-engine'):
b67caa
+                self.fail('NG: ibus-table not installed?')
b67caa
+            Gtk.main_quit()
b67caa
+            return None
b67caa
+        self.__id += 1
b67caa
+        object_path = '%s/%d' % (self.ENGINE_PATH, self.__id)
b67caa
+        db_dir = '/usr/share/ibus-table/tables'
b67caa
+        db_file = os.path.join(db_dir, engine_name + '.db')
b67caa
+        database = tabsqlitedb.TabSqliteDb(filename=db_file, user_db=':memory:')
b67caa
+        self.__engine = table.TabEngine(
b67caa
+            self.__bus,
b67caa
+            object_path,
b67caa
+            database)
b67caa
+        self.__engine.connect('focus-in', self.__engine_focus_in)
b67caa
+        self.__engine.connect('focus-out', self.__engine_focus_out)
b67caa
+        # FIXME: Need to connect 'reset' after TabEngine.clear_all_input_and_preedit()
b67caa
+        # is called.
b67caa
+        self.__engine.connect_after('reset', self.__engine_reset)
b67caa
+        self.__bus.get_connection().signal_subscribe(
b67caa
+            None,
b67caa
+            IBus.INTERFACE_ENGINE,
b67caa
+            'UpdateLookupTable',
b67caa
+            object_path,
b67caa
+            None,
b67caa
+            0,
b67caa
+            self.__bus_signal_cb,
b67caa
+            self.__bus)
b67caa
+        return self.__engine
b67caa
+
b67caa
+    def __engine_focus_in(self, _engine):
b67caa
+        if self.__test_index == len(TestCases['tests']):
b67caa
+            if DONE_EXIT:
b67caa
+                Gtk.main_quit()
b67caa
+            return
b67caa
+        # Workaround because focus-out resets the preedit text
b67caa
+        # ibus_bus_set_global_engine() calls bus_input_context_set_engine()
b67caa
+        # twice and it causes bus_engine_proxy_focus_out()
b67caa
+        if self.__rerun:
b67caa
+            self.__rerun = False
b67caa
+            self.__main_test()
b67caa
+
b67caa
+    def __engine_focus_out(self, _engine):
b67caa
+        self.__rerun = True
b67caa
+        self.__test_index = 0
b67caa
+        self.__entry.set_text('')
b67caa
+
b67caa
+    def __engine_reset(self, _engine):
b67caa
+        if self.__reset_coming:
b67caa
+            self.__reset_coming = False
b67caa
+            self.__main_test()
b67caa
+
b67caa
+    def __entry_focus_in_event_cb(self, entry, event):
b67caa
+        if self.__test_index == len(TestCases['tests']):
b67caa
+            if DONE_EXIT:
b67caa
+                Gtk.main_quit()
b67caa
+            return False
b67caa
+        self.__bus.set_global_engine_async(ENGINE_NAME,
b67caa
+                                           -1, None, self.__set_engine_cb)
b67caa
+        return False
b67caa
+
b67caa
+    def __set_engine_cb(self, _object, res):
b67caa
+        with self.subTest(i=self.__test_index):
b67caa
+            if not self.__bus.set_global_engine_async_finish(res):
b67caa
+                self.fail('set engine failed.')
b67caa
+            return
b67caa
+        # rerun always happen?
b67caa
+        #self.__main_test()
b67caa
+
b67caa
+    def __get_test_condition_length(self, tag):
b67caa
+        tests = TestCases['tests'][self.__test_index]
b67caa
+        try:
b67caa
+            cases = tests[tag]
b67caa
+        except KeyError:
b67caa
+            return -1
b67caa
+        case_type = list(cases.keys())[0]
b67caa
+        return len(cases[case_type])
b67caa
+
b67caa
+    def __entry_preedit_changed_cb(self, entry, preedit_str):
b67caa
+        if len(preedit_str) == 0:
b67caa
+            return
b67caa
+        if self.__test_index == len(TestCases['tests']):
b67caa
+            if DONE_EXIT:
b67caa
+                Gtk.main_quit()
b67caa
+            return
b67caa
+        self.__preedit_index += 1
b67caa
+        if self.__preedit_index != self.__get_test_condition_length('preedit'):
b67caa
+            return
b67caa
+        if self.__get_test_condition_length('lookup') > 0:
b67caa
+            return
b67caa
+        self.__run_cases('commit')
b67caa
+
b67caa
+    def __main_test(self):
b67caa
+        self.__preedit_index = 0
b67caa
+        self.__lookup_index = 0
b67caa
+        self.__commit_done = False
b67caa
+        self.__run_cases('preedit')
b67caa
+
b67caa
+    def __lookup_test(self):
b67caa
+        lookup_length = self.__get_test_condition_length('lookup')
b67caa
+        # Need to return again even if all the lookup is finished
b67caa
+        # until the final Engine.update_preedit() is called.
b67caa
+        if self.__lookup_index > lookup_length:
b67caa
+            return
b67caa
+        self.__run_cases('lookup',
b67caa
+                         self.__lookup_index,
b67caa
+                         self.__lookup_index + 1)
b67caa
+        if self.__lookup_index < lookup_length:
b67caa
+            self.__lookup_index += 1
b67caa
+            return
b67caa
+        self.__lookup_index += 1
b67caa
+        self.__run_cases('commit')
b67caa
+
b67caa
+    def __run_cases(self, tag, start=-1, end=-1):
b67caa
+        tests = TestCases['tests'][self.__test_index]
b67caa
+        if tests is None:
b67caa
+            return
b67caa
+        try:
b67caa
+            cases = tests[tag]
b67caa
+        except KeyError:
b67caa
+            return
b67caa
+        case_type = list(cases.keys())[0]
b67caa
+        i = 0
b67caa
+        if case_type == 'string':
b67caa
+            printflush('test step: %s sequences: "%s"'
b67caa
+                       % (tag, str(cases['string'])))
b67caa
+            for character in cases['string']:
b67caa
+                if start >= 0 and i < start:
b67caa
+                    i += 1
b67caa
+                    continue
b67caa
+                if 0 <= end <= i:
b67caa
+                    break
b67caa
+                self.__typing(ord(character), 0, 0)
b67caa
+                i += 1
b67caa
+        if case_type == 'keys':
b67caa
+            if start == -1 and end == -1:
b67caa
+                printflush('test step: %s sequences: %s'
b67caa
+                           % (tag, str(cases['keys'])))
b67caa
+            for key in cases['keys']:
b67caa
+                if start >= 0 and i < start:
b67caa
+                    i += 1
b67caa
+                    continue
b67caa
+                if 0 <= end <= i:
b67caa
+                    break
b67caa
+                if start != -1 or end != -1:
b67caa
+                    printflush('test step: %s sequences: [0x%X, 0x%X, 0x%X]'
b67caa
+                               % (tag, key[0], key[1], key[2]))
b67caa
+                self.__typing(key[0], key[1], key[2])
b67caa
+                i += 1
b67caa
+
b67caa
+    def __typing(self, keyval, keycode, modifiers):
b67caa
+        self.__engine.emit('process-key-event', keyval, keycode, modifiers)
b67caa
+        modifiers |= IBus.ModifierType.RELEASE_MASK
b67caa
+        self.__engine.emit('process-key-event', keyval, keycode, modifiers)
b67caa
+
b67caa
+    def __buffer_inserted_text_cb(self, buffer, position, chars, nchars):
b67caa
+        tests = TestCases['tests'][self.__test_index]
b67caa
+        cases = tests['commit']
b67caa
+        case_type = list(cases.keys())[0]
b67caa
+        if case_type == 'keys':
b67caa
+            # space key is sent separatedly later
b67caa
+            if cases['keys'][0] == [IBus.KEY_space, 0, 0]:
b67caa
+                self.__inserted_text += chars
b67caa
+            # FIXME: Return key emits 'reset' signal in GTK and it calls
b67caa
+            # TableEngine.clear_all_input_and_preedit().
b67caa
+            elif cases['keys'][0] == [IBus.KEY_Return, 0, 0] or \
b67caa
+                 cases['keys'][0] == [IBus.KEY_KP_Enter, 0, 0] or \
b67caa
+                 cases['keys'][0] == [IBus.KEY_ISO_Enter, 0, 0] or \
b67caa
+                 cases['keys'][0] == [IBus.KEY_Escape, 0, 0]:
b67caa
+                self.__inserted_text = chars
b67caa
+                self.__reset_coming = True
b67caa
+        else:
b67caa
+            self.__inserted_text = chars
b67caa
+        cases = tests['result']
b67caa
+        if cases['string'] == self.__inserted_text:
b67caa
+            printflush('OK: %d "%s"'
b67caa
+                       % (self.__test_index, self.__inserted_text))
b67caa
+        else:
b67caa
+            if DONE_EXIT:
b67caa
+                Gtk.main_quit()
b67caa
+            with self.subTest(i=self.__test_index):
b67caa
+                self.fail('NG: %d "%s" "%s"'
b67caa
+                          % (self.__test_index, str(cases['string']),
b67caa
+                             self.__inserted_text))
b67caa
+        self.__inserted_text = ''
b67caa
+        self.__test_index += 1
b67caa
+        if self.__test_index == len(TestCases['tests']):
b67caa
+            if DONE_EXIT:
b67caa
+                Gtk.main_quit()
b67caa
+            return
b67caa
+        self.__commit_done = True
b67caa
+        self.__entry.set_text('')
b67caa
+        if not self.__reset_coming:
b67caa
+            self.__main_test()
b67caa
+
b67caa
+    def create_window(self):
b67caa
+        window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
b67caa
+        self.__entry = entry = Gtk.Entry()
b67caa
+        window.connect('destroy', Gtk.main_quit)
b67caa
+        entry.connect('focus-in-event', self.__entry_focus_in_event_cb)
b67caa
+        entry.connect('preedit-changed', self.__entry_preedit_changed_cb)
b67caa
+        buffer = entry.get_buffer()
b67caa
+        buffer.connect('inserted-text', self.__buffer_inserted_text_cb)
b67caa
+        window.add(entry)
b67caa
+        window.show_all()
b67caa
+
b67caa
+    def main(self): # pylint: disable=no-self-use
b67caa
+        # Some ATK relative warnings are called during launching GtkWindow.
b67caa
+        flags = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL)
b67caa
+        Gtk.main()
b67caa
+        GLib.log_set_always_fatal(flags)
b67caa
+
b67caa
+    def test_typing(self):
b67caa
+        if not self.register_ibus_engine():
b67caa
+            sys.exit(-1)
b67caa
+        self.create_window()
b67caa
+        self.main()
b67caa
+        if self._flag:
b67caa
+            self.fail('NG: signal failure')
b67caa
+
b67caa
+def main():
b67caa
+    parser = argparse.ArgumentParser()
b67caa
+    parser.add_argument('-k', '--keep', action='store_true',
b67caa
+                        help='keep this GtkWindow after test is done')
b67caa
+    parser.add_argument('-F', '--unittest-failfast', action='store_true',
b67caa
+                        help='stop on first fail or error in unittest')
b67caa
+    parser.add_argument('-H', '--unittest-help', action='store_true',
b67caa
+                        help='show unittest help message and exit')
b67caa
+    args, unittest_args = parser.parse_known_args()
b67caa
+    sys.argv[1:] = unittest_args
b67caa
+    if args.keep:
b67caa
+        global DONE_EXIT
b67caa
+        DONE_EXIT = False
b67caa
+    if args.unittest_failfast:
b67caa
+        sys.argv.append('-f')
b67caa
+    if args.unittest_help:
b67caa
+        sys.argv.append('-h')
b67caa
+        unittest.main()
b67caa
+
b67caa
+    unittest.main()
b67caa
+
b67caa
+if __name__ == '__main__':
b67caa
+    main()
b67caa
diff -Nru ibus-table-1.9.18/tests/test_it.py ibus-table-1.9.18.new/tests/test_it.py
b67caa
--- ibus-table-1.9.18/tests/test_it.py	2020-07-22 15:02:24.350755681 +0200
b67caa
+++ ibus-table-1.9.18.new/tests/test_it.py	2020-07-22 15:05:43.128698254 +0200
b67caa
@@ -1,6 +1,5 @@
b67caa
-# -*- coding: utf-8 -*-
b67caa
-# vim:et sts=4 sw=4
b67caa
-#
b67caa
+#!/usr/bin/python3
b67caa
+
b67caa
 # ibus-table - The Tables engine for IBus
b67caa
 #
b67caa
 # Copyright (c) 2018 Mike FABIAN <mfabian@redhat.com>
b67caa
@@ -26,19 +25,41 @@
b67caa
 
b67caa
 import sys
b67caa
 import os
b67caa
-import unicodedata
b67caa
 import unittest
b67caa
-import subprocess
b67caa
+import importlib
b67caa
+import mock
b67caa
 
b67caa
 from gi import require_version
b67caa
 require_version('IBus', '1.0')
b67caa
 from gi.repository import IBus
b67caa
 
b67caa
+# Get more verbose output in the test log:
b67caa
+os.environ['IBUS_TABLE_DEBUG_LEVEL'] = '255'
b67caa
+
b67caa
+# Monkey patch the environment with the mock classes:
b67caa
+from mock_engine import MockEngine
b67caa
+from mock_engine import MockLookupTable
b67caa
+from mock_engine import MockProperty
b67caa
+from mock_engine import MockPropList
b67caa
+
b67caa
 sys.path.insert(0, "../engine")
b67caa
-from table import *
b67caa
+import table
b67caa
 import tabsqlitedb
b67caa
-import it_util
b67caa
-#sys.path.pop(0)
b67caa
+import ibus_table_location
b67caa
+sys.path.pop(0)
b67caa
+
b67caa
+ENGINE_PATCHER = mock.patch.object(
b67caa
+    IBus, 'Engine', new=MockEngine)
b67caa
+LOOKUP_TABLE_PATCHER = mock.patch.object(
b67caa
+    IBus, 'LookupTable', new=MockLookupTable)
b67caa
+PROPERTY_PATCHER = mock.patch.object(
b67caa
+    IBus, 'Property', new=MockProperty)
b67caa
+PROP_LIST_PATCHER = mock.patch.object(
b67caa
+    IBus, 'PropList', new=MockPropList)
b67caa
+IBUS_ENGINE = IBus.Engine
b67caa
+IBUS_LOOKUP_TABLE = IBus.LookupTable
b67caa
+IBUS_PROPERTY = IBus.Property
b67caa
+IBUS_PROP_LIST = IBus.PropList
b67caa
 
b67caa
 ENGINE = None
b67caa
 TABSQLITEDB = None
b67caa
@@ -56,6 +77,8 @@
b67caa
 ORIG_AUTOWILDCARD_MODE = None
b67caa
 ORIG_SINGLE_WILDCARD_CHAR = None
b67caa
 ORIG_MULTI_WILDCARD_CHAR = None
b67caa
+ORIG_PINYIN_MODE = None
b67caa
+ORIG_SUGGESTION_MODE = None
b67caa
 
b67caa
 def backup_original_settings():
b67caa
     global ENGINE
b67caa
@@ -73,6 +96,8 @@
b67caa
     global ORIG_AUTOWILDCARD_MODE
b67caa
     global ORIG_SINGLE_WILDCARD_CHAR
b67caa
     global ORIG_MULTI_WILDCARD_CHAR
b67caa
+    global ORIG_PINYIN_MODE
b67caa
+    global ORIG_SUGGESTION_MODE
b67caa
     ORIG_INPUT_MODE = ENGINE.get_input_mode()
b67caa
     ORIG_CHINESE_MODE = ENGINE.get_chinese_mode()
b67caa
     ORIG_LETTER_WIDTH = ENGINE.get_letter_width()
b67caa
@@ -87,6 +112,8 @@
b67caa
     ORIG_AUTOWILDCARD_MODE = ENGINE.get_autowildcard_mode()
b67caa
     ORIG_SINGLE_WILDCARD_CHAR = ENGINE.get_single_wildcard_char()
b67caa
     ORIG_MULTI_WILDCARD_CHAR = ENGINE.get_multi_wildcard_char()
b67caa
+    ORIG_PINYIN_MODE = ENGINE.get_pinyin_mode()
b67caa
+    ORIG_SUGGESTION_MODE = ENGINE.get_suggestion_mode()
b67caa
 
b67caa
 def restore_original_settings():
b67caa
     global ENGINE
b67caa
@@ -104,6 +131,8 @@
b67caa
     global ORIG_AUTOWILDCARD_MODE
b67caa
     global ORIG_SINGLE_WILDCARD_CHAR
b67caa
     global ORIG_MULTI_WILDCARD_CHAR
b67caa
+    global ORIG_PINYIN_MODE
b67caa
+    global ORIG_SUGGESTION_MODE
b67caa
     ENGINE.set_input_mode(ORIG_INPUT_MODE)
b67caa
     ENGINE.set_chinese_mode(ORIG_CHINESE_MODE)
b67caa
     ENGINE.set_letter_width(ORIG_LETTER_WIDTH[0], input_mode=0)
b67caa
@@ -120,14 +149,16 @@
b67caa
     ENGINE.set_autowildcard_mode(ORIG_AUTOWILDCARD_MODE)
b67caa
     ENGINE.set_single_wildcard_char(ORIG_SINGLE_WILDCARD_CHAR)
b67caa
     ENGINE.set_multi_wildcard_char(ORIG_MULTI_WILDCARD_CHAR)
b67caa
+    ENGINE.set_pinyin_mode(ORIG_PINYIN_MODE)
b67caa
+    ENGINE.set_suggestion_mode(ORIG_SUGGESTION_MODE)
b67caa
 
b67caa
 def set_default_settings():
b67caa
     global ENGINE
b67caa
     global TABSQLITEDB
b67caa
     ENGINE.set_input_mode(mode=1)
b67caa
-    chinese_mode = 0
b67caa
+    chinese_mode = 4
b67caa
     language_filter = TABSQLITEDB.ime_properties.get('language_filter')
b67caa
-    if language_filter in ['cm0', 'cm1', 'cm2', 'cm3', 'cm4']:
b67caa
+    if language_filter in ('cm0', 'cm1', 'cm2', 'cm3', 'cm4'):
b67caa
         chinese_mode = int(language_filter[-1])
b67caa
     ENGINE.set_chinese_mode(mode=chinese_mode)
b67caa
 
b67caa
@@ -136,7 +167,7 @@
b67caa
         'def_full_width_letter')
b67caa
     if def_full_width_letter:
b67caa
         letter_width_mode = (def_full_width_letter.lower() == u'true')
b67caa
-    ENGINE.set_letter_width(mode=letter_width_mode, input_mode=0)
b67caa
+    ENGINE.set_letter_width(mode=False, input_mode=0)
b67caa
     ENGINE.set_letter_width(mode=letter_width_mode, input_mode=1)
b67caa
 
b67caa
     punctuation_width_mode = False
b67caa
@@ -144,7 +175,7 @@
b67caa
         'def_full_width_punct')
b67caa
     if def_full_width_punct:
b67caa
         punctuation_width_mode = (def_full_width_punct.lower() == u'true')
b67caa
-    ENGINE.set_punctuation_width(mode=punctuation_width_mode, input_mode=0)
b67caa
+    ENGINE.set_punctuation_width(mode=False, input_mode=0)
b67caa
     ENGINE.set_punctuation_width(mode=punctuation_width_mode, input_mode=1)
b67caa
 
b67caa
     always_show_lookup_mode = True
b67caa
@@ -161,7 +192,8 @@
b67caa
     select_keys_csv = TABSQLITEDB.ime_properties.get('select_keys')
b67caa
     # select_keys_csv is something like: "1,2,3,4,5,6,7,8,9,0"
b67caa
     if select_keys_csv:
b67caa
-        ENGINE.set_page_size(len(select_keys_csv.split(",")))
b67caa
+        page_size = len(select_keys_csv.split(","))
b67caa
+    ENGINE.set_page_size(page_size)
b67caa
 
b67caa
     onechar = False
b67caa
     ENGINE.set_onechar_mode(onechar)
b67caa
@@ -223,28 +255,98 @@
b67caa
         multi_wildcard_char = multi_wildcard_char[0]
b67caa
     ENGINE.set_multi_wildcard_char(multi_wildcard_char)
b67caa
 
b67caa
+    ENGINE.set_pinyin_mode(False)
b67caa
+    ENGINE.set_suggestion_mode(False)
b67caa
+
b67caa
 def set_up(engine_name):
b67caa
+    '''
b67caa
+    Setup an ibus table engine
b67caa
+
b67caa
+    :param engine_name: The name of the engine to setup
b67caa
+    :type engine_name: String
b67caa
+    :return: True if the engine could be setup successfully, False if not.
b67caa
+    :rtype: Boolean
b67caa
+    '''
b67caa
+    global ENGINE_PATCHER
b67caa
+    global LOOKUP_TABLE_PATCHER
b67caa
+    global PROPERTY_PATCHER
b67caa
+    global PROP_LIST_PATCHER
b67caa
+    global IBUS_ENGINE
b67caa
+    global IBUS_LOOKUP_TABLE
b67caa
+    global IBUS_PROPERTY
b67caa
+    global IBUS_PROP_LIST
b67caa
     global TABSQLITEDB
b67caa
     global ENGINE
b67caa
+    ENGINE_PATCHER.start()
b67caa
+    LOOKUP_TABLE_PATCHER.start()
b67caa
+    PROPERTY_PATCHER.start()
b67caa
+    PROP_LIST_PATCHER.start()
b67caa
+    assert IBus.Engine is not IBUS_ENGINE
b67caa
+    assert IBus.Engine is MockEngine
b67caa
+    assert IBus.LookupTable is not IBUS_LOOKUP_TABLE
b67caa
+    assert IBus.LookupTable is MockLookupTable
b67caa
+    assert IBus.Property is not IBUS_PROPERTY
b67caa
+    assert IBus.Property is MockProperty
b67caa
+    assert IBus.PropList is not IBUS_PROP_LIST
b67caa
+    assert IBus.PropList is MockPropList
b67caa
+    # Reload the table module so that the patches
b67caa
+    # are applied to TabEngine:
b67caa
+    sys.path.insert(0, '../engine')
b67caa
+    importlib.reload(table)
b67caa
+    sys.path.pop(0)
b67caa
     bus = IBus.Bus()
b67caa
     db_dir = '/usr/share/ibus-table/tables'
b67caa
     db_file = os.path.join(db_dir, engine_name + '.db')
b67caa
-    TABSQLITEDB = tabsqlitedb.tabsqlitedb(
b67caa
+    if not os.path.isfile(db_file):
b67caa
+        TABSQLITEDB = None
b67caa
+        ENGINE = None
b67caa
+        tear_down()
b67caa
+        return False
b67caa
+    TABSQLITEDB = tabsqlitedb.TabSqliteDb(
b67caa
         filename=db_file, user_db=':memory:')
b67caa
-    ENGINE = tabengine(
b67caa
+    ENGINE = table.TabEngine(
b67caa
         bus,
b67caa
         '/com/redhat/IBus/engines/table/%s/engine/0' %engine_name,
b67caa
         TABSQLITEDB,
b67caa
-        unit_test = True)
b67caa
+        unit_test=True)
b67caa
     backup_original_settings()
b67caa
     set_default_settings()
b67caa
+    return True
b67caa
 
b67caa
 def tear_down():
b67caa
+    global ENGINE_PATCHER
b67caa
+    global LOOKUP_TABLE_PATCHER
b67caa
+    global PROPERTY_PATCHER
b67caa
+    global PROP_LIST_PATCHER
b67caa
+    global IBUS_ENGINE
b67caa
+    global IBUS_LOOKUP_TABLE
b67caa
+    global IBUS_PROPERTY
b67caa
+    global IBUS_PROP_LIST
b67caa
+    global TABSQLITEDB
b67caa
+    global ENGINE
b67caa
+    if ENGINE:
b67caa
         restore_original_settings()
b67caa
+        TABSQLITEDB = None
b67caa
+        ENGINE = None
b67caa
+    # Remove the patches from the IBus stuff:
b67caa
+    ENGINE_PATCHER.stop()
b67caa
+    LOOKUP_TABLE_PATCHER.stop()
b67caa
+    PROPERTY_PATCHER.stop()
b67caa
+    PROP_LIST_PATCHER.stop()
b67caa
+    assert IBus.Engine is IBUS_ENGINE
b67caa
+    assert IBus.Engine is not MockEngine
b67caa
+    assert IBus.LookupTable is IBUS_LOOKUP_TABLE
b67caa
+    assert IBus.LookupTable is not MockLookupTable
b67caa
+    assert IBus.Property is IBUS_PROPERTY
b67caa
+    assert IBus.Property is not MockProperty
b67caa
+    assert IBus.PropList is IBUS_PROP_LIST
b67caa
+    assert IBus.PropList is not MockPropList
b67caa
 
b67caa
-class Wubi_Jidian86TestCase(unittest.TestCase):
b67caa
+class WubiJidian86TestCase(unittest.TestCase):
b67caa
     def setUp(self):
b67caa
-        set_up('wubi-jidian86')
b67caa
+        engine_name = 'wubi-jidian86'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
 
b67caa
     def tearDown(self):
b67caa
         tear_down()
b67caa
@@ -257,7 +359,81 @@
b67caa
         ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
         self.assertEqual(ENGINE.mock_committed_text, '工')
b67caa
 
b67caa
-    def test_commit_to_preedit_and_switching_to_pinyin_and_defining_a_phrase(self):
b67caa
+    def test_pinyin_mode(self):
b67caa
+        # Pinyin mode is False by default:
b67caa
+        self.assertEqual(ENGINE.get_pinyin_mode(), False)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '工')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工')
b67caa
+        ENGINE.set_pinyin_mode(True)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '爱')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工爱')
b67caa
+        ENGINE.set_pinyin_mode(False)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '工')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工爱工')
b67caa
+
b67caa
+    def test_suggestion_mode(self):
b67caa
+        if not ENGINE._ime_sg:
b67caa
+            self.skipTest("This engine does not have a suggestion mode.")
b67caa
+        # Suggestion mode is False by default:
b67caa
+        self.assertEqual(ENGINE.get_suggestion_mode(), False)
b67caa
+        self.assertEqual(ENGINE.get_pinyin_mode(), False)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '工')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工')
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+        ENGINE.set_suggestion_mode(True)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '工')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工工')
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['工作人员 673 0',
b67caa
+                          '工作会议 310 0',
b67caa
+                          '工作报告 267 0',
b67caa
+                          '工人阶级 146 0',
b67caa
+                          '工作重点 78 0',
b67caa
+                          '工作小组 73 0',
b67caa
+                          '工业企业 71 0',
b67caa
+                          '工业大学 69 0',
b67caa
+                          '工作单位 61 0',
b67caa
+                          '工业生产 58 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工工作人员')
b67caa
+        ENGINE.set_pinyin_mode(True)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '爱')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工工作人员爱')
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['爱因斯坦 1109 0',
b67caa
+                          '爱情故事 519 0',
b67caa
+                          '爱国主义 191 0',
b67caa
+                          '爱尔兰语 91 0',
b67caa
+                          '爱好和平 62 0',
b67caa
+                          '爱情小说 58 0',
b67caa
+                          '爱不释手 39 0',
b67caa
+                          '爱国热情 35 0',
b67caa
+                          '爱莫能助 34 0',
b67caa
+                          '爱理不理 32 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '工工作人员爱因斯坦')
b67caa
+
b67caa
+    def test_commit_to_preedit_switching_to_pinyin_defining_a_phrase(self):
b67caa
         ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
         # commit to preëdit needs a press and release of either
b67caa
         # the left or the right shift key:
b67caa
@@ -324,7 +500,8 @@
b67caa
             IBus.KEY_Shift_L, 0,
b67caa
             IBus.ModifierType.SHIFT_MASK | IBus.ModifierType.RELEASE_MASK)
b67caa
         self.assertEqual(ENGINE.mock_preedit_text, '工了你好以在')
b67caa
-        # Move right two characters in the preëdit (triggers a commit to preëdit):
b67caa
+        # Move right two characters in the preëdit
b67caa
+        # (triggers a commit to preëdit):
b67caa
         ENGINE.do_process_key_event(IBus.KEY_Right, 0, 0)
b67caa
         ENGINE.do_process_key_event(IBus.KEY_Right, 0, 0)
b67caa
         self.assertEqual(ENGINE.mock_auxiliary_text, 'd dhf dhfd\t#: abwd')
b67caa
@@ -353,9 +530,88 @@
b67caa
         ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
         self.assertEqual(ENGINE.mock_committed_text, '工了你好以在工了你好以在')
b67caa
 
b67caa
+    def test_chinese_mode(self):
b67caa
+        ENGINE.set_chinese_mode(mode=0) # show simplified Chinese only
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_c, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['以  418261033 0',
b67caa
+                          '能 ex 1820000000 0',
b67caa
+                          '能 exx 1820000000 0',
b67caa
+                          '对 fy 1200000000 0',
b67caa
+                          '又 cc 729000000 0',
b67caa
+                          '又 ccc 729000000 0',
b67caa
+                          '通 ep 521000000 0',
b67caa
+                          '通 epk 521000000 0',
b67caa
+                          '台 kf 486000000 0',
b67caa
+                          '难忘 wyn 404000000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_BackSpace, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+        ENGINE.set_chinese_mode(mode=1) # show traditional Chinese only
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_c, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['以  418261033 0',
b67caa
+                          '能 ex 1820000000 0',
b67caa
+                          '能 exx 1820000000 0',
b67caa
+                          '又 cc 729000000 0',
b67caa
+                          '又 ccc 729000000 0',
b67caa
+                          '通 ep 521000000 0',
b67caa
+                          '通 epk 521000000 0',
b67caa
+                          '台 kf 486000000 0',
b67caa
+                          '能 e 306980312 0',
b67caa
+                          '能力 elt 274000000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_BackSpace, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+        ENGINE.set_chinese_mode(mode=2) # show simplified Chinese first
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_c, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['以  418261033 0',
b67caa
+                          '能 ex 1820000000 0',
b67caa
+                          '能 exx 1820000000 0',
b67caa
+                          '对 fy 1200000000 0',
b67caa
+                          '又 cc 729000000 0',
b67caa
+                          '又 ccc 729000000 0',
b67caa
+                          '通 ep 521000000 0',
b67caa
+                          '通 epk 521000000 0',
b67caa
+                          '台 kf 486000000 0',
b67caa
+                          '难忘 wyn 404000000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_BackSpace, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+        ENGINE.set_chinese_mode(mode=3) # show traditional Chinese first
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_c, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['以  418261033 0',
b67caa
+                          '能 ex 1820000000 0',
b67caa
+                          '能 exx 1820000000 0',
b67caa
+                          '又 cc 729000000 0',
b67caa
+                          '又 ccc 729000000 0',
b67caa
+                          '通 ep 521000000 0',
b67caa
+                          '通 epk 521000000 0',
b67caa
+                          '台 kf 486000000 0',
b67caa
+                          '能 e 306980312 0',
b67caa
+                          '能力 elt 274000000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_BackSpace, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+        ENGINE.set_chinese_mode(mode=4) # show all characters
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_c, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['以  418261033 0',
b67caa
+                          '能 ex 1820000000 0',
b67caa
+                          '能 exx 1820000000 0',
b67caa
+                          '对 fy 1200000000 0',
b67caa
+                          '又 cc 729000000 0',
b67caa
+                          '又 ccc 729000000 0',
b67caa
+                          '通 ep 521000000 0',
b67caa
+                          '通 epk 521000000 0',
b67caa
+                          '台 kf 486000000 0',
b67caa
+                          '难忘 wyn 404000000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_BackSpace, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates, [])
b67caa
+
b67caa
 class Stroke5TestCase(unittest.TestCase):
b67caa
     def setUp(self):
b67caa
-        set_up('stroke5')
b67caa
+        engine_name = 'stroke5'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
 
b67caa
     def tearDown(self):
b67caa
         tear_down()
b67caa
@@ -372,9 +628,56 @@
b67caa
         ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
         self.assertEqual(ENGINE.mock_committed_text, '的')
b67caa
 
b67caa
+class TelexTestCase(unittest.TestCase):
b67caa
+    def setUp(self):
b67caa
+        engine_name = 'telex'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
+
b67caa
+    def tearDown(self):
b67caa
+        tear_down()
b67caa
+
b67caa
+    def test_dummy(self):
b67caa
+        self.assertEqual(True, True)
b67caa
+
b67caa
+    def test_telex(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'o')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'o')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_f, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oò')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'ô')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oò')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oòô')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'ô')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oòô')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oòôô')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_o, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'ô')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oòôô')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_j, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'oòôôộ')
b67caa
+
b67caa
 class TranslitTestCase(unittest.TestCase):
b67caa
     def setUp(self):
b67caa
-        set_up('translit')
b67caa
+        engine_name ='translit'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
 
b67caa
     def tearDown(self):
b67caa
         tear_down()
b67caa
@@ -401,3 +704,215 @@
b67caa
         self.assertEqual(ENGINE.mock_preedit_text, 'с')
b67caa
         ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
         self.assertEqual(ENGINE.mock_committed_text, 'шщс ')
b67caa
+
b67caa
+    def test_sh_multiple_match_slavic(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_scaron, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'ш')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_h, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'щ')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_scaron, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, 'ш')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'щ')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_ccaron, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '')
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'щщ')
b67caa
+
b67caa
+class Cangjie5TestCase(unittest.TestCase):
b67caa
+    def setUp(self):
b67caa
+        engine_name = 'cangjie5'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
+
b67caa
+    def tearDown(self):
b67caa
+        tear_down()
b67caa
+
b67caa
+    def test_dummy(self):
b67caa
+        self.assertEqual(True, True)
b67caa
+
b67caa
+    def test_single_char_commit_with_space(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '日')
b67caa
+
b67caa
+    def test_type_one_char_and_check_auxiliary(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_d, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '木')
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates[8],
b67caa
+                         '林 木 1000 0')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_v, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_i, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_i, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_preedit_text, '機')
b67caa
+        self.assertEqual(ENGINE.mock_auxiliary_text, '木女戈戈 (1 / 1)')
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['機  1000 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '機')
b67caa
+
b67caa
+class IpaXSampaTestCase(unittest.TestCase):
b67caa
+    def setUp(self):
b67caa
+        engine_name = 'ipa-x-sampa'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
+
b67caa
+    def tearDown(self):
b67caa
+        tear_down()
b67caa
+
b67caa
+    def test_dummy(self):
b67caa
+        self.assertEqual(True, True)
b67caa
+
b67caa
+    def test_single_char_commit_with_space(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_at, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'ə ')
b67caa
+
b67caa
+    def test_single_char_commit_with_f3(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_at, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['ə  0 0', 'ɘ \\ 0 0', 'ɚ ` 0 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_F3, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'ɚ')
b67caa
+
b67caa
+class LatexTestCase(unittest.TestCase):
b67caa
+    def setUp(self):
b67caa
+        engine_name = 'latex'
b67caa
+        if not set_up(engine_name):
b67caa
+            self.skipTest('Could not setup “%s”, skipping test.' % engine_name)
b67caa
+
b67caa
+    def tearDown(self):
b67caa
+        tear_down()
b67caa
+
b67caa
+    def test_dummy(self):
b67caa
+        self.assertEqual(True, True)
b67caa
+
b67caa
+    def test_single_char_commit_with_space(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_l, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_p, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_h, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'α')
b67caa
+
b67caa
+    def test_single_char_commit_with_space_fraktur(self):
b67caa
+        # needs ibus-table-others-1.3.10 which adds
b67caa
+        # most of Unicode 9.0 block Mathematical Alphanumeric Symbols
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_m, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_t, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_h, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_f, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_r, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_a, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_k, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_F, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, '𝔉')
b67caa
+
b67caa
+    def test_single_char_commit_with_f3(self):
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_b, 0, 0)
b67caa
+        # Lookup table shows only the first page, subsequent
b67caa
+        # pages are added on demand as a speed optimization:
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['¯ ar 0 0',
b67caa
+                          '⊥ ot 0 0',
b67caa
+                          'β eta 0 0',
b67caa
+                          'ℶ eth 0 0',
b67caa
+                          '⋂ igcap 0 0',
b67caa
+                          '⋃ igcup 0 0',
b67caa
+                          '⋁ igvee 0 0',
b67caa
+                          '⋈ owtie 0 0',
b67caa
+                          '⊡ oxdot 0 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_F3, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'β')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_b, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Page_Down, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['β eta 0 1', # user freq for β increased to 1
b67caa
+                          '¯ ar 0 0',
b67caa
+                          '⊥ ot 0 0',
b67caa
+                          'ℶ eth 0 0',
b67caa
+                          '⋂ igcap 0 0',
b67caa
+                          '⋃ igcup 0 0',
b67caa
+                          '⋁ igvee 0 0',
b67caa
+                          '⋈ owtie 0 0',
b67caa
+                          '⊡ oxdot 0 0',
b67caa
+                          '• ullet 0 0',
b67caa
+                          '∙ ullet 0 0',
b67caa
+                          '≏ umpeq 0 0',
b67caa
+                          '∽ acksim 0 0',
b67caa
+                          '∵ ecause 0 0',
b67caa
+                          '≬ etween 0 0',
b67caa
+                          '⊞ oxplus 0 0',
b67caa
+                          '⊼ arwedge 0 0',
b67caa
+                          '⋀ igwedge 0 0'])
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.get_cursor_pos(), 9)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.get_cursor_pos(), 15)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates[0:18],
b67caa
+                         ['β eta 0 1', # user freq for β increased to 1
b67caa
+                          '¯ ar 0 0',
b67caa
+                          '⊥ ot 0 0',
b67caa
+                          'ℶ eth 0 0',
b67caa
+                          '⋂ igcap 0 0',
b67caa
+                          '⋃ igcup 0 0',
b67caa
+                          '⋁ igvee 0 0',
b67caa
+                          '⋈ owtie 0 0',
b67caa
+                          '⊡ oxdot 0 0',
b67caa
+                          '• ullet 0 0',
b67caa
+                          '∙ ullet 0 0',
b67caa
+                          '≏ umpeq 0 0',
b67caa
+                          '∽ acksim 0 0',
b67caa
+                          '∵ ecause 0 0',
b67caa
+                          '≬ etween 0 0',
b67caa
+                          '⊞ oxplus 0 0',
b67caa
+                          '⊼ arwedge 0 0',
b67caa
+                          '⋀ igwedge 0 0'])
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'β⊞')
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_backslash, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_b, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Page_Down, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.mock_candidates,
b67caa
+                         ['β eta 0 1', # user freq for β increased to 1
b67caa
+                          '⊞ oxplus 0 1', # user freq for ⊞ increased to 1
b67caa
+                          '¯ ar 0 0',
b67caa
+                          '⊥ ot 0 0',
b67caa
+                          'ℶ eth 0 0',
b67caa
+                          '⋂ igcap 0 0',
b67caa
+                          '⋃ igcup 0 0',
b67caa
+                          '⋁ igvee 0 0',
b67caa
+                          '⋈ owtie 0 0',
b67caa
+                          '⊡ oxdot 0 0',
b67caa
+                          '• ullet 0 0',
b67caa
+                          '∙ ullet 0 0',
b67caa
+                          '≏ umpeq 0 0',
b67caa
+                          '∽ acksim 0 0',
b67caa
+                          '∵ ecause 0 0',
b67caa
+                          '≬ etween 0 0',
b67caa
+                          '⊼ arwedge 0 0',
b67caa
+                          '⋀ igwedge 0 0'])
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.get_cursor_pos(), 9)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_Down, 0, 0)
b67caa
+        self.assertEqual(ENGINE._editor._lookup_table.get_cursor_pos(), 15)
b67caa
+        ENGINE.do_process_key_event(IBus.KEY_space, 0, 0)
b67caa
+        self.assertEqual(ENGINE.mock_committed_text, 'β⊞≬')
b67caa
+
b67caa
+if __name__ == '__main__':
b67caa
+    unittest.main()