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=07b810f59a8e5e8af6bdb7bb3ec090f85377523f;hb=5e351965bad7e1de2e94027548b022bac692603c;hpb=764cd70c98c4f9393c8b50abb7b5a16484c28977 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-CheckBoxButton.cpp index 07b810f..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,7 +143,7 @@ int UtcDaliCheckBoxButtonDownCastN(void) END_TEST; } -int UtcDaliCheckBoxButtonSetGetSelected(void) +int UtcDaliCheckBoxButtonSelectedPropertyP(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected"); @@ -131,19 +154,19 @@ int UtcDaliCheckBoxButtonSetGetSelected(void) // global var used to check if CheckBoxButtonClicked is called; gCheckBoxButtonState = false; - checkBoxButton.SetSelected( true ); + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true ); - DALI_TEST_CHECK( checkBoxButton.IsSelected() ); + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION ); DALI_TEST_CHECK( gCheckBoxButtonState ); - checkBoxButton.SetSelected( false ); + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), false ); - DALI_TEST_CHECK( !checkBoxButton.IsSelected() ); + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), false, TEST_LOCATION ); DALI_TEST_CHECK( !gCheckBoxButtonState ); - checkBoxButton.SetSelected( true ); + checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true ); - DALI_TEST_CHECK( checkBoxButton.IsSelected() ); + DALI_TEST_EQUALS( checkBoxButton.GetProperty(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION ); DALI_TEST_CHECK( gCheckBoxButtonState ); END_TEST; } @@ -155,15 +178,18 @@ int UtcDaliCheckBoxSetLabelP(void) CheckBoxButton checkBox = CheckBoxButton::New(); Property::Map propertyMap; - propertyMap.Insert("text", "activate"); - checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap ); - DALI_TEST_EQUALS( checkBox.GetLabelText(), "activate", TEST_LOCATION ); // Change to use GerProperty once that code is implemented + 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 UtcDaliCheckBoxSetLabelDisabledP(void) +int UtcDaliCheckBoxSetDisabledPropertyP(void) { TestApplication application; @@ -171,19 +197,22 @@ int UtcDaliCheckBoxSetLabelDisabledP(void) Stage::GetCurrent().Add( checkBox ); checkBox.SetSize( Vector2( 20.0f, 20.0f ) ); - checkBox.SetDisabledBackgroundImage( "Image.jpg" ); + checkBox.SetProperty(checkBox.GetPropertyIndex("disabledUnselectedBackgroundVisual"), "Image.jpg" ); application.SendNotification(); application.Render(); Property::Map propertyMap; - propertyMap.Insert("text", "activate"); - checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true); + 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 ); // Change to use GerProperty once that code is implemented + DALI_TEST_EQUALS( checkBox.GetProperty(checkBox.GetPropertyIndex("disabled")), true, TEST_LOCATION ); + DALI_TEST_EQUALS( GetButtonText( checkBox ) , "activate", TEST_LOCATION ); END_TEST; } @@ -203,3 +232,158 @@ int UtcDaliCheckBoxSettingDisabled(void) 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; + tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected"); + + CheckBoxButton checkBoxButton = CheckBoxButton::New(); + checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked ); + + // global var used to check if CheckBoxButtonClicked is called; + gCheckBoxButtonState = false; + + checkBoxButton.SetSelected( true ); + + DALI_TEST_CHECK( checkBoxButton.IsSelected() ); + DALI_TEST_CHECK( gCheckBoxButtonState ); + + checkBoxButton.SetSelected( false ); + + DALI_TEST_CHECK( !checkBoxButton.IsSelected() ); + DALI_TEST_CHECK( !gCheckBoxButtonState ); + + checkBoxButton.SetSelected( true ); + + DALI_TEST_CHECK( checkBoxButton.IsSelected() ); + 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