1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
3
# Author: Thomi Richards, Martin Mrazik
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
"Tests to ensure unity is compatible with ibus input method."
11
from autopilot.emulators.ibus import (
13
get_available_input_engines,
15
from autopilot.emulators.unity.dash import Dash
16
from autopilot.emulators.X11 import Keyboard
17
from autopilot.tests import AutopilotTestCase
19
from time import sleep
21
class IBusTests(AutopilotTestCase):
22
"""Base class for IBus tests."""
25
super(IBusTests, self).setUp()
28
self._old_engines = None
31
if self._old_engines is not None:
32
set_active_engines(self._old_engines)
33
super(IBusTests, self).tearDown()
35
def activate_input_engine_or_skip(self, engine_name):
36
available_engines = get_available_input_engines()
37
if engine_name in available_engines:
38
self._old_engines = set_active_engines([engine_name])
40
self.skipTest("This test requires the '%s' engine to be installed." % (engine_name))
42
def activate_ibus(self):
43
# it would be nice to be able to tell if it's currently active or not.
44
self.kb.press_and_release('Ctrl+Space')
46
def deactivate_ibus(self):
47
# it would be nice to be able to tell if it's currently active or not.
48
self.kb.press_and_release('Ctrl+Space')
51
class IBusTestsPinyin(IBusTests):
52
"""Tests for the Pinyin(Chinese) input engine."""
55
('basic', {'input': 'abc1', 'result': u'\u963f\u5e03\u4ece'}),
56
('photo', {'input': 'zhaopian ', 'result': u'\u7167\u7247'}),
57
('internet', {'input': 'hulianwang ', 'result': u'\u4e92\u8054\u7f51'}),
58
('disk', {'input': 'cipan ', 'result': u'\u78c1\u76d8'}),
59
('disk_management', {'input': 'cipan guanli ', 'result': u'\u78c1\u76d8\u7ba1\u7406'}),
62
def test_simple_input(self):
63
self.activate_input_engine_or_skip("pinyin")
64
self.dash.ensure_visible()
68
self.kb.type(self.input)
69
dash_search_string = self.dash.get_searchbar().search_string
70
self.deactivate_ibus()
71
self.dash.ensure_hidden()
73
self.assertEqual(self.result, dash_search_string)
76
class IBusTestsHangul(IBusTests):
77
"""Tests for the Hangul(Korean) input engine."""
80
('transmission', {'input': 'xmfostmaltus ', 'result': u'\ud2b8\ub79c\uc2a4\ubbf8\uc158 '}),
81
('social', {'input': 'httuf ', 'result': u'\uc18c\uc15c '}),
82
('document', {'input': 'anstj ', 'result': u'\ubb38\uc11c '}),
85
def test_simple_input(self):
86
self.activate_input_engine_or_skip("hangul")
87
self.dash.ensure_visible()
91
self.kb.type(self.input)
92
dash_search_string = self.dash.get_searchbar().search_string
93
self.deactivate_ibus()
94
self.dash.ensure_hidden()
96
self.assertEqual(self.result, dash_search_string)
99
class IBusTestsAnthy(IBusTests):
100
"""Tests for the Anthy(Japanese) input engine."""
103
('system', {'input': 'shisutemu ', 'result': u'\u30b7\u30b9\u30c6\u30e0'}),
104
('game', {'input': 'ge-mu ', 'result': u'\u30b2\u30fc\u30e0'}),
105
('user', {'input': 'yu-za- ', 'result': u'\u30e6\u30fc\u30b6\u30fc'}),
108
def test_simple_input(self):
109
self.activate_input_engine_or_skip("anthy")
110
self.dash.ensure_visible()
114
self.kb.type(self.input)
115
self.kb.press_and_release("Ctrl+j")
116
dash_search_string = self.dash.get_searchbar().search_string
117
self.deactivate_ibus()
118
self.dash.ensure_hidden()
120
self.assertEqual(self.result, dash_search_string)