|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file SocketServer.TestSteps.cpp |
|
18 */ |
|
19 |
|
20 #include <commdbconnpref.h> |
|
21 #include "SocketServer.TestSteps.h" |
|
22 |
|
23 |
|
24 // Create Socket Server |
|
25 //--------------------- |
|
26 |
|
27 CCreateRSocketServStep::CCreateRSocketServStep(CCEsockTestBase*& aEsockTest) |
|
28 : CTe_EsockStepBase(aEsockTest) |
|
29 { |
|
30 SetTestStepName(KCreateRSocketServStep); |
|
31 } |
|
32 |
|
33 TVerdict CCreateRSocketServStep::doTestStepPreambleL() |
|
34 { |
|
35 SetTestStepResult(EFail); |
|
36 |
|
37 if (iEsockTest==NULL) |
|
38 iEsockTest = new (ELeave) CCEsockTestBase; |
|
39 |
|
40 SetTestStepResult(EPass); |
|
41 return TestStepResult(); |
|
42 } |
|
43 |
|
44 TInt CCreateRSocketServStep::ConfigureFromIni() |
|
45 { |
|
46 iSockServName.Set(KNullDesC); |
|
47 |
|
48 // Read in appropriate fields |
|
49 if((GetStringFromConfig(iSection, KTe_SocketServName, iSockServName) != 1) |
|
50 || (iSockServName.Length() == 0)) |
|
51 { |
|
52 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
53 return KErrNotFound; |
|
54 } |
|
55 |
|
56 // All ok if we got this far |
|
57 return KErrNone; |
|
58 } |
|
59 |
|
60 TVerdict CCreateRSocketServStep::doSingleTestStep() |
|
61 { |
|
62 TInt error = iEsockTest->CreateSocketServer(iSockServName); |
|
63 if (error!=KErrNone) |
|
64 { |
|
65 INFO_PRINTF2(_L("Could not create socket server (%S)."),&iSockServName); |
|
66 INFO_PRINTF2(_L("Error: %d."),error); |
|
67 return EFail; |
|
68 } |
|
69 return EPass; |
|
70 } |
|
71 |
|
72 |
|
73 |
|
74 // Connect Socket Server |
|
75 //---------------------- |
|
76 |
|
77 CConnectRSocketServStep::CConnectRSocketServStep(CCEsockTestBase*& aEsockTest) |
|
78 : CTe_EsockStepBase(aEsockTest) |
|
79 { |
|
80 SetTestStepName(KConnectRSocketServStep); |
|
81 } |
|
82 |
|
83 TInt CConnectRSocketServStep::ConfigureFromIni() |
|
84 { |
|
85 iSockServName.Set(KNullDesC); |
|
86 |
|
87 // Read in appropriate fields |
|
88 if((GetStringFromConfig(iSection, KTe_SocketServName, iSockServName) != 1) |
|
89 || (iSockServName.Length() == 0)) |
|
90 { |
|
91 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
92 return KErrNotFound; |
|
93 } |
|
94 |
|
95 // All ok if we got this far |
|
96 return KErrNone; |
|
97 } |
|
98 |
|
99 TVerdict CConnectRSocketServStep::doSingleTestStep() |
|
100 { |
|
101 TInt error = iEsockTest->ConnectSocketServer(iSockServName); |
|
102 if (error!=KErrNone) |
|
103 { |
|
104 INFO_PRINTF2(_L("Could not connect socket server (%S)."),&iSockServName); |
|
105 INFO_PRINTF2(_L("Error: %d."),error); |
|
106 return EFail; |
|
107 } |
|
108 return EPass; |
|
109 } |
|
110 |
|
111 |
|
112 // Close Socket Server |
|
113 //-------------------- |
|
114 |
|
115 CCloseRSocketServStep::CCloseRSocketServStep(CCEsockTestBase*& aEsockTest) |
|
116 : CTe_EsockStepBase(aEsockTest) |
|
117 { |
|
118 SetTestStepName(KCloseRSocketServStep); |
|
119 } |
|
120 |
|
121 TInt CCloseRSocketServStep::ConfigureFromIni() |
|
122 { |
|
123 iSockServName.Set(KNullDesC); |
|
124 |
|
125 if((GetStringFromConfig(iSection, KTe_SocketServName, iSockServName) != 1) |
|
126 || (iSockServName.Length() == 0)) |
|
127 { |
|
128 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
129 return KErrNotFound; |
|
130 } |
|
131 |
|
132 // All ok if we got this far |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 TVerdict CCloseRSocketServStep::doSingleTestStep() |
|
137 { |
|
138 TInt error = iEsockTest->CloseSocketServer(iSockServName); |
|
139 if (error!=KErrNone) |
|
140 { |
|
141 INFO_PRINTF2(_L("Could not close socket server (%S)."),&iSockServName); |
|
142 INFO_PRINTF2(_L("Error: %d."),error); |
|
143 return EFail; |
|
144 } |
|
145 return EPass; |
|
146 } |
|
147 |
|
148 |
|
149 |
|
150 // Get number of protocols |
|
151 //------------------------ |
|
152 |
|
153 _LIT(KNumberExpected, "NumberExpected"); |
|
154 _LIT(KSaveNumberAs, "SaveNumberAs"); |
|
155 |
|
156 CSocketServerNumProtocolsStep::CSocketServerNumProtocolsStep(CCEsockTestBase*& aEsockTest) |
|
157 : CTe_EsockStepBase(aEsockTest) |
|
158 { |
|
159 SetTestStepName(KSocketServerNumProtocolsStep); |
|
160 } |
|
161 |
|
162 TInt CSocketServerNumProtocolsStep::ConfigureFromIni() |
|
163 { |
|
164 iParams.Reset(); |
|
165 |
|
166 // The socket server instance to apply the query to |
|
167 if(GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSocketServName) != 1) |
|
168 { |
|
169 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketServName); |
|
170 return KErrNotFound; |
|
171 } |
|
172 |
|
173 // Expected number of protocols |
|
174 if (GetIntFromConfig(iSection, KNumberExpected, iParams.iNumberExpected) == 1) |
|
175 { |
|
176 iParams.iExpected = ETrue; |
|
177 } |
|
178 |
|
179 // Somewhere to save the number fetched |
|
180 if(GetStringFromConfig(iSection, KSaveNumberAs, iParams.iSavedAsName) == 1) |
|
181 { |
|
182 iParams.iToBeSaved = ETrue; |
|
183 } |
|
184 |
|
185 // Check |
|
186 if(!iParams.iExpected && !iParams.iToBeSaved) |
|
187 { |
|
188 INFO_PRINTF1(_L("Must provide an expected value or a place to save the number fetched.")); |
|
189 return KErrNotFound; |
|
190 } |
|
191 |
|
192 // All ok if we got this far |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 TVerdict CSocketServerNumProtocolsStep::doSingleTestStep() |
|
197 { |
|
198 TInt numProtocols; |
|
199 |
|
200 TInt error = iEsockTest->SocketServerNumProtocols(iParams, numProtocols); |
|
201 if (error != KErrNone) |
|
202 { |
|
203 SetTestStepError(error); |
|
204 INFO_PRINTF3(_L("Could not fetch number of protocols from socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
205 return EFail; |
|
206 } |
|
207 |
|
208 // Validate against the expected number |
|
209 if(iParams.iExpected) |
|
210 { |
|
211 if(numProtocols == iParams.iNumberExpected) |
|
212 { |
|
213 return EPass; |
|
214 } |
|
215 else |
|
216 { |
|
217 INFO_PRINTF3(_L("Number of protocols differs from that expected. expected:%d, returned:%d"), iParams.iNumberExpected, numProtocols); |
|
218 return EFail; |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 SetTestStepResult(EPass); |
|
224 return TestStepResult(); |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 // Find protocol |
|
231 //-------------- |
|
232 |
|
233 CSocketServerFindProtocolStep::CSocketServerFindProtocolStep(CCEsockTestBase*& aEsockTest) |
|
234 : CTe_EsockStepBase(aEsockTest) |
|
235 { |
|
236 SetTestStepName(KSocketServerFindProtocolStep); |
|
237 } |
|
238 |
|
239 TInt CSocketServerFindProtocolStep::ConfigureFromIni() |
|
240 { |
|
241 iParams.Reset(); |
|
242 |
|
243 // The socket server instance to apply the query to |
|
244 if(GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSocketServName) != 1) |
|
245 { |
|
246 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketServName); |
|
247 return KErrNotFound; |
|
248 } |
|
249 |
|
250 TInt descStatus = TProtocolDescriptionParams::FetchDescription(iParams.iProtocolDescParams, *this); |
|
251 return descStatus; |
|
252 } |
|
253 |
|
254 TVerdict CSocketServerFindProtocolStep::doSingleTestStep() |
|
255 { |
|
256 TProtocolDesc desc; |
|
257 |
|
258 TInt error = iEsockTest->SocketServerFindProtocol(iParams, desc); |
|
259 if (error != KErrNone) |
|
260 { |
|
261 SetTestStepError(error); |
|
262 INFO_PRINTF3(_L("Could not fetch protocol description from socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
263 return EFail; |
|
264 } |
|
265 |
|
266 // Validate against the expected protocol description |
|
267 if(iParams.iProtocolDescParams.MatchesExpected(desc)) |
|
268 { |
|
269 return EPass; |
|
270 } |
|
271 else |
|
272 { |
|
273 INFO_PRINTF1(_L("Protocol description does not match that expected")); |
|
274 return EFail; |
|
275 } |
|
276 } |
|
277 |
|
278 |
|
279 |
|
280 // Get protocol info |
|
281 //------------------ |
|
282 |
|
283 CSocketServerGetProtocolInfoStep::CSocketServerGetProtocolInfoStep(CCEsockTestBase*& aEsockTest) |
|
284 : CTe_EsockStepBase(aEsockTest) |
|
285 { |
|
286 SetTestStepName(KSocketServerGetProtocolInfoStep); |
|
287 } |
|
288 |
|
289 _LIT(KIndex, "Index"); |
|
290 |
|
291 TInt CSocketServerGetProtocolInfoStep::ConfigureFromIni() |
|
292 { |
|
293 iParams.Reset(); |
|
294 |
|
295 // The socket server instance to apply the query to |
|
296 if(GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSocketServName) != 1) |
|
297 { |
|
298 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketServName); |
|
299 return KErrNotFound; |
|
300 } |
|
301 |
|
302 // Protocol index |
|
303 if (GetIntFromConfig(iSection, KIndex, iParams.iProtocolIndex) != 1) |
|
304 { |
|
305 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, KIndex); |
|
306 return KErrNotFound; |
|
307 } |
|
308 |
|
309 TInt descStatus = TProtocolDescriptionParams::FetchDescription(iParams.iProtocolDescParams, *this); |
|
310 return descStatus; |
|
311 } |
|
312 |
|
313 TVerdict CSocketServerGetProtocolInfoStep::doSingleTestStep() |
|
314 { |
|
315 TProtocolDesc desc; |
|
316 |
|
317 TInt error = iEsockTest->SocketServerGetProtocolInfo(iParams, desc); |
|
318 if (error != KErrNone) |
|
319 { |
|
320 SetTestStepError(error); |
|
321 INFO_PRINTF3(_L("Could not fetch protocol description from socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
322 return EFail; |
|
323 } |
|
324 |
|
325 // Validate against the expected protocol description |
|
326 if(iParams.iProtocolDescParams.MatchesExpected(desc)) |
|
327 { |
|
328 return EPass; |
|
329 } |
|
330 else |
|
331 { |
|
332 INFO_PRINTF1(_L("Protocol description does not match that expected")); |
|
333 return EFail; |
|
334 } |
|
335 } |
|
336 |
|
337 // Start protocol |
|
338 //--------------- |
|
339 _LIT(KAddrFamily, "AddrFamily"); |
|
340 _LIT(KProtocol, "Protocol"); |
|
341 _LIT(KSockType, "SockType"); |
|
342 |
|
343 |
|
344 CSocketServerStartProtocolStep::CSocketServerStartProtocolStep(CCEsockTestBase*& aEsockTest) |
|
345 : CTe_EsockStepBase(aEsockTest) |
|
346 { |
|
347 SetTestStepName(KSocketServerStartProtocolStep); |
|
348 } |
|
349 |
|
350 TInt CSocketServerStartProtocolStep::ConfigureFromIni() |
|
351 { |
|
352 iParams.Reset(); |
|
353 |
|
354 // The socket server instance to apply the query to |
|
355 if(GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSocketServName) != 1) |
|
356 { |
|
357 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketServName); |
|
358 return KErrNotFound; |
|
359 } |
|
360 |
|
361 // Address family |
|
362 if (GetIntFromConfig(iSection, KAddrFamily, iParams.iAddrFamily) != 1) |
|
363 { |
|
364 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KAddrFamily); |
|
365 return KErrNotFound; |
|
366 } |
|
367 |
|
368 // Protocol |
|
369 if (GetIntFromConfig(iSection, KProtocol, iParams.iProtocol) != 1) |
|
370 { |
|
371 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KProtocol); |
|
372 return KErrNotFound; |
|
373 } |
|
374 |
|
375 // Socket type |
|
376 if (GetIntFromConfig(iSection, KSockType, iParams.iSockType) != 1) |
|
377 { |
|
378 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KSockType); |
|
379 return KErrNotFound; |
|
380 } |
|
381 |
|
382 // All ok if we got this far |
|
383 return KErrNone; |
|
384 } |
|
385 |
|
386 TVerdict CSocketServerStartProtocolStep::doSingleTestStep() |
|
387 { |
|
388 TRequestStatus status; |
|
389 TInt error = iEsockTest->SocketServerStartProtocol(iParams, status); |
|
390 if (error != KErrNone) |
|
391 { |
|
392 SetTestStepError(error); |
|
393 SetTestStepResult(EFail); |
|
394 INFO_PRINTF3(_L("Could not start protocol on socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
395 return TestStepResult(); |
|
396 } |
|
397 |
|
398 User::WaitForRequest(status); |
|
399 if (status.Int() != KErrNone) |
|
400 { |
|
401 SetTestStepError(error); |
|
402 SetTestStepResult(EFail); |
|
403 INFO_PRINTF3(_L("Could not start protocol on socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
404 } |
|
405 |
|
406 // Return the test step result |
|
407 return TestStepResult(); |
|
408 } |
|
409 |
|
410 |
|
411 |
|
412 // Stop protocol |
|
413 //--------------- |
|
414 CSocketServerStopProtocolStep::CSocketServerStopProtocolStep(CCEsockTestBase*& aEsockTest) |
|
415 : CTe_EsockStepBase(aEsockTest) |
|
416 { |
|
417 SetTestStepName(KSocketServerStopProtocolStep); |
|
418 } |
|
419 |
|
420 TInt CSocketServerStopProtocolStep::ConfigureFromIni() |
|
421 { |
|
422 iParams.Reset(); |
|
423 |
|
424 // The socket server instance to apply the query to |
|
425 if(GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSocketServName) != 1) |
|
426 { |
|
427 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KTe_SocketServName); |
|
428 return KErrNotFound; |
|
429 } |
|
430 |
|
431 // Address family |
|
432 if (GetIntFromConfig(iSection, KAddrFamily, iParams.iAddrFamily) != 1) |
|
433 { |
|
434 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KAddrFamily); |
|
435 return KErrNotFound; |
|
436 } |
|
437 |
|
438 // Protocol |
|
439 if (GetIntFromConfig(iSection, KProtocol, iParams.iProtocol) != 1) |
|
440 { |
|
441 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KProtocol); |
|
442 return KErrNotFound; |
|
443 } |
|
444 |
|
445 // Socket type |
|
446 if (GetIntFromConfig(iSection, KSockType, iParams.iSockType) != 1) |
|
447 { |
|
448 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KSockType); |
|
449 return KErrNotFound; |
|
450 } |
|
451 |
|
452 // All ok if we got this far |
|
453 return KErrNone; |
|
454 } |
|
455 |
|
456 TVerdict CSocketServerStopProtocolStep::doSingleTestStep() |
|
457 { |
|
458 TRequestStatus status; |
|
459 TInt error = iEsockTest->SocketServerStopProtocol(iParams, status); |
|
460 if (error != KErrNone) |
|
461 { |
|
462 SetTestStepError(error); |
|
463 SetTestStepResult(EFail); |
|
464 INFO_PRINTF3(_L("Could not stop protocol on socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
465 return TestStepResult(); |
|
466 } |
|
467 |
|
468 User::WaitForRequest(status); |
|
469 if (status.Int() != KErrNone) |
|
470 { |
|
471 SetTestStepError(error); |
|
472 SetTestStepResult(EFail); |
|
473 INFO_PRINTF3(_L("Could not stop protocol on socket server. socketServer:%S, error:%d"), &iParams.iSocketServName, error); |
|
474 } |
|
475 |
|
476 // Return the test step result |
|
477 return TestStepResult(); |
|
478 } |
|
479 |
|
480 |
|
481 |
|
482 // Compare integer values |
|
483 //----------------------- |
|
484 _LIT(KValue1, "Value1"); |
|
485 _LIT(KValue2, "Value2"); |
|
486 _LIT(KDifference, "Difference"); |
|
487 |
|
488 CCompareIntegerValuesStep::CCompareIntegerValuesStep(CCEsockTestBase*& aEsockTest) |
|
489 : CTe_EsockStepBase(aEsockTest) |
|
490 { |
|
491 SetTestStepName(KCompareIntegerValuesStep); |
|
492 } |
|
493 |
|
494 TInt CCompareIntegerValuesStep::ConfigureFromIni() |
|
495 { |
|
496 iParams.Reset(); |
|
497 |
|
498 // The values to the apply the comparison to |
|
499 if(GetStringFromConfig(iSection, KValue1, iParams.iValue1) != 1) |
|
500 { |
|
501 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KValue1); |
|
502 return KErrNotFound; |
|
503 } |
|
504 |
|
505 if(GetStringFromConfig(iSection, KValue2, iParams.iValue2) != 1) |
|
506 { |
|
507 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KValue2); |
|
508 return KErrNotFound; |
|
509 } |
|
510 |
|
511 // The difference to apply |
|
512 if (GetIntFromConfig(iSection, KDifference, iParams.iDifference) != 1) |
|
513 { |
|
514 INFO_PRINTF3(KErrString_MissingConfigFileField, &iSection, &KDifference); |
|
515 return KErrNotFound; |
|
516 } |
|
517 |
|
518 // All ok if we got this far |
|
519 return KErrNone; |
|
520 } |
|
521 |
|
522 TVerdict CCompareIntegerValuesStep::doSingleTestStep() |
|
523 { |
|
524 TInt result; |
|
525 TInt error = iEsockTest->CompareIntegerValues(iParams, result); |
|
526 |
|
527 if (error != KErrNone) |
|
528 { |
|
529 SetTestStepError(error); |
|
530 SetTestStepResult(EFail); |
|
531 INFO_PRINTF1(_L("Could not compare compare integer values")); |
|
532 return TestStepResult(); |
|
533 } |
|
534 else |
|
535 { |
|
536 if(result == 0) |
|
537 { |
|
538 INFO_PRINTF1(_L("Values match.")); |
|
539 SetTestStepResult(EPass); |
|
540 } |
|
541 else |
|
542 { |
|
543 INFO_PRINTF1(_L("Values do not match.")); |
|
544 SetTestStepResult(EFail); |
|
545 } |
|
546 } |
|
547 // Return the test step result |
|
548 return TestStepResult(); |
|
549 } |
|
550 |
|
551 |
|
552 |
|
553 |