~ken-vandine/libqofono/0.90-suggests

« back to all changes in this revision

Viewing changes to test/auto/tests/tst_qofononetworkoperator.cpp

  • Committer: Lorn Potter
  • Date: 2013-07-04 08:27:48 UTC
  • Revision ID: git-v1:a397b694d7ca6412eaab22db184c0c011f19b3a7
add tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <qofono/qofononetworkregistration.h>
 
28
#include <qofono/qofononetworkoperator.h>
 
29
 
 
30
#include <QtDebug>
 
31
 
 
32
 
 
33
class TestQOfonoNetworkOperator : public QObject
 
34
{
 
35
    Q_OBJECT
 
36
 
 
37
private slots:
 
38
    void initTestCase()
 
39
    {
 
40
    m = new QOfonoNetworkRegistration(this);
 
41
    m->setModemPath("/phonesim");
 
42
 
 
43
        QCOMPARE(m->isValid(), true);
 
44
    }
 
45
 
 
46
    void testQOfonoNetworkOperator()
 
47
    {
 
48
        QSignalSpy scan(m, SIGNAL(scanComplete(bool, QStringList)));
 
49
        m->scan();
 
50
        QTest::qWait(5000);
 
51
        QCOMPARE(scan.count(), 1);
 
52
        QVariantList scanList = scan.takeFirst();
 
53
        QCOMPARE(scanList.at(0).toBool(), true);
 
54
        QStringList opIdList = scanList.at(1).toStringList();
 
55
        QVERIFY(opIdList.count() > 0);
 
56
 
 
57
    QList<QOfonoNetworkOperator> opList;
 
58
    foreach(QString opId, opIdList)
 
59
    {
 
60
        QOfonoNetworkOperator op;
 
61
        op.setOperatorPath(opId);
 
62
        opList << op;
 
63
    }
 
64
 
 
65
    int op1 = -1;
 
66
    int op2 = -1;
 
67
    foreach(QOfonoNetworkOperator op, opList) {
 
68
        if (op1 == -1 && op.status() == "current")
 
69
            op1 = opList.indexOf(op);
 
70
        if (op2 == -1 && op.status() == "available")
 
71
            op2 = opList.indexOf(op);
 
72
    }
 
73
    QVERIFY(op1 != -1);
 
74
        QVERIFY(op2 != -1);
 
75
        QVERIFY(opList[op1].name().length() > 0);
 
76
        QVERIFY(opList[op2].name().length() > 0);               
 
77
        QVERIFY(opList[op1].mcc().length() > 0);
 
78
        QVERIFY(opList[op2].mcc().length() > 0);                
 
79
        QVERIFY(opList[op1].mnc().length() > 0);
 
80
        QVERIFY(opList[op2].mnc().length() > 0);                
 
81
        QVERIFY(opList[op1].technologies().count() > 0);
 
82
        QVERIFY(opList[op2].technologies().count() > 0);                
 
83
 
 
84
        QSignalSpy op1Register(&opList[op1], SIGNAL(registerComplete(bool)));
 
85
        QSignalSpy op2Register(&opList[op2], SIGNAL(registerComplete(bool)));
 
86
        QSignalSpy op1Status(&opList[op1], SIGNAL(statusChanged(QString)));
 
87
        QSignalSpy op2Status(&opList[op2], SIGNAL(statusChanged(QString)));
 
88
 
 
89
        QSignalSpy mode(m, SIGNAL(modeChanged(QString)));
 
90
        QSignalSpy status(m, SIGNAL(statusChanged(QString)));   
 
91
        QSignalSpy lac(m, SIGNAL(locationAreaCodeChanged(uint)));       
 
92
        QSignalSpy cellId(m, SIGNAL(cellIdChanged(uint)));      
 
93
        QSignalSpy mcc(m, SIGNAL(mccChanged(QString))); 
 
94
        QSignalSpy mnc(m, SIGNAL(mncChanged(QString))); 
 
95
        QSignalSpy tech(m, SIGNAL(technologyChanged(QString))); 
 
96
        QSignalSpy name(m, SIGNAL(nameChanged(QString)));       
 
97
        QSignalSpy strength(m, SIGNAL(strengthChanged(uint)));  
 
98
        QSignalSpy base(m, SIGNAL(baseStationChanged(QString)));        
 
99
        
 
100
    opList[op2].registerOperator();
 
101
        QTest::qWait(5000);
 
102
    opList[op1].registerOperator();
 
103
        QTest::qWait(5000);
 
104
        
 
105
        QCOMPARE(op1Register.count(), 1);
 
106
        QCOMPARE(op1Register.takeFirst().at(0).toBool(), true);
 
107
        QCOMPARE(op2Register.count(), 1);
 
108
        QCOMPARE(op2Register.takeFirst().at(0).toBool(), true); 
 
109
        QCOMPARE(op1Status.count(), 2);
 
110
        QCOMPARE(op1Status.takeFirst().at(0).toString(), QString("available")); 
 
111
        QCOMPARE(op1Status.takeFirst().at(0).toString(), QString("current"));
 
112
        QCOMPARE(op2Status.count(), 2);
 
113
        QCOMPARE(op2Status.takeFirst().at(0).toString(), QString("current"));
 
114
        QCOMPARE(op2Status.takeFirst().at(0).toString(), QString("available")); 
 
115
        
 
116
        QCOMPARE(mcc.count(), 2);
 
117
        QCOMPARE(mnc.count(), 2);
 
118
        QCOMPARE(name.count(), 2);
 
119
    }
 
120
 
 
121
 
 
122
    void cleanupTestCase()
 
123
    {
 
124
 
 
125
    }
 
126
 
 
127
 
 
128
private:
 
129
    QOfonoNetworkRegistration *m;
 
130
};
 
131
 
 
132
QTEST_MAIN(TestQOfonoNetworkOperator)
 
133
#include "tst_qofononetworkoperator.moc"