a466b078e657d31fea6d4638c50fc9a8f4cec03a
[profile/ivi/ofono-qt.git] / tests / test_ofonomultipartycall.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
7  *
8  * Portions of this file are Copyright (C) 2011 Intel Corporation
9  * Contact: Shane Bryan <shane.bryan@linux.intel.com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * version 2.1 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  *
25  */
26
27 #include <QtTest/QtTest>
28 #include <QtCore/QObject>
29
30 #include <ofonovoicecallmanager.h>
31 #include <ofonovoicecall.h>
32 #include <QtDebug>
33
34 class TestOfonoMultipartyCall : public QObject
35 {
36     Q_OBJECT
37
38 private slots:
39     void initTestCase()
40     {
41         m = new OfonoVoiceCallManager(OfonoModem::ManualSelect, "/phonesim", this);
42         QCOMPARE(m->modem()->isValid(), true);
43         if (!m->modem()->powered()) {
44             m->modem()->setPowered(true);
45             QTest::qWait(5000);
46         }
47         if (!m->modem()->online()) {
48             m->modem()->setOnline(true);
49             QTest::qWait(5000);
50         }
51         QCOMPARE(m->isValid(), true);
52     }
53
54     void testOfonoMultipartyCalls()
55     {
56         // Test for hangupMultiparty():
57         // 1.  Dial a call
58         // 2.  Receive a call (dial "199" to trigger phonesim callback)
59         // 3.  Combine into multiparty call (2 participants)
60         // 4.  Verify createMultiparty() works as expected
61         // 5.  Put multiparty call on hold
62         // 6.  Dial a 3rd call
63         // 7.  Combine into multiparty call (3 participants)
64         // 8.  Split one call off to "private chat"
65         // 9.  Verify privateChat() works as expected
66         // 10. Hangup multiparty call
67         // 11. Verify hangupMultiparty() works as expected
68         // 12. Hangup all calls
69
70         // VoiceCallManager Spy's
71         QSignalSpy dialreg(m,SIGNAL(dialComplete(bool)));
72         QSignalSpy dspy(m, SIGNAL(callAdded(QString)));
73         QSignalSpy rspy(m, SIGNAL(callRemoved(QString)));
74         QSignalSpy haspy(m, SIGNAL(hangupAllComplete(bool)));
75         QSignalSpy haaspy(m, SIGNAL(holdAndAnswerComplete(bool)));
76         QSignalSpy cmspy(m, SIGNAL(createMultipartyComplete(bool)));
77         QSignalSpy hmspy(m, SIGNAL(hangupMultipartyComplete(bool)));
78         QSignalSpy scspy(m, SIGNAL(swapCallsComplete(bool)));
79         QSignalSpy pcspy(m, SIGNAL(privateChatComplete(bool)));
80
81         // 1. Dial a call (outgoing)
82         m->dial("123","");
83         QTest::qWait(1000);
84
85         QCOMPARE(dialreg.count(), 1);
86         QCOMPARE(dialreg.takeFirst().at(0).toBool(),true);
87         QCOMPARE(dspy.count(), 1);
88         QString c1id = dspy.takeFirst().at(0).toString();
89
90         OfonoVoiceCall* c1 = new OfonoVoiceCall(c1id);
91
92         QSignalSpy c1state(c1, SIGNAL(stateChanged(const QString)));
93         QSignalSpy c1discreason(c1,SIGNAL(disconnectReason(const QString)));
94         QSignalSpy c1li (c1, SIGNAL(lineIdentificationChanged(QString)));
95         QSignalSpy c1name (c1, SIGNAL(nameChanged(QString)));
96         QSignalSpy c1info (c1, SIGNAL(informationChanged(QString)));
97         QSignalSpy c1mp (c1, SIGNAL(multipartyChanged(bool)));
98         QSignalSpy c1em (c1, SIGNAL(emergencyChanged(bool)));
99         QSignalSpy c1st (c1, SIGNAL(startTimeChanged(QString)));
100         QSignalSpy c1ic (c1, SIGNAL(iconChanged(quint8)));
101
102         qDebug() << "Please find a call in 'Dialing' state in phonesim window and press 'Active' button";
103         QTest::qWait(15000);
104         //    - new call should have a state change, and be in "active" state
105         QVERIFY(c1state.count()>0);
106         QVERIFY(c1st.count()>0);
107         QVERIFY(c1ic.count()==0);
108         QVERIFY(c1em.count()==0);
109         QVERIFY(c1mp.count()==0);
110         QVERIFY(c1info.count()==0);
111         QVERIFY(c1name.count()==0);
112         QVERIFY(c1li.count()==0);
113
114         QCOMPARE(c1->state(),QString("active"));
115         QCOMPARE(c1->lineIdentification(),QString("123"));
116         QCOMPARE(c1->emergency(),false);
117         QCOMPARE(c1->multiparty(),false);
118         QCOMPARE(c1->name(),QString(""));
119         QCOMPARE(c1->information(),QString(""));
120
121         // 2. Receive a call
122         //    - dial "199" to trigger phonesim callback
123         m->dial("199","");
124         QTest::qWait(8000);
125
126         QCOMPARE(dialreg.count(), 1);
127         QCOMPARE(dialreg.takeFirst().at(0).toBool(),false);
128         QCOMPARE(dspy.count(),1);
129         QString c2id = dspy.takeFirst().at(0).toString();
130
131         OfonoVoiceCall* c2 = new OfonoVoiceCall(c2id);
132         QSignalSpy c2state(c2, SIGNAL(stateChanged(const QString)));
133         QSignalSpy c2time(c2,SIGNAL(startTimeChanged(const QString)));
134         QSignalSpy c2discreason(c2,SIGNAL(disconnectReason(const QString)));
135
136         QSignalSpy c2li (c2, SIGNAL(lineIdentificationChanged(QString)));
137         QSignalSpy c2name (c2, SIGNAL(nameChanged(QString)));
138         QSignalSpy c2info (c2, SIGNAL(informationChanged(QString)));
139         QSignalSpy c2mp (c2, SIGNAL(multipartyChanged(bool)));
140         QSignalSpy c2em (c2, SIGNAL(emergencyChanged(bool)));
141         QSignalSpy c2ic (c2, SIGNAL(iconChanged(quint8)));
142
143         QTest::qWait(3000);
144         QCOMPARE(c2->state(),QString("waiting"));
145
146         //    - accept incoming call, placing first call on hold
147         m->holdAndAnswer();
148         QTest::qWait(1000);
149
150         QCOMPARE(haaspy.count(),1);
151         QCOMPARE(haaspy.takeFirst().at(0).toBool(),true);
152
153         QTest::qWait(3000);
154         //    - call #1 should be in "held" state
155         QVERIFY(c1state.count()>0);
156         QCOMPARE(c1->state(),QString("held"));
157
158         //    - call #2 should be in "active" state
159         QVERIFY(c2state.count()>0);
160         QCOMPARE(c2->state(),QString("active"));
161         QCOMPARE(c2->lineIdentification(),QString("1234567"));
162         QVERIFY(c2time.count()>0);
163
164         QVERIFY(c2ic.count()==0);
165         QVERIFY(c2em.count()==0);
166         QVERIFY(c2mp.count()==0);
167         QVERIFY(c2info.count()==0);
168         QVERIFY(c2name.count()==0);
169         QVERIFY(c2li.count()==0);
170
171         // 3. Combine into multiparty call (2 participants)
172         m->createMultiparty();
173         QTest::qWait(1000);
174         QCOMPARE(cmspy.count(),1);
175         QCOMPARE(cmspy.takeFirst().at(0).toBool(),true);
176
177         QTest::qWait(3000);
178         // 4. Verify createMultiparty() works as expected
179         //    - call #1 should have a stateChanged signal triggered
180         QVERIFY(c1state.count()>0);
181         //    - both calls should have a multipartyChanged signal triggered,
182         //      be in "active" state and have multiparty property set to "true"
183         QVERIFY(c1mp.count()>0);
184         QVERIFY(c2mp.count()>0);
185         QCOMPARE(c1->state(),QString("active"));
186         QCOMPARE(c2->state(),QString("active"));
187         QCOMPARE(c1->multiparty(),true);
188         QCOMPARE(c2->multiparty(),true);
189
190         // 5. Put multiparty call on hold
191         m->swapCalls();
192         QTest::qWait(1000);
193
194         QCOMPARE(scspy.count(),1);
195         QCOMPARE(scspy.takeFirst().at(0).toBool(),true);
196
197         QTest::qWait(3000);
198         //    - both calls should have a stateChanged signal triggered
199         //      and be in "held" state
200         QVERIFY(c1state.count()>0);
201         QVERIFY(c2state.count()>0);
202         QCOMPARE(c1->state(),QString("held"));
203         QCOMPARE(c2->state(),QString("held"));
204
205         // 6. Dial a 3rd call
206         m->dial("456","");
207         QTest::qWait(1000);
208
209         QCOMPARE(dialreg.count(), 1);
210         QCOMPARE(dialreg.takeFirst().at(0).toBool(),true);
211         QCOMPARE(dspy.count(), 1);
212         QString c3id = dspy.takeFirst().at(0).toString();
213
214         OfonoVoiceCall* c3 = new OfonoVoiceCall(c3id);
215
216         QSignalSpy c3state(c3, SIGNAL(stateChanged(const QString)));
217         QSignalSpy c3discreason(c3,SIGNAL(disconnectReason(const QString)));
218         QSignalSpy c3li (c3, SIGNAL(lineIdentificationChanged(QString)));
219         QSignalSpy c3name (c3, SIGNAL(nameChanged(QString)));
220         QSignalSpy c3info (c3, SIGNAL(informationChanged(QString)));
221         QSignalSpy c3mp (c3, SIGNAL(multipartyChanged(bool)));
222         QSignalSpy c3em (c3, SIGNAL(emergencyChanged(bool)));
223         QSignalSpy c3st (c3, SIGNAL(startTimeChanged(QString)));
224         QSignalSpy c3ic (c3, SIGNAL(iconChanged(quint8)));
225
226         qDebug() << "Please find a call in 'Dialing' state in phonesim window and press 'Active' button";
227         QTest::qWait(15000);
228         //    - 3rd call should have a state change, and be in "active" state
229         QVERIFY(c3state.count()>0);
230         QVERIFY(c3st.count()>0);
231         QVERIFY(c3ic.count()==0);
232         QVERIFY(c3em.count()==0);
233         QVERIFY(c3mp.count()==0);
234         QVERIFY(c3info.count()==0);
235         QVERIFY(c3name.count()==0);
236         QVERIFY(c3li.count()==0);
237
238         QCOMPARE(c3->state(),QString("active"));
239         QCOMPARE(c3->lineIdentification(),QString("456"));
240         QCOMPARE(c3->emergency(),false);
241         QCOMPARE(c3->multiparty(),false);
242         QCOMPARE(c3->name(),QString(""));
243         QCOMPARE(c3->information(),QString(""));
244
245         // 7. Combine into multiparty call (3 participants)
246         m->createMultiparty();
247         QTest::qWait(1000);
248
249         QCOMPARE(cmspy.count(),1);
250         QCOMPARE(cmspy.takeFirst().at(0).toBool(),true);
251
252         QTest::qWait(3000);
253         //    - calls #1 and #2 should have a stateChanged signal triggered
254         QVERIFY(c1state.count()>0);
255         QVERIFY(c2state.count()>0);
256         //    - all calls should have a multipartyChanged signal triggered,
257         //      be in "active" state and have multiparty property set to "true"
258         QVERIFY(c1mp.count()>0);
259         QVERIFY(c2mp.count()>0);
260         QVERIFY(c3mp.count()>0);
261         QCOMPARE(c1->state(),QString("active"));
262         QCOMPARE(c2->state(),QString("active"));
263         QCOMPARE(c3->state(),QString("active"));
264         QCOMPARE(c1->multiparty(),true);
265         QCOMPARE(c2->multiparty(),true);
266         QCOMPARE(c3->multiparty(),true);
267
268         // 8.  Split call #1 off to "private chat"
269         m->privateChat(c1id);
270         QTest::qWait(1000);
271
272         QCOMPARE(pcspy.count(),1);
273         QCOMPARE(pcspy.takeFirst().at(0).toBool(),true);
274
275         QTest::qWait(3000);
276         // 9.  Verify privateChat() works as expected
277         //    - call #1 should have a multipartyChanged signal triggered,
278         //      it's multiparty property set to false and be in "active" state
279         QVERIFY(c1mp.count()>0);
280         QCOMPARE(c1->multiparty(),false);
281         QCOMPARE(c1->state(),QString("active"));
282         //    - calls #2 and #3 should have a stateChanged signal triggered
283         //      and be back in "held" state
284         QVERIFY(c2state.count()>0);
285         QVERIFY(c3state.count()>0);
286         QCOMPARE(c2->state(),QString("held"));
287         QCOMPARE(c3->state(),QString("held"));
288
289
290         // 10. Hangup multiparty call
291         m->hangupMultiparty();
292         QTest::qWait(1000);
293         QCOMPARE(hmspy.count(), 1);
294         QCOMPARE(hmspy.takeFirst().at(0).toBool(),true);
295
296         QTest::qWait(3000);
297         // 11. Verify hangupMultiparty() works as expected
298         //    - two calls should have been removed
299         QVERIFY(rspy.count()==2);
300         QString r2id = rspy.takeFirst().at(0).toString();
301         QString r3id = rspy.takeFirst().at(0).toString();
302         QCOMPARE(r2id,c2id);
303         QCOMPARE(r3id,c3id);
304
305         //    - call #1 should still be in "active" state
306         QCOMPARE(c1->state(),QString("active"));
307
308         //    - calls #2 and #3 should have a stateChanged signal triggered
309         //      and have a disconnect reason of "local"
310         QVERIFY(c2state.count()>0);
311         QVERIFY(c3state.count()>0);
312         QCOMPARE(c2discreason.count(), 1);
313         QCOMPARE(c3discreason.count(), 1);
314         QCOMPARE(c2discreason.takeFirst().at(0).toString(), QString("local"));
315         QCOMPARE(c3discreason.takeFirst().at(0).toString(), QString("local"));
316
317         // 12. Hangup all calls
318         m->hangupAll();
319         QTest::qWait(1000);
320         QCOMPARE(haspy.count(), 1);
321         QCOMPARE(haspy.takeFirst().at(0).toBool(),true);
322
323         QTest::qWait(3000);
324         QCOMPARE(c1discreason.count(), 1);
325         QCOMPARE(c1discreason.takeFirst().at(0).toString(), QString("local"));
326
327         delete c1;
328         delete c2;
329         delete c3;
330     }
331
332     void cleanupTestCase()
333     {
334
335     }
336
337
338 private:
339     OfonoVoiceCallManager *m;
340 };
341
342 QTEST_MAIN(TestOfonoMultipartyCall)
343 #include "test_ofonomultipartycall.moc"