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