Add AnimatedVectorImageVisual property
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedVectorImageVisual.cpp
index 587c7ac..534aeb6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
@@ -76,7 +76,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -86,7 +86,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
   Renderer renderer = actor.GetRendererAt( 0u );
   DALI_TEST_CHECK( renderer );
 
-  // Test SetOffStage().
+  // Test SetOffScene().
   actor.Unparent();
   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
 
@@ -109,7 +109,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -148,7 +148,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -180,7 +180,8 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
              .Add( "loopCount", 3 )
              .Add( "playRange", playRange )
              .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME )
-             .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE );
+             .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE )
+             .Add( "redrawInScalingDown", false );
 
   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
   DALI_TEST_CHECK( visual );
@@ -189,13 +190,17 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
 
+  // Trigger count is 1 - render a frame
+  DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
   // renderer is added to actor
   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+
   Renderer renderer = actor.GetRendererAt( 0u );
   DALI_TEST_CHECK( renderer );
 
@@ -228,6 +233,10 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::AUTO_REVERSE );
 
+  value = resultMap.Find( DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get< bool >() == false );
+
   actor.Unparent( );
   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
 
@@ -261,11 +270,13 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
 
+  std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
+
   Property::Map resultMap;
   resultMap = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
 
@@ -302,6 +313,10 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
   value = resultMap.Find( DevelImageVisual::Property::CONTENT_INFO, Property::MAP );
   DALI_TEST_CHECK( value );
 
+  value = resultMap.Find( DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get< bool >() == true );    // Check default value
+
   // request AnimatedVectorImageVisual with an URL
   Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() );
 
@@ -343,7 +358,7 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void)
     tet_infoline( "Test Play action" );
     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
 
-    Stage::GetCurrent().Add( dummyControl );
+    application.GetScene().Add( dummyControl );
     application.SendNotification();
     application.Render( 16 );
 
@@ -412,7 +427,7 @@ int UtcDaliAnimatedVectorImageVisualPlayback(void)
     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
 
     tet_infoline( "On stage again" );
-    Stage::GetCurrent().Add( dummyControl );
+    application.GetScene().Add( dummyControl );
 
     application.SendNotification();
     application.Render(16);
@@ -474,7 +489,7 @@ int UtcDaliAnimatedVectorImageVisualCustomShader(void)
 
   dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
   dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  Stage::GetCurrent().Add( dummy );
+  application.GetScene().Add( dummy );
 
   application.SendNotification();
   application.Render();
@@ -513,7 +528,7 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
   Vector2 controlSize( 20.f, 30.f );
   Vector2 naturalSize;
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -554,7 +569,7 @@ int UtcDaliAnimatedVectorImageVisualLoopCount(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -598,7 +613,7 @@ int UtcDaliAnimatedVectorImageVisualPlayRange(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -675,6 +690,8 @@ int UtcDaliAnimatedVectorImageVisualPlayRange(void)
   application.SendNotification();
   application.Render();
 
+  std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
+
   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
 
@@ -714,7 +731,7 @@ int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -813,7 +830,7 @@ int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -845,6 +862,8 @@ int UtcDaliAnimatedVectorImageVisualJumpTo(void)
   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
   DALI_TEST_CHECK( visual );
 
+  tet_printf( "1. Visual is created.\n" );
+
   DummyControl actor = DummyControl::New( true );
   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
@@ -852,7 +871,7 @@ int UtcDaliAnimatedVectorImageVisualJumpTo(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -862,10 +881,14 @@ int UtcDaliAnimatedVectorImageVisualJumpTo(void)
   application.SendNotification();
   application.Render();
 
+  std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
+
   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 );
 
+  tet_printf( "2. The current frame number is [%d].\n", value->Get< int >() );
+
   Property::Array array;
   array.PushBack( 0 );
   array.PushBack( 2 );
@@ -879,10 +902,14 @@ int UtcDaliAnimatedVectorImageVisualJumpTo(void)
   application.SendNotification();
   application.Render();
 
+  std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
+
   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 );
 
+  tet_printf( "3. The current frame number is [%d].\n", value->Get< int >() );
+
   // Change play range
   attributes.Clear();
   array.Clear();
@@ -913,16 +940,22 @@ int UtcDaliAnimatedVectorImageVisualJumpTo(void)
   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
   DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION );
 
+  tet_printf( "4. The current frame number is [%d].\n", value->Get< int >() );
+
   // Jump to the same position
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 );
 
   application.SendNotification();
   application.Render();
 
+  std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
+
   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 );
 
+  tet_printf( "5. The current frame number is [%d].\n", value->Get< int >() );
+
   END_TEST;
 }
 
@@ -952,7 +985,7 @@ int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -1064,7 +1097,7 @@ int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -1159,7 +1192,7 @@ int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   Property::Map attributes;
   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
@@ -1237,7 +1270,7 @@ int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
   actor.SetProperty( Actor::Property::SIZE, controlSize );
   actor.SetProperty( Actor::Property::SCALE, controlScale );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -1297,7 +1330,7 @@ int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
   Vector2 controlSize( 20.f, 30.f );
   actor1.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor1 );
+  application.GetScene().Add( actor1 );
 
   propertyMap.Clear();
   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
@@ -1312,7 +1345,7 @@ int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
 
   actor2.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor2 );
+  application.GetScene().Add( actor2 );
 
   DevelControl::DoAction( actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map() );
 
@@ -1361,7 +1394,7 @@ int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();
@@ -1408,7 +1441,7 @@ int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
   Vector2 controlSize( 20.f, 30.f );
   actor.SetProperty( Actor::Property::SIZE, controlSize );
 
-  Stage::GetCurrent().Add( actor );
+  application.GetScene().Add( actor );
 
   application.SendNotification();
   application.Render();