Merge "Removed On(...)Event()" 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
16 TestCustomActor TestCustomActor::New()
17 {
18   Impl::TestCustomActor* impl = new Impl::TestCustomActor;
19   TestCustomActor custom( *impl ); // takes ownership
20
21   impl->Initialize();
22
23   return custom;
24 }
25
26 TestCustomActor TestCustomActor::NewNegoSize()
27 {
28   Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
29   TestCustomActor custom( *impl ); // takes ownership
30   custom.SetProperty( Dali::Actor::Property::NAME, "SizeNegotiationActor" );
31
32   impl->Initialize();
33
34   return custom;
35 }
36
37 TestCustomActor TestCustomActor::NewVariant1( Actor childToAdd )
38 {
39   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
40   TestCustomActor custom( *impl ); // takes ownership
41
42   impl->Initialize();
43
44   return custom;
45 }
46
47 TestCustomActor TestCustomActor::NewVariant2()
48 {
49   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
50   TestCustomActor custom( *impl ); // takes ownership
51
52   impl->Initialize();
53
54   return custom;
55 }
56
57 TestCustomActor TestCustomActor::NewVariant3( Actor childToAdd )
58 {
59   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
60   TestCustomActor custom( *impl ); // takes ownership
61
62   impl->Initialize();
63
64   return custom;
65 }
66
67 TestCustomActor TestCustomActor::NewVariant4()
68 {
69   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
70   TestCustomActor custom( *impl ); // takes ownership
71
72   impl->Initialize();
73
74   return custom;
75 }
76
77 TestCustomActor TestCustomActor::NewVariant5(Integration::Scene scene)
78 {
79   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(scene);
80   TestCustomActor custom( *impl ); // takes ownership
81
82   impl->Initialize();
83
84   return custom;
85 }
86
87 TestCustomActor TestCustomActor::NewVariant6(Integration::Scene scene)
88 {
89   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(scene);
90   TestCustomActor custom( *impl ); // takes ownership
91
92   impl->Initialize();
93
94   return custom;
95 }
96
97 TestCustomActor TestCustomActor::NewVariant7( const char* name )
98 {
99   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
100   TestCustomActor custom( *impl ); // takes ownership
101
102   impl->Initialize( name );
103
104   return custom;
105 }
106
107 TestCustomActor TestCustomActor::NewVariant8( Actor rival )
108 {
109   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
110   TestCustomActor custom( *impl ); // takes ownership
111
112   impl->Initialize();
113
114   return custom;
115 }
116
117 TestCustomActor::~TestCustomActor()
118 {
119 }
120
121 Impl::TestCustomActor& TestCustomActor::GetImpl()
122 {
123   return static_cast<Impl::TestCustomActor&>(GetImplementation());
124 }
125
126 std::vector< std::string >& TestCustomActor::GetMethodsCalled()
127 {
128   return GetImpl().mMethodsCalled;
129 }
130
131 void TestCustomActor::ResetCallStack()
132 {
133   GetImpl().ResetCallStack();
134 }
135
136 void TestCustomActor::SetDaliProperty(std::string s)
137 {
138   GetImpl().SetDaliProperty(s);
139 }
140
141 Vector3 TestCustomActor::GetSize()
142 {
143   return GetImpl().mSizeSet;
144 }
145
146 Vector3 TestCustomActor::GetTargetSize()
147 {
148   return GetImpl().mTargetSize;
149 }
150
151 Vector3 TestCustomActor::GetNaturalSize()
152 {
153   return Vector3( 0.0f, 0.0f, 0.0f );
154 }
155
156 float TestCustomActor::GetHeightForWidth( float width )
157 {
158   return 0.0f;
159 }
160
161 float TestCustomActor::GetWidthForHeight( float height )
162 {
163   return 0.0f;
164 }
165
166 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
167 {
168 }
169
170 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
171 {
172 }
173
174 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
175 {
176 }
177
178 void TestCustomActor::TestRelayoutRequest()
179 {
180   GetImpl().TestRelayoutRequest();
181 }
182
183 float TestCustomActor::TestGetHeightForWidthBase( float width )
184 {
185   return GetImpl().TestGetHeightForWidthBase( width );
186 }
187
188 float TestCustomActor::TestGetWidthForHeightBase( float height )
189 {
190   return GetImpl().TestGetWidthForHeightBase( height );
191 }
192
193 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
194 {
195   return GetImpl().TestCalculateChildSizeBase( child, dimension );
196 }
197
198 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
199 {
200   return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
201 }
202
203 uint32_t TestCustomActor::GetDepth()
204 {
205   return GetImpl().mDepth;
206 }
207
208 TestCustomActor::TestCustomActor()
209 {
210 }
211
212 TestCustomActor::TestCustomActor( Impl::TestCustomActor& impl )
213 : CustomActor( impl )
214 {
215 }
216
217 TestCustomActor::TestCustomActor( Dali::Internal::CustomActor* internal )
218 : CustomActor( internal )
219 {
220 }
221
222 TestCustomActor TestCustomActor::DownCast( BaseHandle handle )
223 {
224   TestCustomActor actor;
225   CustomActor custom = Dali::CustomActor::DownCast(handle);
226   if(custom)
227   {
228     CustomActorImpl& customImpl = custom.GetImplementation();
229
230     Test::Impl::TestCustomActor* impl = dynamic_cast<Test::Impl::TestCustomActor*>(&customImpl);
231     if( impl )
232     {
233       actor = TestCustomActor(customImpl.GetOwner());
234     }
235   }
236   return actor;
237 }
238
239 namespace Impl
240 {
241
242 TestCustomActor::TestCustomActor()
243 : CustomActorImpl( ActorFlags( DISABLE_SIZE_NEGOTIATION ) ),
244   mDaliProperty( Property::INVALID_INDEX ),
245   mSizeSet( Vector3::ZERO ),
246   mTargetSize( Vector3::ZERO ),
247   mNego( false ),
248   mDepth(0u),
249   develProp6( 10.0f )
250 {
251 }
252
253 TestCustomActor::TestCustomActor(bool nego)
254 : CustomActorImpl( ActorFlags() ),
255   mDaliProperty( Property::INVALID_INDEX ),
256   mSizeSet( Vector3::ZERO ),
257   mTargetSize( Vector3::ZERO ),
258   mNego( nego ),
259   develProp6( 10.0f )
260 {
261 }
262 /**
263  * Destructor
264  */
265 TestCustomActor::~TestCustomActor()
266 {
267 }
268
269 void TestCustomActor::Initialize( const char* name )
270 {
271   mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
272
273   OnInitialize( name );
274 }
275
276 void TestCustomActor::OnInitialize( const char* name ) {}
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
495 BaseHandle CreateActor()
496 {
497   return Test::TestCustomActor::New();
498 }
499
500 DALI_TYPE_REGISTRATION_BEGIN( Test::TestCustomActor, Dali::CustomActor, CreateActor );
501
502 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1)
503 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2)
504 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3)
505 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4)
506 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5)
507 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Test, TestCustomActor, "develTestProperty6", FLOAT, DEVEL_TEST_PROPERTY6)
508
509 DALI_TYPE_REGISTRATION_END()
510
511 } // Impl
512 } // Test namespace