|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <barsread.h> |
|
23 #include <basched.h> |
|
24 #include <coeaui.h> |
|
25 #include <eikappui.h> |
|
26 #include <eikapp.h> |
|
27 #include <eikdoc.h> |
|
28 #include <techview/eikdialg.h> |
|
29 #include <techview/eikchlst.h> |
|
30 #include <techview/eikchkbx.h> |
|
31 #include <techview/eikmfne.h> |
|
32 #include <techview/eikmenup.h> |
|
33 #include <eikenv.h> |
|
34 #include <ecom/ecom.h> |
|
35 |
|
36 #include <tbmpanim.rsg> |
|
37 #include <tbmpanim.mbg> |
|
38 #include "Tanctl.h" |
|
39 #include "TBMPAnim.hrh" |
|
40 |
|
41 #include <bmpancli.h> |
|
42 #include "TBmpAnimStep.h" |
|
43 |
|
44 |
|
45 |
|
46 _LIT(resourceFileName,"z:\\resource\\apps\\tbmpanim\\tbmpanim.rsc"); |
|
47 const TInt KArrayGranularity = 5; |
|
48 |
|
49 |
|
50 |
|
51 // Panics |
|
52 |
|
53 void CTestContainer::Panic(TContainerPanic aPanic) |
|
54 { |
|
55 _LIT(KPanicCat,"TBmpAnim-Animation"); |
|
56 User::Panic(KPanicCat, aPanic); |
|
57 } |
|
58 |
|
59 |
|
60 TAnimationAttributes::TAnimationAttributes() |
|
61 : iNumberOfCycles(-1) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 // |
|
67 // CAnimationDlg |
|
68 // |
|
69 |
|
70 CAnimationDlg::CAnimationDlg(TFileName aFileName) |
|
71 : iFileName(aFileName) |
|
72 { |
|
73 } |
|
74 |
|
75 CAnimationDlg::~CAnimationDlg() |
|
76 { |
|
77 if(iTimer) |
|
78 iTimer->Cancel(); |
|
79 delete iTimer; |
|
80 } |
|
81 void CAnimationDlg::PostLayoutDynInitL() |
|
82 { |
|
83 CAnimateFramesCtl* animationCtl = static_cast<CAnimateFramesCtl*>(Control(EBmpAnimationCtlId)); |
|
84 animationCtl->StartAnimationL(); |
|
85 |
|
86 |
|
87 TCallBack cb(Execute,this); |
|
88 iTimer = CPeriodic::NewL(EPriorityLow); |
|
89 iTimer->Start(TTimeIntervalMicroSeconds32(7000000), TTimeIntervalMicroSeconds32(1), cb); |
|
90 |
|
91 } |
|
92 |
|
93 TInt CAnimationDlg::Execute(TAny* aDialog) |
|
94 { |
|
95 CAnimationDlg* theDialog = (CAnimationDlg*) aDialog; |
|
96 theDialog->iTimer->Cancel(); |
|
97 delete theDialog->iTimer; |
|
98 theDialog->iTimer = 0; |
|
99 theDialog->TryExitL(-2); |
|
100 return 0; |
|
101 } |
|
102 |
|
103 TBool CAnimationDlg::OkToExitL(TInt /*aControlId*/) |
|
104 { |
|
105 static_cast<CAnimateFramesCtl*>(Control(EBmpAnimationCtlId))->CancelAnimationL(); |
|
106 return(ETrue); |
|
107 } |
|
108 |
|
109 SEikControlInfo CAnimationDlg::CreateCustomControlL(TInt aControlType) |
|
110 { |
|
111 SEikControlInfo controlInfo; |
|
112 controlInfo.iControl = NULL; |
|
113 controlInfo.iTrailerTextId = 0; |
|
114 controlInfo.iFlags = 0; |
|
115 if (aControlType == EBmpAnimationCtlType) |
|
116 { |
|
117 controlInfo.iControl = CAnimateFramesCtl::NewL(); |
|
118 static_cast<CAnimateFramesCtl*>(controlInfo.iControl)->SetFileName(iFileName); |
|
119 } |
|
120 return controlInfo; |
|
121 } |
|
122 |
|
123 // |
|
124 // |
|
125 // class CAnimation |
|
126 // |
|
127 |
|
128 |
|
129 |
|
130 CAnimation::CAnimation() |
|
131 : iIndex(0), |
|
132 iType(ENoAnimation) |
|
133 { |
|
134 } |
|
135 |
|
136 CAnimation::~CAnimation() |
|
137 { |
|
138 delete iAnimationCtl; |
|
139 } |
|
140 |
|
141 |
|
142 void CAnimation::SetAnimationExtent() |
|
143 { |
|
144 TSize animSize = iAnimationCtl->MinimumSize(); |
|
145 TPoint position(0, 0); |
|
146 switch (iType) |
|
147 { |
|
148 case EDefaultAnimation: |
|
149 position.SetXY(0, 0); |
|
150 break; |
|
151 case EDefaultAnimationSh: |
|
152 position.SetXY(100, 50); |
|
153 break; |
|
154 case EBallAnimation: |
|
155 position.SetXY(0, 100); |
|
156 break; |
|
157 case ERedPurpBallAnimationMaskedBackground: |
|
158 position.SetXY(0, 100); |
|
159 break; |
|
160 case ETBmpAnimBallAnimWindowCovering: |
|
161 position.SetXY(0, 100); |
|
162 break; |
|
163 default: |
|
164 return; |
|
165 } |
|
166 iAnimationCtl->SetExtent(position, animSize); |
|
167 } |
|
168 |
|
169 void CAnimation::CopyAttributesFromClientData() |
|
170 { |
|
171 CBitmapAnimClientData* animClientData = iAnimationCtl->BitmapAnimData(); |
|
172 if (animClientData) |
|
173 { |
|
174 iAttributes.iFrameIntervalInMilliSeconds = animClientData->FrameIntervalInMilliSeconds(); |
|
175 iAttributes.iPlayMode = animClientData->PlayMode(); |
|
176 } |
|
177 } |
|
178 |
|
179 class CTestContainer; |
|
180 |
|
181 |
|
182 // |
|
183 // |
|
184 // class CTestContainer |
|
185 // |
|
186 |
|
187 CTestContainer::CTestContainer() |
|
188 { |
|
189 } |
|
190 |
|
191 CTestContainer::~CTestContainer() |
|
192 { |
|
193 if (iAnimationsArray) |
|
194 iAnimationsArray->ResetAndDestroy(); |
|
195 delete iAnimationsArray; |
|
196 |
|
197 // Delete window used in test cases. |
|
198 delete iCoveringWindowControl; |
|
199 } |
|
200 |
|
201 // |
|
202 // |
|
203 void CTestContainer::ConstructL() |
|
204 { |
|
205 iColor = KRgbBlack; |
|
206 CreateWindowL(); |
|
207 RWindow window = Window(); |
|
208 window.SetTransparencyAlphaChannel(); |
|
209 window.SetBackgroundColor(TRgb(150,150,150,150)); |
|
210 iAnimationsArray=new(ELeave) CArrayPtrFlat<CAnimation>(KArrayGranularity); |
|
211 |
|
212 //Set the background of the container window to the default. |
|
213 iBackgroundType = EBackgroundBlackRedGreenYellowStripes; |
|
214 ActivateL(); |
|
215 |
|
216 //Construct a window that can be used in test cases. |
|
217 iCoveringWindowControl = new (ELeave) CTestWindowControl; |
|
218 iCoveringWindowControl->ConstructL(); |
|
219 } |
|
220 |
|
221 // |
|
222 // |
|
223 void CTestContainer::StartAnimationL(TInt aIndex) |
|
224 { |
|
225 TInt count = iAnimationsArray->Count(); |
|
226 __ASSERT_ALWAYS(iAnimationsArray, Panic(TContainerPanicNoArray)); |
|
227 __ASSERT_ALWAYS((aIndex >= 0 && (aIndex < count || aIndex == EAllAnimations)), Panic(TInvalidIndex)); |
|
228 TInt startIndex = 0; |
|
229 if (aIndex != EAllAnimations) |
|
230 { |
|
231 count = aIndex; |
|
232 startIndex = aIndex; |
|
233 } |
|
234 else |
|
235 count -= 1; |
|
236 for (TInt i=startIndex; i<=count; i++) |
|
237 { |
|
238 CAnimation* singleAnimationCtl = iAnimationsArray->At(i); |
|
239 if (singleAnimationCtl->iAttributes.iOnOff) |
|
240 { |
|
241 singleAnimationCtl->iAnimationCtl->StartAnimationL(); |
|
242 |
|
243 } |
|
244 } |
|
245 } |
|
246 |
|
247 void CTestContainer::CancelAnimationL(TInt aIndex) |
|
248 { |
|
249 TInt count = iAnimationsArray->Count(); |
|
250 __ASSERT_ALWAYS(iAnimationsArray, Panic(TContainerPanicNoArray)); |
|
251 __ASSERT_ALWAYS((aIndex >= 0 && (aIndex < count || aIndex == EAllAnimations)), Panic(TInvalidIndex)); |
|
252 TInt startIndex = 0; |
|
253 if (aIndex != EAllAnimations) |
|
254 { |
|
255 count = aIndex + 1; |
|
256 startIndex = aIndex; |
|
257 } |
|
258 for (TInt i=startIndex; i<count; i++) |
|
259 iAnimationsArray->At(i)->iAnimationCtl->CancelAnimationL(); |
|
260 } |
|
261 |
|
262 void CTestContainer::ShowAnimationL(TAnimationFlag aAnimationType) |
|
263 { |
|
264 TInt index = FindAnimation(aAnimationType); |
|
265 if (index == KErrNotFound) |
|
266 return; |
|
267 else |
|
268 StartAnimationL(index); |
|
269 } |
|
270 |
|
271 |
|
272 TInt CTestContainer::FindAnimation(TAnimationFlag aAnimationType) |
|
273 { |
|
274 TInt count = iAnimationsArray->Count(); |
|
275 __ASSERT_ALWAYS(iAnimationsArray, Panic(TContainerPanicNoArray)); |
|
276 TInt index = 0; |
|
277 for(index=0; index<count; index++) |
|
278 if (iAnimationsArray->At(index)->iType == aAnimationType) |
|
279 return index; |
|
280 return KErrNotFound; |
|
281 } |
|
282 |
|
283 CAnimation* CTestContainer::CreateAnimationByTypeL(TAnimationFlag aAnimationType) |
|
284 { |
|
285 __ASSERT_ALWAYS(iAnimationsArray, Panic(TContainerPanicNoArray)); |
|
286 TInt count = iAnimationsArray->Count(); |
|
287 CAnimation* singleAnimationCtl = new (ELeave) CAnimation; |
|
288 CleanupStack::PushL(singleAnimationCtl); |
|
289 singleAnimationCtl->iIndex = count; |
|
290 singleAnimationCtl->iType = aAnimationType; |
|
291 CAnimateFramesCtl* animationCtl = NULL; |
|
292 TRAPD(error, animationCtl = CAnimateFramesCtl::NewL()); |
|
293 if (error != KErrNone) |
|
294 User::Panic(_L("New Animation"), error); |
|
295 |
|
296 singleAnimationCtl->iAnimationCtl = animationCtl; |
|
297 animationCtl->SetFileName(iFileName); |
|
298 |
|
299 TInt resourceReaderId = 0; |
|
300 switch (aAnimationType) |
|
301 { |
|
302 case EDefaultAnimation: |
|
303 resourceReaderId = R_TBMPANIM_IMAGE1; |
|
304 break; |
|
305 case EDefaultAnimationSh: |
|
306 resourceReaderId = R_TBMPANIM_IMAGE1; |
|
307 break; |
|
308 case EBallAnimation: |
|
309 resourceReaderId = R_TBMPANIM_IMAGE3; |
|
310 break; |
|
311 case ERedPurpBallAnimationMaskedBackground: |
|
312 resourceReaderId = R_TBMPANIM_IMAGE4; |
|
313 break; |
|
314 case ETBmpAnimBallAnimWindowCovering: |
|
315 resourceReaderId = R_TBMPANIM_IMAGE5; |
|
316 break; |
|
317 default: |
|
318 delete singleAnimationCtl; |
|
319 return NULL; |
|
320 } |
|
321 |
|
322 TResourceReader reader; |
|
323 iCoeEnv->CreateResourceReaderLC(reader,resourceReaderId); |
|
324 animationCtl->ConstructFromResourceL(reader); |
|
325 CleanupStack::PopAndDestroy(); // reader |
|
326 singleAnimationCtl->SetAnimationExtent(); |
|
327 singleAnimationCtl->CopyAttributesFromClientData(); |
|
328 iAnimationsArray->AppendL(singleAnimationCtl); |
|
329 CleanupStack::Pop(); // singleAnimationCtl |
|
330 return singleAnimationCtl; |
|
331 } |
|
332 |
|
333 void CTestContainer::SizeChanged() |
|
334 { |
|
335 TInt count = 0; |
|
336 TRect rect = Rect(); |
|
337 if(iAnimationsArray) |
|
338 count = iAnimationsArray->Count(); |
|
339 for (TInt index = 0; index < count; index++) |
|
340 iAnimationsArray->At(index)->iAnimationCtl->SetRect(rect); |
|
341 } |
|
342 |
|
343 TInt CTestContainer::CountComponentControls() const |
|
344 { |
|
345 return iAnimationsArray->Count();; |
|
346 } |
|
347 |
|
348 void CTestContainer::Draw(const TRect& /*aRect*/) const |
|
349 { |
|
350 switch(iBackgroundType) |
|
351 { |
|
352 case EBackgroundBlackRedGreenYellowStripes: |
|
353 { |
|
354 const TRect rect=Rect(); |
|
355 CWindowGc& gc=SystemGc(); |
|
356 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
357 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
358 gc.SetBrushColor(iColor); |
|
359 TInt yOffset = rect.Height() / 4; |
|
360 TRect portionRect(rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iTl.iY + yOffset); |
|
361 gc.DrawRect(portionRect); |
|
362 gc.SetBrushColor(KRgbRed); |
|
363 portionRect.iTl.iY = portionRect.iBr.iY; |
|
364 portionRect.iBr.iY += yOffset; |
|
365 gc.DrawRect(portionRect); |
|
366 gc.SetBrushColor(KRgbGreen); |
|
367 portionRect.iTl.iY = portionRect.iBr.iY; |
|
368 portionRect.iBr.iY += yOffset; |
|
369 gc.DrawRect(portionRect); |
|
370 gc.SetBrushColor(KRgbYellow); |
|
371 portionRect.iTl.iY = portionRect.iBr.iY; |
|
372 portionRect.iBr.iY = rect.iBr.iY; |
|
373 gc.DrawRect(portionRect); |
|
374 gc.SetBrushColor(KRgbWhite); |
|
375 } |
|
376 break; |
|
377 case EBackgroundYellow: |
|
378 { |
|
379 const TRect rect=Rect(); |
|
380 CWindowGc& gc=SystemGc(); |
|
381 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
382 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
383 gc.SetBrushColor(KRgbYellow); |
|
384 gc.DrawRect(rect); |
|
385 } |
|
386 break; |
|
387 case EBackgroundBlue: |
|
388 { |
|
389 const TRect rect=Rect(); |
|
390 CWindowGc& gc=SystemGc(); |
|
391 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
392 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
393 gc.SetBrushColor(KRgbBlue); |
|
394 gc.DrawRect(rect); |
|
395 } |
|
396 break; |
|
397 default: |
|
398 break; |
|
399 } |
|
400 } |
|
401 |
|
402 CCoeControl* CTestContainer::ComponentControl(TInt aIndex) const |
|
403 { |
|
404 return iAnimationsArray->At(aIndex)->iAnimationCtl; |
|
405 } |
|
406 |
|
407 void CTestContainer::SetAppFileName(TDesC& aAppFileName) |
|
408 { |
|
409 iFileName = aAppFileName; |
|
410 } |
|
411 |
|
412 void CTestContainer::CreateAndRunAnimationL() |
|
413 { |
|
414 CAnimateFramesCtl* animationCtl = CAnimateFramesCtl::NewL(); |
|
415 CleanupStack::PushL(animationCtl); |
|
416 animationCtl->SetContainerWindowL(*this); |
|
417 animationCtl->SetFileName(iFileName); |
|
418 TResourceReader reader; |
|
419 iCoeEnv->CreateResourceReaderLC(reader, R_TBMPANIM_IMAGE3); |
|
420 animationCtl->ConstructFromResourceL(reader); |
|
421 CleanupStack::PopAndDestroy(); // reader |
|
422 animationCtl->StartAnimationL(); |
|
423 User::After(1000000); |
|
424 animationCtl->CancelAnimationL(); |
|
425 animationCtl->SetFrameIndexL(4); |
|
426 User::After(1000000); |
|
427 animationCtl->StartAnimationL(); |
|
428 User::After(1000000); |
|
429 animationCtl->SetPosition(TPoint(100, 100)); |
|
430 User::After(1000000); |
|
431 animationCtl->SetFrameIndexL(1); |
|
432 User::After(1000000); |
|
433 animationCtl->SetFrameIndexL(4); |
|
434 User::After(1000000); |
|
435 animationCtl->SetFrameIntervalL(100); |
|
436 User::After(1000000); |
|
437 CleanupStack::PopAndDestroy(); // animationCtl |
|
438 } |
|
439 |
|
440 |
|
441 void CTestContainer::SetAnimationAttributesL(TAnimationFlag aAnimationType) |
|
442 { |
|
443 // CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
444 // CSimpleAppUi* theApplication = (CSimpleAppUi*) (coeEnv->AppUi()); |
|
445 |
|
446 CAnimation* animation = NULL; |
|
447 TInt animationIndex = FindAnimation(aAnimationType); |
|
448 TBool notFound = (animationIndex == KErrNotFound ? ETrue : EFalse); |
|
449 if (notFound) |
|
450 { |
|
451 animation = CreateAnimationByTypeL(aAnimationType); |
|
452 if (animation) |
|
453 animationIndex = animation->iIndex; |
|
454 else |
|
455 return; |
|
456 } |
|
457 else |
|
458 animation = iAnimationsArray->At(animationIndex); |
|
459 |
|
460 animation->iAttributes.iOnOff=ETrue; |
|
461 |
|
462 if (notFound) |
|
463 { |
|
464 CAnimateFramesCtl* animationCtl = iAnimationsArray->At(animationIndex)->iAnimationCtl; |
|
465 animationCtl->SetAnimationCtlWindowL(this); |
|
466 animationCtl->SetExtent(animationCtl->Position(), animationCtl->MinimumSize()); |
|
467 animationCtl->ActivateL(); |
|
468 animationCtl->DrawNow(); |
|
469 } |
|
470 |
|
471 ShowAnimationL(aAnimationType); |
|
472 } |
|
473 /* |
|
474 * INC 133854, DEF136660 |
|
475 * |
|
476 * Tests that the background frame is drawn |
|
477 * |
|
478 * Actions: |
|
479 * 1. Create background frame |
|
480 * 2. Create another frame (atleast one frame is required to enter into the animation loop) |
|
481 * 3. Start the animation which displays both the frames on the screen |
|
482 * 4. Create a bitmap and blit into it the part of the screen where frame with background was displayed |
|
483 * 5. Create a bitmap and blit into it the background and frame bitmaps |
|
484 * 6. Compare the 2 bitmaps from step 4 and 5 (test fails if the 2 bitmaps dont match) |
|
485 * |
|
486 * Expected Result: The background bitmap is drawn and test passes |
|
487 */ |
|
488 TBool CTestContainer::TestRenderBackgroundFrameL() |
|
489 { |
|
490 TPoint pos(0,0); |
|
491 CAnimateFramesCtl* animationCtl = CAnimateFramesCtl::NewL(); |
|
492 CleanupStack::PushL(animationCtl); |
|
493 animationCtl->SetAnimationCtlWindowL(this); |
|
494 animationCtl->BitmapAnimData()->SetPlayMode(CBitmapAnimClientData::ECycle); |
|
495 animationCtl->ActivateL(); |
|
496 |
|
497 // set backgroud frame |
|
498 CFbsBitmap* backgroundBitmap = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath, EMbmTbmpanimTextured); |
|
499 CleanupStack::PushL(backgroundBitmap); |
|
500 CBitmapFrameData* backgroundFrame = CBitmapFrameData::NewL(backgroundBitmap); |
|
501 CleanupStack::PushL(backgroundFrame); |
|
502 animationCtl->BitmapAnimData()->SetBackgroundFrame(backgroundFrame); |
|
503 CleanupStack::Pop(2,backgroundBitmap); |
|
504 |
|
505 // set frame 1 |
|
506 CFbsBitmap* frame1Bitmap = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath, EMbmTbmpanimLink0); |
|
507 CleanupStack::PushL(frame1Bitmap); |
|
508 CFbsBitmap* frame1BitmapMask = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath, EMbmTbmpanimLink0m); |
|
509 CleanupStack::PushL(frame1BitmapMask); |
|
510 CBitmapFrameData* frame1 = CBitmapFrameData::NewL(frame1Bitmap,frame1BitmapMask); |
|
511 CleanupStack::PushL(frame1); |
|
512 animationCtl->BitmapAnimData()->AppendFrameL(frame1); |
|
513 CleanupStack::Pop(3,frame1Bitmap); //frame1, frame1BitmapMask, frame1Bitmap |
|
514 |
|
515 animationCtl->CompleteAnimationInitialisationL(); |
|
516 animationCtl->Animation()->StartL(); |
|
517 User::After(1000000); |
|
518 |
|
519 TBool ret=CompareScreenContentWithTestBitmapL(*backgroundFrame,*frame1, pos); |
|
520 |
|
521 animationCtl->Animation()->StopL(); |
|
522 CleanupStack::PopAndDestroy(); // animationCtl |
|
523 return ret; |
|
524 } |
|
525 |
|
526 TBool CTestContainer::CompareScreenContentWithTestBitmapL(const CBitmapFrameData& aBkgdFrame, const CBitmapFrameData& aFrame1, const TPoint& aPos) |
|
527 { |
|
528 TSize size = aFrame1.Bitmap()->SizeInPixels(); |
|
529 |
|
530 // Create test bitmap for comparison |
|
531 CFbsBitmap* testBitmap = new (ELeave) CFbsBitmap; |
|
532 CleanupStack::PushL(testBitmap); |
|
533 User::LeaveIfError( testBitmap->Create(size, iEikonEnv->DefaultDisplayMode())); |
|
534 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(testBitmap); |
|
535 CleanupStack::PushL(bitmapDevice); |
|
536 CFbsBitGc* bitmapGc = CFbsBitGc::NewL(); |
|
537 CleanupStack::PushL(bitmapGc); |
|
538 bitmapGc->Activate(bitmapDevice); |
|
539 // Blit the background bitmap |
|
540 bitmapGc->BitBlt(aPos, aBkgdFrame.Bitmap()); |
|
541 // Blit the frame bitmap with mask |
|
542 bitmapGc->BitBltMasked(aPos, aFrame1.Bitmap(), size, aFrame1.Mask(), ETrue); |
|
543 |
|
544 // Create bitmap and blit the screen contents into it for comparing it with test bitmap created above |
|
545 TRect rect(aPos,size); |
|
546 CFbsBitmap* scrBitmap = new (ELeave) CFbsBitmap; |
|
547 CleanupStack::PushL(scrBitmap); |
|
548 User::LeaveIfError(scrBitmap->Create(size, iEikonEnv->DefaultDisplayMode()) ); |
|
549 User::LeaveIfError( iEikonEnv->ScreenDevice()->CopyScreenToBitmap(scrBitmap,rect) ); |
|
550 |
|
551 TBool ret=CompareBitmapsL(testBitmap,scrBitmap); |
|
552 |
|
553 CleanupStack::PopAndDestroy(4); //scrBitmap, bitmapGc, bitmapDevice, testBitmap |
|
554 return ret; |
|
555 } |
|
556 |
|
557 /** |
|
558 Returns true if the contents of aBmp1 match the contents of aBmp2 |
|
559 */ |
|
560 TBool CTestContainer::CompareBitmapsL(CFbsBitmap* aBmp1, CFbsBitmap* aBmp2) |
|
561 { |
|
562 if (aBmp1 == NULL || aBmp2 == NULL) |
|
563 { |
|
564 return EFalse; |
|
565 } |
|
566 |
|
567 TInt width = aBmp1->SizeInPixels().iWidth; |
|
568 TInt height = aBmp1->SizeInPixels().iHeight; |
|
569 |
|
570 if (aBmp1->DisplayMode() == aBmp2->DisplayMode()) |
|
571 { |
|
572 TInt lineLen = CFbsBitmap::ScanLineLength(width,aBmp1->DisplayMode()); |
|
573 HBufC8* buf1 = HBufC8::NewMaxLC(lineLen); |
|
574 HBufC8* buf2 = HBufC8::NewMaxLC(lineLen); |
|
575 TPtr8 ptr1(buf1->Des()); |
|
576 TPtr8 ptr2(buf2->Des()); |
|
577 |
|
578 TInt row = 0; |
|
579 |
|
580 for (row = 0; row < height; ++row) |
|
581 { |
|
582 aBmp1->GetScanLine(ptr1,TPoint(0,row),width,aBmp1->DisplayMode()); |
|
583 aBmp2->GetScanLine(ptr2,TPoint(0,row),width,aBmp2->DisplayMode()); |
|
584 if (ptr1!=ptr2) |
|
585 { |
|
586 CleanupStack::PopAndDestroy(buf2); |
|
587 CleanupStack::PopAndDestroy(buf1); |
|
588 return EFalse; |
|
589 } |
|
590 } |
|
591 CleanupStack::PopAndDestroy(buf2); |
|
592 CleanupStack::PopAndDestroy(buf1); |
|
593 } |
|
594 else |
|
595 { |
|
596 TRgb p1(0,0,0); |
|
597 TRgb p2(0,0,0); |
|
598 |
|
599 TInt i = 0; |
|
600 for(i = 0; i < width; i++) |
|
601 { |
|
602 TInt j = 0; |
|
603 for(j = 0; j < height; j++) |
|
604 { |
|
605 aBmp1->GetPixel(p1, TPoint(i, j)); |
|
606 aBmp2->GetPixel(p2, TPoint(i, j)); |
|
607 if(p1 != p2) |
|
608 { |
|
609 return EFalse; |
|
610 } |
|
611 } |
|
612 } |
|
613 } |
|
614 return ETrue; |
|
615 } |
|
616 |
|
617 |
|
618 /* |
|
619 |
|
620 Used by test case to display a gray filled window |
|
621 |
|
622 */ |
|
623 void CTestContainer::DisplayAnimCoveringWindowL() |
|
624 { |
|
625 iCoveringWindowControl->MakeVisible(ETrue); |
|
626 iCoveringWindowControl->DrawNow(); |
|
627 } |
|
628 |
|
629 /* |
|
630 |
|
631 CTestWindowControl, displays a gray filled window |
|
632 |
|
633 */ |
|
634 CTestWindowControl::CTestWindowControl() |
|
635 { |
|
636 } |
|
637 |
|
638 CTestWindowControl::~CTestWindowControl() |
|
639 { |
|
640 } |
|
641 |
|
642 void CTestWindowControl::ConstructL() |
|
643 { |
|
644 // Set test window control slightly smaller than the size of ball anim window. |
|
645 // So that the animation can be seen behind the covering window. |
|
646 CreateWindowL(); |
|
647 |
|
648 // Set the size before activating. |
|
649 SetRect(TRect(0,100,200,200)); |
|
650 |
|
651 //Set the window invisible |
|
652 MakeVisible(EFalse); |
|
653 |
|
654 ActivateL(); |
|
655 } |
|
656 |
|
657 void CTestWindowControl::Draw(const TRect& /*aRect*/) const |
|
658 { |
|
659 //Set the covering window to be filled gray. |
|
660 const TRect rect=Rect(); |
|
661 CWindowGc& gc=SystemGc(); |
|
662 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
663 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
664 gc.SetBrushColor(KRgbGray); |
|
665 gc.DrawRect(rect); |
|
666 } |
|
667 |
|
668 // |
|
669 // |
|
670 // class CSimpleAppUi |
|
671 // |
|
672 |
|
673 /** |
|
674 |
|
675 |
|
676 @SYMTestCaseID UIF-TBMPAnimStep-RunAnimWithMaskedBgL |
|
677 |
|
678 @SYMPREQ CR Number PHAR-5JHGVF. |
|
679 |
|
680 @SYMTestCaseDesc Tests that the masked background of the animation is displayed correctly\n |
|
681 when the bitmap animation passes over the animation masked background area.\n |
|
682 Also tests that the masked bitmap of the animation is displayed correctly.\n |
|
683 |
|
684 @SYMTestPriority High |
|
685 |
|
686 @SYMTestStatus Implemented |
|
687 |
|
688 @SYMTestActions Call RunAnimWithMaskedBgL() which does the following:\n |
|
689 (1) Sets the flag to set the animation container window colour (yellow).\n |
|
690 (2) Call the window control DrawNow to display the window control.\n |
|
691 (3) Calls the control fn to set up and run the requested animation.\n |
|
692 |
|
693 API Calls:\n |
|
694 CCoeControl::DrawNow()\n |
|
695 RBitmapAnim::StartL(), through the animation control in TAnctl.cpp\n |
|
696 |
|
697 @SYMTestExpectedResults The ball bitmap animation will be displayed on a yellow background,\n |
|
698 with the area surrounding the ball being yellow. The bitmap will then pass over its masked background which is green.\n |
|
699 The area surrounding the red ball will then be green and the masked bg will be displayed in place of the yellow window bg.\n |
|
700 Additionally, the masked bitmap animation will only display the red ball\n |
|
701 and the surrounding pixels of the ball bitmap will be transparent and display\n |
|
702 whatever is surrounding the ball at the time of the animation.\n |
|
703 The surrounding pixels of the ball bitmap are initially purple before the bitmap mask is applied.\n |
|
704 |
|
705 |
|
706 */ |
|
707 void CSimpleAppUi::RunAnimWithMaskedBgL() |
|
708 { |
|
709 //Switches from the default window background to a yellow one. |
|
710 iContainer->iBackgroundType = CTestContainer::EBackgroundYellow; |
|
711 iContainer->DrawNow(); |
|
712 |
|
713 //Run the animation. |
|
714 iContainer->SetAnimationAttributesL(ERedPurpBallAnimationMaskedBackground); |
|
715 } |
|
716 |
|
717 |
|
718 /** |
|
719 @SYMTestCaseID UIF-TBMPAnimStep-RunAnimWithWindowCoveringL |
|
720 |
|
721 @SYMPREQ Defect Numbers INC039385 & INC040604 implemented in CR Number PHAR-5JHGVF. |
|
722 |
|
723 @SYMTestCaseDesc Tests that the animation redraws itself correctly,\n |
|
724 when it is initially covered by another window and then the animation is uncovered,\n |
|
725 removing the covering window.\n |
|
726 |
|
727 @SYMTestPriority High |
|
728 |
|
729 @SYMTestStatus Implemented |
|
730 |
|
731 @SYMTestActions Call RunAnimWithWindowCoveringL() which does the following:\n |
|
732 (1) Sets the flag to set the container control window colour (blue).\n |
|
733 (2) Call the window control DrawNow to display the container window control\n |
|
734 (filled in blue).\n |
|
735 (3) Calls the control fn to display a gray window partially covering\n |
|
736 the ball animation and run the requested animation.\n |
|
737 (4) Runs the ball animation and then deletes the covering window.\n |
|
738 API Calls:\n |
|
739 CCoeControl::DrawNow()\n |
|
740 RBitmapAnim::StartL(), through the animation control in TAnctl.cpp\n |
|
741 |
|
742 @SYMTestExpectedResults The covering window is displayed in gray on a blue window.\n |
|
743 The yellow ball animation starts running behind the gray covering window.\n |
|
744 The animation should be seen behind the gray covering window.\n |
|
745 The gray covering window is removed. The ball animation should be running,\n |
|
746 yellow ball on blue background.\n |
|
747 |
|
748 */ |
|
749 void CSimpleAppUi::RunAnimWithWindowCoveringL() |
|
750 { |
|
751 // Set the container window control to be filled blue. |
|
752 iContainer->iBackgroundType = CTestContainer::EBackgroundBlue; |
|
753 iContainer->DrawNow(); |
|
754 |
|
755 // Setup and display the window control, filled in grey, which will initially cover animation. |
|
756 // Then the window is removed. |
|
757 iContainer->DisplayAnimCoveringWindowL(); |
|
758 |
|
759 // Run the animation. |
|
760 iContainer->SetAnimationAttributesL(ETBmpAnimBallAnimWindowCovering); |
|
761 } |
|
762 |
|
763 |
|
764 |
|
765 CSimpleAppUi::CSimpleAppUi(CTmsTestStep* aStep) : |
|
766 CTestAppUi(aStep, resourceFileName, R_ANIM_HOTKEYS,R_ANIM_MENUBAR, R_TANIM_TOOLBAR) |
|
767 { |
|
768 } |
|
769 |
|
770 CSimpleAppUi::~CSimpleAppUi() |
|
771 { |
|
772 delete iContainer; |
|
773 } |
|
774 |
|
775 void CSimpleAppUi::ConstructL() |
|
776 { |
|
777 CTestAppUi::ConstructL(); |
|
778 //BaseConstructL(); |
|
779 ConstructContainerL(); |
|
780 AutoTestManager().StartAutoTest(); |
|
781 } |
|
782 |
|
783 void CSimpleAppUi::ConstructContainerL() |
|
784 { |
|
785 TRect boundingRect=ClientRect(); // make toolband stretch to the screen width by default |
|
786 iContainer=new(ELeave) CTestContainer; |
|
787 iContainer->ConstructL(); |
|
788 |
|
789 ReduceRect(boundingRect); |
|
790 iContainer->SetRect(boundingRect); |
|
791 //vmTFileName tempFileName(Application()->BitmapStoreName()); |
|
792 TFileName tempFileName(KTBmpAnimMBMFilePath); |
|
793 iContainer->SetAppFileName(tempFileName); |
|
794 iContainer->DrawNow(); |
|
795 } |
|
796 |
|
797 |
|
798 void CSimpleAppUi::HandleCommandL(TInt aCommand) |
|
799 { |
|
800 switch (aCommand) |
|
801 { |
|
802 case ETBmpAnimCmdStart: |
|
803 if (iContainer) |
|
804 iContainer->StartAnimationL(EAllAnimations); |
|
805 break; |
|
806 case ETBmpAnimCmdStop: |
|
807 if (iContainer) |
|
808 iContainer->CancelAnimationL(EAllAnimations); |
|
809 break; |
|
810 case ETBmpAnimCmdDefault: |
|
811 iContainer->SetAnimationAttributesL(EDefaultAnimation); |
|
812 break; |
|
813 case ETBmpAnimCmdDefaultSh: |
|
814 iContainer->SetAnimationAttributesL(EDefaultAnimationSh); |
|
815 break; |
|
816 case ETBmpAnimCmdBall: |
|
817 iContainer->SetAnimationAttributesL(EBallAnimation); |
|
818 break; |
|
819 case ETBmpAnimCmdMemoryTest: |
|
820 CmdTestOutOfMemoryL(); |
|
821 break; |
|
822 case ETBmpAnimCmdAutoTestDLL: |
|
823 break; |
|
824 case ETBmpAnimCmdDlgWithAnim1: |
|
825 DialogWithAnimationL(R_TBMPANIM_DIALOG_WITH_ANIMATED_BALL); |
|
826 break; |
|
827 case ETBmpAnimCmdDlgWithAnim2: |
|
828 DialogWithAnimationL(R_TBMPANIM_DIALOG_WITH_FLOATING_SHEET); |
|
829 break; |
|
830 case ETBmpAnimCmdRedPurpBallMaskedBackground: |
|
831 // Run ball animation with masked background test case. |
|
832 RunAnimWithMaskedBgL(); |
|
833 break; |
|
834 case ETBmpAnimCmdBallAnimWindowCovering: |
|
835 // Run ball animation test case, firstly with an opaque window, partly covering the animation. |
|
836 RunAnimWithWindowCoveringL(); |
|
837 break; |
|
838 case ETBmpAnimCmdBackgroundBitmap: |
|
839 if (!iContainer->TestRenderBackgroundFrameL()) |
|
840 { |
|
841 iTestResult=CAutoTestManager::EFailed; |
|
842 } |
|
843 break; |
|
844 case EEikCmdExit: |
|
845 if (iContainer) |
|
846 iContainer->CancelAnimationL(EAllAnimations); |
|
847 CBaActiveScheduler::Exit(); |
|
848 break; |
|
849 default: |
|
850 break; |
|
851 } |
|
852 } |
|
853 |
|
854 |
|
855 |
|
856 void CSimpleAppUi::RunTestStepL(TInt aNumStep) |
|
857 { |
|
858 switch(aNumStep) |
|
859 { |
|
860 case 1: |
|
861 INFO_PRINTF1(_L("Default animation")); |
|
862 HandleCommandL(ETBmpAnimCmdDefault); |
|
863 break; |
|
864 case 2: |
|
865 INFO_PRINTF1(_L("Default animation Sh")); |
|
866 HandleCommandL(ETBmpAnimCmdDefaultSh); |
|
867 break; |
|
868 case 3: |
|
869 User::After(5000000); |
|
870 INFO_PRINTF1(_L("Ball animation")); |
|
871 HandleCommandL(ETBmpAnimCmdBall); |
|
872 break; |
|
873 case 4: |
|
874 INFO_PRINTF1(_L("Stop all animations")); |
|
875 User::After(10000000); |
|
876 HandleCommandL(ETBmpAnimCmdStop); |
|
877 case 5: |
|
878 INFO_PRINTF1(_L("Test out of memory")); |
|
879 HandleCommandL(ETBmpAnimCmdMemoryTest); |
|
880 break; |
|
881 case 6: |
|
882 INFO_PRINTF1(_L("Test dialog with animated ball")); |
|
883 HandleCommandL(ETBmpAnimCmdDlgWithAnim1); |
|
884 break; |
|
885 case 7: |
|
886 INFO_PRINTF1(_L("Test dialog with floating sheet")); |
|
887 HandleCommandL(ETBmpAnimCmdDlgWithAnim2); |
|
888 break; |
|
889 case 8: |
|
890 { |
|
891 // Stop all animations. |
|
892 HandleCommandL(ETBmpAnimCmdStop); |
|
893 |
|
894 // Run animation test case to test masked background and masked bitmap anim. |
|
895 SetTestStepID(_L("UIF-TBMPAnimStep-RunAnimWithMaskedBgL")); |
|
896 INFO_PRINTF1(_L("Running ball animation with a masked background")); |
|
897 HandleCommandL(ETBmpAnimCmdRedPurpBallMaskedBackground); |
|
898 RecordTestResultL(); |
|
899 } |
|
900 break; |
|
901 |
|
902 case 9: |
|
903 { |
|
904 // Wait to display test case. |
|
905 INFO_PRINTF1(_L("Waiting to display animation on screen.......")); |
|
906 User::After(5000000); |
|
907 |
|
908 // Stop test case. |
|
909 INFO_PRINTF1(_L("Stopping Animation......")); |
|
910 HandleCommandL(ETBmpAnimCmdStop); |
|
911 |
|
912 //Reset container control window back to yellow. |
|
913 INFO_PRINTF1(_L("Reset window back to all yellow.....")); |
|
914 iContainer->iBackgroundType = CTestContainer::EBackgroundYellow; |
|
915 iContainer->DrawNow(); |
|
916 |
|
917 INFO_PRINTF1(_L("Completed reset after test case.")); |
|
918 } |
|
919 break; |
|
920 |
|
921 case 10: |
|
922 { |
|
923 // Run animation test case to test animation redraws correctly after |
|
924 // a window covering the animation is removed. |
|
925 SetTestStepID(_L("UIF-TBMPAnimStep-RunAnimWithWindowCoveringL")); |
|
926 INFO_PRINTF1(_L("A covering window with ball animation running behind, then window removed to display anim")); |
|
927 HandleCommandL(ETBmpAnimCmdBallAnimWindowCovering); |
|
928 RecordTestResultL(); |
|
929 CloseTMSGraphicsStep(); |
|
930 } |
|
931 break; |
|
932 |
|
933 case 11: |
|
934 { |
|
935 // Wait to display test case. |
|
936 INFO_PRINTF1(_L("Waiting to display animation on screen.......")); |
|
937 User::After(5000000); |
|
938 |
|
939 //Remove the covering window. |
|
940 iContainer->iCoveringWindowControl->MakeVisible(EFalse); |
|
941 } |
|
942 break; |
|
943 |
|
944 case 12: |
|
945 { |
|
946 // Stop previous animation |
|
947 HandleCommandL(ETBmpAnimCmdStop); |
|
948 |
|
949 INFO_PRINTF1(_L("TestRenderBackgroundFrame")); |
|
950 HandleCommandL(ETBmpAnimCmdBackgroundBitmap); |
|
951 if (iTestResult==CAutoTestManager::EFailed) |
|
952 { |
|
953 ERR_PRINTF1(_L("TestRenderBackgroundFrame FAILED")); |
|
954 iStep->SetTestStepResult(EFail); |
|
955 } |
|
956 } |
|
957 break; |
|
958 |
|
959 case 13: |
|
960 { |
|
961 // Stop all animations. |
|
962 HandleCommandL(ETBmpAnimCmdStop); |
|
963 |
|
964 // Stop test cases running and exit. |
|
965 AutoTestManager().FinishAllTestCases(iTestResult); |
|
966 } |
|
967 break; |
|
968 } |
|
969 } |
|
970 |
|
971 void CSimpleAppUi::CmdTestOutOfMemoryL() |
|
972 { |
|
973 // __ASSERT_ALWAYS(iContainer, CTestContainer::Panic(TContainerInalidPointer)); |
|
974 // Creates and deletes to bitmaps in order to allocate filename in the cache for FBserv |
|
975 CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath/*Application()->BitmapStoreName()*/, 0); |
|
976 CFbsBitmap* mask = iEikonEnv->CreateBitmapL(KTBmpAnimMBMFilePath/*Application()->BitmapStoreName()*/, 1); |
|
977 delete bitmap; |
|
978 delete mask; |
|
979 iContainer->CancelAnimationL(EAllAnimations); |
|
980 TInt error = KErrNoMemory; |
|
981 iEikonEnv->BusyMsgL(_L("OOMemory Test")); |
|
982 __UHEAP_RESET; |
|
983 for(TInt fail=0; error != KErrNone; fail++) |
|
984 { |
|
985 __UHEAP_SETFAIL(RHeap::EFailNext, fail); // turn failure on |
|
986 __UHEAP_MARK; |
|
987 TRAP(error, iContainer->CreateAndRunAnimationL()); |
|
988 if ( (error != KErrNoMemory) && (error != KErrNone) ) |
|
989 User::Panic(_L("Memory Test"), error); |
|
990 REComSession::FinalClose(); |
|
991 __UHEAP_MARKEND; |
|
992 } |
|
993 __UHEAP_SETFAIL(RHeap::ENone, 0); // turn failure off |
|
994 iEikonEnv->BusyMsgCancel(); |
|
995 iEikonEnv->InfoMsg(_L("OOMemory test completed")); |
|
996 } |
|
997 |
|
998 void CSimpleAppUi::DialogWithAnimationL(TInt aResourceId) |
|
999 { |
|
1000 TPtrC ptr; |
|
1001 ptr.Set(KTBmpAnimMBMFilePath/*Application()->BitmapStoreName()*/); |
|
1002 |
|
1003 |
|
1004 CEikDialog* dialog = new (ELeave) CAnimationDlg(ptr); |
|
1005 dialog->ExecuteLD(aResourceId); |
|
1006 } |
|
1007 |
|
1008 void CTBmpAnimStep::ConstructAppL(CEikonEnv* aCoe) |
|
1009 { // runs inside a TRAP harness |
|
1010 aCoe->ConstructL(); |
|
1011 CSimpleAppUi* appUi=new(ELeave) CSimpleAppUi(this); |
|
1012 aCoe->SetAppUi(appUi); |
|
1013 appUi->ConstructL(); |
|
1014 } |
|
1015 |
|
1016 |
|
1017 CTBmpAnimStep::~CTBmpAnimStep() |
|
1018 /** |
|
1019 Destructor |
|
1020 */ |
|
1021 { |
|
1022 } |
|
1023 |
|
1024 CTBmpAnimStep::CTBmpAnimStep() |
|
1025 /** |
|
1026 Constructor |
|
1027 */ |
|
1028 { |
|
1029 // Call base class method to set up the human readable name for logging |
|
1030 SetTestStepName(KTBmpAnimStep); |
|
1031 } |
|
1032 |
|
1033 |
|
1034 TVerdict CTBmpAnimStep::doTestStepL() |
|
1035 { |
|
1036 INFO_PRINTF1(_L("Test Started")); |
|
1037 |
|
1038 PreallocateHALBuffer(); |
|
1039 |
|
1040 __UHEAP_MARK; |
|
1041 |
|
1042 CEikonEnv* coe=new CEikonEnv; |
|
1043 TRAPD(err,ConstructAppL(coe)); |
|
1044 |
|
1045 if (!err) |
|
1046 coe->ExecuteD(); |
|
1047 |
|
1048 // test.End(); |
|
1049 INFO_PRINTF1(_L("Test Finished")); |
|
1050 |
|
1051 REComSession::FinalClose(); |
|
1052 __UHEAP_MARKEND; |
|
1053 |
|
1054 return TestStepResult(); |
|
1055 } |
|
1056 |
|
1057 |