Merge commit 'refs/merge-requests/1' of gitorious.org:meego-cellular/ofono-qt into...
[profile/ivi/ofono-qt.git] / tests / test_ofonoconnmancontext.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2011 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 <ofonoconnman.h>
28 #include <ofonoconnmancontext.h>
29 #include <QtDebug>
30
31
32 class TestOfonoConnmanContext : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37     void initTestCase()
38     {
39         m = new OfonoConnMan(OfonoModem::ManualSelect, "/phonesim", this);
40         QCOMPARE(m->modem()->isValid(), true);
41         if (!m->modem()->powered()) {
42             m->modem()->setPowered(true);
43             QTest::qWait(5000);
44         }
45         if (!m->modem()->online()) {
46             m->modem()->setOnline(true);
47             QTest::qWait(5000);
48         }
49         QCOMPARE(m->isValid(), true);
50     }
51
52     void testOfonoConnmanContext ()
53     {
54         QSignalSpy addcon(m,SIGNAL(addContextComplete(bool)));
55         QSignalSpy conadd(m, SIGNAL(contextAdded(const QString&)));
56         QSignalSpy conrem(m, SIGNAL(contextRemoved(const QString&)));
57
58         m->addContext("internet");
59         QTest::qWait(1000);
60
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();
65
66         OfonoConnmanContext* context = new OfonoConnmanContext(contextid);
67
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&)));
77
78         context->setAccessPointName("hyva");
79         QTest::qWait(5000);
80         context->setUsername("huomenta");
81         QTest::qWait(5000);
82         context->setPassword("HYVA");
83         QTest::qWait(5000);
84         context->setName("yota");
85         QTest::qWait(5000);
86         context->setType("mms");
87         QTest::qWait(5000);
88         context->setProtocol("ipv6");
89         QTest::qWait(5000);
90
91         context->setActive(true);
92         QTest::qWait(10000);
93
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>(),QString("dummy0"));
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);
113         QTest::qWait(5000);
114         delete context;
115         QTest::qWait(5000);
116         m->removeContext(contextid);
117         QTest::qWait(5000);
118         QCOMPARE(active.count(),2);
119         QCOMPARE(sett.count(),0);
120         QCOMPARE(sett6.count(),2);
121         QCOMPARE(conrem.count(), 1);
122
123     }
124
125     void cleanupTestCase()
126     {
127
128     }
129
130 private:
131     OfonoConnMan *m;
132 };
133
134 QTEST_MAIN(TestOfonoConnmanContext)
135 #include "test_ofonoconnmancontext.moc"