|
1 /* |
|
2 libconninet - Internet Connectivity support library |
|
3 |
|
4 Copyright (C) 2009 Nokia Corporation. All rights reserved. |
|
5 |
|
6 Contact: Aapo Makela <aapo.makela@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 <QDebug> |
|
26 |
|
27 #include <iapconf.h> |
|
28 |
|
29 class Ut_IAPConf : public QObject |
|
30 { |
|
31 Q_OBJECT |
|
32 |
|
33 private Q_SLOTS: |
|
34 void init(); |
|
35 void cleanup(); |
|
36 void initTestCase(); |
|
37 void cleanupTestCase(); |
|
38 |
|
39 void setupIAP(); |
|
40 void setupIAPContainingDot(); |
|
41 void unsetIAPValueIsNotValid(); |
|
42 void verifyAllIAPs(); |
|
43 void allForEmptyConfReturnsEmptyList(); |
|
44 void settingInvalidValueUnsetsKey(); |
|
45 |
|
46 private: |
|
47 Maemo::IAPConf *mSubject; |
|
48 }; |
|
49 |
|
50 void Ut_IAPConf::init() |
|
51 { |
|
52 mSubject = new Maemo::IAPConf("test_iap"); |
|
53 } |
|
54 |
|
55 void Ut_IAPConf::cleanup() |
|
56 { |
|
57 // Clear made settings |
|
58 mSubject->clear(); |
|
59 |
|
60 delete mSubject; |
|
61 mSubject = 0; |
|
62 } |
|
63 |
|
64 void Ut_IAPConf::initTestCase() |
|
65 { |
|
66 } |
|
67 |
|
68 void Ut_IAPConf::cleanupTestCase() |
|
69 { |
|
70 } |
|
71 |
|
72 void Ut_IAPConf::setupIAP() |
|
73 { |
|
74 // Set bunch of values |
|
75 mSubject->set("ipv4_type", "AUTO", |
|
76 "wlan_wepkey1", "connt", |
|
77 "wlan_wepdefkey", 1, |
|
78 "wlan_ssid", QByteArray("CONNTEST-1")); |
|
79 |
|
80 // Set one value |
|
81 mSubject->setValue("type", "WLAN_INFRA"); |
|
82 |
|
83 // Check all values that they were set correctly |
|
84 QVERIFY(mSubject->value("ipv4_type").toString() == "AUTO"); |
|
85 QVERIFY(mSubject->value("wlan_wepkey1").toString() == "connt"); |
|
86 QVERIFY(mSubject->value("wlan_wepdefkey").toInt() == 1); |
|
87 QVERIFY(mSubject->value("wlan_ssid").toByteArray() == QByteArray("CONNTEST-1")); |
|
88 QVERIFY(mSubject->value("type").toString() == "WLAN_INFRA"); |
|
89 } |
|
90 |
|
91 void Ut_IAPConf::setupIAPContainingDot() |
|
92 { |
|
93 delete mSubject; |
|
94 mSubject = new Maemo::IAPConf("test.iap"); |
|
95 |
|
96 // Set and check one value |
|
97 mSubject->setValue("type", "DUMMY"); |
|
98 QVERIFY(mSubject->value("type").toString() == "DUMMY"); |
|
99 } |
|
100 |
|
101 void Ut_IAPConf::unsetIAPValueIsNotValid() |
|
102 { |
|
103 QVariant invalidValue = mSubject->value("this_value_does_not_exist"); |
|
104 QVERIFY(invalidValue.isValid() == false); |
|
105 } |
|
106 |
|
107 void Ut_IAPConf::verifyAllIAPs() |
|
108 { |
|
109 int count = 0, extras = 0; |
|
110 QRegExp regexp("iap[1-3]"); |
|
111 Maemo::IAPConf iap1("iap1"); |
|
112 Maemo::IAPConf iap2("iap2"); |
|
113 Maemo::IAPConf iap3("iap3"); |
|
114 |
|
115 iap1.clear(); |
|
116 iap2.clear(); |
|
117 iap3.clear(); |
|
118 |
|
119 iap1.setValue("name", "iap1"); |
|
120 iap2.setValue("name", "iap2"); |
|
121 iap3.setValue("name", "iap3"); |
|
122 |
|
123 count = extras = 0; |
|
124 QList<QString> iaps; |
|
125 Maemo::IAPConf::getAll(iaps, true); |
|
126 foreach (QString iap_path, iaps) { |
|
127 QString iap_id = iap_path.section('/', 5); /* This is the IAP id */ |
|
128 if (!iap_id.contains(regexp)) { |
|
129 extras++; |
|
130 continue; |
|
131 } |
|
132 Maemo::IAPConf iap(iap_id); |
|
133 QString name = iap.value("name").toString(); |
|
134 QVERIFY(name == iap_id); |
|
135 count++; |
|
136 } |
|
137 QCOMPARE(count, iaps.size()-extras); |
|
138 |
|
139 iap1.clear(); |
|
140 iap2.clear(); |
|
141 iap3.clear(); |
|
142 |
|
143 iap1.setValue("name", "iap1"); |
|
144 iap2.setValue("name", "iap2"); |
|
145 iap3.setValue("name", "iap3"); |
|
146 |
|
147 count = extras = 0; |
|
148 Maemo::IAPConf::getAll(iaps); |
|
149 foreach (QString iap_id, iaps) { |
|
150 if (!iap_id.contains(regexp)) { |
|
151 extras++; |
|
152 continue; |
|
153 } |
|
154 Maemo::IAPConf iap(iap_id); |
|
155 QString name = iap.value("name").toString(); |
|
156 QVERIFY(name == iap_id); |
|
157 count++; |
|
158 } |
|
159 QCOMPARE(count, iaps.size()-extras); |
|
160 } |
|
161 |
|
162 void Ut_IAPConf::allForEmptyConfReturnsEmptyList() |
|
163 { |
|
164 // Clear everything in configuration |
|
165 mSubject->clearAll(); |
|
166 |
|
167 // Get all for a list and check that it is empty |
|
168 QStringList iaps; |
|
169 mSubject->getAll(iaps); |
|
170 QVERIFY(iaps.isEmpty()); |
|
171 } |
|
172 |
|
173 void Ut_IAPConf::settingInvalidValueUnsetsKey() |
|
174 { |
|
175 // Setup some IAP |
|
176 setupIAP(); |
|
177 |
|
178 // Set invalid value to unset "wlan_wepdefkey" key and verify that the |
|
179 // value is unset |
|
180 mSubject->setValue("wlan_wepdefkey", QVariant()); |
|
181 QVERIFY(!mSubject->value("wlan_wepdefkey").isValid()); |
|
182 } |
|
183 |
|
184 QTEST_MAIN(Ut_IAPConf) |
|
185 |
|
186 #include "ut_iapconf.moc" |