Merge "DALi C# binding - adding property for Animation LoopCount and others." into...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TransitionData.cpp
1 /*
2  * Copyright (c) 2016 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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
23 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
24 #include "dummy-control.h"
25
26 using namespace Dali;
27 using namespace Toolkit;
28
29
30 void utc_dali_toolkit_transition_data_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_toolkit_transition_data_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 Property::Map CreateMap()
41 {
42   Property::Map map;
43
44   map["target"] = "Actor1";
45   map["property"] = "color";
46   map["initialValue"] = Color::MAGENTA;
47   map["targetValue"] = Color::RED;
48   map["animator"] = Property::Map()
49     .Add("alphaFunction", "EASE_IN_OUT_BACK")
50     .Add("timePeriod", Property::Map()
51          .Add("delay", 0.5f)
52          .Add("duration", 1.0f));
53   return map;
54 }
55
56 void CHECK_ARRAY_EQUALS( Property::Array test, Property::Value result )
57 {
58   if( result.GetType() == Property::ARRAY )
59   {
60     // Compare arrays
61     Property::Array *resultArray = result.GetArray();
62     DALI_TEST_EQUALS( test.Count(), resultArray->Count(), TEST_LOCATION );
63     for( size_t i=0; i < std::min(test.Count(), resultArray->Count()); ++i )
64     {
65       Property::Value a = test.GetElementAt(i);
66       Property::Value b = resultArray->GetElementAt(i);
67       DALI_TEST_EQUALS( a.GetType(), b.GetType(), TEST_LOCATION );
68       DALI_TEST_EQUALS( a, b, 0.001, TEST_LOCATION );
69     }
70   }
71   else if( result.GetType() == Property::VECTOR4 )
72   {
73     Vector4 value = result.Get<Vector4>();
74     DALI_TEST_CHECK( test.Count() >= 4 );
75     for( size_t i=0; i < 4; ++i )
76     {
77       Property::Value a = test.GetElementAt(i);
78       DALI_TEST_EQUALS( a.GetType(), Property::FLOAT, TEST_LOCATION );
79       DALI_TEST_EQUALS( a.Get<float>(), value[i], 0.001, TEST_LOCATION );
80     }
81   }
82   else
83   {
84     DALI_TEST_CHECK( 0 );
85   }
86 }
87
88 void CHECK_MAP_EQUALS( Property::Map test, Property::Map result )
89 {
90   DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
91
92   for( unsigned int i=0; i< test.Count(); ++i )
93   {
94     KeyValuePair keyValue = test.GetKeyValue(i);
95     Property::Value* value;
96
97     if( keyValue.first.type == Property::Key::STRING )
98     {
99       value = result.Find(keyValue.first.stringKey);
100     }
101     else
102     {
103       value = result.Find(keyValue.first.indexKey);
104     }
105
106     DALI_TEST_CHECK( value != NULL );
107     if( value != NULL )
108     {
109       if( keyValue.second.GetType() == Property::MAP )
110       {
111         DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
112         CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) );
113       }
114       else if( keyValue.second.GetType() == Property::ARRAY )
115       {
116         CHECK_ARRAY_EQUALS( *(keyValue.second.GetArray()), *value );
117       }
118       else if( keyValue.second.GetType() == Property::STRING )
119       {
120         DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
121         std::string str;
122         value->Get(str);
123         DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION );
124       }
125       else
126       {
127         DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
128         DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION );
129       }
130     }
131   }
132 }
133
134
135 int UtcDaliTransitionDataNew(void)
136 {
137   TestApplication application;
138
139   Property::Map map = CreateMap();
140   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
141   DALI_TEST_CHECK( transition );
142
143   END_TEST;
144 }
145
146 int UtcDaliTransitionDataDownCast(void)
147 {
148   TestApplication application;
149
150   Property::Map map = CreateMap();
151
152   BaseHandle handle = TransitionData::New( map );
153   DALI_TEST_CHECK( handle );
154
155   TransitionData transitionData = TransitionData::DownCast( handle );
156   DALI_TEST_CHECK( transitionData );
157   END_TEST;
158 }
159
160 int UtcDaliTransitionDataCopyConstructor(void)
161 {
162   TestApplication application;
163
164   Property::Map map = CreateMap();
165
166   TransitionData transitionData = TransitionData::New( map );
167   DALI_TEST_CHECK( transitionData );
168
169   TransitionData td2( transitionData );
170   DALI_TEST_CHECK( td2 );
171   DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
172   END_TEST;
173 }
174
175 int UtcDaliTransitionDataAssignmentOperator(void)
176 {
177   TestApplication application;
178
179   Property::Map map = CreateMap();
180
181   TransitionData transitionData = TransitionData::New( map );
182   DALI_TEST_CHECK( transitionData );
183
184   TransitionData td2;
185   DALI_TEST_CHECK( !td2 );
186
187   td2 = transitionData;
188   DALI_TEST_CHECK( td2 );
189
190   DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
191   END_TEST;
192 }
193
194 int UtcDaliTransitionDataCount(void)
195 {
196   TestApplication application;
197
198   Property::Map map = CreateMap();
199   TransitionData transitionData = TransitionData::New( map );
200   DALI_TEST_CHECK( transitionData );
201   DALI_TEST_EQUALS( transitionData.Count(), 1, TEST_LOCATION );
202
203   Property::Array array;
204   array.PushBack( map );
205   array.PushBack( map );
206   array.PushBack( map );
207
208   TransitionData transitionData2 = TransitionData::New( array );
209   DALI_TEST_CHECK( transitionData2 );
210   DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION );
211
212   END_TEST;
213 }
214
215 int UtcDaliTransitionDataMap1P(void)
216 {
217   TestApplication application;
218
219   tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
220
221   Property::Map map;
222   map["target"] = "visual1";
223   map["property"] = "mixColor";
224   map["initialValue"] = Color::MAGENTA;
225   map["targetValue"] = Color::RED;
226   map["animator"] = Property::Map()
227     .Add("alphaFunction", "EASE_IN_OUT")
228     .Add("timePeriod", Property::Map()
229          .Add("delay", 0.5f)
230          .Add("duration", 1.0f));
231
232   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
233
234   DummyControl actor = DummyControl::New();
235   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
236   actor.SetName("Actor1");
237   actor.SetColor(Color::CYAN);
238   Stage::GetCurrent().Add(actor);
239
240   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
241
242   Property::Map visualMap;
243   visualMap[Visual::Property::TYPE] = Visual::COLOR;
244   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
245   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
246   visual.SetName( "visual1" );
247
248   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
249   dummyImpl.RegisterVisual( visualIndex, actor, visual );
250
251   Animation anim = dummyImpl.CreateTransition( transition );
252   DALI_TEST_CHECK( anim );
253
254   Renderer renderer = actor.GetRendererAt(0);
255   Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
256   application.SendNotification();
257   application.Render(0);
258
259   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::MAGENTA, TEST_LOCATION);
260
261   anim.Play();
262
263   application.SendNotification();
264   application.Render(0);
265   application.Render(500); // Start animation
266   application.Render(500); // Halfway thru anim
267   application.SendNotification();
268   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
269
270   application.Render(500); // End of anim
271   application.SendNotification();
272   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::RED, TEST_LOCATION );
273
274   END_TEST;
275 }
276
277 int UtcDaliTransitionDataMap2P(void)
278 {
279   TestApplication application;
280
281   tet_printf("Testing animation of a visual property using programmatic maps\n");
282
283   Property::Map map;
284   map["target"] = "visual1";
285   //Control::CONTROL_PROPERTY_END_INDEX + 1
286   map["property"] = ColorVisual::Property::MIX_COLOR;
287   map["initialValue"] = Color::MAGENTA;
288   map["targetValue"] = Color::RED;
289   map["animator"] = Property::Map()
290     .Add("alphaFunction", "LINEAR")
291     .Add("timePeriod", Property::Map()
292          .Add("delay", 0.5f)
293          .Add("duration", 1.0f));
294
295   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
296
297   DummyControl actor = DummyControl::New();
298   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
299   actor.SetName("Actor1");
300   actor.SetColor(Color::CYAN);
301   Stage::GetCurrent().Add(actor);
302
303   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
304
305   Property::Map visualMap;
306   visualMap[Visual::Property::TYPE] = Visual::COLOR;
307   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
308   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
309   visual.SetName( "visual1" );
310
311   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
312   dummyImpl.RegisterVisual( visualIndex, actor, visual );
313
314   Animation anim = dummyImpl.CreateTransition( transition );
315   DALI_TEST_CHECK( anim );
316
317   Renderer renderer = actor.GetRendererAt(0);
318   Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
319   application.SendNotification();
320   application.Render(0);
321
322   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::MAGENTA, TEST_LOCATION);
323
324   anim.Play();
325
326   application.SendNotification();
327   application.Render(0);
328   application.Render(500); // Start animation
329   application.Render(500); // Halfway thru anim
330   application.SendNotification();
331   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
332
333   application.Render(500); // End of anim
334   application.SendNotification();
335   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::RED, TEST_LOCATION );
336
337   END_TEST;
338 }
339
340
341 int UtcDaliTransitionDataMap3P(void)
342 {
343   TestApplication application;
344
345   tet_printf("Testing animation of a visual's placement actor property\n");
346
347   Property::Map map;
348   map["target"] = "visual1";
349   map["property"] = "color";
350   map["initialValue"] = Color::MAGENTA;
351   map["targetValue"] = Color::RED;
352   map["animator"] = Property::Map()
353     .Add("alphaFunction", "EASE_IN_OUT")
354     .Add("timePeriod", Property::Map()
355          .Add("delay", 0.5f)
356          .Add("duration", 1.0f));
357
358   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
359
360   DummyControl actor = DummyControl::New();
361   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
362   actor.SetName("Actor1");
363   actor.SetColor(Color::CYAN);
364   Stage::GetCurrent().Add(actor);
365
366   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
367
368   Property::Map visualMap;
369   visualMap[Visual::Property::TYPE] = Visual::COLOR;
370   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
371   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
372   visual.SetName( "visual1" );
373
374   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
375   dummyImpl.RegisterVisual( visualIndex, actor, visual );
376
377   Animation anim = dummyImpl.CreateTransition( transition );
378   DALI_TEST_CHECK( anim );
379
380   application.SendNotification();
381   application.Render(0);
382   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
383
384   anim.Play();
385
386   application.SendNotification();
387   application.Render(0);
388   application.Render(500);
389   application.Render(500); // Halfway thru map1 anim
390   application.SendNotification();
391   DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
392
393   application.Render(500); // End of map1 anim
394   application.SendNotification();
395   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
396   END_TEST;
397 }
398
399
400 int UtcDaliTransitionDataMap4P(void)
401 {
402   TestApplication application;
403
404   tet_printf("Testing animation of a visual's placement actor property using bezier curve\n");
405
406   Property::Map map;
407   map["target"] = "Actor1";
408   map["property"] = "position";
409   map["initialValue"] = Vector3(0, 0, 0);
410   map["targetValue"] = Vector3(100, 100, 0);
411   map["animator"] = Property::Map()
412     .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
413     .Add("timePeriod", Property::Map()
414          .Add("delay", 0.0f)
415          .Add("duration", 1.0f));
416
417   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
418
419   DummyControl actor = DummyControl::New();
420   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
421   actor.SetName("Actor1");
422   Stage::GetCurrent().Add(actor);
423
424   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
425   Animation anim = dummyImpl.CreateTransition( transition );
426   DALI_TEST_CHECK( anim );
427
428   application.SendNotification();
429   application.Render(0);
430   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
431
432   anim.Play();
433
434   application.SendNotification();
435   application.Render(0);
436
437   application.Render(250); // 25%
438   application.SendNotification();
439   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(-10,-10,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50%
440
441   application.Render(250); // Halfway thru map1 anim
442   application.SendNotification();
443   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(24,24,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50%
444
445   application.Render(250); // End of map1 anim
446   application.SendNotification();
447   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve
448
449   application.Render(250); // End of map1 anim
450   application.SendNotification();
451   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
452   END_TEST;
453 }
454
455 int UtcDaliTransitionDataMap1N(void)
456 {
457   TestApplication application;
458
459   Property::Map map;
460   map["target"] = "Actor1";
461   map["property"] = "randomProperty";
462   map["initialValue"] = Color::MAGENTA;
463   map["targetValue"] = Color::RED;
464   map["animator"] = Property::Map()
465     .Add("alphaFunction", "EASE_OUT")
466     .Add("timePeriod", Property::Map()
467          .Add("delay", 0.5f)
468          .Add("duration", 1.0f));
469
470   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
471
472   DummyControl actor = DummyControl::New();
473   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
474   actor.SetName("Actor1");
475   actor.SetColor(Color::CYAN);
476   Stage::GetCurrent().Add(actor);
477
478   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
479   Animation anim = dummyImpl.CreateTransition( transition );
480   DALI_TEST_CHECK( ! anim );
481
482   CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
483   END_TEST;
484 }
485
486
487 int UtcDaliTransitionDataMapN3(void)
488 {
489   TestApplication application;
490
491   tet_printf("Testing visual lookup with no renderers\n");
492
493   Property::Map map;
494   map["target"] = "visual1";
495   map["property"] = "mixColor";
496   map["initialValue"] = Color::MAGENTA;
497   map["targetValue"] = Color::RED;
498   map["animator"] = Property::Map()
499     .Add("alphaFunction", "EASE_OUT_BACK")
500     .Add("timePeriod", Property::Map()
501          .Add("delay", 0.5f)
502          .Add("duration", 1.0f));
503
504   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
505   CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
506
507   DummyControl actor = DummyControl::New();
508   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
509   actor.SetName("Actor1");
510   actor.SetColor(Color::CYAN);
511   // Don't stage actor
512
513   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
514   Property::Map visualMap;
515   visualMap[Visual::Property::TYPE] = Visual::COLOR;
516   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
517   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
518   visual.SetName( "visual1" );
519
520   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
521   dummyImpl.RegisterVisual( visualIndex, actor, visual );
522
523   Animation anim = dummyImpl.CreateTransition( transition );
524   DALI_TEST_CHECK( !anim );
525   END_TEST;
526 }
527
528
529 int UtcDaliTransitionDataMapN4(void)
530 {
531   TestApplication application;
532
533   tet_printf("Testing visual doesn't animate with duff bezier data \n");
534
535   Property::Map map;
536   map["target"] = "visual1";
537   map["property"] = "mixColor";
538   map["initialValue"] = Color::MAGENTA;
539   map["targetValue"] = Color::RED;
540   map["animator"] = Property::Map()
541     .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
542     .Add("timePeriod", Property::Map()
543          .Add("delay", 0.5f)
544          .Add("duration", 1.0f));
545
546   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
547
548   DummyControl actor = DummyControl::New();
549   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
550   actor.SetName("Actor1");
551   actor.SetColor(Color::CYAN);
552   Stage::GetCurrent().Add(actor);
553
554   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
555   Property::Map visualMap;
556   visualMap[Visual::Property::TYPE] = Visual::COLOR;
557   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
558   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
559   visual.SetName( "visual1" );
560
561   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
562   dummyImpl.RegisterVisual( visualIndex, actor, visual );
563
564   Animation anim = dummyImpl.CreateTransition( transition );
565   DALI_TEST_CHECK( !anim );
566
567   application.SendNotification();
568   application.Render(0);
569   application.SendNotification();
570
571   Renderer renderer = actor.GetRendererAt(0);
572   Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR);
573
574   tet_printf( "Test that the property has been set to target value\n");
575   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
576
577   END_TEST;
578 }
579
580 int UtcDaliTransitionDataMapN5(void)
581 {
582   TestApplication application;
583
584   tet_printf("Testing visual doesn't animate with duff bezier data \n");
585
586   Property::Map map;
587   map["target"] = "visual1";
588   map["property"] = "mixColor";
589   map["initialValue"] = Color::MAGENTA;
590   map["targetValue"] = Color::RED;
591   map["animator"] = Property::Map()
592     .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
593     .Add("timePeriod", Property::Map()
594          .Add("delay", 0.5f)
595          .Add("duration", 1.0f));
596
597   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
598
599   DummyControl actor = DummyControl::New();
600   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
601   actor.SetName("Actor1");
602   actor.SetColor(Color::CYAN);
603   Stage::GetCurrent().Add(actor);
604
605   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
606   Property::Map visualMap;
607   visualMap[Visual::Property::TYPE] = Visual::COLOR;
608   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
609   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
610   visual.SetName( "visual1" );
611
612   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
613   dummyImpl.RegisterVisual( visualIndex, actor, visual );
614
615   Animation anim = dummyImpl.CreateTransition( transition );
616   DALI_TEST_CHECK( !anim );
617
618   application.SendNotification();
619   application.Render(0);
620   application.SendNotification();
621
622   Renderer renderer = actor.GetRendererAt(0);
623   Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR);
624
625   tet_printf( "Test that the property has been set to target value\n");
626   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
627
628   END_TEST;
629 }
630
631 int UtcDaliTransitionDataMapN6(void)
632 {
633   TestApplication application;
634
635   tet_printf("Testing visual doesn't animate with duff bezier data \n");
636
637   Property::Map map;
638   map["target"] = "visual1";
639   map["property"] = "mixColor";
640   map["initialValue"] = Color::MAGENTA;
641   map["targetValue"] = Color::RED;
642   map["animator"] = Property::Map()
643     .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
644     .Add("timePeriod", Property::Map()
645          .Add("delay", 0.5f)
646          .Add("duration", 1.0f));
647
648   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
649
650   DummyControl actor = DummyControl::New();
651   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
652   actor.SetName("Actor1");
653   actor.SetColor(Color::CYAN);
654   Stage::GetCurrent().Add(actor);
655
656   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
657   Property::Map visualMap;
658   visualMap[Visual::Property::TYPE] = Visual::COLOR;
659   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
660   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
661   visual.SetName( "visual1" );
662
663   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
664   dummyImpl.RegisterVisual( visualIndex, actor, visual );
665
666   Animation anim = dummyImpl.CreateTransition( transition );
667   DALI_TEST_CHECK( !anim );
668
669   application.SendNotification();
670   application.Render(0);
671   application.SendNotification();
672
673   Renderer renderer = actor.GetRendererAt(0);
674   Property::Index mixColorIdx = renderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR);
675
676   tet_printf( "Test that the property has been set to target value\n");
677   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
678
679   END_TEST;
680 }
681
682
683 int UtcDaliTransitionDataArrayP(void)
684 {
685   TestApplication application;
686
687   Property::Map map1;
688   map1["target"] = "Actor1";
689   map1["property"] = "color";
690   map1["initialValue"] = Color::MAGENTA;
691   map1["targetValue"] = Color::RED;
692   map1["animator"] = Property::Map()
693     .Add("alphaFunction", "EASE_IN_OUT")
694     .Add("timePeriod", Property::Map()
695          .Add("delay", 0.5f)
696          .Add("duration", 1.0f));
697
698   Property::Map map2;
699   map2["target"] = "Actor1";
700   map2["property"] = "position";
701   map2["initialValue"] = Vector3(100,0,0);
702   map2["targetValue"] = Vector3(0,100,0);
703   map2["animator"] = Property::Map()
704     .Add("alphaFunction", "EASE_IN_OUT")
705     .Add("timePeriod", Property::Map()
706          .Add("delay", 0.0f)
707          .Add("duration", 1.0f));
708
709   Property::Map map3;
710   map3["target"] = "Actor1";
711   map3["property"] = "orientation";
712   map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
713
714   Property::Array array;
715   array.PushBack(map1);
716   array.PushBack(map2);
717   array.PushBack(map3);
718
719   Dali::Toolkit::TransitionData transition = TransitionData::New( array );
720
721   DummyControl actor = DummyControl::New();
722   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
723   actor.SetName("Actor1");
724   actor.SetColor(Color::CYAN);
725   Stage::GetCurrent().Add(actor);
726   DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
727
728   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
729   Animation anim = dummyImpl.CreateTransition( transition );
730   DALI_TEST_CHECK( anim );
731   application.SendNotification();
732   application.Render(0);
733   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
734   DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
735   anim.Play();
736
737   application.SendNotification();
738   application.Render(0);   // start map2 anim
739   application.SendNotification();
740   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
741
742   application.Render(500); // Start map1 animation, halfway thru map2 anim
743   application.SendNotification();
744   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
745
746   application.Render(500); // Halfway thru map1 anim, end of map2 anim
747   application.SendNotification();
748   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
749   DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
750
751   application.Render(500); // End of map1 anim
752   application.SendNotification();
753   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
754
755   END_TEST;
756 }
757
758
759 int UtcDaliTransitionDataGetAnimatorP(void)
760 {
761   TestApplication application;
762
763   Property::Map map1;
764   map1["target"] = "Actor1";
765   map1["property"] = "color";
766   map1["initialValue"] = Color::MAGENTA;
767   map1["targetValue"] = Color::RED;
768   map1["animator"] = Property::Map()
769     .Add("alphaFunction", "EASE_IN_SQUARE")
770     .Add("timePeriod", Property::Map()
771          .Add("delay", 0.5f)
772          .Add("duration", 0.5f));
773
774   Property::Map map2;
775   map2["target"] = "Actor1";
776   map2["property"] = "position";
777   map2["initialValue"] = Vector3(100,0,0);
778   map2["targetValue"] = Vector3(0,100,0);
779   map2["animator"] = Property::Map()
780     .Add("alphaFunction", "EASE_OUT_SQUARE")
781     .Add("timePeriod", Property::Map()
782          .Add("delay", 0.2f)
783          .Add("duration", 2.0f));
784
785   Property::Map map3;
786   map3["target"] = "Actor1";
787   map3["property"] = "size";
788   map3["initialValue"] = Vector2(10,10);
789   map3["targetValue"] = Vector2(100,100);
790   map3["animator"] = Property::Map()
791     .Add("alphaFunction", "EASE_OUT_SINE")
792     .Add("timePeriod", Property::Map()
793          .Add("delay", 0.4f)
794          .Add("duration", 3.0f));
795
796   Property::Map map4;
797   map4["target"] = "Actor2";
798   map4["property"] = "color";
799   map4["initialValue"] = Color::BLACK;
800   map4["targetValue"] = Color::GREEN;
801   map4["animator"] = Property::Map()
802     .Add("alphaFunction", "EASE_IN_OUT_SINE")
803     .Add("timePeriod", Property::Map()
804          .Add("delay", 0.5f)
805          .Add("duration", 0.5f));
806
807   Property::Map map5;
808   map5["target"] = "Actor2";
809   map5["property"] = "position";
810   map5["initialValue"] = Vector3(100,0,0);
811   map5["targetValue"] = Vector3(0,100,0);
812   map5["animator"] = Property::Map()
813     .Add("alphaFunction", "BOUNCE")
814     .Add("timePeriod", Property::Map()
815          .Add("delay", 0.2f)
816          .Add("duration", 2.0f));
817
818   Property::Map map6;
819   map6["target"] = "Actor2";
820   map6["property"] = "size";
821   map6["initialValue"] = Vector2(10,10);
822   map6["targetValue"] = Vector2(100,100);
823   map6["animator"] = Property::Map()
824     .Add("alphaFunction", "SIN")
825     .Add("timePeriod", Property::Map()
826          .Add("delay", 0.4f)
827          .Add("duration", 3.0f));
828
829   Property::Map map7;
830   map7["target"] = "Actor4";
831   map7["property"] = "sizeModeFactor";
832   map7["initialValue"] = Vector3(1,1,1);
833   map7["targetValue"] = Vector3(2,2,2);
834   map7["animator"] = Property::Map()
835     .Add("alphaFunction", "EASE_IN_SINE")
836     .Add("timePeriod", Property::Map()
837          .Add("delay", 0.0f)
838          .Add("duration", 1.0f));
839
840   Property::Map map8;
841   map8["target"] = "Visual1";
842   map8["property"] = "colorAlpha";
843   map8["targetValue"] = 1.0f;
844   map8["animator"] = Property::Map()
845     .Add("alphaFunction", "EASE_IN")
846     .Add("timePeriod", Property::Map()
847          .Add("delay", 0.3f)
848          .Add("duration", 9.0f));
849
850   Property::Map map9;
851   map9["target"] = "Actor2";
852   map9["property"] = "scale";
853   map9["initialValue"] = Vector3(0,0,0);
854   map9["targetValue"] = Vector3(1,1,1);
855   map9["animator"] = Property::Map()
856     .Add("alphaFunction", "REVERSE")
857     .Add("timePeriod", Property::Map()
858          .Add("delay", 0.0f)
859          .Add("duration", 1.0f));
860
861   Property::Map map10;
862   map10["target"] = "Actor2";
863   map10["property"] = "scale";
864   map10["initialValue"] = Vector3(0,0,0);
865   map10["targetValue"] = Vector3(1,1,1);
866   map10["animator"] = Property::Map()
867     .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
868     .Add("timePeriod", Property::Map()
869          .Add("delay", 0.0f)
870          .Add("duration", 1.0f));
871
872   Property::Map map11;
873   map11["target"] = "Actor2";
874   map11["property"] = "scale";
875   map11["initialValue"] = Vector3(0,0,0);
876   map11["targetValue"] = Vector3(1,1,1);
877   map11["animator"] = Property::Map()
878     .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
879     .Add("timePeriod", Property::Map()
880          .Add("delay", 0.0f)
881          .Add("duration", 1.0f));
882
883   Property::Map map12;
884   map12["target"] = "Actor1";
885   map12["property"] = "orientation";
886   map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
887
888   Property::Array array;
889   array.PushBack(map1);
890   array.PushBack(map2);
891   array.PushBack(map3);
892   array.PushBack(map4);
893   array.PushBack(map5);
894   array.PushBack(map6);
895   array.PushBack(map7);
896   array.PushBack(map8);
897   array.PushBack(map9);
898   array.PushBack(map10);
899   array.PushBack(map11);
900   array.PushBack(map12);
901
902   Dali::Toolkit::TransitionData transition = TransitionData::New( array );
903
904   DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
905
906   for( unsigned int i=0; i < array.Count(); ++i )
907   {
908     Property::Map animatorMap = transition.GetAnimatorAt(i);
909     Property::Value& value = array.GetElementAt(i);
910     Property::Map* inputMap = value.GetMap();
911     DALI_TEST_CHECK( inputMap );
912     CHECK_MAP_EQUALS( *inputMap, animatorMap );
913   }
914
915   END_TEST;
916 }