Add a pointer to Qt coding style
[profile/ivi/ofono-qt.git] / tests / test_ofononetworkregistration.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 <ofononetworkregistration.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoNetworkRegistration : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37     void initTestCase()
38     {
39         m = new OfonoNetworkRegistration(OfonoModem::ManualSelect, "/phonesim", this);
40         QCOMPARE(m->modem()->isValid(), true);  
41
42         if (!m->modem()->powered()) {
43             m->modem()->setPowered(true);
44             QTest::qWait(5000);
45         }
46         if (!m->modem()->online()) {
47             m->modem()->setOnline(true);
48             QTest::qWait(5000);
49         }
50         QCOMPARE(m->isValid(), true);
51     }
52
53     void testOfonoNetworkRegistration()
54     {
55         QSignalSpy mode(m, SIGNAL(modeChanged(QString)));
56         QSignalSpy status(m, SIGNAL(statusChanged(QString)));   
57         QSignalSpy lac(m, SIGNAL(locationAreaCodeChanged(uint)));       
58         QSignalSpy cellId(m, SIGNAL(cellIdChanged(uint)));      
59         QSignalSpy mcc(m, SIGNAL(mccChanged(QString))); 
60         QSignalSpy mnc(m, SIGNAL(mncChanged(QString))); 
61         QSignalSpy tech(m, SIGNAL(technologyChanged(QString))); 
62         QSignalSpy name(m, SIGNAL(nameChanged(QString)));       
63         QSignalSpy strength(m, SIGNAL(strengthChanged(uint)));  
64         QSignalSpy base(m, SIGNAL(baseStationChanged(QString)));        
65
66         QSignalSpy registerS(m, SIGNAL(registerComplete(bool)));
67         QSignalSpy deregister(m, SIGNAL(deregisterComplete(bool)));
68         QSignalSpy scan(m, SIGNAL(scanComplete(bool, QStringList)));
69         QSignalSpy getOp(m, SIGNAL(getOperatorsComplete(bool, QStringList)));
70
71         QVERIFY(m->mode().length() > 0);
72         QCOMPARE(m->status(), QString("registered"));
73         QCOMPARE(m->mcc(), QString("234"));     
74         QCOMPARE(m->mnc(), QString("01"));      
75         QVERIFY(m->name().length() > 0);
76         QCOMPARE(m->strength(), uint(100));
77
78         m->scan();
79         QTest::qWait(5000);
80         QCOMPARE(scan.count(), 1);
81         QVariantList scanList = scan.takeFirst();
82         QCOMPARE(scanList.at(0).toBool(), true);
83         QStringList scanOpList = scanList.at(1).toStringList();
84         QVERIFY(scanOpList.count() > 0);
85
86         m->getOperators();
87         QTest::qWait(1000);
88         QCOMPARE(getOp.count(), 1);
89         QVariantList getList = getOp.takeFirst();
90         QCOMPARE(getList.at(0).toBool(), true);
91         QStringList getOpList = getList.at(1).toStringList();
92         QVERIFY(getOpList.count() > 0);
93         QCOMPARE(scanOpList, getOpList);
94         
95         m->deregister();
96         QTest::qWait(1000);
97         QCOMPARE(deregister.count(), 1);
98         QCOMPARE(deregister.takeFirst().at(0).toBool(), false);
99         QCOMPARE(m->errorName(), QString("org.ofono.Error.Failed"));
100         QCOMPARE(m->errorMessage(), QString("Operation failed"));
101         QCOMPARE(mode.count(), 1);
102         QCOMPARE(mode.takeFirst().at(0).toString(), QString("off"));
103         m->registerOp();
104         QTest::qWait(5000);
105         QCOMPARE(registerS.count(), 1);
106         QCOMPARE(registerS.takeFirst().at(0).toBool(), true);
107         QCOMPARE(mode.count(), 1);
108         QCOMPARE(mode.takeFirst().at(0).toString(), QString("auto"));
109
110         m->modem()->setOnline(false);
111         QTest::qWait(5000);
112         QCOMPARE(m->isValid(), false);  
113         m->modem()->setOnline(true);
114         QTest::qWait(5000);
115         QCOMPARE(status.count(), 1);
116         QCOMPARE(status.takeFirst().at(0).toString(), QString("registered"));
117         QCOMPARE(mcc.count(), 1);
118         QCOMPARE(mcc.takeFirst().at(0).toString(), QString("234"));
119         QCOMPARE(mnc.count(), 1);
120         QCOMPARE(mnc.takeFirst().at(0).toString(), QString("01"));
121         QCOMPARE(name.count(), 2);
122         QVERIFY(name.takeFirst().at(0).toString().length() > 0);
123         QVERIFY(name.takeFirst().at(0).toString().length() > 0);
124         QCOMPARE(strength.count(), 1);
125         QCOMPARE(strength.takeFirst().at(0).toUInt(), uint(100));
126     }
127
128
129     void cleanupTestCase()
130     {
131
132     }
133
134
135 private:
136     OfonoNetworkRegistration *m;
137 };
138
139 QTEST_MAIN(TestOfonoNetworkRegistration)
140 #include "test_ofononetworkregistration.moc"