1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @test |
|
20 @internalComponent |
|
21 |
|
22 This contains CT_DataFbsScreenDevice |
|
23 */ |
|
24 |
|
25 // User includes |
|
26 #include "T_DataFbsScreenDevice.h" |
|
27 #include "T_GraphicsUtil.h" |
|
28 |
|
29 /*@{*/ |
|
30 //Commands |
|
31 _LIT(KCmdNewL, "NewL"); |
|
32 _LIT(KCmdDestructor, "~"); |
|
33 |
|
34 _LIT(KCmdChangeScreenDevice, "ChangeScreenDevice"); |
|
35 _LIT(KCmdDrawSpriteBegin, "DrawSpriteBegin"); |
|
36 _LIT(KCmdDrawSpriteEnd, "DrawSpriteEnd"); |
|
37 _LIT(KCmdHardwareBitmap, "HardwareBitmap"); |
|
38 _LIT(KCmdScreenNo, "ScreenNo"); |
|
39 _LIT(KCmdSetAutoUpdate, "SetAutoUpdate"); |
|
40 _LIT(KCmdUpdate, "Update"); |
|
41 _LIT(KCmdCancelSprite, "CancelSprite"); |
|
42 _LIT(KCmdHideSprite, "HideSprite"); |
|
43 _LIT(KCmdShowSprite, "ShowSprite"); |
|
44 |
|
45 _LIT(KCmdDisown, "disown"); |
|
46 |
|
47 //Fields |
|
48 _LIT(KFldExpected, "expected"); |
|
49 _LIT(KLibName, "libname"); |
|
50 _LIT(KScreenNumber, "screen_number"); |
|
51 _LIT(KRgbColorRed, "rgb_red"); |
|
52 _LIT(KRgbColorGreen, "rgb_green"); |
|
53 _LIT(KRgbColorBlue, "rgb_blue"); |
|
54 _LIT(KDisplayMode, "displaymode"); |
|
55 _LIT(KAutoUpdate, "autoupdate"); |
|
56 _LIT(KRegion, "region"); |
|
57 _LIT(KFbsScreenDevice, "FbsScrDevName"); |
|
58 _LIT(KFldRect, "rect"); |
|
59 _LIT(KFldRegion, "region"); |
|
60 _LIT(KSpriteBase, "spritebase"); |
|
61 |
|
62 //Logging |
|
63 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
64 |
|
65 /*@}*/ |
|
66 /** |
|
67 * Two phase constructor |
|
68 */ |
|
69 CT_DataFbsScreenDevice* CT_DataFbsScreenDevice::NewL() |
|
70 { |
|
71 CT_DataFbsScreenDevice* ret = new (ELeave) CT_DataFbsScreenDevice(); |
|
72 CleanupStack::PushL(ret); |
|
73 ret->ConstructL(); |
|
74 CleanupStack::Pop(ret); |
|
75 return ret; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Protected constructor. First phase construction |
|
80 */ |
|
81 CT_DataFbsScreenDevice::CT_DataFbsScreenDevice() |
|
82 : CT_DataFbsDevice() |
|
83 , iFbsScreenDevice(NULL) |
|
84 { |
|
85 } |
|
86 |
|
87 /** |
|
88 * Protected second phase construction |
|
89 */ |
|
90 void CT_DataFbsScreenDevice::ConstructL() |
|
91 { |
|
92 } |
|
93 |
|
94 /** |
|
95 * Set the object that the data wraps |
|
96 * |
|
97 * @param aObject object that the wrapper is testing |
|
98 * |
|
99 */ |
|
100 void CT_DataFbsScreenDevice::SetObjectL(TAny* aAny) |
|
101 { |
|
102 DestroyData(); |
|
103 iFbsScreenDevice = static_cast<CFbsScreenDevice*> (aAny); |
|
104 } |
|
105 |
|
106 void CT_DataFbsScreenDevice::DisownObjectL() |
|
107 { |
|
108 iFbsScreenDevice = NULL; |
|
109 } |
|
110 |
|
111 /** |
|
112 * Destructor. |
|
113 */ |
|
114 CT_DataFbsScreenDevice::~CT_DataFbsScreenDevice() |
|
115 { |
|
116 DestroyData(); |
|
117 } |
|
118 |
|
119 void CT_DataFbsScreenDevice::DestroyData() |
|
120 { |
|
121 delete iFbsScreenDevice; |
|
122 iFbsScreenDevice=NULL; |
|
123 } |
|
124 |
|
125 MGraphicsDeviceMap* CT_DataFbsScreenDevice::GetGraphicsDeviceMap() const |
|
126 { |
|
127 return iFbsScreenDevice; |
|
128 } |
|
129 |
|
130 CGraphicsDevice* CT_DataFbsScreenDevice::GetGraphicsDevice() const |
|
131 { |
|
132 return iFbsScreenDevice; |
|
133 } |
|
134 |
|
135 CBitmapDevice* CT_DataFbsScreenDevice::GetBitmapDevice() const |
|
136 { |
|
137 return iFbsScreenDevice; |
|
138 } |
|
139 |
|
140 CFbsDevice* CT_DataFbsScreenDevice::GetFbsDevice() const |
|
141 { |
|
142 return iFbsScreenDevice; |
|
143 } |
|
144 |
|
145 /** |
|
146 * Return a pointer to the object that the data wraps |
|
147 * |
|
148 * @return pointer to the object that the data wraps |
|
149 */ |
|
150 TAny* CT_DataFbsScreenDevice::GetObject() |
|
151 { |
|
152 return iFbsScreenDevice; |
|
153 } |
|
154 |
|
155 /** |
|
156 * Process a command read from the ini file |
|
157 * |
|
158 * @param aDataWrapper test step requiring command to be processed |
|
159 * @param aCommand the command to process |
|
160 * @param aSection the entry in the ini file requiring the command to be processed |
|
161 * |
|
162 * @return ETrue if the command is processed |
|
163 */ |
|
164 TBool CT_DataFbsScreenDevice::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
165 { |
|
166 /* Another work package will complete the implement of this */ |
|
167 TBool retVal = ETrue; |
|
168 |
|
169 if ( aCommand == KCmdNewL ) |
|
170 { |
|
171 DoCmdNew(aSection); |
|
172 } |
|
173 else if (aCommand == KCmdDestructor) |
|
174 { |
|
175 DoCmdDestructor(); |
|
176 } |
|
177 else if (aCommand == KCmdChangeScreenDevice) |
|
178 { |
|
179 DoCmdChangeScreenDeviceL(aSection); |
|
180 } |
|
181 else if (aCommand == KCmdDrawSpriteBegin) |
|
182 { |
|
183 DoCmdDrawSpriteBegin(); |
|
184 } |
|
185 else if (aCommand == KCmdDrawSpriteEnd) |
|
186 { |
|
187 DoCmdDrawSpriteEnd(); |
|
188 } |
|
189 else if (aCommand == KCmdHardwareBitmap) |
|
190 { |
|
191 DoCmdHardwareBitmap(); |
|
192 } |
|
193 else if (aCommand == KCmdScreenNo) |
|
194 { |
|
195 DoCmdScreenNo(aSection); |
|
196 } |
|
197 else if (aCommand == KCmdSetAutoUpdate) |
|
198 { |
|
199 DoCmdSetAutoUpdate(aSection); |
|
200 } |
|
201 else if (aCommand == KCmdUpdate) |
|
202 { |
|
203 DoCmdUpdateL(aSection); |
|
204 } |
|
205 else if (aCommand == KCmdCancelSprite) |
|
206 { |
|
207 DoCmdCancelSprite(); |
|
208 } |
|
209 else if (aCommand == KCmdHideSprite) |
|
210 { |
|
211 DoCmdHideSpriteL(aSection); |
|
212 } |
|
213 else if (aCommand == KCmdShowSprite) |
|
214 { |
|
215 DoCmdShowSpriteL(aSection); |
|
216 } |
|
217 else if (aCommand == KCmdDisown) |
|
218 { |
|
219 DisownObjectL(); |
|
220 } |
|
221 else |
|
222 { |
|
223 retVal = CT_DataFbsDevice::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
224 } |
|
225 |
|
226 return retVal; |
|
227 } |
|
228 |
|
229 void CT_DataFbsScreenDevice::DoCmdNew(const TDesC& aSection) |
|
230 { |
|
231 DestroyData(); |
|
232 |
|
233 // get display mode from parameters |
|
234 TDisplayMode displayMode=ENone; |
|
235 TBool hasDisplayMode=CT_GraphicsUtil::ReadDisplayMode(*this, aSection, KDisplayMode(), displayMode); |
|
236 |
|
237 // get lib name from parameters |
|
238 |
|
239 TPtrC libName; |
|
240 TBool hasLibName=GetStringFromConfig(aSection, KLibName(), libName); |
|
241 |
|
242 TBool useRgb = EFalse; |
|
243 |
|
244 TInt red = 0; |
|
245 if(GetIntFromConfig(aSection, KRgbColorRed(), red)) |
|
246 { |
|
247 useRgb=ETrue; |
|
248 } |
|
249 |
|
250 TInt green = 0; |
|
251 if(GetIntFromConfig(aSection, KRgbColorGreen(), green)) |
|
252 { |
|
253 useRgb=ETrue; |
|
254 } |
|
255 |
|
256 TInt blue = 0; |
|
257 if(GetIntFromConfig(aSection, KRgbColorBlue(), blue)) |
|
258 { |
|
259 useRgb = ETrue; |
|
260 } |
|
261 |
|
262 // get screen number from parameters |
|
263 TInt screenNumber = 0; |
|
264 GetIntFromConfig(aSection, KScreenNumber(), screenNumber); |
|
265 |
|
266 TInt err=KErrNone; |
|
267 if ( !hasDisplayMode ) |
|
268 { |
|
269 // Find the best display mode |
|
270 for ( TDisplayMode testMode=TDisplayMode(ENone+1); testMode<EColorLast; testMode=TDisplayMode(testMode+1) ) |
|
271 { |
|
272 if ( hasLibName ) // if lib name is given |
|
273 { |
|
274 if ( useRgb ) |
|
275 { |
|
276 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, testMode, TRgb(red, green, blue))); |
|
277 } |
|
278 else |
|
279 { |
|
280 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, testMode)); |
|
281 } |
|
282 } |
|
283 else // if lib name is not given |
|
284 { |
|
285 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(screenNumber, testMode)); |
|
286 } |
|
287 |
|
288 // Test if Mode OK |
|
289 if ( err==KErrNone ) |
|
290 { |
|
291 displayMode=testMode; |
|
292 hasDisplayMode=ETrue; |
|
293 delete iFbsScreenDevice; |
|
294 iFbsScreenDevice=NULL; |
|
295 INFO_PRINTF2(_L("Mode %d supported"), testMode); |
|
296 } |
|
297 } |
|
298 } |
|
299 |
|
300 if ( hasDisplayMode ) |
|
301 { |
|
302 if ( hasLibName ) // if lib name is given |
|
303 { |
|
304 if ( useRgb ) |
|
305 { |
|
306 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, displayMode, TRgb(red, green, blue))); |
|
307 } |
|
308 else |
|
309 { |
|
310 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, displayMode)); |
|
311 } |
|
312 } |
|
313 else // if lib name is not given |
|
314 { |
|
315 TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(screenNumber, displayMode)); |
|
316 } |
|
317 |
|
318 if ( err!=KErrNone ) |
|
319 { |
|
320 ERR_PRINTF2(_L("NewL failed with error %d"), err); |
|
321 SetError(err); |
|
322 } |
|
323 } |
|
324 else |
|
325 { |
|
326 ERR_PRINTF1(_L("No Display Mode")); |
|
327 SetBlockResult(EFail); |
|
328 } |
|
329 } |
|
330 |
|
331 void CT_DataFbsScreenDevice::DoCmdDestructor() |
|
332 { |
|
333 DestroyData(); |
|
334 } |
|
335 |
|
336 void CT_DataFbsScreenDevice::DoCmdChangeScreenDeviceL(const TDesC& aSection) |
|
337 { |
|
338 TPtrC FbsScreenDevNameOld; |
|
339 CFbsScreenDevice* FbsScreenDevOld = NULL; |
|
340 |
|
341 if (GetStringFromConfig(aSection, KFbsScreenDevice, FbsScreenDevNameOld)) |
|
342 { |
|
343 FbsScreenDevOld = static_cast<CFbsScreenDevice*>(GetDataObjectL(FbsScreenDevNameOld)); |
|
344 INFO_PRINTF1(_L("FbsScreenDevice::ChangeScreenDevice(CFbsScreenDevice *aOldDevice) is called!")); |
|
345 iFbsScreenDevice->ChangeScreenDevice(FbsScreenDevOld); |
|
346 } |
|
347 else |
|
348 { |
|
349 INFO_PRINTF2(KLogMissingParameter, &KFbsScreenDevice); |
|
350 SetBlockResult(EFail); |
|
351 } |
|
352 } |
|
353 |
|
354 void CT_DataFbsScreenDevice::DoCmdDrawSpriteBegin() |
|
355 { |
|
356 INFO_PRINTF1(_L("FbsScreenDevice::DrawSpriteBegin() is called!")); |
|
357 iFbsScreenDevice->DrawSpriteBegin(); |
|
358 } |
|
359 |
|
360 void CT_DataFbsScreenDevice::DoCmdDrawSpriteEnd() |
|
361 { |
|
362 INFO_PRINTF1(_L("FbsScreenDevice::DrawSpriteEnd() is called!")); |
|
363 iFbsScreenDevice->DrawSpriteEnd(); |
|
364 } |
|
365 |
|
366 void CT_DataFbsScreenDevice::DoCmdHardwareBitmap() |
|
367 { |
|
368 INFO_PRINTF1(_L("FbsScreenDevice::HardwareBitmap() is called!")); |
|
369 RHardwareBitmap handle = iFbsScreenDevice->HardwareBitmap(); |
|
370 INFO_PRINTF2(_L("The actual handle from HardwareBitmap() is %d"), handle.iHandle); |
|
371 } |
|
372 |
|
373 void CT_DataFbsScreenDevice::DoCmdScreenNo(const TDesC& aSection) |
|
374 { |
|
375 // Execute command and log parameters |
|
376 INFO_PRINTF1(_L("FbsScreenDevice::ScreenNo() is called!")); |
|
377 TInt actual = iFbsScreenDevice->ScreenNo(); |
|
378 INFO_PRINTF2(_L("The actual result of ScreenNo() is %d"), actual); |
|
379 |
|
380 // Diaplay command return value, check if it matches the expected value |
|
381 TInt expected; |
|
382 if (!GetIntFromConfig(aSection, KFldExpected, expected)) |
|
383 { |
|
384 ERR_PRINTF2(KLogMissingParameter, &KFldExpected); |
|
385 SetBlockResult(EFail); |
|
386 } |
|
387 else |
|
388 { |
|
389 if (actual!=expected) |
|
390 { |
|
391 ERR_PRINTF3(_L("The expected result %d is not equal to the actual result %d!"), expected, actual); |
|
392 SetBlockResult(EFail); |
|
393 } |
|
394 } |
|
395 } |
|
396 |
|
397 void CT_DataFbsScreenDevice::DoCmdSetAutoUpdate(const TDesC& aSection) |
|
398 { |
|
399 TBool autoupdate; |
|
400 if (!GetBoolFromConfig(aSection, KAutoUpdate, autoupdate)) |
|
401 { |
|
402 ERR_PRINTF2(KLogMissingParameter, &KAutoUpdate); |
|
403 SetBlockResult(EFail); |
|
404 } |
|
405 else |
|
406 { |
|
407 iFbsScreenDevice->SetAutoUpdate(autoupdate); |
|
408 INFO_PRINTF2(_L("FbsScreenDevice::SetAutoUpdate(%d) has been called."), autoupdate); |
|
409 } |
|
410 } |
|
411 |
|
412 void CT_DataFbsScreenDevice::DoCmdUpdateL(const TDesC& aSection) |
|
413 { |
|
414 RRegion region(1); |
|
415 CleanupClosePushL(region); |
|
416 |
|
417 if (GetRegionFromConfig(aSection, KRegion(), region)) |
|
418 { |
|
419 INFO_PRINTF1(_L("FbsScreenDevice::Update(const TRegion &aRegion) has been called.")); |
|
420 iFbsScreenDevice->Update(region); |
|
421 } |
|
422 else |
|
423 { |
|
424 INFO_PRINTF1(_L("FbsScreenDevice::Update() has been called.")); |
|
425 iFbsScreenDevice->Update(); |
|
426 } |
|
427 CleanupStack::PopAndDestroy(®ion); |
|
428 } |
|
429 |
|
430 void CT_DataFbsScreenDevice::DoCmdCancelSprite() |
|
431 { |
|
432 INFO_PRINTF1(_L("execute CancelSprite()!")); |
|
433 iFbsScreenDevice->CancelSprite(); |
|
434 } |
|
435 |
|
436 void CT_DataFbsScreenDevice::DoCmdHideSpriteL(const TDesC& aSection) |
|
437 { |
|
438 TRect datRect; |
|
439 RRegion datRegion(1); |
|
440 CleanupClosePushL(datRegion); |
|
441 |
|
442 if (GetRectFromConfig(aSection, KFldRect, datRect)) |
|
443 { |
|
444 if (GetRegionFromConfig(aSection, KFldRegion, datRegion)) |
|
445 { |
|
446 INFO_PRINTF1(_L("execute HideSprite(const TRect &aRect, const TRegion *aClippingRegion)!")); |
|
447 TSpriteBase* spritebase = iFbsScreenDevice->HideSprite(datRect, &datRegion); |
|
448 } |
|
449 else |
|
450 { |
|
451 ERR_PRINTF2(KLogMissingParameter, &KFldRegion); |
|
452 SetBlockResult(EFail); |
|
453 } |
|
454 } |
|
455 else |
|
456 { |
|
457 INFO_PRINTF1(_L("execute HideSprite(void)!")); |
|
458 TSpriteBase* spritebase = iFbsScreenDevice->HideSprite(); |
|
459 } |
|
460 |
|
461 CleanupStack::PopAndDestroy(&datRegion); |
|
462 } |
|
463 |
|
464 |
|
465 void CT_DataFbsScreenDevice::DoCmdShowSpriteL(const TDesC& aSection) |
|
466 { |
|
467 TSpriteBase* spritebase = NULL; |
|
468 TPtrC SpriteBase; |
|
469 TRect datRect; |
|
470 RRegion datRegion(1); |
|
471 CleanupClosePushL(datRegion); |
|
472 |
|
473 if (GetStringFromConfig(aSection, KSpriteBase, SpriteBase)) |
|
474 { |
|
475 spritebase = static_cast<TSpriteBase*>(GetDataObjectL(SpriteBase)); |
|
476 } |
|
477 else |
|
478 { |
|
479 ERR_PRINTF2(KLogMissingParameter, &KSpriteBase); |
|
480 SetBlockResult(EFail); |
|
481 } |
|
482 |
|
483 if (GetRectFromConfig(aSection, KFldRect, datRect)) |
|
484 { |
|
485 if (GetRegionFromConfig(aSection, KFldRegion, datRegion)) |
|
486 { |
|
487 INFO_PRINTF1(_L("execute ShowSprite(TSpriteBase*, const TRect&, const TRegion*)!")); |
|
488 iFbsScreenDevice->ShowSprite(spritebase, datRect, &datRegion); |
|
489 } |
|
490 else |
|
491 { |
|
492 ERR_PRINTF2(KLogMissingParameter, &KFldRegion); |
|
493 SetBlockResult(EFail); |
|
494 } |
|
495 } |
|
496 else |
|
497 { |
|
498 INFO_PRINTF1(_L("execute ShowSprite(TSpriteBase*)!")); |
|
499 iFbsScreenDevice->ShowSprite(spritebase); |
|
500 } |
|
501 CleanupStack::PopAndDestroy(&datRegion); |
|
502 } |
|