2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
23 using namespace Toolkit;
28 static bool gCheckBoxButtonState = false;
29 bool CheckBoxButtonClicked( Button button )
31 gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
37 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
39 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
42 PixelBuffer* pixbuf = imageData.GetBuffer();
43 unsigned int size = width * height;
45 for( size_t i = 0; i < size; i++ )
47 pixbuf[i*4+0] = 0xFF * color.r;
48 pixbuf[i*4+1] = 0xFF * color.g;
49 pixbuf[i*4+2] = 0xFF * color.b;
50 pixbuf[i*4+3] = 0xFF * color.a;
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 UtcDaliCheckBoxButtonSetGetChecked(void)
73 ToolkitTestApplication application;
74 tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
76 CheckBoxButton checkBoxButton = CheckBoxButton::New();
77 checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
79 // global var used to check if CheckBoxButtonClicked is called;
80 gCheckBoxButtonState = false;
82 checkBoxButton.SetChecked( true );
84 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
85 DALI_TEST_CHECK( gCheckBoxButtonState );
87 checkBoxButton.SetChecked( false );
89 DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
90 DALI_TEST_CHECK( !gCheckBoxButtonState );
92 checkBoxButton.SetChecked( true );
94 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
95 DALI_TEST_CHECK( gCheckBoxButtonState );
99 int UtcDaliCheckBoxButtonSetImages(void)
101 ToolkitTestApplication application;
102 tet_infoline(" UtcDaliCheckBoxButtonSetImages");
106 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
107 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
108 imageActor01.SetSize( 20, 20 );
110 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
111 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
112 imageActor02.SetSize( 40, 40 );
114 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
115 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
116 imageActor03.SetSize( 60, 60 );
118 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
119 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
120 imageActor04.SetSize( 80, 80 );
123 CheckBoxButton checkBoxButton = CheckBoxButton::New();
125 application.SendNotification();
126 application.Render();
128 // Just check if check box button size changes when a bigger image is set.
130 checkBoxButton.SetBackgroundImage( image01 );
132 application.SendNotification();
133 application.Render();
135 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
137 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
138 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
140 checkBoxButton.SetBackgroundImage( imageActor01 );
142 application.SendNotification();
143 application.Render();
145 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
147 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
148 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
150 checkBoxButton.SetCheckedImage( image02 );
152 application.SendNotification();
153 application.Render();
155 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
157 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
158 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
160 checkBoxButton.SetCheckedImage( imageActor02 );
162 application.SendNotification();
163 application.Render();
165 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
167 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
168 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
170 checkBoxButton.SetDimmedBackgroundImage( image03 );
172 application.SendNotification();
173 application.Render();
175 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
177 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
178 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
180 checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
182 application.SendNotification();
183 application.Render();
185 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
187 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
188 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
190 checkBoxButton.SetDimmedCheckedImage( image04 );
192 application.SendNotification();
193 application.Render();
195 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
197 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
198 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
200 checkBoxButton.SetDimmedCheckedImage( imageActor04 );
202 application.SendNotification();
203 application.Render();
205 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
207 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
208 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );