2
* Copyright (C) 2013 Canonical, Ltd.
4
* This file is part of telephony-service.
6
* telephony-service is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* telephony-service is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include <QtCore/QObject>
20
#include <QtTest/QtTest>
21
#include "handlercontroller.h"
22
#include "mockcontroller.h"
24
#include "telepathyhelper.h"
26
class HandlerTest : public QObject
32
void testMakingCalls();
33
void testHangUpCall();
34
void testSendMessage();
40
void HandlerTest::initTestCase()
42
QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady()));
43
QTRY_COMPARE(spy.count(), 1);
44
QTRY_VERIFY(TelepathyHelper::instance()->connected());
46
// register the approver
47
mApprover = new Approver(this);
48
TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");
49
// Tp-qt does not set registered status to approvers
50
QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));
52
// we need to wait in order to give telepathy time to notify about the approver
56
void HandlerTest::testMakingCalls()
58
QString callerId("1234567");
59
QSignalSpy callReceivedSpy(MockController::instance(), SIGNAL(callReceived(QString)));
60
HandlerController::instance()->startCall(callerId);
61
QTRY_COMPARE(callReceivedSpy.count(), 1);
62
QCOMPARE(callReceivedSpy.first().first().toString(), callerId);
64
MockController::instance()->hangupCall(callerId);
67
void HandlerTest::testHangUpCall()
69
QString callerId("7654321");
71
QVariantMap properties;
72
properties["Caller"] = callerId;
73
properties["State"] = "incoming";
75
QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));
76
MockController::instance()->placeCall(properties);
78
// wait for the channel to hit the approver
79
QTRY_COMPARE(approverCallSpy.count(), 1);
80
mApprover->acceptCall();
82
// wait until the call state is "accepted"
83
QSignalSpy callStateSpy(MockController::instance(), SIGNAL(callStateChanged(QString,QString,QString)));
87
while (state != "active" && tries < 5) {
88
QTRY_COMPARE(callStateSpy.count(), 1);
89
objectPath = callStateSpy.first()[1].toString();
90
state = callStateSpy.first()[2].toString();
95
QCOMPARE(state, QString("active"));
96
QVERIFY(!objectPath.isEmpty());
98
// and finally request the hangup
99
QSignalSpy callEndedSpy(MockController::instance(), SIGNAL(callEnded(QString)));
100
HandlerController::instance()->hangUpCall(objectPath);
101
QTRY_COMPARE(callEndedSpy.count(), 1);
104
void HandlerTest::testSendMessage()
106
QString recipient("22222222");
107
QString message("Hello, world!");
108
QSignalSpy messageSentSpy(MockController::instance(), SIGNAL(messageSent(QString,QVariantMap)));
109
HandlerController::instance()->sendMessage(recipient, message);
110
QTRY_COMPARE(messageSentSpy.count(), 1);
111
QString sentMessage = messageSentSpy.first().first().toString();
112
QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();
113
QCOMPARE(sentMessage, message);
114
QCOMPARE(messageProperties["Recipients"].value<QStringList>().count(), 1);
115
QCOMPARE(messageProperties["Recipients"].value<QStringList>().first(), recipient);
118
QTEST_MAIN(HandlerTest)
119
#include "HandlerTest.moc"