summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libconninet/tests/ut_iapconf.cpp
blob: 6a91d61a0d87e4d41632a35cdd0c930dc33b9bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
  libconninet - Internet Connectivity support library

  Copyright (C) 2009 Nokia Corporation. All rights reserved.

  Contact: Aapo Makela <aapo.makela@nokia.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License
  version 2.1 as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  02110-1301 USA
*/


#include <QtTest/QtTest>
#include <QDebug>

#include <iapconf.h>

class Ut_IAPConf : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void init();
    void cleanup();
    void initTestCase();
    void cleanupTestCase();

    void setupIAP();
    void setupIAPContainingDot();
    void unsetIAPValueIsNotValid();
    void verifyAllIAPs();
    void allForEmptyConfReturnsEmptyList();
    void settingInvalidValueUnsetsKey();

private:
    Maemo::IAPConf *mSubject;
};

void Ut_IAPConf::init()
{
    mSubject = new Maemo::IAPConf("test_iap");
}

void Ut_IAPConf::cleanup()
{
    // Clear made settings
    mSubject->clear();

    delete mSubject;
    mSubject = 0;
}

void Ut_IAPConf::initTestCase()
{
} 

void Ut_IAPConf::cleanupTestCase()
{
}

void Ut_IAPConf::setupIAP()
{
    // Set bunch of values
    mSubject->set("ipv4_type", "AUTO",
                  "wlan_wepkey1", "connt",
                  "wlan_wepdefkey", 1,
                  "wlan_ssid", QByteArray("CONNTEST-1"));

    // Set one value
    mSubject->setValue("type", "WLAN_INFRA");

    // Check all values that they were set correctly
    QVERIFY(mSubject->value("ipv4_type").toString() == "AUTO");
    QVERIFY(mSubject->value("wlan_wepkey1").toString() == "connt");
    QVERIFY(mSubject->value("wlan_wepdefkey").toInt() == 1);
    QVERIFY(mSubject->value("wlan_ssid").toByteArray() == QByteArray("CONNTEST-1"));
    QVERIFY(mSubject->value("type").toString() == "WLAN_INFRA");
}

void Ut_IAPConf::setupIAPContainingDot()
{
    delete mSubject;
    mSubject = new Maemo::IAPConf("test.iap");

    // Set and check one value
    mSubject->setValue("type", "DUMMY");
    QVERIFY(mSubject->value("type").toString() == "DUMMY");
}

void Ut_IAPConf::unsetIAPValueIsNotValid()
{
    QVariant invalidValue = mSubject->value("this_value_does_not_exist");
    QVERIFY(invalidValue.isValid() == false);
}

void Ut_IAPConf::verifyAllIAPs()
{
    int count = 0, extras = 0;
    QRegExp regexp("iap[1-3]");
    Maemo::IAPConf iap1("iap1");
    Maemo::IAPConf iap2("iap2");
    Maemo::IAPConf iap3("iap3");

    iap1.clear();
    iap2.clear();
    iap3.clear();

    iap1.setValue("name", "iap1");
    iap2.setValue("name", "iap2");
    iap3.setValue("name", "iap3");

    count = extras = 0;
    QList<QString> iaps;
    Maemo::IAPConf::getAll(iaps, true);
    foreach (QString iap_path, iaps) {
        QString iap_id = iap_path.section('/', 5);  /* This is the IAP id */
	if (!iap_id.contains(regexp)) {
	    extras++;
	    continue;
	}
	Maemo::IAPConf iap(iap_id);
	QString name = iap.value("name").toString();
	QVERIFY(name == iap_id);
	count++;
    }
    QCOMPARE(count, iaps.size()-extras);

    iap1.clear();
    iap2.clear();
    iap3.clear();

    iap1.setValue("name", "iap1");
    iap2.setValue("name", "iap2");
    iap3.setValue("name", "iap3");

    count = extras = 0;
    Maemo::IAPConf::getAll(iaps);
    foreach (QString iap_id, iaps) {
        if (!iap_id.contains(regexp)) {
	    extras++;
	    continue;
	}
	Maemo::IAPConf iap(iap_id);
	QString name = iap.value("name").toString();
	QVERIFY(name == iap_id);
	count++;
    }
    QCOMPARE(count, iaps.size()-extras);
}

void Ut_IAPConf::allForEmptyConfReturnsEmptyList()
{
    // Clear everything in configuration
    mSubject->clearAll();

    // Get all for a list and check that it is empty
    QStringList iaps;
    mSubject->getAll(iaps);
    QVERIFY(iaps.isEmpty());
}

void Ut_IAPConf::settingInvalidValueUnsetsKey()
{
    // Setup some IAP
    setupIAP();

    // Set invalid value to unset "wlan_wepdefkey" key and verify that the
    // value is unset
    mSubject->setValue("wlan_wepdefkey", QVariant());
    QVERIFY(!mSubject->value("wlan_wepdefkey").isValid());
}

QTEST_MAIN(Ut_IAPConf)

#include "ut_iapconf.moc"