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

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