2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alex.kanavin@gmail.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 <ofonosimmanager.h>
33 class TestOfonoSimManager : public QObject
40 m = new OfonoSimManager(OfonoModem::ManualSelect, "/phonesim", this);
41 QCOMPARE(m->modem()->isValid(), true);
43 if (!m->modem()->powered()) {
44 m->modem()->setPowered(true);
47 if (!m->modem()->online()) {
48 m->modem()->setOnline(true);
51 QCOMPARE(m->isValid(), true);
54 void testOfonoSimManager()
56 QSignalSpy presence(m, SIGNAL(presenceChanged(bool)));
57 QSignalSpy subscriberIdentity(m, SIGNAL(subscriberIdentityChanged(QString)));
58 QSignalSpy mcc(m, SIGNAL(mobileCountryCodeChanged(QString)));
59 QSignalSpy mnc(m, SIGNAL(mobileNetworkCodeChanged(QString)));
60 QSignalSpy subscriberNumbers(m, SIGNAL(subscriberNumbersChanged(QStringList)));
61 QSignalSpy serviceNumbers(m, SIGNAL(serviceNumbersChanged(OfonoServiceNumbers)));
62 QSignalSpy pinRequired(m, SIGNAL(pinRequiredChanged(QString)));
63 QSignalSpy lockedPins(m, SIGNAL(lockedPinsChanged(QStringList)));
64 QSignalSpy cardIdentifier(m, SIGNAL(cardIdentifierChanged(QString)));
65 QSignalSpy preferredLanguages(m, SIGNAL(preferredLanguagesChanged(QStringList)));
66 QSignalSpy fixedDialing(m, SIGNAL(fixedDialingChanged(bool)));
67 QSignalSpy barredDialing(m, SIGNAL(barredDialingChanged(bool)));
69 QSignalSpy setSubscriberNumbersFailed(m, SIGNAL(setSubscriberNumbersFailed()));
71 QSignalSpy changePin(m, SIGNAL(changePinComplete(bool)));
72 QSignalSpy enterPin(m, SIGNAL(enterPinComplete(bool)));
73 QSignalSpy resetPin(m, SIGNAL(resetPinComplete(bool)));
74 QSignalSpy lockPin(m, SIGNAL(lockPinComplete(bool)));
75 QSignalSpy unlockPin(m, SIGNAL(unlockPinComplete(bool)));
77 QCOMPARE(m->present(), true);
78 QCOMPARE(m->subscriberIdentity(), QString("246813579"));
79 QCOMPARE(m->mobileCountryCode(), QString("246"));
80 QCOMPARE(m->mobileNetworkCode(), QString("81"));
81 QVERIFY(m->subscriberNumbers().count() > 0);
82 QCOMPARE(m->subscriberNumbers()[0], QString("358501234567"));
83 QVERIFY(m->serviceNumbers().count() > 0);
84 QCOMPARE(m->serviceNumbers()[".HELP DESK"], QString("2601"));
85 QCOMPARE(m->pinRequired(), QString("none"));
86 QCOMPARE(m->lockedPins().count(), 0);
87 QCOMPARE(m->cardIdentifier(), QString("8949222074451242066"));
88 QVERIFY(m->preferredLanguages().count() > 0);
89 QCOMPARE(m->preferredLanguages()[0], QString("de"));
90 QCOMPARE(m->pinRetries().count(), 0);
91 QCOMPARE(m->fixedDialing(), false);
92 QCOMPARE(m->barredDialing(), false);
94 QStringList numbers = m->subscriberNumbers();
95 QStringList newNumbers;
96 newNumbers << "1234567";
97 m->setSubscriberNumbers(newNumbers);
99 QCOMPARE(subscriberNumbers.count(), 1);
100 QStringList newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
101 QCOMPARE(newNumbersSignal.count(), 1);
102 QCOMPARE(newNumbersSignal, newNumbers);
106 m->setSubscriberNumbers(newNumbers);
108 QCOMPARE(setSubscriberNumbersFailed.count(), 1);
109 setSubscriberNumbersFailed.takeFirst();
111 m->setSubscriberNumbers(numbers);
113 QCOMPARE(subscriberNumbers.count(), 1);
114 newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
115 QCOMPARE(newNumbersSignal.count(), 1);
116 QCOMPARE(newNumbersSignal, numbers);
118 //SIM hotswap is not testable with phonesim, so we simulate a modem reset
119 m->modem()->setOnline(false);
121 m->modem()->setPowered(false);
123 m->modem()->setPowered(true);
125 m->modem()->setOnline(true);
127 QCOMPARE(presence.count(), 0);
128 QCOMPARE(subscriberIdentity.count(), 1);
129 QCOMPARE(subscriberIdentity.takeFirst().at(0).toString(), QString("246813579"));
130 QCOMPARE(mcc.count(), 1);
131 QCOMPARE(mcc.takeFirst().at(0).toString(), QString("246"));
132 QCOMPARE(mnc.count(), 1);
133 QCOMPARE(mnc.takeFirst().at(0).toString(), QString("81"));
134 QCOMPARE(subscriberNumbers.count(), 1);
135 numbers = subscriberNumbers.takeFirst().at(0).toStringList();
136 QCOMPARE(numbers.count(), 1);
137 QCOMPARE(numbers[0], QString("358501234567"));
138 QCOMPARE(serviceNumbers.count(), 1);
139 OfonoServiceNumbers serviceNumbersMap = serviceNumbers.takeFirst().at(0).value<OfonoServiceNumbers>();
140 QVERIFY(serviceNumbersMap.count() > 0);
141 QCOMPARE(serviceNumbersMap[".HELP DESK"], QString("2601"));
142 QCOMPARE(pinRequired.count(), 0);
143 QCOMPARE(lockedPins.count(), 0);
144 QCOMPARE(cardIdentifier.count(), 1);
145 QCOMPARE(cardIdentifier.takeFirst().at(0).toString(), QString("8949222074451242066"));
146 QCOMPARE(preferredLanguages.count(), 1);
147 QStringList languages = preferredLanguages.takeFirst().at(0).toStringList();
148 QVERIFY(languages.count() > 0);
149 QCOMPARE(languages[0], QString("de"));
150 QCOMPARE(fixedDialing.count(), 0);
151 QCOMPARE(barredDialing.count(), 0);
154 void testOfonoSimManagerPin()
156 QSignalSpy presence(m, SIGNAL(presenceChanged(bool)));
157 QSignalSpy subscriberIdentity(m, SIGNAL(subscriberIdentityChanged(QString)));
158 QSignalSpy mcc(m, SIGNAL(mobileCountryCodeChanged(QString)));
159 QSignalSpy mnc(m, SIGNAL(mobileNetworkCodeChanged(QString)));
160 QSignalSpy subscriberNumbers(m, SIGNAL(subscriberNumbersChanged(QStringList)));
161 QSignalSpy serviceNumbers(m, SIGNAL(serviceNumbersChanged(OfonoServiceNumbers)));
162 QSignalSpy pinRequired(m, SIGNAL(pinRequiredChanged(QString)));
163 QSignalSpy lockedPins(m, SIGNAL(lockedPinsChanged(QStringList)));
164 QSignalSpy cardIdentifier(m, SIGNAL(cardIdentifierChanged(QString)));
165 QSignalSpy preferredLanguages(m, SIGNAL(preferredLanguagesChanged(QStringList)));
166 QSignalSpy pinRetries(m, SIGNAL(pinRetriesChanged(OfonoPinRetries)));
168 QSignalSpy changePin(m, SIGNAL(changePinComplete(bool)));
169 QSignalSpy enterPin(m, SIGNAL(enterPinComplete(bool)));
170 QSignalSpy resetPin(m, SIGNAL(resetPinComplete(bool)));
171 QSignalSpy lockPin(m, SIGNAL(lockPinComplete(bool)));
172 QSignalSpy unlockPin(m, SIGNAL(unlockPinComplete(bool)));
174 m->lockPin("pin", "2468");
176 m->changePin("pin", "2468", "1234");
178 m->changePin("pin", "1234", "2468");
180 // entering and resetting PIN is not possible with phonesim's default config
181 m->enterPin("pin", "2468");
183 m->resetPin("puk", "13243546", "2468");
185 m->unlockPin("pin", "2468");
188 QCOMPARE(lockedPins.count(), 2);
189 QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 1);
190 QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 0);
192 QCOMPARE(lockPin.count(), 1);
193 QCOMPARE(lockPin.takeFirst().at(0).toBool(), true);
194 QCOMPARE(unlockPin.count(), 1);
195 QCOMPARE(unlockPin.takeFirst().at(0).toBool(), true);
196 QCOMPARE(changePin.count(), 2);
197 QCOMPARE(changePin.takeFirst().at(0).toBool(), true);
198 QCOMPARE(changePin.takeFirst().at(0).toBool(), true);
199 QCOMPARE(enterPin.count(), 1);
200 QCOMPARE(enterPin.takeFirst().at(0).toBool(), false);
201 QCOMPARE(resetPin.count(), 1);
202 QCOMPARE(resetPin.takeFirst().at(0).toBool(), false);
204 // entering PIN is not possible with phonesim's default config
205 QCOMPARE(pinRetries.count(), 0);
208 void testOfonoSimManagerIcon()
210 QSignalSpy getIcon(m, SIGNAL(getIconComplete(bool, QByteArray)));
215 QCOMPARE(getIcon.count(), 2);
216 QCOMPARE(getIcon.takeFirst().at(0).toBool(), false);
217 QVariantList list = getIcon.takeFirst();
218 QCOMPARE(list.at(0).toBool(), true);
219 QVERIFY(list.at(1).toByteArray().length() > 0);
222 void cleanupTestCase()
232 QTEST_MAIN(TestOfonoSimManager)
233 #include "test_ofonosimmanager.moc"