|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 #include "../qbearertestcommon.h" |
|
44 #include "qnetworkconfiguration.h" |
|
45 #include "qnetworkconfigmanager.h" |
|
46 |
|
47 #ifdef Q_WS_MAEMO_6 |
|
48 #include <stdio.h> |
|
49 #include <iapconf.h> |
|
50 #endif |
|
51 |
|
52 QTM_USE_NAMESPACE |
|
53 class tst_QNetworkConfiguration : public QObject |
|
54 { |
|
55 Q_OBJECT |
|
56 |
|
57 public slots: |
|
58 void initTestCase(); |
|
59 void cleanupTestCase(); |
|
60 |
|
61 private slots: |
|
62 void invalidPoint(); |
|
63 void comparison(); |
|
64 void children(); |
|
65 void isRoamingAvailable(); |
|
66 |
|
67 private: |
|
68 #ifdef Q_WS_MAEMO_6 |
|
69 Maemo::IAPConf *iapconf; |
|
70 Maemo::IAPConf *iapconf2; |
|
71 Maemo::IAPConf *gprsiap; |
|
72 #define MAX_IAPS 50 |
|
73 Maemo::IAPConf *iaps[MAX_IAPS]; |
|
74 QProcess *icd_stub; |
|
75 #endif |
|
76 }; |
|
77 |
|
78 void tst_QNetworkConfiguration::initTestCase() |
|
79 { |
|
80 #ifdef Q_WS_MAEMO_6 |
|
81 iapconf = new Maemo::IAPConf("007"); |
|
82 iapconf->setValue("ipv4_type", "AUTO"); |
|
83 iapconf->setValue("wlan_wepkey1", "connt"); |
|
84 iapconf->setValue("wlan_wepdefkey", 1); |
|
85 iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); |
|
86 iapconf->setValue("name", "James Bond"); |
|
87 iapconf->setValue("type", "WLAN_INFRA"); |
|
88 |
|
89 iapconf2 = new Maemo::IAPConf("osso.net"); |
|
90 iapconf2->setValue("ipv4_type", "AUTO"); |
|
91 iapconf2->setValue("wlan_wepkey1", "osso.net"); |
|
92 iapconf2->setValue("wlan_wepdefkey", 1); |
|
93 iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); |
|
94 iapconf2->setValue("name", "osso.net"); |
|
95 iapconf2->setValue("type", "WLAN_INFRA"); |
|
96 iapconf2->setValue("wlan_security", "WEP"); |
|
97 |
|
98 gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); |
|
99 gprsiap->setValue("ask_password", false); |
|
100 gprsiap->setValue("gprs_accesspointname", "internet"); |
|
101 gprsiap->setValue("gprs_password", ""); |
|
102 gprsiap->setValue("gprs_username", ""); |
|
103 gprsiap->setValue("ipv4_autodns", true); |
|
104 gprsiap->setValue("ipv4_type", "AUTO"); |
|
105 gprsiap->setValue("sim_imsi", "244070123456789"); |
|
106 gprsiap->setValue("name", "MI6"); |
|
107 gprsiap->setValue("type", "GPRS"); |
|
108 |
|
109 /* Create large number of IAPs in the gconf and see what happens */ |
|
110 fflush(stdout); |
|
111 printf("Creating %d IAPS: ", MAX_IAPS); |
|
112 for (int i=0; i<MAX_IAPS; i++) { |
|
113 QString num = QString().sprintf("%d", i); |
|
114 QString iap = "iap-" + num; |
|
115 iaps[i] = new Maemo::IAPConf(iap); |
|
116 iaps[i]->setValue("name", QString("test-iap-")+num); |
|
117 iaps[i]->setValue("type", "WLAN_INFRA"); |
|
118 iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); |
|
119 iaps[i]->setValue("wlan_security", "WPA_PSK"); |
|
120 iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); |
|
121 printf("."); |
|
122 fflush(stdout); |
|
123 } |
|
124 printf("\n"); |
|
125 fflush(stdout); |
|
126 |
|
127 icd_stub = new QProcess(this); |
|
128 icd_stub->start("/usr/bin/icd2_stub.py"); |
|
129 QTest::qWait(1000); |
|
130 |
|
131 // Add a known network to scan list that icd2 stub returns |
|
132 QProcess dbus_send; |
|
133 // 007 network |
|
134 dbus_send.start("dbus-send --type=method_call --system " |
|
135 "--dest=com.nokia.icd2 /com/nokia/icd2 " |
|
136 "com.nokia.icd2.testing.add_available_network " |
|
137 "string:'' uint32:0 string:'' " |
|
138 "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); |
|
139 dbus_send.waitForFinished(); |
|
140 |
|
141 // osso.net network |
|
142 dbus_send.start("dbus-send --type=method_call --system " |
|
143 "--dest=com.nokia.icd2 /com/nokia/icd2 " |
|
144 "com.nokia.icd2.testing.add_available_network " |
|
145 "string:'' uint32:0 string:'' " |
|
146 "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); |
|
147 dbus_send.waitForFinished(); |
|
148 #endif |
|
149 } |
|
150 |
|
151 void tst_QNetworkConfiguration::cleanupTestCase() |
|
152 { |
|
153 #ifdef Q_WS_MAEMO_6 |
|
154 iapconf->clear(); |
|
155 delete iapconf; |
|
156 iapconf2->clear(); |
|
157 delete iapconf2; |
|
158 gprsiap->clear(); |
|
159 delete gprsiap; |
|
160 |
|
161 printf("Deleting %d IAPS : ", MAX_IAPS); |
|
162 for (int i=0; i<MAX_IAPS; i++) { |
|
163 iaps[i]->clear(); |
|
164 delete iaps[i]; |
|
165 printf("."); |
|
166 fflush(stdout); |
|
167 } |
|
168 printf("\n"); |
|
169 qDebug() << "Deleted" << MAX_IAPS << "IAPs"; |
|
170 |
|
171 // Terminate icd2 stub |
|
172 icd_stub->terminate(); |
|
173 icd_stub->waitForFinished(); |
|
174 #endif |
|
175 } |
|
176 |
|
177 void tst_QNetworkConfiguration::invalidPoint() |
|
178 { |
|
179 QNetworkConfiguration pt; |
|
180 |
|
181 QVERIFY(pt.name().isEmpty()); |
|
182 QVERIFY(!pt.isValid()); |
|
183 QVERIFY(pt.type() == QNetworkConfiguration::Invalid); |
|
184 QVERIFY(!(pt.state() & QNetworkConfiguration::Defined)); |
|
185 QVERIFY(!(pt.state() & QNetworkConfiguration::Discovered)); |
|
186 QVERIFY(!(pt.state() & QNetworkConfiguration::Active)); |
|
187 QVERIFY(!pt.isRoamingAvailable()); |
|
188 |
|
189 QNetworkConfiguration pt2(pt); |
|
190 QVERIFY(pt2.name().isEmpty()); |
|
191 QVERIFY(!pt2.isValid()); |
|
192 QVERIFY(pt2.type() == QNetworkConfiguration::Invalid); |
|
193 QVERIFY(!(pt2.state() & QNetworkConfiguration::Defined)); |
|
194 QVERIFY(!(pt2.state() & QNetworkConfiguration::Discovered)); |
|
195 QVERIFY(!(pt2.state() & QNetworkConfiguration::Active)); |
|
196 QVERIFY(!pt2.isRoamingAvailable()); |
|
197 |
|
198 } |
|
199 |
|
200 void tst_QNetworkConfiguration::comparison() |
|
201 { |
|
202 //test copy constructor and assignment operator |
|
203 //compare invalid connection points |
|
204 QNetworkConfiguration pt1; |
|
205 QVERIFY(!pt1.isValid()); |
|
206 QVERIFY(pt1.type() == QNetworkConfiguration::Invalid); |
|
207 |
|
208 QNetworkConfiguration pt2(pt1); |
|
209 QVERIFY(pt1==pt2); |
|
210 QVERIFY(!(pt1!=pt2)); |
|
211 QVERIFY(pt1.name() == pt2.name()); |
|
212 QVERIFY(pt1.isValid() == pt2.isValid()); |
|
213 QVERIFY(pt1.type() == pt2.type()); |
|
214 QVERIFY(pt1.state() == pt2.state()); |
|
215 QVERIFY(pt1.purpose() == pt2.purpose()); |
|
216 |
|
217 |
|
218 QNetworkConfiguration pt3; |
|
219 pt3 = pt1; |
|
220 QVERIFY(pt1==pt3); |
|
221 QVERIFY(!(pt1!=pt3)); |
|
222 QVERIFY(pt1.name() == pt3.name()); |
|
223 QVERIFY(pt1.isValid() == pt3.isValid()); |
|
224 QVERIFY(pt1.type() == pt3.type()); |
|
225 QVERIFY(pt1.state() == pt3.state()); |
|
226 QVERIFY(pt1.purpose() == pt3.purpose()); |
|
227 |
|
228 //test case must run on machine that has valid connection points |
|
229 QNetworkConfigurationManager manager; |
|
230 QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations(); |
|
231 |
|
232 QSignalSpy spy(&manager, SIGNAL(updateCompleted())); |
|
233 manager.updateConfigurations(); //initiate scans |
|
234 QTRY_VERIFY(spy.count() == 1); //wait for scan to complete |
|
235 |
|
236 QList<QNetworkConfiguration> configs = manager.allConfigurations(QNetworkConfiguration::Discovered); |
|
237 QVERIFY(configs.count()); |
|
238 QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); |
|
239 QVERIFY(defaultConfig.isValid()); |
|
240 QVERIFY(defaultConfig.type() != QNetworkConfiguration::Invalid); |
|
241 QVERIFY(!defaultConfig.name().isEmpty()); |
|
242 |
|
243 pt3 = defaultConfig; |
|
244 QVERIFY(defaultConfig==pt3); |
|
245 QVERIFY(!(defaultConfig!=pt3)); |
|
246 QVERIFY(defaultConfig.name() == pt3.name()); |
|
247 QVERIFY(defaultConfig.isValid() == pt3.isValid()); |
|
248 QVERIFY(defaultConfig.type() == pt3.type()); |
|
249 QVERIFY(defaultConfig.state() == pt3.state()); |
|
250 QVERIFY(defaultConfig.purpose() == pt3.purpose()); |
|
251 } |
|
252 |
|
253 void tst_QNetworkConfiguration::children() |
|
254 { |
|
255 QNetworkConfigurationManager manager; |
|
256 QList<QNetworkConfiguration> configs = manager.allConfigurations(); |
|
257 |
|
258 foreach(QNetworkConfiguration c, configs) |
|
259 { |
|
260 if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { |
|
261 qDebug() << "found service network" << c.name() << c.children().count(); |
|
262 QVERIFY(c.isValid()); |
|
263 QList<QNetworkConfiguration> members = c.children(); |
|
264 foreach(QNetworkConfiguration child, members) { |
|
265 QVERIFY(child.isValid()); |
|
266 QVERIFY(configs.contains(child)); |
|
267 qDebug() << "\t" << child.name(); |
|
268 } |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 void tst_QNetworkConfiguration::isRoamingAvailable() |
|
274 { |
|
275 QNetworkConfigurationManager manager; |
|
276 QList<QNetworkConfiguration> configs = manager.allConfigurations(); |
|
277 |
|
278 //force update to get maximum list |
|
279 QSignalSpy spy(&manager, SIGNAL(updateCompleted())); |
|
280 manager.updateConfigurations(); //initiate scans |
|
281 QTRY_VERIFY(spy.count() == 1); //wait for scan to complete |
|
282 |
|
283 foreach(QNetworkConfiguration c, configs) |
|
284 { |
|
285 QVERIFY(QNetworkConfiguration::UserChoice != c.type()); |
|
286 QVERIFY(QNetworkConfiguration::Invalid != c.type()); |
|
287 if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { |
|
288 //cannot test flag as some SNAPs may not support roaming anyway |
|
289 //QVERIFY(c.roamingavailable()) |
|
290 if ( c.children().count() <= 1 ) |
|
291 QVERIFY(!c.isRoamingAvailable()); |
|
292 foreach(QNetworkConfiguration child, c.children()) { |
|
293 QVERIFY(QNetworkConfiguration::InternetAccessPoint == child.type()); |
|
294 QCOMPARE(child.children().count(), 0); |
|
295 } |
|
296 } else { |
|
297 QVERIFY(!c.isRoamingAvailable()); |
|
298 } |
|
299 } |
|
300 } |
|
301 |
|
302 QTEST_MAIN(tst_QNetworkConfiguration) |
|
303 #include "tst_qnetworkconfiguration.moc" |