Asynchronous loading of Scene3D resources
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-Model.cpp
index 02393e3..5d2c344 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <toolkit-event-thread-callback.h>
 
 #include <dali-scene3d/public-api/controls/model/model.h>
 
@@ -51,6 +52,7 @@ const char* TEST_GLTF_FILE_NAME                    = TEST_RESOURCE_DIR "/Animate
 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME     = TEST_RESOURCE_DIR "/animationTest.gltf";
 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
 const char* TEST_DLI_FILE_NAME                     = TEST_RESOURCE_DIR "/arc.dli";
+const char* TEST_DLI_EXERCISE_FILE_NAME            = TEST_RESOURCE_DIR "/exercise.dli";
 /**
  * For the diffuse and specular cube map texture.
  * These textures are based off version of Wave engine sample
@@ -92,6 +94,19 @@ void TestFocusChangedCallback(Actor, Actor)
   gFocusChangedCallBackCalled = true;
 }
 
+// For ResourceReady
+static bool gOnRelayoutCallBackCalled = false;
+void        OnRelayoutCallback(Actor actor)
+{
+  gOnRelayoutCallBackCalled = true;
+}
+
+static bool gResourceReadyCalled = false;
+void        OnResourceReady(Control control)
+{
+  gResourceReadyCalled = true;
+}
+
 } // namespace
 
 // Negative test case for a method
@@ -250,15 +265,23 @@ int UtcDaliModelOnScene01(void)
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   uint32_t modelCount = model.GetModelRoot().GetChildCount();
   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
-
   END_TEST;
 }
 
@@ -267,12 +290,21 @@ int UtcDaliModelOnScene02(void)
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   uint32_t modelCount = model.GetModelRoot().GetChildCount();
   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
 
@@ -312,7 +344,20 @@ int UtcDaliModelGetNaturalSize(void)
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
 
   Vector3 naturalSize = model.GetNaturalSize();
+  DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
+
+  application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  naturalSize = model.GetNaturalSize();
   DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
 
   Actor root = model.GetModelRoot();
@@ -326,12 +371,21 @@ int UtcDaliModelSetImageBasedLightSource01(void)
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = model.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -344,14 +398,27 @@ int UtcDaliModelSetImageBasedLightSource01(void)
   Texture diffuseTexture  = textureSet.GetTexture(7u);
   Texture specularTexture = textureSet.GetTexture(8u);
 
+  gResourceReadyCalled = false;
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
   model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
 
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
   Texture newSpecularTexture = textureSet.GetTexture(8u);
 
   DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
   DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
 
+  model.Unparent();
+  model.Reset();
   END_TEST;
 }
 
@@ -360,12 +427,21 @@ int UtcDaliModelSetImageBasedLightSource02(void)
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = model.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -378,6 +454,7 @@ int UtcDaliModelSetImageBasedLightSource02(void)
   Texture diffuseTexture  = textureSet.GetTexture(7u);
   Texture specularTexture = textureSet.GetTexture(8u);
 
+  // if url is empty, loading is not requested.
   model.SetImageBasedLightSource("", "");
 
   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
@@ -394,12 +471,21 @@ int UtcDaliModelSetImageBasedLightSource03(void)
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = model.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -412,8 +498,19 @@ int UtcDaliModelSetImageBasedLightSource03(void)
   Texture diffuseTexture  = textureSet.GetTexture(7u);
   Texture specularTexture = textureSet.GetTexture(8u);
 
+  gResourceReadyCalled = false;
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
   model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
 
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
   Texture newSpecularTexture = textureSet.GetTexture(8u);
 
@@ -423,6 +520,29 @@ int UtcDaliModelSetImageBasedLightSource03(void)
   END_TEST;
 }
 
+int UtcDaliModelSetImageBasedLightSource04(void)
+{
+  ToolkitTestApplication application;
+
+  Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+  model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
+  application.GetScene().Add(model);
+
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+  END_TEST;
+}
+
 int UtcDaliModelImageBasedFactor(void)
 {
   ToolkitTestApplication application;
@@ -452,12 +572,21 @@ int UtcDaliModelChildrenSensitive01(void)
   // Allow children actor's event before on scene.
   view.SetChildrenSensitive(true);
   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
-
   application.GetScene().Add(view);
 
+  gResourceReadyCalled = false;
+  view.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = view.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -540,12 +669,21 @@ int UtcDaliModelChildrenSensitive02(void)
   // Block children actor's event before on scene.
   view.SetChildrenSensitive(false);
   DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
-
   application.GetScene().Add(view);
 
+  gResourceReadyCalled = false;
+  view.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = view.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -611,12 +749,21 @@ int UtcDaliModelChildrenFocusable01(void)
   // Allow children actor's focus before on scene.
   view.SetChildrenFocusable(true);
   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
-
   application.GetScene().Add(view);
 
+  gResourceReadyCalled = false;
+  view.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = view.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -710,12 +857,21 @@ int UtcDaliModelModelChildrenFocusable02(void)
   // Block children actor's focus before on scene.
   view.SetChildrenFocusable(false);
   DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
-
   application.GetScene().Add(view);
 
+  gResourceReadyCalled = false;
+  view.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   Actor meshActor = view.FindChildByName("AnimatedCube");
   DALI_TEST_CHECK(meshActor);
 
@@ -782,12 +938,21 @@ int UtcDaliModelAnimation01(void)
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
   uint32_t animationCount = model.GetAnimationCount();
   DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
 
@@ -807,9 +972,16 @@ int UtcDaliModelAnimation02(void)
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
@@ -829,15 +1001,56 @@ int UtcDaliModelAnimation02(void)
   END_TEST;
 }
 
+int UtcDaliModelAnimation03(void)
+{
+  ToolkitTestApplication application;
+
+  Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
+  model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
+  application.GetScene().Add(model);
+
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  uint32_t animationCount = model.GetAnimationCount();
+  DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
+
+  Animation animationByIndex = model.GetAnimation(0u);
+  DALI_TEST_CHECK(animationByIndex);
+
+  Animation animationByName = model.GetAnimation("idleClip");
+  DALI_TEST_CHECK(animationByName);
+  DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliModelMultiplePrimitives(void)
 {
   ToolkitTestApplication application;
 
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
@@ -856,9 +1069,16 @@ int UtcDaliModelColorMode(void)
   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
   model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
-
   application.GetScene().Add(model);
 
+  gResourceReadyCalled = false;
+  model.ResourceReadySignal().Connect(&OnResourceReady);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
   application.SendNotification();
   application.Render();
 
@@ -871,23 +1091,6 @@ int UtcDaliModelColorMode(void)
 
   END_TEST;
 }
-
-// For ResourceReady
-namespace
-{
-static bool gOnRelayoutCallBackCalled = false;
-void        OnRelayoutCallback(Actor actor)
-{
-  gOnRelayoutCallBackCalled = true;
-}
-
-static bool gResourceReadyCalled = false;
-void        OnResourceReady(Control control)
-{
-  gResourceReadyCalled = true;
-}
-} // namespace
-
 int UtcDaliModelResourceReady(void)
 {
   ToolkitTestApplication application;
@@ -909,6 +1112,10 @@ int UtcDaliModelResourceReady(void)
   application.SendNotification();
   application.Render();
 
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
   DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);