1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TTransptAnim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,367 @@
1.4 +// Copyright (c) 2003-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 +#include "TTransptAnim.h"
1.25 +
1.26 +struct FrameSet
1.27 + {
1.28 + TRgb* iFrames;
1.29 + const TInt iFrameCount;
1.30 + FrameSet(TRgb* aFrames, const TInt aFrameCount)
1.31 + : iFrames(aFrames),
1.32 + iFrameCount(aFrameCount)
1.33 + {
1.34 + }
1.35 + };
1.36 +
1.37 +TRgb FrameSequenceAlpha[]=
1.38 +{ TRgb(255, 0, 0, 50), TRgb(0, 255, 0, 70), TRgb(0, 0, 255, 100), TRgb(255, 255, 0, 150), TRgb(0, 255, 255, 200) };
1.39 +TRgb FrameSequenceNoAlpha[] =
1.40 +{ TRgb(255, 0, 0), TRgb(0, 255, 0), TRgb(0, 0, 255), TRgb(255, 255, 0), TRgb(0, 255, 255) };
1.41 +
1.42 +FrameSet frameSetAlpha(FrameSequenceAlpha, sizeof(FrameSequenceAlpha)/sizeof(TRgb));
1.43 +FrameSet frameSetNoAlpha(FrameSequenceNoAlpha, sizeof(FrameSequenceNoAlpha)/sizeof(TRgb));
1.44 +FrameSet TestFrameSets[] =
1.45 + {
1.46 + frameSetAlpha, frameSetNoAlpha
1.47 + };
1.48 +
1.49 +static const TInt FRAME_DELAY = 2000000;
1.50 +static const TInt DRAW_LINE_ANIMATION = 36;
1.51 +static const TBool ALPHATRANSPARENCY_ON = ETrue;
1.52 +static const TInt ALPHA_FRAMESET = 0;
1.53 +
1.54 +//*****************************************************************************
1.55 +CTTestCase* CTTransparentAnim::CreateTestCaseL(CTTransparentAnim* aTransAnim, TInt aTestCaseId)
1.56 + {
1.57 + CTTestCase* testCase = aTransAnim->GetCurrent();
1.58 +
1.59 + if (!testCase)
1.60 + {
1.61 + switch (aTestCaseId)
1.62 + {
1.63 + case GraphicsWServ0483 :
1.64 + testCase = CTGraphicsWServ0483::NewL();
1.65 + break;
1.66 + }
1.67 + }
1.68 +
1.69 + return testCase;
1.70 + }
1.71 +
1.72 +//*****************************************************************************
1.73 +CTTransparentAnim::CTTransparentAnim(CTestStep* aStep)
1.74 +: CTWsGraphicsBase(aStep), iCurrentTestCase(NULL)
1.75 + {}
1.76 +
1.77 +CTTransparentAnim::~CTTransparentAnim()
1.78 + {
1.79 + TheClient->iWs.SetAutoFlush(EFalse);
1.80 + }
1.81 +
1.82 +void CTTransparentAnim::ConstructL()
1.83 + {
1.84 + TheClient->iWs.SetAutoFlush(ETrue);
1.85 + }
1.86 +
1.87 +void CTTransparentAnim::RunTestCaseL(TInt)
1.88 + {
1.89 + ((CTTransparentAnimStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0483"));
1.90 + CTTestCase* testCase = CTTransparentAnim::CreateTestCaseL(this, iTest->iState);
1.91 +
1.92 + if (!testCase)
1.93 + {
1.94 + TestComplete();
1.95 + return ;
1.96 + }
1.97 +
1.98 + TInt err = KErrNone;
1.99 +
1.100 + if (!testCase->IsAlreadyRunning())
1.101 + {
1.102 + SetCurrent(testCase);
1.103 + iTest->LogSubTest(testCase->TestCaseName());
1.104 + TRAP(err, testCase->StartL());
1.105 + testCase->SetError(err);
1.106 + }
1.107 +
1.108 + if (testCase->IsComplete() || err != KErrNone)
1.109 + {
1.110 + ((CTTransparentAnimStep*)iStep)->RecordTestResultL();
1.111 + ((CTTransparentAnimStep*)iStep)->CloseTMSGraphicsStep();
1.112 + if (testCase->HasFailed())
1.113 + {
1.114 + INFO_PRINTF3(_L("ErrorStatus - Expected: %d, Actual: %d"), ETrue, EFalse);
1.115 + }
1.116 + ++iTest->iState;
1.117 + SetCurrent(NULL);
1.118 + delete testCase;
1.119 + }
1.120 + else
1.121 + {
1.122 + // Prevent test harness from repeatedly running the test case too quickly.
1.123 + User::After(TTimeIntervalMicroSeconds32(FRAME_DELAY));
1.124 + }
1.125 + }
1.126 +
1.127 +void CTTransparentAnim::SetCurrent(CTTestCase* aTestCase)
1.128 + {
1.129 + iCurrentTestCase = aTestCase;
1.130 + }
1.131 +
1.132 +CTTestCase* CTTransparentAnim::GetCurrent()
1.133 + {
1.134 + return iCurrentTestCase;
1.135 + }
1.136 +
1.137 +//*****************************************************************************
1.138 +CTTAnimation::CTTAnimation(CTWin* aWin, TInt aDrawArg)
1.139 +: iWin(aWin), iFrameCount(0), iCurrentFrameSet(0), iIsComplete(EFalse), iDrawArg(aDrawArg)
1.140 + {
1.141 + iAnimDll = RAnimDll(TheClient->iWs);
1.142 + iAnimDll.Load(KAnimDLLName);
1.143 + iDrawAnim = RTestAnim(iAnimDll);
1.144 + iDrawAnim.Construct(*iWin->BaseWin(), EAnimTypeTrans, TPckgBuf<TRect>(aWin->Size()));
1.145 + }
1.146 +
1.147 +CTTAnimation::~CTTAnimation()
1.148 + {
1.149 + iDrawAnim.Close();
1.150 + iAnimDll.Close();
1.151 + delete iWin;
1.152 + }
1.153 +
1.154 +void CTTAnimation::StartL()
1.155 + {
1.156 + iAnimTimer.ConstructL();
1.157 + iAnimTimer.Start(FRAME_DELAY, TCallBack(CTTAnimation::NextFrame,this));
1.158 + }
1.159 +
1.160 +TBool CTTAnimation::IsComplete()
1.161 + {
1.162 + return iIsComplete;
1.163 + }
1.164 +
1.165 +void CTTAnimation::SetCurrentFrameSet(TInt aFrameSet)
1.166 + {
1.167 + iCurrentFrameSet = aFrameSet;
1.168 + }
1.169 +
1.170 +CTWin* CTTAnimation::GetWindow()
1.171 + {
1.172 + return iWin;
1.173 + }
1.174 +
1.175 +void CTTAnimation::Attach(MAnimationObserver* aObserver)
1.176 + {
1.177 + iObserver = aObserver;
1.178 + }
1.179 +
1.180 +TInt CTTAnimation::NextFrame(TAny* aAnim)
1.181 + {
1.182 + STATIC_CAST(CTTAnimation*,aAnim)->NextFrame();
1.183 +
1.184 + return KErrNone;
1.185 + }
1.186 +
1.187 +void CTTAnimation::NextFrame()
1.188 + {
1.189 + TRgb Color;
1.190 + TPckgBuf<TFrameData> paramsPckg;
1.191 +
1.192 + if (iFrameCount == TestFrameSets[iCurrentFrameSet].iFrameCount)
1.193 + {
1.194 + iIsComplete = ETrue;
1.195 + iObserver->Update(this);
1.196 + return ;
1.197 + }
1.198 +
1.199 + Color = TestFrameSets[iCurrentFrameSet].iFrames[iFrameCount++];
1.200 +
1.201 + paramsPckg().draw = iDrawArg;
1.202 + paramsPckg().color = Color;
1.203 +
1.204 + iDrawAnim.Command(EADllNextFrame, paramsPckg);
1.205 +
1.206 + iAnimTimer.Start(FRAME_DELAY, TCallBack(CTTAnimation::NextFrame,this));
1.207 + }
1.208 +
1.209 +//*****************************************************************************
1.210 +CTransAnimTimer::CTransAnimTimer()
1.211 +: CTimer(EPriorityStandard)
1.212 + {}
1.213 +
1.214 +CTransAnimTimer::~CTransAnimTimer()
1.215 + {}
1.216 +
1.217 +void CTransAnimTimer::ConstructL()
1.218 + {
1.219 + CTimer::ConstructL();
1.220 + CActiveScheduler::Add(this);
1.221 + }
1.222 +
1.223 +void CTransAnimTimer::RunL()
1.224 + {
1.225 + iCallBack.CallBack();
1.226 + }
1.227 +
1.228 +void CTransAnimTimer::Start(TTimeIntervalMicroSeconds32 aInterval,TCallBack aCallBack)
1.229 + {
1.230 + iCallBack = aCallBack;
1.231 + After(aInterval);
1.232 + }
1.233 +
1.234 +//*****************************************************************************
1.235 +CTTestCase::CTTestCase()
1.236 +: iError(KErrNone), iIsComplete(EFalse), iIsRunning(EFalse)
1.237 + {}
1.238 +
1.239 +TBool CTTestCase::IsAlreadyRunning()
1.240 + {
1.241 + return iIsRunning;
1.242 + }
1.243 +
1.244 +void CTTestCase::Update(CTTAnimation* aAnim)
1.245 + {
1.246 + iIsComplete = aAnim->IsComplete();
1.247 + }
1.248 +
1.249 +TBool CTTestCase::IsComplete()
1.250 + {
1.251 + return iIsComplete;
1.252 + }
1.253 +
1.254 +void CTTestCase::StartL()
1.255 + {
1.256 + if (!iIsRunning)
1.257 + {
1.258 + RunTestCaseL();
1.259 + iIsRunning = ETrue;
1.260 + }
1.261 + }
1.262 +
1.263 +TBool CTTestCase::HasFailed()
1.264 + {
1.265 + TBool ret = EFalse;
1.266 + if (iError != KErrNone)
1.267 + {
1.268 + ret = ETrue;
1.269 + }
1.270 + return ret;
1.271 + }
1.272 +
1.273 +void CTTestCase::SetIsCompleted(TBool aIsComplete)
1.274 + {
1.275 + iIsComplete = aIsComplete;
1.276 + }
1.277 +
1.278 +void CTTestCase::SetError(TInt aError)
1.279 + {
1.280 + iError = aError;
1.281 + }
1.282 +
1.283 +//*********************** New Test Case Classes go here************************
1.284 +
1.285 +/**
1.286 + * @SYMTestCaseID GRAPHICS-WSERV-0483
1.287 + *
1.288 + * @SYMTestCaseDesc There are two animations running, one attached to a transparent
1.289 + * window using SetTransparencyAlphaChannel and a second animation with a non-transparent
1.290 + * window. The animations draw a line and then change the color of the line in subsequent
1.291 + * frames. After the last frame the alpha channel for the first animation is set to
1.292 + * opaque and then compared with the second animation to make certain that no artifacts
1.293 + * are present.
1.294 + *
1.295 + * @SYMTestPriority High
1.296 + *
1.297 + * @SYMTestStatus Implemented
1.298 + *
1.299 + * @SYMTestActions An anim is attached with a Transparent window.
1.300 + * The anim draws several frames using WSERV's Anim animation functionality.
1.301 + *
1.302 + * @SYMTestExpectedResults Both animations draw a line and then change it's color, the first
1.303 + * animation doing it in a tranparent window and the second doing it in a non-transparent window.
1.304 + **/
1.305 +CTGraphicsWServ0483* CTGraphicsWServ0483::NewL()
1.306 + {
1.307 + CTGraphicsWServ0483* testCase = new(ELeave) CTGraphicsWServ0483();
1.308 +
1.309 + CleanupStack::PushL(testCase);
1.310 + testCase->ConstructL();
1.311 + CleanupStack::Pop();
1.312 +
1.313 + return testCase;
1.314 + }
1.315 +
1.316 +CTGraphicsWServ0483::~CTGraphicsWServ0483()
1.317 + {
1.318 + delete iAnim;
1.319 + delete iCheckAnim;
1.320 + }
1.321 +
1.322 +void CTGraphicsWServ0483::ConstructL()
1.323 + {
1.324 + iAnim = new(ELeave) CTTAnimation(CTAnimWin<ALPHATRANSPARENCY_ON>::NewL(
1.325 + BaseWin->GetBorderWin()->Position(),
1.326 + BaseWin->GetBorderWin()->Size()), DRAW_LINE_ANIMATION);
1.327 +
1.328 + iCheckAnim = new(ELeave) CTTAnimation(CTAnimWin<>::NewL(
1.329 + TestWin->GetBorderWin()->Position(),
1.330 + TestWin->GetBorderWin()->Size()), DRAW_LINE_ANIMATION);
1.331 + TheClient->WaitForRedrawsToFinish();
1.332 + }
1.333 +
1.334 +void CTGraphicsWServ0483::RunTestCaseL()
1.335 + {
1.336 + iAnim->Attach(this);
1.337 + iCheckAnim->Attach(this);
1.338 +
1.339 + iAnim->SetCurrentFrameSet(ALPHA_FRAMESET);
1.340 + iAnim->StartL();
1.341 +
1.342 + iCheckAnim->SetCurrentFrameSet(ALPHA_FRAMESET);
1.343 + iCheckAnim->StartL();
1.344 + }
1.345 +
1.346 +void CTGraphicsWServ0483::Update(CTTAnimation*)
1.347 + {
1.348 + if (iAnim->IsComplete() && iCheckAnim->IsComplete())
1.349 + {
1.350 + TRgb bgColor(150, 150, 150, 255);
1.351 + iAnim->GetWindow()->Win()->SetBackgroundColor(bgColor);
1.352 + iAnim->GetWindow()->Win()->Invalidate();
1.353 + TheClient->iWs.Finish();
1.354 + TheClient->WaitForRedrawsToFinish();
1.355 + if (!DoCheckRect(iAnim->GetWindow(), iCheckAnim->GetWindow()))
1.356 + {
1.357 + SetError(KErrGeneral);
1.358 + }
1.359 + SetIsCompleted(ETrue);
1.360 + }
1.361 + }
1.362 +
1.363 +TPtrC CTGraphicsWServ0483::TestCaseName()
1.364 + {
1.365 + _LIT(KTransparentAlphaChannelAnimationTest, "Transparent Anim Test");
1.366 +
1.367 + return TPtrC(KTransparentAlphaChannelAnimationTest);
1.368 + }
1.369 +
1.370 +__WS_CONSTRUCT_STEP__(TransparentAnim)