2 * Copyright (c) 2019 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/devel-api/rendering/renderer-devel.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
26 #include "dummy-control.h"
29 using namespace Toolkit;
32 void utc_dali_toolkit_transition_data_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_transition_data_cleanup(void)
39 test_return_value = TET_PASS;
42 Property::Map CreateMap()
46 map["target"] = "Actor1";
47 map["property"] = "color";
48 map["initialValue"] = Color::MAGENTA;
49 map["targetValue"] = Color::RED;
50 map["animator"] = Property::Map()
51 .Add("alphaFunction", "EASE_IN_OUT_BACK")
52 .Add("timePeriod", Property::Map()
54 .Add("duration", 1.0f));
58 void CHECK_ARRAY_EQUALS( Property::Array test, Property::Value result )
60 if( result.GetType() == Property::ARRAY )
63 Property::Array *resultArray = result.GetArray();
64 DALI_TEST_EQUALS( test.Count(), resultArray->Count(), TEST_LOCATION );
65 for( size_t i=0; i < std::min(test.Count(), resultArray->Count()); ++i )
67 Property::Value a = test.GetElementAt(i);
68 Property::Value b = resultArray->GetElementAt(i);
69 DALI_TEST_EQUALS( a.GetType(), b.GetType(), TEST_LOCATION );
70 DALI_TEST_EQUALS( a, b, 0.001, TEST_LOCATION );
73 else if( result.GetType() == Property::VECTOR4 )
75 Vector4 value = result.Get<Vector4>();
76 DALI_TEST_CHECK( test.Count() >= 4 );
77 for( size_t i=0; i < 4; ++i )
79 Property::Value a = test.GetElementAt(i);
80 DALI_TEST_EQUALS( a.GetType(), Property::FLOAT, TEST_LOCATION );
81 DALI_TEST_EQUALS( a.Get<float>(), value[i], 0.001, TEST_LOCATION );
90 void CHECK_MAP_EQUALS( Property::Map test, Property::Map result )
92 DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
94 for( unsigned int i=0; i< test.Count(); ++i )
96 KeyValuePair keyValue = test.GetKeyValue(i);
97 Property::Value* value;
99 if( keyValue.first.type == Property::Key::STRING )
101 value = result.Find(keyValue.first.stringKey);
105 value = result.Find(keyValue.first.indexKey);
108 DALI_TEST_CHECK( value != NULL );
111 if( keyValue.second.GetType() == Property::MAP )
113 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
114 CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) );
116 else if( keyValue.second.GetType() == Property::ARRAY )
118 CHECK_ARRAY_EQUALS( *(keyValue.second.GetArray()), *value );
120 else if( keyValue.second.GetType() == Property::STRING )
122 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
125 DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION );
129 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
130 DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION );
137 int UtcDaliTransitionDataNew(void)
139 ToolkitTestApplication application;
141 Property::Map map = CreateMap();
142 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
143 DALI_TEST_CHECK( transition );
148 int UtcDaliTransitionDataDownCast(void)
150 ToolkitTestApplication application;
152 Property::Map map = CreateMap();
154 BaseHandle handle = TransitionData::New( map );
155 DALI_TEST_CHECK( handle );
157 TransitionData transitionData = TransitionData::DownCast( handle );
158 DALI_TEST_CHECK( transitionData );
162 int UtcDaliTransitionDataCopyConstructor(void)
164 ToolkitTestApplication application;
166 Property::Map map = CreateMap();
168 TransitionData transitionData = TransitionData::New( map );
169 DALI_TEST_CHECK( transitionData );
171 TransitionData td2( transitionData );
172 DALI_TEST_CHECK( td2 );
173 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
177 int UtcDaliTransitionDataAssignmentOperator(void)
179 ToolkitTestApplication application;
181 Property::Map map = CreateMap();
183 TransitionData transitionData = TransitionData::New( map );
184 DALI_TEST_CHECK( transitionData );
187 DALI_TEST_CHECK( !td2 );
189 td2 = transitionData;
190 DALI_TEST_CHECK( td2 );
192 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
196 int UtcDaliTransitionDataCount(void)
198 ToolkitTestApplication application;
200 Property::Map map = CreateMap();
201 TransitionData transitionData = TransitionData::New( map );
202 DALI_TEST_CHECK( transitionData );
203 DALI_TEST_EQUALS( transitionData.Count(), 1, TEST_LOCATION );
205 Property::Array array;
206 array.PushBack( map );
207 array.PushBack( map );
208 array.PushBack( map );
210 TransitionData transitionData2 = TransitionData::New( array );
211 DALI_TEST_CHECK( transitionData2 );
212 DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION );
217 int UtcDaliTransitionDataMap1P(void)
219 ToolkitTestApplication application;
221 tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
224 map["target"] = "visual1";
225 map["property"] = "mixColor";
226 map["initialValue"] = Color::MAGENTA;
227 map["targetValue"] = Color::RED;
228 map["animator"] = Property::Map()
229 .Add("alphaFunction", "EASE_IN_OUT")
230 .Add("timePeriod", Property::Map()
232 .Add("duration", 1.0f));
234 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
236 DummyControl actor = DummyControl::New();
237 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
238 actor.SetName("Actor1");
239 actor.SetColor(Color::CYAN);
240 Stage::GetCurrent().Add(actor);
242 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
244 Property::Map visualMap;
245 visualMap[Visual::Property::TYPE] = Visual::COLOR;
246 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
247 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
248 visual.SetName( "visual1" );
250 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
251 dummyImpl.RegisterVisual( visualIndex, visual );
253 Animation anim = dummyImpl.CreateTransition( transition );
254 DALI_TEST_CHECK( anim );
256 Renderer renderer = actor.GetRendererAt(0);
257 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
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>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
264 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 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 >( DevelRenderer::Property::OPACITY ), 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 >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
285 int UtcDaliTransitionDataMap2P(void)
287 ToolkitTestApplication 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 application.SendNotification();
327 application.Render(0);
329 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
330 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
331 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
332 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
336 application.SendNotification();
337 application.Render(0);
338 application.Render(500); // Start animation
339 application.Render(500); // Halfway thru anim
340 application.SendNotification();
341 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
342 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
344 application.Render(500); // End of anim
345 application.SendNotification();
346 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
347 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
353 int UtcDaliTransitionDataMap2Pb(void)
355 ToolkitTestApplication application;
357 tet_printf("Testing animation of a visual property using programmatic maps\n");
360 map["target"] = "visual1";
361 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
362 map["initialValue"] = Color::MAGENTA;
363 map["targetValue"] = Color::RED;
364 map["animator"] = Property::Map()
365 .Add("alphaFunction", "LINEAR")
366 .Add("timePeriod", Property::Map()
368 .Add("duration", 1.0f));
370 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
372 DummyControl actor = DummyControl::New();
373 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
374 actor.SetName("Actor1");
375 actor.SetColor(Color::CYAN);
376 Stage::GetCurrent().Add(actor);
378 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
380 Property::Map visualMap;
381 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
382 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
383 visualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
384 visualMap[ PrimitiveVisual::Property::SLICES ] = 10;
385 visualMap[ PrimitiveVisual::Property::STACKS ] = 10;
387 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
388 visual.SetName( "visual1" );
390 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
391 dummyImpl.RegisterVisual( visualIndex, visual );
393 Animation anim = dummyImpl.CreateTransition( transition );
394 DALI_TEST_CHECK( anim );
396 Renderer renderer = actor.GetRendererAt(0);
397 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, PrimitiveVisual::Property::MIX_COLOR );
398 application.SendNotification();
399 application.Render(0);
401 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
402 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
403 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
404 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
408 application.SendNotification();
409 application.Render(0);
410 application.Render(500); // Start animation
411 application.Render(500); // Halfway thru anim
412 application.SendNotification();
413 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
414 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
416 application.Render(500); // End of anim
417 application.SendNotification();
418 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
419 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
425 int UtcDaliTransitionDataMap3P(void)
427 ToolkitTestApplication application;
429 tet_printf("Testing animation of an actor's position property using bezier curve\n");
432 map["target"] = "Actor1";
433 map["property"] = "position";
434 map["initialValue"] = Vector3(0, 0, 0);
435 map["targetValue"] = Vector3(100, 100, 0);
436 map["animator"] = Property::Map()
437 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
438 .Add("timePeriod", Property::Map()
440 .Add("duration", 1.0f));
442 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
444 DummyControl actor = DummyControl::New();
445 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
446 actor.SetName("Actor1");
447 Stage::GetCurrent().Add(actor);
449 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
450 Animation anim = dummyImpl.CreateTransition( transition );
451 DALI_TEST_CHECK( anim );
453 application.SendNotification();
454 application.Render(0);
455 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
459 application.SendNotification();
460 application.Render(0);
462 application.Render(250); // 25%
463 application.SendNotification();
464 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%
466 application.Render(250); // Halfway thru map1 anim
467 application.SendNotification();
468 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%
470 application.Render(250); // End of map1 anim
471 application.SendNotification();
472 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
474 application.Render(250); // End of map1 anim
475 application.SendNotification();
476 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
481 int UtcDaliTransitionDataMap4P(void)
483 ToolkitTestApplication application;
485 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
488 map1["target"] = "testVisual";
489 map1["property"] = "offset";
490 map1["initialValue"] = Vector2(0.0f, 0.0f);
491 map1["targetValue"] = Vector2(100.0f, 100.0f);
492 map1["animator"] = Property::Map()
493 .Add("alphaFunction", "LINEAR")
494 .Add("timePeriod", Property::Map()
496 .Add("duration", 1.0f));
499 map2["target"] = "testVisual";
500 map2["property"] = "size";
501 map2["initialValue"] = Vector2(10.0f, 10.0f);
502 map2["targetValue"] = Vector2(110.0f, 110.0f);
503 map2["animator"] = Property::Map()
504 .Add("alphaFunction", "LINEAR")
505 .Add("timePeriod", Property::Map()
507 .Add("duration", 1.0f));
509 Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) );
511 DummyControl actor = DummyControl::New();
512 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
513 actor.SetName("Actor1");
514 Stage::GetCurrent().Add(actor);
516 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
518 Property::Map visualMap;
519 visualMap[Visual::Property::TYPE] = Visual::COLOR;
520 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
521 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
523 visual.SetName( "testVisual" );
524 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
526 Animation anim = dummyImpl.CreateTransition( transition );
527 DALI_TEST_CHECK( anim );
529 Renderer renderer = actor.GetRendererAt(0);
530 Property::Index sizeIndex = renderer.GetPropertyIndex( "size" );
531 application.SendNotification();
532 application.Render(0);
534 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
535 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(10.0f, 10.0f), TEST_LOCATION);
539 application.SendNotification();
540 application.Render(0);
541 application.Render(500); // Start animation
542 application.Render(500); // Halfway thru anim
543 application.SendNotification();
544 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(60.0f, 60.0f), TEST_LOCATION);
546 application.Render(500); // End of anim
547 application.SendNotification();
548 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(110.0f, 110.0f), TEST_LOCATION );
553 int UtcDaliTransitionDataMap5P(void)
555 ToolkitTestApplication application;
557 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
560 map["target"] = "visual1";
561 map["property"] = "opacity";
562 map["initialValue"] = 0.0f;
563 map["targetValue"] = 1.0f;
564 map["animator"] = Property::Map()
565 .Add("alphaFunction", "EASE_IN_OUT")
566 .Add("timePeriod", Property::Map()
568 .Add("duration", 1.0f));
570 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
572 DummyControl actor = DummyControl::New();
573 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
574 actor.SetName("Actor1");
575 actor.SetColor(Color::CYAN);
576 Stage::GetCurrent().Add(actor);
578 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
580 Property::Map visualMap;
581 visualMap[Visual::Property::TYPE] = Visual::COLOR;
582 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
583 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
584 visual.SetName( "visual1" );
586 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
587 dummyImpl.RegisterVisual( visualIndex, visual );
589 Animation anim = dummyImpl.CreateTransition( transition );
590 DALI_TEST_CHECK( anim );
592 Renderer renderer = actor.GetRendererAt(0);
593 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
594 application.SendNotification();
595 application.Render(0);
597 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
598 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
599 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
601 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
602 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
603 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
607 application.SendNotification();
608 application.Render(500); // Start animation
609 application.Render(500); // Halfway thru anim
610 application.SendNotification();
611 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
612 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
613 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
615 application.Render(501); // End of anim
616 application.SendNotification();
617 application.Render();
618 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
619 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
620 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::AUTO, TEST_LOCATION );
626 int UtcDaliTransitionDataMap6P(void)
628 ToolkitTestApplication application;
630 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
633 map["target"] = "visual1";
634 map["property"] = "opacity";
635 map["targetValue"] = 0.0f;
636 map["animator"] = Property::Map()
637 .Add("alphaFunction", "EASE_IN_OUT")
638 .Add("timePeriod", Property::Map()
640 .Add("duration", 1.0f));
642 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
644 DummyControl actor = DummyControl::New();
645 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
646 actor.SetName("Actor1");
647 actor.SetColor(Color::CYAN);
648 Stage::GetCurrent().Add(actor);
650 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
652 Property::Map visualMap;
653 visualMap[Visual::Property::TYPE] = Visual::COLOR;
654 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
655 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
656 visual.SetName( "visual1" );
658 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
659 dummyImpl.RegisterVisual( visualIndex, visual );
661 Animation anim = dummyImpl.CreateTransition( transition );
662 DALI_TEST_CHECK( anim );
664 Renderer renderer = actor.GetRendererAt(0);
665 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
666 application.SendNotification();
667 application.Render(0);
669 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
670 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
671 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
672 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
674 // Note, This should be testing for AUTO
675 // this is the same problem as C# target value being set before Play is called.
676 // @todo How was this solved?
677 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
678 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
682 application.SendNotification();
683 application.Render(500); // Start animation
684 application.Render(500); // Halfway thru anim
685 application.SendNotification();
686 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
687 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
688 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
690 application.Render(500); // End of anim
691 application.SendNotification();
692 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
693 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
694 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
700 int UtcDaliTransitionDataMap1N(void)
702 ToolkitTestApplication application;
705 map["target"] = "Actor1";
706 map["property"] = "randomProperty";
707 map["initialValue"] = Color::MAGENTA;
708 map["targetValue"] = Color::RED;
709 map["animator"] = Property::Map()
710 .Add("alphaFunction", "EASE_OUT")
711 .Add("timePeriod", Property::Map()
713 .Add("duration", 1.0f));
715 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
717 DummyControl actor = DummyControl::New();
718 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
719 actor.SetName("Actor1");
720 actor.SetColor(Color::CYAN);
721 Stage::GetCurrent().Add(actor);
723 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
724 Animation anim = dummyImpl.CreateTransition( transition );
725 DALI_TEST_CHECK( ! anim );
727 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
732 int UtcDaliTransitionDataMapN3(void)
734 ToolkitTestApplication application;
736 tet_printf("Testing visual lookup with no renderers\n");
739 map["target"] = "visual1";
740 map["property"] = "mixColor";
741 map["initialValue"] = Vector3(Color::MAGENTA);
742 map["targetValue"] = Vector3(Color::RED);
743 map["animator"] = Property::Map()
744 .Add("alphaFunction", "EASE_OUT_BACK")
745 .Add("timePeriod", Property::Map()
747 .Add("duration", 1.0f));
749 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
750 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
752 DummyControl actor = DummyControl::New();
753 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
754 actor.SetName("Actor1");
755 actor.SetColor(Color::CYAN);
758 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
759 Property::Map visualMap;
760 visualMap[Visual::Property::TYPE] = Visual::COLOR;
761 visualMap[ColorVisual::Property::MIX_COLOR] = Vector3(Color::MAGENTA);
762 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
763 visual.SetName( "visual1" );
765 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
766 dummyImpl.RegisterVisual( visualIndex, visual );
768 Animation anim = dummyImpl.CreateTransition( transition );
769 DALI_TEST_CHECK( !anim );
774 int UtcDaliTransitionDataMapN4(void)
776 ToolkitTestApplication application;
778 tet_printf("Testing visual doesn't animate with duff bezier data \n");
781 map["target"] = "visual1";
782 map["property"] = "mixColor";
783 map["initialValue"] = Vector3(Color::MAGENTA);
784 map["targetValue"] = Vector3(Color::RED);
785 map["animator"] = Property::Map()
786 .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
787 .Add("timePeriod", Property::Map()
789 .Add("duration", 1.0f));
791 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
793 DummyControl actor = DummyControl::New();
794 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
795 actor.SetName("Actor1");
796 actor.SetColor(Color::CYAN);
797 Stage::GetCurrent().Add(actor);
799 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
800 Property::Map visualMap;
801 visualMap[Visual::Property::TYPE] = Visual::COLOR;
802 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
803 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
804 visual.SetName( "visual1" );
806 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
807 dummyImpl.RegisterVisual( visualIndex, visual );
809 Animation anim = dummyImpl.CreateTransition( transition );
810 DALI_TEST_CHECK( !anim );
812 application.SendNotification();
813 application.Render(0);
814 application.SendNotification();
816 Renderer renderer = actor.GetRendererAt(0);
817 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
819 tet_printf( "Test that the property has been set to target value\n");
820 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
821 DALI_TEST_EQUALS(renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001, TEST_LOCATION);
826 int UtcDaliTransitionDataMapN5(void)
828 ToolkitTestApplication application;
830 tet_printf("Testing visual doesn't animate with duff bezier data \n");
833 map["target"] = "visual1";
834 map["property"] = "mixColor";
835 map["initialValue"] = Color::MAGENTA;
836 map["targetValue"] = Color::RED;
837 map["animator"] = Property::Map()
838 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
839 .Add("timePeriod", Property::Map()
841 .Add("duration", 1.0f));
843 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
845 DummyControl actor = DummyControl::New();
846 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
847 actor.SetName("Actor1");
848 actor.SetColor(Color::CYAN);
849 Stage::GetCurrent().Add(actor);
851 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
852 Property::Map visualMap;
853 visualMap[Visual::Property::TYPE] = Visual::COLOR;
854 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
855 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
856 visual.SetName( "visual1" );
858 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
859 dummyImpl.RegisterVisual( visualIndex, visual );
861 Animation anim = dummyImpl.CreateTransition( transition );
862 DALI_TEST_CHECK( !anim );
864 application.SendNotification();
865 application.Render(0);
866 application.SendNotification();
868 Renderer renderer = actor.GetRendererAt(0);
869 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
871 tet_printf( "Test that the property has been set to target value\n");
872 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
877 int UtcDaliTransitionDataMapN6(void)
879 ToolkitTestApplication application;
881 tet_printf("Testing visual doesn't animate with duff bezier data \n");
884 map["target"] = "visual1";
885 map["property"] = "mixColor";
886 map["initialValue"] = Color::MAGENTA;
887 map["targetValue"] = Color::RED;
888 map["animator"] = Property::Map()
889 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
890 .Add("timePeriod", Property::Map()
892 .Add("duration", 1.0f));
894 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
896 DummyControl actor = DummyControl::New();
897 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
898 actor.SetName("Actor1");
899 actor.SetColor(Color::CYAN);
900 Stage::GetCurrent().Add(actor);
902 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
903 Property::Map visualMap;
904 visualMap[Visual::Property::TYPE] = Visual::COLOR;
905 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
906 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
907 visual.SetName( "visual1" );
909 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
910 dummyImpl.RegisterVisual( visualIndex, visual );
912 Animation anim = dummyImpl.CreateTransition( transition );
913 DALI_TEST_CHECK( !anim );
915 application.SendNotification();
916 application.Render(0);
917 application.SendNotification();
919 Renderer renderer = actor.GetRendererAt(0);
920 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
922 tet_printf( "Test that the property has been set to target value\n");
923 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
924 DALI_TEST_EQUALS(renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001, TEST_LOCATION);
930 int UtcDaliTransitionDataArrayP(void)
932 ToolkitTestApplication application;
935 map1["target"] = "Actor1";
936 map1["property"] = "color";
937 map1["initialValue"] = Color::MAGENTA;
938 map1["targetValue"] = Color::RED;
939 map1["animator"] = Property::Map()
940 .Add("alphaFunction", "EASE_IN_OUT")
941 .Add("timePeriod", Property::Map()
943 .Add("duration", 1.0f));
946 map2["target"] = "Actor1";
947 map2["property"] = "position";
948 map2["initialValue"] = Vector3(100,0,0);
949 map2["targetValue"] = Vector3(0,100,0);
950 map2["animator"] = Property::Map()
951 .Add("alphaFunction", "EASE_IN_OUT")
952 .Add("timePeriod", Property::Map()
954 .Add("duration", 1.0f));
957 map3["target"] = "Actor1";
958 map3["property"] = "orientation";
959 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
961 Property::Array array;
962 array.PushBack(map1);
963 array.PushBack(map2);
964 array.PushBack(map3);
966 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
968 DummyControl actor = DummyControl::New();
969 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
970 actor.SetName("Actor1");
971 actor.SetColor(Color::CYAN);
972 Stage::GetCurrent().Add(actor);
973 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
975 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
976 Animation anim = dummyImpl.CreateTransition( transition );
977 DALI_TEST_CHECK( anim );
978 application.SendNotification();
979 application.Render(0);
980 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
981 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
984 application.SendNotification();
985 application.Render(0); // start map2 anim
986 application.SendNotification();
987 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
989 application.Render(500); // Start map1 animation, halfway thru map2 anim
990 application.SendNotification();
991 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
993 application.Render(500); // Halfway thru map1 anim, end of map2 anim
994 application.SendNotification();
995 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
996 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
998 application.Render(500); // End of map1 anim
999 application.SendNotification();
1000 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
1006 int UtcDaliTransitionDataGetAnimatorP(void)
1008 ToolkitTestApplication application;
1011 map1["target"] = "Actor1";
1012 map1["property"] = "color";
1013 map1["initialValue"] = Color::MAGENTA;
1014 map1["targetValue"] = Color::RED;
1015 map1["animator"] = Property::Map()
1016 .Add("alphaFunction", "EASE_IN_SQUARE")
1017 .Add("timePeriod", Property::Map()
1019 .Add("duration", 0.5f));
1022 map2["target"] = "Actor1";
1023 map2["property"] = "position";
1024 map2["initialValue"] = Vector3(100,0,0);
1025 map2["targetValue"] = Vector3(0,100,0);
1026 map2["animator"] = Property::Map()
1027 .Add("alphaFunction", "EASE_OUT_SQUARE")
1028 .Add("timePeriod", Property::Map()
1030 .Add("duration", 2.0f));
1033 map3["target"] = "Actor1";
1034 map3["property"] = "size";
1035 map3["initialValue"] = Vector2(10,10);
1036 map3["targetValue"] = Vector2(100,100);
1037 map3["animator"] = Property::Map()
1038 .Add("alphaFunction", "EASE_OUT_SINE")
1039 .Add("timePeriod", Property::Map()
1041 .Add("duration", 3.0f));
1044 map4["target"] = "Actor2";
1045 map4["property"] = "color";
1046 map4["initialValue"] = Color::BLACK;
1047 map4["targetValue"] = Color::GREEN;
1048 map4["animator"] = Property::Map()
1049 .Add("alphaFunction", "EASE_IN_OUT_SINE")
1050 .Add("timePeriod", Property::Map()
1052 .Add("duration", 0.5f));
1055 map5["target"] = "Actor2";
1056 map5["property"] = "position";
1057 map5["initialValue"] = Vector3(100,0,0);
1058 map5["targetValue"] = Vector3(0,100,0);
1059 map5["animator"] = Property::Map()
1060 .Add("alphaFunction", "BOUNCE")
1061 .Add("timePeriod", Property::Map()
1063 .Add("duration", 2.0f));
1066 map6["target"] = "Actor2";
1067 map6["property"] = "size";
1068 map6["initialValue"] = Vector2(10,10);
1069 map6["targetValue"] = Vector2(100,100);
1070 map6["animator"] = Property::Map()
1071 .Add("alphaFunction", "SIN")
1072 .Add("timePeriod", Property::Map()
1074 .Add("duration", 3.0f));
1077 map7["target"] = "Actor4";
1078 map7["property"] = "sizeModeFactor";
1079 map7["initialValue"] = Vector3(1,1,1);
1080 map7["targetValue"] = Vector3(2,2,2);
1081 map7["animator"] = Property::Map()
1082 .Add("alphaFunction", "EASE_IN_SINE")
1083 .Add("timePeriod", Property::Map()
1085 .Add("duration", 1.0f));
1088 map8["target"] = "Visual1";
1089 map8["property"] = "opacity";
1090 map8["initialValue"] = 0.0f;
1091 map8["targetValue"] = 1.0f;
1092 map8["animator"] = Property::Map()
1093 .Add("alphaFunction", "EASE_IN")
1094 .Add("timePeriod", Property::Map()
1096 .Add("duration", 9.0f));
1099 map9["target"] = "Actor2";
1100 map9["property"] = "scale";
1101 map9["initialValue"] = Vector3(0,0,0);
1102 map9["targetValue"] = Vector3(1,1,1);
1103 map9["animator"] = Property::Map()
1104 .Add("alphaFunction", "REVERSE")
1105 .Add("timePeriod", Property::Map()
1107 .Add("duration", 1.0f));
1109 Property::Map map10;
1110 map10["target"] = "Actor2";
1111 map10["property"] = "scale";
1112 map10["initialValue"] = Vector3(0,0,0);
1113 map10["targetValue"] = Vector3(1,1,1);
1114 map10["animator"] = Property::Map()
1115 .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
1116 .Add("timePeriod", Property::Map()
1118 .Add("duration", 1.0f));
1120 Property::Map map11;
1121 map11["target"] = "Actor2";
1122 map11["property"] = "scale";
1123 map11["initialValue"] = Vector3(0,0,0);
1124 map11["targetValue"] = Vector3(1,1,1);
1125 map11["animator"] = Property::Map()
1126 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1127 .Add("timePeriod", Property::Map()
1129 .Add("duration", 1.0f));
1131 Property::Map map12;
1132 map12["target"] = "Actor1";
1133 map12["property"] = "orientation";
1134 map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
1136 Property::Array array;
1137 array.PushBack(map1);
1138 array.PushBack(map2);
1139 array.PushBack(map3);
1140 array.PushBack(map4);
1141 array.PushBack(map5);
1142 array.PushBack(map6);
1143 array.PushBack(map7);
1144 array.PushBack(map8);
1145 array.PushBack(map9);
1146 array.PushBack(map10);
1147 array.PushBack(map11);
1148 array.PushBack(map12);
1150 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1152 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
1154 for( unsigned int i=0; i < array.Count(); ++i )
1156 Property::Map animatorMap = transition.GetAnimatorAt(i);
1157 Property::Value& value = array.GetElementAt(i);
1158 Property::Map* inputMap = value.GetMap();
1159 DALI_TEST_CHECK( inputMap );
1160 CHECK_MAP_EQUALS( *inputMap, animatorMap );