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();
147 Stage::GetCurrent().Add( pushButton );
149 pushButton.SetBackgroundImage( image01 );
150 pushButton.SetSize( 10.f, 10.f );
152 application.SendNotification();
153 application.Render();
155 size = pushButton.GetCurrentSize();
157 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
158 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
162 int UtcDaliButtonClicked(void)
164 ToolkitTestApplication application;
165 tet_infoline(" UtcDaliButtonClicked");
167 PushButton pushButton = PushButton::New();
168 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
169 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
170 pushButton.SetPosition( 240, 400 );
171 pushButton.SetSize( 100, 100 );
173 Stage::GetCurrent().Add( pushButton );
175 application.SendNotification();
176 application.Render();
178 // connect to its touch signal
179 pushButton.ClickedSignal().Connect( &ButtonClicked );
181 Dali::Integration::TouchEvent event;
183 // Test1. Touch point down and up inside the button.
185 gButtonClicked = false;
186 event = Dali::Integration::TouchEvent();
187 event.AddPoint( pointDownInside );
188 application.ProcessEvent( event );
190 event = Dali::Integration::TouchEvent();
191 event.AddPoint( pointUpInside );
192 application.ProcessEvent( event );
194 DALI_TEST_CHECK( gButtonClicked );
196 // Test2. Touch point down and up outside the button.
198 gButtonClicked = false;
199 event = Dali::Integration::TouchEvent();
200 event.AddPoint( pointDownOutside );
201 application.ProcessEvent( event );
203 event = Dali::Integration::TouchEvent();
204 event.AddPoint( pointUpOutside );
205 application.ProcessEvent( event );
207 DALI_TEST_CHECK( !gButtonClicked );
209 // Test3. Touch point down inside and up outside the button.
211 gButtonClicked = false;
212 event = Dali::Integration::TouchEvent();
213 event.AddPoint( pointDownInside );
214 application.ProcessEvent( event );
216 event = Dali::Integration::TouchEvent();
217 event.AddPoint( pointLeave );
218 application.ProcessEvent( event );
220 event = Dali::Integration::TouchEvent();
221 event.AddPoint( pointUpOutside );
222 application.ProcessEvent( event );
224 DALI_TEST_CHECK( !gButtonClicked );
226 // Test4. Touch point down outside and up inside the button.
228 gButtonClicked = false;
229 event = Dali::Integration::TouchEvent();
230 event.AddPoint( pointDownOutside );
231 application.ProcessEvent( event );
233 event = Dali::Integration::TouchEvent();
234 event.AddPoint( pointEnter );
235 application.ProcessEvent( event );
237 event = Dali::Integration::TouchEvent();
238 event.AddPoint( pointUpInside );
239 application.ProcessEvent( event );
241 DALI_TEST_CHECK( !gButtonClicked );
248 static bool gClickedCallBackCalled;
250 static bool TestClickedCallback(Button button)
252 gClickedCallBackCalled = true;
258 int UtcDaliButtonConnectSignal(void)
260 ToolkitTestApplication application;
261 tet_infoline("UtcDaliButtonConnectSignal()");
263 gClickedCallBackCalled = false;
265 PushButton pushButton = PushButton::New();
266 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
267 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
268 pushButton.SetPosition( 240, 400 );
269 pushButton.SetSize( 100, 100 );
271 Stage::GetCurrent().Add( pushButton );
273 application.SendNotification();
274 application.Render();
276 // connect to its clicked signal
277 pushButton.ClickedSignal().Connect(TestClickedCallback);
279 Dali::Integration::TouchEvent event;
281 // Touch point down and up inside the button.
283 event = Dali::Integration::TouchEvent();
284 event.AddPoint( pointDownInside );
285 application.ProcessEvent( event );
287 event = Dali::Integration::TouchEvent();
288 event.AddPoint( pointUpInside );
289 application.ProcessEvent( event );
291 DALI_TEST_CHECK( gClickedCallBackCalled == true );
293 gClickedCallBackCalled = false;
294 pushButton.ClickedSignal().Disconnect(TestClickedCallback);
296 // simulate another touch event
297 application.ProcessEvent( event );
299 DALI_TEST_CHECK( gClickedCallBackCalled == false );
303 int UtcDaliButtonSetGetAnimationTime(void)
305 ToolkitTestApplication application;
306 tet_infoline(" UtcDaliButtonSetGetAnimationTime");
308 PushButton pushButton = PushButton::New();
310 pushButton.SetAnimationTime( ANIMATION_TIME );
312 DALI_TEST_EQUALS( pushButton.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );