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", OfonoGetAllOnStartup, this);
41 if (oi->properties()["Powered"].toBool() == false) {
42 oi->setProperty("Powered", qVariantFromValue(true));
45 if (oi->properties()["Online"].toBool() == false) {
46 oi->setProperty("Online", qVariantFromValue(true));
51 void testGetProperties()
53 QCOMPARE(oi->properties()["Manufacturer"].toString(), QString("MeeGo"));
55 oi_async = new OfonoInterface("/phonesim", "org.ofono.Modem", OfonoGetAllOnFirstRequest, this);
56 QCOMPARE(oi_async->properties().count(), 0);
58 QSignalSpy spy_request(oi_async, SIGNAL(requestPropertyComplete(bool, const QString &, const QVariant &)));
59 oi_async->requestProperty("Manufacturer");
60 oi_async->requestProperty("Model");
62 QCOMPARE(spy_request.count(), 1);
63 QVariantList list = spy_request.takeFirst();
64 QCOMPARE(list[0].toBool(), false);
65 QCOMPARE(list[1].toString(), QString("Model"));
66 QCOMPARE(oi_async->errorMessage(), QString("Already in progress"));
68 while (spy_request.count() != 1) {
71 list = spy_request.takeFirst();
72 QCOMPARE(list[0].toBool(), true);
73 QCOMPARE(list[1].toString(), QString("Manufacturer"));
74 QCOMPARE(list[2].value<QVariant>().toString(), QString("MeeGo"));
76 oi_async->requestProperty("Model");
77 QCOMPARE(spy_request.count(), 1);
78 list = spy_request.takeFirst();
79 QCOMPARE(list[0].toBool(), true);
80 QCOMPARE(list[1].toString(), QString("Model"));
81 QCOMPARE(list[2].value<QVariant>().toString(), QString("Synthetic Device"));
83 oi_async->requestProperty("UnknownProperty");
84 while (spy_request.count() != 1) {
87 QCOMPARE(spy_request.count(), 1);
88 list = spy_request.takeFirst();
89 QCOMPARE(list[0].toBool(), false);
90 QCOMPARE(list[1].toString(), QString("UnknownProperty"));
91 QCOMPARE(oi_async->errorMessage(), QString("Property not available"));
94 void testSetProperty()
96 QSignalSpy spy_changed(oi, SIGNAL(propertyChanged(const QString &, const QVariant &)));
97 QSignalSpy spy_failed(oi, SIGNAL(setPropertyFailed(const QString &)));
102 oi->setProperty("Online", qVariantFromValue(false));
103 while (spy_changed.count() != 3 && spy_failed.count() == 0) {
106 QCOMPARE(spy_changed.count(), 3);
107 QCOMPARE(spy_failed.count(), 0);
109 online_found = false;
110 while (spy_changed.count() > 0) {
111 list = spy_changed.takeFirst();
112 if (list[0] == "Online") {
113 online = list[1].value<QVariant>().toBool();
117 QCOMPARE(online_found, true);
118 QCOMPARE(online, false);
120 oi->setProperty("Online", qVariantFromValue(true));
121 while (spy_changed.count() < 3 && spy_failed.count() == 0) {
124 QVERIFY(spy_changed.count() > 3);
125 QCOMPARE(spy_failed.count(), 0);
127 online_found = false;
128 while (spy_changed.count() > 0) {
129 list = spy_changed.takeFirst();
130 if (list[0] == "Online") {
131 online = list[1].value<QVariant>().toBool();
135 QCOMPARE(online_found, true);
136 QCOMPARE(online, true);
140 void testSetPropertyFailed()
142 QSignalSpy spy_changed(oi, SIGNAL(propertyChanged(const QString &, const QVariant &)));
143 QSignalSpy spy_failed(oi, SIGNAL(setPropertyFailed(const QString &)));
146 oi->setProperty("Manufacturer", qVariantFromValue(QString("Nokia")));
147 while (spy_changed.count() == 0 && spy_failed.count() == 0) {
150 QCOMPARE(spy_changed.count(), 0);
151 QCOMPARE(spy_failed.count(), 1);
152 list = spy_failed.takeFirst();
153 QCOMPARE(list[0].toString(), QString("Manufacturer"));
154 QCOMPARE(oi->errorName(), QString("org.ofono.Error.InvalidArguments"));
155 QCOMPARE(oi->errorMessage(), QString("Invalid arguments in method call"));
159 void cleanupTestCase()
167 OfonoInterface *oi_async;
170 QTEST_MAIN(TestOfonoInterface)
171 #include "test_ofonointerface.moc"