Remove some public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameCallbackInterface.cpp
1 /*
2  * Copyright (c) 2018 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
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/devel-api/common/stage-devel.h>
24 #include <dali/devel-api/update/frame-callback-interface.h>
25 #include <dali/devel-api/update/update-proxy.h>
26 #include <dali-test-suite-utils.h>
27
28 using namespace Dali;
29
30 void utc_dali_frame_callback_interface_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_frame_callback_interface_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 namespace
42 {
43
44 class FrameCallbackBasic : public FrameCallbackInterface
45 {
46 public:
47
48   FrameCallbackBasic() = default;
49
50   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds )
51   {
52     mCalled = true;
53   }
54
55   virtual void Reset()
56   {
57     mCalled = false;
58   }
59
60   bool mCalled{ false };
61 };
62
63 class FrameCallbackOneActor : public FrameCallbackBasic
64 {
65 public:
66
67   FrameCallbackOneActor( unsigned int actorId )
68   : mActorId( actorId )
69   {
70   }
71
72   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ) override
73   {
74     FrameCallbackBasic::Update( updateProxy, elapsedSeconds );
75     updateProxy.GetSize( mActorId, mSizeGetSizeCall );
76     updateProxy.GetPosition( mActorId, mPositionGetPositionCall );
77     updateProxy.GetPositionAndSize( mActorId, mPositionGetPositionAndSizeCall, mSizeGetPositionAndSizeCall );
78     updateProxy.GetColor( mActorId, mColor );
79     updateProxy.GetScale( mActorId, mScale );
80   }
81
82   const unsigned int mActorId;
83
84   Vector3 mSizeGetSizeCall;
85   Vector3 mPositionGetPositionCall;
86   Vector3 mPositionGetPositionAndSizeCall;
87   Vector3 mSizeGetPositionAndSizeCall;
88   Vector4 mColor;
89   Vector3 mScale;
90 };
91
92 class FrameCallbackSetter : public FrameCallbackBasic
93 {
94 public:
95
96   FrameCallbackSetter(
97       unsigned int actorId,
98       const Vector3& sizeToSet,
99       const Vector3& positionToSet,
100       const Vector4& colorToSet,
101       const Vector3& scaleToSet )
102   : mActorId( actorId ),
103     mSizeToSet( sizeToSet ),
104     mPositionToSet( positionToSet ),
105     mColorToSet( colorToSet ),
106     mScaleToSet( scaleToSet )
107   {
108   }
109
110   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ) override
111   {
112     FrameCallbackBasic::Update( updateProxy, elapsedSeconds );
113     updateProxy.SetSize( mActorId, mSizeToSet );
114     updateProxy.SetPosition( mActorId, mPositionToSet );
115     updateProxy.SetColor( mActorId, mColorToSet );
116     updateProxy.SetScale( mActorId, mScaleToSet );
117     updateProxy.GetSize( mActorId, mSizeAfterSetting );
118     updateProxy.GetPosition( mActorId, mPositionAfterSetting );
119     updateProxy.GetColor( mActorId, mColorAfterSetting );
120     updateProxy.GetScale( mActorId, mScaleAfterSetting );
121   }
122
123   const unsigned int mActorId;
124   const Vector3& mSizeToSet;
125   const Vector3& mPositionToSet;
126   const Vector4& mColorToSet;
127   const Vector3& mScaleToSet;
128
129   Vector3 mSizeAfterSetting;
130   Vector3 mPositionAfterSetting;
131   Vector4 mColorAfterSetting;
132   Vector3 mScaleAfterSetting;
133 };
134
135 class FrameCallbackBaker : public FrameCallbackBasic
136 {
137 public:
138
139   FrameCallbackBaker(
140       unsigned int actorId,
141       const Vector3& sizeToSet,
142       const Vector3& positionToSet,
143       const Vector4& colorToSet,
144       const Vector3& scaleToSet )
145   : mActorId( actorId ),
146     mSizeToSet( sizeToSet ),
147     mPositionToSet( positionToSet ),
148     mColorToSet( colorToSet ),
149     mScaleToSet( scaleToSet )
150   {
151   }
152
153   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ) override
154   {
155     FrameCallbackBasic::Update( updateProxy, elapsedSeconds );
156     updateProxy.BakeSize( mActorId, mSizeToSet );
157     updateProxy.BakePosition( mActorId, mPositionToSet );
158     updateProxy.BakeColor( mActorId, mColorToSet );
159     updateProxy.BakeScale( mActorId, mScaleToSet );
160     updateProxy.GetSize( mActorId, mSizeAfterSetting );
161     updateProxy.GetPosition( mActorId, mPositionAfterSetting );
162     updateProxy.GetColor( mActorId, mColorAfterSetting );
163     updateProxy.GetScale( mActorId, mScaleAfterSetting );
164   }
165
166   const unsigned int mActorId;
167   const Vector3& mSizeToSet;
168   const Vector3& mPositionToSet;
169   const Vector4& mColorToSet;
170   const Vector3& mScaleToSet;
171
172   Vector3 mSizeAfterSetting;
173   Vector3 mPositionAfterSetting;
174   Vector4 mColorAfterSetting;
175   Vector3 mScaleAfterSetting;
176 };
177
178 class FrameCallbackMultipleActors : public FrameCallbackBasic
179 {
180 public:
181
182   FrameCallbackMultipleActors()
183   {
184   }
185
186   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ) override
187   {
188     FrameCallbackBasic::Update( updateProxy, elapsedSeconds );
189     for( auto&& i : mActorIds )
190     {
191       Vector3 position;
192       Vector3 size;
193       updateProxy.GetPositionAndSize( i, position, size );
194       mPositions[ i ] = position;
195       mSizes[ i ] = size;
196     }
197   }
198
199   Vector< unsigned int > mActorIds;
200
201   std::map< unsigned int, Vector3 > mPositions;
202   std::map< unsigned int, Vector3 > mSizes;
203 };
204
205 class FrameCallbackActorIdCheck : public FrameCallbackBasic
206 {
207 public:
208
209   FrameCallbackActorIdCheck( unsigned int actorId )
210   : mActorId( actorId )
211   {
212   }
213
214   virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ) override
215   {
216     FrameCallbackBasic::Update( updateProxy, elapsedSeconds );
217     Vector3 vec3;
218     Vector4 vec4;
219
220     mGetSizeCallSuccess            = updateProxy.GetSize( mActorId, vec3 );
221     mGetPositionCallSuccess        = updateProxy.GetPosition( mActorId, vec3 );
222     mGetColorCallSuccess           = updateProxy.GetColor( mActorId, vec4 );
223     mGetScaleCallSuccess           = updateProxy.GetScale( mActorId, vec3 );
224     mGetPositionAndSizeCallSuccess = updateProxy.GetPositionAndSize( mActorId, vec3, vec3 );
225     mSetSizeCallSuccess            = updateProxy.SetSize( mActorId, vec3 );
226     mSetPositionCallSuccess        = updateProxy.SetPosition( mActorId, vec3 );
227     mSetColorCallSuccess           = updateProxy.SetColor( mActorId, vec4 );
228     mSetScaleCallSuccess           = updateProxy.SetScale( mActorId, vec3 );
229     mBakeSizeCallSuccess           = updateProxy.BakeSize( mActorId, vec3 );
230     mBakePositionCallSuccess       = updateProxy.BakePosition( mActorId, vec3 );
231     mBakeColorCallSuccess          = updateProxy.BakeColor( mActorId, vec4 );
232     mBakeScaleCallSuccess          = updateProxy.BakeScale( mActorId, vec3 );
233   }
234
235   virtual void Reset() override
236   {
237     // Up-call
238     FrameCallbackBasic::Reset();
239
240     mGetSizeCallSuccess = false;
241     mGetPositionCallSuccess = false;
242     mGetColorCallSuccess = false;
243     mGetScaleCallSuccess = false;
244     mGetPositionAndSizeCallSuccess = false;
245     mSetSizeCallSuccess = false;
246     mSetPositionCallSuccess = false;
247     mSetColorCallSuccess = false;
248     mSetScaleCallSuccess = false;
249     mBakeSizeCallSuccess = false;
250     mBakePositionCallSuccess = false;
251     mBakeColorCallSuccess = false;
252     mBakeScaleCallSuccess = false;
253   }
254
255   const uint32_t mActorId;
256   bool mGetSizeCallSuccess{ false };
257   bool mGetPositionCallSuccess{ false };
258   bool mGetColorCallSuccess{ false };
259   bool mGetScaleCallSuccess{ false };
260   bool mGetPositionAndSizeCallSuccess{ false };
261   bool mSetSizeCallSuccess{ false };
262   bool mSetPositionCallSuccess{ false };
263   bool mSetColorCallSuccess{ false };
264   bool mSetScaleCallSuccess{ false };
265   bool mBakeSizeCallSuccess{ false };
266   bool mBakePositionCallSuccess{ false };
267   bool mBakeColorCallSuccess{ false };
268   bool mBakeScaleCallSuccess{ false };
269 };
270
271 } // anon namespace
272
273 ///////////////////////////////////////////////////////////////////////////////
274
275 int UtcDaliFrameCallbackCheckInstallationAndRemoval(void)
276 {
277   // Basic test to check that the frame-callback can be installed and removed correctly
278
279   TestApplication application;
280
281   FrameCallbackBasic frameCallback;
282
283   Stage stage = Stage::GetCurrent();
284   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
285
286   application.SendNotification();
287   application.Render();
288
289   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
290
291   frameCallback.mCalled = false;
292
293   DevelStage::RemoveFrameCallback( stage, frameCallback );
294
295   application.SendNotification();
296   application.Render();
297
298   DALI_TEST_EQUALS( frameCallback.mCalled, false, TEST_LOCATION );
299
300   END_TEST;
301 }
302
303 int UtcDaliFrameCallbackGetters(void)
304 {
305   // Test to see that the Getters all return the expected values
306
307   TestApplication application;
308   Vector2 actorSize( 200, 300 );
309   Vector4 color( 0.5f, 0.6f, 0.7f, 0.8f );
310   Vector3 position( 10.0f, 20.0f, 30.0f );
311   Vector3 scale( 2.0f, 4.0f, 6.0f );
312
313   Actor actor = Actor::New();
314   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
315   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
316   actor.SetSize( actorSize );
317   actor.SetProperty( Actor::Property::COLOR, color );
318   actor.SetPosition( position );
319   actor.SetScale( scale );
320
321   Stage stage = Stage::GetCurrent();
322   stage.Add( actor );
323
324   FrameCallbackOneActor frameCallback( actor.GetId() );
325   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
326
327   application.SendNotification();
328   application.Render();
329
330   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
331   DALI_TEST_EQUALS( frameCallback.mSizeGetSizeCall, Vector3( actorSize.width, actorSize.height, 0.0f ), TEST_LOCATION );
332   DALI_TEST_EQUALS( frameCallback.mPositionGetPositionCall, position, TEST_LOCATION );
333   DALI_TEST_EQUALS( frameCallback.mPositionGetPositionAndSizeCall, position, TEST_LOCATION );
334   DALI_TEST_EQUALS( frameCallback.mSizeGetPositionAndSizeCall, Vector3( actorSize.width, actorSize.height, 0.0f ), TEST_LOCATION );
335   DALI_TEST_EQUALS( frameCallback.mColor, color, TEST_LOCATION );
336   DALI_TEST_EQUALS( frameCallback.mScale, scale, TEST_LOCATION );
337
338   END_TEST;
339 }
340
341 int UtcDaliFrameCallbackSetters(void)
342 {
343   // Test to see that the setters set the values appropriately
344
345   TestApplication application;
346   Vector2 actorSize( 200, 300 );
347
348   Actor actor = Actor::New();
349   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
350   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
351   actor.SetSize( actorSize );
352
353   Stage stage = Stage::GetCurrent();
354   stage.Add( actor );
355
356   Vector3 sizeToSet( 1.0f, 2.0f, 3.0f );
357   Vector3 positionToSet( 10.0f, 20.0f, 30.0f );
358   Vector4 colorToSet( Color::MAGENTA );
359   Vector3 scaleToSet( 1.0f, 3.0f, 5.0f );
360
361   FrameCallbackSetter frameCallback( actor.GetId(), sizeToSet, positionToSet, colorToSet, scaleToSet );
362   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
363
364   application.SendNotification();
365   application.Render();
366
367   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
368   DALI_TEST_EQUALS( frameCallback.mSizeAfterSetting, sizeToSet, TEST_LOCATION );
369   DALI_TEST_EQUALS( frameCallback.mPositionAfterSetting, positionToSet, TEST_LOCATION );
370   DALI_TEST_EQUALS( frameCallback.mColorAfterSetting, colorToSet, TEST_LOCATION );
371   DALI_TEST_EQUALS( frameCallback.mScaleAfterSetting, scaleToSet, TEST_LOCATION );
372
373   // Ensure the actual actor values haven't changed as we didn't bake the values after removing the callback
374   DevelStage::RemoveFrameCallback( stage, frameCallback );
375
376   application.SendNotification();
377   application.Render();
378
379   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), Vector3::ZERO, TEST_LOCATION );
380   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SIZE ).Get< Vector3 >(), Vector3( actorSize ), TEST_LOCATION );
381   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::COLOR ).Get< Vector4 >(), Color::WHITE, TEST_LOCATION );
382   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SCALE ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
383
384   // Render for a couple more frames to ensure the values are reset properly (some values are double-buffered)
385
386   application.SendNotification();
387   application.Render();
388
389   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), Vector3::ZERO, TEST_LOCATION );
390   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SIZE ).Get< Vector3 >(), Vector3( actorSize ), TEST_LOCATION );
391   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::COLOR ).Get< Vector4 >(), Color::WHITE, TEST_LOCATION );
392   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SCALE ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
393
394   application.SendNotification();
395   application.Render();
396
397   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), Vector3::ZERO, TEST_LOCATION );
398   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SIZE ).Get< Vector3 >(), Vector3( actorSize ), TEST_LOCATION );
399   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::COLOR ).Get< Vector4 >(), Color::WHITE, TEST_LOCATION );
400   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SCALE ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
401
402   END_TEST;
403 }
404
405 int UtcDaliFrameCallbackBake(void)
406 {
407   // Test to see that the bake methods bake the values
408
409   TestApplication application;
410   Vector2 actorSize( 200, 300 );
411
412   Actor actor = Actor::New();
413   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
414   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
415   actor.SetSize( actorSize );
416
417   Stage stage = Stage::GetCurrent();
418   stage.Add( actor );
419
420   Vector3 sizeToSet( 1.0f, 2.0f, 3.0f );
421   Vector3 positionToSet( 10.0f, 20.0f, 30.0f );
422   Vector4 colorToSet( Color::MAGENTA );
423   Vector3 scaleToSet( 1.0f, 3.0f, 5.0f );
424
425   FrameCallbackBaker frameCallback( actor.GetId(), sizeToSet, positionToSet, colorToSet, scaleToSet );
426   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
427
428   application.SendNotification();
429   application.Render();
430
431   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
432   DALI_TEST_EQUALS( frameCallback.mSizeAfterSetting, sizeToSet, TEST_LOCATION );
433   DALI_TEST_EQUALS( frameCallback.mPositionAfterSetting, positionToSet, TEST_LOCATION );
434   DALI_TEST_EQUALS( frameCallback.mColorAfterSetting, colorToSet, TEST_LOCATION );
435   DALI_TEST_EQUALS( frameCallback.mScaleAfterSetting, scaleToSet, TEST_LOCATION );
436
437   // Ensure the new values are saved after removing the callback
438   DevelStage::RemoveFrameCallback( stage, frameCallback );
439
440   application.SendNotification();
441   application.Render();
442
443   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::POSITION ).Get< Vector3 >(), positionToSet, TEST_LOCATION );
444   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SIZE ).Get< Vector3 >(), sizeToSet, TEST_LOCATION );
445   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::COLOR ).Get< Vector4 >(), colorToSet, TEST_LOCATION );
446   DALI_TEST_EQUALS( actor.GetCurrentProperty( Actor::Property::SCALE ).Get< Vector3 >(), scaleToSet, TEST_LOCATION );
447
448   END_TEST;
449 }
450
451
452 int UtcDaliFrameCallbackMultipleActors(void)
453 {
454   /**
455    * Test to check that the frame callback behaves appropriately with multiple actors
456    *
457    * Tree:
458    *              root-layer
459    *              /        \
460    *             /          \
461    *            /            \
462    *           /              \
463    *        actorA           actorE
464    *         / \              / \
465    *        /   \            /   \
466    *    actorB  actorD   actorF actorG
467    *      /                        \
468    *   actorC                     actorH
469    *
470    *  Screen positions (with minor alterations due to local position):
471    *  -----------------------
472    *  |actorA|actorD        |
473    *  |      actorB         |
474    *  |      actorC         |
475    *  |                     |
476    *  |                     |
477    *  |                     |
478    *  |                     |
479    *  |                     |
480    *  |actorF       actorH  |
481    *  |actorE|actorG        |
482    *  -----------------------
483    */
484
485   TestApplication application;
486   Stage stage = Stage::GetCurrent();
487
488   std::map< char, Vector3 > sizes;
489   sizes['A'] = Vector3(  50.0f,  50.0f, 0.0f );
490   sizes['B'] = Vector3( 100.0f, 100.0f, 0.0f );
491   sizes['C'] = Vector3( 150.0f, 150.0f, 0.0f );
492   sizes['D'] = Vector3( 200.0f, 200.0f, 0.0f );
493   sizes['E'] = Vector3( 250.0f, 250.0f, 0.0f );
494   sizes['F'] = Vector3( 300.0f, 300.0f, 0.0f );
495   sizes['G'] = Vector3( 350.0f, 350.0f, 0.0f );
496   sizes['H'] = Vector3( 400.0f, 350.0f, 0.0f );
497
498   std::map< char, Vector3 > positions;
499   positions['A'] = Vector3(  0.0f,  1.0f,  2.0f );
500   positions['B'] = Vector3(  2.0f,  3.0f,  4.0f );
501   positions['C'] = Vector3(  5.0f,  6.0f,  7.0f );
502   positions['D'] = Vector3(  8.0f,  9.0f, 10.0f );
503   positions['E'] = Vector3( 11.0f, 12.0f, 13.0f );
504   positions['F'] = Vector3( 14.0f, 15.0f, 16.0f );
505   positions['G'] = Vector3( 17.0f, 18.0f, 19.0f );
506   positions['H'] = Vector3( 20.0f, 21.0f, 22.0f );
507
508   Actor actorA = Actor::New();
509   actorA.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
510   actorA.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
511   actorA.SetSize( sizes['A'] );
512   actorA.SetPosition( positions['A'] );
513   stage.Add( actorA );
514
515   Actor actorB = Actor::New();
516   actorB.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT );
517   actorB.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
518   actorB.SetSize( sizes['B'] );
519   actorB.SetPosition( positions['B'] );
520   actorA.Add( actorB );
521
522   Actor actorC = Actor::New();
523   actorC.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
524   actorC.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
525   actorC.SetSize( sizes['C'] );
526   actorC.SetPosition( positions['C'] );
527   actorB.Add( actorC );
528
529   Actor actorD = Actor::New();
530   actorD.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT );
531   actorD.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
532   actorD.SetSize( sizes['D'] );
533   actorD.SetPosition( positions['D'] );
534   actorA.Add( actorD );
535
536   Actor actorE = Actor::New();
537   actorE.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
538   actorE.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
539   actorE.SetSize( sizes['E'] );
540   actorE.SetPosition( positions['E'] );
541   stage.Add( actorE );
542
543   Actor actorF = Actor::New();
544   actorF.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
545   actorF.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
546   actorF.SetSize( sizes['F'] );
547   actorF.SetPosition( positions['F'] );
548   actorE.Add( actorF );
549
550   Actor actorG = Actor::New();
551   actorG.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT );
552   actorG.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
553   actorG.SetSize( sizes['G'] );
554   actorG.SetPosition( positions['G'] );
555   actorE.Add( actorG );
556
557   Actor actorH = Actor::New();
558   actorH.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
559   actorH.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
560   actorH.SetSize( sizes['H'] );
561   actorH.SetPosition( positions['H'] );
562   actorG.Add( actorH );
563
564   std::map< char, unsigned int > actorIds;
565   actorIds['A'] = actorA.GetId();
566   actorIds['B'] = actorB.GetId();
567   actorIds['C'] = actorC.GetId();
568   actorIds['D'] = actorD.GetId();
569   actorIds['E'] = actorE.GetId();
570   actorIds['F'] = actorF.GetId();
571   actorIds['G'] = actorG.GetId();
572   actorIds['H'] = actorH.GetId();
573
574   FrameCallbackMultipleActors frameCallback;
575   for( auto&& i : actorIds )
576   {
577     frameCallback.mActorIds.PushBack( i.second );
578   }
579
580   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
581
582   application.SendNotification();
583   application.Render();
584
585   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
586
587   for( char i = 'A'; i <= 'H'; ++i )
588   {
589     DALI_TEST_EQUALS( frameCallback.mPositions[ actorIds[ i ] ], positions[ i ], TEST_LOCATION );
590     DALI_TEST_EQUALS( frameCallback.mSizes[ actorIds[ i ] ], sizes[ i ], TEST_LOCATION );
591   }
592
593   // Render again to make sure it still gets called and gives the correct values (in case any optimisations break this)
594   frameCallback.mCalled = false;
595
596   application.SendNotification();
597   application.Render();
598
599   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
600
601   for( char i = 'A'; i <= 'H'; ++i )
602   {
603     DALI_TEST_EQUALS( frameCallback.mPositions[ actorIds[ i ] ], positions[ i ], TEST_LOCATION );
604     DALI_TEST_EQUALS( frameCallback.mSizes[ actorIds[ i ] ], sizes[ i ], TEST_LOCATION );
605   }
606
607   END_TEST;
608 }
609
610 int UtcDaliFrameCallbackCheckActorNotAdded(void)
611 {
612   TestApplication application;
613
614   Actor actor = Actor::New();
615   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
616   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
617   actor.SetSize( 200, 300 );
618
619   Stage stage = Stage::GetCurrent();
620   FrameCallbackOneActor frameCallback( actor.GetId() );
621   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
622
623   application.SendNotification();
624   application.Render();
625
626   // All should be default constructed objects
627   DALI_TEST_EQUALS( frameCallback.mCalled, true, TEST_LOCATION );
628   DALI_TEST_EQUALS( frameCallback.mPositionGetPositionCall, Vector3::ZERO, TEST_LOCATION );
629   DALI_TEST_EQUALS( frameCallback.mSizeGetSizeCall, Vector3::ZERO, TEST_LOCATION );
630   DALI_TEST_EQUALS( frameCallback.mColor, Vector4::ZERO, TEST_LOCATION );
631   DALI_TEST_EQUALS( frameCallback.mScale, Vector3::ZERO, TEST_LOCATION );
632
633   END_TEST;
634 }
635
636 int UtcDaliFrameCallbackInvalidActorId(void)
637 {
638   // Test to ensure that there are no issues when trying to use the update-proxy methods with an invalid actor ID.
639
640   TestApplication application;
641   Stage stage = Stage::GetCurrent();
642
643   FrameCallbackActorIdCheck frameCallback( 10000 );
644   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
645
646   application.SendNotification();
647   application.Render();
648
649   // Invalid Actor ID so all the methods should not return successfully.
650
651   DALI_TEST_EQUALS( frameCallback.mCalled,                        true,  TEST_LOCATION );
652   DALI_TEST_EQUALS( frameCallback.mGetSizeCallSuccess,            false, TEST_LOCATION );
653   DALI_TEST_EQUALS( frameCallback.mGetPositionCallSuccess,        false, TEST_LOCATION );
654   DALI_TEST_EQUALS( frameCallback.mGetColorCallSuccess,           false, TEST_LOCATION );
655   DALI_TEST_EQUALS( frameCallback.mGetScaleCallSuccess,           false, TEST_LOCATION );
656   DALI_TEST_EQUALS( frameCallback.mGetPositionAndSizeCallSuccess, false, TEST_LOCATION );
657   DALI_TEST_EQUALS( frameCallback.mSetSizeCallSuccess,            false, TEST_LOCATION );
658   DALI_TEST_EQUALS( frameCallback.mSetPositionCallSuccess,        false, TEST_LOCATION );
659   DALI_TEST_EQUALS( frameCallback.mSetColorCallSuccess,           false, TEST_LOCATION );
660   DALI_TEST_EQUALS( frameCallback.mSetScaleCallSuccess,           false, TEST_LOCATION );
661   DALI_TEST_EQUALS( frameCallback.mBakeSizeCallSuccess,           false, TEST_LOCATION );
662   DALI_TEST_EQUALS( frameCallback.mBakePositionCallSuccess,       false, TEST_LOCATION );
663   DALI_TEST_EQUALS( frameCallback.mBakeColorCallSuccess,          false, TEST_LOCATION );
664   DALI_TEST_EQUALS( frameCallback.mBakeScaleCallSuccess,          false, TEST_LOCATION );
665
666   END_TEST;
667 }
668
669 int UtcDaliFrameCallbackActorRemovedAndAdded(void)
670 {
671   // Test to ensure that we do not call methods on actors that have been removed on the stage
672   // and then re-start calling the required methods if that actor is re-added back to the stage
673
674   TestApplication application;
675   Stage stage = Stage::GetCurrent();
676
677   Actor actor = Actor::New();
678   stage.Add( actor );
679
680   FrameCallbackActorIdCheck frameCallback( actor.GetId() );
681   DevelStage::AddFrameCallback( stage, frameCallback, stage.GetRootLayer() );
682
683   application.SendNotification();
684   application.Render();
685
686   // All methods should return successfully.
687
688   DALI_TEST_EQUALS( frameCallback.mCalled,                        true, TEST_LOCATION );
689   DALI_TEST_EQUALS( frameCallback.mGetSizeCallSuccess,            true, TEST_LOCATION );
690   DALI_TEST_EQUALS( frameCallback.mGetPositionCallSuccess,        true, TEST_LOCATION );
691   DALI_TEST_EQUALS( frameCallback.mGetColorCallSuccess,           true, TEST_LOCATION );
692   DALI_TEST_EQUALS( frameCallback.mGetScaleCallSuccess,           true, TEST_LOCATION );
693   DALI_TEST_EQUALS( frameCallback.mGetPositionAndSizeCallSuccess, true, TEST_LOCATION );
694   DALI_TEST_EQUALS( frameCallback.mSetSizeCallSuccess,            true, TEST_LOCATION );
695   DALI_TEST_EQUALS( frameCallback.mSetPositionCallSuccess,        true, TEST_LOCATION );
696   DALI_TEST_EQUALS( frameCallback.mSetColorCallSuccess,           true, TEST_LOCATION );
697   DALI_TEST_EQUALS( frameCallback.mSetScaleCallSuccess,           true, TEST_LOCATION );
698   DALI_TEST_EQUALS( frameCallback.mBakeSizeCallSuccess,           true, TEST_LOCATION );
699   DALI_TEST_EQUALS( frameCallback.mBakePositionCallSuccess,       true, TEST_LOCATION );
700   DALI_TEST_EQUALS( frameCallback.mBakeColorCallSuccess,          true, TEST_LOCATION );
701   DALI_TEST_EQUALS( frameCallback.mBakeScaleCallSuccess,          true, TEST_LOCATION );
702   frameCallback.Reset();
703
704   // Remove the actor from stage, the methods should not return successfully.
705
706   stage.Remove( actor );
707
708   application.SendNotification();
709   application.Render();
710
711   DALI_TEST_EQUALS( frameCallback.mCalled,                        true,  TEST_LOCATION );
712   DALI_TEST_EQUALS( frameCallback.mGetSizeCallSuccess,            false, TEST_LOCATION );
713   DALI_TEST_EQUALS( frameCallback.mGetPositionCallSuccess,        false, TEST_LOCATION );
714   DALI_TEST_EQUALS( frameCallback.mGetColorCallSuccess,           false, TEST_LOCATION );
715   DALI_TEST_EQUALS( frameCallback.mGetScaleCallSuccess,           false, TEST_LOCATION );
716   DALI_TEST_EQUALS( frameCallback.mGetPositionAndSizeCallSuccess, false, TEST_LOCATION );
717   DALI_TEST_EQUALS( frameCallback.mSetSizeCallSuccess,            false, TEST_LOCATION );
718   DALI_TEST_EQUALS( frameCallback.mSetPositionCallSuccess,        false, TEST_LOCATION );
719   DALI_TEST_EQUALS( frameCallback.mSetColorCallSuccess,           false, TEST_LOCATION );
720   DALI_TEST_EQUALS( frameCallback.mSetScaleCallSuccess,           false, TEST_LOCATION );
721   DALI_TEST_EQUALS( frameCallback.mBakeSizeCallSuccess,           false, TEST_LOCATION );
722   DALI_TEST_EQUALS( frameCallback.mBakePositionCallSuccess,       false, TEST_LOCATION );
723   DALI_TEST_EQUALS( frameCallback.mBakeColorCallSuccess,          false, TEST_LOCATION );
724   DALI_TEST_EQUALS( frameCallback.mBakeScaleCallSuccess,          false, TEST_LOCATION );
725   frameCallback.Reset();
726
727   // Re-add the actor back to the stage, all the methods should once again, return successfully.
728
729   stage.Add( actor );
730
731   application.SendNotification();
732   application.Render();
733
734   DALI_TEST_EQUALS( frameCallback.mCalled,                        true, TEST_LOCATION );
735   DALI_TEST_EQUALS( frameCallback.mGetSizeCallSuccess,            true, TEST_LOCATION );
736   DALI_TEST_EQUALS( frameCallback.mGetPositionCallSuccess,        true, TEST_LOCATION );
737   DALI_TEST_EQUALS( frameCallback.mGetColorCallSuccess,           true, TEST_LOCATION );
738   DALI_TEST_EQUALS( frameCallback.mGetScaleCallSuccess,           true, TEST_LOCATION );
739   DALI_TEST_EQUALS( frameCallback.mGetPositionAndSizeCallSuccess, true, TEST_LOCATION );
740   DALI_TEST_EQUALS( frameCallback.mSetSizeCallSuccess,            true, TEST_LOCATION );
741   DALI_TEST_EQUALS( frameCallback.mSetPositionCallSuccess,        true, TEST_LOCATION );
742   DALI_TEST_EQUALS( frameCallback.mSetColorCallSuccess,           true, TEST_LOCATION );
743   DALI_TEST_EQUALS( frameCallback.mSetScaleCallSuccess,           true, TEST_LOCATION );
744   DALI_TEST_EQUALS( frameCallback.mBakeSizeCallSuccess,           true, TEST_LOCATION );
745   DALI_TEST_EQUALS( frameCallback.mBakePositionCallSuccess,       true, TEST_LOCATION );
746   DALI_TEST_EQUALS( frameCallback.mBakeColorCallSuccess,          true, TEST_LOCATION );
747   DALI_TEST_EQUALS( frameCallback.mBakeScaleCallSuccess,          true, TEST_LOCATION );
748
749   END_TEST;
750 }
751
752 int UtcDaliFrameCallbackMultipleCallbacks(void)
753 {
754   // Test to ensure multiple frame-callbacks work as expected
755
756   TestApplication application;
757   Stage stage = Stage::GetCurrent();
758
759   Actor actor = Actor::New();
760   stage.Add( actor );
761
762   FrameCallbackBasic frameCallback1;
763   FrameCallbackBasic frameCallback2;
764   DevelStage::AddFrameCallback( stage, frameCallback1, stage.GetRootLayer() );
765   DevelStage::AddFrameCallback( stage, frameCallback2, stage.GetRootLayer() );
766
767   application.SendNotification();
768   application.Render();
769
770   DALI_TEST_EQUALS( frameCallback1.mCalled, true,  TEST_LOCATION );
771   DALI_TEST_EQUALS( frameCallback2.mCalled, true,  TEST_LOCATION );
772   frameCallback1.Reset();
773   frameCallback2.Reset();
774
775   // Remove the second frame-callback, only the first should be called
776
777   DevelStage::RemoveFrameCallback( stage, frameCallback2 );
778
779   application.SendNotification();
780   application.Render();
781
782   DALI_TEST_EQUALS( frameCallback1.mCalled, true,  TEST_LOCATION );
783   DALI_TEST_EQUALS( frameCallback2.mCalled, false, TEST_LOCATION );
784   frameCallback1.Reset();
785   frameCallback2.Reset();
786
787   // Re-add the second frame-callback and remove the first, only the second should be called
788
789   DevelStage::AddFrameCallback( stage, frameCallback2, stage.GetRootLayer() );
790   DevelStage::RemoveFrameCallback( stage, frameCallback1 );
791
792   application.SendNotification();
793   application.Render();
794
795   DALI_TEST_EQUALS( frameCallback1.mCalled, false, TEST_LOCATION );
796   DALI_TEST_EQUALS( frameCallback2.mCalled, true,  TEST_LOCATION );
797   frameCallback1.Reset();
798   frameCallback2.Reset();
799
800   // Attempt removal of the first frame-callback again, should be a no-op and yield the exact same results as the last run
801   DevelStage::RemoveFrameCallback( stage, frameCallback1 );
802
803   application.SendNotification();
804   application.Render();
805
806   DALI_TEST_EQUALS( frameCallback1.mCalled, false, TEST_LOCATION );
807   DALI_TEST_EQUALS( frameCallback2.mCalled, true,  TEST_LOCATION );
808   frameCallback1.Reset();
809   frameCallback2.Reset();
810
811   // Remove the second frame-callback as well, neither should be called
812   DevelStage::RemoveFrameCallback( stage, frameCallback2 );
813
814   application.SendNotification();
815   application.Render();
816
817   DALI_TEST_EQUALS( frameCallback1.mCalled, false, TEST_LOCATION );
818   DALI_TEST_EQUALS( frameCallback2.mCalled, false, TEST_LOCATION );
819
820   END_TEST;
821 }
822
823 int UtcDaliFrameCallbackActorDestroyed(void)
824 {
825   // Test to ensure that the frame-callback behaves gracefully if the connected root-actor is destroyed
826
827   TestApplication application;
828   Stage stage = Stage::GetCurrent();
829
830   Actor actor = Actor::New();
831   stage.Add( actor );
832
833   FrameCallbackBasic frameCallback1;
834   FrameCallbackBasic frameCallback2;
835   DevelStage::AddFrameCallback( stage, frameCallback1, actor );
836   DevelStage::AddFrameCallback( stage, frameCallback2, actor );
837
838   application.SendNotification();
839   application.Render();
840
841   DALI_TEST_EQUALS( frameCallback1.mCalled, true,  TEST_LOCATION );
842   DALI_TEST_EQUALS( frameCallback2.mCalled, true,  TEST_LOCATION );
843   frameCallback1.Reset();
844   frameCallback2.Reset();
845
846   // Remove the second frame-callback, only the first should be called
847
848   DevelStage::RemoveFrameCallback( stage, frameCallback2 );
849
850   application.SendNotification();
851   application.Render();
852
853   DALI_TEST_EQUALS( frameCallback1.mCalled, true,  TEST_LOCATION );
854   DALI_TEST_EQUALS( frameCallback2.mCalled, false, TEST_LOCATION );
855   frameCallback1.Reset();
856   frameCallback2.Reset();
857
858   // Remove and destroy the actor, the first one should not be called either
859   stage.Remove( actor );
860   actor.Reset();
861
862   application.SendNotification();
863   application.Render();
864
865   DALI_TEST_EQUALS( frameCallback1.mCalled, false,  TEST_LOCATION );
866   DALI_TEST_EQUALS( frameCallback2.mCalled, false, TEST_LOCATION );
867
868   END_TEST;
869 }
870
871 int UtcDaliFrameCallbackDestroyedBeforeRemoving(void)
872 {
873   // Ensure there's no segmentation fault if the callback is deleted without being removed
874
875   TestApplication application;
876   Stage stage = Stage::GetCurrent();
877
878   Actor actor = Actor::New();
879   stage.Add( actor );
880
881   {
882     FrameCallbackBasic frameCallback;
883     DevelStage::AddFrameCallback( stage, frameCallback, actor );
884
885     application.SendNotification();
886     application.Render();
887
888     DALI_TEST_EQUALS( frameCallback.mCalled, true,  TEST_LOCATION );
889     frameCallback.Reset();
890   }
891
892   // frameCallback has now been destroyed but not removed
893
894   application.SendNotification();
895   application.Render();
896   DALI_TEST_CHECK( true ); // If it runs to here then there's no segmentation fault
897
898   END_TEST;
899 }
900
901 int UtcDaliFrameCallbackDoubleAddition(void)
902 {
903   // Ensure we don't connect the same frame-callback twice
904
905   TestApplication application;
906   Stage stage = Stage::GetCurrent();
907   Actor rootActor = stage.GetRootLayer();
908
909   FrameCallbackBasic frameCallback;
910   DevelStage::AddFrameCallback( stage, frameCallback, rootActor );
911
912   try
913   {
914     DevelStage::AddFrameCallback( stage, frameCallback, rootActor );
915   }
916   catch( ... )
917   {
918     DALI_TEST_CHECK( true );
919   }
920
921   END_TEST;
922 }