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/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 <dali-toolkit/devel-api/visuals/visual-properties-devel.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 TestApplication application;
141 Property::Map map = CreateMap();
142 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
143 DALI_TEST_CHECK( transition );
148 int UtcDaliTransitionDataDownCast(void)
150 TestApplication 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 TestApplication 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 TestApplication 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 TestApplication 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 TestApplication 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 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
259 application.SendNotification();
260 application.Render(0);
262 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
263 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
267 application.SendNotification();
268 application.Render(500); // Start animation
269 application.Render(500); // Halfway thru anim
270 application.SendNotification();
271 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
272 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
274 application.Render(500); // End of anim
275 application.SendNotification();
276 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION );
277 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
284 int UtcDaliTransitionDataMap2P(void)
286 TestApplication application;
288 tet_printf("Testing animation of a visual property using programmatic maps\n");
291 map["target"] = "visual1";
292 map["property"] = ColorVisual::Property::MIX_COLOR;
293 map["initialValue"] = Color::MAGENTA;
294 map["targetValue"] = Color::RED;
295 map["animator"] = Property::Map()
296 .Add("alphaFunction", "LINEAR")
297 .Add("timePeriod", Property::Map()
299 .Add("duration", 1.0f));
301 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
303 DummyControl actor = DummyControl::New();
304 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
305 actor.SetName("Actor1");
306 actor.SetColor(Color::CYAN);
307 Stage::GetCurrent().Add(actor);
309 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
311 Property::Map visualMap;
312 visualMap[Visual::Property::TYPE] = Visual::COLOR;
313 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
314 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
315 visual.SetName( "visual1" );
317 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
318 dummyImpl.RegisterVisual( visualIndex, visual );
320 Animation anim = dummyImpl.CreateTransition( transition );
321 DALI_TEST_CHECK( anim );
323 Renderer renderer = actor.GetRendererAt(0);
324 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
325 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
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.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
334 application.SendNotification();
335 application.Render(0);
336 application.Render(500); // Start animation
337 application.Render(500); // Halfway thru anim
338 application.SendNotification();
339 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
340 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
342 application.Render(500); // End of anim
343 application.SendNotification();
344 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION );
345 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
351 int UtcDaliTransitionDataMap2Pb(void)
353 TestApplication application;
355 tet_printf("Testing animation of a visual property using programmatic maps\n");
358 map["target"] = "visual1";
359 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
360 map["initialValue"] = Color::MAGENTA;
361 map["targetValue"] = Color::RED;
362 map["animator"] = Property::Map()
363 .Add("alphaFunction", "LINEAR")
364 .Add("timePeriod", Property::Map()
366 .Add("duration", 1.0f));
368 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
370 DummyControl actor = DummyControl::New();
371 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
372 actor.SetName("Actor1");
373 actor.SetColor(Color::CYAN);
374 Stage::GetCurrent().Add(actor);
376 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
378 Property::Map visualMap;
379 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
380 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
381 visualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
382 visualMap[ PrimitiveVisual::Property::SLICES ] = 10;
383 visualMap[ PrimitiveVisual::Property::STACKS ] = 10;
385 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
386 visual.SetName( "visual1" );
388 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
389 dummyImpl.RegisterVisual( visualIndex, visual );
391 Animation anim = dummyImpl.CreateTransition( transition );
392 DALI_TEST_CHECK( anim );
394 Renderer renderer = actor.GetRendererAt(0);
395 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, PrimitiveVisual::Property::MIX_COLOR );
396 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
397 application.SendNotification();
398 application.Render(0);
400 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
401 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
405 application.SendNotification();
406 application.Render(0);
407 application.Render(500); // Start animation
408 application.Render(500); // Halfway thru anim
409 application.SendNotification();
410 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
411 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
413 application.Render(500); // End of anim
414 application.SendNotification();
415 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION );
416 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION);
422 int UtcDaliTransitionDataMap3P(void)
424 TestApplication application;
426 tet_printf("Testing animation of an actor's position property using bezier curve\n");
429 map["target"] = "Actor1";
430 map["property"] = "position";
431 map["initialValue"] = Vector3(0, 0, 0);
432 map["targetValue"] = Vector3(100, 100, 0);
433 map["animator"] = Property::Map()
434 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
435 .Add("timePeriod", Property::Map()
437 .Add("duration", 1.0f));
439 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
441 DummyControl actor = DummyControl::New();
442 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
443 actor.SetName("Actor1");
444 Stage::GetCurrent().Add(actor);
446 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
447 Animation anim = dummyImpl.CreateTransition( transition );
448 DALI_TEST_CHECK( anim );
450 application.SendNotification();
451 application.Render(0);
452 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
456 application.SendNotification();
457 application.Render(0);
459 application.Render(250); // 25%
460 application.SendNotification();
461 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%
463 application.Render(250); // Halfway thru map1 anim
464 application.SendNotification();
465 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%
467 application.Render(250); // End of map1 anim
468 application.SendNotification();
469 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
471 application.Render(250); // End of map1 anim
472 application.SendNotification();
473 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
478 int UtcDaliTransitionDataMap4P(void)
480 TestApplication application;
482 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
485 map1["target"] = "testVisual";
486 map1["property"] = "offset";
487 map1["initialValue"] = Vector2(0.0f, 0.0f);
488 map1["targetValue"] = Vector2(100.0f, 100.0f);
489 map1["animator"] = Property::Map()
490 .Add("alphaFunction", "LINEAR")
491 .Add("timePeriod", Property::Map()
493 .Add("duration", 1.0f));
496 map2["target"] = "testVisual";
497 map2["property"] = "size";
498 map2["initialValue"] = Vector2(10.0f, 10.0f);
499 map2["targetValue"] = Vector2(110.0f, 110.0f);
500 map2["animator"] = Property::Map()
501 .Add("alphaFunction", "LINEAR")
502 .Add("timePeriod", Property::Map()
504 .Add("duration", 1.0f));
506 Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) );
508 DummyControl actor = DummyControl::New();
509 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
510 actor.SetName("Actor1");
511 Stage::GetCurrent().Add(actor);
513 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
515 Property::Map visualMap;
516 visualMap[Visual::Property::TYPE] = Visual::COLOR;
517 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
518 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
520 visual.SetName( "testVisual" );
521 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
523 Animation anim = dummyImpl.CreateTransition( transition );
524 DALI_TEST_CHECK( anim );
526 Renderer renderer = actor.GetRendererAt(0);
527 Property::Index sizeIndex = renderer.GetPropertyIndex( "size" );
528 application.SendNotification();
529 application.Render(0);
531 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
535 application.SendNotification();
536 application.Render(0);
537 application.Render(500); // Start animation
538 application.Render(500); // Halfway thru anim
539 application.SendNotification();
540 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(60.0f, 60.0f), TEST_LOCATION);
542 application.Render(500); // End of anim
543 application.SendNotification();
544 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(110.0f, 110.0f), TEST_LOCATION );
549 int UtcDaliTransitionDataMap5P(void)
551 TestApplication application;
553 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
556 map["target"] = "visual1";
557 map["property"] = "opacity";
558 map["initialValue"] = 0.0f;
559 map["targetValue"] = 1.0f;
560 map["animator"] = Property::Map()
561 .Add("alphaFunction", "EASE_IN_OUT")
562 .Add("timePeriod", Property::Map()
564 .Add("duration", 1.0f));
566 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
568 DummyControl actor = DummyControl::New();
569 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
570 actor.SetName("Actor1");
571 actor.SetColor(Color::CYAN);
572 Stage::GetCurrent().Add(actor);
574 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
576 Property::Map visualMap;
577 visualMap[Visual::Property::TYPE] = Visual::COLOR;
578 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
579 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
580 visual.SetName( "visual1" );
582 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
583 dummyImpl.RegisterVisual( visualIndex, visual );
585 Animation anim = dummyImpl.CreateTransition( transition );
586 DALI_TEST_CHECK( anim );
588 Renderer renderer = actor.GetRendererAt(0);
589 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
590 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
591 application.SendNotification();
592 application.Render(0);
594 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
595 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.0f, 0.001f, TEST_LOCATION );
596 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
600 application.SendNotification();
601 application.Render(500); // Start animation
602 application.Render(500); // Halfway thru anim
603 application.SendNotification();
604 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
605 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.5f, 0.001f, TEST_LOCATION );
606 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
608 application.Render(501); // End of anim
609 application.SendNotification();
610 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION );
611 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
612 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::AUTO, TEST_LOCATION );
618 int UtcDaliTransitionDataMap6P(void)
620 TestApplication application;
622 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
625 map["target"] = "visual1";
626 map["property"] = "opacity";
627 map["targetValue"] = 0.0f;
628 map["animator"] = Property::Map()
629 .Add("alphaFunction", "EASE_IN_OUT")
630 .Add("timePeriod", Property::Map()
632 .Add("duration", 1.0f));
634 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
636 DummyControl actor = DummyControl::New();
637 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
638 actor.SetName("Actor1");
639 actor.SetColor(Color::CYAN);
640 Stage::GetCurrent().Add(actor);
642 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
644 Property::Map visualMap;
645 visualMap[Visual::Property::TYPE] = Visual::COLOR;
646 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
647 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
648 visual.SetName( "visual1" );
650 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
651 dummyImpl.RegisterVisual( visualIndex, visual );
653 Animation anim = dummyImpl.CreateTransition( transition );
654 DALI_TEST_CHECK( anim );
656 Renderer renderer = actor.GetRendererAt(0);
657 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
658 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
659 application.SendNotification();
660 application.Render(0);
662 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
663 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
665 // Note, This should be testing for AUTO
666 // this is the same problem as C# target value being set before Play is called.
667 // @todo How was this solved?
668 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
672 application.SendNotification();
673 application.Render(500); // Start animation
674 application.Render(500); // Halfway thru anim
675 application.SendNotification();
676 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
677 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.5f, 0.001f, TEST_LOCATION );
678 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
680 application.Render(500); // End of anim
681 application.SendNotification();
682 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION );
683 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.0f, 0.001f, TEST_LOCATION );
684 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
690 int UtcDaliTransitionDataMap1N(void)
692 TestApplication application;
695 map["target"] = "Actor1";
696 map["property"] = "randomProperty";
697 map["initialValue"] = Color::MAGENTA;
698 map["targetValue"] = Color::RED;
699 map["animator"] = Property::Map()
700 .Add("alphaFunction", "EASE_OUT")
701 .Add("timePeriod", Property::Map()
703 .Add("duration", 1.0f));
705 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
707 DummyControl actor = DummyControl::New();
708 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
709 actor.SetName("Actor1");
710 actor.SetColor(Color::CYAN);
711 Stage::GetCurrent().Add(actor);
713 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
714 Animation anim = dummyImpl.CreateTransition( transition );
715 DALI_TEST_CHECK( ! anim );
717 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
722 int UtcDaliTransitionDataMapN3(void)
724 TestApplication application;
726 tet_printf("Testing visual lookup with no renderers\n");
729 map["target"] = "visual1";
730 map["property"] = "mixColor";
731 map["initialValue"] = Vector3(Color::MAGENTA);
732 map["targetValue"] = Vector3(Color::RED);
733 map["animator"] = Property::Map()
734 .Add("alphaFunction", "EASE_OUT_BACK")
735 .Add("timePeriod", Property::Map()
737 .Add("duration", 1.0f));
739 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
740 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
742 DummyControl actor = DummyControl::New();
743 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
744 actor.SetName("Actor1");
745 actor.SetColor(Color::CYAN);
748 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
749 Property::Map visualMap;
750 visualMap[Visual::Property::TYPE] = Visual::COLOR;
751 visualMap[ColorVisual::Property::MIX_COLOR] = Vector3(Color::MAGENTA);
752 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
753 visual.SetName( "visual1" );
755 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
756 dummyImpl.RegisterVisual( visualIndex, visual );
758 Animation anim = dummyImpl.CreateTransition( transition );
759 DALI_TEST_CHECK( !anim );
764 int UtcDaliTransitionDataMapN4(void)
766 TestApplication application;
768 tet_printf("Testing visual doesn't animate with duff bezier data \n");
771 map["target"] = "visual1";
772 map["property"] = "mixColor";
773 map["initialValue"] = Vector3(Color::MAGENTA);
774 map["targetValue"] = Vector3(Color::RED);
775 map["animator"] = Property::Map()
776 .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
777 .Add("timePeriod", Property::Map()
779 .Add("duration", 1.0f));
781 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
783 DummyControl actor = DummyControl::New();
784 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
785 actor.SetName("Actor1");
786 actor.SetColor(Color::CYAN);
787 Stage::GetCurrent().Add(actor);
789 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
790 Property::Map visualMap;
791 visualMap[Visual::Property::TYPE] = Visual::COLOR;
792 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
793 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
794 visual.SetName( "visual1" );
796 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
797 dummyImpl.RegisterVisual( visualIndex, visual );
799 Animation anim = dummyImpl.CreateTransition( transition );
800 DALI_TEST_CHECK( !anim );
802 application.SendNotification();
803 application.Render(0);
804 application.SendNotification();
806 Renderer renderer = actor.GetRendererAt(0);
807 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
808 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
810 tet_printf( "Test that the property has been set to target value\n");
811 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
812 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
817 int UtcDaliTransitionDataMapN5(void)
819 TestApplication application;
821 tet_printf("Testing visual doesn't animate with duff bezier data \n");
824 map["target"] = "visual1";
825 map["property"] = "mixColor";
826 map["initialValue"] = Color::MAGENTA;
827 map["targetValue"] = Color::RED;
828 map["animator"] = Property::Map()
829 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
830 .Add("timePeriod", Property::Map()
832 .Add("duration", 1.0f));
834 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
836 DummyControl actor = DummyControl::New();
837 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
838 actor.SetName("Actor1");
839 actor.SetColor(Color::CYAN);
840 Stage::GetCurrent().Add(actor);
842 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
843 Property::Map visualMap;
844 visualMap[Visual::Property::TYPE] = Visual::COLOR;
845 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
846 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
847 visual.SetName( "visual1" );
849 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
850 dummyImpl.RegisterVisual( visualIndex, visual );
852 Animation anim = dummyImpl.CreateTransition( transition );
853 DALI_TEST_CHECK( !anim );
855 application.SendNotification();
856 application.Render(0);
857 application.SendNotification();
859 Renderer renderer = actor.GetRendererAt(0);
860 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
862 tet_printf( "Test that the property has been set to target value\n");
863 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
868 int UtcDaliTransitionDataMapN6(void)
870 TestApplication application;
872 tet_printf("Testing visual doesn't animate with duff bezier data \n");
875 map["target"] = "visual1";
876 map["property"] = "mixColor";
877 map["initialValue"] = Color::MAGENTA;
878 map["targetValue"] = Color::RED;
879 map["animator"] = Property::Map()
880 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
881 .Add("timePeriod", Property::Map()
883 .Add("duration", 1.0f));
885 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
887 DummyControl actor = DummyControl::New();
888 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
889 actor.SetName("Actor1");
890 actor.SetColor(Color::CYAN);
891 Stage::GetCurrent().Add(actor);
893 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
894 Property::Map visualMap;
895 visualMap[Visual::Property::TYPE] = Visual::COLOR;
896 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
897 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
898 visual.SetName( "visual1" );
900 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
901 dummyImpl.RegisterVisual( visualIndex, visual );
903 Animation anim = dummyImpl.CreateTransition( transition );
904 DALI_TEST_CHECK( !anim );
906 application.SendNotification();
907 application.Render(0);
908 application.SendNotification();
910 Renderer renderer = actor.GetRendererAt(0);
911 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
912 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
914 tet_printf( "Test that the property has been set to target value\n");
915 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
916 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
922 int UtcDaliTransitionDataArrayP(void)
924 TestApplication application;
927 map1["target"] = "Actor1";
928 map1["property"] = "color";
929 map1["initialValue"] = Color::MAGENTA;
930 map1["targetValue"] = Color::RED;
931 map1["animator"] = Property::Map()
932 .Add("alphaFunction", "EASE_IN_OUT")
933 .Add("timePeriod", Property::Map()
935 .Add("duration", 1.0f));
938 map2["target"] = "Actor1";
939 map2["property"] = "position";
940 map2["initialValue"] = Vector3(100,0,0);
941 map2["targetValue"] = Vector3(0,100,0);
942 map2["animator"] = Property::Map()
943 .Add("alphaFunction", "EASE_IN_OUT")
944 .Add("timePeriod", Property::Map()
946 .Add("duration", 1.0f));
949 map3["target"] = "Actor1";
950 map3["property"] = "orientation";
951 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
953 Property::Array array;
954 array.PushBack(map1);
955 array.PushBack(map2);
956 array.PushBack(map3);
958 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
960 DummyControl actor = DummyControl::New();
961 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
962 actor.SetName("Actor1");
963 actor.SetColor(Color::CYAN);
964 Stage::GetCurrent().Add(actor);
965 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
967 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
968 Animation anim = dummyImpl.CreateTransition( transition );
969 DALI_TEST_CHECK( anim );
970 application.SendNotification();
971 application.Render(0);
972 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
973 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
976 application.SendNotification();
977 application.Render(0); // start map2 anim
978 application.SendNotification();
979 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
981 application.Render(500); // Start map1 animation, halfway thru map2 anim
982 application.SendNotification();
983 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
985 application.Render(500); // Halfway thru map1 anim, end of map2 anim
986 application.SendNotification();
987 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
988 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
990 application.Render(500); // End of map1 anim
991 application.SendNotification();
992 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
998 int UtcDaliTransitionDataGetAnimatorP(void)
1000 TestApplication application;
1003 map1["target"] = "Actor1";
1004 map1["property"] = "color";
1005 map1["initialValue"] = Color::MAGENTA;
1006 map1["targetValue"] = Color::RED;
1007 map1["animator"] = Property::Map()
1008 .Add("alphaFunction", "EASE_IN_SQUARE")
1009 .Add("timePeriod", Property::Map()
1011 .Add("duration", 0.5f));
1014 map2["target"] = "Actor1";
1015 map2["property"] = "position";
1016 map2["initialValue"] = Vector3(100,0,0);
1017 map2["targetValue"] = Vector3(0,100,0);
1018 map2["animator"] = Property::Map()
1019 .Add("alphaFunction", "EASE_OUT_SQUARE")
1020 .Add("timePeriod", Property::Map()
1022 .Add("duration", 2.0f));
1025 map3["target"] = "Actor1";
1026 map3["property"] = "size";
1027 map3["initialValue"] = Vector2(10,10);
1028 map3["targetValue"] = Vector2(100,100);
1029 map3["animator"] = Property::Map()
1030 .Add("alphaFunction", "EASE_OUT_SINE")
1031 .Add("timePeriod", Property::Map()
1033 .Add("duration", 3.0f));
1036 map4["target"] = "Actor2";
1037 map4["property"] = "color";
1038 map4["initialValue"] = Color::BLACK;
1039 map4["targetValue"] = Color::GREEN;
1040 map4["animator"] = Property::Map()
1041 .Add("alphaFunction", "EASE_IN_OUT_SINE")
1042 .Add("timePeriod", Property::Map()
1044 .Add("duration", 0.5f));
1047 map5["target"] = "Actor2";
1048 map5["property"] = "position";
1049 map5["initialValue"] = Vector3(100,0,0);
1050 map5["targetValue"] = Vector3(0,100,0);
1051 map5["animator"] = Property::Map()
1052 .Add("alphaFunction", "BOUNCE")
1053 .Add("timePeriod", Property::Map()
1055 .Add("duration", 2.0f));
1058 map6["target"] = "Actor2";
1059 map6["property"] = "size";
1060 map6["initialValue"] = Vector2(10,10);
1061 map6["targetValue"] = Vector2(100,100);
1062 map6["animator"] = Property::Map()
1063 .Add("alphaFunction", "SIN")
1064 .Add("timePeriod", Property::Map()
1066 .Add("duration", 3.0f));
1069 map7["target"] = "Actor4";
1070 map7["property"] = "sizeModeFactor";
1071 map7["initialValue"] = Vector3(1,1,1);
1072 map7["targetValue"] = Vector3(2,2,2);
1073 map7["animator"] = Property::Map()
1074 .Add("alphaFunction", "EASE_IN_SINE")
1075 .Add("timePeriod", Property::Map()
1077 .Add("duration", 1.0f));
1080 map8["target"] = "Visual1";
1081 map8["property"] = "opacity";
1082 map8["initialValue"] = 0.0f;
1083 map8["targetValue"] = 1.0f;
1084 map8["animator"] = Property::Map()
1085 .Add("alphaFunction", "EASE_IN")
1086 .Add("timePeriod", Property::Map()
1088 .Add("duration", 9.0f));
1091 map9["target"] = "Actor2";
1092 map9["property"] = "scale";
1093 map9["initialValue"] = Vector3(0,0,0);
1094 map9["targetValue"] = Vector3(1,1,1);
1095 map9["animator"] = Property::Map()
1096 .Add("alphaFunction", "REVERSE")
1097 .Add("timePeriod", Property::Map()
1099 .Add("duration", 1.0f));
1101 Property::Map map10;
1102 map10["target"] = "Actor2";
1103 map10["property"] = "scale";
1104 map10["initialValue"] = Vector3(0,0,0);
1105 map10["targetValue"] = Vector3(1,1,1);
1106 map10["animator"] = Property::Map()
1107 .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
1108 .Add("timePeriod", Property::Map()
1110 .Add("duration", 1.0f));
1112 Property::Map map11;
1113 map11["target"] = "Actor2";
1114 map11["property"] = "scale";
1115 map11["initialValue"] = Vector3(0,0,0);
1116 map11["targetValue"] = Vector3(1,1,1);
1117 map11["animator"] = Property::Map()
1118 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1119 .Add("timePeriod", Property::Map()
1121 .Add("duration", 1.0f));
1123 Property::Map map12;
1124 map12["target"] = "Actor1";
1125 map12["property"] = "orientation";
1126 map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
1128 Property::Array array;
1129 array.PushBack(map1);
1130 array.PushBack(map2);
1131 array.PushBack(map3);
1132 array.PushBack(map4);
1133 array.PushBack(map5);
1134 array.PushBack(map6);
1135 array.PushBack(map7);
1136 array.PushBack(map8);
1137 array.PushBack(map9);
1138 array.PushBack(map10);
1139 array.PushBack(map11);
1140 array.PushBack(map12);
1142 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1144 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
1146 for( unsigned int i=0; i < array.Count(); ++i )
1148 Property::Map animatorMap = transition.GetAnimatorAt(i);
1149 Property::Value& value = array.GetElementAt(i);
1150 Property::Map* inputMap = value.GetMap();
1151 DALI_TEST_CHECK( inputMap );
1152 CHECK_MAP_EQUALS( *inputMap, animatorMap );