2 * This file is part of ofono-qt
4 * Copyright (C) 2011 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 <ofonoconnman.h>
28 #include <ofonoconnmancontext.h>
32 class TestOfonoConnmanContext : public QObject
39 m = new OfonoConnMan(OfonoModem::ManualSelect, "/phonesim", this);
40 QCOMPARE(m->modem()->isValid(), true);
41 if (!m->modem()->powered()) {
42 m->modem()->setPowered(true);
45 if (!m->modem()->online()) {
46 m->modem()->setOnline(true);
49 QCOMPARE(m->isValid(), true);
52 void testOfonoConnmanContext ()
54 QSignalSpy addcon(m,SIGNAL(addContextComplete(bool)));
55 QSignalSpy conadd(m, SIGNAL(contextAdded(const QString&)));
56 QSignalSpy conrem(m, SIGNAL(contextRemoved(const QString&)));
58 m->addContext("internet");
61 QCOMPARE(addcon.count(), 1);
62 QCOMPARE(addcon.takeFirst().at(0).toBool(),true);
63 QCOMPARE(conadd.count(), 1);
64 QString contextid = conadd.takeFirst().at(0).toString();
66 OfonoConnmanContext* context = new OfonoConnmanContext(contextid);
68 QSignalSpy active(context, SIGNAL(activeChanged(const bool)));
69 QSignalSpy apn(context,SIGNAL(accessPointNameChanged(const QString&)));
70 QSignalSpy name(context, SIGNAL(nameChanged(const QString&)));
71 QSignalSpy type (context, SIGNAL(typeChanged(const QString&)));
72 QSignalSpy uname (context, SIGNAL(usernameChanged(const QString&)));
73 QSignalSpy pw (context, SIGNAL(passwordChanged(const QString&)));
74 QSignalSpy proto (context, SIGNAL(protocolChanged(const QString&)));
75 QSignalSpy sett (context, SIGNAL(settingsChanged(const QVariantMap&)));
76 QSignalSpy sett6 (context, SIGNAL(IPv6SettingsChanged(const QVariantMap&)));
78 context->setAccessPointName("hyva");
80 context->setUsername("huomenta");
82 context->setPassword("HYVA");
84 context->setName("yota");
86 context->setType("mms");
88 context->setProtocol("ipv6");
91 context->setActive(true);
94 QCOMPARE(apn.count(),1);
95 QCOMPARE(apn.takeFirst().at(0).toString(),QString("hyva"));
96 QCOMPARE(uname.count(),1);
97 QCOMPARE(uname.takeFirst().at(0).toString(),QString("huomenta"));
98 QCOMPARE(pw.count(),1);
99 QCOMPARE(pw.takeFirst().at(0).toString(),QString("HYVA"));
100 QCOMPARE(name.count(),1);
101 QCOMPARE(name.takeFirst().at(0).toString(),QString("yota"));
102 QCOMPARE(type.count(),1);
103 QCOMPARE(type.takeFirst().at(0).toString(),QString("mms"));
104 QCOMPARE(sett.count(),0);
105 QCOMPARE(sett6.count(),1);
106 QVariantMap settings = context->IPv6Settings();
107 QCOMPARE(settings["Interface"].value<QString>().left(5),QString("dummy")); // "dummy" plus number
108 QCOMPARE(proto.count(),1);
109 QCOMPARE(proto.takeFirst().at(0).toString(),QString("ipv6"));
110 QCOMPARE(active.count(),1);
111 QCOMPARE(context->active(),true);
112 context->setActive(false);
116 m->removeContext(contextid);
118 QCOMPARE(active.count(),2);
119 QCOMPARE(sett.count(),0);
120 QCOMPARE(sett6.count(),2);
121 QCOMPARE(conrem.count(), 1);
125 void cleanupTestCase()
134 QTEST_MAIN(TestOfonoConnmanContext)
135 #include "test_ofonoconnmancontext.moc"