|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains ESock Test cases from section 11 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 |
|
22 // Test system includes |
|
23 #include "SocketTestSection11.h" |
|
24 |
|
25 |
|
26 // Test step 11.1 |
|
27 const TDesC &CSocketTest11_1::GetTestName() |
|
28 { |
|
29 _LIT(ret,"Test11.1"); |
|
30 return ret; |
|
31 } |
|
32 |
|
33 enum TVerdict CSocketTest11_1::InternalDoTestStepL( void ) |
|
34 { |
|
35 TVerdict verdict = EPass; |
|
36 |
|
37 Logger().WriteFormat(_L("Test Purpose: Successful Socket Transfer")); |
|
38 |
|
39 // connect to esock |
|
40 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
41 RSocketServ ss1; |
|
42 TInt ret = OptimalConnect(ss1); |
|
43 CleanupClosePushL(ss1); |
|
44 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
45 TESTL(KErrNone == ret); |
|
46 |
|
47 Logger().WriteFormat(_L("Creating second connection to socket server")); |
|
48 RSocketServ ss2; |
|
49 ret = OptimalConnect(ss2); |
|
50 CleanupClosePushL(ss2); |
|
51 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
52 TESTL(KErrNone == ret); |
|
53 |
|
54 Logger().WriteFormat(_L("Opening socket on first connection to dummy protocol 1")); |
|
55 RSocket sock1; |
|
56 RSocket tran1; |
|
57 ret = sock1.Open(ss1, _L("Dummy Protocol 1")); |
|
58 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
59 TESTL(KErrNone == ret); |
|
60 |
|
61 Logger().WriteFormat(_L("Getting name of socket")); |
|
62 TName socketname; |
|
63 ret = sock1.Name(socketname); |
|
64 Logger().WriteFormat(_L("Name returned %S, name '%S'"), |
|
65 &EpocErrorToText(ret), &socketname); |
|
66 TESTL(KErrNone == ret); |
|
67 //--------------------------------------------------------------------- |
|
68 //-- if SYMBIAN_NETWORKING_PLATSEC symbol is defined, we are using EKA2 and secured RSocket::Transfer() |
|
69 //-- in this case the transfer shall be enabled by setting appropriate socket option with "pulling" process capabilities |
|
70 |
|
71 //-- define the capabilities set for the socket "pulling" process (this one, actually) |
|
72 //-- this process must have at least NetworkServices and NetworkControl capabilities |
|
73 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl); |
|
74 |
|
75 |
|
76 //-- this transfer attempt shall fail with KErrPermissionDenied because the transfer hasn't been enabled |
|
77 Logger().WriteFormat(_L("Transferring the socket to another session shall fail with KErrPermissionDenied")); |
|
78 ret = tran1.Transfer(ss2, socketname); |
|
79 Logger().WriteFormat(_L("RSocket::Transfer() returned %S"), &EpocErrorToText(ret)); |
|
80 TESTL(KErrPermissionDenied == ret); |
|
81 |
|
82 //-- Test setting new socket options |
|
83 Logger().WriteFormat(_L("Testing setting options KSOEnableTransfer, KSODisableTransfer..")); |
|
84 ret = sock1.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
85 TESTL(KErrNone == ret); |
|
86 |
|
87 ret = sock1.SetOpt(KSODisableTransfer, KSOLSocket); |
|
88 TESTL(KErrNone == ret); |
|
89 |
|
90 //-- this transfer attempt shall also fail, because we set KSOCancelTransfer above |
|
91 ret = tran1.Transfer(ss2, socketname); |
|
92 TESTL(KErrPermissionDenied == ret); |
|
93 Logger().WriteFormat(_L("OK")); |
|
94 |
|
95 //-- enable socket transfer (see lines below) with PlatSec check. Set socket option with receiving process capabilities |
|
96 ret = sock1.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
97 TESTL(KErrNone == ret); |
|
98 |
|
99 |
|
100 //--------------------------------------------------------------------- |
|
101 Logger().WriteFormat(_L("Transferring first socket to second session")); |
|
102 ret = tran1.Transfer(ss2, socketname); |
|
103 Logger().WriteFormat(_L("Transfer returned %S"), &EpocErrorToText(ret)); |
|
104 TESTL(KErrNone == ret); |
|
105 |
|
106 Logger().WriteFormat(_L("Checking Info on first socket fails")); |
|
107 TProtocolDesc protoInfo; |
|
108 ret = sock1.Info(protoInfo); |
|
109 Logger().WriteFormat(_L("Info returned %S"), &EpocErrorToText(ret)); |
|
110 TESTL(KErrBadHandle == ret); |
|
111 sock1.Close(); |
|
112 |
|
113 Logger().WriteFormat(_L("Checking Info on transferred socket")); |
|
114 ret = tran1.Info(protoInfo); |
|
115 Logger().WriteFormat(_L("Info returned %S"), &EpocErrorToText(ret)); |
|
116 TESTL(KErrNone == ret); |
|
117 tran1.Close(); |
|
118 |
|
119 CleanupStack::Pop(&ss2); |
|
120 CleanupStack::Pop(&ss1); |
|
121 |
|
122 ss1.Close(); |
|
123 ss2.Close(); |
|
124 |
|
125 SetTestStepResult(verdict); |
|
126 return verdict; |
|
127 } |
|
128 |
|
129 // Test step 11.2 |
|
130 const TDesC &CSocketTest11_2::GetTestName() |
|
131 { |
|
132 _LIT(ret,"Test11.2"); |
|
133 return ret; |
|
134 } |
|
135 |
|
136 enum TVerdict CSocketTest11_2::InternalDoTestStepL( void ) |
|
137 { |
|
138 TVerdict verdict = EPass; |
|
139 |
|
140 Logger().WriteFormat(_L("Test Purpose: Null Socket Transfer Fails")); |
|
141 |
|
142 // connect to esock |
|
143 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
144 RSocketServ ss1; |
|
145 TInt ret = OptimalConnect(ss1); |
|
146 CleanupClosePushL(ss1); |
|
147 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
148 TESTL(KErrNone == ret); |
|
149 |
|
150 Logger().WriteFormat(_L("Creating second connection to socket server")); |
|
151 RSocketServ ss2; |
|
152 ret = OptimalConnect(ss2); |
|
153 CleanupClosePushL(ss2); |
|
154 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
155 TESTL(KErrNone == ret); |
|
156 |
|
157 Logger().WriteFormat(_L("Opening null socket on second connection")); |
|
158 RSocket sock2; |
|
159 ret = sock2.Open(ss2); |
|
160 CleanupClosePushL(sock2); |
|
161 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
162 TESTL(KErrNone == ret); |
|
163 |
|
164 Logger().WriteFormat(_L("Getting name of socket")); |
|
165 TName socketname; |
|
166 ret = sock2.Name(socketname); |
|
167 Logger().WriteFormat(_L("Name returned %S, name '%S'"), |
|
168 &EpocErrorToText(ret), &socketname); |
|
169 TESTL(KErrNone == ret); |
|
170 |
|
171 //--------------------------------------------------------------------- |
|
172 //-- if SYMBIAN_NETWORKING_PLATSEC symbol is defined, we are using EKA2 and secured RSocket::Transfer() |
|
173 //-- in this case the transfer shall be enabled by setting appropriate socket option with "pulling" process capabilities |
|
174 |
|
175 //-- define the capabilities set for the socket "pulling" process (this one, actually) |
|
176 //-- this process must have at least NetworkServices and NetworkControl capabilities |
|
177 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl); |
|
178 |
|
179 //-- enable socket transfer (see lines below) with PlatSec check. Set socket option with receiving process capabilities |
|
180 ret = sock2.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
181 TESTL(KErrNotReady == ret); |
|
182 |
|
183 |
|
184 //--------------------------------------------------------------------- |
|
185 |
|
186 Logger().WriteFormat(_L("Attempting to transfer second socket")); |
|
187 RSocket tran2; |
|
188 ret = tran2.Transfer(ss1, socketname); |
|
189 CleanupClosePushL(tran2); |
|
190 Logger().WriteFormat(_L("Transfer returned %S"), &EpocErrorToText(ret)); |
|
191 TESTL(KErrPermissionDenied == ret); |
|
192 |
|
193 Logger().WriteFormat(_L("Checking Info on second socket fails")); |
|
194 TProtocolDesc protoInfo; |
|
195 ret = sock2.Info(protoInfo); |
|
196 Logger().WriteFormat(_L("Info returned %S"), &EpocErrorToText(ret)); |
|
197 TESTL(KErrNotFound == ret); |
|
198 |
|
199 CleanupStack::Pop(&tran2); |
|
200 CleanupStack::Pop(&sock2); |
|
201 CleanupStack::Pop(&ss2); |
|
202 CleanupStack::Pop(&ss1); |
|
203 |
|
204 ss1.Close(); |
|
205 sock2.Close(); |
|
206 tran2.Close(); |
|
207 ss2.Close(); |
|
208 |
|
209 SetTestStepResult(verdict); |
|
210 return verdict; |
|
211 } |
|
212 |
|
213 // Test step 11.3 |
|
214 const TDesC &CSocketTest11_3::GetTestName() |
|
215 { |
|
216 _LIT(ret,"Test11.3"); |
|
217 return ret; |
|
218 } |
|
219 |
|
220 enum TVerdict CSocketTest11_3::InternalDoTestStepL( void ) |
|
221 { |
|
222 TVerdict verdict = EPass; |
|
223 |
|
224 Logger().WriteFormat(_L("Test Purpose: Successful Transfer from Main dealer to other dealer")); |
|
225 |
|
226 // connect to esock |
|
227 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
228 RSocketServ ss1; |
|
229 TInt ret = ss1.Connect(); |
|
230 CleanupClosePushL(ss1); |
|
231 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
232 TESTL(KErrNone == ret); |
|
233 |
|
234 Logger().WriteFormat(_L("Creating second optimal connection to socket server")); |
|
235 RSocketServ ss2; |
|
236 ret = OptimalConnect(ss2); |
|
237 CleanupClosePushL(ss2); |
|
238 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
239 TESTL(KErrNone == ret); |
|
240 |
|
241 Logger().WriteFormat(_L("Opening null socket on second connection")); |
|
242 RSocket sock1; |
|
243 ret = sock1.Open(ss2,_L("Dummy Protocol 1")); |
|
244 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
245 TESTL(KErrNone == ret); |
|
246 |
|
247 Logger().WriteFormat(_L("Getting name of socket")); |
|
248 TName socketname; |
|
249 ret = sock1.Name(socketname); |
|
250 Logger().WriteFormat(_L("Name returned %S, name '%S'"), |
|
251 &EpocErrorToText(ret), &socketname); |
|
252 TESTL(KErrNone == ret); |
|
253 |
|
254 //--------------------------------------------------------------------- |
|
255 //-- if SYMBIAN_NETWORKING_PLATSEC symbol is defined, we are using EKA2 and secured RSocket::Transfer() |
|
256 //-- in this case the transfer shall be enabled by setting appropriate socket option with "pulling" process capabilities |
|
257 |
|
258 //-- define the capabilities set for the socket "pulling" process (this one, actually) |
|
259 //-- this process must have at least NetworkServices and NetworkControl capabilities |
|
260 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl); |
|
261 |
|
262 //-- enable socket transfer (see lines below) with PlatSec check. Set socket option with receiving process capabilities |
|
263 ret = sock1.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
264 TESTL(KErrNone == ret); |
|
265 |
|
266 |
|
267 //--------------------------------------------------------------------- |
|
268 |
|
269 Logger().WriteFormat(_L("Attempting to transfer socket")); |
|
270 RSocket tran1; |
|
271 ret = tran1.Transfer(ss2, socketname); |
|
272 Logger().WriteFormat(_L("Transfer returned %S"), &EpocErrorToText(ret)); |
|
273 TESTL(KErrNone == ret); |
|
274 |
|
275 Logger().WriteFormat(_L("Checking Info on first socket fails")); |
|
276 TProtocolDesc protoInfo; |
|
277 ret = sock1.Info(protoInfo); |
|
278 Logger().WriteFormat(_L("Info returned %S"), &EpocErrorToText(ret)); |
|
279 TESTL(KErrBadHandle == ret); |
|
280 sock1.Close(); |
|
281 |
|
282 Logger().WriteFormat(_L("Checking Info on transferred socket")); |
|
283 ret = tran1.Info(protoInfo); |
|
284 Logger().WriteFormat(_L("Info returned %S"), &EpocErrorToText(ret)); |
|
285 TESTL(KErrNone == ret); |
|
286 tran1.Close(); |
|
287 |
|
288 CleanupStack::Pop(&ss2); |
|
289 ss1.Close(); |
|
290 CleanupStack::Pop(&ss1); |
|
291 ss2.Close(); |
|
292 |
|
293 return verdict; |
|
294 } |
|
295 |
|
296 |
|
297 // Test step 11.4 |
|
298 const TDesC &CSocketTest11_4::GetTestName() |
|
299 { |
|
300 _LIT(ret,"Test11.4"); |
|
301 return ret; |
|
302 } |
|
303 |
|
304 enum TVerdict CSocketTest11_4::InternalDoTestStepL( void ) |
|
305 { |
|
306 TVerdict verdict = EPass; |
|
307 |
|
308 Logger().WriteFormat(_L("Test Purpose: Attempt transfer of fake socket name")); |
|
309 |
|
310 // connect to esock |
|
311 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
312 RSocketServ ss1; |
|
313 TInt ret = ss1.Connect(); |
|
314 CleanupClosePushL(ss1); |
|
315 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
316 TESTL(KErrNone == ret); |
|
317 |
|
318 Logger().WriteFormat(_L("Creating second optimal connection to socket server")); |
|
319 RSocketServ ss2; |
|
320 ret = OptimalConnect(ss2); |
|
321 CleanupClosePushL(ss2); |
|
322 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
323 TESTL(KErrNone == ret); |
|
324 |
|
325 Logger().WriteFormat(_L("Opening null socket on second connection")); |
|
326 RSocket sock1; |
|
327 ret = sock1.Open(ss2,_L("Dummy Protocol 1")); |
|
328 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
329 TESTL(KErrNone == ret); |
|
330 |
|
331 |
|
332 //--------------------------------------------------------------------- |
|
333 //-- if SYMBIAN_NETWORKING_PLATSEC symbol is defined, we are using EKA2 and secured RSocket::Transfer() |
|
334 //-- in this case the transfer shall be enabled by setting appropriate socket option with "pulling" process capabilities |
|
335 |
|
336 //-- define the capabilities set for the socket "pulling" process (this one, actually) |
|
337 //-- this process must have at least NetworkServices and NetworkControl capabilities |
|
338 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl); |
|
339 |
|
340 //-- enable socket transfer (see lines below) with PlatSec check. Set socket option with receiving process capabilities |
|
341 ret = sock1.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
342 TESTL(KErrNone == ret); |
|
343 |
|
344 |
|
345 //--------------------------------------------------------------------- |
|
346 |
|
347 Logger().WriteFormat(_L("Attempting to transfer socket to good thread# but fake addr 5 ADEADF8")); |
|
348 RSocket tran1; |
|
349 // Try OK thread #, bad address |
|
350 ret = tran1.Transfer(ss2, _L("5 ADEADF8")); |
|
351 Logger().WriteFormat(_L("Transfer returned %S"), &EpocErrorToText(ret)); |
|
352 TESTL(KErrNotFound == ret); |
|
353 |
|
354 // Try thread # out of range |
|
355 Logger().WriteFormat(_L("Attempting to transfer socket to out-of-range thread# 9 ADEADF8")); |
|
356 ret = tran1.Transfer(ss2, _L("9 ADEADF8")); |
|
357 Logger().WriteFormat(_L("Transfer returned %S"), &EpocErrorToText(ret)); |
|
358 TESTL(KErrNotFound == ret); |
|
359 |
|
360 sock1.Close(); |
|
361 |
|
362 tran1.Close(); |
|
363 |
|
364 CleanupStack::Pop(&ss2); |
|
365 ss1.Close(); |
|
366 CleanupStack::Pop(&ss1); |
|
367 ss2.Close(); |
|
368 |
|
369 return verdict; |
|
370 } |
|
371 |
|
372 |
|
373 |