~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/tests/test_ibus.py

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2012 Canonical
 
3
# Author: Thomi Richards, Martin Mrazik
 
4
#
 
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.
 
8
 
 
9
"Tests to ensure unity is compatible with ibus input method."
 
10
 
 
11
from autopilot.emulators.ibus import (
 
12
    set_active_engines,
 
13
    get_available_input_engines,
 
14
    )
 
15
from autopilot.emulators.unity.dash import Dash
 
16
from autopilot.emulators.X11 import Keyboard
 
17
from autopilot.tests import AutopilotTestCase
 
18
 
 
19
from time import sleep
 
20
 
 
21
class IBusTests(AutopilotTestCase):
 
22
    """Base class for IBus tests."""
 
23
 
 
24
    def setUp(self):
 
25
        super(IBusTests, self).setUp()
 
26
        self.kb = Keyboard()
 
27
        self.dash = Dash()
 
28
        self._old_engines = None
 
29
 
 
30
    def tearDown(self):
 
31
        if self._old_engines is not None:
 
32
            set_active_engines(self._old_engines)
 
33
        super(IBusTests, self).tearDown()
 
34
 
 
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])
 
39
        else:
 
40
            self.skipTest("This test requires the '%s' engine to be installed." % (engine_name))
 
41
 
 
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')
 
45
 
 
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')
 
49
 
 
50
 
 
51
class IBusTestsPinyin(IBusTests):
 
52
    """Tests for the Pinyin(Chinese) input engine."""
 
53
 
 
54
    scenarios = [
 
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'}),
 
60
    ]
 
61
 
 
62
    def test_simple_input(self):
 
63
        self.activate_input_engine_or_skip("pinyin")
 
64
        self.dash.ensure_visible()
 
65
        sleep(0.5)
 
66
        self.activate_ibus()
 
67
        sleep(0.5)
 
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()
 
72
 
 
73
        self.assertEqual(self.result, dash_search_string)
 
74
 
 
75
 
 
76
class IBusTestsHangul(IBusTests):
 
77
    """Tests for the Hangul(Korean) input engine."""
 
78
 
 
79
    scenarios = [
 
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 '}),
 
83
        ]
 
84
 
 
85
    def test_simple_input(self):
 
86
        self.activate_input_engine_or_skip("hangul")
 
87
        self.dash.ensure_visible()
 
88
        sleep(0.5)
 
89
        self.activate_ibus()
 
90
        sleep(0.5)
 
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()
 
95
 
 
96
        self.assertEqual(self.result, dash_search_string)
 
97
 
 
98
 
 
99
class IBusTestsAnthy(IBusTests):
 
100
    """Tests for the Anthy(Japanese) input engine."""
 
101
 
 
102
    scenarios = [
 
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'}),
 
106
        ]
 
107
 
 
108
    def test_simple_input(self):
 
109
        self.activate_input_engine_or_skip("anthy")
 
110
        self.dash.ensure_visible()
 
111
        sleep(0.5)
 
112
        self.activate_ibus()
 
113
        sleep(0.5)
 
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()
 
119
 
 
120
        self.assertEqual(self.result, dash_search_string)