Merge commit 'refs/merge-requests/1' of gitorious.org:meego-cellular/ofono-qt into...
[profile/ivi/ofono-qt.git] / tests / test_ofonocallsettings.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 <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 <ofonocallsettings.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoCallSettings : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37     void initTestCase()
38     {
39         m = new OfonoCallSettings(OfonoModem::ManualSelect, "/phonesim", this);
40         QCOMPARE(m->modem()->isValid(), true);  
41
42         if (!m->modem()->powered()) {
43             m->modem()->setPowered(true);
44             QTest::qWait(5000);
45         }
46         if (!m->modem()->online()) {
47             m->modem()->setOnline(true);
48             QTest::qWait(5000);
49         }
50         QCOMPARE(m->isValid(), true);
51     }
52
53     void testOfonoCallSettings()
54     {
55         QSignalSpy callingLinePresentationComplete(m, SIGNAL(callingLinePresentationComplete(bool, QString)));
56         QSignalSpy calledLinePresentationComplete(m, SIGNAL(calledLinePresentationComplete(bool, QString)));
57         QSignalSpy connectedLinePresentationComplete(m, SIGNAL(connectedLinePresentationComplete(bool, QString)));
58         QSignalSpy connectedLineRestrictionComplete(m, SIGNAL(connectedLineRestrictionComplete(bool, QString)));
59         QSignalSpy callingLineRestrictionComplete(m, SIGNAL(callingLineRestrictionComplete(bool, QString)));
60         QSignalSpy hideCallerIdComplete(m, SIGNAL(hideCallerIdComplete(bool, QString)));
61         QSignalSpy voiceCallWaitingComplete(m, SIGNAL(voiceCallWaitingComplete(bool, QString)));
62
63         QSignalSpy callingLinePresentationChanged(m, SIGNAL(callingLinePresentationChanged(QString)));        
64         QSignalSpy calledLinePresentationChanged(m, SIGNAL(calledLinePresentationChanged(QString)));        
65         QSignalSpy connectedLinePresentationChanged(m, SIGNAL(connectedLinePresentationChanged(QString)));
66         QSignalSpy connectedLineRestrictionChanged(m, SIGNAL(connectedLineRestrictionChanged(QString)));
67         QSignalSpy callingLineRestrictionChanged(m, SIGNAL(callingLineRestrictionChanged(QString)));        
68         QSignalSpy hideCallerIdChanged(m, SIGNAL(hideCallerIdChanged(QString)));        
69         QSignalSpy voiceCallWaitingChanged(m, SIGNAL(voiceCallWaitingChanged(QString)));        
70
71         QSignalSpy setHideCallerIdFailed(m, SIGNAL(setHideCallerIdFailed()));
72         QSignalSpy setVoiceCallWaitingFailed(m, SIGNAL(setVoiceCallWaitingFailed()));
73
74         m->requestCallingLinePresentation();
75         QTest::qWait(5000);
76         QCOMPARE(callingLinePresentationComplete.count(), 1);
77         QVariantList list = callingLinePresentationComplete.takeFirst();
78         QCOMPARE(list.at(0).toBool(), true);
79         QCOMPARE(list.at(1).toString(), QString("enabled"));
80         QVERIFY(callingLinePresentationChanged.count() > 0);    
81         QCOMPARE(callingLinePresentationChanged.takeFirst().at(0).toString(), QString("enabled"));      
82         m->requestCalledLinePresentation();
83         QTest::qWait(1000);
84         QCOMPARE(calledLinePresentationComplete.count(), 1);
85         list = calledLinePresentationComplete.takeFirst();
86         QCOMPARE(list.at(0).toBool(), true);
87         QCOMPARE(list.at(1).toString(), QString("enabled"));
88         QVERIFY(calledLinePresentationChanged.count() > 0);     
89         QCOMPARE(calledLinePresentationChanged.takeFirst().at(0).toString(), QString("enabled"));       
90         m->requestConnectedLinePresentation();
91         QTest::qWait(1000);
92         QCOMPARE(connectedLinePresentationComplete.count(), 1);
93         list = connectedLinePresentationComplete.takeFirst();
94         QCOMPARE(list.at(0).toBool(), true);
95         QCOMPARE(list.at(1).toString(), QString("enabled"));
96         QVERIFY(connectedLinePresentationChanged.count() > 0);
97         QCOMPARE(connectedLinePresentationChanged.takeFirst().at(0).toString(), QString("enabled"));
98         m->requestConnectedLineRestriction();
99         QTest::qWait(1000);
100         QCOMPARE(connectedLineRestrictionComplete.count(), 1);
101         list = connectedLineRestrictionComplete.takeFirst();
102         QCOMPARE(list.at(0).toBool(), true);
103         QCOMPARE(list.at(1).toString(), QString("enabled"));
104         QVERIFY(connectedLineRestrictionChanged.count() > 0);
105         QCOMPARE(connectedLineRestrictionChanged.takeFirst().at(0).toString(), QString("enabled"));
106         m->requestCallingLineRestriction();
107         QTest::qWait(1000);
108         QCOMPARE(callingLineRestrictionComplete.count(), 1);
109         list = callingLineRestrictionComplete.takeFirst();
110         QCOMPARE(list.at(0).toBool(), true);
111         QCOMPARE(list.at(1).toString(), QString("on"));
112         QVERIFY(callingLineRestrictionChanged.count() > 0);     
113         QCOMPARE(callingLineRestrictionChanged.takeFirst().at(0).toString(), QString("on"));    
114         m->requestHideCallerId();
115         QTest::qWait(1000);
116         QCOMPARE(hideCallerIdComplete.count(), 1);
117         list = hideCallerIdComplete.takeFirst();
118         QCOMPARE(list.at(0).toBool(), true);
119         QCOMPARE(list.at(1).toString(), QString("default"));
120         QVERIFY(hideCallerIdChanged.count() > 0);       
121         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("default"));
122         m->requestVoiceCallWaiting();
123         QTest::qWait(1000);
124         QCOMPARE(voiceCallWaitingComplete.count(), 1);
125         list = voiceCallWaitingComplete.takeFirst();
126         QCOMPARE(list.at(0).toBool(), true);
127         QCOMPARE(list.at(1).toString(), QString("enabled"));
128         QVERIFY(voiceCallWaitingChanged.count() > 0);   
129         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("enabled"));
130         
131         m->setHideCallerId("abc");
132         QTest::qWait(1000);
133         QCOMPARE(setHideCallerIdFailed.count(), 1);
134         setHideCallerIdFailed.takeFirst();
135         m->setVoiceCallWaiting("abc");
136         QTest::qWait(1000);
137         QCOMPARE(setVoiceCallWaitingFailed.count(), 1);
138         setVoiceCallWaitingFailed.takeFirst();
139         
140         hideCallerIdChanged.clear();
141         m->setHideCallerId("enabled");
142         QTest::qWait(1000);
143         m->setHideCallerId("default");
144         QTest::qWait(1000);
145         QCOMPARE(hideCallerIdChanged.count(), 2);       
146         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("enabled"));
147         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("default"));
148         
149         voiceCallWaitingChanged.clear();        
150         m->setVoiceCallWaiting("disabled");
151         QTest::qWait(5000);
152         m->setVoiceCallWaiting("enabled");
153         QTest::qWait(5000);
154         QCOMPARE(voiceCallWaitingChanged.count(), 2);   
155         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("disabled"));
156         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("enabled"));
157     }
158
159
160     void cleanupTestCase()
161     {
162
163     }
164
165
166 private:
167     OfonoCallSettings *m;
168 };
169
170 QTEST_MAIN(TestOfonoCallSettings)
171 #include "test_ofonocallsettings.moc"