Change contact email address as the nokia one will be no longer valid soon
[profile/ivi/ofono-qt.git] / tests / test_ofonocallbarring.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 <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 <ofonocallbarring.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoCallBarring : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37
38     void initTestCase()
39     {
40         m = new OfonoCallBarring(OfonoModem::ManualSelect, "/phonesim", this);
41         QCOMPARE(m->modem()->isValid(), true);  
42
43         if (!m->modem()->powered()) {
44             m->modem()->setPowered(true);
45             QTest::qWait(5000);
46         }
47         if (!m->modem()->online()) {
48             m->modem()->setOnline(true);
49             QTest::qWait(5000);
50         }
51         QCOMPARE(m->isValid(), true);    
52     }
53
54     void testOfonoCallbarring()
55     {
56         QSignalSpy voiceIncomingComplete(m, SIGNAL(voiceIncomingComplete(bool, QString)));
57         QSignalSpy voiceOutgoingComplete(m, SIGNAL(voiceOutgoingComplete(bool, QString)));        
58         QSignalSpy voiceIncomingChanged(m, SIGNAL(voiceIncomingChanged(QString)));
59         QSignalSpy voiceOutgoingChanged(m, SIGNAL(voiceOutgoingChanged(QString)));        
60         QSignalSpy setVoiceIncomingFailed(m, SIGNAL(setVoiceIncomingFailed()));
61         QSignalSpy setVoiceOutgoingFailed(m, SIGNAL(setVoiceOutgoingFailed()));
62
63         // These two are unused until we support a voicecall API
64         QSignalSpy incomingBarringInEffect(m, SIGNAL(incomingBarringInEffect()));
65         QSignalSpy outgoingBarringInEffect(m, SIGNAL(outgoingBarringInEffect()));        
66
67         QSignalSpy changePasswordComplete(m, SIGNAL(changePasswordComplete(bool)));
68         QSignalSpy disableAllComplete(m, SIGNAL(disableAllComplete(bool)));
69         QSignalSpy disableAllIncomingComplete(m, SIGNAL(disableAllIncomingComplete(bool)));
70         QSignalSpy disableAllOutgoingComplete(m, SIGNAL(disableAllOutgoingComplete(bool)));
71         
72         m->requestVoiceIncoming();
73         QTest::qWait(1000);
74         QCOMPARE(voiceIncomingComplete.count(), 1);
75         QVariantList list = voiceIncomingComplete.takeFirst();
76         QCOMPARE(list.at(0).toBool(), true);
77         QCOMPARE(list.at(1).toString(), QString("disabled"));
78         QCOMPARE(voiceIncomingChanged.count(), 1);      
79         QCOMPARE(voiceIncomingChanged.takeFirst().at(0).toString(), QString("disabled"));
80         m->requestVoiceOutgoing();
81         QTest::qWait(1000);
82         QCOMPARE(voiceOutgoingComplete.count(), 1);
83         list = voiceOutgoingComplete.takeFirst();
84         QCOMPARE(list.at(0).toBool(), true);
85         QCOMPARE(list.at(1).toString(), QString("disabled"));
86         QCOMPARE(voiceOutgoingChanged.count(), 1);
87         QCOMPARE(voiceOutgoingChanged.takeFirst().at(0).toString(), QString("disabled"));
88
89         m->setVoiceIncoming("always", "0000");
90         QTest::qWait(1000);
91         QCOMPARE(setVoiceIncomingFailed.count(), 1);
92         setVoiceIncomingFailed.takeFirst();
93         m->setVoiceOutgoing("always", "0000");
94         QTest::qWait(1000);
95         QCOMPARE(setVoiceOutgoingFailed.count(), 1);
96         setVoiceOutgoingFailed.takeFirst();
97
98         m->setVoiceIncoming("always", "3579");
99         QTest::qWait(1000);
100         QCOMPARE(voiceIncomingChanged.count(), 1);
101         QCOMPARE(voiceIncomingChanged.takeFirst().at(0).toString(), QString("always"));
102         m->setVoiceOutgoing("international", "3579");
103         QTest::qWait(1000);
104         QCOMPARE(voiceOutgoingChanged.count(), 1);
105         QCOMPARE(voiceOutgoingChanged.takeFirst().at(0).toString(), QString("international"));
106
107         m->disableAllIncoming("3579");
108         QTest::qWait(1000);
109         QCOMPARE(disableAllIncomingComplete.count(), 1);
110         QCOMPARE(disableAllIncomingComplete.takeFirst().at(0).toBool(), false);
111         QCOMPARE(m->errorName(), QString("org.ofono.Error.Failed"));
112         QCOMPARE(m->errorMessage(), QString("Operation failed"));
113         m->disableAllOutgoing("3579");
114         QTest::qWait(1000);
115         QCOMPARE(disableAllOutgoingComplete.count(), 1);
116         QCOMPARE(disableAllOutgoingComplete.takeFirst().at(0).toBool(), false);
117         QCOMPARE(m->errorName(), QString("org.ofono.Error.Failed"));
118         QCOMPARE(m->errorMessage(), QString("Operation failed"));
119         m->disableAll("3579");
120         QTest::qWait(1000);
121         QCOMPARE(disableAllComplete.count(), 1);
122         QCOMPARE(disableAllComplete.takeFirst().at(0).toBool(), true);
123         QCOMPARE(voiceIncomingChanged.count(), 1);
124         QCOMPARE(voiceIncomingChanged.takeFirst().at(0).toString(), QString("disabled"));
125         QCOMPARE(voiceOutgoingChanged.count(), 1);
126         QCOMPARE(voiceOutgoingChanged.takeFirst().at(0).toString(), QString("disabled"));
127         
128         m->changePassword("3579", "1234");
129         QTest::qWait(1000);
130         m->changePassword("1234", "3579");
131         QTest::qWait(1000);
132         QCOMPARE(changePasswordComplete.count(), 2);    
133         QCOMPARE(changePasswordComplete.takeFirst().at(0).toBool(), true);
134         QCOMPARE(changePasswordComplete.takeFirst().at(0).toBool(), true);
135     }
136
137
138     void cleanupTestCase()
139     {
140
141     }
142
143
144 private:
145     OfonoCallBarring *m;
146 };
147
148 QTEST_MAIN(TestOfonoCallBarring)
149 #include "test_ofonocallbarring.moc"