1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/**
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
*/
#include <QtCore/QObject>
#include <QtTest/QtTest>
#include <QVariant>
#include <TelepathyQt/Contact>
#include "telepathyhelper.h"
#include "ofonomockcontroller.h"
class ConnectionTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testConnected();
void testModemStatus();
};
void ConnectionTest::initTestCase()
{
TelepathyHelper::instance();
QSignalSpy spy(TelepathyHelper::instance(),
SIGNAL(accountReady()));
QTRY_COMPARE(spy.count(), 1);
OfonoMockController::instance()->SimManagerSetPresence(true);
OfonoMockController::instance()->SimManagerSetPinRequired("none");
OfonoMockController::instance()->ModemSetOnline();
OfonoMockController::instance()->NetworkRegistrationSetStatus("registered");
qRegisterMetaType<Tp::Presence>();
QTest::qWait(3000);
}
void ConnectionTest::testConnected()
{
// the account should be connected automatically
QTRY_VERIFY(TelepathyHelper::instance()->connected());
}
void ConnectionTest::testModemStatus()
{
Tp::ContactPtr selfContact = TelepathyHelper::instance()->account()->connection()->selfContact();
QSignalSpy signalSpy(selfContact.data(), SIGNAL(presenceChanged(Tp::Presence)));
// set the status as unregistered
OfonoMockController::instance()->NetworkRegistrationSetStatus("unregistered");
QTRY_COMPARE(signalSpy.count(), 1);
Tp::Presence presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAway);
signalSpy.clear();
// now set the modem as registered to the network again to see if it works
OfonoMockController::instance()->NetworkRegistrationSetStatus("registered");
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAvailable);
signalSpy.clear();
// searching should be reported as away
OfonoMockController::instance()->NetworkRegistrationSetStatus("searching");
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAway);
signalSpy.clear();
// denied should be reported as away (set registered first to force the signal to be emitted)
OfonoMockController::instance()->NetworkRegistrationSetStatus("registered");
QTRY_COMPARE(signalSpy.count(), 1);
signalSpy.clear();
OfonoMockController::instance()->NetworkRegistrationSetStatus("denied");
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAway);
signalSpy.clear();
// unknown should be reported as offline (set registered first to force the signal to be emitted)
OfonoMockController::instance()->NetworkRegistrationSetStatus("registered");
QTRY_COMPARE(signalSpy.count(), 1);
signalSpy.clear();
OfonoMockController::instance()->NetworkRegistrationSetStatus("unknown");
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAway);
signalSpy.clear();
// roaming should be reported as available
OfonoMockController::instance()->NetworkRegistrationSetStatus("roaming");
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAvailable);
signalSpy.clear();
// offline modem should be reported as offline (flightmode)
OfonoMockController::instance()->ModemSetOnline(false);
QTRY_COMPARE(signalSpy.count(), 1);
presence = signalSpy.first().first().value<Tp::Presence>();
QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeOffline);
}
QTEST_MAIN(ConnectionTest)
#include "ConnectionTest.moc"
|