|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains ESock Test cases from section 15 |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include "SocketTestSection15.h" |
|
20 #include <ss_std.h> |
|
21 #include "ES_DUMMY.H" |
|
22 #include <elements/sd_std.h> |
|
23 |
|
24 _LIT8(KSendString, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // Sample testdata to send in these tests |
|
25 const TInt txlength1 = 26; // Length of KSEndString Its useful to be const |
|
26 |
|
27 _LIT8(KSendString2, "0123456789"); // Sample testdata to send in these tests |
|
28 const TInt txlength2 = 10; // Length of KSEndString2 Its useful to be const |
|
29 |
|
30 const TInt segmentlength = 10; // Amount of data to receive at a time. The number choosen must |
|
31 // allow for three reads of the 26-octet testdata where the last |
|
32 // read doesnt is less than this. 10 fulfills there requirements. |
|
33 |
|
34 // Test step 15.0 |
|
35 const TDesC& CSocketTest15_0::GetTestName() |
|
36 { |
|
37 _LIT(ret,"Test15.0"); |
|
38 return ret; |
|
39 } |
|
40 |
|
41 enum TVerdict CSocketTest15_0::InternalDoTestStepL( void ) |
|
42 { |
|
43 TVerdict verdict = EPass; |
|
44 |
|
45 Logger().WriteFormat(_L("Test Purpose: Panic Client using a Bad Descriptor")); |
|
46 |
|
47 // stop debugger crashing |
|
48 TBool oldJit = User::JustInTime(); |
|
49 User::SetJustInTime(EFalse); |
|
50 |
|
51 Logger().WriteFormat(_L("Creating thread which uses a bad descriptor")); |
|
52 RThread t; |
|
53 TSocketThreadArg tArg; |
|
54 tArg.iHandle = this; |
|
55 tArg.iSem = NULL; |
|
56 tArg.iNumSockets = 0; |
|
57 TInt ret = t.Create(_L("BadDescriptor"), BadDescriptorThread, KDefaultStackSize, |
|
58 KDefaultHeapSize, KDefaultHeapSize, &tArg); |
|
59 CleanupClosePushL(t); |
|
60 Logger().WriteFormat(_L("Create returned %S"), &EpocErrorToText(ret)); |
|
61 TESTL(KErrNone == ret); |
|
62 |
|
63 Logger().WriteFormat(_L("Logging on and resuming thread")); |
|
64 TRequestStatus stat; |
|
65 t.Logon(stat); |
|
66 t.Resume(); |
|
67 User::WaitForRequest(stat); |
|
68 TPtrC catName = t.ExitCategory(); |
|
69 Logger().WriteFormat(_L("Thread Exit Category '%S', Reason %d, Type %d"), |
|
70 &catName, t.ExitReason(), t.ExitType()); |
|
71 TESTL(t.ExitCategory() == Den::KWorkerClientPanic); |
|
72 TESTL(Den::ECommonBadDescriptorLength == t.ExitReason()); |
|
73 |
|
74 TESTL(EExitPanic == t.ExitType()); |
|
75 CleanupStack::PopAndDestroy(&t); |
|
76 |
|
77 // reset JIT state |
|
78 User::SetJustInTime(oldJit); |
|
79 |
|
80 SetTestStepResult(verdict); |
|
81 return verdict; |
|
82 |
|
83 } |
|
84 |
|
85 // Test step 15.1 |
|
86 const TDesC& CSocketTest15_1::GetTestName() |
|
87 { |
|
88 _LIT(ret,"Test15.1"); |
|
89 return ret; |
|
90 } |
|
91 |
|
92 |
|
93 enum TVerdict CSocketTest15_1::InternalDoTestStepL( void ) |
|
94 { |
|
95 Logger().WriteFormat(_L("Test Purpose: Datagram Continuation test. The trivial case")); |
|
96 Logger().WriteFormat(_L("Will send the 26 letters and retrieve them in portions of 10, 10 and the rest in a 10 octet buffer")); |
|
97 |
|
98 // <Test setup> |
|
99 |
|
100 Logger().WriteFormat(_L("Open socket server")); |
|
101 TAutoClose<RSocketServ> server; |
|
102 TInt ret=server.iObj.Connect(); |
|
103 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
104 TESTL(KErrNone == ret); |
|
105 server.PushL(); |
|
106 |
|
107 TAutoClose<RSocket> socket; |
|
108 Logger().WriteFormat(_L("Opening a socket on %S"), &KDummyOneName); |
|
109 ret = socket.iObj.Open(server.iObj, KDummyOneName); |
|
110 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
111 TESTL(KErrNone == ret); |
|
112 socket.PushL(); |
|
113 |
|
114 Logger().WriteFormat(_L("Connecting socket")); |
|
115 TSockAddr addr; |
|
116 TRequestStatus status; |
|
117 socket.iObj.Connect(addr, status); |
|
118 User::WaitForRequest(status); |
|
119 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(status.Int())); |
|
120 TESTL(KErrNone == status.Int()); |
|
121 |
|
122 // <Main test body> |
|
123 |
|
124 // Setup the txdata |
|
125 TBuf<txlength1> logstr; |
|
126 logstr.Copy(KSendString); |
|
127 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength1); |
|
128 |
|
129 // Send the data out |
|
130 TSockXfrLength length; |
|
131 socket.iObj.Send(KSendString, 0, status, length); |
|
132 User::WaitForRequest(status); |
|
133 Logger().WriteFormat(_L("Send status is %S"), &EpocErrorToText(status.Int())); |
|
134 TESTL(KErrNone == status.Int()); |
|
135 TESTL(txlength1 == length()); |
|
136 |
|
137 // Receive setup |
|
138 TSockXfrLength rxlength; |
|
139 TBuf8<segmentlength> rxbuf; |
|
140 TBuf<txlength1> expected; // Contain stuff to compare received to |
|
141 expected.Copy(KSendString); |
|
142 TInt remaining = txlength1; |
|
143 TInt recvFlags = 0; |
|
144 |
|
145 // Receive loop |
|
146 while (remaining > 0) |
|
147 { |
|
148 TInt minlen = Min(segmentlength, remaining); |
|
149 // show how much we expect to receive |
|
150 Logger().WriteFormat(_L("Recv next %d octets of expected %d remaining"), minlen, remaining); |
|
151 |
|
152 // receive up to segmentlength octets |
|
153 socket.iObj.Recv(rxbuf, recvFlags, status, rxlength); |
|
154 User::WaitForRequest(status); |
|
155 |
|
156 // display what we got and what we expected |
|
157 logstr.Copy(rxbuf); |
|
158 expected.SetLength(minlen); |
|
159 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
160 &EpocErrorToText(status.Int()), remaining - minlen, rxlength(), &logstr, &expected); |
|
161 TESTL(KErrNone == status.Int()); |
|
162 TESTL(expected==logstr); |
|
163 recvFlags = KSockReadContinuation; |
|
164 |
|
165 // update comparison string |
|
166 expected.SetLength(remaining); |
|
167 remaining -= minlen; |
|
168 expected.Delete(0, segmentlength); |
|
169 TESTL(remaining==rxlength()); |
|
170 } |
|
171 // <End of life as we know it> |
|
172 socket.Pop(); // Autoclose object |
|
173 server.Pop(); // Autoclose object |
|
174 SetTestStepResult(EPass); |
|
175 return EPass; |
|
176 } |
|
177 |
|
178 // Test step 15.2 |
|
179 const TDesC& CSocketTest15_2::GetTestName() |
|
180 { |
|
181 _LIT(ret,"Test15.2"); |
|
182 return ret; |
|
183 } |
|
184 |
|
185 enum TVerdict CSocketTest15_2::InternalDoTestStepL( void ) |
|
186 { |
|
187 Logger().WriteFormat(_L("Test Purpose: Datagram Continuation test.")); |
|
188 Logger().WriteFormat(_L("Will send a 26 octet dgram, then send a 10 octet dgram, retrieve the first 10, then continue to retrieve next datagram instead.")); |
|
189 |
|
190 // <Test setup> |
|
191 |
|
192 Logger().WriteFormat(_L("Open socket server")); |
|
193 TAutoClose<RSocketServ> server; |
|
194 TInt ret=server.iObj.Connect(); |
|
195 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
196 TESTL(KErrNone == ret); |
|
197 server.PushL(); |
|
198 |
|
199 TAutoClose<RSocket> socket; |
|
200 Logger().WriteFormat(_L("Opening a socket on %S"), &KDummyOneName); |
|
201 ret = socket.iObj.Open(server.iObj, KDummyOneName); |
|
202 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
203 TESTL(KErrNone == ret); |
|
204 socket.PushL(); |
|
205 |
|
206 Logger().WriteFormat(_L("Connecting socket")); |
|
207 TSockAddr addr; |
|
208 TRequestStatus status; |
|
209 socket.iObj.Connect(addr, status); |
|
210 User::WaitForRequest(status); |
|
211 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(status.Int())); |
|
212 TESTL(KErrNone == status.Int()); |
|
213 |
|
214 // <Main test body> |
|
215 |
|
216 // show what we are going to send in the first string |
|
217 TBuf<txlength1> logstr; |
|
218 logstr.Copy(KSendString); |
|
219 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength1); |
|
220 |
|
221 // send the first string |
|
222 TSockXfrLength length; |
|
223 socket.iObj.Send(KSendString, 0, status, length); |
|
224 User::WaitForRequest(status); |
|
225 Logger().WriteFormat(_L("Status of Send() is %S"), &EpocErrorToText(status.Int())); |
|
226 TESTL(KErrNone == status.Int()); |
|
227 TESTL(txlength1 == length()); |
|
228 |
|
229 // show what we are going to send in the second string |
|
230 logstr.Copy(KSendString2); |
|
231 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength2); |
|
232 |
|
233 // send the second string |
|
234 socket.iObj.Send(KSendString2, 0, status, length); |
|
235 User::WaitForRequest(status); |
|
236 Logger().WriteFormat(_L("Status of Send() is %S"), &EpocErrorToText(status.Int())); |
|
237 TESTL(KErrNone == status.Int()); |
|
238 TESTL(txlength2 == length()); |
|
239 |
|
240 // show how much we expect to receive |
|
241 TInt remaining = txlength1; |
|
242 Logger().WriteFormat(_L("Recv max %d octets of expected %d remaining"), segmentlength, remaining); |
|
243 |
|
244 // receive setup |
|
245 TSockXfrLength rxlength; |
|
246 TBuf8<segmentlength> rxbuf; |
|
247 TBuf<txlength1> expected; // Contain stuff to compare received to |
|
248 |
|
249 // receive the first 10 octets |
|
250 socket.iObj.Recv(rxbuf, 0, status, rxlength); |
|
251 remaining-=segmentlength; |
|
252 User::WaitForRequest(status); |
|
253 |
|
254 // display what we got and what we expected |
|
255 logstr.Copy(rxbuf); |
|
256 expected.Copy(KSendString); |
|
257 expected.SetLength(segmentlength); |
|
258 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
259 &EpocErrorToText(status.Int()), remaining, rxlength(), &logstr, &expected); |
|
260 TESTL(KErrNone == status.Int()); |
|
261 TESTL(remaining==rxlength()); |
|
262 TESTL(expected==logstr); |
|
263 |
|
264 Logger().WriteFormat(_L("Ignore rest of datagram and continue to retrieve next instead.")); |
|
265 |
|
266 // show how much we expect to receive |
|
267 remaining = txlength2; |
|
268 Logger().WriteFormat(_L("Recv max %d octets of expected %d remaining"), segmentlength, remaining); |
|
269 |
|
270 // receive the first 10 octets of next datagram |
|
271 socket.iObj.Recv(rxbuf, 0, status, rxlength); |
|
272 remaining-=segmentlength; |
|
273 User::WaitForRequest(status); |
|
274 |
|
275 // display what we got and what we expected |
|
276 logstr.Copy(rxbuf); |
|
277 expected.Copy(KSendString2); |
|
278 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
279 &EpocErrorToText(status.Int()), remaining, rxlength(), &logstr, &expected); |
|
280 TESTL(KErrNone == status.Int()); |
|
281 TESTL(remaining==rxlength()); |
|
282 TESTL(expected==logstr); |
|
283 |
|
284 // <End of life as we know it> |
|
285 socket.Pop(); // Autoclose object |
|
286 server.Pop(); // Autoclose object |
|
287 SetTestStepResult(EPass); |
|
288 return EPass; |
|
289 } |
|
290 |
|
291 // Test step 15.3 |
|
292 const TDesC& CSocketTest15_3::GetTestName() |
|
293 { |
|
294 _LIT(ret,"Test15.3"); |
|
295 return ret; |
|
296 } |
|
297 |
|
298 enum TVerdict CSocketTest15_3::InternalDoTestStepL( void ) |
|
299 { |
|
300 Logger().WriteFormat(_L("Test Purpose: Datagram Continuation test.")); |
|
301 Logger().WriteFormat(_L("Retrieve async 10 octets from a dgram, send a 26 octet dgram, retrieve async next dgram, wait a bit to make sure it doesnt complete without data, then send 10octets for the second recv.")); |
|
302 |
|
303 // <Test setup> |
|
304 |
|
305 Logger().WriteFormat(_L("Open socket server")); |
|
306 TAutoClose<RSocketServ> server; |
|
307 TInt ret=server.iObj.Connect(); |
|
308 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
309 TESTL(KErrNone == ret); |
|
310 server.PushL(); |
|
311 |
|
312 TAutoClose<RSocket> socket; |
|
313 Logger().WriteFormat(_L("Opening a socket on %S"), &KDummyOneName); |
|
314 ret = socket.iObj.Open(server.iObj, KDummyOneName); |
|
315 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
316 TESTL(KErrNone == ret); |
|
317 socket.PushL(); |
|
318 |
|
319 Logger().WriteFormat(_L("Connecting socket")); |
|
320 TSockAddr addr; |
|
321 TRequestStatus status; |
|
322 socket.iObj.Connect(addr, status); |
|
323 User::WaitForRequest(status); |
|
324 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(status.Int())); |
|
325 TESTL(KErrNone == status.Int()); |
|
326 |
|
327 // <Main test body> |
|
328 |
|
329 TSockXfrLength rxlength; |
|
330 TInt remaining = txlength1; |
|
331 TBuf8<segmentlength> rxbuf; |
|
332 TBuf<txlength1> expected; // Contain stuff to compare received to |
|
333 |
|
334 // receive the first 10 octets (which shouldn't block or complete) |
|
335 Logger().WriteFormat(_L("Recv max %d octets of expected %d remaining"), segmentlength, remaining); |
|
336 socket.iObj.Recv(rxbuf, 0, status, rxlength); |
|
337 TESTL(KRequestPending == status.Int()); |
|
338 remaining-=segmentlength; |
|
339 |
|
340 // show what we are going to send |
|
341 TBuf<txlength1> logstr; |
|
342 logstr.Copy(KSendString); |
|
343 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength1); |
|
344 |
|
345 // send the first string |
|
346 TRequestStatus txstatus; |
|
347 TSockXfrLength length; |
|
348 socket.iObj.Send(KSendString, 0, txstatus, length); |
|
349 |
|
350 User::WaitForRequest(txstatus); // wait for tx to complete |
|
351 Logger().WriteFormat(_L("Status of Send() is %S"), &EpocErrorToText(txstatus.Int())); |
|
352 // test that send was a success |
|
353 TESTL(KErrNone == txstatus.Int()); |
|
354 TESTL(txlength1 == length()); |
|
355 |
|
356 User::WaitForRequest(status); // wait for rx to complete |
|
357 Logger().WriteFormat(_L("Status of Recv() is %S"), &EpocErrorToText(status.Int())); |
|
358 // test that the receive was a success |
|
359 logstr.Copy(rxbuf); |
|
360 expected.Copy(KSendString); |
|
361 expected.SetLength(segmentlength); |
|
362 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
363 &EpocErrorToText(status.Int()), remaining, rxlength(), &logstr, &expected); |
|
364 TESTL(KErrNone == status.Int()); |
|
365 TESTL(remaining==rxlength()); |
|
366 TESTL(expected==logstr); |
|
367 |
|
368 // receive the first 10 octets from the next datagram (which shouldn't block or complete) |
|
369 Logger().WriteFormat(_L("Recv %d octets"), txlength2); |
|
370 socket.iObj.Recv(rxbuf, 0, status, rxlength); |
|
371 TESTL(KRequestPending == status.Int()); |
|
372 remaining=0; |
|
373 |
|
374 // show what we are going to send in the second string |
|
375 logstr.Copy(KSendString2); |
|
376 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength2); |
|
377 |
|
378 // send the second string |
|
379 socket.iObj.Send(KSendString2, 0, txstatus, length); |
|
380 |
|
381 User::WaitForRequest(txstatus); // wait for tx to complete |
|
382 Logger().WriteFormat(_L("Status of Send() is %S"), &EpocErrorToText(txstatus.Int())); |
|
383 // test that send was a success |
|
384 TESTL(KErrNone == txstatus.Int()); |
|
385 TESTL(txlength2 == length()); |
|
386 |
|
387 User::WaitForRequest(status); // wait for rx to complete |
|
388 Logger().WriteFormat(_L("Status of Recv() is %S"), &EpocErrorToText(status.Int())); |
|
389 // Test that receive was a success |
|
390 logstr.Copy(rxbuf); |
|
391 expected.Copy(KSendString2); |
|
392 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
393 &EpocErrorToText(status.Int()), remaining, rxlength(), &logstr, &expected); |
|
394 TESTL(KErrNone == status.Int()); |
|
395 TESTL(remaining==rxlength()); |
|
396 TESTL(expected==logstr); |
|
397 |
|
398 // <End of life as we know it> |
|
399 socket.Pop(); // Autoclose object |
|
400 server.Pop(); // Autoclose object |
|
401 SetTestStepResult(EPass); |
|
402 return EPass; |
|
403 } |
|
404 |
|
405 // Test step 15.4 |
|
406 const TDesC& CSocketTest15_4::GetTestName() |
|
407 { |
|
408 _LIT(ret,"Test15.4"); |
|
409 return ret; |
|
410 } |
|
411 |
|
412 enum TVerdict CSocketTest15_4::InternalDoTestStepL( void ) |
|
413 { |
|
414 Logger().WriteFormat(_L("Test Purpose: Datagram Continuation test. The trivial case")); |
|
415 Logger().WriteFormat(_L("Will send the 26 letters and retrieve them in portions of 10, 10 and the rest in a 10 octet buffer")); |
|
416 |
|
417 // <Test setup> |
|
418 |
|
419 Logger().WriteFormat(_L("Open socket server")); |
|
420 TAutoClose<RSocketServ> server; |
|
421 TInt ret=server.iObj.Connect(); |
|
422 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
423 TESTL(KErrNone == ret); |
|
424 server.PushL(); |
|
425 |
|
426 TAutoClose<RSocket> socket; |
|
427 Logger().WriteFormat(_L("Opening a socket on %S"), &KDummyOneName); |
|
428 ret = socket.iObj.Open(server.iObj, KDummyOneName); |
|
429 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
430 TESTL(KErrNone == ret); |
|
431 socket.PushL(); |
|
432 |
|
433 Logger().WriteFormat(_L("Connecting socket")); |
|
434 TSockAddr addr; |
|
435 TRequestStatus status; |
|
436 socket.iObj.Connect(addr, status); |
|
437 User::WaitForRequest(status); |
|
438 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(status.Int())); |
|
439 TESTL(KErrNone == status.Int()); |
|
440 |
|
441 // <Main test body> |
|
442 |
|
443 // Setup the txdata |
|
444 TBuf<txlength1> logstr; |
|
445 logstr.Copy(KSendString); |
|
446 Logger().WriteFormat(_L("Sending 8bit data: \"%S\", %d octets"), &logstr, txlength1); |
|
447 |
|
448 // Send the data out |
|
449 TSockXfrLength length; |
|
450 socket.iObj.Send(KSendString, 0, status, length); |
|
451 User::WaitForRequest(status); |
|
452 Logger().WriteFormat(_L("Send status is %S"), &EpocErrorToText(status.Int())); |
|
453 TESTL(KErrNone == status.Int()); |
|
454 TESTL(txlength1 == length()); |
|
455 |
|
456 // Receive setup |
|
457 TSockXfrLength rxlength; |
|
458 TBuf8<segmentlength> rxbuf; |
|
459 TBuf<txlength1> expected; // Contain stuff to compare received to |
|
460 expected.Copy(KSendString); |
|
461 TInt remaining = txlength1; |
|
462 TInt recvFlags = KSockReadPeek; |
|
463 |
|
464 // Receive loop |
|
465 while (remaining > 0) |
|
466 { |
|
467 TInt minlen = Min(segmentlength, remaining); |
|
468 // show how much we expect to peek |
|
469 Logger().WriteFormat(_L("PEEK Recv next %d octets of expected %d remaining"), minlen, remaining); |
|
470 |
|
471 // receive up to segmentlength octets |
|
472 socket.iObj.Recv(rxbuf, recvFlags, status, rxlength); |
|
473 User::WaitForRequest(status); |
|
474 |
|
475 // display what we got and what we expected |
|
476 logstr.Copy(rxbuf); |
|
477 expected.SetLength(minlen); |
|
478 Logger().WriteFormat(_L("PEEK Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
479 &EpocErrorToText(status.Int()), remaining, rxlength(), &logstr, &expected); |
|
480 TESTL(KErrNone == status.Int()); |
|
481 TESTL(expected==logstr); |
|
482 TESTL(remaining==rxlength()); |
|
483 recvFlags = KSockReadContinuation; |
|
484 |
|
485 // show how much we expect to receive |
|
486 Logger().WriteFormat(_L("Recv next %d octets of expected %d remaining"), minlen, remaining); |
|
487 |
|
488 // receive up to segmentlength octets |
|
489 socket.iObj.Recv(rxbuf, recvFlags, status, rxlength); |
|
490 User::WaitForRequest(status); |
|
491 |
|
492 // display what we got and what we expected |
|
493 logstr.Copy(rxbuf); |
|
494 expected.SetLength(minlen); |
|
495 Logger().WriteFormat(_L("Recv status %S, expected length remaining %d, length remaining %d, buffer '%S', expected '%S'"), |
|
496 &EpocErrorToText(status.Int()), remaining - minlen, rxlength(), &logstr, &expected); |
|
497 TESTL(KErrNone == status.Int()); |
|
498 TESTL(expected==logstr); |
|
499 recvFlags = KSockReadContinuation | KSockReadPeek; |
|
500 |
|
501 // update comparison string |
|
502 expected.SetLength(remaining); |
|
503 remaining -= minlen; |
|
504 expected.Delete(0, segmentlength); |
|
505 TESTL(remaining==rxlength()); |
|
506 } |
|
507 |
|
508 // <End of life as we know it> |
|
509 socket.Pop(); // Autoclose object |
|
510 server.Pop(); // Autoclose object |
|
511 SetTestStepResult(EPass); |
|
512 return EPass; |
|
513 } |
|
514 |
|
515 // Test step 15.4 |
|
516 const TDesC& CSocketTest15_5::GetTestName() |
|
517 { |
|
518 _LIT(ret,"Test15.5"); |
|
519 return ret; |
|
520 } |
|
521 |
|
522 enum TVerdict CSocketTest15_5::InternalDoTestStepL( void ) |
|
523 { |
|
524 _LIT8(KSendData, "ABC"); // Sample testdata to send in this test |
|
525 |
|
526 Logger().WriteFormat(_L("Test Purpose: Datagram Continuation test.")); |
|
527 Logger().WriteFormat(_L("Perform multiple reads from each individual packet received (non-connected socket).")); |
|
528 |
|
529 // <Test setup> |
|
530 |
|
531 Logger().WriteFormat(_L("Open socket server")); |
|
532 TAutoClose<RSocketServ> server; |
|
533 TInt ret=server.iObj.Connect(); |
|
534 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
535 TESTL(KErrNone == ret); |
|
536 server.PushL(); |
|
537 |
|
538 TAutoClose<RSocket> socket; |
|
539 Logger().WriteFormat(_L("Opening a socket on %S"), &KDummyOneName); |
|
540 ret = socket.iObj.Open(server.iObj, KDummyOneName); |
|
541 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
542 TESTL(KErrNone == ret); |
|
543 socket.PushL(); |
|
544 |
|
545 Logger().WriteFormat(_L("Connecting socket")); |
|
546 TSockAddr addr; |
|
547 TRequestStatus status; |
|
548 socket.iObj.Connect(addr, status); |
|
549 User::WaitForRequest(status); |
|
550 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(status.Int())); |
|
551 TESTL(KErrNone == status.Int()); |
|
552 |
|
553 // <Main test body> |
|
554 |
|
555 TUint count; |
|
556 for (count=0; count<5; count++) // perform the test a few times |
|
557 { |
|
558 // send the data |
|
559 TSockXfrLength txlength; |
|
560 socket.iObj.Send(KSendData, 0, status, txlength); |
|
561 User::WaitForRequest(status); |
|
562 TESTL(KErrNone == status.Int()); |
|
563 |
|
564 TBuf8<1> rxbuf; |
|
565 TBuf<1> buf16; |
|
566 TSockXfrLength rxLength = 0; |
|
567 |
|
568 // receive it back (using the KSockReadContinuation option) |
|
569 socket.iObj.Recv(rxbuf, 0, status, rxLength); |
|
570 User::WaitForRequest(status); |
|
571 buf16.Copy(rxbuf); |
|
572 Logger().WriteFormat(_L("Receive status is %S, data received is '%S'"), &EpocErrorToText(status.Int()), &buf16); |
|
573 TESTL(KErrNone == status.Int()); |
|
574 TESTL(rxLength() == 2); |
|
575 |
|
576 // receive more of it back (using the KSockReadContinuation option) |
|
577 socket.iObj.Recv(rxbuf, KSockReadContinuation, status, rxLength); |
|
578 User::WaitForRequest(status); |
|
579 buf16.Copy(rxbuf); |
|
580 Logger().WriteFormat(_L("Receive status is %S, data received is '%S'"), &EpocErrorToText(status.Int()), &buf16); |
|
581 TESTL(KErrNone == status.Int()); |
|
582 TESTL(rxLength() == 1); |
|
583 |
|
584 // receive the rest of it back (using the KSockReadContinuation option) |
|
585 socket.iObj.Recv(rxbuf, KSockReadContinuation, status, rxLength); |
|
586 User::WaitForRequest(status); |
|
587 buf16.Copy(rxbuf); |
|
588 Logger().WriteFormat(_L("Receive status is %S, data received is '%S'"), &EpocErrorToText(status.Int()), &buf16); |
|
589 TESTL(KErrNone == status.Int()); |
|
590 TESTL(rxLength() == 0); |
|
591 } |
|
592 |
|
593 CleanupStack::PopAndDestroy(2); |
|
594 |
|
595 return EPass; |
|
596 } |
|
597 |