(StyleManager) Add style monitor signal into StyleManager
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Button.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
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
23
24 #include <dali.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31
32 void utc_dali_toolkit_button_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_button_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44 static bool gButtonClicked = false;
45
46 static bool ButtonClicked( Button button )
47 {
48   gButtonClicked = true;
49   return false;
50 }
51
52 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
53 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
54 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
55 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
56 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
57 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
58
59 static float ANIMATION_TIME( 0.5f );
60 } // namespace
61
62
63
64 // Positive test case for a method
65 int UtcDaliButtonNew(void)
66 {
67   ToolkitTestApplication application;
68   tet_infoline(" UtcDaliButtonNew");
69
70   PushButton pushButton = PushButton::New();
71
72   DALI_TEST_CHECK( pushButton );
73
74   PushButton pushButton2( pushButton );
75
76   DALI_TEST_CHECK( pushButton2 );
77
78    pushButton2 = NULL;
79
80   // Test down cast
81   Handle handleButton;
82   handleButton = pushButton;
83   Button downCastPushButton = Button::DownCast( handleButton );
84   DALI_TEST_CHECK( downCastPushButton );
85   PushButton downCastPushButton2 = PushButton::DownCast( handleButton );
86   DALI_TEST_CHECK( downCastPushButton2 );
87
88   END_TEST;
89 }
90
91 int UtcDaliButtonSetProperty(void)
92 {
93   tet_infoline("UtcDaliButtonSetProperty: ");
94   ToolkitTestApplication application;
95
96   PushButton pushButton = PushButton::New();
97
98   pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), false);
99   DALI_TEST_CHECK( false == pushButton.IsDimmed() );
100   pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), true);
101   DALI_TEST_CHECK( true == pushButton.IsDimmed() );
102   END_TEST;
103 }
104
105 int UtcDaliButtonSetGetDimmed(void)
106 {
107   ToolkitTestApplication application;
108   tet_infoline(" UtcDaliButtonSetGetDimmed");
109
110   PushButton pushButton = PushButton::New();
111
112   pushButton.SetDimmed( true );
113
114   DALI_TEST_CHECK( pushButton.IsDimmed() );
115
116   pushButton.SetDimmed( false );
117
118   DALI_TEST_CHECK( !pushButton.IsDimmed() );
119
120   pushButton.SetDimmed( true );
121
122   DALI_TEST_CHECK( pushButton.IsDimmed() );
123
124   pushButton.SetDimmed( false );
125
126   DALI_TEST_CHECK( !pushButton.IsDimmed() );
127   END_TEST;
128 }
129
130 int UtcDaliButtonSize(void)
131 {
132   ToolkitTestApplication application;
133   tet_infoline(" UtcDaliButtonSize");
134
135   ImageActor image01 = ImageActor::New(CreateBitmapImage());
136   image01.SetSize( 100, 50 );
137
138   PushButton pushButton;
139
140   Vector3 size;
141
142   // Test1 Size is set through Actor API
143
144   // First an image is set, then SetSize is called.
145   pushButton = PushButton::New();
146
147   pushButton.SetBackgroundImage( image01 );
148   pushButton.SetSize( 10.f, 10.f );
149
150   application.SendNotification();
151   application.Render();
152
153   size = pushButton.GetCurrentSize();
154
155   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
156   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
157   END_TEST;
158 }
159
160 int UtcDaliButtonClicked(void)
161 {
162   ToolkitTestApplication application;
163   tet_infoline(" UtcDaliButtonClicked");
164
165   PushButton pushButton = PushButton::New();
166   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
167   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
168   pushButton.SetPosition( 240, 400 );
169   pushButton.SetSize( 100, 100 );
170
171   Stage::GetCurrent().Add( pushButton );
172
173   application.SendNotification();
174   application.Render();
175
176   // connect to its touch signal
177   pushButton.ClickedSignal().Connect( &ButtonClicked );
178
179   Dali::Integration::TouchEvent event;
180
181   // Test1. Touch point down and up inside the button.
182
183   gButtonClicked = false;
184   event = Dali::Integration::TouchEvent();
185   event.AddPoint( pointDownInside );
186   application.ProcessEvent( event );
187
188   event = Dali::Integration::TouchEvent();
189   event.AddPoint( pointUpInside );
190   application.ProcessEvent( event );
191
192   DALI_TEST_CHECK( gButtonClicked );
193
194   // Test2. Touch point down and up outside the button.
195
196   gButtonClicked = false;
197   event = Dali::Integration::TouchEvent();
198   event.AddPoint( pointDownOutside );
199   application.ProcessEvent( event );
200
201   event = Dali::Integration::TouchEvent();
202   event.AddPoint( pointUpOutside );
203   application.ProcessEvent( event );
204
205   DALI_TEST_CHECK( !gButtonClicked );
206
207   // Test3. Touch point down inside and up outside the button.
208
209   gButtonClicked = false;
210   event = Dali::Integration::TouchEvent();
211   event.AddPoint( pointDownInside );
212   application.ProcessEvent( event );
213
214   event = Dali::Integration::TouchEvent();
215   event.AddPoint( pointLeave );
216   application.ProcessEvent( event );
217
218   event = Dali::Integration::TouchEvent();
219   event.AddPoint( pointUpOutside );
220   application.ProcessEvent( event );
221
222   DALI_TEST_CHECK( !gButtonClicked );
223
224   // Test4. Touch point down outside and up inside the button.
225
226   gButtonClicked = false;
227   event = Dali::Integration::TouchEvent();
228   event.AddPoint( pointDownOutside );
229   application.ProcessEvent( event );
230
231   event = Dali::Integration::TouchEvent();
232   event.AddPoint( pointEnter );
233   application.ProcessEvent( event );
234
235   event = Dali::Integration::TouchEvent();
236   event.AddPoint( pointUpInside );
237   application.ProcessEvent( event );
238
239   DALI_TEST_CHECK( !gButtonClicked );
240   END_TEST;
241 }
242
243 namespace
244 {
245
246 static bool gClickedCallBackCalled;
247
248 static bool TestClickedCallback(Button button)
249 {
250   gClickedCallBackCalled = true;
251   return true;
252 }
253
254 } // namespace
255
256 int UtcDaliButtonConnectSignal(void)
257 {
258   ToolkitTestApplication application;
259   tet_infoline("UtcDaliButtonConnectSignal()");
260
261   gClickedCallBackCalled = false;
262
263   PushButton pushButton = PushButton::New();
264   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
265   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
266   pushButton.SetPosition( 240, 400 );
267   pushButton.SetSize( 100, 100 );
268
269   Stage::GetCurrent().Add( pushButton );
270
271   application.SendNotification();
272   application.Render();
273
274   // connect to its clicked signal
275   pushButton.ClickedSignal().Connect(TestClickedCallback);
276
277   Dali::Integration::TouchEvent event;
278
279   // Touch point down and up inside the button.
280
281   event = Dali::Integration::TouchEvent();
282   event.AddPoint( pointDownInside );
283   application.ProcessEvent( event );
284
285   event = Dali::Integration::TouchEvent();
286   event.AddPoint( pointUpInside );
287   application.ProcessEvent( event );
288
289   DALI_TEST_CHECK( gClickedCallBackCalled == true );
290
291   gClickedCallBackCalled = false;
292   pushButton.ClickedSignal().Disconnect(TestClickedCallback);
293
294   // simulate another touch event
295   application.ProcessEvent( event );
296
297   DALI_TEST_CHECK( gClickedCallBackCalled == false );
298   END_TEST;
299 }
300
301 int UtcDaliButtonSetGetAnimationTime(void)
302 {
303   ToolkitTestApplication application;
304   tet_infoline(" UtcDaliButtonSetGetAnimationTime");
305
306   PushButton pushButton = PushButton::New();
307
308   pushButton.SetAnimationTime( ANIMATION_TIME );
309
310   DALI_TEST_EQUALS( pushButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
311
312   END_TEST;
313 }