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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "testrendererneg.h"
17 #include "videoframebuffer.h"
18 #include "resourcefilereader.h"
19 #include "testgceharness.h"
21 RTestRendererCreateSurfaceStep* RTestRendererCreateSurfaceStep::NewL(const TDesC& aStepName,
23 TRgbFormat aRgbFormat,
27 RTestRendererCreateSurfaceStep* self = new (ELeave) RTestRendererCreateSurfaceStep(aStepName,
35 RTestRendererCreateSurfaceStep::RTestRendererCreateSurfaceStep(const TDesC& aStepName,
37 TRgbFormat aRgbFormat,
40 RTestRendererStep(aStepName, EFalse),
41 iExpectedError(aExpectedError),
42 iNumBuffers(aNumBuffers)
44 iVideoFormat.iRgbFormat = aRgbFormat;
48 TVerdict RTestRendererCreateSurfaceStep::DoTestStepL()
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);
58 delete iVideoRenderer;
59 iVideoRenderer = NULL;
61 // cleanup test harness
62 CTestGCEHarness::Remove();
66 return iTestStepResult;
70 RTestRendererUpdateTwiceStep* RTestRendererUpdateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
72 RTestRendererUpdateTwiceStep* self = new (ELeave) RTestRendererUpdateTwiceStep(aStepName, aTimed);
76 RTestRendererUpdateTwiceStep::RTestRendererUpdateTwiceStep(const TDesC& aStepName, TBool aTimed) :
77 RTestRendererStep(aStepName, aTimed)
81 void RTestRendererUpdateTwiceStep::FsmL(TTestRendererEvents aEventCode)
86 iFsmState = EStateCreate;
87 CreateRendererAndSurfaceL(1);
89 case EBufferAvailable:
91 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
93 iFsmState = EStateUpdate;
95 // received the first callback, map surface to display
96 TInt err = SetBackgroundSurface(iSurfaceId);
99 ERR_PRINTF2(_L("RWindow::SetBackgroundSurface() returned %d"), err);
100 iTestStepResult = EFail;
104 // send the first buffer
105 TTime presentationTime(0);
107 INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
108 TVideoFrameBuffer* buffer;
109 buffer = iVideoRenderer->NextBuffer();
110 TESTL(buffer != NULL);
111 TESTL(buffer->BufferId() == 0);
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);
118 // send the same buffer again
119 TESTL(buffer != NULL);
120 TESTL(buffer->BufferId() == 0);
121 iVideoRenderer->UpdateBuffer(buffer, presentationTime);
123 else if (iFsmState == EStateUpdate)
125 // buffer is available again after update
126 if (iBuffAvailCallback == 2 && iBuffDisplayCallback == 1)
128 // all available callback and display callback have been received, complete test with pass
134 // unexpected state, fail test
135 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
140 case EBufferDisplayed:
141 iBuffDisplayCallback++;
142 if (iFsmState == EStateUpdate && iBuffDisplayCallback == 1 && iBufferId == 0)
144 // receive the first display callback, the buffer id is 0 (first buffer)
145 if (iBuffAvailCallback == 2)
147 // received all bufAvailable callback after buffer displayed, test complete with pass
150 // otherwise, haven't received all bufAvailable callback yet, continue waiting
154 // received unexpected event
155 ERR_PRINTF2(_L("State %d was not expected when handling buffer displayed event."), iFsmState);
161 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateTwiceStep::FsmL"), aEventCode);
168 RTestRendererReleaseTwiceStep* RTestRendererReleaseTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
170 RTestRendererReleaseTwiceStep* self = new (ELeave) RTestRendererReleaseTwiceStep(aStepName, aTimed);
174 RTestRendererReleaseTwiceStep::RTestRendererReleaseTwiceStep(const TDesC& aStepName, TBool aTimed) :
175 RTestRendererStep(aStepName, aTimed)
179 TVerdict RTestRendererReleaseTwiceStep::DoTestStepL()
183 // Call the state handler from IDLE state, don't need to start active scheduler
184 TRAPD(err, FsmL(EStartTest));
187 ERR_PRINTF2(_L("FsmL(EStartTest) leave with %d"), err);
188 iTestStepResult = EFail;
191 delete iVideoRenderer;
192 iVideoRenderer = NULL;
194 // cleanup test harness
195 CTestGCEHarness::Remove();
199 return iTestStepResult;
202 void RTestRendererReleaseTwiceStep::FsmL(TTestRendererEvents aEventCode)
207 iFsmState = EStateCreate;
208 CreateRendererAndSurfaceL(1);
210 case EBufferAvailable:
211 iBuffAvailCallback++;
212 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
214 // buffer is available after surface create
215 iFsmState = EStateReleaseBuffer;
217 INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
218 iBuffer = iVideoRenderer->NextBuffer();
219 TESTL(iBuffer != NULL);
220 TESTL(iBuffer->BufferId() == 0);
222 INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
223 iVideoRenderer->ReleaseBuffer(iBuffer);
225 else if (iFsmState == EStateReleaseBuffer && iBuffAvailCallback == 2)
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);
232 // call release buffer again, expect no error and no extra callback
233 INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
234 iVideoRenderer->ReleaseBuffer(iBuffer);
238 // unexpected state, fail test
239 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
240 iTestStepResult = EFail;
246 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererReleaseTwiceStep::FsmL"), aEventCode);
247 iTestStepResult = EFail;
253 RTestRendererDestroySurfaceStep* RTestRendererDestroySurfaceStep::NewL(const TDesC& aStepName, TBool aTimed)
255 RTestRendererDestroySurfaceStep* self = new (ELeave) RTestRendererDestroySurfaceStep(aStepName, aTimed);
259 RTestRendererDestroySurfaceStep::RTestRendererDestroySurfaceStep(const TDesC& aStepName, TBool aTimed) :
260 RTestRendererReleaseTwiceStep(aStepName, aTimed)
264 void RTestRendererDestroySurfaceStep::FsmL(TTestRendererEvents aEventCode)
269 iFsmState = EStateCreate;
270 CreateRendererAndSurfaceL(1);
272 case EBufferAvailable:
273 iBuffAvailCallback++;
274 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
276 // buffer is available after surface create
277 iFsmState = EStateReleaseBuffer;
279 INFO_PRINTF1(_L("iVideoRenderer->NextBuffer()"));
280 iBuffer = iVideoRenderer->NextBuffer();
281 TESTL(iBuffer != NULL);
282 TESTL(iBuffer->BufferId() == 0);
284 INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
285 iVideoRenderer->DestroySurface(iSurfaceId);
287 // check that iBuffer is not null
288 TESTL(iBuffer != NULL);
290 // submit update, expect no callback and no error
291 TTime presentationTime(0);
292 INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
293 iVideoRenderer->UpdateBuffer(iBuffer, presentationTime);
295 // release buffer, expect no callback and no error
296 INFO_PRINTF1(_L("iVideoRenderer->ReleaseBuffer()"));
297 iVideoRenderer->ReleaseBuffer(iBuffer);
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);
306 // unexpected state, fail test
307 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
308 iTestStepResult = EFail;
314 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroySurfaceStep::FsmL"), aEventCode);
315 iTestStepResult = EFail;
321 RTestRendererUpdateAndDestroyStep* RTestRendererUpdateAndDestroyStep::NewL(const TDesC& aStepName, TBool aTimed)
323 RTestRendererUpdateAndDestroyStep* self = new (ELeave) RTestRendererUpdateAndDestroyStep(aStepName, aTimed);
327 RTestRendererUpdateAndDestroyStep::RTestRendererUpdateAndDestroyStep(const TDesC& aStepName, TBool aTimed) :
328 RTestRendererStep(aStepName, aTimed)
332 TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPreambleL()
334 TVerdict result = RTestRendererStep::DoTestStepPreambleL();
336 TCallBack callback(TimerCallbackFunc, this);
337 iCallbackTimer = CCallBackTimer::NewL(callback);
342 TVerdict RTestRendererUpdateAndDestroyStep::DoTestStepPostambleL()
344 delete iCallbackTimer;
345 return RTestRendererStep::DoTestStepPostambleL();
348 TInt RTestRendererUpdateAndDestroyStep::TimerCallbackFunc(TAny *aPtr)
350 RTestRendererDelayStep* teststep = static_cast<RTestRendererDelayStep*>(aPtr);
351 TRAP_IGNORE(teststep->FsmL(ETimerExpired)); // ETimerExpired state does not leave
356 void RTestRendererUpdateAndDestroyStep::FsmL(TTestRendererEvents aEventCode)
361 iFsmState = EStateCreate;
362 CreateRendererAndSurfaceL(1);
364 case EBufferAvailable:
365 iBuffAvailCallback++;
366 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
368 iFsmState = EStateUpdate;
370 // received callback, map surface to display
371 TInt err = SetBackgroundSurface(iSurfaceId);
372 TESTL(err == KErrNone);
376 nowTime.UniversalTime();
377 TTimeIntervalMicroSeconds delay1(500000); // use half second delay
378 TTime presentationTime1 = nowTime + delay1;
379 GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
382 INFO_PRINTF1(_L("iVideoRenderer->DestroySurface()"));
383 iVideoRenderer->DestroySurface(iSurfaceId);
385 // wait for a second for ensure that timed mode is ok, expect nothing
386 TTimeIntervalMicroSeconds32 oneSecond(1000000);
387 iCallbackTimer->After(oneSecond);
391 // unexpected state, test failed
392 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
397 // timer expired, stop active scheduler, heap check marco will check for any leak
398 CActiveScheduler::Stop();
402 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDestroyStep::FsmL"), aEventCode);
409 RTestRendererUpdateAndDeleteStep* RTestRendererUpdateAndDeleteStep::NewL(const TDesC& aStepName, TBool aTimed)
411 RTestRendererUpdateAndDeleteStep* self = new (ELeave) RTestRendererUpdateAndDeleteStep(aStepName, aTimed);
415 RTestRendererUpdateAndDeleteStep::RTestRendererUpdateAndDeleteStep(const TDesC& aStepName, TBool aTimed) :
416 RTestRendererReleaseTwiceStep(aStepName, aTimed)
420 void RTestRendererUpdateAndDeleteStep::FsmL(TTestRendererEvents aEventCode)
425 iFsmState = EStateCreate;
426 CreateRendererAndSurfaceL(1);
428 case EBufferAvailable:
429 iBuffAvailCallback++;
430 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
432 iFsmState = EStateUpdate;
434 // received callback, map surface to display
435 TInt err = SetBackgroundSurface(iSurfaceId);
436 TESTL(err == KErrNone);
440 nowTime.UniversalTime();
441 TTimeIntervalMicroSeconds delay1(500000); // use half second delay
442 TTime presentationTime1 = nowTime + delay1;
443 GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
446 INFO_PRINTF1(_L("delete iVideoRenderer"));
447 delete iVideoRenderer;
450 // wait for a second for ensure that timed mode is ok, expect nothing
451 TTimeIntervalMicroSeconds32 oneSecond(1000000);
452 User::After(oneSecond);
456 // unexpected state, test failed
457 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
458 iTestStepResult = EFail;
463 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateAndDeleteStep::FsmL"), aEventCode);
464 iTestStepResult = EFail;
470 RTestRendererUpdateInvalidStep* RTestRendererUpdateInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
472 RTestRendererUpdateInvalidStep* self = new (ELeave) RTestRendererUpdateInvalidStep(aStepName, aTimed);
476 RTestRendererUpdateInvalidStep::RTestRendererUpdateInvalidStep(const TDesC& aStepName, TBool aTimed) :
477 RTestRendererReleaseTwiceStep(aStepName, aTimed)
481 void RTestRendererUpdateInvalidStep::FsmL(TTestRendererEvents aEventCode)
486 iFsmState = EStateCreate;
487 CreateRendererAndSurfaceL(1);
489 case EBufferAvailable:
490 iBuffAvailCallback++;
491 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
493 iFsmState = EStateUpdate;
495 // received callback, map surface to display
496 TInt err = SetBackgroundSurface(iSurfaceId);
497 TESTL(err == KErrNone);
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);
508 // create a local buffer with same parameters
509 TVideoFrameBuffer localBuffer(buffer->Format(),
515 TInt bufSize = buffer->Stride() * iSize.iHeight;
516 Mem::Fill(buffer->Buffer(), bufSize, KRgbGreen.Internal());
518 INFO_PRINTF1(_L("iVideoRenderer->UpdateBuffer()"));
519 iVideoRenderer->UpdateBuffer(&localBuffer, time);
523 // unexpected state, test failed
524 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
525 iTestStepResult = EFail;
530 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererUpdateInvalidStep::FsmL"), aEventCode);
531 iTestStepResult = EFail;
536 RTestRendererCreateTwiceStep* RTestRendererCreateTwiceStep::NewL(const TDesC& aStepName, TBool aTimed)
538 RTestRendererCreateTwiceStep* self = new (ELeave) RTestRendererCreateTwiceStep(aStepName, aTimed);
542 RTestRendererCreateTwiceStep::RTestRendererCreateTwiceStep(const TDesC& aStepName, TBool aTimed) :
543 RTestRendererReleaseTwiceStep(aStepName, aTimed)
547 void RTestRendererCreateTwiceStep::FsmL(TTestRendererEvents aEventCode)
552 iFsmState = EStateCreate;
553 CreateRendererAndSurfaceL(1);
555 case EBufferAvailable:
556 iBuffAvailCallback++;
557 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
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);
566 // unexpected state, test failed
567 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
568 iTestStepResult = EFail;
573 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererCreateTwiceStep::FsmL"), aEventCode);
574 iTestStepResult = EFail;
579 RTestRendererDestroyInvalidStep* RTestRendererDestroyInvalidStep::NewL(const TDesC& aStepName, TBool aTimed)
581 RTestRendererDestroyInvalidStep* self = new (ELeave) RTestRendererDestroyInvalidStep(aStepName, aTimed);
585 RTestRendererDestroyInvalidStep::RTestRendererDestroyInvalidStep(const TDesC& aStepName, TBool aTimed) :
586 RTestRendererReleaseTwiceStep(aStepName, aTimed)
590 void RTestRendererDestroyInvalidStep::FsmL(TTestRendererEvents aEventCode)
595 iFsmState = EStateCreate;
596 CreateRendererAndSurfaceL(1);
598 case EBufferAvailable:
599 iBuffAvailCallback++;
600 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
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;
609 // Destory surface with invalid id
610 iVideoRenderer->DestroySurface(invalidId);
612 // Destory surface twice, the second call is ignored
613 iVideoRenderer->DestroySurface(iSurfaceId);
614 iVideoRenderer->DestroySurface(iSurfaceId);
616 // Destory surface with invalid id after the surface is destroyed
617 iVideoRenderer->DestroySurface(invalidId);
621 // unexpected state, test failed
622 ERR_PRINTF2(_L("State %d was not expected when handling buffer available event."), iFsmState);
623 iTestStepResult = EFail;
628 ERR_PRINTF2(_L("Unexpected event code %d in RTestRendererDestroyInvalidStep::FsmL"), aEventCode);
629 iTestStepResult = EFail;
634 RTestResourceFileReaderStep* RTestResourceFileReaderStep::NewL(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
636 RTestResourceFileReaderStep* self = new (ELeave) RTestResourceFileReaderStep(aStepName, aFileName, aExpectedFormatErr, aExpectedTimerErr, aExpectedDefaultDelay, aExpectedDelay);
640 RTestResourceFileReaderStep::RTestResourceFileReaderStep(const TDesC& aStepName, const TDesC& aFileName, TInt aExpectedFormatErr, TInt aExpectedTimerErr, TInt64 aExpectedDefaultDelay, TInt64 aExpectedDelay)
642 iTestStepName = aStepName;
643 iFileName = aFileName;
644 iExpectedFormatErr = aExpectedFormatErr;
645 iExpectedTimerErr = aExpectedTimerErr;
646 iExpectedDefaultDelay = aExpectedDefaultDelay;
647 iExpectedMaxDelay = aExpectedDelay;
650 TVerdict RTestResourceFileReaderStep::DoTestStepL()
652 INFO_PRINTF1(_L("Check Resource file reader"));
656 RArray<TUncompressedVideoFormat> supportedFormat;
657 CleanupClosePushL(supportedFormat);
658 CResourceFileReader* reader = CResourceFileReader::NewLC(iFileName);
659 TRAPD(err, reader->ReadSupportedFormatL(supportedFormat));
660 if (err != iExpectedFormatErr)
662 iTestStepResult = EFail;
663 ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedFormatErr, err);
667 TRAP(err, reader->ReadTimerInfoL(defaultDelay, maxDelay));
668 if (err != iExpectedTimerErr)
670 iTestStepResult = EFail;
671 ERR_PRINTF3(_L("Expected error code=%d, received error code=%d"), iExpectedTimerErr, err);
673 else if (defaultDelay != iExpectedDefaultDelay || maxDelay != iExpectedMaxDelay)
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);
680 CleanupStack::PopAndDestroy(2, &supportedFormat);
684 return iTestStepResult;
688 RTestRendererDelayStep* RTestRendererDelayStep::NewL(const TDesC& aStepName)
690 RTestRendererDelayStep* self = new (ELeave) RTestRendererDelayStep(aStepName);
694 RTestRendererDelayStep::RTestRendererDelayStep(const TDesC& aStepName) :
695 RTestRendererUpdateAndDestroyStep(aStepName, ETrue)
699 void RTestRendererDelayStep::FsmL(TTestRendererEvents aEventCode)
704 iFsmState = EStateCreate;
705 CreateRendererAndSurfaceL(1);
707 case EBufferAvailable:
708 iBuffAvailCallback++;
709 if (iFsmState == EStateCreate && iBuffAvailCallback == 1)
711 iFsmState = EStateUpdate;
713 // send the buffer without set background surface
715 nowTime.UniversalTime();
716 TTimeIntervalMicroSeconds delay1(500000); // use half second delay
717 TTime presentationTime1 = nowTime + delay1;
718 GetNextBufferAndSubmitUpdateL(0, KRgbGreen, presentationTime1);
720 iCallbackTimer->AtUTC(presentationTime1);
722 else if (iFsmState == EStateUpdate)
724 // buffer is available again after update
725 if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
727 // all callbacks have been received, complete test with pass
733 // unexpected state, fail test
740 // received the first callback, map surface to display
741 INFO_PRINTF1(_L("Timer expired event receibed"));
743 TInt err = SetBackgroundSurface(iSurfaceId);
744 TESTL(err == KErrNone);
746 if (iBuffAvailCallback == 2 && iBuffSkipCallback == 1)
748 // all callbacks have been received, complete test with pass
755 // expect 1 buffer skipped callback at fsm state EStateUpdate for bufferId 0
756 if (iFsmState != EStateUpdate || iBuffSkipCallback != 1 || iBufferId != 0)