2 * This file is part of ofono-qt
4 * Copyright (C) 2010-2011 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>
26 #include <QDBusObjectPath>
28 #include <ofonomessagemanager.h>
29 #include <ofonomessage.h>
34 class TestOfonoMessageManager : public QObject
42 m = new OfonoMessageManager(OfonoModem::ManualSelect, "/phonesim", this);
43 QCOMPARE(m->modem()->isValid(), true);
45 if (!m->modem()->powered()) {
46 m->modem()->setPowered(true);
49 if (!m->modem()->online()) {
50 m->modem()->setOnline(true);
53 QCOMPARE(m->isValid(), true);
56 void testOfonoMessageManager()
58 QSignalSpy sendMessage(m, SIGNAL(sendMessageComplete(bool, QDBusObjectPath)));
59 QSignalSpy messageAdded(m, SIGNAL(messageAdded(QString)));
60 QSignalSpy messageRemoved(m, SIGNAL(messageRemoved(QString)));
61 QSignalSpy immediateMessage(m, SIGNAL(immediateMessage(QString, QVariantMap)));
62 QSignalSpy incomingMessage(m, SIGNAL(incomingMessage(QString, QVariantMap)));
65 QStringList messages = m->getMessages();
66 QVERIFY(messages.count() == 0);
68 m->sendMessage("99999", "success");
72 QCOMPARE(sendMessage.count(), 1);
73 QVariantList params = sendMessage.takeFirst();
74 QCOMPARE(params.at(0).toBool(), true);
75 QDBusObjectPath objectPath = params.at(1).value<QDBusObjectPath>();
76 QVERIFY(objectPath.path().length() > 0);
77 qDebug() << objectPath.path();
79 QCOMPARE(messageAdded.count(), 1);
80 QCOMPARE(messageRemoved.count(), 1);
82 QString messageId = messageAdded.takeFirst().at(0).toString();
83 OfonoMessage* message = new OfonoMessage(messageId);
84 QSignalSpy state(message, SIGNAL(stateChanged(const QString)));
85 qDebug() << message->state();
87 m->sendMessage("abc", "fail");
91 QCOMPARE(sendMessage.count(), 1);
92 params = sendMessage.takeFirst();
93 QCOMPARE(params.at(0).toBool(), false);
94 objectPath = params.at(1).value<QDBusObjectPath>();
95 QVERIFY(objectPath.path().length() == 0);
98 void testOfonoMessageManagerSca()
100 QSignalSpy scaComplete(m, SIGNAL(serviceCenterAddressComplete(bool, QString)));
101 m->requestServiceCenterAddress();
102 for (int i=0; i<30; i++) {
103 if (scaComplete.count() > 0)
107 QCOMPARE(scaComplete.count(), 1);
108 QVariantList params = scaComplete.takeFirst();
109 QCOMPARE(params.at(0).toBool(), true);
110 QString sca = params.at(1).toString();
111 QVERIFY(sca.length() > 0);
114 QSignalSpy setScaFailed(m, SIGNAL(setServiceCenterAddressFailed()));
115 QSignalSpy scaChanged(m, SIGNAL(serviceCenterAddressChanged(QString)));
117 m->setServiceCenterAddress("+12345678");
118 for (int i=0; i<30; i++) {
119 if (setScaFailed.count() > 0 || scaChanged.count() > 0)
123 QCOMPARE(setScaFailed.count(), 0);
124 QCOMPARE(scaChanged.count(), 1);
125 QCOMPARE(scaChanged.takeFirst().at(0).toString(), QString("+12345678"));
127 m->setServiceCenterAddress("");
128 for (int i=0; i<30; i++) {
129 if (setScaFailed.count() > 0 || scaChanged.count() > 0)
133 QCOMPARE(setScaFailed.count(), 1);
134 setScaFailed.takeFirst();
135 QCOMPARE(scaChanged.count(), 0);
136 QCOMPARE(m->errorName(), QString("org.ofono.Error.InvalidFormat"));
137 QCOMPARE(m->errorMessage(), QString("Argument format is not recognized"));
139 m->setServiceCenterAddress(sca);
140 for (int i=0; i<30; i++) {
141 if (setScaFailed.count() > 0 || scaChanged.count() > 0)
145 QCOMPARE(setScaFailed.count(), 0);
146 QCOMPARE(scaChanged.count(), 1);
147 QCOMPARE(scaChanged.takeFirst().at(0).toString(), sca);
150 void testOfonoMessageManagerUseDeliveryReports()
152 QSignalSpy useDeliveryReportsComplete(m, SIGNAL(useDeliveryReportsComplete(bool, bool)));
153 QSignalSpy setUseDeliveryReportsFailed(m, SIGNAL(setUseDeliveryReportsFailed()));
154 QSignalSpy useDeliveryReportsChanged(m, SIGNAL(useDeliveryReportsChanged(bool)));
156 m->requestUseDeliveryReports();
157 for (int i=0; i<30; i++) {
158 if (useDeliveryReportsComplete.count() > 0)
162 QCOMPARE(useDeliveryReportsComplete.count(), 1);
163 QVariantList params = useDeliveryReportsComplete.takeFirst();
164 QCOMPARE(params.at(0).toBool(), true);
165 QCOMPARE(params.at(1).toBool(), false);
167 m->setUseDeliveryReports(true);
168 for (int i=0; i<30; i++) {
169 if (setUseDeliveryReportsFailed.count() > 0 || useDeliveryReportsChanged.count() > 0)
173 QCOMPARE(setUseDeliveryReportsFailed.count(), 0);
174 QCOMPARE(useDeliveryReportsChanged.count(), 1);
175 QCOMPARE(useDeliveryReportsChanged.takeFirst().at(0).toBool(), true);
177 m->setUseDeliveryReports(false);
178 for (int i=0; i<30; i++) {
179 if (setUseDeliveryReportsFailed.count() > 0 || useDeliveryReportsChanged.count() > 0)
183 QCOMPARE(setUseDeliveryReportsFailed.count(), 0);
184 QCOMPARE(useDeliveryReportsChanged.count(), 1);
185 QCOMPARE(useDeliveryReportsChanged.takeFirst().at(0).toBool(), false);
188 void testOfonoMessageManagerAlphabet()
190 QSignalSpy alphabetComplete(m, SIGNAL(alphabetComplete(bool, QString)));
191 QSignalSpy setAlphabetFailed(m, SIGNAL(setAlphabetFailed()));
192 QSignalSpy alphabetChanged(m, SIGNAL(alphabetChanged(QString)));
194 m->requestAlphabet();
195 for (int i=0; i<30; i++) {
196 if (alphabetComplete.count() > 0)
201 QCOMPARE(alphabetComplete.count(), 1);
202 QVariantList params = alphabetComplete.takeFirst();
203 QCOMPARE(params.at(0).toBool(), true);
204 QString alphabet = params.at(1).toString();
205 QVERIFY(alphabet.length() > 0);
206 QCOMPARE(alphabet, QString("default"));
207 qDebug() << alphabet;
209 m->setAlphabet("spanish");
210 for (int i=0; i<30; i++) {
211 if (setAlphabetFailed.count() > 0 || alphabetChanged.count() > 0)
216 QCOMPARE(setAlphabetFailed.count(), 0);
217 QCOMPARE(alphabetChanged.count(), 1);
218 QCOMPARE(alphabetChanged.takeFirst().at(0).toString(), QString("spanish"));
220 m->setAlphabet(alphabet);
221 for (int i=0; i<30; i++) {
222 if (setAlphabetFailed.count() > 0 || alphabetChanged.count() > 0)
227 QCOMPARE(setAlphabetFailed.count(), 0);
228 QCOMPARE(alphabetChanged.count(), 1);
229 QCOMPARE(alphabetChanged.takeFirst().at(0).toString(), alphabet);
232 void testOfonoMessageManagerBearer()
234 QSignalSpy bearerComplete(m, SIGNAL(bearerComplete(bool, QString)));
235 QSignalSpy setBearerFailed(m, SIGNAL(setBearerFailed()));
236 QSignalSpy bearerChanged(m, SIGNAL(bearerChanged(QString)));
239 for (int i=0; i<30; i++) {
240 if (bearerComplete.count() > 0)
245 QCOMPARE(bearerComplete.count(), 1);
246 QVariantList params = bearerComplete.takeFirst();
247 QCOMPARE(params.at(0).toBool(), true);
248 QString bearer = params.at(1).toString();
249 QVERIFY(bearer.length() > 0);
250 QCOMPARE(bearer, QString("cs-preferred"));
253 m->setBearer("ps-preferred");
254 for (int i=0; i<30; i++) {
255 if (setBearerFailed.count() > 0 || bearerChanged.count() > 0)
260 QCOMPARE(setBearerFailed.count(), 0);
261 QCOMPARE(bearerChanged.count(), 1);
262 QCOMPARE(bearerChanged.takeFirst().at(0).toString(), QString("ps-preferred"));
264 m->setBearer(bearer); // change value
265 for (int i=0; i<30; i++) {
266 if (setBearerFailed.count() > 0 || bearerChanged.count() > 0)
271 QCOMPARE(setBearerFailed.count(), 0);
272 QCOMPARE(bearerChanged.count(), 1);
273 QCOMPARE(bearerChanged.takeFirst().at(0).toString(), bearer);
276 void cleanupTestCase()
283 OfonoMessageManager *m;
286 QTEST_MAIN(TestOfonoMessageManager)
287 #include "test_ofonomessagemanager.moc"