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-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
25 /*******************************************************************************
29 ******************************************************************************/
32 struct MyTestCustomActor : public CustomActorImpl
34 typedef Signal<void()> SignalType;
35 typedef Signal<void(float)> SignalTypeFloat;
38 : CustomActorImpl(ActorFlags())
42 virtual ~MyTestCustomActor()
50 // From CustomActorImpl
51 virtual void OnSceneConnection(int depth)
54 virtual void OnSceneDisconnection()
57 virtual void OnChildAdd(Actor& child)
60 virtual void OnChildRemove(Actor& child)
63 virtual void OnSizeSet(const Vector3& targetSize)
66 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
69 virtual void OnKeyInputFocusGained()
72 virtual void OnKeyInputFocusLost()
75 virtual Vector3 GetNaturalSize()
77 return Vector3(0.0f, 0.0f, 0.0f);
80 virtual float GetHeightForWidth(float width)
85 virtual float GetWidthForHeight(float height)
90 virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
94 virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
98 virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
102 virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
107 virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
111 virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS)
122 class MyTestCustomActor : public CustomActor
125 typedef Signal<void()> SignalType;
126 typedef Signal<void(float)> SignalTypeFloat;
132 static MyTestCustomActor New()
134 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
135 return MyTestCustomActor(*p); // takes ownership
138 virtual ~MyTestCustomActor()
142 static MyTestCustomActor DownCast(BaseHandle handle)
144 MyTestCustomActor result;
146 CustomActor custom = Dali::CustomActor::DownCast(handle);
149 CustomActorImpl& customImpl = custom.GetImplementation();
151 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
155 result = MyTestCustomActor(customImpl.GetOwner());
162 SignalType& GetCustomSignal()
164 Dali::RefObject& obj = GetImplementation();
165 return static_cast<Impl::MyTestCustomActor&>(obj).mSignal;
168 MyTestCustomActor(Internal::CustomActor* internal)
169 : CustomActor(internal)
173 MyTestCustomActor(Impl::MyTestCustomActor& impl)
181 int UtcDaliWeakHandleBaseConstructorVoid(void)
183 TestApplication application;
184 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase()");
186 WeakHandleBase object;
188 DALI_TEST_CHECK(!object.GetBaseHandle());
193 int UtcDaliWeakHandleBaseConstructorWithBaseHandle(void)
195 TestApplication application;
196 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(BaseHandle)");
198 BaseHandle emptyHandle;
199 WeakHandleBase emptyObject(emptyHandle);
200 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
202 Actor actor = Actor::New();
203 WeakHandleBase object(actor);
204 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
206 Animation animation = Animation::New(1.0f);
207 WeakHandleBase animationObject(animation);
208 DALI_TEST_CHECK(animationObject.GetBaseHandle() == animation);
213 int UtcDaliWeakHandleBaseCopyConstructor(void)
215 TestApplication application;
216 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)");
218 Actor actor = Actor::New();
219 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
221 WeakHandleBase object(actor);
222 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
223 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
225 WeakHandleBase copy(object);
226 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
227 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
232 int UtcDaliWeakHandleBaseAssignmentOperator(void)
234 TestApplication application;
235 tet_infoline("Testing Dali::WeakHandleBase::operator=");
237 Actor actor = Actor::New();
238 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
240 WeakHandleBase object(actor);
241 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
242 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
244 WeakHandleBase copy = object;
245 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
246 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
251 int UtcDaliWeakHandleBaseMoveConstructor(void)
253 TestApplication application;
255 Actor actor = Actor::New();
256 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
258 WeakHandleBase object(actor);
259 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
260 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
262 WeakHandleBase move = std::move(object);
263 DALI_TEST_CHECK(move.GetBaseHandle() == actor);
264 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
265 DALI_TEST_CHECK(!object.GetBaseHandle()); // object moved
270 int UtcDaliWeakHandleBaseMoveAssignment(void)
272 TestApplication application;
274 Actor actor = Actor::New();
275 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
277 WeakHandleBase object(actor);
278 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
279 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
282 move = std::move(object);
283 DALI_TEST_CHECK(move.GetBaseHandle() == actor);
284 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
285 DALI_TEST_CHECK(!object.GetBaseHandle()); // object moved
290 int UtcDaliWeakHandleBaseEqualityOperatorP(void)
292 TestApplication application;
293 tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
295 WeakHandleBase object;
296 WeakHandleBase theSameObject;
297 DALI_TEST_CHECK(object == theSameObject);
299 Actor actor = Actor::New();
301 object = WeakHandleBase(actor);
302 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
304 theSameObject = object;
305 DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
306 DALI_TEST_CHECK(object == theSameObject);
311 int UtcDaliWeakHandleBaseEqualityOperatorN(void)
313 TestApplication application;
314 tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
316 Actor actor = Actor::New();
318 WeakHandleBase object(actor);
319 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
321 Actor differentActor = Actor::New();
322 WeakHandleBase aDifferentWeakHandleBase(differentActor);
324 DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
329 int UtcDaliWeakHandleBaseInequalityOperatorP(void)
331 TestApplication application;
332 tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
334 Actor actor = Actor::New();
336 WeakHandleBase object(actor);
337 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
339 Actor differentActor = Actor::New();
340 WeakHandleBase aDifferentWeakHandleBase(differentActor);
342 DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
346 int UtcDaliWeakHandleBaseInequalityOperatorN(void)
348 TestApplication application;
349 tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
351 Actor actor = Actor::New();
353 WeakHandleBase object(actor);
354 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
356 WeakHandleBase theSameWeakHandleBase = object;
358 DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
362 int UtcDaliWeakHandleBaseGetBaseHandle(void)
364 TestApplication application;
365 tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
368 WeakHandleBase emptyObject(emptyHandle);
369 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
371 Actor actor = Actor::New();
372 WeakHandleBase object(actor);
373 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
375 WeakHandleBase theSameObject = WeakHandleBase(actor);
376 DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
378 Actor differentActor = Actor::New();
379 WeakHandleBase aDifferentWeakHandleBase(differentActor);
380 DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
382 Animation animation = Animation::New(1.0f);
383 WeakHandleBase animationObject(animation);
384 DALI_TEST_CHECK(animationObject.GetBaseHandle() == animation);
386 WeakHandleBase theSameAnimationObject = WeakHandleBase(animation);
387 DALI_TEST_CHECK(animationObject.GetBaseHandle() == theSameAnimationObject.GetBaseHandle());
389 Animation differentAnimation = Animation::New(1.0f);
390 WeakHandleBase aDifferentAnimationObject(differentAnimation);
391 DALI_TEST_CHECK(animationObject.GetBaseHandle() != aDifferentAnimationObject.GetBaseHandle());
396 int UtcDaliWeakHandleBaseReset(void)
398 TestApplication application;
399 tet_infoline("Testing Daku::WeakHandleBase::Reset()");
401 Actor actor = Actor::New();
402 WeakHandleBase object(actor);
403 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
407 DALI_TEST_CHECK(object == WeakHandleBase());
408 DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
413 int UtcDaliWeakHandleGetHandle(void)
415 TestApplication application;
416 tet_infoline("Testing Dali::WeakHandle::GetHandle()");
418 Actor actor = Actor::New();
419 WeakHandle<Actor> object(actor);
420 DALI_TEST_CHECK(object.GetHandle() == actor);
422 MyTestCustomActor customActor = MyTestCustomActor::New();
423 WeakHandle<MyTestCustomActor> customObject(customActor);
424 DALI_TEST_CHECK(customObject.GetHandle() == customActor);
426 DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
428 Animation animation = Animation::New(1.0f);
429 WeakHandle<Animation> animationObject(animation);
430 DALI_TEST_CHECK(animationObject.GetHandle() == animation);
433 DALI_TEST_CHECK(animationObject.GetHandle() == Animation());
438 int UtcDaliWeakHandleMoveConstructor(void)
440 TestApplication application;
442 Actor actor = Actor::New();
443 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
445 WeakHandle<Actor> object(actor);
446 DALI_TEST_CHECK(object.GetHandle() == actor);
447 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
449 WeakHandle<Actor> move = std::move(object);
450 DALI_TEST_CHECK(move.GetHandle() == actor);
451 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
452 DALI_TEST_CHECK(!object.GetHandle()); // object moved
457 int UtcDaliWeakHandleMoveAssignment(void)
459 TestApplication application;
461 Actor actor = Actor::New();
462 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
464 WeakHandle<Actor> object(actor);
465 DALI_TEST_CHECK(object.GetHandle() == actor);
466 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
468 WeakHandle<Actor> move;
469 move = std::move(object);
470 DALI_TEST_CHECK(move.GetHandle() == actor);
471 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
472 DALI_TEST_CHECK(!object.GetHandle()); // object moved