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 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
24 #include "dali-test-suite-utils/dali-test-suite-utils.h"
29 void utc_base_handle_startup(void)
31 test_return_value = TET_UNDEF;
34 // Called after each test
35 void utc_base_handle_cleanup(void)
37 test_return_value = TET_PASS;
43 // Functor to test whether an animation finish signal is emitted
44 struct AnimationFinishCheck
46 AnimationFinishCheck(bool& signalReceived)
47 : mSignalReceived(signalReceived)
51 void operator()(Animation& animation)
53 mSignalReceived = true;
58 mSignalReceived = false;
61 void CheckSignalReceived()
65 tet_printf("Expected Finish signal was not received\n");
74 bool& mSignalReceived; // owned by individual tests
77 BaseHandle ImplicitCopyConstructor(BaseHandle passedByValue)
79 // object + copy + passedByValue, ref count == 3
80 DALI_TEST_CHECK(passedByValue);
83 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
89 static bool gTouchCallBackCalled;
95 gTouchCallBackCalled = true;
99 // Used for testing BaseObject::GetTypeName with an object that is not registered
100 class FakeObject : public BaseObject
103 // used for testing ThisIsSaferThanReturningVoidStar
104 class FakeHandle : public BaseHandle
110 return ThisIsSaferThanReturningVoidStar();
115 int UtcDaliBaseHandleConstructorVoid(void)
117 TestApplication application;
118 tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
122 DALI_TEST_CHECK(!object);
127 int UtcDaliBaseHandleCopyConstructor(void)
129 TestApplication application;
130 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
132 // Initialize an object, ref count == 1
133 BaseHandle object = Actor::New();
135 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
137 // Copy the object, ref count == 2
138 BaseHandle copy(object);
139 DALI_TEST_CHECK(copy);
142 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
146 // Pass by value, and return another copy, ref count == 3
147 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
149 DALI_TEST_CHECK(anotherCopy);
152 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
156 // anotherCopy out of scope, ref count == 2
157 DALI_TEST_CHECK(copy);
160 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
165 int UtcDaliBaseHandleAssignmentOperator(void)
167 TestApplication application;
168 tet_infoline("Testing Dali::BaseHandle::operator=");
170 BaseHandle object = Actor::New();
172 DALI_TEST_CHECK(object);
175 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
178 BaseHandle copy = object;
180 DALI_TEST_CHECK(copy);
183 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
188 int UtcDaliBaseHandleGetBaseObject(void)
190 TestApplication application;
191 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
193 BaseHandle object = Actor::New();
195 BaseObject& handle = object.GetBaseObject();
197 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
201 int UtcDaliBaseHandleReset(void)
203 TestApplication application;
204 tet_infoline("Testing Dali::BaseHandle::Reset()");
206 // Initialize an object, ref count == 1
207 BaseHandle object = Actor::New();
209 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
213 DALI_TEST_CHECK(!object);
217 int UtcDaliBaseHandleEqualityOperator01(void)
219 TestApplication application;
220 tet_infoline("Positive Test Dali::BaseHandle::operator==");
222 BaseHandle object = Actor::New();
224 DALI_TEST_CHECK(object);
226 BaseHandle theSameBaseHandle = object;
228 DALI_TEST_CHECK(object == theSameBaseHandle);
232 int UtcDaliBaseHandleEqualityOperator02(void)
234 TestApplication application;
235 tet_infoline("Negative Test Dali::BaseHandle::operator==");
237 BaseHandle object = Actor::New();
239 DALI_TEST_CHECK(object);
241 BaseHandle aDifferentBaseHandle = Actor::New();
243 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
247 int UtcDaliBaseHandleInequalityOperator01(void)
249 TestApplication application;
250 tet_infoline("Positive Test Dali::BaseHandle::operator!=");
252 BaseHandle object = Actor::New();
254 DALI_TEST_CHECK(object);
256 BaseHandle aDifferentBaseHandle = Actor::New();
258 DALI_TEST_CHECK(object != aDifferentBaseHandle);
262 int UtcDaliBaseHandleInequalityOperator02(void)
264 TestApplication application;
265 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
267 BaseHandle object = Actor::New();
269 DALI_TEST_CHECK(object);
271 BaseHandle theSameBaseHandle = object;
273 DALI_TEST_CHECK(!(object != theSameBaseHandle));
277 int UtcDaliBaseHandleStlVector(void)
279 TestApplication application;
280 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
282 const int TargetVectorSize(5);
284 std::vector<Actor> myVector;
286 for (int i=0; i<TargetVectorSize; ++i)
288 Actor actor = Actor::New();
290 std::stringstream stream;
291 stream << "Actor " << i+1;
292 actor.SetName(stream.str());
294 myVector.push_back(actor);
297 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
299 DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1");
300 DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2");
301 DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3");
302 DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4");
303 DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5");
307 int UtcDaliBaseHandleDoAction(void)
309 TestApplication application;
310 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
312 Actor actor = Actor::New();
313 BaseHandle actorObject = actor;
315 DALI_TEST_CHECK(actorObject);
317 // Check that an invalid command is not performed
318 Property::Map attributes;
319 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
321 // Check that the actor is visible
322 actor.SetVisible(true);
323 DALI_TEST_CHECK(actor.IsVisible() == true);
325 // Check the actor performed an action to hide itself
326 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
328 // flush the queue and render once
329 application.SendNotification();
330 application.Render();
332 // Check that the actor is now invisible
333 DALI_TEST_CHECK(actor.IsVisible() == false);
335 // Check the actor performed an action to show itself
336 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
338 // flush the queue and render once
339 application.SendNotification();
340 application.Render();
342 // Check that the actor is now visible
343 DALI_TEST_CHECK(actor.IsVisible() == true);
345 Stage::GetCurrent().Add(actor);
347 // Build an animation with initial duration of 1 second
348 float durationSeconds(1.0f);
349 Animation animation = Animation::New(durationSeconds);
350 BaseHandle animationObject = animation;
352 DALI_TEST_CHECK(animationObject);
354 // Check the current animation duration is 1 second
355 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
357 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
358 animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
360 // Set the new duration to be 2 seconds
361 float newDurationSeconds(2.0f);
362 Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds );
363 attributes["duration"] = newDurationSecondsValue;
365 // Check the animation performed an action to play itself with the specified duration of 2 seconds
366 animationObject.DoAction("play", attributes);
368 bool signalReceived(false);
369 AnimationFinishCheck finishCheck(signalReceived);
370 animation.FinishedSignal().Connect(&application, finishCheck);
372 application.SendNotification();
373 application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
375 // We expect the animation to finish
376 application.SendNotification();
377 finishCheck.CheckSignalReceived();
378 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
380 // Check the new animation duration is 2 seconds
381 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
386 int UtcDaliBaseHandleConnectSignal(void)
388 TestApplication application;
389 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
391 gTouchCallBackCalled = false;
393 // get the root layer
394 Actor actor = Actor::New();
395 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
396 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
397 actor.SetPosition( 240, 400 );
398 actor.SetSize( 100, 100 );
400 Stage::GetCurrent().Add( actor );
402 DALI_TEST_CHECK( gTouchCallBackCalled == false );
404 // connect to its touch signal
405 actor.ConnectSignal( &application, "touched", TestCallback() );
407 application.SendNotification();
408 application.Render(1000);
409 application.SendNotification();
410 application.Render(1000);
412 // simulate a touch event
413 Dali::TouchPoint point( 0, TouchPoint::Down, 240, 400 );
414 Dali::Integration::TouchEvent event;
415 event.AddPoint( point );
416 application.ProcessEvent( event );
418 application.SendNotification();
419 application.Render(1000);
420 application.SendNotification();
421 application.Render(1000);
423 DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
424 DALI_TEST_CHECK( gTouchCallBackCalled == true );
426 gTouchCallBackCalled = false;
427 application.DisconnectAll();
429 // simulate another touch event
430 application.ProcessEvent( event );
432 DALI_TEST_CHECK( gTouchCallBackCalled == false );
436 int UtcDaliBaseHandleGetTypeNameP(void)
438 TestApplication application;
439 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
441 // get the root layer
442 Actor actor = Actor::New();
444 std::string typeName = actor.GetTypeName();
446 DALI_TEST_CHECK( typeName.size() );
447 DALI_TEST_CHECK( typeName == std::string("Actor") );
451 int UtcDaliBaseHandleGetTypeNameN(void)
454 TestApplication application;
455 tet_infoline("Testing Dali::BaseObject::GetTypeName");
457 std::string typeName = object.GetTypeName();
459 DALI_TEST_CHECK( typeName.empty() );
463 int UtcDaliBaseHandleGetTypeInfoP(void)
465 TestApplication application;
466 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
469 Actor actor = Actor::New();
471 bool ok = actor.GetTypeInfo( info );
472 DALI_TEST_CHECK( ok );
476 int UtcDaliBaseHandleThisIsSaferThanReturningVoidStar(void)
478 TestApplication application;
479 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
482 tet_result(TET_PASS);
487 int UtcDaliBaseHandleGetTypeInfoN(void)
489 TestApplication application;
490 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
495 bool ok = object.GetTypeInfo( info );
496 DALI_TEST_CHECK( !ok );
500 int UtcDaliBaseHandleGetObjectPtr(void)
502 TestApplication application;
503 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
505 // get the root layer
506 Actor actor = Actor::New();
508 Dali::RefObject* p = actor.GetObjectPtr();
510 DALI_TEST_CHECK( p != NULL );
514 int UtcDaliBaseHandleBooleanCast(void)
516 TestApplication application;
517 tet_infoline("Testing Dali::BaseHandle::BooleanType");
519 // get the root layer
520 BaseHandle handle = Actor::New();
522 DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );