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 OnTouchEvent(const TouchEvent& event)
71 virtual bool OnHoverEvent(const HoverEvent& event)
75 virtual bool OnWheelEvent(const WheelEvent& event)
79 virtual bool OnKeyEvent(const KeyEvent& event)
83 virtual void OnKeyInputFocusGained()
86 virtual void OnKeyInputFocusLost()
89 virtual Vector3 GetNaturalSize()
91 return Vector3( 0.0f, 0.0f, 0.0f );
94 virtual float GetHeightForWidth( float width )
99 virtual float GetWidthForHeight( float height )
104 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
108 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
112 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
116 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
121 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
125 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
137 class MyTestCustomActor : public CustomActor
141 typedef Signal< void ()> SignalType;
142 typedef Signal< void (float)> SignalTypeFloat;
148 static MyTestCustomActor New()
150 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
151 return MyTestCustomActor( *p ); // takes ownership
154 virtual ~MyTestCustomActor()
158 static MyTestCustomActor DownCast( BaseHandle handle )
160 MyTestCustomActor result;
162 CustomActor custom = Dali::CustomActor::DownCast( handle );
165 CustomActorImpl& customImpl = custom.GetImplementation();
167 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
171 result = MyTestCustomActor(customImpl.GetOwner());
178 SignalType& GetCustomSignal()
180 Dali::RefObject& obj = GetImplementation();
181 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
184 MyTestCustomActor(Internal::CustomActor* internal)
185 : CustomActor(internal)
189 MyTestCustomActor( Impl::MyTestCustomActor& impl )
190 : CustomActor( impl )
197 int UtcDaliWeakHandleBaseConstructorVoid(void)
199 TestApplication application;
200 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase()");
202 WeakHandleBase object;
204 DALI_TEST_CHECK(!object.GetBaseHandle());
209 int UtcDaliWeakHandleBaseConstructorWithBaseHandle(void)
211 TestApplication application;
212 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(BaseHandle)");
214 BaseHandle emptyHandle;
215 WeakHandleBase emptyObject(emptyHandle);
216 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
218 Actor actor = Actor::New();
219 WeakHandleBase object(actor);
220 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
222 Animation animation = Animation::New( 1.0f );
223 WeakHandleBase animationObject( animation );
224 DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
229 int UtcDaliWeakHandleBaseCopyConstructor(void)
231 TestApplication application;
232 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)");
234 Actor actor = Actor::New();
235 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
237 WeakHandleBase object(actor);
238 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
239 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
241 WeakHandleBase copy(object);
242 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
243 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
248 int UtcDaliWeakHandleBaseAssignmentOperator(void)
250 TestApplication application;
251 tet_infoline("Testing Dali::WeakHandleBase::operator=");
253 Actor actor = Actor::New();
254 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
256 WeakHandleBase object(actor);
257 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
258 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
260 WeakHandleBase copy = object;
261 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
262 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
267 int UtcDaliWeakHandleBaseMoveConstructor(void)
269 TestApplication application;
271 Actor actor = Actor::New();
272 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
274 WeakHandleBase object( actor );
275 DALI_TEST_CHECK( object.GetBaseHandle() == actor);
276 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
278 WeakHandleBase move = std::move( object );
279 DALI_TEST_CHECK(move.GetBaseHandle() == actor );
280 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
281 DALI_TEST_CHECK( !object.GetBaseHandle() ); // object moved
286 int UtcDaliWeakHandleBaseMoveAssignment(void)
288 TestApplication application;
290 Actor actor = Actor::New();
291 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
293 WeakHandleBase object( actor );
294 DALI_TEST_CHECK( object.GetBaseHandle() == actor);
295 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
298 move = std::move( object );
299 DALI_TEST_CHECK(move.GetBaseHandle() == actor );
300 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
301 DALI_TEST_CHECK( !object.GetBaseHandle() ); // object moved
306 int UtcDaliWeakHandleBaseEqualityOperatorP(void)
308 TestApplication application;
309 tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
311 WeakHandleBase object;
312 WeakHandleBase theSameObject;
313 DALI_TEST_CHECK(object == theSameObject);
315 Actor actor = Actor::New();
317 object = WeakHandleBase(actor);
318 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
320 theSameObject = object;
321 DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
322 DALI_TEST_CHECK(object == theSameObject);
327 int UtcDaliWeakHandleBaseEqualityOperatorN(void)
329 TestApplication application;
330 tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
332 Actor actor = Actor::New();
334 WeakHandleBase object(actor);
335 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
337 Actor differentActor = Actor::New();
338 WeakHandleBase aDifferentWeakHandleBase(differentActor);
340 DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
345 int UtcDaliWeakHandleBaseInequalityOperatorP(void)
347 TestApplication application;
348 tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
350 Actor actor = Actor::New();
352 WeakHandleBase object(actor);
353 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
355 Actor differentActor = Actor::New();
356 WeakHandleBase aDifferentWeakHandleBase(differentActor);
358 DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
362 int UtcDaliWeakHandleBaseInequalityOperatorN(void)
364 TestApplication application;
365 tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
367 Actor actor = Actor::New();
369 WeakHandleBase object(actor);
370 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
372 WeakHandleBase theSameWeakHandleBase = object;
374 DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
378 int UtcDaliWeakHandleBaseGetBaseHandle(void)
380 TestApplication application;
381 tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
384 WeakHandleBase emptyObject(emptyHandle);
385 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
387 Actor actor = Actor::New();
388 WeakHandleBase object(actor);
389 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
391 WeakHandleBase theSameObject = WeakHandleBase(actor);
392 DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
394 Actor differentActor = Actor::New();
395 WeakHandleBase aDifferentWeakHandleBase(differentActor);
396 DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
398 Animation animation = Animation::New( 1.0f );
399 WeakHandleBase animationObject( animation );
400 DALI_TEST_CHECK( animationObject.GetBaseHandle() == animation );
402 WeakHandleBase theSameAnimationObject = WeakHandleBase( animation );
403 DALI_TEST_CHECK( animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle() );
405 Animation differentAnimation = Animation::New( 1.0f );
406 WeakHandleBase aDifferentAnimationObject( differentAnimation );
407 DALI_TEST_CHECK( animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle() );
412 int UtcDaliWeakHandleBaseReset(void)
414 TestApplication application;
415 tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
417 Actor actor = Actor::New();
418 WeakHandleBase object(actor);
419 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
423 DALI_TEST_CHECK(object == WeakHandleBase());
424 DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
429 int UtcDaliWeakHandleGetHandle(void)
431 TestApplication application;
432 tet_infoline("Testing Dali::WeakHandle::GetHandle()");
434 Actor actor = Actor::New();
435 WeakHandle<Actor> object(actor);
436 DALI_TEST_CHECK(object.GetHandle() == actor);
438 MyTestCustomActor customActor = MyTestCustomActor::New();
439 WeakHandle<MyTestCustomActor> customObject(customActor);
440 DALI_TEST_CHECK(customObject.GetHandle() == customActor);
442 DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
444 Animation animation = Animation::New( 1.0f );
445 WeakHandle<Animation> animationObject( animation );
446 DALI_TEST_CHECK( animationObject.GetHandle() == animation );
449 DALI_TEST_CHECK( animationObject.GetHandle() == Animation() );
454 int UtcDaliWeakHandleMoveConstructor(void)
456 TestApplication application;
458 Actor actor = Actor::New();
459 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
461 WeakHandle<Actor> object( actor );
462 DALI_TEST_CHECK( object.GetHandle() == actor );
463 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
465 WeakHandle<Actor> move = std::move( object );
466 DALI_TEST_CHECK( move.GetHandle() == actor );
467 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
468 DALI_TEST_CHECK( !object.GetHandle() ); // object moved
473 int UtcDaliWeakHandleMoveAssignment(void)
475 TestApplication application;
477 Actor actor = Actor::New();
478 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
480 WeakHandle<Actor> object( actor );
481 DALI_TEST_CHECK( object.GetHandle() == actor );
482 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
484 WeakHandle<Actor> move;
485 move = std::move( object );
486 DALI_TEST_CHECK( move.GetHandle() == actor );
487 DALI_TEST_EQUALS( 1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION ); // reference count of the actor is not increased
488 DALI_TEST_CHECK( !object.GetHandle() ); // object moved