|
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 19 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection19.h" |
|
24 |
|
25 |
|
26 // Test step 19.1 |
|
27 const TDesC& CEsockTest19_1::GetTestName() |
|
28 { |
|
29 // store the name of this test case |
|
30 _LIT(ret,"Test19.1"); |
|
31 return ret; |
|
32 } |
|
33 |
|
34 CEsockTest19_1::~CEsockTest19_1() |
|
35 { |
|
36 } |
|
37 |
|
38 enum TVerdict CEsockTest19_1::easyTestStepL() |
|
39 { |
|
40 TInetAddr addr; |
|
41 TBuf<39> buf; |
|
42 |
|
43 // setting the IP address |
|
44 |
|
45 const TIp6Addr KInet6Addr19_1 = {{{0xff,0xfe,0,0,0,0,0,0,0,0,0,0,0,0,0x29,0xfe}}}; |
|
46 const TIp6Addr KInet6Addr19_2 = {{{0xff,0xf1,0,1,0,1,0,1,0,1,0,1,0,1,0x29,0xff}}}; |
|
47 |
|
48 // setting the IP address |
|
49 |
|
50 // set the address |
|
51 addr.SetAddress(KInet6Addr19_1); |
|
52 |
|
53 // check it has been set correctly |
|
54 addr.OutputWithScope(buf); |
|
55 TESTL(buf==_L("fffe::29fe")); |
|
56 |
|
57 // check port number initialised to 0 |
|
58 TESTL(addr.Port()==0); |
|
59 |
|
60 // change the address |
|
61 addr.SetAddress(KInet6Addr19_2); |
|
62 |
|
63 // check it has been set correctly |
|
64 addr.OutputWithScope(buf); |
|
65 TESTL(buf==_L("fff1:1:1:1:1:1:1:29ff")); |
|
66 |
|
67 // check port number is still set to 0 |
|
68 TESTL(addr.Port()==0); |
|
69 |
|
70 return EPass; |
|
71 } |
|
72 |
|
73 |
|
74 // Test step 19.2 |
|
75 const TDesC& CEsockTest19_2::GetTestName() |
|
76 { |
|
77 // store the name of this test case |
|
78 _LIT(ret,"Test19.2"); |
|
79 return ret; |
|
80 } |
|
81 |
|
82 CEsockTest19_2::~CEsockTest19_2() |
|
83 { |
|
84 } |
|
85 |
|
86 enum TVerdict CEsockTest19_2::easyTestStepL() |
|
87 { |
|
88 TInetAddr addrCompat, addrIpv4; |
|
89 TInt port; |
|
90 TBuf<39> ipv4Buf; |
|
91 TBuf<39> ipv4compatBuf; |
|
92 |
|
93 // setting an IPv4 compatible address |
|
94 |
|
95 // get ip addresses from script (IPv4 format) |
|
96 TESTL(GetIpAddressFromConfig(_L("Test_19.2"), _L("ipAddress"), addrIpv4)); |
|
97 |
|
98 // get port number from script |
|
99 TESTL(GetIntFromConfig(_L("Test_19.2"), _L("port"), port)); |
|
100 |
|
101 // set port number |
|
102 addrIpv4.SetPort(port); |
|
103 |
|
104 // get address into a TUint32 |
|
105 TUint32 longAddr = addrIpv4.Address(); |
|
106 |
|
107 // set an IPv4 compatible address |
|
108 addrCompat.SetV4CompatAddress(longAddr); |
|
109 |
|
110 // get string representations of the addresses |
|
111 addrIpv4.OutputWithScope(ipv4Buf); // original IPv4 address |
|
112 addrCompat.OutputWithScope(ipv4compatBuf); // IPv4 compat. address |
|
113 |
|
114 // check IPv4 compatible address set correctly |
|
115 // looks like original with :: prefix |
|
116 ipv4Buf.Insert(0, _L("::")); |
|
117 TESTL(ipv4Buf==ipv4compatBuf); |
|
118 |
|
119 // check the port initialised to 0 |
|
120 TESTL(addrCompat.Port() == 0); |
|
121 |
|
122 // repeat for unspecified address |
|
123 addrCompat.SetV4CompatAddress(INET_ADDR(0, 0, 0, 0)); |
|
124 addrCompat.OutputWithScope(ipv4compatBuf); |
|
125 TESTL(ipv4compatBuf==_L("::")); |
|
126 TESTL(addrCompat.Port() == 0); |
|
127 |
|
128 return EPass; |
|
129 } |
|
130 |
|
131 |
|
132 // Test step 19.3 |
|
133 const TDesC& CEsockTest19_3::GetTestName() |
|
134 { |
|
135 // store the name of this test case |
|
136 _LIT(ret,"Test19.3"); |
|
137 return ret; |
|
138 } |
|
139 |
|
140 CEsockTest19_3::~CEsockTest19_3() |
|
141 { |
|
142 } |
|
143 |
|
144 enum TVerdict CEsockTest19_3::easyTestStepL() |
|
145 { |
|
146 TInetAddr addrMapped, addrIpv4_1, addrIpv4_2; |
|
147 TInt port1, port2; |
|
148 TBuf<39> ipv4Buf; |
|
149 TBuf<39> ipv4mappedBuf; |
|
150 |
|
151 // setting an IPv4 mapped address |
|
152 |
|
153 // get ip addresses from script (IPv4 format) |
|
154 TESTL(GetIpAddressFromConfig(_L("Test_19.3"), _L("ipAddress1"), addrIpv4_1)); |
|
155 TESTL(GetIpAddressFromConfig(_L("Test_19.3"), _L("ipAddress2"), addrIpv4_2)); |
|
156 |
|
157 // get port numbers from script |
|
158 TESTL(GetIntFromConfig(_L("Test_19.3"), _L("port1"), port1)); |
|
159 TESTL(GetIntFromConfig(_L("Test_19.3"), _L("port2"), port2)); |
|
160 |
|
161 // set port number of ip address |
|
162 addrIpv4_1.SetPort(port1); |
|
163 |
|
164 // get address into a TUint32 |
|
165 TUint32 longAddr = addrIpv4_1.Address(); |
|
166 |
|
167 // set an IPv4 mapped address |
|
168 addrMapped.SetV4MappedAddress(longAddr); |
|
169 |
|
170 // get string representations of the addresses |
|
171 addrIpv4_1.OutputWithScope(ipv4Buf); |
|
172 addrMapped.OutputWithScope(ipv4mappedBuf); |
|
173 |
|
174 // check IPv4 mapped address set correctly |
|
175 |
|
176 |
|
177 TESTL(ipv4Buf==ipv4mappedBuf); |
|
178 |
|
179 // check the port number |
|
180 TESTL(addrMapped.Port() == 0); |
|
181 |
|
182 // repeat for 2nd ip address |
|
183 addrIpv4_2.SetPort(port2); |
|
184 longAddr = addrIpv4_2.Address(); |
|
185 addrMapped.SetV4MappedAddress(longAddr); |
|
186 addrIpv4_2.OutputWithScope(ipv4Buf); |
|
187 addrMapped.OutputWithScope(ipv4mappedBuf); |
|
188 |
|
189 TESTL(ipv4Buf==ipv4mappedBuf); |
|
190 TESTL(addrMapped.Port() == 0); |
|
191 |
|
192 return EPass; |
|
193 } |
|
194 |
|
195 |
|
196 // Test step 19.4 |
|
197 const TDesC& CEsockTest19_4::GetTestName() |
|
198 { |
|
199 // store the name of this test case |
|
200 _LIT(ret,"Test19.4"); |
|
201 return ret; |
|
202 } |
|
203 |
|
204 CEsockTest19_4::~CEsockTest19_4() |
|
205 { |
|
206 } |
|
207 |
|
208 enum TVerdict CEsockTest19_4::easyTestStepL() |
|
209 { |
|
210 TInetAddr /*addrCompat,*/ addrIpv4_1, addrIpv4_2; |
|
211 TInt port1, port2; |
|
212 TBuf<39> ipv4Buf; |
|
213 TBuf<39> ipv4compatBuf; |
|
214 |
|
215 // converting to an IPv4 compatible address |
|
216 |
|
217 // get ip addresses from script (IPv4 format) |
|
218 TESTL(GetIpAddressFromConfig(_L("Test_19.4"), _L("ipAddress1"), addrIpv4_1)); |
|
219 TESTL(GetIpAddressFromConfig(_L("Test_19.4"), _L("ipAddress2"), addrIpv4_2)); |
|
220 |
|
221 // get port numbers from script |
|
222 TESTL(GetIntFromConfig(_L("Test_19.4"), _L("port1"), port1)); |
|
223 TESTL(GetIntFromConfig(_L("Test_19.4"), _L("port2"), port2)); |
|
224 |
|
225 // set the port number |
|
226 addrIpv4_1.SetPort(port1); |
|
227 |
|
228 // get string representation of the input address |
|
229 addrIpv4_1.OutputWithScope(ipv4Buf); |
|
230 |
|
231 // convert to IPv4 compatible address |
|
232 addrIpv4_1.ConvertToV4Compat(); |
|
233 |
|
234 // get string representation of the converted address |
|
235 addrIpv4_1.OutputWithScope(ipv4compatBuf); |
|
236 |
|
237 // check IPv4 compatible address set correctly |
|
238 if (addrIpv4_1.IsUnspecified()) // special case - unspecifed address |
|
239 ipv4Buf=_L("::"); |
|
240 else |
|
241 ipv4Buf.Insert(0, _L("::")); |
|
242 |
|
243 TESTL(ipv4Buf==ipv4compatBuf); |
|
244 |
|
245 // check the port number |
|
246 TESTL(addrIpv4_1.Port() == (TUint)port1); |
|
247 |
|
248 // repeat for 2nd ip address |
|
249 addrIpv4_2.SetPort(port2); |
|
250 addrIpv4_2.OutputWithScope(ipv4Buf); |
|
251 addrIpv4_2.ConvertToV4Compat(); |
|
252 addrIpv4_2.OutputWithScope(ipv4compatBuf); |
|
253 if (addrIpv4_2.IsUnspecified()) |
|
254 ipv4Buf=_L("::"); |
|
255 else |
|
256 ipv4Buf.Insert(0, _L("::")); |
|
257 TESTL(ipv4Buf==ipv4compatBuf); |
|
258 TESTL(addrIpv4_2.Port() == (TUint)port2); |
|
259 |
|
260 return EPass; |
|
261 } |
|
262 |
|
263 |
|
264 // Test step 19.5 |
|
265 const TDesC& CEsockTest19_5::GetTestName() |
|
266 { |
|
267 // store the name of this test case |
|
268 _LIT(ret,"Test19.5"); |
|
269 return ret; |
|
270 } |
|
271 |
|
272 CEsockTest19_5::~CEsockTest19_5() |
|
273 { |
|
274 } |
|
275 |
|
276 enum TVerdict CEsockTest19_5::easyTestStepL() |
|
277 { |
|
278 TInetAddr addrIpv4_1, addrIpv4_2; |
|
279 TInt port1, port2; |
|
280 TBuf<39> ipv4Buf; |
|
281 TBuf<39> ipv4mappedBuf; |
|
282 |
|
283 // converting to an IPv4 mapped address |
|
284 |
|
285 // get ip addresses from script (IPv4 format) |
|
286 TESTL(GetIpAddressFromConfig(_L("Test_19.5"), _L("ipAddress1"), addrIpv4_1)); |
|
287 TESTL(GetIpAddressFromConfig(_L("Test_19.5"), _L("ipAddress2"), addrIpv4_2)); |
|
288 |
|
289 // get port numbers from script |
|
290 TESTL(GetIntFromConfig(_L("Test_19.5"), _L("port1"), port1)); |
|
291 TESTL(GetIntFromConfig(_L("Test_19.5"), _L("port2"), port2)); |
|
292 |
|
293 // set the port number |
|
294 addrIpv4_1.SetPort(port1); |
|
295 |
|
296 // get string representation of the input address |
|
297 addrIpv4_1.OutputWithScope(ipv4Buf); |
|
298 |
|
299 // convert to IPv4 compatible address |
|
300 addrIpv4_1.ConvertToV4Mapped(); |
|
301 |
|
302 // get string representation of the converted address |
|
303 addrIpv4_1.OutputWithScope(ipv4mappedBuf); |
|
304 |
|
305 // check IPv4 compatible address set correctly |
|
306 |
|
307 TESTL(ipv4Buf==ipv4mappedBuf); |
|
308 |
|
309 // check the port number |
|
310 TESTL(addrIpv4_1.Port() == (TUint)port1); |
|
311 |
|
312 // repeat for 2nd ip address |
|
313 addrIpv4_2.SetPort(port2); |
|
314 addrIpv4_2.OutputWithScope(ipv4Buf); |
|
315 addrIpv4_2.ConvertToV4Mapped(); |
|
316 addrIpv4_2.OutputWithScope(ipv4mappedBuf); |
|
317 |
|
318 TESTL(ipv4Buf==ipv4mappedBuf); |
|
319 TESTL(addrIpv4_2.Port() == (TUint)port2); |
|
320 |
|
321 return EPass; |
|
322 } |
|
323 |
|
324 |
|
325 // Test step 19.6 |
|
326 const TDesC& CEsockTest19_6::GetTestName() |
|
327 { |
|
328 // store the name of this test case |
|
329 _LIT(ret,"Test19.6"); |
|
330 return ret; |
|
331 } |
|
332 |
|
333 CEsockTest19_6::~CEsockTest19_6() |
|
334 { |
|
335 } |
|
336 |
|
337 enum TVerdict CEsockTest19_6::easyTestStepL() |
|
338 { |
|
339 TInetAddr addr; |
|
340 TBuf<39> buf; |
|
341 |
|
342 // convert to V4 |
|
343 |
|
344 // set address to IPv6 unspecified address |
|
345 addr.Input(_L("::")); |
|
346 |
|
347 // convert to IPv4 format |
|
348 addr.ConvertToV4(); |
|
349 addr.OutputWithScope(buf); |
|
350 |
|
351 // check address has been reformatted correctly |
|
352 addr.OutputWithScope(buf); |
|
353 TESTL(buf==_L("0.0.0.0")); |
|
354 |
|
355 // change address to IPv4 compatible address |
|
356 addr.Input(_L("::199.12.255.21")); |
|
357 |
|
358 // convert to IPv4 format |
|
359 addr.ConvertToV4(); |
|
360 |
|
361 // check address has been reformatted correctly |
|
362 addr.OutputWithScope(buf); |
|
363 TESTL(buf==_L("199.12.255.21")); |
|
364 |
|
365 // change address to IPv4 mapped address |
|
366 addr.Input(_L("::FFFF:149.124.223.12")); |
|
367 |
|
368 // convert to IPv4 format |
|
369 addr.ConvertToV4(); |
|
370 |
|
371 // check address has been reformatted correctly |
|
372 addr.OutputWithScope(buf); |
|
373 TESTL(buf==_L("149.124.223.12")); |
|
374 |
|
375 return EPass; |
|
376 } |
|
377 |
|
378 |
|
379 // Test step 19.7 |
|
380 const TDesC& CEsockTest19_7::GetTestName() |
|
381 { |
|
382 // store the name of this test case |
|
383 _LIT(ret,"Test19.7"); |
|
384 return ret; |
|
385 } |
|
386 |
|
387 CEsockTest19_7::~CEsockTest19_7() |
|
388 { |
|
389 } |
|
390 |
|
391 enum TVerdict CEsockTest19_7::easyTestStepL() |
|
392 { |
|
393 TInetAddr addr; |
|
394 TBuf<39> buf; |
|
395 |
|
396 // set IP address using a prefix length |
|
397 |
|
398 // set IP address |
|
399 addr.PrefixMask(60); |
|
400 |
|
401 // check it has been set correctly |
|
402 addr.OutputWithScope(buf); |
|
403 TESTL(buf==_L("ffff:ffff:ffff:fff0::")); |
|
404 |
|
405 // change the IP address |
|
406 addr.Input(_L("1.1.1.1.1.1.1.1")); |
|
407 |
|
408 // set the IP address using a different prefisx length |
|
409 addr.PrefixMask(58); |
|
410 |
|
411 // check it has been set correctly |
|
412 addr.OutputWithScope(buf); |
|
413 TESTL(buf==_L("ffff:ffff:ffff:ffc0::")); |
|
414 |
|
415 return EPass; |
|
416 } |
|
417 |
|
418 |
|
419 // Test step 19.8 |
|
420 const TDesC& CEsockTest19_8::GetTestName() |
|
421 { |
|
422 // store the name of this test case |
|
423 _LIT(ret,"Test19.8"); |
|
424 return ret; |
|
425 } |
|
426 |
|
427 CEsockTest19_8::~CEsockTest19_8() |
|
428 { |
|
429 } |
|
430 |
|
431 enum TVerdict CEsockTest19_8::easyTestStepL() |
|
432 { |
|
433 TInetAddr addr, addr1; |
|
434 TBuf<39> buf; |
|
435 |
|
436 // setting IP address using an IP address and a prefix length |
|
437 |
|
438 // set an IP address |
|
439 addr1.Input(_L("ffee:fffc:0001:0001:1:1:1:1")); |
|
440 |
|
441 // set the IP address from addr and prefix length |
|
442 addr.Prefix(addr1, 18); |
|
443 |
|
444 // check that the address has been set correctly |
|
445 addr.OutputWithScope(buf); |
|
446 TESTL(buf==(_L("ffee:c000::"))); |
|
447 |
|
448 // set the IP address using a different length |
|
449 addr.Prefix(addr1, 64); |
|
450 |
|
451 // check that the address has been set correctly |
|
452 addr.OutputWithScope(buf); |
|
453 TESTL(buf==(_L("ffee:fffc:1:1::"))); |
|
454 |
|
455 return EPass; |
|
456 } |
|
457 |
|
458 |
|
459 // Test step 19.9 |
|
460 const TDesC& CEsockTest19_9::GetTestName() |
|
461 { |
|
462 // store the name of this test case |
|
463 _LIT(ret,"Test19.9"); |
|
464 return ret; |
|
465 } |
|
466 |
|
467 CEsockTest19_9::~CEsockTest19_9() |
|
468 { |
|
469 } |
|
470 |
|
471 enum TVerdict CEsockTest19_9::easyTestStepL() |
|
472 { |
|
473 TInetAddr addr, addrOut; |
|
474 TBuf<39> buf; |
|
475 |
|
476 // getting the IP address |
|
477 |
|
478 // set an IPv6 address |
|
479 const TIp6Addr KInet6Addr19_3 = {{{0xff,0xff,0,0,0,0,0,0,0,0,0,0,0x1,0x78,0,0x1}}}; |
|
480 addr.SetAddress(KInet6Addr19_3); |
|
481 |
|
482 // get the address - check the return value is 0 |
|
483 TESTL(addr.Address()==0); |
|
484 |
|
485 // set up an IPv4 compatible address |
|
486 TInetAddr addr2(INET_ADDR(140, 179, 229, 12), 23); |
|
487 addr2.ConvertToV4Compat(); |
|
488 |
|
489 // check conversion |
|
490 addr2.OutputWithScope(buf); |
|
491 TESTL(buf==_L("::140.179.229.12")); |
|
492 |
|
493 // get the address - check it is returned as an IPv4 address |
|
494 addrOut.SetAddress(addr2.Address()); |
|
495 addrOut.OutputWithScope(buf); |
|
496 TESTL(buf==_L("140.179.229.12")); |
|
497 |
|
498 // set up an IPv4 mapped address |
|
499 TInetAddr addr3(INET_ADDR(140, 179, 193, 121), 24); |
|
500 addr3.ConvertToV4Mapped(); |
|
501 |
|
502 // check conversion |
|
503 addr3.OutputWithScope(buf); |
|
504 |
|
505 TESTL(buf==_L("140.179.193.121")); |
|
506 |
|
507 // get the address - check it is returned as an IPv4 address |
|
508 addrOut.SetAddress(addr3.Address()); |
|
509 addrOut.OutputWithScope(buf); |
|
510 TESTL(buf==_L("140.179.193.121")); |
|
511 |
|
512 return EPass; |
|
513 } |
|
514 |