Merge "Include the algorithm header file" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / dali-test-suite-utils / test-custom-actor.cpp
1 #include "test-custom-actor.h"
2
3 using namespace Dali;
4
5 std::vector<std::string> MasterCallStack;
6 bool                     gOnRelayout = false;
7
8 namespace Test
9 {
10 namespace Impl
11 {
12 struct TestCustomActor;
13 }
14
15 TestCustomActor TestCustomActor::New()
16 {
17   Impl::TestCustomActor* impl = new Impl::TestCustomActor;
18   TestCustomActor        custom(*impl); // takes ownership
19
20   impl->Initialize();
21
22   return custom;
23 }
24
25 TestCustomActor TestCustomActor::NewNegoSize()
26 {
27   Impl::TestCustomActor* impl = new Impl::TestCustomActor(true);
28   TestCustomActor        custom(*impl); // takes ownership
29   custom.SetProperty(Dali::Actor::Property::NAME, "SizeNegotiationActor");
30
31   impl->Initialize();
32
33   return custom;
34 }
35
36 TestCustomActor TestCustomActor::NewVariant1(Actor childToAdd)
37 {
38   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1(childToAdd);
39   TestCustomActor        custom(*impl); // takes ownership
40
41   impl->Initialize();
42
43   return custom;
44 }
45
46 TestCustomActor TestCustomActor::NewVariant2()
47 {
48   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
49   TestCustomActor        custom(*impl); // takes ownership
50
51   impl->Initialize();
52
53   return custom;
54 }
55
56 TestCustomActor TestCustomActor::NewVariant3(Actor childToAdd)
57 {
58   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3(childToAdd);
59   TestCustomActor        custom(*impl); // takes ownership
60
61   impl->Initialize();
62
63   return custom;
64 }
65
66 TestCustomActor TestCustomActor::NewVariant4()
67 {
68   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
69   TestCustomActor        custom(*impl); // takes ownership
70
71   impl->Initialize();
72
73   return custom;
74 }
75
76 TestCustomActor TestCustomActor::NewVariant5(Integration::Scene scene)
77 {
78   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(scene);
79   TestCustomActor        custom(*impl); // takes ownership
80
81   impl->Initialize();
82
83   return custom;
84 }
85
86 TestCustomActor TestCustomActor::NewVariant6(Integration::Scene scene)
87 {
88   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(scene);
89   TestCustomActor        custom(*impl); // takes ownership
90
91   impl->Initialize();
92
93   return custom;
94 }
95
96 TestCustomActor TestCustomActor::NewVariant7(const char* name)
97 {
98   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
99   TestCustomActor        custom(*impl); // takes ownership
100
101   impl->Initialize(name);
102
103   return custom;
104 }
105
106 TestCustomActor TestCustomActor::NewVariant8(Actor rival)
107 {
108   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8(rival);
109   TestCustomActor        custom(*impl); // takes ownership
110
111   impl->Initialize();
112
113   return custom;
114 }
115
116 TestCustomActor::~TestCustomActor()
117 {
118 }
119
120 Impl::TestCustomActor& TestCustomActor::GetImpl()
121 {
122   return static_cast<Impl::TestCustomActor&>(GetImplementation());
123 }
124
125 std::vector<std::string>& TestCustomActor::GetMethodsCalled()
126 {
127   return GetImpl().mMethodsCalled;
128 }
129
130 void TestCustomActor::ResetCallStack()
131 {
132   GetImpl().ResetCallStack();
133 }
134
135 void TestCustomActor::SetDaliProperty(std::string s)
136 {
137   GetImpl().SetDaliProperty(s);
138 }
139
140 Vector3 TestCustomActor::GetSize()
141 {
142   return GetImpl().mSizeSet;
143 }
144
145 Vector3 TestCustomActor::GetTargetSize()
146 {
147   return GetImpl().mTargetSize;
148 }
149
150 Vector3 TestCustomActor::GetNaturalSize()
151 {
152   return Vector3(0.0f, 0.0f, 0.0f);
153 }
154
155 float TestCustomActor::GetHeightForWidth(float width)
156 {
157   return 0.0f;
158 }
159
160 float TestCustomActor::GetWidthForHeight(float height)
161 {
162   return 0.0f;
163 }
164
165 void TestCustomActor::OnRelayout(const Vector2& size, RelayoutContainer& container)
166 {
167 }
168
169 void TestCustomActor::OnLayoutNegotiated(float size, Dimension::Type dimension)
170 {
171 }
172
173 void TestCustomActor::OnCalculateRelayoutSize(Dimension::Type dimension)
174 {
175 }
176
177 void TestCustomActor::TestRelayoutRequest()
178 {
179   GetImpl().TestRelayoutRequest();
180 }
181
182 float TestCustomActor::TestGetHeightForWidthBase(float width)
183 {
184   return GetImpl().TestGetHeightForWidthBase(width);
185 }
186
187 float TestCustomActor::TestGetWidthForHeightBase(float height)
188 {
189   return GetImpl().TestGetWidthForHeightBase(height);
190 }
191
192 float TestCustomActor::TestCalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension)
193 {
194   return GetImpl().TestCalculateChildSizeBase(child, dimension);
195 }
196
197 bool TestCustomActor::TestRelayoutDependentOnChildrenBase(Dimension::Type dimension)
198 {
199   return GetImpl().TestRelayoutDependentOnChildrenBase(dimension);
200 }
201
202 uint32_t TestCustomActor::GetDepth()
203 {
204   return GetImpl().mDepth;
205 }
206
207 TestCustomActor::TestCustomActor()
208 {
209 }
210
211 TestCustomActor::TestCustomActor(Impl::TestCustomActor& impl)
212 : CustomActor(impl)
213 {
214 }
215
216 TestCustomActor::TestCustomActor(Dali::Internal::CustomActor* internal)
217 : CustomActor(internal)
218 {
219 }
220
221 TestCustomActor TestCustomActor::DownCast(BaseHandle handle)
222 {
223   TestCustomActor actor;
224   CustomActor     custom = Dali::CustomActor::DownCast(handle);
225   if(custom)
226   {
227     CustomActorImpl& customImpl = custom.GetImplementation();
228
229     Test::Impl::TestCustomActor* impl = dynamic_cast<Test::Impl::TestCustomActor*>(&customImpl);
230     if(impl)
231     {
232       actor = TestCustomActor(customImpl.GetOwner());
233     }
234   }
235   return actor;
236 }
237
238 namespace Impl
239 {
240 TestCustomActor::TestCustomActor()
241 : CustomActorImpl(ActorFlags(DISABLE_SIZE_NEGOTIATION)),
242   mDaliProperty(Property::INVALID_INDEX),
243   mSizeSet(Vector3::ZERO),
244   mTargetSize(Vector3::ZERO),
245   mNego(false),
246   mDepth(0u),
247   develProp6(10.0f)
248 {
249 }
250
251 TestCustomActor::TestCustomActor(bool nego)
252 : CustomActorImpl(ActorFlags()),
253   mDaliProperty(Property::INVALID_INDEX),
254   mSizeSet(Vector3::ZERO),
255   mTargetSize(Vector3::ZERO),
256   mNego(nego),
257   develProp6(10.0f)
258 {
259 }
260 /**
261  * Destructor
262  */
263 TestCustomActor::~TestCustomActor()
264 {
265 }
266
267 void TestCustomActor::Initialize(const char* name)
268 {
269   mDaliProperty = Self().RegisterProperty("Dali", std::string("no"), Property::READ_WRITE);
270
271   OnInitialize(name);
272 }
273
274 void TestCustomActor::OnInitialize(const char* name)
275 {
276 }
277
278 /**
279  * Resets the call stack
280  */
281 void TestCustomActor::ResetCallStack()
282 {
283   mSizeSet    = Vector3();
284   mTargetSize = Vector3();
285   mMethodsCalled.clear();
286 }
287
288 void TestCustomActor::AddToCallStacks(const char* method)
289 {
290   mMethodsCalled.push_back(method);
291
292   // Combine Actor name with method string
293   std::string nameAndMethod(Self().GetProperty<std::string>(Dali::Actor::Property::NAME));
294   if(0 == nameAndMethod.size())
295   {
296     nameAndMethod = "Unknown: ";
297   }
298   else
299   {
300     nameAndMethod += ": ";
301   }
302   nameAndMethod += method;
303
304   MasterCallStack.push_back(nameAndMethod);
305 }
306
307 // From CustomActorImpl
308 void TestCustomActor::OnSceneConnection(int depth)
309 {
310   AddToCallStacks("OnSceneConnection");
311   mDepth = depth;
312 }
313 void TestCustomActor::OnSceneDisconnection()
314 {
315   AddToCallStacks("OnSceneDisconnection");
316 }
317 void TestCustomActor::OnChildAdd(Actor& child)
318 {
319   AddToCallStacks("OnChildAdd");
320 }
321 void TestCustomActor::OnChildRemove(Actor& child)
322 {
323   AddToCallStacks("OnChildRemove");
324 }
325 void TestCustomActor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
326 {
327   AddToCallStacks("OnPropertySet");
328 }
329 void TestCustomActor::OnSizeSet(const Vector3& targetSize)
330 {
331   mSizeSet = targetSize;
332   AddToCallStacks("OnSizeSet");
333 }
334 void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
335 {
336   mTargetSize = targetSize;
337   AddToCallStacks("OnSizeAnimation");
338 }
339 void TestCustomActor::OnKeyInputFocusGained()
340 {
341   AddToCallStacks("OnKeyInputFocusGained");
342 }
343 void TestCustomActor::OnKeyInputFocusLost()
344 {
345   AddToCallStacks("OnKeyInputFocusLost");
346 }
347 Vector3 TestCustomActor::GetNaturalSize()
348 {
349   return Vector3(0.0f, 0.0f, 0.0f);
350 }
351
352 float TestCustomActor::GetHeightForWidth(float width)
353 {
354   return 0.0f;
355 }
356
357 float TestCustomActor::GetWidthForHeight(float height)
358 {
359   return 0.0f;
360 }
361
362 void TestCustomActor::OnRelayout(const Vector2& size, RelayoutContainer& container)
363 {
364   gOnRelayout = true;
365 }
366
367 void TestCustomActor::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
368 {
369 }
370
371 void TestCustomActor::OnCalculateRelayoutSize(Dimension::Type dimension)
372 {
373 }
374
375 float TestCustomActor::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
376 {
377   return 0.0f;
378 }
379
380 void TestCustomActor::OnLayoutNegotiated(float size, Dimension::Type dimension)
381 {
382 }
383
384 bool TestCustomActor::RelayoutDependentOnChildren(Dimension::Type dimension)
385 {
386   return false;
387 }
388
389 void TestCustomActor::SetDaliProperty(std::string s)
390 {
391   Self().SetProperty(mDaliProperty, s);
392 }
393 void TestCustomActor::TestRelayoutRequest()
394 {
395   RelayoutRequest();
396 }
397
398 float TestCustomActor::TestGetHeightForWidthBase(float width)
399 {
400   return GetHeightForWidthBase(width);
401 }
402
403 float TestCustomActor::TestGetWidthForHeightBase(float height)
404 {
405   return GetWidthForHeightBase(height);
406 }
407
408 float TestCustomActor::TestCalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension)
409 {
410   return CalculateChildSizeBase(child, dimension);
411 }
412
413 bool TestCustomActor::TestRelayoutDependentOnChildrenBase(Dimension::Type dimension)
414 {
415   return RelayoutDependentOnChildrenBase(dimension);
416 }
417
418 void TestCustomActor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
419 {
420   Test::TestCustomActor actor = Test::TestCustomActor::DownCast(Dali::BaseHandle(object));
421
422   if(actor)
423   {
424     TestCustomActor& actorImpl = GetImpl(actor);
425     switch(index)
426     {
427       case Test::TestCustomActor::Property::TEST_PROPERTY1:
428       {
429         actorImpl.prop1 = value.Get<float>();
430         break;
431       }
432       case Test::TestCustomActor::Property::TEST_PROPERTY2:
433       {
434         actorImpl.prop2 = value.Get<Vector4>();
435         break;
436       }
437       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
438       {
439         actorImpl.develProp3 = value.Get<Vector4>();
440         break;
441       }
442       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
443       {
444         actorImpl.develProp4 = value.Get<int>();
445         break;
446       }
447       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
448       {
449         actorImpl.develProp5 = value.Get<float>();
450         break;
451       }
452     }
453   }
454 }
455
456 Property::Value TestCustomActor::GetProperty(BaseObject* object, Property::Index index)
457 {
458   Test::TestCustomActor actor = Test::TestCustomActor::DownCast(Dali::BaseHandle(object));
459
460   if(actor)
461   {
462     TestCustomActor& actorImpl = GetImpl(actor);
463     switch(index)
464     {
465       case Test::TestCustomActor::Property::TEST_PROPERTY1:
466       {
467         return Property::Value(actorImpl.prop1);
468       }
469       case Test::TestCustomActor::Property::TEST_PROPERTY2:
470       {
471         return Property::Value(actorImpl.prop2);
472       }
473       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
474       {
475         return Property::Value(actorImpl.develProp3);
476       }
477       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
478       {
479         return Property::Value(actorImpl.develProp4);
480       }
481       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
482       {
483         return Property::Value(actorImpl.develProp5);
484       }
485       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6:
486       {
487         return Property::Value(actorImpl.develProp6);
488       }
489     }
490   }
491   return Property::Value();
492 }
493
494 BaseHandle CreateActor()
495 {
496   return Test::TestCustomActor::New();
497 }
498
499 DALI_TYPE_REGISTRATION_BEGIN(Test::TestCustomActor, Dali::CustomActor, CreateActor);
500
501 DALI_PROPERTY_REGISTRATION(Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1)
502 DALI_PROPERTY_REGISTRATION(Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2)
503 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3)
504 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4)
505 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5)
506 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Test, TestCustomActor, "develTestProperty6", FLOAT, DEVEL_TEST_PROPERTY6)
507
508 DALI_TYPE_REGISTRATION_END()
509
510 } // namespace Impl
511 } // namespace Test