2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <test-application.h>
23 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
27 using namespace Toolkit;
32 static bool gCheckBoxButtonState = false;
33 bool CheckBoxButtonClicked( Button button )
35 gCheckBoxButtonState = button.GetProperty<bool>(button.GetPropertyIndex("selected")) ;
39 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
40 const Vector2 TEST_IMAGE_SIZE = Vector2( 66.0f, 66.0f );
42 static std::string GetButtonText( Button button )
44 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
46 Property::Map *labelProperty = value.GetMap();
48 std::string textLabel;
52 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
53 value->Get( textLabel );
61 void checkbox_button_startup(void)
63 test_return_value = TET_UNDEF;
66 void checkbox_button_cleanup(void)
68 test_return_value = TET_PASS;
71 int UtcDaliCheckBoxButtonConstructorP(void)
73 ToolkitTestApplication application;
75 CheckBoxButton checkBox;
77 DALI_TEST_CHECK( !checkBox );
81 int UtcDaliCheckBoxButtonCopyConstructorP(void)
83 ToolkitTestApplication application;
85 // Initialize an object, ref count == 1
86 CheckBoxButton checkBox = CheckBoxButton::New();
88 CheckBoxButton copy( checkBox );
89 DALI_TEST_CHECK( copy );
93 int UtcDaliCheckBoxButtonAssignmentOperatorP(void)
95 ToolkitTestApplication application;
97 CheckBoxButton checkBox = CheckBoxButton::New();
99 CheckBoxButton copy( checkBox );
100 DALI_TEST_CHECK( copy );
102 DALI_TEST_CHECK( checkBox == copy );
106 int UtcDaliCheckBoxButtonNewP(void)
108 ToolkitTestApplication application;
110 CheckBoxButton checkBox = CheckBoxButton::New();
112 DALI_TEST_CHECK( checkBox );
116 int UtcDaliCheckBoxButtonDownCastP(void)
118 ToolkitTestApplication application;
120 CheckBoxButton checkBox = CheckBoxButton::New();
122 BaseHandle object(checkBox);
124 CheckBoxButton checkBox2 = CheckBoxButton::DownCast( object );
125 DALI_TEST_CHECK(checkBox2);
127 CheckBoxButton checkBox3 = DownCast< CheckBoxButton >(object);
128 DALI_TEST_CHECK(checkBox3);
132 int UtcDaliCheckBoxButtonDownCastN(void)
134 ToolkitTestApplication application;
136 BaseHandle unInitializedObject;
138 CheckBoxButton checkBox1 = CheckBoxButton::DownCast( unInitializedObject );
139 DALI_TEST_CHECK( !checkBox1 );
141 CheckBoxButton checkBox2 = DownCast< CheckBoxButton >( unInitializedObject );
142 DALI_TEST_CHECK( !checkBox2 );
146 int UtcDaliCheckBoxButtonSelectedPropertyP(void)
148 ToolkitTestApplication application;
149 tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected");
151 CheckBoxButton checkBoxButton = CheckBoxButton::New();
152 checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked );
154 // global var used to check if CheckBoxButtonClicked is called;
155 gCheckBoxButtonState = false;
157 checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true );
159 DALI_TEST_EQUALS( checkBoxButton.GetProperty<bool>(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION );
160 DALI_TEST_CHECK( gCheckBoxButtonState );
162 checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), false );
164 DALI_TEST_EQUALS( checkBoxButton.GetProperty<bool>(checkBoxButton.GetPropertyIndex("selected")), false, TEST_LOCATION );
165 DALI_TEST_CHECK( !gCheckBoxButtonState );
167 checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("selected"), true );
169 DALI_TEST_EQUALS( checkBoxButton.GetProperty<bool>(checkBoxButton.GetPropertyIndex("selected")), true, TEST_LOCATION );
170 DALI_TEST_CHECK( gCheckBoxButtonState );
174 int UtcDaliCheckBoxSetLabelP(void)
176 ToolkitTestApplication application;
178 CheckBoxButton checkBox = CheckBoxButton::New();
180 Property::Map propertyMap;
182 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
183 .Add( Toolkit::TextVisual::Property::TEXT, "activate" )
184 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
186 checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap );
188 DALI_TEST_EQUALS( GetButtonText( checkBox ) , "activate", TEST_LOCATION );
192 int UtcDaliCheckBoxSetDisabledPropertyP(void)
194 ToolkitTestApplication application;
196 CheckBoxButton checkBox = CheckBoxButton::New();
197 Stage::GetCurrent().Add( checkBox );
199 checkBox.SetSize( Vector2( 20.0f, 20.0f ) );
200 checkBox.SetProperty(checkBox.GetPropertyIndex("disabledUnselectedBackgroundVisual"), "Image.jpg" );
202 application.SendNotification();
203 application.Render();
205 Property::Map propertyMap;
207 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
208 .Add( Toolkit::TextVisual::Property::TEXT, "activate" )
209 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
211 checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true);
212 checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap );
214 DALI_TEST_EQUALS( checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")), true, TEST_LOCATION );
215 DALI_TEST_EQUALS( GetButtonText( checkBox ) , "activate", TEST_LOCATION );
220 int UtcDaliCheckBoxSettingDisabled(void)
222 ToolkitTestApplication application;
224 CheckBoxButton checkBox = CheckBoxButton::New();
226 checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true);
227 DALI_TEST_CHECK( checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
229 checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), false);
231 DALI_TEST_CHECK( !checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
236 int UtcDaliCheckBoxSetLabelPadding(void)
238 tet_infoline("UtcDaliCheckBoxSetLabelPadding\n");
240 ToolkitTestApplication application;
242 CheckBoxButton checkBox = CheckBoxButton::New();
244 Property::Map propertyMap;
246 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
247 .Add( Toolkit::TextVisual::Property::TEXT, "activate" )
248 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
250 checkBox.SetProperty( Toolkit::Button::Property::LABEL, propertyMap );
252 application.SendNotification();
253 application.Render();
255 Vector3 orginalSize = checkBox.GetNaturalSize();
257 checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
259 application.SendNotification();
260 application.Render();
262 Vector3 paddingAddedSize = checkBox.GetNaturalSize();
264 DALI_TEST_EQUALS( checkBox.GetProperty<Vector4>( Toolkit::DevelButton::Property::LABEL_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
266 tet_infoline("Comparing original size of button with just text and button size with text and padding\n");
268 DALI_TEST_EQUALS( orginalSize.width +10.0f + 10.0f , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
270 DALI_TEST_EQUALS( orginalSize.height +10.0f + 10.0f , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
275 int UtcDaliCheckBoxSetForegroundPadding(void)
277 tet_infoline("UtcDaliCheckBoxSetForegroundPadding\n");
279 ToolkitTestApplication application;
281 CheckBoxButton checkBox = CheckBoxButton::New();
283 Property::Map propertyMap;
285 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
286 .Add( Toolkit::TextVisual::Property::TEXT, "activate" )
287 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
289 checkBox.SetProperty( Toolkit::Button::Property::LABEL, propertyMap );
290 checkBox.SetProperty( Toolkit::DevelButton::Property::LABEL_PADDING, Vector4( 5.0f, 5.0f, 5.0f, 5.0f ) );
292 application.SendNotification();
293 application.Render();
295 tet_printf( "Button RelayoutSize with text(%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height );
297 TestPlatformAbstraction& platform = application.GetPlatform();
298 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
300 checkBox.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE );
301 checkBox.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, TEST_IMAGE_ONE );
304 application.SendNotification();
305 application.Render();
307 Vector3 preVisualPaddingSize = checkBox.GetNaturalSize();
309 tet_printf( "Button RelayoutSize with text and icon (%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height );
311 checkBox.SetProperty( Toolkit::DevelButton::Property::VISUAL_PADDING, Vector4( 25.0f, 25.0f, 25.0f, 25.0f ) );
313 application.SendNotification();
314 application.Render();
316 Vector3 paddingAddedSize = checkBox.GetNaturalSize();
318 tet_printf( "Button RelayoutSize with text, icon and padding (%f,%f)\n", checkBox.GetNaturalSize().width, checkBox.GetNaturalSize().height );
320 DALI_TEST_EQUALS( checkBox.GetProperty<Vector4>( Toolkit::DevelButton::Property::VISUAL_PADDING ), Vector4( 25.0f, 25.0f, 25.0f, 25.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
322 tet_infoline("Comparing original size of button before adding padding to visual foreground\n");
324 DALI_TEST_GREATER( paddingAddedSize.width, preVisualPaddingSize.width , TEST_LOCATION );
326 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");
328 DALI_TEST_GREATER( paddingAddedSize.height, preVisualPaddingSize.height , TEST_LOCATION );
333 // Deprecated API Tests
335 int UtcDaliCheckBoxButtonSetGetSelected(void)
337 ToolkitTestApplication application;
338 tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected");
340 CheckBoxButton checkBoxButton = CheckBoxButton::New();
341 checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked );
343 // global var used to check if CheckBoxButtonClicked is called;
344 gCheckBoxButtonState = false;
346 checkBoxButton.SetProperty( Button::Property::SELECTED, true );
348 DALI_TEST_EQUALS( checkBoxButton.GetProperty( Button::Property::SELECTED ).Get<bool>(), true, TEST_LOCATION );
349 DALI_TEST_CHECK( gCheckBoxButtonState );
351 checkBoxButton.SetProperty( Button::Property::SELECTED, false );
353 DALI_TEST_EQUALS( checkBoxButton.GetProperty( Button::Property::SELECTED ).Get<bool>(), false, TEST_LOCATION );
354 DALI_TEST_CHECK( !gCheckBoxButtonState );
356 checkBoxButton.SetProperty( Button::Property::SELECTED, true );
358 DALI_TEST_EQUALS( checkBoxButton.GetProperty( Button::Property::SELECTED ).Get<bool>(), true, TEST_LOCATION );
359 DALI_TEST_CHECK( gCheckBoxButtonState );
363 int UtcDaliCheckBoxSetLabelDisabledP(void)
365 ToolkitTestApplication application;
367 CheckBoxButton checkBox = CheckBoxButton::New();
368 Stage::GetCurrent().Add( checkBox );
370 checkBox.SetSize( Vector2( 20.0f, 20.0f ) );
371 checkBox.SetProperty(Button::Property::DISABLED_UNSELECTED_VISUAL, "Image.jpg" );
373 application.SendNotification();
374 application.Render();
376 Property::Map propertyMap;
378 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
379 .Add( Toolkit::TextVisual::Property::TEXT, "activate" )
380 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
382 checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true);
383 checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap );
385 DALI_TEST_CHECK( checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
386 DALI_TEST_EQUALS( GetButtonText(checkBox), "activate", TEST_LOCATION );