Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / 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 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21
22 using namespace Dali;
23 using namespace Toolkit;
24
25 namespace
26 {
27
28 static bool gCheckBoxButtonState = false;
29 bool CheckBoxButtonClicked( Button button )
30 {
31   gCheckBoxButtonState = static_cast<CheckBoxButton&>( button ).IsChecked();
32   return true;
33 }
34
35
36
37 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
38 {
39   BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
40
41   // Create the image
42   PixelBuffer* pixbuf = imageData.GetBuffer();
43   unsigned int size = width * height;
44
45   for( size_t i = 0; i < size; i++ )
46     {
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;
51     }
52
53   imageData.Update();
54
55   return imageData;
56 }
57
58 } // namespace
59
60
61 void checkbox_button_startup(void)
62 {
63   test_return_value = TET_UNDEF;
64 }
65
66 void checkbox_button_cleanup(void)
67 {
68   test_return_value = TET_PASS;
69 }
70
71 int UtcDaliCheckBoxButtonSetGetChecked(void)
72 {
73   ToolkitTestApplication application;
74   tet_infoline(" UtcDaliCheckBoxButtonSetGetChecked");
75
76   CheckBoxButton checkBoxButton = CheckBoxButton::New();
77   checkBoxButton.ClickedSignal().Connect( &CheckBoxButtonClicked );
78
79   // global var used to check if CheckBoxButtonClicked is called;
80   gCheckBoxButtonState = false;
81
82   checkBoxButton.SetChecked( true );
83
84   DALI_TEST_CHECK( checkBoxButton.IsChecked() );
85   DALI_TEST_CHECK( gCheckBoxButtonState );
86
87   checkBoxButton.SetChecked( false );
88
89   DALI_TEST_CHECK( !checkBoxButton.IsChecked() );
90   DALI_TEST_CHECK( !gCheckBoxButtonState );
91
92   checkBoxButton.SetChecked( true );
93
94   DALI_TEST_CHECK( checkBoxButton.IsChecked() );
95   DALI_TEST_CHECK( gCheckBoxButtonState );
96   END_TEST;
97 }
98
99 int UtcDaliCheckBoxButtonSetImages(void)
100 {
101   ToolkitTestApplication application;
102   tet_infoline(" UtcDaliCheckBoxButtonSetImages");
103
104   Actor imageActor;
105
106   Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
107   ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
108   imageActor01.SetSize( 20, 20 );
109
110   Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
111   ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
112   imageActor02.SetSize( 40, 40 );
113
114   Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
115   ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
116   imageActor03.SetSize( 60, 60 );
117
118   Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
119   ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
120   imageActor04.SetSize( 80, 80 );
121
122   Vector3 size;
123   CheckBoxButton checkBoxButton = CheckBoxButton::New();
124
125   application.SendNotification();
126   application.Render();
127
128   // Just check if check box button size changes when a bigger image is set.
129
130   checkBoxButton.SetBackgroundImage( image01 );
131
132   application.SendNotification();
133   application.Render();
134
135   size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
136
137   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
138   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
139
140   checkBoxButton.SetBackgroundImage( imageActor01 );
141
142   application.SendNotification();
143   application.Render();
144
145   size = checkBoxButton.GetBackgroundImage().GetCurrentSize();
146
147   DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
148   DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
149
150   checkBoxButton.SetCheckedImage( image02 );
151
152   application.SendNotification();
153   application.Render();
154
155   size = checkBoxButton.GetCheckedImage().GetCurrentSize();
156
157   DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
158   DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
159
160   checkBoxButton.SetCheckedImage( imageActor02 );
161
162   application.SendNotification();
163   application.Render();
164
165   size = checkBoxButton.GetCheckedImage().GetCurrentSize();
166
167   DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
168   DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
169
170   checkBoxButton.SetDimmedBackgroundImage( image03 );
171
172   application.SendNotification();
173   application.Render();
174
175   size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
176
177   DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
178   DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
179
180   checkBoxButton.SetDimmedBackgroundImage( imageActor03 );
181
182   application.SendNotification();
183   application.Render();
184
185   size = checkBoxButton.GetDimmedBackgroundImage().GetCurrentSize();
186
187   DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
188   DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
189
190   checkBoxButton.SetDimmedCheckedImage( image04 );
191
192   application.SendNotification();
193   application.Render();
194
195   size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
196
197   DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
198   DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
199
200   checkBoxButton.SetDimmedCheckedImage( imageActor04 );
201
202   application.SendNotification();
203   application.Render();
204
205   size = checkBoxButton.GetDimmedCheckedImage().GetCurrentSize();
206
207   DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
208   DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
209   END_TEST;
210 }