2 * Copyright (c) 2017 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/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"
28 using namespace Toolkit;
31 void utc_dali_toolkit_transition_data_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_transition_data_cleanup(void)
38 test_return_value = TET_PASS;
41 Property::Map CreateMap()
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()
53 .Add("duration", 1.0f));
57 void CHECK_ARRAY_EQUALS( Property::Array test, Property::Value result )
59 if( result.GetType() == Property::ARRAY )
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 )
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 );
72 else if( result.GetType() == Property::VECTOR4 )
74 Vector4 value = result.Get<Vector4>();
75 DALI_TEST_CHECK( test.Count() >= 4 );
76 for( size_t i=0; i < 4; ++i )
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 );
89 void CHECK_MAP_EQUALS( Property::Map test, Property::Map result )
91 DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
93 for( unsigned int i=0; i< test.Count(); ++i )
95 KeyValuePair keyValue = test.GetKeyValue(i);
96 Property::Value* value;
98 if( keyValue.first.type == Property::Key::STRING )
100 value = result.Find(keyValue.first.stringKey);
104 value = result.Find(keyValue.first.indexKey);
107 DALI_TEST_CHECK( value != NULL );
110 if( keyValue.second.GetType() == Property::MAP )
112 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
113 CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) );
115 else if( keyValue.second.GetType() == Property::ARRAY )
117 CHECK_ARRAY_EQUALS( *(keyValue.second.GetArray()), *value );
119 else if( keyValue.second.GetType() == Property::STRING )
121 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
124 DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION );
128 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
129 DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION );
136 int UtcDaliTransitionDataNew(void)
138 TestApplication application;
140 Property::Map map = CreateMap();
141 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
142 DALI_TEST_CHECK( transition );
147 int UtcDaliTransitionDataDownCast(void)
149 TestApplication application;
151 Property::Map map = CreateMap();
153 BaseHandle handle = TransitionData::New( map );
154 DALI_TEST_CHECK( handle );
156 TransitionData transitionData = TransitionData::DownCast( handle );
157 DALI_TEST_CHECK( transitionData );
161 int UtcDaliTransitionDataCopyConstructor(void)
163 TestApplication application;
165 Property::Map map = CreateMap();
167 TransitionData transitionData = TransitionData::New( map );
168 DALI_TEST_CHECK( transitionData );
170 TransitionData td2( transitionData );
171 DALI_TEST_CHECK( td2 );
172 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
176 int UtcDaliTransitionDataAssignmentOperator(void)
178 TestApplication application;
180 Property::Map map = CreateMap();
182 TransitionData transitionData = TransitionData::New( map );
183 DALI_TEST_CHECK( transitionData );
186 DALI_TEST_CHECK( !td2 );
188 td2 = transitionData;
189 DALI_TEST_CHECK( td2 );
191 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
195 int UtcDaliTransitionDataCount(void)
197 TestApplication application;
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 );
204 Property::Array array;
205 array.PushBack( map );
206 array.PushBack( map );
207 array.PushBack( map );
209 TransitionData transitionData2 = TransitionData::New( array );
210 DALI_TEST_CHECK( transitionData2 );
211 DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION );
216 int UtcDaliTransitionDataMap1P(void)
218 TestApplication application;
220 tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
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()
231 .Add("duration", 1.0f));
233 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
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);
241 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
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" );
249 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
250 dummyImpl.RegisterVisual( visualIndex, visual );
252 Animation anim = dummyImpl.CreateTransition( transition );
253 DALI_TEST_CHECK( anim );
255 Renderer renderer = actor.GetRendererAt(0);
256 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
257 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
258 application.SendNotification();
259 application.Render(0);
261 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
262 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
263 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
264 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
268 application.SendNotification();
269 application.Render(500); // Start animation
270 application.Render(500); // Halfway thru anim
271 application.SendNotification();
272 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
273 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
275 application.Render(500); // End of anim
276 application.SendNotification();
277 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
278 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
285 int UtcDaliTransitionDataMap2P(void)
287 TestApplication application;
289 tet_printf("Testing animation of a visual property using programmatic maps\n");
292 map["target"] = "visual1";
293 map["property"] = ColorVisual::Property::MIX_COLOR;
294 map["initialValue"] = Color::MAGENTA;
295 map["targetValue"] = Color::RED;
296 map["animator"] = Property::Map()
297 .Add("alphaFunction", "LINEAR")
298 .Add("timePeriod", Property::Map()
300 .Add("duration", 1.0f));
302 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
304 DummyControl actor = DummyControl::New();
305 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
306 actor.SetName("Actor1");
307 actor.SetColor(Color::CYAN);
308 Stage::GetCurrent().Add(actor);
310 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
312 Property::Map visualMap;
313 visualMap[Visual::Property::TYPE] = Visual::COLOR;
314 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
315 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
316 visual.SetName( "visual1" );
318 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
319 dummyImpl.RegisterVisual( visualIndex, visual );
321 Animation anim = dummyImpl.CreateTransition( transition );
322 DALI_TEST_CHECK( anim );
324 Renderer renderer = actor.GetRendererAt(0);
325 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
326 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
327 application.SendNotification();
328 application.Render(0);
330 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
331 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
332 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
333 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
337 application.SendNotification();
338 application.Render(0);
339 application.Render(500); // Start animation
340 application.Render(500); // Halfway thru anim
341 application.SendNotification();
342 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
343 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
345 application.Render(500); // End of anim
346 application.SendNotification();
347 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
348 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
354 int UtcDaliTransitionDataMap2Pb(void)
356 TestApplication application;
358 tet_printf("Testing animation of a visual property using programmatic maps\n");
361 map["target"] = "visual1";
362 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
363 map["initialValue"] = Color::MAGENTA;
364 map["targetValue"] = Color::RED;
365 map["animator"] = Property::Map()
366 .Add("alphaFunction", "LINEAR")
367 .Add("timePeriod", Property::Map()
369 .Add("duration", 1.0f));
371 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
373 DummyControl actor = DummyControl::New();
374 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
375 actor.SetName("Actor1");
376 actor.SetColor(Color::CYAN);
377 Stage::GetCurrent().Add(actor);
379 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
381 Property::Map visualMap;
382 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
383 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
384 visualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
385 visualMap[ PrimitiveVisual::Property::SLICES ] = 10;
386 visualMap[ PrimitiveVisual::Property::STACKS ] = 10;
388 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
389 visual.SetName( "visual1" );
391 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
392 dummyImpl.RegisterVisual( visualIndex, visual );
394 Animation anim = dummyImpl.CreateTransition( transition );
395 DALI_TEST_CHECK( anim );
397 Renderer renderer = actor.GetRendererAt(0);
398 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, PrimitiveVisual::Property::MIX_COLOR );
399 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
400 application.SendNotification();
401 application.Render(0);
403 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
404 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
405 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
406 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
410 application.SendNotification();
411 application.Render(0);
412 application.Render(500); // Start animation
413 application.Render(500); // Halfway thru anim
414 application.SendNotification();
415 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
416 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
418 application.Render(500); // End of anim
419 application.SendNotification();
420 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
421 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
427 int UtcDaliTransitionDataMap3P(void)
429 TestApplication application;
431 tet_printf("Testing animation of an actor's position property using bezier curve\n");
434 map["target"] = "Actor1";
435 map["property"] = "position";
436 map["initialValue"] = Vector3(0, 0, 0);
437 map["targetValue"] = Vector3(100, 100, 0);
438 map["animator"] = Property::Map()
439 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
440 .Add("timePeriod", Property::Map()
442 .Add("duration", 1.0f));
444 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
446 DummyControl actor = DummyControl::New();
447 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
448 actor.SetName("Actor1");
449 Stage::GetCurrent().Add(actor);
451 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
452 Animation anim = dummyImpl.CreateTransition( transition );
453 DALI_TEST_CHECK( anim );
455 application.SendNotification();
456 application.Render(0);
457 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
461 application.SendNotification();
462 application.Render(0);
464 application.Render(250); // 25%
465 application.SendNotification();
466 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%
468 application.Render(250); // Halfway thru map1 anim
469 application.SendNotification();
470 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%
472 application.Render(250); // End of map1 anim
473 application.SendNotification();
474 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
476 application.Render(250); // End of map1 anim
477 application.SendNotification();
478 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
483 int UtcDaliTransitionDataMap4P(void)
485 TestApplication application;
487 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
490 map1["target"] = "testVisual";
491 map1["property"] = "offset";
492 map1["initialValue"] = Vector2(0.0f, 0.0f);
493 map1["targetValue"] = Vector2(100.0f, 100.0f);
494 map1["animator"] = Property::Map()
495 .Add("alphaFunction", "LINEAR")
496 .Add("timePeriod", Property::Map()
498 .Add("duration", 1.0f));
501 map2["target"] = "testVisual";
502 map2["property"] = "size";
503 map2["initialValue"] = Vector2(10.0f, 10.0f);
504 map2["targetValue"] = Vector2(110.0f, 110.0f);
505 map2["animator"] = Property::Map()
506 .Add("alphaFunction", "LINEAR")
507 .Add("timePeriod", Property::Map()
509 .Add("duration", 1.0f));
511 Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) );
513 DummyControl actor = DummyControl::New();
514 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
515 actor.SetName("Actor1");
516 Stage::GetCurrent().Add(actor);
518 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
520 Property::Map visualMap;
521 visualMap[Visual::Property::TYPE] = Visual::COLOR;
522 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
523 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
525 visual.SetName( "testVisual" );
526 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
528 Animation anim = dummyImpl.CreateTransition( transition );
529 DALI_TEST_CHECK( anim );
531 Renderer renderer = actor.GetRendererAt(0);
532 Property::Index sizeIndex = renderer.GetPropertyIndex( "size" );
533 application.SendNotification();
534 application.Render(0);
536 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
537 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(10.0f, 10.0f), TEST_LOCATION);
541 application.SendNotification();
542 application.Render(0);
543 application.Render(500); // Start animation
544 application.Render(500); // Halfway thru anim
545 application.SendNotification();
546 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(60.0f, 60.0f), TEST_LOCATION);
548 application.Render(500); // End of anim
549 application.SendNotification();
550 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(110.0f, 110.0f), TEST_LOCATION );
555 int UtcDaliTransitionDataMap5P(void)
557 TestApplication application;
559 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
562 map["target"] = "visual1";
563 map["property"] = "opacity";
564 map["initialValue"] = 0.0f;
565 map["targetValue"] = 1.0f;
566 map["animator"] = Property::Map()
567 .Add("alphaFunction", "EASE_IN_OUT")
568 .Add("timePeriod", Property::Map()
570 .Add("duration", 1.0f));
572 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
574 DummyControl actor = DummyControl::New();
575 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
576 actor.SetName("Actor1");
577 actor.SetColor(Color::CYAN);
578 Stage::GetCurrent().Add(actor);
580 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
582 Property::Map visualMap;
583 visualMap[Visual::Property::TYPE] = Visual::COLOR;
584 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
585 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
586 visual.SetName( "visual1" );
588 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
589 dummyImpl.RegisterVisual( visualIndex, visual );
591 Animation anim = dummyImpl.CreateTransition( transition );
592 DALI_TEST_CHECK( anim );
594 Renderer renderer = actor.GetRendererAt(0);
595 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
596 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
597 application.SendNotification();
598 application.Render(0);
600 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
601 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.0f, 0.001f, TEST_LOCATION );
602 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
604 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
605 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.0f, 0.001f, TEST_LOCATION );
606 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
610 application.SendNotification();
611 application.Render(500); // Start animation
612 application.Render(500); // Halfway thru anim
613 application.SendNotification();
614 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
615 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.5f, 0.001f, TEST_LOCATION );
616 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
618 application.Render(501); // End of anim
619 application.SendNotification();
620 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
621 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
622 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::AUTO, TEST_LOCATION );
628 int UtcDaliTransitionDataMap6P(void)
630 TestApplication application;
632 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
635 map["target"] = "visual1";
636 map["property"] = "opacity";
637 map["targetValue"] = 0.0f;
638 map["animator"] = Property::Map()
639 .Add("alphaFunction", "EASE_IN_OUT")
640 .Add("timePeriod", Property::Map()
642 .Add("duration", 1.0f));
644 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
646 DummyControl actor = DummyControl::New();
647 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
648 actor.SetName("Actor1");
649 actor.SetColor(Color::CYAN);
650 Stage::GetCurrent().Add(actor);
652 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
654 Property::Map visualMap;
655 visualMap[Visual::Property::TYPE] = Visual::COLOR;
656 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
657 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
658 visual.SetName( "visual1" );
660 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
661 dummyImpl.RegisterVisual( visualIndex, visual );
663 Animation anim = dummyImpl.CreateTransition( transition );
664 DALI_TEST_CHECK( anim );
666 Renderer renderer = actor.GetRendererAt(0);
667 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
668 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
669 application.SendNotification();
670 application.Render(0);
672 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
673 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
674 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
675 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
677 // Note, This should be testing for AUTO
678 // this is the same problem as C# target value being set before Play is called.
679 // @todo How was this solved?
680 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
681 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
685 application.SendNotification();
686 application.Render(500); // Start animation
687 application.Render(500); // Halfway thru anim
688 application.SendNotification();
689 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
690 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.5f, 0.001f, TEST_LOCATION );
691 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
693 application.Render(500); // End of anim
694 application.SendNotification();
695 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
696 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.0f, 0.001f, TEST_LOCATION );
697 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
703 int UtcDaliTransitionDataMap1N(void)
705 TestApplication application;
708 map["target"] = "Actor1";
709 map["property"] = "randomProperty";
710 map["initialValue"] = Color::MAGENTA;
711 map["targetValue"] = Color::RED;
712 map["animator"] = Property::Map()
713 .Add("alphaFunction", "EASE_OUT")
714 .Add("timePeriod", Property::Map()
716 .Add("duration", 1.0f));
718 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
720 DummyControl actor = DummyControl::New();
721 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
722 actor.SetName("Actor1");
723 actor.SetColor(Color::CYAN);
724 Stage::GetCurrent().Add(actor);
726 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
727 Animation anim = dummyImpl.CreateTransition( transition );
728 DALI_TEST_CHECK( ! anim );
730 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
735 int UtcDaliTransitionDataMapN3(void)
737 TestApplication application;
739 tet_printf("Testing visual lookup with no renderers\n");
742 map["target"] = "visual1";
743 map["property"] = "mixColor";
744 map["initialValue"] = Vector3(Color::MAGENTA);
745 map["targetValue"] = Vector3(Color::RED);
746 map["animator"] = Property::Map()
747 .Add("alphaFunction", "EASE_OUT_BACK")
748 .Add("timePeriod", Property::Map()
750 .Add("duration", 1.0f));
752 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
753 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
755 DummyControl actor = DummyControl::New();
756 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
757 actor.SetName("Actor1");
758 actor.SetColor(Color::CYAN);
761 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
762 Property::Map visualMap;
763 visualMap[Visual::Property::TYPE] = Visual::COLOR;
764 visualMap[ColorVisual::Property::MIX_COLOR] = Vector3(Color::MAGENTA);
765 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
766 visual.SetName( "visual1" );
768 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
769 dummyImpl.RegisterVisual( visualIndex, visual );
771 Animation anim = dummyImpl.CreateTransition( transition );
772 DALI_TEST_CHECK( !anim );
777 int UtcDaliTransitionDataMapN4(void)
779 TestApplication application;
781 tet_printf("Testing visual doesn't animate with duff bezier data \n");
784 map["target"] = "visual1";
785 map["property"] = "mixColor";
786 map["initialValue"] = Vector3(Color::MAGENTA);
787 map["targetValue"] = Vector3(Color::RED);
788 map["animator"] = Property::Map()
789 .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
790 .Add("timePeriod", Property::Map()
792 .Add("duration", 1.0f));
794 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
796 DummyControl actor = DummyControl::New();
797 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
798 actor.SetName("Actor1");
799 actor.SetColor(Color::CYAN);
800 Stage::GetCurrent().Add(actor);
802 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
803 Property::Map visualMap;
804 visualMap[Visual::Property::TYPE] = Visual::COLOR;
805 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
806 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
807 visual.SetName( "visual1" );
809 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
810 dummyImpl.RegisterVisual( visualIndex, visual );
812 Animation anim = dummyImpl.CreateTransition( transition );
813 DALI_TEST_CHECK( !anim );
815 application.SendNotification();
816 application.Render(0);
817 application.SendNotification();
819 Renderer renderer = actor.GetRendererAt(0);
820 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
821 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
823 tet_printf( "Test that the property has been set to target value\n");
824 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
825 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
830 int UtcDaliTransitionDataMapN5(void)
832 TestApplication application;
834 tet_printf("Testing visual doesn't animate with duff bezier data \n");
837 map["target"] = "visual1";
838 map["property"] = "mixColor";
839 map["initialValue"] = Color::MAGENTA;
840 map["targetValue"] = Color::RED;
841 map["animator"] = Property::Map()
842 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
843 .Add("timePeriod", Property::Map()
845 .Add("duration", 1.0f));
847 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
849 DummyControl actor = DummyControl::New();
850 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
851 actor.SetName("Actor1");
852 actor.SetColor(Color::CYAN);
853 Stage::GetCurrent().Add(actor);
855 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
856 Property::Map visualMap;
857 visualMap[Visual::Property::TYPE] = Visual::COLOR;
858 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
859 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
860 visual.SetName( "visual1" );
862 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
863 dummyImpl.RegisterVisual( visualIndex, visual );
865 Animation anim = dummyImpl.CreateTransition( transition );
866 DALI_TEST_CHECK( !anim );
868 application.SendNotification();
869 application.Render(0);
870 application.SendNotification();
872 Renderer renderer = actor.GetRendererAt(0);
873 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
875 tet_printf( "Test that the property has been set to target value\n");
876 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
881 int UtcDaliTransitionDataMapN6(void)
883 TestApplication application;
885 tet_printf("Testing visual doesn't animate with duff bezier data \n");
888 map["target"] = "visual1";
889 map["property"] = "mixColor";
890 map["initialValue"] = Color::MAGENTA;
891 map["targetValue"] = Color::RED;
892 map["animator"] = Property::Map()
893 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
894 .Add("timePeriod", Property::Map()
896 .Add("duration", 1.0f));
898 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
900 DummyControl actor = DummyControl::New();
901 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
902 actor.SetName("Actor1");
903 actor.SetColor(Color::CYAN);
904 Stage::GetCurrent().Add(actor);
906 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
907 Property::Map visualMap;
908 visualMap[Visual::Property::TYPE] = Visual::COLOR;
909 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
910 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
911 visual.SetName( "visual1" );
913 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
914 dummyImpl.RegisterVisual( visualIndex, visual );
916 Animation anim = dummyImpl.CreateTransition( transition );
917 DALI_TEST_CHECK( !anim );
919 application.SendNotification();
920 application.Render(0);
921 application.SendNotification();
923 Renderer renderer = actor.GetRendererAt(0);
924 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
925 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, Visual::Property::OPACITY );
927 tet_printf( "Test that the property has been set to target value\n");
928 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
929 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
935 int UtcDaliTransitionDataArrayP(void)
937 TestApplication application;
940 map1["target"] = "Actor1";
941 map1["property"] = "color";
942 map1["initialValue"] = Color::MAGENTA;
943 map1["targetValue"] = Color::RED;
944 map1["animator"] = Property::Map()
945 .Add("alphaFunction", "EASE_IN_OUT")
946 .Add("timePeriod", Property::Map()
948 .Add("duration", 1.0f));
951 map2["target"] = "Actor1";
952 map2["property"] = "position";
953 map2["initialValue"] = Vector3(100,0,0);
954 map2["targetValue"] = Vector3(0,100,0);
955 map2["animator"] = Property::Map()
956 .Add("alphaFunction", "EASE_IN_OUT")
957 .Add("timePeriod", Property::Map()
959 .Add("duration", 1.0f));
962 map3["target"] = "Actor1";
963 map3["property"] = "orientation";
964 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
966 Property::Array array;
967 array.PushBack(map1);
968 array.PushBack(map2);
969 array.PushBack(map3);
971 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
973 DummyControl actor = DummyControl::New();
974 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
975 actor.SetName("Actor1");
976 actor.SetColor(Color::CYAN);
977 Stage::GetCurrent().Add(actor);
978 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
980 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
981 Animation anim = dummyImpl.CreateTransition( transition );
982 DALI_TEST_CHECK( anim );
983 application.SendNotification();
984 application.Render(0);
985 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
986 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
989 application.SendNotification();
990 application.Render(0); // start map2 anim
991 application.SendNotification();
992 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
994 application.Render(500); // Start map1 animation, halfway thru map2 anim
995 application.SendNotification();
996 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
998 application.Render(500); // Halfway thru map1 anim, end of map2 anim
999 application.SendNotification();
1000 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
1001 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
1003 application.Render(500); // End of map1 anim
1004 application.SendNotification();
1005 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
1011 int UtcDaliTransitionDataGetAnimatorP(void)
1013 TestApplication application;
1016 map1["target"] = "Actor1";
1017 map1["property"] = "color";
1018 map1["initialValue"] = Color::MAGENTA;
1019 map1["targetValue"] = Color::RED;
1020 map1["animator"] = Property::Map()
1021 .Add("alphaFunction", "EASE_IN_SQUARE")
1022 .Add("timePeriod", Property::Map()
1024 .Add("duration", 0.5f));
1027 map2["target"] = "Actor1";
1028 map2["property"] = "position";
1029 map2["initialValue"] = Vector3(100,0,0);
1030 map2["targetValue"] = Vector3(0,100,0);
1031 map2["animator"] = Property::Map()
1032 .Add("alphaFunction", "EASE_OUT_SQUARE")
1033 .Add("timePeriod", Property::Map()
1035 .Add("duration", 2.0f));
1038 map3["target"] = "Actor1";
1039 map3["property"] = "size";
1040 map3["initialValue"] = Vector2(10,10);
1041 map3["targetValue"] = Vector2(100,100);
1042 map3["animator"] = Property::Map()
1043 .Add("alphaFunction", "EASE_OUT_SINE")
1044 .Add("timePeriod", Property::Map()
1046 .Add("duration", 3.0f));
1049 map4["target"] = "Actor2";
1050 map4["property"] = "color";
1051 map4["initialValue"] = Color::BLACK;
1052 map4["targetValue"] = Color::GREEN;
1053 map4["animator"] = Property::Map()
1054 .Add("alphaFunction", "EASE_IN_OUT_SINE")
1055 .Add("timePeriod", Property::Map()
1057 .Add("duration", 0.5f));
1060 map5["target"] = "Actor2";
1061 map5["property"] = "position";
1062 map5["initialValue"] = Vector3(100,0,0);
1063 map5["targetValue"] = Vector3(0,100,0);
1064 map5["animator"] = Property::Map()
1065 .Add("alphaFunction", "BOUNCE")
1066 .Add("timePeriod", Property::Map()
1068 .Add("duration", 2.0f));
1071 map6["target"] = "Actor2";
1072 map6["property"] = "size";
1073 map6["initialValue"] = Vector2(10,10);
1074 map6["targetValue"] = Vector2(100,100);
1075 map6["animator"] = Property::Map()
1076 .Add("alphaFunction", "SIN")
1077 .Add("timePeriod", Property::Map()
1079 .Add("duration", 3.0f));
1082 map7["target"] = "Actor4";
1083 map7["property"] = "sizeModeFactor";
1084 map7["initialValue"] = Vector3(1,1,1);
1085 map7["targetValue"] = Vector3(2,2,2);
1086 map7["animator"] = Property::Map()
1087 .Add("alphaFunction", "EASE_IN_SINE")
1088 .Add("timePeriod", Property::Map()
1090 .Add("duration", 1.0f));
1093 map8["target"] = "Visual1";
1094 map8["property"] = "opacity";
1095 map8["initialValue"] = 0.0f;
1096 map8["targetValue"] = 1.0f;
1097 map8["animator"] = Property::Map()
1098 .Add("alphaFunction", "EASE_IN")
1099 .Add("timePeriod", Property::Map()
1101 .Add("duration", 9.0f));
1104 map9["target"] = "Actor2";
1105 map9["property"] = "scale";
1106 map9["initialValue"] = Vector3(0,0,0);
1107 map9["targetValue"] = Vector3(1,1,1);
1108 map9["animator"] = Property::Map()
1109 .Add("alphaFunction", "REVERSE")
1110 .Add("timePeriod", Property::Map()
1112 .Add("duration", 1.0f));
1114 Property::Map map10;
1115 map10["target"] = "Actor2";
1116 map10["property"] = "scale";
1117 map10["initialValue"] = Vector3(0,0,0);
1118 map10["targetValue"] = Vector3(1,1,1);
1119 map10["animator"] = Property::Map()
1120 .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
1121 .Add("timePeriod", Property::Map()
1123 .Add("duration", 1.0f));
1125 Property::Map map11;
1126 map11["target"] = "Actor2";
1127 map11["property"] = "scale";
1128 map11["initialValue"] = Vector3(0,0,0);
1129 map11["targetValue"] = Vector3(1,1,1);
1130 map11["animator"] = Property::Map()
1131 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1132 .Add("timePeriod", Property::Map()
1134 .Add("duration", 1.0f));
1136 Property::Map map12;
1137 map12["target"] = "Actor1";
1138 map12["property"] = "orientation";
1139 map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
1141 Property::Array array;
1142 array.PushBack(map1);
1143 array.PushBack(map2);
1144 array.PushBack(map3);
1145 array.PushBack(map4);
1146 array.PushBack(map5);
1147 array.PushBack(map6);
1148 array.PushBack(map7);
1149 array.PushBack(map8);
1150 array.PushBack(map9);
1151 array.PushBack(map10);
1152 array.PushBack(map11);
1153 array.PushBack(map12);
1155 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1157 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
1159 for( unsigned int i=0; i < array.Count(); ++i )
1161 Property::Map animatorMap = transition.GetAnimatorAt(i);
1162 Property::Value& value = array.GetElementAt(i);
1163 Property::Map* inputMap = value.GetMap();
1164 DALI_TEST_CHECK( inputMap );
1165 CHECK_MAP_EQUALS( *inputMap, animatorMap );