ec5fcda31cce6a60e1092b5eceb465c3848c0500
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / buttons / utc-Dali-CheckBoxButton.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
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>
25
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 namespace
32 {
33 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
34 {
35   BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
36
37   // Create the image
38   PixelBuffer* pixbuf = imageData.GetBuffer();
39   unsigned int size = width * height;
40
41   for( size_t i = 0; i < size; i++ )
42     {
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;
47     }
48
49   imageData.Update();
50
51   return imageData;
52 }
53
54 static bool gCheckBoxButtonState = false;
55 bool CheckBoxButtonClicked( Button button )
56 {
57   gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
58   return true;
59 }
60 } // namespace
61
62 static void Startup();
63 static void Cleanup();
64
65 extern "C" {
66   void (*tet_startup)() = Startup;
67   void (*tet_cleanup)() = Cleanup;
68 }
69
70 enum {
71   POSITIVE_TC_IDX = 0x01,
72   NEGATIVE_TC_IDX,
73 };
74 #define MAX_NUMBER_OF_TESTS 10000
75 extern "C" {
76   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
77 }
78
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 );
82
83 // Called only once before first test is run.
84 static void Startup()
85 {
86 }
87
88 // Called only once after last test is run
89 static void Cleanup()
90 {
91 }
92
93 static void UtcDaliCheckBoxButtonSetGetChecked()
94 {
95   ToolkitTestApplication application;
96   tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
97
98   CheckBoxButton checkBoxButton = CheckBoxButton::New();
99   checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
100
101   // global var used to check if CheckBoxButtonClicked is called;
102   gCheckBoxButtonState = false;
103
104   checkBoxButton.SetChecked( true );
105
106   DALI_TEST_CHECK( checkBoxButton.IsChecked() );
107   DALI_TEST_CHECK( gCheckBoxButtonState );
108
109   checkBoxButton.SetChecked( false );
110
111   DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
112   DALI_TEST_CHECK( !gCheckBoxButtonState );
113
114   checkBoxButton.SetChecked( true );
115
116   DALI_TEST_CHECK( checkBoxButton.IsChecked() );
117   DALI_TEST_CHECK( gCheckBoxButtonState );
118 }
119
120 static void UtcDaliCheckBoxButtonSetImages()
121 {
122   ToolkitTestApplication application;
123   tet_infoline(" UtcDaliCheckBoxButtonSetImages");
124
125   Actor imageActor;
126
127   Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
128   ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
129   imageActor01.SetSize( 20, 20 );
130
131   Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
132   ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
133   imageActor02.SetSize( 40, 40 );
134
135   Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
136   ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
137   imageActor03.SetSize( 60, 60 );
138
139   Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
140   ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
141   imageActor04.SetSize( 80, 80 );
142
143   Vector3 size;
144   CheckBoxButton checkBoxButton = CheckBoxButton::New();
145
146   application.SendNotification();
147   application.Render();
148
149   // Just check if check box button size changes when a bigger image is set.
150
151   checkBoxButton.SetBackgroundImage( image01 );
152
153   application.SendNotification();
154   application.Render();
155
156   size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
157
158   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
159   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
160
161   checkBoxButton.SetBackgroundImage( imageActor01 );
162
163   application.SendNotification();
164   application.Render();
165
166   size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
167
168   DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
169   DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
170
171   checkBoxButton.SetCheckedImage( image02 );
172
173   application.SendNotification();
174   application.Render();
175
176   size = checkBoxButton.GetCheckedImage().GetCurrentSize();
177
178   DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
179   DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
180
181   checkBoxButton.SetCheckedImage( imageActor02 );
182
183   application.SendNotification();
184   application.Render();
185
186   size = checkBoxButton.GetCheckedImage().GetCurrentSize();
187
188   DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
189   DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
190
191   checkBoxButton.SetDimmedBackgroundImage( image03 );
192
193   application.SendNotification();
194   application.Render();
195
196   size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
197
198   DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
199   DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
200
201   checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
202
203   application.SendNotification();
204   application.Render();
205
206   size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
207
208   DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
209   DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
210
211   checkBoxButton.SetDimmedCheckedImage( image04 );
212
213   application.SendNotification();
214   application.Render();
215
216   size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
217
218   DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
219   DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
220
221   checkBoxButton.SetDimmedCheckedImage( imageActor04 );
222
223   application.SendNotification();
224   application.Render();
225
226   size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
227
228   DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
229   DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
230 }