Update CallForwarding class to match latest oFono
[profile/ivi/ofono-qt.git] / tests / test_ofonosupplementaryservices.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010-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 <ofonosupplementaryservices.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoSupplementaryServices : public QObject
33 {
34     Q_OBJECT
35
36 public slots:
37
38 private slots:
39     void initTestCase()
40     {
41         m = new OfonoSupplementaryServices(OfonoModem::ManualSelect, "/phonesim", this);
42         QCOMPARE(m->modem()->isValid(), true);  
43
44         if (!m->modem()->powered()) {
45             m->modem()->setPowered(true);
46             QTest::qWait(5000);
47         }
48         if (!m->modem()->online()) {
49             m->modem()->setOnline(true);
50             QTest::qWait(5000);
51         }
52         QCOMPARE(m->isValid(), true);
53     }
54
55     void testOfonoSupplementaryServices()
56     {
57         QSignalSpy notification(m, SIGNAL(notificationReceived(QString)));
58         QSignalSpy request(m, SIGNAL(requestReceived(QString)));
59
60         QSignalSpy state(m, SIGNAL(stateChanged(QString)));
61
62         QSignalSpy initiateUSSD(m, SIGNAL(initiateUSSDComplete(QString)));
63         QSignalSpy barring(m, SIGNAL(barringComplete(QString, QString, QVariantMap)));
64         QSignalSpy forwarding(m, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
65         QSignalSpy waiting(m, SIGNAL(waitingComplete(QString, QVariantMap)));
66         QSignalSpy callingLinePresentation(m, SIGNAL(callingLinePresentationComplete(QString, QString)));
67         QSignalSpy connectedLinePresentation(m, SIGNAL(connectedLinePresentationComplete(QString, QString)));
68         QSignalSpy callingLineRestriction(m, SIGNAL(callingLineRestrictionComplete(QString, QString)));
69         QSignalSpy connectedLineRestriction(m, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
70
71         QSignalSpy initiateFailed(m, SIGNAL(initiateFailed()));
72         QSignalSpy respond(m, SIGNAL(respondComplete(bool, QString)));
73         QSignalSpy cancel(m, SIGNAL(cancelComplete(bool)));
74     
75         QCOMPARE(m->state(), QString("idle"));
76
77         m->initiate("*225#");
78         QTest::qWait(1000);
79         QCOMPARE(state.count(), 2);
80         QCOMPARE(state.takeFirst().at(0).toString(), QString("active"));
81         QCOMPARE(state.takeFirst().at(0).toString(), QString("idle"));
82         QCOMPARE(initiateUSSD.count(), 1);
83         QCOMPARE(initiateUSSD.takeFirst().at(0).toString(), QString("Thank you, your request is being processed. A message will be sent to your phone."));
84         
85         m->cancel();
86         QTest::qWait(1000);
87         QCOMPARE(cancel.count(), 1);
88         QCOMPARE(cancel.takeFirst().at(0).toBool(), false);
89
90         m->respond("*225#");
91         QTest::qWait(1000);
92         QCOMPARE(respond.count(), 1);
93         QCOMPARE(respond.takeFirst().at(0).toBool(), false);
94
95         m->initiate("*226#");
96         QTest::qWait(1000);
97         QCOMPARE(state.count(), 2);
98         QCOMPARE(state.takeFirst().at(0).toString(), QString("active"));
99         QCOMPARE(state.takeFirst().at(0).toString(), QString("idle"));
100         QCOMPARE(initiateFailed.count(), 1);
101         initiateFailed.takeFirst();
102
103         m->initiate("*#331#");
104         QTest::qWait(1000);
105         QCOMPARE(barring.count(), 1);
106         QVariantList list = barring.takeFirst();
107         QCOMPARE(list.at(0).toString(), QString("interrogation"));
108         QCOMPARE(list.at(1).toString(), QString("InternationalOutgoing"));
109         QVariantMap map = list.at(2).toMap();
110         QCOMPARE(map.count(), 3);
111         QCOMPARE(map["DataInternationalOutgoing"].toString(), QString("disabled"));
112         
113         m->initiate("*#002**11#");
114         QTest::qWait(1000);
115         QCOMPARE(forwarding.count(), 1);
116         list = forwarding.takeFirst();
117         QCOMPARE(list.at(0).toString(), QString("interrogation"));
118         QCOMPARE(list.at(1).toString(), QString("All"));
119         map = list.at(2).toMap();
120         QCOMPARE(map.count(), 5);
121         QCOMPARE(map["VoiceNoReplyTimeout"].toUInt(), uint(20));
122
123         m->initiate("*#43#");
124         QTest::qWait(5000);
125         QCOMPARE(waiting.count(), 1);
126         list = waiting.takeFirst();
127         QCOMPARE(list.at(0).toString(), QString("interrogation"));
128         map = list.at(1).toMap();
129         QCOMPARE(map.count(), 5);
130         QCOMPARE(map["DataAsyncCallWaiting"].toString(), QString("disabled"));
131
132         m->initiate("*#31#");
133         QTest::qWait(1000);
134         QCOMPARE(callingLineRestriction.count(), 1);
135         list = callingLineRestriction.takeFirst();
136         QCOMPARE(list.at(0).toString(), QString("interrogation"));
137         QCOMPARE(list.at(1).toString(), QString("disabled"));
138
139         m->initiate("*#30#");
140         QTest::qWait(1000);
141         QCOMPARE(callingLinePresentation.count(), 1);
142         list = callingLinePresentation.takeFirst();
143         QCOMPARE(list.at(0).toString(), QString("interrogation"));
144         QCOMPARE(list.at(1).toString(), QString("enabled"));
145
146         m->initiate("*#76#");
147         QTest::qWait(1000);
148         QCOMPARE(connectedLinePresentation.count(), 1);
149         list = connectedLinePresentation.takeFirst();
150         QCOMPARE(list.at(0).toString(), QString("interrogation"));
151         QCOMPARE(list.at(1).toString(), QString("enabled"));
152
153         m->initiate("*#77#");
154         QTest::qWait(1000);
155         QCOMPARE(connectedLineRestriction.count(), 1);
156         list = connectedLineRestriction.takeFirst();
157         QCOMPARE(list.at(0).toString(), QString("interrogation"));
158         QCOMPARE(list.at(1).toString(), QString("enabled"));
159     }
160
161
162     void cleanupTestCase()
163     {
164
165     }
166
167
168 private:
169     OfonoSupplementaryServices *m;
170 };
171
172 QTEST_MAIN(TestOfonoSupplementaryServices)
173 #include "test_ofonosupplementaryservices.moc"