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