Add a pointer to Qt coding style
[profile/ivi/ofono-qt.git] / tests / test_ofononetworkoperator.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 #include <ofononetworkoperator.h>
29
30 #include <QtDebug>
31
32
33 class TestOfonoNetworkOperator : public QObject
34 {
35     Q_OBJECT
36
37 private slots:
38     void initTestCase()
39     {
40         m = new OfonoNetworkRegistration(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 testOfonoNetworkOperator()
55     {
56         QSignalSpy scan(m, SIGNAL(scanComplete(bool, QStringList)));
57         m->scan();
58         QTest::qWait(5000);
59         QCOMPARE(scan.count(), 1);
60         QVariantList scanList = scan.takeFirst();
61         QCOMPARE(scanList.at(0).toBool(), true);
62         QStringList opIdList = scanList.at(1).toStringList();
63         QVERIFY(opIdList.count() > 0);
64
65         QList<OfonoNetworkOperator> opList;
66         foreach(QString opId, opIdList)
67         {
68             opList << OfonoNetworkOperator(opId);
69         }
70
71         int op1 = -1;
72         int op2 = -1;
73         foreach(OfonoNetworkOperator op, opList) {
74             if (op1 == -1 && op.status() == "current")
75                 op1 = opList.indexOf(op);
76             if (op2 == -1 && op.status() == "available")
77                 op2 = opList.indexOf(op);
78         }
79         QVERIFY(op1 != -1);
80         QVERIFY(op2 != -1);
81         QVERIFY(opList[op1].name().length() > 0);
82         QVERIFY(opList[op2].name().length() > 0);               
83         QVERIFY(opList[op1].mcc().length() > 0);
84         QVERIFY(opList[op2].mcc().length() > 0);                
85         QVERIFY(opList[op1].mnc().length() > 0);
86         QVERIFY(opList[op2].mnc().length() > 0);                
87         QVERIFY(opList[op1].technologies().count() > 0);
88         QVERIFY(opList[op2].technologies().count() > 0);                
89
90         QSignalSpy op1Register(&opList[op1], SIGNAL(registerComplete(bool)));
91         QSignalSpy op2Register(&opList[op2], SIGNAL(registerComplete(bool)));
92         QSignalSpy op1Status(&opList[op1], SIGNAL(statusChanged(QString)));
93         QSignalSpy op2Status(&opList[op2], SIGNAL(statusChanged(QString)));
94
95         QSignalSpy mode(m, SIGNAL(modeChanged(QString)));
96         QSignalSpy status(m, SIGNAL(statusChanged(QString)));   
97         QSignalSpy lac(m, SIGNAL(locationAreaCodeChanged(uint)));       
98         QSignalSpy cellId(m, SIGNAL(cellIdChanged(uint)));      
99         QSignalSpy mcc(m, SIGNAL(mccChanged(QString))); 
100         QSignalSpy mnc(m, SIGNAL(mncChanged(QString))); 
101         QSignalSpy tech(m, SIGNAL(technologyChanged(QString))); 
102         QSignalSpy name(m, SIGNAL(nameChanged(QString)));       
103         QSignalSpy strength(m, SIGNAL(strengthChanged(uint)));  
104         QSignalSpy base(m, SIGNAL(baseStationChanged(QString)));        
105         
106         opList[op2].registerOp();
107         QTest::qWait(5000);
108         opList[op1].registerOp();
109         QTest::qWait(5000);
110         
111         QCOMPARE(op1Register.count(), 1);
112         QCOMPARE(op1Register.takeFirst().at(0).toBool(), true);
113         QCOMPARE(op2Register.count(), 1);
114         QCOMPARE(op2Register.takeFirst().at(0).toBool(), true); 
115         QCOMPARE(op1Status.count(), 2);
116         QCOMPARE(op1Status.takeFirst().at(0).toString(), QString("available")); 
117         QCOMPARE(op1Status.takeFirst().at(0).toString(), QString("current"));
118         QCOMPARE(op2Status.count(), 2);
119         QCOMPARE(op2Status.takeFirst().at(0).toString(), QString("current"));
120         QCOMPARE(op2Status.takeFirst().at(0).toString(), QString("available")); 
121         
122         QCOMPARE(mcc.count(), 2);
123         QCOMPARE(mnc.count(), 2);
124         QCOMPARE(name.count(), 2);
125     }
126
127
128     void cleanupTestCase()
129     {
130
131     }
132
133
134 private:
135     OfonoNetworkRegistration *m;
136 };
137
138 QTEST_MAIN(TestOfonoNetworkOperator)
139 #include "test_ofononetworkoperator.moc"