~michael-sheldon/ubuntu/utopic/maliit-framework/fix-orientation-updates

« back to all changes in this revision

Viewing changes to tests/bbt_connection/bbt_connection.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) 2010 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 "bbt_connection.h"
16
 
#include "core-utils.h"
17
 
 
18
 
// Direct connection backend
19
 
#include <mimdirectserverconnection.h>
20
 
#include <miminputcontextdirectconnection.h>
21
 
 
22
 
// GlibDBus connection backend
23
 
#include <connectionfactory.h>
24
 
 
25
 
#include <QtCore>
26
 
#include <limits>
27
 
 
28
 
namespace {
29
 
    const char * const CONNECTION_TYPE_DIRECT = "direct: ";
30
 
    const char * const CONNECTION_TYPE_GLIB_DBUS = "glib dbus: ";
31
 
 
32
 
    /* Return a list of integers that might be worthwhile to test. */
33
 
    QList<int> getInterestingIntegers()
34
 
    {
35
 
        QList<int> interestingIntegers;
36
 
        const int minInt = std::numeric_limits<int>::min();
37
 
        const int maxInt = std::numeric_limits<int>::max();
38
 
        interestingIntegers << minInt << -1 << 0 << 1 << maxInt;
39
 
        return interestingIntegers;
40
 
    }
41
 
}
42
 
 
43
 
 
44
 
void Bbt_Connection::initTestCase()
45
 
{
46
 
    // TODO: also test CONNECTION_TYPE_GLIB_DBUS;
47
 
    mConnectionTypes << CONNECTION_TYPE_DIRECT;
48
 
}
49
 
 
50
 
void Bbt_Connection::cleanupTestCase()
51
 
{
52
 
 
53
 
}
54
 
 
55
 
void Bbt_Connection::init()
56
 
{
57
 
    // Direct connection backend
58
 
    MImInputContextDirectConnection *directIcConn = new MImInputContextDirectConnection();
59
 
    MImDirectServerConnection *directServerConn = new MImDirectServerConnection();
60
 
    directServerConn->connectTo(directIcConn);
61
 
    mIcConnections.insert(CONNECTION_TYPE_DIRECT, directIcConn);
62
 
    mServerConnections.insert(CONNECTION_TYPE_DIRECT, directServerConn);
63
 
    directServerConn->activateContext();
64
 
 
65
 
    // Glib DBus backend
66
 
    // FIXME: currently cannot be tested due to blocking call for getting the dbus address
67
 
    /*
68
 
    mIcConnections.insert(CONNECTION_TYPE_GLIB_DBUS, new MInputContextGlibDBusConnection());
69
 
    MImServerConnection *glibDbusServerConn = new GlibDBusIMServerProxy();
70
 
    mServerConnections.insert(CONNECTION_TYPE_GLIB_DBUS, glibDbusServerConn);
71
 
    glibDbusServerConn->activateContext();
72
 
    */
73
 
}
74
 
 
75
 
void Bbt_Connection::cleanup()
76
 
{
77
 
    qDeleteAll(mServerConnections);
78
 
    qDeleteAll(mIcConnections);
79
 
}
80
 
 
81
 
/* Populate QTest data.
82
 
Adds a QString "connectionType" column with the different connection types.
83
 
Used in test functions which do not want to have different input data. */
84
 
void Bbt_Connection::setupConnectionsDataVoid()
85
 
{
86
 
    QTest::addColumn<QString>("connectionType");
87
 
 
88
 
    Q_FOREACH (const QString &connType, mConnectionTypes) {
89
 
        QTest::newRow(connType.toUtf8()) << connType;
90
 
    }
91
 
}
92
 
 
93
 
/* Populate QTest data.
94
 
Adds a QString "connectionType" column with the different connection types and
95
 
a bool "enabled" column with true and false.
96
 
Used in test functions which want to test connections with boolean input data. */
97
 
void Bbt_Connection::setupConnectionsDataBool()
98
 
{
99
 
    QTest::addColumn<QString>("connectionType");
100
 
    QTest::addColumn<bool>("enabled");
101
 
 
102
 
    Q_FOREACH (const QString &connType, mConnectionTypes) {
103
 
        QTest::newRow((connType + QString("test true")).toUtf8())
104
 
                << connType << true;
105
 
        QTest::newRow((connType + QString("test false")).toUtf8())
106
 
                << connType << false;
107
 
    }
108
 
}
109
 
 
110
 
/* Return the MImServerConnection that should be used in a test.
111
 
 * A QString "connectionType" column must be provided in the QTest data. */
112
 
MImServerConnection *
113
 
Bbt_Connection::serverConnection()
114
 
{
115
 
    QFETCH(QString, connectionType);
116
 
    return mServerConnections.value(connectionType);
117
 
}
118
 
 
119
 
/* Return the MInputContextConnection that should be used in a test.
120
 
 * A QString "connectionType" column must be provided in the QTest data. */
121
 
MInputContextConnection *
122
 
Bbt_Connection::icConnection()
123
 
{
124
 
    QFETCH(QString, connectionType);
125
 
    return mIcConnections.value(connectionType);
126
 
}
127
 
 
128
 
/* Test that invokeAction() on server side reaches input context side */
129
 
void Bbt_Connection::testInvokeAction_data()
130
 
{
131
 
    setupConnectionsDataVoid();
132
 
}
133
 
void Bbt_Connection::testInvokeAction()
134
 
{
135
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(invokeAction(QString,QKeySequence)));
136
 
    icConnection()->invokeAction("copy", QKeySequence(QKeySequence::Copy));
137
 
    icConnection()->invokeAction("paste", QKeySequence(QKeySequence::Paste));
138
 
 
139
 
    MaliitTestUtils::waitAndProcessEvents(10);
140
 
 
141
 
    QCOMPARE(signalSpy.count(), 2);
142
 
}
143
 
 
144
 
/* Test that notififyImInitiatedHiding() on server side reaches input context side */
145
 
void Bbt_Connection::testImInitiatedHide_data()
146
 
{
147
 
    setupConnectionsDataVoid();
148
 
}
149
 
void Bbt_Connection::testImInitiatedHide()
150
 
{
151
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(imInitiatedHide()));
152
 
    icConnection()->notifyImInitiatedHiding();
153
 
 
154
 
    MaliitTestUtils::waitAndProcessEvents(10);
155
 
 
156
 
    QCOMPARE(signalSpy.count(), 1);
157
 
}
158
 
 
159
 
/* Test that setRedirectKeys() on server side reaches input context side */
160
 
void Bbt_Connection::testSetRedirectKeys_data()
161
 
{
162
 
    setupConnectionsDataBool();
163
 
}
164
 
void Bbt_Connection::testSetRedirectKeys()
165
 
{
166
 
    const bool enabled = true;
167
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(setRedirectKeys(bool)));
168
 
    icConnection()->setRedirectKeys(enabled);
169
 
 
170
 
    MaliitTestUtils::waitAndProcessEvents(10);
171
 
 
172
 
    QCOMPARE(signalSpy.count(), 1);
173
 
    QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
174
 
}
175
 
 
176
 
/* Test that setDetectableAutoRepeat() on server side reaches input context side */
177
 
void Bbt_Connection::testSetDetectableAutoRepeat_data()
178
 
{
179
 
    setupConnectionsDataBool();
180
 
}
181
 
void Bbt_Connection::testSetDetectableAutoRepeat()
182
 
{
183
 
    const bool enabled = true;
184
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(setDetectableAutoRepeat(bool)));
185
 
    icConnection()->setDetectableAutoRepeat(enabled);
186
 
 
187
 
    MaliitTestUtils::waitAndProcessEvents(10);
188
 
 
189
 
    QCOMPARE(signalSpy.count(), 1);
190
 
    QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
191
 
}
192
 
 
193
 
/* Test that setDetectableAutoRepeat() on server side reaches input context side */
194
 
void Bbt_Connection::testSetGlobalCorrectionEnabled_data()
195
 
{
196
 
    setupConnectionsDataBool();
197
 
}
198
 
void Bbt_Connection::testSetGlobalCorrectionEnabled()
199
 
{
200
 
    QFETCH(bool, enabled);
201
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(setGlobalCorrectionEnabled(bool)));
202
 
    icConnection()->setGlobalCorrectionEnabled(enabled);
203
 
 
204
 
    MaliitTestUtils::waitAndProcessEvents(10);
205
 
 
206
 
    QCOMPARE(signalSpy.count(), 1);
207
 
    QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
208
 
}
209
 
 
210
 
/* Test that setSelection(int start, int length); */
211
 
void Bbt_Connection::testSetSelection_data()
212
 
{
213
 
    QTest::addColumn<QString>("connectionType");
214
 
    QTest::addColumn<int>("start");
215
 
    QTest::addColumn<int>("length");
216
 
 
217
 
    /* Test some different data for each parameter for each of the connections. */
218
 
    Q_FOREACH (const QString &connType, mConnectionTypes) {
219
 
 
220
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
221
 
            QTest::newRow((connType + QString("start=") + QString::number(integer)).toUtf8())
222
 
                    << connType << integer << 0;
223
 
        }
224
 
 
225
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
226
 
            QTest::newRow((connType + QString("length=") + QString::number(integer)).toUtf8())
227
 
                    << connType << 0 << integer;
228
 
        }
229
 
    }
230
 
}
231
 
void Bbt_Connection::testSetSelection()
232
 
{
233
 
    QFETCH(int, start);
234
 
    QFETCH(int, length);
235
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(setSelection(int,int)));
236
 
    icConnection()->setSelection(start, length);
237
 
 
238
 
    MaliitTestUtils::waitAndProcessEvents(10);
239
 
 
240
 
    QCOMPARE(signalSpy.count(), 1);
241
 
    QCOMPARE(signalSpy.first().at(0).toInt(), start);
242
 
    QCOMPARE(signalSpy.first().at(1).toInt(), length);
243
 
}
244
 
 
245
 
 
246
 
/* Tests that sendCommitString on server side reaches input context side. */
247
 
void Bbt_Connection::testCommitString_data()
248
 
{
249
 
    QTest::addColumn<QString>("connectionType");
250
 
    QTest::addColumn<QString>("commitString");
251
 
    QTest::addColumn<int>("replaceStart");
252
 
    QTest::addColumn<int>("replaceLength");
253
 
    QTest::addColumn<int>("cursorPos");
254
 
 
255
 
    /* Test some different data for each parameter for each of the connections. */
256
 
    Q_FOREACH (const QString &connType, mConnectionTypes) {
257
 
 
258
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
259
 
            QTest::newRow((connType + QString("replaceStart=") + QString::number(integer)).toUtf8())
260
 
                    << connType << QString("") << integer << 0 << 0;
261
 
        }
262
 
 
263
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
264
 
            QTest::newRow((connType + QString("replaceStart=") + QString::number(integer)).toUtf8())
265
 
                    << connType << QString("") << integer << 0 << 0;
266
 
        }
267
 
 
268
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
269
 
            QTest::newRow((connType + QString("replaceEnd=") + QString::number(integer)).toUtf8())
270
 
                    << connType << QString("") << 0 << integer << 0;
271
 
        }
272
 
 
273
 
        Q_FOREACH (int integer, getInterestingIntegers()) {
274
 
            QTest::newRow((connType + QString("cursorPos=") + QString::number(integer)).toUtf8())
275
 
                    << connType << QString("") << 0 << 0 << integer;
276
 
        }
277
 
    }
278
 
}
279
 
void Bbt_Connection::testCommitString()
280
 
{
281
 
    QFETCH(QString, commitString);
282
 
    QFETCH(int, replaceStart);
283
 
    QFETCH(int, replaceLength);
284
 
    QFETCH(int, cursorPos);
285
 
 
286
 
    QSignalSpy signalSpy(serverConnection(), SIGNAL(commitString(QString,int,int,int)));
287
 
 
288
 
    icConnection()->sendCommitString(commitString, replaceStart, replaceLength, cursorPos);
289
 
 
290
 
    MaliitTestUtils::waitAndProcessEvents(10);
291
 
 
292
 
    QCOMPARE(signalSpy.count(), 1);
293
 
    QCOMPARE(signalSpy.first().at(0).toString(), commitString);
294
 
    QCOMPARE(signalSpy.first().at(1).toInt(), replaceStart);
295
 
    QCOMPARE(signalSpy.first().at(2).toInt(), replaceLength);
296
 
    QCOMPARE(signalSpy.first().at(3).toInt(), cursorPos);
297
 
}
298
 
 
299
 
QTEST_MAIN(Bbt_Connection)