remove dep for doxygen
[profile/ivi/ofono-qt.git] / tests / test_ofonosimmanager.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
7  *
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.
11  *
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.
16  *
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
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
26
27 #include <ofonosimmanager.h>
28
29 #include <QtDebug>
30 #include <QVariant>
31
32
33 class TestOfonoSimManager : public QObject
34 {
35     Q_OBJECT
36
37 private slots:
38     void initTestCase()
39     {
40         m = new OfonoSimManager(OfonoModem::ManualSelect, "/phonesim", this);
41         QCOMPARE(m->modem()->isValid(), true);  
42
43         if (!m->modem()->powered()) {
44             m->modem()->setPowered(true);
45             QTest::qWait(5000);
46         }
47         if (!m->modem()->online()) {
48             m->modem()->setOnline(true);
49             QTest::qWait(5000);
50         }
51         QCOMPARE(m->isValid(), true);    
52     }
53
54     void testOfonoSimManager()
55     {
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)));
68
69         QSignalSpy setSubscriberNumbersFailed(m, SIGNAL(setSubscriberNumbersFailed()));
70
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)));
76             
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);
93         
94         QStringList numbers = m->subscriberNumbers();
95         QStringList newNumbers;
96         newNumbers << "1234567";
97         m->setSubscriberNumbers(newNumbers);
98         QTest::qWait(1000);
99         QCOMPARE(subscriberNumbers.count(), 1);
100         QStringList newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
101         QCOMPARE(newNumbersSignal.count(), 1);
102         QCOMPARE(newNumbersSignal, newNumbers);
103
104         newNumbers.clear();
105         newNumbers << "";
106         m->setSubscriberNumbers(newNumbers);
107         QTest::qWait(1000);
108         QCOMPARE(setSubscriberNumbersFailed.count(), 1);
109         setSubscriberNumbersFailed.takeFirst();
110
111         m->setSubscriberNumbers(numbers);
112         QTest::qWait(1000);
113         QCOMPARE(subscriberNumbers.count(), 1);
114         newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
115         QCOMPARE(newNumbersSignal.count(), 1);
116         QCOMPARE(newNumbersSignal, numbers);
117
118         //SIM hotswap is not testable with phonesim, so we simulate a modem reset
119         m->modem()->setOnline(false);
120         QTest::qWait(5000);
121         m->modem()->setPowered(false);
122         QTest::qWait(5000);
123         m->modem()->setPowered(true);
124         QTest::qWait(5000);
125         m->modem()->setOnline(true);
126         QTest::qWait(5000);
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);
152     }
153     
154     void testOfonoSimManagerPin()
155     {
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)));
167
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)));
173
174         m->lockPin("pin", "2468");
175         QTest::qWait(1000);
176         m->changePin("pin", "2468", "1234");
177         QTest::qWait(1000);
178         m->changePin("pin", "1234", "2468");
179         QTest::qWait(1000);
180         // entering and resetting PIN is not possible with phonesim's default config
181         m->enterPin("pin", "2468");     
182         QTest::qWait(1000);
183         m->resetPin("puk", "13243546", "2468");     
184         QTest::qWait(1000);
185         m->unlockPin("pin", "2468");
186         QTest::qWait(1000);
187         
188         QCOMPARE(lockedPins.count(), 2);
189         QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 1);
190         QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 0);
191         
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);
203
204         // entering PIN is not possible with phonesim's default config
205         QCOMPARE(pinRetries.count(), 0);
206     }
207
208     void testOfonoSimManagerIcon()
209     {
210         QSignalSpy getIcon(m, SIGNAL(getIconComplete(bool, QByteArray)));
211         m->getIcon(0);
212         QTest::qWait(1000);
213         m->getIcon(1);
214         QTest::qWait(1000);
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);
220     }
221
222     void cleanupTestCase()
223     {
224
225     }
226
227
228 private:
229     OfonoSimManager *m;
230 };
231
232 QTEST_MAIN(TestOfonoSimManager)
233 #include "test_ofonosimmanager.moc"