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 );
331 float width = 640.0f;
332 float height = test.GetHeightForWidth( width );
333 DALI_TEST_CHECK( test.GetWidthForHeight( height ) == width );
335 test.KeyEventSignal();
337 // Provide coverage for pointer destructor
338 Control* testControlPtr = new Control;
339 DALI_TEST_CHECK( testControlPtr );
340 delete testControlPtr;
344 int UtcDaliControlBackgroundColor(void)
346 ToolkitTestApplication application;
347 Control control = Control::New();
349 DALI_TEST_CHECK( !control.GetBackgroundActor() );
350 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
352 control.SetBackgroundColor( Color::RED );
353 DALI_TEST_CHECK( control.GetBackgroundActor() );
354 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
359 int UtcDaliControlBackgroundImage(void)
361 ToolkitTestApplication application;
362 Control control = Control::New();
364 DALI_TEST_CHECK( !control.GetBackgroundActor() );
365 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
367 Image image = ResourceImage::New("TestImage");
368 control.SetBackgroundImage( image );
369 DALI_TEST_CHECK( control.GetBackgroundActor() );
370 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::WHITE, TEST_LOCATION );
372 control.SetBackgroundColor( Color::GREEN );
373 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::GREEN, TEST_LOCATION );
375 control.ClearBackground();
376 DALI_TEST_CHECK( !control.GetBackgroundActor() );
377 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
379 control.SetBackgroundColor( Color::YELLOW );
380 control.SetBackgroundImage( image );
381 DALI_TEST_CHECK( control.GetBackgroundActor() );
382 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
387 int UtcDaliControlBackgroundProperties(void)
389 ToolkitTestApplication application;
390 Control control = Control::New();
392 DALI_TEST_CHECK( !control.GetBackgroundActor() );
393 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
394 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
395 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
397 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::RED );
398 DALI_TEST_CHECK( control.GetBackgroundActor() );
399 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
400 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
402 Property::Map imageMap;
403 imageMap[ "filename" ] = "TestImage";
405 map[ "image" ] = imageMap;
406 control.SetProperty( Control::Property::BACKGROUND_IMAGE, map );
407 DALI_TEST_CHECK( control.GetBackgroundActor() );
408 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
409 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::RED, TEST_LOCATION );
411 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
412 DALI_TEST_CHECK( propValue.HasKey( "image" ) );
413 DALI_TEST_CHECK( propValue.GetValue( "image" ).HasKey( "filename" ) );
414 DALI_TEST_CHECK( propValue.GetValue( "image" ).GetValue( "filename" ).Get< std::string>() == "TestImage" );
416 Property::Map emptyMap;
417 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
418 DALI_TEST_CHECK( !control.GetBackgroundActor() );
419 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
420 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::TRANSPARENT, TEST_LOCATION );
421 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
426 int UtcDaliControlKeyProperties(void)
428 ToolkitTestApplication application;
430 Control control = Control::New();
431 Stage::GetCurrent().Add( control );
433 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
435 control.SetKeyInputFocus();
436 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
438 control.ClearKeyInputFocus();
439 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
441 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
442 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
447 int UtcDaliControlGestureSignals(void)
449 ToolkitTestApplication application;
450 ConnectionTracker connectionTracker;
451 Control control = Control::New();
453 // Each gesture detector gets created when connecting to the gesture signals
454 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
455 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
456 DALI_TEST_CHECK( control.GetTapGestureDetector() );
458 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
459 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
460 DALI_TEST_CHECK( control.GetPanGestureDetector() );
462 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
463 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
464 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
466 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
467 control.ConnectSignal( &connectionTracker, "long-pressed", &TestVoidCallback );
468 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );