windowing/windowserver/test/tauto/TTransptAnim.cpp
branchRCL_3
changeset 163 bbf46f59e123
equal deleted inserted replaced
150:57c618273d5c 163:bbf46f59e123
       
     1 // Copyright (c) 2003-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 #include "TTransptAnim.h"
       
    22 
       
    23 struct FrameSet
       
    24 	{
       
    25 	TRgb* iFrames;
       
    26 	const TInt iFrameCount;
       
    27 	FrameSet(TRgb* aFrames, const TInt aFrameCount)
       
    28 	: iFrames(aFrames),
       
    29 	iFrameCount(aFrameCount)
       
    30 		{
       
    31 		}
       
    32 	};
       
    33 
       
    34 TRgb FrameSequenceAlpha[]= 
       
    35 { 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) };
       
    36 TRgb FrameSequenceNoAlpha[] =
       
    37 { TRgb(255, 0, 0), TRgb(0, 255, 0), TRgb(0, 0, 255), TRgb(255, 255, 0), TRgb(0, 255, 255) };
       
    38 
       
    39 FrameSet frameSetAlpha(FrameSequenceAlpha, 	sizeof(FrameSequenceAlpha)/sizeof(TRgb));
       
    40 FrameSet frameSetNoAlpha(FrameSequenceNoAlpha, sizeof(FrameSequenceNoAlpha)/sizeof(TRgb));
       
    41 FrameSet TestFrameSets[] =
       
    42 	{
       
    43 	frameSetAlpha, frameSetNoAlpha
       
    44 	};
       
    45 
       
    46 static const TInt 	FRAME_DELAY 			= 2000000;
       
    47 static const TInt 	DRAW_LINE_ANIMATION 	= 36;
       
    48 static const TBool 	ALPHATRANSPARENCY_ON 	= ETrue;
       
    49 static const TInt	ALPHA_FRAMESET 			= 0;
       
    50 
       
    51 //*****************************************************************************
       
    52 CTTestCase* CTTransparentAnim::CreateTestCaseL(CTTransparentAnim* aTransAnim, TInt aTestCaseId)
       
    53 	{
       
    54 	CTTestCase* testCase = aTransAnim->GetCurrent();
       
    55 	
       
    56 	if (!testCase)
       
    57 		{
       
    58 		switch (aTestCaseId)
       
    59 			{
       
    60 		case GraphicsWServ0483 :
       
    61 			testCase =  CTGraphicsWServ0483::NewL();
       
    62 			break;
       
    63 			}
       
    64 		}
       
    65 	
       
    66 	return testCase;
       
    67 	}
       
    68 
       
    69 //*****************************************************************************
       
    70 CTTransparentAnim::CTTransparentAnim(CTestStep* aStep)
       
    71 : CTWsGraphicsBase(aStep), iCurrentTestCase(NULL)
       
    72 	{}
       
    73 
       
    74 CTTransparentAnim::~CTTransparentAnim()
       
    75 	{
       
    76 	TheClient->iWs.SetAutoFlush(EFalse);
       
    77 	}
       
    78 
       
    79 void CTTransparentAnim::ConstructL()
       
    80 	{
       
    81 	TheClient->iWs.SetAutoFlush(ETrue);
       
    82 	}
       
    83 
       
    84 void CTTransparentAnim::RunTestCaseL(TInt)
       
    85 	{
       
    86 	((CTTransparentAnimStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0483"));
       
    87 	CTTestCase* testCase = CTTransparentAnim::CreateTestCaseL(this, iTest->iState);
       
    88 	
       
    89 	if (!testCase)
       
    90 		{
       
    91 		TestComplete();
       
    92 		return ;
       
    93 		}
       
    94 
       
    95 	TInt err = KErrNone;
       
    96 	
       
    97 	if (!testCase->IsAlreadyRunning())
       
    98 		{
       
    99 		SetCurrent(testCase);
       
   100 		iTest->LogSubTest(testCase->TestCaseName());
       
   101 		TRAP(err, testCase->StartL());
       
   102 		testCase->SetError(err);
       
   103 		}
       
   104 	
       
   105 	if (testCase->IsComplete() || err != KErrNone)
       
   106 		{
       
   107 		((CTTransparentAnimStep*)iStep)->RecordTestResultL();
       
   108 		((CTTransparentAnimStep*)iStep)->CloseTMSGraphicsStep();
       
   109 		if (testCase->HasFailed())
       
   110 			{
       
   111 			INFO_PRINTF3(_L("ErrorStatus  - Expected: %d, Actual: %d"), ETrue, EFalse);
       
   112 			}
       
   113 		++iTest->iState;
       
   114 		SetCurrent(NULL);
       
   115 		delete testCase;
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		// Prevent test harness from repeatedly running the test case too quickly.
       
   120 		User::After(TTimeIntervalMicroSeconds32(FRAME_DELAY));
       
   121 		}
       
   122 	}
       
   123 
       
   124 void CTTransparentAnim::SetCurrent(CTTestCase* aTestCase)
       
   125 	{
       
   126 	iCurrentTestCase = aTestCase;
       
   127 	}
       
   128 
       
   129 CTTestCase* CTTransparentAnim::GetCurrent()
       
   130 	{
       
   131 	return iCurrentTestCase;
       
   132 	}
       
   133 
       
   134 //*****************************************************************************
       
   135 CTTAnimation::CTTAnimation(CTWin* aWin, TInt aDrawArg)
       
   136 : iWin(aWin), iFrameCount(0), iCurrentFrameSet(0), iIsComplete(EFalse), iDrawArg(aDrawArg)
       
   137 	{
       
   138 	iAnimDll = RAnimDll(TheClient->iWs);
       
   139 	iAnimDll.Load(KAnimDLLName);
       
   140 	iDrawAnim = RTestAnim(iAnimDll);
       
   141 	iDrawAnim.Construct(*iWin->BaseWin(), EAnimTypeTrans, TPckgBuf<TRect>(aWin->Size()));
       
   142 	}
       
   143 
       
   144 CTTAnimation::~CTTAnimation()
       
   145 	{
       
   146 	iDrawAnim.Close();
       
   147 	iAnimDll.Close();
       
   148 	delete iWin;
       
   149 	}
       
   150 
       
   151 void CTTAnimation::StartL()
       
   152 	{
       
   153 	iAnimTimer.ConstructL();
       
   154 	iAnimTimer.Start(FRAME_DELAY, TCallBack(CTTAnimation::NextFrame,this));
       
   155 	}
       
   156 
       
   157 TBool CTTAnimation::IsComplete()
       
   158 	{
       
   159 	return iIsComplete;
       
   160 	}
       
   161 
       
   162 void CTTAnimation::SetCurrentFrameSet(TInt aFrameSet)
       
   163 	{
       
   164 	iCurrentFrameSet = aFrameSet;
       
   165 	}
       
   166 
       
   167 CTWin* CTTAnimation::GetWindow()
       
   168 	{
       
   169 	return iWin;
       
   170 	}
       
   171 
       
   172 void CTTAnimation::Attach(MAnimationObserver* aObserver)
       
   173 	{
       
   174 	iObserver = aObserver;
       
   175 	}
       
   176 
       
   177 TInt CTTAnimation::NextFrame(TAny* aAnim)
       
   178 	{
       
   179 	STATIC_CAST(CTTAnimation*,aAnim)->NextFrame();
       
   180 
       
   181 	return KErrNone;
       
   182 	}
       
   183 
       
   184 void CTTAnimation::NextFrame()
       
   185 	{
       
   186 	TRgb Color;
       
   187 	TPckgBuf<TFrameData> paramsPckg;
       
   188 
       
   189 	if (iFrameCount == TestFrameSets[iCurrentFrameSet].iFrameCount)
       
   190 		{
       
   191 		iIsComplete = ETrue;
       
   192 		iObserver->Update(this);
       
   193 		return ;
       
   194 		}
       
   195 	
       
   196 	Color = TestFrameSets[iCurrentFrameSet].iFrames[iFrameCount++];
       
   197 	
       
   198 	paramsPckg().draw = iDrawArg;
       
   199 	paramsPckg().color = Color;
       
   200 	
       
   201 	iDrawAnim.Command(EADllNextFrame, paramsPckg);
       
   202 
       
   203 	iAnimTimer.Start(FRAME_DELAY, TCallBack(CTTAnimation::NextFrame,this));
       
   204 	}
       
   205 
       
   206 //*****************************************************************************
       
   207 CTransAnimTimer::CTransAnimTimer() 
       
   208 : CTimer(EPriorityStandard)
       
   209 	{}
       
   210 
       
   211 CTransAnimTimer::~CTransAnimTimer()
       
   212 	{}
       
   213 
       
   214 void CTransAnimTimer::ConstructL()
       
   215 	{
       
   216 	CTimer::ConstructL();
       
   217 	CActiveScheduler::Add(this);
       
   218 	}
       
   219 
       
   220 void CTransAnimTimer::RunL()
       
   221 	{
       
   222 	iCallBack.CallBack();
       
   223 	}
       
   224 
       
   225 void CTransAnimTimer::Start(TTimeIntervalMicroSeconds32 aInterval,TCallBack aCallBack)
       
   226 	{
       
   227 	iCallBack = aCallBack;
       
   228 	After(aInterval);
       
   229 	}
       
   230 
       
   231 //*****************************************************************************
       
   232 CTTestCase::CTTestCase()
       
   233 : iError(KErrNone), iIsComplete(EFalse), iIsRunning(EFalse)
       
   234 	{}
       
   235 
       
   236 TBool CTTestCase::IsAlreadyRunning()
       
   237 	{
       
   238 	return iIsRunning;
       
   239 	}
       
   240 
       
   241 void CTTestCase::Update(CTTAnimation* aAnim)
       
   242 	{
       
   243 	iIsComplete = aAnim->IsComplete();
       
   244 	}
       
   245 
       
   246 TBool CTTestCase::IsComplete()
       
   247 	{
       
   248 	return iIsComplete;
       
   249 	}
       
   250 
       
   251 void CTTestCase::StartL()
       
   252 	{
       
   253 	if (!iIsRunning)
       
   254 		{
       
   255 		RunTestCaseL();
       
   256 		iIsRunning = ETrue;
       
   257 		}
       
   258 	}
       
   259 
       
   260 TBool CTTestCase::HasFailed()
       
   261 	{
       
   262 	TBool ret = EFalse;
       
   263 	if (iError != KErrNone)
       
   264 		{
       
   265 		ret = ETrue;
       
   266 		}
       
   267 	return ret;
       
   268 	}
       
   269 
       
   270 void CTTestCase::SetIsCompleted(TBool aIsComplete)
       
   271 	{
       
   272 	iIsComplete = aIsComplete;
       
   273 	}
       
   274 
       
   275 void CTTestCase::SetError(TInt aError)
       
   276 	{
       
   277 	iError = aError;
       
   278 	}
       
   279 
       
   280 //*********************** New Test Case Classes go here************************
       
   281 
       
   282 /**
       
   283  * @SYMTestCaseID GRAPHICS-WSERV-0483
       
   284  *
       
   285  * @SYMTestCaseDesc There are two animations running, one attached to a transparent
       
   286  * window using SetTransparencyAlphaChannel and a second animation with a non-transparent
       
   287  * window. The animations draw a line and then change the color of the line in subsequent
       
   288  * frames. After the last frame the alpha channel for the first animation is set to
       
   289  * opaque and then compared with the second animation to make certain that no artifacts
       
   290  * are present.
       
   291  *
       
   292  * @SYMTestPriority High
       
   293  *
       
   294  * @SYMTestStatus Implemented
       
   295  *
       
   296  * @SYMTestActions An anim is attached with a Transparent window.
       
   297  * 	The anim draws several frames using WSERV's Anim animation functionality.
       
   298  *
       
   299  * @SYMTestExpectedResults Both animations draw a line and then change it's color, the first
       
   300  * animation doing it in a tranparent window and the second doing it in a non-transparent window.
       
   301  **/
       
   302 CTGraphicsWServ0483* CTGraphicsWServ0483::NewL()
       
   303 	{
       
   304 	CTGraphicsWServ0483* testCase = new(ELeave) CTGraphicsWServ0483();
       
   305 	
       
   306 	CleanupStack::PushL(testCase);
       
   307 	testCase->ConstructL();
       
   308 	CleanupStack::Pop();
       
   309 	
       
   310 	return testCase;
       
   311 	}
       
   312 
       
   313 CTGraphicsWServ0483::~CTGraphicsWServ0483()
       
   314 	{
       
   315 	delete iAnim;
       
   316 	delete iCheckAnim;
       
   317 	}
       
   318 
       
   319 void CTGraphicsWServ0483::ConstructL()
       
   320 	{
       
   321 	iAnim = new(ELeave) CTTAnimation(CTAnimWin<ALPHATRANSPARENCY_ON>::NewL(
       
   322 										BaseWin->GetBorderWin()->Position(),
       
   323 										BaseWin->GetBorderWin()->Size()), DRAW_LINE_ANIMATION);
       
   324 	
       
   325 	iCheckAnim = new(ELeave) CTTAnimation(CTAnimWin<>::NewL(
       
   326 										TestWin->GetBorderWin()->Position(),
       
   327 										TestWin->GetBorderWin()->Size()), DRAW_LINE_ANIMATION);
       
   328 	TheClient->WaitForRedrawsToFinish();
       
   329 	}
       
   330 
       
   331 void CTGraphicsWServ0483::RunTestCaseL()
       
   332 	{
       
   333 	iAnim->Attach(this);
       
   334 	iCheckAnim->Attach(this);
       
   335 	
       
   336 	iAnim->SetCurrentFrameSet(ALPHA_FRAMESET);
       
   337 	iAnim->StartL();
       
   338 	
       
   339 	iCheckAnim->SetCurrentFrameSet(ALPHA_FRAMESET);
       
   340 	iCheckAnim->StartL();	
       
   341 	}
       
   342 
       
   343 void CTGraphicsWServ0483::Update(CTTAnimation*)
       
   344 	{
       
   345 	if (iAnim->IsComplete() && iCheckAnim->IsComplete())
       
   346 		{
       
   347 		TRgb bgColor(150, 150, 150, 255); 
       
   348 		iAnim->GetWindow()->Win()->SetBackgroundColor(bgColor);
       
   349 		iAnim->GetWindow()->Win()->Invalidate();
       
   350 		TheClient->iWs.Finish();
       
   351 		TheClient->WaitForRedrawsToFinish();
       
   352 		if (!DoCheckRect(iAnim->GetWindow(), iCheckAnim->GetWindow()))
       
   353 			{
       
   354 			SetError(KErrGeneral);
       
   355 			}
       
   356 		SetIsCompleted(ETrue);
       
   357 		}
       
   358 	}
       
   359 
       
   360 TPtrC CTGraphicsWServ0483::TestCaseName()
       
   361 	{
       
   362 	_LIT(KTransparentAlphaChannelAnimationTest, "Transparent Anim Test");
       
   363 	
       
   364 	return TPtrC(KTransparentAlphaChannelAnimationTest);
       
   365 	}
       
   366 
       
   367 __WS_CONSTRUCT_STEP__(TransparentAnim)