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