|
1 // Copyright (c) 2001-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 6 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 #include <es_mbuf.h> |
|
22 #include <ss_pman.h> |
|
23 |
|
24 // Test system includes |
|
25 #include "EsockTestSection6.h" |
|
26 |
|
27 |
|
28 // Test step 6.1 |
|
29 const TDesC& CEsockTest6_1::GetTestName() |
|
30 { |
|
31 // store the name of this test case |
|
32 _LIT(ret,"Test6.1"); |
|
33 |
|
34 return ret; |
|
35 } |
|
36 |
|
37 CEsockTest6_1::~CEsockTest6_1() |
|
38 { |
|
39 } |
|
40 |
|
41 enum TVerdict CEsockTest6_1::easyTestStepPreambleL() |
|
42 { |
|
43 CloseSockets(); |
|
44 |
|
45 TInt connections; |
|
46 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.1"), iSockIndex2, iSockIndex3)); |
|
47 if (KErrNone != ret) |
|
48 { |
|
49 return EFail; |
|
50 } |
|
51 if (0 >= connections) |
|
52 { |
|
53 return EFail; |
|
54 } |
|
55 |
|
56 return EPass; |
|
57 } |
|
58 |
|
59 enum TVerdict CEsockTest6_1::easyTestStepL() |
|
60 { |
|
61 TESTL(EPass == TestStepResult()); |
|
62 |
|
63 TRequestStatus stat; |
|
64 // shutdown server socket - Normal mode |
|
65 iEsockSuite->GetSocketHandle(iSockIndex3).Shutdown(RSocket::ENormal, stat); |
|
66 User::WaitForRequest(stat); |
|
67 TESTEL(stat==KErrNone, stat.Int()); |
|
68 |
|
69 TBuf8<40> rbuf; |
|
70 // read from server socket |
|
71 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
72 User::WaitForRequest(stat); |
|
73 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
74 |
|
75 // write on server socket |
|
76 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("some data"), stat); |
|
77 User::WaitForRequest(stat); |
|
78 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
79 |
|
80 // read fronm client socket |
|
81 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
82 User::WaitForRequest(stat); |
|
83 TESTEL(stat==KErrEof, stat.Int()); // nothing to read |
|
84 |
|
85 // write on client socket |
|
86 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("some data"), stat); |
|
87 User::WaitForRequest(stat); |
|
88 TESTEL(stat==KErrNone, stat.Int()); // successful |
|
89 |
|
90 return EPass; |
|
91 } |
|
92 |
|
93 |
|
94 // Test step 6.2 |
|
95 const TDesC& CEsockTest6_2::GetTestName() |
|
96 { |
|
97 // store the name of this test case |
|
98 _LIT(ret,"Test6.2"); |
|
99 |
|
100 return ret; |
|
101 } |
|
102 |
|
103 CEsockTest6_2::~CEsockTest6_2() |
|
104 { |
|
105 } |
|
106 |
|
107 enum TVerdict CEsockTest6_2::easyTestStepPreambleL() |
|
108 { |
|
109 CloseSockets(); |
|
110 |
|
111 TInt connections; |
|
112 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.2"), iSockIndex2, iSockIndex3)); |
|
113 if (KErrNone != ret) |
|
114 { |
|
115 return EFail; |
|
116 } |
|
117 if (0 >= connections) |
|
118 { |
|
119 return EFail; |
|
120 } |
|
121 |
|
122 return EPass; |
|
123 } |
|
124 |
|
125 enum TVerdict CEsockTest6_2::easyTestStepL() |
|
126 { |
|
127 TESTL(EPass == TestStepResult()); |
|
128 |
|
129 TRequestStatus stat; |
|
130 // shutdown server socket - StopOutput mode |
|
131 iEsockSuite->GetSocketHandle(iSockIndex3).Shutdown(RSocket::EStopOutput, stat); |
|
132 User::WaitForRequest(stat); |
|
133 TESTEL(stat==KErrNone, stat.Int()); |
|
134 |
|
135 // write on server socket |
|
136 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("some data"), stat); |
|
137 User::WaitForRequest(stat); |
|
138 TESTEL(stat==KErrEof, stat.Int()); |
|
139 |
|
140 // read on client |
|
141 TBuf8<40> rbuf, wbuf; |
|
142 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
143 User::WaitForRequest(stat); |
|
144 TESTEL(stat==KErrEof, stat.Int()); |
|
145 |
|
146 // write on client |
|
147 wbuf.SetMax(); |
|
148 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf, stat); |
|
149 User::WaitForRequest(stat); |
|
150 TESTEL(stat==KErrNone, stat.Int()); |
|
151 |
|
152 // read on server |
|
153 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
154 User::WaitForRequest(stat); |
|
155 TESTEL(stat==KErrNone, stat.Int()); |
|
156 |
|
157 TESTL(rbuf==wbuf); |
|
158 |
|
159 return EPass; |
|
160 } |
|
161 |
|
162 |
|
163 // Test step 6.3 |
|
164 const TDesC& CEsockTest6_3::GetTestName() |
|
165 { |
|
166 // store the name of this test case |
|
167 _LIT(ret,"Test6.3"); |
|
168 |
|
169 return ret; |
|
170 } |
|
171 |
|
172 CEsockTest6_3::~CEsockTest6_3() |
|
173 { |
|
174 } |
|
175 |
|
176 enum TVerdict CEsockTest6_3::easyTestStepPreambleL() |
|
177 { |
|
178 CloseSockets(); |
|
179 |
|
180 TInt connections; |
|
181 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.3"), iSockIndex2, iSockIndex3)); |
|
182 if (KErrNone != ret) |
|
183 { |
|
184 return EFail; |
|
185 } |
|
186 if (0 >= connections) |
|
187 { |
|
188 return EFail; |
|
189 } |
|
190 |
|
191 return EPass; |
|
192 } |
|
193 |
|
194 enum TVerdict CEsockTest6_3::easyTestStepL() |
|
195 { |
|
196 TESTL(EPass == TestStepResult()); |
|
197 |
|
198 TRequestStatus stat; |
|
199 // shutdown server socket - StopInput mode |
|
200 iEsockSuite->GetSocketHandle(iSockIndex3).Shutdown(RSocket::EStopInput, stat); |
|
201 User::WaitForRequest(stat); |
|
202 TESTEL(stat==KErrNone, stat.Int()); |
|
203 |
|
204 TBuf8<4> rbuf, wbuf; |
|
205 // write on server |
|
206 wbuf.SetMax(); |
|
207 iEsockSuite->GetSocketHandle(iSockIndex3).Write(wbuf, stat); |
|
208 User::WaitForRequest(stat); |
|
209 TESTEL(stat==KErrNone, stat.Int()); |
|
210 |
|
211 // read on client |
|
212 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
213 User::WaitForRequest(stat); |
|
214 TESTEL(stat==KErrNone, stat.Int()); |
|
215 |
|
216 TESTL(rbuf==wbuf); |
|
217 |
|
218 // write on client socket |
|
219 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("some data"), stat); |
|
220 User::WaitForRequest(stat); |
|
221 TESTEL(stat==KErrNone, stat.Int()); |
|
222 |
|
223 // read on server |
|
224 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
225 User::WaitForRequest(stat); |
|
226 TESTEL(stat==KErrEof, stat.Int()); |
|
227 |
|
228 return EPass; |
|
229 } |
|
230 |
|
231 |
|
232 // Test step 6.4 |
|
233 const TDesC& CEsockTest6_4::GetTestName() |
|
234 { |
|
235 // store the name of this test case |
|
236 _LIT(ret,"Test6.4"); |
|
237 |
|
238 return ret; |
|
239 } |
|
240 |
|
241 CEsockTest6_4::~CEsockTest6_4() |
|
242 { |
|
243 } |
|
244 |
|
245 enum TVerdict CEsockTest6_4::easyTestStepPreambleL() |
|
246 { |
|
247 CloseSockets(); |
|
248 |
|
249 TInt connections; |
|
250 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.4"), iSockIndex2, iSockIndex3)); |
|
251 if (KErrNone != ret) |
|
252 { |
|
253 return EFail; |
|
254 } |
|
255 if (0 >= connections) |
|
256 { |
|
257 return EFail; |
|
258 } |
|
259 |
|
260 return EPass; |
|
261 } |
|
262 |
|
263 enum TVerdict CEsockTest6_4::easyTestStepL() |
|
264 { |
|
265 TESTL(EPass == TestStepResult()); |
|
266 |
|
267 TRequestStatus stat; |
|
268 // shutdown server socket - Immediate mode |
|
269 iEsockSuite->GetSocketHandle(iSockIndex3).Shutdown(RSocket::EImmediate, stat); |
|
270 User::WaitForRequest(stat); |
|
271 TESTEL(stat==KErrNone, stat.Int()); |
|
272 |
|
273 TBuf8<40> rbuf; |
|
274 // read on server socket |
|
275 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
276 User::WaitForRequest(stat); |
|
277 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
278 |
|
279 // write on server |
|
280 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("some data"), stat); |
|
281 User::WaitForRequest(stat); |
|
282 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
283 |
|
284 // read on client |
|
285 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
286 User::WaitForRequest(stat); |
|
287 TESTEL(stat==KErrDisconnected, stat.Int()); |
|
288 |
|
289 // write on client |
|
290 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("more data"), stat); |
|
291 User::WaitForRequest(stat); |
|
292 TESTEL(stat==KErrDisconnected, stat.Int()); |
|
293 |
|
294 return EPass; |
|
295 } |
|
296 |
|
297 |
|
298 // Test step 6.5 |
|
299 const TDesC& CEsockTest6_5::GetTestName() |
|
300 { |
|
301 // store the name of this test case |
|
302 _LIT(ret,"Test6.5"); |
|
303 |
|
304 return ret; |
|
305 } |
|
306 |
|
307 CEsockTest6_5::~CEsockTest6_5() |
|
308 { |
|
309 } |
|
310 |
|
311 enum TVerdict CEsockTest6_5::easyTestStepPreambleL() |
|
312 { |
|
313 CloseSockets(); |
|
314 |
|
315 TInt connections; |
|
316 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.5"), iSockIndex2, iSockIndex3)); |
|
317 if (KErrNone != ret) |
|
318 { |
|
319 return EFail; |
|
320 } |
|
321 if (0 >= connections) |
|
322 { |
|
323 return EFail; |
|
324 } |
|
325 |
|
326 return EPass; |
|
327 } |
|
328 |
|
329 enum TVerdict CEsockTest6_5::easyTestStepL() |
|
330 { |
|
331 TESTL(EPass == TestStepResult()); |
|
332 |
|
333 TRequestStatus stat; |
|
334 // shutdown client socket - Normal mode |
|
335 iEsockSuite->GetSocketHandle(iSockIndex2).Shutdown(RSocket::ENormal, stat); |
|
336 User::WaitForRequest(stat); |
|
337 TESTEL(stat==KErrNone, stat.Int()); |
|
338 |
|
339 TBuf8<40> rbuf; |
|
340 // read on client socket |
|
341 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
342 User::WaitForRequest(stat); |
|
343 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
344 |
|
345 // write on client |
|
346 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("some data"), stat); |
|
347 User::WaitForRequest(stat); |
|
348 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
349 |
|
350 // read on server |
|
351 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
352 User::WaitForRequest(stat); |
|
353 TESTEL(stat==KErrEof, stat.Int()); |
|
354 |
|
355 // write on server |
|
356 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("more data"), stat); |
|
357 User::WaitForRequest(stat); |
|
358 TESTEL(stat==KErrNone, stat.Int()); |
|
359 |
|
360 return EPass; |
|
361 } |
|
362 |
|
363 |
|
364 // Test step 6.6 |
|
365 const TDesC& CEsockTest6_6::GetTestName() |
|
366 { |
|
367 // store the name of this test case |
|
368 _LIT(ret,"Test6.6"); |
|
369 |
|
370 return ret; |
|
371 } |
|
372 |
|
373 CEsockTest6_6::~CEsockTest6_6() |
|
374 { |
|
375 } |
|
376 |
|
377 enum TVerdict CEsockTest6_6::easyTestStepPreambleL() |
|
378 { |
|
379 CloseSockets(); |
|
380 |
|
381 TInt connections; |
|
382 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.6"), iSockIndex2, iSockIndex3)); |
|
383 if (KErrNone != ret) |
|
384 { |
|
385 return EFail; |
|
386 } |
|
387 if (0 >= connections) |
|
388 { |
|
389 return EFail; |
|
390 } |
|
391 |
|
392 return EPass; |
|
393 } |
|
394 |
|
395 enum TVerdict CEsockTest6_6::easyTestStepL() |
|
396 { |
|
397 TESTL(EPass == TestStepResult()); |
|
398 |
|
399 TRequestStatus stat; |
|
400 // shutdown client socket - StopOutput mode |
|
401 iEsockSuite->GetSocketHandle(iSockIndex2).Shutdown(RSocket::EStopOutput, stat); |
|
402 User::WaitForRequest(stat); |
|
403 TESTEL(stat==KErrNone, stat.Int()); |
|
404 |
|
405 // write on client socket |
|
406 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("some data"), stat); |
|
407 User::WaitForRequest(stat); |
|
408 TESTEL(stat==KErrEof, stat.Int()); |
|
409 |
|
410 TBuf8<40> rbuf, wbuf; |
|
411 // read on server |
|
412 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
413 User::WaitForRequest(stat); |
|
414 TESTEL(stat==KErrEof, stat.Int()); |
|
415 |
|
416 // write on server |
|
417 wbuf.SetMax(); |
|
418 iEsockSuite->GetSocketHandle(iSockIndex3).Write(wbuf, stat); |
|
419 User::WaitForRequest(stat); |
|
420 TESTEL(stat==KErrNone, stat.Int()); |
|
421 |
|
422 // read on client |
|
423 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
424 User::WaitForRequest(stat); |
|
425 TESTEL(stat==KErrNone, stat.Int()); |
|
426 |
|
427 TESTL(rbuf==wbuf); |
|
428 |
|
429 return EPass; |
|
430 } |
|
431 |
|
432 |
|
433 // Test step 6.7 |
|
434 const TDesC& CEsockTest6_7::GetTestName() |
|
435 { |
|
436 // store the name of this test case |
|
437 _LIT(ret,"Test6.7"); |
|
438 |
|
439 return ret; |
|
440 } |
|
441 |
|
442 CEsockTest6_7::~CEsockTest6_7() |
|
443 { |
|
444 } |
|
445 |
|
446 enum TVerdict CEsockTest6_7::easyTestStepPreambleL() |
|
447 { |
|
448 CloseSockets(); |
|
449 |
|
450 TInt connections; |
|
451 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.7"), iSockIndex2, iSockIndex3)); |
|
452 if (KErrNone != ret) |
|
453 { |
|
454 return EFail; |
|
455 } |
|
456 if (0 >= connections) |
|
457 { |
|
458 return EFail; |
|
459 } |
|
460 |
|
461 return EPass; |
|
462 } |
|
463 |
|
464 enum TVerdict CEsockTest6_7::easyTestStepL() |
|
465 { |
|
466 TESTL(EPass == TestStepResult()); |
|
467 |
|
468 TRequestStatus stat; |
|
469 // shutdown client socket - StopInput mode |
|
470 iEsockSuite->GetSocketHandle(iSockIndex2).Shutdown(RSocket::EStopInput, stat); |
|
471 User::WaitForRequest(stat); |
|
472 TESTEL(stat==KErrNone, stat.Int()); |
|
473 |
|
474 // For testing - try a short delay |
|
475 User::After(1000000); |
|
476 |
|
477 TBuf8<40> rbuf, wbuf; |
|
478 // write on client |
|
479 wbuf.SetMax(); |
|
480 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf, stat); |
|
481 User::WaitForRequest(stat); |
|
482 TESTEL(stat==KErrNone, stat.Int()); |
|
483 |
|
484 // read on server |
|
485 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
486 User::WaitForRequest(stat); |
|
487 TESTEL(stat==KErrNone, stat.Int()); |
|
488 |
|
489 // write on server socket |
|
490 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("some data"), stat); |
|
491 User::WaitForRequest(stat); |
|
492 TESTEL(stat==KErrNone, stat.Int()); |
|
493 |
|
494 // read on client |
|
495 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
496 User::WaitForRequest(stat); |
|
497 TESTEL(stat==KErrEof, stat.Int()); |
|
498 |
|
499 // For testing - try a short delay |
|
500 User::After(1000000); |
|
501 |
|
502 return EPass; |
|
503 } |
|
504 |
|
505 |
|
506 // Test step 6.8 |
|
507 const TDesC& CEsockTest6_8::GetTestName() |
|
508 { |
|
509 // store the name of this test case |
|
510 _LIT(ret,"Test6.8"); |
|
511 |
|
512 return ret; |
|
513 } |
|
514 |
|
515 CEsockTest6_8::~CEsockTest6_8() |
|
516 { |
|
517 } |
|
518 |
|
519 enum TVerdict CEsockTest6_8::easyTestStepPreambleL() |
|
520 { |
|
521 CloseSockets(); |
|
522 |
|
523 TInt connections; |
|
524 TRAPD(ret, connections = OpenConnectionsL(_L("Test_6.8"), iSockIndex2, iSockIndex3)); |
|
525 if (KErrNone != ret) |
|
526 { |
|
527 return EFail; |
|
528 } |
|
529 if (0 >= connections) |
|
530 { |
|
531 return EFail; |
|
532 } |
|
533 |
|
534 return EPass; |
|
535 } |
|
536 |
|
537 enum TVerdict CEsockTest6_8::easyTestStepL() |
|
538 { |
|
539 TESTL(EPass == TestStepResult()); |
|
540 |
|
541 TRequestStatus stat; |
|
542 // shutdown client socket - Immediate mode |
|
543 iEsockSuite->GetSocketHandle(iSockIndex2).Shutdown(RSocket::EImmediate, stat); |
|
544 User::WaitForRequest(stat); |
|
545 TESTEL(stat==KErrNone, stat.Int()); |
|
546 |
|
547 // read on client socket |
|
548 TBuf8<40> rbuf; |
|
549 iEsockSuite->GetSocketHandle(iSockIndex2).Read(rbuf, stat); |
|
550 User::WaitForRequest(stat); |
|
551 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
552 |
|
553 // write on client |
|
554 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("some data"), stat); |
|
555 User::WaitForRequest(stat); |
|
556 TESTEL(stat==KErrBadHandle, stat.Int()); |
|
557 |
|
558 // read on server |
|
559 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
560 User::WaitForRequest(stat); |
|
561 TESTEL(stat==KErrDisconnected, stat.Int()); |
|
562 |
|
563 // write on server |
|
564 iEsockSuite->GetSocketHandle(iSockIndex3).Write(_L8("more data"), stat); |
|
565 User::WaitForRequest(stat); |
|
566 TESTEL(stat==KErrDisconnected, stat.Int()); |
|
567 return EPass; |
|
568 } |
|
569 |