2 * Copyright (c) 2014 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>
24 using namespace Toolkit;
29 static bool gCheckBoxButtonState = false;
30 bool CheckBoxButtonClicked( Button button )
32 gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
38 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
40 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
43 PixelBuffer* pixbuf = imageData.GetBuffer();
44 unsigned int size = width * height;
46 for( size_t i = 0; i < size; i++ )
48 pixbuf[i*4+0] = 0xFF * color.r;
49 pixbuf[i*4+1] = 0xFF * color.g;
50 pixbuf[i*4+2] = 0xFF * color.b;
51 pixbuf[i*4+3] = 0xFF * color.a;
62 void checkbox_button_startup(void)
64 test_return_value = TET_UNDEF;
67 void checkbox_button_cleanup(void)
69 test_return_value = TET_PASS;
72 int UtcDaliCheckBoxButtonSetGetChecked(void)
74 ToolkitTestApplication application;
75 tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
77 CheckBoxButton checkBoxButton = CheckBoxButton::New();
78 checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
80 // global var used to check if CheckBoxButtonClicked is called;
81 gCheckBoxButtonState = false;
83 checkBoxButton.SetChecked( true );
85 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
86 DALI_TEST_CHECK( gCheckBoxButtonState );
88 checkBoxButton.SetChecked( false );
90 DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
91 DALI_TEST_CHECK( !gCheckBoxButtonState );
93 checkBoxButton.SetChecked( true );
95 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
96 DALI_TEST_CHECK( gCheckBoxButtonState );
100 int UtcDaliCheckBoxButtonSetImages(void)
102 ToolkitTestApplication application;
103 tet_infoline(" UtcDaliCheckBoxButtonSetImages");
107 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
108 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
109 imageActor01.SetSize( 20, 20 );
111 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
112 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
113 imageActor02.SetSize( 40, 40 );
115 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
116 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
117 imageActor03.SetSize( 60, 60 );
119 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
120 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
121 imageActor04.SetSize( 80, 80 );
124 CheckBoxButton checkBoxButton = CheckBoxButton::New();
126 application.SendNotification();
127 application.Render();
129 // Just check if check box button size changes when a bigger image is set.
131 checkBoxButton.SetBackgroundImage( image01 );
133 application.SendNotification();
134 application.Render();
136 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
138 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
139 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
141 checkBoxButton.SetBackgroundImage( imageActor01 );
143 application.SendNotification();
144 application.Render();
146 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
148 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
149 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
151 checkBoxButton.SetCheckedImage( image02 );
153 application.SendNotification();
154 application.Render();
156 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
158 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
159 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
161 checkBoxButton.SetCheckedImage( imageActor02 );
163 application.SendNotification();
164 application.Render();
166 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
168 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
169 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
171 checkBoxButton.SetDimmedBackgroundImage( image03 );
173 application.SendNotification();
174 application.Render();
176 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
178 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
179 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
181 checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
183 application.SendNotification();
184 application.Render();
186 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
188 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
189 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
191 checkBoxButton.SetDimmedCheckedImage( image04 );
193 application.SendNotification();
194 application.Render();
196 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
198 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
199 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
201 checkBoxButton.SetDimmedCheckedImage( imageActor04 );
203 application.SendNotification();
204 application.Render();
206 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
208 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
209 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );