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;
101 int UtcDaliBaseHandleConstructorVoid(void)
103 TestApplication application;
104 tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
108 DALI_TEST_CHECK(!object);
113 int UtcDaliBaseHandleCopyConstructor(void)
115 TestApplication application;
116 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
118 // Initialize an object, ref count == 1
119 BaseHandle object = Actor::New();
121 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
123 // Copy the object, ref count == 2
124 BaseHandle copy(object);
125 DALI_TEST_CHECK(copy);
128 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
132 // Pass by value, and return another copy, ref count == 3
133 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
135 DALI_TEST_CHECK(anotherCopy);
138 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142 // anotherCopy out of scope, ref count == 2
143 DALI_TEST_CHECK(copy);
146 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
151 int UtcDaliBaseHandleAssignmentOperator(void)
153 TestApplication application;
154 tet_infoline("Testing Dali::BaseHandle::operator=");
156 BaseHandle object = Actor::New();
158 DALI_TEST_CHECK(object);
161 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
164 BaseHandle copy = object;
166 DALI_TEST_CHECK(copy);
169 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
174 int UtcDaliBaseHandleGetBaseObject(void)
176 TestApplication application;
177 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
179 BaseHandle object = Actor::New();
181 BaseObject& handle = object.GetBaseObject();
183 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
187 int UtcDaliBaseHandleReset(void)
189 TestApplication application;
190 tet_infoline("Testing Dali::BaseHandle::Reset()");
192 // Initialize an object, ref count == 1
193 BaseHandle object = Actor::New();
195 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
199 DALI_TEST_CHECK(!object);
203 int UtcDaliBaseHandleEqualityOperator01(void)
205 TestApplication application;
206 tet_infoline("Positive Test Dali::BaseHandle::operator==");
208 BaseHandle object = Actor::New();
210 DALI_TEST_CHECK(object);
212 BaseHandle theSameBaseHandle = object;
214 DALI_TEST_CHECK(object == theSameBaseHandle);
218 int UtcDaliBaseHandleEqualityOperator02(void)
220 TestApplication application;
221 tet_infoline("Negative Test Dali::BaseHandle::operator==");
223 BaseHandle object = Actor::New();
225 DALI_TEST_CHECK(object);
227 BaseHandle aDifferentBaseHandle = Actor::New();
229 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
233 int UtcDaliBaseHandleInequalityOperator01(void)
235 TestApplication application;
236 tet_infoline("Positive Test Dali::BaseHandle::operator!=");
238 BaseHandle object = Actor::New();
240 DALI_TEST_CHECK(object);
242 BaseHandle aDifferentBaseHandle = Actor::New();
244 DALI_TEST_CHECK(object != aDifferentBaseHandle);
248 int UtcDaliBaseHandleInequalityOperator02(void)
250 TestApplication application;
251 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
253 BaseHandle object = Actor::New();
255 DALI_TEST_CHECK(object);
257 BaseHandle theSameBaseHandle = object;
259 DALI_TEST_CHECK(!(object != theSameBaseHandle));
263 int UtcDaliBaseHandleStlVector(void)
265 TestApplication application;
266 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
268 const int TargetVectorSize(5);
270 std::vector<Actor> myVector;
272 for (int i=0; i<TargetVectorSize; ++i)
274 Actor actor = Actor::New();
276 std::stringstream stream;
277 stream << "Actor " << i+1;
278 actor.SetName(stream.str());
280 myVector.push_back(actor);
283 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
285 DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1");
286 DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2");
287 DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3");
288 DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4");
289 DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5");
293 int UtcDaliBaseHandleDoAction(void)
295 TestApplication application;
296 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
298 Actor actor = Actor::New();
299 BaseHandle actorObject = actor;
301 DALI_TEST_CHECK(actorObject);
303 // Check that an invalid command is not performed
304 std::vector<Property::Value> attributes;
305 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
307 // Check that the actor is visible
308 actor.SetVisible(true);
309 DALI_TEST_CHECK(actor.IsVisible() == true);
311 // Check the actor performed an action to hide itself
312 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
314 // flush the queue and render once
315 application.SendNotification();
316 application.Render();
318 // Check that the actor is now invisible
319 DALI_TEST_CHECK(actor.IsVisible() == false);
321 // Check the actor performed an action to show itself
322 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
324 // flush the queue and render once
325 application.SendNotification();
326 application.Render();
328 // Check that the actor is now visible
329 DALI_TEST_CHECK(actor.IsVisible() == true);
331 Stage::GetCurrent().Add(actor);
333 // Build an animation with initial duration of 1 second
334 float durationSeconds(1.0f);
335 Animation animation = Animation::New(durationSeconds);
336 BaseHandle animationObject = animation;
338 DALI_TEST_CHECK(animationObject);
340 // Check the current animation duration is 1 second
341 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
343 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
344 animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear);
346 // Set the new duration to be 2 seconds
347 float newDurationSeconds(2.0f);
348 Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds );
349 attributes.push_back(newDurationSecondsValue);
351 // Check the animation performed an action to play itself with the specified duration of 2 seconds
352 animationObject.DoAction("play", attributes);
354 bool signalReceived(false);
355 AnimationFinishCheck finishCheck(signalReceived);
356 animation.FinishedSignal().Connect(&application, finishCheck);
358 application.SendNotification();
359 application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
361 // We expect the animation to finish
362 application.SendNotification();
363 finishCheck.CheckSignalReceived();
364 DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
366 // Check the new animation duration is 2 seconds
367 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
372 int UtcDaliBaseHandleConnectSignal(void)
374 TestApplication application;
375 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
377 gTouchCallBackCalled = false;
379 // get the root layer
380 Actor actor = Actor::New();
381 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
382 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
383 actor.SetPosition( 240, 400 );
384 actor.SetSize( 100, 100 );
386 Stage::GetCurrent().Add( actor );
388 DALI_TEST_CHECK( gTouchCallBackCalled == false );
390 // connect to its touch signal
391 actor.ConnectSignal( &application, "touched", TestCallback() );
393 application.SendNotification();
394 application.Render(1000);
395 application.SendNotification();
396 application.Render(1000);
398 // simulate a touch event
399 Dali::TouchPoint point( 0, TouchPoint::Down, 240, 400 );
400 Dali::Integration::TouchEvent event;
401 event.AddPoint( point );
402 application.ProcessEvent( event );
404 application.SendNotification();
405 application.Render(1000);
406 application.SendNotification();
407 application.Render(1000);
409 DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
410 DALI_TEST_CHECK( gTouchCallBackCalled == true );
412 gTouchCallBackCalled = false;
413 application.DisconnectAll();
415 // simulate another touch event
416 application.ProcessEvent( event );
418 DALI_TEST_CHECK( gTouchCallBackCalled == false );
422 int UtcDaliBaseHandleGetTypeName(void)
424 TestApplication application;
425 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
427 // get the root layer
428 Actor actor = Actor::New();
430 std::string typeName = actor.GetTypeName();
432 DALI_TEST_CHECK( typeName.size() );
433 DALI_TEST_CHECK( typeName == std::string("Actor") );
437 int UtcDaliBaseHandleGetObjectPtr(void)
439 TestApplication application;
440 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
442 // get the root layer
443 Actor actor = Actor::New();
445 Dali::RefObject* p = actor.GetObjectPtr();
447 DALI_TEST_CHECK( p != NULL );
451 int UtcDaliBaseHandleBooleanCast(void)
453 TestApplication application;
454 tet_infoline("Testing Dali::BaseHandle::BooleanType");
456 // get the root layer
457 BaseHandle handle = Actor::New();
459 DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );