os/mm/mmlibs/mmfw/tsrc/mmfunittest/videorenderer/src/testrendererneg.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-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 #include "testrendererneg.h"
    17 #include "videoframebuffer.h"
    18 #include "resourcefilereader.h"
    19 #include "testgceharness.h"
    20 
    21 RTestRendererCreateSurfaceStep* RTestRendererCreateSurfaceStep::NewL(const TDesC& aStepName, 
    22 																			TInt aExpectedError, 
    23 																			TRgbFormat aRgbFormat, 
    24 																			TSize aSize, 
    25 																			TInt aNumBuffers)
    26 	{
    27 	RTestRendererCreateSurfaceStep* self = new (ELeave) RTestRendererCreateSurfaceStep(aStepName,
    28 																					aExpectedError, 
    29 																					aRgbFormat, 
    30 																					aSize, 
    31 																					aNumBuffers);
    32 	return self;
    33 	}
    34 
    35 RTestRendererCreateSurfaceStep::RTestRendererCreateSurfaceStep(const TDesC& aStepName, 
    36 																		TInt aExpectedError, 
    37 																		TRgbFormat aRgbFormat, 
    38 																		TSize aSize, 
    39 																		TInt aNumBuffers) :
    40 	RTestRendererStep(aStepName, EFalse),
    41 	iExpectedError(aExpectedError), 
    42 	iNumBuffers(aNumBuffers)
    43 	{
    44 	iVideoFormat.iRgbFormat = aRgbFormat;
    45 	iSize = aSize;
    46 	}
    47 
    48 TVerdict RTestRendererCreateSurfaceStep::DoTestStepL()
    49 	{
    50 	__UHEAP_MARK;
    51 	
    52 	CTestGCEHarness::NewL(iNumBuffers);
    53 	iVideoRenderer = CVideoRenderer::NewL(*this, iTimed);
    54 	TRAPD(err, iVideoRenderer->CreateSurfaceL(iSize, iNumBuffers, iVideoFormat, iSurfaceId));
    55 	INFO_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedError, err);
    56 	TESTL(err == iExpectedError);
    57 
    58 	delete iVideoRenderer;
    59 	iVideoRenderer = NULL;
    60 
    61 	// cleanup test harness
    62 	CTestGCEHarness::Remove();
    63 	    
    64 	__UHEAP_MARKEND;
    65 
    66     return iTestStepResult;
    67 	}
    68 
    69 
    70 RTestRendererUpdateTwiceStep* RTestRendererUpdateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
    71 	{
    72 	RTestRendererUpdateTwiceStep* self = new (ELeave) RTestRendererUpdateTwiceStep(aStepName, aTimed);
    73 	return self;
    74 	}
    75 
    76 RTestRendererUpdateTwiceStep::RTestRendererUpdateTwiceStep(const TDesC& aStepName, TBool aTimed) :
    77 	RTestRendererStep(aStepName, aTimed)
    78 	{
    79 	}
    80 
    81 void RTestRendererUpdateTwiceStep::FsmL(TTestRendererEvents aEventCode)
    82 	{
    83 	switch (aEventCode)
    84 	    {
    85 	    case EStartTest:
    86 	    	iFsmState = EStateCreate;
    87 	        CreateRendererAndSurfaceL(1);
    88 	        break;
    89 	    case EBufferAvailable:
    90 	    	iBuffAvailCallback++;
    91 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
    92 	    		{
    93 	            iFsmState = EStateUpdate;
    94 
    95 	            // received the first callback, map surface to display
    96 	            TInt err = SetBackgroundSurface(iSurfaceId);
    97 	            if (err != KErrNone)
    98 	            	{
    99 		        	ERR_PRINTF2(_L("RWindow::SetBackgroundSurface() returned %d"), err);
   100                     iTestStepResult = EFail;
   101                     break;
   102 	            	}
   103 
   104 	            // send the first buffer
   105 	        	TTime presentationTime(0);
   106 
   107 	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   108 	        	TVideoFrameBuffer* buffer;
   109 	        	buffer = iVideoRenderer->NextBuffer();
   110 	        	TESTL(buffer != NULL);
   111 	        	TESTL(buffer->BufferId() == 0);
   112 	        	
   113 	        	TInt bufSize = buffer->Stride() * iSize.iHeight;
   114 	        	Mem::Fill(buffer->Buffer(), bufSize, KRgbGreen.Internal());
   115 	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   116 	        	iVideoRenderer->UpdateBuffer(buffer, presentationTime);
   117 
   118 	        	// send the same buffer again
   119 	        	TESTL(buffer != NULL);
   120 	        	TESTL(buffer->BufferId() == 0);
   121 	        	iVideoRenderer->UpdateBuffer(buffer, presentationTime);
   122 	    		}
   123 	    	else if (iFsmState == EStateUpdate)
   124 	    		{
   125 	        	// buffer is available again after update
   126 	    	    if (iBuffAvailCallback == 2 && iBuffDisplayCallback == 1)
   127 	    	    	{
   128 	    	    	// all available callback and display callback have been received, complete test with pass
   129 	            	EndTest(EPass);
   130 	    	    	}
   131 	    		}
   132 	    	else
   133 	    		{
   134 	    		// unexpected state, fail test
   135 	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   136 	        	EndTest(EFail);
   137 	    		}
   138 	
   139 	    	break;
   140 	    case EBufferDisplayed:
   141 	    	iBuffDisplayCallback++;
   142 	    	if (iFsmState == EStateUpdate && iBuffDisplayCallback == 1 && iBufferId == 0)
   143 	    		{
   144 	    		// receive the first display callback, the buffer id is 0 (first buffer)
   145 	        	if (iBuffAvailCallback == 2)
   146 	        		{
   147 	        		// received all bufAvailable callback after buffer displayed, test complete with pass
   148 	        		EndTest(EPass);
   149 	        		}
   150 	        	// otherwise, haven't received all bufAvailable callback yet, continue waiting
   151 	    		}
   152 	    	else
   153 	    		{
   154 	    		// received unexpected event
   155 	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer displayed event."), iFsmState);
   156 	    		EndTest(EFail);
   157 	    		}
   158 	    	break;
   159 	    default:
   160 			// unexpected event
   161 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateTwiceStep::FsmL"), aEventCode);
   162 	    	EndTest(EFail);
   163 	    	break;
   164 	    }
   165 	}
   166 
   167 
   168 RTestRendererReleaseTwiceStep* RTestRendererReleaseTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
   169 	{
   170 	RTestRendererReleaseTwiceStep* self = new (ELeave) RTestRendererReleaseTwiceStep(aStepName, aTimed);
   171 	return self;
   172 	}
   173 
   174 RTestRendererReleaseTwiceStep::RTestRendererReleaseTwiceStep(const TDesC& aStepName, TBool aTimed) :
   175 	RTestRendererStep(aStepName, aTimed)
   176 	{
   177 	}
   178 
   179 TVerdict RTestRendererReleaseTwiceStep::DoTestStepL()
   180 	{
   181 	__UHEAP_MARK;
   182 	
   183     // Call the state handler from IDLE state, don't need to start active scheduler
   184     TRAPD(err, FsmL(EStartTest));
   185     if (err != KErrNone)
   186     	{
   187         ERR_PRINTF2(_L("FsmL(EStartTest) leave with %d"), err);
   188     	iTestStepResult = EFail;
   189     	}
   190     
   191 	delete iVideoRenderer;
   192 	iVideoRenderer = NULL;
   193 
   194 	// cleanup test harness
   195 	CTestGCEHarness::Remove();
   196 	    
   197 	__UHEAP_MARKEND;
   198 
   199     return iTestStepResult;
   200 	}
   201 
   202 void RTestRendererReleaseTwiceStep::FsmL(TTestRendererEvents aEventCode)
   203 	{
   204 	switch (aEventCode)
   205 	    {
   206 	    case EStartTest:
   207 	    	iFsmState = EStateCreate;
   208 	        CreateRendererAndSurfaceL(1);
   209 	        break;
   210 	    case EBufferAvailable:
   211 	    	iBuffAvailCallback++;
   212 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   213 	    		{
   214 	        	// buffer is available after surface create
   215 	            iFsmState = EStateReleaseBuffer;
   216 
   217 	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   218 	        	iBuffer = iVideoRenderer->NextBuffer();
   219 	        	TESTL(iBuffer != NULL);
   220 	        	TESTL(iBuffer->BufferId() == 0);
   221 	        	
   222 	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   223 	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   224 	    		}
   225 	    	else if (iFsmState == EStateReleaseBuffer && iBuffAvailCallback == 2)
   226 	    		{
   227 	        	// buffer is available again after update
   228 	        	// check that buffer still point to the same buffer
   229 	        	TESTL(iBuffer != NULL);
   230 	        	TESTL(iBuffer->BufferId() == 0);
   231 
   232 	        	// call release buffer again, expect no error and no extra callback
   233 	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   234 	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   235 	    		}
   236 	    	else
   237 	    		{
   238 	    		// unexpected state, fail test
   239 	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   240                 iTestStepResult = EFail;
   241 	    		}
   242 	
   243 	    	break;
   244 	    default:
   245 			// unexpected event
   246 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererReleaseTwiceStep::FsmL"), aEventCode);
   247 	    	iTestStepResult = EFail;
   248 	    	break;
   249 	    }
   250 	}
   251 
   252 
   253 RTestRendererDestroySurfaceStep* RTestRendererDestroySurfaceStep::NewL(const TDesC& aStepName, TBool aTimed)
   254 	{
   255 	RTestRendererDestroySurfaceStep* self = new (ELeave) RTestRendererDestroySurfaceStep(aStepName, aTimed);
   256 	return self;
   257 	}
   258 
   259 RTestRendererDestroySurfaceStep::RTestRendererDestroySurfaceStep(const TDesC& aStepName, TBool aTimed) :
   260 	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   261 	{
   262 	}
   263 
   264 void RTestRendererDestroySurfaceStep::FsmL(TTestRendererEvents aEventCode)
   265 	{
   266 	switch (aEventCode)
   267 	    {
   268 	    case EStartTest:
   269 	    	iFsmState = EStateCreate;
   270 	        CreateRendererAndSurfaceL(1);
   271 	        break;
   272 	    case EBufferAvailable:
   273 	    	iBuffAvailCallback++;
   274 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   275 	    		{
   276 	        	// buffer is available after surface create
   277 	            iFsmState = EStateReleaseBuffer;
   278 	
   279 	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   280 	        	iBuffer = iVideoRenderer->NextBuffer();
   281 	        	TESTL(iBuffer != NULL);
   282 	        	TESTL(iBuffer->BufferId() == 0);
   283 
   284 	        	INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
   285 	        	iVideoRenderer->DestroySurface(iSurfaceId);
   286 
   287 	        	// check that iBuffer is not null
   288 	        	TESTL(iBuffer != NULL);
   289 
   290 	        	// submit update, expect no callback and no error
   291 	            TTime presentationTime(0);
   292 	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   293 	        	iVideoRenderer->UpdateBuffer(iBuffer, presentationTime);
   294 
   295 	        	// release buffer, expect no callback and no error
   296 	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   297 	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   298 
   299 	        	// try to get the next buffer after surface destroyed, expect null
   300 	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   301 	        	iBuffer = iVideoRenderer->NextBuffer();
   302 	        	TESTL(iBuffer == NULL);
   303 	    		}
   304 	    	else
   305 	    		{
   306 	    		// unexpected state, fail test
   307 	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   308 	            iTestStepResult = EFail;
   309 	    		}
   310 	
   311 	    	break;
   312 	    default:
   313 			// unexpected event
   314 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroySurfaceStep::FsmL"), aEventCode);
   315 	    	iTestStepResult = EFail;
   316 	    	break;
   317 	    }
   318 	}
   319 
   320 
   321 RTestRendererUpdateAndDestroyStep* RTestRendererUpdateAndDestroyStep::NewL(const TDesC& aStepName, TBool aTimed)
   322 	{
   323 	RTestRendererUpdateAndDestroyStep* self = new (ELeave) RTestRendererUpdateAndDestroyStep(aStepName, aTimed);
   324 	return self;
   325 	}
   326 
   327 RTestRendererUpdateAndDestroyStep::RTestRendererUpdateAndDestroyStep(const TDesC& aStepName, TBool aTimed) :
   328 	RTestRendererStep(aStepName, aTimed)
   329 	{
   330 	}
   331 
   332 TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPreambleL()
   333 	{
   334 	TVerdict result = RTestRendererStep::DoTestStepPreambleL();
   335 	
   336 	TCallBack callback(TimerCallbackFunc, this);
   337 	iCallbackTimer = CCallBackTimer::NewL(callback);
   338 
   339 	return result;
   340 	}
   341 
   342 TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPostambleL()
   343 	{
   344 	delete iCallbackTimer;
   345 	return RTestRendererStep::DoTestStepPostambleL();
   346 	}
   347 
   348 TInt RTestRendererUpdateAndDestroyStep::TimerCallbackFunc(TAny *aPtr)
   349 	{
   350 	RTestRendererDelayStep* teststep = static_cast<RTestRendererDelayStep*>(aPtr);
   351 	TRAP_IGNORE(teststep->FsmL(ETimerExpired)); // ETimerExpired state does not leave
   352 
   353 	return KErrNone;
   354 	}
   355 
   356 void RTestRendererUpdateAndDestroyStep::FsmL(TTestRendererEvents aEventCode)
   357 	{
   358 	switch (aEventCode)
   359 	    {
   360 	    case EStartTest:
   361 	    	iFsmState = EStateCreate;
   362 	        CreateRendererAndSurfaceL(1);
   363 	        break;
   364 	    case EBufferAvailable:
   365 	    	iBuffAvailCallback++;
   366 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   367 	    		{
   368 	            iFsmState = EStateUpdate;
   369 
   370     	    	// received callback, map surface to display
   371 	            TInt err = SetBackgroundSurface(iSurfaceId);
   372 	            TESTL(err == KErrNone);
   373 
   374 	            // send the buffer
   375 	        	TTime nowTime;
   376 	        	nowTime.UniversalTime();
   377 	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   378 	        	TTime presentationTime1 = nowTime + delay1;
   379 	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   380 	            
   381 	            // destroy surface
   382 	        	INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
   383 	        	iVideoRenderer->DestroySurface(iSurfaceId);
   384 	        	
   385 	        	// wait for a second for ensure that timed mode is ok, expect nothing
   386 	        	TTimeIntervalMicroSeconds32 oneSecond(1000000);
   387 	            iCallbackTimer->After(oneSecond);
   388             	}
   389             else
   390             	{
   391             	// unexpected state, test failed
   392             	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   393                 EndTest(EFail);
   394 	    		}
   395 	    	break;
   396 	    case ETimerExpired:
   397 	    	// timer expired, stop active scheduler, heap check marco will check for any leak
   398 	    	CActiveScheduler::Stop();
   399 	    	break;
   400 	    default:
   401 			// unexpected event
   402 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDestroyStep::FsmL"), aEventCode);
   403 	    	EndTest(EFail);
   404 	    	break;
   405 	    }
   406 	}
   407 
   408 
   409 RTestRendererUpdateAndDeleteStep* RTestRendererUpdateAndDeleteStep::NewL(const TDesC& aStepName, TBool aTimed)
   410 	{
   411 	RTestRendererUpdateAndDeleteStep* self = new (ELeave) RTestRendererUpdateAndDeleteStep(aStepName, aTimed);
   412 	return self;
   413 	}
   414 
   415 RTestRendererUpdateAndDeleteStep::RTestRendererUpdateAndDeleteStep(const TDesC& aStepName, TBool aTimed) :
   416 	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   417 	{
   418 	}
   419 
   420 void RTestRendererUpdateAndDeleteStep::FsmL(TTestRendererEvents aEventCode)
   421 	{
   422 	switch (aEventCode)
   423 	    {
   424 	    case EStartTest:
   425 	    	iFsmState = EStateCreate;
   426 	        CreateRendererAndSurfaceL(1);
   427 	        break;
   428 	    case EBufferAvailable:
   429 	    	iBuffAvailCallback++;
   430 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   431 	    		{
   432 	            iFsmState = EStateUpdate;
   433 	
   434 		    	// received callback, map surface to display
   435 	            TInt err = SetBackgroundSurface(iSurfaceId);
   436 	            TESTL(err == KErrNone);
   437 	
   438 	            // send the buffer
   439 	        	TTime nowTime;
   440 	        	nowTime.UniversalTime();
   441 	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   442 	        	TTime presentationTime1 = nowTime + delay1;
   443 	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   444 	            
   445 	            // delete renderer
   446 	        	INFO_PRINTF1(_L("delete iVideoRenderer"));
   447 	        	delete iVideoRenderer;
   448 	        	iVideoRenderer = 0;
   449 
   450 	        	// wait for a second for ensure that timed mode is ok, expect nothing
   451 	        	TTimeIntervalMicroSeconds32 oneSecond(1000000);
   452 	        	User::After(oneSecond);
   453 	    		}
   454 	        else
   455 	        	{
   456 	        	// unexpected state, test failed
   457 	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   458 	            iTestStepResult = EFail;
   459 	    		}
   460 	    	break;
   461 	    default:
   462 			// unexpected event
   463 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDeleteStep::FsmL"), aEventCode);
   464 	    	iTestStepResult = EFail;
   465 	    	break;
   466 	    }
   467 	}
   468 
   469 
   470 RTestRendererUpdateInvalidStep* RTestRendererUpdateInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
   471 	{
   472 	RTestRendererUpdateInvalidStep* self = new (ELeave) RTestRendererUpdateInvalidStep(aStepName, aTimed);
   473 	return self;
   474 	}
   475 
   476 RTestRendererUpdateInvalidStep::RTestRendererUpdateInvalidStep(const TDesC& aStepName, TBool aTimed) :
   477 	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   478 	{
   479 	}
   480 
   481 void RTestRendererUpdateInvalidStep::FsmL(TTestRendererEvents aEventCode)
   482 	{
   483 	switch (aEventCode)
   484 	    {
   485 	    case EStartTest:
   486 	    	iFsmState = EStateCreate;
   487 	        CreateRendererAndSurfaceL(1);
   488 	        break;
   489 	    case EBufferAvailable:
   490 	    	iBuffAvailCallback++;
   491 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   492 	    		{
   493 	            iFsmState = EStateUpdate;
   494 	
   495 		    	// received callback, map surface to display
   496 	            TInt err = SetBackgroundSurface(iSurfaceId);
   497 	            TESTL(err == KErrNone);
   498 
   499 	            // get a buffer
   500 	        	TVideoFrameBuffer* buffer;
   501 	        	buffer = iVideoRenderer->NextBuffer();
   502 	        	TESTL(buffer != NULL);
   503 	        	TESTL(buffer->Format() == iVideoFormat);
   504 	        	TESTL(buffer->Stride() == iSize.iWidth *  4); // 4 bite per pixel for ERgb32bit888
   505 	        	TESTL(buffer->BufferId() == 0);
   506 	        	TESTL(buffer->Buffer() != NULL);
   507 
   508 	            // create a local buffer with same parameters
   509 	        	TVideoFrameBuffer localBuffer(buffer->Format(), 
   510 	        			buffer->Stride(),
   511 	        			buffer->BufferId(), 
   512 	        			buffer->Chunk(),
   513 	        			0);
   514 	        	
   515 	        	TInt bufSize = buffer->Stride() * iSize.iHeight;
   516 	        	Mem::Fill(buffer->Buffer(), bufSize, KRgbGreen.Internal());
   517 	        	TTime time(0);
   518 	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   519 	        	iVideoRenderer->UpdateBuffer(&localBuffer, time);
   520 	    		}
   521 	        else
   522 	        	{
   523 	        	// unexpected state, test failed
   524 	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   525 	            iTestStepResult = EFail;
   526 	    		}
   527 	    	break;
   528 	    default:
   529 			// unexpected event
   530 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateInvalidStep::FsmL"), aEventCode);
   531 	    	iTestStepResult = EFail;
   532 	    	break;
   533 	    }
   534 	}
   535 
   536 RTestRendererCreateTwiceStep* RTestRendererCreateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
   537 	{
   538 	RTestRendererCreateTwiceStep* self = new (ELeave) RTestRendererCreateTwiceStep(aStepName, aTimed);
   539 	return self;
   540 	}
   541 
   542 RTestRendererCreateTwiceStep::RTestRendererCreateTwiceStep(const TDesC& aStepName, TBool aTimed) :
   543 	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   544 	{
   545 	}
   546 
   547 void RTestRendererCreateTwiceStep::FsmL(TTestRendererEvents aEventCode)
   548 	{
   549 	switch (aEventCode)
   550 	    {
   551 	    case EStartTest:
   552 	    	iFsmState = EStateCreate;
   553 	        CreateRendererAndSurfaceL(1);
   554 	        break;
   555 	    case EBufferAvailable:
   556 	    	iBuffAvailCallback++;
   557 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   558 	    		{
   559 	    		// Create surface again
   560 	    		TRAPD(err, CreateSurfaceL(1));
   561 	    		INFO_PRINTF3(_L("Expected error code=%d, received error code=%d"), KErrInUse, err);
   562 	    		TESTL(err == KErrInUse);
   563 	    		}
   564 	        else
   565 	        	{
   566 	        	// unexpected state, test failed
   567 	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   568 	            iTestStepResult = EFail;
   569 	    		}
   570 	    	break;
   571 	    default:
   572 			// unexpected event
   573 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererCreateTwiceStep::FsmL"), aEventCode);
   574 	    	iTestStepResult = EFail;
   575 	    	break;
   576 	    }
   577 	}
   578 
   579 RTestRendererDestroyInvalidStep* RTestRendererDestroyInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
   580 	{
   581 	RTestRendererDestroyInvalidStep* self = new (ELeave) RTestRendererDestroyInvalidStep(aStepName, aTimed);
   582 	return self;
   583 	}
   584 
   585 RTestRendererDestroyInvalidStep::RTestRendererDestroyInvalidStep(const TDesC& aStepName, TBool aTimed) :
   586 	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   587 	{
   588 	}
   589 
   590 void RTestRendererDestroyInvalidStep::FsmL(TTestRendererEvents aEventCode)
   591 	{
   592 	switch (aEventCode)
   593 	    {
   594 	    case EStartTest:
   595 	    	iFsmState = EStateCreate;
   596 	        CreateRendererAndSurfaceL(1);
   597 	        break;
   598 	    case EBufferAvailable:
   599 	    	iBuffAvailCallback++;
   600 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   601 	    		{
   602 	    		// create a surface id that is not the same as iSurfaceId
   603 	    		TSurfaceId invalidId = iSurfaceId;
   604 	    		invalidId.iInternal[0] += 1;
   605 	    		invalidId.iInternal[1] += 1;
   606 	    		invalidId.iInternal[2] += 1;
   607 	    		invalidId.iInternal[3] += 1;
   608 	    		
   609 	    		// Destory surface with invalid id
   610 	    		iVideoRenderer->DestroySurface(invalidId);
   611 
   612 	    		// Destory surface twice, the second call is ignored
   613 	    		iVideoRenderer->DestroySurface(iSurfaceId);
   614 	    		iVideoRenderer->DestroySurface(iSurfaceId);
   615 
   616 	    		// Destory surface with invalid id after the surface is destroyed
   617 	    		iVideoRenderer->DestroySurface(invalidId);
   618 	    		}
   619 	        else
   620 	        	{
   621 	        	// unexpected state, test failed
   622 	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   623 	            iTestStepResult = EFail;
   624 	    		}
   625 	    	break;
   626 	    default:
   627 			// unexpected event
   628 			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroyInvalidStep::FsmL"), aEventCode);
   629 	    	iTestStepResult = EFail;
   630 	    	break;
   631 	    }
   632 	}
   633 
   634 RTestResourceFileReaderStep* RTestResourceFileReaderStep::NewL(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
   635 	{
   636 	RTestResourceFileReaderStep* self = new (ELeave) RTestResourceFileReaderStep(aStepName, aFileName, aExpectedFormatErr, aExpectedTimerErr, aExpectedDefaultDelay, aExpectedDelay);
   637 	return self;	
   638 	}
   639 
   640 RTestResourceFileReaderStep::RTestResourceFileReaderStep(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
   641 	{
   642 	iTestStepName = aStepName;
   643 	iFileName = aFileName;
   644 	iExpectedFormatErr = aExpectedFormatErr;
   645 	iExpectedTimerErr = aExpectedTimerErr;
   646 	iExpectedDefaultDelay = aExpectedDefaultDelay;
   647 	iExpectedMaxDelay = aExpectedDelay;
   648 	}
   649 
   650 TVerdict RTestResourceFileReaderStep::DoTestStepL()
   651 	{
   652 	INFO_PRINTF1(_L("Check Resource file reader"));
   653 	
   654 	__UHEAP_MARK;
   655 	
   656 	RArray<TUncompressedVideoFormat> supportedFormat;
   657 	CleanupClosePushL(supportedFormat);
   658 	CResourceFileReader* reader = CResourceFileReader::NewLC(iFileName);
   659 	TRAPD(err, reader->ReadSupportedFormatL(supportedFormat));
   660 	if (err != iExpectedFormatErr)
   661 		{
   662 		iTestStepResult = EFail;
   663 		ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedFormatErr, err);
   664 		}
   665 	TInt64 defaultDelay;
   666 	TInt64 maxDelay;
   667 	TRAP(err, reader->ReadTimerInfoL(defaultDelay, maxDelay));
   668 	if (err != iExpectedTimerErr)
   669 		{
   670 		iTestStepResult = EFail;
   671 		ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedTimerErr, err);
   672 		}
   673 	else if (defaultDelay != iExpectedDefaultDelay || maxDelay != iExpectedMaxDelay)
   674 		{
   675 		iTestStepResult = EFail;
   676 		ERR_PRINTF3(_L("Expected default delay=%d, received default delay=%d"), iExpectedDefaultDelay, defaultDelay);
   677 		ERR_PRINTF3(_L("Expected max delay=%d, received max delay=%d"), iExpectedMaxDelay, maxDelay);
   678 		}
   679 		
   680 	CleanupStack::PopAndDestroy(2, &supportedFormat);
   681 	
   682 	__UHEAP_MARKEND;
   683 
   684 	return iTestStepResult;
   685 	}
   686 
   687 
   688 RTestRendererDelayStep* RTestRendererDelayStep::NewL(const TDesC& aStepName)
   689 	{
   690 	RTestRendererDelayStep* self = new (ELeave) RTestRendererDelayStep(aStepName);
   691 	return self;
   692 	}
   693 
   694 RTestRendererDelayStep::RTestRendererDelayStep(const TDesC& aStepName) :
   695 	RTestRendererUpdateAndDestroyStep(aStepName, ETrue)
   696 	{
   697 	}
   698 
   699 void RTestRendererDelayStep::FsmL(TTestRendererEvents aEventCode)
   700 	{
   701 	switch (aEventCode)
   702 	    {
   703 	    case EStartTest:
   704 	    	iFsmState = EStateCreate;
   705 	        CreateRendererAndSurfaceL(1);
   706 	        break;
   707 	    case EBufferAvailable:
   708 	    	iBuffAvailCallback++;
   709 	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   710 	    		{
   711 	            iFsmState = EStateUpdate;
   712 
   713 	            // send the buffer without set background surface
   714 	        	TTime nowTime;
   715 	        	nowTime.UniversalTime();
   716 	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   717 	        	TTime presentationTime1 = nowTime + delay1;
   718 	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   719 	            
   720 	            iCallbackTimer->AtUTC(presentationTime1);
   721             	}
   722 	    	else if (iFsmState == EStateUpdate)
   723 	    		{
   724 	        	// buffer is available again after update
   725 	    	    if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
   726 	    	    	{
   727 	    	    	// all callbacks have been received, complete test with pass
   728 	            	EndTest(EPass);
   729 	    	    	}
   730 	    		}
   731 	    	else
   732 	    		{
   733 	    		// unexpected state, fail test
   734 	        	EndTest(EFail);
   735 	    		}
   736 	
   737 	    	break;
   738 	    case ETimerExpired:
   739 	    	{
   740 	    	// received the first callback, map surface to display
   741 			INFO_PRINTF1(_L("Timer expired event receibed"));
   742 
   743 	        TInt err = SetBackgroundSurface(iSurfaceId);
   744 	        TESTL(err == KErrNone);
   745 
   746 	        if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
   747     	    	{
   748     	    	// all callbacks have been received, complete test with pass
   749             	EndTest(EPass);
   750     	    	}
   751 	    	break;
   752 	    	}
   753 	    case EBufferSkipped:
   754 	    	iBuffSkipCallback++;
   755 	    	// expect 1 buffer skipped callback at fsm state EStateUpdate for bufferId 0
   756 	    	if (iFsmState != EStateUpdate || iBuffSkipCallback != 1 || iBufferId != 0)
   757 	    		{
   758 	        	EndTest(EFail);
   759 	    		}
   760 	    	break;
   761 	    default:
   762 	    	// unexpected state
   763 	    	EndTest(EFail);
   764 	    	break;
   765 	    }
   766 	}