Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Control.cpp
index 800c65f..0082fa7 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>
@@ -200,7 +201,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 +216,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 +232,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 +247,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);
     }
@@ -352,3 +353,156 @@ int UtcDaliControlTestParameters(void)
   delete testControlPtr;
   END_TEST;
 }
+
+int UtcDaliControlBackgroundColor(void)
+{
+  ToolkitTestApplication application;
+  Control control = Control::New();
+
+  DALI_TEST_CHECK( !control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
+
+  control.SetBackgroundColor( Color::RED );
+  DALI_TEST_CHECK( control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliControlBackgroundImage(void)
+{
+  ToolkitTestApplication application;
+  Control control = Control::New();
+
+  DALI_TEST_CHECK( !control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
+
+  Image image = Image::New("TestImage");
+  control.SetBackground( image );
+  DALI_TEST_CHECK( control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::WHITE, TEST_LOCATION );
+
+  control.SetBackgroundColor( Color::GREEN );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::GREEN, TEST_LOCATION );
+
+  control.ClearBackground();
+  DALI_TEST_CHECK( !control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
+
+  control.SetBackgroundColor( Color::YELLOW );
+  control.SetBackground( image );
+  DALI_TEST_CHECK( control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliControlBackgroundProperties(void)
+{
+  ToolkitTestApplication application;
+  Control control = Control::New();
+
+  DALI_TEST_CHECK( !control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
+  DALI_TEST_CHECK( control.GetProperty( Control::PROPERTY_BACKGROUND ).Get< Property::Map >().empty() );
+
+  control.SetProperty( Control::PROPERTY_BACKGROUND_COLOR, Color::RED );
+  DALI_TEST_CHECK( control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
+
+  Property::Map imageMap;
+  imageMap.push_back( Property::StringValuePair( "filename", "TestImage" ) );
+  Property::Map map;
+  map.push_back( Property::StringValuePair( "image", imageMap ) );
+  control.SetProperty( Control::PROPERTY_BACKGROUND, map );
+  DALI_TEST_CHECK( control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
+
+  Property::Value propValue = control.GetProperty( Control::PROPERTY_BACKGROUND );
+  DALI_TEST_CHECK( propValue.HasKey( "image" ) );
+  DALI_TEST_CHECK( propValue.GetValue( "image" ).HasKey( "filename" ) );
+  DALI_TEST_CHECK( propValue.GetValue( "image" ).GetValue( "filename" ).Get< std::string>() == "TestImage" );
+
+  Property::Map emptyMap;
+  control.SetProperty( Control::PROPERTY_BACKGROUND, emptyMap );
+  DALI_TEST_CHECK( !control.GetBackgroundActor() );
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetProperty( Control::PROPERTY_BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
+  DALI_TEST_CHECK( control.GetProperty( Control::PROPERTY_BACKGROUND ).Get< Property::Map >().empty() );
+
+  END_TEST;
+}
+
+int UtcDaliControlSizePolicyProperties(void)
+{
+  ToolkitTestApplication application;
+
+  Control control = Control::New();
+
+  Control::SizePolicy widthPolicy( Control::Fixed );
+  Control::SizePolicy heightPolicy( Control::Fixed );
+
+  control.GetSizePolicy( widthPolicy, heightPolicy );
+  DALI_TEST_EQUALS( "FIXED", control.GetProperty( Control::PROPERTY_WIDTH_POLICY ).Get< std::string >(), TEST_LOCATION );
+  DALI_TEST_EQUALS( "FIXED", control.GetProperty( Control::PROPERTY_HEIGHT_POLICY ).Get< std::string >(), TEST_LOCATION );
+
+  control.SetSizePolicy( Control::Flexible, Control::Range );
+  DALI_TEST_EQUALS( "FLEXIBLE", control.GetProperty( Control::PROPERTY_WIDTH_POLICY ).Get< std::string >(), TEST_LOCATION );
+  DALI_TEST_EQUALS( "RANGE", control.GetProperty( Control::PROPERTY_HEIGHT_POLICY ).Get< std::string >(), TEST_LOCATION );
+
+  control.SetProperty( Control::PROPERTY_WIDTH_POLICY, "MAXIMUM" );
+  control.SetProperty( Control::PROPERTY_HEIGHT_POLICY, "MINIMUM" );
+  control.GetSizePolicy( widthPolicy, heightPolicy );
+  DALI_TEST_EQUALS( Control::Maximum, widthPolicy, TEST_LOCATION );
+  DALI_TEST_EQUALS( Control::Minimum, heightPolicy, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliControlSizeProperties(void)
+{
+  ToolkitTestApplication application;
+
+  Control control = Control::New();
+
+  DALI_TEST_EQUALS( control.GetMinimumSize(), control.GetProperty( Control::PROPERTY_MINIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetMaximumSize(), control.GetProperty( Control::PROPERTY_MAXIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION );
+
+  control.SetMinimumSize( Vector3( 100.0f, 200.0f, 300.0f ) );
+  DALI_TEST_EQUALS( Vector3( 100.0f, 200.0f, 300.0f ), control.GetProperty( Control::PROPERTY_MINIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION );
+
+
+  control.SetMaximumSize( Vector3( 200.0f, 250.0f, 800.0f ) );
+  DALI_TEST_EQUALS( Vector3( 200.0f, 250.0f, 800.0f ), control.GetProperty( Control::PROPERTY_MAXIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION );
+
+  control.SetProperty( Control::PROPERTY_MINIMUM_SIZE, Vector3( 1.0f, 2.0f, 3.0f ) );
+  control.SetProperty( Control::PROPERTY_MAXIMUM_SIZE, Vector3( 10.0f, 20.0f, 30.0f ) );
+  DALI_TEST_EQUALS( control.GetMinimumSize(), Vector3( 1.0f, 2.0f, 3.0f ), TEST_LOCATION );
+  DALI_TEST_EQUALS( control.GetMaximumSize(), Vector3( 10.0f, 20.0f, 30.0f ), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliControlKeyProperties(void)
+{
+  ToolkitTestApplication application;
+
+  Control control = Control::New();
+  Stage::GetCurrent().Add( control );
+
+  DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
+
+  control.SetKeyInputFocus();
+  DALI_TEST_EQUALS( true, control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
+
+  control.ClearKeyInputFocus();
+  DALI_TEST_EQUALS( false, control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
+
+  control.SetProperty( Control::PROPERTY_KEY_INPUT_FOCUS, true );
+  DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
+
+  END_TEST;
+}