lafagnosticuifoundation/animation/tef/TBasic.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-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  @internalComponent - Internal Symbian test code  
       
    19 */
       
    20 
       
    21 #include "TBasic.h"
       
    22 #include "AnimationConfig.h"
       
    23 #include "AnimationTestServer.h"
       
    24 
       
    25 _LIT(KSymBallFile, "Z:\\Private\\10204F5B\\symball.gif");
       
    26 _LIT(KSymWaveFile, "Z:\\Private\\10204F5B\\symwave.gif");
       
    27 
       
    28 //
       
    29 // Windows:
       
    30 //
       
    31 CBasicAnimationWindow::CBasicAnimationWindow(RWsSession& aWsSession, CTestWindowGroup& aGroup, CWindowGc& aGc) : CTestWindow(aWsSession, aGroup, aGc)
       
    32 	{
       
    33 	}
       
    34 
       
    35 void CBasicAnimationWindow::SetAnimation(CBasicAnimation* aAnimation)
       
    36 	{
       
    37 	iAnimation = aAnimation;
       
    38 	}
       
    39 	
       
    40 void CBasicAnimationWindow::DrawL()
       
    41 	{
       
    42 	if(iAnimation)
       
    43 		iAnimation->Draw(iGc);
       
    44 	}
       
    45 	
       
    46 CSpriteAnimationWindow::CSpriteAnimationWindow(RWsSession& aWsSession, CTestWindowGroup& aGroup, CWindowGc& aGc) : CTestWindow(aWsSession, aGroup, aGc)
       
    47 	{
       
    48 	}
       
    49 
       
    50 //
       
    51 // The test:
       
    52 //
       
    53 CBasic::CBasic()
       
    54 	{
       
    55 	SetTestStepName(KBasicStep);
       
    56 	}
       
    57 	
       
    58 CBasic::~CBasic()
       
    59 	{
       
    60 	delete iAnimationGroup;
       
    61 	delete iBasicAnimation;
       
    62 	delete iSpriteAnimation;
       
    63 	delete iBasicWin;
       
    64 	delete iSpriteWin;
       
    65 	}
       
    66 
       
    67 void CBasic::InitialiseL()
       
    68 	{
       
    69 	CAnimationTestStep::InitialiseL();
       
    70 	
       
    71 	ANIM_INFO1(_L("Begin test BASIC"));
       
    72 
       
    73 	TInt winborder = 2;
       
    74 	iWinSize = Screen()->SizeInPixels();
       
    75 	iWinSize.iWidth /= 2;
       
    76 	iWinSize.iHeight /= 2;
       
    77 	iBasicWinPosition = TPoint(iWinSize.iWidth + winborder, winborder);
       
    78 	iSpriteWinPosition = TPoint(iWinSize.iWidth + winborder, iWinSize.iHeight + winborder);
       
    79 	iWinSize.iWidth -= winborder * 2;
       
    80 	iWinSize.iHeight -= winborder * 2;
       
    81 
       
    82 	iBasicWin = new (ELeave) CBasicAnimationWindow(Ws(), *GroupWin(), *Gc());
       
    83 	iBasicWin->Window()->SetRequiredDisplayMode(EColor256);
       
    84 	iBasicWin->Window()->SetExtent(iBasicWinPosition, iWinSize);
       
    85 	iBasicWin->Window()->SetBackgroundColor(iBackgroundColor1);
       
    86 	iBasicWin->Window()->SetVisible(ETrue);
       
    87 	iBasicWin->Window()->Activate();
       
    88 
       
    89 	iSpriteWin = new (ELeave) CSpriteAnimationWindow(Ws(), *GroupWin(), *Gc());
       
    90 	iSpriteWin->Window()->SetRequiredDisplayMode(EColor256);
       
    91 	iSpriteWin->Window()->SetExtent(iSpriteWinPosition, iWinSize);
       
    92 	iSpriteWin->Window()->SetBackgroundColor(iBackgroundColor1);
       
    93 	iSpriteWin->Window()->SetVisible(ETrue);
       
    94 	iSpriteWin->Window()->Activate();
       
    95 
       
    96 	CICLAnimationDataProvider* dataProvider;
       
    97 	dataProvider=new(ELeave)CICLAnimationDataProvider;
       
    98 	CleanupStack::PushL(dataProvider);
       
    99 	dataProvider->SetFileL(iFs, KSymBallFile());
       
   100 	CleanupStack::Pop(dataProvider);
       
   101 	iBasicAnimation = CBasicAnimation::NewL(dataProvider, TPoint(0,0), Ws(), *iBasicWin->Window(), this);
       
   102 	iBasicWin->SetAnimation(iBasicAnimation);
       
   103 
       
   104 	dataProvider=new(ELeave)CICLAnimationDataProvider;
       
   105 	CleanupStack::PushL(dataProvider);
       
   106 	dataProvider->SetFileL(iFs, KSymBallFile());
       
   107 	CleanupStack::Pop(dataProvider);
       
   108 	iSpriteAnimation = CSpriteAnimation::NewL(dataProvider, TPoint(0,0), Ws(), *iSpriteWin->Window(), this);
       
   109 
       
   110 	iAnimationGroup = CAnimationGroup::NewL();
       
   111 	iAnimationGroup->Animations().Append(iBasicAnimation);
       
   112 	iAnimationGroup->Animations().Append(iSpriteAnimation);
       
   113 	}
       
   114 
       
   115 // Although this function doesn't leave, it is the intention that it will do
       
   116 // in future, since it is supposed to be verifying the output:
       
   117 void CBasic::StartStopL(const TAnimationConfig& aConfig)
       
   118 	{
       
   119 	iAnimationGroup->Start(aConfig);
       
   120 	Wait(5000000);
       
   121 	iAnimationGroup->Stop();
       
   122 	Wait(500000);
       
   123 	}
       
   124 /**
       
   125 	@SYMTestCaseID UIF-animation-TBasic-TestLoopsForeverL-0001
       
   126 */
       
   127 /**
       
   128 	@SYMTestCaseID UIF-animation-TBasic-TestLoopsForeverL-0002
       
   129 
       
   130 	@SYMPREQ 269
       
   131 	
       
   132 	@SYMTestCaseDesc 
       
   133 	This runs an animation loop forever (actual run time 5 seconds).
       
   134 
       
   135 	@SYMTestStatus Implemented
       
   136 
       
   137 	@SYMTestPriority High
       
   138 
       
   139 	@SYMTestActions 
       
   140 	The animation must be initialised, and this test is called with an animation
       
   141 	group with basic and sprite animations.
       
   142 
       
   143 	@SYMTestExpectedResults Animation displayed.
       
   144 
       
   145 */
       
   146 void CBasic::TestLoopsForeverL()
       
   147 	{
       
   148 	TAnimationConfig config;
       
   149 	config.iFlags = TAnimationConfig::ELoop;
       
   150 	config.iData = -1;
       
   151 
       
   152 	StartStopL(config);
       
   153 	}
       
   154 	
       
   155 /**
       
   156 	@SYMTestCaseID UIF-animation-TBasic-TestLoopsNumberedL
       
   157 
       
   158 	@SYMTestCaseDesc 
       
   159 	This runs an animation loop twice.
       
   160 
       
   161 	@SYMPREQ 269
       
   162 
       
   163 	@SYMTestStatus Implemented
       
   164 
       
   165 	@SYMTestPriority High
       
   166 
       
   167 	@SYMTestActions 
       
   168 	The animation must be initialised, and this test is called with an animation
       
   169 	group with basic and sprite animations.
       
   170 
       
   171 	@SYMTestExpectedResults Animation displayed.
       
   172 
       
   173 */
       
   174 void CBasic::TestLoopsNumberedL()
       
   175 	{
       
   176 	TAnimationConfig config;
       
   177 	config.iFlags = TAnimationConfig::ELoop;
       
   178 	config.iData = 2;
       
   179 
       
   180 	StartStopL(config);
       
   181 	}
       
   182 	
       
   183 /**
       
   184 	@SYMTestCaseID UIF-animation-TBasic-TestNotLoopedL
       
   185 
       
   186 	@SYMTestCaseDesc 
       
   187 	This runs an animation displayed without looping.
       
   188 
       
   189 	@SYMPREQ 269
       
   190 
       
   191 	@SYMTestStatus Implemented
       
   192 
       
   193 	@SYMTestPriority High
       
   194 
       
   195 	@SYMTestActions 
       
   196 	The animation must be initialised, and this test is called with an animation
       
   197 	group with basic and sprite animations.
       
   198 
       
   199 	@SYMTestExpectedResults Animation displayed.
       
   200 */
       
   201 void CBasic::TestNotLoopedL()
       
   202 	{
       
   203 	TAnimationConfig config;
       
   204 
       
   205 	StartStopL(config);
       
   206 	}
       
   207 	
       
   208 /**
       
   209 	@SYMTestCaseID UIF-animation-TBasic-TestControlL
       
   210 
       
   211 	@SYMTestCaseDesc 
       
   212 	This tests animation operations such as start, pause, resume and stop.  
       
   213 
       
   214 	@SYMPREQ 269
       
   215 
       
   216 	@SYMTestStatus Implemented
       
   217 
       
   218 	@SYMTestPriority High
       
   219 
       
   220 	@SYMTestActions 
       
   221 	The animation must be initialised, and this test is called with an animation
       
   222 	group with basic and sprite animations.  After a straightforward sequence of 
       
   223 	operations: start, pause, resume and stop, invalid operations for the current 
       
   224 	state are tested, such as stop when already stopped, and resume when stopped.
       
   225 
       
   226 	@SYMTestExpectedResults Animation displayed.
       
   227 */
       
   228 void CBasic::TestControlL()
       
   229 	{
       
   230 	TAnimationConfig config;
       
   231 	config.iFlags = TAnimationConfig::ELoop;
       
   232 	config.iData = -1;
       
   233 	
       
   234 	// Start, Pause, Resume, Stop:
       
   235 	iAnimationGroup->Start(config);
       
   236 	Wait(500000);
       
   237 	iAnimationGroup->Pause();
       
   238 	Wait(1000000);
       
   239 	iAnimationGroup->Resume();
       
   240 	Wait(700000);
       
   241 	iAnimationGroup->Stop();
       
   242 	Wait(500000);
       
   243 	
       
   244 	// Start again:
       
   245 	iAnimationGroup->Start(config);
       
   246 	Wait(500000);
       
   247 	iAnimationGroup->Stop();
       
   248 	
       
   249 	// Commands for wrong state (stop when already stopped etc):
       
   250 	iAnimationGroup->Start(config);
       
   251 	Wait(500000);
       
   252 	iAnimationGroup->Start(config);
       
   253 	Wait(500000);
       
   254 	iAnimationGroup->Resume();
       
   255 	Wait(500000);
       
   256 	iAnimationGroup->Stop();
       
   257 	iAnimationGroup->Stop();
       
   258 	Wait(500000);	
       
   259 	iAnimationGroup->Resume();
       
   260 	Wait(500000);	
       
   261 	}
       
   262 	
       
   263 /**
       
   264 	@SYMTestCaseID UIF-animation-TBasic-TestMovingL
       
   265 
       
   266 	@SYMTestCaseDesc 
       
   267 	This test starts an animation and then moves its position multiple times.  
       
   268 	The animation is then stopped.
       
   269 
       
   270 	@SYMPREQ 269
       
   271 
       
   272 	@SYMTestStatus Implemented
       
   273 
       
   274 	@SYMTestPriority High
       
   275 
       
   276 	@SYMTestActions 
       
   277 	The animation must be initialised, and this test is called with an animation
       
   278 	group with basic and sprite animations.  After the animation is started it is 
       
   279 	moved horizontally five pixels to the right for a length of 200 pixels, 
       
   280 	with a 50ms pause between each step.
       
   281 
       
   282 	@SYMTestExpectedResults Animation displayed moving to the right.
       
   283 */
       
   284 void CBasic::TestMovingL()
       
   285 	{
       
   286 	TAnimationConfig config;
       
   287 	config.iFlags = TAnimationConfig::ELoop;
       
   288 	config.iData = -1;
       
   289 	
       
   290 	iAnimationGroup->Start(config);
       
   291 
       
   292 	TInt y = 0;	
       
   293 	for (TInt x = 0; x < 200; x += 5)
       
   294 		{
       
   295 		iAnimationGroup->SetPosition(TPoint(x, y));
       
   296 		Ws().Flush();
       
   297 		Wait(50000);
       
   298 		y += 1;
       
   299 		}
       
   300 	iAnimationGroup->Stop();
       
   301 	}
       
   302 
       
   303 /**
       
   304 	@SYMTestCaseID UIF-animation-TBasic-TestDataChangeL
       
   305 
       
   306 	@SYMTestCaseDesc 
       
   307 	This test changes the data provider file.
       
   308 
       
   309 	@SYMPREQ 269
       
   310 
       
   311 	@SYMTestStatus Implemented
       
   312 
       
   313 	@SYMTestPriority High
       
   314 
       
   315 	@SYMTestActions 
       
   316 	The animation must be initialised, and the data provider for a basic animation and
       
   317 	a sprite animation are changed.
       
   318 
       
   319 	@SYMTestExpectedResults 
       
   320 	No output changed.  The animation test TestLoopsForeverL is run afterwards.
       
   321 */
       
   322 void CBasic::TestDataChangeL()
       
   323 	{
       
   324 	static_cast<CICLAnimationDataProvider*>(iBasicAnimation->DataProvider())->SetFileL(iFs, KSymWaveFile());
       
   325 	static_cast<CICLAnimationDataProvider*>(iSpriteAnimation->DataProvider())->SetFileL(iFs, KSymWaveFile());
       
   326 	Wait(2000000);
       
   327 	}
       
   328 
       
   329 TVerdict CBasic::doActiveTestStepL()
       
   330 	{
       
   331 	_LIT(KLoopsForever, "Loops forever");
       
   332 	_LIT(KLoopsNumbered, "Loops numbered");
       
   333 	_LIT(KNotLooped, "Not looped");
       
   334 	_LIT(KControl, "Control");
       
   335 	_LIT(KMoving, "Moving");
       
   336 	_LIT(KDataChange, "Data Change");
       
   337 	
       
   338 	InitialiseL();
       
   339 
       
   340 	Wait(2000000);
       
   341 
       
   342 	TInt stage = 0;
       
   343 	TBool finished = EFalse;
       
   344 	while((TestStepResult() == EPass) && !finished)
       
   345 		{
       
   346 		switch(stage)
       
   347 			{
       
   348 			case 0:
       
   349 				SetTestStepID(_L("UIF-animation-TBasic-TestLoopsForeverL-0001"));
       
   350 				ANIM_INFO1(KLoopsForever);
       
   351 				TestLoopsForeverL();
       
   352 				RecordTestResultL();
       
   353 				break;
       
   354 			case 1:
       
   355 				SetTestStepID(_L("UIF-animation-TBasic-TestLoopsNumberedL"));
       
   356 				ANIM_INFO1(KLoopsNumbered);
       
   357 				TestLoopsNumberedL();
       
   358 				RecordTestResultL();
       
   359 				break;
       
   360 			case 2:
       
   361 				SetTestStepID(_L("UIF-animation-TBasic-TestNotLoopedL"));
       
   362 				ANIM_INFO1(KNotLooped);
       
   363 				TestNotLoopedL();
       
   364 				RecordTestResultL();
       
   365 				break;
       
   366 			case 3:
       
   367 				SetTestStepID(_L("UIF-animation-TBasic-TestControlL"));
       
   368 				ANIM_INFO1(KControl);
       
   369 				TestControlL();
       
   370 				RecordTestResultL();
       
   371 				break;
       
   372 			case 4:
       
   373 				SetTestStepID(_L("UIF-animation-TBasic-TestMovingL"));
       
   374 				ANIM_INFO1(KMoving);
       
   375 				TestMovingL();
       
   376 				RecordTestResultL();
       
   377 				break;
       
   378 			case 5:
       
   379 				SetTestStepID(_L("UIF-animation-TBasic-TestDataChangeL"));
       
   380 				ANIM_INFO1(KDataChange);
       
   381 				TestDataChangeL();
       
   382 				RecordTestResultL();
       
   383 				break;
       
   384 			case 6:
       
   385 				SetTestStepID(_L("UIF-animation-TBasic-TestLoopsForeverL-0002"));
       
   386 				ANIM_INFO1(KLoopsForever);
       
   387 				TestLoopsForeverL();
       
   388 				RecordTestResultL();
       
   389 				CloseTMSGraphicsStep();
       
   390 				break;
       
   391 			default:
       
   392 				finished = ETrue;
       
   393 			}
       
   394 		++stage;
       
   395 		}
       
   396 	return TestStepResult();
       
   397 	}
       
   398 	
       
   399 void CBasic::AnimationEvent(CAnimation& /*aSender*/, TInt aEvent, TAny* aData)
       
   400 	{
       
   401 	switch(aEvent)
       
   402 		{
       
   403 		case MAnimationObserver::EDataProviderError:
       
   404 			ANIMTESTERR(*static_cast<TInt*>(aData));
       
   405 			break;
       
   406 		default:
       
   407 			break;
       
   408 		}
       
   409 	}