2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
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.
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.
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
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
27 #include <ofonomodem.h>
31 class TestOfonoModem : public QObject
39 mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
40 ma = new OfonoModem(OfonoModem::AutomaticSelect, QString(), this);
53 void testOfonoModemManual()
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);
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"));
71 void testOfonoModemAutomatic()
73 QVERIFY(ma->isValid());
74 QVERIFY(ma->path().length() > 1);
77 void testOfonoModemAddRemove()
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)));
84 qDebug() << "Please stop oFono and then start it again";
86 for (int i=0; i<30; i++) {
87 if (avalid.count() == 2 &&
89 amodemPath.count() == 2 &&
90 modemPath.count() == 0)
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);
104 QVERIFY(!mm->isValid());
105 QVERIFY(ma->isValid());
106 QVERIFY(ma->path().length() > 1);
108 mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
109 if (!mm->powered()) {
110 mm->setPowered(true);
119 void testOfonoModemPowercycle()
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 &)));
136 mm->setOnline(false);
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);
154 mm->setPowered(false);
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);
172 mm->setLockdown(true);
174 QCOMPARE(lockdown.count(), 1);
175 QCOMPARE(lockdown.takeFirst().at(0).toBool(), true);
176 QCOMPARE(lockdownFailed.count(), 0);
178 mm->setLockdown(false);
180 QCOMPARE(lockdown.count(), 1);
181 QCOMPARE(lockdown.takeFirst().at(0).toBool(), false);
182 QCOMPARE(lockdownFailed.count(), 0);
186 QCOMPARE(onlineFailed.count(), 1);
187 onlineFailed.takeFirst();
189 mm->setPowered(true);
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);
202 QCOMPARE(revision.count(), 1);
203 revision.takeFirst();
204 QCOMPARE(serial.count(), 1);
206 QVERIFY(features.count() > 0);
207 QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
209 QVERIFY(interfaces.count() > 0);
210 QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
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);
233 void cleanupTestCase()
244 QTEST_MAIN(TestOfonoModem)
245 #include "test_ofonomodem.moc"