|
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 adds a control factory function and resource file to the application.\n |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent - Internal Symbian test code |
|
21 */ |
|
22 |
|
23 #include <basched.h> |
|
24 #include <eikenv.h> |
|
25 #include <eikappui.h> |
|
26 #include <techview/eikon.hrh> |
|
27 #include <eikapp.h> |
|
28 #include <eikdoc.h> |
|
29 #include <techview/eiklabel.h> |
|
30 #include <eikfctry.h> |
|
31 #include <coecntrl.h> |
|
32 #include <barsread.h> |
|
33 #include "TADDLIB.HRH" |
|
34 #include <external.rsg> |
|
35 #include <techview/eiktbar.h> |
|
36 #include <techview/eikmenub.h> |
|
37 #include <eikspane.h> |
|
38 #include <ecom/ecom.h> |
|
39 |
|
40 |
|
41 _LIT(KTAddLibResourceFilePath, ""); |
|
42 |
|
43 #include "Taddlib.h" |
|
44 |
|
45 /** |
|
46 Auxiliary function for refreshing Label |
|
47 |
|
48 This method is an override from CEikLabel. It draws the label control. |
|
49 |
|
50 */ |
|
51 void CTestLabel::Draw(const TRect& aRect) const |
|
52 { |
|
53 CWindowGc& gc=SystemGc(); |
|
54 gc.SetPenColor(KRgbBlack); |
|
55 CEikLabel::Draw(aRect); |
|
56 } |
|
57 |
|
58 |
|
59 CTestContainer::CTestContainer(CTestAppUi* aAppUi) |
|
60 : iResourceFile(_L("z:\\system\\test\\taddlib\\external.rsc")), |
|
61 iAppUi(aAppUi) |
|
62 /** |
|
63 Constructor |
|
64 */ |
|
65 { |
|
66 } |
|
67 |
|
68 void CTestContainer::ConstructL(const TRect& aRect) |
|
69 { |
|
70 CreateWindowL(); |
|
71 Window().SetShadowDisabled(ETrue); |
|
72 Window().SetBackgroundColor(KRgbWhite); |
|
73 SetRect(aRect); |
|
74 |
|
75 ActivateL(); |
|
76 } |
|
77 |
|
78 /** |
|
79 @SYMTestCaseID UIF-AddLib-AddLibraryL |
|
80 |
|
81 @SYMPREQ |
|
82 |
|
83 @SYMTestCaseDesc Tests CEikonEnv::AddLibraryL() method. |
|
84 |
|
85 @SYMTestPriority High |
|
86 |
|
87 @SYMTestStatus Implemented |
|
88 |
|
89 @SYMTestActions The test case tests whether the specified control factory |
|
90 function and resource file are added to their respective lists by |
|
91 CEikonEnv::AddLibraryL(). The method verifies this by checking whether |
|
92 CEikonEnv::AddLibraryL() returns a non-zero value for the resource file |
|
93 offset indicating successful addition.\n |
|
94 API Calls:\n |
|
95 TInt CEikonEnv::AddLibraryL(TCreateByTypeFunction aControlFactory, TFileName* aResourceFile)\n |
|
96 |
|
97 @SYMTestExpectedResults On successful addition of the specified control |
|
98 factory function and resource file, CEikonEnv::AddLibraryL() should |
|
99 return a non-zero value. |
|
100 |
|
101 */ |
|
102 void CTestContainer::AddLibraryL() |
|
103 { |
|
104 if(iResFileOffset) |
|
105 { |
|
106 iEikonEnv->InfoMsg(_L("Library already added!")); |
|
107 return; |
|
108 } |
|
109 iAppUi->INFO_PRINTF1(_L("ADD LOCAL CONTROL FACTORY AND RESOURCE FILE TO THE EIKON ENVIRONMENT")); |
|
110 iResFileOffset = iEikonEnv->AddLibraryL(CreateByTypeL, &iResourceFile); |
|
111 iAppUi->TEST(iResFileOffset >= 0); |
|
112 iEikonEnv->InfoMsg(_L("Library added.")); |
|
113 } |
|
114 |
|
115 |
|
116 /** |
|
117 @SYMTestCaseID UIF-AddLib_RemoveLibrary |
|
118 |
|
119 @SYMPREQ |
|
120 |
|
121 @SYMTestCaseDesc Tests CEikonEnv::RemoveLibrary() method. |
|
122 |
|
123 @SYMTestPriority High |
|
124 |
|
125 @SYMTestStatus Implemented |
|
126 |
|
127 @SYMTestActions The test case tests whether the specified control factory |
|
128 function and the resource file identified by the resource file offset |
|
129 specified as parameters are removed from their respective lists by |
|
130 CEikonEnv::RemoveLibrary().\n |
|
131 API Calls:\n |
|
132 void CEikonEnv::RemoveLibrary(TCreateByTypeFunction aControlFactory, TInt aResourceFileOffset)\n |
|
133 |
|
134 @SYMTestExpectedResults The test removes the control factory function |
|
135 and the resource file which was previously added. |
|
136 |
|
137 */ |
|
138 void CTestContainer::RemoveLibrary() |
|
139 { |
|
140 if(!iResFileOffset) |
|
141 { |
|
142 iEikonEnv->InfoMsg(_L("No library to remove.")); |
|
143 return; |
|
144 } |
|
145 iAppUi->INFO_PRINTF1(_L("FREE UP THE CONTROL FACTORY AND RESOURCE FILE MEMORY FROM EIKENV")); |
|
146 iEikonEnv->RemoveLibrary(CreateByTypeL, iResFileOffset); |
|
147 delete iLabel; |
|
148 iLabel = NULL; |
|
149 iResFileOffset = 0; |
|
150 iEikonEnv->InfoMsg(_L("Library removed.")); |
|
151 DrawNow(); |
|
152 } |
|
153 |
|
154 /** |
|
155 Auxiliary function for TestCaseID T-AddLib-RunL |
|
156 |
|
157 This method is used by CTestContainer::RunL() to create the applications |
|
158 control. This method calls the control factory function |
|
159 CTestContainer::CreateByTypeL() to create the control. The method then uses |
|
160 Cone to construct the control by reading information from the resource |
|
161 file that was added. |
|
162 |
|
163 */ |
|
164 TBool CTestContainer::CreateControlL() |
|
165 { |
|
166 TBool ret = EFalse; |
|
167 if(!iLabel) |
|
168 { |
|
169 iAppUi->INFO_PRINTF1(_L("ASK THE EIKON CONTROL FACTORY TO CREATE THIS APPLICATION'S CONTROL\n")); |
|
170 SEikControlInfo controlInfo = EikControlFactory::CreateByTypeL(ECtTestLabel); |
|
171 if(controlInfo.iControl) |
|
172 { |
|
173 iAppUi->INFO_PRINTF1(_L("Control successfully created\n")); |
|
174 iLabel = STATIC_CAST(CTestLabel*, controlInfo.iControl); |
|
175 iAppUi -> TEST(iLabel != NULL); |
|
176 |
|
177 iLabel->SetContainerWindowL(*this); |
|
178 iLabel->SetControlContext(iLabel); |
|
179 |
|
180 iAppUi->INFO_PRINTF1(_L("ASK CONE TO CONSTRUCT THIS APPLICATION'S CONTROL FROM THE LOCAL RESOURCE FILE\n")); |
|
181 |
|
182 TResourceReader reader; |
|
183 iCoeEnv->CreateResourceReaderLC(reader,R_TESTADDLIB_LABEL); |
|
184 iLabel->ConstructFromResourceL(reader); |
|
185 CleanupStack::PopAndDestroy(); |
|
186 iLabel->SetRect(TRect(TPoint(260,110),iLabel->MinimumSize())); |
|
187 iLabel->ActivateL(); |
|
188 ret = ETrue; |
|
189 } |
|
190 } |
|
191 // Control already created |
|
192 else ret = ETrue; |
|
193 |
|
194 return ret; |
|
195 } |
|
196 |
|
197 /** |
|
198 @SYMTestCaseID UIF-AddLib-RunL |
|
199 |
|
200 @SYMPREQ |
|
201 |
|
202 @SYMTestCaseDesc Tests Creation of Applications Control. |
|
203 |
|
204 @SYMTestPriority High |
|
205 |
|
206 @SYMTestStatus Implemented |
|
207 |
|
208 @SYMTestActions The test initiates creation of applications control and |
|
209 draws it on the container. \n |
|
210 |
|
211 @SYMTestExpectedResults The test should create controls by reading |
|
212 information from the resource file and should display them. |
|
213 |
|
214 */ |
|
215 void CTestContainer::RunL() |
|
216 { |
|
217 if(CreateControlL()) |
|
218 DrawNow(); |
|
219 else iEikonEnv->InfoMsg(_L("Must add library first!")); |
|
220 } |
|
221 |
|
222 |
|
223 CTestContainer::~CTestContainer() |
|
224 /** |
|
225 Destructor |
|
226 */ |
|
227 { |
|
228 delete iLabel; |
|
229 } |
|
230 |
|
231 /** |
|
232 Auxiliary function for TestCaseID T-AddLib-RunL |
|
233 |
|
234 This method is an override from CCoeControl. It returns the number of |
|
235 controls contained in a compound control. |
|
236 |
|
237 */ |
|
238 TInt CTestContainer::CountComponentControls() const |
|
239 { |
|
240 if(iLabel) |
|
241 return 1; |
|
242 else |
|
243 return 0; |
|
244 } |
|
245 |
|
246 /** |
|
247 Auxiliary function for TestCaseID T-AddLib-RunL |
|
248 |
|
249 This method is an override from CCoeControl. It returns the label component |
|
250 from the container control. |
|
251 |
|
252 */ |
|
253 CCoeControl* CTestContainer::ComponentControl(TInt aIndex) const |
|
254 { |
|
255 switch (aIndex) |
|
256 { |
|
257 case 0: |
|
258 default: |
|
259 return iLabel; |
|
260 } |
|
261 } |
|
262 |
|
263 /** |
|
264 Auxiliary function for refreshing Container |
|
265 |
|
266 This method is an override from CCoeControl. It draws the container control. |
|
267 |
|
268 */ |
|
269 void CTestContainer::Draw(const TRect& aRect) const |
|
270 { |
|
271 CWindowGc& gc=SystemGc(); |
|
272 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
273 gc.SetBrushColor(KRgbGray); |
|
274 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
275 gc.SetPenColor(KRgbWhite); |
|
276 gc.DrawRect(aRect); |
|
277 } |
|
278 |
|
279 /** |
|
280 Auxiliary function for TestCaseID T-AddLib-RunL |
|
281 |
|
282 This method is the control factory function for this Application. |
|
283 It is called by CTestContainer::CreateControlL() to create label control. |
|
284 The method returns the structure SEikControlInfo which contains the |
|
285 control information for the control. |
|
286 |
|
287 */ |
|
288 SEikControlInfo CTestContainer::CreateByTypeL(TInt aControlType) |
|
289 { |
|
290 SEikControlInfo controlInfo; |
|
291 controlInfo.iControl = NULL; |
|
292 controlInfo.iTrailerTextId = 0; |
|
293 controlInfo.iFlags = 0; |
|
294 |
|
295 switch (aControlType) |
|
296 { |
|
297 case ECtTestLabel: |
|
298 controlInfo.iControl = new(ELeave) CTestLabel; |
|
299 break; |
|
300 } |
|
301 return controlInfo; |
|
302 } |
|
303 |
|
304 |
|
305 |
|
306 CTestAddLibraryAppUi::CTestAddLibraryAppUi(CTmsTestStep* aStep, const TDesC& aRes) : |
|
307 CTestAppUi( aStep, aRes) |
|
308 /** |
|
309 Constructor |
|
310 */ |
|
311 { |
|
312 } |
|
313 |
|
314 |
|
315 CTestAddLibraryAppUi::~CTestAddLibraryAppUi() |
|
316 /** |
|
317 Destructor |
|
318 */ |
|
319 { |
|
320 RemoveFromStack(iContainer); |
|
321 delete iContainer; |
|
322 |
|
323 } |
|
324 |
|
325 |
|
326 /** |
|
327 Auxiliary function for all Test Cases |
|
328 |
|
329 The method creates a container and sets active object with lowest |
|
330 priority for running test in auto mode. |
|
331 |
|
332 */ |
|
333 void CTestAddLibraryAppUi::ConstructL() |
|
334 { |
|
335 CTestAppUi::ConstructL(); |
|
336 |
|
337 TRect boundingRect=ClientRect(); // make toolband stretch to the screen width by default |
|
338 iContainer=new(ELeave) CTestContainer(this); |
|
339 |
|
340 ReduceRect(boundingRect); |
|
341 iContainer->ConstructL(boundingRect); |
|
342 AddToStackL(iContainer); |
|
343 |
|
344 AutoTestManager().StartAutoTest(); |
|
345 } |
|
346 |
|
347 |
|
348 /** |
|
349 Auxiliary function for all Test Cases |
|
350 |
|
351 The method is an override from CTestAppUi. The method initiates all tests |
|
352 to be performed by calling CTestAddLibraryAppUi::HandleCommandL(). |
|
353 |
|
354 */ |
|
355 void CTestAddLibraryAppUi::RunTestStepL(TInt aStep) |
|
356 { |
|
357 TInt theProgramState = 0; |
|
358 |
|
359 //#ifdef FORCE_AUTO |
|
360 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
361 //#endif |
|
362 switch (aStep) |
|
363 { |
|
364 case 1: |
|
365 INFO_PRINTF1(_L("Adding library\n")); |
|
366 SetTestStepID(_L("UIF-AddLib-AddLibraryL")); |
|
367 theProgramState = ECmdAddLibrary; |
|
368 RecordTestResultL(); |
|
369 break; |
|
370 case 2: |
|
371 INFO_PRINTF1(_L("Run library\n")); |
|
372 SetTestStepID(_L("UIF-AddLib-RunL")); |
|
373 theProgramState = ECmdRun; |
|
374 RecordTestResultL(); |
|
375 break; |
|
376 case 3: |
|
377 INFO_PRINTF1(_L("Removing library\n")); |
|
378 SetTestStepID(_L("UIF-AddLib_RemoveLibrary")); |
|
379 theProgramState = ECmdRemoveLibrary; |
|
380 RecordTestResultL(); |
|
381 CloseTMSGraphicsStep(); |
|
382 break; |
|
383 case 5: |
|
384 theProgramState = EEikCmdExit; |
|
385 break; |
|
386 } |
|
387 HandleCommandL(theProgramState); |
|
388 } |
|
389 |
|
390 |
|
391 |
|
392 /** |
|
393 Auxiliary function for all Test Cases |
|
394 |
|
395 This method is called by CTestAddLibraryAppUi::RunTestStepL() to initiate |
|
396 the tests. |
|
397 |
|
398 */ |
|
399 void CTestAddLibraryAppUi::HandleCommandL(TInt aCommand) |
|
400 { |
|
401 |
|
402 switch (aCommand) |
|
403 { |
|
404 case ECmdAddLibrary: |
|
405 if(iContainer) |
|
406 { |
|
407 iContainer->AddLibraryL(); |
|
408 } |
|
409 break; |
|
410 case ECmdRemoveLibrary: |
|
411 if(iContainer) |
|
412 { |
|
413 iContainer->RemoveLibrary(); |
|
414 } |
|
415 break; |
|
416 case ECmdRun: |
|
417 if(iContainer) |
|
418 { |
|
419 iContainer->RunL(); |
|
420 } |
|
421 break; |
|
422 case EEikCmdExit: |
|
423 if(iContainer) |
|
424 { |
|
425 iContainer->RemoveLibrary(); |
|
426 iCoeEnv->Flush(); |
|
427 } |
|
428 Exit(); |
|
429 break; |
|
430 } |
|
431 } |
|
432 |
|
433 |
|
434 //---------- |
|
435 |
|
436 CTestAddLibraryStep::CTestAddLibraryStep() |
|
437 /** |
|
438 Constructor |
|
439 */ |
|
440 { |
|
441 SetTestStepName(KTestAddLibraryStep); |
|
442 } |
|
443 |
|
444 CTestAddLibraryStep::~CTestAddLibraryStep() |
|
445 /** |
|
446 Destructor |
|
447 */ |
|
448 { |
|
449 } |
|
450 |
|
451 /** |
|
452 Auxiliary function for all Test Cases |
|
453 |
|
454 The method creates & sets the application's user interface object. |
|
455 |
|
456 */ |
|
457 void CTestAddLibraryStep::ConstructAppL(CEikonEnv* aCoe) |
|
458 { // runs inside a TRAP harness |
|
459 aCoe->ConstructL(); |
|
460 |
|
461 CTestAppUi* appUi= new (ELeave) CTestAddLibraryAppUi(this,KTAddLibResourceFilePath); |
|
462 aCoe->SetAppUi(appUi); |
|
463 appUi->ConstructL(); |
|
464 } |
|
465 |
|
466 /** |
|
467 Auxiliary function for all Test Cases |
|
468 |
|
469 The method creates & sets the application's user interface object to |
|
470 launch the application which will initiate the tests. |
|
471 |
|
472 */ |
|
473 TVerdict CTestAddLibraryStep::doTestStepL() // main function called by E32 |
|
474 { |
|
475 PreallocateHALBuffer(); |
|
476 __UHEAP_MARK; |
|
477 |
|
478 CEikonEnv* coe=new CEikonEnv; |
|
479 TRAPD(err,ConstructAppL(coe)); |
|
480 |
|
481 if (!err) |
|
482 coe->ExecuteD(); |
|
483 |
|
484 REComSession::FinalClose(); |
|
485 __UHEAP_MARKEND; |
|
486 |
|
487 return TestStepResult(); |
|
488 } |
|
489 |