Revert "[Tizen] Revert "Use touch consumed return to set whether we process a gesture...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PanGestureDetector.cpp
index 2cfadee..180c1c3 100644 (file)
@@ -2833,3 +2833,94 @@ int UtcDaliPanGestureNoTimeDiff(void)
 
   END_TEST;
 }
+
+int UtcDaliPanGestureInterruptedWhenTouchConsumed(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  application.GetScene().Add(actor);
+
+  bool                           consume = false;
+  TouchEventFunctorConsumeSetter touchFunctor(consume);
+  actor.TouchedSignal().Connect(&application, touchFunctor);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  SignalData             data;
+  GestureReceivedFunctor functor(data);
+
+  PanGestureDetector detector = PanGestureDetector::New();
+  detector.Attach(actor);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  // Start gesture within the actor's area, we should receive the pan as the touch is NOT being consumed
+  uint32_t time = 100;
+  TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
+  data.Reset();
+
+  // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
+  consume = true;
+
+  TestMovePan(application, Vector2(26.0f, 4.0f), time);
+  time += TestGetFrameInterval();
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(GestureState::CANCELLED, data.receivedGesture.GetState(), TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliPanGestureDisableDetectionDuringPanN(void)
+{
+  // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
+
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  application.GetScene().Add(actor);
+
+  // Add a pan detector
+  PanGestureDetector detector      = PanGestureDetector::New();
+  bool               functorCalled = false;
+  detector.Attach(actor);
+  detector.DetectedSignal().Connect(
+    &application,
+    [&detector, &functorCalled](Actor actor, const PanGesture& pan) {
+      if(pan.GetState() == GestureState::FINISHED)
+      {
+        detector.Detach(actor);
+        functorCalled = true;
+      }
+    });
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Try the gesture, should not crash
+  try
+  {
+    uint32_t time = 100;
+    TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
+    TestEndPan(application, Vector2(26.0f, 20.0f));
+
+    DALI_TEST_CHECK(true); // No crash, test has passed
+    DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(false); // If we crash, the test has failed
+  }
+
+  END_TEST;
+}