X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-CheckBoxButton.cpp;h=1544a601061ed3b9696a117c993dbf7b4c13466b;hp=a8aca4807fc493ca69e6beff9cb21f18c3b74d35;hb=895e2909bd541d9f987923c40dabd9417f66325b;hpb=f60d2ee843df1c81ea988c4a986e9168c905fcc9 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp index a8aca48..1544a60 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -19,6 +19,9 @@ #include #include #include +#include +#include + using namespace Dali; using namespace Toolkit; @@ -29,10 +32,30 @@ namespace static bool gCheckBoxButtonState = false; bool CheckBoxButtonClicked( Button button ) { - gCheckBoxButtonState = button.IsSelected(); + gCheckBoxButtonState = button.GetProperty(button.GetPropertyIndex("selected")) ; return true; } +static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; +const Vector2 TEST_IMAGE_SIZE = Vector2( 66.0f, 66.0f ); + +static std::string GetButtonText( Button button ) +{ + Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL ); + + Property::Map *labelProperty = value.GetMap(); + + std::string textLabel; + + if ( labelProperty ) + { + Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT ); + value->Get( textLabel ); + } + + return textLabel; +} + } // namespace void checkbox_button_startup(void) @@ -120,6 +143,195 @@ int UtcDaliCheckBoxButtonDownCastN(void) END_TEST; } +int UtcDaliCheckBoxButtonSelectedPropertyP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected"); + + CheckBoxButton checkBoxButton = CheckBoxButton::New(); + checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked ); + + // global var used to check if CheckBoxButtonClicked is called; + gCheckBoxButtonState = false; + + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true ); + + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION ); + DALI_TEST_CHECK( gCheckBoxButtonState ); + + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), false ); + + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), false, TEST_LOCATION ); + DALI_TEST_CHECK( !gCheckBoxButtonState ); + + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true ); + + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION ); + DALI_TEST_CHECK( gCheckBoxButtonState ); + END_TEST; +} + +int UtcDaliCheckBoxSetLabelP(void) +{ + TestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + + Property::Map propertyMap; + + propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) + .Add( Toolkit::TextVisual::Property::TEXT, "activate" ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap ); + + DALI_TEST_EQUALS( GetButtonText( checkBox ) , "activate", TEST_LOCATION ); + END_TEST; +} + +int UtcDaliCheckBoxSetDisabledPropertyP(void) +{ + TestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + Stage::GetCurrent().Add( checkBox ); + + checkBox.SetSize( Vector2( 20.0f, 20.0f ) ); + checkBox.SetProperty(checkBox.GetPropertyIndex("disabledUnselectedBackgroundVisual"), "Image.jpg" ); + + application.SendNotification(); + application.Render(); + + Property::Map propertyMap; + + propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) + .Add( Toolkit::TextVisual::Property::TEXT, "activate" ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true); + checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap ); + + DALI_TEST_EQUALS( checkBox.GetProperty(checkBox.GetPropertyIndex("disabled")), true, TEST_LOCATION ); + DALI_TEST_EQUALS( GetButtonText( checkBox ) , "activate", TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliCheckBoxSettingDisabled(void) +{ + ToolkitTestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + + checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true); + DALI_TEST_CHECK( checkBox.GetProperty(checkBox.GetPropertyIndex("disabled")) ); + + checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), false); + + DALI_TEST_CHECK( !checkBox.GetProperty(checkBox.GetPropertyIndex("disabled")) ); + + END_TEST; +} + +int UtcDaliCheckBoxSetLabelPadding(void) +{ + tet_infoline("UtcDaliCheckBoxSetLabelPadding\n"); + + ToolkitTestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + + Property::Map propertyMap; + + propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) + .Add( Toolkit::TextVisual::Property::TEXT, "activate" ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL, propertyMap ); + + application.SendNotification(); + application.Render(); + + Vector3 orginalSize = checkBox.GetNaturalSize(); + + checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) ); + + application.SendNotification(); + application.Render(); + + Vector3 paddingAddedSize = checkBox.GetNaturalSize(); + + DALI_TEST_EQUALS( checkBox.GetProperty( Toolkit::DevelButton::Property::LABEL_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + tet_infoline("Comparing original size of button with just text and button size with text and padding\n"); + + DALI_TEST_EQUALS( orginalSize.width +10.0f + 10.0f , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + DALI_TEST_EQUALS( orginalSize.height +10.0f + 10.0f , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliCheckBoxSetForegroundPadding(void) +{ + tet_infoline("UtcDaliCheckBoxSetForegroundPadding\n"); + + ToolkitTestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + + Property::Map propertyMap; + + propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) + .Add( Toolkit::TextVisual::Property::TEXT, "activate" ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL, propertyMap ); + checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL_PADDING, Vector4( 5.0f, 5.0f, 5.0f, 5.0f ) ); + + application.SendNotification(); + application.Render(); + + tet_printf( "Button RelayoutSize with text(%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height ); + + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetClosestImageSize( TEST_IMAGE_SIZE ); + + checkBox.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE ); + checkBox.SetProperty( Toolkit::DevelButton::Property::SELECTED_VISUAL, TEST_IMAGE_ONE ); + + + application.SendNotification(); + application.Render(); + + Vector3 preVisualPaddingSize = checkBox.GetNaturalSize(); + + tet_printf( "Button RelayoutSize with text and icon (%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height ); + + checkBox.SetProperty( Toolkit::DevelButton::Property::VISUAL_PADDING, Vector4( 25.0f, 25.0f, 25.0f, 25.0f ) ); + + application.SendNotification(); + application.Render(); + + Vector3 paddingAddedSize = checkBox.GetNaturalSize(); + + tet_printf( "Button RelayoutSize with text, icon and padding (%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height ); + + DALI_TEST_EQUALS( checkBox.GetProperty( Toolkit::DevelButton::Property::VISUAL_PADDING ), Vector4( 25.0f, 25.0f, 25.0f, 25.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + tet_infoline("Comparing original size of button before adding padding to visual foreground\n"); + + DALI_TEST_GREATER( paddingAddedSize.width, preVisualPaddingSize.width , TEST_LOCATION ); + + tet_infoline("Text and Visual are side by side, visual height and padding must be greater than text height and padding for this test\n"); + + DALI_TEST_GREATER( paddingAddedSize.height, preVisualPaddingSize.height , TEST_LOCATION ); + + END_TEST; +} + +// Deprecated API Tests + int UtcDaliCheckBoxButtonSetGetSelected(void) { ToolkitTestApplication application; @@ -147,3 +359,31 @@ int UtcDaliCheckBoxButtonSetGetSelected(void) DALI_TEST_CHECK( gCheckBoxButtonState ); END_TEST; } + +int UtcDaliCheckBoxSetLabelDisabledP(void) +{ + TestApplication application; + + CheckBoxButton checkBox = CheckBoxButton::New(); + Stage::GetCurrent().Add( checkBox ); + + checkBox.SetSize( Vector2( 20.0f, 20.0f ) ); + checkBox.SetDisabledBackgroundImage( "Image.jpg" ); + + application.SendNotification(); + application.Render(); + + Property::Map propertyMap; + + propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) + .Add( Toolkit::TextVisual::Property::TEXT, "activate" ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true); + checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap ); + + DALI_TEST_CHECK( checkBox.GetProperty(checkBox.GetPropertyIndex("disabled")) ); + DALI_TEST_EQUALS( checkBox.GetLabelText(), "activate", TEST_LOCATION ); + + END_TEST; +} \ No newline at end of file