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 <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.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
264 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
265 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
269 application.SendNotification();
270 application.Render(500); // Start animation
271 application.Render(500); // Halfway thru anim
272 application.SendNotification();
273 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
274 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
276 application.Render(500); // End of anim
277 application.SendNotification();
278 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
279 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
286 int UtcDaliTransitionDataMap2P(void)
288 TestApplication application;
290 tet_printf("Testing animation of a visual property using programmatic maps\n");
293 map["target"] = "visual1";
294 map["property"] = ColorVisual::Property::MIX_COLOR;
295 map["initialValue"] = Color::MAGENTA;
296 map["targetValue"] = Color::RED;
297 map["animator"] = Property::Map()
298 .Add("alphaFunction", "LINEAR")
299 .Add("timePeriod", Property::Map()
301 .Add("duration", 1.0f));
303 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
305 DummyControl actor = DummyControl::New();
306 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
307 actor.SetName("Actor1");
308 actor.SetColor(Color::CYAN);
309 Stage::GetCurrent().Add(actor);
311 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
313 Property::Map visualMap;
314 visualMap[Visual::Property::TYPE] = Visual::COLOR;
315 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
316 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
317 visual.SetName( "visual1" );
319 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
320 dummyImpl.RegisterVisual( visualIndex, visual );
322 Animation anim = dummyImpl.CreateTransition( transition );
323 DALI_TEST_CHECK( anim );
325 Renderer renderer = actor.GetRendererAt(0);
326 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
327 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
328 application.SendNotification();
329 application.Render(0);
331 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
332 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
333 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
334 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
338 application.SendNotification();
339 application.Render(0);
340 application.Render(500); // Start animation
341 application.Render(500); // Halfway thru anim
342 application.SendNotification();
343 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
344 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
346 application.Render(500); // End of anim
347 application.SendNotification();
348 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
349 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
355 int UtcDaliTransitionDataMap2Pb(void)
357 TestApplication application;
359 tet_printf("Testing animation of a visual property using programmatic maps\n");
362 map["target"] = "visual1";
363 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
364 map["initialValue"] = Color::MAGENTA;
365 map["targetValue"] = Color::RED;
366 map["animator"] = Property::Map()
367 .Add("alphaFunction", "LINEAR")
368 .Add("timePeriod", Property::Map()
370 .Add("duration", 1.0f));
372 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
374 DummyControl actor = DummyControl::New();
375 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
376 actor.SetName("Actor1");
377 actor.SetColor(Color::CYAN);
378 Stage::GetCurrent().Add(actor);
380 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
382 Property::Map visualMap;
383 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
384 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
385 visualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
386 visualMap[ PrimitiveVisual::Property::SLICES ] = 10;
387 visualMap[ PrimitiveVisual::Property::STACKS ] = 10;
389 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
390 visual.SetName( "visual1" );
392 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
393 dummyImpl.RegisterVisual( visualIndex, visual );
395 Animation anim = dummyImpl.CreateTransition( transition );
396 DALI_TEST_CHECK( anim );
398 Renderer renderer = actor.GetRendererAt(0);
399 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, PrimitiveVisual::Property::MIX_COLOR );
400 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
401 application.SendNotification();
402 application.Render(0);
404 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
405 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
406 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
407 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
411 application.SendNotification();
412 application.Render(0);
413 application.Render(500); // Start animation
414 application.Render(500); // Halfway thru anim
415 application.SendNotification();
416 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
417 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
419 application.Render(500); // End of anim
420 application.SendNotification();
421 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
422 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION);
428 int UtcDaliTransitionDataMap3P(void)
430 TestApplication application;
432 tet_printf("Testing animation of an actor's position property using bezier curve\n");
435 map["target"] = "Actor1";
436 map["property"] = "position";
437 map["initialValue"] = Vector3(0, 0, 0);
438 map["targetValue"] = Vector3(100, 100, 0);
439 map["animator"] = Property::Map()
440 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
441 .Add("timePeriod", Property::Map()
443 .Add("duration", 1.0f));
445 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
447 DummyControl actor = DummyControl::New();
448 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
449 actor.SetName("Actor1");
450 Stage::GetCurrent().Add(actor);
452 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
453 Animation anim = dummyImpl.CreateTransition( transition );
454 DALI_TEST_CHECK( anim );
456 application.SendNotification();
457 application.Render(0);
458 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,0,0), 0.001f, TEST_LOCATION);
462 application.SendNotification();
463 application.Render(0);
465 application.Render(250); // 25%
466 application.SendNotification();
467 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%
469 application.Render(250); // Halfway thru map1 anim
470 application.SendNotification();
471 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%
473 application.Render(250); // End of map1 anim
474 application.SendNotification();
475 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
477 application.Render(250); // End of map1 anim
478 application.SendNotification();
479 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,100,0), TEST_LOCATION );
484 int UtcDaliTransitionDataMap4P(void)
486 TestApplication application;
488 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
491 map1["target"] = "testVisual";
492 map1["property"] = "offset";
493 map1["initialValue"] = Vector2(0.0f, 0.0f);
494 map1["targetValue"] = Vector2(100.0f, 100.0f);
495 map1["animator"] = Property::Map()
496 .Add("alphaFunction", "LINEAR")
497 .Add("timePeriod", Property::Map()
499 .Add("duration", 1.0f));
502 map2["target"] = "testVisual";
503 map2["property"] = "size";
504 map2["initialValue"] = Vector2(10.0f, 10.0f);
505 map2["targetValue"] = Vector2(110.0f, 110.0f);
506 map2["animator"] = Property::Map()
507 .Add("alphaFunction", "LINEAR")
508 .Add("timePeriod", Property::Map()
510 .Add("duration", 1.0f));
512 Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) );
514 DummyControl actor = DummyControl::New();
515 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
516 actor.SetName("Actor1");
517 Stage::GetCurrent().Add(actor);
519 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
521 Property::Map visualMap;
522 visualMap[Visual::Property::TYPE] = Visual::COLOR;
523 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
524 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
526 visual.SetName( "testVisual" );
527 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
529 Animation anim = dummyImpl.CreateTransition( transition );
530 DALI_TEST_CHECK( anim );
532 Renderer renderer = actor.GetRendererAt(0);
533 Property::Index sizeIndex = renderer.GetPropertyIndex( "size" );
534 application.SendNotification();
535 application.Render(0);
537 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
538 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(10.0f, 10.0f), TEST_LOCATION);
542 application.SendNotification();
543 application.Render(0);
544 application.Render(500); // Start animation
545 application.Render(500); // Halfway thru anim
546 application.SendNotification();
547 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(60.0f, 60.0f), TEST_LOCATION);
549 application.Render(500); // End of anim
550 application.SendNotification();
551 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(110.0f, 110.0f), TEST_LOCATION );
556 int UtcDaliTransitionDataMap5P(void)
558 TestApplication application;
560 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
563 map["target"] = "visual1";
564 map["property"] = "opacity";
565 map["initialValue"] = 0.0f;
566 map["targetValue"] = 1.0f;
567 map["animator"] = Property::Map()
568 .Add("alphaFunction", "EASE_IN_OUT")
569 .Add("timePeriod", Property::Map()
571 .Add("duration", 1.0f));
573 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
575 DummyControl actor = DummyControl::New();
576 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
577 actor.SetName("Actor1");
578 actor.SetColor(Color::CYAN);
579 Stage::GetCurrent().Add(actor);
581 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
583 Property::Map visualMap;
584 visualMap[Visual::Property::TYPE] = Visual::COLOR;
585 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
586 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
587 visual.SetName( "visual1" );
589 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
590 dummyImpl.RegisterVisual( visualIndex, visual );
592 Animation anim = dummyImpl.CreateTransition( transition );
593 DALI_TEST_CHECK( anim );
595 Renderer renderer = actor.GetRendererAt(0);
596 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
597 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
598 application.SendNotification();
599 application.Render(0);
601 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
602 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 0.0f, 0.001f, TEST_LOCATION );
603 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
605 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
606 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.0f, 0.001f, TEST_LOCATION );
607 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
611 application.SendNotification();
612 application.Render(500); // Start animation
613 application.Render(500); // Halfway thru anim
614 application.SendNotification();
615 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
616 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.5f, 0.001f, TEST_LOCATION );
617 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
619 application.Render(501); // End of anim
620 application.SendNotification();
621 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
622 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
623 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::AUTO, TEST_LOCATION );
629 int UtcDaliTransitionDataMap6P(void)
631 TestApplication application;
633 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
636 map["target"] = "visual1";
637 map["property"] = "opacity";
638 map["targetValue"] = 0.0f;
639 map["animator"] = Property::Map()
640 .Add("alphaFunction", "EASE_IN_OUT")
641 .Add("timePeriod", Property::Map()
643 .Add("duration", 1.0f));
645 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
647 DummyControl actor = DummyControl::New();
648 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
649 actor.SetName("Actor1");
650 actor.SetColor(Color::CYAN);
651 Stage::GetCurrent().Add(actor);
653 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
655 Property::Map visualMap;
656 visualMap[Visual::Property::TYPE] = Visual::COLOR;
657 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
658 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
659 visual.SetName( "visual1" );
661 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
662 dummyImpl.RegisterVisual( visualIndex, visual );
664 Animation anim = dummyImpl.CreateTransition( transition );
665 DALI_TEST_CHECK( anim );
667 Renderer renderer = actor.GetRendererAt(0);
668 Property::Index mixColorIndex = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
669 Property::Index opacityIndex = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
670 application.SendNotification();
671 application.Render(0);
673 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
674 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
675 DALI_TEST_EQUALS( renderer.GetProperty<float>(opacityIndex), 1.0f, 0.001f, TEST_LOCATION );
676 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 1.0f, 0.001f, TEST_LOCATION );
678 // Note, This should be testing for AUTO
679 // this is the same problem as C# target value being set before Play is called.
680 // @todo How was this solved?
681 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::BLEND_MODE), (int)BlendMode::ON, TEST_LOCATION );
682 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
686 application.SendNotification();
687 application.Render(500); // Start animation
688 application.Render(500); // Halfway thru anim
689 application.SendNotification();
690 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
691 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.5f, 0.001f, TEST_LOCATION );
692 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
694 application.Render(500); // End of anim
695 application.SendNotification();
696 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
697 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( opacityIndex ), 0.0f, 0.001f, TEST_LOCATION );
698 DALI_TEST_EQUALS( renderer.GetCurrentProperty< int >( Renderer::Property::BLEND_MODE ), (int)BlendMode::ON, TEST_LOCATION );
704 int UtcDaliTransitionDataMap1N(void)
706 TestApplication application;
709 map["target"] = "Actor1";
710 map["property"] = "randomProperty";
711 map["initialValue"] = Color::MAGENTA;
712 map["targetValue"] = Color::RED;
713 map["animator"] = Property::Map()
714 .Add("alphaFunction", "EASE_OUT")
715 .Add("timePeriod", Property::Map()
717 .Add("duration", 1.0f));
719 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
721 DummyControl actor = DummyControl::New();
722 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
723 actor.SetName("Actor1");
724 actor.SetColor(Color::CYAN);
725 Stage::GetCurrent().Add(actor);
727 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
728 Animation anim = dummyImpl.CreateTransition( transition );
729 DALI_TEST_CHECK( ! anim );
731 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
736 int UtcDaliTransitionDataMapN3(void)
738 TestApplication application;
740 tet_printf("Testing visual lookup with no renderers\n");
743 map["target"] = "visual1";
744 map["property"] = "mixColor";
745 map["initialValue"] = Vector3(Color::MAGENTA);
746 map["targetValue"] = Vector3(Color::RED);
747 map["animator"] = Property::Map()
748 .Add("alphaFunction", "EASE_OUT_BACK")
749 .Add("timePeriod", Property::Map()
751 .Add("duration", 1.0f));
753 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
754 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
756 DummyControl actor = DummyControl::New();
757 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
758 actor.SetName("Actor1");
759 actor.SetColor(Color::CYAN);
762 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
763 Property::Map visualMap;
764 visualMap[Visual::Property::TYPE] = Visual::COLOR;
765 visualMap[ColorVisual::Property::MIX_COLOR] = Vector3(Color::MAGENTA);
766 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
767 visual.SetName( "visual1" );
769 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
770 dummyImpl.RegisterVisual( visualIndex, visual );
772 Animation anim = dummyImpl.CreateTransition( transition );
773 DALI_TEST_CHECK( !anim );
778 int UtcDaliTransitionDataMapN4(void)
780 TestApplication application;
782 tet_printf("Testing visual doesn't animate with duff bezier data \n");
785 map["target"] = "visual1";
786 map["property"] = "mixColor";
787 map["initialValue"] = Vector3(Color::MAGENTA);
788 map["targetValue"] = Vector3(Color::RED);
789 map["animator"] = Property::Map()
790 .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
791 .Add("timePeriod", Property::Map()
793 .Add("duration", 1.0f));
795 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
797 DummyControl actor = DummyControl::New();
798 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
799 actor.SetName("Actor1");
800 actor.SetColor(Color::CYAN);
801 Stage::GetCurrent().Add(actor);
803 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
804 Property::Map visualMap;
805 visualMap[Visual::Property::TYPE] = Visual::COLOR;
806 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
807 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
808 visual.SetName( "visual1" );
810 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
811 dummyImpl.RegisterVisual( visualIndex, visual );
813 Animation anim = dummyImpl.CreateTransition( transition );
814 DALI_TEST_CHECK( !anim );
816 application.SendNotification();
817 application.Render(0);
818 application.SendNotification();
820 Renderer renderer = actor.GetRendererAt(0);
821 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
822 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
824 tet_printf( "Test that the property has been set to target value\n");
825 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
826 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
831 int UtcDaliTransitionDataMapN5(void)
833 TestApplication application;
835 tet_printf("Testing visual doesn't animate with duff bezier data \n");
838 map["target"] = "visual1";
839 map["property"] = "mixColor";
840 map["initialValue"] = Color::MAGENTA;
841 map["targetValue"] = Color::RED;
842 map["animator"] = Property::Map()
843 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
844 .Add("timePeriod", Property::Map()
846 .Add("duration", 1.0f));
848 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
850 DummyControl actor = DummyControl::New();
851 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
852 actor.SetName("Actor1");
853 actor.SetColor(Color::CYAN);
854 Stage::GetCurrent().Add(actor);
856 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
857 Property::Map visualMap;
858 visualMap[Visual::Property::TYPE] = Visual::COLOR;
859 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
860 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
861 visual.SetName( "visual1" );
863 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
864 dummyImpl.RegisterVisual( visualIndex, visual );
866 Animation anim = dummyImpl.CreateTransition( transition );
867 DALI_TEST_CHECK( !anim );
869 application.SendNotification();
870 application.Render(0);
871 application.SendNotification();
873 Renderer renderer = actor.GetRendererAt(0);
874 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
876 tet_printf( "Test that the property has been set to target value\n");
877 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
882 int UtcDaliTransitionDataMapN6(void)
884 TestApplication application;
886 tet_printf("Testing visual doesn't animate with duff bezier data \n");
889 map["target"] = "visual1";
890 map["property"] = "mixColor";
891 map["initialValue"] = Color::MAGENTA;
892 map["targetValue"] = Color::RED;
893 map["animator"] = Property::Map()
894 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
895 .Add("timePeriod", Property::Map()
897 .Add("duration", 1.0f));
899 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
901 DummyControl actor = DummyControl::New();
902 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
903 actor.SetName("Actor1");
904 actor.SetColor(Color::CYAN);
905 Stage::GetCurrent().Add(actor);
907 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
908 Property::Map visualMap;
909 visualMap[Visual::Property::TYPE] = Visual::COLOR;
910 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
911 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
912 visual.SetName( "visual1" );
914 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
915 dummyImpl.RegisterVisual( visualIndex, visual );
917 Animation anim = dummyImpl.CreateTransition( transition );
918 DALI_TEST_CHECK( !anim );
920 application.SendNotification();
921 application.Render(0);
922 application.SendNotification();
924 Renderer renderer = actor.GetRendererAt(0);
925 Property::Index mixColorIdx = DevelHandle::GetPropertyIndex( renderer, ColorVisual::Property::MIX_COLOR );
926 Property::Index opacityIdx = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
928 tet_printf( "Test that the property has been set to target value\n");
929 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
930 DALI_TEST_EQUALS(renderer.GetProperty<float>(opacityIdx), 1.0f, 0.001, TEST_LOCATION);
936 int UtcDaliTransitionDataArrayP(void)
938 TestApplication application;
941 map1["target"] = "Actor1";
942 map1["property"] = "color";
943 map1["initialValue"] = Color::MAGENTA;
944 map1["targetValue"] = Color::RED;
945 map1["animator"] = Property::Map()
946 .Add("alphaFunction", "EASE_IN_OUT")
947 .Add("timePeriod", Property::Map()
949 .Add("duration", 1.0f));
952 map2["target"] = "Actor1";
953 map2["property"] = "position";
954 map2["initialValue"] = Vector3(100,0,0);
955 map2["targetValue"] = Vector3(0,100,0);
956 map2["animator"] = Property::Map()
957 .Add("alphaFunction", "EASE_IN_OUT")
958 .Add("timePeriod", Property::Map()
960 .Add("duration", 1.0f));
963 map3["target"] = "Actor1";
964 map3["property"] = "orientation";
965 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
967 Property::Array array;
968 array.PushBack(map1);
969 array.PushBack(map2);
970 array.PushBack(map3);
972 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
974 DummyControl actor = DummyControl::New();
975 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
976 actor.SetName("Actor1");
977 actor.SetColor(Color::CYAN);
978 Stage::GetCurrent().Add(actor);
979 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
981 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
982 Animation anim = dummyImpl.CreateTransition( transition );
983 DALI_TEST_CHECK( anim );
984 application.SendNotification();
985 application.Render(0);
986 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION);
987 DALI_TEST_EQUALS( actor.GetCurrentOrientation(), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
990 application.SendNotification();
991 application.Render(0); // start map2 anim
992 application.SendNotification();
993 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(100,0,0), TEST_LOCATION);
995 application.Render(500); // Start map1 animation, halfway thru map2 anim
996 application.SendNotification();
997 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(50,50,0), TEST_LOCATION);
999 application.Render(500); // Halfway thru map1 anim, end of map2 anim
1000 application.SendNotification();
1001 DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3(0,100,0), TEST_LOCATION);
1002 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
1004 application.Render(500); // End of map1 anim
1005 application.SendNotification();
1006 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::RED, TEST_LOCATION );
1012 int UtcDaliTransitionDataGetAnimatorP(void)
1014 TestApplication application;
1017 map1["target"] = "Actor1";
1018 map1["property"] = "color";
1019 map1["initialValue"] = Color::MAGENTA;
1020 map1["targetValue"] = Color::RED;
1021 map1["animator"] = Property::Map()
1022 .Add("alphaFunction", "EASE_IN_SQUARE")
1023 .Add("timePeriod", Property::Map()
1025 .Add("duration", 0.5f));
1028 map2["target"] = "Actor1";
1029 map2["property"] = "position";
1030 map2["initialValue"] = Vector3(100,0,0);
1031 map2["targetValue"] = Vector3(0,100,0);
1032 map2["animator"] = Property::Map()
1033 .Add("alphaFunction", "EASE_OUT_SQUARE")
1034 .Add("timePeriod", Property::Map()
1036 .Add("duration", 2.0f));
1039 map3["target"] = "Actor1";
1040 map3["property"] = "size";
1041 map3["initialValue"] = Vector2(10,10);
1042 map3["targetValue"] = Vector2(100,100);
1043 map3["animator"] = Property::Map()
1044 .Add("alphaFunction", "EASE_OUT_SINE")
1045 .Add("timePeriod", Property::Map()
1047 .Add("duration", 3.0f));
1050 map4["target"] = "Actor2";
1051 map4["property"] = "color";
1052 map4["initialValue"] = Color::BLACK;
1053 map4["targetValue"] = Color::GREEN;
1054 map4["animator"] = Property::Map()
1055 .Add("alphaFunction", "EASE_IN_OUT_SINE")
1056 .Add("timePeriod", Property::Map()
1058 .Add("duration", 0.5f));
1061 map5["target"] = "Actor2";
1062 map5["property"] = "position";
1063 map5["initialValue"] = Vector3(100,0,0);
1064 map5["targetValue"] = Vector3(0,100,0);
1065 map5["animator"] = Property::Map()
1066 .Add("alphaFunction", "BOUNCE")
1067 .Add("timePeriod", Property::Map()
1069 .Add("duration", 2.0f));
1072 map6["target"] = "Actor2";
1073 map6["property"] = "size";
1074 map6["initialValue"] = Vector2(10,10);
1075 map6["targetValue"] = Vector2(100,100);
1076 map6["animator"] = Property::Map()
1077 .Add("alphaFunction", "SIN")
1078 .Add("timePeriod", Property::Map()
1080 .Add("duration", 3.0f));
1083 map7["target"] = "Actor4";
1084 map7["property"] = "sizeModeFactor";
1085 map7["initialValue"] = Vector3(1,1,1);
1086 map7["targetValue"] = Vector3(2,2,2);
1087 map7["animator"] = Property::Map()
1088 .Add("alphaFunction", "EASE_IN_SINE")
1089 .Add("timePeriod", Property::Map()
1091 .Add("duration", 1.0f));
1094 map8["target"] = "Visual1";
1095 map8["property"] = "opacity";
1096 map8["initialValue"] = 0.0f;
1097 map8["targetValue"] = 1.0f;
1098 map8["animator"] = Property::Map()
1099 .Add("alphaFunction", "EASE_IN")
1100 .Add("timePeriod", Property::Map()
1102 .Add("duration", 9.0f));
1105 map9["target"] = "Actor2";
1106 map9["property"] = "scale";
1107 map9["initialValue"] = Vector3(0,0,0);
1108 map9["targetValue"] = Vector3(1,1,1);
1109 map9["animator"] = Property::Map()
1110 .Add("alphaFunction", "REVERSE")
1111 .Add("timePeriod", Property::Map()
1113 .Add("duration", 1.0f));
1115 Property::Map map10;
1116 map10["target"] = "Actor2";
1117 map10["property"] = "scale";
1118 map10["initialValue"] = Vector3(0,0,0);
1119 map10["targetValue"] = Vector3(1,1,1);
1120 map10["animator"] = Property::Map()
1121 .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
1122 .Add("timePeriod", Property::Map()
1124 .Add("duration", 1.0f));
1126 Property::Map map11;
1127 map11["target"] = "Actor2";
1128 map11["property"] = "scale";
1129 map11["initialValue"] = Vector3(0,0,0);
1130 map11["targetValue"] = Vector3(1,1,1);
1131 map11["animator"] = Property::Map()
1132 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1133 .Add("timePeriod", Property::Map()
1135 .Add("duration", 1.0f));
1137 Property::Map map12;
1138 map12["target"] = "Actor1";
1139 map12["property"] = "orientation";
1140 map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
1142 Property::Array array;
1143 array.PushBack(map1);
1144 array.PushBack(map2);
1145 array.PushBack(map3);
1146 array.PushBack(map4);
1147 array.PushBack(map5);
1148 array.PushBack(map6);
1149 array.PushBack(map7);
1150 array.PushBack(map8);
1151 array.PushBack(map9);
1152 array.PushBack(map10);
1153 array.PushBack(map11);
1154 array.PushBack(map12);
1156 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1158 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
1160 for( unsigned int i=0; i < array.Count(); ++i )
1162 Property::Map animatorMap = transition.GetAnimatorAt(i);
1163 Property::Value& value = array.GetElementAt(i);
1164 Property::Map* inputMap = value.GetMap();
1165 DALI_TEST_CHECK( inputMap );
1166 CHECK_MAP_EQUALS( *inputMap, animatorMap );