2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
29 #include <dali-toolkit-test-suite-utils.h>
32 using namespace Toolkit;
36 static bool gButtonClicked = false;
38 static bool ButtonClicked( Button button )
40 gButtonClicked = true;
44 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
45 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
46 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
47 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
48 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
49 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
51 static bool gObjectCreatedCallBackCalled;
53 static void TestObjectCreatedCallback(BaseHandle handle)
55 gObjectCreatedCallBackCalled = true;
58 static float ANIMATION_TIME( 0.5f );
61 static void Startup();
62 static void Cleanup();
65 void (*tet_startup)() = Startup;
66 void (*tet_cleanup)() = Cleanup;
70 POSITIVE_TC_IDX = 0x01,
74 #define MAX_NUMBER_OF_TESTS 10000
76 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
79 // Add test functionality for all APIs in the class (Positive and Negative)
80 TEST_FUNCTION( UtcDaliButtonNew, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliButtonProperties, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliButtonSetGetDimmed, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliButtonSize, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliButtonClicked, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliButtonConnectSignal, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliButtonSetGetAnimationTime, POSITIVE_TC_IDX );
88 // Called only once before first test is run.
93 // Called only once after last test is run
99 // Positive test case for a method
100 static void UtcDaliButtonNew()
102 ToolkitTestApplication application;
103 tet_infoline(" UtcDaliButtonNew");
105 CheckBoxButton checkBoxButton = CheckBoxButton::New();
107 DALI_TEST_CHECK( checkBoxButton );
109 PushButton pushButton = PushButton::New();
111 DALI_TEST_CHECK( pushButton );
113 CheckBoxButton checkBoxButton2( checkBoxButton );
115 DALI_TEST_CHECK( checkBoxButton2 );
117 PushButton pushButton2( pushButton );
119 DALI_TEST_CHECK( pushButton2 );
121 checkBoxButton2 = NULL;
125 //Additional check to ensure object is created by checking if it's registered
126 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
127 DALI_TEST_CHECK( registry );
129 gObjectCreatedCallBackCalled = false;
130 registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
132 CheckBoxButton checkBoxButton = CheckBoxButton::New();
134 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
136 gObjectCreatedCallBackCalled = false;
137 registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
139 PushButton pushButton = PushButton::New();
141 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
145 handleButton = pushButton;
146 Button downCastPushButton = Button::DownCast( handleButton );
147 DALI_TEST_CHECK( downCastPushButton );
148 PushButton downCastPushButton2 = PushButton::DownCast( handleButton );
149 DALI_TEST_CHECK( downCastPushButton2 );
151 handleButton = checkBoxButton;
152 Button downCastCheckBoxButton = Button::DownCast( handleButton );
153 DALI_TEST_CHECK( downCastCheckBoxButton );
154 CheckBoxButton downCastCheckBoxButton2 = CheckBoxButton::DownCast( handleButton );
155 DALI_TEST_CHECK( downCastCheckBoxButton2 );
158 static void UtcDaliButtonProperties()
160 tet_infoline("UtcDaliButtonSetProperty: ");
161 ToolkitTestApplication application;
163 CheckBoxButton checkBoxButton = CheckBoxButton::New();
164 PushButton pushButton = PushButton::New();
166 //Test various properties
167 checkBoxButton.SetProperty( Button::PROPERTY_DIMMED, false );
168 DALI_TEST_CHECK( false == checkBoxButton.IsDimmed() );
169 DALI_TEST_CHECK( false == checkBoxButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) );
170 checkBoxButton.SetProperty( Button::PROPERTY_DIMMED, true );
171 DALI_TEST_CHECK( true == checkBoxButton.IsDimmed() );
172 DALI_TEST_CHECK( true == checkBoxButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) );
174 pushButton.SetProperty( Button::PROPERTY_DIMMED, false );
175 DALI_TEST_CHECK( false == pushButton.IsDimmed() );
176 DALI_TEST_CHECK( false == pushButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) );
177 pushButton.SetProperty( Button::PROPERTY_DIMMED, true );
178 DALI_TEST_CHECK( true == pushButton.IsDimmed() );
179 DALI_TEST_CHECK( true == pushButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) );
182 static void UtcDaliButtonSetGetDimmed()
184 ToolkitTestApplication application;
185 tet_infoline(" UtcDaliButtonSetGetDimmed");
187 CheckBoxButton checkBoxButton = CheckBoxButton::New();
188 PushButton pushButton = PushButton::New();
190 checkBoxButton.SetDimmed( true );
191 pushButton.SetDimmed( true );
193 DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
194 DALI_TEST_CHECK( pushButton.IsDimmed() );
196 checkBoxButton.SetDimmed( false );
197 pushButton.SetDimmed( false );
199 DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
200 DALI_TEST_CHECK( !pushButton.IsDimmed() );
202 checkBoxButton.SetDimmed( true );
203 pushButton.SetDimmed( true );
205 DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
206 DALI_TEST_CHECK( pushButton.IsDimmed() );
208 checkBoxButton.SetDimmed( false );
209 pushButton.SetDimmed( false );
211 DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
212 DALI_TEST_CHECK( !pushButton.IsDimmed() );
215 static void UtcDaliButtonSize()
217 ToolkitTestApplication application;
218 tet_infoline(" UtcDaliButtonSize");
220 // Creates 100x50 images.
221 ImageActor image01 = CreateSolidColorActor( Color::RED );
222 image01.SetSize( 100, 50 );
224 CheckBoxButton checkBoxButton;
225 PushButton pushButton;
229 // Test1 Size is set through Actor API
231 // First an image is set, then SetSize is called.
232 pushButton = PushButton::New();
234 pushButton.SetBackgroundImage( image01 );
235 pushButton.SetSize( 10.f, 10.f );
237 application.SendNotification();
238 application.Render();
240 size = pushButton.GetCurrentSize();
242 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
243 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
246 static void UtcDaliButtonClicked()
248 ToolkitTestApplication application;
249 tet_infoline(" UtcDaliButtonClicked");
251 PushButton pushButton = PushButton::New();
252 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
253 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
254 pushButton.SetPosition( 240, 400 );
255 pushButton.SetSize( 100, 100 );
257 Stage::GetCurrent().Add( pushButton );
259 application.SendNotification();
260 application.Render();
262 // connect to its touch signal
263 pushButton.ClickedSignal().Connect( &ButtonClicked );
265 Dali::Integration::TouchEvent event;
267 // Test1. Touch point down and up inside the button.
269 gButtonClicked = false;
270 event = Dali::Integration::TouchEvent();
271 event.AddPoint( pointDownInside );
272 application.ProcessEvent( event );
274 event = Dali::Integration::TouchEvent();
275 event.AddPoint( pointUpInside );
276 application.ProcessEvent( event );
278 DALI_TEST_CHECK( gButtonClicked );
280 // Test2. Touch point down and up outside the button.
282 gButtonClicked = false;
283 event = Dali::Integration::TouchEvent();
284 event.AddPoint( pointDownOutside );
285 application.ProcessEvent( event );
287 event = Dali::Integration::TouchEvent();
288 event.AddPoint( pointUpOutside );
289 application.ProcessEvent( event );
291 DALI_TEST_CHECK( !gButtonClicked );
293 // Test3. Touch point down inside and up outside the button.
295 gButtonClicked = false;
296 event = Dali::Integration::TouchEvent();
297 event.AddPoint( pointDownInside );
298 application.ProcessEvent( event );
300 event = Dali::Integration::TouchEvent();
301 event.AddPoint( pointLeave );
302 application.ProcessEvent( event );
304 event = Dali::Integration::TouchEvent();
305 event.AddPoint( pointUpOutside );
306 application.ProcessEvent( event );
308 DALI_TEST_CHECK( !gButtonClicked );
310 // Test4. Touch point down outside and up inside the button.
312 gButtonClicked = false;
313 event = Dali::Integration::TouchEvent();
314 event.AddPoint( pointDownOutside );
315 application.ProcessEvent( event );
317 event = Dali::Integration::TouchEvent();
318 event.AddPoint( pointEnter );
319 application.ProcessEvent( event );
321 event = Dali::Integration::TouchEvent();
322 event.AddPoint( pointUpInside );
323 application.ProcessEvent( event );
325 DALI_TEST_CHECK( !gButtonClicked );
328 static bool gClickedCallBackCalled;
330 static bool TestClickedCallback(Button button)
332 gClickedCallBackCalled = true;
336 static void UtcDaliButtonConnectSignal()
338 ToolkitTestApplication application;
339 tet_infoline("UtcDaliButtonConnectSignal()");
341 gClickedCallBackCalled = false;
343 PushButton pushButton = PushButton::New();
344 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
345 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
346 pushButton.SetPosition( 240, 400 );
347 pushButton.SetSize( 100, 100 );
349 Stage::GetCurrent().Add( pushButton );
351 application.SendNotification();
352 application.Render();
354 // connect to its clicked signal
355 pushButton.ClickedSignal().Connect(TestClickedCallback);
357 Dali::Integration::TouchEvent event;
359 // Touch point down and up inside the button.
361 event = Dali::Integration::TouchEvent();
362 event.AddPoint( pointDownInside );
363 application.ProcessEvent( event );
365 event = Dali::Integration::TouchEvent();
366 event.AddPoint( pointUpInside );
367 application.ProcessEvent( event );
369 DALI_TEST_CHECK( gClickedCallBackCalled == true );
371 gClickedCallBackCalled = false;
372 pushButton.ClickedSignal().Disconnect(TestClickedCallback);
374 // simulate another touch event
375 application.ProcessEvent( event );
377 DALI_TEST_CHECK( gClickedCallBackCalled == false );
380 static void UtcDaliButtonSetGetAnimationTime()
382 ToolkitTestApplication application;
383 tet_infoline(" UtcDaliButtonSetGetAnimationTime");
385 CheckBoxButton checkBoxButton = CheckBoxButton::New();
386 PushButton pushButton = PushButton::New();
388 checkBoxButton.SetAnimationTime( ANIMATION_TIME );
389 pushButton.SetAnimationTime( ANIMATION_TIME );
391 DALI_TEST_EQUALS( checkBoxButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
392 DALI_TEST_EQUALS( pushButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );