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

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