(Builder) Added Quit Signal
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-Builder.cpp
index 833a40e..f95bbe7 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/public-api/builder/builder.h>
+#include <dali/integration-api/events/touch-event-integ.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -159,6 +160,21 @@ std::string ReplaceQuotes(const std::string &in_s)
   return s;
 }
 
+struct BuilderFunctor
+{
+  BuilderFunctor( bool& called ) : mCalled( called )
+  {
+    mCalled = false;
+  }
+
+  void operator()()
+  {
+    mCalled = true;
+  }
+
+  bool& mCalled;
+};
+
 } // namespace
 
 
@@ -429,3 +445,44 @@ int UtcDaliBuilderApplyFromJson(void)
 
   END_TEST;
 }
+
+int UtcDaliBuilderQuitSignal(void)
+{
+  ToolkitTestApplication application;
+
+  // JSON with a quit event when the actor is touched
+  std::string json(
+      "{"
+         "\"stage\":"
+         "[{"
+           "\"type\": \"Actor\","
+           "\"size\": [100,100,1],"
+           "\"parent-origin\": \"TOP_LEFT\","
+           "\"anchor-point\": \"TOP_LEFT\","
+           "\"signals\": [{"
+             "\"name\": \"touched\","
+             "\"action\": \"quit\""
+           "}]"
+         "}]"
+      "}"
+  );
+  Builder builder = Builder::New();
+  builder.LoadFromString( json );
+  builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
+
+  // Connect to builder's quit signal
+  bool functorCalled( false );
+  builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Emit touch event and check that our quit method is called
+  Integration::TouchEvent touchEvent;
+  touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
+  application.ProcessEvent( touchEvent );
+  DALI_TEST_CHECK( functorCalled );
+
+  END_TEST;
+}