File: test_ofonovoicecall.cpp

package info (click to toggle)
libofono-qt 1.30-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 960 kB
  • sloc: cpp: 6,663; xml: 77; makefile: 14
file content (222 lines) | stat: -rw-r--r-- 7,658 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * This file is part of ofono-qt
 *
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <QtTest/QtTest>
#include <QtCore/QObject>

#include <ofonovoicecallmanager.h>
#include <ofonovoicecall.h>
#include <QtDebug>


class TestOfonoVoiceCall : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase()
    {
        m = new OfonoVoiceCallManager(OfonoModem::ManualSelect, "/phonesim", this);
        QCOMPARE(m->modem()->isValid(), true);
        if (!m->modem()->powered()) {
            m->modem()->setPowered(true);
            QTest::qWait(5000);
        }
        if (!m->modem()->online()) {
            m->modem()->setOnline(true);
            QTest::qWait(5000);
        }
        QCOMPARE(m->isValid(), true);
    }

    void testOfonoVoiceCall()
    {
        bool success = false;
        QSignalSpy dspy(m, SIGNAL(callAdded(QString, QVariantMap)));

        // Dial and hangup
        QDBusObjectPath objectPath = m->dial("123","", success);
        QTest::qWait(1000);

        QCOMPARE(objectPath.path().isEmpty(), false);
        QCOMPARE(success,true);
        QCOMPARE(dspy.count(), 1);
        QString callid = objectPath.path();

        OfonoVoiceCall* call = new OfonoVoiceCall(callid);

        QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
        QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
        QSignalSpy hspy(call, SIGNAL(hangupComplete(bool)));
        QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString)));
        QSignalSpy name (call, SIGNAL(nameChanged(QString)));
        QSignalSpy info (call, SIGNAL(informationChanged(QString)));
        QSignalSpy mp (call, SIGNAL(multipartyChanged(bool)));
        QSignalSpy em (call, SIGNAL(emergencyChanged(bool)));
        QSignalSpy st (call, SIGNAL(startTimeChanged(QString)));
        QSignalSpy ic (call, SIGNAL(iconChanged(quint8)));

        qDebug() << "Please find a call in 'Dialing' state in phonesim window and press 'Active' button";
        QTest::qWait(15000);

        QVERIFY(state.count()>0);
        QVERIFY(st.count()>0);
        QVERIFY(ic.count()==0);
        QVERIFY(em.count()==0);
        QVERIFY(mp.count()==0);
        QVERIFY(info.count()==0);
        QVERIFY(name.count()==0);
        QVERIFY(li.count()==0);

        QCOMPARE(call->state(),QString("active"));
        QCOMPARE(call->lineIdentification(),QString("123"));
        QCOMPARE(call->emergency(),false);
        QCOMPARE(call->multiparty(),false);
        QCOMPARE(call->name(),QString(""));
        QCOMPARE(call->information(),QString(""));

        call->hangup();
        QTest::qWait(5000);
        QCOMPARE(hspy.count(), 1);
        QCOMPARE(hspy.takeFirst().at(0).toBool(),true);
        QCOMPARE(discreason.count(), 1);
        QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
        delete call;
    }

    void testOfonoVoiceCallStep2()
    {
        bool success = false;
        //Dial failure, incoming, answer and local hangup
        QSignalSpy callsignal(m, SIGNAL(callAdded(const QString, QVariantMap)));

        QDBusObjectPath objectPath = m->dial("199","", success);
        QTest::qWait(8000);

        QCOMPARE(callsignal.count(),1);
        QString callid = callsignal.takeFirst().at(0).toString();

        OfonoVoiceCall* call = new OfonoVoiceCall(callid);
        QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
        QSignalSpy time(call,SIGNAL(startTimeChanged(const QString)));
        QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
        QSignalSpy hspy(call, SIGNAL(hangupComplete(bool)));
        QSignalSpy aspy(call, SIGNAL(answerComplete(bool)));

        QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString)));
        QSignalSpy name (call, SIGNAL(nameChanged(QString)));
        QSignalSpy info (call, SIGNAL(informationChanged(QString)));
        QSignalSpy mp (call, SIGNAL(multipartyChanged(bool)));
        QSignalSpy em (call, SIGNAL(emergencyChanged(bool)));
        QSignalSpy ic (call, SIGNAL(iconChanged(quint8)));


        QTest::qWait(8000);
        QCOMPARE(call->state(),QString("incoming"));
        call->answer();
        QTest::qWait(10000);
        QVERIFY(state.count()>0);
        QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
        QVERIFY(time.count()>0);
        QCOMPARE(aspy.count(), 1);
        QCOMPARE(aspy.takeFirst().at(0).toBool(),true);

        QVERIFY(ic.count()==0);
        QVERIFY(em.count()==0);
        QVERIFY(mp.count()==0);
        QVERIFY(info.count()==0);
        QVERIFY(name.count()==0);
        QVERIFY(li.count()==0);

        call->hangup();
        QTest::qWait(5000);
        QCOMPARE(hspy.count(), 1);
        QCOMPARE(hspy.takeFirst().at(0).toBool(), true);
        QCOMPARE(discreason.count(), 1);
        QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
        delete call;
    }

    void testOfonoVoiceCallStep3()
    {
        bool success = false;
        //Dial failed, incoming, no answer and state change to disconnect
        QSignalSpy callsignal(m, SIGNAL(callAdded(const QString, QVariantMap)));

        QDBusObjectPath objectPath = m->dial("177","", success);
        QTest::qWait(3000);

        QCOMPARE(callsignal.count(),1);
        QString callid = callsignal.takeFirst().at(0).toString();

        OfonoVoiceCall* call = new OfonoVoiceCall(callid);
        QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
        QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));

        QTest::qWait(1000);
        QCOMPARE(call->state(),QString("incoming"));
        QTest::qWait(8000);
        QVERIFY(state.count()>0);
        QCOMPARE(discreason.count(), 1);
        QCOMPARE(discreason.takeFirst().at(0).toString(), QString("remote"));
        delete call;

    }
    void testOfonoVoiceCallStep4()
    {
        bool success = false;
        //Deflect
        QSignalSpy callsignal(m, SIGNAL(callAdded(const QString, QVariantMap)));
        QDBusObjectPath objectPath = m->dial("199","", success);
        QTest::qWait(8000);

        QCOMPARE(callsignal.count(),1);
        QString callid = callsignal.takeFirst().at(0).toString();

        OfonoVoiceCall* call = new OfonoVoiceCall(callid);
        QSignalSpy dfspy(call, SIGNAL(deflectComplete(bool)));

        QTest::qWait(8000);
        QCOMPARE(call->state(),QString("incoming"));
        QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
        call->deflect("2345");
        QTest::qWait(8000);
        QCOMPARE(dfspy.count(), 1);
        QCOMPARE(dfspy.takeFirst().at(0).toBool(), true);
        QTest::qWait(10000);

        delete call;

    }
    void cleanupTestCase()
    {

    }


private:
    OfonoVoiceCallManager *m;
};

QTEST_MAIN(TestOfonoVoiceCall)
#include "test_ofonovoicecall.moc"