Add a pointer to Qt coding style
[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 <alexander.kanavin@nokia.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
67         QSignalSpy setSubscriberNumbersFailed(m, SIGNAL(setSubscriberNumbersFailed()));
68
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)));
74             
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"));
88         
89         QStringList numbers = m->subscriberNumbers();
90         QStringList newNumbers;
91         newNumbers << "1234567";
92         m->setSubscriberNumbers(newNumbers);
93         QTest::qWait(1000);
94         QCOMPARE(subscriberNumbers.count(), 1);
95         QStringList newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
96         QCOMPARE(newNumbersSignal.count(), 1);
97         QCOMPARE(newNumbersSignal, newNumbers);
98
99         newNumbers.clear();
100         newNumbers << "";
101         m->setSubscriberNumbers(newNumbers);
102         QTest::qWait(1000);
103         QCOMPARE(setSubscriberNumbersFailed.count(), 1);
104         setSubscriberNumbersFailed.takeFirst();
105
106         m->setSubscriberNumbers(numbers);
107         QTest::qWait(1000);
108         QCOMPARE(subscriberNumbers.count(), 1);
109         newNumbersSignal = subscriberNumbers.takeFirst().at(0).toStringList();
110         QCOMPARE(newNumbersSignal.count(), 1);
111         QCOMPARE(newNumbersSignal, numbers);
112
113         //SIM hotswap is not testable with phonesim, so we simulate a modem reset
114         m->modem()->setOnline(false);
115         QTest::qWait(5000);
116         m->modem()->setPowered(false);
117         QTest::qWait(5000);
118         m->modem()->setPowered(true);
119         QTest::qWait(5000);
120         m->modem()->setOnline(true);
121         QTest::qWait(5000);
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"));
145     }
146     
147     void testOfonoSimManagerPin()
148     {
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)));
159
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)));
165
166         m->lockPin("pin", "2468");
167         QTest::qWait(1000);
168         m->changePin("pin", "2468", "1234");
169         QTest::qWait(1000);
170         m->changePin("pin", "1234", "2468");
171         QTest::qWait(1000);
172         // entering and resetting PIN is not possible with phonesim's default config
173         m->enterPin("pin", "2468");     
174         QTest::qWait(1000);
175         m->resetPin("puk", "13243546", "2468");     
176         QTest::qWait(1000);
177         m->unlockPin("pin", "2468");
178         QTest::qWait(1000);
179         
180         QCOMPARE(lockedPins.count(), 2);
181         QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 1);
182         QCOMPARE(lockedPins.takeFirst().at(0).toStringList().count(), 0);
183         
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);
195     }
196
197
198     void cleanupTestCase()
199     {
200
201     }
202
203
204 private:
205     OfonoSimManager *m;
206 };
207
208 QTEST_MAIN(TestOfonoSimManager)
209 #include "test_ofonosimmanager.moc"