2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.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->emergency());
59 QVERIFY(mm->features().count() > 0);
60 QVERIFY(mm->interfaces().count() > 0);
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"));
70 void testOfonoModemAutomatic()
72 QVERIFY(ma->isValid());
73 QVERIFY(ma->path().length() > 1);
76 void testOfonoModemAddRemove()
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)));
83 qDebug() << "Please stop oFono and then start it again";
85 for (int i=0; i<30; i++) {
86 if (avalid.count() == 2 &&
88 amodemPath.count() == 2 &&
89 modemPath.count() == 0)
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);
103 QVERIFY(!mm->isValid());
104 QVERIFY(ma->isValid());
105 QVERIFY(ma->path().length() > 1);
107 mm = new OfonoModem(OfonoModem::ManualSelect, "/phonesim", this);
108 if (!mm->powered()) {
109 mm->setPowered(true);
118 void testOfonoModemPowercycle()
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 &)));
133 mm->setOnline(false);
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);
151 mm->setPowered(false);
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);
171 QCOMPARE(onlineFailed.count(), 1);
172 onlineFailed.takeFirst();
174 mm->setPowered(true);
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);
187 QCOMPARE(revision.count(), 1);
188 revision.takeFirst();
189 QCOMPARE(serial.count(), 1);
191 QVERIFY(features.count() > 0);
192 QVERIFY(features.takeLast().at(0).toStringList().count() > 0);
194 QVERIFY(interfaces.count() > 0);
195 QVERIFY(interfaces.takeLast().at(0).toStringList().count() > 0);
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);
218 void cleanupTestCase()
229 QTEST_MAIN(TestOfonoModem)
230 #include "test_ofonomodem.moc"