2 * Copyright (c) 2017 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 OnStageConnection( int depth )
52 virtual void OnStageDisconnection()
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 UtcDaliWeakHandleBaseConstructorWithHandle(void)
211 TestApplication application;
212 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(Handle)");
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);
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 UtcDaliWeakHandleBaseEqualityOperatorP(void)
265 TestApplication application;
266 tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
268 WeakHandleBase object;
269 WeakHandleBase theSameObject;
270 DALI_TEST_CHECK(object == theSameObject);
272 Actor actor = Actor::New();
274 object = WeakHandleBase(actor);
275 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
277 theSameObject = object;
278 DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
279 DALI_TEST_CHECK(object == theSameObject);
284 int UtcDaliWeakHandleBaseEqualityOperatorN(void)
286 TestApplication application;
287 tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
289 Actor actor = Actor::New();
291 WeakHandleBase object(actor);
292 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
294 Actor differentActor = Actor::New();
295 WeakHandleBase aDifferentWeakHandleBase(differentActor);
297 DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
302 int UtcDaliWeakHandleBaseInequalityOperatorP(void)
304 TestApplication application;
305 tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
307 Actor actor = Actor::New();
309 WeakHandleBase object(actor);
310 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
312 Actor differentActor = Actor::New();
313 WeakHandleBase aDifferentWeakHandleBase(differentActor);
315 DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
319 int UtcDaliWeakHandleBaseInequalityOperatorN(void)
321 TestApplication application;
322 tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
324 Actor actor = Actor::New();
326 WeakHandleBase object(actor);
327 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
329 WeakHandleBase theSameWeakHandleBase = object;
331 DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
335 int UtcDaliWeakHandleBaseGetBaseHandle(void)
337 TestApplication application;
338 tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
341 WeakHandleBase emptyObject(emptyHandle);
342 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
344 Actor actor = Actor::New();
345 WeakHandleBase object(actor);
346 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
348 WeakHandleBase theSameObject = WeakHandleBase(actor);
349 DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
351 Actor differentActor = Actor::New();
352 WeakHandleBase aDifferentWeakHandleBase(differentActor);
353 DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
358 int UtcDaliWeakHandleBaseReset(void)
360 TestApplication application;
361 tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
363 Actor actor = Actor::New();
364 WeakHandleBase object(actor);
365 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
369 DALI_TEST_CHECK(object == WeakHandleBase());
370 DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
375 int UtcDaliWeakHandleGetHandle(void)
377 TestApplication application;
378 tet_infoline("Testing Dali::WeakHandle::GetHandle()");
380 Actor actor = Actor::New();
381 WeakHandle<Actor> object(actor);
382 DALI_TEST_CHECK(object.GetHandle() == actor);
384 MyTestCustomActor customActor = MyTestCustomActor::New();
385 WeakHandle<MyTestCustomActor> customObject(customActor);
386 DALI_TEST_CHECK(customObject.GetHandle() == customActor);
388 DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());