2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
23 #include "dali-test-suite-utils/dali-test-suite-utils.h"
28 void utc_base_handle_startup(void)
30 test_return_value = TET_UNDEF;
33 // Called after each test
34 void utc_base_handle_cleanup(void)
36 test_return_value = TET_PASS;
42 // Functor to test whether an animation finish signal is emitted
43 struct AnimationFinishCheck
45 AnimationFinishCheck(bool& signalReceived)
46 : mSignalReceived(signalReceived)
50 void operator()(Animation& animation)
52 mSignalReceived = true;
57 mSignalReceived = false;
60 void CheckSignalReceived()
64 tet_printf("Expected Finish signal was not received\n");
73 bool& mSignalReceived; // owned by individual tests
76 BaseHandle ImplicitCopyConstructor(BaseHandle passedByValue)
78 // object + copy + passedByValue, ref count == 3
79 DALI_TEST_CHECK(passedByValue);
82 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
88 static bool gTouchCallBackCalled;
94 gTouchCallBackCalled = true;
100 int UtcDaliBaseHandleConstructorVoid(void)
102 TestApplication application;
103 tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
107 DALI_TEST_CHECK(!object);
112 int UtcDaliBaseHandleCopyConstructor(void)
114 TestApplication application;
115 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
117 // Initialize an object, ref count == 1
118 BaseHandle object = Actor::New();
120 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
122 // Copy the object, ref count == 2
123 BaseHandle copy(object);
124 DALI_TEST_CHECK(copy);
127 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131 // Pass by value, and return another copy, ref count == 3
132 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
134 DALI_TEST_CHECK(anotherCopy);
137 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
141 // anotherCopy out of scope, ref count == 2
142 DALI_TEST_CHECK(copy);
145 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
150 int UtcDaliBaseHandleAssignmentOperator(void)
152 TestApplication application;
153 tet_infoline("Testing Dali::BaseHandle::operator=");
155 BaseHandle object = Actor::New();
157 DALI_TEST_CHECK(object);
160 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
163 BaseHandle copy = object;
165 DALI_TEST_CHECK(copy);
168 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
173 int UtcDaliBaseHandleGetBaseObject(void)
175 TestApplication application;
176 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
178 BaseHandle object = Actor::New();
180 BaseObject& handle = object.GetBaseObject();
182 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
186 int UtcDaliBaseHandleReset(void)
188 TestApplication application;
189 tet_infoline("Testing Dali::BaseHandle::Reset()");
191 // Initialize an object, ref count == 1
192 BaseHandle object = Actor::New();
194 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
198 DALI_TEST_CHECK(!object);
202 int UtcDaliBaseHandleEqualityOperator01(void)
204 TestApplication application;
205 tet_infoline("Positive Test Dali::BaseHandle::operator==");
207 BaseHandle object = Actor::New();
209 DALI_TEST_CHECK(object);
211 BaseHandle theSameBaseHandle = object;
213 DALI_TEST_CHECK(object == theSameBaseHandle);
217 int UtcDaliBaseHandleEqualityOperator02(void)
219 TestApplication application;
220 tet_infoline("Negative Test Dali::BaseHandle::operator==");
222 BaseHandle object = Actor::New();
224 DALI_TEST_CHECK(object);
226 BaseHandle aDifferentBaseHandle = Actor::New();
228 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
232 int UtcDaliBaseHandleInequalityOperator01(void)
234 TestApplication application;
235 tet_infoline("Positive 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 UtcDaliBaseHandleInequalityOperator02(void)
249 TestApplication application;
250 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
252 BaseHandle object = Actor::New();
254 DALI_TEST_CHECK(object);
256 BaseHandle theSameBaseHandle = object;
258 DALI_TEST_CHECK(!(object != theSameBaseHandle));
262 int UtcDaliBaseHandleStlVector(void)
264 TestApplication application;
265 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
267 const int TargetVectorSize(5);
269 std::vector<Actor> myVector;
271 for (int i=0; i<TargetVectorSize; ++i)
273 Actor actor = Actor::New();
275 std::stringstream stream;
276 stream << "Actor " << i+1;
277 actor.SetName(stream.str());
279 myVector.push_back(actor);
282 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
284 DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1");
285 DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2");
286 DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3");
287 DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4");
288 DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5");
292 int UtcDaliBaseHandleDoAction(void)
294 TestApplication application;
295 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
297 Actor actor = Actor::New();
298 BaseHandle actorObject = actor;
300 DALI_TEST_CHECK(actorObject);
302 // Check that an invalid command is not performed
303 std::vector<Property::Value> attributes;
304 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
306 // Check that the actor is visible
307 actor.SetVisible(true);
308 DALI_TEST_CHECK(actor.IsVisible() == true);
310 // Check the actor performed an action to hide itself
311 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
313 // flush the queue and render once
314 application.SendNotification();
315 application.Render();
317 // Check that the actor is now invisible
318 DALI_TEST_CHECK(actor.IsVisible() == false);
320 // Check the actor performed an action to show itself
321 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
323 // flush the queue and render once
324 application.SendNotification();
325 application.Render();
327 // Check that the actor is now visible
328 DALI_TEST_CHECK(actor.IsVisible() == true);
330 Stage::GetCurrent().Add(actor);
332 // Build an animation with initial duration of 1 second
333 float durationSeconds(1.0f);
334 Animation animation = Animation::New(durationSeconds);
335 BaseHandle animationObject = animation;
337 DALI_TEST_CHECK(animationObject);
339 // Check the current animation duration is 1 second
340 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
342 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
343 animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear);
345 // Set the new duration to be 2 seconds
346 float newDurationSeconds(2.0f);
347 Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds );
348 attributes.push_back(newDurationSecondsValue);
350 // Check the animation performed an action to play itself with the specified duration of 2 seconds
351 animationObject.DoAction("play", attributes);
353 bool signalReceived(false);
354 AnimationFinishCheck finishCheck(signalReceived);
355 animation.FinishedSignal().Connect(&application, finishCheck);
357 application.SendNotification();
358 application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
360 // We expect the animation to finish
361 application.SendNotification();
362 finishCheck.CheckSignalReceived();
363 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
365 // Check the new animation duration is 2 seconds
366 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
371 int UtcDaliBaseHandleConnectSignal(void)
373 TestApplication application;
374 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
376 gTouchCallBackCalled = false;
378 // get the root layer
379 Actor actor = Actor::New();
380 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
381 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
382 actor.SetPosition( 240, 400 );
383 actor.SetSize( 100, 100 );
385 Stage::GetCurrent().Add( actor );
387 DALI_TEST_CHECK( gTouchCallBackCalled == false );
389 // connect to its touch signal
390 actor.ConnectSignal( &application, "touched", TestCallback() );
392 application.SendNotification();
393 application.Render(1000);
394 application.SendNotification();
395 application.Render(1000);
397 // simulate a touch event
398 Dali::TouchPoint point( 0, TouchPoint::Down, 240, 400 );
399 Dali::Integration::TouchEvent event;
400 event.AddPoint( point );
401 application.ProcessEvent( event );
403 application.SendNotification();
404 application.Render(1000);
405 application.SendNotification();
406 application.Render(1000);
408 DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
409 DALI_TEST_CHECK( gTouchCallBackCalled == true );
411 gTouchCallBackCalled = false;
412 application.DisconnectAll();
414 // simulate another touch event
415 application.ProcessEvent( event );
417 DALI_TEST_CHECK( gTouchCallBackCalled == false );
421 int UtcDaliBaseHandleGetTypeName(void)
423 TestApplication application;
424 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
426 // get the root layer
427 Actor actor = Actor::New();
429 std::string typeName = actor.GetTypeName();
431 DALI_TEST_CHECK( typeName.size() );
432 DALI_TEST_CHECK( typeName == std::string("Actor") );
436 int UtcDaliBaseHandleGetObjectPtr(void)
438 TestApplication application;
439 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
441 // get the root layer
442 Actor actor = Actor::New();
444 Dali::RefObject* p = actor.GetObjectPtr();
446 DALI_TEST_CHECK( p != NULL );
450 int UtcDaliBaseHandleBooleanCast(void)
452 TestApplication application;
453 tet_infoline("Testing Dali::BaseHandle::BooleanType");
455 // get the root layer
456 BaseHandle handle = Actor::New();
458 DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );