|
1 // Copyright (c) 2005-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 // Test CApaCommandLine Apis\n |
|
15 // Test CApaCommandLine API by setting launching information and |
|
16 // checking setter and getter function.\n |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include "T_CmdlnStep.h" |
|
26 #include "testableapalssession.h" |
|
27 |
|
28 /** |
|
29 @SYMTestCaseID T-CmdlnStep-testSecureCmdLinesL |
|
30 |
|
31 @SYMPREQ 280 - File Handle Support |
|
32 |
|
33 @SYMTestCaseDesc Tests CApaCommandLine Apis. |
|
34 |
|
35 @SYMTestPriority High |
|
36 |
|
37 @SYMTestStatus Implemented |
|
38 |
|
39 |
|
40 @SYMTestActions . |
|
41 Observe the operation that is executed on each command.\n |
|
42 Test the following accessor functions:\n |
|
43 CApaCommandLine::ExecutableName()\n |
|
44 CApaCommandLine::Command()\n |
|
45 CApaCommandLine::DocumentName()\n |
|
46 CApaCommandLine::TailEnd()\n |
|
47 CApaCommandLine::ServerId()\n |
|
48 CApaCommandLine::SessionHandle()\n |
|
49 CApaCommandLine::SubSessionHandle()\n |
|
50 Check whether each of these getter functions return the individual components.\n\n |
|
51 Test the following setter functions:\n |
|
52 CApaCommandLine::SetExecutableNameL()\n |
|
53 CApaCommandLine::SetCommandL()\n |
|
54 CApaCommandLine::SetDocumentNameL()\n |
|
55 CApaCommandLine::SetTailEndL()\n |
|
56 CApaCommandLine::SetServerId()\n |
|
57 CApaCommandLine::SetSessionHandle()\n |
|
58 CApaCommandLine::SetSubSessionHandle()\n |
|
59 Use the setter functions to set the individual components. Use the |
|
60 getter methods to verify values set to the individual components.\n |
|
61 API Calls:\n |
|
62 CApaCommandLine::NewL(const RMessagePtr2& aMessage)\n |
|
63 CApaCommandLine::ExecutableName() const\n |
|
64 CApaCommandLine::Command() const\n |
|
65 CApaCommandLine::DocumentName() const\n |
|
66 CApaCommandLine::TailEnd() const\n |
|
67 CApaCommandLine::TailEnd() const\n |
|
68 CApaCommandLine::ServerId() const\n |
|
69 CApaCommandLine::SessionHandle() const\n |
|
70 CApaCommandLine::SubSessionHandle() const\n |
|
71 CApaCommandLine::EnviromentSlotsReaderL()\n |
|
72 CApaCommandLine::SetExecutableNameL(const TDesC& aAppName)\n |
|
73 CApaCommandLine::SetCommandL(TApaCommand aCommand)\n |
|
74 CApaCommandLine::SetDocumentNameL(const TDesC& aDocName)\n |
|
75 CApaCommandLine::SetTailEndL(const TDesC8& aTailEnd)\n |
|
76 CApaCommandLine::SetServerId(TInt aServerId)\n |
|
77 CApaCommandLine::SetSessionHandle(TInt aSessionHandle)\n |
|
78 CApaCommandLine::SetSubSessionHandle(TInt aSubSessionHandle)\n |
|
79 CApaCommandLine::SetProcessEnvironmentL(RProcess& aProcess) const\n |
|
80 |
|
81 |
|
82 |
|
83 @SYMTestExpectedResults Tests checks results against desired results. |
|
84 |
|
85 */ |
|
86 void CT_CmdlnStep::testSecureCmdLinesL() |
|
87 { |
|
88 RTestableApaLsSession ls; |
|
89 TEST(KErrNone == ls.Connect()); |
|
90 CleanupClosePushL(ls); |
|
91 |
|
92 testPositiveInputsL(); |
|
93 testInitializationL(); |
|
94 testBoundaryConditionsL(); |
|
95 //DONT_CHECK since type store is updated |
|
96 HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, testRecAppLaunchL(ls), NO_CLEANUP); |
|
97 |
|
98 CleanupStack::PopAndDestroy(&ls); |
|
99 } |
|
100 |
|
101 /** |
|
102 Auxiliary function for TestCaseID T-CmdlnStep-testSecureCmdLinesL |
|
103 |
|
104 |
|
105 @SYMPREQ 280 - File Handle Support |
|
106 |
|
107 Call the Set APIs below with valid inputs |
|
108 CApaCommandLine::SetExecutableNameL(appName); |
|
109 CApaCommandLine::SetDocumentNameL(docName); |
|
110 CApaCommandLine::SetTailEndL(tailEnd); |
|
111 CApaCommandLine::SetFileByHandleL(aFile); |
|
112 CApaCommandLine::SetCommandL(command); |
|
113 |
|
114 Compares the values set by the above APIs with those obtained by the GET APIs mentioned below |
|
115 CApaCommandLine::ExecutableName()); |
|
116 CApaCommandLine::DocumentName()); |
|
117 CApaCommandLine::TailEnd()); |
|
118 CApaCommandLine::GetFileByHandleL(); |
|
119 CApaCommandLine::Command()); |
|
120 |
|
121 |
|
122 */ |
|
123 void CT_CmdlnStep::testPositiveInputsL() |
|
124 { |
|
125 TPtrC appName; |
|
126 TPtrC docName; |
|
127 TApaCommand command = EApaCommandRun; |
|
128 TPtrC8 tailEnd; |
|
129 TEntry dirEntry; |
|
130 RFs fSession; |
|
131 RFile file; |
|
132 |
|
133 INFO_PRINTF1(_L("Tests the Set and Get command line APIs for valid inputs")); |
|
134 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); // start with an empty command line |
|
135 |
|
136 appName.Set(KTAppName); |
|
137 docName.Set(KTDocName); |
|
138 tailEnd.Set(KTTailEnd); |
|
139 |
|
140 User::LeaveIfError(fSession.Connect()); |
|
141 //User::LeaveIfError(fSession.ShareProtected()); |
|
142 INFO_PRINTF1(_L("Check for the existence of C:\\System\\Data Directory")); |
|
143 TInt ret = fSession.Entry(KTempDir,dirEntry); |
|
144 if(ret==KErrNotFound) |
|
145 { |
|
146 INFO_PRINTF1(_L("Create C:\\System\\Data Directory if not existing already")); |
|
147 fSession.MkDir(KTempDir); /* Created Data Directory as it does not exist */ |
|
148 } |
|
149 User::LeaveIfError(file.Replace(fSession, KTDocName, EFileStreamText|EFileShareAny)); |
|
150 User::LeaveIfError(file.Write(KTWriteData));//write some test data |
|
151 |
|
152 INFO_PRINTF1(_L("The Set command line APIs are invoked with valid arguments")); |
|
153 // Set the member variables using the Set functions |
|
154 |
|
155 TRAP(ret, |
|
156 { |
|
157 cmdLine->SetExecutableNameL(appName); |
|
158 cmdLine->SetDocumentNameL(docName); |
|
159 cmdLine->SetTailEndL(tailEnd); |
|
160 cmdLine->SetFileByHandleL(file); |
|
161 cmdLine->SetCommandL(command); |
|
162 } ) |
|
163 |
|
164 TEST(KErrNone==ret); |
|
165 |
|
166 if(KErrNone==ret) |
|
167 { |
|
168 INFO_PRINTF1(_L("The Get command line APIs are invoked and their return values are verified")); |
|
169 //Test the values returned by the Get Functions |
|
170 TEST(appName==cmdLine->ExecutableName()); |
|
171 TEST(docName==cmdLine->DocumentName()); |
|
172 TEST(tailEnd==cmdLine->TailEnd()); |
|
173 |
|
174 RFile tempFile; |
|
175 TBuf8<10> readData; |
|
176 TRAP(ret,cmdLine->GetFileByHandleL(tempFile)); |
|
177 TEST(KErrNone==ret); |
|
178 if(KErrNone==ret) |
|
179 { |
|
180 tempFile.Read(0,readData);//file still open so rewind file pointer |
|
181 TEST(readData==KTWriteData); |
|
182 } |
|
183 } |
|
184 |
|
185 file.Close(); |
|
186 fSession.Close(); |
|
187 //fSession.Delete(KTDocName); |
|
188 CleanupStack::PopAndDestroy(cmdLine); |
|
189 |
|
190 } |
|
191 |
|
192 |
|
193 /** |
|
194 Auxiliary function for TestCaseID T-CmdlnStep-testSecureCmdLinesL |
|
195 |
|
196 @SYMPREQ 280 - File Handle Support |
|
197 |
|
198 Tests the initial values of the member variables |
|
199 |
|
200 Following are the SET APIs tested |
|
201 CApaCommandLine::SetExecutableNameL(appName); |
|
202 CApaCommandLine::SetDocumentNameL(docName); |
|
203 CApaCommandLine::SetTailEndL(tailEnd); |
|
204 CApaCommandLine::SetSessionHandle(TInt aSessionHandle); |
|
205 CApaCommandLine::SetSubSessionHandle(TInt aSubSessionHandle); |
|
206 CApaCommandLine::SetServerIdL(TInt serverId); |
|
207 CApaCommandLine::SetCommandL(command); |
|
208 |
|
209 Compares the values set with those obtained by the GET APIs |
|
210 CApaCommandLine::ExecutableName(); |
|
211 CApaCommandLine::DocumentName(); |
|
212 CApaCommandLine::TailEnd(); |
|
213 CApaCommandLine::ServerId(); |
|
214 CApaCommandLine::SessionHandle(); |
|
215 CApaCommandLine::SubSessionHandle(); |
|
216 CApaCommandLine::Command(); |
|
217 |
|
218 Following Scenarios are tested |
|
219 |
|
220 1. Do not set the values and check the values returned by the GET APIs |
|
221 2. Set Application Name and check all the values returned by the GET APIs |
|
222 3. Set AppName,DocName and check all the values returned by the GET APIs |
|
223 4. Set AppName,DocName,Tailend and check all the values returned by the GET APIs |
|
224 5. Set AppName,DocName,Tailend,Serverid and check all the values returned by the GET APIs |
|
225 6. Set AppName,DocName,Tailend,Serverid,sessionId and check all the values returned by the GET APIs |
|
226 7. Set AppName,DocName,Tailend,Serverid,sessionId and subsessionId and check all the values returned by the GET APIs |
|
227 */ |
|
228 |
|
229 void CT_CmdlnStep::testInitializationL() |
|
230 { |
|
231 |
|
232 TPtrC appName(KNullDesC); |
|
233 TPtrC docName(KNullDesC); |
|
234 TApaCommand cmdType = EApaCommandRun;//CApaCommandLine's initial value |
|
235 TPtrC8 tailEnd(KNullDesC8); |
|
236 RFs fSession; |
|
237 RFile file; |
|
238 TEntry dirEntry; |
|
239 |
|
240 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); // start with an empty command line |
|
241 |
|
242 for(TInt index = 0; index < TEST_SET_APIS-1; index++) |
|
243 { |
|
244 switch(index) |
|
245 { |
|
246 case TEST_INITIALIZATION: |
|
247 INFO_PRINTF1(_L("Tests the initial values of the member data")); |
|
248 break; |
|
249 case TEST_APP: |
|
250 INFO_PRINTF1(_L("Setting Application Name to \"app name\".")); |
|
251 appName.Set(KTAppName); |
|
252 cmdLine->SetExecutableNameL(appName); |
|
253 break; |
|
254 case TEST_DOC: |
|
255 INFO_PRINTF1(_L("Setting document name to \"doc name\".")); |
|
256 docName.Set(KTDocName); |
|
257 cmdLine->SetDocumentNameL(docName); |
|
258 break; |
|
259 case TEST_TAILEND: |
|
260 INFO_PRINTF1(_L("Setting tail end to \"tail end \".")); |
|
261 tailEnd.Set(KTTailEnd); |
|
262 cmdLine->SetTailEndL(tailEnd); |
|
263 break; |
|
264 case TEST_COMMAND: |
|
265 INFO_PRINTF1(_L("Setting tail end to \"command type \".")); |
|
266 cmdType=EApaCommandOpen;//any update to the command value |
|
267 cmdLine->SetCommandL(cmdType); |
|
268 break; |
|
269 case TEST_FILE_HANDLE: |
|
270 { |
|
271 INFO_PRINTF1(_L("Setting file handle name to \"handle name\".")); |
|
272 User::LeaveIfError(fSession.Connect()); |
|
273 User::LeaveIfError(fSession.ShareProtected()); |
|
274 INFO_PRINTF1(_L("Check for the existence of C:\\System\\Data Directory")); |
|
275 TInt ret = fSession.Entry(KTempDir,dirEntry); |
|
276 if(ret==KErrNotFound) |
|
277 { |
|
278 INFO_PRINTF1(_L("Create C:\\System\\Data Directory if not existing already")); |
|
279 fSession.MkDir(KTempDir); /* Created Data Directory as it does not exist */ |
|
280 } |
|
281 User::LeaveIfError(file.Replace(fSession, KTDocName, EFileStreamText|EFileShareAny)); |
|
282 TRAP(ret,cmdLine->SetFileByHandleL(file)); |
|
283 TEST(KErrNone==ret); |
|
284 break; |
|
285 } |
|
286 default: |
|
287 break; |
|
288 } |
|
289 |
|
290 INFO_PRINTF1(_L("The Get command line APIs are invoked and their return values are verified")); |
|
291 |
|
292 //Test the values returned by the Get Functions |
|
293 TEST(appName==cmdLine->ExecutableName()); |
|
294 TEST(docName==cmdLine->DocumentName()); |
|
295 TEST(tailEnd==cmdLine->TailEnd()); |
|
296 TEST(cmdType==cmdLine->Command()); |
|
297 |
|
298 RFile testFile; |
|
299 TRAPD(ret,cmdLine->GetFileByHandleL(testFile)); |
|
300 TEST(KErrNone==ret); |
|
301 if(KErrNone==ret) |
|
302 { //this test relies on TEST_FILE_HANDLE being the last case in the case statement |
|
303 if(index==TEST_FILE_HANDLE) |
|
304 {//not equal when initialised |
|
305 TEST(file.SubSessionHandle()!=testFile.SubSessionHandle()); |
|
306 } |
|
307 else |
|
308 {//equal when uninitialised |
|
309 TEST(file.SubSessionHandle()==testFile.SubSessionHandle()); |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 file.Close(); |
|
315 fSession.Close(); |
|
316 //fSession.Delete(KTDocName); |
|
317 CleanupStack::PopAndDestroy(cmdLine); |
|
318 |
|
319 } |
|
320 |
|
321 /** |
|
322 Auxiliary function for TestCaseID T-CmdlnStep-testSecureCmdLinesL |
|
323 |
|
324 @SYMPREQ 280 - File Handle Support |
|
325 |
|
326 Tests CApaCommandLine Apis. |
|
327 |
|
328 Tests the Boundary values of the member variables like Null descriptors and zero for integer member variables |
|
329 Also test negative values for the integer member variables |
|
330 |
|
331 CApaCommandLine::SetExecutableNameL(appName); |
|
332 CApaCommandLine::SetDocumentNameL(docName); |
|
333 CApaCommandLine::SetTailEndL(tailEnd); |
|
334 CApaCommandLine::SetCommandL(command); |
|
335 |
|
336 Compares the values set with those obtained by the GET APIs |
|
337 CApaCommandLine::ExecutableName()); |
|
338 CApaCommandLine::DocumentName()); |
|
339 CApaCommandLine::TailEnd()); |
|
340 CApaCommandLine::Command()); |
|
341 |
|
342 Following Scenarios are tested |
|
343 |
|
344 1. Set AppName,DocName and Tailend to Null descriptors and check the values returned by the corresponding |
|
345 GET APIs |
|
346 */ |
|
347 |
|
348 void CT_CmdlnStep::testBoundaryConditionsL() |
|
349 { |
|
350 |
|
351 TPtrC appName(KNullDesC); |
|
352 TPtrC docName(KNullDesC); |
|
353 TPtrC8 tailEnd; |
|
354 |
|
355 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); // start with an empty command line |
|
356 |
|
357 INFO_PRINTF1(_L("TEST APIS WITH BOUNDARY CONDITIONS\n")); |
|
358 |
|
359 //Set the member variables |
|
360 cmdLine->SetExecutableNameL(appName); |
|
361 cmdLine->SetDocumentNameL(docName); |
|
362 tailEnd.Set(KTNullTail); |
|
363 cmdLine->SetTailEndL(tailEnd); |
|
364 |
|
365 // Check the values returned by the Get Functions |
|
366 TEST(appName==cmdLine->ExecutableName()); |
|
367 TEST(docName==cmdLine->DocumentName()); |
|
368 TEST(tailEnd==cmdLine->TailEnd()); |
|
369 |
|
370 CleanupStack::PopAndDestroy(cmdLine); |
|
371 |
|
372 } |
|
373 |
|
374 /** |
|
375 Auxiliary function for TestCaseID T-CmdlnStep-testSecureCmdLinesL |
|
376 |
|
377 @SYMPREQ 280 - File Handle Support |
|
378 |
|
379 Tests CApaCommandLine Apis. |
|
380 |
|
381 The functions tests positive and negative test scenarios for API |
|
382 TInt RApaLsSession::StartDocument(const TDesC& aFileName, RFs& aFSession, RFile& aFile, TThreadId& aThreadId) |
|
383 |
|
384 The test case opens a document "temp.test" with datatype "test/plain" which is recognized by TESTREC. |
|
385 T_EnvSlots.exe is application mapped to the this data type using InsertDataMappingL function. |
|
386 When the file is opened using StartDocument the application is launched which verifies the environment slots |
|
387 of the launched application to those set. |
|
388 |
|
389 |
|
390 */ |
|
391 |
|
392 void CT_CmdlnStep::testRecAppLaunchL(RApaLsSession& aLs) |
|
393 { |
|
394 |
|
395 TThreadId startAppThreadID; |
|
396 RFs fSession; |
|
397 RFile file; |
|
398 TDataType dataType(KTDataType); |
|
399 TEntry dirEntry; |
|
400 |
|
401 User::LeaveIfError(fSession.Connect()); |
|
402 User::LeaveIfError(fSession.ShareProtected()); |
|
403 |
|
404 INFO_PRINTF1(_L("Check for the existence of C:\\System\\Data Directory")); |
|
405 TInt ret = fSession.Entry(KTempDir,dirEntry); |
|
406 |
|
407 if(ret==KErrNotFound) |
|
408 { |
|
409 INFO_PRINTF1(_L("Create C:\\System\\Data Directory if not existing already")); |
|
410 fSession.MkDir(KTempDir); /* Created Data Directory as it does not exist */ |
|
411 } |
|
412 |
|
413 User::LeaveIfError(file.Replace(fSession, KTDocName, EFileStreamText|EFileShareAny)); |
|
414 User::LeaveIfError(file.Write(KTWriteData)); |
|
415 |
|
416 //Create A Global mutex to control the access to the logfile |
|
417 |
|
418 RMutex fileAccess; |
|
419 fileAccess.CreateGlobal(KTLogFileAccess); |
|
420 |
|
421 INFO_PRINTF1(_L("Start Valid Document of Data type : test")); |
|
422 |
|
423 TUid uid; |
|
424 uid.iUid = (0x102032AB); |
|
425 ret = aLs.InsertDataMapping(dataType, KDataTypePriorityHigh, uid); |
|
426 TEST(ret==KErrNone); |
|
427 if(ret == KErrNone) |
|
428 { |
|
429 INFO_PRINTF1(_L("InsertDataMapping API call successful")); |
|
430 } |
|
431 else |
|
432 { |
|
433 INFO_PRINTF1(_L("InsertDataMapping API call failed")); |
|
434 } |
|
435 |
|
436 ret = aLs.StartDocument(file,startAppThreadID); |
|
437 TEST(ret==KErrNone); |
|
438 if(ret == KErrNone) |
|
439 { |
|
440 INFO_PRINTF1(_L("Start Document API call successful")); |
|
441 } |
|
442 else |
|
443 { |
|
444 INFO_PRINTF1(_L("Start Document API call failed")); |
|
445 } |
|
446 |
|
447 // Make the process sleep in order to launch T_EnvSlots |
|
448 User::After(KOneSecond); |
|
449 |
|
450 // Wait for the Mutex for log file access |
|
451 fileAccess.Wait(); |
|
452 TBufC<KMaxFilePath> filePath(KEnvFilePath); |
|
453 RFile logFile; |
|
454 |
|
455 INFO_PRINTF1(_L("File Access Mutex obtained")); |
|
456 |
|
457 //Open the logfile in the readmode |
|
458 User::LeaveIfError(logFile.Open(fSession,filePath,EFileRead)); |
|
459 |
|
460 INFO_PRINTF1(_L("Env Log File Open successful")); |
|
461 |
|
462 TBuf8<8> expected(KTPass); |
|
463 TBuf8<8> obtained; |
|
464 TBuf8<8> failReason; |
|
465 |
|
466 // Read from the logfile |
|
467 User::LeaveIfError(logFile.Read(obtained)); |
|
468 |
|
469 INFO_PRINTF1(_L("Env Log File Read successful")); |
|
470 |
|
471 TEST(expected==obtained); |
|
472 |
|
473 if(expected == obtained) |
|
474 { |
|
475 INFO_PRINTF1(_L("Environment slots verification Passed")); |
|
476 } |
|
477 else { |
|
478 // Read up to the end of the file to log all the failures |
|
479 do |
|
480 { |
|
481 // Read the environment slot whose verification failed |
|
482 logFile.Read(failReason); |
|
483 |
|
484 if(failReason == KTApp) |
|
485 { |
|
486 INFO_PRINTF1(_L("Environment slot verification failed for Application Name")); |
|
487 } |
|
488 else if(failReason == KTDoc) |
|
489 { |
|
490 INFO_PRINTF1(_L("Environment slot verification failed for Document Name")); |
|
491 } |
|
492 else if(failReason == KTServer) |
|
493 { |
|
494 INFO_PRINTF1(_L("Environment slot verification failed for Server Id")); |
|
495 } |
|
496 else if(failReason == KTCommand) |
|
497 { |
|
498 INFO_PRINTF1(_L("Environment slot verification failed for Command")); |
|
499 } |
|
500 |
|
501 // Skip the "TestFail" text |
|
502 logFile.Read(failReason); |
|
503 |
|
504 //Exit the loop if end of the file |
|
505 if(failReason.Length() == 0) |
|
506 break; |
|
507 |
|
508 } while(ETrue); |
|
509 } |
|
510 |
|
511 ret = aLs.DeleteDataMapping(dataType); |
|
512 TEST(ret==KErrNone); |
|
513 if(ret == KErrNone) |
|
514 { |
|
515 INFO_PRINTF1(_L("DeleteDataMapping API call successful")); |
|
516 } |
|
517 else |
|
518 { |
|
519 INFO_PRINTF1(_L("DeleteDataMapping API call failed")); |
|
520 } |
|
521 |
|
522 ret = aLs.StartDocument(file,startAppThreadID); |
|
523 TEST(ret==KErrNotFound); |
|
524 if(ret == KErrNotFound) |
|
525 { |
|
526 INFO_PRINTF1(_L("Start Document API call with expected failure successful")); |
|
527 } |
|
528 else |
|
529 { |
|
530 INFO_PRINTF1(_L("Start Document API call with expected failure failed")); |
|
531 } |
|
532 |
|
533 logFile.Close(); |
|
534 |
|
535 // Test on Invalid Document Name, Invalid File Session and Invalid File Args removed |
|
536 // This test was invalid & panics |
|
537 |
|
538 file.Close(); |
|
539 fSession.Close(); |
|
540 //fSession.Delete(KTDocName); |
|
541 fileAccess.Close(); |
|
542 |
|
543 } |
|
544 |
|
545 /** |
|
546 @SYMTestCaseID CT-CmdlnStep-testCmdLinesAPIsL() |
|
547 |
|
548 @SYMPREQ |
|
549 |
|
550 @SYMTestCaseDesc Command line APIs to be properly tested |
|
551 |
|
552 @SYMTestActions CApaCommandLine::NewLC() is called to create a commandline object;CApaCommandLineSetFileByHandleL() is called to set the file session and file handle; RProcess::Create is called to create a new process to launch the exe; |
|
553 CApaCommandLine::SetProcessEnvironmentL is called to initialise the parameters of the child process; CApaCommandLine::GetCommandLineFromProcessEnvironment is |
|
554 called by the child process to get the commandline object created by the parent process; In order to be able to read the file, CApaCommandLine::GetFileByHandleL is called by the child process |
|
555 to get the file handle created by the parent process. |
|
556 |
|
557 API Calls:static CApaCommandLine* NewLC(); |
|
558 void SetProcessEnvironmentL(RProcess& aProcess) const; |
|
559 static TInt GetCommandLineFromProcessEnvironment(CApaCommandLine*& aCommandLine); |
|
560 void SetFileByHandleL(const RFile& aFile); |
|
561 void GetFileByHandleL(RFile& aFile) const; |
|
562 |
|
563 @SYMTestExpectedResults Returns an integer value (99) if no exception occurs else return system wide errors. |
|
564 |
|
565 */ |
|
566 void CT_CmdlnStep::testCmdLinesAPIsL() |
|
567 { |
|
568 INFO_PRINTF1(_L("Start test testCmdLinesAPIsL ...")); |
|
569 RFs fs; |
|
570 RFile file; |
|
571 RProcess process; |
|
572 TInt ret(0); |
|
573 _LIT(KFileName, "z:\\system\\data\\one_byte.txt"); //the file to be read by the process |
|
574 _LIT(KExeName, "TCmdLineExe"); //exe that is created for this test case |
|
575 TRequestStatus status; |
|
576 |
|
577 ret = fs.Connect(); |
|
578 TEST(ret==KErrNone); |
|
579 CleanupClosePushL(fs); |
|
580 ret = fs.ShareProtected(); |
|
581 TEST(ret==KErrNone); |
|
582 ret = file.Open(fs, KFileName, EFileRead|EFileShareAny); //open for read |
|
583 TEST(ret==KErrNone); |
|
584 CleanupClosePushL(file); |
|
585 if(ret == KErrNone) |
|
586 { |
|
587 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); |
|
588 ret = process.Create(KExeName, KNullDesC); |
|
589 CleanupClosePushL(process); |
|
590 TEST(ret==KErrNone); |
|
591 if(ret==KErrNone) |
|
592 { |
|
593 TRAP(ret,cmdLine->SetFileByHandleL(file)); |
|
594 TEST(ret==KErrNone); |
|
595 if(ret==KErrNone) |
|
596 { |
|
597 TRAP(ret,cmdLine->SetProcessEnvironmentL(process)); |
|
598 TEST(ret==KErrNone); |
|
599 if(ret==KErrNone) |
|
600 { |
|
601 status = KRequestPending; |
|
602 process.Logon(status); |
|
603 process.Resume(); |
|
604 User::WaitForRequest(status); |
|
605 } |
|
606 TEST(status.Int()==KFileHandleTestPassed); |
|
607 } |
|
608 } |
|
609 |
|
610 CleanupStack::PopAndDestroy(&process); |
|
611 CleanupStack::PopAndDestroy(cmdLine); |
|
612 } |
|
613 CleanupStack::PopAndDestroy(2); |
|
614 TEST(ret==KErrNone); |
|
615 } |
|
616 |
|
617 |
|
618 |
|
619 CT_CmdlnStep::~CT_CmdlnStep() |
|
620 /** |
|
621 Destructor |
|
622 */ |
|
623 { |
|
624 } |
|
625 |
|
626 CT_CmdlnStep::CT_CmdlnStep() |
|
627 /** |
|
628 Constructor |
|
629 */ |
|
630 { |
|
631 // Call base class method to set up the human readable name for logging |
|
632 SetTestStepName(KT_CmdlnStep); |
|
633 } |
|
634 |
|
635 TVerdict CT_CmdlnStep::doTestStepPreambleL() |
|
636 /** |
|
637 @return - TVerdict code |
|
638 Override of base class virtual |
|
639 */ |
|
640 { |
|
641 SetTestStepResult(EPass); |
|
642 return TestStepResult(); |
|
643 } |
|
644 |
|
645 TVerdict CT_CmdlnStep::doTestStepPostambleL() |
|
646 /** |
|
647 @return - TVerdict code |
|
648 Override of base class virtual |
|
649 */ |
|
650 { |
|
651 return TestStepResult(); |
|
652 } |
|
653 |
|
654 |
|
655 // need to also test CApaCommandLine - SetServerNotRequiredL/SetServerRequiredL/ServerRequired |
|
656 |
|
657 TVerdict CT_CmdlnStep::doTestStepL() |
|
658 /** |
|
659 @return - TVerdict code |
|
660 Override of base class virtual |
|
661 */ |
|
662 { |
|
663 INFO_PRINTF1(_L("Test setting full command lines")); |
|
664 |
|
665 // run the testcode (inside an alloc heaven harness) |
|
666 |
|
667 __UHEAP_MARK; |
|
668 TRAPD(ret,testSecureCmdLinesL()); |
|
669 TEST(ret==KErrNone); |
|
670 |
|
671 TRAP(ret,testCmdLinesAPIsL()); |
|
672 TEST(ret==KErrNone); |
|
673 __UHEAP_MARKEND; |
|
674 |
|
675 INFO_PRINTF1(_L("Test completed!")); |
|
676 return TestStepResult(); |
|
677 } |
|
678 |
|
679 |