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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
30 using namespace Toolkit;
33 void utc_dali_toolkit_button_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_button_cleanup(void)
40 test_return_value = TET_PASS;
45 static bool gButtonClicked = false;
47 static bool ButtonClicked( Button button )
49 gButtonClicked = true;
53 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
54 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
55 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
56 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
57 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
58 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
60 static float ANIMATION_TIME( 0.5f );
65 // Positive test case for a method
66 int UtcDaliButtonNew(void)
68 ToolkitTestApplication application;
69 tet_infoline(" UtcDaliButtonNew");
71 PushButton pushButton = PushButton::New();
73 DALI_TEST_CHECK( pushButton );
75 PushButton pushButton2( pushButton );
77 DALI_TEST_CHECK( pushButton2 );
83 handleButton = pushButton;
84 Button downCastPushButton = Button::DownCast( handleButton );
85 DALI_TEST_CHECK( downCastPushButton );
86 PushButton downCastPushButton2 = PushButton::DownCast( handleButton );
87 DALI_TEST_CHECK( downCastPushButton2 );
92 int UtcDaliButtonSetProperty(void)
94 tet_infoline("UtcDaliButtonSetProperty: ");
95 ToolkitTestApplication application;
97 PushButton pushButton = PushButton::New();
99 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
100 DALI_TEST_CHECK( false == pushButton.IsDisabled() );
101 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
102 DALI_TEST_CHECK( true == pushButton.IsDisabled() );
106 int UtcDaliButtonSetGetDimmed(void)
108 ToolkitTestApplication application;
109 tet_infoline(" UtcDaliButtonSetGetDimmed");
111 PushButton pushButton = PushButton::New();
113 pushButton.SetDisabled( true );
115 DALI_TEST_CHECK( pushButton.IsDisabled() );
117 pushButton.SetDisabled( false );
119 DALI_TEST_CHECK( !pushButton.IsDisabled() );
121 pushButton.SetDisabled( true );
123 DALI_TEST_CHECK( pushButton.IsDisabled() );
125 pushButton.SetDisabled( false );
127 DALI_TEST_CHECK( !pushButton.IsDisabled() );
131 int UtcDaliButtonSize(void)
133 ToolkitTestApplication application;
134 tet_infoline(" UtcDaliButtonSize");
136 ImageActor image01 = ImageActor::New(CreateBufferImage());
137 image01.SetSize( 100, 50 );
139 PushButton pushButton;
143 // Test1 Size is set through Actor API
145 // First an image is set, then SetSize is called.
146 pushButton = PushButton::New();
148 pushButton.SetBackgroundImage( image01 );
149 pushButton.SetSize( 10.f, 10.f );
151 application.SendNotification();
152 application.Render();
154 size = pushButton.GetCurrentSize();
156 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
157 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
161 int UtcDaliButtonClicked(void)
163 ToolkitTestApplication application;
164 tet_infoline(" UtcDaliButtonClicked");
166 PushButton pushButton = PushButton::New();
167 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
168 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
169 pushButton.SetPosition( 240, 400 );
170 pushButton.SetSize( 100, 100 );
172 Stage::GetCurrent().Add( pushButton );
174 application.SendNotification();
175 application.Render();
177 // connect to its touch signal
178 pushButton.ClickedSignal().Connect( &ButtonClicked );
180 Dali::Integration::TouchEvent event;
182 // Test1. Touch point down and up inside the button.
184 gButtonClicked = false;
185 event = Dali::Integration::TouchEvent();
186 event.AddPoint( pointDownInside );
187 application.ProcessEvent( event );
189 event = Dali::Integration::TouchEvent();
190 event.AddPoint( pointUpInside );
191 application.ProcessEvent( event );
193 DALI_TEST_CHECK( gButtonClicked );
195 // Test2. Touch point down and up outside the button.
197 gButtonClicked = false;
198 event = Dali::Integration::TouchEvent();
199 event.AddPoint( pointDownOutside );
200 application.ProcessEvent( event );
202 event = Dali::Integration::TouchEvent();
203 event.AddPoint( pointUpOutside );
204 application.ProcessEvent( event );
206 DALI_TEST_CHECK( !gButtonClicked );
208 // Test3. Touch point down inside and up outside the button.
210 gButtonClicked = false;
211 event = Dali::Integration::TouchEvent();
212 event.AddPoint( pointDownInside );
213 application.ProcessEvent( event );
215 event = Dali::Integration::TouchEvent();
216 event.AddPoint( pointLeave );
217 application.ProcessEvent( event );
219 event = Dali::Integration::TouchEvent();
220 event.AddPoint( pointUpOutside );
221 application.ProcessEvent( event );
223 DALI_TEST_CHECK( !gButtonClicked );
225 // Test4. Touch point down outside and up inside the button.
227 gButtonClicked = false;
228 event = Dali::Integration::TouchEvent();
229 event.AddPoint( pointDownOutside );
230 application.ProcessEvent( event );
232 event = Dali::Integration::TouchEvent();
233 event.AddPoint( pointEnter );
234 application.ProcessEvent( event );
236 event = Dali::Integration::TouchEvent();
237 event.AddPoint( pointUpInside );
238 application.ProcessEvent( event );
240 DALI_TEST_CHECK( !gButtonClicked );
247 static bool gClickedCallBackCalled;
249 static bool TestClickedCallback(Button button)
251 gClickedCallBackCalled = true;
257 int UtcDaliButtonConnectSignal(void)
259 ToolkitTestApplication application;
260 tet_infoline("UtcDaliButtonConnectSignal()");
262 gClickedCallBackCalled = false;
264 PushButton pushButton = PushButton::New();
265 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
266 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
267 pushButton.SetPosition( 240, 400 );
268 pushButton.SetSize( 100, 100 );
270 Stage::GetCurrent().Add( pushButton );
272 application.SendNotification();
273 application.Render();
275 // connect to its clicked signal
276 pushButton.ClickedSignal().Connect(TestClickedCallback);
278 Dali::Integration::TouchEvent event;
280 // Touch point down and up inside the button.
282 event = Dali::Integration::TouchEvent();
283 event.AddPoint( pointDownInside );
284 application.ProcessEvent( event );
286 event = Dali::Integration::TouchEvent();
287 event.AddPoint( pointUpInside );
288 application.ProcessEvent( event );
290 DALI_TEST_CHECK( gClickedCallBackCalled == true );
292 gClickedCallBackCalled = false;
293 pushButton.ClickedSignal().Disconnect(TestClickedCallback);
295 // simulate another touch event
296 application.ProcessEvent( event );
298 DALI_TEST_CHECK( gClickedCallBackCalled == false );
302 int UtcDaliButtonSetGetAnimationTime(void)
304 ToolkitTestApplication application;
305 tet_infoline(" UtcDaliButtonSetGetAnimationTime");
307 PushButton pushButton = PushButton::New();
309 pushButton.SetAnimationTime( ANIMATION_TIME );
311 DALI_TEST_EQUALS( pushButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );