1d38e4432193621b6069c5274eb13204612e87df
[profile/ivi/ofono-qt.git] / tests / test_ofonomodeminterface.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 <ofonomodeminterface.h>
28
29 #include <QtDebug>
30
31 class TestOfonoModemInterface : public QObject
32 {
33     Q_OBJECT
34
35 private slots:
36
37     void initTestCase()
38     {
39         mi = new OfonoModemInterface(OfonoModem::ManualSelect, "/phonesim", "org.ofono.NetworkRegistration", OfonoGetAllOnStartup, this);
40         
41         if (!mi->modem()->powered()) {
42             mi->modem()->setPowered(true);
43             QTest::qWait(5000);
44         }
45         if (!mi->modem()->online()) {
46             mi->modem()->setOnline(true);
47             QTest::qWait(5000);
48         }
49
50     }
51
52     void testOfonoModemInterfaceOnlineOfflineModem()
53     {
54         QSignalSpy validity(mi, SIGNAL(validityChanged(bool)));
55         QCOMPARE(mi->isValid(), true);
56
57         mi->modem()->setOnline(false);
58         QTest::qWait(5000);
59         QCOMPARE(validity.count(), 1);
60         QCOMPARE(validity.takeFirst().at(0).toBool(), false);
61
62         mi->modem()->setOnline(true);
63         QTest::qWait(5000);
64         QCOMPARE(validity.count(), 1);
65         QCOMPARE(validity.takeFirst().at(0).toBool(), true);
66     }
67
68     void testOfonoModemInterfaceAddRemoveModem()
69     {
70         QSignalSpy validity(mi, SIGNAL(validityChanged(bool)));
71         qDebug() << "Please stop oFono and then start it again";
72     
73         for (int i=0; i<30; i++) {
74             if (validity.count() > 0)
75                 break;
76             QTest::qWait(1000);
77         }
78         QCOMPARE(validity.count(), 1);
79         QCOMPARE(validity.takeFirst().at(0).toBool(), false);
80         delete mi;
81         QTest::qWait(10000);
82         mi = new OfonoModemInterface(OfonoModem::ManualSelect, "/phonesim", "org.ofono.NetworkRegistration", OfonoGetAllOnStartup, this);
83         if (!mi->modem()->powered()) {
84             mi->modem()->setPowered(true);
85             QTest::qWait(5000);
86         }
87         if (!mi->modem()->online()) {
88             mi->modem()->setOnline(true);
89             QTest::qWait(5000);
90         }
91         QCOMPARE(validity.count(), 0);
92     }
93
94     void cleanupTestCase()
95     {
96
97     }
98
99
100 private:
101     OfonoModemInterface *mi;
102 };
103
104 QTEST_MAIN(TestOfonoModemInterface)
105 #include "test_ofonomodeminterface.moc"