|
1 // Copyright (c) 2007-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Tests control panel Application Apparc base classes and utility functions to get application's data.\n |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include <f32file.h> |
|
26 #include <fbs.h> |
|
27 #include <s32std.h> |
|
28 #include <s32stor.h> |
|
29 #include <s32file.h> |
|
30 |
|
31 #include <apaid.h> |
|
32 #include "..\apparc\apadll.h" |
|
33 #include <apgaplst.h> |
|
34 #include <apgicnfl.h> |
|
35 #include <apgdoor.h> |
|
36 #include <apfrec.h> |
|
37 #include <apfctlf.h> |
|
38 #include <apgctl.h> |
|
39 #include <apgaplst.h> |
|
40 #include <apaflrec.h> |
|
41 #include <apgcli.h> |
|
42 #include <apacmdln.h> |
|
43 #include <apsserv.h> |
|
44 #include <appfwk_test_AppUi.h> |
|
45 |
|
46 #include "T_ControlPanelTest.h" |
|
47 #include "tstapp.h" |
|
48 #include <w32std.h> |
|
49 |
|
50 #if !defined(__E32TEST_H__) |
|
51 #include <e32test.h> |
|
52 #endif |
|
53 |
|
54 _LIT(KCompleted, "Completed."); |
|
55 |
|
56 |
|
57 _LIT(KRSCDIR,"C:\\Resource\\apps\\"); |
|
58 _LIT(KRSCREGDIR,"C:\\private\\10003a3f\\import\\apps\\"); |
|
59 _LIT(KNEWCTLPATH,"C:\\sys\\bin\\app_CTRL2.exe"); |
|
60 _LIT(KSRCRESOURCEPATH,"Z:\\private\\10003a3f\\import\\apps\\App_CTRL2_reg.Rsc"); |
|
61 _LIT(KDESTRESOURCEPATH,"C:\\private\\10003a3f\\import\\apps\\App_CTRL2_reg.Rsc"); |
|
62 |
|
63 LOCAL_D TInt SimulateKey(TAny*) |
|
64 { |
|
65 User::After(3000000); |
|
66 RWsSession session; |
|
67 User::LeaveIfError(session.Connect()); |
|
68 //control down |
|
69 TRawEvent rawEvent; |
|
70 |
|
71 rawEvent.Set(TRawEvent::EKeyDown,EStdKeyLeftCtrl); |
|
72 session.SimulateRawEvent(rawEvent); |
|
73 |
|
74 // e down |
|
75 rawEvent.Set(TRawEvent::EKeyDown,'E'); |
|
76 session.SimulateRawEvent(rawEvent); |
|
77 |
|
78 // e up |
|
79 rawEvent.Set(TRawEvent::EKeyUp,'E'); |
|
80 session.SimulateRawEvent(rawEvent); |
|
81 |
|
82 //control up |
|
83 rawEvent.Set(TRawEvent::EKeyUp,EStdKeyLeftCtrl); |
|
84 session.SimulateRawEvent(rawEvent); |
|
85 |
|
86 session.Flush(); |
|
87 |
|
88 session.Close(); |
|
89 |
|
90 return KErrNone; |
|
91 } |
|
92 |
|
93 void CT_ControlPanelTestStep::RemoveFilesFromCDrive() |
|
94 { |
|
95 TInt ret = iTestServ.SetReadOnly(KDESTRESOURCEPATH,0); //remove READ ONLY option |
|
96 TEST(ret==KErrNone); |
|
97 |
|
98 TRAP(ret,iTestServ.DeleteFileL(KDESTRESOURCEPATH)); |
|
99 TEST(ret==KErrNone); |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 /** |
|
105 Auxiliary Fn for Test Case ID T-ControlPanelStep-testControls1L, |
|
106 T-ControlPanelStep-testControls2L, T-ControlPanelStep-testControls3L |
|
107 |
|
108 The method finds the index of control app_ctrl2.exe in the control list. |
|
109 Depending on the Boolean value of argument aIsNewPath the search is |
|
110 done on ROM / RAM.\n |
|
111 |
|
112 */ |
|
113 |
|
114 TInt CT_ControlPanelTestStep::ControlIndexInList(CApaSystemControlList* aList, TBool aIsNewPath) |
|
115 { |
|
116 TFileName ctlPath=_L("Z:\\sys\\bin\\app_CTRL2.exe"); |
|
117 TFileName newCtlPath=_L("c:\\sys\\bin\\app_ctrl2.exe"); |
|
118 const TInt count = aList->Count(); |
|
119 TInt retVal = KErrNotFound; |
|
120 for(TInt ii = 0; ii < count; ++ii) |
|
121 { |
|
122 if(((aList->Control(ii)->FileName().CompareF(ctlPath)==0) && (!aIsNewPath)) || |
|
123 ((aList->Control(ii)->FileName().CompareF(newCtlPath)==0) && (aIsNewPath))) |
|
124 { |
|
125 retVal = ii; |
|
126 |
|
127 |
|
128 if(aList->Control(ii)->FileName().CompareF(ctlPath)==0) |
|
129 { |
|
130 INFO_PRINTF1(_L("***Found control on the z: drive")); |
|
131 } |
|
132 else |
|
133 { |
|
134 INFO_PRINTF1(_L("***Found control on the c: drive")); |
|
135 } |
|
136 break; |
|
137 } |
|
138 } |
|
139 INFO_PRINTF2(_L("Out [%d] controlIndexInList"),retVal); |
|
140 return retVal; |
|
141 } |
|
142 |
|
143 |
|
144 /** |
|
145 @SYMTestCaseID T-ControlPanelStep-testControls1L |
|
146 |
|
147 @SYMPREQ |
|
148 |
|
149 @SYMTestCaseDesc Tests CApaSystemControlList::UpdateL(). |
|
150 |
|
151 @SYMTestPriority High |
|
152 |
|
153 @SYMTestStatus Implemented |
|
154 |
|
155 @SYMTestActions Check the control list to find the number of controls in the |
|
156 list and the number of updates to the list. Call UpdateL(). Check the list |
|
157 again for no change in the count of controls and updates to the list.\n |
|
158 API Calls:\n |
|
159 CApaSystemControlList::UpdateL()\n |
|
160 |
|
161 @SYMTestExpectedResults Test confirms that there is no change in the control |
|
162 list after updating. |
|
163 */ |
|
164 void CT_ControlPanelTestStep::testControls1L() |
|
165 { |
|
166 INFO_PRINTF1(_L("In testControls1L......")); |
|
167 |
|
168 iControlCount1 = iControlList->Count(); |
|
169 TEST((iControlCount1>=1)); |
|
170 |
|
171 TEST((iControlList->UpdateCount()>=1));//update count returns 1 if new list |
|
172 // |
|
173 // do an update - there should be no changes |
|
174 TInt ret; |
|
175 INFO_PRINTF1(_L("Updating the list ......")); |
|
176 TRAP(ret, iControlList->UpdateL()); |
|
177 TEST(ret==KErrNone); |
|
178 iControlCount2 = iControlList->Count(); |
|
179 TEST(iControlCount2 == iControlCount1); |
|
180 TEST((iControlList->UpdateCount()>=1)); |
|
181 iIndex = ControlIndexInList(iControlList,EFalse); |
|
182 TEST((iIndex >= 0) && (iIndex < iControlCount2)); |
|
183 |
|
184 INFO_PRINTF1(_L("Out testControls1L......")); |
|
185 } |
|
186 |
|
187 |
|
188 /** |
|
189 @SYMTestCaseID T-ControlPanelStep-testControls2L |
|
190 |
|
191 @SYMPREQ |
|
192 |
|
193 @SYMTestCaseDesc Tests CApaSystemControlList::UpdateL() and UpdateCount(). |
|
194 |
|
195 @SYMTestPriority High |
|
196 |
|
197 @SYMTestStatus Implemented |
|
198 |
|
199 @SYMTestActions Copy control from Z: drive to C: drive. Call UpdateL() to |
|
200 update the control list. Check if UpdateL() has incremented iUpdateCount |
|
201 by calling UpdateCount(). Check the filename of control to ensure that the |
|
202 control copied to C: drive has been updated in the list. Delete the newly |
|
203 copied control.\n |
|
204 API Calls:\n |
|
205 CApaSystemControlList::UpdateL()\n |
|
206 CApaSystemControlList::UpdateCount()const\n |
|
207 |
|
208 @SYMTestExpectedResults The test shows updating of the copied control in control list. |
|
209 */ |
|
210 |
|
211 void CT_ControlPanelTestStep::testControls2L() |
|
212 { |
|
213 INFO_PRINTF1(_L("In testControls2L......")); |
|
214 |
|
215 iTestServ.CreateDirectoryL(KRSCDIR); |
|
216 iTestServ.CreateDirectoryL(KRSCREGDIR); |
|
217 |
|
218 TInt ret=iTestServ.CopyFileL(KSRCRESOURCEPATH,KDESTRESOURCEPATH); |
|
219 TEST(ret==KErrNone); |
|
220 |
|
221 INFO_PRINTF1(_L("Files Copied to C Drive......")); |
|
222 INFO_PRINTF1(_L("Updating the list ......")); |
|
223 iControlCount=iControlList->UpdateCount(); |
|
224 while(iControlList->UpdateCount()<=iControlCount) |
|
225 { |
|
226 TRAP(ret, iControlList->UpdateL()); |
|
227 if(ret!=KErrNone) |
|
228 { |
|
229 break; |
|
230 } |
|
231 User::After(100000); |
|
232 } |
|
233 |
|
234 INFO_PRINTF2(_L("In testControls2L After Controllist update [%d]......"),ret); |
|
235 TEST(ret==KErrNone); |
|
236 iControlCount3 = iControlList->Count(); |
|
237 TEST(iControlCount3 == iControlCount1); |
|
238 TEST((iControlList->UpdateCount()>=2)); |
|
239 iIndex = ControlIndexInList(iControlList,ETrue); |
|
240 TEST((iIndex >= 0) && (iIndex < iControlCount3)); |
|
241 |
|
242 TFileName name=iControlList->Control(iIndex)->FileName(); |
|
243 TEST(name.CompareF(KNEWCTLPATH)==0); |
|
244 RemoveFilesFromCDrive(); |
|
245 INFO_PRINTF1(_L("Removed the file from C Drive......")); |
|
246 INFO_PRINTF1(_L("Updating the list ......")); |
|
247 iControlCount=iControlList->UpdateCount(); |
|
248 while(iControlList->UpdateCount()<=iControlCount) |
|
249 { |
|
250 TRAPD(ret, iControlList->UpdateL()); |
|
251 if(ret!=KErrNone) |
|
252 { |
|
253 break; |
|
254 } |
|
255 User::After(100000); |
|
256 } |
|
257 INFO_PRINTF1(_L("Out testControls2L......")); |
|
258 } |
|
259 |
|
260 /** |
|
261 @SYMTestCaseID T-ControlPanelStep-testControls3L |
|
262 |
|
263 @SYMPREQ |
|
264 |
|
265 @SYMTestCaseDesc Tests CApaSystemControlList::Control() and CApaSystemControl APIs Type() and Caption(). |
|
266 |
|
267 @SYMTestPriority High |
|
268 |
|
269 @SYMTestStatus Implemented |
|
270 |
|
271 @SYMTestActions Update the control list to ensure that the deleted control is |
|
272 removed from the list and the control on the Z: Drive is added to the list. |
|
273 Retrieve this control from the list using CApaSystemControlList::Control(). |
|
274 Check the type and caption of the control calling Type() and Caption() methods.\n |
|
275 API Calls:\n |
|
276 CApaSystemControlList::Control(TInt aIndex)const\n |
|
277 CApaSystemControl::Type()const\n |
|
278 CApaSystemControl::Caption()const\n |
|
279 |
|
280 @SYMTestExpectedResults The test shows the addition of the control present on |
|
281 Z: drive in control list. Test confirms the retrieved info on the control |
|
282 obtained from the control list. |
|
283 |
|
284 */ |
|
285 void CT_ControlPanelTestStep::testControls3L() |
|
286 { |
|
287 INFO_PRINTF1(_L("In testControls3L......")); |
|
288 TFileName ctlPath=_L("Z:\\sys\\bin\\app_ctrl2.exe"); |
|
289 TFileName ctlCaption=_L("app_ctrl2"); |
|
290 // This method is called to close the panic dialog generated by previous test |
|
291 CloseAllPanicWindowsL(); |
|
292 |
|
293 INFO_PRINTF1(_L("IN testControls3L Before Updating the list......")); |
|
294 TRAPD(ret, iControlList->UpdateL()); |
|
295 |
|
296 TEST(ret==KErrNone); |
|
297 const TInt controlCount4 = iControlList->Count(); |
|
298 TEST(controlCount4 == iControlCount1); // no changes in the count |
|
299 TEST((iControlList->UpdateCount()>=3)); |
|
300 |
|
301 iIndex = ControlIndexInList(iControlList,EFalse); |
|
302 TEST((iIndex >= 0) && (iIndex < controlCount4)); |
|
303 TEST(iControlList->Control(iIndex)->FileName().CompareF(ctlPath)==0); |
|
304 |
|
305 INFO_PRINTF1(_L("Testing CApaSystemControl")); |
|
306 // |
|
307 //get the control from the list and check it's type and caption |
|
308 iControl=iControlList->Control(iIndex); |
|
309 TEST(iControl!=NULL); |
|
310 TFileName caption=iControl->Caption(); |
|
311 TEST(caption.CompareF(ctlCaption)==0); |
|
312 TEST(iControl->Icon()!=NULL); |
|
313 |
|
314 RThread thread; |
|
315 TFullName name=_L("Control Panel Test"); |
|
316 TInt r=thread.Create(name,SimulateKey,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,NULL); |
|
317 TEST(r==KErrNone); |
|
318 thread.Resume(); |
|
319 |
|
320 // run the control |
|
321 TRAP(ret, iControl->CreateL()); // this call is synchronous |
|
322 TEST(ret==KErrNone); |
|
323 |
|
324 thread.Close(); |
|
325 INFO_PRINTF1(_L("Out testControls3L......")); |
|
326 } |
|
327 |
|
328 |
|
329 |
|
330 /** |
|
331 Auxiliary Fn for T-ControlPanelStep-testControls1L, T-ControlPanelStep-testControls2L, T-ControlPanelStep-testControls3L |
|
332 |
|
333 This method creates a control list by calling CApaSystemControlList::NewL() and |
|
334 initiates subsequent tests on CApaSystemControlList and CApaSystemControl APIs. |
|
335 |
|
336 */ |
|
337 void CT_ControlPanelTestStep::testControlsL() |
|
338 { |
|
339 INFO_PRINTF1(_L("Testing CApaSystemControlList")); |
|
340 |
|
341 //Create a session with F & B server |
|
342 TInt ret=RFbsSession::Connect(); |
|
343 TEST(!ret); |
|
344 |
|
345 TRAP(ret,iControlList=CApaSystemControlList::NewL(iFs)); |
|
346 TEST(ret==KErrNone); |
|
347 |
|
348 TRAPD(err,testControls1L()); |
|
349 TRAP(err,testControls2L()); |
|
350 TRAP(err,testControls3L()); |
|
351 |
|
352 delete iControlList; |
|
353 |
|
354 //Close the session F & B server. |
|
355 RFbsSession::Disconnect(); |
|
356 } |
|
357 |
|
358 |
|
359 /** |
|
360 Auxiliary Fn for all Test Cases. |
|
361 |
|
362 This method creates and installs an active scheduler and puts the |
|
363 test code on the scheduler as a CIdle object. The method initiates |
|
364 all tests by calling the static method CT_ControlPanelTestCallBack::CallBack(). |
|
365 |
|
366 */ |
|
367 void CT_ControlPanelTestStep::DoStepTestsInCallbackL() |
|
368 { |
|
369 // create an active scheduler |
|
370 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
371 CActiveScheduler::Install(scheduler); |
|
372 CleanupStack::PushL(scheduler); |
|
373 |
|
374 // put the test code onto the scheduler as an idle object |
|
375 CIdle* idle=CIdle::NewL(-20); |
|
376 CleanupStack::PushL(idle); |
|
377 |
|
378 CT_ControlPanelTestCallBack* callBack = new(ELeave) CT_ControlPanelTestCallBack(this); |
|
379 CleanupStack::PushL(callBack); |
|
380 |
|
381 idle->Start(TCallBack(CT_ControlPanelTestCallBack::CallBack,callBack)); |
|
382 // start the test code |
|
383 CActiveScheduler::Start(); |
|
384 |
|
385 // all outstanding requests complete - kill the scheduler |
|
386 CleanupStack::PopAndDestroy(3); //scheduler, callBack, idle |
|
387 } |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 /** |
|
393 Auxiliary Fn for all Test Cases. |
|
394 |
|
395 The method initiates all tests to be performed. |
|
396 |
|
397 */ |
|
398 void CT_ControlPanelTestStep::DoStepTests() |
|
399 { |
|
400 __UHEAP_MARK; |
|
401 INFO_PRINTF1(_L("Test Controls......")); |
|
402 TRAPD(r,testControlsL()); |
|
403 TEST(r==KErrNone); |
|
404 INFO_PRINTF1(KCompleted); |
|
405 __UHEAP_MARKEND; |
|
406 } |
|
407 |
|
408 |
|
409 CT_ControlPanelTestStep::~CT_ControlPanelTestStep() |
|
410 /** |
|
411 Destructor |
|
412 */ |
|
413 { |
|
414 } |
|
415 |
|
416 CT_ControlPanelTestStep::CT_ControlPanelTestStep() |
|
417 /** |
|
418 Constructor |
|
419 */ |
|
420 { |
|
421 // Call base class method to set up the human readable name for logging |
|
422 SetTestStepName(KT_ControlPanelTest); |
|
423 } |
|
424 |
|
425 TVerdict CT_ControlPanelTestStep::doTestStepPreambleL() |
|
426 /** |
|
427 @return - TVerdict code |
|
428 Override of base class virtual |
|
429 */ |
|
430 { |
|
431 SetTestStepResult(EPass); |
|
432 return TestStepResult(); |
|
433 } |
|
434 |
|
435 TVerdict CT_ControlPanelTestStep::doTestStepPostambleL() |
|
436 /** |
|
437 @return - TVerdict code |
|
438 Override of base class virtual |
|
439 */ |
|
440 { |
|
441 return TestStepResult(); |
|
442 } |
|
443 |
|
444 |
|
445 TVerdict CT_ControlPanelTestStep::doTestStepL() |
|
446 /** |
|
447 @return - TVerdict code |
|
448 Override of base class virtual |
|
449 */ |
|
450 { |
|
451 INFO_PRINTF1(_L("Testing Apparc ...T_ControlPanel")); |
|
452 |
|
453 // set up the directory structure |
|
454 User::LeaveIfError(iFs.Connect()); |
|
455 |
|
456 // connect to the test utils server |
|
457 User::LeaveIfError(iTestServ.Connect()); |
|
458 |
|
459 // Run the tests...w |
|
460 TRAPD(ret,DoStepTestsInCallbackL()) |
|
461 TEST(ret==KErrNone); |
|
462 |
|
463 // Close everything |
|
464 iFs.Close(); |
|
465 iTestServ.Close(); |
|
466 |
|
467 INFO_PRINTF1(_L("T_ControlPanel Completed.")); |
|
468 return TestStepResult(); |
|
469 } |
|
470 |
|
471 |
|
472 TInt CT_ControlPanelTestCallBack::CallBack(TAny* callBack /*aThis*/) |
|
473 /** |
|
474 This static method is the callback function of CIdle object. The method |
|
475 calls the non-static method DoStepTests() which initiates all the tests. |
|
476 */ |
|
477 { |
|
478 |
|
479 //Call Test Step func |
|
480 |
|
481 ((CT_ControlPanelTestCallBack *)callBack)->iTestStep->DoStepTests(); |
|
482 |
|
483 CActiveScheduler::Stop(); |
|
484 return EFalse; // don't call back again |
|
485 } |
|
486 |
|
487 |
|
488 CT_ControlPanelTestCallBack::CT_ControlPanelTestCallBack(CT_ControlPanelTestStep* aTestStep) |
|
489 /** |
|
490 Constructor |
|
491 */ |
|
492 { |
|
493 iTestStep = aTestStep; |
|
494 } |
|
495 |
|
496 CT_ControlPanelTestCallBack::~CT_ControlPanelTestCallBack() |
|
497 /** |
|
498 Destructor |
|
499 */ |
|
500 { |
|
501 |
|
502 } |