Using SingletonService instead of Adaptor
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Control.cpp
index 095879b..5cc1e0e 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <iostream>
 #include <stdlib.h>
@@ -43,13 +44,17 @@ void utc_dali_toolkit_control_cleanup(void)
 namespace
 {
 
-static bool gObjectCreatedCallBackCalled;
+bool gObjectCreatedCallBackCalled;
 
-static void TestCallback(BaseHandle handle)
+void TestCallback(BaseHandle handle)
 {
   gObjectCreatedCallBackCalled = true;
 }
 
+void TestVoidCallback()
+{
+}
+
 } // namespace
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -200,7 +205,7 @@ int UtcDaliControlGetImplementation(void)
   {
     try
     {
-      ControlImpl& controlImpl = control.GetImplementation();
+      Toolkit::Internal::Control& controlImpl = control.GetImplementation();
       (void)controlImpl; // Avoid unused warning
       tet_result(TET_FAIL);
     }
@@ -215,7 +220,7 @@ int UtcDaliControlGetImplementation(void)
     try
     {
       const DummyControl constControl(control);
-      const ControlImpl& controlImpl = constControl.GetImplementation();
+      const Toolkit::Internal::Control& controlImpl = constControl.GetImplementation();
       (void)controlImpl; // Avoid unused warning
       tet_result(TET_FAIL);
     }
@@ -231,7 +236,7 @@ int UtcDaliControlGetImplementation(void)
   {
     try
     {
-      ControlImpl& controlImpl = control.GetImplementation();
+      Toolkit::Internal::Control& controlImpl = control.GetImplementation();
       (void)controlImpl; // Avoid unused warning
       tet_result(TET_PASS);
     }
@@ -246,7 +251,7 @@ int UtcDaliControlGetImplementation(void)
     try
     {
       const DummyControl constControl(control);
-      const ControlImpl& controlImpl = constControl.GetImplementation();
+      const Toolkit::Internal::Control& controlImpl = constControl.GetImplementation();
       (void)controlImpl; // Avoid unused warning
       tet_result(TET_PASS);
     }
@@ -267,23 +272,27 @@ int UtcDaliControlSignalConnectDisconnect(void)
 
     Actor actor = Actor::New();
     DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 0u, TEST_LOCATION );
-    actor.SetSizeSignal().Connect( &dummy, &DummyControl::CustomSlot1 );
+    Toolkit::Internal::Control& control = dummy.GetImplementation();
+    DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
+    DALI_TEST_CHECK( dummyImpl );
+
+    actor.SetSizeSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
     DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 1u, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Value,  Vector3::ZERO, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Value,  Vector3::ZERO, TEST_LOCATION );
 
     const Vector3 newSize( 10, 10, 0 );
     actor.SetSize( newSize );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Called, true, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Value,  newSize, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Value,  newSize, TEST_LOCATION );
 
-    dummy.mCustomSlot1Called = false;
-    actor.SetSizeSignal().Disconnect( &dummy, &DummyControl::CustomSlot1 );
+    dummyImpl->mCustomSlot1Called = false;
+    actor.SetSizeSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
     DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 0u, TEST_LOCATION );
     const Vector3 ignoredSize( 20, 20, 0 );
     actor.SetSize( ignoredSize );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Value,  newSize/*not ignoredSize*/, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Value,  newSize/*not ignoredSize*/, TEST_LOCATION );
   }
   END_TEST;
 }
@@ -296,16 +305,19 @@ int UtcDaliControlSignalAutomaticDisconnect(void)
 
   {
     DummyControl dummy = DummyControlImpl::New();
+    Toolkit::Internal::Control& control = dummy.GetImplementation();
+    DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
+    DALI_TEST_CHECK( dummyImpl );
 
-    actor.SetSizeSignal().Connect( &dummy, &DummyControl::CustomSlot1 );
+    actor.SetSizeSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
     DALI_TEST_EQUALS( actor.SetSizeSignal().GetConnectionCount(), 1u, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Called, false, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Value,  Vector3::ZERO, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Value,  Vector3::ZERO, TEST_LOCATION );
 
     const Vector3 newSize( 10, 10, 0 );
     actor.SetSize( newSize );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Called, true, TEST_LOCATION );
-    DALI_TEST_EQUALS( dummy.mCustomSlot1Value,  newSize, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
+    DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Value,  newSize, TEST_LOCATION );
   }
   // dummyControl automatically disconnects
 
@@ -343,8 +355,6 @@ int UtcDaliControlTestParameters(void)
   DALI_TEST_CHECK( test.GetMaximumSize() == maxSize );
 
   test.KeyEventSignal();
-  DummyControl test2 = DummyControl::New();
-  dynamic_cast< ConnectionTrackerInterface& >( test2 ).GetConnectionCount();
 
   // Provide coverage for pointer destructor
   Control* testControlPtr = new Control;
@@ -505,3 +515,29 @@ int UtcDaliControlKeyProperties(void)
 
   END_TEST;
 }
+
+int UtcDaliControlGestureSignals(void)
+{
+  ToolkitTestApplication application;
+  ConnectionTracker connectionTracker;
+  Control control = Control::New();
+
+  // Each gesture detector gets created when connecting to the gesture signals
+  DALI_TEST_CHECK( !control.GetTapGestureDetector() );
+  control.ConnectSignal( &connectionTracker, Control::SIGNAL_TAPPED, &TestVoidCallback );
+  DALI_TEST_CHECK( control.GetTapGestureDetector() );
+
+  DALI_TEST_CHECK( !control.GetPanGestureDetector() );
+  control.ConnectSignal( &connectionTracker, Control::SIGNAL_PANNED, &TestVoidCallback );
+  DALI_TEST_CHECK( control.GetPanGestureDetector() );
+
+  DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
+  control.ConnectSignal( &connectionTracker, Control::SIGNAL_PINCHED, &TestVoidCallback );
+  DALI_TEST_CHECK( control.GetPinchGestureDetector() );
+
+  DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
+  control.ConnectSignal( &connectionTracker, Control::SIGNAL_LONG_PRESSED, &TestVoidCallback );
+  DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
+
+  END_TEST;
+}