~ken-vandine/libqofono/0.90-suggests

« back to all changes in this revision

Viewing changes to test/auto/tests/tst_qofononetworkregistration.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-2011 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 <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 scan(m, SIGNAL(scanComplete(bool, QStringList)));
 
68
        QSignalSpy getOp(m, SIGNAL(getOperatorsComplete(bool, QStringList)));
 
69
 
 
70
        QVERIFY(m->mode().length() > 0);
 
71
        QCOMPARE(m->status(), QString("registered"));
 
72
        QCOMPARE(m->mcc(), QString("234"));     
 
73
        QCOMPARE(m->mnc(), QString("01"));      
 
74
        QVERIFY(m->name().length() > 0);
 
75
        QCOMPARE(m->strength(), uint(100));
 
76
 
 
77
        m->scan();
 
78
        QTest::qWait(5000);
 
79
        QCOMPARE(scan.count(), 1);
 
80
        QVariantList scanList = scan.takeFirst();
 
81
        QCOMPARE(scanList.at(0).toBool(), true);
 
82
        QStringList scanOpList = scanList.at(1).toStringList();
 
83
        QVERIFY(scanOpList.count() > 0);
 
84
 
 
85
        m->getOperators();
 
86
        QTest::qWait(1000);
 
87
        QCOMPARE(getOp.count(), 1);
 
88
        QVariantList getList = getOp.takeFirst();
 
89
        QCOMPARE(getList.at(0).toBool(), true);
 
90
        QStringList getOpList = getList.at(1).toStringList();
 
91
        QVERIFY(getOpList.count() > 0);
 
92
        QCOMPARE(scanOpList, getOpList);
 
93
 
 
94
        m->registerOp();
 
95
        QTest::qWait(5000);
 
96
        QCOMPARE(registerS.count(), 1);
 
97
        QCOMPARE(registerS.takeFirst().at(0).toBool(), true);
 
98
        QCOMPARE(m->mode(), QString("auto"));
 
99
 
 
100
        m->modem()->setOnline(false);
 
101
        QTest::qWait(5000);
 
102
        QCOMPARE(m->isValid(), false);  
 
103
        m->modem()->setOnline(true);
 
104
        QTest::qWait(5000);
 
105
        QCOMPARE(status.count(), 1);
 
106
        QCOMPARE(status.takeFirst().at(0).toString(), QString("registered"));
 
107
        QCOMPARE(mcc.count(), 1);
 
108
        QCOMPARE(mcc.takeFirst().at(0).toString(), QString("234"));
 
109
        QCOMPARE(mnc.count(), 1);
 
110
        QCOMPARE(mnc.takeFirst().at(0).toString(), QString("01"));
 
111
        QCOMPARE(name.count(), 2);
 
112
        QVERIFY(name.takeFirst().at(0).toString().length() > 0);
 
113
        QVERIFY(name.takeFirst().at(0).toString().length() > 0);
 
114
        QCOMPARE(strength.count(), 1);
 
115
        QCOMPARE(strength.takeFirst().at(0).toUInt(), uint(100));
 
116
    }
 
117
 
 
118
 
 
119
    void cleanupTestCase()
 
120
    {
 
121
 
 
122
    }
 
123
 
 
124
 
 
125
private:
 
126
    OfonoNetworkRegistration *m;
 
127
};
 
128
 
 
129
QTEST_MAIN(TestOfonoNetworkRegistration)
 
130
#include "test_ofononetworkregistration.moc"