Merge "Revert public API changes. Handle methods." into devel/master
[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
342 int UtcDaliTransitionDataMap3P(void)
343 {
344   TestApplication application;
345
346   tet_printf("Testing animation of a visual's placement actor property\n");
347
348   Property::Map map;
349   map["target"] = "visual1";
350   map["property"] = "color";
351   map["initialValue"] = Color::MAGENTA;
352   map["targetValue"] = Color::RED;
353   map["animator"] = Property::Map()
354     .Add("alphaFunction", "EASE_IN_OUT")
355     .Add("timePeriod", Property::Map()
356          .Add("delay", 0.5f)
357          .Add("duration", 1.0f));
358
359   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
360
361   DummyControl actor = DummyControl::New();
362   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
363   actor.SetName("Actor1");
364   actor.SetColor(Color::CYAN);
365   Stage::GetCurrent().Add(actor);
366
367   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
368
369   Property::Map visualMap;
370   visualMap[Visual::Property::TYPE] = Visual::COLOR;
371   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
372   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
373   visual.SetName( "visual1" );
374
375   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
376   dummyImpl.RegisterVisual( visualIndex, visual );
377
378   Animation anim = dummyImpl.CreateTransition( transition );
379   DALI_TEST_CHECK( anim );
380
381   application.SendNotification();
382   application.Render(0);
383   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
384
385   anim.Play();
386
387   application.SendNotification();
388   application.Render(0);
389   application.Render(500);
390   application.Render(500); // Halfway thru map1 anim
391   application.SendNotification();
392   DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
393
394   application.Render(500); // End of map1 anim
395   application.SendNotification();
396   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
397   END_TEST;
398 }
399
400
401 int UtcDaliTransitionDataMap4P(void)
402 {
403   TestApplication application;
404
405   tet_printf("Testing animation of a visual's placement actor property using bezier curve\n");
406
407   Property::Map map;
408   map["target"] = "Actor1";
409   map["property"] = "position";
410   map["initialValue"] = Vector3(0, 0, 0);
411   map["targetValue"] = Vector3(100, 100, 0);
412   map["animator"] = Property::Map()
413     .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
414     .Add("timePeriod", Property::Map()
415          .Add("delay", 0.0f)
416          .Add("duration", 1.0f));
417
418   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
419
420   DummyControl actor = DummyControl::New();
421   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
422   actor.SetName("Actor1");
423   Stage::GetCurrent().Add(actor);
424
425   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
426   Animation anim = dummyImpl.CreateTransition( transition );
427   DALI_TEST_CHECK( anim );
428
429   application.SendNotification();
430   application.Render(0);
431   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
432
433   anim.Play();
434
435   application.SendNotification();
436   application.Render(0);
437
438   application.Render(250); // 25%
439   application.SendNotification();
440   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%
441
442   application.Render(250); // Halfway thru map1 anim
443   application.SendNotification();
444   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%
445
446   application.Render(250); // End of map1 anim
447   application.SendNotification();
448   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
449
450   application.Render(250); // End of map1 anim
451   application.SendNotification();
452   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
453   END_TEST;
454 }
455
456 int UtcDaliTransitionDataMap1N(void)
457 {
458   TestApplication application;
459
460   Property::Map map;
461   map["target"] = "Actor1";
462   map["property"] = "randomProperty";
463   map["initialValue"] = Color::MAGENTA;
464   map["targetValue"] = Color::RED;
465   map["animator"] = Property::Map()
466     .Add("alphaFunction", "EASE_OUT")
467     .Add("timePeriod", Property::Map()
468          .Add("delay", 0.5f)
469          .Add("duration", 1.0f));
470
471   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
472
473   DummyControl actor = DummyControl::New();
474   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
475   actor.SetName("Actor1");
476   actor.SetColor(Color::CYAN);
477   Stage::GetCurrent().Add(actor);
478
479   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
480   Animation anim = dummyImpl.CreateTransition( transition );
481   DALI_TEST_CHECK( ! anim );
482
483   CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
484   END_TEST;
485 }
486
487
488 int UtcDaliTransitionDataMapN3(void)
489 {
490   TestApplication application;
491
492   tet_printf("Testing visual lookup with no renderers\n");
493
494   Property::Map map;
495   map["target"] = "visual1";
496   map["property"] = "mixColor";
497   map["initialValue"] = Color::MAGENTA;
498   map["targetValue"] = Color::RED;
499   map["animator"] = Property::Map()
500     .Add("alphaFunction", "EASE_OUT_BACK")
501     .Add("timePeriod", Property::Map()
502          .Add("delay", 0.5f)
503          .Add("duration", 1.0f));
504
505   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
506   CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
507
508   DummyControl actor = DummyControl::New();
509   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
510   actor.SetName("Actor1");
511   actor.SetColor(Color::CYAN);
512   // Don't stage actor
513
514   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
515   Property::Map visualMap;
516   visualMap[Visual::Property::TYPE] = Visual::COLOR;
517   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
518   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
519   visual.SetName( "visual1" );
520
521   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
522   dummyImpl.RegisterVisual( visualIndex, visual );
523
524   Animation anim = dummyImpl.CreateTransition( transition );
525   DALI_TEST_CHECK( !anim );
526   END_TEST;
527 }
528
529
530 int UtcDaliTransitionDataMapN4(void)
531 {
532   TestApplication application;
533
534   tet_printf("Testing visual doesn't animate with duff bezier data \n");
535
536   Property::Map map;
537   map["target"] = "visual1";
538   map["property"] = "mixColor";
539   map["initialValue"] = Color::MAGENTA;
540   map["targetValue"] = Color::RED;
541   map["animator"] = Property::Map()
542     .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
543     .Add("timePeriod", Property::Map()
544          .Add("delay", 0.5f)
545          .Add("duration", 1.0f));
546
547   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
548
549   DummyControl actor = DummyControl::New();
550   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
551   actor.SetName("Actor1");
552   actor.SetColor(Color::CYAN);
553   Stage::GetCurrent().Add(actor);
554
555   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
556   Property::Map visualMap;
557   visualMap[Visual::Property::TYPE] = Visual::COLOR;
558   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
559   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
560   visual.SetName( "visual1" );
561
562   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
563   dummyImpl.RegisterVisual( visualIndex, visual );
564
565   Animation anim = dummyImpl.CreateTransition( transition );
566   DALI_TEST_CHECK( !anim );
567
568   application.SendNotification();
569   application.Render(0);
570   application.SendNotification();
571
572   Renderer renderer = actor.GetRendererAt(0);
573   Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
574
575   tet_printf( "Test that the property has been set to target value\n");
576   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
577
578   END_TEST;
579 }
580
581 int UtcDaliTransitionDataMapN5(void)
582 {
583   TestApplication application;
584
585   tet_printf("Testing visual doesn't animate with duff bezier data \n");
586
587   Property::Map map;
588   map["target"] = "visual1";
589   map["property"] = "mixColor";
590   map["initialValue"] = Color::MAGENTA;
591   map["targetValue"] = Color::RED;
592   map["animator"] = Property::Map()
593     .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
594     .Add("timePeriod", Property::Map()
595          .Add("delay", 0.5f)
596          .Add("duration", 1.0f));
597
598   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
599
600   DummyControl actor = DummyControl::New();
601   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
602   actor.SetName("Actor1");
603   actor.SetColor(Color::CYAN);
604   Stage::GetCurrent().Add(actor);
605
606   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
607   Property::Map visualMap;
608   visualMap[Visual::Property::TYPE] = Visual::COLOR;
609   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
610   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
611   visual.SetName( "visual1" );
612
613   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
614   dummyImpl.RegisterVisual( visualIndex, visual );
615
616   Animation anim = dummyImpl.CreateTransition( transition );
617   DALI_TEST_CHECK( !anim );
618
619   application.SendNotification();
620   application.Render(0);
621   application.SendNotification();
622
623   Renderer renderer = actor.GetRendererAt(0);
624   Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
625
626   tet_printf( "Test that the property has been set to target value\n");
627   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
628
629   END_TEST;
630 }
631
632 int UtcDaliTransitionDataMapN6(void)
633 {
634   TestApplication application;
635
636   tet_printf("Testing visual doesn't animate with duff bezier data \n");
637
638   Property::Map map;
639   map["target"] = "visual1";
640   map["property"] = "mixColor";
641   map["initialValue"] = Color::MAGENTA;
642   map["targetValue"] = Color::RED;
643   map["animator"] = Property::Map()
644     .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
645     .Add("timePeriod", Property::Map()
646          .Add("delay", 0.5f)
647          .Add("duration", 1.0f));
648
649   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
650
651   DummyControl actor = DummyControl::New();
652   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
653   actor.SetName("Actor1");
654   actor.SetColor(Color::CYAN);
655   Stage::GetCurrent().Add(actor);
656
657   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
658   Property::Map visualMap;
659   visualMap[Visual::Property::TYPE] = Visual::COLOR;
660   visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
661   Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
662   visual.SetName( "visual1" );
663
664   Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
665   dummyImpl.RegisterVisual( visualIndex, visual );
666
667   Animation anim = dummyImpl.CreateTransition( transition );
668   DALI_TEST_CHECK( !anim );
669
670   application.SendNotification();
671   application.Render(0);
672   application.SendNotification();
673
674   Renderer renderer = actor.GetRendererAt(0);
675   Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
676
677   tet_printf( "Test that the property has been set to target value\n");
678   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(mixColorIdx), Color::RED, 0.001, TEST_LOCATION);
679
680   END_TEST;
681 }
682
683
684 int UtcDaliTransitionDataArrayP(void)
685 {
686   TestApplication application;
687
688   Property::Map map1;
689   map1["target"] = "Actor1";
690   map1["property"] = "color";
691   map1["initialValue"] = Color::MAGENTA;
692   map1["targetValue"] = Color::RED;
693   map1["animator"] = Property::Map()
694     .Add("alphaFunction", "EASE_IN_OUT")
695     .Add("timePeriod", Property::Map()
696          .Add("delay", 0.5f)
697          .Add("duration", 1.0f));
698
699   Property::Map map2;
700   map2["target"] = "Actor1";
701   map2["property"] = "position";
702   map2["initialValue"] = Vector3(100,0,0);
703   map2["targetValue"] = Vector3(0,100,0);
704   map2["animator"] = Property::Map()
705     .Add("alphaFunction", "EASE_IN_OUT")
706     .Add("timePeriod", Property::Map()
707          .Add("delay", 0.0f)
708          .Add("duration", 1.0f));
709
710   Property::Map map3;
711   map3["target"] = "Actor1";
712   map3["property"] = "orientation";
713   map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
714
715   Property::Array array;
716   array.PushBack(map1);
717   array.PushBack(map2);
718   array.PushBack(map3);
719
720   Dali::Toolkit::TransitionData transition = TransitionData::New( array );
721
722   DummyControl actor = DummyControl::New();
723   actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
724   actor.SetName("Actor1");
725   actor.SetColor(Color::CYAN);
726   Stage::GetCurrent().Add(actor);
727   DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
728
729   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
730   Animation anim = dummyImpl.CreateTransition( transition );
731   DALI_TEST_CHECK( anim );
732   application.SendNotification();
733   application.Render(0);
734   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
735   DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
736   anim.Play();
737
738   application.SendNotification();
739   application.Render(0);   // start map2 anim
740   application.SendNotification();
741   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
742
743   application.Render(500); // Start map1 animation, halfway thru map2 anim
744   application.SendNotification();
745   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
746
747   application.Render(500); // Halfway thru map1 anim, end of map2 anim
748   application.SendNotification();
749   DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
750   DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
751
752   application.Render(500); // End of map1 anim
753   application.SendNotification();
754   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
755
756   END_TEST;
757 }
758
759
760 int UtcDaliTransitionDataGetAnimatorP(void)
761 {
762   TestApplication application;
763
764   Property::Map map1;
765   map1["target"] = "Actor1";
766   map1["property"] = "color";
767   map1["initialValue"] = Color::MAGENTA;
768   map1["targetValue"] = Color::RED;
769   map1["animator"] = Property::Map()
770     .Add("alphaFunction", "EASE_IN_SQUARE")
771     .Add("timePeriod", Property::Map()
772          .Add("delay", 0.5f)
773          .Add("duration", 0.5f));
774
775   Property::Map map2;
776   map2["target"] = "Actor1";
777   map2["property"] = "position";
778   map2["initialValue"] = Vector3(100,0,0);
779   map2["targetValue"] = Vector3(0,100,0);
780   map2["animator"] = Property::Map()
781     .Add("alphaFunction", "EASE_OUT_SQUARE")
782     .Add("timePeriod", Property::Map()
783          .Add("delay", 0.2f)
784          .Add("duration", 2.0f));
785
786   Property::Map map3;
787   map3["target"] = "Actor1";
788   map3["property"] = "size";
789   map3["initialValue"] = Vector2(10,10);
790   map3["targetValue"] = Vector2(100,100);
791   map3["animator"] = Property::Map()
792     .Add("alphaFunction", "EASE_OUT_SINE")
793     .Add("timePeriod", Property::Map()
794          .Add("delay", 0.4f)
795          .Add("duration", 3.0f));
796
797   Property::Map map4;
798   map4["target"] = "Actor2";
799   map4["property"] = "color";
800   map4["initialValue"] = Color::BLACK;
801   map4["targetValue"] = Color::GREEN;
802   map4["animator"] = Property::Map()
803     .Add("alphaFunction", "EASE_IN_OUT_SINE")
804     .Add("timePeriod", Property::Map()
805          .Add("delay", 0.5f)
806          .Add("duration", 0.5f));
807
808   Property::Map map5;
809   map5["target"] = "Actor2";
810   map5["property"] = "position";
811   map5["initialValue"] = Vector3(100,0,0);
812   map5["targetValue"] = Vector3(0,100,0);
813   map5["animator"] = Property::Map()
814     .Add("alphaFunction", "BOUNCE")
815     .Add("timePeriod", Property::Map()
816          .Add("delay", 0.2f)
817          .Add("duration", 2.0f));
818
819   Property::Map map6;
820   map6["target"] = "Actor2";
821   map6["property"] = "size";
822   map6["initialValue"] = Vector2(10,10);
823   map6["targetValue"] = Vector2(100,100);
824   map6["animator"] = Property::Map()
825     .Add("alphaFunction", "SIN")
826     .Add("timePeriod", Property::Map()
827          .Add("delay", 0.4f)
828          .Add("duration", 3.0f));
829
830   Property::Map map7;
831   map7["target"] = "Actor4";
832   map7["property"] = "sizeModeFactor";
833   map7["initialValue"] = Vector3(1,1,1);
834   map7["targetValue"] = Vector3(2,2,2);
835   map7["animator"] = Property::Map()
836     .Add("alphaFunction", "EASE_IN_SINE")
837     .Add("timePeriod", Property::Map()
838          .Add("delay", 0.0f)
839          .Add("duration", 1.0f));
840
841   Property::Map map8;
842   map8["target"] = "Visual1";
843   map8["property"] = "colorAlpha";
844   map8["targetValue"] = 1.0f;
845   map8["animator"] = Property::Map()
846     .Add("alphaFunction", "EASE_IN")
847     .Add("timePeriod", Property::Map()
848          .Add("delay", 0.3f)
849          .Add("duration", 9.0f));
850
851   Property::Map map9;
852   map9["target"] = "Actor2";
853   map9["property"] = "scale";
854   map9["initialValue"] = Vector3(0,0,0);
855   map9["targetValue"] = Vector3(1,1,1);
856   map9["animator"] = Property::Map()
857     .Add("alphaFunction", "REVERSE")
858     .Add("timePeriod", Property::Map()
859          .Add("delay", 0.0f)
860          .Add("duration", 1.0f));
861
862   Property::Map map10;
863   map10["target"] = "Actor2";
864   map10["property"] = "scale";
865   map10["initialValue"] = Vector3(0,0,0);
866   map10["targetValue"] = Vector3(1,1,1);
867   map10["animator"] = Property::Map()
868     .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
869     .Add("timePeriod", Property::Map()
870          .Add("delay", 0.0f)
871          .Add("duration", 1.0f));
872
873   Property::Map map11;
874   map11["target"] = "Actor2";
875   map11["property"] = "scale";
876   map11["initialValue"] = Vector3(0,0,0);
877   map11["targetValue"] = Vector3(1,1,1);
878   map11["animator"] = Property::Map()
879     .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
880     .Add("timePeriod", Property::Map()
881          .Add("delay", 0.0f)
882          .Add("duration", 1.0f));
883
884   Property::Map map12;
885   map12["target"] = "Actor1";
886   map12["property"] = "orientation";
887   map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
888
889   Property::Array array;
890   array.PushBack(map1);
891   array.PushBack(map2);
892   array.PushBack(map3);
893   array.PushBack(map4);
894   array.PushBack(map5);
895   array.PushBack(map6);
896   array.PushBack(map7);
897   array.PushBack(map8);
898   array.PushBack(map9);
899   array.PushBack(map10);
900   array.PushBack(map11);
901   array.PushBack(map12);
902
903   Dali::Toolkit::TransitionData transition = TransitionData::New( array );
904
905   DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
906
907   for( unsigned int i=0; i < array.Count(); ++i )
908   {
909     Property::Map animatorMap = transition.GetAnimatorAt(i);
910     Property::Value& value = array.GetElementAt(i);
911     Property::Map* inputMap = value.GetMap();
912     DALI_TEST_CHECK( inputMap );
913     CHECK_MAP_EQUALS( *inputMap, animatorMap );
914   }
915
916   END_TEST;
917 }