X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-AnimatedVectorImageVisual.cpp;h=20ee4d786b622e77de4c1fd67cf4366a5bf8d63b;hb=refs%2Fchanges%2F32%2F210132%2F4;hp=c0fee4158fd5d3932ec8d2e1339e33fb2e8d10d7;hpb=88164ac28facfc414392d99ff5d1cbcd4f9e9d2c;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index c0fee41..20ee4d7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include #include @@ -25,6 +27,7 @@ #include #include #include +#include #include "dummy-control.h" using namespace Dali; @@ -45,6 +48,16 @@ namespace const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json"; +bool gAnimationFinishedSignalFired = false; + +void VisualEventSignal( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId ) +{ + if( visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED ) + { + gAnimationFinishedSignalFired = true; + } +} + } int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void) @@ -120,11 +133,16 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void) ToolkitTestApplication application; tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map" ); + int startFrame = 1, endFrame = 3; + Property::Array playRange; + playRange.PushBack( startFrame ); + playRange.PushBack( endFrame ); + Property::Map propertyMap; propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, Vector2( 0.2f, 0.8f ) ); + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -157,11 +175,18 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) ToolkitTestApplication application; tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map" ); + int startFrame = 1, endFrame = 3; + Property::Array playRange; + playRange.PushBack( startFrame ); + playRange.PushBack( endFrame ); + Property::Map propertyMap; propertyMap.Add( "visualType", DevelVisual::ANIMATED_VECTOR_IMAGE ) - .Add( "url", TEST_VECTOR_IMAGE_FILE_NAME ) - .Add( "loopCount", 3 ) - .Add( "playRange", Vector2( 0.2f, 0.8f ) ); + .Add( "url", TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( "loopCount", 3 ) + .Add( "playRange", playRange ) + .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME ) + .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -183,6 +208,35 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) Renderer renderer = actor.GetRendererAt( 0u ); DALI_TEST_CHECK( renderer ); + Property::Map resultMap; + visual.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from a visual + Property::Value* value = resultMap.Find( ImageVisual::Property::URL, Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< std::string >() == TEST_VECTOR_IMAGE_FILE_NAME ); + + value = resultMap.Find( DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == 3 ); + + value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY ); + DALI_TEST_CHECK( value ); + + Property::Array* result = value->GetArray(); + DALI_TEST_CHECK( result ); + + DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame ); + DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame ); + + value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::FIRST_FRAME ); + + value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::AUTO_REVERSE ); + actor.Unparent( ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -194,13 +248,16 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) ToolkitTestApplication application; tet_infoline( "UtcDaliAnimatedVectorImageVisualGetPropertyMap01" ); - Vector2 playRange( 0.2f, 0.8f ); + int startFrame = 1, endFrame = 3; + Property::Array playRange; + playRange.PushBack( startFrame ); + playRange.PushBack( endFrame ); Property::Map propertyMap; propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) - .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) - .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); // request AnimatedVectorImageVisual with a property map VisualFactory factory = VisualFactory::Get(); @@ -222,9 +279,22 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get< int >() == 3 ); - value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::VECTOR2 ); + value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY ); DALI_TEST_CHECK( value ); - DALI_TEST_CHECK( value->Get< Vector2 >() == playRange ); + + Property::Array* result = value->GetArray(); + DALI_TEST_CHECK( result ); + + DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame ); + DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame ); + + value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::CURRENT_FRAME ); + + value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::RESTART ); // request AnimatedVectorImageVisual with an URL Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() ); @@ -271,9 +341,13 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void) application.SendNotification(); application.Render( 16 ); + std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); // wait for one animation loop (16fps, 5frames, need 80ms) + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); - // test + Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); tet_infoline( "Test Pause action" ); DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes ); @@ -281,15 +355,21 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void) application.SendNotification(); application.Render(16); - // test + std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) ); // wait for next rasterize thread run - tet_infoline( "Test Resume action" ); - DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::RESUME, attributes ); + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED ); + + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); application.SendNotification(); application.Render(16); - // test + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); tet_infoline( "Test Stop action" ); DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); @@ -297,7 +377,9 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void) application.SendNotification(); application.Render(16); - // test + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); tet_infoline( "Test Stop action again" ); DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); @@ -305,7 +387,9 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void) application.SendNotification(); application.Render(16); - // test + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); tet_infoline( "Test Play action" ); DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); @@ -313,15 +397,50 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void) application.SendNotification(); application.Render(16); - // test + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); - dummyControl.SetSize( 100.0f, 100.0f ); + tet_infoline( "Off stage" ); + dummyControl.Unparent(); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED ); + + tet_infoline( "On stage again" ); + Stage::GetCurrent().Add( dummyControl ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED ); + + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); + + // Change Size + Vector3 newSize( 100.0f, 100.0f, 0.0f ); + dummyControl.SetSize( newSize ); application.SendNotification(); application.Render(16); - // test // Size should be changed + Vector3 naturalSize = dummyControl.GetNaturalSize(); + DALI_TEST_CHECK( naturalSize == newSize ); dummyControl.Unparent(); } @@ -396,7 +515,6 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void) Vector2 controlSize( 20.f, 30.f ); Vector2 naturalSize; - actor.SetSize( controlSize ); Stage::GetCurrent().Add( actor ); application.SendNotification(); @@ -406,6 +524,17 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void) visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( 100.0f, 100.0f ), TEST_LOCATION ); // 100x100 is the content default size. + + actor.SetSize( controlSize ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, controlSize, TEST_LOCATION ); END_TEST; @@ -439,7 +568,8 @@ int UtcDaliAnimatedVectorImageVisualLoopCount(void) application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + // Trigger count is 2 - resource ready and animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); // renderer is added to actor DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); @@ -454,12 +584,15 @@ int UtcDaliAnimatedVectorImageVisualPlayRange(void) ToolkitTestApplication application; tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayRange" ); - Vector2 playRange( 0.8f, 0.2f ); + int startFrame = 3, endFrame = 1; + Property::Array array; + array.PushBack( startFrame ); + array.PushBack( endFrame ); Property::Map propertyMap; propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( DevelImageVisual::Property::PLAY_RANGE, array ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -486,5 +619,431 @@ int UtcDaliAnimatedVectorImageVisualPlayRange(void) Renderer renderer = actor.GetRendererAt( 0u ); DALI_TEST_CHECK( renderer ); + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_RANGE ); + + int resultStartFrame, resultEndFrame; + Property::Array* result = value->GetArray(); + result->GetElementAt( 0 ).Get( resultStartFrame ); + result->GetElementAt( 1 ).Get( resultEndFrame ); + + DALI_TEST_EQUALS( startFrame, resultStartFrame, TEST_LOCATION ); + DALI_TEST_EQUALS( endFrame, resultEndFrame, TEST_LOCATION ); + + // Set invalid play range + array.Clear(); + array.PushBack( -1 ); + array.PushBack( 100 ); + + attributes.Clear(); + attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array ); + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_RANGE ); + + result = value->GetArray(); + result->GetElementAt( 0 ).Get( resultStartFrame ); + result->GetElementAt( 1 ).Get( resultEndFrame ); + + DALI_TEST_EQUALS( startFrame, resultStartFrame, TEST_LOCATION ); // Should not be changed + DALI_TEST_EQUALS( endFrame, resultEndFrame, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal" ); + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + DevelControl::VisualEventSignal( actor ).Connect( &VisualEventSignal ); + + Vector2 controlSize( 20.f, 30.f ); + actor.SetSize( controlSize ); + + Stage::GetCurrent().Add( actor ); + + Property::Map attributes; + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Wait for animation finish + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); + + DALI_TEST_EQUALS( gAnimationFinishedSignalFired, true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualJumpTo(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualJumpTo" ); + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + Vector2 controlSize( 20.f, 30.f ); + actor.SetSize( controlSize ); + + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2 ); + + application.SendNotification(); + application.Render(); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 2, TEST_LOCATION ); + + Property::Array array; + array.PushBack( 0 ); + array.PushBack( 2 ); + + Property::Map attributes; + attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array ); + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 2, TEST_LOCATION ); + + // Change play range + attributes.Clear(); + array.Clear(); + + array.PushBack( 0 ); + array.PushBack( 4 ); + + attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array ); + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + attributes.Clear(); + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Stop and jump to 3 + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualUpdateProperty(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualJumpToCurrentProgress" ); + + int startFrame = 1, endFrame = 3; + Property::Array playRange; + playRange.PushBack( startFrame ); + playRange.PushBack( endFrame ); + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + Vector2 controlSize( 20.f, 30.f ); + actor.SetSize( controlSize ); + + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::LOOP_COUNT ); + DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION ); + + value = map.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY ); + DALI_TEST_CHECK( value ); + + Property::Array* result = value->GetArray(); + DALI_TEST_CHECK( result ); + + DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame ); + DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame ); + + playRange.Clear(); + playRange.PushBack( 0 ); + playRange.PushBack( 2 ); + + Property::Map attributes; + attributes.Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + attributes.Add( DevelImageVisual::Property::LOOP_COUNT, 5 ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::LOOP_COUNT ); + DALI_TEST_EQUALS( value->Get< int >(), 5, TEST_LOCATION ); + + value = map.Find( DevelImageVisual::Property::PLAY_RANGE ); + result = value->GetArray(); + DALI_TEST_CHECK( result ); + + DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == 0 ); + DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == 2 ); + + attributes.Clear(); + + playRange.Clear(); + playRange.PushBack( startFrame ); + playRange.PushBack( endFrame ); + + attributes.Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_RANGE ); + + result = value->GetArray(); + DALI_TEST_CHECK( result ); + + DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame ); + DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame ); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualStopBehavior(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualStopBehavior" ); + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) + .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + Vector2 controlSize( 20.f, 30.f ); + actor.SetSize( controlSize ); + + Stage::GetCurrent().Add( actor ); + + Property::Map attributes; + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - resource ready and animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame + + // Change stop behavior + attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + attributes.Clear(); + + // Play again + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Trigger count is 1 - animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + + Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER ); + int totalFrameNumber = value1->Get< int >(); + + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION ); // Should be the last frame + + // Change stop behavior + attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME ); + attributes.Add( DevelImageVisual::Property::LOOP_COUNT, -1 ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + attributes.Clear(); + + // Play again + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Pause + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes ); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + int currentFrameNumber = value->Get< int >(); + + // Stop + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); + + // Trigger count is 1 - animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), currentFrameNumber, TEST_LOCATION ); // Should be same with currentFrameNumber + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualLoopingMode(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualLoopingMode" ); + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) + .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) + .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME ) + .Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + Vector2 controlSize( 20.f, 30.f ); + actor.SetSize( controlSize ); + + Stage::GetCurrent().Add( actor ); + + Property::Map attributes; + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - resource ready and animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame because of auto reverse + + // Change stop behavior + attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + // Play again + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Trigger count is 1 - animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION ); // Should be the first frame + + // Change looping mode + attributes.Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes ); + + // Play again + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(); + + // Trigger count is 1 - animation finished + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER ); + int totalFrameNumber = value1->Get< int >(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER ); + DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION ); // Should be the last frame + END_TEST; }