Add a pointer to Qt coding style
[profile/ivi/ofono-qt.git] / tests / test_ofonocallsettings.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 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 calledLineRestrictionComplete(m, SIGNAL(calledLineRestrictionComplete(bool, QString)));
58         QSignalSpy callingLineRestrictionComplete(m, SIGNAL(callingLineRestrictionComplete(bool, QString)));
59         QSignalSpy hideCallerIdComplete(m, SIGNAL(hideCallerIdComplete(bool, QString)));
60         QSignalSpy voiceCallWaitingComplete(m, SIGNAL(voiceCallWaitingComplete(bool, QString)));
61
62         QSignalSpy callingLinePresentationChanged(m, SIGNAL(callingLinePresentationChanged(QString)));        
63         QSignalSpy calledLinePresentationChanged(m, SIGNAL(calledLinePresentationChanged(QString)));        
64         QSignalSpy calledLineRestrictionChanged(m, SIGNAL(calledLineRestrictionChanged(QString)));        
65         QSignalSpy callingLineRestrictionChanged(m, SIGNAL(callingLineRestrictionChanged(QString)));        
66         QSignalSpy hideCallerIdChanged(m, SIGNAL(hideCallerIdChanged(QString)));        
67         QSignalSpy voiceCallWaitingChanged(m, SIGNAL(voiceCallWaitingChanged(QString)));        
68
69         QSignalSpy setHideCallerIdFailed(m, SIGNAL(setHideCallerIdFailed()));
70         QSignalSpy setVoiceCallWaitingFailed(m, SIGNAL(setVoiceCallWaitingFailed()));
71
72         m->requestCallingLinePresentation();
73         QTest::qWait(5000);
74         QCOMPARE(callingLinePresentationComplete.count(), 1);
75         QVariantList list = callingLinePresentationComplete.takeFirst();
76         QCOMPARE(list.at(0).toBool(), true);
77         QCOMPARE(list.at(1).toString(), QString("enabled"));
78         QVERIFY(callingLinePresentationChanged.count() > 0);    
79         QCOMPARE(callingLinePresentationChanged.takeFirst().at(0).toString(), QString("enabled"));      
80         m->requestCalledLinePresentation();
81         QTest::qWait(1000);
82         QCOMPARE(calledLinePresentationComplete.count(), 1);
83         list = calledLinePresentationComplete.takeFirst();
84         QCOMPARE(list.at(0).toBool(), true);
85         QCOMPARE(list.at(1).toString(), QString("enabled"));
86         QVERIFY(calledLinePresentationChanged.count() > 0);     
87         QCOMPARE(calledLinePresentationChanged.takeFirst().at(0).toString(), QString("enabled"));       
88         m->requestCalledLineRestriction();
89         QTest::qWait(1000);
90         QCOMPARE(calledLineRestrictionComplete.count(), 1);
91         list = calledLineRestrictionComplete.takeFirst();
92         QCOMPARE(list.at(0).toBool(), true);
93         QCOMPARE(list.at(1).toString(), QString("enabled"));
94         QVERIFY(calledLineRestrictionChanged.count() > 0);      
95         QCOMPARE(calledLineRestrictionChanged.takeFirst().at(0).toString(), QString("enabled"));        
96         m->requestCallingLineRestriction();
97         QTest::qWait(1000);
98         QCOMPARE(callingLineRestrictionComplete.count(), 1);
99         list = callingLineRestrictionComplete.takeFirst();
100         QCOMPARE(list.at(0).toBool(), true);
101         QCOMPARE(list.at(1).toString(), QString("on"));
102         QVERIFY(callingLineRestrictionChanged.count() > 0);     
103         QCOMPARE(callingLineRestrictionChanged.takeFirst().at(0).toString(), QString("on"));    
104         m->requestHideCallerId();
105         QTest::qWait(1000);
106         QCOMPARE(hideCallerIdComplete.count(), 1);
107         list = hideCallerIdComplete.takeFirst();
108         QCOMPARE(list.at(0).toBool(), true);
109         QCOMPARE(list.at(1).toString(), QString("default"));
110         QVERIFY(hideCallerIdChanged.count() > 0);       
111         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("default"));
112         m->requestVoiceCallWaiting();
113         QTest::qWait(1000);
114         QCOMPARE(voiceCallWaitingComplete.count(), 1);
115         list = voiceCallWaitingComplete.takeFirst();
116         QCOMPARE(list.at(0).toBool(), true);
117         QCOMPARE(list.at(1).toString(), QString("enabled"));
118         QVERIFY(voiceCallWaitingChanged.count() > 0);   
119         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("enabled"));
120         
121         m->setHideCallerId("abc");
122         QTest::qWait(1000);
123         QCOMPARE(setHideCallerIdFailed.count(), 1);
124         setHideCallerIdFailed.takeFirst();
125         m->setVoiceCallWaiting("abc");
126         QTest::qWait(1000);
127         QCOMPARE(setVoiceCallWaitingFailed.count(), 1);
128         setVoiceCallWaitingFailed.takeFirst();
129         
130         hideCallerIdChanged.clear();
131         m->setHideCallerId("enabled");
132         QTest::qWait(1000);
133         m->setHideCallerId("default");
134         QTest::qWait(1000);
135         QCOMPARE(hideCallerIdChanged.count(), 2);       
136         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("enabled"));
137         QCOMPARE(hideCallerIdChanged.takeFirst().at(0).toString(), QString("default"));
138         
139         voiceCallWaitingChanged.clear();        
140         m->setVoiceCallWaiting("disabled");
141         QTest::qWait(5000);
142         m->setVoiceCallWaiting("enabled");
143         QTest::qWait(5000);
144         QCOMPARE(voiceCallWaitingChanged.count(), 2);   
145         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("disabled"));
146         QCOMPARE(voiceCallWaitingChanged.takeFirst().at(0).toString(), QString("enabled"));
147     }
148
149
150     void cleanupTestCase()
151     {
152
153     }
154
155
156 private:
157     OfonoCallSettings *m;
158 };
159
160 QTEST_MAIN(TestOfonoCallSettings)
161 #include "test_ofonocallsettings.moc"