X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-VideoView.cpp;h=b0aa75ef3225a00d1fa7fd67ca5754e33c125c87;hp=8baed37239e00eca77284ce4d8e517d3341cf549;hb=7b49f95b6d22be04ef9a3320eaaae7dc3e63ec46;hpb=48d13d45cb7f363d3cf8da048ce6cef074c55060 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp index 8baed37..b0aa75e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ #include #include #include +#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -30,6 +32,7 @@ const char* const TEST_FILE( "test.mp4" ); const char* const VOLUME_LEFT( "volumeLeft" ); const char* const VOLUME_RIGHT( "volumeRight" ); const char* const RENDERING_TYPE( "renderingTarget" ); +const char* const DUMMY_STRING( "dummy string" ); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n @@ -48,9 +51,10 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( }\n ); +const char* fragmentShaderPrefix( "#extension GL_OES_EGL_image_external:require\n" ); const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n + uniform samplerExternalOES sTexture;\n uniform lowp vec4 uColor;\n \n void main()\n @@ -104,7 +108,8 @@ int UtcDaliVideoViewNew(void) Toolkit::VideoView view = Toolkit::VideoView::New(); DALI_TEST_CHECK( view ); - Toolkit::VideoView view2 = Toolkit::VideoView::New( "" ); + const std::string url( DUMMY_STRING ); + Toolkit::VideoView view2 = Toolkit::VideoView::New( url ); DALI_TEST_CHECK( view2 ); END_TEST; } @@ -150,7 +155,7 @@ int UtcDaliVideoViewProperty1b(void) Toolkit::VideoView view = Toolkit::VideoView::New(); DALI_TEST_CHECK( view ); - Stage stage = Stage::GetCurrent(); + Integration::Scene stage = application.GetScene(); std::string file; Property::Map map; @@ -269,6 +274,43 @@ int UtcDaliVideoViewCopyAndAssignment(void) END_TEST; } +int UtcDaliVideoViewMoveConstructor(void) +{ + ToolkitTestApplication application; + + VideoView view = Toolkit::VideoView::New(); + DALI_TEST_EQUALS( 1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + view.SetProperty( VideoView::Property::LOOPING, true ); + DALI_TEST_CHECK( view.GetProperty( VideoView::Property::LOOPING ) ); + + VideoView moved = std::move( view ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( moved.GetProperty( VideoView::Property::LOOPING ) ); + DALI_TEST_CHECK( !view ); + + END_TEST; +} + +int UtcDaliVideoViewMoveAssignment(void) +{ + ToolkitTestApplication application; + + VideoView view = Toolkit::VideoView::New(); + DALI_TEST_EQUALS( 1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + view.SetProperty( VideoView::Property::LOOPING, true ); + DALI_TEST_CHECK( view.GetProperty( VideoView::Property::LOOPING ) ); + + VideoView moved; + moved = std::move( view ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( moved.GetProperty( VideoView::Property::LOOPING ) ); + DALI_TEST_CHECK( !view ); + + END_TEST; +} + int UtcDaliVideoViewTypeRegistry(void) { ToolkitTestApplication application; @@ -300,6 +342,9 @@ int UtcDaliVideoViewMethodsForCoverage(void) videoView.Stop(); videoView.Forward(10); videoView.Backward(10); + + Toolkit::DevelVideoView::GetMediaPlayer( videoView ); + VideoView::VideoViewSignalType& signal = videoView.FinishedSignal(); DALI_TEST_EQUALS( 0, signal.GetConnectionCount(), TEST_LOCATION ); @@ -347,7 +392,13 @@ int UtcDaliVideoViewCustomShaderForCoverage(void) VideoView videoView = VideoView::New(); DALI_TEST_CHECK( videoView ); - Stage::GetCurrent().Add( videoView ); + ToolkitApplication::DECODED_IMAGES_SUPPORTED = true; + + videoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false ); + bool isUnderlay = videoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >(); + DALI_TEST_CHECK( !isUnderlay ); + + application.GetScene().Add( videoView ); videoView.SetProperty( VideoView::Property::VIDEO, "testvideo" ); Property::Map customShader; @@ -376,7 +427,7 @@ int UtcDaliVideoViewMethodsForCoverage2(void) windowSurfaceTarget.Insert( RENDERING_TYPE, "windowSurfaceTarget" ); - Stage::GetCurrent().Add( videoView ); + application.GetScene().Add( videoView ); application.SendNotification(); application.Render(); @@ -394,14 +445,14 @@ int UtcDaliVideoViewMethodsForCoverage2(void) Vector3 vector(100.0f, 100.0f, 0.0f); - DALI_TEST_CHECK(vector != videoView.GetCurrentSize()); - videoView.SetSize( vector ); + DALI_TEST_CHECK(vector != videoView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE )); + videoView.SetProperty( Actor::Property::SIZE, vector ); application.SendNotification(); application.Render(); // Check the size in the new frame - DALI_TEST_CHECK(vector == videoView.GetCurrentSize()); + DALI_TEST_CHECK(vector == videoView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE )); END_TEST; } @@ -409,12 +460,13 @@ int UtcDaliVideoViewMethodsForCoverage2(void) int UtcDaliVideoViewPropertyUnderlay(void) { ToolkitTestApplication application; + tet_infoline("UtcDaliVideoViewPropertyUnderlay"); ToolkitApplication::DECODED_IMAGES_SUPPORTED = true; VideoView view = VideoView::New(); DALI_TEST_CHECK( view ); - Stage::GetCurrent().Add( view ); + application.GetScene().Add( view ); view.Play(); application.SendNotification(); @@ -453,3 +505,285 @@ int UtcDaliVideoViewPropertyUnderlay(void) END_TEST; } + +int UtcDaliVideoViewPropertyPlayPosition(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliVideoViewPropertyPlayPosition"); + + VideoView view = VideoView::New(); + DALI_TEST_CHECK( view ); + + application.GetScene().Add( view ); + view.Play(); + + application.SendNotification(); + application.Render(); + + int playPos = view.GetProperty( Toolkit::VideoView::Property::PLAY_POSITION ).Get< int >(); + DALI_TEST_CHECK( playPos == 0 ); + + view.SetProperty( Toolkit::VideoView::Property::PLAY_POSITION, 10 ); + playPos = view.GetProperty( Toolkit::VideoView::Property::PLAY_POSITION ).Get< int >(); + // Actually setting play position will be async + // Actual platform result may be different. + DALI_TEST_CHECK( playPos == 10 ); + + END_TEST; +} + +// For coverage. +int UtcDaliVideoViewNew2(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliVideoViewNew2"); + + VideoView view = VideoView::New( true ); + DALI_TEST_CHECK( view ); + + application.GetScene().Add( view ); + view.Play(); + + application.SendNotification(); + application.Render(); + + VideoView view2 = VideoView::New( "", false ); + DALI_TEST_CHECK( view2 ); + + application.GetScene().Add( view2 ); + view2.Play(); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcDaliVideoViewPropertyDisplayMode(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliVideoViewPropertyDisplayMode"); + + VideoView view = VideoView::New(); + DALI_TEST_CHECK( view ); + + application.GetScene().Add( view ); + view.Play(); + + application.SendNotification(); + application.Render(); + + view.SetProperty( Toolkit::VideoView::Property::DISPLAY_MODE, Toolkit::VideoView::DisplayMode::DST_ROI ); + int displayMode = view.GetProperty( Toolkit::VideoView::Property::DISPLAY_MODE ).Get< int >(); + DALI_TEST_CHECK( displayMode == Toolkit::VideoView::DisplayMode::DST_ROI ); + + END_TEST; +} + + +int UtcDaliVideoViewCustomShader(void) +{ + ToolkitTestApplication application; + tet_infoline( "VideoView with custom shader" ); + + VideoView view = VideoView::New( false ); + DALI_TEST_CHECK( view ); + + ToolkitApplication::DECODED_IMAGES_SUPPORTED = true; + + view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false ); + bool isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >(); + DALI_TEST_CHECK( !isUnderlay ); + + application.GetScene().Add( view ); + view.SetProperty( VideoView::Property::VIDEO, "testvideo" ); + + /* insert custom shader */ + Property::Map customShader; + std::string fragmentShaderString; + fragmentShaderString.reserve( strlen( fragmentShaderPrefix ) + strlen( FRAGMENT_SHADER ) ); + fragmentShaderString.append( fragmentShaderPrefix ); + fragmentShaderString.append( FRAGMENT_SHADER ); + customShader.Insert( "vertexShader", VERTEX_SHADER ); + customShader.Insert( "fragmentShader", fragmentShaderString ); + + Property::Map map; + map.Insert( "shader", customShader ); + + view.SetProperty( VideoView::Property::VIDEO, map ); + + /* do render for check custom shader */ + application.GetScene().Add( view ); + view.Play(); + + application.SendNotification(); + application.Render(); + + /* get renderer */ + DALI_TEST_CHECK( view.GetRendererCount() == 1u ); + Renderer renderer = view.GetRendererAt( 0 ); + Shader shader = renderer.GetShader(); + DALI_TEST_CHECK( shader ); + + Property::Value value = shader.GetProperty(Shader::Property::PROGRAM); + Property::Map* shaderMap = value.GetMap(); + DALI_TEST_CHECK( shaderMap ); + + Property::Value* fragment = shaderMap->Find( "fragment" ); // fragment key name from shader-impl.cpp + DALI_TEST_EQUALS( fragmentShaderString, fragment->Get(), TEST_LOCATION ); + + Property::Value* vertex = shaderMap->Find( "vertex" ); // vertex key name from shader-impl.cpp + DALI_TEST_EQUALS( VERTEX_SHADER, vertex->Get(), TEST_LOCATION ); + + END_TEST; +} + +// Functor to test whether a Finish signal is emitted +struct AnimationFinishCheck +{ + AnimationFinishCheck(bool& signalReceived) + : mSignalReceived(signalReceived) + { + } + + void operator()(Animation& animation) + { + mSignalReceived = true; + } + + void Reset() + { + mSignalReceived = false; + } + + void CheckSignalReceived() + { + if (!mSignalReceived) + { + tet_printf("Expected Finish signal was not received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + void CheckSignalNotReceived() + { + if (mSignalReceived) + { + tet_printf("Unexpected Finish signal was received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + bool& mSignalReceived; // owned by individual tests +}; + +int UtcDaliVideoViewSyncAniamtionForCoverage(void) +{ + ToolkitTestApplication application; + + VideoView videoView = DevelVideoView::New( Dali::VideoSyncMode::ENABLED ); + DALI_TEST_CHECK( videoView ); + + application.GetScene().Add( videoView ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + + // Start the animation + Vector3 targetPosition(10.0f, 10.0f, 10.0f); + animation.AnimateTo(Property(videoView, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR); + DevelVideoView::PlayAnimation( videoView, animation ); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*1000.0f) - 1u/*just less than the animation duration*/); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + application.Render(2u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( targetPosition, videoView.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION ); + + // Restart the animation, with a different duration + finishCheck.Reset(); + + END_TEST; +} + +int UtcDaliVideoViewASyncAniamtionForCoverage(void) +{ + ToolkitTestApplication application; + + VideoView videoView = DevelVideoView::New( Dali::VideoSyncMode::DISABLED ); + DALI_TEST_CHECK( videoView ); + + application.GetScene().Add( videoView ); + + // Build the animation + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); + + // Start the animation + Vector3 targetPosition(10.0f, 10.0f, 10.0f); + animation.AnimateTo(Property(videoView, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR); + DevelVideoView::PlayAnimation( videoView, animation ); + + bool signalReceived(false); + AnimationFinishCheck finishCheck(signalReceived); + animation.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(static_cast(durationSeconds*1000.0f) - 1u/*just less than the animation duration*/); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + application.Render(2u/*just beyond the animation duration*/); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( targetPosition, videoView.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION ); + + // Restart the animation, with a different duration + finishCheck.Reset(); + + END_TEST; +} + +int UtcDaliVideoViewResizeWithSynchronization(void) +{ + ToolkitTestApplication application; + VideoView videoView = DevelVideoView::New( Dali::VideoSyncMode::ENABLED ); + DALI_TEST_CHECK( videoView ); + + application.GetScene().Add( videoView ); + + Vector3 vector(50.0f, 200.0f, 0.0f); + videoView.SetProperty( Actor::Property::SIZE, vector ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(vector == videoView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE )); + + END_TEST; +}