Fix voice call tests
[profile/ivi/ofono-qt.git] / tests / test_ofonovoicecall.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  * 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.
11  *
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.
16  *
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
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
26
27 #include <ofonovoicecallmanager.h>
28 #include <ofonovoicecall.h>
29 #include <QtDebug>
30
31
32 class TestOfonoVoiceCall : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37     void initTestCase()
38     {
39         m = new OfonoVoiceCallManager(OfonoModem::ManualSelect, "/phonesim", this);
40         QCOMPARE(m->modem()->isValid(), true);
41         if (!m->modem()->powered()) {
42             m->modem()->setPowered(true);
43             QTest::qWait(5000);
44         }
45         if (!m->modem()->online()) {
46             m->modem()->setOnline(true);
47             QTest::qWait(5000);
48         }
49         QCOMPARE(m->isValid(), true);
50     }
51
52     void testOfonoVoiceCall()
53     {
54         QSignalSpy dialreg(m,SIGNAL(dialComplete(bool)));
55         QSignalSpy dspy(m, SIGNAL(callAdded(QString)));
56
57         // Dial and hangup
58         m->dial("123","");
59         QTest::qWait(1000);
60
61         QCOMPARE(dialreg.count(), 1);
62         QCOMPARE(dialreg.takeFirst().at(0).toBool(),true);
63         QCOMPARE(dspy.count(), 1);
64         QString callid = dspy.takeFirst().at(0).toString();
65
66         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
67
68         QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
69         QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
70         QSignalSpy hspy(call, SIGNAL(hangupComplete(bool)));
71         QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString)));
72         QSignalSpy name (call, SIGNAL(nameChanged(QString)));
73         QSignalSpy info (call, SIGNAL(informationChanged(QString)));
74         QSignalSpy mp (call, SIGNAL(multipartyChanged(bool)));
75         QSignalSpy em (call, SIGNAL(emergencyChanged(bool)));
76         QSignalSpy st (call, SIGNAL(startTimeChanged(QString)));
77         QSignalSpy ic (call, SIGNAL(iconChanged(quint8)));
78
79         qDebug() << "Please find a call in 'Dialing' state in phonesim window and press 'Active' button";
80         QTest::qWait(15000);
81
82         QVERIFY(state.count()>0);
83         QVERIFY(st.count()>0);
84         QVERIFY(ic.count()==0);
85         QVERIFY(em.count()==0);
86         QVERIFY(mp.count()==0);
87         QVERIFY(info.count()==0);
88         QVERIFY(name.count()==0);
89         QVERIFY(li.count()==0);
90
91         QCOMPARE(call->state(),QString("active"));
92         QCOMPARE(call->lineIdentification(),QString("123"));
93         QCOMPARE(call->emergency(),false);
94         QCOMPARE(call->multiparty(),false);
95         QCOMPARE(call->name(),QString(""));
96         QCOMPARE(call->information(),QString(""));
97
98         call->hangup();
99         QTest::qWait(5000);
100         QCOMPARE(hspy.count(), 1);
101         QCOMPARE(hspy.takeFirst().at(0).toBool(),true);
102         QCOMPARE(discreason.count(), 1);
103         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
104         delete call;
105     }
106
107     void testOfonoVoiceCallStep2()
108     {
109         //Dial failure, incoming, answer and local hangup
110         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
111
112         m->dial("199","");
113         QTest::qWait(8000);
114
115         QCOMPARE(callsignal.count(),1);
116         QString callid = callsignal.takeFirst().at(0).toString();
117
118         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
119         QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
120         QSignalSpy time(call,SIGNAL(startTimeChanged(const QString)));
121         QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
122         QSignalSpy hspy(call, SIGNAL(hangupComplete(bool)));
123         QSignalSpy aspy(call, SIGNAL(answerComplete(bool)));
124
125         QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString)));
126         QSignalSpy name (call, SIGNAL(nameChanged(QString)));
127         QSignalSpy info (call, SIGNAL(informationChanged(QString)));
128         QSignalSpy mp (call, SIGNAL(multipartyChanged(bool)));
129         QSignalSpy em (call, SIGNAL(emergencyChanged(bool)));
130         QSignalSpy ic (call, SIGNAL(iconChanged(quint8)));
131
132
133         QTest::qWait(8000);
134         QCOMPARE(call->state(),QString("incoming"));
135         call->answer();
136         QTest::qWait(10000);
137         QVERIFY(state.count()>0);
138         QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
139         QVERIFY(time.count()>0);
140         QCOMPARE(aspy.count(), 1);
141         QCOMPARE(aspy.takeFirst().at(0).toBool(),true);
142
143         QVERIFY(ic.count()==0);
144         QVERIFY(em.count()==0);
145         QVERIFY(mp.count()==0);
146         QVERIFY(info.count()==0);
147         QVERIFY(name.count()==0);
148         QVERIFY(li.count()==0);
149
150         call->hangup();
151         QTest::qWait(5000);
152         QCOMPARE(hspy.count(), 1);
153         QCOMPARE(hspy.takeFirst().at(0).toBool(), true);
154         QCOMPARE(discreason.count(), 1);
155         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
156         delete call;
157     }
158
159     void testOfonoVoiceCallStep3()
160     {
161         //Dial failed, incoming, no answer and state change to disconnect
162         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
163
164         m->dial("177","");
165         QTest::qWait(3000);
166
167         QCOMPARE(callsignal.count(),1);
168         QString callid = callsignal.takeFirst().at(0).toString();
169
170         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
171         QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
172         QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
173
174         QTest::qWait(1000);
175         QCOMPARE(call->state(),QString("incoming"));
176         QTest::qWait(8000);
177         QVERIFY(state.count()>0);
178         QCOMPARE(discreason.count(), 1);
179         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("remote"));
180         delete call;
181
182     }
183     void testOfonoVoiceCallStep4()
184     {
185         //Deflect
186         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
187         m->dial("199","");
188         QTest::qWait(8000);
189
190         QCOMPARE(callsignal.count(),1);
191         QString callid = callsignal.takeFirst().at(0).toString();
192
193         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
194         QSignalSpy dfspy(call, SIGNAL(deflectComplete(bool)));
195
196         QTest::qWait(8000);
197         QCOMPARE(call->state(),QString("incoming"));
198         QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
199         call->deflect("2345");
200         QTest::qWait(8000);
201         QCOMPARE(dfspy.count(), 1);
202         QCOMPARE(dfspy.takeFirst().at(0).toBool(), true);
203         QTest::qWait(10000);
204
205         delete call;
206
207     }
208     void cleanupTestCase()
209     {
210
211     }
212
213
214 private:
215     OfonoVoiceCallManager *m;
216 };
217
218 QTEST_MAIN(TestOfonoVoiceCall)
219 #include "test_ofonovoicecall.moc"