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 "dummy-control.h"
30 using namespace Dali::Toolkit;
32 void utc_dali_toolkit_control_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_control_cleanup(void)
39 test_return_value = TET_PASS;
42 ///////////////////////////////////////////////////////////////////////////////////////////////////
47 bool gObjectCreatedCallBackCalled;
49 void TestCallback(BaseHandle handle)
51 gObjectCreatedCallBackCalled = true;
54 void TestVoidCallback()
60 ///////////////////////////////////////////////////////////////////////////////////////////////////
63 int UtcDaliControlConstructor(void)
65 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
69 DALI_TEST_CHECK( !Control::DownCast(dummy) );
71 dummy = DummyControl::New();
73 DALI_TEST_CHECK( Control::DownCast(dummy) );
77 int UtcDaliControlNew(void)
79 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
83 DALI_TEST_CHECK( !Control::DownCast(control) );
85 control = Control::New();
87 DALI_TEST_CHECK( Control::DownCast(control) );
92 int UtcDaliControlRegister(void)
94 ToolkitTestApplication application;
96 // Ensure the object is registered after creation
97 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
98 DALI_TEST_CHECK( registry );
100 gObjectCreatedCallBackCalled = false;
101 registry.ObjectCreatedSignal().Connect( &TestCallback );
103 Alignment alignment = Alignment::New();
105 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
109 int UtcDaliControlCopyAndAssignment(void)
111 ToolkitTestApplication application;
113 DummyControl control = DummyControl::New();
114 Control emptyControl;
116 Control controlCopy( control );
117 DALI_TEST_CHECK( control == controlCopy );
119 Control emptyControlCopy( emptyControl );
120 DALI_TEST_CHECK( emptyControl == emptyControlCopy );
122 Control controlEquals;
123 controlEquals = control;
124 DALI_TEST_CHECK( control == controlEquals );
126 Control emptyControlEquals;
127 emptyControlEquals = emptyControl;
128 DALI_TEST_CHECK( emptyControl == emptyControlEquals );
132 DALI_TEST_CHECK( control == controlCopy );
136 int UtcDaliControlDownCast(void)
138 ToolkitTestApplication application;
140 DummyControl control;
142 DALI_TEST_CHECK( !Control::DownCast( control ) );
144 control = DummyControl::New();
146 DALI_TEST_CHECK( Control::DownCast( control ) );
150 DALI_TEST_CHECK( !Control::DownCast( actor ) );
152 actor = Actor::New();
154 DALI_TEST_CHECK( !Control::DownCast( actor ) );
158 int UtcDaliControlDownCastTemplate(void)
160 ToolkitTestApplication application;
162 DummyControl control;
164 DALI_TEST_CHECK( !DummyControl::DownCast( control ));
166 control = DummyControl::New();
168 DALI_TEST_CHECK( DummyControl::DownCast( control ) );
172 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
174 actor = Actor::New();
176 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
180 int UtcDaliControlKeyInputFocus(void)
182 ToolkitTestApplication application;
183 Stage stage = Stage::GetCurrent();
185 DummyControl control;
187 PushButton pushButton1 = PushButton::New();
188 stage.Add( pushButton1 );
190 pushButton1.SetKeyInputFocus();
191 DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
193 pushButton1.ClearKeyInputFocus();
194 DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
198 int UtcDaliControlGetImplementation(void)
200 ToolkitTestApplication application;
202 DummyControl control;
208 Toolkit::Internal::Control& controlImpl = control.GetImplementation();
209 (void)controlImpl; // Avoid unused warning
210 tet_result(TET_FAIL);
212 catch (DaliException &exception)
214 tet_result(TET_PASS);
222 const DummyControl constControl(control);
223 const Toolkit::Internal::Control& controlImpl = constControl.GetImplementation();
224 (void)controlImpl; // Avoid unused warning
225 tet_result(TET_FAIL);
227 catch (DaliException &exception)
229 tet_result(TET_PASS);
233 control = DummyControl::New();
239 Toolkit::Internal::Control& controlImpl = control.GetImplementation();
240 (void)controlImpl; // Avoid unused warning
241 tet_result(TET_PASS);
243 catch (DaliException &exception)
245 tet_result(TET_FAIL);
253 const DummyControl constControl(control);
254 const Toolkit::Internal::Control& controlImpl = constControl.GetImplementation();
255 (void)controlImpl; // Avoid unused warning
256 tet_result(TET_PASS);
258 catch (DaliException &exception)
260 tet_result(TET_FAIL);
266 int UtcDaliControlSignalConnectDisconnect(void)
268 ToolkitTestApplication application;
271 DummyControl dummy = DummyControlImpl::New();
273 Actor actor = Actor::New();
274 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
275 Toolkit::Internal::Control& control = dummy.GetImplementation();
276 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
277 DALI_TEST_CHECK( dummyImpl );
279 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
280 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
281 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
283 Stage::GetCurrent().Add( actor );
284 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
286 dummyImpl->mCustomSlot1Called = false;
287 actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
288 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
289 Stage::GetCurrent().Remove( actor );
290 Stage::GetCurrent().Add( actor );
291 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
296 int UtcDaliControlSignalAutomaticDisconnect(void)
298 ToolkitTestApplication application;
300 Actor actor = Actor::New();
303 DummyControl dummy = DummyControlImpl::New();
304 Toolkit::Internal::Control& control = dummy.GetImplementation();
305 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
306 DALI_TEST_CHECK( dummyImpl );
308 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
309 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
310 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
312 Stage::GetCurrent().Add( actor );
313 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
314 Stage::GetCurrent().Remove( actor );
316 // dummyControl automatically disconnects
318 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
320 const Vector3 ignoredSize( 20, 20, 0 );
321 actor.SetSize( ignoredSize );
325 int UtcDaliControlTestParameters(void)
327 ToolkitTestApplication application;
328 DummyControl test = DummyControl::New();
330 test.SetSize( 0.7f, 0.7f, 0.7f );
332 Stage::GetCurrent().Add( test );
334 application.SendNotification();
335 application.Render();
337 float width = 640.0f;
338 float height = test.GetHeightForWidth( width );
339 DALI_TEST_CHECK( test.GetWidthForHeight( height ) == width );
341 test.KeyEventSignal();
343 // Provide coverage for pointer destructor
344 Control* testControlPtr = new Control;
345 DALI_TEST_CHECK( testControlPtr );
346 delete testControlPtr;
350 int UtcDaliControlBackgroundColor(void)
352 ToolkitTestApplication application;
353 Control control = Control::New();
355 DALI_TEST_CHECK( !control.GetBackgroundActor() );
356 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
358 control.SetBackgroundColor( Color::RED );
359 DALI_TEST_CHECK( control.GetBackgroundActor() );
360 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
365 int UtcDaliControlBackgroundImage(void)
367 ToolkitTestApplication application;
368 Control control = Control::New();
370 DALI_TEST_CHECK( !control.GetBackgroundActor() );
371 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
373 Image image = ResourceImage::New("TestImage");
374 control.SetBackgroundImage( image );
375 DALI_TEST_CHECK( control.GetBackgroundActor() );
376 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::WHITE, TEST_LOCATION );
378 control.SetBackgroundColor( Color::GREEN );
379 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::GREEN, TEST_LOCATION );
381 control.ClearBackground();
382 DALI_TEST_CHECK( !control.GetBackgroundActor() );
383 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
385 control.SetBackgroundColor( Color::YELLOW );
386 control.SetBackgroundImage( image );
387 DALI_TEST_CHECK( control.GetBackgroundActor() );
388 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
393 int UtcDaliControlBackgroundProperties(void)
395 ToolkitTestApplication application;
396 Control control = Control::New();
398 DALI_TEST_CHECK( !control.GetBackgroundActor() );
399 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
400 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
401 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
403 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::RED );
404 DALI_TEST_CHECK( control.GetBackgroundActor() );
405 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
406 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
408 Property::Map imageMap;
409 imageMap[ "filename" ] = "TestImage";
411 map[ "image" ] = imageMap;
412 control.SetProperty( Control::Property::BACKGROUND_IMAGE, map );
413 DALI_TEST_CHECK( control.GetBackgroundActor() );
414 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
415 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
417 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
418 DALI_TEST_CHECK( propValue.HasKey( "image" ) );
419 DALI_TEST_CHECK( propValue.GetValue( "image" ).HasKey( "filename" ) );
420 DALI_TEST_CHECK( propValue.GetValue( "image" ).GetValue( "filename" ).Get< std::string>() == "TestImage" );
422 Property::Map emptyMap;
423 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
424 DALI_TEST_CHECK( !control.GetBackgroundActor() );
425 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
426 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
427 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
432 int UtcDaliControlKeyProperties(void)
434 ToolkitTestApplication application;
436 Control control = Control::New();
437 Stage::GetCurrent().Add( control );
439 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
441 control.SetKeyInputFocus();
442 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
444 control.ClearKeyInputFocus();
445 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
447 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
448 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
453 int UtcDaliControlGestureSignals(void)
455 ToolkitTestApplication application;
456 ConnectionTracker connectionTracker;
457 Control control = Control::New();
459 // Each gesture detector gets created when connecting to the gesture signals
460 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
461 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
462 DALI_TEST_CHECK( control.GetTapGestureDetector() );
464 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
465 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
466 DALI_TEST_CHECK( control.GetPanGestureDetector() );
468 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
469 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
470 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
472 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
473 control.ConnectSignal( &connectionTracker, "long-pressed", &TestVoidCallback );
474 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );