Merge commit 'refs/merge-requests/1' of gitorious.org:meego-cellular/ofono-qt into...
[profile/ivi/ofono-qt.git] / tests / test_ofonovoicecallmanager.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 <ofonovoicecallmanager.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoVoiceCallManager : 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
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 testOfonoVoiceCallManager()
54     {
55         QVERIFY(m->emergencyNumbers().count() > 0);
56
57         QSignalSpy emergencyNumbers(m, SIGNAL(emergencyNumbersChanged(QStringList)));
58         QSignalSpy dialreg(m,SIGNAL(dialComplete(bool)));
59         QSignalSpy dspy(m, SIGNAL(callAdded(QString)));
60         QSignalSpy hupreg(m,SIGNAL(hangupAllComplete(bool)));
61         QSignalSpy tonereg(m,SIGNAL(sendTonesComplete(bool)));
62         QSignalSpy hspy(m, SIGNAL(callRemoved(QString)));
63
64         m->modem()->setPowered(false);
65         QTest::qWait(5000);
66         m->modem()->setPowered(true);
67         QTest::qWait(5000);
68         m->modem()->setOnline(true);
69         QTest::qWait(5000);
70
71         QCOMPARE(emergencyNumbers.count(), 1);
72         QVERIFY(emergencyNumbers.takeFirst().at(0).toStringList().count() > 0);
73         //Dial testing
74         m->dial("123","");
75         QTest::qWait(5000);
76         QCOMPARE(dialreg.count(), 1);
77         QCOMPARE(dialreg.takeFirst().at(0).toBool(),true);
78         QCOMPARE(dspy.count(), 1);
79         //Tones testing
80         QTest::qWait(5000);
81         m->sendTones("1234");
82         QTest::qWait(45000);
83         QCOMPARE(tonereg.count(), 1);
84         QCOMPARE(tonereg.takeFirst().at(0).toBool(),true);
85         QTest::qWait(5000);
86         QStringList calls = m->getCalls();
87         QVERIFY(calls.size()>0);
88         //hangup testing
89         m->hangupAll();
90         QTest::qWait(5000);
91         QCOMPARE(hupreg.count(), 1);
92         QCOMPARE(hupreg.takeFirst().at(0).toBool(),true);
93         QCOMPARE(hspy.count(), 1);
94
95     }
96
97     void testoFonoVoiceCallManagerStep2()
98     {
99         // test dial failure and hangup of incoming alerting call
100         QSignalSpy dialreg(m,SIGNAL(dialComplete(bool)));
101         QSignalSpy hupreg(m,SIGNAL(hangupAllComplete(bool)));
102         QSignalSpy dspy(m, SIGNAL(callAdded(QString)));
103         QSignalSpy hspy(m, SIGNAL(callRemoved(QString)));
104
105
106         m->dial("199","");
107         QTest::qWait(5000);
108         QCOMPARE(dialreg.count(), 1);
109         QCOMPARE(dialreg.takeFirst().at(0).toBool(),false);
110         QTest::qWait(10000);
111         QCOMPARE(dspy.count(), 1);
112
113         //hangup the alerting call
114         m->hangupAll();
115         QTest::qWait(5000);
116         QCOMPARE(hupreg.count(), 1);
117         QCOMPARE(hupreg.takeFirst().at(0).toBool(),true);
118
119         QTest::qWait(10000);
120         QCOMPARE(hspy.count(), 1);
121
122     }
123     void testOfonoVoiceCallmanagerStep3()
124     {
125         // MO call and MT hangup
126         QSignalSpy dspy(m, SIGNAL(callAdded(QString)));
127         QSignalSpy hspy(m, SIGNAL(callRemoved(QString)));
128
129         QTest::qWait(5000);
130         m->dial("0512305","");
131         QTest::qWait(10000);
132         QCOMPARE(dspy.count(), 1);
133         QTest::qWait(10000);
134         QCOMPARE(hspy.count(), 1);
135     }
136
137     void cleanupTestCase()
138     {
139
140     }
141
142
143 private:
144     OfonoVoiceCallManager *m;
145 };
146
147 QTEST_MAIN(TestOfonoVoiceCallManager)
148 #include "test_ofonovoicecallmanager.moc"