8f6b148e8330973320d9b580a4e7ef6bae1af22e
[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 <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 <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->lockdown());
59         QVERIFY(!mm->emergency());
60         QVERIFY(mm->features().count() > 0);
61         QVERIFY(mm->interfaces().count() > 0);
62
63         QCOMPARE(mm->path(), QString("/phonesim"));
64         QCOMPARE(mm->name(), QString());
65         QCOMPARE(mm->manufacturer(), QString("MeeGo"));
66         QCOMPARE(mm->model(), QString("Synthetic Device"));
67         QCOMPARE(mm->revision(), QString("REV1"));
68         QCOMPARE(mm->serial(), QString("1234567890"));
69     }
70
71     void testOfonoModemAutomatic()
72     {
73         QVERIFY(ma->isValid());
74         QVERIFY(ma->path().length() > 1);
75     }
76
77     void testOfonoModemAddRemove()
78     {
79         QSignalSpy avalid(ma, SIGNAL(validityChanged(bool)));
80         QSignalSpy valid(mm, SIGNAL(validityChanged(bool)));
81         QSignalSpy amodemPath(ma, SIGNAL(pathChanged(QString)));
82         QSignalSpy modemPath(mm, SIGNAL(pathChanged(QString)));
83         
84         qDebug() << "Please stop oFono and then start it again";
85     
86         for (int i=0; i<30; i++) {
87             if (avalid.count() == 2 &&
88                 valid.count() == 1 &&
89                 amodemPath.count() == 2 &&
90                 modemPath.count() == 0)
91                 break;
92             QTest::qWait(1000);
93         }
94         QCOMPARE(avalid.count(), 2);
95         QCOMPARE(valid.count(), 1);
96         QCOMPARE(amodemPath.count(), 2);
97         QCOMPARE(modemPath.count(), 0);
98         QCOMPARE(avalid.takeFirst().at(0).toBool(), false);
99         QCOMPARE(avalid.takeFirst().at(0).toBool(), true);        
100         QCOMPARE(valid.takeFirst().at(0).toBool(), false);
101         amodemPath.takeFirst();
102         QVERIFY(amodemPath.takeFirst().at(0).toString().length() > 1);
103
104         QVERIFY(!mm->isValid());
105         QVERIFY(ma->isValid());
106         QVERIFY(ma->path().length() > 1);
107         delete mm;
108         mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
109         if (!mm->powered()) {
110             mm->setPowered(true);
111             QTest::qWait(5000);
112         }
113         if (!mm->online()) {
114             mm->setOnline(true);
115             QTest::qWait(5000);
116         }
117     }
118
119     void testOfonoModemPowercycle()
120     {
121         QSignalSpy powered(mm, SIGNAL(poweredChanged(bool)));
122         QSignalSpy poweredFailed(mm, SIGNAL(setPoweredFailed()));
123         QSignalSpy online(mm, SIGNAL(onlineChanged(bool)));
124         QSignalSpy onlineFailed(mm, SIGNAL(setOnlineFailed()));
125         QSignalSpy lockdown(mm, SIGNAL(lockdownChanged(bool)));
126         QSignalSpy lockdownFailed(mm, SIGNAL(setLockdownFailed()));
127         QSignalSpy emergency(mm, SIGNAL(emergencyChanged(bool)));
128         QSignalSpy name(mm, SIGNAL(nameChanged(const QString &)));
129         QSignalSpy manufacturer(mm, SIGNAL(manufacturerChanged(const QString &)));
130         QSignalSpy model(mm, SIGNAL(modelChanged(const QString &)));
131         QSignalSpy revision(mm, SIGNAL(revisionChanged(const QString &)));
132         QSignalSpy serial(mm, SIGNAL(serialChanged(const QString &)));
133         QSignalSpy features(mm, SIGNAL(featuresChanged(const QStringList &)));
134         QSignalSpy interfaces(mm, SIGNAL(interfacesChanged(const QStringList &)));
135         
136         mm->setOnline(false);
137         QTest::qWait(5000);
138         QCOMPARE(powered.count(), 0);
139         QCOMPARE(poweredFailed.count(), 0);
140         QCOMPARE(online.count(), 1);
141         QCOMPARE(online.takeFirst().at(0).toBool(), false);
142         QCOMPARE(onlineFailed.count(), 0);
143         QCOMPARE(emergency.count(), 0);
144         QCOMPARE(name.count(), 0);
145         QCOMPARE(manufacturer.count(), 0);
146         QCOMPARE(model.count(), 0);
147         QCOMPARE(revision.count(), 0);
148         QCOMPARE(serial.count(), 0);
149         QCOMPARE(features.count(), 1);
150         QVERIFY(features.takeFirst().at(0).toStringList().count() > 0);
151         QCOMPARE(interfaces.count(), 1);
152         QVERIFY(interfaces.takeFirst().at(0).toStringList().count() > 0);
153
154         mm->setPowered(false);
155         QTest::qWait(5000);
156         QCOMPARE(powered.count(), 1);
157         QCOMPARE(powered.takeFirst().at(0).toBool(), false);
158         QCOMPARE(poweredFailed.count(), 0);
159         QCOMPARE(online.count(), 0);
160         QCOMPARE(onlineFailed.count(), 0);
161         QCOMPARE(emergency.count(), 0);
162         QCOMPARE(name.count(), 0);
163         QCOMPARE(manufacturer.count(), 0);
164         QCOMPARE(model.count(), 0);
165         QCOMPARE(revision.count(), 0);
166         QCOMPARE(serial.count(), 0);
167         QCOMPARE(features.count(), 1);
168         QCOMPARE(features.takeFirst().at(0).toStringList().count(), 0);
169         QCOMPARE(interfaces.count(), 1);
170         QCOMPARE(interfaces.takeFirst().at(0).toStringList().count(), 0);
171
172         mm->setLockdown(true);
173         QTest::qWait(5000);
174         QCOMPARE(lockdown.count(), 1);
175         QCOMPARE(lockdown.takeFirst().at(0).toBool(), true);
176         QCOMPARE(lockdownFailed.count(), 0);
177
178         mm->setLockdown(false);
179         QTest::qWait(5000);
180         QCOMPARE(lockdown.count(), 1);
181         QCOMPARE(lockdown.takeFirst().at(0).toBool(), false);
182         QCOMPARE(lockdownFailed.count(), 0);
183
184         mm->setOnline(true);
185         QTest::qWait(5000);
186         QCOMPARE(onlineFailed.count(), 1);
187         onlineFailed.takeFirst();
188
189         mm->setPowered(true);
190         QTest::qWait(5000);
191         QCOMPARE(powered.count(), 1);
192         QCOMPARE(powered.takeFirst().at(0).toBool(), true);
193         QCOMPARE(poweredFailed.count(), 0);
194         QCOMPARE(online.count(), 0);
195         QCOMPARE(onlineFailed.count(), 0);
196         QCOMPARE(emergency.count(), 0);
197         QCOMPARE(name.count(), 0);
198         QCOMPARE(manufacturer.count(), 1);
199         manufacturer.takeFirst();
200         QCOMPARE(model.count(), 1);
201         model.takeFirst();
202         QCOMPARE(revision.count(), 1);
203         revision.takeFirst();
204         QCOMPARE(serial.count(), 1);
205         serial.takeFirst();
206         QVERIFY(features.count() > 0);
207         QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
208         features.clear();
209         QVERIFY(interfaces.count() > 0);
210         QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
211         interfaces.clear();
212
213         mm->setOnline(true);
214         QTest::qWait(5000);
215         QCOMPARE(powered.count(), 0);
216         QCOMPARE(poweredFailed.count(), 0);
217         QCOMPARE(online.count(), 1);
218         QCOMPARE(online.takeFirst().at(0).toBool(), true);
219         QCOMPARE(onlineFailed.count(), 0);
220         QCOMPARE(emergency.count(), 0);
221         QCOMPARE(name.count(), 0);
222         QCOMPARE(manufacturer.count(), 0);
223         QCOMPARE(model.count(), 0);
224         QCOMPARE(revision.count(), 0);
225         QCOMPARE(serial.count(), 0);
226         QVERIFY(features.count() > 0);
227         QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
228         QVERIFY(interfaces.count() > 0);
229         QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
230
231     }    
232
233     void cleanupTestCase()
234     {
235
236     }
237
238
239 private:
240     OfonoModem *mm;
241     OfonoModem *ma;
242 };
243
244 QTEST_MAIN(TestOfonoModem)
245 #include "test_ofonomodem.moc"