2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
23 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
24 #include "dummy-control.h"
27 using namespace Toolkit;
30 void utc_dali_toolkit_transition_data_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_transition_data_cleanup(void)
37 test_return_value = TET_PASS;
40 Property::Map CreateMap()
44 map["target"] = "Actor1";
45 map["property"] = "color";
46 map["initialValue"] = Color::MAGENTA;
47 map["targetValue"] = Color::RED;
48 map["animator"] = Property::Map()
49 .Add("alphaFunction", "EASE_IN_OUT_BACK")
50 .Add("timePeriod", Property::Map()
52 .Add("duration", 1.0f));
56 void CHECK_MAP_EQUALS( Property::Map test, Property::Map result )
58 DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
60 for( unsigned int i=0; i< test.Count(); ++i )
62 KeyValuePair keyValue = test.GetKeyValue(i);
63 Property::Value* value;
65 if( keyValue.first.type == Property::Key::STRING )
67 value = result.Find(keyValue.first.stringKey);
71 value = result.Find(keyValue.first.indexKey);
74 DALI_TEST_CHECK( value != NULL );
77 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
78 if( keyValue.second.GetType() == Property::MAP )
80 CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) );
82 else if( keyValue.second.GetType() == Property::ARRAY )
85 else if( keyValue.second.GetType() == Property::STRING )
89 DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION );
93 DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION );
100 int UtcDaliTransitionDataNew(void)
102 TestApplication application;
104 Property::Map map = CreateMap();
105 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
106 DALI_TEST_CHECK( transition );
111 int UtcDaliTransitionDataDownCast(void)
113 TestApplication application;
115 Property::Map map = CreateMap();
117 BaseHandle handle = TransitionData::New( map );
118 DALI_TEST_CHECK( handle );
120 TransitionData transitionData = TransitionData::DownCast( handle );
121 DALI_TEST_CHECK( transitionData );
125 int UtcDaliTransitionDataCopyConstructor(void)
127 TestApplication application;
129 Property::Map map = CreateMap();
131 TransitionData transitionData = TransitionData::New( map );
132 DALI_TEST_CHECK( transitionData );
134 TransitionData td2( transitionData );
135 DALI_TEST_CHECK( td2 );
136 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
140 int UtcDaliTransitionDataAssignmentOperator(void)
142 TestApplication application;
144 Property::Map map = CreateMap();
146 TransitionData transitionData = TransitionData::New( map );
147 DALI_TEST_CHECK( transitionData );
150 DALI_TEST_CHECK( !td2 );
152 td2 = transitionData;
153 DALI_TEST_CHECK( td2 );
155 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
159 int UtcDaliTransitionDataCount(void)
161 TestApplication application;
163 Property::Map map = CreateMap();
164 TransitionData transitionData = TransitionData::New( map );
165 DALI_TEST_CHECK( transitionData );
166 DALI_TEST_EQUALS( transitionData.Count(), 1, TEST_LOCATION );
168 Property::Array array;
169 array.PushBack( map );
170 array.PushBack( map );
171 array.PushBack( map );
173 TransitionData transitionData2 = TransitionData::New( array );
174 DALI_TEST_CHECK( transitionData2 );
175 DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION );
180 int UtcDaliTransitionDataMap1P(void)
182 TestApplication application;
184 tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
187 map["target"] = "visual1";
188 map["property"] = "mixColor";
189 map["initialValue"] = Color::MAGENTA;
190 map["targetValue"] = Color::RED;
191 map["animator"] = Property::Map()
192 .Add("alphaFunction", "EASE_IN_OUT")
193 .Add("timePeriod", Property::Map()
195 .Add("duration", 1.0f));
197 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
199 DummyControl actor = DummyControl::New();
200 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
201 actor.SetName("Actor1");
202 actor.SetColor(Color::CYAN);
203 Stage::GetCurrent().Add(actor);
205 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
207 Property::Map visualMap;
208 visualMap[Visual::Property::TYPE] = Visual::COLOR;
209 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
210 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
211 visual.SetName( "visual1" );
213 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
214 dummyImpl.RegisterVisual( visualIndex, actor, visual );
216 Animation anim = dummyImpl.CreateTransition( transition );
217 DALI_TEST_CHECK( anim );
219 Renderer renderer = actor.GetRendererAt(0);
220 Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
221 application.SendNotification();
222 application.Render(0);
224 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::MAGENTA, TEST_LOCATION);
228 application.SendNotification();
229 application.Render(0);
230 application.Render(500); // Start animation
231 application.Render(500); // Halfway thru anim
232 application.SendNotification();
233 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
235 application.Render(500); // End of anim
236 application.SendNotification();
237 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::RED, TEST_LOCATION );
242 int UtcDaliTransitionDataMap2P(void)
244 TestApplication application;
246 tet_printf("Testing animation of a visual property using programmatic maps\n");
249 map["target"] = "visual1";
250 //Control::CONTROL_PROPERTY_END_INDEX + 1
251 map["property"] = ColorVisual::Property::MIX_COLOR;
252 map["initialValue"] = Color::MAGENTA;
253 map["targetValue"] = Color::RED;
254 map["animator"] = Property::Map()
255 .Add("alphaFunction", "LINEAR")
256 .Add("timePeriod", Property::Map()
258 .Add("duration", 1.0f));
260 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
262 DummyControl actor = DummyControl::New();
263 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
264 actor.SetName("Actor1");
265 actor.SetColor(Color::CYAN);
266 Stage::GetCurrent().Add(actor);
268 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
270 Property::Map visualMap;
271 visualMap[Visual::Property::TYPE] = Visual::COLOR;
272 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
273 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
274 visual.SetName( "visual1" );
276 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
277 dummyImpl.RegisterVisual( visualIndex, actor, visual );
279 Animation anim = dummyImpl.CreateTransition( transition );
280 DALI_TEST_CHECK( anim );
282 Renderer renderer = actor.GetRendererAt(0);
283 Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
284 application.SendNotification();
285 application.Render(0);
287 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::MAGENTA, TEST_LOCATION);
291 application.SendNotification();
292 application.Render(0);
293 application.Render(500); // Start animation
294 application.Render(500); // Halfway thru anim
295 application.SendNotification();
296 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
298 application.Render(500); // End of anim
299 application.SendNotification();
300 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(mixColorIndex), Color::RED, TEST_LOCATION );
306 int UtcDaliTransitionDataMapP3(void)
308 TestApplication application;
310 tet_printf("Testing animation of a visual's placement actor property\n");
313 map["target"] = "visual1";
314 map["property"] = "color";
315 map["initialValue"] = Color::MAGENTA;
316 map["targetValue"] = Color::RED;
317 map["animator"] = Property::Map()
318 .Add("alphaFunction", "EASE_IN_OUT")
319 .Add("timePeriod", Property::Map()
321 .Add("duration", 1.0f));
323 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
325 DummyControl actor = DummyControl::New();
326 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
327 actor.SetName("Actor1");
328 actor.SetColor(Color::CYAN);
329 Stage::GetCurrent().Add(actor);
331 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
333 Property::Map visualMap;
334 visualMap[Visual::Property::TYPE] = Visual::COLOR;
335 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
336 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
337 visual.SetName( "visual1" );
339 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
340 dummyImpl.RegisterVisual( visualIndex, actor, visual );
342 Animation anim = dummyImpl.CreateTransition( transition );
343 DALI_TEST_CHECK( anim );
345 application.SendNotification();
346 application.Render(0);
347 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
351 application.SendNotification();
352 application.Render(0);
353 application.Render(500);
354 application.Render(500); // Halfway thru map1 anim
355 application.SendNotification();
356 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
358 application.Render(500); // End of map1 anim
359 application.SendNotification();
360 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
364 int UtcDaliTransitionDataMap1N(void)
366 TestApplication application;
369 map["target"] = "Actor1";
370 map["property"] = "randomProperty";
371 map["initialValue"] = Color::MAGENTA;
372 map["targetValue"] = Color::RED;
373 map["animator"] = Property::Map()
374 .Add("alphaFunction", "EASE_OUT")
375 .Add("timePeriod", Property::Map()
377 .Add("duration", 1.0f));
379 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
381 DummyControl actor = DummyControl::New();
382 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
383 actor.SetName("Actor1");
384 actor.SetColor(Color::CYAN);
385 Stage::GetCurrent().Add(actor);
387 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
388 Animation anim = dummyImpl.CreateTransition( transition );
389 DALI_TEST_CHECK( ! anim );
391 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
396 int UtcDaliTransitionDataMapN3(void)
398 TestApplication application;
400 tet_printf("Testing visual lookup with no renderers\n");
403 map["target"] = "visual1";
404 map["property"] = "mixColor";
405 map["initialValue"] = Color::MAGENTA;
406 map["targetValue"] = Color::RED;
407 map["animator"] = Property::Map()
408 .Add("alphaFunction", "EASE_OUT_BACK")
409 .Add("timePeriod", Property::Map()
411 .Add("duration", 1.0f));
413 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
414 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
416 DummyControl actor = DummyControl::New();
417 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
418 actor.SetName("Actor1");
419 actor.SetColor(Color::CYAN);
422 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
423 Property::Map visualMap;
424 visualMap[Visual::Property::TYPE] = Visual::COLOR;
425 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
426 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
427 visual.SetName( "visual1" );
429 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
430 dummyImpl.RegisterVisual( visualIndex, actor, visual );
432 Animation anim = dummyImpl.CreateTransition( transition );
433 DALI_TEST_CHECK( !anim );
437 int UtcDaliTransitionDataArrayP(void)
439 TestApplication application;
442 map1["target"] = "Actor1";
443 map1["property"] = "color";
444 map1["initialValue"] = Color::MAGENTA;
445 map1["targetValue"] = Color::RED;
446 map1["animator"] = Property::Map()
447 .Add("alphaFunction", "EASE_IN_OUT")
448 .Add("timePeriod", Property::Map()
450 .Add("duration", 1.0f));
453 map2["target"] = "Actor1";
454 map2["property"] = "position";
455 map2["initialValue"] = Vector3(100,0,0);
456 map2["targetValue"] = Vector3(0,100,0);
457 map2["animator"] = Property::Map()
458 .Add("alphaFunction", "EASE_IN_OUT")
459 .Add("timePeriod", Property::Map()
461 .Add("duration", 1.0f));
464 map3["target"] = "Actor1";
465 map3["property"] = "orientation";
466 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
468 Property::Array array;
469 array.PushBack(map1);
470 array.PushBack(map2);
471 array.PushBack(map3);
473 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
475 DummyControl actor = DummyControl::New();
476 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
477 actor.SetName("Actor1");
478 actor.SetColor(Color::CYAN);
479 Stage::GetCurrent().Add(actor);
480 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
482 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
483 Animation anim = dummyImpl.CreateTransition( transition );
484 DALI_TEST_CHECK( anim );
485 application.SendNotification();
486 application.Render(0);
487 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
488 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
491 application.SendNotification();
492 application.Render(0); // start map2 anim
493 application.SendNotification();
494 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
496 application.Render(500); // Start map1 animation, halfway thru map2 anim
497 application.SendNotification();
498 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
500 application.Render(500); // Halfway thru map1 anim, end of map2 anim
501 application.SendNotification();
502 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
503 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
505 application.Render(500); // End of map1 anim
506 application.SendNotification();
507 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
513 int UtcDaliTransitionDataGetAnimatorP(void)
515 TestApplication application;
518 map1["target"] = "Actor1";
519 map1["property"] = "color";
520 map1["initialValue"] = Color::MAGENTA;
521 map1["targetValue"] = Color::RED;
522 map1["animator"] = Property::Map()
523 .Add("alphaFunction", "EASE_IN_SQUARE")
524 .Add("timePeriod", Property::Map()
526 .Add("duration", 0.5f));
529 map2["target"] = "Actor1";
530 map2["property"] = "position";
531 map2["initialValue"] = Vector3(100,0,0);
532 map2["targetValue"] = Vector3(0,100,0);
533 map2["animator"] = Property::Map()
534 .Add("alphaFunction", "EASE_OUT_SQUARE")
535 .Add("timePeriod", Property::Map()
537 .Add("duration", 2.0f));
540 map3["target"] = "Actor1";
541 map3["property"] = "size";
542 map3["initialValue"] = Vector2(10,10);
543 map3["targetValue"] = Vector2(100,100);
544 map3["animator"] = Property::Map()
545 .Add("alphaFunction", "EASE_OUT_SINE")
546 .Add("timePeriod", Property::Map()
548 .Add("duration", 3.0f));
551 map4["target"] = "Actor2";
552 map4["property"] = "color";
553 map4["initialValue"] = Color::BLACK;
554 map4["targetValue"] = Color::GREEN;
555 map4["animator"] = Property::Map()
556 .Add("alphaFunction", "EASE_IN_OUT_SINE")
557 .Add("timePeriod", Property::Map()
559 .Add("duration", 0.5f));
562 map5["target"] = "Actor2";
563 map5["property"] = "position";
564 map5["initialValue"] = Vector3(100,0,0);
565 map5["targetValue"] = Vector3(0,100,0);
566 map5["animator"] = Property::Map()
567 .Add("alphaFunction", "BOUNCE")
568 .Add("timePeriod", Property::Map()
570 .Add("duration", 2.0f));
573 map6["target"] = "Actor2";
574 map6["property"] = "size";
575 map6["initialValue"] = Vector2(10,10);
576 map6["targetValue"] = Vector2(100,100);
577 map6["animator"] = Property::Map()
578 .Add("alphaFunction", "SIN")
579 .Add("timePeriod", Property::Map()
581 .Add("duration", 3.0f));
584 map7["target"] = "Actor4";
585 map7["property"] = "sizeModeFactor";
586 map7["initialValue"] = Vector3(1,1,1);
587 map7["targetValue"] = Vector3(2,2,2);
588 map7["animator"] = Property::Map()
589 .Add("alphaFunction", "EASE_IN_SINE")
590 .Add("timePeriod", Property::Map()
592 .Add("duration", 1.0f));
595 map8["target"] = "Visual1";
596 map8["property"] = "colorAlpha";
597 map8["targetValue"] = 1.0f;
598 map8["animator"] = Property::Map()
599 .Add("alphaFunction", "EASE_IN")
600 .Add("timePeriod", Property::Map()
602 .Add("duration", 9.0f));
605 map9["target"] = "Actor2";
606 map9["property"] = "scale";
607 map9["initialValue"] = Vector3(0,0,0);
608 map9["targetValue"] = Vector3(1,1,1);
609 map9["animator"] = Property::Map()
610 .Add("alphaFunction", "REVERSE")
611 .Add("timePeriod", Property::Map()
613 .Add("duration", 1.0f));
616 map10["target"] = "Actor1";
617 map10["property"] = "orientation";
618 map10["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
620 Property::Array array;
621 array.PushBack(map1);
622 array.PushBack(map2);
623 array.PushBack(map3);
624 array.PushBack(map4);
625 array.PushBack(map5);
626 array.PushBack(map6);
627 array.PushBack(map7);
628 array.PushBack(map8);
629 array.PushBack(map9);
630 array.PushBack(map10);
632 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
634 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
636 for( unsigned int i=0; i < array.Count(); ++i )
638 Property::Map animatorMap = transition.GetAnimatorAt(i);
639 Property::Value& value = array.GetElementAt(i);
640 Property::Map* inputMap = value.GetMap();
641 DALI_TEST_CHECK( inputMap );
642 CHECK_MAP_EQUALS( *inputMap, animatorMap );