Remove unnecessary 'request' prefixes
[profile/ivi/ofono-qt.git] / tests / test_ofonomodem.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 <ofonomodem.h>
28
29 #include <QtDebug>
30
31 class TestOfonoModem : public QObject
32 {
33     Q_OBJECT
34
35 private slots:
36
37     void initTestCase()
38     {
39         mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
40         ma = new OfonoModem(OfonoModem::AutomaticSelect, QString(), this);
41         
42         if (!mm->powered()) {
43             mm->setPowered(true);
44             QTest::qWait(5000);
45         }
46         if (!mm->online()) {
47             mm->setOnline(true);
48             QTest::qWait(5000);
49         }
50
51     }
52
53     void testOfonoModemManual()
54     {
55         QVERIFY(mm->isValid());
56         QVERIFY(mm->powered());
57         QVERIFY(mm->online());
58         QVERIFY(!mm->emergency());
59         QVERIFY(mm->features().count() > 0);
60         QVERIFY(mm->interfaces().count() > 0);
61
62         QCOMPARE(mm->path(), QString("/phonesim"));
63         QCOMPARE(mm->name(), QString());
64         QCOMPARE(mm->manufacturer(), QString("MeeGo"));
65         QCOMPARE(mm->model(), QString("Synthetic Device"));
66         QCOMPARE(mm->revision(), QString("REV1"));
67         QCOMPARE(mm->serial(), QString("1234567890"));
68     }
69
70     void testOfonoModemAutomatic()
71     {
72         QVERIFY(ma->isValid());
73         QVERIFY(ma->path().length() > 1);
74     }
75
76     void testOfonoModemAddRemove()
77     {
78         QSignalSpy avalid(ma, SIGNAL(validityChanged(bool)));
79         QSignalSpy valid(mm, SIGNAL(validityChanged(bool)));
80         QSignalSpy amodemPath(ma, SIGNAL(pathChanged(QString)));
81         QSignalSpy modemPath(mm, SIGNAL(pathChanged(QString)));
82         
83         qDebug() << "Please stop oFono and then start it again";
84     
85         for (int i=0; i<30; i++) {
86             if (avalid.count() == 2 &&
87                 valid.count() == 1 &&
88                 amodemPath.count() == 2 &&
89                 modemPath.count() == 0)
90                 break;
91             QTest::qWait(1000);
92         }
93         QCOMPARE(avalid.count(), 2);
94         QCOMPARE(valid.count(), 1);
95         QCOMPARE(amodemPath.count(), 2);
96         QCOMPARE(modemPath.count(), 0);
97         QCOMPARE(avalid.takeFirst().at(0).toBool(), false);
98         QCOMPARE(avalid.takeFirst().at(0).toBool(), true);        
99         QCOMPARE(valid.takeFirst().at(0).toBool(), false);
100         amodemPath.takeFirst();
101         QVERIFY(amodemPath.takeFirst().at(0).toString().length() > 1);
102
103         QVERIFY(!mm->isValid());
104         QVERIFY(ma->isValid());
105         QVERIFY(ma->path().length() > 1);
106         delete mm;
107         mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
108         if (!mm->powered()) {
109             mm->setPowered(true);
110             QTest::qWait(5000);
111         }
112         if (!mm->online()) {
113             mm->setOnline(true);
114             QTest::qWait(5000);
115         }
116     }
117
118     void testOfonoModemPowercycle()
119     {
120         QSignalSpy powered(mm, SIGNAL(poweredChanged(bool)));
121         QSignalSpy poweredFailed(mm, SIGNAL(setPoweredFailed()));
122         QSignalSpy online(mm, SIGNAL(onlineChanged(bool)));
123         QSignalSpy onlineFailed(mm, SIGNAL(setOnlineFailed()));
124         QSignalSpy emergency(mm, SIGNAL(emergencyChanged(bool)));
125         QSignalSpy name(mm, SIGNAL(nameChanged(const QString &)));
126         QSignalSpy manufacturer(mm, SIGNAL(manufacturerChanged(const QString &)));
127         QSignalSpy model(mm, SIGNAL(modelChanged(const QString &)));
128         QSignalSpy revision(mm, SIGNAL(revisionChanged(const QString &)));
129         QSignalSpy serial(mm, SIGNAL(serialChanged(const QString &)));
130         QSignalSpy features(mm, SIGNAL(featuresChanged(const QStringList &)));
131         QSignalSpy interfaces(mm, SIGNAL(interfacesChanged(const QStringList &)));
132         
133         mm->setOnline(false);
134         QTest::qWait(5000);
135         QCOMPARE(powered.count(), 0);
136         QCOMPARE(poweredFailed.count(), 0);
137         QCOMPARE(online.count(), 1);
138         QCOMPARE(online.takeFirst().at(0).toBool(), false);
139         QCOMPARE(onlineFailed.count(), 0);
140         QCOMPARE(emergency.count(), 0);
141         QCOMPARE(name.count(), 0);
142         QCOMPARE(manufacturer.count(), 0);
143         QCOMPARE(model.count(), 0);
144         QCOMPARE(revision.count(), 0);
145         QCOMPARE(serial.count(), 0);
146         QCOMPARE(features.count(), 1);
147         QVERIFY(features.takeFirst().at(0).toStringList().count() > 0);
148         QCOMPARE(interfaces.count(), 1);
149         QVERIFY(interfaces.takeFirst().at(0).toStringList().count() > 0);
150
151         mm->setPowered(false);
152         QTest::qWait(5000);
153         QCOMPARE(powered.count(), 1);
154         QCOMPARE(powered.takeFirst().at(0).toBool(), false);
155         QCOMPARE(poweredFailed.count(), 0);
156         QCOMPARE(online.count(), 0);
157         QCOMPARE(onlineFailed.count(), 0);
158         QCOMPARE(emergency.count(), 0);
159         QCOMPARE(name.count(), 0);
160         QCOMPARE(manufacturer.count(), 0);
161         QCOMPARE(model.count(), 0);
162         QCOMPARE(revision.count(), 0);
163         QCOMPARE(serial.count(), 0);
164         QCOMPARE(features.count(), 1);
165         QCOMPARE(features.takeFirst().at(0).toStringList().count(), 0);
166         QCOMPARE(interfaces.count(), 1);
167         QCOMPARE(interfaces.takeFirst().at(0).toStringList().count(), 0);
168
169         mm->setOnline(true);
170         QTest::qWait(5000);
171         QCOMPARE(onlineFailed.count(), 1);
172         onlineFailed.takeFirst();
173
174         mm->setPowered(true);
175         QTest::qWait(5000);
176         QCOMPARE(powered.count(), 1);
177         QCOMPARE(powered.takeFirst().at(0).toBool(), true);
178         QCOMPARE(poweredFailed.count(), 0);
179         QCOMPARE(online.count(), 0);
180         QCOMPARE(onlineFailed.count(), 0);
181         QCOMPARE(emergency.count(), 0);
182         QCOMPARE(name.count(), 0);
183         QCOMPARE(manufacturer.count(), 1);
184         manufacturer.takeFirst();
185         QCOMPARE(model.count(), 1);
186         model.takeFirst();
187         QCOMPARE(revision.count(), 1);
188         revision.takeFirst();
189         QCOMPARE(serial.count(), 1);
190         serial.takeFirst();
191         QVERIFY(features.count() > 0);
192         QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
193         features.clear();
194         QVERIFY(interfaces.count() > 0);
195         QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
196         interfaces.clear();
197
198         mm->setOnline(true);
199         QTest::qWait(5000);
200         QCOMPARE(powered.count(), 0);
201         QCOMPARE(poweredFailed.count(), 0);
202         QCOMPARE(online.count(), 1);
203         QCOMPARE(online.takeFirst().at(0).toBool(), true);
204         QCOMPARE(onlineFailed.count(), 0);
205         QCOMPARE(emergency.count(), 0);
206         QCOMPARE(name.count(), 0);
207         QCOMPARE(manufacturer.count(), 0);
208         QCOMPARE(model.count(), 0);
209         QCOMPARE(revision.count(), 0);
210         QCOMPARE(serial.count(), 0);
211         QVERIFY(features.count() > 0);
212         QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
213         QVERIFY(interfaces.count() > 0);
214         QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
215
216     }    
217
218     void cleanupTestCase()
219     {
220
221     }
222
223
224 private:
225     OfonoModem *mm;
226     OfonoModem *ma;
227 };
228
229 QTEST_MAIN(TestOfonoModem)
230 #include "test_ofonomodem.moc"