|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file CUCCTest.cpp |
|
22 */ |
|
23 |
|
24 #include <stdlib.h> |
|
25 #include <string.h> |
|
26 #include <testexecutelog.h> |
|
27 #include "CUCCTest.h" |
|
28 #include "CNetworkEmulatorSetupCommdb.h" |
|
29 #include "uccs_errorcodes.h" |
|
30 |
|
31 #define RECORD_ID "RECORD_ID" |
|
32 #define COMMDB_VALUE "VALUETOSET" |
|
33 #define BUFFERSIZE 256 |
|
34 #define MAXLOGINSCRIPT 512 |
|
35 #define MAXVARLEN 64 |
|
36 |
|
37 const TInt KMaxCommandLineLength = 4096; |
|
38 const TInt KMaxParamNameLength = 128; |
|
39 const TInt KMaxParamValueLength = 1024; |
|
40 |
|
41 |
|
42 CUCCTestStartUseCase::CUCCTestStartUseCase() |
|
43 { |
|
44 SetTestStepName(KTestStartUseCase); |
|
45 } |
|
46 |
|
47 CUCCTestStartUseCase::~CUCCTestStartUseCase() |
|
48 { |
|
49 } |
|
50 |
|
51 TVerdict CUCCTestStartUseCase::doTestStepL() |
|
52 { |
|
53 int ret, uid; |
|
54 int err = 0; |
|
55 CUCCSDeviceControl *app; |
|
56 |
|
57 // get the application control instance and use-case id |
|
58 app = CreateApplicationControlInstance( &uid ); |
|
59 if( app == NULL ) |
|
60 { |
|
61 SetTestStepResult(EFail); |
|
62 return TestStepResult(); |
|
63 } |
|
64 |
|
65 // start the usecase |
|
66 ret = app->startUseCase(uid, &err); |
|
67 |
|
68 // cleanup the app control instance |
|
69 delete app; |
|
70 |
|
71 // return success / failure |
|
72 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
73 return TestStepResult(); |
|
74 } |
|
75 |
|
76 CUCCTestSignal::CUCCTestSignal() |
|
77 { |
|
78 SetTestStepName(KTestSignal); |
|
79 } |
|
80 |
|
81 CUCCTestSignal::~CUCCTestSignal() |
|
82 { |
|
83 } |
|
84 |
|
85 TVerdict CUCCTestSignal::doTestStepL() |
|
86 { |
|
87 int ret, uid; |
|
88 int err = 0; |
|
89 CUCCSDeviceControl *app; |
|
90 |
|
91 // get the application control instance and use-case id |
|
92 app = CreateApplicationControlInstance( &uid ); |
|
93 if( app == NULL ) |
|
94 { |
|
95 SetTestStepResult(EFail); |
|
96 return TestStepResult(); |
|
97 } |
|
98 |
|
99 // call signal |
|
100 ret = app->signal(uid, &err); |
|
101 |
|
102 // cleanup the app control instance |
|
103 delete app; |
|
104 |
|
105 // return success / failure |
|
106 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
107 return TestStepResult(); |
|
108 } |
|
109 |
|
110 CUCCTestRendezvous::CUCCTestRendezvous() |
|
111 { |
|
112 SetTestStepName(KTestRendezvous); |
|
113 } |
|
114 |
|
115 CUCCTestRendezvous::~CUCCTestRendezvous() |
|
116 { |
|
117 } |
|
118 |
|
119 TVerdict CUCCTestRendezvous::doTestStepL() |
|
120 { |
|
121 int ret, uid; |
|
122 int err = 0; |
|
123 CUCCSDeviceControl *app; |
|
124 |
|
125 // get the application control instance and use-case id |
|
126 app = CreateApplicationControlInstance( &uid ); |
|
127 if( app == NULL ) |
|
128 { |
|
129 SetTestStepResult(EFail); |
|
130 return TestStepResult(); |
|
131 } |
|
132 |
|
133 // call rendezvous |
|
134 ret = app->rendezvous(uid, &err); |
|
135 |
|
136 // cleanup the app control instance |
|
137 delete app; |
|
138 |
|
139 // return success / failure |
|
140 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
141 return TestStepResult(); |
|
142 } |
|
143 |
|
144 CUCCTestEndUseCase::CUCCTestEndUseCase() |
|
145 { |
|
146 SetTestStepName(KTestEndUseCase); |
|
147 } |
|
148 |
|
149 CUCCTestEndUseCase::~CUCCTestEndUseCase() |
|
150 { |
|
151 } |
|
152 |
|
153 TVerdict CUCCTestEndUseCase::doTestStepL() |
|
154 { |
|
155 int ret, uid; |
|
156 int err = 0; |
|
157 CUCCSDeviceControl *app; |
|
158 |
|
159 // get the application control instance and use-case id |
|
160 app = CreateApplicationControlInstance( &uid ); |
|
161 if( app == NULL ) |
|
162 { |
|
163 SetTestStepResult(EFail); |
|
164 return TestStepResult(); |
|
165 } |
|
166 |
|
167 // call endusecase |
|
168 TVerdict tmpVerdict = EFail; |
|
169 ret = app->endUseCase(uid, tmpVerdict, &err); |
|
170 SetTestStepResult( tmpVerdict ); |
|
171 |
|
172 // cleanup the app control instance |
|
173 delete app; |
|
174 |
|
175 // return success / failure |
|
176 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
177 return TestStepResult(); |
|
178 } |
|
179 |
|
180 CUCCTestWaitfor::CUCCTestWaitfor() |
|
181 { |
|
182 SetTestStepName(KTestWaitfor); |
|
183 } |
|
184 |
|
185 CUCCTestWaitfor::~CUCCTestWaitfor() |
|
186 { |
|
187 } |
|
188 |
|
189 TVerdict CUCCTestWaitfor::doTestStepL() |
|
190 { |
|
191 int ret, uid; |
|
192 int err = 0; |
|
193 CUCCSDeviceControl *app; |
|
194 |
|
195 // get the application control instance and use-case id |
|
196 app = CreateApplicationControlInstance( &uid ); |
|
197 if( app == NULL ) |
|
198 { |
|
199 SetTestStepResult(EFail); |
|
200 return TestStepResult(); |
|
201 } |
|
202 |
|
203 // call waitfor |
|
204 ret = app->waitfor(uid, &err); |
|
205 |
|
206 // cleanup the app control instance |
|
207 delete app; |
|
208 |
|
209 // return success / failure |
|
210 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
211 return TestStepResult(); |
|
212 } |
|
213 |
|
214 CUCCTestGetVariableName::CUCCTestGetVariableName() |
|
215 { |
|
216 SetTestStepName(KTestGetVariableName); |
|
217 } |
|
218 |
|
219 CUCCTestGetVariableName::~CUCCTestGetVariableName() |
|
220 { |
|
221 } |
|
222 |
|
223 TVerdict CUCCTestGetVariableName::doTestStepL() |
|
224 { |
|
225 int ret, uid; |
|
226 int err = 0; |
|
227 CUCCSDeviceControl *app; |
|
228 char variableValue[64]; |
|
229 char* variableName = "ENV"; |
|
230 |
|
231 // get the application control instance and use-case id |
|
232 app = CreateApplicationControlInstance( &uid ); |
|
233 if( app == NULL ) |
|
234 { |
|
235 SetTestStepResult(EFail); |
|
236 return TestStepResult(); |
|
237 } |
|
238 |
|
239 // call getVariableName |
|
240 ret = app->getVariableName( variableName, variableValue, 64, &err ); |
|
241 |
|
242 // cleanup the app control instance |
|
243 delete app; |
|
244 |
|
245 // return success / failure |
|
246 SetTestStepResult( (ret == UCCS_OK) ? EPass : EFail ); |
|
247 return TestStepResult(); |
|
248 } |
|
249 |
|
250 CUCCTestRunCommand::CUCCTestRunCommand() |
|
251 { |
|
252 SetTestStepName(KTestRunCommand); |
|
253 } |
|
254 |
|
255 CUCCTestRunCommand::~CUCCTestRunCommand() |
|
256 { |
|
257 } |
|
258 |
|
259 // Ini file parameter names and standard values |
|
260 _LIT(KEquals, "="); |
|
261 _LIT(KSpace, " "); |
|
262 _LIT(KQuote, "\""); |
|
263 _LIT(KRunCmd, "runcmd"); |
|
264 _LIT(KServiceName, "svcname"); |
|
265 _LIT(KCall, "call"); |
|
266 _LIT(KMethodID, "methodid"); |
|
267 _LIT(KDefaultMethodID, "10"); |
|
268 |
|
269 TVerdict CUCCTestRunCommand::doTestStepL() |
|
270 { |
|
271 TInt ret, uid; |
|
272 TInt err = 0; |
|
273 CUCCSDeviceControl *app; |
|
274 HBufC* commandLine = HBufC::NewLC(KMaxCommandLineLength); |
|
275 TPtr commandLinePtr(commandLine->Des()); |
|
276 |
|
277 // Specific ini file parameter names and standard values |
|
278 _LIT(KServiceID, "svcid"); |
|
279 _LIT(KServiceHost, "svchost"); |
|
280 _LIT(KNumParams, "num_params" ); |
|
281 _LIT(KParamNameStr,"param_name_"); |
|
282 _LIT(KParamValueStr,"param_value_"); |
|
283 _LIT(KExpectPositiveReturnCodeStr,"expect_positive_return_code"); |
|
284 |
|
285 commandLinePtr.Append( KRunCmd ); |
|
286 |
|
287 // Retrieve the service name |
|
288 TPtrC svcname; |
|
289 TInt rv = GetStringFromConfig( ConfigSection(), KServiceName, svcname ); |
|
290 if( rv ) |
|
291 { |
|
292 // Append the service_name to the command line |
|
293 commandLinePtr.Append( KSpace ); |
|
294 commandLinePtr.Append( KServiceName ); |
|
295 commandLinePtr.Append( KEquals ); |
|
296 commandLinePtr.Append( KQuote ); |
|
297 commandLinePtr.Append( svcname ); |
|
298 commandLinePtr.Append( KQuote ); |
|
299 } |
|
300 else |
|
301 { |
|
302 // Otherwise revert to the legacy svcid and svchost |
|
303 TPtrC svcid; |
|
304 TPtrC svchost; |
|
305 rv = GetStringFromConfig( ConfigSection(), KServiceID, svcid ); |
|
306 if( rv ) |
|
307 { |
|
308 rv = GetStringFromConfig( ConfigSection(), KServiceHost, svchost ); |
|
309 } |
|
310 if( rv ) |
|
311 { |
|
312 // Append the svcid command line |
|
313 commandLinePtr.Append( KSpace ); |
|
314 commandLinePtr.Append( KServiceID ); |
|
315 commandLinePtr.Append( KEquals ); |
|
316 commandLinePtr.Append( svcid ); |
|
317 // Append the svchost command line |
|
318 commandLinePtr.Append( KSpace ); |
|
319 commandLinePtr.Append( KServiceHost ); |
|
320 commandLinePtr.Append( KEquals ); |
|
321 commandLinePtr.Append( KQuote ); |
|
322 commandLinePtr.Append( svchost ); |
|
323 commandLinePtr.Append( KQuote ); |
|
324 } |
|
325 } |
|
326 |
|
327 if( rv ) |
|
328 { |
|
329 // Look up the call name |
|
330 TPtrC call; |
|
331 rv = GetStringFromConfig( ConfigSection(), KCall, call ); |
|
332 if( rv ) |
|
333 { |
|
334 // Append the default methodid (10) to the command line |
|
335 commandLinePtr.Append( KSpace ); |
|
336 commandLinePtr.Append( KMethodID ); |
|
337 commandLinePtr.Append( KEquals ); |
|
338 commandLinePtr.Append( KDefaultMethodID ); |
|
339 // Append the call name to the command line |
|
340 commandLinePtr.Append( KSpace ); |
|
341 commandLinePtr.Append( KCall ); |
|
342 commandLinePtr.Append( KEquals ); |
|
343 commandLinePtr.Append( KQuote ); |
|
344 commandLinePtr.Append( call ); |
|
345 commandLinePtr.Append( KQuote ); |
|
346 } |
|
347 else |
|
348 { |
|
349 // If it is not there look up the method id |
|
350 TPtrC methodid; |
|
351 rv = GetStringFromConfig( ConfigSection(), KMethodID, methodid ); |
|
352 if( rv ) |
|
353 { |
|
354 // Append the methodid command line |
|
355 commandLinePtr.Append( KSpace ); |
|
356 commandLinePtr.Append( KMethodID ); |
|
357 commandLinePtr.Append( KEquals ); |
|
358 commandLinePtr.Append( methodid ); |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 // Iterate through the parameters adding them to the command line as we go |
|
364 TInt num_params = 0; |
|
365 rv = GetIntFromConfig( ConfigSection(), KNumParams, num_params ); |
|
366 if( num_params > 0 ) |
|
367 { |
|
368 HBufC* param_name_str = HBufC::NewLC(KMaxParamNameLength); |
|
369 HBufC* param_value_str = HBufC::NewLC(KMaxParamValueLength); |
|
370 TPtr param_name_str_ptr(param_name_str->Des()); |
|
371 TPtr param_value_str_ptr(param_value_str->Des()); |
|
372 |
|
373 for( int i=1 ; i<=num_params && rv ; i++ ) |
|
374 { |
|
375 TPtrC param_name; |
|
376 TPtrC param_value; |
|
377 |
|
378 param_name_str_ptr.Copy( KParamNameStr ); |
|
379 // Append the parameter number to the end of the ini string |
|
380 param_name_str_ptr.AppendNum( i ); |
|
381 rv = GetStringFromConfig( ConfigSection(), param_name_str_ptr, param_name ); |
|
382 if( rv ) |
|
383 { |
|
384 param_value_str_ptr.Copy( KParamValueStr ); |
|
385 // Append the parameter number to the end of the ini string |
|
386 param_value_str_ptr.AppendNum( i ); |
|
387 rv = GetStringFromConfig( ConfigSection(), param_value_str_ptr, param_value ); |
|
388 } |
|
389 if( rv ) |
|
390 { |
|
391 // Append the parameter name/value to the command line |
|
392 commandLinePtr.Append( KSpace ); |
|
393 commandLinePtr.Append( param_name ); |
|
394 commandLinePtr.Append( KEquals ); |
|
395 commandLinePtr.Append( KQuote ); |
|
396 commandLinePtr.Append( param_value ); |
|
397 commandLinePtr.Append( KQuote ); |
|
398 } |
|
399 } |
|
400 |
|
401 // Cleanup |
|
402 CleanupStack::PopAndDestroy(param_value_str); |
|
403 CleanupStack::PopAndDestroy(param_name_str); |
|
404 } |
|
405 |
|
406 // get the application control instance |
|
407 app = CreateApplicationControlInstance( &uid, EFalse ); |
|
408 if( app == NULL ) |
|
409 { |
|
410 SetTestStepResult(EFail); |
|
411 CleanupStack::PopAndDestroy(commandLine); |
|
412 return TestStepResult(); |
|
413 } |
|
414 |
|
415 // Call runCommand |
|
416 HBufC8* commandLine8 = HBufC8::NewLC(commandLinePtr.Length()+1); |
|
417 TPtr8 ptr8(commandLine8->Des()); |
|
418 ptr8.Copy(commandLinePtr); |
|
419 ret = app->runCommandL( (char*)ptr8.PtrZ(), &err ); |
|
420 |
|
421 // Log the UCC/Service call result |
|
422 _LIT( KUCCCallResult, "UCC Call Result = %d" ); |
|
423 INFO_PRINTF2( KUCCCallResult, ret ); |
|
424 |
|
425 // Cleanup |
|
426 delete app; |
|
427 CleanupStack::PopAndDestroy(commandLine8); |
|
428 CleanupStack::PopAndDestroy(commandLine); |
|
429 |
|
430 // the following section represents an ultra lightweight way of tolerating handles returned by services, without assuming |
|
431 // that any nonzero return code is a problem. |
|
432 // in future this could be extended to store the specific handle values in a map to refer back to them in later test steps.. |
|
433 // something like "store_result_as_handle_called=Test1" |
|
434 TBool expectPositiveReturnCode(EFalse); |
|
435 rv = GetBoolFromConfig( ConfigSection(), KExpectPositiveReturnCodeStr, expectPositiveReturnCode ); |
|
436 if(expectPositiveReturnCode && ret > 0) |
|
437 { |
|
438 if(ret>0) // a handle value was returned = success |
|
439 { |
|
440 ret=KErrNone; |
|
441 } |
|
442 else if(ret==0) // null handle means there was a problem |
|
443 { |
|
444 ret=KErrUnknown; |
|
445 } |
|
446 } |
|
447 |
|
448 // Return success / failure |
|
449 SetTestStepResult( (ret == KErrNone) ? EPass : EFail ); |
|
450 return TestStepResult(); |
|
451 } |
|
452 |
|
453 CUCCTestSetDeviceID::CUCCTestSetDeviceID() |
|
454 { |
|
455 SetTestStepName(KTestSetDeviceID); |
|
456 } |
|
457 |
|
458 CUCCTestSetDeviceID::~CUCCTestSetDeviceID() |
|
459 { |
|
460 } |
|
461 |
|
462 TVerdict CUCCTestSetDeviceID::doTestStepL() |
|
463 { |
|
464 int uid; |
|
465 CUCCSDeviceControl *app; |
|
466 |
|
467 // get the application control instance and use-case id |
|
468 app = CreateApplicationControlInstance( &uid ); |
|
469 if( app == NULL ) |
|
470 { |
|
471 SetTestStepResult(EFail); |
|
472 return TestStepResult(); |
|
473 } |
|
474 |
|
475 // do the set |
|
476 SetTestStepResult( UpdateCommdbEntry( app ) ); |
|
477 |
|
478 // cleanup and exit |
|
479 delete app; |
|
480 app = NULL; |
|
481 return TestStepResult(); |
|
482 } |
|
483 |
|
484 TVerdict CUCCTestSetDeviceID::UpdateCommdbEntry( CUCCSDeviceControl *aApp ) |
|
485 { |
|
486 int ret, err = 0, isp_index, device_id; |
|
487 TCommDBError cdberr; |
|
488 CSetUpCommDb commdb_handle; |
|
489 TBuf<MAXLOGINSCRIPT> login_script_string; |
|
490 char device_id_string[MAXVARLEN]; |
|
491 char isp_index_string[MAXVARLEN]; |
|
492 |
|
493 // get the device id from the use-case script |
|
494 ret = aApp->getVariableName( "DEVICEID", device_id_string, MAXVARLEN, &err ); |
|
495 if( ret != UCCS_OK ) |
|
496 { |
|
497 SetTestStepResult(EFail); |
|
498 return TestStepResult(); |
|
499 } |
|
500 device_id = atoi(device_id_string); |
|
501 |
|
502 // get the ISP index from the use-case script |
|
503 ret = aApp->getVariableName( "COMMDB_ISP_INDEX", isp_index_string, MAXVARLEN, &err ); |
|
504 if( ret != UCCS_OK ) |
|
505 { |
|
506 SetTestStepResult(EFail); |
|
507 return TestStepResult(); |
|
508 } |
|
509 isp_index = atoi( isp_index_string ); |
|
510 |
|
511 // create the entry string |
|
512 login_script_string.FillZ(); |
|
513 login_script_string.Append( _L("CHARMAP [windows-1252]\n") ); |
|
514 login_script_string.Append( _L("LOOP 10\n{\nSEND \"ID=") ); |
|
515 login_script_string.AppendNum( device_id ); |
|
516 login_script_string.Append( _L("\"+<0x0d>\nWAIT 3\n{\n\"SERVER(") ); |
|
517 login_script_string.AppendNum( device_id ); |
|
518 login_script_string.Append( _L(")\" OK\n}\n}\nEXIT KErrNoAnswer$\n\nOK:\nEXIT\n") ); |
|
519 |
|
520 // set the value in COMMDB |
|
521 cdberr = commdb_handle.initialise(); |
|
522 if( cdberr != TCommDB_Success ) |
|
523 { |
|
524 SetTestStepResult(EFail); |
|
525 return TestStepResult(); |
|
526 } |
|
527 cdberr = commdb_handle.updateEntry( DIAL_OUT_ISP, isp_index, ISP_LOGIN_SCRIPT, (char*)login_script_string.PtrZ(), &err ); |
|
528 if( cdberr != TCommDB_Success ) |
|
529 { |
|
530 SetTestStepResult(EFail); |
|
531 return TestStepResult(); |
|
532 } |
|
533 |
|
534 // done ik |
|
535 SetTestStepResult(EPass); |
|
536 return TestStepResult(); |
|
537 } |