Merge commit 'refs/merge-requests/1' of gitorious.org:meego-cellular/ofono-qt into...
[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 <alexander.kanavin@nokia.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         QTest::qWait(10000);
80
81         QVERIFY(state.count()>0);
82         QVERIFY(st.count()>0);
83         QVERIFY(ic.count()==0);
84         QVERIFY(em.count()==0);
85         QVERIFY(mp.count()==0);
86         QVERIFY(info.count()==0);
87         QVERIFY(name.count()==0);
88         QVERIFY(li.count()==0);
89
90         QCOMPARE(call->state(),QString("active"));
91         QCOMPARE(call->lineIdentification(),QString("123"));
92         QCOMPARE(call->emergency(),false);
93         QCOMPARE(call->multiparty(),false);
94         QCOMPARE(call->name(),QString(""));
95         QCOMPARE(call->information(),QString(""));
96
97         call->hangup();
98         QTest::qWait(5000);
99         QCOMPARE(hspy.count(), 1);
100         QCOMPARE(hspy.takeFirst().at(0).toBool(),true);
101         QCOMPARE(discreason.count(), 1);
102         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
103         delete call;
104     }
105
106     void testOfonoVoiceCallStep2()
107     {
108         //Dial failure, incoming, answer and local hangup
109         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
110
111         m->dial("199","");
112         QTest::qWait(8000);
113
114         QCOMPARE(callsignal.count(),1);
115         QString callid = callsignal.takeFirst().at(0).toString();
116
117         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
118         QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
119         QSignalSpy time(call,SIGNAL(startTimeChanged(const QString)));
120         QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
121         QSignalSpy hspy(call, SIGNAL(hangupComplete(bool)));
122         QSignalSpy aspy(call, SIGNAL(answerComplete(bool)));
123
124         QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString)));
125         QSignalSpy name (call, SIGNAL(nameChanged(QString)));
126         QSignalSpy info (call, SIGNAL(informationChanged(QString)));
127         QSignalSpy mp (call, SIGNAL(multipartyChanged(bool)));
128         QSignalSpy em (call, SIGNAL(emergencyChanged(bool)));
129         QSignalSpy ic (call, SIGNAL(iconChanged(quint8)));
130
131
132         QTest::qWait(8000);
133         QCOMPARE(call->state(),QString("incoming"));
134         call->answer();
135         QTest::qWait(10000);
136         QVERIFY(state.count()>0);
137         QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
138         QVERIFY(time.count()>0);
139         QCOMPARE(aspy.count(), 1);
140         QCOMPARE(aspy.takeFirst().at(0).toBool(),true);
141
142         QVERIFY(ic.count()==0);
143         QVERIFY(em.count()==0);
144         QVERIFY(mp.count()==0);
145         QVERIFY(info.count()==0);
146         QVERIFY(name.count()==0);
147         QVERIFY(li.count()==0);
148
149         call->hangup();
150         QTest::qWait(5000);
151         QCOMPARE(hspy.count(), 1);
152         QCOMPARE(hspy.takeFirst().at(0).toBool(), true);
153         QCOMPARE(discreason.count(), 1);
154         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local"));
155         delete call;
156     }
157
158     void testOfonoVoiceCallStep3()
159     {
160         //Dial failed, incoming, no answer and state change to disconnect
161         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
162
163         m->dial("177","");
164         QTest::qWait(3000);
165
166         QCOMPARE(callsignal.count(),1);
167         QString callid = callsignal.takeFirst().at(0).toString();
168
169         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
170         QSignalSpy state(call, SIGNAL(stateChanged(const QString)));
171         QSignalSpy discreason(call,SIGNAL(disconnectReason(const QString)));
172
173         QTest::qWait(1000);
174         QCOMPARE(call->state(),QString("incoming"));
175         QTest::qWait(8000);
176         QVERIFY(state.count()>0);
177         QCOMPARE(discreason.count(), 1);
178         QCOMPARE(discreason.takeFirst().at(0).toString(), QString("remote"));
179         delete call;
180
181     }
182     void testOfonoVoiceCallStep4()
183     {
184         //Deflect
185         QSignalSpy callsignal(m, SIGNAL(callAdded(const QString)));
186         m->dial("199","");
187         QTest::qWait(8000);
188
189         QCOMPARE(callsignal.count(),1);
190         QString callid = callsignal.takeFirst().at(0).toString();
191
192         OfonoVoiceCall* call = new OfonoVoiceCall(callid);
193         QSignalSpy dfspy(call, SIGNAL(deflectComplete(bool)));
194
195         QTest::qWait(8000);
196         QCOMPARE(call->state(),QString("incoming"));
197         QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value
198         call->deflect("2345");
199         QTest::qWait(8000);
200         QCOMPARE(dfspy.count(), 1);
201         QCOMPARE(dfspy.takeFirst().at(0).toBool(), true);
202         QTest::qWait(10000);
203
204         delete call;
205
206     }
207     void cleanupTestCase()
208     {
209
210     }
211
212
213 private:
214     OfonoVoiceCallManager *m;
215 };
216
217 QTEST_MAIN(TestOfonoVoiceCall)
218 #include "test_ofonovoicecall.moc"