2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
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.
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.
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
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
27 #include <ofononetworkregistration.h>
32 class TestOfonoNetworkRegistration : public QObject
39 m = new OfonoNetworkRegistration(OfonoModem::ManualSelect, "/phonesim", this);
40 QCOMPARE(m->modem()->isValid(), true);
42 if (!m->modem()->powered()) {
43 m->modem()->setPowered(true);
46 if (!m->modem()->online()) {
47 m->modem()->setOnline(true);
50 QCOMPARE(m->isValid(), true);
53 void testOfonoNetworkRegistration()
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)));
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)));
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));
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);
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);
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"));
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"));
110 m->modem()->setOnline(false);
112 QCOMPARE(m->isValid(), false);
113 m->modem()->setOnline(true);
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));
129 void cleanupTestCase()
136 OfonoNetworkRegistration *m;
139 QTEST_MAIN(TestOfonoNetworkRegistration)
140 #include "test_ofononetworkregistration.moc"