|
1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This is the source file for Connection Utilities test context. |
|
16 */ |
|
17 |
|
18 #include <QObject> |
|
19 #include <QSharedPointer> |
|
20 #include <QTest> |
|
21 #include <rconnmon.h> |
|
22 #include <nifvar.h> |
|
23 #include <cmmanager_shim.h> |
|
24 |
|
25 #include "wlanqtutils.h" |
|
26 #include "wlanqtutilstestcontext.h" |
|
27 #include "wlanqtutilsap.h" |
|
28 #include "wlanqtutilsconnection.h" |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // class WlanQtUtilsCtxEsock |
|
32 // --------------------------------------------------------- |
|
33 |
|
34 WlanQtUtilsCtxEsock::WlanQtUtilsCtxEsock() : |
|
35 startRetValue_(KErrNone) |
|
36 { |
|
37 } |
|
38 |
|
39 WlanQtUtilsCtxEsock::~WlanQtUtilsCtxEsock() |
|
40 { |
|
41 } |
|
42 |
|
43 void WlanQtUtilsCtxEsock::initialize() |
|
44 { |
|
45 startRetValue_ = KErrNone; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // class WlanQtUtilsCtxActiveConn |
|
50 // --------------------------------------------------------- |
|
51 |
|
52 WlanQtUtilsCtxActiveConn::WlanQtUtilsCtxActiveConn() : |
|
53 WlanQtUtilsConnection(), connMonBearerType_(EBearerUnknown), connMonConnectionStatus_( |
|
54 KConnectionUninitialised), connMonWlanConnectionMode_(-1), connMonWlanSecurityMode_(-1), |
|
55 applicationUids_() |
|
56 { |
|
57 } |
|
58 |
|
59 WlanQtUtilsCtxActiveConn::~WlanQtUtilsCtxActiveConn() |
|
60 { |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------- |
|
64 // class WlanQtUtilsCtxActiveConnections |
|
65 // --------------------------------------------------------- |
|
66 |
|
67 WlanQtUtilsCtxActiveConnections::WlanQtUtilsCtxActiveConnections() : |
|
68 activeConnList_() |
|
69 { |
|
70 } |
|
71 |
|
72 WlanQtUtilsCtxActiveConnections::~WlanQtUtilsCtxActiveConnections() |
|
73 { |
|
74 clearActiveConnList(); |
|
75 } |
|
76 |
|
77 void WlanQtUtilsCtxActiveConnections::initialize() |
|
78 { |
|
79 clearActiveConnList(); |
|
80 } |
|
81 |
|
82 void WlanQtUtilsCtxActiveConnections::createDefaultActiveConnList(int numberOfActiveConns, |
|
83 int firstIapId) |
|
84 { |
|
85 clearActiveConnList(); |
|
86 for (int i = 0; i < numberOfActiveConns; i++) { |
|
87 WlanQtUtilsCtxActiveConn *activeConn = new WlanQtUtilsCtxActiveConn(); |
|
88 |
|
89 activeConn->setConnectionId((i + 1) * 100); |
|
90 activeConn->setIapId(firstIapId + i); |
|
91 activeConn->connMonConnectionStatus_ = KLinkLayerOpen; |
|
92 activeConn->setConnectionStatus(WlanQtUtils::ConnStatusConnected); |
|
93 |
|
94 // WLAN connection. |
|
95 activeConn->connMonBearerType_ = EBearerWLAN; |
|
96 activeConn->connMonWlanSecurityMode_ = EConnMonSecurityOpen; |
|
97 activeConn->connMonWlanConnectionMode_ = EConnMonInfraStructure; |
|
98 activeConnList_.append(activeConn); |
|
99 } |
|
100 } |
|
101 |
|
102 void WlanQtUtilsCtxActiveConnections::clearActiveConnList() |
|
103 { |
|
104 Q_FOREACH(WlanQtUtilsCtxActiveConn* activeConn, activeConnList_) |
|
105 { |
|
106 delete activeConn; |
|
107 } |
|
108 activeConnList_.clear(); |
|
109 } |
|
110 |
|
111 void WlanQtUtilsCtxActiveConnections::verifyActiveConnList( |
|
112 QList<WlanQtUtilsConnection*> activeConnList) |
|
113 { |
|
114 QCOMPARE(activeConnList.count(), activeConnList_.count()); |
|
115 |
|
116 for (int i = 0; i < activeConnList_.count(); i++) { |
|
117 QCOMPARE(activeConnList[i]->connectionId(), activeConnList_[i]->connectionId()); |
|
118 QCOMPARE(activeConnList[i]->iapId(), activeConnList_[i]->iapId()); |
|
119 QCOMPARE(activeConnList[i]->connectionStatus(), activeConnList_[i]->connectionStatus()); |
|
120 } |
|
121 } |
|
122 |
|
123 WlanQtUtilsCtxActiveConn *WlanQtUtilsCtxActiveConnections::findActiveConn(uint connectionId) const |
|
124 { |
|
125 WlanQtUtilsCtxActiveConn *activeConn = NULL; |
|
126 for (int i = 0; i < activeConnList_.count(); i++) { |
|
127 if (activeConnList_[i]->connectionId() == connectionId) { |
|
128 activeConn = activeConnList_[i]; |
|
129 } |
|
130 } |
|
131 Q_ASSERT(activeConn != NULL); |
|
132 return activeConn; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------- |
|
136 // class WlanQtUtilsWlanScanResult |
|
137 // --------------------------------------------------------- |
|
138 |
|
139 WlanQtUtilsWlanScanResult::WlanQtUtilsWlanScanResult() : |
|
140 wlanScanResultList_(), |
|
141 completeWlanScan_(true), |
|
142 scanRetValue_(KErrNone) |
|
143 { |
|
144 } |
|
145 |
|
146 WlanQtUtilsWlanScanResult::~WlanQtUtilsWlanScanResult() |
|
147 { |
|
148 clearWlanScanResultList(); |
|
149 } |
|
150 |
|
151 void WlanQtUtilsWlanScanResult::initialize() |
|
152 { |
|
153 clearWlanScanResultList(); |
|
154 completeWlanScan_ = true; |
|
155 scanRetValue_ = KErrNone; |
|
156 } |
|
157 |
|
158 void WlanQtUtilsWlanScanResult::createDefaultWlanScanResultList(int numberOfWlanAps) |
|
159 { |
|
160 clearWlanScanResultList(); |
|
161 for (int i = 0; i < numberOfWlanAps; i++) { |
|
162 WlanQtUtilsAp *ap = new WlanQtUtilsAp(); |
|
163 ap->setValue(WlanQtUtilsAp::ConfIdSsid, "TestWlanAp" + QString::number(i + 1)); |
|
164 ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 20); |
|
165 ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra); |
|
166 ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen); |
|
167 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false); |
|
168 // TODO: Create constructor to WlanQtUtilsWlanAp which takes all member variables as parameter. |
|
169 wlanScanResultList_.append(ap); |
|
170 } |
|
171 } |
|
172 |
|
173 void WlanQtUtilsWlanScanResult::clearWlanScanResultList() |
|
174 { |
|
175 Q_FOREACH(WlanQtUtilsAp* ap, wlanScanResultList_) |
|
176 { |
|
177 delete ap; |
|
178 } |
|
179 wlanScanResultList_.clear(); |
|
180 } |
|
181 |
|
182 void WlanQtUtilsWlanScanResult::verifyWlanScanResultList( |
|
183 QList<QSharedPointer<WlanQtUtilsAp> > wlanApList) |
|
184 { |
|
185 QCOMPARE(wlanApList.count(), wlanScanResultList_.count()); |
|
186 |
|
187 for (int i = 0; i < wlanScanResultList_.count(); i++) { |
|
188 QCOMPARE(wlanApList[i]->value(WlanQtUtilsAp::ConfIdSsid), |
|
189 wlanScanResultList_[i]->value(WlanQtUtilsAp::ConfIdSsid)); |
|
190 QCOMPARE(wlanApList[i]->value(WlanQtUtilsAp::ConfIdSignalStrength), |
|
191 wlanScanResultList_[i]->value(WlanQtUtilsAp::ConfIdSignalStrength)); |
|
192 QCOMPARE(wlanApList[i]->value(WlanQtUtilsAp::ConfIdConnectionMode), |
|
193 wlanScanResultList_[i]->value(WlanQtUtilsAp::ConfIdConnectionMode)); |
|
194 QCOMPARE(wlanApList[i]->value(WlanQtUtilsAp::ConfIdSecurityMode), |
|
195 wlanScanResultList_[i]->value(WlanQtUtilsAp::ConfIdSecurityMode)); |
|
196 QCOMPARE(wlanApList[i]->value(WlanQtUtilsAp::ConfIdWpaPskUse), |
|
197 wlanScanResultList_[i]->value(WlanQtUtilsAp::ConfIdWpaPskUse)); |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // class WlanQtUtilsCtxConnMon |
|
203 // --------------------------------------------------------- |
|
204 |
|
205 WlanQtUtilsCtxConnMon::WlanQtUtilsCtxConnMon() : |
|
206 wlanScanResult_() |
|
207 { |
|
208 } |
|
209 |
|
210 WlanQtUtilsCtxConnMon::~WlanQtUtilsCtxConnMon() |
|
211 { |
|
212 } |
|
213 |
|
214 void WlanQtUtilsCtxConnMon::initialize() |
|
215 { |
|
216 wlanScanResult_.initialize(); |
|
217 activeConnections_.initialize(); |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------- |
|
221 // class WlanQtUtilsCtxIct |
|
222 // --------------------------------------------------------- |
|
223 |
|
224 WlanQtUtilsCtxIct::WlanQtUtilsCtxIct() |
|
225 { |
|
226 } |
|
227 |
|
228 WlanQtUtilsCtxIct::~WlanQtUtilsCtxIct() |
|
229 { |
|
230 } |
|
231 |
|
232 void WlanQtUtilsCtxIct::initialize() |
|
233 { |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // class WlanQtUtilsTestContext |
|
238 // --------------------------------------------------------- |
|
239 |
|
240 WlanQtUtilsTestContext::WlanQtUtilsTestContext() : |
|
241 esock_(), connMon_(), ict_() |
|
242 { |
|
243 } |
|
244 |
|
245 WlanQtUtilsTestContext::~WlanQtUtilsTestContext() |
|
246 { |
|
247 } |
|
248 |
|
249 void WlanQtUtilsTestContext::initialize() |
|
250 { |
|
251 esock_.initialize(); |
|
252 connMon_.initialize(); |
|
253 ict_.initialize(); |
|
254 } |