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);
126 int UtcDaliBaseHandleCopyConstructor(void)
128 TestApplication application;
129 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
131 // Initialize an object, ref count == 1
132 BaseHandle object = Actor::New();
134 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
136 // Copy the object, ref count == 2
137 BaseHandle copy(object);
138 DALI_TEST_CHECK(copy);
141 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
145 // Pass by value, and return another copy, ref count == 3
146 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
148 DALI_TEST_CHECK(anotherCopy);
151 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
155 // anotherCopy out of scope, ref count == 2
156 DALI_TEST_CHECK(copy);
159 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
164 int UtcDaliBaseHandleAssignmentOperator(void)
166 TestApplication application;
167 tet_infoline("Testing Dali::BaseHandle::operator=");
169 BaseHandle object = Actor::New();
171 DALI_TEST_CHECK(object);
174 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
177 BaseHandle copy = object;
179 DALI_TEST_CHECK(copy);
182 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 int UtcDaliBaseHandleGetBaseObject(void)
189 TestApplication application;
190 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
192 BaseHandle object = Actor::New();
194 BaseObject& handle = object.GetBaseObject();
196 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
200 int UtcDaliBaseHandleReset(void)
202 TestApplication application;
203 tet_infoline("Testing Dali::BaseHandle::Reset()");
205 // Initialize an object, ref count == 1
206 BaseHandle object = Actor::New();
208 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
212 DALI_TEST_CHECK(!object);
216 int UtcDaliBaseHandleEqualityOperator01(void)
218 TestApplication application;
219 tet_infoline("Positive Test Dali::BaseHandle::operator==");
221 BaseHandle object = Actor::New();
223 DALI_TEST_CHECK(object);
225 BaseHandle theSameBaseHandle = object;
227 DALI_TEST_CHECK(object == theSameBaseHandle);
231 int UtcDaliBaseHandleEqualityOperator02(void)
233 TestApplication application;
234 tet_infoline("Negative Test Dali::BaseHandle::operator==");
236 BaseHandle object = Actor::New();
238 DALI_TEST_CHECK(object);
240 BaseHandle aDifferentBaseHandle = Actor::New();
242 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
246 int UtcDaliBaseHandleInequalityOperator01(void)
248 TestApplication application;
249 tet_infoline("Positive Test Dali::BaseHandle::operator!=");
251 BaseHandle object = Actor::New();
253 DALI_TEST_CHECK(object);
255 BaseHandle aDifferentBaseHandle = Actor::New();
257 DALI_TEST_CHECK(object != aDifferentBaseHandle);
261 int UtcDaliBaseHandleInequalityOperator02(void)
263 TestApplication application;
264 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
266 BaseHandle object = Actor::New();
268 DALI_TEST_CHECK(object);
270 BaseHandle theSameBaseHandle = object;
272 DALI_TEST_CHECK(!(object != theSameBaseHandle));
276 int UtcDaliBaseHandleStlVector(void)
278 TestApplication application;
279 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
281 const int TargetVectorSize(5);
283 std::vector<Actor> myVector;
285 for (int i=0; i<TargetVectorSize; ++i)
287 Actor actor = Actor::New();
289 std::stringstream stream;
290 stream << "Actor " << i+1;
291 actor.SetName(stream.str());
293 myVector.push_back(actor);
296 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
298 DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1");
299 DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2");
300 DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3");
301 DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4");
302 DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5");
306 int UtcDaliBaseHandleDoAction(void)
308 TestApplication application;
309 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
311 Actor actor = Actor::New();
312 BaseHandle actorObject = actor;
314 DALI_TEST_CHECK(actorObject);
316 // Check that an invalid command is not performed
317 Property::Map attributes;
318 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
320 // Check that the actor is visible
321 actor.SetVisible(true);
322 DALI_TEST_CHECK(actor.IsVisible() == true);
324 // Check the actor performed an action to hide itself
325 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
327 // flush the queue and render once
328 application.SendNotification();
329 application.Render();
331 // Check that the actor is now invisible
332 DALI_TEST_CHECK(actor.IsVisible() == false);
334 // Check the actor performed an action to show itself
335 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
337 // flush the queue and render once
338 application.SendNotification();
339 application.Render();
341 // Check that the actor is now visible
342 DALI_TEST_CHECK(actor.IsVisible() == true);
344 Stage::GetCurrent().Add(actor);
346 // Build an animation with initial duration of 1 second
347 float durationSeconds(1.0f);
348 Animation animation = Animation::New(durationSeconds);
349 BaseHandle animationObject = animation;
351 DALI_TEST_CHECK(animationObject);
353 // Check the current animation duration is 1 second
354 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
356 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
357 animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
359 // Set the new duration to be 2 seconds
360 float newDurationSeconds(2.0f);
361 Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds );
362 attributes["duration"] = newDurationSecondsValue;
364 // Check the animation performed an action to play itself with the specified duration of 2 seconds
365 animationObject.DoAction("play", attributes);
367 bool signalReceived(false);
368 AnimationFinishCheck finishCheck(signalReceived);
369 animation.FinishedSignal().Connect(&application, finishCheck);
371 application.SendNotification();
372 application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
374 // We expect the animation to finish
375 application.SendNotification();
376 finishCheck.CheckSignalReceived();
377 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
379 // Check the new animation duration is 2 seconds
380 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
385 int UtcDaliBaseHandleConnectSignal(void)
387 TestApplication application;
388 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
390 gTouchCallBackCalled = false;
392 // get the root layer
393 Actor actor = Actor::New();
394 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
395 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
396 actor.SetPosition( 240, 400 );
397 actor.SetSize( 100, 100 );
399 Stage::GetCurrent().Add( actor );
401 DALI_TEST_CHECK( gTouchCallBackCalled == false );
403 // connect to its touch signal
404 actor.ConnectSignal( &application, "touched", TestCallback() );
406 application.SendNotification();
407 application.Render(1000);
408 application.SendNotification();
409 application.Render(1000);
411 // simulate a touch event
412 Dali::Integration::Point point;
413 point.SetState( PointState::DOWN );
414 point.SetScreenPosition( Vector2( 240, 400 ) );
415 Dali::Integration::TouchEvent event;
416 event.AddPoint( point );
417 application.ProcessEvent( event );
419 application.SendNotification();
420 application.Render(1000);
421 application.SendNotification();
422 application.Render(1000);
424 DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
425 DALI_TEST_CHECK( gTouchCallBackCalled == true );
427 gTouchCallBackCalled = false;
428 application.DisconnectAll();
430 // simulate another touch event
431 application.ProcessEvent( event );
433 DALI_TEST_CHECK( gTouchCallBackCalled == false );
437 int UtcDaliBaseHandleGetTypeNameP(void)
439 TestApplication application;
440 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
442 // get the root layer
443 Actor actor = Actor::New();
445 std::string typeName = actor.GetTypeName();
447 DALI_TEST_CHECK( typeName.size() );
448 DALI_TEST_CHECK( typeName == std::string("Actor") );
452 int UtcDaliBaseHandleGetTypeNameN(void)
455 TestApplication application;
456 tet_infoline("Testing Dali::BaseObject::GetTypeName");
458 std::string typeName = object.GetTypeName();
460 DALI_TEST_CHECK( typeName.empty() );
464 int UtcDaliBaseHandleGetTypeInfoP(void)
466 TestApplication application;
467 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
470 Actor actor = Actor::New();
472 bool ok = actor.GetTypeInfo( info );
473 DALI_TEST_CHECK( ok );
477 int UtcDaliBaseHandleThisIsSaferThanReturningVoidStar(void)
479 TestApplication application;
480 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
483 tet_result(TET_PASS);
488 int UtcDaliBaseHandleGetTypeInfoN(void)
490 TestApplication application;
491 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
496 bool ok = object.GetTypeInfo( info );
497 DALI_TEST_CHECK( !ok );
501 int UtcDaliBaseHandleGetObjectPtr(void)
503 TestApplication application;
504 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
506 // get the root layer
507 Actor actor = Actor::New();
509 Dali::RefObject* p = actor.GetObjectPtr();
511 DALI_TEST_CHECK( p != NULL );
515 int UtcDaliBaseHandleBooleanCast(void)
517 TestApplication application;
518 tet_infoline("Testing Dali::BaseHandle::BooleanType");
520 // get the root layer
521 BaseHandle handle = Actor::New();
523 DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );
527 int UtcDaliBaseHandleCompareOperatorN(void)
529 TestApplication application;
530 BaseHandle handle1 = Actor::New();
531 BaseHandle handle2 = handle1;
533 DALI_TEST_CHECK( (handle1 < handle2) == false );