2 * Copyright (c) 2021 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/rendering/renderer-devel.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include "dummy-control.h"
28 using namespace Toolkit;
31 void utc_dali_toolkit_transition_data_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_transition_data_cleanup(void)
38 test_return_value = TET_PASS;
41 Property::Map CreateMap()
45 map["target"] = "Actor1";
46 map["property"] = "color";
47 map["initialValue"] = Color::MAGENTA;
48 map["targetValue"] = Color::RED;
49 map["animator"] = Property::Map()
50 .Add("alphaFunction", "EASE_IN_OUT_BACK")
51 .Add("timePeriod", Property::Map()
53 .Add("duration", 1.0f));
57 void CHECK_ARRAY_EQUALS( Property::Array test, Property::Value result )
59 if( result.GetType() == Property::ARRAY )
62 Property::Array *resultArray = result.GetArray();
63 DALI_TEST_EQUALS( test.Count(), resultArray->Count(), TEST_LOCATION );
64 for( size_t i=0; i < std::min(test.Count(), resultArray->Count()); ++i )
66 Property::Value a = test.GetElementAt(i);
67 Property::Value b = resultArray->GetElementAt(i);
68 DALI_TEST_EQUALS( a.GetType(), b.GetType(), TEST_LOCATION );
69 DALI_TEST_EQUALS( a, b, 0.001, TEST_LOCATION );
72 else if( result.GetType() == Property::VECTOR4 )
74 Vector4 value = result.Get<Vector4>();
75 DALI_TEST_CHECK( test.Count() >= 4 );
76 for( size_t i=0; i < 4; ++i )
78 Property::Value a = test.GetElementAt(i);
79 DALI_TEST_EQUALS( a.GetType(), Property::FLOAT, TEST_LOCATION );
80 DALI_TEST_EQUALS( a.Get<float>(), value[i], 0.001, TEST_LOCATION );
89 void CHECK_MAP_EQUALS( Property::Map test, Property::Map result )
91 DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
93 for( unsigned int i=0; i< test.Count(); ++i )
95 KeyValuePair keyValue = test.GetKeyValue(i);
96 Property::Value* value;
98 if( keyValue.first.type == Property::Key::STRING )
100 value = result.Find(keyValue.first.stringKey);
104 value = result.Find(keyValue.first.indexKey);
107 DALI_TEST_CHECK( value != NULL );
110 if( keyValue.second.GetType() == Property::MAP )
112 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
113 CHECK_MAP_EQUALS( *(keyValue.second.GetMap()), *(value->GetMap()) );
115 else if( keyValue.second.GetType() == Property::ARRAY )
117 CHECK_ARRAY_EQUALS( *(keyValue.second.GetArray()), *value );
119 else if( keyValue.second.GetType() == Property::STRING )
121 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
124 DALI_TEST_EQUALS( keyValue.second, str.c_str(), TEST_LOCATION );
128 DALI_TEST_EQUALS( keyValue.second.GetType(), value->GetType(), TEST_LOCATION );
129 DALI_TEST_EQUALS( keyValue.second, *value, 0.001f, TEST_LOCATION );
136 int UtcDaliTransitionDataNew(void)
138 ToolkitTestApplication application;
140 Property::Map map = CreateMap();
141 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
142 DALI_TEST_CHECK( transition );
147 int UtcDaliTransitionDataDownCast(void)
149 ToolkitTestApplication application;
151 Property::Map map = CreateMap();
153 BaseHandle handle = TransitionData::New( map );
154 DALI_TEST_CHECK( handle );
156 TransitionData transitionData = TransitionData::DownCast( handle );
157 DALI_TEST_CHECK( transitionData );
161 int UtcDaliTransitionDataCopyConstructor(void)
163 ToolkitTestApplication application;
165 Property::Map map = CreateMap();
167 TransitionData transitionData = TransitionData::New( map );
168 DALI_TEST_CHECK( transitionData );
170 TransitionData td2( transitionData );
171 DALI_TEST_CHECK( td2 );
172 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
176 int UtcDaliTransitionDataAssignmentOperator(void)
178 ToolkitTestApplication application;
180 Property::Map map = CreateMap();
182 TransitionData transitionData = TransitionData::New( map );
183 DALI_TEST_CHECK( transitionData );
186 DALI_TEST_CHECK( !td2 );
188 td2 = transitionData;
189 DALI_TEST_CHECK( td2 );
191 DALI_TEST_EQUALS( td2.Count(), 1, TEST_LOCATION );
195 int UtcDaliTransitionDataCount(void)
197 ToolkitTestApplication application;
199 Property::Map map = CreateMap();
200 TransitionData transitionData = TransitionData::New( map );
201 DALI_TEST_CHECK( transitionData );
202 DALI_TEST_EQUALS( transitionData.Count(), 1, TEST_LOCATION );
204 Property::Array array;
205 array.PushBack( map );
206 array.PushBack( map );
207 array.PushBack( map );
209 TransitionData transitionData2 = TransitionData::New( array );
210 DALI_TEST_CHECK( transitionData2 );
211 DALI_TEST_EQUALS( transitionData2.Count(), 3, TEST_LOCATION );
216 int UtcDaliTransitionDataMap1P(void)
218 ToolkitTestApplication application;
220 tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
223 map["target"] = "visual1";
224 map["property"] = "mixColor";
225 map["initialValue"] = Color::MAGENTA;
226 map["targetValue"] = Color::RED;
227 map["animator"] = Property::Map()
228 .Add("alphaFunction", "EASE_IN_OUT")
229 .Add("timePeriod", Property::Map()
231 .Add("duration", 1.0f));
233 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
235 DummyControl actor = DummyControl::New();
236 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
237 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
238 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
239 application.GetScene().Add(actor);
241 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
243 Property::Map visualMap;
244 visualMap[Visual::Property::TYPE] = Visual::COLOR;
245 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
246 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
247 visual.SetName( "visual1" );
249 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
250 dummyImpl.RegisterVisual( visualIndex, visual );
252 Animation anim = dummyImpl.CreateTransition( transition );
253 DALI_TEST_CHECK( anim );
255 Renderer renderer = actor.GetRendererAt(0);
256 Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
257 application.SendNotification();
258 application.Render(0);
260 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
261 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
262 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
263 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 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.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
272 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
274 application.Render(500); // End of anim
275 application.SendNotification();
276 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
277 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
284 int UtcDaliTransitionDataMap2P(void)
286 ToolkitTestApplication 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.SetProperty( Dali::Actor::Property::NAME,"Actor1");
306 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
307 application.GetScene().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 = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
325 application.SendNotification();
326 application.Render(0);
328 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
329 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
330 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
331 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
335 application.SendNotification();
336 application.Render(0);
337 application.Render(500); // Start animation
338 application.Render(500); // Halfway thru anim
339 application.SendNotification();
340 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
341 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
343 application.Render(500); // End of anim
344 application.SendNotification();
345 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
346 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
352 int UtcDaliTransitionDataMap2Pb(void)
354 ToolkitTestApplication application;
356 tet_printf("Testing animation of a visual property using programmatic maps\n");
359 map["target"] = "visual1";
360 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
361 map["initialValue"] = Color::MAGENTA;
362 map["targetValue"] = Color::RED;
363 map["animator"] = Property::Map()
364 .Add("alphaFunction", "LINEAR")
365 .Add("timePeriod", Property::Map()
367 .Add("duration", 1.0f));
369 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
371 DummyControl actor = DummyControl::New();
372 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
373 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
374 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
375 application.GetScene().Add(actor);
377 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
379 Property::Map visualMap;
380 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
381 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
382 visualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
383 visualMap[ PrimitiveVisual::Property::SLICES ] = 10;
384 visualMap[ PrimitiveVisual::Property::STACKS ] = 10;
386 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
387 visual.SetName( "visual1" );
389 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
390 dummyImpl.RegisterVisual( visualIndex, visual );
392 Animation anim = dummyImpl.CreateTransition( transition );
393 DALI_TEST_CHECK( anim );
395 Renderer renderer = actor.GetRendererAt(0);
396 Property::Index mixColorIndex = renderer.GetPropertyIndex( PrimitiveVisual::Property::MIX_COLOR );
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.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
402 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
403 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
407 application.SendNotification();
408 application.Render(0);
409 application.Render(500); // Start animation
410 application.Render(500); // Halfway thru anim
411 application.SendNotification();
412 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
413 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
415 application.Render(500); // End of anim
416 application.SendNotification();
417 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::RED), TEST_LOCATION );
418 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION);
424 int UtcDaliTransitionDataMap3P(void)
426 ToolkitTestApplication application;
428 tet_printf("Testing animation of an actor's position property using bezier curve\n");
431 map["target"] = "Actor1";
432 map["property"] = "position";
433 map["initialValue"] = Vector3(0, 0, 0);
434 map["targetValue"] = Vector3(100, 100, 0);
435 map["animator"] = Property::Map()
436 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38) )
437 .Add("timePeriod", Property::Map()
439 .Add("duration", 1.0f));
441 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
443 DummyControl actor = DummyControl::New();
444 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
445 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
446 application.GetScene().Add(actor);
448 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
449 Animation anim = dummyImpl.CreateTransition( transition );
450 DALI_TEST_CHECK( anim );
452 application.SendNotification();
453 application.Render(0);
454 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(0,0,0), 0.001f, TEST_LOCATION);
458 application.SendNotification();
459 application.Render(0);
461 application.Render(250); // 25%
462 application.SendNotification();
463 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(-10,-10,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50%
465 application.Render(250); // Halfway thru map1 anim
466 application.SendNotification();
467 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(24,24,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve at 50%
469 application.Render(250); // End of map1 anim
470 application.SendNotification();
471 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100,100,0), 1.0, TEST_LOCATION); // High epsilon as we don't have exact figure for bezier curve
473 application.Render(250); // End of map1 anim
474 application.SendNotification();
475 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100,100,0), TEST_LOCATION );
480 int UtcDaliTransitionDataMap4P(void)
482 ToolkitTestApplication application;
484 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
487 map1["target"] = "testVisual";
488 map1["property"] = "offset";
489 map1["initialValue"] = Vector2(0.0f, 0.0f);
490 map1["targetValue"] = Vector2(100.0f, 100.0f);
491 map1["animator"] = Property::Map()
492 .Add("alphaFunction", "LINEAR")
493 .Add("timePeriod", Property::Map()
495 .Add("duration", 1.0f));
498 map2["target"] = "testVisual";
499 map2["property"] = "size";
500 map2["initialValue"] = Vector2(10.0f, 10.0f);
501 map2["targetValue"] = Vector2(110.0f, 110.0f);
502 map2["animator"] = Property::Map()
503 .Add("alphaFunction", "LINEAR")
504 .Add("timePeriod", Property::Map()
506 .Add("duration", 1.0f));
508 Dali::Toolkit::TransitionData transition = TransitionData::New( Property::Array().Add(map1).Add(map2) );
510 DummyControl actor = DummyControl::New();
511 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
512 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
513 application.GetScene().Add(actor);
515 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
517 Property::Map visualMap;
518 visualMap[Visual::Property::TYPE] = Visual::COLOR;
519 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
520 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
522 visual.SetName( "testVisual" );
523 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
525 Animation anim = dummyImpl.CreateTransition( transition );
526 DALI_TEST_CHECK( anim );
528 Renderer renderer = actor.GetRendererAt(0);
529 Property::Index sizeIndex = renderer.GetPropertyIndex( "size" );
530 application.SendNotification();
531 application.Render(0);
533 DALI_TEST_EQUALS( renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
534 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(10.0f, 10.0f), TEST_LOCATION);
538 application.SendNotification();
539 application.Render(0);
540 application.Render(500); // Start animation
541 application.Render(500); // Halfway thru anim
542 application.SendNotification();
543 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(60.0f, 60.0f), TEST_LOCATION);
545 application.Render(500); // End of anim
546 application.SendNotification();
547 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector2 >( sizeIndex ), Vector2(110.0f, 110.0f), TEST_LOCATION );
552 int UtcDaliTransitionDataMap5P(void)
554 ToolkitTestApplication application;
556 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
559 map["target"] = "visual1";
560 map["property"] = "opacity";
561 map["initialValue"] = 0.0f;
562 map["targetValue"] = 1.0f;
563 map["animator"] = Property::Map()
564 .Add("alphaFunction", "EASE_IN_OUT")
565 .Add("timePeriod", Property::Map()
567 .Add("duration", 1.0f));
569 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
571 DummyControl actor = DummyControl::New();
572 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
573 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
574 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
575 application.GetScene().Add(actor);
577 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
579 Property::Map visualMap;
580 visualMap[Visual::Property::TYPE] = Visual::COLOR;
581 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
582 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
583 visual.SetName( "visual1" );
585 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
586 dummyImpl.RegisterVisual( visualIndex, visual );
588 Animation anim = dummyImpl.CreateTransition( transition );
589 DALI_TEST_CHECK( anim );
591 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
592 glAbstraction.EnableEnableDisableCallTrace( true );
593 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
594 std::ostringstream blendStr;
595 blendStr << std::hex << GL_BLEND;
597 Renderer renderer = actor.GetRendererAt(0);
598 Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
599 application.SendNotification();
600 application.Render(0);
602 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
603 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
605 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
606 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
608 // The Renderer is transparent. So rendering is skipped. The state should not be changed.
609 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
610 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
614 glEnableStack.Reset();
616 application.SendNotification();
617 application.Render(500); // Start animation
618 application.Render(500); // Halfway thru anim
619 application.SendNotification();
620 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
621 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
623 // Should not be changed
624 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
626 glEnableStack.Reset();
628 application.Render(501); // End of anim
629 application.SendNotification();
630 application.Render();
631 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
632 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
634 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
640 int UtcDaliTransitionDataMap6P(void)
642 ToolkitTestApplication application;
644 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
647 map["target"] = "visual1";
648 map["property"] = "opacity";
649 map["targetValue"] = 0.0f;
650 map["animator"] = Property::Map()
651 .Add("alphaFunction", "EASE_IN_OUT")
652 .Add("timePeriod", Property::Map()
654 .Add("duration", 1.0f));
656 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
658 DummyControl actor = DummyControl::New();
659 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
660 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
661 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
662 application.GetScene().Add(actor);
664 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
666 Property::Map visualMap;
667 visualMap[Visual::Property::TYPE] = Visual::COLOR;
668 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
669 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
670 visual.SetName( "visual1" );
672 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
673 dummyImpl.RegisterVisual( visualIndex, visual );
675 Animation anim = dummyImpl.CreateTransition( transition );
676 DALI_TEST_CHECK( anim );
678 Renderer renderer = actor.GetRendererAt(0);
679 Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
681 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
682 glAbstraction.EnableEnableDisableCallTrace( true );
683 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
684 std::ostringstream blendStr;
685 blendStr << std::hex << GL_BLEND;
687 application.SendNotification();
688 application.Render(0);
690 DALI_TEST_EQUALS( renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
691 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
692 DALI_TEST_EQUALS( renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
693 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
695 // Default state is disabled. So test if "Enabled" is not called.
696 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
700 glEnableStack.Reset();
702 application.SendNotification();
703 application.Render(500); // Start animation
704 application.Render(500); // Halfway thru anim
705 application.SendNotification();
707 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
708 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
710 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
712 glEnableStack.Reset();
714 application.Render(500); // End of anim
715 application.SendNotification();
717 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
718 DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
720 // GL_BLEND should not be changed: Keep enabled
721 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
727 int UtcDaliTransitionDataMap1N(void)
729 ToolkitTestApplication application;
732 map["target"] = "Actor1";
733 map["property"] = "randomProperty";
734 map["initialValue"] = Color::MAGENTA;
735 map["targetValue"] = Color::RED;
736 map["animator"] = Property::Map()
737 .Add("alphaFunction", "EASE_OUT")
738 .Add("timePeriod", Property::Map()
740 .Add("duration", 1.0f));
742 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
744 DummyControl actor = DummyControl::New();
745 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
746 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
747 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
748 application.GetScene().Add(actor);
750 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
751 Animation anim = dummyImpl.CreateTransition( transition );
752 DALI_TEST_CHECK( ! anim );
754 CHECK_MAP_EQUALS( map, transition.GetAnimatorAt(0) );
758 int UtcDaliTransitionDataMapN4(void)
760 ToolkitTestApplication application;
762 tet_printf("Testing visual doesn't animate with duff bezier data \n");
765 map["target"] = "visual1";
766 map["property"] = "mixColor";
767 map["initialValue"] = Vector3(Color::MAGENTA);
768 map["targetValue"] = Vector3(Color::RED);
769 map["animator"] = Property::Map()
770 .Add("alphaFunction", Vector3(.1f,1.0f,0.5f))
771 .Add("timePeriod", Property::Map()
773 .Add("duration", 1.0f));
775 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
777 DummyControl actor = DummyControl::New();
778 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
779 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
780 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
781 application.GetScene().Add(actor);
783 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
784 Property::Map visualMap;
785 visualMap[Visual::Property::TYPE] = Visual::COLOR;
786 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
787 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
788 visual.SetName( "visual1" );
790 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
791 dummyImpl.RegisterVisual( visualIndex, visual );
793 Animation anim = dummyImpl.CreateTransition( transition );
794 DALI_TEST_CHECK( !anim );
796 application.SendNotification();
797 application.Render(0);
798 application.SendNotification();
800 Renderer renderer = actor.GetRendererAt(0);
801 Property::Index mixColorIdx = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
803 tet_printf( "Test that the property has been set to target value\n");
804 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
805 DALI_TEST_EQUALS(renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001, TEST_LOCATION);
810 int UtcDaliTransitionDataMapN5(void)
812 ToolkitTestApplication application;
814 tet_printf("Testing visual doesn't animate with duff bezier data \n");
817 map["target"] = "visual1";
818 map["property"] = "mixColor";
819 map["initialValue"] = Color::MAGENTA;
820 map["targetValue"] = Color::RED;
821 map["animator"] = Property::Map()
822 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
823 .Add("timePeriod", Property::Map()
825 .Add("duration", 1.0f));
827 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
829 DummyControl actor = DummyControl::New();
830 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
831 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
832 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
833 application.GetScene().Add(actor);
835 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
836 Property::Map visualMap;
837 visualMap[Visual::Property::TYPE] = Visual::COLOR;
838 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
839 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
840 visual.SetName( "visual1" );
842 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
843 dummyImpl.RegisterVisual( visualIndex, visual );
845 Animation anim = dummyImpl.CreateTransition( transition );
846 DALI_TEST_CHECK( !anim );
848 application.SendNotification();
849 application.Render(0);
850 application.SendNotification();
852 Renderer renderer = actor.GetRendererAt(0);
853 Property::Index mixColorIdx = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
855 tet_printf( "Test that the property has been set to target value\n");
856 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
861 int UtcDaliTransitionDataMapN6(void)
863 ToolkitTestApplication application;
865 tet_printf("Testing visual doesn't animate with duff bezier data \n");
868 map["target"] = "visual1";
869 map["property"] = "mixColor";
870 map["initialValue"] = Color::MAGENTA;
871 map["targetValue"] = Color::RED;
872 map["animator"] = Property::Map()
873 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
874 .Add("timePeriod", Property::Map()
876 .Add("duration", 1.0f));
878 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
880 DummyControl actor = DummyControl::New();
881 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
882 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
883 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
884 application.GetScene().Add(actor);
886 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
887 Property::Map visualMap;
888 visualMap[Visual::Property::TYPE] = Visual::COLOR;
889 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
890 Visual::Base visual = VisualFactory::Get().CreateVisual( visualMap );
891 visual.SetName( "visual1" );
893 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
894 dummyImpl.RegisterVisual( visualIndex, visual );
896 Animation anim = dummyImpl.CreateTransition( transition );
897 DALI_TEST_CHECK( !anim );
899 application.SendNotification();
900 application.Render(0);
901 application.SendNotification();
903 Renderer renderer = actor.GetRendererAt(0);
904 Property::Index mixColorIdx = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
906 tet_printf( "Test that the property has been set to target value\n");
907 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIdx), Vector3(Color::RED), 0.001, TEST_LOCATION);
908 DALI_TEST_EQUALS(renderer.GetProperty<float>( DevelRenderer::Property::OPACITY ), 1.0f, 0.001, TEST_LOCATION);
914 int UtcDaliTransitionDataArrayP(void)
916 ToolkitTestApplication application;
919 map1["target"] = "Actor1";
920 map1["property"] = "color";
921 map1["initialValue"] = Color::MAGENTA;
922 map1["targetValue"] = Color::RED;
923 map1["animator"] = Property::Map()
924 .Add("alphaFunction", "EASE_IN_OUT")
925 .Add("timePeriod", Property::Map()
927 .Add("duration", 1.0f));
930 map2["target"] = "Actor1";
931 map2["property"] = "position";
932 map2["initialValue"] = Vector3(100,0,0);
933 map2["targetValue"] = Vector3(0,100,0);
934 map2["animator"] = Property::Map()
935 .Add("alphaFunction", "EASE_IN_OUT")
936 .Add("timePeriod", Property::Map()
938 .Add("duration", 1.0f));
941 map3["target"] = "Actor1";
942 map3["property"] = "orientation";
943 map3["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
945 Property::Array array;
946 array.PushBack(map1);
947 array.PushBack(map2);
948 array.PushBack(map3);
950 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
952 DummyControl actor = DummyControl::New();
953 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
954 actor.SetProperty( Dali::Actor::Property::NAME,"Actor1");
955 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
956 application.GetScene().Add(actor);
957 DALI_TEST_EQUALS( actor.GetCurrentProperty< Quaternion >( Actor::Property::ORIENTATION ), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
959 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
960 Animation anim = dummyImpl.CreateTransition( transition );
961 DALI_TEST_CHECK( anim );
962 application.SendNotification();
963 application.Render(0);
964 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::MAGENTA, TEST_LOCATION);
965 DALI_TEST_EQUALS( actor.GetCurrentProperty< Quaternion >( Actor::Property::ORIENTATION ), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
968 application.SendNotification();
969 application.Render(0); // start map2 anim
970 application.SendNotification();
971 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100,0,0), TEST_LOCATION);
973 application.Render(500); // Start map1 animation, halfway thru map2 anim
974 application.SendNotification();
975 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(50,50,0), TEST_LOCATION);
977 application.Render(500); // Halfway thru map1 anim, end of map2 anim
978 application.SendNotification();
979 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(0,100,0), TEST_LOCATION);
980 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), (Color::MAGENTA+Color::RED)*0.5f, TEST_LOCATION);
982 application.Render(500); // End of map1 anim
983 application.SendNotification();
984 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::RED, TEST_LOCATION );
990 int UtcDaliTransitionDataGetAnimatorP(void)
992 ToolkitTestApplication application;
995 map1["target"] = "Actor1";
996 map1["property"] = "color";
997 map1["initialValue"] = Color::MAGENTA;
998 map1["targetValue"] = Color::RED;
999 map1["animator"] = Property::Map()
1000 .Add("alphaFunction", "EASE_IN_SQUARE")
1001 .Add("timePeriod", Property::Map()
1003 .Add("duration", 0.5f));
1006 map2["target"] = "Actor1";
1007 map2["property"] = "position";
1008 map2["initialValue"] = Vector3(100,0,0);
1009 map2["targetValue"] = Vector3(0,100,0);
1010 map2["animator"] = Property::Map()
1011 .Add("alphaFunction", "EASE_OUT_SQUARE")
1012 .Add("timePeriod", Property::Map()
1014 .Add("duration", 2.0f));
1017 map3["target"] = "Actor1";
1018 map3["property"] = "size";
1019 map3["initialValue"] = Vector2(10,10);
1020 map3["targetValue"] = Vector2(100,100);
1021 map3["animator"] = Property::Map()
1022 .Add("alphaFunction", "EASE_OUT_SINE")
1023 .Add("timePeriod", Property::Map()
1025 .Add("duration", 3.0f));
1028 map4["target"] = "Actor2";
1029 map4["property"] = "color";
1030 map4["initialValue"] = Color::BLACK;
1031 map4["targetValue"] = Color::GREEN;
1032 map4["animator"] = Property::Map()
1033 .Add("alphaFunction", "EASE_IN_OUT_SINE")
1034 .Add("timePeriod", Property::Map()
1036 .Add("duration", 0.5f));
1039 map5["target"] = "Actor2";
1040 map5["property"] = "position";
1041 map5["initialValue"] = Vector3(100,0,0);
1042 map5["targetValue"] = Vector3(0,100,0);
1043 map5["animator"] = Property::Map()
1044 .Add("alphaFunction", "BOUNCE")
1045 .Add("timePeriod", Property::Map()
1047 .Add("duration", 2.0f));
1050 map6["target"] = "Actor2";
1051 map6["property"] = "size";
1052 map6["initialValue"] = Vector2(10,10);
1053 map6["targetValue"] = Vector2(100,100);
1054 map6["animator"] = Property::Map()
1055 .Add("alphaFunction", "SIN")
1056 .Add("timePeriod", Property::Map()
1058 .Add("duration", 3.0f));
1061 map7["target"] = "Actor4";
1062 map7["property"] = "sizeModeFactor";
1063 map7["initialValue"] = Vector3(1,1,1);
1064 map7["targetValue"] = Vector3(2,2,2);
1065 map7["animator"] = Property::Map()
1066 .Add("alphaFunction", "EASE_IN_SINE")
1067 .Add("timePeriod", Property::Map()
1069 .Add("duration", 1.0f));
1072 map8["target"] = "Visual1";
1073 map8["property"] = "opacity";
1074 map8["initialValue"] = 0.0f;
1075 map8["targetValue"] = 1.0f;
1076 map8["animator"] = Property::Map()
1077 .Add("alphaFunction", "EASE_IN")
1078 .Add("timePeriod", Property::Map()
1080 .Add("duration", 9.0f));
1083 map9["target"] = "Actor2";
1084 map9["property"] = "scale";
1085 map9["initialValue"] = Vector3(0,0,0);
1086 map9["targetValue"] = Vector3(1,1,1);
1087 map9["animator"] = Property::Map()
1088 .Add("alphaFunction", "REVERSE")
1089 .Add("timePeriod", Property::Map()
1091 .Add("duration", 1.0f));
1093 Property::Map map10;
1094 map10["target"] = "Actor2";
1095 map10["property"] = "scale";
1096 map10["initialValue"] = Vector3(0,0,0);
1097 map10["targetValue"] = Vector3(1,1,1);
1098 map10["animator"] = Property::Map()
1099 .Add("alphaFunction", Vector4(.23,.4,.8,1.2))
1100 .Add("timePeriod", Property::Map()
1102 .Add("duration", 1.0f));
1104 Property::Map map11;
1105 map11["target"] = "Actor2";
1106 map11["property"] = "scale";
1107 map11["initialValue"] = Vector3(0,0,0);
1108 map11["targetValue"] = Vector3(1,1,1);
1109 map11["animator"] = Property::Map()
1110 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1111 .Add("timePeriod", Property::Map()
1113 .Add("duration", 1.0f));
1115 Property::Map map12;
1116 map12["target"] = "Actor1";
1117 map12["property"] = "orientation";
1118 map12["targetValue"] = Quaternion( Radian(Math::PI_2), Vector3::ZAXIS );
1120 Property::Array array;
1121 array.PushBack(map1);
1122 array.PushBack(map2);
1123 array.PushBack(map3);
1124 array.PushBack(map4);
1125 array.PushBack(map5);
1126 array.PushBack(map6);
1127 array.PushBack(map7);
1128 array.PushBack(map8);
1129 array.PushBack(map9);
1130 array.PushBack(map10);
1131 array.PushBack(map11);
1132 array.PushBack(map12);
1134 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1136 DALI_TEST_EQUALS( transition.Count(), array.Count(), TEST_LOCATION );
1138 for( unsigned int i=0; i < array.Count(); ++i )
1140 Property::Map animatorMap = transition.GetAnimatorAt(i);
1141 Property::Value& value = array.GetElementAt(i);
1142 Property::Map* inputMap = value.GetMap();
1143 DALI_TEST_CHECK( inputMap );
1144 CHECK_MAP_EQUALS( *inputMap, animatorMap );