Dali 3D User Interface Engine
utc-Dali-BaseHandle.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
23 
24 #include "dali-test-suite-utils/dali-test-suite-utils.h"
25 
26 using namespace Dali;
27 
28 
30 {
32 }
33 
34 // Called after each test
36 {
38 }
39 
40 namespace
41 {
42 
43 // Functor to test whether an animation finish signal is emitted
45 {
46  AnimationFinishCheck(bool& signalReceived)
47  : mSignalReceived(signalReceived)
48  {
49  }
50 
51  void operator()(Animation& animation)
52  {
53  mSignalReceived = true;
54  }
55 
56  void Reset()
57  {
58  mSignalReceived = false;
59  }
60 
61  void CheckSignalReceived()
62  {
63  if (!mSignalReceived)
64  {
65  tet_printf("Expected Finish signal was not received\n");
67  }
68  else
69  {
71  }
72  }
73 
74  bool& mSignalReceived; // owned by individual tests
75 };
76 
78 {
79  // object + copy + passedByValue, ref count == 3
80  DALI_TEST_CHECK(passedByValue);
81  if (passedByValue)
82  {
84  }
85 
86  return passedByValue;
87 }
88 
90 
92 {
93  void operator()()
94  {
95  gTouchCallBackCalled = true;
96  }
97 };
98 
99 // Used for testing BaseObject::GetTypeName with an object that is not registered
100 class FakeObject : public BaseObject
101 {
102 };
103 // used for testing ThisIsSaferThanReturningVoidStar
104 class FakeHandle : public BaseHandle
105 {
106 public:
107 
108  void RunTest()
109  {
110  return ThisIsSaferThanReturningVoidStar();
111  }
112 };
113 } // anon namespace
114 
116 {
117  TestApplication application;
118  tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
119 
120  BaseHandle object;
121 
122  DALI_TEST_CHECK(!object);
123  END_TEST;
124 }
125 
126 
128 {
129  TestApplication application;
130  tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
131 
132  // Initialize an object, ref count == 1
133  BaseHandle object = Actor::New();
134 
135  DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
136 
137  // Copy the object, ref count == 2
138  BaseHandle copy(object);
139  DALI_TEST_CHECK(copy);
140  if (copy)
141  {
143  }
144 
145  {
146  // Pass by value, and return another copy, ref count == 3
147  BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
148 
149  DALI_TEST_CHECK(anotherCopy);
150  if (anotherCopy)
151  {
153  }
154  }
155 
156  // anotherCopy out of scope, ref count == 2
157  DALI_TEST_CHECK(copy);
158  if (copy)
159  {
161  }
162  END_TEST;
163 }
164 
166 {
167  TestApplication application;
168  tet_infoline("Testing Dali::BaseHandle::operator=");
169 
170  BaseHandle object = Actor::New();
171 
172  DALI_TEST_CHECK(object);
173  if (object)
174  {
175  DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
176  }
177 
178  BaseHandle copy = object;
179 
180  DALI_TEST_CHECK(copy);
181  if (copy)
182  {
184  }
185  END_TEST;
186 }
187 
189 {
190  TestApplication application;
191  tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
192 
193  BaseHandle object = Actor::New();
194 
195  BaseObject& handle = object.GetBaseObject();
196 
198  END_TEST;
199 }
200 
202 {
203  TestApplication application;
204  tet_infoline("Testing Dali::BaseHandle::Reset()");
205 
206  // Initialize an object, ref count == 1
207  BaseHandle object = Actor::New();
208 
209  DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
210 
211  object.Reset();
212 
213  DALI_TEST_CHECK(!object);
214  END_TEST;
215 }
216 
218 {
219  TestApplication application;
220  tet_infoline("Positive Test Dali::BaseHandle::operator==");
221 
222  BaseHandle object = Actor::New();
223 
224  DALI_TEST_CHECK(object);
225 
226  BaseHandle theSameBaseHandle = object;
227 
228  DALI_TEST_CHECK(object == theSameBaseHandle);
229  END_TEST;
230 }
231 
233 {
234  TestApplication application;
235  tet_infoline("Negative Test Dali::BaseHandle::operator==");
236 
237  BaseHandle object = Actor::New();
238 
239  DALI_TEST_CHECK(object);
240 
241  BaseHandle aDifferentBaseHandle = Actor::New();
242 
243  DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
244  END_TEST;
245 }
246 
248 {
249  TestApplication application;
250  tet_infoline("Positive Test Dali::BaseHandle::operator!=");
251 
252  BaseHandle object = Actor::New();
253 
254  DALI_TEST_CHECK(object);
255 
256  BaseHandle aDifferentBaseHandle = Actor::New();
257 
258  DALI_TEST_CHECK(object != aDifferentBaseHandle);
259  END_TEST;
260 }
261 
263 {
264  TestApplication application;
265  tet_infoline("Negative Test Dali::BaseHandle::operator!=");
266 
267  BaseHandle object = Actor::New();
268 
269  DALI_TEST_CHECK(object);
270 
271  BaseHandle theSameBaseHandle = object;
272 
273  DALI_TEST_CHECK(!(object != theSameBaseHandle));
274  END_TEST;
275 }
276 
278 {
279  TestApplication application;
280  tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
281 
282  const int TargetVectorSize(5);
283 
284  std::vector<Actor> myVector;
285 
286  for (int i=0; i<TargetVectorSize; ++i)
287  {
288  Actor actor = Actor::New();
289 
290  std::stringstream stream;
291  stream << "Actor " << i+1;
292  actor.SetName(stream.str());
293 
294  myVector.push_back(actor);
295  }
296 
297  DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
298 
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");
304  END_TEST;
305 }
306 
308 {
309  TestApplication application;
310  tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
311 
312  Actor actor = Actor::New();
313  BaseHandle actorObject = actor;
314 
315  DALI_TEST_CHECK(actorObject);
316 
317  // Check that an invalid command is not performed
318  Property::Map attributes;
319  DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
320 
321  // Check that the actor is visible
322  actor.SetVisible(true);
323  DALI_TEST_CHECK(actor.IsVisible() == true);
324 
325  // Check the actor performed an action to hide itself
326  DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
327 
328  // flush the queue and render once
329  application.SendNotification();
330  application.Render();
331 
332  // Check that the actor is now invisible
333  DALI_TEST_CHECK(actor.IsVisible() == false);
334 
335  // Check the actor performed an action to show itself
336  DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
337 
338  // flush the queue and render once
339  application.SendNotification();
340  application.Render();
341 
342  // Check that the actor is now visible
343  DALI_TEST_CHECK(actor.IsVisible() == true);
344 
345  Stage::GetCurrent().Add(actor);
346 
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;
351 
352  DALI_TEST_CHECK(animationObject);
353 
354  // Check the current animation duration is 1 second
355  DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
356 
357  Vector3 targetPosition(100.0f, 100.0f, 100.0f);
358  animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
359 
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;
364 
365  // Check the animation performed an action to play itself with the specified duration of 2 seconds
366  animationObject.DoAction("play", attributes);
367 
368  bool signalReceived(false);
369  AnimationFinishCheck finishCheck(signalReceived);
370  animation.FinishedSignal().Connect(&application, finishCheck);
371 
372  application.SendNotification();
373  application.Render(static_cast<unsigned int>(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/);
374 
375  // We expect the animation to finish
376  application.SendNotification();
377  finishCheck.CheckSignalReceived();
378  DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
379 
380  // Check the new animation duration is 2 seconds
381  DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
382  END_TEST;
383 }
384 
385 
387 {
388  TestApplication application;
389  tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
390 
391  gTouchCallBackCalled = false;
392 
393  // get the root layer
394  Actor actor = Actor::New();
397  actor.SetPosition( 240, 400 );
398  actor.SetSize( 100, 100 );
399 
400  Stage::GetCurrent().Add( actor );
401 
403 
404  // connect to its touch signal
405  actor.ConnectSignal( &application, "touched", TestCallback() );
406 
407  application.SendNotification();
408  application.Render(1000);
409  application.SendNotification();
410  application.Render(1000);
411 
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 );
417 
418  application.SendNotification();
419  application.Render(1000);
420  application.SendNotification();
421  application.Render(1000);
422 
423  DALI_TEST_CHECK( application.GetConnectionCount() > 0 );
425 
426  gTouchCallBackCalled = false;
427  application.DisconnectAll();
428 
429  // simulate another touch event
430  application.ProcessEvent( event );
431 
433  END_TEST;
434 }
435 
437 {
438  TestApplication application;
439  tet_infoline("Testing Dali::BaseHandle::GetTypeName");
440 
441  // get the root layer
442  Actor actor = Actor::New();
443 
444  std::string typeName = actor.GetTypeName();
445 
446  DALI_TEST_CHECK( typeName.size() );
447  DALI_TEST_CHECK( typeName == std::string("Actor") );
448  END_TEST;
449 }
450 
452 {
453 
454  TestApplication application;
455  tet_infoline("Testing Dali::BaseObject::GetTypeName");
456  FakeObject object;
457  std::string typeName = object.GetTypeName();
458 
459  DALI_TEST_CHECK( typeName.empty() );
460  END_TEST;
461 }
462 
464 {
465  TestApplication application;
466  tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
467 
468  Dali::TypeInfo info;
469  Actor actor = Actor::New();
470 
471  bool ok = actor.GetTypeInfo( info );
472  DALI_TEST_CHECK( ok );
473  END_TEST;
474 }
475 
477 {
478  TestApplication application;
479  tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
480  FakeHandle handle;
481  handle.RunTest();
483  END_TEST;
484 
485 }
486 
488 {
489  TestApplication application;
490  tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
491 
492  Dali::TypeInfo info;
493  FakeObject object;
494 
495  bool ok = object.GetTypeInfo( info );
496  DALI_TEST_CHECK( !ok );
497  END_TEST;
498 }
499 
501 {
502  TestApplication application;
503  tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
504 
505  // get the root layer
506  Actor actor = Actor::New();
507 
508  Dali::RefObject* p = actor.GetObjectPtr();
509 
510  DALI_TEST_CHECK( p != NULL );
511  END_TEST;
512 }
513 
515 {
516  TestApplication application;
517  tet_infoline("Testing Dali::BaseHandle::BooleanType");
518 
519  // get the root layer
520  BaseHandle handle = Actor::New();
521 
522  DALI_TEST_CHECK( static_cast<BaseHandle::BooleanType>( handle ) );
523  END_TEST;
524 }
525 
527 {
528  TestApplication application;
529  BaseHandle handle1 = Actor::New();
530  BaseHandle handle2 = handle1;
531 
532  DALI_TEST_CHECK( (handle1 < handle2) == false );
533 
534  END_TEST;
535 }
Dali Docs Home
Read more about Dali