|
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 // Tests interface between container control and component controls.\n |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent - Internal Symbian test code |
|
21 */ |
|
22 |
|
23 #include <coeaui.h> |
|
24 #include <coemain.h> |
|
25 #include <coedef.h> |
|
26 #include <coesndpy.h> |
|
27 #include <basched.h> |
|
28 #include <bassnd.h> |
|
29 #include <ecom/ecom.h> |
|
30 #include "TCone6Step.h" |
|
31 #include <gdi.h> |
|
32 |
|
33 /** Constructor fo CCtlBase class.\n */ |
|
34 |
|
35 CCtlBase::CCtlBase() |
|
36 { |
|
37 } |
|
38 |
|
39 /** |
|
40 Second phase constructor for CCtlBase Class.\n |
|
41 Creates a font for the default graphics device, based on the specified TFontSpec.\n |
|
42 Initiazes the screen font for the control.\n |
|
43 */ |
|
44 void CCtlBase::ConstructL() |
|
45 { |
|
46 TFontSpec spec(_L("Arial"),240); |
|
47 iFont = iCoeEnv->CreateScreenFontL( spec ) ; |
|
48 } |
|
49 /** Destructor for CCtlBase class.\n */ |
|
50 |
|
51 CCtlBase::~CCtlBase() |
|
52 { |
|
53 iCoeEnv->ReleaseScreenFont(iFont); |
|
54 } |
|
55 /** |
|
56 Writes the text "aText" on the control.\n |
|
57 Sets the font,pen colour,brush style used for writing the text.\n |
|
58 Draws the text uisng Draw Text function of Graphics context.\n |
|
59 */ |
|
60 void CCtlBase::WriteName( CWindowGc& aGc, const TDesC& aText ) const |
|
61 { |
|
62 TRect rect = Rect() ; |
|
63 rect.Shrink( 3, 3 ) ; |
|
64 aGc.UseFont( iFont ) ; |
|
65 TInt ascent = ( rect.iBr.iY - rect.iTl.iY-iFont->HeightInPixels() ) / 2 + iFont->AscentInPixels() ; |
|
66 aGc.SetPenColor( KRgbBlack ) ; |
|
67 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ) ; |
|
68 aGc.DrawText( aText, rect, ascent, CGraphicsContext::ECenter ) ; |
|
69 } |
|
70 /** |
|
71 Draw function for the CCtlBase class.\n |
|
72 |
|
73 */ |
|
74 void CCtlBase::DoDraw( CWindowGc& aGc, TRect aRect ) const |
|
75 { |
|
76 aGc.DrawRect( aRect ) ; |
|
77 aRect.Shrink( 1, 1 ) ; |
|
78 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ) ; |
|
79 aGc.DrawRect( aRect ) ; |
|
80 WriteName( aGc, *iName ) ; |
|
81 } |
|
82 |
|
83 /** |
|
84 Constructor for CTestMCoeFocusObserver class.\n |
|
85 */ |
|
86 CTestMCoeFocusObserver::CTestMCoeFocusObserver(CCoeControl& aContainer) : iCtlContainer(aContainer) |
|
87 { |
|
88 } |
|
89 /** |
|
90 Destructor for CTestMCoeFocusObserver class.\n |
|
91 */ |
|
92 CTestMCoeFocusObserver::~CTestMCoeFocusObserver() |
|
93 { |
|
94 } |
|
95 |
|
96 void CTestMCoeFocusObserver::HandleChangeInFocus() |
|
97 { |
|
98 } |
|
99 /** |
|
100 Handles destruction of any control. It is called by framework if any control is destroyed.\n |
|
101 Accesses the component controls to make sure the components are not removed from |
|
102 CCoeControlArray before notifying the observer.\n |
|
103 */ |
|
104 void CTestMCoeFocusObserver::HandleDestructionOfFocusedItem() |
|
105 { |
|
106 TInt cnt = iCtlContainer.CountComponentControls(); |
|
107 while(cnt--) |
|
108 { |
|
109 CCoeControl* child = iCtlContainer.ComponentControl(cnt); |
|
110 child->SetFocus(ETrue); // use control to make sure its not deleted |
|
111 } |
|
112 } |
|
113 |
|
114 /** |
|
115 Constructor for the CCtlContainer class.\n |
|
116 */ |
|
117 CCtlContainer::CCtlContainer() |
|
118 { |
|
119 } |
|
120 /** |
|
121 Destructor for CCtlContainer class.\n |
|
122 Deletes the iName member variable.\n |
|
123 */ |
|
124 CCtlContainer::~CCtlContainer() |
|
125 { |
|
126 // kids should be destroyed automatically |
|
127 delete iName ; |
|
128 } |
|
129 /** |
|
130 Second phase constructor for CCtlContainer class.\n |
|
131 Invokes the base class "CCtlBase" second phase constructor.\n |
|
132 Adds three objects each of CCtlContainee class as component controls.\n |
|
133 The first two are added using a component Id while the same is not provided for the third control.\n |
|
134 The container control window is activated.\n |
|
135 */ |
|
136 void CCtlContainer::ConstructL( const TDesC& aName ) |
|
137 { |
|
138 CCtlBase::ConstructL() ; |
|
139 // construct the kids, add them to the array. |
|
140 iName = aName.AllocL() ; |
|
141 CreateWindowL() ; |
|
142 InitComponentArrayL(); |
|
143 |
|
144 CCtlContainee* child = NULL ; |
|
145 child = new (ELeave) CCtlContainee ; |
|
146 Components().AppendLC( child, KChildOneID ) ; |
|
147 child->ConstructL( _L("child1") ) ; |
|
148 CleanupStack::Pop( child ) ; |
|
149 |
|
150 child = new (ELeave) CCtlContainee ; |
|
151 Components().AppendLC( child, KChildTwoID ) ; |
|
152 child->ConstructL( _L("child2") ) ; |
|
153 CleanupStack::Pop( child ) ; |
|
154 |
|
155 CCtlContainee* temp = new (ELeave) CCtlContainee ; |
|
156 Components().AppendLC( temp ) ; |
|
157 temp ->ConstructL( _L("orphan") ) ; |
|
158 CleanupStack::Pop( temp ) ; |
|
159 iOrphan = temp ; |
|
160 |
|
161 ActivateL() ; |
|
162 } |
|
163 /** |
|
164 Sets the size of the component objects based on the present size of the container window.\n |
|
165 Calculates the present size of the container control and also the number of component objects.\n |
|
166 Sets the component object dimensions accordingly.\n |
|
167 */ |
|
168 void CCtlContainer::SizeChanged() |
|
169 { |
|
170 // set the size of the children |
|
171 TRect rect = Rect() ; |
|
172 TSize size = rect.Size() ; |
|
173 TPoint tl = rect.iTl ; |
|
174 TInt childCount = CountComponentControls() ; |
|
175 if ( childCount > 0 ) |
|
176 { |
|
177 size.iWidth = size.iWidth/childCount ; |
|
178 size.iHeight = size.iHeight/childCount ; |
|
179 CCoeControl* child ; |
|
180 for ( TInt ii = 0; ii < childCount ; ++ii ) |
|
181 { |
|
182 child = ComponentControl( ii ) ; |
|
183 child->SetRect( TRect( tl, size ) ) ; |
|
184 tl.iX += size.iWidth ; |
|
185 tl.iY += size.iHeight ; |
|
186 } |
|
187 } |
|
188 } |
|
189 /** |
|
190 Draw function to draw the container control.\n |
|
191 Gets a handle to the Windows Graphic context.\n |
|
192 Calculates the present dimensions of the control and invokes the DoDraw function.\n |
|
193 */ |
|
194 void CCtlContainer::Draw( const TRect& /*aRect*/ ) const |
|
195 { |
|
196 // get a graphics contect - outline the control |
|
197 CWindowGc& gc=SystemGc(); |
|
198 TRect rect=Rect(); |
|
199 gc.SetBrushColor( KRgbBlue ) ; |
|
200 DoDraw( gc, rect ) ; |
|
201 } |
|
202 |
|
203 /** |
|
204 @SYMTestCaseID UIF-TCone6Step-TestRemoveControlById |
|
205 |
|
206 @SYMPREQ |
|
207 |
|
208 @SYMTestCaseDesc Removes a component with Id KChildTwoID using API RemoveComponentById.\n |
|
209 |
|
210 @SYMTestPriority High |
|
211 |
|
212 @SYMTestStatus Implemented |
|
213 |
|
214 @SYMTestActions : Removes a component control using Component Id.\n |
|
215 Removes a component with Id KChildTwoID using API RemoveComponentById.\n |
|
216 The API removes a component control from a component array. |
|
217 It also sets the component's parent to <code>NULL</code>.\n |
|
218 The component control is later deleted.\n |
|
219 |
|
220 @SYMTestExpectedResults : Boolean, True if Component control is deleted.\n |
|
221 |
|
222 @SYMTestType : CIT |
|
223 */ |
|
224 TBool CCtlContainer::TestRemoveControlById() |
|
225 { |
|
226 TBool seemsOK ; |
|
227 TInt count = CountComponentControls() ; |
|
228 CCoeControl* runt = NULL ; |
|
229 runt = Components().RemoveById( KChildTwoID ) ; |
|
230 |
|
231 seemsOK = ( ( runt != NULL ) && ( CountComponentControls() == (count - 1) )) ; |
|
232 |
|
233 // So far, so good. This is a good time to test RemoveComponent() for non-existant |
|
234 if ( seemsOK ) |
|
235 { |
|
236 TInt err = Components().Remove( runt ) ; // should return KErrNotFound |
|
237 seemsOK = ( err == KErrNotFound ) ; |
|
238 } |
|
239 |
|
240 delete runt ; |
|
241 return seemsOK ; |
|
242 } |
|
243 /** |
|
244 @SYMTestCaseID UIF-TCone6Step-TestCleanupL |
|
245 |
|
246 @SYMPREQ |
|
247 |
|
248 @SYMTestCaseDesc The functions tests clean up after forced memory fail.\n |
|
249 |
|
250 @SYMTestPriority High |
|
251 |
|
252 @SYMTestStatus Implemented |
|
253 |
|
254 @SYMTestActions : The functions tests clean up after forced memory fail.\n |
|
255 The present number of component controls is obtained using CountComponentControls.\n |
|
256 The next memory allocation is caused to fail using macro "__UHEAP_FAILNEXT".\n |
|
257 A new component is added using AddComponentByIdLC API.\n |
|
258 The number of component controls should remain the same after memory allocation failure also .\n |
|
259 |
|
260 @SYMTestExpectedResults : Boolean, True if Clean up is successful after memory allocation failure.\n |
|
261 |
|
262 @SYMTestType : CIT |
|
263 */ |
|
264 TBool CCtlContainer::TestCleanupL() |
|
265 { |
|
266 |
|
267 TBool seemsOK = EFalse ; |
|
268 |
|
269 // Initial count of controls |
|
270 TInt count = CountComponentControls() ; |
|
271 |
|
272 // Create a new control to add to the array |
|
273 CCtlContainee* child = NULL ; |
|
274 child = new (ELeave) CCtlContainee ; |
|
275 |
|
276 // Set memory allocation to fail |
|
277 __UHEAP_MARK ; |
|
278 __UHEAP_SETFAIL((RHeap::EDeterministic),1); |
|
279 |
|
280 // Expect addition of the control to the array to fail |
|
281 TRAPD(err, |
|
282 { |
|
283 Components().AppendLC( child ); |
|
284 CleanupStack::Pop(child); |
|
285 } ); |
|
286 |
|
287 // Re-align the heap |
|
288 __UHEAP_RESET ; |
|
289 __UHEAP_MARKEND ; |
|
290 |
|
291 // The no of controls should be the same as at the start |
|
292 // as appending should have failed with KErrNoMemory |
|
293 seemsOK = ( (count == CountComponentControls()) && |
|
294 (err == KErrNoMemory)) ; |
|
295 |
|
296 return seemsOK ; |
|
297 } |
|
298 /** |
|
299 @SYMTestCaseID UIF-TCone6Step-TestGetControlL |
|
300 |
|
301 @SYMPREQ |
|
302 |
|
303 @SYMTestCaseDesc Tests the ability to obtain handle to the component control using Component Id.\n |
|
304 |
|
305 @SYMTestPriority High |
|
306 |
|
307 @SYMTestStatus Implemented |
|
308 |
|
309 @SYMTestActions : Third component control is added using AddComponentByIdLC API with KChildThreeID as component ID.\n |
|
310 Later the ID is passed to ComponentById API which returns the pointer to the component control.\n |
|
311 The name of the control obtained is verified against the one set.\n |
|
312 |
|
313 @SYMTestExpectedResults : Boolean, True if names match.\n |
|
314 |
|
315 @SYMTestType : CIT |
|
316 */ |
|
317 TBool CCtlContainer::TestGetControlL() |
|
318 { |
|
319 _LIT( KNameDes, "childx") ; |
|
320 // construct a control, add it. Get one back. is it the same one? |
|
321 CCtlContainee* child = NULL ; |
|
322 child = new (ELeave) CCtlContainee ; |
|
323 Components().AppendLC( child, KChildThreeID ) ; |
|
324 child->ConstructL( KNameDes ) ; |
|
325 CleanupStack::Pop( child ) ; |
|
326 |
|
327 CCoeControl* anotherChild = NULL ; |
|
328 anotherChild = Components().ControlById<CCtlContainee>(KChildThreeID); |
|
329 TInt match = 1 ; |
|
330 if ( anotherChild ) |
|
331 { |
|
332 match = KNameDes().Compare( static_cast<CCtlContainee*>(anotherChild)->WhoAmI() ) ; |
|
333 } |
|
334 return ( match == 0 ) ; |
|
335 } |
|
336 /** |
|
337 @SYMTestCaseID UIF-TCone6Step-TestGetControlConstL |
|
338 |
|
339 @SYMPREQ |
|
340 |
|
341 @SYMTestCaseDesc Gets a constant handle to the component control.\n |
|
342 |
|
343 @SYMTestPriority High |
|
344 |
|
345 @SYMTestStatus Implemented |
|
346 |
|
347 @SYMTestActions : Gets a constant handle to the component control.\n |
|
348 Handle to component with Id KChildThreeID is obtained using ComponentById API.\n |
|
349 The name of the control obtained is verified against the KNameDes descriptor.\n |
|
350 |
|
351 @SYMTestExpectedResults : Boolean, True if names match.\n |
|
352 |
|
353 @SYMTestType : CIT |
|
354 */ |
|
355 TBool CCtlContainer::TestGetControlConstL() const |
|
356 { // dependant on TestGetControlL() |
|
357 _LIT( KNameDes, "childx") ; |
|
358 const CCtlContainee* anotherChild = NULL ; |
|
359 anotherChild = Components().ControlById<CCtlContainee>(KChildThreeID); |
|
360 |
|
361 TInt match = 1 ; |
|
362 if ( anotherChild ) |
|
363 { |
|
364 match = KNameDes().Compare((anotherChild)->WhoAmI() ) ; |
|
365 } |
|
366 return ( match == 0 ) ; |
|
367 } |
|
368 /** |
|
369 @SYMTestCaseID UIF-TCone6Step-TestGetUnknownControlConstL |
|
370 |
|
371 @SYMPREQ |
|
372 |
|
373 @SYMTestCaseDesc Gets a constant handle to the non existant component control .\n |
|
374 |
|
375 @SYMTestPriority High |
|
376 |
|
377 @SYMTestStatus Implemented |
|
378 |
|
379 @SYMTestActions : Component control with ID KChildTwoID does not exist.\n |
|
380 Handle to component with Id KChildTwoID is obtained using ComponentById API.\n |
|
381 |
|
382 @SYMTestExpectedResults : Boolean, True if obtained component control pointer is NULL.\n |
|
383 |
|
384 @SYMTestType : CIT |
|
385 */ |
|
386 TBool CCtlContainer::TestGetUnknownControlConstL() const |
|
387 { // dependant on TestGetControlL and TestRemoveControl which removes child2 |
|
388 const CCoeControl* anotherChild = NULL ; |
|
389 anotherChild = Components().ControlById<CCoeControl>( KChildTwoID ) ; |
|
390 return ( anotherChild == NULL ) ; |
|
391 } |
|
392 |
|
393 /** |
|
394 @SYMTestCaseID UIF-TCone6Step-TestAddDuplicateControlL |
|
395 |
|
396 @SYMPREQ |
|
397 |
|
398 @SYMTestCaseDesc Tests adding a component control using an already used Id.\n |
|
399 |
|
400 @SYMTestPriority High |
|
401 |
|
402 @SYMTestStatus Implemented |
|
403 |
|
404 @SYMTestActions : Tests adding a component control using an already used Id.\n |
|
405 A component is created and added with Id 'KChildThreeID' which is already used.\n |
|
406 |
|
407 @SYMTestExpectedResults : Boolean, True if addition of duplicate control fails.\n |
|
408 |
|
409 @SYMTestType : CIT |
|
410 */ |
|
411 TBool CCtlContainer::TestAddDuplicateControlL() |
|
412 { |
|
413 _LIT( KNameDes, "childx") ; |
|
414 // construct a control, add it using an already used ID. Dependant on TestGetControlL() |
|
415 CCtlContainee* child = NULL ; |
|
416 child = new (ELeave) CCtlContainee ; |
|
417 TInt err ; |
|
418 __UHEAP_MARK ; |
|
419 TRAP( err, Components().AppendLC( child, KChildThreeID ) ) ; |
|
420 __UHEAP_MARKEND ; |
|
421 if ( err == KErrNone ) |
|
422 { |
|
423 child->ConstructL( KNameDes ) ; |
|
424 CleanupStack::Pop( child ) ; |
|
425 return EFalse ; // test failed |
|
426 } |
|
427 else |
|
428 { |
|
429 return ETrue ; |
|
430 } |
|
431 } |
|
432 /** |
|
433 @SYMTestCaseID UIF-TCone6Step-TestRemoveNonExistantById |
|
434 |
|
435 @SYMPREQ |
|
436 |
|
437 @SYMTestCaseDesc Tests removal of a control using a non existant component ID.\n |
|
438 |
|
439 @SYMTestPriority High |
|
440 |
|
441 @SYMTestStatus Implemented |
|
442 |
|
443 @SYMTestActions : Tests removal of a control using a non existant component ID.\n |
|
444 The number of component controls is obtained uisng CountComponentControls.\n |
|
445 The a control with Id '99' which is non existant is removed using API 'RemoveComponentById'.\n |
|
446 |
|
447 @SYMTestExpectedResults : Boolean, True if the number of controls remains the same and object pointer returned by |
|
448 RemoveComponentById is NULL.\n |
|
449 |
|
450 @SYMTestType : CIT |
|
451 */ |
|
452 TBool CCtlContainer::TestRemoveNonExistantById() |
|
453 { |
|
454 TBool seemsOK ; |
|
455 TInt count = CountComponentControls() ; |
|
456 CCoeControl* runt = NULL ; |
|
457 |
|
458 runt = Components().RemoveById( 99 ) ; |
|
459 |
|
460 TInt postCount = CountComponentControls() ; |
|
461 seemsOK = ( ( runt == NULL ) && ( CountComponentControls() == count ) ) ; |
|
462 return seemsOK ; |
|
463 } |
|
464 /** |
|
465 @SYMTestCaseID UIF-TCone6Step-TestRemoveControlL |
|
466 |
|
467 @SYMPREQ |
|
468 |
|
469 @SYMTestCaseDesc Tests removal of a control without using a control ID.\n |
|
470 |
|
471 @SYMTestPriority High |
|
472 |
|
473 @SYMTestStatus Implemented |
|
474 |
|
475 @SYMTestActions : Tests removal of a control without using a control ID.\n |
|
476 A new component control is created and is added to the container control using API 'AddComponentByIdLC'.\n |
|
477 The number of component controls is obtained using 'CountComponentControls' API.\n |
|
478 The newly added component control is removed using API 'RemoveComponent' passing the pointer as argument.\n |
|
479 |
|
480 @SYMTestExpectedResults : Boolean, True if RemoveComponent returns KErrNone and |
|
481 number of component control is decreased by One.\n |
|
482 |
|
483 @SYMTestType : CIT |
|
484 */ |
|
485 TBool CCtlContainer::TestRemoveControlL() // See also TestRemoveControById() |
|
486 { |
|
487 _LIT( KNameDes, "child4") ; |
|
488 // construct a control, add it. Remove it. Is it removed? |
|
489 CCtlContainee* child = NULL ; |
|
490 child = new (ELeave) CCtlContainee ; |
|
491 Components().AppendLC( child, KChildFourID ) ; |
|
492 child->ConstructL( KNameDes ) ; |
|
493 CleanupStack::Pop( child ) ; |
|
494 |
|
495 TInt count = CountComponentControls() ; |
|
496 TInt err = Components().Remove( child ) ; // should return KErrNone |
|
497 TInt seemsOK = ( ( err == KErrNone ) && ( CountComponentControls() == (count - 1) )) ; |
|
498 |
|
499 delete child ; |
|
500 return seemsOK ; |
|
501 } |
|
502 /** |
|
503 @SYMTestCaseID UIF-TCone6Step-TestGetUnsetUniqueHandle |
|
504 |
|
505 @SYMPREQ |
|
506 |
|
507 @SYMTestCaseDesc Tests getting a unique handle to a component control without prior setting.\n |
|
508 |
|
509 @SYMTestPriority High |
|
510 |
|
511 @SYMTestStatus Implemented |
|
512 |
|
513 @SYMTestActions : Gets the handle to a component control with ID (KChildOneID).\n |
|
514 A unique handle(KUniqueId) is not set to the above control using 'SetUniqueHandle' API prior to calling the get function.\n |
|
515 |
|
516 @SYMTestExpectedResults : Boolean, True if the obtained handle is equal to Zero.\n |
|
517 |
|
518 @SYMTestType : CIT |
|
519 */ |
|
520 TBool CCtlContainer::TestGetUnsetUniqueHandle() |
|
521 { |
|
522 // will panic in debug |
|
523 TInt handle = Components().ControlById<CCoeControl>( KChildOneID )->UniqueHandle() ; |
|
524 // ignore error |
|
525 return ( handle == KErrNotFound ) ; |
|
526 |
|
527 } |
|
528 //! Unique Id used to identify a component control.\n |
|
529 const TInt KUniqueId = 0x5AD ; |
|
530 /** |
|
531 @SYMTestCaseID UIF-TCone6Step-TestSetUniqueHandle |
|
532 |
|
533 @SYMPREQ |
|
534 |
|
535 @SYMTestCaseDesc Tests setting a unique handle to a component control.\n |
|
536 |
|
537 @SYMTestPriority High |
|
538 |
|
539 @SYMTestStatus Implemented |
|
540 |
|
541 @SYMTestActions : Sets a Unique Handle( KUniqueId )to a component Control with ID( KChildOneID).\n |
|
542 |
|
543 @SYMTestExpectedResults : Boolean,True if SetUniqueHandle returns KErrNone.\n |
|
544 |
|
545 @SYMTestType : CIT |
|
546 */ |
|
547 TBool CCtlContainer::TestSetUniqueHandle() |
|
548 { |
|
549 TInt err = Components().ControlById<CCoeControl>( KChildOneID )->SetUniqueHandle( KUniqueId ) ; |
|
550 return ( err == KErrNone ) ; |
|
551 } |
|
552 /** |
|
553 @SYMTestCaseID UIF-TCone6Step-TestGetUniqueHandle |
|
554 |
|
555 @SYMPREQ |
|
556 |
|
557 @SYMTestCaseDesc Tests getting a unique handle to a component control.\n |
|
558 |
|
559 @SYMTestPriority High |
|
560 |
|
561 @SYMTestStatus Implemented |
|
562 |
|
563 @SYMTestActions : Gets the handle to a component control with ID (KChildOneID).\n |
|
564 A unique handle(KUniqueId) is set to the above control using 'SetUniqueHandle' API prior to calling the get function.\n |
|
565 |
|
566 @SYMTestExpectedResults : Boolean, True if the obtained handle is equal to KUniqueId.\n |
|
567 |
|
568 @SYMTestType : CIT |
|
569 */ |
|
570 TBool CCtlContainer::TestGetUniqueHandle() |
|
571 { |
|
572 TInt handle = Components().ControlById<CCoeControl>( KChildOneID )->UniqueHandle() ; |
|
573 return ( handle == KUniqueId ) ; |
|
574 } |
|
575 /** |
|
576 @SYMTestCaseID UIF-TCone6Step-TestSetUniqueHandleOOM |
|
577 |
|
578 @SYMPREQ |
|
579 |
|
580 @SYMTestCaseDesc Tests Setting a unique handle to a component control with forced memory allocation failure.\n |
|
581 |
|
582 @SYMTestPriority High |
|
583 |
|
584 @SYMTestStatus Implemented |
|
585 |
|
586 @SYMTestActions : A new component control is created .\n |
|
587 The next memory allocation is caused to fail using macro '__UHEAP_FAILNEXT( 1 )'.\n |
|
588 A unique handle(KUniqueId) is set to the above control using 'SetUniqueHandle' API.\n |
|
589 |
|
590 @SYMTestExpectedResults : Boolean, True if SetUniqueHandle returns KErrNoMemory.\n |
|
591 |
|
592 @SYMTestType : CIT |
|
593 */ |
|
594 TBool CCtlContainer::TestSetUniqueHandleOOM() |
|
595 { |
|
596 CCtlContainee* child = NULL ; |
|
597 child = new (ELeave) CCtlContainee ; |
|
598 child->SetContainerWindowL(*this); |
|
599 child->ActivateL(); // By activating the control its reserved memory is purged, so that the SetUniqueHandle() call can fail below. |
|
600 __UHEAP_MARK ; |
|
601 __UHEAP_FAILNEXT( 1 ) ; |
|
602 TInt err = child->SetUniqueHandle( KUniqueId ) ; |
|
603 __UHEAP_RESET ; |
|
604 __UHEAP_MARKEND ; |
|
605 delete child ; |
|
606 return ( err == KErrNoMemory ) ; |
|
607 } |
|
608 |
|
609 NONSHARABLE_CLASS(RDebugHeap) : public RHeap |
|
610 { |
|
611 public: |
|
612 static bool OOMTrigered() |
|
613 { |
|
614 RDebugHeap& heap = STATIC_CAST(RDebugHeap&,User::Heap()); |
|
615 return (!(heap.iFailAllocCount%heap.iFailRate) && (RAllocator::ENone == heap.iFailType)); |
|
616 } |
|
617 static bool OOMComplete() |
|
618 { |
|
619 RDebugHeap& heap = STATIC_CAST(RDebugHeap&,User::Heap()); |
|
620 return ((RAllocator::EFailNext == heap.iFailType) && (heap.iFailAllocCount%heap.iFailRate)); |
|
621 } |
|
622 }; |
|
623 |
|
624 TBool CCtlContainer::TestInsertAfter() |
|
625 { |
|
626 _LIT(KNameDes, "child3"); |
|
627 CCtlContainee* child = NULL; |
|
628 |
|
629 TInt err; |
|
630 TInt oomCount = 1; |
|
631 |
|
632 #ifdef __WINS__ |
|
633 while(oomCount < 100) |
|
634 { |
|
635 __UHEAP_FAILNEXT(oomCount); |
|
636 err = KErrNone; |
|
637 #endif |
|
638 TRAP(err, |
|
639 { |
|
640 child = new (ELeave) CCtlContainee; |
|
641 Components().InsertAfterLC(KChildOneID, child, KChildFiveID); |
|
642 child->ConstructL(KNameDes); |
|
643 CleanupStack::Pop(child); |
|
644 }); |
|
645 #ifdef __WINS__ |
|
646 if (RDebugHeap::OOMTrigered()) |
|
647 { |
|
648 __UHEAP_RESET; |
|
649 if(err == KErrNone) |
|
650 { |
|
651 if(Components().At(1).iId != KChildFiveID) |
|
652 { |
|
653 return EFalse; |
|
654 } |
|
655 Components().Remove( child ); |
|
656 delete child; |
|
657 } |
|
658 if(Components().At(1).iId == KChildFiveID) |
|
659 { |
|
660 return EFalse; |
|
661 } |
|
662 if(err != KErrNone && err != KErrNoMemory) |
|
663 { |
|
664 return EFalse; |
|
665 } |
|
666 |
|
667 // If we get to here, it was a properly-handled OOM situation |
|
668 oomCount++; |
|
669 } |
|
670 else if(RDebugHeap::OOMComplete()) |
|
671 { |
|
672 __UHEAP_RESET; |
|
673 break; |
|
674 } |
|
675 else |
|
676 { |
|
677 __UHEAP_RESET; |
|
678 return EFalse; |
|
679 } |
|
680 } |
|
681 #endif |
|
682 if (err == KErrNone && oomCount != 100) |
|
683 { |
|
684 if (Components().At(1).iId == KChildFiveID) |
|
685 { |
|
686 return ETrue; |
|
687 } |
|
688 else |
|
689 { |
|
690 return EFalse; |
|
691 } |
|
692 } |
|
693 else |
|
694 { |
|
695 return EFalse; |
|
696 } |
|
697 } |
|
698 |
|
699 //Tests the Insertion of the control after the last control using InsertAfterLC |
|
700 TBool CCtlContainer::TestInsertLast() |
|
701 { |
|
702 _LIT(KNameDes, "child6"); |
|
703 CCtlContainee* child = NULL; |
|
704 child = new (ELeave) CCtlContainee; |
|
705 |
|
706 TRAPD(err, |
|
707 { |
|
708 Components().InsertAfterLC(KChildOneID, child, KChildSixID); |
|
709 child->ConstructL(KNameDes); |
|
710 CleanupStack::Pop(child); |
|
711 }); |
|
712 if (err == KErrNone) |
|
713 { |
|
714 if (Components().At(3).iId == KChildSixID) |
|
715 { |
|
716 return ETrue; |
|
717 } |
|
718 else |
|
719 { |
|
720 return EFalse; |
|
721 } |
|
722 } |
|
723 else |
|
724 { |
|
725 return EFalse; |
|
726 } |
|
727 } |
|
728 |
|
729 /** |
|
730 @SYMTestCaseID UIF-TCone6Step-TestFailingInsertAfter |
|
731 |
|
732 @SYMPREQ |
|
733 |
|
734 @SYMTestCaseDesc Tests that InsertAfterLC() works correctly when invalid reference component id is given.\n |
|
735 |
|
736 @SYMTestPriority High |
|
737 |
|
738 @SYMTestStatus Implemented |
|
739 |
|
740 @SYMTestActions : Creates a child and tries to add it using invalid reference component id.\n |
|
741 |
|
742 @SYMTestExpectedResults : Boolean, True.\n |
|
743 |
|
744 @SYMTestType : CIT |
|
745 */ |
|
746 TBool CCtlContainer::TestFailingInsertAfter() |
|
747 { |
|
748 __UHEAP_MARK; |
|
749 CCtlContainee* child = new(ELeave) CCtlContainee; |
|
750 TRAPD(err, Components().InsertAfterLC(KErrNotFound, child)); |
|
751 __UHEAP_MARKEND; |
|
752 return (err == KErrNotFound); |
|
753 } |
|
754 |
|
755 TBool CCtlContainer::TestId() |
|
756 { |
|
757 if (Components().Id(*Components().At(0).iControl) == KChildOneID) |
|
758 { |
|
759 return ETrue; |
|
760 } |
|
761 else |
|
762 { |
|
763 return EFalse; |
|
764 } |
|
765 } |
|
766 |
|
767 TBool CCtlContainer::TestCursor() |
|
768 { |
|
769 CCoeControlArray::TCursor cursor = Components().Begin(); |
|
770 CCoeControl* child = cursor.Control<CCoeControl>(); |
|
771 // Check that begin points to the first control |
|
772 if (Components().Id(*child) != KChildOneID) |
|
773 { |
|
774 return EFalse; |
|
775 } |
|
776 // Check that next points to the second control |
|
777 // The test TestInsertAfter will have put the corresponding |
|
778 // control in the second position |
|
779 if (cursor.Next()) |
|
780 { |
|
781 CCoeControl* child = cursor.Control<CCoeControl>(); |
|
782 if (Components().Id(*child) != KChildFiveID) |
|
783 { |
|
784 return EFalse; |
|
785 } |
|
786 } |
|
787 else |
|
788 { |
|
789 return EFalse; |
|
790 } |
|
791 // Go back by one and check again |
|
792 if (cursor.Prev()) |
|
793 { |
|
794 CCoeControl* child = cursor.Control<CCoeControl>(); |
|
795 if (Components().Id(*child) != KChildOneID) |
|
796 { |
|
797 return EFalse; |
|
798 } |
|
799 } |
|
800 else |
|
801 { |
|
802 return EFalse; |
|
803 } |
|
804 |
|
805 // Check == and != |
|
806 CCoeControlArray::TCursor cursor2 = Components().Begin(); |
|
807 if (!(cursor == cursor2) || (cursor != cursor2)) |
|
808 { |
|
809 return EFalse; |
|
810 } |
|
811 cursor.Next(); |
|
812 if ((cursor == cursor2) || !(cursor != cursor2)) |
|
813 { |
|
814 return EFalse; |
|
815 } |
|
816 |
|
817 return ETrue; |
|
818 } |
|
819 |
|
820 TBool CCtlContainer::TestFind() |
|
821 { |
|
822 CCoeControlArray::TCursor cursor = Components().Find(KChildOneID); |
|
823 if (!cursor.IsValid()) |
|
824 { |
|
825 return EFalse; |
|
826 } |
|
827 CCoeControl* control = Components().At(0).iControl; |
|
828 CCoeControlArray::TCursor cursor2 = Components().Find(control); |
|
829 if (!cursor2.IsValid()) |
|
830 { |
|
831 return EFalse; |
|
832 } |
|
833 // Check that an inexistent id returns a "null" cursor |
|
834 CCoeControlArray::TCursor cursor3 = Components().Find(76765); |
|
835 if (cursor3.IsValid()) |
|
836 { |
|
837 return EFalse; |
|
838 } |
|
839 // Check that an inexistent control returns a "null" cursor |
|
840 CCoeControl* dummyControl = new CCoeControl(); |
|
841 CCoeControlArray::TCursor cursor4 = Components().Find(dummyControl); |
|
842 delete dummyControl; |
|
843 if (cursor4.IsValid()) |
|
844 { |
|
845 return EFalse; |
|
846 } |
|
847 |
|
848 return ETrue; |
|
849 } |
|
850 |
|
851 TBool CCtlContainer::TestSort() |
|
852 { |
|
853 //Removing the orphan control from array and deleting the control |
|
854 User::LeaveIfError(Components().Remove(iOrphan)); |
|
855 delete iOrphan; |
|
856 iOrphan = 0; |
|
857 CCtlContainee* child = NULL ; |
|
858 child = new (ELeave) CCtlContainee ; |
|
859 Components().InsertAfterLC(KChildOneID, child, KChildTwoID); |
|
860 _LIT(KNameDes2, "child2"); |
|
861 child->ConstructL(KNameDes2 ) ; |
|
862 CleanupStack::Pop( child ) ; |
|
863 |
|
864 //Creates an object of 'TLinearOrder'. |
|
865 TLinearOrder<TCoeControlWithId> order(CCtlContainer::CompareControls); |
|
866 |
|
867 //Sorts the controls stored in the object. |
|
868 //Before sorting the order of control in the array is 0, 1, 2. |
|
869 Components().Sort(order); |
|
870 |
|
871 TBool sorted=ETrue; |
|
872 |
|
873 //Checking whether the controls are sorted in descending order or not |
|
874 for(TInt i=0; i < Components().Count(); i++) |
|
875 { |
|
876 TInt k=Components().At(i).iId; |
|
877 if (Components().At(i).iId != Components().Count() - i -1) |
|
878 { |
|
879 sorted=EFalse; |
|
880 break; |
|
881 } |
|
882 } |
|
883 return sorted; |
|
884 } |
|
885 TInt CCtlContainer::CompareControls(const TCoeControlWithId& aFirst, const TCoeControlWithId& aSecond) |
|
886 { |
|
887 //Algorithm to sort the controls in descending order based on the control id |
|
888 //It will return 1,0 or -1. |
|
889 return aSecond.iId - aFirst.iId; |
|
890 } |
|
891 TBool CCtlContainer::TestRemove() |
|
892 { |
|
893 CCoeControlArray::TCursor cursor = Components().Find(KChildFiveID); |
|
894 if (!cursor.IsValid()) |
|
895 { |
|
896 return EFalse; |
|
897 } |
|
898 CCoeControl* control = Components().Remove(cursor); |
|
899 if (!control) |
|
900 { |
|
901 return EFalse; |
|
902 } |
|
903 delete control; |
|
904 |
|
905 return ETrue; |
|
906 } |
|
907 |
|
908 TBool CCtlContainer::TestReplace() |
|
909 { |
|
910 CCoeControlArray::TCursor cursor = Components().Find(KChildOneID); |
|
911 if (!cursor.IsValid()) |
|
912 { |
|
913 return EFalse; |
|
914 } |
|
915 CCoeControl* ctrl = cursor.Control<CCoeControl>(); |
|
916 CCtlContainee* child = new (ELeave) CCtlContainee; |
|
917 TInt err = Components().Replace(ctrl, child); |
|
918 if (err != KErrNone) |
|
919 { |
|
920 delete child; |
|
921 return EFalse; |
|
922 } |
|
923 delete ctrl; |
|
924 |
|
925 // Check replacement of inexistent control |
|
926 err = Components().Replace(ctrl, child); |
|
927 if (err != KErrNotFound) |
|
928 { |
|
929 return EFalse; |
|
930 } |
|
931 |
|
932 return ETrue; |
|
933 } |
|
934 |
|
935 TBool CCtlContainer::TestSetArrayLocked() |
|
936 { |
|
937 Components().SetArrayLocked(); |
|
938 if (!Components().IsArrayLocked()) |
|
939 { |
|
940 return EFalse; |
|
941 } |
|
942 CCtlContainee* child = NULL ; |
|
943 child = new (ELeave) CCtlContainee ; |
|
944 TRAPD(err, Components().AppendLC(child, KChildOneID)); |
|
945 if (err != KErrLocked) |
|
946 { |
|
947 return EFalse; |
|
948 } |
|
949 return ETrue; |
|
950 } |
|
951 |
|
952 /** |
|
953 @SYMTestCaseID UIF-TCone6Step-TestOwnedExternally |
|
954 |
|
955 @SYMPREQ |
|
956 |
|
957 @SYMTestCaseDesc Tests that CCoeControlArray is behaving correctly when adding controls when they are owned externally.\n |
|
958 |
|
959 @SYMTestPriority High |
|
960 |
|
961 @SYMTestStatus Implemented |
|
962 |
|
963 @SYMTestActions : Creates a child removes and deletes it.\n |
|
964 Creates a child and makes the cleanupstack item remove the child, and deletes the child.\n |
|
965 Tries to add a CCtlUnparentableContainee and deletes it.\n |
|
966 Creates a child and adds it using InsertAfterLC().\n |
|
967 Tries to add a child but using an invalid component id for InsertAfterLC().\n |
|
968 |
|
969 @SYMTestExpectedResults : Boolean, True.\n |
|
970 |
|
971 @SYMTestType : CIT |
|
972 */ |
|
973 TBool CCtlContainer::TestOwnedExternally() |
|
974 { |
|
975 Components().ResetAndDestroy(); |
|
976 Components().SetControlsOwnedExternally(ETrue); |
|
977 |
|
978 // Test InsertLC() |
|
979 |
|
980 //normal usage |
|
981 CCtlContainee* child = new(ELeave) CCtlContainee; |
|
982 CleanupStack::PushL(child); |
|
983 Components().AppendLC(child); |
|
984 CleanupStack::Pop(child); |
|
985 Components().Remove(child); |
|
986 CleanupStack::PopAndDestroy(child); |
|
987 |
|
988 //emulate leave |
|
989 child = new(ELeave) CCtlContainee; |
|
990 CleanupStack::PushL(child); |
|
991 Components().AppendLC(child); |
|
992 CleanupStack::PopAndDestroy(child); //"leave" |
|
993 CleanupStack::PopAndDestroy(child); |
|
994 if(Components().Find(child).IsValid()) return EFalse; |
|
995 |
|
996 //SetParent() is called before the cleanup stack is created |
|
997 //make sure there's no double deletion when the SetParent() call fails |
|
998 CCtlUnparentableContainee* childOfNoone = new(ELeave) CCtlUnparentableContainee; |
|
999 CleanupStack::PushL(childOfNoone); |
|
1000 TRAP_IGNORE(Components().AppendLC(childOfNoone)); |
|
1001 CleanupStack::PopAndDestroy(childOfNoone); |
|
1002 if(Components().Find(childOfNoone).IsValid()) return EFalse; |
|
1003 |
|
1004 // Test InsertAfterLC() |
|
1005 |
|
1006 //add a reference child |
|
1007 CCtlContainee* firstChild = new(ELeave) CCtlContainee; |
|
1008 CleanupStack::PushL(firstChild); |
|
1009 Components().AppendLC(firstChild, KChildOneID); |
|
1010 CleanupStack::Pop(firstChild); |
|
1011 |
|
1012 //insert successfully, remove by emulating leave |
|
1013 child = new(ELeave) CCtlContainee; |
|
1014 CleanupStack::PushL(child); |
|
1015 Components().InsertAfterLC(KChildOneID, child); |
|
1016 CleanupStack::PopAndDestroy(child); //"leave" |
|
1017 CleanupStack::PopAndDestroy(child); |
|
1018 if(Components().Find(child).IsValid()) return EFalse; |
|
1019 |
|
1020 //insert with invalid reference component id |
|
1021 child = new(ELeave) CCtlContainee; |
|
1022 CleanupStack::PushL(child); |
|
1023 TRAP_IGNORE(Components().InsertAfterLC(KErrNotFound, child)); |
|
1024 CleanupStack::PopAndDestroy(child); |
|
1025 if(Components().Find(child).IsValid()) return EFalse; |
|
1026 |
|
1027 //cleanup reference child |
|
1028 Components().Remove(firstChild); |
|
1029 CleanupStack::PopAndDestroy(firstChild); |
|
1030 |
|
1031 return (CountComponentControls() == 0); |
|
1032 } |
|
1033 |
|
1034 /** |
|
1035 @SYMTestCaseID UIF-TCone6Step-TestHandleDestructionOfFocusedItemL |
|
1036 |
|
1037 @SYMDEF DEF087937 MMS: MMS Editor - Messaging crash using jog dial to scroll through message wh... |
|
1038 |
|
1039 @SYMTestCaseDesc Tests the CCoeControl's destructor notifies the observer before |
|
1040 CCoeControl's CCoeControlArray components are deleted and the array is shrinked.\n |
|
1041 The observer should access CCoeControl::CountComponentsControl() and ComponentControl().\n |
|
1042 |
|
1043 @SYMTestPriority High |
|
1044 |
|
1045 @SYMTestStatus Implemented |
|
1046 |
|
1047 @SYMTestActions : The parent control is created and two child controls are added to it.\n |
|
1048 The parent control is registered with observer to get notification.\n |
|
1049 Delete both parent control and observer.\n |
|
1050 |
|
1051 @SYMTestExpectedResults : The CCoeControl's destructor notifies the observer before deleting |
|
1052 and shrinking the CCoeCotrolArray.\n |
|
1053 The observer accesses CoeControl::CountComponentsControl() and ComponentControl(). |
|
1054 |
|
1055 @SYMTestType : CIT |
|
1056 */ |
|
1057 void CCtlContainer::TestHandleDestructionOfFocusedItemL() |
|
1058 { |
|
1059 CParentControl* parent = new (ELeave) CParentControl; |
|
1060 CleanupStack::PushL(parent); |
|
1061 parent->SetContainerWindowL(*this); |
|
1062 parent->InitComponentArrayL(); |
|
1063 |
|
1064 CCoeControl* child1 = new (ELeave) CCoeControl; |
|
1065 parent->Components().AppendLC(child1) ; |
|
1066 CleanupStack::Pop( child1 ); |
|
1067 |
|
1068 CCoeControl* child2 = new (ELeave) CCoeControl; |
|
1069 parent->Components().AppendLC(child2) ; |
|
1070 CleanupStack::Pop( child2 ); |
|
1071 |
|
1072 CTestMCoeFocusObserver* obs = new (ELeave) CTestMCoeFocusObserver(*parent) ; |
|
1073 CleanupStack::PushL(obs); |
|
1074 CCoeEnv::Static()->AddFocusObserverL(*obs); |
|
1075 CleanupStack::Pop(obs); |
|
1076 |
|
1077 // set both focused to make the test independent of deletion order |
|
1078 child1->SetFocus(ETrue); |
|
1079 child2->SetFocus(ETrue); |
|
1080 |
|
1081 // parent will delete its children |
|
1082 // obs will be notified via HandleDestructionOfFocusedItem |
|
1083 // obs will refer to deleted child1 |
|
1084 CleanupStack::PopAndDestroy(parent); |
|
1085 CCoeEnv::Static()->RemoveFocusObserver(*obs); |
|
1086 delete obs; |
|
1087 } |
|
1088 |
|
1089 CCtlContainee::CCtlContainee() |
|
1090 { |
|
1091 } |
|
1092 /** |
|
1093 Destructor for CCtlContainee classused for creating component controls.\n |
|
1094 */ |
|
1095 CCtlContainee::~CCtlContainee() |
|
1096 { |
|
1097 delete iName ; |
|
1098 } |
|
1099 /** |
|
1100 Second phase constructor for CCtlContainee classused for creating component controls.\n |
|
1101 Invokes the base class second phase construtor.\n |
|
1102 Allocates a string which contains the ID of the component control.\n |
|
1103 */ |
|
1104 void CCtlContainee::ConstructL( const TDesC& aName ) |
|
1105 { |
|
1106 CCtlBase::ConstructL() ; |
|
1107 iName = aName.AllocL() ; |
|
1108 } |
|
1109 /** |
|
1110 Function to draw the component control.\n |
|
1111 Obtains a handle to Windows Graphic Context.\n |
|
1112 Sets the Brush colour and invokes the DoDraw function.\n |
|
1113 */ |
|
1114 void CCtlContainee::Draw(const TRect& /*aRect*/) const |
|
1115 { |
|
1116 CWindowGc& gc=SystemGc(); |
|
1117 TRect rect=Rect(); |
|
1118 gc.SetBrushColor( KRgbYellow ) ; |
|
1119 DoDraw( gc, rect ) ; |
|
1120 } |
|
1121 /** |
|
1122 Returns the string associated with the component control.\n |
|
1123 |
|
1124 @return String associated with the control.\n |
|
1125 */ |
|
1126 const TDesC& CCtlContainee::WhoAmI() const |
|
1127 { |
|
1128 return *iName ; |
|
1129 } |
|
1130 |
|
1131 |
|
1132 /** |
|
1133 Constructor for CCone6TestAppUi class.\n |
|
1134 Sets the Test step Name.\n |
|
1135 */ |
|
1136 CCone6TestAppUi::CCone6TestAppUi(CTmsTestStep* aStep) : |
|
1137 CTestCoeAppUi(aStep) |
|
1138 {} |
|
1139 |
|
1140 /** |
|
1141 Destructor for CCone6TestAppUi class.\n |
|
1142 */ |
|
1143 CCone6TestAppUi::~CCone6TestAppUi() |
|
1144 { |
|
1145 delete iContainer ; |
|
1146 } |
|
1147 |
|
1148 /** |
|
1149 Second phase constructor for the CCone6TestAppUi class.\n |
|
1150 Invokes the base class CTestCoeAppUi ConstructL function.\n |
|
1151 Instantiates a container control object.\n |
|
1152 Sets the container control's extent using CCoeControl::SetExtent API.\n |
|
1153 Starts the asynchronous execution of tests using Auto test manager.\n |
|
1154 */ |
|
1155 void CCone6TestAppUi::ConstructL() |
|
1156 { |
|
1157 INFO_PRINTF1(_L("App UI ConstructL")); |
|
1158 |
|
1159 CTestCoeAppUi::ConstructL(); |
|
1160 |
|
1161 ReinitializeContainerL(); |
|
1162 |
|
1163 AutoTestManager().StartAutoTest(); |
|
1164 } |
|
1165 /** |
|
1166 Makes sure the container is in its initial state.\n |
|
1167 Must be called by tests that make the container change state so that following |
|
1168 tests knows what to expect. |
|
1169 */ |
|
1170 void CCone6TestAppUi::ReinitializeContainerL() |
|
1171 { |
|
1172 delete iContainer; |
|
1173 iContainer = NULL; |
|
1174 |
|
1175 iContainer = new (ELeave) CCtlContainer; |
|
1176 |
|
1177 iContainer->ConstructL( _L("Container") ) ; |
|
1178 iContainer->SetExtent( TPoint(20,20),TSize(600,200) ) ; |
|
1179 } |
|
1180 |
|
1181 /** |
|
1182 The function handles the key events received by CCone6Test AppUi.\n |
|
1183 Exits the application in case Ctrl + E is received.\n |
|
1184 |
|
1185 @return TKeyResponse, Indicating whether the key event has been handled or not.\n |
|
1186 */ |
|
1187 TKeyResponse CCone6TestAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
1188 { |
|
1189 TKeyResponse ret=EKeyWasNotConsumed; |
|
1190 if (aType==EEventKey && aKeyEvent.iCode==CTRL('e')) |
|
1191 { |
|
1192 CBaActiveScheduler::Exit(); |
|
1193 ret=EKeyWasConsumed; |
|
1194 } |
|
1195 return ret; |
|
1196 } |
|
1197 |
|
1198 /** |
|
1199 Auxilliary Function for all test cases.\n |
|
1200 This function is iteratively called by the RunL function of the Autotestmanager |
|
1201 asynchronously.\n |
|
1202 Calls the following function\n |
|
1203 1. Draw the container.\n |
|
1204 2. Make the control invisible and invoke Draw.\n |
|
1205 3. Make the control visible and invoke Draw.\n |
|
1206 4. Test the cleanup after forced memory fail.\n |
|
1207 5. Test removing a component control using Id.\n |
|
1208 6. Test Getting a control using a component Id.\n |
|
1209 7. Test Getting a const pointer to a control .\n |
|
1210 8. Addition of a duplicate control.\n |
|
1211 9. Removal of a non existant control.\n |
|
1212 10. Unsetting a unique handle.\n |
|
1213 11. Setting a unique handle.\n |
|
1214 12. Getting a unique handle.\n |
|
1215 |
|
1216 25. Externally owned component controls.\n |
|
1217 26. Failing InsertAfterLC().\n |
|
1218 */ |
|
1219 void CCone6TestAppUi::RunTestStepL(TInt aStepNum) |
|
1220 { |
|
1221 |
|
1222 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
1223 |
|
1224 switch(aStepNum) |
|
1225 { |
|
1226 case 0 : |
|
1227 case 1 : |
|
1228 INFO_PRINTF1(_L("Test 6 case 1")); |
|
1229 iContainer->DrawNow() ; |
|
1230 break ; |
|
1231 case 2 : |
|
1232 INFO_PRINTF1(_L("Test 6: Case 2")); |
|
1233 iContainer->MakeVisible( EFalse ) ; |
|
1234 iContainer->DrawNow() ; |
|
1235 break ; |
|
1236 case 3 : |
|
1237 INFO_PRINTF1(_L("Test 6: Case 3")); |
|
1238 iContainer->MakeVisible( ETrue ) ; |
|
1239 iContainer->DrawNow() ; |
|
1240 break ; |
|
1241 case 4 : |
|
1242 INFO_PRINTF1(_L("Test 6: Case 4")); |
|
1243 #if defined( _DEBUG ) |
|
1244 TEST(iContainer->TestCleanupL()); |
|
1245 #endif |
|
1246 iContainer->DrawNow() ; |
|
1247 break ; |
|
1248 case 5 : |
|
1249 SetTestStepID(_L("UIF-TCone6Step-TestRemoveControlById")); |
|
1250 INFO_PRINTF1(_L("Test 6: Case 5")); |
|
1251 TEST( iContainer->TestRemoveControlById() ) ; |
|
1252 iContainer->DrawNow() ; |
|
1253 RecordTestResultL(); |
|
1254 break ; |
|
1255 case 6 : |
|
1256 SetTestStepID(_L("UIF-TCone6Step-TestGetControlL")); |
|
1257 INFO_PRINTF1(_L("Test 6: Case 6")); |
|
1258 TEST( iContainer->TestGetControlL() ) ; |
|
1259 RecordTestResultL(); |
|
1260 break ; |
|
1261 case 7 : |
|
1262 SetTestStepID(_L("UIF-TCone6Step-TestGetControlConstL")); |
|
1263 INFO_PRINTF1(_L("Test 6: Case 7")); |
|
1264 TEST( iContainer->TestGetControlConstL() ) ; |
|
1265 RecordTestResultL(); |
|
1266 break ; |
|
1267 case 8 : |
|
1268 SetTestStepID(_L("UIF-TCone6Step-TestGetUnknownControlConstL")); |
|
1269 INFO_PRINTF1(_L("Test 6: Case 8")); |
|
1270 TEST( iContainer->TestGetUnknownControlConstL() ) ; |
|
1271 RecordTestResultL(); |
|
1272 break ; |
|
1273 case 9 : |
|
1274 SetTestStepID(_L("UIF-TCone6Step-TestAddDuplicateControlL")); |
|
1275 INFO_PRINTF1(_L("Test 6: Case 9")); |
|
1276 // TEST( iContainer->TestAddDuplicateControlL() ) ; |
|
1277 RecordTestResultL(); |
|
1278 break ; |
|
1279 case 10 : |
|
1280 SetTestStepID(_L("UIF-TCone6Step-TestRemoveNonExistantById")); |
|
1281 INFO_PRINTF1(_L("Test 6: Case 10")); |
|
1282 TEST( iContainer->TestRemoveNonExistantById() ) ; |
|
1283 RecordTestResultL(); |
|
1284 break ; |
|
1285 case 11 : |
|
1286 SetTestStepID(_L("UIF-TCone6Step-TestRemoveControlL")); |
|
1287 INFO_PRINTF1(_L("Test 6: Case 11")); |
|
1288 TEST( iContainer->TestRemoveControlL() ) ; |
|
1289 RecordTestResultL(); |
|
1290 break ; |
|
1291 case 12 : |
|
1292 SetTestStepID(_L("UIF-TCone6Step-TestGetUnsetUniqueHandle")); |
|
1293 INFO_PRINTF1(_L("Test 6: Case 12")); |
|
1294 TEST( iContainer->TestGetUnsetUniqueHandle() ) ; |
|
1295 RecordTestResultL(); |
|
1296 break ; |
|
1297 case 13 : |
|
1298 SetTestStepID(_L("UIF-TCone6Step-TestSetUniqueHandle")); |
|
1299 INFO_PRINTF1(_L("Test 6: Case 13")); |
|
1300 TEST( iContainer->TestSetUniqueHandle() ) ; |
|
1301 RecordTestResultL(); |
|
1302 break ; |
|
1303 case 14 : |
|
1304 SetTestStepID(_L("UIF-TCone6Step-TestGetUniqueHandle")); |
|
1305 INFO_PRINTF1(_L("Test 6: Case 14")); |
|
1306 TEST( iContainer->TestGetUniqueHandle() ) ; |
|
1307 RecordTestResultL(); |
|
1308 break ; |
|
1309 case 15 : |
|
1310 INFO_PRINTF1(_L("Test 6: Case 15")); |
|
1311 TEST( iContainer->TestInsertAfter()); |
|
1312 break; |
|
1313 case 22 : |
|
1314 INFO_PRINTF1(_L("Test 6: Case 22")); |
|
1315 TEST( iContainer->TestInsertLast()); |
|
1316 break; |
|
1317 case 16 : |
|
1318 INFO_PRINTF1(_L("Test 6: Case 16")); |
|
1319 TEST( iContainer->TestId()); |
|
1320 break; |
|
1321 case 17 : |
|
1322 INFO_PRINTF1(_L("Test 6: Case 17")); |
|
1323 TEST( iContainer->TestCursor()); |
|
1324 break; |
|
1325 case 18 : |
|
1326 INFO_PRINTF1(_L("Test 6: Case 18")); |
|
1327 TEST( iContainer->TestFind()); |
|
1328 break; |
|
1329 case 19 : |
|
1330 INFO_PRINTF1(_L("Test 6: Case 19")); |
|
1331 TEST( iContainer->TestRemove()); |
|
1332 break; |
|
1333 case 20 : |
|
1334 INFO_PRINTF1(_L("Test 6: Case 20")); |
|
1335 TEST( iContainer->TestReplace()); |
|
1336 break; |
|
1337 case 21 : |
|
1338 INFO_PRINTF1(_L("Test 6: Case 21")); |
|
1339 TEST( iContainer->TestSort()); |
|
1340 break ; |
|
1341 case 23 : |
|
1342 SetTestStepID(_L("UIF-TCone6Step-TestHandleDestructionOfFocusedItemL")); |
|
1343 INFO_PRINTF1(_L("Test 6: Case 23")); |
|
1344 TRAPD(ret,iContainer->TestHandleDestructionOfFocusedItemL()); |
|
1345 TEST(ret == KErrNone); |
|
1346 RecordTestResultL(); |
|
1347 break; |
|
1348 case 24 : |
|
1349 INFO_PRINTF1(_L("Test 6: Case 24")); |
|
1350 #if defined( __WINS__ ) |
|
1351 TEST( iContainer->TestSetUniqueHandleOOM() ) ; |
|
1352 #else // No memory failure testing on hardware because UREL |
|
1353 TEST( ETrue) ; |
|
1354 #endif |
|
1355 break ; |
|
1356 case 25: |
|
1357 SetTestStepID(_L("UIF-TCone6Step-TestOwnedExternally")); |
|
1358 INFO_PRINTF1(_L("Test 6: Case 25")); |
|
1359 TEST( iContainer->TestOwnedExternally() ); |
|
1360 ReinitializeContainerL(); |
|
1361 RecordTestResultL(); |
|
1362 break; |
|
1363 case 26: |
|
1364 SetTestStepID(_L("UIF-TCone6Step-TestFailingInsertAfter")); |
|
1365 INFO_PRINTF1(_L("Test 6: Case 26")); |
|
1366 TEST( iContainer->TestFailingInsertAfter() ); |
|
1367 RecordTestResultL(); |
|
1368 CloseTMSGraphicsStep(); |
|
1369 break; |
|
1370 case 27 : |
|
1371 INFO_PRINTF1(_L("Test 6: Case 27")); |
|
1372 TEST( iContainer->TestSetArrayLocked()); |
|
1373 break; |
|
1374 default : |
|
1375 INFO_PRINTF1(_L("Test 6: Case default")); |
|
1376 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
1377 break; |
|
1378 |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 |
|
1383 /** |
|
1384 Completes the construction of the Control Environment(CCoeEnv object).\n |
|
1385 Instantiates the CCone6TestAppUi class which serves as a AppUi class.\n |
|
1386 Sets the CCone6TestAppUi object as the application's user interface object.\n |
|
1387 Invokes the second phase constructor of the application's UI.\n |
|
1388 */ |
|
1389 void CTCone6Step::ConstructAppL(CCoeEnv* aCoe) |
|
1390 { // runs inside a TRAP harness |
|
1391 aCoe->ConstructL(); |
|
1392 CCone6TestAppUi* appUi= new (ELeave) CCone6TestAppUi(this); |
|
1393 aCoe->SetAppUi(appUi); |
|
1394 appUi->ConstructL(); |
|
1395 } |
|
1396 /** |
|
1397 Constructor for CTCone6Step class.\n |
|
1398 Sets the test step name.\n |
|
1399 */ |
|
1400 CTCone6Step::CTCone6Step() |
|
1401 { |
|
1402 SetTestStepName(KTCone6Step); |
|
1403 } |
|
1404 /** |
|
1405 Destructor for CTCone6Step class.\n |
|
1406 */ |
|
1407 CTCone6Step::~CTCone6Step() |
|
1408 {} |
|
1409 |
|
1410 /** |
|
1411 Entry function for CTCone6 Test Step.\n |
|
1412 Sets up the control environment.\n |
|
1413 Constructs and Launches the CTCone5 Test application.\n |
|
1414 */ |
|
1415 TVerdict CTCone6Step::doTestStepL() // main function called by E32 |
|
1416 { |
|
1417 INFO_PRINTF1(_L("Test 6 Started")); |
|
1418 |
|
1419 PreallocateHALBuffer(); |
|
1420 |
|
1421 __UHEAP_MARK; |
|
1422 |
|
1423 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
1424 |
|
1425 TRAPD(err,ConstructAppL(coe)); |
|
1426 |
|
1427 if (!err) |
|
1428 { |
|
1429 coe->ExecuteD(); |
|
1430 } |
|
1431 else |
|
1432 { |
|
1433 SetTestStepResult(EFail); |
|
1434 delete coe; |
|
1435 } |
|
1436 |
|
1437 REComSession::FinalClose(); |
|
1438 |
|
1439 __UHEAP_MARKEND; |
|
1440 |
|
1441 INFO_PRINTF1(_L("Test Finished")); |
|
1442 return TestStepResult(); |
|
1443 } |
|
1444 |
|
1445 |