1
/* * This file is part of Maliit framework *
3
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: maliit-discuss@lists.maliit.org
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
15
#include "bbt_connection.h"
16
#include "core-utils.h"
18
// Direct connection backend
19
#include <mimdirectserverconnection.h>
20
#include <miminputcontextdirectconnection.h>
22
// GlibDBus connection backend
23
#include <connectionfactory.h>
29
const char * const CONNECTION_TYPE_DIRECT = "direct: ";
30
const char * const CONNECTION_TYPE_GLIB_DBUS = "glib dbus: ";
32
/* Return a list of integers that might be worthwhile to test. */
33
QList<int> getInterestingIntegers()
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;
44
void Bbt_Connection::initTestCase()
46
// TODO: also test CONNECTION_TYPE_GLIB_DBUS;
47
mConnectionTypes << CONNECTION_TYPE_DIRECT;
50
void Bbt_Connection::cleanupTestCase()
55
void Bbt_Connection::init()
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();
66
// FIXME: currently cannot be tested due to blocking call for getting the dbus address
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();
75
void Bbt_Connection::cleanup()
77
qDeleteAll(mServerConnections);
78
qDeleteAll(mIcConnections);
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()
86
QTest::addColumn<QString>("connectionType");
88
Q_FOREACH (const QString &connType, mConnectionTypes) {
89
QTest::newRow(connType.toUtf8()) << connType;
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()
99
QTest::addColumn<QString>("connectionType");
100
QTest::addColumn<bool>("enabled");
102
Q_FOREACH (const QString &connType, mConnectionTypes) {
103
QTest::newRow((connType + QString("test true")).toUtf8())
105
QTest::newRow((connType + QString("test false")).toUtf8())
106
<< connType << false;
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()
115
QFETCH(QString, connectionType);
116
return mServerConnections.value(connectionType);
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()
124
QFETCH(QString, connectionType);
125
return mIcConnections.value(connectionType);
128
/* Test that invokeAction() on server side reaches input context side */
129
void Bbt_Connection::testInvokeAction_data()
131
setupConnectionsDataVoid();
133
void Bbt_Connection::testInvokeAction()
135
QSignalSpy signalSpy(serverConnection(), SIGNAL(invokeAction(QString,QKeySequence)));
136
icConnection()->invokeAction("copy", QKeySequence(QKeySequence::Copy));
137
icConnection()->invokeAction("paste", QKeySequence(QKeySequence::Paste));
139
MaliitTestUtils::waitAndProcessEvents(10);
141
QCOMPARE(signalSpy.count(), 2);
144
/* Test that notififyImInitiatedHiding() on server side reaches input context side */
145
void Bbt_Connection::testImInitiatedHide_data()
147
setupConnectionsDataVoid();
149
void Bbt_Connection::testImInitiatedHide()
151
QSignalSpy signalSpy(serverConnection(), SIGNAL(imInitiatedHide()));
152
icConnection()->notifyImInitiatedHiding();
154
MaliitTestUtils::waitAndProcessEvents(10);
156
QCOMPARE(signalSpy.count(), 1);
159
/* Test that setRedirectKeys() on server side reaches input context side */
160
void Bbt_Connection::testSetRedirectKeys_data()
162
setupConnectionsDataBool();
164
void Bbt_Connection::testSetRedirectKeys()
166
const bool enabled = true;
167
QSignalSpy signalSpy(serverConnection(), SIGNAL(setRedirectKeys(bool)));
168
icConnection()->setRedirectKeys(enabled);
170
MaliitTestUtils::waitAndProcessEvents(10);
172
QCOMPARE(signalSpy.count(), 1);
173
QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
176
/* Test that setDetectableAutoRepeat() on server side reaches input context side */
177
void Bbt_Connection::testSetDetectableAutoRepeat_data()
179
setupConnectionsDataBool();
181
void Bbt_Connection::testSetDetectableAutoRepeat()
183
const bool enabled = true;
184
QSignalSpy signalSpy(serverConnection(), SIGNAL(setDetectableAutoRepeat(bool)));
185
icConnection()->setDetectableAutoRepeat(enabled);
187
MaliitTestUtils::waitAndProcessEvents(10);
189
QCOMPARE(signalSpy.count(), 1);
190
QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
193
/* Test that setDetectableAutoRepeat() on server side reaches input context side */
194
void Bbt_Connection::testSetGlobalCorrectionEnabled_data()
196
setupConnectionsDataBool();
198
void Bbt_Connection::testSetGlobalCorrectionEnabled()
200
QFETCH(bool, enabled);
201
QSignalSpy signalSpy(serverConnection(), SIGNAL(setGlobalCorrectionEnabled(bool)));
202
icConnection()->setGlobalCorrectionEnabled(enabled);
204
MaliitTestUtils::waitAndProcessEvents(10);
206
QCOMPARE(signalSpy.count(), 1);
207
QCOMPARE(signalSpy.first().at(0).toBool(), enabled);
210
/* Test that setSelection(int start, int length); */
211
void Bbt_Connection::testSetSelection_data()
213
QTest::addColumn<QString>("connectionType");
214
QTest::addColumn<int>("start");
215
QTest::addColumn<int>("length");
217
/* Test some different data for each parameter for each of the connections. */
218
Q_FOREACH (const QString &connType, mConnectionTypes) {
220
Q_FOREACH (int integer, getInterestingIntegers()) {
221
QTest::newRow((connType + QString("start=") + QString::number(integer)).toUtf8())
222
<< connType << integer << 0;
225
Q_FOREACH (int integer, getInterestingIntegers()) {
226
QTest::newRow((connType + QString("length=") + QString::number(integer)).toUtf8())
227
<< connType << 0 << integer;
231
void Bbt_Connection::testSetSelection()
235
QSignalSpy signalSpy(serverConnection(), SIGNAL(setSelection(int,int)));
236
icConnection()->setSelection(start, length);
238
MaliitTestUtils::waitAndProcessEvents(10);
240
QCOMPARE(signalSpy.count(), 1);
241
QCOMPARE(signalSpy.first().at(0).toInt(), start);
242
QCOMPARE(signalSpy.first().at(1).toInt(), length);
246
/* Tests that sendCommitString on server side reaches input context side. */
247
void Bbt_Connection::testCommitString_data()
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");
255
/* Test some different data for each parameter for each of the connections. */
256
Q_FOREACH (const QString &connType, mConnectionTypes) {
258
Q_FOREACH (int integer, getInterestingIntegers()) {
259
QTest::newRow((connType + QString("replaceStart=") + QString::number(integer)).toUtf8())
260
<< connType << QString("") << integer << 0 << 0;
263
Q_FOREACH (int integer, getInterestingIntegers()) {
264
QTest::newRow((connType + QString("replaceStart=") + QString::number(integer)).toUtf8())
265
<< connType << QString("") << integer << 0 << 0;
268
Q_FOREACH (int integer, getInterestingIntegers()) {
269
QTest::newRow((connType + QString("replaceEnd=") + QString::number(integer)).toUtf8())
270
<< connType << QString("") << 0 << integer << 0;
273
Q_FOREACH (int integer, getInterestingIntegers()) {
274
QTest::newRow((connType + QString("cursorPos=") + QString::number(integer)).toUtf8())
275
<< connType << QString("") << 0 << 0 << integer;
279
void Bbt_Connection::testCommitString()
281
QFETCH(QString, commitString);
282
QFETCH(int, replaceStart);
283
QFETCH(int, replaceLength);
284
QFETCH(int, cursorPos);
286
QSignalSpy signalSpy(serverConnection(), SIGNAL(commitString(QString,int,int,int)));
288
icConnection()->sendCommitString(commitString, replaceStart, replaceLength, cursorPos);
290
MaliitTestUtils::waitAndProcessEvents(10);
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);
299
QTEST_MAIN(Bbt_Connection)