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