lafagnosticuifoundation/animation/tef/TSynch.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2008-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 // NOTE: This test is screen sensitive, so anything appearing on the techview screen while running will cause the image
       
    15 // comparison algorithm to fail.
       
    16 // Ones of the culprits can be the techview Heartbeat inactivity timer (see DEF116740), hence, a way to avoid being
       
    17 // hit by this problem is to keep the test duration shorter than the inactivity timeout (currently set at 60s)
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file
       
    23  @test
       
    24  @internalComponent - Internal Symbian test code 
       
    25 */
       
    26 
       
    27 
       
    28 #include "TSynch.h"
       
    29 #include "AnimationConfig.h"
       
    30 #include "AnimationTestServer.h"
       
    31 
       
    32 _LIT(KEightStep, "Z:\\private\\10204F5B\\rgb1.gif");
       
    33 _LIT(KThreeStep, "Z:\\private\\10204F5B\\rgb2.gif");
       
    34 
       
    35 const TInt KSynchNumAnimations = 10;
       
    36 const TInt KSynchTestPeriod = 200000;
       
    37 
       
    38 //
       
    39 // Windows:
       
    40 //
       
    41 CSynchAnimationWindow::CSynchAnimationWindow(RWsSession& aWsSession, CTestWindowGroup& aGroup, CWindowGc& aGc) : CTestWindow(aWsSession, aGroup, aGc)
       
    42 	{
       
    43 	}
       
    44 
       
    45 void CSynchAnimationWindow::SetAnimations(RPointerArray<CAnimation>* aAnimations)
       
    46 	{
       
    47 	iAnimations = aAnimations;
       
    48 	}
       
    49 	
       
    50 void CSynchAnimationWindow::DrawL()
       
    51 	{
       
    52 	if (iAnimations)
       
    53 		{
       
    54 		for(TInt anim = 0; anim < iAnimations->Count(); ++anim)
       
    55 			{
       
    56 			static_cast<CBasicAnimation*>((*iAnimations)[anim])->Draw(iGc);
       
    57 			}
       
    58 		}
       
    59 	}
       
    60 	
       
    61 //
       
    62 // The test:
       
    63 //
       
    64 CSynch::CSynch()
       
    65 	{
       
    66 	SetTestStepName(KSynchStep);
       
    67 	}
       
    68 	
       
    69 CSynch::~CSynch()
       
    70 	{
       
    71 	UnloadAnimations();
       
    72 	delete iAnimationGroup;
       
    73 	delete iWin;
       
    74 	}
       
    75 
       
    76 void CSynch::InitialiseL()
       
    77 	{
       
    78 	CAnimationTestStep::InitialiseL();
       
    79 
       
    80 	ANIM_INFO1(_L("Begin test SYNCH"));
       
    81 
       
    82 	TInt winborder = 2;
       
    83 	iWinSize = Screen()->SizeInPixels();
       
    84 	iWinSize.iWidth /= 2;
       
    85 	iWinPosition = TPoint(iWinSize.iWidth + winborder, winborder);
       
    86 	iWinSize.iWidth -= winborder * 2;
       
    87 	iWinSize.iHeight -= winborder * 2;
       
    88 	iWinRect = TRect(iWinPosition, iWinSize);
       
    89 
       
    90 	iWin = new (ELeave) CSynchAnimationWindow(Ws(), *GroupWin(), *Gc());
       
    91 	iWin->Window()->SetRequiredDisplayMode(iDisplayMode);
       
    92 	iWin->Window()->SetExtent(iWinPosition, iWinSize);
       
    93 	iWin->Window()->SetBackgroundColor(iBackgroundColor1);
       
    94 	iWin->Window()->SetVisible(ETrue);
       
    95 	iWin->Window()->Activate();
       
    96 
       
    97 	iAnimationGroup = CAnimationGroup::NewL();
       
    98 	}
       
    99 
       
   100 void CSynch::StartStopL(const TAnimationConfig& aConfig, TInt aPeriod)
       
   101 	{
       
   102 	iAnimationGroup->Start(aConfig);
       
   103 	for(TInt ii = 0; ii < aPeriod; ii += KSynchTestPeriod)
       
   104 		{
       
   105 		Wait(KSynchTestPeriod);
       
   106 		WaitForRedrawsToFinish();
       
   107 		ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   108 		}
       
   109 	iAnimationGroup->Stop();
       
   110 	WaitForRedrawsToFinish();
       
   111 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   112 	}
       
   113 
       
   114 /**
       
   115 	@SYMTestCaseID UIF-animation-TSynch-TestLoopsForeverL
       
   116 
       
   117 	@SYMTestCaseDesc 
       
   118 	This runs an animation loop forever, testing synchronization.
       
   119 
       
   120 	@SYMPREQ 269
       
   121 
       
   122 	@SYMTestStatus Implemented
       
   123 
       
   124 	@SYMTestPriority High
       
   125 
       
   126 	@SYMTestActions 
       
   127 	The animation must be initialised, and this test is called twice, first with
       
   128 	a set of synchronized basic animations, and second with an set of synchronized 
       
   129 	sprite animations.
       
   130 
       
   131 	@SYMTestExpectedResults Animation displayed in rows
       
   132 
       
   133 */
       
   134 void CSynch::TestLoopsForeverL()
       
   135 	{
       
   136 	TAnimationConfig config;
       
   137 	config.iFlags = TAnimationConfig::ELoop;
       
   138 	config.iData = -1;
       
   139 
       
   140 	StartStopL(config, 3000000);
       
   141 	}
       
   142 
       
   143 /**
       
   144 	@SYMTestCaseID UIF-animation-TSynch-TestLoopsNumberedL
       
   145 
       
   146 	@SYMTestCaseDesc 
       
   147 	This runs an animation loops twice, testing synchronization.
       
   148 
       
   149 	@SYMPREQ 269
       
   150 
       
   151 	@SYMTestStatus Implemented
       
   152 
       
   153 	@SYMTestPriority High
       
   154 
       
   155 	@SYMTestActions 
       
   156 	The animation must be initialised, and this test is called twice, first with
       
   157 	a set of synchronized basic animations, and second with an set of synchronized 
       
   158 	sprite animations.
       
   159 
       
   160 	@SYMTestExpectedResults Animation displayed in rows
       
   161 
       
   162 */	
       
   163 void CSynch::TestLoopsNumberedL()
       
   164 	{
       
   165 	TAnimationConfig config;
       
   166 	config.iFlags = TAnimationConfig::ELoop;
       
   167 	config.iData = 2;
       
   168 
       
   169 	StartStopL(config);
       
   170 	}
       
   171 	
       
   172 /**
       
   173 	@SYMTestCaseID UIF-animation-TSynch-TestNotLoopedL
       
   174 
       
   175 	@SYMTestCaseDesc 
       
   176 	This runs an animation is displayed without looping.
       
   177 
       
   178 	@SYMPREQ 269
       
   179 
       
   180 	@SYMTestStatus Implemented
       
   181 
       
   182 	@SYMTestPriority High
       
   183 
       
   184 	@SYMTestActions 
       
   185 	The animation must be initialised, and this test is called twice, first with
       
   186 	a set of synchronized basic animations, and second with an set of synchronized 
       
   187 	sprite animations.
       
   188 
       
   189 	@SYMTestExpectedResults Animation displayed in rows
       
   190 */	
       
   191 void CSynch::TestNotLoopedL()
       
   192 	{
       
   193 	TAnimationConfig config;
       
   194 	config.iFlags = 0;
       
   195 
       
   196 	StartStopL(config);
       
   197 	}
       
   198 
       
   199 /**
       
   200 	@SYMTestCaseID UIF-animation-TSynch-TestControlL
       
   201 
       
   202 	@SYMTestCaseDesc 
       
   203 	This tests animation operations such as start, pause, resume and stop.  Tests
       
   204 	performed on a set of synchronized animations.  
       
   205 
       
   206 	@SYMPREQ 269
       
   207 
       
   208 	@SYMTestStatus Implemented
       
   209 
       
   210 	@SYMTestPriority High
       
   211 
       
   212 	@SYMTestActions 
       
   213 	The animation must be initialised, and this test is called twice, first with
       
   214 	a set of synchronized basic animation, and second with an set of synchronized 
       
   215 	sprite animations. After a straightforward sequence of operations: start, pause, 
       
   216 	resume and stop, invalid operations for the current state are tested, such as 
       
   217 	stop when already stopped, and resume when stopped.
       
   218 
       
   219 	@SYMTestExpectedResults Animation displayed in rows.
       
   220 */	
       
   221 void CSynch::TestControlL()
       
   222 	{
       
   223 	TAnimationConfig config;
       
   224 	config.iFlags = TAnimationConfig::ELoop;
       
   225 	config.iData = -1;
       
   226 	
       
   227 	// Start, Pause, Resume, Stop:
       
   228 	iAnimationGroup->Start(config);
       
   229 	Wait(500000);
       
   230 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   231 	iAnimationGroup->Pause();
       
   232 	Wait(1000000);
       
   233 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   234 	iAnimationGroup->Resume();
       
   235 	Wait(700000);
       
   236 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   237 	iAnimationGroup->Stop();
       
   238 	Wait(500000);
       
   239 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   240 	
       
   241 	// Start again:
       
   242 	iAnimationGroup->Start(config);
       
   243 	Wait(500000);
       
   244 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   245 	iAnimationGroup->Stop();
       
   246 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   247 	
       
   248 	// Put some of them on hold and make sure they recover:
       
   249 	iAnimationGroup->Start(config);
       
   250 	Wait(500000);
       
   251 	for(TInt i = 0; i < iAnimations.Count(); ++i)
       
   252 		{
       
   253 		if(i % 3)
       
   254 			iAnimations[i]->Hold();
       
   255 		}
       
   256 	Wait(2500000);
       
   257 	iAnimationGroup->Unhold();
       
   258 	Wait(500000);
       
   259 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   260 	iAnimationGroup->Stop();
       
   261 	
       
   262 	// Commands for wrong state (stop when already stopped etc):
       
   263 	iAnimationGroup->Start(config);
       
   264 	Wait(500000);
       
   265 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   266 	iAnimationGroup->Start(config);
       
   267 	Wait(500000);
       
   268 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   269 	iAnimationGroup->Resume();
       
   270 	Wait(500000);
       
   271 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   272 	iAnimationGroup->Stop();
       
   273 	iAnimationGroup->Stop();
       
   274 	Wait(500000);	
       
   275 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   276 	iAnimationGroup->Resume();
       
   277 	Wait(500000);
       
   278 	ANIMTESTCOLORSL(iWinRect, 2, 2 + iExtraColors);
       
   279 	}
       
   280 	
       
   281 void CSynch::LoadBasicAnimationsL()
       
   282 	{
       
   283 	UnloadAnimations();
       
   284 	
       
   285 	CICLAnimationDataProvider* dataProvider;
       
   286 	
       
   287 	for (TInt anim = 0; anim < KSynchNumAnimations; ++anim)
       
   288 		{
       
   289 		dataProvider = new (ELeave) CICLAnimationDataProvider;
       
   290 		CleanupStack::PushL(dataProvider);
       
   291 		dataProvider->SetFileL(iFs, KEightStep());
       
   292 		CleanupStack::Pop(dataProvider);
       
   293 		CBasicAnimation* animation = CBasicAnimation::NewL(dataProvider, TPoint(anim * 4,anim * 18), Ws(), *iWin->Window());
       
   294 		iAnimations.Append(animation);
       
   295 		iAnimationGroup->Animations().Append(animation);
       
   296 
       
   297 		dataProvider = new (ELeave) CICLAnimationDataProvider;
       
   298 		CleanupStack::PushL(dataProvider);
       
   299 		dataProvider->SetFileL(iFs, KThreeStep());
       
   300 		CleanupStack::Pop(dataProvider);
       
   301 		animation = CBasicAnimation::NewL(dataProvider, TPoint(anim * 4 + 2,anim * 18 + 9), Ws(), *iWin->Window());
       
   302 		iAnimations.Append(animation);
       
   303 		iAnimationGroup->Animations().Append(animation);		
       
   304 		}
       
   305 	iWin->SetAnimations(&iAnimations);
       
   306 	Wait(3000000);
       
   307 	}
       
   308 	
       
   309 void CSynch::LoadSpriteAnimationsL()
       
   310 	{
       
   311 	UnloadAnimations();
       
   312 	
       
   313 	CICLAnimationDataProvider* dataProvider;
       
   314 	
       
   315 	for (TInt anim = 0; anim < KSynchNumAnimations; ++anim)
       
   316 		{
       
   317 		dataProvider = new (ELeave) CICLAnimationDataProvider;
       
   318 		CleanupStack::PushL(dataProvider);
       
   319 		dataProvider->SetFileL(iFs, KEightStep());
       
   320 		CleanupStack::Pop(dataProvider);
       
   321 		CSpriteAnimation* animation = CSpriteAnimation::NewL(dataProvider, TPoint(anim * 4,anim * 18), Ws(), *iWin->Window());
       
   322 		iAnimations.Append(animation);
       
   323 		iAnimationGroup->Animations().Append(animation);
       
   324 
       
   325 		dataProvider = new (ELeave) CICLAnimationDataProvider;
       
   326 		CleanupStack::PushL(dataProvider);
       
   327 		dataProvider->SetFileL(iFs, KThreeStep());
       
   328 		CleanupStack::Pop(dataProvider);
       
   329 		animation = CSpriteAnimation::NewL(dataProvider, TPoint(anim * 4 + 2,anim * 18 + 9), Ws(), *iWin->Window());
       
   330 		iAnimations.Append(animation);
       
   331 		iAnimationGroup->Animations().Append(animation);		
       
   332 		}
       
   333 	Wait(3000000);
       
   334 	}
       
   335 	
       
   336 void CSynch::UnloadAnimations()
       
   337 	{
       
   338 	if (iWin)
       
   339 		{
       
   340 		iWin->SetAnimations(0);
       
   341 		iWin->Window()->Invalidate();
       
   342 		}
       
   343 	if (iAnimationGroup)
       
   344 		iAnimationGroup->Animations().Reset();
       
   345 	iAnimations.ResetAndDestroy();
       
   346 	}
       
   347 
       
   348 TVerdict CSynch::doActiveTestStepL()
       
   349 	{
       
   350 	_LIT(KBasic, "Load basic animations");
       
   351 	_LIT(KSprite, "Load sprite animations");
       
   352 	_LIT(KLoopsForever, "Loops forever");
       
   353 	_LIT(KLoopsNumbered, "Loops numbered");
       
   354 	_LIT(KNotLooped, "Not looped");
       
   355 	_LIT(KControl, "Control");
       
   356 	
       
   357 	InitialiseL();
       
   358 	
       
   359 	TInt stage = 0;
       
   360 	TInt animType = 0;
       
   361 	TBool finished = EFalse;
       
   362 	while(TestStepResult() == EPass && !finished)
       
   363 		{
       
   364 		switch(stage)
       
   365 			{
       
   366 			case 0:
       
   367 				switch(animType)
       
   368 					{
       
   369 					case 0:
       
   370 						ANIM_INFO1(KBasic);
       
   371 						iExtraColors = 0;
       
   372 						LoadBasicAnimationsL();
       
   373 						break;
       
   374 					case 1:
       
   375 						ANIM_INFO1(KSprite);
       
   376 						// 1 extra colour is unfortunate, but unavoidable
       
   377 						// due to multiple processes/threads being involved.
       
   378 						iExtraColors = 1; 
       
   379 						LoadSpriteAnimationsL();
       
   380 						break;
       
   381 					default:
       
   382 						finished = ETrue;
       
   383 					}
       
   384 				break;
       
   385 			case 1:
       
   386 				SetTestStepID(_L("UIF-animation-TSynch-TestLoopsForeverL"));
       
   387 				ANIM_INFO1(KLoopsForever);
       
   388 				TestLoopsForeverL();
       
   389 				RecordTestResultL();
       
   390 				break;
       
   391 			case 2:
       
   392 				SetTestStepID(_L("UIF-animation-TSynch-TestLoopsNumberedL"));
       
   393 				ANIM_INFO1(KLoopsNumbered);
       
   394 				TestLoopsNumberedL();
       
   395 				RecordTestResultL();
       
   396 				break;
       
   397 			case 3:
       
   398 				SetTestStepID(_L("UIF-animation-TSynch-TestNotLoopedL"));
       
   399 				ANIM_INFO1(KNotLooped);
       
   400 				TestNotLoopedL();
       
   401 				RecordTestResultL();
       
   402 				break;
       
   403 			case 4:
       
   404 				SetTestStepID(_L("UIF-animation-TSynch-TestControlL"));
       
   405 				ANIM_INFO1(KControl);
       
   406 				TestControlL();
       
   407 				RecordTestResultL();
       
   408 				CloseTMSGraphicsStep();
       
   409 				break;
       
   410 			default:
       
   411 				stage = -1; // ++ later
       
   412 				++animType;
       
   413 				break;
       
   414 			}
       
   415 		++stage;
       
   416 		}
       
   417 	return TestStepResult();
       
   418 	}