1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/twsgraphic/TWsGraphicTest.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1610 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include <w32stdgraphic.h>
1.26 +#include <imageconversion.h>
1.27 +#include "testbase.h"
1.28 +#include "testbase.h"
1.29 +
1.30 +// Bitmap to load for tests
1.31 +#define MY_TEST_BITMAP _L("Z:\\WSTEST\\MYTEST.MBM")
1.32 +
1.33 +// Animation to load for tests
1.34 +_LIT(KSymBallFile, "Z:\\WSTEST\\symball.gif");
1.35 +
1.36 +// Executables for different sharing of graphic tests
1.37 +_LIT(KTestExe1, "TWSGRAPHICSHARETEST.exe");
1.38 +_LIT(KTestExe2, "TWSGRAPHICSHAREGLOBALTEST.exe");
1.39 +_LIT(KTestExe3, "TWSGRAPHICUNSHAREGLOBALTEST.exe");
1.40 +_LIT(KTestExe4, "TWSGRAPHICSHARESECURETEST.exe");
1.41 +_LIT(KTestExe5, "TWSGRAPHICUNSHARESECURETEST.exe");
1.42 +
1.43 +// Graphic is shared or not in executeable
1.44 +_LIT(KShare, " true");
1.45 +_LIT(KNoShare, " false");
1.46 +
1.47 +TUid KUidTestAnimation = {0x87654321};
1.48 +const TInt KDummyGraphicId = 99;
1.49 +const TInt KMaxLogLength = 256;
1.50 +const TInt KAnimationRunTime = 5000000; // 5 seconds max time to run a single animation loop
1.51 +
1.52 +// Animation loader
1.53 +class CIclLoader: public CActive
1.54 + {
1.55 +public:
1.56 + CIclLoader();
1.57 + ~CIclLoader();
1.58 + void ConstructL(const TDesC& aFileName, TBool aUseUID, TBool aReplace);
1.59 + const TWsGraphicId GetId();
1.60 + inline TInt FrameCount() const {return iTotalFrames;};
1.61 + inline TBool Ok() const {return !iFailed;};
1.62 +protected:
1.63 + void RunL();
1.64 + TInt RunError(TInt aError);
1.65 + void DoCancel();
1.66 +private:
1.67 + void TestL(TInt aCondition);
1.68 + CImageDecoder* iDecoder;
1.69 + CWsGraphicBitmapAnimation* iTestAnimation;
1.70 + TLogMessageText iTestLog;
1.71 + TBool iUseUID;
1.72 + TBool iReplace;
1.73 + RPointerArray<CWsGraphicBitmapAnimation::CFrame> iFrames;
1.74 + TInt iTotalFrames;
1.75 + void NextL();
1.76 + RFs iFs;
1.77 + TBool iFailed;
1.78 + };
1.79 +
1.80 +CIclLoader::CIclLoader():
1.81 + CActive(CActive::EPriorityLow)
1.82 + {
1.83 + CActiveScheduler::Add(this);
1.84 + }
1.85 +
1.86 +CIclLoader::~CIclLoader()
1.87 + {
1.88 + if (iTestAnimation)
1.89 + {
1.90 + delete iTestAnimation;
1.91 + iTestAnimation = NULL;
1.92 + }
1.93 + if (iDecoder)
1.94 + {
1.95 + delete iDecoder;
1.96 + iDecoder = NULL;
1.97 + }
1.98 + iFrames.ResetAndDestroy();
1.99 + iFs.Close();
1.100 + }
1.101 +
1.102 +const TWsGraphicId CIclLoader::GetId()
1.103 + {
1.104 + if (iTestAnimation)
1.105 + {
1.106 + return iTestAnimation->Id();
1.107 + }
1.108 + else
1.109 + {
1.110 + TWsGraphicId id(KDummyGraphicId);
1.111 + return id;
1.112 + }
1.113 + }
1.114 +
1.115 +void CIclLoader::TestL(TInt aCondition)
1.116 + {
1.117 + if(!aCondition)
1.118 + {
1.119 + RWsSession rWs;
1.120 + User::LeaveIfError(rWs.Connect());
1.121 + TBuf<KMaxLogLength> buf;
1.122 + _LIT(Fail,"AUTO Failed in WsGraphics Test : CIclLoader");
1.123 + buf.Append(Fail);
1.124 + buf.Append(iTestLog);
1.125 + rWs.LogMessage(buf);
1.126 + rWs.Flush();
1.127 + rWs.Close();
1.128 + User::Leave(KErrGeneral);
1.129 + }
1.130 + }
1.131 +
1.132 +void CIclLoader::ConstructL(const TDesC& aFileName, TBool aUseUID,TBool aReplace)
1.133 + {
1.134 + iUseUID = aUseUID;
1.135 + iReplace = aReplace;
1.136 +
1.137 + User::LeaveIfError(iFs.Connect());
1.138 +
1.139 + iDecoder = CImageDecoder::FileNewL(iFs,aFileName);
1.140 + if(!iDecoder->IsImageHeaderProcessingComplete())
1.141 + {
1.142 + User::Leave(KErrGeneral);
1.143 + }
1.144 + NextL();
1.145 + }
1.146 +
1.147 +void CIclLoader::NextL()
1.148 + {
1.149 + // Load a frame from the animation
1.150 + if (iDecoder && (iDecoder->FrameCount() > iFrames.Count()))
1.151 + {
1.152 + const TFrameInfo& info = iDecoder->FrameInfo(iFrames.Count());
1.153 + CWsGraphicBitmapAnimation::CFrame* frame = CWsGraphicBitmapAnimation::CFrame::NewL();
1.154 + CleanupStack::PushL(frame);
1.155 + iFrames.AppendL(frame);
1.156 + CleanupStack::Pop(frame);
1.157 + frame->SetFrameInfo(info);
1.158 + TFrameInfo copiedInfo = frame->FrameInfo();
1.159 + TestL(info.iFlags==copiedInfo.iFlags);
1.160 +
1.161 + TSize bmpSize(info.iFrameCoordsInPixels.Size());
1.162 + CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
1.163 + frame->SetBitmap(bitmap); //takes ownership
1.164 + User::LeaveIfError(bitmap->Create(bmpSize,info.iFrameDisplayMode));
1.165 +
1.166 + TDisplayMode maskDispMode;
1.167 + CFbsBitmap* mask = new(ELeave) CFbsBitmap;
1.168 + frame->SetMask(mask); //takes ownership
1.169 + if((TFrameInfo::EAlphaChannel|TFrameInfo::ETransparencyPossible) & info.iFlags)
1.170 + {
1.171 + maskDispMode = EGray256;
1.172 + }
1.173 + else
1.174 + {
1.175 + maskDispMode = EGray2;
1.176 + }
1.177 +
1.178 + User::LeaveIfError(mask->Create(info.iFrameCoordsInPixels.Size(),maskDispMode));
1.179 + iDecoder->Convert(&iStatus,*bitmap,*mask,iFrames.Count()-1);
1.180 +
1.181 + SetActive();
1.182 + }
1.183 +
1.184 + // if a frame loaded
1.185 + else if(iFrames.Count())
1.186 + {
1.187 + _LIT_SECURE_ID(KTestSecId,0x12345678);
1.188 +
1.189 + // The extra code around the NewL is checking that no heap failures occur when
1.190 + // creating the CWsGraphicBitmapAnimation
1.191 + TInt failRate = 1;
1.192 + const TInt KMaxIteration = 1000;
1.193 + for (;failRate < KMaxIteration; failRate++)
1.194 + {
1.195 + __UHEAP_RESET;
1.196 + __UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
1.197 + __UHEAP_MARK;
1.198 +
1.199 + TInt err = KErrGeneral;
1.200 + if (iUseUID)
1.201 + {// creating animation using UID
1.202 + TRAP(err, iTestAnimation = CWsGraphicBitmapAnimation::NewL(KUidTestAnimation,iFrames.Array()););
1.203 + }
1.204 + else
1.205 + {// creating using transient ID allocated by wserv
1.206 + TRAP(err, iTestAnimation = CWsGraphicBitmapAnimation::NewL(iFrames.Array()););
1.207 + }
1.208 +
1.209 + TestL((err==KErrNone || err==KErrNoMemory));
1.210 +
1.211 + if (err != KErrNone)
1.212 + {
1.213 + __UHEAP_MARKEND;
1.214 + TestL(iTestAnimation == NULL);
1.215 + }
1.216 + else
1.217 + {
1.218 + break;
1.219 + }
1.220 + }
1.221 + __UHEAP_RESET;
1.222 + TestL(iTestAnimation != NULL);
1.223 + TestL(failRate > 1); //Ensure the udeb version of euser.dll is available (i.e. that the rom was build with the -D_DEBUG option)
1.224 + RDebug::Printf("TWSGraphicTest.CPP: Heapfailure loop completed after %d allocs.", failRate-1);
1.225 +
1.226 + // if testing that a created animation can be replaced
1.227 + if (iReplace)
1.228 + {
1.229 + // replace the animation just created with another
1.230 + TWsGraphicId testId = iTestAnimation->Id();
1.231 + TInt testInt = testId.Id();
1.232 +
1.233 + CWsGraphicBitmapAnimation* testReplacement = CWsGraphicBitmapAnimation::NewL(testId,iFrames.Array());
1.234 +
1.235 + delete iTestAnimation;
1.236 +
1.237 + iTestAnimation = testReplacement;
1.238 +
1.239 + TestL(iTestAnimation->Id().Id()==testInt);
1.240 + }
1.241 +
1.242 + delete iDecoder;
1.243 + iDecoder = NULL;
1.244 + iTotalFrames = iFrames.Count();
1.245 + iFrames.ResetAndDestroy();
1.246 +
1.247 + // test that the animation methods can be used without error
1.248 + TestL(iTestAnimation->ShareGlobally()==KErrNone);
1.249 + TestL(iTestAnimation->UnShareGlobally()==KErrNone);
1.250 + TestL(iTestAnimation->Share(KTestSecId)==KErrNone);
1.251 + TestL(iTestAnimation->UnShare(KTestSecId)==KErrNone);
1.252 + TestL(iTestAnimation->UnShare(KTestSecId)==KErrNotFound);
1.253 + }
1.254 + }
1.255 +
1.256 +void CIclLoader::RunL()
1.257 + {
1.258 + if (iStatus == KErrNone)
1.259 + {
1.260 + NextL();
1.261 + }
1.262 + else
1.263 + {
1.264 + TestL(EFalse); // kill the test
1.265 + }
1.266 + }
1.267 +
1.268 +TInt CIclLoader::RunError(TInt aError)
1.269 + {
1.270 + RDebug::Printf("CIclLoader::RunError, aError %d", aError);
1.271 + iFailed = ETrue;
1.272 + return KErrNone;
1.273 + }
1.274 +
1.275 +void CIclLoader::DoCancel()
1.276 + {
1.277 + if(iDecoder)
1.278 + {
1.279 + iDecoder->Cancel();
1.280 + }
1.281 + }
1.282 +
1.283 +// Class for testing CWsGraphics
1.284 +class CActiveWait;
1.285 +class CRedrawAO;
1.286 +class CWsGraphicBase : public CBase
1.287 + {
1.288 +public:
1.289 + CWsGraphicBase();
1.290 + CWsGraphicBase(TInt aScreenNumber);
1.291 + ~CWsGraphicBase();
1.292 + void ConstructL();
1.293 + void DoTestL(TInt aTestNo);
1.294 + void RedrawMe(TRect aRedrawRect, TInt aFrame);
1.295 +
1.296 + enum TTestCases
1.297 + {
1.298 + ETestCreateGraphicUID,
1.299 + ETestCreateGraphicID,
1.300 + ETestUpdateGraphic,
1.301 + ETestDeleteGraphic,
1.302 + ETestDrawInvalideBitmapID,
1.303 + ETestDrawGraphic,
1.304 + ETestDrawGraphicID,
1.305 + ETestDrawGraphicCompare,
1.306 + ETestDrawGraphicSessionHandle,
1.307 + ETestDrawAnimatedGraphicUID,
1.308 + ETestDrawAnimatedGraphicID,
1.309 + ETestCreateMsgGraphicMsgBuf,
1.310 + ETestDrawReplaceGraphicID,
1.311 + ETestDrawInvalidAnimationID,
1.312 + ETestDrawSharedGraphic,
1.313 + // additional cases to be added here, before ETestMaxNumberOfTests
1.314 + ETestMaxNumberOfTests
1.315 + };
1.316 +
1.317 +private :
1.318 + void PrepGc();
1.319 + void RetireGc();
1.320 + void RunAnimation(TInt aFrameCount);
1.321 + void LaunchNewProcessL(const TDesC& aExecutable, TBool aShare);
1.322 + inline void TestForIdenticalBitmaps(){Test(iScreen->RectCompare(iPosition1,iPosition2));};
1.323 + inline void TestForDifferentBitmaps(){Test(!iScreen->RectCompare(iPosition1,iPosition2));};
1.324 + void Test(TInt aCondition);
1.325 + void DoTestCreateGraphicUidL();
1.326 + void DoTestCreateGraphicIdL();
1.327 + void DoTestUpdateGraphicL();
1.328 + void DoTestDrawSharedGraphicL();
1.329 + void DoTestDeleteGraphicL();
1.330 + void DoTestDrawGraphicL();
1.331 + void DoTestDrawGraphicIDL();
1.332 + void DoTestDrawGraphicCompareL();
1.333 + void DoTestDrawAnimatedGraphicUIDL();
1.334 + void DoTestDrawAnimatedGraphicIDL();
1.335 + void DoTestDrawGraphicSessionHandleL();
1.336 + void DoTestCreateMsgGraphicMsgBufL();
1.337 + void DoTestDrawReplaceGraphicIDL();
1.338 + void DoTestDrawInvalidBitmapIDL();
1.339 + void DoTestDrawInvalidAnimationIDL();
1.340 +private :
1.341 + TInt iScreenNumber;
1.342 + CWindowGc *iGc;
1.343 + RWsSession iWs;
1.344 + RWindowGroup *iGroupWin;
1.345 + CWsScreenDevice *iScreen;
1.346 + RWindow *iWin;
1.347 + TLogMessageText iTestLog;
1.348 + TRect iPosition1;
1.349 + TRect iPosition2;
1.350 + CActiveWait* iTimer;
1.351 + CRedrawAO* iRedrawListener;
1.352 + TWsGraphicId iAnimId;
1.353 + TWsGraphicAnimation iAnimData;
1.354 + };
1.355 +
1.356 +//
1.357 +// class CRedrawAO
1.358 +// request & listen for redraw events from wserv
1.359 +// if a redraw event is received, notify the observing class
1.360 +//
1.361 +class CRedrawAO : public CActive
1.362 + {
1.363 +public:
1.364 + static CRedrawAO* NewL(RWsSession* aWs);
1.365 + ~CRedrawAO();
1.366 + // from CActive:
1.367 + void RunL();
1.368 + void DoCancel();
1.369 + TInt RunError(TInt aError);
1.370 + void RequestRedraw();
1.371 + inline void SetFrameCount(TInt aCount){iFrameCount = aCount;};
1.372 + inline TInt GetFrameCount() const {return iFrameCount;};
1.373 +private:
1.374 + CRedrawAO(RWsSession* aWs);
1.375 + void ConstructL();
1.376 +private:
1.377 + RWsSession* iWs;
1.378 + TInt iFrameCount;
1.379 + };
1.380 +
1.381 +CRedrawAO* CRedrawAO::NewL(RWsSession* aWs)
1.382 + {
1.383 + CRedrawAO* self = new (ELeave) CRedrawAO(aWs);
1.384 + CleanupStack::PushL(self);
1.385 + self->ConstructL();
1.386 + CleanupStack::Pop(self);
1.387 + return self;
1.388 + }
1.389 +
1.390 +CRedrawAO::CRedrawAO(RWsSession* aWs):
1.391 +CActive(CActive::EPriorityHigh), iWs(aWs)
1.392 + {
1.393 + CActiveScheduler::Add(this);
1.394 + }
1.395 +
1.396 +CRedrawAO::~CRedrawAO()
1.397 + {
1.398 + // cleanup
1.399 + Cancel();
1.400 + }
1.401 +
1.402 +void CRedrawAO::ConstructL()
1.403 + {
1.404 + // nothing to construct
1.405 + }
1.406 +
1.407 +void CRedrawAO::RunL()
1.408 + {
1.409 + // leave if status is not ok. RunError will process this result
1.410 + User::LeaveIfError(iStatus.Int());
1.411 + TWsRedrawEvent redraw;
1.412 + iWs->GetRedraw(redraw);
1.413 + TUint redrawHandle = redraw.Handle();
1.414 + if (redrawHandle == ENullWsHandle)
1.415 + {
1.416 + User::Leave(KErrBadHandle); // sanity check the client handle isn't a dummy
1.417 + }
1.418 + else if (redrawHandle)
1.419 + {
1.420 + --iFrameCount;
1.421 + (reinterpret_cast<CWsGraphicBase *>(redrawHandle))->RedrawMe(redraw.Rect(), iFrameCount); // handle the redraw signal
1.422 + }
1.423 +
1.424 + if (iFrameCount > 0)
1.425 + {
1.426 + RequestRedraw();
1.427 + }
1.428 + }
1.429 +
1.430 +TInt CRedrawAO::RunError(TInt aError)
1.431 + {
1.432 + if (aError != KErrBadHandle)
1.433 + {
1.434 + RequestRedraw();
1.435 + }
1.436 + return KErrNone;
1.437 + }
1.438 +
1.439 +void CRedrawAO::DoCancel()
1.440 + {
1.441 + // kill all outstanding asynch. wserv requests
1.442 + iWs->RedrawReadyCancel();
1.443 + iFrameCount = KErrNone;
1.444 + }
1.445 +
1.446 +void CRedrawAO::RequestRedraw()
1.447 + {
1.448 + if (!IsActive())
1.449 + {
1.450 + iWs->RedrawReady(&iStatus);
1.451 + SetActive();
1.452 + }
1.453 + }
1.454 +
1.455 +//
1.456 +
1.457 +class CActiveWait : public CActive
1.458 + {
1.459 +public:
1.460 + static CActiveWait* NewL();
1.461 + ~CActiveWait();
1.462 + void Wait(TInt aDelay);
1.463 + // From CActive:
1.464 + void RunL();
1.465 + void DoCancel();
1.466 + TInt RunError(TInt aError);
1.467 +protected:
1.468 + CActiveWait();
1.469 + void ConstructL();
1.470 +protected:
1.471 + RTimer iTimer;
1.472 + TTime iFromTime;
1.473 + };
1.474 +
1.475 +CActiveWait* CActiveWait::NewL()
1.476 + {
1.477 + CActiveWait* self = new (ELeave) CActiveWait;
1.478 + CleanupStack::PushL(self);
1.479 + self->ConstructL();
1.480 + CleanupStack::Pop(self);
1.481 + return self;
1.482 + }
1.483 +
1.484 +void CActiveWait::ConstructL()
1.485 + {
1.486 + User::LeaveIfError(iTimer.CreateLocal());
1.487 + CActiveScheduler::Add(this);
1.488 + }
1.489 +
1.490 +CActiveWait::CActiveWait() : CActive(CActive::EPriorityStandard)
1.491 + {
1.492 + iFromTime.HomeTime();
1.493 + }
1.494 +
1.495 +CActiveWait::~CActiveWait()
1.496 + {
1.497 + Cancel();
1.498 + iTimer.Close();
1.499 + }
1.500 +
1.501 +void CActiveWait::DoCancel()
1.502 + {
1.503 + iTimer.Cancel();
1.504 + CActiveScheduler::Stop();
1.505 + }
1.506 +
1.507 +void CActiveWait::RunL()
1.508 + {
1.509 + CActiveScheduler::Stop();
1.510 + }
1.511 +
1.512 +TInt CActiveWait::RunError(TInt aError)
1.513 + {
1.514 + return aError; // exists so a break point can be placed on it.
1.515 + }
1.516 +
1.517 +void CActiveWait::Wait(TInt aDelay)
1.518 +
1.519 +
1.520 + {
1.521 + iTimer.After(iStatus, aDelay);
1.522 + SetActive();
1.523 + CActiveScheduler::Start();
1.524 + }
1.525 +
1.526 +//
1.527 +
1.528 +CWsGraphicBase::CWsGraphicBase(TInt aScreenNumber) : iScreenNumber(aScreenNumber), iAnimId(KDummyGraphicId)
1.529 + {
1.530 + }
1.531 +
1.532 +CWsGraphicBase::~CWsGraphicBase()
1.533 + {
1.534 + iWin->Close();
1.535 + delete iWin;
1.536 + delete iScreen;
1.537 + delete iGc;
1.538 + delete iGroupWin;
1.539 + iWs.Close();
1.540 + if (iTimer)
1.541 + {
1.542 + delete iTimer;
1.543 + iTimer = NULL;
1.544 + }
1.545 + if (iRedrawListener)
1.546 + {
1.547 + delete iRedrawListener;
1.548 + iRedrawListener = NULL;
1.549 + }
1.550 + }
1.551 +
1.552 +void CWsGraphicBase::ConstructL()
1.553 + {
1.554 + User::LeaveIfError(iWs.Connect());
1.555 + iScreen=new(ELeave) CWsScreenDevice(iWs);
1.556 + User::LeaveIfError(iScreen->Construct(iScreenNumber));
1.557 +
1.558 + TSize screenSize = iScreen->SizeInPixels();
1.559 + iPosition1.SetRect(0,0,screenSize.iWidth/2,screenSize.iHeight);
1.560 + iPosition2.SetRect(screenSize.iWidth/2,0,screenSize.iWidth,screenSize.iHeight);
1.561 +
1.562 + iTimer = CActiveWait::NewL();
1.563 + iRedrawListener = CRedrawAO::NewL(&iWs);
1.564 +
1.565 + iGc=new(ELeave) CWindowGc(iScreen);
1.566 + User::LeaveIfError(iGc->Construct());
1.567 + iGroupWin=new(ELeave) RWindowGroup(iWs);
1.568 + iGroupWin->Construct(1);
1.569 +
1.570 + iWin=new(ELeave) RWindow(iWs);
1.571 + iWin->Construct(*iGroupWin, (TUint32)this);
1.572 + iWin->EnableRedrawStore(EFalse); // disable the redraw store for these tests
1.573 + iWin->SetRequiredDisplayMode(EColor256);
1.574 + iWin->SetExtent(TPoint(0,0),iScreen->SizeInPixels());
1.575 + iWin->Activate();
1.576 + iWin->BeginRedraw();
1.577 + iWin->EndRedraw();
1.578 + iWs.Flush();
1.579 + }
1.580 +
1.581 +// To test whether sharing of graphics works a new process has to be launched.
1.582 +// The argument is set whether the graphic should be shared or not.
1.583 +void CWsGraphicBase::LaunchNewProcessL(const TDesC& aExecutable, TBool aShare)
1.584 + {
1.585 + TBuf<128> args;
1.586 + RProcess pr;
1.587 + TRequestStatus status;
1.588 +
1.589 + if (aShare)
1.590 + {
1.591 + args.Append(KShare);
1.592 + }
1.593 + else
1.594 + {
1.595 + args.Append(KNoShare);
1.596 + }
1.597 +
1.598 + User::LeaveIfError(pr.Create(aExecutable,args));
1.599 + pr.Logon(status);
1.600 + pr.Resume();
1.601 + User::WaitForRequest(status);
1.602 + pr.Close();
1.603 +
1.604 + if (status != KErrNone)
1.605 + {
1.606 + User::Leave(status.Int());
1.607 + }
1.608 + }
1.609 +
1.610 +//
1.611 +// CWsGraphicBase::PrepGc
1.612 +// activate a gc & clear the two rects
1.613 +//
1.614 +void CWsGraphicBase::PrepGc()
1.615 + {
1.616 + iGc->Activate(*iWin);
1.617 + iWin->Invalidate();
1.618 + iWin->BeginRedraw();
1.619 + iGc->Clear(iPosition1);
1.620 + iGc->Clear(iPosition2);
1.621 + iWs.Flush();
1.622 + }
1.623 +
1.624 +//
1.625 +// CWsGraphicBase::RetireGc
1.626 +// deactivate a gc & flush any outstanding RWindow requests
1.627 +void CWsGraphicBase::RetireGc()
1.628 + {
1.629 + iGc->Deactivate();
1.630 + iWin->EndRedraw();
1.631 + iWs.Flush();
1.632 + }
1.633 +
1.634 +//
1.635 +// CWsGraphicBase::RedrawMe
1.636 +// called from the redraw listener AO, triggered by a redraw event
1.637 +// Invalidates the area requiring a redraw &
1.638 +// initiates a redraw of the CWsGraphicBitmapAnimation's window
1.639 +//
1.640 +void CWsGraphicBase::RedrawMe(TRect aRedrawRect, TInt aFrame)
1.641 + {
1.642 + // do draw with next frame
1.643 + if (iAnimData.IsPlaying())
1.644 + {
1.645 + iGc->Activate(*iWin);
1.646 + iWin->Invalidate(aRedrawRect);
1.647 + iWin->BeginRedraw();
1.648 + iWs.Flush();
1.649 + iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg());
1.650 + iGc->Deactivate();
1.651 + iWin->EndRedraw();
1.652 + iWs.Flush();
1.653 +
1.654 + // check for last frame
1.655 + if (aFrame == 0)
1.656 + {
1.657 + iTimer->Cancel();
1.658 + }
1.659 + }
1.660 + }
1.661 +
1.662 +/**
1.663 + @SYMTestCaseID GRAPHICS-WSERV-0001
1.664 +
1.665 + @SYMPREQ PREQ1246
1.666 +
1.667 + @SYMTestCaseDesc Create Globally and Locally Shared Graphic Bitmaps from UIDs.
1.668 +
1.669 + @SYMTestPriority High
1.670 +
1.671 + @SYMTestStatus Implemented
1.672 +
1.673 + @SYMTestActions First test that TWsGraphicIds can be created from UIDs. Then create CWsGraphicBitmap objects through
1.674 + CWsGraphicBitmap::NewL, passing a UID from a TWsGraphicId. Two different objects are created
1.675 + 1. Globally shared available to all applications
1.676 + 2. Locally shared available to selected clients
1.677 +
1.678 + @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no errors are reported.
1.679 + */
1.680 +void CWsGraphicBase::DoTestCreateGraphicUidL()
1.681 + {
1.682 + iTestLog.Append(_L("CreateGraphicUid"));
1.683 +
1.684 + _LIT_SECURE_ID(KTestSecId,0x12345678);
1.685 +
1.686 + // Test the creation of TWsGraphicIds from UIDs
1.687 + TUid uid1 = {0x10000001};
1.688 + TUid uid2 = {0x10000002};
1.689 +
1.690 + TWsGraphicId twsGraphicId1(uid1);
1.691 + Test(twsGraphicId1.Uid()==uid1);
1.692 +
1.693 + TWsGraphicId twsGraphicId2(uid2);
1.694 + Test(twsGraphicId2.Uid()==uid2);
1.695 +
1.696 + TWsGraphicId twsGraphicId3(twsGraphicId2);
1.697 + Test(twsGraphicId3.Uid()==uid2);
1.698 +
1.699 + TWsGraphicId twsGraphicId4(1);
1.700 + twsGraphicId4.Set(uid1);
1.701 + Test(twsGraphicId4.Uid()==uid1);
1.702 +
1.703 + // Create globally shared CWsGraphicBitmap
1.704 + CFbsBitmap bitmap1;
1.705 + CFbsBitmap mask1;
1.706 +
1.707 + TSize screenSize = iScreen->SizeInPixels();
1.708 + bitmap1.Create(screenSize,iScreen->DisplayMode());
1.709 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.710 +
1.711 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(twsGraphicId1.Uid(), &bitmap1,&mask1);
1.712 + Test(bTest->IsActive());
1.713 +
1.714 + TWsGraphicId tid1 = bTest->Id();
1.715 + Test(tid1.Uid()==uid1);
1.716 +
1.717 + Test(bTest->ShareGlobally()==KErrNone);
1.718 +
1.719 + // Create local shared CWsGraphicBitmap
1.720 + CFbsBitmap bitmap2;
1.721 + CFbsBitmap mask2;
1.722 +
1.723 + bitmap2.Create(screenSize,iScreen->DisplayMode());
1.724 + mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode());
1.725 +
1.726 + CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);
1.727 +
1.728 + TWsGraphicId tid2 = bTest2->Id();
1.729 + Test(tid2.Uid()==uid2);
1.730 +
1.731 + Test(bTest2->Share(KTestSecId)==KErrNone);
1.732 +
1.733 + // Test the unsharing of the CWsGraphicBitmaps
1.734 + Test(bTest->UnShareGlobally()==KErrNone);
1.735 + Test(bTest2->UnShare(KTestSecId)==KErrNone);
1.736 + Test(bTest2->UnShare(KTestSecId)==KErrNotFound);
1.737 +
1.738 + delete bTest;
1.739 + delete bTest2;
1.740 + }
1.741 +
1.742 +/**
1.743 + @SYMTestCaseID GRAPHICS-WSERV-0002
1.744 +
1.745 + @SYMPREQ PREQ1246
1.746 +
1.747 + @SYMTestCaseDesc Create Globally and Locally Shared Graphic Bitmaps.
1.748 +
1.749 + @SYMTestPriority High
1.750 +
1.751 + @SYMTestStatus Implemented
1.752 +
1.753 + @SYMTestActions First test that TWsGraphicIds can be created from IDs. Then create CWsGraphicBitmap objects through
1.754 + CWsGraphicBitmap::NewL. Two different objects are created
1.755 + 1. Globally shared available to all applications
1.756 + 2. Locally shared available to selected clients
1.757 +
1.758 + @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no errors are reported.
1.759 + */
1.760 +void CWsGraphicBase::DoTestCreateGraphicIdL()
1.761 + {
1.762 + iTestLog.Append(_L("CreateGraphicId"));
1.763 +
1.764 + _LIT_SECURE_ID(KTestSecId,0x12345678);
1.765 +
1.766 + // Test creating TWsGraphicIds from ids first
1.767 + TUid uid1 = {0x10000001};
1.768 +
1.769 + TWsGraphicId twsGraphicId1(uid1);
1.770 +
1.771 + twsGraphicId1.Set(9);
1.772 + Test(twsGraphicId1.Id()==9);
1.773 +
1.774 + TWsGraphicId twsGraphicId2(twsGraphicId1);
1.775 + Test(twsGraphicId2.Id()==9);
1.776 +
1.777 + TWsGraphicId twsGraphicId3(7);
1.778 + Test(twsGraphicId3.Id()==7);
1.779 +
1.780 + // Create globally shared CWsGraphicBitmap
1.781 + CFbsBitmap bitmap1;
1.782 + CFbsBitmap mask1;
1.783 +
1.784 + TSize screenSize = iScreen->SizeInPixels();
1.785 + bitmap1.Create(screenSize,iScreen->DisplayMode());
1.786 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.787 +
1.788 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.789 + Test(bTest->IsActive());
1.790 +
1.791 + TWsGraphicId tid1 = bTest->Id();
1.792 +
1.793 + Test(bTest->ShareGlobally()==KErrNone);
1.794 +
1.795 + // Create local shared CWsGraphicBitmap
1.796 + CFbsBitmap bitmap2;
1.797 + CFbsBitmap mask2;
1.798 +
1.799 + bitmap2.Create(screenSize,iScreen->DisplayMode());
1.800 + mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode());
1.801 +
1.802 + CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2);
1.803 +
1.804 + TWsGraphicId tid2 = bTest2->Id();
1.805 +
1.806 + Test(bTest2->Share(KTestSecId)==KErrNone);
1.807 +
1.808 + // Test the unsharing of the CWsGraphicBitmaps
1.809 + Test(bTest->UnShareGlobally()==KErrNone);
1.810 + Test(bTest2->UnShare(KTestSecId)==KErrNone);
1.811 + Test(bTest2->UnShare(KTestSecId)==KErrNotFound);
1.812 +
1.813 + delete bTest2;
1.814 + delete bTest;
1.815 + }
1.816 +
1.817 + /**
1.818 + @SYMTestCaseID GRAPHICS-WSERV-0003
1.819 +
1.820 + @SYMPREQ PREQ1246
1.821 +
1.822 + @SYMTestCaseDesc Update an existing graphic bitmap with new data.
1.823 +
1.824 + @SYMTestPriority High
1.825 +
1.826 + @SYMTestStatus Implemented
1.827 +
1.828 + @SYMTestActions The test calls CWsGraphicBitmap::NewL method with new data passed to the CWsGraphicBitmap object.
1.829 +
1.830 +
1.831 + @SYMTestExpectedResults The CWsGraphicBitmap object is updated with no errors reported.
1.832 + */
1.833 +void CWsGraphicBase::DoTestUpdateGraphicL()
1.834 + {
1.835 + iTestLog.Append(_L("UpdateGraphic"));
1.836 +
1.837 + CFbsBitmap bitmap1;
1.838 + CFbsBitmap mask1;
1.839 + CFbsBitmap bitmap2;
1.840 + CFbsBitmap mask2;
1.841 +
1.842 + TSize screenSize = iScreen->SizeInPixels();
1.843 + bitmap1.Create(screenSize,iScreen->DisplayMode());
1.844 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.845 +
1.846 + CWsGraphic* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.847 +
1.848 + bitmap2.Create(screenSize,iScreen->DisplayMode());
1.849 + mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode());
1.850 +
1.851 + TWsGraphicId tid1 = bTest->Id();
1.852 + TInt testInt = tid1.Id();
1.853 +
1.854 + CWsGraphic* testReplacement = CWsGraphicBitmap::NewL(tid1, &bitmap2,&mask2);
1.855 +
1.856 + delete bTest;
1.857 + bTest = testReplacement;
1.858 +
1.859 + Test(bTest->Id().Id()==testInt);
1.860 +
1.861 + delete bTest;
1.862 + }
1.863 +
1.864 +
1.865 +
1.866 + /**
1.867 + @SYMTestCaseID GRAPHICS-WSERV-0004
1.868 +
1.869 + @SYMPREQ PREQ1246
1.870 +
1.871 + @SYMTestCaseDesc Try to delete an existing graphic.
1.872 +
1.873 + @SYMTestPriority High
1.874 +
1.875 + @SYMTestStatus Implemented
1.876 +
1.877 + @SYMTestActions The test app calls CWsGraphic::Destroy() method,
1.878 +
1.879 + @SYMTestExpectedResults The CWsGraphicBitmap object is removed from the Window Server with no
1.880 + errors reported
1.881 + */
1.882 +void CWsGraphicBase::DoTestDeleteGraphicL()
1.883 + {
1.884 + iTestLog.Append(_L("DeleteGraphic"));
1.885 +
1.886 + CFbsBitmap bitmap1;
1.887 + CFbsBitmap mask1;
1.888 +
1.889 + TSize screenSize = iScreen->SizeInPixels();
1.890 + bitmap1.Create(screenSize,iScreen->DisplayMode());
1.891 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.892 +
1.893 + CWsGraphic* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.894 +
1.895 + bTest->Destroy();
1.896 +
1.897 + Test(!bTest->IsActive());
1.898 +
1.899 + delete bTest;
1.900 + }
1.901 +
1.902 + /**
1.903 + @SYMTestCaseID GRAPHICS-WSERV-0005
1.904 +
1.905 + @SYMPREQ PREQ1246
1.906 +
1.907 + @SYMTestCaseDesc Check a bitmap is not drawn if the bitmap and mask it uses are invalid
1.908 +
1.909 + @SYMTestPriority High
1.910 +
1.911 + @SYMTestStatus Implemented
1.912 +
1.913 + @SYMTestActions The test app creates a valid and invalid bitmap and attempts to draw them
1.914 +
1.915 + @SYMTestExpectedResults The valid bitmap is drawn but the invalid bitmap is not drawn
1.916 + */
1.917 +void CWsGraphicBase::DoTestDrawInvalidBitmapIDL()
1.918 + {
1.919 + iTestLog.Append(_L("DrawInvalidBitmapID"));
1.920 +
1.921 + CFbsBitmap bitmap1;
1.922 + CFbsBitmap mask1;
1.923 + CFbsBitmap *bitmap2 = NULL;
1.924 + CFbsBitmap *mask2 = NULL;
1.925 +
1.926 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.927 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.928 +
1.929 + // valid bitmap
1.930 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.931 +
1.932 + // invalid bitmap
1.933 + CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(bitmap2,mask2);
1.934 +
1.935 + PrepGc();
1.936 + iGc->DrawWsGraphic(bTest->Id(),iPosition1);
1.937 + iGc->DrawWsGraphic(bTest2->Id(),iPosition2);
1.938 + RetireGc();
1.939 +
1.940 + // compare the graphic in both positions, should only be graphic in position 1
1.941 + TestForDifferentBitmaps();
1.942 +
1.943 + delete bTest2;
1.944 + delete bTest;
1.945 + }
1.946 +
1.947 + /**
1.948 + @SYMTestCaseID GRAPHICS-WSERV-0006
1.949 +
1.950 + @SYMPREQ PREQ1246
1.951 +
1.952 + @SYMTestCaseDesc Draw a graphic within a rectangle on the screen, then try to draw with a non-existant graphic
1.953 +
1.954 + @SYMTestPriority High
1.955 +
1.956 + @SYMTestStatus Implemented
1.957 +
1.958 + @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() method using the TWGraphicId object, to draw within a rectangle on the screen
1.959 +
1.960 + @SYMTestExpectedResults The graphic is drawn on the screen with no errors reported. Drawing with a non-existant graphic causes
1.961 + nothing to be drawn and no error reported
1.962 + */
1.963 +void CWsGraphicBase::DoTestDrawGraphicL()
1.964 + {
1.965 + iTestLog.Append(_L("DrawGraphic"));
1.966 +
1.967 + _LIT8(KTestData,"HelloWorld");
1.968 +
1.969 + CFbsBitmap bitmap1;
1.970 + CFbsBitmap mask1;
1.971 +
1.972 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.973 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.974 +
1.975 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.976 +
1.977 + PrepGc();
1.978 + iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData);
1.979 + TWsGraphicId twsGraphicId1(KDummyGraphicId); // create unrecognised wsbitmap id & attempt to draw it
1.980 + iGc->DrawWsGraphic(twsGraphicId1,iPosition2,KTestData);
1.981 + RetireGc();
1.982 +
1.983 + // compare the graphic in both positions, should only be graphic in position 1
1.984 + TestForDifferentBitmaps();
1.985 +
1.986 + delete bTest;
1.987 + }
1.988 +
1.989 + /**
1.990 + @SYMTestCaseID GRAPHICS-WSERV-0007
1.991 +
1.992 + @SYMPREQ PREQ1246
1.993 +
1.994 + @SYMTestCaseDesc Draw a graphic using a transient ID within a rectangle on the screen
1.995 +
1.996 + @SYMTestPriority High
1.997 +
1.998 + @SYMTestStatus Implemented
1.999 +
1.1000 + @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() using a TWsGraphic object, to draw within
1.1001 + a rectangle on the screen
1.1002 +
1.1003 + @SYMTestExpectedResults The graphic is drawn.
1.1004 + */
1.1005 +void CWsGraphicBase::DoTestDrawGraphicIDL()
1.1006 + {
1.1007 + iTestLog.Append(_L("DrawGraphicID"));
1.1008 +
1.1009 + CFbsBitmap bitmap1;
1.1010 + CFbsBitmap mask1;
1.1011 +
1.1012 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.1013 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.1014 +
1.1015 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.1016 +
1.1017 + PrepGc();
1.1018 + iGc->DrawWsGraphic(bTest->Id(),iPosition1);
1.1019 + RetireGc();
1.1020 +
1.1021 + // compare the graphic in both positions, should only be graphic in position 1
1.1022 + TestForDifferentBitmaps();
1.1023 +
1.1024 + delete bTest;
1.1025 + }
1.1026 +
1.1027 +
1.1028 +
1.1029 + /**
1.1030 + @SYMTestCaseID GRAPHICS-WSERV-0008
1.1031 +
1.1032 + @SYMPREQ PREQ1246
1.1033 +
1.1034 + @SYMTestCaseDesc Draw a graphic in two different rectangles on the screen and compare them
1.1035 +
1.1036 + @SYMTestPriority High
1.1037 +
1.1038 + @SYMTestStatus Implemented
1.1039 +
1.1040 + @SYMTestActions The test app calls CWindowGC::DrawWsGraphic() using the TWsGraphic object, to draw a known bitmap
1.1041 + rectangle on the screen twice in different places. The bitmaps are then compared.
1.1042 +
1.1043 + @SYMTestExpectedResults The two bitmaps are identical
1.1044 + */
1.1045 +void CWsGraphicBase::DoTestDrawGraphicCompareL()
1.1046 + {
1.1047 + iTestLog.Append(_L("DrawGraphicCompare"));
1.1048 +
1.1049 + _LIT8(KTestData,"HelloWorld");
1.1050 +
1.1051 + CFbsBitmap bitmap1;
1.1052 + CFbsBitmap mask1;
1.1053 +
1.1054 + CFbsBitmap bitmap2;
1.1055 + CFbsBitmap mask2;
1.1056 +
1.1057 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.1058 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.1059 +
1.1060 + User::LeaveIfError(bitmap2.Load(MY_TEST_BITMAP,0));
1.1061 + mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode());
1.1062 +
1.1063 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.1064 + CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2);
1.1065 +
1.1066 + PrepGc();
1.1067 + //draw the graphic in the two different rectangles
1.1068 + iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData);
1.1069 + iGc->DrawWsGraphic(bTest2->Id(),iPosition2,KTestData);
1.1070 + RetireGc();
1.1071 +
1.1072 + // compare the graphic in both positions. Contents of each rect should be identical
1.1073 + TestForIdenticalBitmaps();
1.1074 +
1.1075 + delete bTest2;
1.1076 + delete bTest;
1.1077 + }
1.1078 +
1.1079 + /**
1.1080 + @SYMTestCaseID GRAPHICS-WSERV-0009
1.1081 +
1.1082 + @SYMPREQ PREQ1246
1.1083 +
1.1084 + @SYMTestCaseDesc Draw a global and local graphic in two different rectangles on the screen and compare them
1.1085 +
1.1086 + @SYMTestPriority High
1.1087 +
1.1088 + @SYMTestStatus Implemented
1.1089 +
1.1090 + @SYMTestActions The test app calls CWindowGC::DrawGraphic() using the TWsGraphic object, to draw a known
1.1091 + global and local bitmap rectangle on the screen twice in different places. The bitmaps are then compared.
1.1092 +
1.1093 + @SYMTestExpectedResults The two bitmaps are identical
1.1094 + */
1.1095 +void CWsGraphicBase::DoTestDrawGraphicSessionHandleL()
1.1096 + {
1.1097 + iTestLog.Append(_L("DrawGraphicSessionHandle"));
1.1098 + _LIT_SECURE_ID(KTestSecId,0x12345678);
1.1099 +
1.1100 + // test TWsGraphicControlState first
1.1101 + _LIT8(KTestData,"HelloWorld");
1.1102 +
1.1103 + CFbsBitmap bitmap1;
1.1104 + CFbsBitmap mask1;
1.1105 +
1.1106 + CFbsBitmap bitmap2;
1.1107 + CFbsBitmap mask2;
1.1108 +
1.1109 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.1110 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.1111 +
1.1112 + User::LeaveIfError(bitmap2.Load(MY_TEST_BITMAP,0));
1.1113 + mask2.Create(bitmap2.SizeInPixels(),iScreen->DisplayMode());
1.1114 +
1.1115 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1);
1.1116 + CWsGraphicBitmap* bTest2 = CWsGraphicBitmap::NewL(&bitmap2,&mask2);
1.1117 +
1.1118 + Test(bTest->ShareGlobally()==KErrNone);
1.1119 + Test(bTest2->Share(KTestSecId)==KErrNone);
1.1120 +
1.1121 + PrepGc();
1.1122 + iGc->DrawWsGraphic(bTest->Id(),iPosition1,KTestData);
1.1123 + iGc->DrawWsGraphic(bTest2->Id(),iPosition2,KTestData);
1.1124 + RetireGc();
1.1125 +
1.1126 + // compare the graphic in both positions. Contents of each rect should be identical
1.1127 + TestForIdenticalBitmaps();
1.1128 +
1.1129 + delete bTest2;
1.1130 + delete bTest;
1.1131 + }
1.1132 +
1.1133 + /**
1.1134 + @SYMTestCaseID GRAPHICS-WSERV-0010
1.1135 +
1.1136 + @SYMPREQ PREQ1246
1.1137 +
1.1138 + @SYMTestCaseDesc Check an animation can be constructed using a UID, manipulated and then drawn
1.1139 +
1.1140 + @SYMTestPriority High
1.1141 +
1.1142 + @SYMTestStatus Implemented
1.1143 +
1.1144 + @SYMTestActions The test app creates CWsGraphicBitmapAnimation object via a UID and then draws the object to the screen
1.1145 +
1.1146 + @SYMTestExpectedResults The object is drawn
1.1147 + */
1.1148 +void CWsGraphicBase::DoTestDrawAnimatedGraphicUIDL()
1.1149 + {
1.1150 + iTestLog.Append(_L("DrawAnimatedGraphicUID"));
1.1151 +
1.1152 + // test TWsGraphicAnimation first
1.1153 + iAnimData.Play(EFalse);
1.1154 +
1.1155 + // load the animation via a UID
1.1156 + CIclLoader* iclLoader;
1.1157 + iclLoader = new(ELeave) CIclLoader();
1.1158 + iclLoader->ConstructL(KSymBallFile,ETrue,EFalse); // this is actually an asynchronous operation, so we give it a chance to execute below
1.1159 +
1.1160 + while (iclLoader->Ok() && iclLoader->GetId().Id() == KDummyGraphicId)
1.1161 + {
1.1162 + iTimer->Wait(1000);
1.1163 + }
1.1164 +
1.1165 + Test(iclLoader->Ok()); // fail test if iclLoder experienced problems
1.1166 +
1.1167 + iAnimId = iclLoader->GetId();
1.1168 +
1.1169 + // animation is ready to be drawn. draw to the 1st position only
1.1170 + PrepGc();
1.1171 + iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg());
1.1172 + RetireGc();
1.1173 +
1.1174 + // run the animation
1.1175 + RunAnimation(iclLoader->FrameCount());
1.1176 +
1.1177 + // compare the graphic in both positions.
1.1178 + TestForDifferentBitmaps();
1.1179 +
1.1180 + iTimer->Cancel();
1.1181 + iclLoader->Cancel();
1.1182 + delete iclLoader;
1.1183 + }
1.1184 +
1.1185 + /**
1.1186 + @SYMTestCaseID GRAPHICS-WSERV-0011
1.1187 +
1.1188 + @SYMPREQ PREQ1246
1.1189 +
1.1190 + @SYMTestCaseDesc Check an animation can be constructed using an ID, manipulated and then drawn
1.1191 +
1.1192 + @SYMTestPriority High
1.1193 +
1.1194 + @SYMTestStatus Implemented
1.1195 +
1.1196 + @SYMTestActions The test app creates CWsGraphicBitmapAnimation object via an ID and then draws the object to the screen
1.1197 +
1.1198 + @SYMTestExpectedResults The object is drawn
1.1199 + */
1.1200 +void CWsGraphicBase::DoTestDrawAnimatedGraphicIDL()
1.1201 + {
1.1202 + iTestLog.Append(_L("DrawAnimatedGraphicID"));
1.1203 + iAnimData.Play(ETrue);
1.1204 + iAnimData.Play(ETrue);
1.1205 + Test(iAnimData.Loops());
1.1206 + iAnimData.Pause();
1.1207 + Test(!iAnimData.IsPlaying());
1.1208 + Test(iAnimData.IsPaused());
1.1209 + iAnimData.Pause();
1.1210 + Test(iAnimData.Loops());
1.1211 + iAnimData.Play(EFalse);
1.1212 + Test(!iAnimData.Loops());
1.1213 + Test(!iAnimData.IsStopping());
1.1214 + Test(!iAnimData.IsStopped());
1.1215 +
1.1216 + // load the animation via an ID
1.1217 + CIclLoader* iclLoader;
1.1218 + iclLoader = new(ELeave) CIclLoader();
1.1219 + iclLoader->ConstructL(KSymBallFile,EFalse,EFalse);
1.1220 +
1.1221 + while (iclLoader->GetId().Id() == KDummyGraphicId)
1.1222 + {
1.1223 + iTimer->Wait(1000);
1.1224 + }
1.1225 + iAnimId = iclLoader->GetId();
1.1226 +
1.1227 + PrepGc();
1.1228 + iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg());
1.1229 + RetireGc();
1.1230 +
1.1231 + // run the animation
1.1232 + RunAnimation(iclLoader->FrameCount());
1.1233 +
1.1234 + // compare the graphic in both positions
1.1235 + TestForDifferentBitmaps();
1.1236 +
1.1237 + iAnimData.Stop(ETrue);
1.1238 + Test(iAnimData.IsStopped());
1.1239 + iAnimData.Pause();
1.1240 + iAnimData.Play(EFalse);
1.1241 + iAnimData.Stop(EFalse);
1.1242 + Test(!iAnimData.IsStopped());
1.1243 +
1.1244 + iTimer->Cancel();
1.1245 + iclLoader->Cancel();
1.1246 + delete iclLoader;
1.1247 + }
1.1248 +
1.1249 + /**
1.1250 + @SYMTestCaseID GRAPHICS-WSERV-0012
1.1251 +
1.1252 + @SYMPREQ PREQ1246
1.1253 +
1.1254 + @SYMTestCaseDesc Check an animation can be constructed and then replaced, manipulated and then drawn
1.1255 +
1.1256 + @SYMTestPriority High
1.1257 +
1.1258 + @SYMTestStatus Implemented
1.1259 +
1.1260 + @SYMTestActions The test app creates CWsGraphicBitmapAnimation object, the replaces it, and then draws the object
1.1261 + to the screen
1.1262 +
1.1263 + @SYMTestExpectedResults The object is drawn
1.1264 + */
1.1265 +void CWsGraphicBase::DoTestDrawReplaceGraphicIDL()
1.1266 + {
1.1267 + // test TWsGraphicControlStateTimed first
1.1268 + iTestLog.Append(_L("DrawAnimatedGraphicID"));
1.1269 + _LIT8(KTestData,"HelloWorld");
1.1270 + iAnimData.Stop(ETrue);
1.1271 +
1.1272 + // load and replace the animation
1.1273 + CIclLoader* iclLoader;
1.1274 + iclLoader = new(ELeave) CIclLoader();
1.1275 + iclLoader->ConstructL(KSymBallFile,false,true);
1.1276 +
1.1277 + while (iclLoader->GetId().Id() == KDummyGraphicId)
1.1278 + {
1.1279 + iTimer->Wait(1000);
1.1280 + }
1.1281 + iAnimId = iclLoader->GetId();
1.1282 +
1.1283 + // draw the animation in two positions
1.1284 + PrepGc();
1.1285 + iGc->DrawWsGraphic(iAnimId,iPosition1,KTestData);
1.1286 + RetireGc();
1.1287 +
1.1288 + // run the animation
1.1289 + RunAnimation(iclLoader->FrameCount());
1.1290 +
1.1291 + // compare the graphic in both positions
1.1292 + // Expect identical, as the command buffer used in position1 animation is invalid, therefore never drawn
1.1293 + TestForIdenticalBitmaps();
1.1294 +
1.1295 + iTimer->Cancel();
1.1296 + iclLoader->Cancel();
1.1297 + delete iclLoader;
1.1298 + }
1.1299 +
1.1300 + /**
1.1301 + @SYMTestCaseID GRAPHICS-WSERV-0013
1.1302 +
1.1303 + @SYMPREQ PREQ1246
1.1304 +
1.1305 + @SYMTestCaseDesc Check the creation and manipulation of an RWsGraphicMsgBuf object
1.1306 +
1.1307 + @SYMTestPriority High
1.1308 +
1.1309 + @SYMTestStatus Implemented
1.1310 +
1.1311 + @SYMTestActions Creates and manipulates an RWsGraphicMsgBuf object
1.1312 +
1.1313 + @SYMTestExpectedResults RWsGraphicMsgBuf functions correctly
1.1314 + */
1.1315 +void CWsGraphicBase::DoTestCreateMsgGraphicMsgBufL()
1.1316 + {
1.1317 + iTestLog.Append(_L("CreateMsgGraphicMsgBuf"));
1.1318 +
1.1319 + _LIT(KNebraska,"Nebraska");
1.1320 + _LIT8(KTesting,"Testing");
1.1321 + RWsGraphicMsgBuf msgBuf;
1.1322 + msgBuf.CleanupClosePushL();
1.1323 + msgBuf.Append(TUid::Uid(0x12345670),KTesting());
1.1324 + msgBuf.Append(TUid::Uid(0x12345671),KNebraska());
1.1325 + msgBuf.Append(TUid::Uid(0x12345670),KTesting());
1.1326 +
1.1327 + Test(TUid::Uid(0x12345670)==msgBuf.TypeId(0));
1.1328 +
1.1329 + msgBuf.Remove(0);
1.1330 + const TInt count = msgBuf.Count();
1.1331 + Test(count == 2);
1.1332 +
1.1333 + iAnimData.Play(ETrue);
1.1334 + msgBuf.Append(iAnimData);
1.1335 + Test(msgBuf.Count() == 3);
1.1336 +
1.1337 + CleanupStack::Pop();
1.1338 +
1.1339 + // load the animation via a UID
1.1340 + CIclLoader* iclLoader;
1.1341 + iclLoader = new(ELeave) CIclLoader();
1.1342 + iclLoader->ConstructL(KSymBallFile,true,false);
1.1343 +
1.1344 + while (iclLoader->GetId().Id() == KDummyGraphicId)
1.1345 + {
1.1346 + iTimer->Wait(1000);
1.1347 + }
1.1348 + iAnimId = iclLoader->GetId();
1.1349 +
1.1350 + PrepGc();
1.1351 + iGc->DrawWsGraphic(iAnimId,iPosition1,msgBuf.Pckg());
1.1352 + RetireGc();
1.1353 +
1.1354 + // run the animation
1.1355 + RunAnimation(iclLoader->FrameCount());
1.1356 +
1.1357 + // compare the graphic in both positions
1.1358 + TestForDifferentBitmaps();
1.1359 +
1.1360 + iTimer->Cancel();
1.1361 + iclLoader->Cancel();
1.1362 + delete iclLoader;
1.1363 + msgBuf.Close();
1.1364 + }
1.1365 +
1.1366 +
1.1367 +
1.1368 + /**
1.1369 + @SYMTestCaseID GRAPHICS-WSERV-0014
1.1370 +
1.1371 + @SYMPREQ PREQ1246
1.1372 +
1.1373 + @SYMTestCaseDesc Check an animation is not drawn if the command buffer it uses is invalid
1.1374 +
1.1375 + @SYMTestPriority High
1.1376 +
1.1377 + @SYMTestStatus Implemented
1.1378 +
1.1379 + @SYMTestActions The test app creates CWsGraphicBitmapAnimation object then draws the animation using
1.1380 + a valid and invalid command buffer
1.1381 +
1.1382 + @SYMTestExpectedResults The animation is drawn while using the valid command buffer but not drawn
1.1383 + when the command buffer is invalid
1.1384 + */
1.1385 +void CWsGraphicBase::DoTestDrawInvalidAnimationIDL()
1.1386 + {
1.1387 + // test TWsGraphicControlStateTimed first, a valid command buffer
1.1388 + iTestLog.Append(_L("DrawInvalidAnimationID"));
1.1389 + iAnimData.Play(ETrue);
1.1390 +
1.1391 + // invalid command buffer
1.1392 + _LIT8(KTestData2,"12345678");
1.1393 +
1.1394 + // load and replace the animation
1.1395 + CIclLoader* iclLoader;
1.1396 + iclLoader = new(ELeave) CIclLoader();
1.1397 + iclLoader->ConstructL(KSymBallFile,false,false);
1.1398 +
1.1399 + while (iclLoader->GetId().Id() == KDummyGraphicId)
1.1400 + {
1.1401 + iTimer->Wait(1000);
1.1402 + }
1.1403 + iAnimId = iclLoader->GetId();
1.1404 +
1.1405 + PrepGc();
1.1406 + iGc->DrawWsGraphic(iAnimId,iPosition1,iAnimData.Pckg());
1.1407 + iGc->DrawWsGraphic(iAnimId,iPosition2,KTestData2);
1.1408 + RetireGc();
1.1409 +
1.1410 + // run the animation
1.1411 + RunAnimation(iclLoader->FrameCount());
1.1412 +
1.1413 + // compare the graphic in both positions
1.1414 + TestForDifferentBitmaps();
1.1415 +
1.1416 + iAnimData.Stop(ETrue);
1.1417 + iTimer->Cancel();
1.1418 + iclLoader->Cancel();
1.1419 + delete iclLoader;
1.1420 + }
1.1421 +
1.1422 + /**
1.1423 + @SYMTestCaseID GRAPHICS-WSERV-0015
1.1424 +
1.1425 + @SYMPREQ PREQ1246
1.1426 +
1.1427 + @SYMTestCaseDesc Check the sharing of graphics with other clients.
1.1428 +
1.1429 + @SYMTestPriority High
1.1430 +
1.1431 + @SYMTestStatus Implemented
1.1432 +
1.1433 + @SYMTestActions The test app creates CWsGraphicBitmap object an then tests the sharing of the object with
1.1434 + different clients
1.1435 +
1.1436 + @SYMTestExpectedResults The CWsGraphicBitmap object is shared correctly
1.1437 + */
1.1438 +void CWsGraphicBase::DoTestDrawSharedGraphicL()
1.1439 + {
1.1440 + iTestLog.Append(_L("DrawSharedGraphic"));
1.1441 + _LIT_SECURE_ID(KTestSecId,0x10003a4b);
1.1442 +
1.1443 + TUid uid1 = {0x12000021};
1.1444 + TWsGraphicId twsGraphicId1(uid1);
1.1445 +
1.1446 + CFbsBitmap bitmap1;
1.1447 + CFbsBitmap mask1;
1.1448 +
1.1449 + User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0));
1.1450 + mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode());
1.1451 +
1.1452 + CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(twsGraphicId1.Uid(), &bitmap1,&mask1);
1.1453 +
1.1454 + // Try to draw the graphic in an client. Should fail as graphic is not shared
1.1455 + TRAPD(err, LaunchNewProcessL(KTestExe1, EFalse));
1.1456 + Test(err == KErrNone);
1.1457 +
1.1458 + // Share the graphic globally and try to draw the graphic in an client. Should pass
1.1459 + Test(bTest->ShareGlobally()==KErrNone);
1.1460 + TRAP(err, LaunchNewProcessL(KTestExe2, ETrue));
1.1461 + Test(err == KErrNone);
1.1462 +
1.1463 + // Unshare the graphic globally and try to draw the graphic in an client. Should fail
1.1464 + Test(bTest->UnShareGlobally()==KErrNone);
1.1465 + TRAP(err, LaunchNewProcessL(KTestExe3, EFalse));
1.1466 + Test(err == KErrNone);
1.1467 +
1.1468 + // Share the graphic to a client and try to draw the graphic in the client. Should pass
1.1469 + Test(bTest->Share(KTestSecId)==KErrNone);
1.1470 + TRAP(err, LaunchNewProcessL(KTestExe4, ETrue));
1.1471 + Test(err == KErrNone);
1.1472 +
1.1473 + // Unshare the graphic to a client and try to draw the graphic in the client. Should fail
1.1474 + Test(bTest->UnShare(KTestSecId)==KErrNone);
1.1475 + TRAP(err, LaunchNewProcessL(KTestExe5, EFalse));
1.1476 + Test(err == KErrNone);
1.1477 +
1.1478 + delete bTest;
1.1479 + }
1.1480 +
1.1481 +
1.1482 +void CWsGraphicBase::DoTestL(TInt aTestNo)
1.1483 + {
1.1484 + switch (aTestNo)
1.1485 + {
1.1486 + case ETestCreateGraphicUID:
1.1487 + DoTestCreateGraphicUidL();
1.1488 + break;
1.1489 + case ETestCreateGraphicID:
1.1490 + DoTestCreateGraphicIdL();
1.1491 + break;
1.1492 + case ETestUpdateGraphic:
1.1493 + DoTestUpdateGraphicL();
1.1494 + break;
1.1495 + case ETestDeleteGraphic:
1.1496 + DoTestDeleteGraphicL();
1.1497 + break;
1.1498 + case ETestDrawInvalideBitmapID:
1.1499 + DoTestDrawInvalidBitmapIDL();
1.1500 + break;
1.1501 + case ETestDrawGraphic:
1.1502 + DoTestDrawGraphicL();
1.1503 + break;
1.1504 + case ETestDrawGraphicID:
1.1505 + DoTestDrawGraphicIDL();
1.1506 + break;
1.1507 + case ETestDrawGraphicCompare:
1.1508 + DoTestDrawGraphicCompareL();
1.1509 + break;
1.1510 + case ETestDrawGraphicSessionHandle:
1.1511 + DoTestDrawGraphicSessionHandleL();
1.1512 + break;
1.1513 +#ifdef _DEBUG
1.1514 + // These tests require debug-only API to simulate OOM. Running
1.1515 + // the tests in non-debug environments invalidates the tests.
1.1516 + case ETestDrawAnimatedGraphicUID:
1.1517 + DoTestDrawAnimatedGraphicUIDL();
1.1518 + break;
1.1519 + case ETestDrawAnimatedGraphicID:
1.1520 + DoTestDrawAnimatedGraphicIDL();
1.1521 + break;
1.1522 + case ETestCreateMsgGraphicMsgBuf:
1.1523 + DoTestCreateMsgGraphicMsgBufL();
1.1524 + break;
1.1525 + case ETestDrawReplaceGraphicID:
1.1526 + DoTestDrawReplaceGraphicIDL();
1.1527 + break;
1.1528 + case ETestDrawInvalidAnimationID:
1.1529 + DoTestDrawInvalidAnimationIDL();
1.1530 + break;
1.1531 +#endif
1.1532 + case ETestDrawSharedGraphic:
1.1533 + DoTestDrawSharedGraphicL();
1.1534 + break;
1.1535 + }
1.1536 + RDebug::Print(iTestLog);
1.1537 + iTestLog.Delete(0,256);
1.1538 + }
1.1539 +
1.1540 +// writes out to WSERV.log if error
1.1541 +void CWsGraphicBase::Test(TInt aCondition)
1.1542 + {
1.1543 + if(!aCondition)
1.1544 + {
1.1545 + TBuf<KMaxLogLength> buf;
1.1546 + _LIT(Fail,"AUTO Failed in WsGraphics Test : ");
1.1547 + buf.Append(Fail);
1.1548 + buf.Append(iTestLog);
1.1549 + RDebug::Print(buf);
1.1550 + RProcess().Terminate(KErrGeneral);
1.1551 + }
1.1552 + }
1.1553 +
1.1554 +//
1.1555 +// CWsGraphicBase::RunAnimation
1.1556 +// Redraw event listener is launched & the
1.1557 +// animation is given a total of KAnimationRunTime (25 seconds) to run a single loop
1.1558 +//
1.1559 +void CWsGraphicBase::RunAnimation(TInt aFrameCount)
1.1560 + {
1.1561 + --aFrameCount; // account for the fact the initial frame is already displayed
1.1562 + iRedrawListener->SetFrameCount(aFrameCount);
1.1563 + iRedrawListener->RequestRedraw();
1.1564 + iTimer->Wait(KAnimationRunTime);
1.1565 + if (iAnimData.IsPlaying())
1.1566 + {
1.1567 + iAnimData.Stop(ETrue);
1.1568 + }
1.1569 + iRedrawListener->Cancel();
1.1570 + iAnimData.Stop(EFalse);
1.1571 + Test(iRedrawListener->GetFrameCount() == 0); // ensure the animation ran through until last frame
1.1572 + }
1.1573 +
1.1574 +void MainL()
1.1575 + {
1.1576 + TInt testCount = KErrNone;
1.1577 +
1.1578 + //Read the argument from the command line for current screen number
1.1579 + TBuf<256> commandLine;
1.1580 + User::CommandLine(commandLine);
1.1581 + TLex lex(commandLine);
1.1582 + lex.NextToken();
1.1583 + lex.SkipSpace();
1.1584 + TInt screenNumber=(TInt)lex.Get();
1.1585 +
1.1586 + CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler;
1.1587 + CActiveScheduler::Install(activeScheduler);
1.1588 + CleanupStack::PushL(activeScheduler);
1.1589 +
1.1590 + CWsGraphicBase testBase(screenNumber);
1.1591 + testBase.ConstructL();
1.1592 +
1.1593 + // run through all the tests
1.1594 + while (testCount < CWsGraphicBase::ETestMaxNumberOfTests)
1.1595 + {
1.1596 + testBase.DoTestL(testCount);
1.1597 + testCount++;
1.1598 + }
1.1599 +
1.1600 + CleanupStack::PopAndDestroy(activeScheduler);
1.1601 + }
1.1602 +
1.1603 +GLDEF_C TInt E32Main()
1.1604 + {
1.1605 + CTrapCleanup* cleanUpStack=CTrapCleanup::New();
1.1606 + if(cleanUpStack==NULL)
1.1607 + {
1.1608 + return KErrNoMemory;
1.1609 + }
1.1610 + TRAPD(err, MainL());
1.1611 + delete cleanUpStack;
1.1612 + return(err);
1.1613 + }