2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
27 #include <ofonointerface.h>
31 class TestOfonoInterface : public QObject
39 oi = new OfonoInterface("/phonesim", "org.ofono.Modem", OfonoInterface::GetAllOnStartup, this);
40 oi_async = new OfonoInterface("/phonesim", "org.ofono.Modem", OfonoInterface::GetAllOnFirstRequest, this);
44 void testGetProperties()
46 QCOMPARE(oi->properties()["Manufacturer"].toString(), QString("MeeGo"));
48 QCOMPARE(oi_async->properties().count(), 0);
50 QSignalSpy spy_request(oi_async, SIGNAL(requestPropertyComplete(bool, const QString &, const QVariant &)));
51 oi_async->requestProperty("Manufacturer");
52 oi_async->requestProperty("Model");
54 QCOMPARE(spy_request.count(), 1);
55 QVariantList list = spy_request.takeFirst();
56 QCOMPARE(list[0].toBool(), false);
57 QCOMPARE(list[1].toString(), QString("Model"));
58 QCOMPARE(oi_async->errorMessage(), QString("Already in progress"));
60 while (spy_request.count() != 1) {
63 list = spy_request.takeFirst();
64 QCOMPARE(list[0].toBool(), true);
65 QCOMPARE(list[1].toString(), QString("Manufacturer"));
66 QCOMPARE(list[2].value<QVariant>().toString(), QString("MeeGo"));
68 oi_async->requestProperty("Model");
69 QCOMPARE(spy_request.count(), 1);
70 list = spy_request.takeFirst();
71 QCOMPARE(list[0].toBool(), true);
72 QCOMPARE(list[1].toString(), QString("Model"));
73 QCOMPARE(list[2].value<QVariant>().toString(), QString("Synthetic Device"));
75 oi_async->requestProperty("UnknownProperty");
76 while (spy_request.count() != 1) {
79 QCOMPARE(spy_request.count(), 1);
80 list = spy_request.takeFirst();
81 QCOMPARE(list[0].toBool(), false);
82 QCOMPARE(list[1].toString(), QString("UnknownProperty"));
83 QCOMPARE(oi_async->errorMessage(), QString("Property not available"));
86 void testSetProperty()
88 QSignalSpy spy_changed(oi, SIGNAL(propertyChanged(const QString &, const QVariant &)));
89 QSignalSpy spy_failed(oi, SIGNAL(setPropertyFailed(const QString &)));
94 oi->setProperty("Online", qVariantFromValue(false));
95 while (spy_changed.count() != 3 && spy_failed.count() == 0) {
98 QCOMPARE(spy_changed.count(), 3);
99 QCOMPARE(spy_failed.count(), 0);
101 online_found = false;
102 while (spy_changed.count() > 0) {
103 list = spy_changed.takeFirst();
104 if (list[0] == "Online") {
105 online = list[1].value<QVariant>().toBool();
109 QCOMPARE(online_found, true);
110 QCOMPARE(online, false);
112 oi->setProperty("Online", qVariantFromValue(true));
113 while (spy_changed.count() < 3 && spy_failed.count() == 0) {
116 QVERIFY(spy_changed.count() > 3);
117 QCOMPARE(spy_failed.count(), 0);
119 online_found = false;
120 while (spy_changed.count() > 0) {
121 list = spy_changed.takeFirst();
122 if (list[0] == "Online") {
123 online = list[1].value<QVariant>().toBool();
127 QCOMPARE(online_found, true);
128 QCOMPARE(online, true);
132 void testSetPropertyFailed()
134 QSignalSpy spy_changed(oi, SIGNAL(propertyChanged(const QString &, const QVariant &)));
135 QSignalSpy spy_failed(oi, SIGNAL(setPropertyFailed(const QString &)));
138 oi->setProperty("Manufacturer", qVariantFromValue(QString("Nokia")));
139 while (spy_changed.count() == 0 && spy_failed.count() == 0) {
142 QCOMPARE(spy_changed.count(), 0);
143 QCOMPARE(spy_failed.count(), 1);
144 list = spy_failed.takeFirst();
145 QCOMPARE(list[0].toString(), QString("Manufacturer"));
146 QCOMPARE(oi->errorName(), QString("org.ofono.Error.InvalidArguments"));
147 QCOMPARE(oi->errorMessage(), QString("Invalid arguments in method call"));
151 void cleanupTestCase()
159 OfonoInterface *oi_async;
162 QTEST_MAIN(TestOfonoInterface)
163 #include "test_ofonointerface.moc"