~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to tests/ut_maliit_inputmethod/ut_maliit_inputmethod.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
#include <QtCore/QString>
16
 
#include <QtTest/QtTest>
17
 
#include <QApplication>
18
 
#include <QScopedPointer>
19
 
 
20
 
#include <maliit/inputmethod.h>
21
 
 
22
 
#include "gui-utils.h"
23
 
 
24
 
using Maliit::InputMethod;
25
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
26
 
using MaliitTestUtils::EventSpyInputContext;
27
 
#endif
28
 
 
29
 
namespace {
30
 
    const QRect DefaultArea;
31
 
    const QRect TestArea(QPoint(100, 100), QSize(100, 100));
32
 
 
33
 
    const Maliit::OrientationAngle DefaultAngle(Maliit::Angle0);
34
 
 
35
 
    void resetInputMethodToDefault() {
36
 
        InputMethod::instance()->setArea(DefaultArea);
37
 
        InputMethod::instance()->setOrientationAngle(DefaultAngle);
38
 
    }
39
 
}
40
 
 
41
 
class Ut_Maliit_InputMethod : public QObject
42
 
{
43
 
    Q_OBJECT
44
 
 
45
 
private Q_SLOTS:
46
 
    void initTestCase();
47
 
    void cleanupTestCase();
48
 
    void testDefaultArea();
49
 
    void testDefaultOrientationAngle();
50
 
    void testSetArea();
51
 
    void testSetArea_data();
52
 
    void testStartOrientationAngleChange();
53
 
    void testSetOrientationAngle();
54
 
    void testSetOrientationAngleSignal();
55
 
    void testSetOrientationAngleSignal_data();
56
 
    void testEmitKeyPress();
57
 
    void testEmitKeyRelease();
58
 
    void testRequestInputMethodPanel();
59
 
    void testCloseInputMethodPanel();
60
 
};
61
 
 
62
 
void Ut_Maliit_InputMethod::initTestCase()
63
 
{
64
 
}
65
 
 
66
 
void Ut_Maliit_InputMethod::cleanupTestCase()
67
 
{
68
 
}
69
 
 
70
 
void Ut_Maliit_InputMethod::testDefaultArea()
71
 
{
72
 
    QCOMPARE(InputMethod::instance()->area(), DefaultArea);
73
 
}
74
 
 
75
 
void Ut_Maliit_InputMethod::testDefaultOrientationAngle()
76
 
{
77
 
    QCOMPARE(InputMethod::instance()->orientationAngle(), DefaultAngle);
78
 
}
79
 
 
80
 
void Ut_Maliit_InputMethod::testSetArea()
81
 
{
82
 
    resetInputMethodToDefault();
83
 
    QFETCH(QRect, area);
84
 
    QFETCH(QRect, expectedArea);
85
 
    QFETCH(int, areaChangedCount);
86
 
 
87
 
    QSignalSpy areaChanged(InputMethod::instance(), SIGNAL(areaChanged(QRect)));
88
 
    InputMethod::instance()->setArea(area);
89
 
 
90
 
    QCOMPARE(InputMethod::instance()->area(), expectedArea);
91
 
    QCOMPARE(areaChanged.size(), areaChangedCount);
92
 
    if (areaChanged.size() > 0)
93
 
        QCOMPARE(areaChanged.first().at(0).toRect(), expectedArea);
94
 
}
95
 
 
96
 
void Ut_Maliit_InputMethod::testSetArea_data()
97
 
{
98
 
    QTest::addColumn<QRect>("area");
99
 
    QTest::addColumn<QRect>("expectedArea");
100
 
    QTest::addColumn<int>("areaChangedCount");
101
 
 
102
 
    QTest::newRow("change to different area") << TestArea << TestArea << 1;
103
 
    QTest::newRow("change to same area (should not Q_EMIT a signal)") << DefaultArea << DefaultArea << 0;
104
 
}
105
 
 
106
 
void Ut_Maliit_InputMethod::testStartOrientationAngleChange()
107
 
{
108
 
    resetInputMethodToDefault();
109
 
    InputMethod::instance()->startOrientationAngleChange(Maliit::Angle180);
110
 
 
111
 
    QCOMPARE(InputMethod::instance()->orientationAngle(), Maliit::Angle180);
112
 
}
113
 
 
114
 
void Ut_Maliit_InputMethod::testSetOrientationAngle()
115
 
{
116
 
    resetInputMethodToDefault();
117
 
    InputMethod::instance()->setOrientationAngle(Maliit::Angle180);
118
 
 
119
 
    QCOMPARE(InputMethod::instance()->orientationAngle(), Maliit::Angle180);
120
 
}
121
 
 
122
 
void Ut_Maliit_InputMethod::testSetOrientationAngleSignal()
123
 
{
124
 
    resetInputMethodToDefault();
125
 
    QFETCH(Maliit::OrientationAngle, startAngle);
126
 
    QFETCH(Maliit::OrientationAngle, setAngle);
127
 
    QFETCH(Maliit::OrientationAngle, expectedAngle);
128
 
    QFETCH(int, aboutToChangeCount);
129
 
    QFETCH(int, changedCount);
130
 
 
131
 
    QSignalSpy aboutToChange(InputMethod::instance(), SIGNAL(orientationAngleAboutToChange(Maliit::OrientationAngle)));
132
 
    QSignalSpy changed(InputMethod::instance(), SIGNAL(orientationAngleChanged(Maliit::OrientationAngle)));
133
 
 
134
 
    InputMethod::instance()->startOrientationAngleChange(startAngle);
135
 
    InputMethod::instance()->setOrientationAngle(setAngle);
136
 
 
137
 
    QCOMPARE(InputMethod::instance()->orientationAngle(), expectedAngle);
138
 
    QCOMPARE(aboutToChange.size(), aboutToChangeCount);
139
 
    QCOMPARE(changed.size(), changedCount);
140
 
}
141
 
 
142
 
void Ut_Maliit_InputMethod::testSetOrientationAngleSignal_data()
143
 
{
144
 
    QTest::addColumn<Maliit::OrientationAngle>("startAngle");
145
 
    QTest::addColumn<Maliit::OrientationAngle>("setAngle");
146
 
    QTest::addColumn<Maliit::OrientationAngle>("expectedAngle");
147
 
    QTest::addColumn<int>("aboutToChangeCount");
148
 
    QTest::addColumn<int>("changedCount");
149
 
 
150
 
    QTest::newRow("startAngle and setAngle to the same angle") << Maliit::Angle90 << Maliit::Angle90 << Maliit::Angle90 << 1 << 1;
151
 
    QTest::newRow("just setAngle to an angle") << DefaultAngle << Maliit::Angle90 << Maliit::Angle90 << 0 << 1;
152
 
    QTest::newRow("startAngle and setAngle to different angles") << Maliit::Angle90 << Maliit::Angle180 << Maliit::Angle180 << 1 << 1;
153
 
    QTest::newRow("startAngle and setAngle to the default angle") << DefaultAngle  << DefaultAngle  << DefaultAngle << 0 << 0;
154
 
}
155
 
 
156
 
void Ut_Maliit_InputMethod::testEmitKeyPress()
157
 
{
158
 
    const QKeyEvent eventA(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, QString::fromLatin1("a"));
159
 
    const QKeyEvent eventZ(QEvent::KeyPress, Qt::Key_Z, Qt::ShiftModifier, QString::fromLatin1("Z"));
160
 
    QSignalSpy keyPress(InputMethod::instance(), SIGNAL(keyPress(QKeyEvent)));
161
 
 
162
 
    InputMethod::instance()->emitKeyPress(eventA);
163
 
    InputMethod::instance()->emitKeyPress(eventZ);
164
 
 
165
 
    QCOMPARE(keyPress.size(), 2);
166
 
}
167
 
 
168
 
void Ut_Maliit_InputMethod::testEmitKeyRelease()
169
 
{
170
 
    const QKeyEvent eventA(QEvent::KeyRelease, Qt::Key_A, Qt::NoModifier, QString::fromLatin1("a"));
171
 
    const QKeyEvent eventZ(QEvent::KeyRelease, Qt::Key_Z, Qt::ShiftModifier, QString::fromLatin1("Z"));
172
 
    QSignalSpy keyRelease(InputMethod::instance(), SIGNAL(keyRelease(QKeyEvent)));
173
 
 
174
 
    InputMethod::instance()->emitKeyRelease(eventA);
175
 
    InputMethod::instance()->emitKeyRelease(eventZ);
176
 
 
177
 
    QCOMPARE(keyRelease.size(), 2);
178
 
}
179
 
 
180
 
void Ut_Maliit_InputMethod::testRequestInputMethodPanel()
181
 
{
182
 
    // API not available on Qt 5 anymore
183
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
184
 
    EventSpyInputContext<QEvent::Type> *spy = new EventSpyInputContext<QEvent::Type>(std::mem_fun(&QEvent::type));
185
 
    qApp->setInputContext(spy);
186
 
 
187
 
    Maliit::requestInputMethodPanel();
188
 
 
189
 
    QVERIFY(spy->size() == 1);
190
 
    QCOMPARE(spy->at(0), QEvent::RequestSoftwareInputPanel);
191
 
#endif
192
 
}
193
 
 
194
 
void Ut_Maliit_InputMethod::testCloseInputMethodPanel()
195
 
{
196
 
    // API not available on Qt 5 anymore
197
 
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
198
 
 
199
 
    EventSpyInputContext<QEvent::Type> *spy = new EventSpyInputContext<QEvent::Type>(std::mem_fun(&QEvent::type));
200
 
    qApp->setInputContext(spy);
201
 
 
202
 
    Maliit::closeInputMethodPanel();
203
 
 
204
 
    QVERIFY(spy->size() == 1);
205
 
    QCOMPARE(spy->at(0), QEvent::CloseSoftwareInputPanel);
206
 
#endif
207
 
}
208
 
 
209
 
QTEST_MAIN(Ut_Maliit_InputMethod)
210
 
 
211
 
#include "ut_maliit_inputmethod.moc"