Remove unnecessary 'request' prefixes
[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
31
32 class TestOfonoSimManager : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37
38     void validityChanged(bool validity)
39     {
40         qDebug() << "ValidityChanged" << validity;
41     }
42
43     void presenceChanged(bool ispresent)
44     {
45         qDebug() << "presenceChanged" << ispresent;
46     }
47     void subscriberIdentityChanged(QString imsi)
48     {
49         qDebug() << "subscriberIdentityChanged" << imsi;
50     }
51     void mobileCountryCodeChanged(QString mcc)
52     {
53         qDebug() << "mobileCountryCodeChanged" << mcc;
54     }
55     void mobileNetworkCodeChanged(QString mnc)
56     {
57         qDebug() << "mobileNetworkCodeChanged" << mnc;
58     }
59     void subscriberNumbersChanged(QStringList msisdns)
60     {
61         qDebug() << "subscriberNumbersChanged" << msisdns;
62     }
63     void serviceNumbersChanged(QMap<QString, QString> sdns)
64     {
65         qDebug() << "serviceNumbersChanged" << sdns;
66     }
67     void pinRequiredChanged(QString pintype)
68     {
69         qDebug() << "pinRequiredChanged" << pintype;
70     }
71     void lockedPinsChanged(QStringList pins)
72     {
73         qDebug() << "lockedPinsChanged" << pins;
74     }
75     void cardIdentifierChanged(QString iccid)
76     {
77         qDebug() << "cardIdentifierChanged" << iccid;
78     }
79     void preferredLanguagesChanged(QStringList languages)
80     {
81         qDebug() << "preferredLanguagesChanged" << languages;
82     }
83
84     void enterPinComplete(bool success)
85     {
86         qDebug() << "enterPinComplete:" << success;
87         if (!success)
88             qDebug() << "Error name/message" << m->errorName() << m->errorMessage();
89     }
90     void resetPinComplete(bool success)
91     {
92         qDebug() << "resetPinComplete:" << success;
93         if (!success)
94             qDebug() << "Error name/message" << m->errorName() << m->errorMessage();
95     }
96
97     void changePinComplete(bool success)
98     {
99         qDebug() << "changePinComplete:" << success;
100     }
101
102     void lockPinComplete(bool success)
103     {
104         qDebug() << "lockPinComplete:" << success;
105     }
106
107     void unlockPinComplete(bool success)
108     {
109         qDebug() << "unlockPinComplete:" << success;
110     }
111
112     void initTestCase()
113     {
114         m = new OfonoSimManager(OfonoModem::AutomaticSelect, QString(), this);
115         connect(m, SIGNAL(validityChanged(bool)), this, 
116                 SLOT(validityChanged(bool)));
117         connect(m, SIGNAL(presenceChanged(bool)), 
118                 this, 
119                 SLOT(presenceChanged(bool)));
120         connect(m, SIGNAL(subscriberIdentityChanged(QString)), this, 
121                 SLOT(subscriberIdentityChanged(QString)));
122         connect(m, SIGNAL(mobileCountryCodeChanged(QString)), this, 
123                 SLOT(mobileCountryCodeChanged(QString)));
124         connect(m, SIGNAL(mobileNetworkCodeChanged(QString)), this, 
125                 SLOT(mobileNetworkCodeChanged(QString)));
126         connect(m, SIGNAL(subscriberNumbersChanged(QStringList)), this, 
127                 SLOT(subscriberNumbersChanged(QStringList)));
128         connect(m, SIGNAL(serviceNumbersChanged(QMap<QString, QString>)), this, 
129                 SLOT(serviceNumbersChanged(QMap<QString, QString>)));
130         connect(m, SIGNAL(pinRequiredChanged(QString)), this, 
131                 SLOT(pinRequiredChanged(QString)));
132         connect(m, SIGNAL(lockedPinsChanged(QStringList)), this, 
133                 SLOT(lockedPinsChanged(QStringList)));
134         connect(m, SIGNAL(cardIdentifierChanged(QString)), this, 
135                 SLOT(cardIdentifierChanged(QString)));
136         connect(m, SIGNAL(preferredLanguagesChanged(QStringList)), this, 
137                 SLOT(preferredLanguagesChanged(QStringList)));
138     }
139
140     void testOfonoSimManager()
141     {
142         qDebug() << "validity:" << m->isValid();
143         qDebug() << "present():" << m->present();
144         qDebug() << "subscriberIdentity():" << m->subscriberIdentity();
145         qDebug() << "mobileCountryCode():" << m->mobileCountryCode();
146         qDebug() << "mobileNetworkCode():" << m->mobileNetworkCode();
147         qDebug() << "subscriberNumbers():" << m->subscriberNumbers();
148         qDebug() << "serviceNumbers():" << m->serviceNumbers();
149         qDebug() << "pinRequired():" << m->pinRequired();
150         qDebug() << "lockedPins():" << m->lockedPins();
151         qDebug() << "cardIdentifier():" << m->cardIdentifier();
152         qDebug() << "preferredLanguages():" << m->preferredLanguages();
153
154         /* If we are using phonesim */
155         if (m->subscriberIdentity() == "246813579") {
156             connect(m, SIGNAL(lockPinComplete(bool)), 
157                     this, SLOT(lockPinComplete(bool)));
158             connect(m, SIGNAL(unlockPinComplete(bool)), 
159                     this, SLOT(unlockPinComplete(bool)));
160             connect(m, SIGNAL(changePinComplete(bool)), 
161                     this, SLOT(changePinComplete(bool)));
162
163             if (m->pinRequired() == "pin") {
164                 connect(m, SIGNAL(enterPinComplete(bool)), 
165                         this, SLOT(enterPinComplete(bool)));
166                 m->enterPin("pin", "2468");
167                 QTest::qWait(1000);
168             } else if (m->pinRequired() == "puk") {
169                 connect(m, SIGNAL(resetPinComplete(bool)), 
170                         this, SLOT(resetPinComplete(bool)));
171                 m->resetPin("puk", "13243546", "2468");     
172             }
173
174             if (m->lockedPins().contains("pin")) {
175                 m->unlockPin("pin", "2468");
176                 QTest::qWait(1000);
177                 m->lockPin("pin", "2468");
178                 QTest::qWait(1000);
179                 m->changePin("pin", "2468", "1234");
180                 QTest::qWait(1000);
181                 m->changePin("pin", "1234", "2468");
182             } else {
183                 m->lockPin("pin", "2468");
184                 QTest::qWait(1000);
185                 m->changePin("pin", "2468", "1234");
186                 QTest::qWait(1000);
187                 m->changePin("pin", "1234", "2468");
188                 QTest::qWait(1000);
189                 m->unlockPin("pin", "2468");
190             }
191         }
192         QTest::qWait(120000);
193     }
194
195
196     void cleanupTestCase()
197     {
198
199     }
200
201
202 private:
203     OfonoSimManager *m;
204 };
205
206 QTEST_MAIN(TestOfonoSimManager)
207 #include "test_ofonosimmanager.moc"