Revert "[Tizen] Update RenderState in PreRender"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-GestureDetector.cpp
index 42fad1e..f53121b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
  *
  */
 
-#include <iostream>
-
+#include <dali-test-suite-utils.h>
+#include <dali/public-api/dali-core.h>
 #include <stdlib.h>
+
 #include <algorithm>
-#include <dali/public-api/dali-core.h>
-#include <dali-test-suite-utils.h>
+#include <iostream>
 
 using namespace Dali;
-using namespace std;
 
 void utc_dali_gesture_detector_startup(void)
 {
@@ -35,8 +34,7 @@ void utc_dali_gesture_detector_cleanup(void)
   test_return_value = TET_PASS;
 }
 
-
-int UtcDaliGestureDetectorConstructorNegative(void)
+int UtcDaliGestureDetectorConstructorN(void)
 {
   TestApplication application;
 
@@ -49,17 +47,14 @@ int UtcDaliGestureDetectorConstructorNegative(void)
     detector.Attach(actor);
     tet_result(TET_FAIL);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
-    if ( exception.mCondition.find("detector") != string::npos )
-    {
-      tet_result(TET_PASS);
-    }
+    DALI_TEST_ASSERT(e, "detector", TEST_LOCATION);
   }
   END_TEST;
 }
 
-int UtcDaliGestureDetectorConstructorPositive(void)
+int UtcDaliGestureDetectorConstructorP(void)
 {
   TestApplication application;
 
@@ -73,14 +68,40 @@ int UtcDaliGestureDetectorConstructorPositive(void)
     detector.Attach(actor);
     tet_result(TET_PASS);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
+  {
+    DALI_TEST_PRINT_ASSERT(e);
+    tet_result(TET_FAIL);
+  }
+  END_TEST;
+}
+
+int UtcDaliGestureDetectorAssignP(void)
+{
+  TestApplication application;
+
+  // Use pan gesture as GestureDetector cannot be created.
+  GestureDetector detector = PanGestureDetector::New();
+  GestureDetector detector2;
+
+  detector2 = detector;
+
+  Actor actor = Actor::New();
+
+  try
+  {
+    detector2.Attach(actor);
+    tet_result(TET_PASS);
+  }
+  catch(DaliException& e)
   {
+    DALI_TEST_PRINT_ASSERT(e);
     tet_result(TET_FAIL);
   }
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDownCast(void)
+int UtcDaliGestureDetectorDownCastP(void)
 {
   TestApplication application;
   tet_infoline("Testing Dali::GestureDetector::DownCast()");
@@ -92,19 +113,19 @@ int UtcDaliGestureDetectorDownCast(void)
   GestureDetector detector2 = GestureDetector::DownCast(object);
   DALI_TEST_CHECK(detector2);
 
-  GestureDetector detector3 = DownCast< GestureDetector >(object);
+  GestureDetector detector3 = DownCast<GestureDetector>(object);
   DALI_TEST_CHECK(detector3);
 
-  BaseHandle unInitializedObject;
+  BaseHandle      unInitializedObject;
   GestureDetector detector4 = GestureDetector::DownCast(unInitializedObject);
   DALI_TEST_CHECK(!detector4);
 
-  GestureDetector detector5 = DownCast< GestureDetector >(unInitializedObject);
+  GestureDetector detector5 = DownCast<GestureDetector>(unInitializedObject);
   DALI_TEST_CHECK(!detector5);
   END_TEST;
 }
 
-int UtcDaliGestureDetectorAttachPositive(void)
+int UtcDaliGestureDetectorAttachP(void)
 {
   TestApplication application;
 
@@ -115,13 +136,17 @@ int UtcDaliGestureDetectorAttachPositive(void)
 
   detector.Attach(actor);
 
-  vector<Actor> actors = detector.GetAttachedActors();
-
-  if (find(actors.begin(), actors.end(), actor) != actors.end())
+  bool found = false;
+  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
   {
-    tet_result(TET_PASS);
+    if(detector.GetAttachedActor(i) == actor)
+    {
+      tet_result(TET_PASS);
+      found = true;
+    }
   }
-  else
+
+  if(!found)
   {
     tet_result(TET_FAIL);
   }
@@ -137,7 +162,7 @@ int UtcDaliGestureDetectorAttachPositive(void)
   END_TEST;
 }
 
-int UtcDaliGestureDetectorAttachNegative(void)
+int UtcDaliGestureDetectorAttachN(void)
 {
   TestApplication application;
 
@@ -152,17 +177,14 @@ int UtcDaliGestureDetectorAttachNegative(void)
     detector.Attach(actor);
     tet_result(TET_FAIL);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
-    if ( exception.mCondition.find("actor") != string::npos )
-    {
-      tet_result(TET_PASS);
-    }
+    DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
   }
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachPositive(void)
+int UtcDaliGestureDetectorDetachP(void)
 {
   TestApplication application;
 
@@ -171,33 +193,47 @@ int UtcDaliGestureDetectorDetachPositive(void)
 
   Actor actor = Actor::New();
   detector.Attach(actor);
-  vector<Actor> actors = detector.GetAttachedActors();
 
-  if (find(actors.begin(), actors.end(), actor) != actors.end())
+  bool found = false;
+  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
   {
-    tet_result(TET_PASS);
+    if(detector.GetAttachedActor(i) == actor)
+    {
+      tet_result(TET_PASS);
+      found = true;
+    }
   }
-  else
+
+  if(!found)
   {
     tet_result(TET_FAIL);
   }
 
-  // Detach and retrive attached actors again, the vector should be empty.
+  // Detach and retrieve attached actors again, the vector should be empty.
   detector.Detach(actor);
 
-  actors = detector.GetAttachedActors();
-  if (actors.empty())
+  found = false;
+  for(size_t i = 0; i < detector.GetAttachedActorCount(); i++)
   {
-    tet_result(TET_PASS);
+    if(detector.GetAttachedActor(i) == actor)
+    {
+      found = true;
+    }
   }
-  else
+
+  if(found)
   {
     tet_result(TET_FAIL);
   }
+  else
+  {
+    tet_result(TET_PASS);
+  }
+
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachNegative01(void)
+int UtcDaliGestureDetectorDetachN01(void)
 {
   TestApplication application;
 
@@ -212,17 +248,14 @@ int UtcDaliGestureDetectorDetachNegative01(void)
     detector.Detach(actor);
     tet_result(TET_FAIL);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
-    if ( exception.mCondition.find("actor") != string::npos )
-    {
-      tet_result(TET_PASS);
-    }
+    DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
   }
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachNegative02(void)
+int UtcDaliGestureDetectorDetachN02(void)
 {
   TestApplication application;
 
@@ -239,17 +272,17 @@ int UtcDaliGestureDetectorDetachNegative02(void)
     detector.Detach(actor2);
     tet_result(TET_PASS);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
+    DALI_TEST_PRINT_ASSERT(e);
     tet_result(TET_FAIL);
   }
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachNegative03(void)
+int UtcDaliGestureDetectorDetachN03(void)
 {
   TestApplication application;
-  TestGestureManager& gestureManager = application.GetGestureManager();
 
   // Use pan gesture as GestureDetector cannot be created.
   GestureDetector detector = PanGestureDetector::New();
@@ -257,24 +290,26 @@ int UtcDaliGestureDetectorDetachNegative03(void)
   Actor actor = Actor::New();
   detector.Attach(actor);
 
+  DALI_TEST_EQUALS(1, detector.GetAttachedActorCount(), TEST_LOCATION);
+
   // Detach an actor twice - no exception should happen.
   try
   {
     detector.Detach(actor);
-    DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
-
-    gestureManager.Initialize(); // Reset values
     detector.Detach(actor);
-    DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
+    DALI_TEST_PRINT_ASSERT(e);
     tet_result(TET_FAIL);
   }
+
+  DALI_TEST_EQUALS(0, detector.GetAttachedActorCount(), TEST_LOCATION);
+
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachAll(void)
+int UtcDaliGestureDetectorDetachAllP(void)
 {
   TestApplication application;
 
@@ -282,63 +317,56 @@ int UtcDaliGestureDetectorDetachAll(void)
   GestureDetector detector = PanGestureDetector::New();
 
   const unsigned int actorsToAdd = 5;
-  vector<Actor> myActors;
+  std::vector<Actor> myActors;
 
-  for (unsigned int i = 0; i < actorsToAdd; ++i)
+  for(unsigned int i = 0; i < actorsToAdd; ++i)
   {
     Actor actor = Actor::New();
     myActors.push_back(actor);
     detector.Attach(actor);
   }
 
-  vector<Actor> attachedActors = detector.GetAttachedActors();
-  DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach and retrieve attached actors again, the vector should be empty.
   detector.DetachAll();
 
-  attachedActors = detector.GetAttachedActors();
-  DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
   END_TEST;
 }
 
-int UtcDaliGestureDetectorDetachAllNegative(void)
+int UtcDaliGestureDetectorDetachAllN(void)
 {
   TestApplication application;
-  TestGestureManager& gestureManager = application.GetGestureManager();
 
   // Use pan gesture as GestureDetector cannot be created.
   GestureDetector detector = PanGestureDetector::New();
 
   const unsigned int actorsToAdd = 5;
-  vector<Actor> myActors;
+  std::vector<Actor> myActors;
 
-  for (unsigned int i = 0; i < actorsToAdd; ++i)
+  for(unsigned int i = 0; i < actorsToAdd; ++i)
   {
     Actor actor = Actor::New();
     myActors.push_back(actor);
     detector.Attach(actor);
   }
 
-  vector<Actor> attachedActors = detector.GetAttachedActors();
-  DALI_TEST_EQUALS(actorsToAdd, attachedActors.size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorsToAdd, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach and retrieve attached actors again, the vector should be empty.
   detector.DetachAll();
 
-  attachedActors = detector.GetAttachedActors();
-  DALI_TEST_EQUALS(true, attachedActors.empty(), TEST_LOCATION);
-  DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
+  DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Call DetachAll again, there should not be any exception
   try
   {
-    gestureManager.Initialize(); // Reset values
     detector.DetachAll();
-    DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
   }
-  catch (DaliException& exception)
+  catch(DaliException& e)
   {
+    DALI_TEST_PRINT_ASSERT(e);
     tet_result(TET_FAIL);
   }
   END_TEST;
@@ -352,55 +380,113 @@ int UtcDaliGestureDetectorGetAttachedActors(void)
   GestureDetector detector = PanGestureDetector::New();
 
   // Initially there should not be any actors.
-  DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Attach one actor
   Actor actor1 = Actor::New();
   detector.Attach(actor1);
-  DALI_TEST_EQUALS(1u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(1u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Attach another actor
   Actor actor2 = Actor::New();
   detector.Attach(actor2);
-  DALI_TEST_EQUALS(2u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(2u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Attach another five actors
-  vector<Actor> myActors;
-  for (unsigned int i = 0; i < 5; ++i)
+  std::vector<Actor> myActors;
+  for(unsigned int i = 0; i < 5; ++i)
   {
     Actor actor = Actor::New();
     myActors.push_back(actor);
     detector.Attach(actor);
   }
-  DALI_TEST_EQUALS(7u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(7u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach actor2
   detector.Detach(actor2);
-  DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Attach actor1 again, count should not increase.
   detector.Attach(actor1);
-  DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach actor2 again, count should not decrease.
   detector.Detach(actor2);
-  DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach actor1.
   detector.Detach(actor1);
-  DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Create scoped actor, actor should be automatically removed from the detector when it goes out
   // of scope.
   {
     Actor scopedActor = Actor::New();
     detector.Attach(scopedActor);
-    DALI_TEST_EQUALS(6u, detector.GetAttachedActors().size(), TEST_LOCATION);
+    DALI_TEST_EQUALS(6u, detector.GetAttachedActorCount(), TEST_LOCATION);
   }
-  DALI_TEST_EQUALS(5u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(5u, detector.GetAttachedActorCount(), TEST_LOCATION);
 
   // Detach all so nothing remains.
   detector.DetachAll();
-  DALI_TEST_EQUALS(0u, detector.GetAttachedActors().size(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0u, detector.GetAttachedActorCount(), TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliGestureDetectorProperties(void)
+{
+  TestApplication application;
+
+  // Use pinch gesture as that doen't currently have any properties. Will need to change it if default properties are added.
+  GestureDetector detector = PinchGestureDetector::New();
+
+  DALI_TEST_EQUALS(detector.GetPropertyCount(), 0u, TEST_LOCATION);
+
+  Property::IndexContainer indices;
+  detector.GetPropertyIndices(indices);
+  DALI_TEST_EQUALS(indices.Size(), 0u, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(detector.IsPropertyWritable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(detector.IsPropertyAnimatable(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(detector.GetPropertyType(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX), Property::NONE, TEST_LOCATION);
+  DALI_TEST_EQUALS(detector.GetPropertyIndex("InvalidIndex"), Property::INVALID_INDEX, TEST_LOCATION);
+
+  Property::Value propValue = detector.GetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX);
+  DALI_TEST_EQUALS(propValue.GetType(), Property::NONE, TEST_LOCATION);
+
+  DALI_TEST_CHECK(detector.GetPropertyName(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX).empty());
+
+  // For coverage only, not testable
+  detector.SetProperty(DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, true);
+
+  END_TEST;
+}
+
+int UtcDaliGestureDetectorRegisterProperty(void)
+{
+  TestApplication application;
+
+  GestureDetector detector = PinchGestureDetector::New();
+
+  Property::Index index = detector.RegisterProperty("sceneProperty", 0);
+  DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
+  DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 0, TEST_LOCATION);
+
+  detector.SetProperty(index, -123);
+  DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
+
+  using Dali::Animation;
+  Animation animation = Animation::New(1.0f);
+  animation.AnimateTo(Property(detector, index), 99);
+
+  DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), -123, TEST_LOCATION);
+  // Start the animation
+  animation.Play();
+
+  application.SendNotification();
+  application.Render(1000 /* 100% progress */);
+  DALI_TEST_EQUALS(detector.GetProperty<int32_t>(index), 99, TEST_LOCATION);
+
   END_TEST;
 }