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 <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)));
67 QSignalSpy setSubscriberNumbersFailed(m, SIGNAL(setSubscriberNumbersFailed()));
69 QSignalSpy changePin(m, SIGNAL(changePinComplete(bool)));
70 QSignalSpy enterPin(m, SIGNAL(enterPinComplete(bool)));
71 QSignalSpy resetPin(m, SIGNAL(resetPinComplete(bool)));
72 QSignalSpy lockPin(m, SIGNAL(lockPinComplete(bool)));
73 QSignalSpy unlockPin(m, SIGNAL(unlockPinComplete(bool)));
75 QCOMPARE(m->present(), true);
76 QCOMPARE(m->subscriberIdentity(), QString("246813579"));
77 QCOMPARE(m->mobileCountryCode(), QString("246"));
78 QCOMPARE(m->mobileNetworkCode(), QString("81"));
79 QVERIFY(m->subscriberNumbers().count() > 0);
80 QCOMPARE(m->subscriberNumbers()[0], QString("358501234567"));
81 QVERIFY(m->serviceNumbers().count() > 0);
82 QCOMPARE(m->serviceNumbers()[".HELP DESK"], QString("2601"));
83 QCOMPARE(m->pinRequired(), QString("none"));
84 QCOMPARE(m->lockedPins().count(), 0);
85 QCOMPARE(m->cardIdentifier(), QString("8949222074451242066"));
86 QVERIFY(m->preferredLanguages().count() > 0);
87 QCOMPARE(m->preferredLanguages()[0], QString("de"));
89 QStringList numbers = m->subscriberNumbers();
90 QStringList newNumbers;
91 newNumbers << "1234567";
92 m->setSubscriberNumbers(newNumbers);
94 QCOMPARE(subscriberNumbers.count(), 1);
95 QStringList newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
96 QCOMPARE(newNumbersSignal.count(), 1);
97 QCOMPARE(newNumbersSignal, newNumbers);
101 m->setSubscriberNumbers(newNumbers);
103 QCOMPARE(setSubscriberNumbersFailed.count(), 1);
104 setSubscriberNumbersFailed.takeFirst();
106 m->setSubscriberNumbers(numbers);
108 QCOMPARE(subscriberNumbers.count(), 1);
109 newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
110 QCOMPARE(newNumbersSignal.count(), 1);
111 QCOMPARE(newNumbersSignal, numbers);
113 //SIM hotswap is not testable with phonesim, so we simulate a modem reset
114 m->modem()->setOnline(false);
116 m->modem()->setPowered(false);
118 m->modem()->setPowered(true);
120 m->modem()->setOnline(true);
122 QCOMPARE(presence.count(), 0);
123 QCOMPARE(subscriberIdentity.count(), 1);
124 QCOMPARE(subscriberIdentity.takeFirst().at(0).toString(), QString("246813579"));
125 QCOMPARE(mcc.count(), 1);
126 QCOMPARE(mcc.takeFirst().at(0).toString(), QString("246"));
127 QCOMPARE(mnc.count(), 1);
128 QCOMPARE(mnc.takeFirst().at(0).toString(), QString("81"));
129 QCOMPARE(subscriberNumbers.count(), 1);
130 numbers = subscriberNumbers.takeFirst().at(0).toStringList();
131 QCOMPARE(numbers.count(), 1);
132 QCOMPARE(numbers[0], QString("358501234567"));
133 QCOMPARE(serviceNumbers.count(), 1);
134 OfonoServiceNumbers serviceNumbersMap = serviceNumbers.takeFirst().at(0).value<OfonoServiceNumbers>();
135 QVERIFY(serviceNumbersMap.count() > 0);
136 QCOMPARE(serviceNumbersMap[".HELP DESK"], QString("2601"));
137 QCOMPARE(pinRequired.count(), 0);
138 QCOMPARE(lockedPins.count(), 0);
139 QCOMPARE(cardIdentifier.count(), 1);
140 QCOMPARE(cardIdentifier.takeFirst().at(0).toString(), QString("8949222074451242066"));
141 QCOMPARE(preferredLanguages.count(), 1);
142 QStringList languages = preferredLanguages.takeFirst().at(0).toStringList();
143 QVERIFY(languages.count() > 0);
144 QCOMPARE(languages[0], QString("de"));
147 void testOfonoSimManagerPin()
149 QSignalSpy presence(m, SIGNAL(presenceChanged(bool)));
150 QSignalSpy subscriberIdentity(m, SIGNAL(subscriberIdentityChanged(QString)));
151 QSignalSpy mcc(m, SIGNAL(mobileCountryCodeChanged(QString)));
152 QSignalSpy mnc(m, SIGNAL(mobileNetworkCodeChanged(QString)));
153 QSignalSpy subscriberNumbers(m, SIGNAL(subscriberNumbersChanged(QStringList)));
154 QSignalSpy serviceNumbers(m, SIGNAL(serviceNumbersChanged(OfonoServiceNumbers)));
155 QSignalSpy pinRequired(m, SIGNAL(pinRequiredChanged(QString)));
156 QSignalSpy lockedPins(m, SIGNAL(lockedPinsChanged(QStringList)));
157 QSignalSpy cardIdentifier(m, SIGNAL(cardIdentifierChanged(QString)));
158 QSignalSpy preferredLanguages(m, SIGNAL(preferredLanguagesChanged(QStringList)));
160 QSignalSpy changePin(m, SIGNAL(changePinComplete(bool)));
161 QSignalSpy enterPin(m, SIGNAL(enterPinComplete(bool)));
162 QSignalSpy resetPin(m, SIGNAL(resetPinComplete(bool)));
163 QSignalSpy lockPin(m, SIGNAL(lockPinComplete(bool)));
164 QSignalSpy unlockPin(m, SIGNAL(unlockPinComplete(bool)));
166 m->lockPin("pin", "2468");
168 m->changePin("pin", "2468", "1234");
170 m->changePin("pin", "1234", "2468");
172 // entering and resetting PIN is not possible with phonesim's default config
173 m->enterPin("pin", "2468");
175 m->resetPin("puk", "13243546", "2468");
177 m->unlockPin("pin", "2468");
180 QCOMPARE(lockedPins.count(), 2);
181 QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 1);
182 QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 0);
184 QCOMPARE(lockPin.count(), 1);
185 QCOMPARE(lockPin.takeFirst().at(0).toBool(), true);
186 QCOMPARE(unlockPin.count(), 1);
187 QCOMPARE(unlockPin.takeFirst().at(0).toBool(), true);
188 QCOMPARE(changePin.count(), 2);
189 QCOMPARE(changePin.takeFirst().at(0).toBool(), true);
190 QCOMPARE(changePin.takeFirst().at(0).toBool(), true);
191 QCOMPARE(enterPin.count(), 1);
192 QCOMPARE(enterPin.takeFirst().at(0).toBool(), false);
193 QCOMPARE(resetPin.count(), 1);
194 QCOMPARE(resetPin.takeFirst().at(0).toBool(), false);
198 void cleanupTestCase()
208 QTEST_MAIN(TestOfonoSimManager)
209 #include "test_ofonosimmanager.moc"