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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
25 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Toolkit;
34 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
36 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
39 PixelBuffer* pixbuf = imageData.GetBuffer();
40 unsigned int size = width * height;
42 for( size_t i = 0; i < size; i++ )
44 pixbuf[i*4+0] = 0xFF * color.r;
45 pixbuf[i*4+1] = 0xFF * color.g;
46 pixbuf[i*4+2] = 0xFF * color.b;
47 pixbuf[i*4+3] = 0xFF * color.a;
55 static bool gCheckBoxButtonState = false;
56 bool CheckBoxButtonClicked( Button button )
58 gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
63 static void Startup();
64 static void Cleanup();
67 void (*tet_startup)() = Startup;
68 void (*tet_cleanup)() = Cleanup;
72 POSITIVE_TC_IDX = 0x01,
75 #define MAX_NUMBER_OF_TESTS 10000
77 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
80 // Add test functionality for all APIs in the class (Positive and Negative)
81 TEST_FUNCTION( UtcDaliCheckBoxButtonSetGetChecked, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliCheckBoxButtonSetImages, POSITIVE_TC_IDX );
84 // Called only once before first test is run.
89 // Called only once after last test is run
94 static void UtcDaliCheckBoxButtonSetGetChecked()
96 ToolkitTestApplication application;
97 tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
99 CheckBoxButton checkBoxButton = CheckBoxButton::New();
100 checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
102 // global var used to check if CheckBoxButtonClicked is called;
103 gCheckBoxButtonState = false;
105 checkBoxButton.SetChecked( true );
107 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
108 DALI_TEST_CHECK( gCheckBoxButtonState );
110 checkBoxButton.SetChecked( false );
112 DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
113 DALI_TEST_CHECK( !gCheckBoxButtonState );
115 checkBoxButton.SetChecked( true );
117 DALI_TEST_CHECK( checkBoxButton.IsChecked() );
118 DALI_TEST_CHECK( gCheckBoxButtonState );
121 static void UtcDaliCheckBoxButtonSetImages()
123 ToolkitTestApplication application;
124 tet_infoline(" UtcDaliCheckBoxButtonSetImages");
128 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
129 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
130 imageActor01.SetSize( 20, 20 );
132 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
133 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
134 imageActor02.SetSize( 40, 40 );
136 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
137 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
138 imageActor03.SetSize( 60, 60 );
140 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
141 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
142 imageActor04.SetSize( 80, 80 );
145 CheckBoxButton checkBoxButton = CheckBoxButton::New();
147 application.SendNotification();
148 application.Render();
150 // Just check if check box button size changes when a bigger image is set.
152 checkBoxButton.SetBackgroundImage( image01 );
154 application.SendNotification();
155 application.Render();
157 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
159 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
160 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
162 checkBoxButton.SetBackgroundImage( imageActor01 );
164 application.SendNotification();
165 application.Render();
167 size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
169 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
170 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
172 checkBoxButton.SetCheckedImage( image02 );
174 application.SendNotification();
175 application.Render();
177 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
179 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
180 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
182 checkBoxButton.SetCheckedImage( imageActor02 );
184 application.SendNotification();
185 application.Render();
187 size = checkBoxButton.GetCheckedImage().GetCurrentSize();
189 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
190 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
192 checkBoxButton.SetDimmedBackgroundImage( image03 );
194 application.SendNotification();
195 application.Render();
197 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
199 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
200 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
202 checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
204 application.SendNotification();
205 application.Render();
207 size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
209 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
210 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
212 checkBoxButton.SetDimmedCheckedImage( image04 );
214 application.SendNotification();
215 application.Render();
217 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
219 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
220 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
222 checkBoxButton.SetDimmedCheckedImage( imageActor04 );
224 application.SendNotification();
225 application.Render();
227 size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
229 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
230 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );