os/mm/mmlibs/mmfw/tsrc/mmfunittest/videorenderer/src/testrendererneg.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/videorenderer/src/testrendererneg.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,766 @@
     1.4 +// Copyright (c) 2007-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 +#include "testrendererneg.h"
    1.20 +#include "videoframebuffer.h"
    1.21 +#include "resourcefilereader.h"
    1.22 +#include "testgceharness.h"
    1.23 +
    1.24 +RTestRendererCreateSurfaceStep* RTestRendererCreateSurfaceStep::NewL(const TDesC& aStepName, 
    1.25 +																			TInt aExpectedError, 
    1.26 +																			TRgbFormat aRgbFormat, 
    1.27 +																			TSize aSize, 
    1.28 +																			TInt aNumBuffers)
    1.29 +	{
    1.30 +	RTestRendererCreateSurfaceStep* self = new (ELeave) RTestRendererCreateSurfaceStep(aStepName,
    1.31 +																					aExpectedError, 
    1.32 +																					aRgbFormat, 
    1.33 +																					aSize, 
    1.34 +																					aNumBuffers);
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +RTestRendererCreateSurfaceStep::RTestRendererCreateSurfaceStep(const TDesC& aStepName, 
    1.39 +																		TInt aExpectedError, 
    1.40 +																		TRgbFormat aRgbFormat, 
    1.41 +																		TSize aSize, 
    1.42 +																		TInt aNumBuffers) :
    1.43 +	RTestRendererStep(aStepName, EFalse),
    1.44 +	iExpectedError(aExpectedError), 
    1.45 +	iNumBuffers(aNumBuffers)
    1.46 +	{
    1.47 +	iVideoFormat.iRgbFormat = aRgbFormat;
    1.48 +	iSize = aSize;
    1.49 +	}
    1.50 +
    1.51 +TVerdict RTestRendererCreateSurfaceStep::DoTestStepL()
    1.52 +	{
    1.53 +	__UHEAP_MARK;
    1.54 +	
    1.55 +	CTestGCEHarness::NewL(iNumBuffers);
    1.56 +	iVideoRenderer = CVideoRenderer::NewL(*this, iTimed);
    1.57 +	TRAPD(err, iVideoRenderer->CreateSurfaceL(iSize, iNumBuffers, iVideoFormat, iSurfaceId));
    1.58 +	INFO_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedError, err);
    1.59 +	TESTL(err == iExpectedError);
    1.60 +
    1.61 +	delete iVideoRenderer;
    1.62 +	iVideoRenderer = NULL;
    1.63 +
    1.64 +	// cleanup test harness
    1.65 +	CTestGCEHarness::Remove();
    1.66 +	    
    1.67 +	__UHEAP_MARKEND;
    1.68 +
    1.69 +    return iTestStepResult;
    1.70 +	}
    1.71 +
    1.72 +
    1.73 +RTestRendererUpdateTwiceStep* RTestRendererUpdateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
    1.74 +	{
    1.75 +	RTestRendererUpdateTwiceStep* self = new (ELeave) RTestRendererUpdateTwiceStep(aStepName, aTimed);
    1.76 +	return self;
    1.77 +	}
    1.78 +
    1.79 +RTestRendererUpdateTwiceStep::RTestRendererUpdateTwiceStep(const TDesC& aStepName, TBool aTimed) :
    1.80 +	RTestRendererStep(aStepName, aTimed)
    1.81 +	{
    1.82 +	}
    1.83 +
    1.84 +void RTestRendererUpdateTwiceStep::FsmL(TTestRendererEvents aEventCode)
    1.85 +	{
    1.86 +	switch (aEventCode)
    1.87 +	    {
    1.88 +	    case EStartTest:
    1.89 +	    	iFsmState = EStateCreate;
    1.90 +	        CreateRendererAndSurfaceL(1);
    1.91 +	        break;
    1.92 +	    case EBufferAvailable:
    1.93 +	    	iBuffAvailCallback++;
    1.94 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
    1.95 +	    		{
    1.96 +	            iFsmState = EStateUpdate;
    1.97 +
    1.98 +	            // received the first callback, map surface to display
    1.99 +	            TInt err = SetBackgroundSurface(iSurfaceId);
   1.100 +	            if (err != KErrNone)
   1.101 +	            	{
   1.102 +		        	ERR_PRINTF2(_L("RWindow::SetBackgroundSurface() returned %d"), err);
   1.103 +                    iTestStepResult = EFail;
   1.104 +                    break;
   1.105 +	            	}
   1.106 +
   1.107 +	            // send the first buffer
   1.108 +	        	TTime presentationTime(0);
   1.109 +
   1.110 +	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   1.111 +	        	TVideoFrameBuffer* buffer;
   1.112 +	        	buffer = iVideoRenderer->NextBuffer();
   1.113 +	        	TESTL(buffer != NULL);
   1.114 +	        	TESTL(buffer->BufferId() == 0);
   1.115 +	        	
   1.116 +	        	TInt bufSize = buffer->Stride() * iSize.iHeight;
   1.117 +	        	Mem::Fill(buffer->Buffer(), bufSize, KRgbGreen.Internal());
   1.118 +	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   1.119 +	        	iVideoRenderer->UpdateBuffer(buffer, presentationTime);
   1.120 +
   1.121 +	        	// send the same buffer again
   1.122 +	        	TESTL(buffer != NULL);
   1.123 +	        	TESTL(buffer->BufferId() == 0);
   1.124 +	        	iVideoRenderer->UpdateBuffer(buffer, presentationTime);
   1.125 +	    		}
   1.126 +	    	else if (iFsmState == EStateUpdate)
   1.127 +	    		{
   1.128 +	        	// buffer is available again after update
   1.129 +	    	    if (iBuffAvailCallback == 2 && iBuffDisplayCallback == 1)
   1.130 +	    	    	{
   1.131 +	    	    	// all available callback and display callback have been received, complete test with pass
   1.132 +	            	EndTest(EPass);
   1.133 +	    	    	}
   1.134 +	    		}
   1.135 +	    	else
   1.136 +	    		{
   1.137 +	    		// unexpected state, fail test
   1.138 +	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.139 +	        	EndTest(EFail);
   1.140 +	    		}
   1.141 +	
   1.142 +	    	break;
   1.143 +	    case EBufferDisplayed:
   1.144 +	    	iBuffDisplayCallback++;
   1.145 +	    	if (iFsmState == EStateUpdate && iBuffDisplayCallback == 1 && iBufferId == 0)
   1.146 +	    		{
   1.147 +	    		// receive the first display callback, the buffer id is 0 (first buffer)
   1.148 +	        	if (iBuffAvailCallback == 2)
   1.149 +	        		{
   1.150 +	        		// received all bufAvailable callback after buffer displayed, test complete with pass
   1.151 +	        		EndTest(EPass);
   1.152 +	        		}
   1.153 +	        	// otherwise, haven't received all bufAvailable callback yet, continue waiting
   1.154 +	    		}
   1.155 +	    	else
   1.156 +	    		{
   1.157 +	    		// received unexpected event
   1.158 +	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer displayed event."), iFsmState);
   1.159 +	    		EndTest(EFail);
   1.160 +	    		}
   1.161 +	    	break;
   1.162 +	    default:
   1.163 +			// unexpected event
   1.164 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateTwiceStep::FsmL"), aEventCode);
   1.165 +	    	EndTest(EFail);
   1.166 +	    	break;
   1.167 +	    }
   1.168 +	}
   1.169 +
   1.170 +
   1.171 +RTestRendererReleaseTwiceStep* RTestRendererReleaseTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.172 +	{
   1.173 +	RTestRendererReleaseTwiceStep* self = new (ELeave) RTestRendererReleaseTwiceStep(aStepName, aTimed);
   1.174 +	return self;
   1.175 +	}
   1.176 +
   1.177 +RTestRendererReleaseTwiceStep::RTestRendererReleaseTwiceStep(const TDesC& aStepName, TBool aTimed) :
   1.178 +	RTestRendererStep(aStepName, aTimed)
   1.179 +	{
   1.180 +	}
   1.181 +
   1.182 +TVerdict RTestRendererReleaseTwiceStep::DoTestStepL()
   1.183 +	{
   1.184 +	__UHEAP_MARK;
   1.185 +	
   1.186 +    // Call the state handler from IDLE state, don't need to start active scheduler
   1.187 +    TRAPD(err, FsmL(EStartTest));
   1.188 +    if (err != KErrNone)
   1.189 +    	{
   1.190 +        ERR_PRINTF2(_L("FsmL(EStartTest) leave with %d"), err);
   1.191 +    	iTestStepResult = EFail;
   1.192 +    	}
   1.193 +    
   1.194 +	delete iVideoRenderer;
   1.195 +	iVideoRenderer = NULL;
   1.196 +
   1.197 +	// cleanup test harness
   1.198 +	CTestGCEHarness::Remove();
   1.199 +	    
   1.200 +	__UHEAP_MARKEND;
   1.201 +
   1.202 +    return iTestStepResult;
   1.203 +	}
   1.204 +
   1.205 +void RTestRendererReleaseTwiceStep::FsmL(TTestRendererEvents aEventCode)
   1.206 +	{
   1.207 +	switch (aEventCode)
   1.208 +	    {
   1.209 +	    case EStartTest:
   1.210 +	    	iFsmState = EStateCreate;
   1.211 +	        CreateRendererAndSurfaceL(1);
   1.212 +	        break;
   1.213 +	    case EBufferAvailable:
   1.214 +	    	iBuffAvailCallback++;
   1.215 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.216 +	    		{
   1.217 +	        	// buffer is available after surface create
   1.218 +	            iFsmState = EStateReleaseBuffer;
   1.219 +
   1.220 +	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   1.221 +	        	iBuffer = iVideoRenderer->NextBuffer();
   1.222 +	        	TESTL(iBuffer != NULL);
   1.223 +	        	TESTL(iBuffer->BufferId() == 0);
   1.224 +	        	
   1.225 +	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   1.226 +	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   1.227 +	    		}
   1.228 +	    	else if (iFsmState == EStateReleaseBuffer && iBuffAvailCallback == 2)
   1.229 +	    		{
   1.230 +	        	// buffer is available again after update
   1.231 +	        	// check that buffer still point to the same buffer
   1.232 +	        	TESTL(iBuffer != NULL);
   1.233 +	        	TESTL(iBuffer->BufferId() == 0);
   1.234 +
   1.235 +	        	// call release buffer again, expect no error and no extra callback
   1.236 +	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   1.237 +	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   1.238 +	    		}
   1.239 +	    	else
   1.240 +	    		{
   1.241 +	    		// unexpected state, fail test
   1.242 +	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.243 +                iTestStepResult = EFail;
   1.244 +	    		}
   1.245 +	
   1.246 +	    	break;
   1.247 +	    default:
   1.248 +			// unexpected event
   1.249 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererReleaseTwiceStep::FsmL"), aEventCode);
   1.250 +	    	iTestStepResult = EFail;
   1.251 +	    	break;
   1.252 +	    }
   1.253 +	}
   1.254 +
   1.255 +
   1.256 +RTestRendererDestroySurfaceStep* RTestRendererDestroySurfaceStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.257 +	{
   1.258 +	RTestRendererDestroySurfaceStep* self = new (ELeave) RTestRendererDestroySurfaceStep(aStepName, aTimed);
   1.259 +	return self;
   1.260 +	}
   1.261 +
   1.262 +RTestRendererDestroySurfaceStep::RTestRendererDestroySurfaceStep(const TDesC& aStepName, TBool aTimed) :
   1.263 +	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   1.264 +	{
   1.265 +	}
   1.266 +
   1.267 +void RTestRendererDestroySurfaceStep::FsmL(TTestRendererEvents aEventCode)
   1.268 +	{
   1.269 +	switch (aEventCode)
   1.270 +	    {
   1.271 +	    case EStartTest:
   1.272 +	    	iFsmState = EStateCreate;
   1.273 +	        CreateRendererAndSurfaceL(1);
   1.274 +	        break;
   1.275 +	    case EBufferAvailable:
   1.276 +	    	iBuffAvailCallback++;
   1.277 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.278 +	    		{
   1.279 +	        	// buffer is available after surface create
   1.280 +	            iFsmState = EStateReleaseBuffer;
   1.281 +	
   1.282 +	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   1.283 +	        	iBuffer = iVideoRenderer->NextBuffer();
   1.284 +	        	TESTL(iBuffer != NULL);
   1.285 +	        	TESTL(iBuffer->BufferId() == 0);
   1.286 +
   1.287 +	        	INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
   1.288 +	        	iVideoRenderer->DestroySurface(iSurfaceId);
   1.289 +
   1.290 +	        	// check that iBuffer is not null
   1.291 +	        	TESTL(iBuffer != NULL);
   1.292 +
   1.293 +	        	// submit update, expect no callback and no error
   1.294 +	            TTime presentationTime(0);
   1.295 +	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   1.296 +	        	iVideoRenderer->UpdateBuffer(iBuffer, presentationTime);
   1.297 +
   1.298 +	        	// release buffer, expect no callback and no error
   1.299 +	            INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
   1.300 +	        	iVideoRenderer->ReleaseBuffer(iBuffer);
   1.301 +
   1.302 +	        	// try to get the next buffer after surface destroyed, expect null
   1.303 +	        	INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
   1.304 +	        	iBuffer = iVideoRenderer->NextBuffer();
   1.305 +	        	TESTL(iBuffer == NULL);
   1.306 +	    		}
   1.307 +	    	else
   1.308 +	    		{
   1.309 +	    		// unexpected state, fail test
   1.310 +	    		ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.311 +	            iTestStepResult = EFail;
   1.312 +	    		}
   1.313 +	
   1.314 +	    	break;
   1.315 +	    default:
   1.316 +			// unexpected event
   1.317 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroySurfaceStep::FsmL"), aEventCode);
   1.318 +	    	iTestStepResult = EFail;
   1.319 +	    	break;
   1.320 +	    }
   1.321 +	}
   1.322 +
   1.323 +
   1.324 +RTestRendererUpdateAndDestroyStep* RTestRendererUpdateAndDestroyStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.325 +	{
   1.326 +	RTestRendererUpdateAndDestroyStep* self = new (ELeave) RTestRendererUpdateAndDestroyStep(aStepName, aTimed);
   1.327 +	return self;
   1.328 +	}
   1.329 +
   1.330 +RTestRendererUpdateAndDestroyStep::RTestRendererUpdateAndDestroyStep(const TDesC& aStepName, TBool aTimed) :
   1.331 +	RTestRendererStep(aStepName, aTimed)
   1.332 +	{
   1.333 +	}
   1.334 +
   1.335 +TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPreambleL()
   1.336 +	{
   1.337 +	TVerdict result = RTestRendererStep::DoTestStepPreambleL();
   1.338 +	
   1.339 +	TCallBack callback(TimerCallbackFunc, this);
   1.340 +	iCallbackTimer = CCallBackTimer::NewL(callback);
   1.341 +
   1.342 +	return result;
   1.343 +	}
   1.344 +
   1.345 +TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPostambleL()
   1.346 +	{
   1.347 +	delete iCallbackTimer;
   1.348 +	return RTestRendererStep::DoTestStepPostambleL();
   1.349 +	}
   1.350 +
   1.351 +TInt RTestRendererUpdateAndDestroyStep::TimerCallbackFunc(TAny *aPtr)
   1.352 +	{
   1.353 +	RTestRendererDelayStep* teststep = static_cast<RTestRendererDelayStep*>(aPtr);
   1.354 +	TRAP_IGNORE(teststep->FsmL(ETimerExpired)); // ETimerExpired state does not leave
   1.355 +
   1.356 +	return KErrNone;
   1.357 +	}
   1.358 +
   1.359 +void RTestRendererUpdateAndDestroyStep::FsmL(TTestRendererEvents aEventCode)
   1.360 +	{
   1.361 +	switch (aEventCode)
   1.362 +	    {
   1.363 +	    case EStartTest:
   1.364 +	    	iFsmState = EStateCreate;
   1.365 +	        CreateRendererAndSurfaceL(1);
   1.366 +	        break;
   1.367 +	    case EBufferAvailable:
   1.368 +	    	iBuffAvailCallback++;
   1.369 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.370 +	    		{
   1.371 +	            iFsmState = EStateUpdate;
   1.372 +
   1.373 +    	    	// received callback, map surface to display
   1.374 +	            TInt err = SetBackgroundSurface(iSurfaceId);
   1.375 +	            TESTL(err == KErrNone);
   1.376 +
   1.377 +	            // send the buffer
   1.378 +	        	TTime nowTime;
   1.379 +	        	nowTime.UniversalTime();
   1.380 +	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   1.381 +	        	TTime presentationTime1 = nowTime + delay1;
   1.382 +	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   1.383 +	            
   1.384 +	            // destroy surface
   1.385 +	        	INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
   1.386 +	        	iVideoRenderer->DestroySurface(iSurfaceId);
   1.387 +	        	
   1.388 +	        	// wait for a second for ensure that timed mode is ok, expect nothing
   1.389 +	        	TTimeIntervalMicroSeconds32 oneSecond(1000000);
   1.390 +	            iCallbackTimer->After(oneSecond);
   1.391 +            	}
   1.392 +            else
   1.393 +            	{
   1.394 +            	// unexpected state, test failed
   1.395 +            	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.396 +                EndTest(EFail);
   1.397 +	    		}
   1.398 +	    	break;
   1.399 +	    case ETimerExpired:
   1.400 +	    	// timer expired, stop active scheduler, heap check marco will check for any leak
   1.401 +	    	CActiveScheduler::Stop();
   1.402 +	    	break;
   1.403 +	    default:
   1.404 +			// unexpected event
   1.405 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDestroyStep::FsmL"), aEventCode);
   1.406 +	    	EndTest(EFail);
   1.407 +	    	break;
   1.408 +	    }
   1.409 +	}
   1.410 +
   1.411 +
   1.412 +RTestRendererUpdateAndDeleteStep* RTestRendererUpdateAndDeleteStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.413 +	{
   1.414 +	RTestRendererUpdateAndDeleteStep* self = new (ELeave) RTestRendererUpdateAndDeleteStep(aStepName, aTimed);
   1.415 +	return self;
   1.416 +	}
   1.417 +
   1.418 +RTestRendererUpdateAndDeleteStep::RTestRendererUpdateAndDeleteStep(const TDesC& aStepName, TBool aTimed) :
   1.419 +	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   1.420 +	{
   1.421 +	}
   1.422 +
   1.423 +void RTestRendererUpdateAndDeleteStep::FsmL(TTestRendererEvents aEventCode)
   1.424 +	{
   1.425 +	switch (aEventCode)
   1.426 +	    {
   1.427 +	    case EStartTest:
   1.428 +	    	iFsmState = EStateCreate;
   1.429 +	        CreateRendererAndSurfaceL(1);
   1.430 +	        break;
   1.431 +	    case EBufferAvailable:
   1.432 +	    	iBuffAvailCallback++;
   1.433 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.434 +	    		{
   1.435 +	            iFsmState = EStateUpdate;
   1.436 +	
   1.437 +		    	// received callback, map surface to display
   1.438 +	            TInt err = SetBackgroundSurface(iSurfaceId);
   1.439 +	            TESTL(err == KErrNone);
   1.440 +	
   1.441 +	            // send the buffer
   1.442 +	        	TTime nowTime;
   1.443 +	        	nowTime.UniversalTime();
   1.444 +	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   1.445 +	        	TTime presentationTime1 = nowTime + delay1;
   1.446 +	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   1.447 +	            
   1.448 +	            // delete renderer
   1.449 +	        	INFO_PRINTF1(_L("delete iVideoRenderer"));
   1.450 +	        	delete iVideoRenderer;
   1.451 +	        	iVideoRenderer = 0;
   1.452 +
   1.453 +	        	// wait for a second for ensure that timed mode is ok, expect nothing
   1.454 +	        	TTimeIntervalMicroSeconds32 oneSecond(1000000);
   1.455 +	        	User::After(oneSecond);
   1.456 +	    		}
   1.457 +	        else
   1.458 +	        	{
   1.459 +	        	// unexpected state, test failed
   1.460 +	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.461 +	            iTestStepResult = EFail;
   1.462 +	    		}
   1.463 +	    	break;
   1.464 +	    default:
   1.465 +			// unexpected event
   1.466 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDeleteStep::FsmL"), aEventCode);
   1.467 +	    	iTestStepResult = EFail;
   1.468 +	    	break;
   1.469 +	    }
   1.470 +	}
   1.471 +
   1.472 +
   1.473 +RTestRendererUpdateInvalidStep* RTestRendererUpdateInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.474 +	{
   1.475 +	RTestRendererUpdateInvalidStep* self = new (ELeave) RTestRendererUpdateInvalidStep(aStepName, aTimed);
   1.476 +	return self;
   1.477 +	}
   1.478 +
   1.479 +RTestRendererUpdateInvalidStep::RTestRendererUpdateInvalidStep(const TDesC& aStepName, TBool aTimed) :
   1.480 +	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   1.481 +	{
   1.482 +	}
   1.483 +
   1.484 +void RTestRendererUpdateInvalidStep::FsmL(TTestRendererEvents aEventCode)
   1.485 +	{
   1.486 +	switch (aEventCode)
   1.487 +	    {
   1.488 +	    case EStartTest:
   1.489 +	    	iFsmState = EStateCreate;
   1.490 +	        CreateRendererAndSurfaceL(1);
   1.491 +	        break;
   1.492 +	    case EBufferAvailable:
   1.493 +	    	iBuffAvailCallback++;
   1.494 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.495 +	    		{
   1.496 +	            iFsmState = EStateUpdate;
   1.497 +	
   1.498 +		    	// received callback, map surface to display
   1.499 +	            TInt err = SetBackgroundSurface(iSurfaceId);
   1.500 +	            TESTL(err == KErrNone);
   1.501 +
   1.502 +	            // get a buffer
   1.503 +	        	TVideoFrameBuffer* buffer;
   1.504 +	        	buffer = iVideoRenderer->NextBuffer();
   1.505 +	        	TESTL(buffer != NULL);
   1.506 +	        	TESTL(buffer->Format() == iVideoFormat);
   1.507 +	        	TESTL(buffer->Stride() == iSize.iWidth *  4); // 4 bite per pixel for ERgb32bit888
   1.508 +	        	TESTL(buffer->BufferId() == 0);
   1.509 +	        	TESTL(buffer->Buffer() != NULL);
   1.510 +
   1.511 +	            // create a local buffer with same parameters
   1.512 +	        	TVideoFrameBuffer localBuffer(buffer->Format(), 
   1.513 +	        			buffer->Stride(),
   1.514 +	        			buffer->BufferId(), 
   1.515 +	        			buffer->Chunk(),
   1.516 +	        			0);
   1.517 +	        	
   1.518 +	        	TInt bufSize = buffer->Stride() * iSize.iHeight;
   1.519 +	        	Mem::Fill(buffer->Buffer(), bufSize, KRgbGreen.Internal());
   1.520 +	        	TTime time(0);
   1.521 +	            INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
   1.522 +	        	iVideoRenderer->UpdateBuffer(&localBuffer, time);
   1.523 +	    		}
   1.524 +	        else
   1.525 +	        	{
   1.526 +	        	// unexpected state, test failed
   1.527 +	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.528 +	            iTestStepResult = EFail;
   1.529 +	    		}
   1.530 +	    	break;
   1.531 +	    default:
   1.532 +			// unexpected event
   1.533 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateInvalidStep::FsmL"), aEventCode);
   1.534 +	    	iTestStepResult = EFail;
   1.535 +	    	break;
   1.536 +	    }
   1.537 +	}
   1.538 +
   1.539 +RTestRendererCreateTwiceStep* RTestRendererCreateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.540 +	{
   1.541 +	RTestRendererCreateTwiceStep* self = new (ELeave) RTestRendererCreateTwiceStep(aStepName, aTimed);
   1.542 +	return self;
   1.543 +	}
   1.544 +
   1.545 +RTestRendererCreateTwiceStep::RTestRendererCreateTwiceStep(const TDesC& aStepName, TBool aTimed) :
   1.546 +	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   1.547 +	{
   1.548 +	}
   1.549 +
   1.550 +void RTestRendererCreateTwiceStep::FsmL(TTestRendererEvents aEventCode)
   1.551 +	{
   1.552 +	switch (aEventCode)
   1.553 +	    {
   1.554 +	    case EStartTest:
   1.555 +	    	iFsmState = EStateCreate;
   1.556 +	        CreateRendererAndSurfaceL(1);
   1.557 +	        break;
   1.558 +	    case EBufferAvailable:
   1.559 +	    	iBuffAvailCallback++;
   1.560 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.561 +	    		{
   1.562 +	    		// Create surface again
   1.563 +	    		TRAPD(err, CreateSurfaceL(1));
   1.564 +	    		INFO_PRINTF3(_L("Expected error code=%d, received error code=%d"), KErrInUse, err);
   1.565 +	    		TESTL(err == KErrInUse);
   1.566 +	    		}
   1.567 +	        else
   1.568 +	        	{
   1.569 +	        	// unexpected state, test failed
   1.570 +	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.571 +	            iTestStepResult = EFail;
   1.572 +	    		}
   1.573 +	    	break;
   1.574 +	    default:
   1.575 +			// unexpected event
   1.576 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererCreateTwiceStep::FsmL"), aEventCode);
   1.577 +	    	iTestStepResult = EFail;
   1.578 +	    	break;
   1.579 +	    }
   1.580 +	}
   1.581 +
   1.582 +RTestRendererDestroyInvalidStep* RTestRendererDestroyInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
   1.583 +	{
   1.584 +	RTestRendererDestroyInvalidStep* self = new (ELeave) RTestRendererDestroyInvalidStep(aStepName, aTimed);
   1.585 +	return self;
   1.586 +	}
   1.587 +
   1.588 +RTestRendererDestroyInvalidStep::RTestRendererDestroyInvalidStep(const TDesC& aStepName, TBool aTimed) :
   1.589 +	RTestRendererReleaseTwiceStep(aStepName, aTimed)
   1.590 +	{
   1.591 +	}
   1.592 +
   1.593 +void RTestRendererDestroyInvalidStep::FsmL(TTestRendererEvents aEventCode)
   1.594 +	{
   1.595 +	switch (aEventCode)
   1.596 +	    {
   1.597 +	    case EStartTest:
   1.598 +	    	iFsmState = EStateCreate;
   1.599 +	        CreateRendererAndSurfaceL(1);
   1.600 +	        break;
   1.601 +	    case EBufferAvailable:
   1.602 +	    	iBuffAvailCallback++;
   1.603 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.604 +	    		{
   1.605 +	    		// create a surface id that is not the same as iSurfaceId
   1.606 +	    		TSurfaceId invalidId = iSurfaceId;
   1.607 +	    		invalidId.iInternal[0] += 1;
   1.608 +	    		invalidId.iInternal[1] += 1;
   1.609 +	    		invalidId.iInternal[2] += 1;
   1.610 +	    		invalidId.iInternal[3] += 1;
   1.611 +	    		
   1.612 +	    		// Destory surface with invalid id
   1.613 +	    		iVideoRenderer->DestroySurface(invalidId);
   1.614 +
   1.615 +	    		// Destory surface twice, the second call is ignored
   1.616 +	    		iVideoRenderer->DestroySurface(iSurfaceId);
   1.617 +	    		iVideoRenderer->DestroySurface(iSurfaceId);
   1.618 +
   1.619 +	    		// Destory surface with invalid id after the surface is destroyed
   1.620 +	    		iVideoRenderer->DestroySurface(invalidId);
   1.621 +	    		}
   1.622 +	        else
   1.623 +	        	{
   1.624 +	        	// unexpected state, test failed
   1.625 +	        	ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
   1.626 +	            iTestStepResult = EFail;
   1.627 +	    		}
   1.628 +	    	break;
   1.629 +	    default:
   1.630 +			// unexpected event
   1.631 +			ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroyInvalidStep::FsmL"), aEventCode);
   1.632 +	    	iTestStepResult = EFail;
   1.633 +	    	break;
   1.634 +	    }
   1.635 +	}
   1.636 +
   1.637 +RTestResourceFileReaderStep* RTestResourceFileReaderStep::NewL(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
   1.638 +	{
   1.639 +	RTestResourceFileReaderStep* self = new (ELeave) RTestResourceFileReaderStep(aStepName, aFileName, aExpectedFormatErr, aExpectedTimerErr, aExpectedDefaultDelay, aExpectedDelay);
   1.640 +	return self;	
   1.641 +	}
   1.642 +
   1.643 +RTestResourceFileReaderStep::RTestResourceFileReaderStep(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
   1.644 +	{
   1.645 +	iTestStepName = aStepName;
   1.646 +	iFileName = aFileName;
   1.647 +	iExpectedFormatErr = aExpectedFormatErr;
   1.648 +	iExpectedTimerErr = aExpectedTimerErr;
   1.649 +	iExpectedDefaultDelay = aExpectedDefaultDelay;
   1.650 +	iExpectedMaxDelay = aExpectedDelay;
   1.651 +	}
   1.652 +
   1.653 +TVerdict RTestResourceFileReaderStep::DoTestStepL()
   1.654 +	{
   1.655 +	INFO_PRINTF1(_L("Check Resource file reader"));
   1.656 +	
   1.657 +	__UHEAP_MARK;
   1.658 +	
   1.659 +	RArray<TUncompressedVideoFormat> supportedFormat;
   1.660 +	CleanupClosePushL(supportedFormat);
   1.661 +	CResourceFileReader* reader = CResourceFileReader::NewLC(iFileName);
   1.662 +	TRAPD(err, reader->ReadSupportedFormatL(supportedFormat));
   1.663 +	if (err != iExpectedFormatErr)
   1.664 +		{
   1.665 +		iTestStepResult = EFail;
   1.666 +		ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedFormatErr, err);
   1.667 +		}
   1.668 +	TInt64 defaultDelay;
   1.669 +	TInt64 maxDelay;
   1.670 +	TRAP(err, reader->ReadTimerInfoL(defaultDelay, maxDelay));
   1.671 +	if (err != iExpectedTimerErr)
   1.672 +		{
   1.673 +		iTestStepResult = EFail;
   1.674 +		ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedTimerErr, err);
   1.675 +		}
   1.676 +	else if (defaultDelay != iExpectedDefaultDelay || maxDelay != iExpectedMaxDelay)
   1.677 +		{
   1.678 +		iTestStepResult = EFail;
   1.679 +		ERR_PRINTF3(_L("Expected default delay=%d, received default delay=%d"), iExpectedDefaultDelay, defaultDelay);
   1.680 +		ERR_PRINTF3(_L("Expected max delay=%d, received max delay=%d"), iExpectedMaxDelay, maxDelay);
   1.681 +		}
   1.682 +		
   1.683 +	CleanupStack::PopAndDestroy(2, &supportedFormat);
   1.684 +	
   1.685 +	__UHEAP_MARKEND;
   1.686 +
   1.687 +	return iTestStepResult;
   1.688 +	}
   1.689 +
   1.690 +
   1.691 +RTestRendererDelayStep* RTestRendererDelayStep::NewL(const TDesC& aStepName)
   1.692 +	{
   1.693 +	RTestRendererDelayStep* self = new (ELeave) RTestRendererDelayStep(aStepName);
   1.694 +	return self;
   1.695 +	}
   1.696 +
   1.697 +RTestRendererDelayStep::RTestRendererDelayStep(const TDesC& aStepName) :
   1.698 +	RTestRendererUpdateAndDestroyStep(aStepName, ETrue)
   1.699 +	{
   1.700 +	}
   1.701 +
   1.702 +void RTestRendererDelayStep::FsmL(TTestRendererEvents aEventCode)
   1.703 +	{
   1.704 +	switch (aEventCode)
   1.705 +	    {
   1.706 +	    case EStartTest:
   1.707 +	    	iFsmState = EStateCreate;
   1.708 +	        CreateRendererAndSurfaceL(1);
   1.709 +	        break;
   1.710 +	    case EBufferAvailable:
   1.711 +	    	iBuffAvailCallback++;
   1.712 +	    	if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
   1.713 +	    		{
   1.714 +	            iFsmState = EStateUpdate;
   1.715 +
   1.716 +	            // send the buffer without set background surface
   1.717 +	        	TTime nowTime;
   1.718 +	        	nowTime.UniversalTime();
   1.719 +	        	TTimeIntervalMicroSeconds delay1(500000); // use half second delay
   1.720 +	        	TTime presentationTime1 = nowTime + delay1;
   1.721 +	            GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
   1.722 +	            
   1.723 +	            iCallbackTimer->AtUTC(presentationTime1);
   1.724 +            	}
   1.725 +	    	else if (iFsmState == EStateUpdate)
   1.726 +	    		{
   1.727 +	        	// buffer is available again after update
   1.728 +	    	    if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
   1.729 +	    	    	{
   1.730 +	    	    	// all callbacks have been received, complete test with pass
   1.731 +	            	EndTest(EPass);
   1.732 +	    	    	}
   1.733 +	    		}
   1.734 +	    	else
   1.735 +	    		{
   1.736 +	    		// unexpected state, fail test
   1.737 +	        	EndTest(EFail);
   1.738 +	    		}
   1.739 +	
   1.740 +	    	break;
   1.741 +	    case ETimerExpired:
   1.742 +	    	{
   1.743 +	    	// received the first callback, map surface to display
   1.744 +			INFO_PRINTF1(_L("Timer expired event receibed"));
   1.745 +
   1.746 +	        TInt err = SetBackgroundSurface(iSurfaceId);
   1.747 +	        TESTL(err == KErrNone);
   1.748 +
   1.749 +	        if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
   1.750 +    	    	{
   1.751 +    	    	// all callbacks have been received, complete test with pass
   1.752 +            	EndTest(EPass);
   1.753 +    	    	}
   1.754 +	    	break;
   1.755 +	    	}
   1.756 +	    case EBufferSkipped:
   1.757 +	    	iBuffSkipCallback++;
   1.758 +	    	// expect 1 buffer skipped callback at fsm state EStateUpdate for bufferId 0
   1.759 +	    	if (iFsmState != EStateUpdate || iBuffSkipCallback != 1 || iBufferId != 0)
   1.760 +	    		{
   1.761 +	        	EndTest(EFail);
   1.762 +	    		}
   1.763 +	    	break;
   1.764 +	    default:
   1.765 +	    	// unexpected state
   1.766 +	    	EndTest(EFail);
   1.767 +	    	break;
   1.768 +	    }
   1.769 +	}