|
1 // Copyright (c) 1995-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 <w32stdgraphic.h> |
|
23 #include <imageconversion.h> |
|
24 #include "testbase.h" |
|
25 #include "testbase.h" |
|
26 |
|
27 // Bitmap to load for tests |
|
28 #define MY_TEST_BITMAP _L("Z:\\WSTEST\\MYTEST.MBM") |
|
29 |
|
30 // Animation to load for tests |
|
31 _LIT(KSymBallFile, "Z:\\WSTEST\\symball.gif"); |
|
32 |
|
33 // Executables for different sharing of graphic tests |
|
34 _LIT(KTestExe1, "TWSGRAPHICSHARETEST.exe"); |
|
35 _LIT(KTestExe2, "TWSGRAPHICSHAREGLOBALTEST.exe"); |
|
36 _LIT(KTestExe3, "TWSGRAPHICUNSHAREGLOBALTEST.exe"); |
|
37 _LIT(KTestExe4, "TWSGRAPHICSHARESECURETEST.exe"); |
|
38 _LIT(KTestExe5, "TWSGRAPHICUNSHARESECURETEST.exe"); |
|
39 |
|
40 // Graphic is shared or not in executeable |
|
41 _LIT(KShare, " true"); |
|
42 _LIT(KNoShare, " false"); |
|
43 |
|
44 TUid KUidTestAnimation = {0x87654321}; |
|
45 const TInt KDummyGraphicId = 99; |
|
46 const TInt KMaxLogLength = 256; |
|
47 const TInt KAnimationRunTime = 5000000; // 5 seconds max time to run a single animation loop |
|
48 |
|
49 // Animation loader |
|
50 class CIclLoader: public CActive |
|
51 { |
|
52 public: |
|
53 CIclLoader(); |
|
54 ~CIclLoader(); |
|
55 void ConstructL(const TDesC& aFileName, TBool aUseUID, TBool aReplace); |
|
56 const TWsGraphicId GetId(); |
|
57 inline TInt FrameCount() const {return iTotalFrames;}; |
|
58 inline TBool Ok() const {return !iFailed;}; |
|
59 protected: |
|
60 void RunL(); |
|
61 TInt RunError(TInt aError); |
|
62 void DoCancel(); |
|
63 private: |
|
64 void TestL(TInt aCondition); |
|
65 CImageDecoder* iDecoder; |
|
66 CWsGraphicBitmapAnimation* iTestAnimation; |
|
67 TLogMessageText iTestLog; |
|
68 TBool iUseUID; |
|
69 TBool iReplace; |
|
70 RPointerArray<CWsGraphicBitmapAnimation::CFrame> iFrames; |
|
71 TInt iTotalFrames; |
|
72 void NextL(); |
|
73 RFs iFs; |
|
74 TBool iFailed; |
|
75 }; |
|
76 |
|
77 CIclLoader::CIclLoader(): |
|
78 CActive(CActive::EPriorityLow) |
|
79 { |
|
80 CActiveScheduler::Add(this); |
|
81 } |
|
82 |
|
83 CIclLoader::~CIclLoader() |
|
84 { |
|
85 if (iTestAnimation) |
|
86 { |
|
87 delete iTestAnimation; |
|
88 iTestAnimation = NULL; |
|
89 } |
|
90 if (iDecoder) |
|
91 { |
|
92 delete iDecoder; |
|
93 iDecoder = NULL; |
|
94 } |
|
95 iFrames.ResetAndDestroy(); |
|
96 iFs.Close(); |
|
97 } |
|
98 |
|
99 const TWsGraphicId CIclLoader::GetId() |
|
100 { |
|
101 if (iTestAnimation) |
|
102 { |
|
103 return iTestAnimation->Id(); |
|
104 } |
|
105 else |
|
106 { |
|
107 TWsGraphicId id(KDummyGraphicId); |
|
108 return id; |
|
109 } |
|
110 } |
|
111 |
|
112 void CIclLoader::TestL(TInt aCondition) |
|
113 { |
|
114 if(!aCondition) |
|
115 { |
|
116 RWsSession rWs; |
|
117 User::LeaveIfError(rWs.Connect()); |
|
118 TBuf<KMaxLogLength> buf; |
|
119 _LIT(Fail,"AUTO Failed in WsGraphics Test : CIclLoader"); |
|
120 buf.Append(Fail); |
|
121 buf.Append(iTestLog); |
|
122 rWs.LogMessage(buf); |
|
123 rWs.Flush(); |
|
124 rWs.Close(); |
|
125 User::Leave(KErrGeneral); |
|
126 } |
|
127 } |
|
128 |
|
129 void CIclLoader::ConstructL(const TDesC& aFileName, TBool aUseUID,TBool aReplace) |
|
130 { |
|
131 iUseUID = aUseUID; |
|
132 iReplace = aReplace; |
|
133 |
|
134 User::LeaveIfError(iFs.Connect()); |
|
135 |
|
136 iDecoder = CImageDecoder::FileNewL(iFs,aFileName); |
|
137 if(!iDecoder->IsImageHeaderProcessingComplete()) |
|
138 { |
|
139 User::Leave(KErrGeneral); |
|
140 } |
|
141 NextL(); |
|
142 } |
|
143 |
|
144 void CIclLoader::NextL() |
|
145 { |
|
146 // Load a frame from the animation |
|
147 if (iDecoder && (iDecoder->FrameCount() > iFrames.Count())) |
|
148 { |
|
149 const TFrameInfo& info = iDecoder->FrameInfo(iFrames.Count()); |
|
150 CWsGraphicBitmapAnimation::CFrame* frame = CWsGraphicBitmapAnimation::CFrame::NewL(); |
|
151 CleanupStack::PushL(frame); |
|
152 iFrames.AppendL(frame); |
|
153 CleanupStack::Pop(frame); |
|
154 frame->SetFrameInfo(info); |
|
155 TFrameInfo copiedInfo = frame->FrameInfo(); |
|
156 TestL(info.iFlags==copiedInfo.iFlags); |
|
157 |
|
158 TSize bmpSize(info.iFrameCoordsInPixels.Size()); |
|
159 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; |
|
160 frame->SetBitmap(bitmap); //takes ownership |
|
161 User::LeaveIfError(bitmap->Create(bmpSize,info.iFrameDisplayMode)); |
|
162 |
|
163 TDisplayMode maskDispMode; |
|
164 CFbsBitmap* mask = new(ELeave) CFbsBitmap; |
|
165 frame->SetMask(mask); //takes ownership |
|
166 if((TFrameInfo::EAlphaChannel|TFrameInfo::ETransparencyPossible) & info.iFlags) |
|
167 { |
|
168 maskDispMode = EGray256; |
|
169 } |
|
170 else |
|
171 { |
|
172 maskDispMode = EGray2; |
|
173 } |
|
174 |
|
175 User::LeaveIfError(mask->Create(info.iFrameCoordsInPixels.Size(),maskDispMode)); |
|
176 iDecoder->Convert(&iStatus,*bitmap,*mask,iFrames.Count()-1); |
|
177 |
|
178 SetActive(); |
|
179 } |
|
180 |
|
181 // if a frame loaded |
|
182 else if(iFrames.Count()) |
|
183 { |
|
184 _LIT_SECURE_ID(KTestSecId,0x12345678); |
|
185 |
|
186 // The extra code around the NewL is checking that no heap failures occur when |
|
187 // creating the CWsGraphicBitmapAnimation |
|
188 TInt failRate = 1; |
|
189 const TInt KMaxIteration = 1000; |
|
190 for (;failRate < KMaxIteration; failRate++) |
|
191 { |
|
192 __UHEAP_RESET; |
|
193 __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); |
|
194 __UHEAP_MARK; |
|
195 |
|
196 TInt err = KErrGeneral; |
|
197 if (iUseUID) |
|
198 {// creating animation using UID |
|
199 TRAP(err, iTestAnimation = CWsGraphicBitmapAnimation::NewL(KUidTestAnimation,iFrames.Array());); |
|
200 } |
|
201 else |
|
202 {// creating using transient ID allocated by wserv |
|
203 TRAP(err, iTestAnimation = CWsGraphicBitmapAnimation::NewL(iFrames.Array());); |
|
204 } |
|
205 |
|
206 TestL((err==KErrNone || err==KErrNoMemory)); |
|
207 |
|
208 if (err != KErrNone) |
|
209 { |
|
210 __UHEAP_MARKEND; |
|
211 TestL(iTestAnimation == NULL); |
|
212 } |
|
213 else |
|
214 { |
|
215 break; |
|
216 } |
|
217 } |
|
218 __UHEAP_RESET; |
|
219 TestL(iTestAnimation != NULL); |
|
220 TestL(failRate > 1); //Ensure the udeb version of euser.dll is available (i.e. that the rom was build with the -D_DEBUG option) |
|
221 RDebug::Printf("TWSGraphicTest.CPP: Heapfailure loop completed after %d allocs.", failRate-1); |
|
222 |
|
223 // if testing that a created animation can be replaced |
|
224 if (iReplace) |
|
225 { |
|
226 // replace the animation just created with another |
|
227 TWsGraphicId testId = iTestAnimation->Id(); |
|
228 TInt testInt = testId.Id(); |
|
229 |
|
230 CWsGraphicBitmapAnimation* testReplacement = CWsGraphicBitmapAnimation::NewL(testId,iFrames.Array()); |
|
231 |
|
232 delete iTestAnimation; |
|
233 |
|
234 iTestAnimation = testReplacement; |
|
235 |
|
236 TestL(iTestAnimation->Id().Id()==testInt); |
|
237 } |
|
238 |
|
239 delete iDecoder; |
|
240 iDecoder = NULL; |
|
241 iTotalFrames = iFrames.Count(); |
|
242 iFrames.ResetAndDestroy(); |
|
243 |
|
244 // test that the animation methods can be used without error |
|
245 TestL(iTestAnimation->ShareGlobally()==KErrNone); |
|
246 TestL(iTestAnimation->UnShareGlobally()==KErrNone); |
|
247 TestL(iTestAnimation->Share(KTestSecId)==KErrNone); |
|
248 TestL(iTestAnimation->UnShare(KTestSecId)==KErrNone); |
|
249 TestL(iTestAnimation->UnShare(KTestSecId)==KErrNotFound); |
|
250 } |
|
251 } |
|
252 |
|
253 void CIclLoader::RunL() |
|
254 { |
|
255 if (iStatus == KErrNone) |
|
256 { |
|
257 NextL(); |
|
258 } |
|
259 else |
|
260 { |
|
261 TestL(EFalse); // kill the test |
|
262 } |
|
263 } |
|
264 |
|
265 TInt CIclLoader::RunError(TInt aError) |
|
266 { |
|
267 RDebug::Printf("CIclLoader::RunError, aError %d", aError); |
|
268 iFailed = ETrue; |
|
269 return KErrNone; |
|
270 } |
|
271 |
|
272 void CIclLoader::DoCancel() |
|
273 { |
|
274 if(iDecoder) |
|
275 { |
|
276 iDecoder->Cancel(); |
|
277 } |
|
278 } |
|
279 |
|
280 // Class for testing CWsGraphics |
|
281 class CActiveWait; |
|
282 class CRedrawAO; |
|
283 class CWsGraphicBase : public CBase |
|
284 { |
|
285 public: |
|
286 CWsGraphicBase(); |
|
287 CWsGraphicBase(TInt aScreenNumber); |
|
288 ~CWsGraphicBase(); |
|
289 void ConstructL(); |
|
290 void DoTestL(TInt aTestNo); |
|
291 void RedrawMe(TRect aRedrawRect, TInt aFrame); |
|
292 |
|
293 enum TTestCases |
|
294 { |
|
295 ETestCreateGraphicUID, |
|
296 ETestCreateGraphicID, |
|
297 ETestUpdateGraphic, |
|
298 ETestDeleteGraphic, |
|
299 ETestDrawInvalideBitmapID, |
|
300 ETestDrawGraphic, |
|
301 ETestDrawGraphicID, |
|
302 ETestDrawGraphicCompare, |
|
303 ETestDrawGraphicSessionHandle, |
|
304 ETestDrawAnimatedGraphicUID, |
|
305 ETestDrawAnimatedGraphicID, |
|
306 ETestCreateMsgGraphicMsgBuf, |
|
307 ETestDrawReplaceGraphicID, |
|
308 ETestDrawInvalidAnimationID, |
|
309 ETestDrawSharedGraphic, |
|
310 // additional cases to be added here, before ETestMaxNumberOfTests |
|
311 ETestMaxNumberOfTests |
|
312 }; |
|
313 |
|
314 private : |
|
315 void PrepGc(); |
|
316 void RetireGc(); |
|
317 void RunAnimation(TInt aFrameCount); |
|
318 void LaunchNewProcessL(const TDesC& aExecutable, TBool aShare); |
|
319 inline void TestForIdenticalBitmaps(){Test(iScreen->RectCompare(iPosition1,iPosition2));}; |
|
320 inline void TestForDifferentBitmaps(){Test(!iScreen->RectCompare(iPosition1,iPosition2));}; |
|
321 void Test(TInt aCondition); |
|
322 void DoTestCreateGraphicUidL(); |
|
323 void DoTestCreateGraphicIdL(); |
|
324 void DoTestUpdateGraphicL(); |
|
325 void DoTestDrawSharedGraphicL(); |
|
326 void DoTestDeleteGraphicL(); |
|
327 void DoTestDrawGraphicL(); |
|
328 void DoTestDrawGraphicIDL(); |
|
329 void DoTestDrawGraphicCompareL(); |
|
330 void DoTestDrawAnimatedGraphicUIDL(); |
|
331 void DoTestDrawAnimatedGraphicIDL(); |
|
332 void DoTestDrawGraphicSessionHandleL(); |
|
333 void DoTestCreateMsgGraphicMsgBufL(); |
|
334 void DoTestDrawReplaceGraphicIDL(); |
|
335 void DoTestDrawInvalidBitmapIDL(); |
|
336 void DoTestDrawInvalidAnimationIDL(); |
|
337 private : |
|
338 TInt iScreenNumber; |
|
339 CWindowGc *iGc; |
|
340 RWsSession iWs; |
|
341 RWindowGroup *iGroupWin; |
|
342 CWsScreenDevice *iScreen; |
|
343 RWindow *iWin; |
|
344 TLogMessageText iTestLog; |
|
345 TRect iPosition1; |
|
346 TRect iPosition2; |
|
347 CActiveWait* iTimer; |
|
348 CRedrawAO* iRedrawListener; |
|
349 TWsGraphicId iAnimId; |
|
350 TWsGraphicAnimation iAnimData; |
|
351 }; |
|
352 |
|
353 // |
|
354 // class CRedrawAO |
|
355 // request & listen for redraw events from wserv |
|
356 // if a redraw event is received, notify the observing class |
|
357 // |
|
358 class CRedrawAO : public CActive |
|
359 { |
|
360 public: |
|
361 static CRedrawAO* NewL(RWsSession* aWs); |
|
362 ~CRedrawAO(); |
|
363 // from CActive: |
|
364 void RunL(); |
|
365 void DoCancel(); |
|
366 TInt RunError(TInt aError); |
|
367 void RequestRedraw(); |
|
368 inline void SetFrameCount(TInt aCount){iFrameCount = aCount;}; |
|
369 inline TInt GetFrameCount() const {return iFrameCount;}; |
|
370 private: |
|
371 CRedrawAO(RWsSession* aWs); |
|
372 void ConstructL(); |
|
373 private: |
|
374 RWsSession* iWs; |
|
375 TInt iFrameCount; |
|
376 }; |
|
377 |
|
378 CRedrawAO* CRedrawAO::NewL(RWsSession* aWs) |
|
379 { |
|
380 CRedrawAO* self = new (ELeave) CRedrawAO(aWs); |
|
381 CleanupStack::PushL(self); |
|
382 self->ConstructL(); |
|
383 CleanupStack::Pop(self); |
|
384 return self; |
|
385 } |
|
386 |
|
387 CRedrawAO::CRedrawAO(RWsSession* aWs): |
|
388 CActive(CActive::EPriorityHigh), iWs(aWs) |
|
389 { |
|
390 CActiveScheduler::Add(this); |
|
391 } |
|
392 |
|
393 CRedrawAO::~CRedrawAO() |
|
394 { |
|
395 // cleanup |
|
396 Cancel(); |
|
397 } |
|
398 |
|
399 void CRedrawAO::ConstructL() |
|
400 { |
|
401 // nothing to construct |
|
402 } |
|
403 |
|
404 void CRedrawAO::RunL() |
|
405 { |
|
406 // leave if status is not ok. RunError will process this result |
|
407 User::LeaveIfError(iStatus.Int()); |
|
408 TWsRedrawEvent redraw; |
|
409 iWs->GetRedraw(redraw); |
|
410 TUint redrawHandle = redraw.Handle(); |
|
411 if (redrawHandle == ENullWsHandle) |
|
412 { |
|
413 User::Leave(KErrBadHandle); // sanity check the client handle isn't a dummy |
|
414 } |
|
415 else if (redrawHandle) |
|
416 { |
|
417 --iFrameCount; |
|
418 (reinterpret_cast<CWsGraphicBase *>(redrawHandle))->RedrawMe(redraw.Rect(), iFrameCount); // handle the redraw signal |
|
419 } |
|
420 |
|
421 if (iFrameCount > 0) |
|
422 { |
|
423 RequestRedraw(); |
|
424 } |
|
425 } |
|
426 |
|
427 TInt CRedrawAO::RunError(TInt aError) |
|
428 { |
|
429 if (aError != KErrBadHandle) |
|
430 { |
|
431 RequestRedraw(); |
|
432 } |
|
433 return KErrNone; |
|
434 } |
|
435 |
|
436 void CRedrawAO::DoCancel() |
|
437 { |
|
438 // kill all outstanding asynch. wserv requests |
|
439 iWs->RedrawReadyCancel(); |
|
440 iFrameCount = KErrNone; |
|
441 } |
|
442 |
|
443 void CRedrawAO::RequestRedraw() |
|
444 { |
|
445 if (!IsActive()) |
|
446 { |
|
447 iWs->RedrawReady(&iStatus); |
|
448 SetActive(); |
|
449 } |
|
450 } |
|
451 |
|
452 // |
|
453 |
|
454 class CActiveWait : public CActive |
|
455 { |
|
456 public: |
|
457 static CActiveWait* NewL(); |
|
458 ~CActiveWait(); |
|
459 void Wait(TInt aDelay); |
|
460 // From CActive: |
|
461 void RunL(); |
|
462 void DoCancel(); |
|
463 TInt RunError(TInt aError); |
|
464 protected: |
|
465 CActiveWait(); |
|
466 void ConstructL(); |
|
467 protected: |
|
468 RTimer iTimer; |
|
469 TTime iFromTime; |
|
470 }; |
|
471 |
|
472 CActiveWait* CActiveWait::NewL() |
|
473 { |
|
474 CActiveWait* self = new (ELeave) CActiveWait; |
|
475 CleanupStack::PushL(self); |
|
476 self->ConstructL(); |
|
477 CleanupStack::Pop(self); |
|
478 return self; |
|
479 } |
|
480 |
|
481 void CActiveWait::ConstructL() |
|
482 { |
|
483 User::LeaveIfError(iTimer.CreateLocal()); |
|
484 CActiveScheduler::Add(this); |
|
485 } |
|
486 |
|
487 CActiveWait::CActiveWait() : CActive(CActive::EPriorityStandard) |
|
488 { |
|
489 iFromTime.HomeTime(); |
|
490 } |
|
491 |
|
492 CActiveWait::~CActiveWait() |
|
493 { |
|
494 Cancel(); |
|
495 iTimer.Close(); |
|
496 } |
|
497 |
|
498 void CActiveWait::DoCancel() |
|
499 { |
|
500 iTimer.Cancel(); |
|
501 CActiveScheduler::Stop(); |
|
502 } |
|
503 |
|
504 void CActiveWait::RunL() |
|
505 { |
|
506 CActiveScheduler::Stop(); |
|
507 } |
|
508 |
|
509 TInt CActiveWait::RunError(TInt aError) |
|
510 { |
|
511 return aError; // exists so a break point can be placed on it. |
|
512 } |
|
513 |
|
514 void CActiveWait::Wait(TInt aDelay) |
|
515 |
|
516 |
|
517 { |
|
518 iTimer.After(iStatus, aDelay); |
|
519 SetActive(); |
|
520 CActiveScheduler::Start(); |
|
521 } |
|
522 |
|
523 // |
|
524 |
|
525 CWsGraphicBase::CWsGraphicBase(TInt aScreenNumber) : iScreenNumber(aScreenNumber), iAnimId(KDummyGraphicId) |
|
526 { |
|
527 } |
|
528 |
|
529 CWsGraphicBase::~CWsGraphicBase() |
|
530 { |
|
531 iWin->Close(); |
|
532 delete iWin; |
|
533 delete iScreen; |
|
534 delete iGc; |
|
535 delete iGroupWin; |
|
536 iWs.Close(); |
|
537 if (iTimer) |
|
538 { |
|
539 delete iTimer; |
|
540 iTimer = NULL; |
|
541 } |
|
542 if (iRedrawListener) |
|
543 { |
|
544 delete iRedrawListener; |
|
545 iRedrawListener = NULL; |
|
546 } |
|
547 } |
|
548 |
|
549 void CWsGraphicBase::ConstructL() |
|
550 { |
|
551 User::LeaveIfError(iWs.Connect()); |
|
552 iScreen=new(ELeave) CWsScreenDevice(iWs); |
|
553 User::LeaveIfError(iScreen->Construct(iScreenNumber)); |
|
554 |
|
555 TSize screenSize = iScreen->SizeInPixels(); |
|
556 iPosition1.SetRect(0,0,screenSize.iWidth/2,screenSize.iHeight); |
|
557 iPosition2.SetRect(screenSize.iWidth/2,0,screenSize.iWidth,screenSize.iHeight); |
|
558 |
|
559 iTimer = CActiveWait::NewL(); |
|
560 iRedrawListener = CRedrawAO::NewL(&iWs); |
|
561 |
|
562 iGc=new(ELeave) CWindowGc(iScreen); |
|
563 User::LeaveIfError(iGc->Construct()); |
|
564 iGroupWin=new(ELeave) RWindowGroup(iWs); |
|
565 iGroupWin->Construct(1); |
|
566 |
|
567 iWin=new(ELeave) RWindow(iWs); |
|
568 iWin->Construct(*iGroupWin, (TUint32)this); |
|
569 iWin->EnableRedrawStore(EFalse); // disable the redraw store for these tests |
|
570 iWin->SetRequiredDisplayMode(EColor256); |
|
571 iWin->SetExtent(TPoint(0,0),iScreen->SizeInPixels()); |
|
572 iWin->Activate(); |
|
573 iWin->BeginRedraw(); |
|
574 iWin->EndRedraw(); |
|
575 iWs.Flush(); |
|
576 } |
|
577 |
|
578 // To test whether sharing of graphics works a new process has to be launched. |
|
579 // The argument is set whether the graphic should be shared or not. |
|
580 void CWsGraphicBase::LaunchNewProcessL(const TDesC& aExecutable, TBool aShare) |
|
581 { |
|
582 TBuf<128> args; |
|
583 RProcess pr; |
|
584 TRequestStatus status; |
|
585 |
|
586 if (aShare) |
|
587 { |
|
588 args.Append(KShare); |
|
589 } |
|
590 else |
|
591 { |
|
592 args.Append(KNoShare); |
|
593 } |
|
594 |
|
595 User::LeaveIfError(pr.Create(aExecutable,args)); |
|
596 pr.Logon(status); |
|
597 pr.Resume(); |
|
598 User::WaitForRequest(status); |
|
599 pr.Close(); |
|
600 |
|
601 if (status != KErrNone) |
|
602 { |
|
603 User::Leave(status.Int()); |
|
604 } |
|
605 } |
|
606 |
|
607 // |
|
608 // CWsGraphicBase::PrepGc |
|
609 // activate a gc & clear the two rects |
|
610 // |
|
611 void CWsGraphicBase::PrepGc() |
|
612 { |
|
613 iGc->Activate(*iWin); |
|
614 iWin->Invalidate(); |
|
615 iWin->BeginRedraw(); |
|
616 iGc->Clear(iPosition1); |
|
617 iGc->Clear(iPosition2); |
|
618 iWs.Flush(); |
|
619 } |
|
620 |
|
621 // |
|
622 // CWsGraphicBase::RetireGc |
|
623 // deactivate a gc & flush any outstanding RWindow requests |
|
624 void CWsGraphicBase::RetireGc() |
|
625 { |
|
626 iGc->Deactivate(); |
|
627 iWin->EndRedraw(); |
|
628 iWs.Flush(); |
|
629 } |
|
630 |
|
631 // |
|
632 // CWsGraphicBase::RedrawMe |
|
633 // called from the redraw listener AO, triggered by a redraw event |
|
634 // Invalidates the area requiring a redraw & |
|
635 // initiates a redraw of the CWsGraphicBitmapAnimation's window |
|
636 // |
|
637 void CWsGraphicBase::RedrawMe(TRect aRedrawRect, TInt aFrame) |
|
638 { |
|
639 // do draw with next frame |
|
640 if (iAnimData.IsPlaying()) |
|
641 { |
|
642 iGc->Activate(*iWin); |
|
643 iWin->Invalidate(aRedrawRect); |
|
644 iWin->BeginRedraw(); |
|
645 iWs.Flush(); |
|
646 iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg()); |
|
647 iGc->Deactivate(); |
|
648 iWin->EndRedraw(); |
|
649 iWs.Flush(); |
|
650 |
|
651 // check for last frame |
|
652 if (aFrame == 0) |
|
653 { |
|
654 iTimer->Cancel(); |
|
655 } |
|
656 } |
|
657 } |
|
658 |
|
659 /** |
|
660 @SYMTestCaseID GRAPHICS-WSERV-0001 |
|
661 |
|
662 @SYMPREQ PREQ1246 |
|
663 |
|
664 @SYMTestCaseDesc Create Globally and Locally Shared Graphic Bitmaps from UIDs. |
|
665 |
|
666 @SYMTestPriority High |
|
667 |
|
668 @SYMTestStatus Implemented |
|
669 |
|
670 @SYMTestActions First test that TWsGraphicIds can be created from UIDs. Then create CWsGraphicBitmap objects through |
|
671 CWsGraphicBitmap::NewL, passing a UID from a TWsGraphicId. Two different objects are created |
|
672 1. Globally shared available to all applications |
|
673 2. Locally shared available to selected clients |
|
674 |
|
675 @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no errors are reported. |
|
676 */ |
|
677 void CWsGraphicBase::DoTestCreateGraphicUidL() |
|
678 { |
|
679 iTestLog.Append(_L("CreateGraphicUid")); |
|
680 |
|
681 _LIT_SECURE_ID(KTestSecId,0x12345678); |
|
682 |
|
683 // Test the creation of TWsGraphicIds from UIDs |
|
684 TUid uid1 = {0x10000001}; |
|
685 TUid uid2 = {0x10000002}; |
|
686 |
|
687 TWsGraphicId twsGraphicId1(uid1); |
|
688 Test(twsGraphicId1.Uid()==uid1); |
|
689 |
|
690 TWsGraphicId twsGraphicId2(uid2); |
|
691 Test(twsGraphicId2.Uid()==uid2); |
|
692 |
|
693 TWsGraphicId twsGraphicId3(twsGraphicId2); |
|
694 Test(twsGraphicId3.Uid()==uid2); |
|
695 |
|
696 TWsGraphicId twsGraphicId4(1); |
|
697 twsGraphicId4.Set(uid1); |
|
698 Test(twsGraphicId4.Uid()==uid1); |
|
699 |
|
700 // Create globally shared CWsGraphicBitmap |
|
701 CFbsBitmap bitmap1; |
|
702 CFbsBitmap mask1; |
|
703 |
|
704 TSize screenSize = iScreen->SizeInPixels(); |
|
705 bitmap1.Create(screenSize,iScreen->DisplayMode()); |
|
706 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
707 |
|
708 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(twsGraphicId1.Uid(), &bitmap1,&mask1); |
|
709 Test(bTest->IsActive()); |
|
710 |
|
711 TWsGraphicId tid1 = bTest->Id(); |
|
712 Test(tid1.Uid()==uid1); |
|
713 |
|
714 Test(bTest->ShareGlobally()==KErrNone); |
|
715 |
|
716 // Create local shared CWsGraphicBitmap |
|
717 CFbsBitmap bitmap2; |
|
718 CFbsBitmap mask2; |
|
719 |
|
720 bitmap2.Create(screenSize,iScreen->DisplayMode()); |
|
721 mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode()); |
|
722 |
|
723 CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2); |
|
724 |
|
725 TWsGraphicId tid2 = bTest2->Id(); |
|
726 Test(tid2.Uid()==uid2); |
|
727 |
|
728 Test(bTest2->Share(KTestSecId)==KErrNone); |
|
729 |
|
730 // Test the unsharing of the CWsGraphicBitmaps |
|
731 Test(bTest->UnShareGlobally()==KErrNone); |
|
732 Test(bTest2->UnShare(KTestSecId)==KErrNone); |
|
733 Test(bTest2->UnShare(KTestSecId)==KErrNotFound); |
|
734 |
|
735 delete bTest; |
|
736 delete bTest2; |
|
737 } |
|
738 |
|
739 /** |
|
740 @SYMTestCaseID GRAPHICS-WSERV-0002 |
|
741 |
|
742 @SYMPREQ PREQ1246 |
|
743 |
|
744 @SYMTestCaseDesc Create Globally and Locally Shared Graphic Bitmaps. |
|
745 |
|
746 @SYMTestPriority High |
|
747 |
|
748 @SYMTestStatus Implemented |
|
749 |
|
750 @SYMTestActions First test that TWsGraphicIds can be created from IDs. Then create CWsGraphicBitmap objects through |
|
751 CWsGraphicBitmap::NewL. Two different objects are created |
|
752 1. Globally shared available to all applications |
|
753 2. Locally shared available to selected clients |
|
754 |
|
755 @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no errors are reported. |
|
756 */ |
|
757 void CWsGraphicBase::DoTestCreateGraphicIdL() |
|
758 { |
|
759 iTestLog.Append(_L("CreateGraphicId")); |
|
760 |
|
761 _LIT_SECURE_ID(KTestSecId,0x12345678); |
|
762 |
|
763 // Test creating TWsGraphicIds from ids first |
|
764 TUid uid1 = {0x10000001}; |
|
765 |
|
766 TWsGraphicId twsGraphicId1(uid1); |
|
767 |
|
768 twsGraphicId1.Set(9); |
|
769 Test(twsGraphicId1.Id()==9); |
|
770 |
|
771 TWsGraphicId twsGraphicId2(twsGraphicId1); |
|
772 Test(twsGraphicId2.Id()==9); |
|
773 |
|
774 TWsGraphicId twsGraphicId3(7); |
|
775 Test(twsGraphicId3.Id()==7); |
|
776 |
|
777 // Create globally shared CWsGraphicBitmap |
|
778 CFbsBitmap bitmap1; |
|
779 CFbsBitmap mask1; |
|
780 |
|
781 TSize screenSize = iScreen->SizeInPixels(); |
|
782 bitmap1.Create(screenSize,iScreen->DisplayMode()); |
|
783 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
784 |
|
785 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
786 Test(bTest->IsActive()); |
|
787 |
|
788 TWsGraphicId tid1 = bTest->Id(); |
|
789 |
|
790 Test(bTest->ShareGlobally()==KErrNone); |
|
791 |
|
792 // Create local shared CWsGraphicBitmap |
|
793 CFbsBitmap bitmap2; |
|
794 CFbsBitmap mask2; |
|
795 |
|
796 bitmap2.Create(screenSize,iScreen->DisplayMode()); |
|
797 mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode()); |
|
798 |
|
799 CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2); |
|
800 |
|
801 TWsGraphicId tid2 = bTest2->Id(); |
|
802 |
|
803 Test(bTest2->Share(KTestSecId)==KErrNone); |
|
804 |
|
805 // Test the unsharing of the CWsGraphicBitmaps |
|
806 Test(bTest->UnShareGlobally()==KErrNone); |
|
807 Test(bTest2->UnShare(KTestSecId)==KErrNone); |
|
808 Test(bTest2->UnShare(KTestSecId)==KErrNotFound); |
|
809 |
|
810 delete bTest2; |
|
811 delete bTest; |
|
812 } |
|
813 |
|
814 /** |
|
815 @SYMTestCaseID GRAPHICS-WSERV-0003 |
|
816 |
|
817 @SYMPREQ PREQ1246 |
|
818 |
|
819 @SYMTestCaseDesc Update an existing graphic bitmap with new data. |
|
820 |
|
821 @SYMTestPriority High |
|
822 |
|
823 @SYMTestStatus Implemented |
|
824 |
|
825 @SYMTestActions The test calls CWsGraphicBitmap::NewL method with new data passed to the CWsGraphicBitmap object. |
|
826 |
|
827 |
|
828 @SYMTestExpectedResults The CWsGraphicBitmap object is updated with no errors reported. |
|
829 */ |
|
830 void CWsGraphicBase::DoTestUpdateGraphicL() |
|
831 { |
|
832 iTestLog.Append(_L("UpdateGraphic")); |
|
833 |
|
834 CFbsBitmap bitmap1; |
|
835 CFbsBitmap mask1; |
|
836 CFbsBitmap bitmap2; |
|
837 CFbsBitmap mask2; |
|
838 |
|
839 TSize screenSize = iScreen->SizeInPixels(); |
|
840 bitmap1.Create(screenSize,iScreen->DisplayMode()); |
|
841 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
842 |
|
843 CWsGraphic* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
844 |
|
845 bitmap2.Create(screenSize,iScreen->DisplayMode()); |
|
846 mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode()); |
|
847 |
|
848 TWsGraphicId tid1 = bTest->Id(); |
|
849 TInt testInt = tid1.Id(); |
|
850 |
|
851 CWsGraphic* testReplacement = CWsGraphicBitmap::NewL(tid1, &bitmap2,&mask2); |
|
852 |
|
853 delete bTest; |
|
854 bTest = testReplacement; |
|
855 |
|
856 Test(bTest->Id().Id()==testInt); |
|
857 |
|
858 delete bTest; |
|
859 } |
|
860 |
|
861 |
|
862 |
|
863 /** |
|
864 @SYMTestCaseID GRAPHICS-WSERV-0004 |
|
865 |
|
866 @SYMPREQ PREQ1246 |
|
867 |
|
868 @SYMTestCaseDesc Try to delete an existing graphic. |
|
869 |
|
870 @SYMTestPriority High |
|
871 |
|
872 @SYMTestStatus Implemented |
|
873 |
|
874 @SYMTestActions The test app calls CWsGraphic::Destroy() method, |
|
875 |
|
876 @SYMTestExpectedResults The CWsGraphicBitmap object is removed from the Window Server with no |
|
877 errors reported |
|
878 */ |
|
879 void CWsGraphicBase::DoTestDeleteGraphicL() |
|
880 { |
|
881 iTestLog.Append(_L("DeleteGraphic")); |
|
882 |
|
883 CFbsBitmap bitmap1; |
|
884 CFbsBitmap mask1; |
|
885 |
|
886 TSize screenSize = iScreen->SizeInPixels(); |
|
887 bitmap1.Create(screenSize,iScreen->DisplayMode()); |
|
888 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
889 |
|
890 CWsGraphic* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
891 |
|
892 bTest->Destroy(); |
|
893 |
|
894 Test(!bTest->IsActive()); |
|
895 |
|
896 delete bTest; |
|
897 } |
|
898 |
|
899 /** |
|
900 @SYMTestCaseID GRAPHICS-WSERV-0005 |
|
901 |
|
902 @SYMPREQ PREQ1246 |
|
903 |
|
904 @SYMTestCaseDesc Check a bitmap is not drawn if the bitmap and mask it uses are invalid |
|
905 |
|
906 @SYMTestPriority High |
|
907 |
|
908 @SYMTestStatus Implemented |
|
909 |
|
910 @SYMTestActions The test app creates a valid and invalid bitmap and attempts to draw them |
|
911 |
|
912 @SYMTestExpectedResults The valid bitmap is drawn but the invalid bitmap is not drawn |
|
913 */ |
|
914 void CWsGraphicBase::DoTestDrawInvalidBitmapIDL() |
|
915 { |
|
916 iTestLog.Append(_L("DrawInvalidBitmapID")); |
|
917 |
|
918 CFbsBitmap bitmap1; |
|
919 CFbsBitmap mask1; |
|
920 CFbsBitmap *bitmap2 = NULL; |
|
921 CFbsBitmap *mask2 = NULL; |
|
922 |
|
923 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
924 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
925 |
|
926 // valid bitmap |
|
927 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
928 |
|
929 // invalid bitmap |
|
930 CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(bitmap2,mask2); |
|
931 |
|
932 PrepGc(); |
|
933 iGc->DrawWsGraphic(bTest->Id(),iPosition1); |
|
934 iGc->DrawWsGraphic(bTest2->Id(),iPosition2); |
|
935 RetireGc(); |
|
936 |
|
937 // compare the graphic in both positions, should only be graphic in position 1 |
|
938 TestForDifferentBitmaps(); |
|
939 |
|
940 delete bTest2; |
|
941 delete bTest; |
|
942 } |
|
943 |
|
944 /** |
|
945 @SYMTestCaseID GRAPHICS-WSERV-0006 |
|
946 |
|
947 @SYMPREQ PREQ1246 |
|
948 |
|
949 @SYMTestCaseDesc Draw a graphic within a rectangle on the screen, then try to draw with a non-existant graphic |
|
950 |
|
951 @SYMTestPriority High |
|
952 |
|
953 @SYMTestStatus Implemented |
|
954 |
|
955 @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() method using the TWGraphicId object, to draw within a rectangle on the screen |
|
956 |
|
957 @SYMTestExpectedResults The graphic is drawn on the screen with no errors reported. Drawing with a non-existant graphic causes |
|
958 nothing to be drawn and no error reported |
|
959 */ |
|
960 void CWsGraphicBase::DoTestDrawGraphicL() |
|
961 { |
|
962 iTestLog.Append(_L("DrawGraphic")); |
|
963 |
|
964 _LIT8(KTestData,"HelloWorld"); |
|
965 |
|
966 CFbsBitmap bitmap1; |
|
967 CFbsBitmap mask1; |
|
968 |
|
969 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
970 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
971 |
|
972 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
973 |
|
974 PrepGc(); |
|
975 iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData); |
|
976 TWsGraphicId twsGraphicId1(KDummyGraphicId); // create unrecognised wsbitmap id & attempt to draw it |
|
977 iGc->DrawWsGraphic(twsGraphicId1,iPosition2,KTestData); |
|
978 RetireGc(); |
|
979 |
|
980 // compare the graphic in both positions, should only be graphic in position 1 |
|
981 TestForDifferentBitmaps(); |
|
982 |
|
983 delete bTest; |
|
984 } |
|
985 |
|
986 /** |
|
987 @SYMTestCaseID GRAPHICS-WSERV-0007 |
|
988 |
|
989 @SYMPREQ PREQ1246 |
|
990 |
|
991 @SYMTestCaseDesc Draw a graphic using a transient ID within a rectangle on the screen |
|
992 |
|
993 @SYMTestPriority High |
|
994 |
|
995 @SYMTestStatus Implemented |
|
996 |
|
997 @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() using a TWsGraphic object, to draw within |
|
998 a rectangle on the screen |
|
999 |
|
1000 @SYMTestExpectedResults The graphic is drawn. |
|
1001 */ |
|
1002 void CWsGraphicBase::DoTestDrawGraphicIDL() |
|
1003 { |
|
1004 iTestLog.Append(_L("DrawGraphicID")); |
|
1005 |
|
1006 CFbsBitmap bitmap1; |
|
1007 CFbsBitmap mask1; |
|
1008 |
|
1009 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
1010 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
1011 |
|
1012 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
1013 |
|
1014 PrepGc(); |
|
1015 iGc->DrawWsGraphic(bTest->Id(),iPosition1); |
|
1016 RetireGc(); |
|
1017 |
|
1018 // compare the graphic in both positions, should only be graphic in position 1 |
|
1019 TestForDifferentBitmaps(); |
|
1020 |
|
1021 delete bTest; |
|
1022 } |
|
1023 |
|
1024 |
|
1025 |
|
1026 /** |
|
1027 @SYMTestCaseID GRAPHICS-WSERV-0008 |
|
1028 |
|
1029 @SYMPREQ PREQ1246 |
|
1030 |
|
1031 @SYMTestCaseDesc Draw a graphic in two different rectangles on the screen and compare them |
|
1032 |
|
1033 @SYMTestPriority High |
|
1034 |
|
1035 @SYMTestStatus Implemented |
|
1036 |
|
1037 @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() using the TWsGraphic object, to draw a known bitmap |
|
1038 rectangle on the screen twice in different places. The bitmaps are then compared. |
|
1039 |
|
1040 @SYMTestExpectedResults The two bitmaps are identical |
|
1041 */ |
|
1042 void CWsGraphicBase::DoTestDrawGraphicCompareL() |
|
1043 { |
|
1044 iTestLog.Append(_L("DrawGraphicCompare")); |
|
1045 |
|
1046 _LIT8(KTestData,"HelloWorld"); |
|
1047 |
|
1048 CFbsBitmap bitmap1; |
|
1049 CFbsBitmap mask1; |
|
1050 |
|
1051 CFbsBitmap bitmap2; |
|
1052 CFbsBitmap mask2; |
|
1053 |
|
1054 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
1055 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
1056 |
|
1057 User::LeaveIfError(bitmap2.Load(MY_TEST_BITMAP,0)); |
|
1058 mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode()); |
|
1059 |
|
1060 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
1061 CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2); |
|
1062 |
|
1063 PrepGc(); |
|
1064 //draw the graphic in the two different rectangles |
|
1065 iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData); |
|
1066 iGc->DrawWsGraphic(bTest2->Id(),iPosition2,KTestData); |
|
1067 RetireGc(); |
|
1068 |
|
1069 // compare the graphic in both positions. Contents of each rect should be identical |
|
1070 TestForIdenticalBitmaps(); |
|
1071 |
|
1072 delete bTest2; |
|
1073 delete bTest; |
|
1074 } |
|
1075 |
|
1076 /** |
|
1077 @SYMTestCaseID GRAPHICS-WSERV-0009 |
|
1078 |
|
1079 @SYMPREQ PREQ1246 |
|
1080 |
|
1081 @SYMTestCaseDesc Draw a global and local graphic in two different rectangles on the screen and compare them |
|
1082 |
|
1083 @SYMTestPriority High |
|
1084 |
|
1085 @SYMTestStatus Implemented |
|
1086 |
|
1087 @SYMTestActions The test app calls CWindowGC::DrawGraphic() using the TWsGraphic object, to draw a known |
|
1088 global and local bitmap rectangle on the screen twice in different places. The bitmaps are then compared. |
|
1089 |
|
1090 @SYMTestExpectedResults The two bitmaps are identical |
|
1091 */ |
|
1092 void CWsGraphicBase::DoTestDrawGraphicSessionHandleL() |
|
1093 { |
|
1094 iTestLog.Append(_L("DrawGraphicSessionHandle")); |
|
1095 _LIT_SECURE_ID(KTestSecId,0x12345678); |
|
1096 |
|
1097 // test TWsGraphicControlState first |
|
1098 _LIT8(KTestData,"HelloWorld"); |
|
1099 |
|
1100 CFbsBitmap bitmap1; |
|
1101 CFbsBitmap mask1; |
|
1102 |
|
1103 CFbsBitmap bitmap2; |
|
1104 CFbsBitmap mask2; |
|
1105 |
|
1106 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
1107 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
1108 |
|
1109 User::LeaveIfError(bitmap2.Load(MY_TEST_BITMAP,0)); |
|
1110 mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode()); |
|
1111 |
|
1112 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); |
|
1113 CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2); |
|
1114 |
|
1115 Test(bTest->ShareGlobally()==KErrNone); |
|
1116 Test(bTest2->Share(KTestSecId)==KErrNone); |
|
1117 |
|
1118 PrepGc(); |
|
1119 iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData); |
|
1120 iGc->DrawWsGraphic(bTest2->Id(),iPosition2,KTestData); |
|
1121 RetireGc(); |
|
1122 |
|
1123 // compare the graphic in both positions. Contents of each rect should be identical |
|
1124 TestForIdenticalBitmaps(); |
|
1125 |
|
1126 delete bTest2; |
|
1127 delete bTest; |
|
1128 } |
|
1129 |
|
1130 /** |
|
1131 @SYMTestCaseID GRAPHICS-WSERV-0010 |
|
1132 |
|
1133 @SYMPREQ PREQ1246 |
|
1134 |
|
1135 @SYMTestCaseDesc Check an animation can be constructed using a UID, manipulated and then drawn |
|
1136 |
|
1137 @SYMTestPriority High |
|
1138 |
|
1139 @SYMTestStatus Implemented |
|
1140 |
|
1141 @SYMTestActions The test app creates CWsGraphicBitmapAnimation object via a UID and then draws the object to the screen |
|
1142 |
|
1143 @SYMTestExpectedResults The object is drawn |
|
1144 */ |
|
1145 void CWsGraphicBase::DoTestDrawAnimatedGraphicUIDL() |
|
1146 { |
|
1147 iTestLog.Append(_L("DrawAnimatedGraphicUID")); |
|
1148 |
|
1149 // test TWsGraphicAnimation first |
|
1150 iAnimData.Play(EFalse); |
|
1151 |
|
1152 // load the animation via a UID |
|
1153 CIclLoader* iclLoader; |
|
1154 iclLoader = new(ELeave) CIclLoader(); |
|
1155 iclLoader->ConstructL(KSymBallFile,ETrue,EFalse); // this is actually an asynchronous operation, so we give it a chance to execute below |
|
1156 |
|
1157 while (iclLoader->Ok() && iclLoader->GetId().Id() == KDummyGraphicId) |
|
1158 { |
|
1159 iTimer->Wait(1000); |
|
1160 } |
|
1161 |
|
1162 Test(iclLoader->Ok()); // fail test if iclLoder experienced problems |
|
1163 |
|
1164 iAnimId = iclLoader->GetId(); |
|
1165 |
|
1166 // animation is ready to be drawn. draw to the 1st position only |
|
1167 PrepGc(); |
|
1168 iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg()); |
|
1169 RetireGc(); |
|
1170 |
|
1171 // run the animation |
|
1172 RunAnimation(iclLoader->FrameCount()); |
|
1173 |
|
1174 // compare the graphic in both positions. |
|
1175 TestForDifferentBitmaps(); |
|
1176 |
|
1177 iTimer->Cancel(); |
|
1178 iclLoader->Cancel(); |
|
1179 delete iclLoader; |
|
1180 } |
|
1181 |
|
1182 /** |
|
1183 @SYMTestCaseID GRAPHICS-WSERV-0011 |
|
1184 |
|
1185 @SYMPREQ PREQ1246 |
|
1186 |
|
1187 @SYMTestCaseDesc Check an animation can be constructed using an ID, manipulated and then drawn |
|
1188 |
|
1189 @SYMTestPriority High |
|
1190 |
|
1191 @SYMTestStatus Implemented |
|
1192 |
|
1193 @SYMTestActions The test app creates CWsGraphicBitmapAnimation object via an ID and then draws the object to the screen |
|
1194 |
|
1195 @SYMTestExpectedResults The object is drawn |
|
1196 */ |
|
1197 void CWsGraphicBase::DoTestDrawAnimatedGraphicIDL() |
|
1198 { |
|
1199 iTestLog.Append(_L("DrawAnimatedGraphicID")); |
|
1200 iAnimData.Play(ETrue); |
|
1201 iAnimData.Play(ETrue); |
|
1202 Test(iAnimData.Loops()); |
|
1203 iAnimData.Pause(); |
|
1204 Test(!iAnimData.IsPlaying()); |
|
1205 Test(iAnimData.IsPaused()); |
|
1206 iAnimData.Pause(); |
|
1207 Test(iAnimData.Loops()); |
|
1208 iAnimData.Play(EFalse); |
|
1209 Test(!iAnimData.Loops()); |
|
1210 Test(!iAnimData.IsStopping()); |
|
1211 Test(!iAnimData.IsStopped()); |
|
1212 |
|
1213 // load the animation via an ID |
|
1214 CIclLoader* iclLoader; |
|
1215 iclLoader = new(ELeave) CIclLoader(); |
|
1216 iclLoader->ConstructL(KSymBallFile,EFalse,EFalse); |
|
1217 |
|
1218 while (iclLoader->GetId().Id() == KDummyGraphicId) |
|
1219 { |
|
1220 iTimer->Wait(1000); |
|
1221 } |
|
1222 iAnimId = iclLoader->GetId(); |
|
1223 |
|
1224 PrepGc(); |
|
1225 iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg()); |
|
1226 RetireGc(); |
|
1227 |
|
1228 // run the animation |
|
1229 RunAnimation(iclLoader->FrameCount()); |
|
1230 |
|
1231 // compare the graphic in both positions |
|
1232 TestForDifferentBitmaps(); |
|
1233 |
|
1234 iAnimData.Stop(ETrue); |
|
1235 Test(iAnimData.IsStopped()); |
|
1236 iAnimData.Pause(); |
|
1237 iAnimData.Play(EFalse); |
|
1238 iAnimData.Stop(EFalse); |
|
1239 Test(!iAnimData.IsStopped()); |
|
1240 |
|
1241 iTimer->Cancel(); |
|
1242 iclLoader->Cancel(); |
|
1243 delete iclLoader; |
|
1244 } |
|
1245 |
|
1246 /** |
|
1247 @SYMTestCaseID GRAPHICS-WSERV-0012 |
|
1248 |
|
1249 @SYMPREQ PREQ1246 |
|
1250 |
|
1251 @SYMTestCaseDesc Check an animation can be constructed and then replaced, manipulated and then drawn |
|
1252 |
|
1253 @SYMTestPriority High |
|
1254 |
|
1255 @SYMTestStatus Implemented |
|
1256 |
|
1257 @SYMTestActions The test app creates CWsGraphicBitmapAnimation object, the replaces it, and then draws the object |
|
1258 to the screen |
|
1259 |
|
1260 @SYMTestExpectedResults The object is drawn |
|
1261 */ |
|
1262 void CWsGraphicBase::DoTestDrawReplaceGraphicIDL() |
|
1263 { |
|
1264 // test TWsGraphicControlStateTimed first |
|
1265 iTestLog.Append(_L("DrawAnimatedGraphicID")); |
|
1266 _LIT8(KTestData,"HelloWorld"); |
|
1267 iAnimData.Stop(ETrue); |
|
1268 |
|
1269 // load and replace the animation |
|
1270 CIclLoader* iclLoader; |
|
1271 iclLoader = new(ELeave) CIclLoader(); |
|
1272 iclLoader->ConstructL(KSymBallFile,false,true); |
|
1273 |
|
1274 while (iclLoader->GetId().Id() == KDummyGraphicId) |
|
1275 { |
|
1276 iTimer->Wait(1000); |
|
1277 } |
|
1278 iAnimId = iclLoader->GetId(); |
|
1279 |
|
1280 // draw the animation in two positions |
|
1281 PrepGc(); |
|
1282 iGc->DrawWsGraphic(iAnimId,iPosition1,KTestData); |
|
1283 RetireGc(); |
|
1284 |
|
1285 // run the animation |
|
1286 RunAnimation(iclLoader->FrameCount()); |
|
1287 |
|
1288 // compare the graphic in both positions |
|
1289 // Expect identical, as the command buffer used in position1 animation is invalid, therefore never drawn |
|
1290 TestForIdenticalBitmaps(); |
|
1291 |
|
1292 iTimer->Cancel(); |
|
1293 iclLoader->Cancel(); |
|
1294 delete iclLoader; |
|
1295 } |
|
1296 |
|
1297 /** |
|
1298 @SYMTestCaseID GRAPHICS-WSERV-0013 |
|
1299 |
|
1300 @SYMPREQ PREQ1246 |
|
1301 |
|
1302 @SYMTestCaseDesc Check the creation and manipulation of an RWsGraphicMsgBuf object |
|
1303 |
|
1304 @SYMTestPriority High |
|
1305 |
|
1306 @SYMTestStatus Implemented |
|
1307 |
|
1308 @SYMTestActions Creates and manipulates an RWsGraphicMsgBuf object |
|
1309 |
|
1310 @SYMTestExpectedResults RWsGraphicMsgBuf functions correctly |
|
1311 */ |
|
1312 void CWsGraphicBase::DoTestCreateMsgGraphicMsgBufL() |
|
1313 { |
|
1314 iTestLog.Append(_L("CreateMsgGraphicMsgBuf")); |
|
1315 |
|
1316 _LIT(KNebraska,"Nebraska"); |
|
1317 _LIT8(KTesting,"Testing"); |
|
1318 RWsGraphicMsgBuf msgBuf; |
|
1319 msgBuf.CleanupClosePushL(); |
|
1320 msgBuf.Append(TUid::Uid(0x12345670),KTesting()); |
|
1321 msgBuf.Append(TUid::Uid(0x12345671),KNebraska()); |
|
1322 msgBuf.Append(TUid::Uid(0x12345670),KTesting()); |
|
1323 |
|
1324 Test(TUid::Uid(0x12345670)==msgBuf.TypeId(0)); |
|
1325 |
|
1326 msgBuf.Remove(0); |
|
1327 const TInt count = msgBuf.Count(); |
|
1328 Test(count == 2); |
|
1329 |
|
1330 iAnimData.Play(ETrue); |
|
1331 msgBuf.Append(iAnimData); |
|
1332 Test(msgBuf.Count() == 3); |
|
1333 |
|
1334 CleanupStack::Pop(); |
|
1335 |
|
1336 // load the animation via a UID |
|
1337 CIclLoader* iclLoader; |
|
1338 iclLoader = new(ELeave) CIclLoader(); |
|
1339 iclLoader->ConstructL(KSymBallFile,true,false); |
|
1340 |
|
1341 while (iclLoader->GetId().Id() == KDummyGraphicId) |
|
1342 { |
|
1343 iTimer->Wait(1000); |
|
1344 } |
|
1345 iAnimId = iclLoader->GetId(); |
|
1346 |
|
1347 PrepGc(); |
|
1348 iGc->DrawWsGraphic(iAnimId,iPosition1,msgBuf.Pckg()); |
|
1349 RetireGc(); |
|
1350 |
|
1351 // run the animation |
|
1352 RunAnimation(iclLoader->FrameCount()); |
|
1353 |
|
1354 // compare the graphic in both positions |
|
1355 TestForDifferentBitmaps(); |
|
1356 |
|
1357 iTimer->Cancel(); |
|
1358 iclLoader->Cancel(); |
|
1359 delete iclLoader; |
|
1360 msgBuf.Close(); |
|
1361 } |
|
1362 |
|
1363 |
|
1364 |
|
1365 /** |
|
1366 @SYMTestCaseID GRAPHICS-WSERV-0014 |
|
1367 |
|
1368 @SYMPREQ PREQ1246 |
|
1369 |
|
1370 @SYMTestCaseDesc Check an animation is not drawn if the command buffer it uses is invalid |
|
1371 |
|
1372 @SYMTestPriority High |
|
1373 |
|
1374 @SYMTestStatus Implemented |
|
1375 |
|
1376 @SYMTestActions The test app creates CWsGraphicBitmapAnimation object then draws the animation using |
|
1377 a valid and invalid command buffer |
|
1378 |
|
1379 @SYMTestExpectedResults The animation is drawn while using the valid command buffer but not drawn |
|
1380 when the command buffer is invalid |
|
1381 */ |
|
1382 void CWsGraphicBase::DoTestDrawInvalidAnimationIDL() |
|
1383 { |
|
1384 // test TWsGraphicControlStateTimed first, a valid command buffer |
|
1385 iTestLog.Append(_L("DrawInvalidAnimationID")); |
|
1386 iAnimData.Play(ETrue); |
|
1387 |
|
1388 // invalid command buffer |
|
1389 _LIT8(KTestData2,"12345678"); |
|
1390 |
|
1391 // load and replace the animation |
|
1392 CIclLoader* iclLoader; |
|
1393 iclLoader = new(ELeave) CIclLoader(); |
|
1394 iclLoader->ConstructL(KSymBallFile,false,false); |
|
1395 |
|
1396 while (iclLoader->GetId().Id() == KDummyGraphicId) |
|
1397 { |
|
1398 iTimer->Wait(1000); |
|
1399 } |
|
1400 iAnimId = iclLoader->GetId(); |
|
1401 |
|
1402 PrepGc(); |
|
1403 iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg()); |
|
1404 iGc->DrawWsGraphic(iAnimId,iPosition2,KTestData2); |
|
1405 RetireGc(); |
|
1406 |
|
1407 // run the animation |
|
1408 RunAnimation(iclLoader->FrameCount()); |
|
1409 |
|
1410 // compare the graphic in both positions |
|
1411 TestForDifferentBitmaps(); |
|
1412 |
|
1413 iAnimData.Stop(ETrue); |
|
1414 iTimer->Cancel(); |
|
1415 iclLoader->Cancel(); |
|
1416 delete iclLoader; |
|
1417 } |
|
1418 |
|
1419 /** |
|
1420 @SYMTestCaseID GRAPHICS-WSERV-0015 |
|
1421 |
|
1422 @SYMPREQ PREQ1246 |
|
1423 |
|
1424 @SYMTestCaseDesc Check the sharing of graphics with other clients. |
|
1425 |
|
1426 @SYMTestPriority High |
|
1427 |
|
1428 @SYMTestStatus Implemented |
|
1429 |
|
1430 @SYMTestActions The test app creates CWsGraphicBitmap object an then tests the sharing of the object with |
|
1431 different clients |
|
1432 |
|
1433 @SYMTestExpectedResults The CWsGraphicBitmap object is shared correctly |
|
1434 */ |
|
1435 void CWsGraphicBase::DoTestDrawSharedGraphicL() |
|
1436 { |
|
1437 iTestLog.Append(_L("DrawSharedGraphic")); |
|
1438 _LIT_SECURE_ID(KTestSecId,0x10003a4b); |
|
1439 |
|
1440 TUid uid1 = {0x12000021}; |
|
1441 TWsGraphicId twsGraphicId1(uid1); |
|
1442 |
|
1443 CFbsBitmap bitmap1; |
|
1444 CFbsBitmap mask1; |
|
1445 |
|
1446 User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); |
|
1447 mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); |
|
1448 |
|
1449 CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(twsGraphicId1.Uid(), &bitmap1,&mask1); |
|
1450 |
|
1451 // Try to draw the graphic in an client. Should fail as graphic is not shared |
|
1452 TRAPD(err, LaunchNewProcessL(KTestExe1, EFalse)); |
|
1453 Test(err == KErrNone); |
|
1454 |
|
1455 // Share the graphic globally and try to draw the graphic in an client. Should pass |
|
1456 Test(bTest->ShareGlobally()==KErrNone); |
|
1457 TRAP(err, LaunchNewProcessL(KTestExe2, ETrue)); |
|
1458 Test(err == KErrNone); |
|
1459 |
|
1460 // Unshare the graphic globally and try to draw the graphic in an client. Should fail |
|
1461 Test(bTest->UnShareGlobally()==KErrNone); |
|
1462 TRAP(err, LaunchNewProcessL(KTestExe3, EFalse)); |
|
1463 Test(err == KErrNone); |
|
1464 |
|
1465 // Share the graphic to a client and try to draw the graphic in the client. Should pass |
|
1466 Test(bTest->Share(KTestSecId)==KErrNone); |
|
1467 TRAP(err, LaunchNewProcessL(KTestExe4, ETrue)); |
|
1468 Test(err == KErrNone); |
|
1469 |
|
1470 // Unshare the graphic to a client and try to draw the graphic in the client. Should fail |
|
1471 Test(bTest->UnShare(KTestSecId)==KErrNone); |
|
1472 TRAP(err, LaunchNewProcessL(KTestExe5, EFalse)); |
|
1473 Test(err == KErrNone); |
|
1474 |
|
1475 delete bTest; |
|
1476 } |
|
1477 |
|
1478 |
|
1479 void CWsGraphicBase::DoTestL(TInt aTestNo) |
|
1480 { |
|
1481 switch (aTestNo) |
|
1482 { |
|
1483 case ETestCreateGraphicUID: |
|
1484 DoTestCreateGraphicUidL(); |
|
1485 break; |
|
1486 case ETestCreateGraphicID: |
|
1487 DoTestCreateGraphicIdL(); |
|
1488 break; |
|
1489 case ETestUpdateGraphic: |
|
1490 DoTestUpdateGraphicL(); |
|
1491 break; |
|
1492 case ETestDeleteGraphic: |
|
1493 DoTestDeleteGraphicL(); |
|
1494 break; |
|
1495 case ETestDrawInvalideBitmapID: |
|
1496 DoTestDrawInvalidBitmapIDL(); |
|
1497 break; |
|
1498 case ETestDrawGraphic: |
|
1499 DoTestDrawGraphicL(); |
|
1500 break; |
|
1501 case ETestDrawGraphicID: |
|
1502 DoTestDrawGraphicIDL(); |
|
1503 break; |
|
1504 case ETestDrawGraphicCompare: |
|
1505 DoTestDrawGraphicCompareL(); |
|
1506 break; |
|
1507 case ETestDrawGraphicSessionHandle: |
|
1508 DoTestDrawGraphicSessionHandleL(); |
|
1509 break; |
|
1510 #ifdef _DEBUG |
|
1511 // These tests require debug-only API to simulate OOM. Running |
|
1512 // the tests in non-debug environments invalidates the tests. |
|
1513 case ETestDrawAnimatedGraphicUID: |
|
1514 DoTestDrawAnimatedGraphicUIDL(); |
|
1515 break; |
|
1516 case ETestDrawAnimatedGraphicID: |
|
1517 DoTestDrawAnimatedGraphicIDL(); |
|
1518 break; |
|
1519 case ETestCreateMsgGraphicMsgBuf: |
|
1520 DoTestCreateMsgGraphicMsgBufL(); |
|
1521 break; |
|
1522 case ETestDrawReplaceGraphicID: |
|
1523 DoTestDrawReplaceGraphicIDL(); |
|
1524 break; |
|
1525 case ETestDrawInvalidAnimationID: |
|
1526 DoTestDrawInvalidAnimationIDL(); |
|
1527 break; |
|
1528 #endif |
|
1529 case ETestDrawSharedGraphic: |
|
1530 DoTestDrawSharedGraphicL(); |
|
1531 break; |
|
1532 } |
|
1533 RDebug::Print(iTestLog); |
|
1534 iTestLog.Delete(0,256); |
|
1535 } |
|
1536 |
|
1537 // writes out to WSERV.log if error |
|
1538 void CWsGraphicBase::Test(TInt aCondition) |
|
1539 { |
|
1540 if(!aCondition) |
|
1541 { |
|
1542 TBuf<KMaxLogLength> buf; |
|
1543 _LIT(Fail,"AUTO Failed in WsGraphics Test : "); |
|
1544 buf.Append(Fail); |
|
1545 buf.Append(iTestLog); |
|
1546 RDebug::Print(buf); |
|
1547 RProcess().Terminate(KErrGeneral); |
|
1548 } |
|
1549 } |
|
1550 |
|
1551 // |
|
1552 // CWsGraphicBase::RunAnimation |
|
1553 // Redraw event listener is launched & the |
|
1554 // animation is given a total of KAnimationRunTime (25 seconds) to run a single loop |
|
1555 // |
|
1556 void CWsGraphicBase::RunAnimation(TInt aFrameCount) |
|
1557 { |
|
1558 --aFrameCount; // account for the fact the initial frame is already displayed |
|
1559 iRedrawListener->SetFrameCount(aFrameCount); |
|
1560 iRedrawListener->RequestRedraw(); |
|
1561 iTimer->Wait(KAnimationRunTime); |
|
1562 if (iAnimData.IsPlaying()) |
|
1563 { |
|
1564 iAnimData.Stop(ETrue); |
|
1565 } |
|
1566 iRedrawListener->Cancel(); |
|
1567 iAnimData.Stop(EFalse); |
|
1568 Test(iRedrawListener->GetFrameCount() == 0); // ensure the animation ran through until last frame |
|
1569 } |
|
1570 |
|
1571 void MainL() |
|
1572 { |
|
1573 TInt testCount = KErrNone; |
|
1574 |
|
1575 //Read the argument from the command line for current screen number |
|
1576 TBuf<256> commandLine; |
|
1577 User::CommandLine(commandLine); |
|
1578 TLex lex(commandLine); |
|
1579 lex.NextToken(); |
|
1580 lex.SkipSpace(); |
|
1581 TInt screenNumber=(TInt)lex.Get(); |
|
1582 |
|
1583 CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler; |
|
1584 CActiveScheduler::Install(activeScheduler); |
|
1585 CleanupStack::PushL(activeScheduler); |
|
1586 |
|
1587 CWsGraphicBase testBase(screenNumber); |
|
1588 testBase.ConstructL(); |
|
1589 |
|
1590 // run through all the tests |
|
1591 while (testCount < CWsGraphicBase::ETestMaxNumberOfTests) |
|
1592 { |
|
1593 testBase.DoTestL(testCount); |
|
1594 testCount++; |
|
1595 } |
|
1596 |
|
1597 CleanupStack::PopAndDestroy(activeScheduler); |
|
1598 } |
|
1599 |
|
1600 GLDEF_C TInt E32Main() |
|
1601 { |
|
1602 CTrapCleanup* cleanUpStack=CTrapCleanup::New(); |
|
1603 if(cleanUpStack==NULL) |
|
1604 { |
|
1605 return KErrNoMemory; |
|
1606 } |
|
1607 TRAPD(err, MainL()); |
|
1608 delete cleanUpStack; |
|
1609 return(err); |
|
1610 } |