|
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 1 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection1.h" |
|
24 |
|
25 |
|
26 // Test step 1.1 |
|
27 const TDesC& CEsockTest1_1::GetTestName() |
|
28 { |
|
29 // store the name of this test case |
|
30 _LIT(ret,"Test1.1"); |
|
31 return ret; |
|
32 } |
|
33 |
|
34 CEsockTest1_1::~CEsockTest1_1() |
|
35 { |
|
36 } |
|
37 |
|
38 enum TVerdict CEsockTest1_1::easyTestStepL() |
|
39 { |
|
40 // get number of sockets from script |
|
41 TInt nSockets; // number of sockets to open |
|
42 TESTL(GetIntFromConfig(SectionName(_L("Test_1.1")), _L("numSockets"), nSockets)); |
|
43 |
|
44 Logger().WriteFormat(_L("Open %d blank socket(s)"), nSockets); |
|
45 |
|
46 TInt ret = OpenSockets(nSockets); |
|
47 TESTEL(KErrNone == ret, ret); |
|
48 |
|
49 return EPass; |
|
50 } |
|
51 |
|
52 |
|
53 // Test step 1.2 |
|
54 const TDesC& CEsockTest1_2::GetTestName() |
|
55 { |
|
56 // store the name of this test case |
|
57 _LIT(ret,"Test1.2"); |
|
58 |
|
59 return ret; |
|
60 } |
|
61 |
|
62 CEsockTest1_2::~CEsockTest1_2() |
|
63 { |
|
64 } |
|
65 |
|
66 enum TVerdict CEsockTest1_2::easyTestStepL() |
|
67 { |
|
68 // get number of sockets from script |
|
69 TInt nSockets; // number of sockets to open |
|
70 TESTL(GetIntFromConfig(SectionName(_L("Test_1.2")), _L("numSockets"), nSockets)); |
|
71 |
|
72 Logger().WriteFormat(_L("Open %d TCP socket(s)"), nSockets); |
|
73 TInt ret = OpenSockets(KAfInet, KSockStream, KProtocolInetTcp, nSockets); |
|
74 TESTEL(KErrNone == ret, ret); |
|
75 |
|
76 TInetAddr addr; |
|
77 TBuf<32> buf; |
|
78 for (TInt i = 0; i < nSockets; i++) |
|
79 { |
|
80 // Get local address of the socket (Empty) |
|
81 (iEsockSuite->GetSocketHandle(i + 1)).LocalName(addr); |
|
82 |
|
83 // Check length of buffer, should be set to (Zero) |
|
84 addr.OutputWithScope(buf); |
|
85 TESTL(buf.Length() == 0); |
|
86 } |
|
87 |
|
88 return EPass; |
|
89 } |
|
90 |
|
91 |
|
92 // Test step 1.3 |
|
93 const TDesC& CEsockTest1_3::GetTestName() |
|
94 { |
|
95 // store the name of this test case |
|
96 _LIT(ret,"Test1.3"); |
|
97 |
|
98 return ret; |
|
99 } |
|
100 |
|
101 CEsockTest1_3::~CEsockTest1_3() |
|
102 { |
|
103 } |
|
104 |
|
105 enum TVerdict CEsockTest1_3::easyTestStepL() |
|
106 { |
|
107 // get number of sockets from script |
|
108 TInt nSockets; // number of sockets to open |
|
109 TESTL(GetIntFromConfig(SectionName(_L("Test_1.3")), _L("numSockets"), nSockets)); |
|
110 |
|
111 Logger().WriteFormat(_L("Open %d UDP socket(s)"), nSockets); |
|
112 TInt ret = OpenSockets(KAfInet, KSockDatagram, KProtocolInetUdp, nSockets); |
|
113 TESTEL(KErrNone == ret, ret); |
|
114 |
|
115 TInetAddr addr; |
|
116 TBuf<39> buf; |
|
117 for (TInt i = 0; i < nSockets; i++) |
|
118 { |
|
119 // Get local address of the socket (Empty) |
|
120 (iEsockSuite->GetSocketHandle(i + 1)).LocalName(addr); |
|
121 |
|
122 // Check length of buffer, should be set to (Zero) |
|
123 addr.OutputWithScope(buf); |
|
124 TESTL(buf.Length() == 0); |
|
125 } |
|
126 |
|
127 return EPass; |
|
128 } |
|
129 |
|
130 |
|
131 // Test step 1.4 |
|
132 const TDesC& CEsockTest1_4::GetTestName() |
|
133 { |
|
134 // store the name of this test case |
|
135 _LIT(ret,"Test1.4"); |
|
136 |
|
137 return ret; |
|
138 } |
|
139 |
|
140 CEsockTest1_4::~CEsockTest1_4() |
|
141 { |
|
142 } |
|
143 |
|
144 enum TVerdict CEsockTest1_4::easyTestStepL() |
|
145 { |
|
146 // Open n ICMP sockets |
|
147 |
|
148 // get number of sockets from script |
|
149 TInt nSockets; // number of sockets to open |
|
150 TESTL(GetIntFromConfig(SectionName(_L("Test_1.4")), _L("numSockets"), nSockets)); |
|
151 |
|
152 Logger().WriteFormat(_L("Open %d ICMP socket(s)"), nSockets); |
|
153 TInt ret = OpenSockets(KAfInet, KSockDatagram, KProtocolInetIcmp, nSockets); |
|
154 TESTEL(KErrNone == ret, ret); |
|
155 |
|
156 TInetAddr addr; |
|
157 TBuf<32> buf; |
|
158 for (TInt i = 0; i < nSockets; i++) |
|
159 { |
|
160 // Get local address of the socket (Empty) |
|
161 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
162 |
|
163 // Check length of buffer, should be set to (Zero) |
|
164 addr.OutputWithScope(buf); |
|
165 TESTL(buf.Length() == KErrNone); |
|
166 } |
|
167 |
|
168 return EPass; |
|
169 } |
|
170 |
|
171 |
|
172 // Test step 1.5 |
|
173 const TDesC& CEsockTest1_5::GetTestName() |
|
174 { |
|
175 // store the name of this test case |
|
176 _LIT(ret,"Test1.5"); |
|
177 |
|
178 return ret; |
|
179 } |
|
180 |
|
181 CEsockTest1_5::~CEsockTest1_5() |
|
182 { |
|
183 } |
|
184 |
|
185 enum TVerdict CEsockTest1_5::easyTestStepL() |
|
186 { |
|
187 // Open n IP sockets |
|
188 |
|
189 // get number of sockets from script |
|
190 TInt nSockets; // number of sockets to open |
|
191 TESTL(GetIntFromConfig(SectionName(_L("Test_1.5")), _L("numSockets"), nSockets)); |
|
192 |
|
193 Logger().WriteFormat(_L("Open %d IP socket(s)"), nSockets); |
|
194 TInt ret = OpenSockets(KAfInet, KSockDatagram, KProtocolInetIp, nSockets); |
|
195 TESTEL(KErrNone == ret, ret); |
|
196 |
|
197 TInetAddr addr; |
|
198 TBuf<32> buf; |
|
199 for (TInt i = 0; i < nSockets; i++) |
|
200 { |
|
201 // Get local address of the socket (Empty) |
|
202 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
203 |
|
204 // Check length of buffer, should be set to (Zero) |
|
205 addr.OutputWithScope(buf); |
|
206 TESTL(buf.Length() == KErrNone); |
|
207 } |
|
208 |
|
209 return EPass; |
|
210 } |
|
211 |
|
212 |
|
213 // Test step 1.6 |
|
214 const TDesC& CEsockTest1_6::GetTestName() |
|
215 { |
|
216 // store the name of this test case |
|
217 _LIT(ret,"Test1.6"); |
|
218 |
|
219 return ret; |
|
220 } |
|
221 |
|
222 CEsockTest1_6::~CEsockTest1_6() |
|
223 { |
|
224 } |
|
225 |
|
226 enum TVerdict CEsockTest1_6::easyTestStepL() |
|
227 { |
|
228 // get number of sockets from script |
|
229 TInt nSockets; // number of sockets to open |
|
230 TESTL(GetIntFromConfig(SectionName(_L("Test_1.6")), _L("numSockets"), nSockets)); |
|
231 |
|
232 Logger().WriteFormat(_L("Open %d TCP socket(s) by name"), nSockets); |
|
233 TInt ret = OpenSockets(_L("tcp"), nSockets); |
|
234 TESTEL(KErrNone == ret, ret); |
|
235 |
|
236 TInetAddr addr; |
|
237 TBuf<32> buf; |
|
238 for (TInt i = 0; i < nSockets; i++) |
|
239 { |
|
240 // Get local address of the socket (Empty) |
|
241 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
242 |
|
243 // Check length of buffer, should be set to (Zero) |
|
244 addr.OutputWithScope(buf); |
|
245 TESTL(buf.Length() == KErrNone); |
|
246 } |
|
247 |
|
248 return EPass; |
|
249 } |
|
250 |
|
251 |
|
252 // Test step 1.7 |
|
253 const TDesC& CEsockTest1_7::GetTestName() |
|
254 { |
|
255 // store the name of this test case |
|
256 _LIT(ret,"Test1.7"); |
|
257 |
|
258 return ret; |
|
259 } |
|
260 |
|
261 CEsockTest1_7::~CEsockTest1_7() |
|
262 { |
|
263 } |
|
264 |
|
265 enum TVerdict CEsockTest1_7::easyTestStepL() |
|
266 { |
|
267 // get number of sockets from script |
|
268 TInt nSockets; // number of sockets to open |
|
269 TESTL(GetIntFromConfig(SectionName(_L("Test_1.7")), _L("numSockets"), nSockets)); |
|
270 |
|
271 Logger().WriteFormat(_L("Open %d UDP socket(s) by name"), nSockets); |
|
272 TInt ret = OpenSockets(_L("udp"), nSockets); |
|
273 TESTEL(KErrNone == ret, ret); |
|
274 |
|
275 TInetAddr addr; |
|
276 TBuf<32> buf; |
|
277 for (TInt i = 0; i < nSockets; i++) |
|
278 { |
|
279 // Get local address of the socket (Empty) |
|
280 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
281 |
|
282 // Check length of buffer, should be set to (Zero) |
|
283 addr.OutputWithScope(buf); |
|
284 TESTL(buf.Length() == KErrNone); |
|
285 } |
|
286 |
|
287 return EPass; |
|
288 } |
|
289 |
|
290 |
|
291 // Test step 1.8 |
|
292 const TDesC& CEsockTest1_8::GetTestName() |
|
293 { |
|
294 // store the name of this test case |
|
295 _LIT(ret,"Test1.8"); |
|
296 |
|
297 return ret; |
|
298 } |
|
299 |
|
300 CEsockTest1_8::~CEsockTest1_8() |
|
301 { |
|
302 } |
|
303 |
|
304 enum TVerdict CEsockTest1_8::easyTestStepL() |
|
305 { |
|
306 // get number of sockets from script |
|
307 TInt nSockets; // number of sockets to open |
|
308 TESTL(GetIntFromConfig(SectionName(_L("Test_1.8")), _L("numSockets"), nSockets)); |
|
309 |
|
310 Logger().WriteFormat(_L("Open %d ICMP socket(s) by name"), nSockets); |
|
311 TInt ret = OpenSockets(_L("icmp"), nSockets); |
|
312 TESTEL(KErrNone == ret, ret); |
|
313 |
|
314 TInetAddr addr; |
|
315 TBuf<32> buf; |
|
316 for (TInt i = 0; i < nSockets; i++) |
|
317 { |
|
318 // Get local address of the socket (Empty) |
|
319 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
320 |
|
321 // Check length of buffer, should be set to (Zero) |
|
322 addr.OutputWithScope(buf); |
|
323 TESTL(buf.Length() == 0); |
|
324 } |
|
325 |
|
326 return EPass; |
|
327 } |
|
328 |
|
329 |
|
330 // Test step 1.9 |
|
331 const TDesC& CEsockTest1_9::GetTestName() |
|
332 { |
|
333 // store the name of this test case |
|
334 _LIT(ret,"Test1.9"); |
|
335 |
|
336 return ret; |
|
337 } |
|
338 |
|
339 CEsockTest1_9::~CEsockTest1_9() |
|
340 { |
|
341 } |
|
342 |
|
343 enum TVerdict CEsockTest1_9::easyTestStepL() |
|
344 { |
|
345 // get number of sockets from script |
|
346 TInt nSockets; // number of sockets to open |
|
347 TESTL(GetIntFromConfig(SectionName(_L("Test_1.9")), _L("numSockets"), nSockets)); |
|
348 |
|
349 Logger().WriteFormat(_L("Open %d IP sockets by name"), nSockets); |
|
350 TInt ret = OpenSockets(_L("ip"), nSockets); |
|
351 TESTEL(KErrNone == ret, ret); |
|
352 |
|
353 TInetAddr addr; |
|
354 TBuf<32> buf; |
|
355 for (TInt i = 0; i < nSockets; i++) |
|
356 { |
|
357 // Get local address of the socket (Empty) |
|
358 iEsockSuite->GetSocketHandle(i + 1).LocalName(addr); |
|
359 |
|
360 // Check length of buffer, should be set to (Zero) |
|
361 addr.OutputWithScope(buf); |
|
362 TESTL(buf.Length() == KErrNone); |
|
363 } |
|
364 |
|
365 return EPass; |
|
366 } |
|
367 |
|
368 |
|
369 // Test step 1.10 |
|
370 const TDesC& CEsockTest1_10::GetTestName() |
|
371 { |
|
372 // store the name of this test case |
|
373 _LIT(ret,"Test1.10"); |
|
374 |
|
375 return ret; |
|
376 } |
|
377 |
|
378 CEsockTest1_10::~CEsockTest1_10() |
|
379 { |
|
380 } |
|
381 |
|
382 enum TVerdict CEsockTest1_10::easyTestStepL() |
|
383 { |
|
384 // Open a TCP socket with invalid socket type |
|
385 Logger().WriteFormat(_L("Open socket, of invalid type, for TCP")); |
|
386 RSocket sock; |
|
387 CleanupClosePushL(sock); |
|
388 TInt ret = sock.Open(iEsockSuite->iSocketServer, KAfInet, 0, KProtocolInetTcp); |
|
389 TESTEL(ret==KErrBadName, ret); |
|
390 |
|
391 // Open a UDP socket with invalid socket type |
|
392 Logger().WriteFormat(_L("Open socket, of invalid type, for UDP")); |
|
393 RSocket sock2; |
|
394 CleanupClosePushL(sock2); |
|
395 ret = sock2.Open(iEsockSuite->iSocketServer, KAfInet, 12, KProtocolInetUdp); |
|
396 TESTEL(ret==KErrBadName, ret); |
|
397 |
|
398 CleanupStack::PopAndDestroy(2, &sock); |
|
399 return EPass; |
|
400 } |
|
401 |
|
402 |
|
403 // Test step 1.11 |
|
404 const TDesC& CEsockTest1_11::GetTestName() |
|
405 { |
|
406 // store the name of this test case |
|
407 _LIT(ret,"Test1.11"); |
|
408 |
|
409 return ret; |
|
410 } |
|
411 |
|
412 CEsockTest1_11::~CEsockTest1_11() |
|
413 { |
|
414 } |
|
415 |
|
416 enum TVerdict CEsockTest1_11::easyTestStepL() |
|
417 { |
|
418 // open sockets with an invalid protocol |
|
419 |
|
420 // get protocol id's from script |
|
421 TInt protocol1, protocol2; |
|
422 TESTL(GetIntFromConfig(SectionName(_L("Test_1.11")), _L("protocolId1"), protocol1)); |
|
423 TESTL(GetIntFromConfig(SectionName(_L("Test_1.11")), _L("protocolId2"), protocol2)); |
|
424 |
|
425 Logger().WriteFormat(_L("Open stream socket for invalid protocol")); |
|
426 RSocket sock; |
|
427 CleanupClosePushL(sock); |
|
428 TInt ret = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, protocol1); |
|
429 TESTEL(ret==KErrBadName, ret); |
|
430 |
|
431 Logger().WriteFormat(_L("Open datagram socket for invalid protocol")); |
|
432 RSocket sock2; |
|
433 CleanupClosePushL(sock2); |
|
434 ret = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, protocol2); |
|
435 TESTEL(ret==KErrBadName, ret); |
|
436 |
|
437 CleanupStack::PopAndDestroy(2, &sock); |
|
438 return EPass; |
|
439 } |
|
440 |
|
441 |
|
442 // Test step 1.12 |
|
443 const TDesC& CEsockTest1_12::GetTestName() |
|
444 { |
|
445 // store the name of this test case |
|
446 _LIT(ret,"Test1.12"); |
|
447 |
|
448 return ret; |
|
449 } |
|
450 |
|
451 CEsockTest1_12::~CEsockTest1_12() |
|
452 { |
|
453 } |
|
454 |
|
455 enum TVerdict CEsockTest1_12::easyTestStepL() |
|
456 { |
|
457 Logger().WriteFormat(_L("Open stream socket for UDP")); |
|
458 |
|
459 RSocket sock; |
|
460 CleanupClosePushL(sock); |
|
461 TInt ret = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetUdp); |
|
462 TESTEL(ret==KErrBadName, ret); |
|
463 |
|
464 CleanupStack::PopAndDestroy(); |
|
465 return EPass; |
|
466 } |
|
467 |
|
468 |
|
469 // Test step 1.13 |
|
470 const TDesC& CEsockTest1_13::GetTestName() |
|
471 { |
|
472 // store the name of this test case |
|
473 _LIT(ret,"Test1.13"); |
|
474 |
|
475 return ret; |
|
476 } |
|
477 |
|
478 CEsockTest1_13::~CEsockTest1_13() |
|
479 { |
|
480 } |
|
481 |
|
482 enum TVerdict CEsockTest1_13::easyTestStepL() |
|
483 { |
|
484 Logger().WriteFormat(_L("Open datagram socket for TCP")); |
|
485 |
|
486 RSocket sock; |
|
487 CleanupClosePushL(sock); |
|
488 TInt ret = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetTcp); |
|
489 TESTEL(ret==KErrBadName, ret); |
|
490 |
|
491 CleanupStack::PopAndDestroy(); |
|
492 return EPass; |
|
493 } |
|
494 |
|
495 |
|
496 // Test step 1.14 |
|
497 const TDesC& CEsockTest1_14::GetTestName() |
|
498 { |
|
499 // store the name of this test case |
|
500 _LIT(ret,"Test1.14"); |
|
501 |
|
502 return ret; |
|
503 } |
|
504 |
|
505 CEsockTest1_14::~CEsockTest1_14() |
|
506 { |
|
507 } |
|
508 |
|
509 enum TVerdict CEsockTest1_14::easyTestStepL() |
|
510 { |
|
511 Logger().WriteFormat(_L("Open socket for invalid protocol by name")); |
|
512 |
|
513 RSocket sock; |
|
514 CleanupClosePushL(sock); |
|
515 TInt ret =sock.Open(iEsockSuite->iSocketServer, _L("abc")); |
|
516 TESTEL(ret==KErrNotFound, ret); |
|
517 |
|
518 CleanupStack::PopAndDestroy(); |
|
519 return EPass; |
|
520 } |
|
521 |
|
522 |
|
523 // Test step 1.15 |
|
524 const TDesC& CEsockTest1_15::GetTestName() |
|
525 { |
|
526 // store the name of this test case |
|
527 _LIT(ret,"Test1.15"); |
|
528 |
|
529 return ret; |
|
530 } |
|
531 |
|
532 CEsockTest1_15::~CEsockTest1_15() |
|
533 { |
|
534 } |
|
535 |
|
536 enum TVerdict CEsockTest1_15::easyTestStepL() |
|
537 { |
|
538 CloseSockets(2); |
|
539 return EPass; |
|
540 } |
|
541 |
|
542 // Test step 1.16 |
|
543 const TDesC& CEsockTest1_16::GetTestName() |
|
544 { |
|
545 // store the name of this test case |
|
546 _LIT(ret,"Test1.16"); |
|
547 |
|
548 return ret; |
|
549 } |
|
550 |
|
551 CEsockTest1_16::~CEsockTest1_16() |
|
552 { |
|
553 } |
|
554 |
|
555 enum TVerdict CEsockTest1_16::easyTestStepPreambleL() |
|
556 { |
|
557 TInt ret = OpenSockets(KAfInet, KSockDatagram, KProtocolInetUdp); |
|
558 Logger().WriteFormat(_L("Open a UDP socket, returned %d"), ret); |
|
559 if (KErrNone != ret) |
|
560 { |
|
561 return EFail; |
|
562 } |
|
563 return EPass; |
|
564 } |
|
565 |
|
566 enum TVerdict CEsockTest1_16::easyTestStepL() |
|
567 { |
|
568 TESTL(EPass == TestStepResult()); |
|
569 |
|
570 if (iEsockSuite->GetSocketListCount() < 1) |
|
571 { |
|
572 return EInconclusive; |
|
573 } |
|
574 |
|
575 const TInt KBufferLength = 10; |
|
576 TBuf8<KBufferLength> buffer; |
|
577 buffer.SetMax(); |
|
578 buffer.FillZ(); |
|
579 |
|
580 TInetAddr destAddr; |
|
581 TRequestStatus status; |
|
582 |
|
583 Logger().WriteFormat(_L("Issuing 'SendTo' with invalid destination...")); |
|
584 iEsockSuite->GetSocketHandle(1).SendTo(buffer, destAddr, 0, status); |
|
585 User::WaitForRequest(status); |
|
586 Logger().WriteFormat(_L("...which returned %d\n"), status.Int()); // Should return '-2' |
|
587 TESTEL(status == KErrGeneral, EFail); |
|
588 |
|
589 // Test 1.15 Close socket |
|
590 |
|
591 return EPass; |
|
592 } |
|
593 |
|
594 // Test step 1.17 |
|
595 // Open a socket using the RawIp protocol |
|
596 const TDesC& CEsockTest1_17::GetTestName() |
|
597 { |
|
598 // store the name of this test case |
|
599 _LIT(ret, "Test1.17"); |
|
600 |
|
601 return ret; |
|
602 } |
|
603 |
|
604 CEsockTest1_17::~CEsockTest1_17() |
|
605 { |
|
606 } |
|
607 |
|
608 enum TVerdict CEsockTest1_17::easyTestStepL() |
|
609 { |
|
610 Logger().WriteFormat(_L("Open a RawIP socket")); |
|
611 |
|
612 _LIT(KRawIp, "rawip"); |
|
613 TInt ret = OpenSockets(KRawIp); |
|
614 TESTEL(ret == KErrNone, ret); |
|
615 |
|
616 return EPass; |
|
617 } |
|
618 |
|
619 |