|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CAlfPerfAppLayoutTestCase implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "alfperfappbasetestcasecontrol.h" |
|
20 #include "alfperfapplayouttestcase.h" |
|
21 #include "alfperfapp.hrh" |
|
22 |
|
23 #include <aknutils.h> |
|
24 #include <alf/alfenv.h> |
|
25 #include <alf/alfdisplay.h> |
|
26 #include <alf/alfcontrol.h> |
|
27 #include <alf/alfcontrolgroup.h> |
|
28 #include <alf/alfroster.h> |
|
29 #include <alf/alfcommand.h> |
|
30 #include <alf/alfevent.h> |
|
31 #include <alf/alftexturemanager.h> |
|
32 #include <alf/alfimagevisual.h> |
|
33 #include <alf/alfimageloaderutil.h> |
|
34 #include <alf/alfutil.h> |
|
35 #include <alf/alfgridlayout.h> |
|
36 #include <alf/alfcurvepathlayout.h> |
|
37 #include <alf/alfdecklayout.h> |
|
38 #include <alf/alfflowlayout.h> |
|
39 #include <alf/alfanchorlayout.h> |
|
40 #include <alf/alfviewportlayout.h> |
|
41 |
|
42 #include <alfperfapp_imagetest.mbg> |
|
43 |
|
44 /** |
|
45 * Control group for test cases. |
|
46 */ |
|
47 const TInt KAlfPerfAppLayoutControlGroup = 1; |
|
48 |
|
49 /** |
|
50 * Start next 'cycle' command. |
|
51 */ |
|
52 const TInt KAlfPerfAppLayoutCmdNext = 0x5001; |
|
53 |
|
54 /** |
|
55 * Testing layouts |
|
56 */ |
|
57 class CAlfPerfAppLayoutTestCaseControl : public CAlfPerfAppBaseTestCaseControl |
|
58 { |
|
59 public: |
|
60 CAlfPerfAppLayoutTestCaseControl(); |
|
61 ~CAlfPerfAppLayoutTestCaseControl(); |
|
62 |
|
63 virtual void ConstructL( |
|
64 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ); |
|
65 virtual void DoStartExecuteL(); |
|
66 virtual TBool OfferEventL( const TAlfEvent& aEvent ); |
|
67 virtual void SetVisibleArea( const TRect& aVisibleArea ); |
|
68 |
|
69 private: |
|
70 |
|
71 /** |
|
72 * Next cycle. |
|
73 */ |
|
74 void NextCycleL(); |
|
75 |
|
76 private: |
|
77 /** |
|
78 * Test case of which execution this instance was created. |
|
79 */ |
|
80 TInt iCaseId; |
|
81 |
|
82 /** |
|
83 * Image visuals. |
|
84 */ |
|
85 RPointerArray< CAlfImageVisual > iImages; |
|
86 |
|
87 /** |
|
88 * Cycle counter. |
|
89 */ |
|
90 TInt iCycleCounter; |
|
91 |
|
92 /** |
|
93 * Image loader utility. |
|
94 * Owned. |
|
95 */ |
|
96 CAlfImageLoaderUtil* iLoader; |
|
97 |
|
98 |
|
99 /** |
|
100 * Main layout |
|
101 * Owned. |
|
102 */ |
|
103 CAlfLayout* iLayout; |
|
104 |
|
105 /** |
|
106 * Test case parameters |
|
107 */ |
|
108 TInt iVisualCount; // Number of visual to be created |
|
109 TFileName iImageFileName; // File name of the texture image file |
|
110 TInt iImageCount; // Number of different images |
|
111 TAlfTextureFlags iTextureFlags; // Texture flags |
|
112 TAlfRealSize iVisualSize; // Initial size of the visual |
|
113 }; |
|
114 |
|
115 // ============================ MEMBER FUNCTIONS =============================== |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // Checks if specified case is supported by this class. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TBool CAlfPerfAppLayoutTestCase::IsSupported( TInt aCaseId ) |
|
122 { |
|
123 return aCaseId > EAlfPerfAppLayoutMin && |
|
124 aCaseId < EAlfPerfAppLayoutMax; |
|
125 } |
|
126 |
|
127 CAlfPerfAppLayoutTestCase* CAlfPerfAppLayoutTestCase::NewL( TInt aCaseId, TInt aSequenceIndex ) |
|
128 { |
|
129 if ( !IsSupported( aCaseId ) ) |
|
130 { |
|
131 User::Leave( KErrNotSupported ); |
|
132 } |
|
133 |
|
134 CAlfPerfAppLayoutTestCase* self = |
|
135 new (ELeave) CAlfPerfAppLayoutTestCase( aCaseId, aSequenceIndex); |
|
136 CleanupStack::PushL( self ); |
|
137 self->ConstructL(); |
|
138 CleanupStack::Pop( self ); |
|
139 return self; |
|
140 } |
|
141 |
|
142 CAlfPerfAppLayoutTestCase::~CAlfPerfAppLayoutTestCase() |
|
143 { |
|
144 if ( iEnv && iControl ) |
|
145 { |
|
146 iControl->CancelExecution(); |
|
147 iEnv->DeleteControlGroup( KAlfPerfAppLayoutControlGroup ); |
|
148 } |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // Starts setup phase. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CAlfPerfAppLayoutTestCase::SetupL( |
|
156 CAlfEnv& aEnv, const TRect& aVisibleArea, TRequestStatus& aStatus ) |
|
157 { |
|
158 iEnv = &aEnv; |
|
159 |
|
160 CAlfDisplay& display = |
|
161 iEnv->NewDisplayL( aVisibleArea, CAlfEnv::ENewDisplayAsCoeControl ); |
|
162 display.SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground ); |
|
163 |
|
164 CAlfControlGroup& group = |
|
165 iEnv->NewControlGroupL( KAlfPerfAppLayoutControlGroup ); |
|
166 |
|
167 CAlfPerfAppBaseTestCaseControl* control = NULL; |
|
168 |
|
169 switch ( iCaseId ) |
|
170 { |
|
171 case EAlfPerfAppLayoutGrid: |
|
172 case EAlfPerfAppLayoutDeck: |
|
173 case EAlfPerfAppLayoutAnchor: |
|
174 case EAlfPerfAppLayoutCurvePath: |
|
175 case EAlfPerfAppLayoutFlow: |
|
176 case EAlfPerfAppLayoutViewport: |
|
177 control = new (ELeave) CAlfPerfAppLayoutTestCaseControl; |
|
178 break; |
|
179 |
|
180 default: |
|
181 User::Leave( KErrNotSupported ); |
|
182 break; |
|
183 } |
|
184 |
|
185 CleanupStack::PushL( control ); |
|
186 control->ConstructL( *iEnv, iCaseId, aVisibleArea ); |
|
187 group.AppendL( control ); // ownership passed to control group. |
|
188 iControl = control; |
|
189 CleanupStack::Pop( control ); |
|
190 |
|
191 display.Roster().ShowL( group ); |
|
192 |
|
193 // This must be last statement. |
|
194 CAlfPerfAppTestCase::CompleteNow( aStatus, KErrNone ); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // Starts execution phase. |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CAlfPerfAppLayoutTestCase::ExecuteL( TRequestStatus& aStatus ) |
|
202 { |
|
203 // SetupL must have been called first. |
|
204 __ASSERT_ALWAYS( iEnv, User::Invariant() ); |
|
205 __ASSERT_ALWAYS( iControl, User::Invariant() ); |
|
206 |
|
207 iControl->StartExecuteL( aStatus ); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // Tears down. |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CAlfPerfAppLayoutTestCase::TearDown() |
|
215 { |
|
216 // Execution side will delete CAlfEnv, so it will delete everything |
|
217 // related to this. |
|
218 iEnv = NULL; |
|
219 iControl = NULL; |
|
220 } |
|
221 |
|
222 void CAlfPerfAppLayoutTestCase::HandleVisibleAreaChange( const TRect& aRect ) |
|
223 { |
|
224 if ( iEnv && iControl ) |
|
225 { |
|
226 if ( iEnv->DisplayCount() > 0 ) |
|
227 { |
|
228 iEnv->PrimaryDisplay().SetVisibleArea( aRect ); |
|
229 } |
|
230 iControl->SetVisibleArea( aRect ); |
|
231 } |
|
232 } |
|
233 |
|
234 TInt CAlfPerfAppLayoutTestCase::CaseID() |
|
235 { |
|
236 return iCaseId; |
|
237 } |
|
238 |
|
239 CAlfPerfAppLayoutTestCase::CAlfPerfAppLayoutTestCase( TInt aCaseId, TInt aSequenceIndex ) |
|
240 : CAlfPerfAppTestCase(aSequenceIndex), iCaseId ( aCaseId ) |
|
241 { |
|
242 } |
|
243 |
|
244 void CAlfPerfAppLayoutTestCase::ConstructL() |
|
245 { |
|
246 } |
|
247 |
|
248 |
|
249 // Implementation of CAlfPerfAppLayoutTestCaseControl: |
|
250 |
|
251 CAlfPerfAppLayoutTestCaseControl::CAlfPerfAppLayoutTestCaseControl() |
|
252 { |
|
253 } |
|
254 |
|
255 CAlfPerfAppLayoutTestCaseControl::~CAlfPerfAppLayoutTestCaseControl() |
|
256 { |
|
257 iImages.Close(); |
|
258 |
|
259 delete iLoader; |
|
260 } |
|
261 |
|
262 void CAlfPerfAppLayoutTestCaseControl::ConstructL( |
|
263 CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea ) |
|
264 { |
|
265 CAlfPerfAppBaseTestCaseControl::ConstructL( aEnv, aCaseId, aVisibleArea ); |
|
266 |
|
267 // Parameters for test cases |
|
268 TSize gridSize = TSize(10,10); // Total count should be equal to iVisualCount |
|
269 iImageFileName = _L("c:\\data\\others\\alfperfapp_imagetest.png"); |
|
270 iImageCount = 4; |
|
271 iVisualCount = 100; |
|
272 iTextureFlags = EAlfTextureFlagDefault; |
|
273 iVisualSize = TAlfRealSize( 25.f, 25.f ); |
|
274 |
|
275 switch(CaseId()) |
|
276 { |
|
277 case EAlfPerfAppLayoutGrid: |
|
278 iLayout = CAlfGridLayout::AddNewL(*this, gridSize.iWidth, gridSize.iHeight); |
|
279 break; |
|
280 |
|
281 case EAlfPerfAppLayoutDeck: |
|
282 iLayout = CAlfDeckLayout::AddNewL(*this); |
|
283 break; |
|
284 |
|
285 case EAlfPerfAppLayoutAnchor: |
|
286 iLayout = CAlfAnchorLayout::AddNewL(*this); |
|
287 break; |
|
288 |
|
289 case EAlfPerfAppLayoutCurvePath: |
|
290 iLayout = CAlfCurvePathLayout::AddNewL(*this); |
|
291 break; |
|
292 |
|
293 case EAlfPerfAppLayoutFlow: |
|
294 iLayout = CAlfFlowLayout::AddNewL(*this); |
|
295 break; |
|
296 |
|
297 case EAlfPerfAppLayoutViewport: |
|
298 iLayout = CAlfViewportLayout::AddNewL(*this); |
|
299 break; |
|
300 |
|
301 default: |
|
302 User::Leave( KErrNotSupported ); |
|
303 break; |
|
304 }; |
|
305 |
|
306 |
|
307 |
|
308 // Create grid layout |
|
309 |
|
310 CAlfTextureManager& textureManager = aEnv.TextureManager(); |
|
311 |
|
312 |
|
313 TParsePtr parse(iImageFileName); |
|
314 |
|
315 for ( TInt count = 0; count < iImageCount; count++ ) |
|
316 { |
|
317 CAlfTexture& texture = textureManager.LoadTextureL(iImageFileName, iTextureFlags, count+1); |
|
318 } |
|
319 |
|
320 for ( TInt ii = 0; ii < iVisualCount; ii++ ) |
|
321 { |
|
322 CAlfImageVisual* visual = CAlfImageVisual::AddNewL( *this, iLayout); |
|
323 iImages.AppendL( visual ); |
|
324 visual->SetSize( iVisualSize ); |
|
325 } |
|
326 |
|
327 iLayout->UpdateChildrenLayout(); |
|
328 } |
|
329 |
|
330 void CAlfPerfAppLayoutTestCaseControl::DoStartExecuteL() |
|
331 { |
|
332 NextCycleL(); |
|
333 // Complete after one cycle |
|
334 CompleteNow( KErrNone ); |
|
335 } |
|
336 |
|
337 void CAlfPerfAppLayoutTestCaseControl::SetVisibleArea( |
|
338 const TRect& /*aVisibleArea*/ ) |
|
339 { |
|
340 if ( IsExecutionOngoing() ) |
|
341 { |
|
342 Env().CancelCustomCommands( this, KAlfPerfAppLayoutCmdNext ); |
|
343 TRAPD( err, NextCycleL() ); |
|
344 if ( err != KErrNone ) |
|
345 { |
|
346 CompleteNow( err ); |
|
347 } |
|
348 } |
|
349 } |
|
350 |
|
351 TBool CAlfPerfAppLayoutTestCaseControl::OfferEventL( const TAlfEvent& aEvent ) |
|
352 { |
|
353 if ( aEvent.IsCustomEvent() && |
|
354 aEvent.CustomParameter() == KAlfPerfAppLayoutCmdNext ) |
|
355 { |
|
356 TRAPD( err, NextCycleL() ); |
|
357 if ( err != KErrNone ) |
|
358 { |
|
359 CompleteNow( err ); |
|
360 } |
|
361 return ETrue; |
|
362 } |
|
363 |
|
364 return CAlfPerfAppBaseTestCaseControl::OfferEventL( aEvent ); |
|
365 } |
|
366 |
|
367 void CAlfPerfAppLayoutTestCaseControl::NextCycleL() |
|
368 { |
|
369 TAlfCustomEventCommand command( KAlfPerfAppLayoutCmdNext, this ); |
|
370 User::LeaveIfError( Env().Send( command, 500 ) ); |
|
371 |
|
372 iCycleCounter++; |
|
373 |
|
374 for(TInt i=0; i<10; i++) |
|
375 { |
|
376 iLayout->UpdateChildrenLayout(); |
|
377 } |
|
378 } |
|
379 |