|
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 8 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection8.h" |
|
24 |
|
25 |
|
26 // Test step 8.1 |
|
27 const TDesC& CEsockTest8_1::GetTestName() |
|
28 { |
|
29 // store the name of this test case |
|
30 _LIT(ret,"Test8.1"); |
|
31 |
|
32 return ret; |
|
33 } |
|
34 |
|
35 CEsockTest8_1::~CEsockTest8_1() |
|
36 { |
|
37 } |
|
38 |
|
39 enum TVerdict CEsockTest8_1::easyTestStepPreambleL() |
|
40 { |
|
41 TInt connections; |
|
42 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.1"), iSockIndex2, iSockIndex3)); |
|
43 if (KErrNone != ret) |
|
44 { |
|
45 return EFail; |
|
46 } |
|
47 if (0 >= connections) |
|
48 { |
|
49 return EFail; |
|
50 } |
|
51 |
|
52 return EPass; |
|
53 } |
|
54 |
|
55 enum TVerdict CEsockTest8_1::easyTestStepL() |
|
56 { |
|
57 TESTL(EPass == TestStepResult()); |
|
58 |
|
59 // Urgent data test - 1 byte read out-of-band |
|
60 |
|
61 // for client enable KSoTcpNextSendUrgentData |
|
62 TESTL(iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1)==KErrNone); |
|
63 |
|
64 // send a single byte from the client |
|
65 TRequestStatus stat; |
|
66 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("7"), stat); |
|
67 User::WaitForRequest(stat); |
|
68 TESTEL(stat==KErrNone, stat.Int()); |
|
69 |
|
70 // wait for 1 second |
|
71 User::After(1000000); |
|
72 |
|
73 // check on server that urgent data is available |
|
74 TInt nRet; |
|
75 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
76 TESTEL(KErrNone == ret, ret); |
|
77 TESTEL(nRet == 1, nRet); |
|
78 |
|
79 // check the urgent data offset (server) |
|
80 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
81 TESTEL(KErrNone == ret, ret); |
|
82 TESTEL(nRet == 0, nRet); |
|
83 |
|
84 // check the number of bytes to read (server) |
|
85 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
86 TESTEL(KErrNone == ret, ret); |
|
87 TESTEL(nRet == 0, nRet); |
|
88 |
|
89 // get the last error - check it is KErrUrgentData (server) |
|
90 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOSelectLastError, KSOLSocket, nRet); |
|
91 TESTEL(KErrUrgentData == ret, ret); |
|
92 |
|
93 // peek for urgent data (server) |
|
94 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
95 TESTEL(KErrNone == ret, ret); |
|
96 TESTEL(nRet == '7', nRet); |
|
97 |
|
98 // peek again |
|
99 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
100 TESTEL(KErrNone == ret, ret); |
|
101 TESTEL(nRet == '7', nRet); |
|
102 |
|
103 // read the urgent data (server) |
|
104 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
105 TESTEL(KErrNone == ret, ret); |
|
106 TESTEL(nRet == '7', nRet); |
|
107 |
|
108 // read again |
|
109 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
110 TESTEL(KErrNotFound == ret, ret); |
|
111 |
|
112 return EPass; |
|
113 } |
|
114 |
|
115 |
|
116 // Test step 8.2 |
|
117 const TDesC& CEsockTest8_2::GetTestName() |
|
118 { |
|
119 // store the name of this test case |
|
120 _LIT(ret,"Test8.2"); |
|
121 |
|
122 return ret; |
|
123 } |
|
124 |
|
125 CEsockTest8_2::~CEsockTest8_2() |
|
126 { |
|
127 } |
|
128 |
|
129 enum TVerdict CEsockTest8_2::easyTestStepPreambleL() |
|
130 { |
|
131 TInt connections; |
|
132 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.2"), iSockIndex2, iSockIndex3)); |
|
133 if (KErrNone != ret) |
|
134 { |
|
135 return EFail; |
|
136 } |
|
137 if (0 >= connections) |
|
138 { |
|
139 return EFail; |
|
140 } |
|
141 |
|
142 return EPass; |
|
143 } |
|
144 |
|
145 enum TVerdict CEsockTest8_2::easyTestStepL() |
|
146 { |
|
147 TESTL(EPass == TestStepResult()); |
|
148 |
|
149 // Urgent data test - 2 bytes, 1 of urgent data read out-of-band |
|
150 |
|
151 // for client enable KSoTcpNextSendUrgentData |
|
152 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
153 TESTEL(KErrNone == ret, ret); |
|
154 |
|
155 // send 2 bytes of data from the client |
|
156 TRequestStatus stat; |
|
157 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("89"), stat); |
|
158 User::WaitForRequest(stat); |
|
159 TESTEL(stat==KErrNone, stat.Int()); |
|
160 |
|
161 // check on server that urgent data is not available |
|
162 TInt nRet; |
|
163 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
164 TESTEL(KErrNone == ret, ret); |
|
165 TESTEL(0 == nRet, nRet); |
|
166 |
|
167 // wait for 1 second |
|
168 User::After(1000000); |
|
169 |
|
170 // check the urgent data offset (server) |
|
171 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
172 TESTEL(KErrNone == ret, ret); |
|
173 TESTEL(1 == nRet, nRet); |
|
174 |
|
175 // check the number of bytes to read (server) |
|
176 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
177 TESTEL(KErrNone == ret, ret); |
|
178 TESTEL(1 == nRet, nRet); |
|
179 |
|
180 // read the data - check only a single byte is read |
|
181 TBuf8<40> rbuf; |
|
182 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
183 User::WaitForRequest(stat); |
|
184 TESTEL(stat==KErrUrgentData, stat.Int()); |
|
185 TESTL(rbuf==_L8("8")); |
|
186 |
|
187 // check that urgent data is now available |
|
188 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
189 TESTEL(KErrNone == ret, ret); |
|
190 TESTEL(1 == nRet, nRet); |
|
191 |
|
192 // check KSoTcpNextSendUrgentData option is disabled (client) |
|
193 ret = iEsockSuite->GetSocketHandle(iSockIndex2).GetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, nRet); |
|
194 TESTEL(KErrNone == ret, ret); |
|
195 TESTEL(0 == nRet, nRet); |
|
196 |
|
197 // get the last error - check it is KErrUrgentData (server) |
|
198 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOSelectLastError, KSOLSocket, nRet); |
|
199 TESTEL(KErrUrgentData == ret, ret); |
|
200 |
|
201 // peek for urgent data (server) |
|
202 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
203 TESTEL(KErrNone == ret, ret); |
|
204 TESTL(nRet=='9'); |
|
205 |
|
206 // read the urgent data (server) |
|
207 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
208 TESTEL(KErrNone == ret, ret); |
|
209 TESTL(nRet=='9'); |
|
210 |
|
211 // read again |
|
212 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
213 TESTEL(KErrNotFound == ret, ret); |
|
214 |
|
215 return EPass; |
|
216 } |
|
217 |
|
218 |
|
219 // Test step 8.3 |
|
220 const TDesC& CEsockTest8_3::GetTestName() |
|
221 { |
|
222 // store the name of this test case |
|
223 _LIT(ret,"Test8.3"); |
|
224 |
|
225 return ret; |
|
226 } |
|
227 |
|
228 CEsockTest8_3::~CEsockTest8_3() |
|
229 { |
|
230 } |
|
231 |
|
232 enum TVerdict CEsockTest8_3::easyTestStepPreambleL() |
|
233 { |
|
234 TInt connections; |
|
235 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.3"), iSockIndex2, iSockIndex3)); |
|
236 if (KErrNone != ret) |
|
237 { |
|
238 return EFail; |
|
239 } |
|
240 if (0 >= connections) |
|
241 { |
|
242 return EFail; |
|
243 } |
|
244 |
|
245 return EPass; |
|
246 } |
|
247 |
|
248 enum TVerdict CEsockTest8_3::easyTestStepL() |
|
249 { |
|
250 TESTL(EPass == TestStepResult()); |
|
251 |
|
252 // Urgent data test - 14 bytes (4th is urgent) read out-of-band |
|
253 |
|
254 // for client enable KSoTcpNextSendUrgentData |
|
255 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
256 TESTEL(KErrNone == ret, ret); |
|
257 |
|
258 // send 4 bytes of data from the client |
|
259 TRequestStatus stat; |
|
260 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("1234"), stat); |
|
261 User::WaitForRequest(stat); |
|
262 TESTEL(stat==KErrNone, stat.Int()); |
|
263 |
|
264 // send 10 more bytes of data from the client |
|
265 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("abcdefghij"), stat); |
|
266 |
|
267 User::WaitForRequest(stat); |
|
268 TESTEL(stat==KErrNone, stat.Int()); |
|
269 |
|
270 // wait for 1 second |
|
271 User::After(1000000); |
|
272 |
|
273 // check on server that urgent data is not available |
|
274 TInt nRet; |
|
275 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
276 TESTEL(KErrNone == ret, ret); |
|
277 TESTEL(0 == nRet, nRet); |
|
278 |
|
279 // check the urgent data offset (server) |
|
280 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
281 TESTEL(KErrNone == ret, ret); |
|
282 TESTEL(3 == nRet, nRet); |
|
283 |
|
284 // check the number of bytes to read before urgent data(server) |
|
285 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
286 TESTEL(KErrNone == ret, ret); |
|
287 TESTEL(3 == nRet, nRet); |
|
288 |
|
289 // read the data - check only 3 bytes are read |
|
290 TBuf8<10> rbuf; |
|
291 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
292 User::WaitForRequest(stat); |
|
293 TESTEL(stat==KErrUrgentData, stat.Int()); |
|
294 TESTL(rbuf==_L8("123")); |
|
295 |
|
296 // check that urgent data is now available |
|
297 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
298 TESTEL(KErrNone == ret, ret); |
|
299 TESTEL(1 == nRet, nRet); |
|
300 |
|
301 // check the number of bytes to read before urgent data (server) |
|
302 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
303 TESTEL(KErrNone == ret, ret); |
|
304 TESTEL(0 == nRet, nRet); |
|
305 |
|
306 // peek for urgent data (server) |
|
307 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
308 TESTEL(KErrNone == ret, ret); |
|
309 TESTL(nRet=='4'); |
|
310 |
|
311 // read the urgent data (server) |
|
312 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
313 TESTEL(KErrNone == ret, ret); |
|
314 TESTL(nRet=='4'); |
|
315 |
|
316 User::After(1000); |
|
317 |
|
318 // check the number of bytes to read is now updated since we read out urgent data |
|
319 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
320 TESTEL(KErrNone == ret, ret); |
|
321 TESTEL(10 == nRet, nRet); |
|
322 |
|
323 // read the rest of the data |
|
324 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
325 User::WaitForRequest(stat); |
|
326 TESTEL(stat==KErrNone, stat.Int()); |
|
327 TESTL(rbuf==_L8("abcdefghij")); |
|
328 |
|
329 return EPass; |
|
330 } |
|
331 |
|
332 |
|
333 // Test step 8.4 |
|
334 const TDesC& CEsockTest8_4::GetTestName() |
|
335 { |
|
336 // store the name of this test case |
|
337 _LIT(ret,"Test8.4"); |
|
338 |
|
339 return ret; |
|
340 } |
|
341 |
|
342 CEsockTest8_4::~CEsockTest8_4() |
|
343 { |
|
344 } |
|
345 |
|
346 enum TVerdict CEsockTest8_4::easyTestStepPreambleL() |
|
347 { |
|
348 TInt connections; |
|
349 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.4"), iSockIndex2, iSockIndex3)); |
|
350 if (KErrNone != ret) |
|
351 { |
|
352 return EFail; |
|
353 } |
|
354 if (0 >= connections) |
|
355 { |
|
356 return EFail; |
|
357 } |
|
358 |
|
359 return EPass; |
|
360 } |
|
361 |
|
362 enum TVerdict CEsockTest8_4::easyTestStepL() |
|
363 { |
|
364 TESTL(EPass == TestStepResult()); |
|
365 |
|
366 // Urgent data test - 8000 bytes (7998th is urgent) read out-of-band |
|
367 |
|
368 // send data from client - 8000 bytes with 7998th marked urgent |
|
369 TBuf8<100> wbuf; |
|
370 TRequestStatus stat; |
|
371 for (TInt i=0 ; i<80 ; i++) |
|
372 { |
|
373 wbuf.SetMax(); |
|
374 wbuf.Fill(TChar((TUint8)i)); // fill buffer with data |
|
375 |
|
376 if (i==79) // send 100 chars with 98th marked urgent |
|
377 { |
|
378 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf.Mid(0,97), stat); |
|
379 User::WaitForRequest(stat); |
|
380 TESTEL(stat==KErrNone, stat.Int()); |
|
381 |
|
382 TESTL(iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1)==KErrNone); |
|
383 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("?"), stat); |
|
384 User::WaitForRequest(stat); |
|
385 TESTEL(stat==KErrNone, stat.Int()); |
|
386 |
|
387 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("yz"), stat); |
|
388 User::WaitForRequest(stat); |
|
389 TESTEL(stat==KErrNone, stat.Int()); |
|
390 } |
|
391 else // send 100 chars |
|
392 { |
|
393 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf, stat); |
|
394 User::WaitForRequest(stat); |
|
395 TESTEL(stat==KErrNone, stat.Int()); |
|
396 } |
|
397 } |
|
398 |
|
399 User::After(1000000); |
|
400 |
|
401 // check on server that urgent data is not available |
|
402 TInt nRet; |
|
403 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
404 TESTEL(KErrNone == ret, ret); |
|
405 TESTEL(0 == nRet, nRet); |
|
406 |
|
407 // check the urgent data offset (server) |
|
408 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
409 TESTEL(KErrNone == ret, ret); |
|
410 TESTEL(7997 == nRet, nRet); |
|
411 |
|
412 // check the number of bytes to read before urgent data(server) |
|
413 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
414 TESTEL(KErrNone == ret, ret); |
|
415 TESTEL(7997 == nRet, nRet); |
|
416 |
|
417 // read the data - check all bytes are read |
|
418 TInt expectedRet = KErrNone; |
|
419 TBuf8<100> rbuf; |
|
420 TInt count; |
|
421 for (count = 0; count < 7997;) |
|
422 { |
|
423 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
424 User::WaitForRequest(stat); |
|
425 TESTL(stat==expectedRet); |
|
426 count+=rbuf.Length(); |
|
427 if (count == 7900) |
|
428 { |
|
429 expectedRet = KErrUrgentData; |
|
430 } |
|
431 } |
|
432 TESTEL(7997 == count, count); |
|
433 |
|
434 // check that urgent data is now available |
|
435 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
436 TESTEL(KErrNone == ret, ret); |
|
437 TESTEL(1 == nRet, nRet); |
|
438 |
|
439 // check the number of bytes to read before urgent data(server) |
|
440 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
441 TESTEL(KErrNone == ret, ret); |
|
442 TESTEL(0 == nRet, nRet); |
|
443 |
|
444 // read the urgent data (server) |
|
445 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
446 TESTEL(KErrNone == ret, ret); |
|
447 TESTL(nRet=='?'); |
|
448 |
|
449 User::After(1000); |
|
450 |
|
451 // check the number of bytes to read (server) |
|
452 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
453 TESTEL(KErrNone == ret, ret); |
|
454 TESTEL(2 == nRet, nRet); |
|
455 |
|
456 // read the rest of the data |
|
457 TBuf8<2> rbuf2; |
|
458 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
459 User::WaitForRequest(stat); |
|
460 TESTEL(stat==KErrNone, stat.Int()); |
|
461 TESTL(rbuf2==_L8("yz")); |
|
462 |
|
463 return EPass; |
|
464 } |
|
465 |
|
466 |
|
467 // Test step 8.5 |
|
468 const TDesC& CEsockTest8_5::GetTestName() |
|
469 { |
|
470 // store the name of this test case |
|
471 _LIT(ret,"Test8.5"); |
|
472 |
|
473 return ret; |
|
474 } |
|
475 |
|
476 CEsockTest8_5::~CEsockTest8_5() |
|
477 { |
|
478 } |
|
479 |
|
480 enum TVerdict CEsockTest8_5::easyTestStepPreambleL() |
|
481 { |
|
482 TInt connections; |
|
483 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.5"), iSockIndex2, iSockIndex3)); |
|
484 if (KErrNone != ret) |
|
485 { |
|
486 return EFail; |
|
487 } |
|
488 if (0 >= connections) |
|
489 { |
|
490 return EFail; |
|
491 } |
|
492 |
|
493 return EPass; |
|
494 } |
|
495 |
|
496 enum TVerdict CEsockTest8_5::easyTestStepL() |
|
497 { |
|
498 TESTL(EPass == TestStepResult()); |
|
499 |
|
500 // Urgent data test - 1 byte of data read in-band |
|
501 |
|
502 // for server enable KSoTcpOobInline |
|
503 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).SetOpt(KSoTcpOobInline, KSolInetTcp, 1); |
|
504 TESTEL(KErrNone == ret, ret); |
|
505 |
|
506 // for client enable KSoTcpNextSendUrgentData |
|
507 ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
508 TESTEL(KErrNone == ret, ret); |
|
509 |
|
510 // send a single data byte from the client |
|
511 TRequestStatus stat; |
|
512 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("7"), stat); |
|
513 User::WaitForRequest(stat); |
|
514 TESTEL(stat==KErrNone, stat.Int()); |
|
515 |
|
516 // delay for 1 second |
|
517 User::After(1000000); |
|
518 |
|
519 // check on server that urgent data is available |
|
520 TInt nRet; |
|
521 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
522 TESTEL(KErrNone == ret, ret); |
|
523 TESTEL(1 == nRet, nRet); |
|
524 |
|
525 // check the urgent data offset (server) |
|
526 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
527 TESTEL(KErrNone == ret, ret); |
|
528 TESTEL(0 == nRet, nRet); |
|
529 |
|
530 // check the number of bytes to read (server) |
|
531 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
532 TESTEL(KErrNone == ret, ret); |
|
533 TESTEL(1 == nRet, nRet); |
|
534 |
|
535 // check KSoTcpNextSendUrgentData option is disabled (client) |
|
536 ret = iEsockSuite->GetSocketHandle(iSockIndex2).GetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, nRet); |
|
537 TESTEL(KErrNone == ret, ret); |
|
538 TESTEL(0 == nRet, nRet); |
|
539 |
|
540 // check that there is no error state for the socket |
|
541 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOSelectLastError, KSOLSocket, nRet); |
|
542 TESTEL(KErrNone == ret, ret); |
|
543 |
|
544 // peek for urgent data (server) |
|
545 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
546 TESTEL(KErrNotFound == ret, ret); |
|
547 |
|
548 // read urgent data (server) |
|
549 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
550 TESTEL(KErrNotFound == ret, ret); |
|
551 |
|
552 // read the data - check only 1 byte is read |
|
553 TBuf8<1> rbuf; |
|
554 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
555 User::WaitForRequest(stat); |
|
556 TESTEL(stat==KErrNone, stat.Int()); |
|
557 TESTL(rbuf==_L8("7")); |
|
558 |
|
559 return EPass; |
|
560 } |
|
561 |
|
562 |
|
563 // Test step 8.6 |
|
564 const TDesC& CEsockTest8_6::GetTestName() |
|
565 { |
|
566 // store the name of this test case |
|
567 _LIT(ret,"Test8.6"); |
|
568 |
|
569 return ret; |
|
570 } |
|
571 |
|
572 CEsockTest8_6::~CEsockTest8_6() |
|
573 { |
|
574 } |
|
575 |
|
576 enum TVerdict CEsockTest8_6::easyTestStepPreambleL() |
|
577 { |
|
578 TInt connections; |
|
579 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.6"), iSockIndex2, iSockIndex3)); |
|
580 if (KErrNone != ret) |
|
581 { |
|
582 return EFail; |
|
583 } |
|
584 if (0 >= connections) |
|
585 { |
|
586 return EFail; |
|
587 } |
|
588 |
|
589 return EPass; |
|
590 } |
|
591 |
|
592 enum TVerdict CEsockTest8_6::easyTestStepL() |
|
593 { |
|
594 TESTL(EPass == TestStepResult()); |
|
595 |
|
596 // Urgent data test - 2 bytes one of urgent data read in-band |
|
597 |
|
598 // for server enable KSoTcpOobInline |
|
599 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).SetOpt(KSoTcpOobInline, KSolInetTcp, 1); |
|
600 TESTEL(KErrNone == ret, ret); |
|
601 |
|
602 // for client enable KSoTcpNextSendUrgentData |
|
603 ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
604 TESTEL(KErrNone == ret, ret); |
|
605 |
|
606 // send 2 bytes of data from the client |
|
607 TRequestStatus stat; |
|
608 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("89"), stat); |
|
609 User::WaitForRequest(stat); |
|
610 TESTEL(stat==KErrNone, stat.Int()); |
|
611 |
|
612 User::After(1000000); |
|
613 |
|
614 // check on server that urgent data is not available |
|
615 TInt nRet; |
|
616 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
617 TESTEL(KErrNone == ret, ret); |
|
618 TESTEL(0 == nRet, nRet); |
|
619 |
|
620 // check the urgent data offset (server) |
|
621 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
622 TESTEL(KErrNone == ret, ret); |
|
623 TESTEL(1 == nRet, nRet); |
|
624 |
|
625 // check the number of bytes to read before urgent data (server) |
|
626 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
627 TESTEL(KErrNone == ret, ret); |
|
628 TESTEL(1 == nRet, nRet); |
|
629 |
|
630 // read the data - check only 1 byte is read |
|
631 TBuf8<1> rbuf; |
|
632 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
633 User::WaitForRequest(stat); |
|
634 TESTEL(stat==KErrNone, stat.Int()); |
|
635 TESTL(rbuf==_L8("8")); |
|
636 |
|
637 User::After(1000); |
|
638 |
|
639 // read again - check the remaining byte is read |
|
640 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
641 User::WaitForRequest(stat); |
|
642 TESTEL(stat==KErrNone, stat.Int()); |
|
643 TESTL(rbuf==_L8("9")); |
|
644 |
|
645 // check urgent data is not available |
|
646 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
647 TESTEL(KErrNone == ret, ret); |
|
648 TESTEL(0 == nRet, nRet); |
|
649 |
|
650 // peek for urgent data (server) |
|
651 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
652 TESTEL(KErrNotFound == ret, ret); |
|
653 |
|
654 // read urgent data (server) |
|
655 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
656 TESTEL(KErrNotFound == ret, ret); |
|
657 |
|
658 return EPass; |
|
659 } |
|
660 |
|
661 |
|
662 // Test step 8.7 |
|
663 const TDesC& CEsockTest8_7::GetTestName() |
|
664 { |
|
665 // store the name of this test case |
|
666 _LIT(ret,"Test8.7"); |
|
667 |
|
668 return ret; |
|
669 } |
|
670 |
|
671 CEsockTest8_7::~CEsockTest8_7() |
|
672 { |
|
673 } |
|
674 |
|
675 enum TVerdict CEsockTest8_7::easyTestStepPreambleL() |
|
676 { |
|
677 TInt connections; |
|
678 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.7"), iSockIndex2, iSockIndex3)); |
|
679 if (KErrNone != ret) |
|
680 { |
|
681 return EFail; |
|
682 } |
|
683 if (0 >= connections) |
|
684 { |
|
685 return EFail; |
|
686 } |
|
687 |
|
688 return EPass; |
|
689 } |
|
690 |
|
691 enum TVerdict CEsockTest8_7::easyTestStepL() |
|
692 { |
|
693 TESTL(EPass == TestStepResult()); |
|
694 |
|
695 // Urgent data test - 14 bytes (4th is urgent) read in-band |
|
696 |
|
697 // for server enable KSoTcpOobInline |
|
698 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).SetOpt(KSoTcpOobInline, KSolInetTcp, 1); |
|
699 TESTEL(KErrNone == ret, ret); |
|
700 |
|
701 // for client enable KSoTcpNextSendUrgentData |
|
702 ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
703 TESTEL(KErrNone == ret, ret); |
|
704 |
|
705 // send 4 bytes of data from the client |
|
706 TRequestStatus stat; |
|
707 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("1234"), stat); |
|
708 User::WaitForRequest(stat); |
|
709 TESTEL(stat==KErrNone, stat.Int()); |
|
710 |
|
711 // send 10 more bytes of data from the client |
|
712 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("1234567890"), stat); |
|
713 User::WaitForRequest(stat); |
|
714 TESTEL(stat==KErrNone, stat.Int()); |
|
715 |
|
716 User::After(1000000); |
|
717 |
|
718 // check on server that urgent data is not available |
|
719 TInt nRet; |
|
720 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
721 TESTEL(KErrNone == ret, ret); |
|
722 TESTEL(0 == nRet, nRet); |
|
723 |
|
724 // check the urgent data offset (server) |
|
725 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
726 TESTEL(KErrNone == ret, ret); |
|
727 TESTEL(3 == nRet, nRet); |
|
728 |
|
729 // check the number of bytes to read before urgent data(server) |
|
730 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
731 TESTEL(KErrNone == ret, ret); |
|
732 TESTEL(3 == nRet, nRet); |
|
733 |
|
734 // read the data - check only 3 bytes are read |
|
735 TBuf8<11> rbuf; |
|
736 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
737 User::WaitForRequest(stat); |
|
738 TESTEL(stat==KErrNone, stat.Int()); |
|
739 TESTL(rbuf==_L8("123")); |
|
740 |
|
741 // check urgent data is available |
|
742 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
743 TESTEL(KErrNone == ret, ret); |
|
744 TESTEL(1 == nRet, nRet); |
|
745 |
|
746 // read again - check the remaining data is read |
|
747 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
748 User::WaitForRequest(stat); |
|
749 TESTEL(stat==KErrNone, stat.Int()); |
|
750 TESTL(rbuf==_L8("41234567890")); |
|
751 |
|
752 // check urgent data is not available |
|
753 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
754 TESTEL(KErrNone == ret, ret); |
|
755 TESTEL(0 == nRet, nRet); |
|
756 |
|
757 // peek for urgent data (server) |
|
758 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpPeekUrgentData, KSolInetTcp, nRet); |
|
759 TESTEL(KErrNotFound == ret, ret); |
|
760 |
|
761 // read urgent data (server) |
|
762 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
763 TESTEL(KErrNotFound == ret, ret); |
|
764 |
|
765 return EPass; |
|
766 } |
|
767 |
|
768 |
|
769 // Test step 8.8 |
|
770 const TDesC& CEsockTest8_8::GetTestName() |
|
771 { |
|
772 // store the name of this test case |
|
773 _LIT(ret,"Test8.8"); |
|
774 |
|
775 return ret; |
|
776 } |
|
777 |
|
778 CEsockTest8_8::~CEsockTest8_8() |
|
779 { |
|
780 } |
|
781 |
|
782 enum TVerdict CEsockTest8_8::easyTestStepPreambleL() |
|
783 { |
|
784 TInt connections; |
|
785 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.8"), iSockIndex2, iSockIndex3)); |
|
786 if (KErrNone != ret) |
|
787 { |
|
788 return EFail; |
|
789 } |
|
790 if (0 >= connections) |
|
791 { |
|
792 return EFail; |
|
793 } |
|
794 |
|
795 return EPass; |
|
796 } |
|
797 |
|
798 enum TVerdict CEsockTest8_8::easyTestStepL() |
|
799 { |
|
800 TESTL(EPass == TestStepResult()); |
|
801 |
|
802 // Urgent data test - 8000 bytes (7998th is urgent) read in-band |
|
803 |
|
804 // for server enable KSoTcpOobInline |
|
805 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex3).SetOpt(KSoTcpOobInline, KSolInetTcp, 1); |
|
806 TESTEL(KErrNone == ret, ret); |
|
807 |
|
808 // send data from client - 8000 bytes with 7998th marked urgent |
|
809 TBuf8<100> wbuf; |
|
810 TRequestStatus stat; |
|
811 for (TInt i=0 ; i<80 ; i++) |
|
812 { |
|
813 wbuf.SetMax(); |
|
814 wbuf.Fill(TChar((TUint8)i)); // fill buffer with data |
|
815 |
|
816 if (i==79) // send 100 chars with 98th marked urgent |
|
817 { |
|
818 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf.Mid(0,97), stat); |
|
819 User::WaitForRequest(stat); |
|
820 TESTEL(stat==KErrNone, stat.Int()); |
|
821 |
|
822 TESTL(iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1)==KErrNone); |
|
823 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("?"), stat); |
|
824 User::WaitForRequest(stat); |
|
825 TESTEL(stat==KErrNone, stat.Int()); |
|
826 |
|
827 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("yz"), stat); |
|
828 User::WaitForRequest(stat); |
|
829 TESTEL(stat==KErrNone, stat.Int()); |
|
830 } |
|
831 else // send 100 chars |
|
832 { |
|
833 iEsockSuite->GetSocketHandle(iSockIndex2).Write(wbuf, stat); |
|
834 User::WaitForRequest(stat); |
|
835 TESTEL(stat==KErrNone, stat.Int()); |
|
836 } |
|
837 } |
|
838 |
|
839 // check on server that urgent data is not available |
|
840 TInt nRet; |
|
841 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
842 TESTEL(KErrNone == ret, ret); |
|
843 TESTEL(0 == nRet, nRet); |
|
844 |
|
845 User::After(1000000); |
|
846 |
|
847 // check the urgent data offset (server) |
|
848 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
849 TESTEL(KErrNone == ret, ret); |
|
850 TESTEL(7997 == nRet, nRet); |
|
851 |
|
852 // check the number of bytes to read before urgent data (server) |
|
853 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
854 TESTEL(KErrNone == ret, ret); |
|
855 TESTEL(7997 == nRet, nRet); |
|
856 |
|
857 // read the data - check all 7997 bytes are read |
|
858 TBuf8<100> rbuf; |
|
859 TInt count; |
|
860 for (count = 0; count < 7997;) |
|
861 { |
|
862 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
863 User::WaitForRequest(stat); |
|
864 TESTEL(stat==KErrNone, stat.Int()); |
|
865 count+=rbuf.Length(); |
|
866 if (count == 7900) |
|
867 rbuf.SetLength(97); |
|
868 } |
|
869 TESTEL(7997 == count, count); |
|
870 |
|
871 // check that urgent data is available |
|
872 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
873 TESTEL(KErrNone == ret, ret); |
|
874 TESTEL(1 == nRet, nRet); |
|
875 |
|
876 // attempt to read the urgent data (server) |
|
877 TESTL(iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet)==KErrNotFound); |
|
878 |
|
879 // read data - check only a single byte is returned |
|
880 TBuf8<1> rbuf2; |
|
881 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
882 User::WaitForRequest(stat); |
|
883 TESTEL(stat==KErrNone, stat.Int()); |
|
884 TESTL(rbuf2==_L8("?")); |
|
885 |
|
886 // check that urgent data is not available |
|
887 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
888 TESTEL(KErrNone == ret, ret); |
|
889 TESTEL(0 == nRet, nRet); |
|
890 |
|
891 // check the number of bytes to read (server) |
|
892 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
893 TESTEL(KErrNone == ret, ret); |
|
894 TESTEL(2 == nRet, nRet); |
|
895 |
|
896 // check the urgent data offset (server) |
|
897 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
898 TESTEL(KErrNone == ret, ret); |
|
899 TESTEL(0 == nRet, nRet); |
|
900 |
|
901 // read the rest of the data - expecting 'y' followed by 'z' |
|
902 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
903 User::WaitForRequest(stat); |
|
904 TESTEL(stat==KErrNone, stat.Int()); |
|
905 TESTL(rbuf2==_L8("y")); |
|
906 |
|
907 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
908 User::WaitForRequest(stat); |
|
909 TESTEL(stat==KErrNone, stat.Int()); |
|
910 TESTL(rbuf2==_L8("z")); |
|
911 |
|
912 return EPass; |
|
913 } |
|
914 |
|
915 |
|
916 // Test step 8.9 |
|
917 const TDesC& CEsockTest8_9::GetTestName() |
|
918 { |
|
919 // store the name of this test case |
|
920 _LIT(ret,"Test8.9"); |
|
921 |
|
922 return ret; |
|
923 } |
|
924 |
|
925 CEsockTest8_9::~CEsockTest8_9() |
|
926 { |
|
927 } |
|
928 |
|
929 enum TVerdict CEsockTest8_9::easyTestStepPreambleL() |
|
930 { |
|
931 TInt connections; |
|
932 TRAPD(ret, connections = OpenConnectionsL(_L("Test_8.9"), iSockIndex2, iSockIndex3)); |
|
933 if (KErrNone != ret) |
|
934 { |
|
935 return EFail; |
|
936 } |
|
937 if (0 >= connections) |
|
938 { |
|
939 return EFail; |
|
940 } |
|
941 |
|
942 return EPass; |
|
943 } |
|
944 |
|
945 enum TVerdict CEsockTest8_9::easyTestStepL() |
|
946 { |
|
947 TESTL(EPass == TestStepResult()); |
|
948 |
|
949 // Urgent data test - send 1 urgent byte and then another read out-of-band |
|
950 |
|
951 // send 4 bytes of data from the client |
|
952 TRequestStatus stat; |
|
953 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("1234"), stat); |
|
954 User::WaitForRequest(stat); |
|
955 TESTEL(stat==KErrNone, stat.Int()); |
|
956 |
|
957 // for client enable KSoTcpNextSendUrgentData |
|
958 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
959 TESTEL(KErrNone == ret, ret); |
|
960 |
|
961 // send 4 more bytes |
|
962 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("5678"), stat); |
|
963 User::WaitForRequest(stat); |
|
964 TESTEL(stat==KErrNone, stat.Int()); |
|
965 |
|
966 User::After(2000000); // Per the outcome of DEF036402, the stack behaviour is not to guarantee that urgent data |
|
967 // forces segment send. Hence here we for 5 seconds to ensure that it does get sent |
|
968 |
|
969 // send 5 more bytes |
|
970 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("90abc"), stat); |
|
971 User::WaitForRequest(stat); |
|
972 TESTEL(stat==KErrNone, stat.Int()); |
|
973 |
|
974 // enable KSoTcpNextSendUrgentData again |
|
975 ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
976 TESTEL(KErrNone == ret, ret); |
|
977 |
|
978 // send 4 more bytes |
|
979 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("defg"), stat); |
|
980 User::WaitForRequest(stat); |
|
981 TESTEL(stat==KErrNone, stat.Int()); |
|
982 |
|
983 // send a final 4 bytes |
|
984 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("hijk"), stat); |
|
985 User::WaitForRequest(stat); |
|
986 TESTEL(stat==KErrNone, stat.Int()); |
|
987 |
|
988 User::After(1000000); |
|
989 |
|
990 // check on server that urgent data is not available |
|
991 TInt nRet; |
|
992 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
993 TESTEL(KErrNone == ret, ret); |
|
994 TESTEL(0 == nRet, nRet); |
|
995 |
|
996 // check the urgent data offset (server) |
|
997 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
998 TESTEL(KErrNone == ret, ret); |
|
999 TESTEL(15 == nRet, nRet); |
|
1000 |
|
1001 // check the number of bytes to read before urgent data(server) |
|
1002 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
1003 TESTEL(KErrNone == ret, ret); |
|
1004 TESTEL(7 == nRet, nRet); |
|
1005 |
|
1006 // check KSoTcpNextSendUrgentData option is disabled (client) |
|
1007 ret = iEsockSuite->GetSocketHandle(iSockIndex2).GetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, nRet); |
|
1008 TESTEL(KErrNone == ret, ret); |
|
1009 TESTEL(0 == nRet, nRet); |
|
1010 |
|
1011 // Attempt to read 10 bytes of data (server). Due to urgent data should complete with KErrUrgentData and |
|
1012 // 7 bytes |
|
1013 TBuf8<10> rbuf; |
|
1014 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
1015 User::WaitForRequest(stat); |
|
1016 TESTEL(stat==KErrUrgentData, stat.Int()); |
|
1017 TESTL(rbuf==_L8("1234567")); |
|
1018 |
|
1019 // the test code below matches the current stack behaviour but it doesn't seem very sensible/intuitive |
|
1020 // In essence it is that the position of the urgent data mark is that of the most recently received urgent data |
|
1021 // even though the stack tracks several urgent data marks in the stream. Specifically, the above test indicates |
|
1022 // urgent data at byte 8, but the RcvAtMark is not set, the offset points to the second mark, and the byte at |
|
1023 // that position is the second urgent write's "g". If the second urgent write is suppressed then here we see |
|
1024 // that we are at the urgent mark, its offset is 0, and the byte is "8". |
|
1025 |
|
1026 // check that urgent data is not available |
|
1027 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
1028 TESTEL(KErrNone == ret, ret); |
|
1029 Logger().WriteFormat(_L("TcpRcvAtMark=%d."), nRet); |
|
1030 TESTL(nRet==0); |
|
1031 |
|
1032 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
1033 TESTEL(KErrNone == ret, ret); |
|
1034 Logger().WriteFormat(_L("KSOUrgentDataOffset=%d."), nRet); |
|
1035 TESTL(nRet==8); |
|
1036 |
|
1037 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
1038 TESTEL(KErrNone == ret, ret); |
|
1039 Logger().WriteFormat(_L("KSOReadBytesPending=%d."), nRet); |
|
1040 TESTL(nRet==8); |
|
1041 |
|
1042 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf, stat); |
|
1043 User::WaitForRequest(stat); |
|
1044 TESTEL(stat==KErrNone, stat.Int()); |
|
1045 TESTL(rbuf==_L8("90abcdef")); |
|
1046 |
|
1047 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpRcvAtMark, KSolInetTcp, nRet); |
|
1048 TESTEL(KErrNone == ret, ret); |
|
1049 Logger().WriteFormat(_L("KSoTcpRcvAtMark=%d."), nRet); |
|
1050 TESTL(nRet==1); |
|
1051 |
|
1052 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOUrgentDataOffset, KSOLSocket, nRet); |
|
1053 TESTEL(KErrNone == ret, ret); |
|
1054 Logger().WriteFormat(_L("KSOUrgentDataOffset=%d."), nRet); |
|
1055 TESTL(nRet==0); |
|
1056 |
|
1057 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
1058 TESTEL(KErrNone == ret, ret); |
|
1059 Logger().WriteFormat(_L("KSoTcpReadUrgentData=%d."), nRet); |
|
1060 TESTL(nRet=='g'); |
|
1061 |
|
1062 User::After(1000); |
|
1063 |
|
1064 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSOReadBytesPending, KSOLSocket, nRet); |
|
1065 TESTEL(KErrNone == ret, ret); |
|
1066 Logger().WriteFormat(_L("KSOReadBytesPending=%d."), nRet); |
|
1067 TESTL(nRet==4); |
|
1068 |
|
1069 // read the remaining data |
|
1070 TBuf8<4> rbuf2; |
|
1071 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
1072 User::WaitForRequest(stat); |
|
1073 TESTEL(stat==KErrNone, stat.Int()); |
|
1074 TESTL(rbuf2==_L8("hijk")); |
|
1075 |
|
1076 return EPass; |
|
1077 } |
|
1078 |
|
1079 |
|
1080 // Test step 8.10 |
|
1081 const TDesC& CEsockTest8_10::GetTestName() |
|
1082 { |
|
1083 // store the name of this test case |
|
1084 _LIT(ret,"Test8.10"); |
|
1085 |
|
1086 return ret; |
|
1087 } |
|
1088 |
|
1089 CEsockTest8_10::~CEsockTest8_10() |
|
1090 { |
|
1091 } |
|
1092 |
|
1093 enum TVerdict CEsockTest8_10::easyTestStepL() |
|
1094 { |
|
1095 TInetAddr addrLocal, addrRemote; |
|
1096 TInt sockIndex1, sockIndex2, sockIndex3; |
|
1097 |
|
1098 // get local ip address |
|
1099 TESTL(GetIpAddressFromConfig(_L("Test_8.10"), _L("ipAddressLocal"), addrLocal)); |
|
1100 |
|
1101 // get ip address to connect to (usually loopback) |
|
1102 TESTL(GetIpAddressFromConfig(_L("Test_8.10"), _L("ipAddressRemote"), addrRemote)); |
|
1103 addrRemote.SetPort(1); |
|
1104 |
|
1105 // open socket and listen for connect requests |
|
1106 TESTL(KErrNone == OpenListeningSocketL(addrLocal, sockIndex1)); |
|
1107 |
|
1108 RSocket sock; |
|
1109 TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1110 TESTEL(KErrNone == nRet, nRet); |
|
1111 |
|
1112 // set receive window size |
|
1113 TInt ret = sock.SetOpt(KSoTcpRecvWinSize, KSolInetTcp, 20); |
|
1114 TESTEL(KErrNone == ret, ret); |
|
1115 |
|
1116 TRequestStatus stat; |
|
1117 sock.Connect(addrRemote, stat); |
|
1118 User::WaitForRequest(stat); |
|
1119 TESTEL(stat==KErrNone, stat.Int()); |
|
1120 |
|
1121 sockIndex2 = iEsockSuite->AddSocketToListL(sock); |
|
1122 |
|
1123 // accept connect request |
|
1124 TESTL(KErrNone == AcceptConnectionL(sockIndex3, sockIndex1)); |
|
1125 |
|
1126 // write 35 bytes (server to client) |
|
1127 iEsockSuite->GetSocketHandle(sockIndex3).Write(_L8("abcdefghijklmnopqrstuvwxyz012345678"), stat); |
|
1128 User::WaitForRequest(stat); |
|
1129 TESTEL(stat==KErrNone, stat.Int()); |
|
1130 |
|
1131 // client has nothing to read |
|
1132 iEsockSuite->GetSocketHandle(sockIndex2).GetOpt(KSoTcpReadBytesPending, KSolInetTcp, nRet); |
|
1133 TESTEL(0 == nRet, nRet); |
|
1134 |
|
1135 // server has data buffered for sending |
|
1136 iEsockSuite->GetSocketHandle(sockIndex3).GetOpt(KSoTcpSendBytesPending, KSolInetTcp, nRet); |
|
1137 TESTEL(35 == nRet, nRet); |
|
1138 |
|
1139 // write another 35 bytes |
|
1140 iEsockSuite->GetSocketHandle(sockIndex3).Write(_L8("abcdefghijklmnopqrstuvwxyz012345678"), stat); |
|
1141 User::WaitForRequest(stat); |
|
1142 TESTEL(stat==KErrNone, stat.Int()); |
|
1143 |
|
1144 // client has only 20 bytes to read |
|
1145 iEsockSuite->GetSocketHandle(sockIndex2).GetOpt(KSoTcpReadBytesPending, KSolInetTcp, nRet); |
|
1146 TESTEL(20 == nRet, nRet); |
|
1147 |
|
1148 // server has remainder buffered |
|
1149 iEsockSuite->GetSocketHandle(sockIndex3).GetOpt(KSoTcpSendBytesPending, KSolInetTcp, nRet); |
|
1150 TESTEL(50 == nRet, nRet); |
|
1151 |
|
1152 // read on client |
|
1153 TBuf8<100> rbuf; |
|
1154 TSockXfrLength len; |
|
1155 iEsockSuite->GetSocketHandle(sockIndex2).RecvOneOrMore(rbuf, 0, stat, len); |
|
1156 User::WaitForRequest(stat); |
|
1157 TESTEL(stat==KErrNone, stat.Int()); |
|
1158 TESTEL(20 == len(), len()); |
|
1159 |
|
1160 // client has only 20 bytes to read |
|
1161 iEsockSuite->GetSocketHandle(sockIndex2).GetOpt(KSoTcpReadBytesPending, KSolInetTcp, nRet); |
|
1162 TESTEL(20 == nRet, nRet); |
|
1163 |
|
1164 // server has remainder buffered |
|
1165 iEsockSuite->GetSocketHandle(sockIndex3).GetOpt(KSoTcpSendBytesPending, KSolInetTcp, nRet); |
|
1166 TESTEL(30 == nRet, nRet); |
|
1167 |
|
1168 iEsockSuite->GetSocketHandle(sockIndex2).RecvOneOrMore(rbuf, 0, stat, len); |
|
1169 User::WaitForRequest(stat); |
|
1170 TESTEL(stat==KErrNone, stat.Int()); |
|
1171 |
|
1172 return EPass; |
|
1173 } |
|
1174 |
|
1175 |
|
1176 |
|
1177 // Test step 8.13 |
|
1178 const TDesC& CEsockTest8_13::GetTestName() |
|
1179 { |
|
1180 // store the name of this test case |
|
1181 _LIT(ret,"Test8.13"); |
|
1182 |
|
1183 return ret; |
|
1184 } |
|
1185 |
|
1186 CEsockTest8_13::~CEsockTest8_13() |
|
1187 { |
|
1188 } |
|
1189 |
|
1190 enum TVerdict CEsockTest8_13::easyTestStepL() |
|
1191 { |
|
1192 // Reuse of address test |
|
1193 |
|
1194 // get ip address |
|
1195 TInetAddr addr; |
|
1196 TESTL(GetIpAddressFromConfig(_L("Test_8.13"), _L("ipAddress"), addr)); |
|
1197 |
|
1198 // get port number |
|
1199 TInt port; |
|
1200 TESTL(GetIntFromConfig(_L("Test_8.13"), _L("port"), port)); |
|
1201 |
|
1202 RSocket sock1; |
|
1203 CleanupClosePushL(sock1); |
|
1204 TInt nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1205 TESTEL(KErrNone == nRet, nRet); |
|
1206 // store socket handle |
|
1207 TInt sockIndex1 = iEsockSuite->AddSocketToListL(sock1); |
|
1208 CleanupStack::Pop(); |
|
1209 |
|
1210 RSocket sock2; |
|
1211 CleanupClosePushL(sock2); |
|
1212 nRet = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1213 TESTEL(KErrNone == nRet, nRet); |
|
1214 // store socket handle |
|
1215 TInt sockIndex2 = iEsockSuite->AddSocketToListL(sock2); |
|
1216 CleanupStack::Pop(); |
|
1217 |
|
1218 // set the port number |
|
1219 addr.SetPort(port); |
|
1220 |
|
1221 // bind the socket |
|
1222 nRet = sock1.Bind(addr); |
|
1223 TESTEL(nRet==KErrNone, nRet); |
|
1224 |
|
1225 // bind the socket to the same address - check for failure |
|
1226 nRet = sock2.Bind(addr); |
|
1227 TESTEL(nRet==KErrInUse, nRet); |
|
1228 |
|
1229 // close the 2 sockets |
|
1230 iEsockSuite->CloseSocket(sockIndex2); |
|
1231 iEsockSuite->CloseSocket(sockIndex1); |
|
1232 |
|
1233 CleanupClosePushL(sock1); |
|
1234 nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1235 TESTEL(KErrNone == nRet, nRet); |
|
1236 sockIndex1=iEsockSuite->AddSocketToListL(sock1); |
|
1237 CleanupStack::Pop(); |
|
1238 |
|
1239 CleanupClosePushL(sock2); |
|
1240 nRet = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1241 TESTEL(KErrNone == nRet, nRet); |
|
1242 sockIndex2=iEsockSuite->AddSocketToListL(sock2); |
|
1243 CleanupStack::Pop(); |
|
1244 |
|
1245 // for each of the 2 sockets enable the KSoReuseAddr option |
|
1246 TESTL(sock1.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
1247 TESTL(sock2.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
1248 |
|
1249 // bind the first socket |
|
1250 nRet = sock1.Bind(addr); |
|
1251 TESTEL(nRet==KErrNone, nRet); |
|
1252 |
|
1253 // bind the second socket - this time it is successful |
|
1254 nRet = sock2.Bind(addr); |
|
1255 TESTEL(nRet==KErrNone, nRet); |
|
1256 |
|
1257 // close the sockets (run test 1.15 to close any sockets) |
|
1258 |
|
1259 return EPass; |
|
1260 } |
|
1261 |
|
1262 |
|
1263 // Test step 8.14 |
|
1264 const TDesC& CEsockTest8_14::GetTestName() |
|
1265 { |
|
1266 // store the name of this test case |
|
1267 _LIT(ret,"Test8.14"); |
|
1268 |
|
1269 return ret; |
|
1270 } |
|
1271 |
|
1272 CEsockTest8_14::~CEsockTest8_14() |
|
1273 { |
|
1274 } |
|
1275 |
|
1276 enum TVerdict CEsockTest8_14::easyTestStepL() |
|
1277 { |
|
1278 TInetAddr addrLocal, addrRemote; |
|
1279 TInt sockIndex1, sockIndex2, sockIndex3; |
|
1280 |
|
1281 // 2MSL wait test |
|
1282 |
|
1283 // get local ip address |
|
1284 TESTL(GetIpAddressFromConfig(_L("Test_8.14"), _L("ipAddressLocal"), addrLocal)); |
|
1285 |
|
1286 // get ip address to connect to (usually loopback) |
|
1287 TESTL(GetIpAddressFromConfig(_L("Test_8.14"), _L("ipAddressRemote"), addrRemote)); |
|
1288 |
|
1289 // open socket and listen for connect requests |
|
1290 TESTL(KErrNone == OpenListeningSocketL(addrLocal, sockIndex1)); |
|
1291 |
|
1292 // open active socket and make connect request |
|
1293 TESTL(KErrNone == OpenActiveSocketL(addrRemote, sockIndex2)); |
|
1294 |
|
1295 // accept connect request |
|
1296 TESTL(KErrNone == AcceptConnectionL(sockIndex3, sockIndex1)); |
|
1297 |
|
1298 // close the sockets - should now be in 2MSL wait state |
|
1299 iEsockSuite->GetSocketHandle(sockIndex3).Close(); |
|
1300 iEsockSuite->GetSocketHandle(sockIndex2).Close(); |
|
1301 iEsockSuite->GetSocketHandle(sockIndex1).Close(); |
|
1302 |
|
1303 // open a TCP socket |
|
1304 RSocket sock; |
|
1305 CleanupClosePushL(sock); |
|
1306 TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1307 TESTEL(KErrNone == nRet, nRet); |
|
1308 |
|
1309 // bind the socket to the same address - check for failure |
|
1310 addrLocal.SetPort(1); |
|
1311 nRet = sock.Bind(addrLocal); |
|
1312 TESTEL(nRet==KErrInUse, nRet); |
|
1313 |
|
1314 // check that the bind is successful after 2MSL wait period has expired |
|
1315 do |
|
1316 { |
|
1317 User::After(1000000); // 1 second delay |
|
1318 nRet = sock.Bind(addrLocal); // keep trying |
|
1319 } while (nRet==KErrInUse); |
|
1320 |
|
1321 TESTEL(nRet==KErrNone, nRet); // check bind is successful after the delay |
|
1322 |
|
1323 // close the socket??? |
|
1324 CleanupStack::PopAndDestroy(); |
|
1325 |
|
1326 // open socket and listen for connect requests |
|
1327 TESTL(KErrNone == OpenListeningSocketL(addrLocal, sockIndex1)); |
|
1328 |
|
1329 // open active socket and make connect request |
|
1330 TESTL(KErrNone == OpenActiveSocketL(addrRemote, sockIndex2)); |
|
1331 |
|
1332 // accept connect request |
|
1333 TESTL(KErrNone == AcceptConnectionL(sockIndex3, sockIndex1)); |
|
1334 |
|
1335 // close the client and server sockets - leaving them in a 2MSL wait state |
|
1336 iEsockSuite->GetSocketHandle(sockIndex3).Close(); |
|
1337 iEsockSuite->GetSocketHandle(sockIndex2).Close(); |
|
1338 |
|
1339 // open a TCP socket |
|
1340 CleanupClosePushL(sock); |
|
1341 nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1342 TESTEL(KErrNone == nRet, nRet); |
|
1343 |
|
1344 // enable the KSoReuseAddr socket option |
|
1345 TESTL(sock.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
1346 |
|
1347 // bind the socket to the same address - bind is now successful |
|
1348 nRet = sock.Bind(addrLocal); |
|
1349 TESTEL(nRet==KErrNone, nRet); |
|
1350 |
|
1351 // attempt to connect - check for failure |
|
1352 TRequestStatus stat; |
|
1353 addrRemote.SetPort(1); |
|
1354 sock.Connect(addrRemote, stat); |
|
1355 User::WaitForRequest(stat); |
|
1356 TESTEL(stat==KErrInUse, stat.Int()); // still in 2MSL wait state |
|
1357 |
|
1358 // enable the KSoTcpAsync2MslWait option |
|
1359 TESTL(sock.SetOpt(KSoTcpAsync2MslWait, KSolInetTcp, 1)==KErrNone); |
|
1360 |
|
1361 // attempt connection again - should succeed now |
|
1362 sock.Connect(addrRemote, stat); |
|
1363 User::WaitForRequest(stat); |
|
1364 TESTEL(stat==KErrNone, stat.Int()); |
|
1365 |
|
1366 // close the sockets |
|
1367 CleanupStack::PopAndDestroy(); |
|
1368 iEsockSuite->GetSocketHandle(sockIndex1).Close(); |
|
1369 |
|
1370 return EPass; |
|
1371 } |
|
1372 |
|
1373 |
|
1374 // Test step 8.15 |
|
1375 const TDesC& CEsockTest8_15::GetTestName() |
|
1376 { |
|
1377 // store the name of this test case |
|
1378 _LIT(ret,"Test8.15"); |
|
1379 |
|
1380 return ret; |
|
1381 } |
|
1382 |
|
1383 CEsockTest8_15::~CEsockTest8_15() |
|
1384 { |
|
1385 } |
|
1386 |
|
1387 enum TVerdict CEsockTest8_15::easyTestStepL() |
|
1388 { |
|
1389 // Number of sockets test |
|
1390 RSocket sock1, sock2, sock3; |
|
1391 CleanupClosePushL(sock3); |
|
1392 CleanupClosePushL(sock2); |
|
1393 CleanupClosePushL(sock1); |
|
1394 |
|
1395 // open a TCP socket |
|
1396 TInt nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1397 TESTEL(KErrNone == nRet, nRet); |
|
1398 |
|
1399 // get the KSoTcpNumSockets socket option |
|
1400 TInt ret = sock1.GetOpt(KSoTcpNumSockets, KSolInetTcp, nRet); |
|
1401 TESTEL(KErrNone == ret, ret); |
|
1402 TESTEL(nRet == 1, nRet); |
|
1403 |
|
1404 // open another TCP socket |
|
1405 nRet = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1406 TESTEL(KErrNone == nRet, nRet); |
|
1407 |
|
1408 // get the KSoTcpNumSockets socket option for the second socket |
|
1409 ret = sock2.GetOpt(KSoTcpNumSockets, KSolInetTcp, nRet); |
|
1410 TESTEL(KErrNone == ret, ret); |
|
1411 TESTEL(nRet == 2, nRet); |
|
1412 |
|
1413 // open a UDP socket |
|
1414 nRet = sock3.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
1415 TESTEL(KErrNone == nRet, nRet); |
|
1416 |
|
1417 // get the KSoTcpNumSockets socket option for the UDP socket - not supported |
|
1418 ret = sock3.GetOpt(KSoTcpNumSockets, KSolInetTcp, nRet); |
|
1419 TESTEL(KErrNotSupported == ret, ret); |
|
1420 |
|
1421 // get the KSoTcpNumSockets socket option for the first TCP socket |
|
1422 ret = sock1.GetOpt(KSoTcpNumSockets, KSolInetTcp, nRet); |
|
1423 TESTEL(KErrNone == ret, ret); |
|
1424 TESTEL(nRet == 2, nRet); |
|
1425 |
|
1426 // close the first TCP socket |
|
1427 CleanupStack::PopAndDestroy(1, &sock1); |
|
1428 |
|
1429 // get the KSoTcpNumSockets socket option for the second TCP socket |
|
1430 ret = sock2.GetOpt(KSoTcpNumSockets, KSolInetTcp, nRet); |
|
1431 TESTEL(KErrNone == ret, ret); |
|
1432 TESTEL(nRet == 1, nRet); |
|
1433 |
|
1434 // close the remaining TCP socket |
|
1435 CleanupStack::PopAndDestroy(1, &sock2); |
|
1436 |
|
1437 // close the UDP socket |
|
1438 CleanupStack::PopAndDestroy(1, &sock3); |
|
1439 |
|
1440 return EPass; |
|
1441 } |
|
1442 |
|
1443 |
|
1444 // Test step 8.16 |
|
1445 const TDesC& CEsockTest8_16::GetTestName() |
|
1446 { |
|
1447 // store the name of this test case |
|
1448 _LIT(ret,"Test8.16"); |
|
1449 |
|
1450 return ret; |
|
1451 } |
|
1452 |
|
1453 CEsockTest8_16::~CEsockTest8_16() |
|
1454 { |
|
1455 } |
|
1456 |
|
1457 enum TVerdict CEsockTest8_16::easyTestStepL() |
|
1458 { |
|
1459 // socket listening test |
|
1460 |
|
1461 TInetAddr addrLocal, addrRemote; |
|
1462 // get local ip address |
|
1463 TESTL(GetIpAddressFromConfig(_L("Test_8.16"), _L("ipAddressLocal"), addrLocal)); |
|
1464 |
|
1465 // get ip address to connect to (usually loopback) |
|
1466 TESTL(GetIpAddressFromConfig(_L("Test_8.16"), _L("ipAddressRemote"), addrRemote)); |
|
1467 |
|
1468 // get port number |
|
1469 TInt port; |
|
1470 TESTL(GetIntFromConfig(_L("Test_8.16"), _L("port"), port)); |
|
1471 |
|
1472 // open a TCP socket |
|
1473 RSocket sock1; |
|
1474 CleanupClosePushL(sock1); |
|
1475 TInt nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1476 TESTEL(KErrNone == nRet, nRet); |
|
1477 |
|
1478 // get the KSoTcpListening socket option - indicates socket is not listening |
|
1479 TInt ret = sock1.GetOpt(KSoTcpListening, KSolInetTcp, nRet); |
|
1480 TESTEL(KErrNone == ret, ret); |
|
1481 TESTEL(0 == nRet, nRet); |
|
1482 |
|
1483 // bind the socket to local address |
|
1484 addrLocal.SetPort(port); |
|
1485 nRet = sock1.Bind(addrLocal); |
|
1486 TESTEL(KErrNone == nRet, nRet); |
|
1487 |
|
1488 // listen on the socket |
|
1489 nRet = sock1.Listen(5); |
|
1490 TESTEL(KErrNone == nRet, nRet); |
|
1491 |
|
1492 // get the KSoTcpListening socket option - indicates socket is listening |
|
1493 ret = sock1.GetOpt(KSoTcpListening, KSolInetTcp, nRet); |
|
1494 TESTEL(KErrNone == ret, ret); |
|
1495 TESTEL(1 == nRet, nRet); |
|
1496 |
|
1497 // open another socket (client) |
|
1498 RSocket sock2; |
|
1499 CleanupClosePushL(sock2); |
|
1500 nRet = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
1501 TESTEL(KErrNone == nRet, nRet); |
|
1502 |
|
1503 // connect via loopback |
|
1504 TRequestStatus stat; |
|
1505 addrRemote.SetPort(port); |
|
1506 sock2.Connect(addrRemote, stat); |
|
1507 User::WaitForRequest(stat); |
|
1508 TESTEL(stat==KErrNone, stat.Int()); |
|
1509 |
|
1510 // open a blank socket |
|
1511 RSocket sock3; |
|
1512 CleanupClosePushL(sock3); |
|
1513 nRet = sock3.Open(iEsockSuite->iSocketServer); |
|
1514 TESTEL(KErrNone == nRet, nRet); |
|
1515 |
|
1516 // accept the connection |
|
1517 sock1.Accept(sock3, stat); |
|
1518 User::WaitForRequest(stat); |
|
1519 TESTEL(stat==KErrNone, stat.Int()); |
|
1520 |
|
1521 // get the KSoTcpListening socket option for the listening socket |
|
1522 ret = sock1.GetOpt(KSoTcpListening, KSolInetTcp, nRet); |
|
1523 TESTEL(KErrNone == ret, ret); |
|
1524 TESTEL(1 == nRet, nRet); |
|
1525 |
|
1526 // get the KSoTcpListening socket option for the client socket |
|
1527 ret = sock2.GetOpt(KSoTcpListening, KSolInetTcp, nRet); |
|
1528 TESTEL(KErrNone == ret, ret); |
|
1529 TESTEL(0 == nRet, nRet); |
|
1530 |
|
1531 // get the KSoTcpListening socket option for the server socket |
|
1532 ret = sock3.GetOpt(KSoTcpListening, KSolInetTcp, nRet); |
|
1533 TESTEL(KErrNone == ret, ret); |
|
1534 TESTEL(0 == nRet, nRet); |
|
1535 |
|
1536 CleanupStack::PopAndDestroy(3, &sock1); |
|
1537 return EPass; |
|
1538 } |
|
1539 |