Dali 3D User Interface Engine
utc-Dali-WeakHandle.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
20 #include <dali-test-suite-utils.h>
21 
22 using namespace Dali;
23 
24 namespace
25 {
26 
27 /*******************************************************************************
28  *
29  * Custom Actor
30  *
31  ******************************************************************************/
32 namespace Impl
33 {
35 {
38 
39  MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
40  { }
41 
42  virtual ~MyTestCustomActor()
43  { }
44 
45  void ResetCallStack()
46  {
47  }
48 
49  // From CustomActorImpl
50  virtual void OnStageConnection( int depth )
51  {
52  }
53  virtual void OnStageDisconnection()
54  {
55  }
56  virtual void OnChildAdd(Actor& child)
57  {
58  }
59  virtual void OnChildRemove(Actor& child)
60  {
61  }
62  virtual void OnSizeSet(const Vector3& targetSize)
63  {
64  }
65  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
66  {
67  }
68  virtual bool OnTouchEvent(const TouchEvent& event)
69  {
70  return true;
71  }
72  virtual bool OnHoverEvent(const HoverEvent& event)
73  {
74  return true;
75  }
76  virtual bool OnWheelEvent(const WheelEvent& event)
77  {
78  return true;
79  }
80  virtual bool OnKeyEvent(const KeyEvent& event)
81  {
82  return true;
83  }
84  virtual void OnKeyInputFocusGained()
85  {
86  }
87  virtual void OnKeyInputFocusLost()
88  {
89  }
90  virtual Vector3 GetNaturalSize()
91  {
92  return Vector3( 0.0f, 0.0f, 0.0f );
93  }
94 
95  virtual float GetHeightForWidth( float width )
96  {
97  return 0.0f;
98  }
99 
100  virtual float GetWidthForHeight( float height )
101  {
102  return 0.0f;
103  }
104 
105  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
106  {
107  }
108 
109  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
110  {
111  }
112 
113  virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
114  {
115  }
116 
117  virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
118  {
119  return 0.0f;
120  }
121 
122  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
123  {
124  }
125 
126  virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
127  {
128  return false;
129  }
130 
131 public:
132 
134 };
135 
136 }; // namespace Impl
137 
139 {
140 public:
141 
144 
146  {
147  }
148 
150  {
152  return MyTestCustomActor( *p ); // takes ownership
153  }
154 
155  virtual ~MyTestCustomActor()
156  {
157  }
158 
160  {
161  MyTestCustomActor result;
162 
163  CustomActor custom = Dali::CustomActor::DownCast( handle );
164  if ( custom )
165  {
166  CustomActorImpl& customImpl = custom.GetImplementation();
167 
168  Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
169 
170  if (impl)
171  {
172  result = MyTestCustomActor(customImpl.GetOwner());
173  }
174  }
175 
176  return result;
177  }
178 
179  SignalType& GetCustomSignal()
180  {
182  return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
183  }
184 
185  MyTestCustomActor(Internal::CustomActor* internal)
186  : CustomActor(internal)
187  {
188  }
189 
191  : CustomActor( impl )
192  {
193  }
194 };
195 
196 }
197 
199 {
200  TestApplication application;
201  tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase()");
202 
203  WeakHandleBase object;
204 
205  DALI_TEST_CHECK(!object.GetBaseHandle());
206 
207  END_TEST;
208 }
209 
211 {
212  TestApplication application;
213  tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(Handle)");
214 
215  Handle emptyHandle;
216  WeakHandleBase emptyObject(emptyHandle);
217  DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
218 
219  Actor actor = Actor::New();
220  WeakHandleBase object(actor);
221  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
222 
223  END_TEST;
224 }
225 
227 {
228  TestApplication application;
229  tet_infoline("Testing Dali::WeakHandleBase::WeakHandleBase(const WeakHandleBase&)");
230 
231  Actor actor = Actor::New();
232  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
233 
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
237 
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
241 
242  END_TEST;
243 }
244 
246 {
247  TestApplication application;
248  tet_infoline("Testing Dali::WeakHandleBase::operator=");
249 
250  Actor actor = Actor::New();
251  DALI_TEST_EQUALS(1, actor.GetBaseObject().ReferenceCount(), TEST_LOCATION); // reference count of the actor is not increased
252 
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
256 
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
260 
261  END_TEST;
262 }
263 
265 {
266  TestApplication application;
267  tet_infoline("Positive Test Dali::WeakHandleBase::operator==");
268 
269  WeakHandleBase object;
270  WeakHandleBase theSameObject;
271  DALI_TEST_CHECK(object == theSameObject);
272 
273  Actor actor = Actor::New();
274 
275  object = WeakHandleBase(actor);
276  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
277 
278  theSameObject = object;
279  DALI_TEST_CHECK(theSameObject.GetBaseHandle() == actor);
280  DALI_TEST_CHECK(object == theSameObject);
281 
282  END_TEST;
283 }
284 
286 {
287  TestApplication application;
288  tet_infoline("Negative Test Dali::WeakHandleBase::operator==");
289 
290  Actor actor = Actor::New();
291 
292  WeakHandleBase object(actor);
293  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
294 
295  Actor differentActor = Actor::New();
296  WeakHandleBase aDifferentWeakHandleBase(differentActor);
297 
298  DALI_TEST_CHECK(!(object == aDifferentWeakHandleBase));
299 
300  END_TEST;
301 }
302 
304 {
305  TestApplication application;
306  tet_infoline("Positive Test Dali::WeakHandleBase::operator!=");
307 
308  Actor actor = Actor::New();
309 
310  WeakHandleBase object(actor);
311  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
312 
313  Actor differentActor = Actor::New();
314  WeakHandleBase aDifferentWeakHandleBase(differentActor);
315 
316  DALI_TEST_CHECK(object != aDifferentWeakHandleBase);
317  END_TEST;
318 }
319 
321 {
322  TestApplication application;
323  tet_infoline("Negative Test Dali::WeakHandleBase::operator!=");
324 
325  Actor actor = Actor::New();
326 
327  WeakHandleBase object(actor);
328  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
329 
330  WeakHandleBase theSameWeakHandleBase = object;
331 
332  DALI_TEST_CHECK(!(object != theSameWeakHandleBase));
333  END_TEST;
334 }
335 
337 {
338  TestApplication application;
339  tet_infoline("Testing Dali::WeakHandleBase::GetBaseHandle()");
340 
341  Handle emptyHandle;
342  WeakHandleBase emptyObject(emptyHandle);
343  DALI_TEST_CHECK(!emptyObject.GetBaseHandle());
344 
345  Actor actor = Actor::New();
346  WeakHandleBase object(actor);
347  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
348 
349  WeakHandleBase theSameObject = WeakHandleBase(actor);
350  DALI_TEST_CHECK(object.GetBaseHandle() == theSameObject.GetBaseHandle());
351 
352  Actor differentActor = Actor::New();
353  WeakHandleBase aDifferentWeakHandleBase(differentActor);
354  DALI_TEST_CHECK(object.GetBaseHandle() != aDifferentWeakHandleBase.GetBaseHandle());
355 
356  END_TEST;
357 }
358 
360 {
361  TestApplication application;
362  tet_infoline("Testing Dali::WeakHandle::GetHandle()");
363 
364  Actor actor = Actor::New();
365  WeakHandle<Actor> object(actor);
366  DALI_TEST_CHECK(object.GetHandle() == actor);
367 
368  MyTestCustomActor customActor = MyTestCustomActor::New();
369  WeakHandle<MyTestCustomActor> customObject(customActor);
370  DALI_TEST_CHECK(customObject.GetHandle() == customActor);
371 
372  DALI_TEST_CHECK(object.GetHandle() != customObject.GetHandle());
373 
374  END_TEST;
375 }
376 
377 
378 
Dali Docs Home
Read more about Dali