2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
28 #include <dali-toolkit-test-suite-utils.h>
31 using namespace Toolkit;
35 static bool gButtonClicked = false;
37 static bool ButtonClicked( Button button )
39 gButtonClicked = true;
43 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
44 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
45 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
46 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
47 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
48 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
50 static bool gObjectCreatedCallBackCalled;
52 static void TestObjectCreatedCallback(BaseHandle handle)
54 gObjectCreatedCallBackCalled = true;
57 static float ANIMATION_TIME( 0.5f );
60 static void Startup();
61 static void Cleanup();
64 void (*tet_startup)() = Startup;
65 void (*tet_cleanup)() = Cleanup;
68 static void UtcDaliButtonNew();
69 static void UtcDaliButtonSetProperty();
70 static void UtcDaliButtonSetGetDimmed();
71 static void UtcDaliButtonSize();
72 static void UtcDaliButtonClicked();
73 static void UtcDaliButtonConnectSignal();
74 static void UtcDaliButtonSetGetAnimationTime();
77 POSITIVE_TC_IDX = 0x01,
81 // Add test functionality for all APIs in the class (Positive and Negative)
83 struct tet_testlist tet_testlist[] = {
84 { UtcDaliButtonNew, POSITIVE_TC_IDX },
85 { UtcDaliButtonSetProperty, POSITIVE_TC_IDX },
86 { UtcDaliButtonSetGetDimmed, POSITIVE_TC_IDX },
87 { UtcDaliButtonSize, POSITIVE_TC_IDX },
88 { UtcDaliButtonClicked, POSITIVE_TC_IDX },
89 { UtcDaliButtonConnectSignal, POSITIVE_TC_IDX },
90 { UtcDaliButtonSetGetAnimationTime, POSITIVE_TC_IDX },
95 // Called only once before first test is run.
100 // Called only once after last test is run
101 static void Cleanup()
106 // Positive test case for a method
107 static void UtcDaliButtonNew()
109 ToolkitTestApplication application;
110 tet_infoline(" UtcDaliButtonNew");
112 CheckBoxButton checkBoxButton = CheckBoxButton::New();
114 DALI_TEST_CHECK( checkBoxButton );
116 PushButton pushButton = PushButton::New();
118 DALI_TEST_CHECK( pushButton );
120 CheckBoxButton checkBoxButton2( checkBoxButton );
122 DALI_TEST_CHECK( checkBoxButton2 );
124 PushButton pushButton2( pushButton );
126 DALI_TEST_CHECK( pushButton2 );
128 checkBoxButton2 = NULL;
132 //Additional check to ensure object is created by checking if it's registered
133 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
134 DALI_TEST_CHECK( registry );
136 gObjectCreatedCallBackCalled = false;
137 registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
139 CheckBoxButton checkBoxButton = CheckBoxButton::New();
141 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
143 gObjectCreatedCallBackCalled = false;
144 registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
146 PushButton pushButton = PushButton::New();
148 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
152 handleButton = pushButton;
153 Button downCastPushButton = Button::DownCast( handleButton );
154 DALI_TEST_CHECK( downCastPushButton );
155 PushButton downCastPushButton2 = PushButton::DownCast( handleButton );
156 DALI_TEST_CHECK( downCastPushButton2 );
158 handleButton = checkBoxButton;
159 Button downCastCheckBoxButton = Button::DownCast( handleButton );
160 DALI_TEST_CHECK( downCastCheckBoxButton );
161 CheckBoxButton downCastCheckBoxButton2 = CheckBoxButton::DownCast( handleButton );
162 DALI_TEST_CHECK( downCastCheckBoxButton2 );
165 static void UtcDaliButtonSetProperty()
167 tet_infoline("UtcDaliButtonSetProperty: ");
168 ToolkitTestApplication application;
170 CheckBoxButton checkBoxButton = CheckBoxButton::New();
171 PushButton pushButton = PushButton::New();
173 //Test various properties
174 checkBoxButton.SetProperty(checkBoxButton.GetPropertyIndex("dimmed"), false);
175 DALI_TEST_CHECK( false == checkBoxButton.IsDimmed() );
176 checkBoxButton.SetProperty(checkBoxButton.GetPropertyIndex("dimmed"), true);
177 DALI_TEST_CHECK( true == checkBoxButton.IsDimmed() );
179 pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), false);
180 DALI_TEST_CHECK( false == pushButton.IsDimmed() );
181 pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), true);
182 DALI_TEST_CHECK( true == pushButton.IsDimmed() );
185 static void UtcDaliButtonSetGetDimmed()
187 ToolkitTestApplication application;
188 tet_infoline(" UtcDaliButtonSetGetDimmed");
190 CheckBoxButton checkBoxButton = CheckBoxButton::New();
191 PushButton pushButton = PushButton::New();
193 checkBoxButton.SetDimmed( true );
194 pushButton.SetDimmed( true );
196 DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
197 DALI_TEST_CHECK( pushButton.IsDimmed() );
199 checkBoxButton.SetDimmed( false );
200 pushButton.SetDimmed( false );
202 DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
203 DALI_TEST_CHECK( !pushButton.IsDimmed() );
205 checkBoxButton.SetDimmed( true );
206 pushButton.SetDimmed( true );
208 DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
209 DALI_TEST_CHECK( pushButton.IsDimmed() );
211 checkBoxButton.SetDimmed( false );
212 pushButton.SetDimmed( false );
214 DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
215 DALI_TEST_CHECK( !pushButton.IsDimmed() );
218 static void UtcDaliButtonSize()
220 ToolkitTestApplication application;
221 tet_infoline(" UtcDaliButtonSize");
223 // Creates 100x50 images.
224 ImageActor image01 = CreateSolidColorActor( Color::RED );
225 image01.SetSize( 100, 50 );
227 CheckBoxButton checkBoxButton;
228 PushButton pushButton;
232 // Test1 Size is set through Actor API
234 // First an image is set, then SetSize is called.
235 pushButton = PushButton::New();
237 pushButton.SetBackgroundImage( image01 );
238 pushButton.SetSize( 10.f, 10.f );
240 application.SendNotification();
241 application.Render();
243 size = pushButton.GetCurrentSize();
245 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
246 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
249 static void UtcDaliButtonClicked()
251 ToolkitTestApplication application;
252 tet_infoline(" UtcDaliButtonClicked");
254 PushButton pushButton = PushButton::New();
255 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
256 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
257 pushButton.SetPosition( 240, 400 );
258 pushButton.SetSize( 100, 100 );
260 Stage::GetCurrent().Add( pushButton );
262 application.SendNotification();
263 application.Render();
265 // connect to its touch signal
266 pushButton.ClickedSignal().Connect( &ButtonClicked );
268 Dali::Integration::TouchEvent event;
270 // Test1. Touch point down and up inside the button.
272 gButtonClicked = false;
273 event = Dali::Integration::TouchEvent();
274 event.AddPoint( pointDownInside );
275 application.GetCore().SendEvent( event );
277 event = Dali::Integration::TouchEvent();
278 event.AddPoint( pointUpInside );
279 application.GetCore().SendEvent( event );
281 DALI_TEST_CHECK( gButtonClicked );
283 // Test2. Touch point down and up outside the button.
285 gButtonClicked = false;
286 event = Dali::Integration::TouchEvent();
287 event.AddPoint( pointDownOutside );
288 application.GetCore().SendEvent( event );
290 event = Dali::Integration::TouchEvent();
291 event.AddPoint( pointUpOutside );
292 application.GetCore().SendEvent( event );
294 DALI_TEST_CHECK( !gButtonClicked );
296 // Test3. Touch point down inside and up outside the button.
298 gButtonClicked = false;
299 event = Dali::Integration::TouchEvent();
300 event.AddPoint( pointDownInside );
301 application.GetCore().SendEvent( event );
303 event = Dali::Integration::TouchEvent();
304 event.AddPoint( pointLeave );
305 application.GetCore().SendEvent( event );
307 event = Dali::Integration::TouchEvent();
308 event.AddPoint( pointUpOutside );
309 application.GetCore().SendEvent( event );
311 DALI_TEST_CHECK( !gButtonClicked );
313 // Test4. Touch point down outside and up inside the button.
315 gButtonClicked = false;
316 event = Dali::Integration::TouchEvent();
317 event.AddPoint( pointDownOutside );
318 application.GetCore().SendEvent( event );
320 event = Dali::Integration::TouchEvent();
321 event.AddPoint( pointEnter );
322 application.GetCore().SendEvent( event );
324 event = Dali::Integration::TouchEvent();
325 event.AddPoint( pointUpInside );
326 application.GetCore().SendEvent( event );
328 DALI_TEST_CHECK( !gButtonClicked );
331 static bool gClickedCallBackCalled;
333 static bool TestClickedCallback(Button button)
335 gClickedCallBackCalled = true;
339 static void UtcDaliButtonConnectSignal()
341 ToolkitTestApplication application;
342 tet_infoline("UtcDaliButtonConnectSignal()");
344 gClickedCallBackCalled = false;
346 PushButton pushButton = PushButton::New();
347 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
348 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
349 pushButton.SetPosition( 240, 400 );
350 pushButton.SetSize( 100, 100 );
352 Stage::GetCurrent().Add( pushButton );
354 application.SendNotification();
355 application.Render();
357 // connect to its clicked signal
358 pushButton.ClickedSignal().Connect(TestClickedCallback);
360 Dali::Integration::TouchEvent event;
362 // Touch point down and up inside the button.
364 event = Dali::Integration::TouchEvent();
365 event.AddPoint( pointDownInside );
366 application.GetCore().SendEvent( event );
368 event = Dali::Integration::TouchEvent();
369 event.AddPoint( pointUpInside );
370 application.GetCore().SendEvent( event );
372 DALI_TEST_CHECK( gClickedCallBackCalled == true );
374 gClickedCallBackCalled = false;
375 pushButton.ClickedSignal().Disconnect(TestClickedCallback);
377 // simulate another touch event
378 application.GetCore().SendEvent( event );
380 DALI_TEST_CHECK( gClickedCallBackCalled == false );
383 static void UtcDaliButtonSetGetAnimationTime()
385 ToolkitTestApplication application;
386 tet_infoline(" UtcDaliButtonSetGetAnimationTime");
388 CheckBoxButton checkBoxButton = CheckBoxButton::New();
389 PushButton pushButton = PushButton::New();
391 checkBoxButton.SetAnimationTime( ANIMATION_TIME );
392 pushButton.SetAnimationTime( ANIMATION_TIME );
394 DALI_TEST_EQUALS( checkBoxButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
395 DALI_TEST_EQUALS( pushButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );