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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
24 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
33 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
35 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
38 PixelBuffer* pixbuf = imageData.GetBuffer();
39 unsigned int size = width * height;
41 for( size_t i = 0; i < size; i++ )
43 pixbuf[i*4+0] = 0xFF * color.r;
44 pixbuf[i*4+1] = 0xFF * color.g;
45 pixbuf[i*4+2] = 0xFF * color.b;
46 pixbuf[i*4+3] = 0xFF * color.a;
54 static bool gCheckBoxButtonState = false;
55 bool CheckBoxButtonClicked( Button button )
57 gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
62 static void Startup();
63 static void Cleanup();
66 void (*tet_startup)() = Startup;
67 void (*tet_cleanup)() = Cleanup;
71 POSITIVE_TC_IDX = 0x01,
74 #define MAX_NUMBER_OF_TESTS 10000
76 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
79 // Add test functionality for all APIs in the class (Positive and Negative)
80 TEST_FUNCTION( UtcDaliCheckBoxButtonSetGetChecked, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliCheckBoxButtonSetImages, POSITIVE_TC_IDX );
83 // Called only once before first test is run.
88 // Called only once after last test is run
93 static void UtcDaliCheckBoxButtonSetGetChecked()
95 ToolkitTestApplication application;
96 tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
98 CheckBoxButton checkBoxButton = CheckBoxButton::New();
99 checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
101 // global var used to check if CheckBoxButtonClicked is called;
102 gCheckBoxButtonState = false;
104 checkBoxButton.SetChecked( true );
106 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
107 DALI_TEST_CHECK( gCheckBoxButtonState );
109 checkBoxButton.SetChecked( false );
111 DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
112 DALI_TEST_CHECK( !gCheckBoxButtonState );
114 checkBoxButton.SetChecked( true );
116 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
117 DALI_TEST_CHECK( gCheckBoxButtonState );
120 static void UtcDaliCheckBoxButtonSetImages()
122 ToolkitTestApplication application;
123 tet_infoline(" UtcDaliCheckBoxButtonSetImages");
127 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
128 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
129 imageActor01.SetSize( 20, 20 );
131 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
132 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
133 imageActor02.SetSize( 40, 40 );
135 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
136 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
137 imageActor03.SetSize( 60, 60 );
139 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
140 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
141 imageActor04.SetSize( 80, 80 );
144 CheckBoxButton checkBoxButton = CheckBoxButton::New();
146 application.SendNotification();
147 application.Render();
149 // Just check if check box button size changes when a bigger image is set.
151 checkBoxButton.SetBackgroundImage( image01 );
153 application.SendNotification();
154 application.Render();
156 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
158 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
159 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
161 checkBoxButton.SetBackgroundImage( imageActor01 );
163 application.SendNotification();
164 application.Render();
166 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
168 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
169 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
171 checkBoxButton.SetCheckedImage( image02 );
173 application.SendNotification();
174 application.Render();
176 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
178 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
179 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
181 checkBoxButton.SetCheckedImage( imageActor02 );
183 application.SendNotification();
184 application.Render();
186 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
188 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
189 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
191 checkBoxButton.SetDimmedBackgroundImage( image03 );
193 application.SendNotification();
194 application.Render();
196 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
198 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
199 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
201 checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
203 application.SendNotification();
204 application.Render();
206 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
208 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
209 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
211 checkBoxButton.SetDimmedCheckedImage( image04 );
213 application.SendNotification();
214 application.Render();
216 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
218 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
219 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
221 checkBoxButton.SetDimmedCheckedImage( imageActor04 );
223 application.SendNotification();
224 application.Render();
226 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
228 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
229 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );