|
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 9 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 #include <test/es_dummy.h> |
|
22 |
|
23 // Test system includes |
|
24 #include "SocketTestSection9.h" |
|
25 |
|
26 |
|
27 // Test step 9.1 |
|
28 const TDesC& CSocketTest9_1::GetTestName() |
|
29 { |
|
30 _LIT(ret,"Test9.1"); |
|
31 return ret; |
|
32 } |
|
33 |
|
34 enum TVerdict CSocketTest9_1::InternalDoTestStepL( void ) |
|
35 { |
|
36 TVerdict verdict = EPass; |
|
37 |
|
38 Logger().WriteFormat(_L("Test Purpose: Partial Read")); |
|
39 |
|
40 // connect to esock |
|
41 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
42 RSocketServ ss; |
|
43 TInt ret = OptimalConnect(ss); |
|
44 CleanupClosePushL(ss); |
|
45 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
46 TESTL(KErrNone == ret); |
|
47 |
|
48 RSocket sk; |
|
49 Logger().WriteFormat(_L("Opening a socket on Dummy protocol 2")); |
|
50 ret = sk.Open(ss, _L("Dummy Protocol 2")); |
|
51 CleanupClosePushL(sk); |
|
52 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
53 TESTL(KErrNone == ret); |
|
54 |
|
55 Logger().WriteFormat(_L("Connecting socket")); |
|
56 TRequestStatus shutStat; |
|
57 TRequestStatus rstat; |
|
58 TSockAddr addr; |
|
59 sk.Connect(addr, rstat); |
|
60 User::WaitForRequest(rstat); |
|
61 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(rstat.Int())); |
|
62 TESTL(KErrNone == rstat.Int()); |
|
63 |
|
64 // test XSockXfrLength |
|
65 Logger().WriteFormat(_L("Trying recv of 6 octets and send of 12")); |
|
66 TSockXfrLength len, rlen; |
|
67 TBuf8<6> buf; |
|
68 TBuf16<6>buf16; |
|
69 sk.Recv(buf, 0, shutStat, rlen); |
|
70 sk.Send(_L8("Hello HELLO "), 0, rstat, len); |
|
71 User::WaitForRequest(rstat); |
|
72 Logger().WriteFormat(_L("Send status %S, length %d"), &EpocErrorToText(rstat.Int()), len()); |
|
73 TESTL(KErrNone == rstat.Int()); |
|
74 TESTL(12 == len()); |
|
75 |
|
76 User::WaitForRequest(shutStat); |
|
77 buf16.Copy(buf); |
|
78 Logger().WriteFormat(_L("Recv status %S, length %d, buffer '%S'"), |
|
79 &EpocErrorToText(shutStat.Int()), rlen(), &buf16); |
|
80 TESTL(KErrNone == shutStat.Int()); |
|
81 TESTL(6 == rlen()); |
|
82 TESTL(_L8("Hello ") == buf); |
|
83 |
|
84 Logger().WriteFormat(_L("Trying recv of another 6 octets")); |
|
85 sk.Recv(buf, 0, rstat, rlen); |
|
86 User::WaitForRequest(rstat); |
|
87 buf16.Copy(buf); |
|
88 Logger().WriteFormat(_L("Recv status %S, length %d, buffer '%S'"), |
|
89 &EpocErrorToText(shutStat.Int()), rlen(), &buf16); |
|
90 TESTL(KErrNone == shutStat.Int()); |
|
91 TESTL(6 == rlen()); |
|
92 TESTL(_L8("HELLO ") == buf); |
|
93 |
|
94 CleanupStack::Pop(&sk); |
|
95 sk.Close(); |
|
96 CleanupStack::Pop(&ss); |
|
97 ss.Close(); |
|
98 |
|
99 SetTestStepResult(verdict); |
|
100 return verdict; |
|
101 } |
|
102 |
|
103 // Test step 9.2 |
|
104 const TDesC& CSocketTest9_2::GetTestName() |
|
105 { |
|
106 _LIT(ret,"Test9.2"); |
|
107 return ret; |
|
108 } |
|
109 |
|
110 enum TVerdict CSocketTest9_2::InternalDoTestStepL( void ) |
|
111 { |
|
112 TVerdict verdict = EPass; |
|
113 |
|
114 Logger().WriteFormat(_L("Test Purpose: RecvFrom not supported on ConnectionOriented socket")); |
|
115 |
|
116 // connect to esock |
|
117 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
118 RSocketServ ss; |
|
119 TInt ret = OptimalConnect(ss); |
|
120 CleanupClosePushL(ss); |
|
121 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
122 TESTL(KErrNone == ret); |
|
123 |
|
124 RSocket sk; |
|
125 Logger().WriteFormat(_L("Opening a socket on Dummy protocol 2")); |
|
126 ret = sk.Open(ss, _L("Dummy Protocol 2")); |
|
127 CleanupClosePushL(sk); |
|
128 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
129 TESTL(KErrNone == ret); |
|
130 |
|
131 Logger().WriteFormat(_L("Connecting socket")); |
|
132 TRequestStatus rstat; |
|
133 TSockAddr addr; |
|
134 sk.Connect(addr, rstat); |
|
135 User::WaitForRequest(rstat); |
|
136 Logger().WriteFormat(_L("Connect status %S"), &EpocErrorToText(rstat.Int())); |
|
137 TESTL(KErrNone == rstat.Int()); |
|
138 |
|
139 Logger().WriteFormat(_L("Trying RecvFrom")); |
|
140 TSockXfrLength rlen; |
|
141 TBuf8<6> buf; |
|
142 sk.RecvFrom(buf, addr, 0, rstat, rlen); |
|
143 User::WaitForRequest(rstat); |
|
144 Logger().WriteFormat(_L("RecvFrom status %S"), &EpocErrorToText(rstat.Int())); |
|
145 TESTL(KErrNotSupported == rstat.Int()); |
|
146 |
|
147 CleanupStack::Pop(&sk); |
|
148 sk.Close(); |
|
149 CleanupStack::Pop(&ss); |
|
150 ss.Close(); |
|
151 |
|
152 SetTestStepResult(verdict); |
|
153 return verdict; |
|
154 } |
|
155 |
|
156 // Test step 9.3 |
|
157 const TDesC& CSocketTest9_3::GetTestName() |
|
158 { |
|
159 _LIT(ret,"Test9.3"); |
|
160 return ret; |
|
161 } |
|
162 |
|
163 enum TVerdict CSocketTest9_3::InternalDoTestStepL( void ) |
|
164 { |
|
165 TVerdict verdict = EPass; |
|
166 |
|
167 Logger().WriteFormat(_L("Test Purpose: Fail Urgent Data on Non-Supporting Socket")); |
|
168 |
|
169 // connect to esock |
|
170 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
171 RSocketServ ss; |
|
172 TInt ret = OptimalConnect(ss); |
|
173 CleanupClosePushL(ss); |
|
174 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
175 TESTL(KErrNone == ret); |
|
176 |
|
177 Logger().WriteFormat(_L("Finding for dummy protocol 1")); |
|
178 TProtocolDesc protoInfo; |
|
179 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
180 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
181 TESTL(KErrNone == ret); |
|
182 |
|
183 Logger().WriteFormat(_L("Opening a socket")); |
|
184 RSocket socket; |
|
185 ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
186 CleanupClosePushL(socket); |
|
187 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
188 TESTL(KErrNone == ret); |
|
189 |
|
190 Logger().WriteFormat(_L("Trying to write urgent data")); |
|
191 TBuf8<10> buf; |
|
192 TRequestStatus stat; |
|
193 buf.SetLength(5); |
|
194 TSockAddr addr; |
|
195 socket.SendTo(buf, addr, KSockWriteUrgent, stat); |
|
196 User::WaitForRequest(stat); |
|
197 Logger().WriteFormat(_L("SendTo status %S"), &EpocErrorToText(stat.Int())); |
|
198 TESTL(KErrNotSupported == stat.Int()); |
|
199 |
|
200 CleanupStack::Pop(&socket); |
|
201 socket.Close(); |
|
202 |
|
203 CleanupStack::Pop(&ss); |
|
204 ss.Close(); |
|
205 |
|
206 SetTestStepResult(verdict); |
|
207 return verdict; |
|
208 } |
|
209 |
|
210 // Test step 9.4 |
|
211 const TDesC& CSocketTest9_4::GetTestName() |
|
212 { |
|
213 _LIT(ret,"Test9.4"); |
|
214 return ret; |
|
215 } |
|
216 |
|
217 enum TVerdict CSocketTest9_4::InternalDoTestStepL( void ) |
|
218 { |
|
219 TVerdict verdict = EPass; |
|
220 |
|
221 Logger().WriteFormat(_L("Test Purpose: Trying to SetOpt/GetOpt socket buffer lengths")); |
|
222 |
|
223 // connect to esock |
|
224 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
225 RSocketServ ss; |
|
226 TInt ret = OptimalConnect(ss); |
|
227 CleanupClosePushL(ss); |
|
228 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
229 TESTL(KErrNone == ret); |
|
230 |
|
231 Logger().WriteFormat(_L("Finding for dummy protocol 1")); |
|
232 TProtocolDesc protoInfo; |
|
233 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
234 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
235 TESTL(KErrNone == ret); |
|
236 |
|
237 Logger().WriteFormat(_L("Opening a socket")); |
|
238 RSocket socket; |
|
239 ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
240 CleanupClosePushL(socket); |
|
241 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
242 TESTL(KErrNone == ret); |
|
243 |
|
244 Logger().WriteFormat(_L("Getting RecvBuf length")); |
|
245 TPckgBuf<TUint> lenbuf; |
|
246 ret = socket.GetOpt(KSORecvBuf, KSOLSocket, lenbuf); |
|
247 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
248 &EpocErrorToText(ret), lenbuf()); |
|
249 TESTL(KErrNone == ret); |
|
250 |
|
251 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
252 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
253 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
254 &EpocErrorToText(ret), lenbuf()); |
|
255 TESTL(KErrNone == ret); |
|
256 |
|
257 TUint x = lenbuf()/2; |
|
258 lenbuf() = x; |
|
259 Logger().WriteFormat(_L("Setting RecvBuf length to %d"), lenbuf()); |
|
260 ret = socket.SetOpt(KSORecvBuf, KSOLSocket, lenbuf); |
|
261 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
262 TESTL(KErrNone == ret); |
|
263 |
|
264 Logger().WriteFormat(_L("Getting RecvBuf length")); |
|
265 ret = socket.GetOpt(KSORecvBuf, KSOLSocket, lenbuf); |
|
266 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
267 &EpocErrorToText(ret), lenbuf()); |
|
268 TESTL(KErrNone == ret); |
|
269 TESTL(lenbuf() == x); |
|
270 |
|
271 lenbuf() = x; |
|
272 Logger().WriteFormat(_L("Setting SendBuf length to %d"), lenbuf()); |
|
273 ret = socket.SetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
274 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
275 TESTL(KErrNone == ret); |
|
276 |
|
277 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
278 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
279 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), &EpocErrorToText(ret), lenbuf()); |
|
280 TESTL(KErrNone == ret); |
|
281 TESTL(lenbuf() == x); |
|
282 |
|
283 CleanupStack::Pop(&socket); |
|
284 socket.Close(); |
|
285 |
|
286 CleanupStack::Pop(&ss); |
|
287 ss.Close(); |
|
288 |
|
289 SetTestStepResult(verdict); |
|
290 return verdict; |
|
291 } |
|
292 |
|
293 // Test step 9.5 |
|
294 const TDesC& CSocketTest9_5::GetTestName() |
|
295 { |
|
296 _LIT(ret,"Test9.5"); |
|
297 return ret; |
|
298 } |
|
299 |
|
300 enum TVerdict CSocketTest9_5::InternalDoTestStepL( void ) |
|
301 { |
|
302 TVerdict verdict = EPass; |
|
303 |
|
304 Logger().WriteFormat(_L("Test Purpose: Write to Unconnected Socket")); |
|
305 |
|
306 // connect to esock |
|
307 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
308 RSocketServ ss; |
|
309 TInt ret = OptimalConnect(ss); |
|
310 CleanupClosePushL(ss); |
|
311 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
312 TESTL(KErrNone == ret); |
|
313 |
|
314 // Write on an unconnected sock to send datagram |
|
315 Logger().WriteFormat(_L("Opening socket on dummy protocol 3")); |
|
316 TRequestStatus rstat; |
|
317 RSocket sock3; |
|
318 ret = sock3.Open(ss,_L("Dummy Protocol 3")); |
|
319 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
320 TESTL(KErrNone == ret); |
|
321 |
|
322 Logger().WriteFormat(_L("Attempting Write")); |
|
323 sock3.Write(_L8("Hello HELLO "), rstat); |
|
324 User::WaitForRequest(rstat); |
|
325 Logger().WriteFormat(_L("Write status %S"), &EpocErrorToText(rstat.Int())); |
|
326 TESTL(KErrNotReady == rstat.Int()); |
|
327 sock3.Close(); |
|
328 |
|
329 // try for dummy protocol 2 |
|
330 Logger().WriteFormat(_L("Opening socket on dummy protocol 2")); |
|
331 RSocket sk; |
|
332 ret = sk.Open(ss,_L("Dummy Protocol 2")); |
|
333 CleanupClosePushL(sk); |
|
334 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
335 TESTL(KErrNone == ret); |
|
336 |
|
337 Logger().WriteFormat(_L("Attempting Write")); |
|
338 sk.Write(_L8("Hello HELLO "), rstat); |
|
339 User::WaitForRequest(rstat); |
|
340 Logger().WriteFormat(_L("Write status %S"), &EpocErrorToText(rstat.Int())); |
|
341 TESTL(KErrNotReady == rstat.Int()); |
|
342 |
|
343 CleanupStack::Pop(&sk); |
|
344 sk.Close(); |
|
345 CleanupStack::Pop(&ss); |
|
346 ss.Close(); |
|
347 |
|
348 SetTestStepResult(verdict); |
|
349 return verdict; |
|
350 } |
|
351 |
|
352 // Test step 9.6 |
|
353 const TDesC& CSocketTest9_6::GetTestName() |
|
354 { |
|
355 _LIT(ret,"Test9.6"); |
|
356 return ret; |
|
357 } |
|
358 |
|
359 enum TVerdict CSocketTest9_6::InternalDoTestStepL( void ) |
|
360 { |
|
361 TVerdict verdict = EPass; |
|
362 |
|
363 Logger().WriteFormat(_L("Test Purpose: Trying to set a protocol to have nolimit on datagram size and send over 64K datagram.")); |
|
364 |
|
365 // connect to esock |
|
366 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
367 RSocketServ ss; |
|
368 |
|
369 TSessionPref pref; |
|
370 pref.iAddrFamily = KDummyAddrFamily; |
|
371 pref.iProtocol = KDummyFive; |
|
372 TInt ret = ss.Connect(pref); |
|
373 |
|
374 // TInt ret = OptimalConnect(ss); |
|
375 CleanupClosePushL(ss); |
|
376 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
377 TESTL(KErrNone == ret); |
|
378 |
|
379 Logger().WriteFormat(_L("Finding for dummy protocol 5")); |
|
380 TProtocolDesc protoInfo; |
|
381 ret = ss.FindProtocol(_L("Dummy Protocol 5"), protoInfo); |
|
382 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
383 TESTL(KErrNone == ret); |
|
384 |
|
385 Logger().WriteFormat(_L("Opening a socket")); |
|
386 RSocket socket; |
|
387 ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
388 CleanupClosePushL(socket); |
|
389 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
390 TESTL(KErrNone == ret); |
|
391 |
|
392 TPckgBuf<TUint> lenbuf; |
|
393 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
394 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
395 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
396 &EpocErrorToText(ret), lenbuf()); |
|
397 TESTL(KErrNone == ret); |
|
398 |
|
399 TUint x(70000); |
|
400 lenbuf() = x; |
|
401 Logger().WriteFormat(_L("Setting SendBuf length to %d"), lenbuf()); |
|
402 ret = socket.SetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
403 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
404 TESTL(KErrNone == ret); |
|
405 |
|
406 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
407 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
408 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), &EpocErrorToText(ret), lenbuf()); |
|
409 TESTL(KErrNone == ret); |
|
410 TESTL(lenbuf() == x); |
|
411 |
|
412 Logger().WriteFormat(_L("Try sending datagram over protocol allowing unlimited datagram size")); |
|
413 TInetAddr destAddr; |
|
414 TRequestStatus status; |
|
415 |
|
416 const TInt KBufferLength = 70000; |
|
417 HBufC8* hbuf = HBufC8::NewMaxLC(KBufferLength); |
|
418 TPtr8 buffer(hbuf->Des()); |
|
419 buffer.FillZ(); |
|
420 |
|
421 socket.SendTo(buffer, destAddr, 0, status); |
|
422 User::WaitForRequest(status); |
|
423 Logger().WriteFormat(_L("...which returned %d\n"), status.Int()); |
|
424 TESTL(status == KErrNone); |
|
425 |
|
426 CleanupStack::PopAndDestroy(hbuf); |
|
427 |
|
428 CleanupStack::Pop(&socket); |
|
429 socket.Close(); |
|
430 |
|
431 CleanupStack::Pop(&ss); |
|
432 ss.Close(); |
|
433 |
|
434 SetTestStepResult(verdict); |
|
435 return verdict; |
|
436 } |
|
437 |
|
438 // Test step 9.7 |
|
439 const TDesC& CSocketTest9_7::GetTestName() |
|
440 { |
|
441 _LIT(ret,"Test9.7"); |
|
442 return ret; |
|
443 } |
|
444 |
|
445 enum TVerdict CSocketTest9_7::InternalDoTestStepL( void ) |
|
446 { |
|
447 TVerdict verdict = EPass; |
|
448 |
|
449 Logger().WriteFormat(_L("Test Purpose: Repeat send over 64K datagram using TSockXfrLength.")); |
|
450 |
|
451 // connect to esock |
|
452 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
453 RSocketServ ss; |
|
454 |
|
455 // protocol allowing unlimited datagram size |
|
456 TSessionPref pref; |
|
457 pref.iAddrFamily = KDummyAddrFamily; |
|
458 pref.iProtocol = KDummyFive; |
|
459 TInt ret = ss.Connect(pref); |
|
460 |
|
461 CleanupClosePushL(ss); |
|
462 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
463 TESTL(KErrNone == ret); |
|
464 |
|
465 Logger().WriteFormat(_L("Finding for dummy protocol 5")); |
|
466 TProtocolDesc protoInfo; |
|
467 ret = ss.FindProtocol(_L("Dummy Protocol 5"), protoInfo); |
|
468 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
469 TESTL(KErrNone == ret); |
|
470 |
|
471 Logger().WriteFormat(_L("Opening a socket")); |
|
472 RSocket socket; |
|
473 ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
474 CleanupClosePushL(socket); |
|
475 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
476 TESTL(KErrNone == ret); |
|
477 |
|
478 TPckgBuf<TUint> lenbuf; |
|
479 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
480 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
481 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
482 &EpocErrorToText(ret), lenbuf()); |
|
483 TESTL(KErrNone == ret); |
|
484 |
|
485 TUint x(70000); |
|
486 lenbuf() = x; |
|
487 Logger().WriteFormat(_L("Setting SendBuf length to %d"), lenbuf()); |
|
488 ret = socket.SetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
489 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
490 TESTL(KErrNone == ret); |
|
491 |
|
492 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
493 ret = socket.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
494 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), &EpocErrorToText(ret), lenbuf()); |
|
495 TESTL(KErrNone == ret); |
|
496 TESTL(lenbuf() == x); |
|
497 |
|
498 Logger().WriteFormat(_L("Try sending datagram over protocol allowing unlimited datagram size")); |
|
499 TInetAddr destAddr; |
|
500 TRequestStatus status; |
|
501 |
|
502 const TInt KBufferLength = 70000; |
|
503 HBufC8* hbuf = HBufC8::NewMaxLC(KBufferLength); |
|
504 TPtr8 buffer(hbuf->Des()); |
|
505 buffer.FillZ(); |
|
506 |
|
507 TSockXfrLength length; |
|
508 socket.SendTo(buffer, destAddr, 0, status, length); |
|
509 User::WaitForRequest(status); |
|
510 Logger().WriteFormat(_L("Status of Send() is %S %d"), &EpocErrorToText(status.Int()), length()); |
|
511 TESTL(status == KErrNone); |
|
512 TESTL(KBufferLength == length()); |
|
513 |
|
514 CleanupStack::PopAndDestroy(hbuf); |
|
515 |
|
516 CleanupStack::Pop(&socket); |
|
517 socket.Close(); |
|
518 |
|
519 CleanupStack::Pop(&ss); |
|
520 ss.Close(); |
|
521 |
|
522 SetTestStepResult(verdict); |
|
523 return verdict; |
|
524 } |
|
525 |
|
526 // Test step 9.8 |
|
527 const TDesC& CSocketTest9_8::GetTestName() |
|
528 { |
|
529 _LIT(ret,"Test9.8"); |
|
530 return ret; |
|
531 } |
|
532 |
|
533 enum TVerdict CSocketTest9_8::InternalDoTestStepL( void ) |
|
534 { |
|
535 TVerdict verdict = EPass; |
|
536 |
|
537 Logger().WriteFormat(_L("Test Purpose: SendTo using TSockXfrLength")); |
|
538 |
|
539 // connect to esock |
|
540 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
541 RSocketServ ss; |
|
542 TSessionPref pref; |
|
543 pref.iAddrFamily = KDummyAddrFamily; |
|
544 pref.iProtocol = KDummyOne; |
|
545 TInt ret = ss.Connect(pref); |
|
546 |
|
547 CleanupClosePushL(ss); |
|
548 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
549 TESTL(KErrNone == ret); |
|
550 |
|
551 Logger().WriteFormat(_L("Finding for dummy protocol 1")); |
|
552 TProtocolDesc protoInfo; |
|
553 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
554 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
555 TESTL(KErrNone == ret); |
|
556 |
|
557 Logger().WriteFormat(_L("Opening a socket")); |
|
558 RSocket socket; |
|
559 ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
560 CleanupClosePushL(socket); |
|
561 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
562 TESTL(KErrNone == ret); |
|
563 |
|
564 |
|
565 // Force the SendTo to 'flow off' |
|
566 TBool flowOff = ETrue; |
|
567 ret = socket.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
568 Logger().WriteFormat(_L("SetOpt (flow off) returned %S"), &EpocErrorToText(ret)); |
|
569 TESTL(KErrNone == ret); |
|
570 |
|
571 // data to send |
|
572 TBuf8<10> pNameBuf; |
|
573 _LIT( Kmessage, "helloworld" ); |
|
574 pNameBuf.Copy( Kmessage); |
|
575 |
|
576 Logger().WriteFormat(_L("Try sending datagram")); |
|
577 TInetAddr destAddr; |
|
578 TRequestStatus status; |
|
579 // induce the 'flow off' state - should never complete |
|
580 TSockXfrLength len; |
|
581 socket.SendTo(pNameBuf, destAddr, 0, status, len); |
|
582 |
|
583 // Now enable the write to complete, by ending the 'flow off' |
|
584 flowOff = EFalse; |
|
585 ret = socket.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
586 TESTL(KErrNone == ret); |
|
587 |
|
588 // check the length returned by the send is OK |
|
589 User::WaitForRequest(status); |
|
590 Logger().WriteFormat(_L("...SendTo returned %d %d\n"), status.Int(),len()); |
|
591 TESTL(status == KErrNone); |
|
592 TESTL(len() == pNameBuf.Length()); |
|
593 |
|
594 CleanupStack::Pop(&socket); |
|
595 socket.Close(); |
|
596 |
|
597 CleanupStack::Pop(&ss); |
|
598 ss.Close(); |
|
599 |
|
600 SetTestStepResult(verdict); |
|
601 return verdict; |
|
602 } |
|
603 |