2 * Copyright (c) 2015 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/devel-api/object/weak-handle.h>
20 #include <dali-test-suite-utils.h>
27 /*******************************************************************************
31 ******************************************************************************/
34 struct MyTestCustomActor : public CustomActorImpl
36 typedef Signal< void ()> SignalType;
37 typedef Signal< void (float)> SignalTypeFloat;
39 MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
42 virtual ~MyTestCustomActor()
49 // From CustomActorImpl
50 virtual void OnStageConnection( int depth )
53 virtual void OnStageDisconnection()
56 virtual void OnChildAdd(Actor& child)
59 virtual void OnChildRemove(Actor& child)
62 virtual void OnSizeSet(const Vector3& targetSize)
65 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
68 virtual bool OnTouchEvent(const TouchEvent& event)
72 virtual bool OnHoverEvent(const HoverEvent& event)
76 virtual bool OnWheelEvent(const WheelEvent& event)
80 virtual bool OnKeyEvent(const KeyEvent& event)
84 virtual void OnKeyInputFocusGained()
87 virtual void OnKeyInputFocusLost()
90 virtual Vector3 GetNaturalSize()
92 return Vector3( 0.0f, 0.0f, 0.0f );
95 virtual float GetHeightForWidth( float width )
100 virtual float GetWidthForHeight( float height )
105 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
109 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
113 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
117 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
122 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
126 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
138 class MyTestCustomActor : public CustomActor
142 typedef Signal< void ()> SignalType;
143 typedef Signal< void (float)> SignalTypeFloat;
149 static MyTestCustomActor New()
151 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
152 return MyTestCustomActor( *p ); // takes ownership
155 virtual ~MyTestCustomActor()
159 static MyTestCustomActor DownCast( BaseHandle handle )
161 MyTestCustomActor result;
163 CustomActor custom = Dali::CustomActor::DownCast( handle );
166 CustomActorImpl& customImpl = custom.GetImplementation();
168 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
172 result = MyTestCustomActor(customImpl.GetOwner());
179 SignalType& GetCustomSignal()
181 Dali::RefObject& obj = GetImplementation();
182 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
185 MyTestCustomActor(Internal::CustomActor* internal)
186 : CustomActor(internal)
190 MyTestCustomActor( Impl::MyTestCustomActor& impl )
191 : CustomActor( impl )
198 int UtcDaliWeakHandleBaseConstructorVoid(void)
200 TestApplication application;
201 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase()");
203 WeakHandleBase object;
205 DALI_TEST_CHECK(!object.GetBaseHandle());
210 int UtcDaliWeakHandleBaseConstructorWithHandle(void)
212 TestApplication application;
213 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(Handle)");
216 WeakHandleBase emptyObject(emptyHandle);
217 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
219 Actor actor = Actor::New();
220 WeakHandleBase object(actor);
221 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
226 int UtcDaliWeakHandleBaseCopyConstructor(void)
228 TestApplication application;
229 tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)");
231 Actor actor = Actor::New();
232 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
234 WeakHandleBase object(actor);
235 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
236 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
238 WeakHandleBase copy(object);
239 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
240 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
245 int UtcDaliWeakHandleBaseAssignmentOperator(void)
247 TestApplication application;
248 tet_infoline("Testing Dali::WeakHandleBase::operator=");
250 Actor actor = Actor::New();
251 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
253 WeakHandleBase object(actor);
254 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
255 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
257 WeakHandleBase copy = object;
258 DALI_TEST_CHECK(copy.GetBaseHandle() == actor);
259 DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
264 int UtcDaliWeakHandleBaseEqualityOperatorP(void)
266 TestApplication application;
267 tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
269 WeakHandleBase object;
270 WeakHandleBase theSameObject;
271 DALI_TEST_CHECK(object == theSameObject);
273 Actor actor = Actor::New();
275 object = WeakHandleBase(actor);
276 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
278 theSameObject = object;
279 DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
280 DALI_TEST_CHECK(object == theSameObject);
285 int UtcDaliWeakHandleBaseEqualityOperatorN(void)
287 TestApplication application;
288 tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
290 Actor actor = Actor::New();
292 WeakHandleBase object(actor);
293 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
295 Actor differentActor = Actor::New();
296 WeakHandleBase aDifferentWeakHandleBase(differentActor);
298 DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
303 int UtcDaliWeakHandleBaseInequalityOperatorP(void)
305 TestApplication application;
306 tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
308 Actor actor = Actor::New();
310 WeakHandleBase object(actor);
311 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
313 Actor differentActor = Actor::New();
314 WeakHandleBase aDifferentWeakHandleBase(differentActor);
316 DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
320 int UtcDaliWeakHandleBaseInequalityOperatorN(void)
322 TestApplication application;
323 tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
325 Actor actor = Actor::New();
327 WeakHandleBase object(actor);
328 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
330 WeakHandleBase theSameWeakHandleBase = object;
332 DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
336 int UtcDaliWeakHandleBaseGetBaseHandle(void)
338 TestApplication application;
339 tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
342 WeakHandleBase emptyObject(emptyHandle);
343 DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
345 Actor actor = Actor::New();
346 WeakHandleBase object(actor);
347 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
349 WeakHandleBase theSameObject = WeakHandleBase(actor);
350 DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
352 Actor differentActor = Actor::New();
353 WeakHandleBase aDifferentWeakHandleBase(differentActor);
354 DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
359 int UtcDaliWeakHandleBaseReset(void)
361 TestApplication application;
362 tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
364 Actor actor = Actor::New();
365 WeakHandleBase object(actor);
366 DALI_TEST_CHECK(object.GetBaseHandle() == actor);
370 DALI_TEST_CHECK(object == WeakHandleBase());
371 DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
376 int UtcDaliWeakHandleGetHandle(void)
378 TestApplication application;
379 tet_infoline("Testing Dali::WeakHandle::GetHandle()");
381 Actor actor = Actor::New();
382 WeakHandle<Actor> object(actor);
383 DALI_TEST_CHECK(object.GetHandle() == actor);
385 MyTestCustomActor customActor = MyTestCustomActor::New();
386 WeakHandle<MyTestCustomActor> customObject(customActor);
387 DALI_TEST_CHECK(customObject.GetHandle() == customActor);
389 DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());