2 * Copyright (c) 2020 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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
26 /*******************************************************************************
30 ******************************************************************************/
33 struct MyTestCustomActor : public CustomActorImpl
35 typedef Signal< void ()> SignalType;
36 typedef Signal< void (float)> SignalTypeFloat;
38 MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
41 virtual ~MyTestCustomActor()
48 // From CustomActorImpl
49 virtual void OnSceneConnection( int depth )
52 virtual void OnSceneDisconnection()
55 virtual void OnChildAdd(Actor& child)
58 virtual void OnChildRemove(Actor& child)
61 virtual void OnSizeSet(const Vector3& targetSize)
64 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
67 virtual bool OnHoverEvent(const HoverEvent& event)
71 virtual bool OnWheelEvent(const WheelEvent& event)
75 virtual bool OnKeyEvent(const KeyEvent& event)
79 virtual void OnKeyInputFocusGained()
82 virtual void OnKeyInputFocusLost()
85 virtual Vector3 GetNaturalSize()
87 return Vector3( 0.0f, 0.0f, 0.0f );
90 virtual float GetHeightForWidth( float width )
95 virtual float GetWidthForHeight( float height )
100 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
104 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
108 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
112 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
117 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
121 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
133 class MyTestCustomActor : public CustomActor
137 typedef Signal< void ()> SignalType;
138 typedef Signal< void (float)> SignalTypeFloat;
144 static MyTestCustomActor New()
146 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
147 return MyTestCustomActor( *p ); // takes ownership
150 virtual ~MyTestCustomActor()
154 static MyTestCustomActor DownCast( BaseHandle handle )
156 MyTestCustomActor result;
158 CustomActor custom = Dali::CustomActor::DownCast( handle );
161 CustomActorImpl& customImpl = custom.GetImplementation();
163 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
167 result = MyTestCustomActor(customImpl.GetOwner());
174 SignalType& GetCustomSignal()
176 Dali::RefObject& obj = GetImplementation();
177 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
180 MyTestCustomActor(Internal::CustomActor* internal)
181 : CustomActor(internal)
185 MyTestCustomActor( Impl::MyTestCustomActor& impl )
186 : CustomActor( impl )
193 int UtcDaliWeakHandleBaseConstructorVoid(void)
195 TestApplication application;
196 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase()");
198 WeakHandleBase object;
200 DALI_TEST_CHECK(!object.GetBaseHandle());
205 int UtcDaliWeakHandleBaseConstructorWithBaseHandle(void)
207 TestApplication application;
208 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(BaseHandle)");
210 BaseHandle emptyHandle;
211 WeakHandleBase emptyObject(emptyHandle);
212 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
214 Actor actor = Actor::New();
215 WeakHandleBase object(actor);
216 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
218 Animation animation = Animation::New( 1.0f );
219 WeakHandleBase animationObject( animation );
220 DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
225 int UtcDaliWeakHandleBaseCopyConstructor(void)
227 TestApplication application;
228 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)");
230 Actor actor = Actor::New();
231 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
233 WeakHandleBase object(actor);
234 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
235 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
237 WeakHandleBase copy(object);
238 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
239 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
244 int UtcDaliWeakHandleBaseAssignmentOperator(void)
246 TestApplication application;
247 tet_infoline("Testing Dali::WeakHandleBase::operator=");
249 Actor actor = Actor::New();
250 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
252 WeakHandleBase object(actor);
253 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
254 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
256 WeakHandleBase copy = object;
257 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
258 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
263 int UtcDaliWeakHandleBaseMoveConstructor(void)
265 TestApplication application;
267 Actor actor = Actor::New();
268 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
270 WeakHandleBase object( actor );
271 DALI_TEST_CHECK( object.GetBaseHandle() == actor);
272 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
274 WeakHandleBase move = std::move( object );
275 DALI_TEST_CHECK(move.GetBaseHandle() == actor );
276 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
277 DALI_TEST_CHECK( !object.GetBaseHandle() ); // object moved
282 int UtcDaliWeakHandleBaseMoveAssignment(void)
284 TestApplication application;
286 Actor actor = Actor::New();
287 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
289 WeakHandleBase object( actor );
290 DALI_TEST_CHECK( object.GetBaseHandle() == actor);
291 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
294 move = std::move( object );
295 DALI_TEST_CHECK(move.GetBaseHandle() == actor );
296 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
297 DALI_TEST_CHECK( !object.GetBaseHandle() ); // object moved
302 int UtcDaliWeakHandleBaseEqualityOperatorP(void)
304 TestApplication application;
305 tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
307 WeakHandleBase object;
308 WeakHandleBase theSameObject;
309 DALI_TEST_CHECK(object == theSameObject);
311 Actor actor = Actor::New();
313 object = WeakHandleBase(actor);
314 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
316 theSameObject = object;
317 DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
318 DALI_TEST_CHECK(object == theSameObject);
323 int UtcDaliWeakHandleBaseEqualityOperatorN(void)
325 TestApplication application;
326 tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
328 Actor actor = Actor::New();
330 WeakHandleBase object(actor);
331 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
333 Actor differentActor = Actor::New();
334 WeakHandleBase aDifferentWeakHandleBase(differentActor);
336 DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
341 int UtcDaliWeakHandleBaseInequalityOperatorP(void)
343 TestApplication application;
344 tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
346 Actor actor = Actor::New();
348 WeakHandleBase object(actor);
349 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
351 Actor differentActor = Actor::New();
352 WeakHandleBase aDifferentWeakHandleBase(differentActor);
354 DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
358 int UtcDaliWeakHandleBaseInequalityOperatorN(void)
360 TestApplication application;
361 tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
363 Actor actor = Actor::New();
365 WeakHandleBase object(actor);
366 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
368 WeakHandleBase theSameWeakHandleBase = object;
370 DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
374 int UtcDaliWeakHandleBaseGetBaseHandle(void)
376 TestApplication application;
377 tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
380 WeakHandleBase emptyObject(emptyHandle);
381 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
383 Actor actor = Actor::New();
384 WeakHandleBase object(actor);
385 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
387 WeakHandleBase theSameObject = WeakHandleBase(actor);
388 DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
390 Actor differentActor = Actor::New();
391 WeakHandleBase aDifferentWeakHandleBase(differentActor);
392 DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
394 Animation animation = Animation::New( 1.0f );
395 WeakHandleBase animationObject( animation );
396 DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
398 WeakHandleBase theSameAnimationObject = WeakHandleBase( animation );
399 DALI_TEST_CHECK( animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle() );
401 Animation differentAnimation = Animation::New( 1.0f );
402 WeakHandleBase aDifferentAnimationObject( differentAnimation );
403 DALI_TEST_CHECK( animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle() );
408 int UtcDaliWeakHandleBaseReset(void)
410 TestApplication application;
411 tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
413 Actor actor = Actor::New();
414 WeakHandleBase object(actor);
415 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
419 DALI_TEST_CHECK(object == WeakHandleBase());
420 DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
425 int UtcDaliWeakHandleGetHandle(void)
427 TestApplication application;
428 tet_infoline("Testing Dali::WeakHandle::GetHandle()");
430 Actor actor = Actor::New();
431 WeakHandle<Actor> object(actor);
432 DALI_TEST_CHECK(object.GetHandle() == actor);
434 MyTestCustomActor customActor = MyTestCustomActor::New();
435 WeakHandle<MyTestCustomActor> customObject(customActor);
436 DALI_TEST_CHECK(customObject.GetHandle() == customActor);
438 DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
440 Animation animation = Animation::New( 1.0f );
441 WeakHandle<Animation> animationObject( animation );
442 DALI_TEST_CHECK( animationObject.GetHandle() == animation );
445 DALI_TEST_CHECK( animationObject.GetHandle() == Animation() );
450 int UtcDaliWeakHandleMoveConstructor(void)
452 TestApplication application;
454 Actor actor = Actor::New();
455 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
457 WeakHandle<Actor> object( actor );
458 DALI_TEST_CHECK( object.GetHandle() == actor );
459 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
461 WeakHandle<Actor> move = std::move( object );
462 DALI_TEST_CHECK( move.GetHandle() == actor );
463 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
464 DALI_TEST_CHECK( !object.GetHandle() ); // object moved
469 int UtcDaliWeakHandleMoveAssignment(void)
471 TestApplication application;
473 Actor actor = Actor::New();
474 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
476 WeakHandle<Actor> object( actor );
477 DALI_TEST_CHECK( object.GetHandle() == actor );
478 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
480 WeakHandle<Actor> move;
481 move = std::move( object );
482 DALI_TEST_CHECK( move.GetHandle() == actor );
483 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
484 DALI_TEST_CHECK( !object.GetHandle() ); // object moved