2 * Copyright (c) 2022 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.
17 #include <dali-toolkit-test-suite-utils.h>
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
20 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include "dummy-control.h"
28 using namespace Toolkit;
30 void utc_dali_toolkit_transition_data_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_transition_data_cleanup(void)
37 test_return_value = TET_PASS;
40 Property::Map CreateMap()
44 map["target"] = "Actor1";
45 map["property"] = "color";
46 map["initialValue"] = Color::MAGENTA;
47 map["targetValue"] = Color::RED;
48 map["animator"] = Property::Map()
49 .Add("alphaFunction", "EASE_IN_OUT_BACK")
50 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
54 void CHECK_ARRAY_EQUALS(Property::Array test, Property::Value result)
56 if(result.GetType() == Property::ARRAY)
59 Property::Array* resultArray = result.GetArray();
60 DALI_TEST_EQUALS(test.Count(), resultArray->Count(), TEST_LOCATION);
61 for(size_t i = 0; i < std::min(test.Count(), resultArray->Count()); ++i)
63 Property::Value a = test.GetElementAt(i);
64 Property::Value b = resultArray->GetElementAt(i);
65 DALI_TEST_EQUALS(a.GetType(), b.GetType(), TEST_LOCATION);
66 DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION);
69 else if(result.GetType() == Property::VECTOR4)
71 Vector4 value = result.Get<Vector4>();
72 DALI_TEST_CHECK(test.Count() >= 4);
73 for(size_t i = 0; i < 4; ++i)
75 Property::Value a = test.GetElementAt(i);
76 DALI_TEST_EQUALS(a.GetType(), Property::FLOAT, TEST_LOCATION);
77 DALI_TEST_EQUALS(a.Get<float>(), value[i], 0.001, TEST_LOCATION);
86 void CHECK_MAP_EQUALS(Property::Map test, Property::Map result)
88 DALI_TEST_EQUALS(test.Count(), result.Count(), TEST_LOCATION);
90 for(unsigned int i = 0; i < test.Count(); ++i)
92 KeyValuePair keyValue = test.GetKeyValue(i);
93 Property::Value* value;
95 if(keyValue.first.type == Property::Key::STRING)
97 value = result.Find(keyValue.first.stringKey);
101 value = result.Find(keyValue.first.indexKey);
104 DALI_TEST_CHECK(value != NULL);
107 if(keyValue.second.GetType() == Property::MAP)
109 DALI_TEST_EQUALS(keyValue.second.GetType(), value->GetType(), TEST_LOCATION);
110 CHECK_MAP_EQUALS(*(keyValue.second.GetMap()), *(value->GetMap()));
112 else if(keyValue.second.GetType() == Property::ARRAY)
114 CHECK_ARRAY_EQUALS(*(keyValue.second.GetArray()), *value);
116 else if(keyValue.second.GetType() == Property::STRING)
118 DALI_TEST_EQUALS(keyValue.second.GetType(), value->GetType(), TEST_LOCATION);
121 DALI_TEST_EQUALS(keyValue.second, str.c_str(), TEST_LOCATION);
125 DALI_TEST_EQUALS(keyValue.second.GetType(), value->GetType(), TEST_LOCATION);
126 DALI_TEST_EQUALS(keyValue.second, *value, 0.001f, TEST_LOCATION);
132 int UtcDaliTransitionDataNew(void)
134 ToolkitTestApplication application;
136 Property::Map map = CreateMap();
137 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
138 DALI_TEST_CHECK(transition);
143 int UtcDaliTransitionDataDownCast(void)
145 ToolkitTestApplication application;
147 Property::Map map = CreateMap();
149 BaseHandle handle = TransitionData::New(map);
150 DALI_TEST_CHECK(handle);
152 TransitionData transitionData = TransitionData::DownCast(handle);
153 DALI_TEST_CHECK(transitionData);
157 int UtcDaliTransitionDataCopyConstructor(void)
159 ToolkitTestApplication application;
161 Property::Map map = CreateMap();
163 TransitionData transitionData = TransitionData::New(map);
164 DALI_TEST_CHECK(transitionData);
166 TransitionData td2(transitionData);
167 DALI_TEST_CHECK(td2);
168 DALI_TEST_EQUALS(td2.Count(), 1, TEST_LOCATION);
172 int UtcDaliTransitionDataAssignmentOperator(void)
174 ToolkitTestApplication application;
176 Property::Map map = CreateMap();
178 TransitionData transitionData = TransitionData::New(map);
179 DALI_TEST_CHECK(transitionData);
182 DALI_TEST_CHECK(!td2);
184 td2 = transitionData;
185 DALI_TEST_CHECK(td2);
187 DALI_TEST_EQUALS(td2.Count(), 1, TEST_LOCATION);
191 int UtcDaliTransitionDataCount(void)
193 ToolkitTestApplication application;
195 Property::Map map = CreateMap();
196 TransitionData transitionData = TransitionData::New(map);
197 DALI_TEST_CHECK(transitionData);
198 DALI_TEST_EQUALS(transitionData.Count(), 1, TEST_LOCATION);
200 Property::Array array;
205 TransitionData transitionData2 = TransitionData::New(array);
206 DALI_TEST_CHECK(transitionData2);
207 DALI_TEST_EQUALS(transitionData2.Count(), 3, TEST_LOCATION);
212 int UtcDaliTransitionDataMap1P(void)
214 ToolkitTestApplication application;
216 tet_printf("Testing animation of a visual property using stylesheet equivalent maps\n");
219 map["target"] = "visual1";
220 map["property"] = "mixColor";
221 map["initialValue"] = Color::MAGENTA;
222 map["targetValue"] = Color::RED;
223 map["animator"] = Property::Map()
224 .Add("alphaFunction", "EASE_IN_OUT")
225 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
227 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
229 DummyControl actor = DummyControl::New();
230 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
231 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
232 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
233 application.GetScene().Add(actor);
235 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
237 Property::Map visualMap;
238 visualMap[Visual::Property::TYPE] = Visual::COLOR;
239 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
240 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
241 visual.SetName("visual1");
243 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
244 dummyImpl.RegisterVisual(visualIndex, visual);
246 Animation anim = dummyImpl.CreateTransition(transition);
247 DALI_TEST_CHECK(anim);
249 Renderer renderer = actor.GetRendererAt(0);
250 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
251 application.SendNotification();
252 application.Render(0);
254 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
255 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
256 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
257 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
261 application.SendNotification();
262 application.Render(500); // Start animation
263 application.Render(500); // Halfway thru anim
264 application.SendNotification();
265 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA + Color::RED) * 0.5f, TEST_LOCATION);
266 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
268 application.Render(500); // End of anim
269 application.SendNotification();
270 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION);
271 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
276 int UtcDaliTransitionDataMap2P(void)
278 ToolkitTestApplication application;
280 tet_printf("Testing animation of a visual property using programmatic maps\n");
283 map["target"] = "visual1";
284 map["property"] = ColorVisual::Property::MIX_COLOR;
285 map["initialValue"] = Color::MAGENTA;
286 map["targetValue"] = Color::RED;
287 map["animator"] = Property::Map()
288 .Add("alphaFunction", "LINEAR")
289 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
291 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
293 DummyControl actor = DummyControl::New();
294 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
295 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
296 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
297 application.GetScene().Add(actor);
299 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
301 Property::Map visualMap;
302 visualMap[Visual::Property::TYPE] = Visual::COLOR;
303 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
304 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
305 visual.SetName("visual1");
307 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
308 dummyImpl.RegisterVisual(visualIndex, visual);
310 Animation anim = dummyImpl.CreateTransition(transition);
311 DALI_TEST_CHECK(anim);
313 Renderer renderer = actor.GetRendererAt(0);
314 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
315 application.SendNotification();
316 application.Render(0);
318 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
319 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
320 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
321 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
325 application.SendNotification();
326 application.Render(0);
327 application.Render(500); // Start animation
328 application.Render(500); // Halfway thru anim
329 application.SendNotification();
330 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA + Color::RED) * 0.5f, TEST_LOCATION);
331 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
333 application.Render(500); // End of anim
334 application.SendNotification();
335 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION);
336 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
341 int UtcDaliTransitionDataMap2Pb(void)
343 ToolkitTestApplication application;
345 tet_printf("Testing animation of a visual property using programmatic maps\n");
348 map["target"] = "visual1";
349 map["property"] = PrimitiveVisual::Property::MIX_COLOR;
350 map["initialValue"] = Color::MAGENTA;
351 map["targetValue"] = Color::RED;
352 map["animator"] = Property::Map()
353 .Add("alphaFunction", "LINEAR")
354 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
356 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
358 DummyControl actor = DummyControl::New();
359 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
360 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
361 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
362 application.GetScene().Add(actor);
364 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
366 Property::Map visualMap;
367 visualMap[Visual::Property::TYPE] = Visual::PRIMITIVE;
368 visualMap[PrimitiveVisual::Property::MIX_COLOR] = Color::MAGENTA;
369 visualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::SPHERE;
370 visualMap[PrimitiveVisual::Property::SLICES] = 10;
371 visualMap[PrimitiveVisual::Property::STACKS] = 10;
373 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
374 visual.SetName("visual1");
376 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
377 dummyImpl.RegisterVisual(visualIndex, visual);
379 Animation anim = dummyImpl.CreateTransition(transition);
380 DALI_TEST_CHECK(anim);
382 Renderer renderer = actor.GetRendererAt(0);
383 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
384 application.SendNotification();
385 application.Render(0);
387 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
388 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
389 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
390 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
394 application.SendNotification();
395 application.Render(0);
396 application.Render(500); // Start animation
397 application.Render(500); // Halfway thru anim
398 application.SendNotification();
399 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA + Color::RED) * 0.5f, TEST_LOCATION);
400 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
402 application.Render(500); // End of anim
403 application.SendNotification();
404 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::RED), TEST_LOCATION);
405 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
410 int UtcDaliTransitionDataMap3P(void)
412 ToolkitTestApplication application;
414 tet_printf("Testing animation of an actor's position property using bezier curve\n");
417 map["target"] = "Actor1";
418 map["property"] = "position";
419 map["initialValue"] = Vector3(0, 0, 0);
420 map["targetValue"] = Vector3(100, 100, 0);
421 map["animator"] = Property::Map()
422 .Add("alphaFunction", Vector4(0.71, -0.57, 0.42, 1.38))
423 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
425 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
427 DummyControl actor = DummyControl::New();
428 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
429 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
430 application.GetScene().Add(actor);
432 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
433 Animation anim = dummyImpl.CreateTransition(transition);
434 DALI_TEST_CHECK(anim);
436 application.SendNotification();
437 application.Render(0);
438 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(0, 0, 0), 0.001f, TEST_LOCATION);
442 application.SendNotification();
443 application.Render(0);
445 application.Render(250); // 25%
446 application.SendNotification();
447 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%
449 application.Render(250); // Halfway thru map1 anim
450 application.SendNotification();
451 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%
453 application.Render(250); // End of map1 anim
454 application.SendNotification();
455 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
457 application.Render(250); // End of map1 anim
458 application.SendNotification();
459 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(100, 100, 0), TEST_LOCATION);
463 int UtcDaliTransitionDataMap4P(void)
465 ToolkitTestApplication application;
467 tet_printf("Testing animation of a visual's transform property using programmatic maps\n");
470 map1["target"] = "testVisual";
471 map1["property"] = "offset";
472 map1["initialValue"] = Vector2(0.0f, 0.0f);
473 map1["targetValue"] = Vector2(100.0f, 100.0f);
474 map1["animator"] = Property::Map()
475 .Add("alphaFunction", "LINEAR")
476 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
479 map2["target"] = "testVisual";
480 map2["property"] = "size";
481 map2["initialValue"] = Vector2(10.0f, 10.0f);
482 map2["targetValue"] = Vector2(110.0f, 110.0f);
483 map2["animator"] = Property::Map()
484 .Add("alphaFunction", "LINEAR")
485 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
487 Dali::Toolkit::TransitionData transition = TransitionData::New(Property::Array().Add(map1).Add(map2));
489 DummyControl actor = DummyControl::New();
490 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
491 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
492 application.GetScene().Add(actor);
494 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
496 Property::Map visualMap;
497 visualMap[Visual::Property::TYPE] = Visual::COLOR;
498 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
499 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
501 visual.SetName("testVisual");
502 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
504 Animation anim = dummyImpl.CreateTransition(transition);
505 DALI_TEST_CHECK(anim);
507 Renderer renderer = actor.GetRendererAt(0);
508 Property::Index sizeIndex = VisualRenderer::Property::TRANSFORM_SIZE;
509 application.SendNotification();
510 application.Render(0);
512 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
513 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(sizeIndex), Vector2(10.0f, 10.0f), TEST_LOCATION);
517 application.SendNotification();
518 application.Render(0);
519 application.Render(500); // Start animation
520 application.Render(500); // Halfway thru anim
521 application.SendNotification();
522 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(sizeIndex), Vector2(60.0f, 60.0f), TEST_LOCATION);
524 application.Render(500); // End of anim
525 application.SendNotification();
526 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector2>(sizeIndex), Vector2(110.0f, 110.0f), TEST_LOCATION);
531 int UtcDaliTransitionDataMap5P(void)
533 ToolkitTestApplication application;
535 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
538 map["target"] = "visual1";
539 map["property"] = "opacity";
540 map["initialValue"] = 0.0f;
541 map["targetValue"] = 1.0f;
542 map["animator"] = Property::Map()
543 .Add("alphaFunction", "EASE_IN_OUT")
544 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
546 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
548 DummyControl actor = DummyControl::New();
549 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
550 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
551 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
552 application.GetScene().Add(actor);
554 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
556 Property::Map visualMap;
557 visualMap[Visual::Property::TYPE] = Visual::COLOR;
558 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
559 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
560 visual.SetName("visual1");
562 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
563 dummyImpl.RegisterVisual(visualIndex, visual);
565 Animation anim = dummyImpl.CreateTransition(transition);
566 DALI_TEST_CHECK(anim);
568 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
569 glAbstraction.EnableEnableDisableCallTrace(true);
570 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
571 std::ostringstream blendStr;
572 blendStr << std::hex << GL_BLEND;
574 Renderer renderer = actor.GetRendererAt(0);
575 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
576 application.SendNotification();
577 application.Render(0);
579 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
580 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.001f, TEST_LOCATION);
582 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
583 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.001f, TEST_LOCATION);
585 // The Renderer is transparent. So rendering is skipped. The state should not be changed.
586 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
587 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
591 glEnableStack.Reset();
593 application.SendNotification();
594 application.Render(500); // Start animation
595 application.Render(500); // Halfway thru anim
596 application.SendNotification();
597 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
598 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.5f, 0.001f, TEST_LOCATION);
600 // Should not be changed
601 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
603 glEnableStack.Reset();
605 application.Render(501); // End of anim
606 application.SendNotification();
607 application.Render();
608 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
609 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
611 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
616 int UtcDaliTransitionDataMap6P(void)
618 ToolkitTestApplication application;
620 tet_printf("Testing animation visual opacity using stylesheet equivalent maps\n");
623 map["target"] = "visual1";
624 map["property"] = "opacity";
625 map["targetValue"] = 0.0f;
626 map["animator"] = Property::Map()
627 .Add("alphaFunction", "EASE_IN_OUT")
628 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
630 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
632 DummyControl actor = DummyControl::New();
633 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
634 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
635 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
636 application.GetScene().Add(actor);
638 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
640 Property::Map visualMap;
641 visualMap[Visual::Property::TYPE] = Visual::COLOR;
642 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
643 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
644 visual.SetName("visual1");
646 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
647 dummyImpl.RegisterVisual(visualIndex, visual);
649 Animation anim = dummyImpl.CreateTransition(transition);
650 DALI_TEST_CHECK(anim);
652 Renderer renderer = actor.GetRendererAt(0);
653 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
654 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
655 glAbstraction.EnableEnableDisableCallTrace(true);
656 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
657 std::ostringstream blendStr;
658 blendStr << std::hex << GL_BLEND;
660 application.SendNotification();
661 application.Render(0);
663 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
664 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
665 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
666 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001f, TEST_LOCATION);
668 // Default state is disabled. So test if "Enabled" is not called.
669 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
673 glEnableStack.Reset();
675 application.SendNotification();
676 application.Render(500); // Start animation
677 application.Render(500); // Halfway thru anim
678 application.SendNotification();
680 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
681 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.5f, 0.001f, TEST_LOCATION);
683 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
685 glEnableStack.Reset();
687 application.Render(500); // End of anim
688 application.SendNotification();
690 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector3>(mixColorIndex), Vector3(Color::MAGENTA), TEST_LOCATION);
691 DALI_TEST_EQUALS(renderer.GetCurrentProperty<float>(DevelRenderer::Property::OPACITY), 0.0f, 0.001f, TEST_LOCATION);
693 // GL_BLEND should not be changed: Keep enabled
694 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
699 int UtcDaliTransitionDataMap1N(void)
701 ToolkitTestApplication application;
704 map["target"] = "Actor1";
705 map["property"] = "randomProperty";
706 map["initialValue"] = Color::MAGENTA;
707 map["targetValue"] = Color::RED;
708 map["animator"] = Property::Map()
709 .Add("alphaFunction", "EASE_OUT")
710 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
712 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
714 DummyControl actor = DummyControl::New();
715 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
716 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
717 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
718 application.GetScene().Add(actor);
720 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
721 Animation anim = dummyImpl.CreateTransition(transition);
722 DALI_TEST_CHECK(!anim);
724 CHECK_MAP_EQUALS(map, transition.GetAnimatorAt(0));
728 int UtcDaliTransitionDataMapN4(void)
730 ToolkitTestApplication application;
732 tet_printf("Testing visual doesn't animate with duff bezier data \n");
735 map["target"] = "visual1";
736 map["property"] = "mixColor";
737 map["initialValue"] = Vector3(Color::MAGENTA);
738 map["targetValue"] = Vector3(Color::RED);
739 map["animator"] = Property::Map()
740 .Add("alphaFunction", Vector3(.1f, 1.0f, 0.5f))
741 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
743 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
745 DummyControl actor = DummyControl::New();
746 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
747 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
748 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
749 application.GetScene().Add(actor);
751 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
752 Property::Map visualMap;
753 visualMap[Visual::Property::TYPE] = Visual::COLOR;
754 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
755 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
756 visual.SetName("visual1");
758 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
759 dummyImpl.RegisterVisual(visualIndex, visual);
761 Animation anim = dummyImpl.CreateTransition(transition);
762 DALI_TEST_CHECK(!anim);
764 application.SendNotification();
765 application.Render(0);
766 application.SendNotification();
768 Renderer renderer = actor.GetRendererAt(0);
769 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
770 tet_printf("Test that the property has been set to target value\n");
771 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), 0.001, TEST_LOCATION);
772 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001, TEST_LOCATION);
777 int UtcDaliTransitionDataMapN5(void)
779 ToolkitTestApplication application;
781 tet_printf("Testing visual doesn't animate with duff bezier data \n");
784 map["target"] = "visual1";
785 map["property"] = "mixColor";
786 map["initialValue"] = Color::MAGENTA;
787 map["targetValue"] = Color::RED;
788 map["animator"] = Property::Map()
789 .Add("alphaFunction", Property::Array().Add(.1f).Add(1.0f).Add(0.5f))
790 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
792 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
794 DummyControl actor = DummyControl::New();
795 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
796 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
797 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
798 application.GetScene().Add(actor);
800 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
801 Property::Map visualMap;
802 visualMap[Visual::Property::TYPE] = Visual::COLOR;
803 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
804 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
805 visual.SetName("visual1");
807 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
808 dummyImpl.RegisterVisual(visualIndex, visual);
810 Animation anim = dummyImpl.CreateTransition(transition);
811 DALI_TEST_CHECK(!anim);
813 application.SendNotification();
814 application.Render(0);
815 application.SendNotification();
817 Renderer renderer = actor.GetRendererAt(0);
818 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
819 tet_printf("Test that the property has been set to target value\n");
820 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), 0.001, TEST_LOCATION);
825 int UtcDaliTransitionDataMapN6(void)
827 ToolkitTestApplication application;
829 tet_printf("Testing visual doesn't animate with duff bezier data \n");
832 map["target"] = "visual1";
833 map["property"] = "mixColor";
834 map["initialValue"] = Color::MAGENTA;
835 map["targetValue"] = Color::RED;
836 map["animator"] = Property::Map()
837 .Add("alphaFunction", Property::Array().Add("1").Add("Two").Add("3").Add("4"))
838 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
840 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
842 DummyControl actor = DummyControl::New();
843 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
844 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
845 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
846 application.GetScene().Add(actor);
848 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
849 Property::Map visualMap;
850 visualMap[Visual::Property::TYPE] = Visual::COLOR;
851 visualMap[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
852 Visual::Base visual = VisualFactory::Get().CreateVisual(visualMap);
853 visual.SetName("visual1");
855 Property::Index visualIndex = Control::CONTROL_PROPERTY_END_INDEX + 1;
856 dummyImpl.RegisterVisual(visualIndex, visual);
858 Animation anim = dummyImpl.CreateTransition(transition);
859 DALI_TEST_CHECK(!anim);
861 application.SendNotification();
862 application.Render(0);
863 application.SendNotification();
865 Renderer renderer = actor.GetRendererAt(0);
866 Property::Index mixColorIndex = VisualRenderer::Property::VISUAL_MIX_COLOR;
868 tet_printf("Test that the property has been set to target value\n");
869 DALI_TEST_EQUALS(renderer.GetProperty<Vector3>(mixColorIndex), Vector3(Color::RED), 0.001, TEST_LOCATION);
870 DALI_TEST_EQUALS(renderer.GetProperty<float>(DevelRenderer::Property::OPACITY), 1.0f, 0.001, TEST_LOCATION);
875 int UtcDaliTransitionDataArrayP(void)
877 ToolkitTestApplication application;
880 map1["target"] = "Actor1";
881 map1["property"] = "color";
882 map1["initialValue"] = Color::MAGENTA;
883 map1["targetValue"] = Color::RED;
884 map1["animator"] = Property::Map()
885 .Add("alphaFunction", "EASE_IN_OUT")
886 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 1.0f));
889 map2["target"] = "Actor1";
890 map2["property"] = "position";
891 map2["initialValue"] = Vector3(100, 0, 0);
892 map2["targetValue"] = Vector3(0, 100, 0);
893 map2["animator"] = Property::Map()
894 .Add("alphaFunction", "EASE_IN_OUT")
895 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
898 map3["target"] = "Actor1";
899 map3["property"] = "orientation";
900 map3["targetValue"] = Quaternion(Radian(Math::PI_2), Vector3::ZAXIS);
902 Property::Array array;
903 array.PushBack(map1);
904 array.PushBack(map2);
905 array.PushBack(map3);
907 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
909 DummyControl actor = DummyControl::New();
910 actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
911 actor.SetProperty(Dali::Actor::Property::NAME, "Actor1");
912 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
913 application.GetScene().Add(actor);
914 DALI_TEST_EQUALS(actor.GetCurrentProperty<Quaternion>(Actor::Property::ORIENTATION), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
916 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
917 Animation anim = dummyImpl.CreateTransition(transition);
918 DALI_TEST_CHECK(anim);
919 application.SendNotification();
920 application.Render(0);
921 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::MAGENTA, TEST_LOCATION);
922 DALI_TEST_EQUALS(actor.GetCurrentProperty<Quaternion>(Actor::Property::ORIENTATION), Quaternion(Radian(Math::PI_2), Vector3::ZAXIS), TEST_LOCATION);
925 application.SendNotification();
926 application.Render(0); // start map2 anim
927 application.SendNotification();
928 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(100, 0, 0), TEST_LOCATION);
930 application.Render(500); // Start map1 animation, halfway thru map2 anim
931 application.SendNotification();
932 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(50, 50, 0), TEST_LOCATION);
934 application.Render(500); // Halfway thru map1 anim, end of map2 anim
935 application.SendNotification();
936 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(0, 100, 0), TEST_LOCATION);
937 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), (Color::MAGENTA + Color::RED) * 0.5f, TEST_LOCATION);
939 application.Render(500); // End of map1 anim
940 application.SendNotification();
941 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::RED, TEST_LOCATION);
946 int UtcDaliTransitionDataGetAnimatorP(void)
948 ToolkitTestApplication application;
951 map1["target"] = "Actor1";
952 map1["property"] = "color";
953 map1["initialValue"] = Color::MAGENTA;
954 map1["targetValue"] = Color::RED;
955 map1["animator"] = Property::Map()
956 .Add("alphaFunction", "EASE_IN_SQUARE")
957 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 0.5f));
960 map2["target"] = "Actor1";
961 map2["property"] = "position";
962 map2["initialValue"] = Vector3(100, 0, 0);
963 map2["targetValue"] = Vector3(0, 100, 0);
964 map2["animator"] = Property::Map()
965 .Add("alphaFunction", "EASE_OUT_SQUARE")
966 .Add("timePeriod", Property::Map().Add("delay", 0.2f).Add("duration", 2.0f));
969 map3["target"] = "Actor1";
970 map3["property"] = "size";
971 map3["initialValue"] = Vector2(10, 10);
972 map3["targetValue"] = Vector2(100, 100);
973 map3["animator"] = Property::Map()
974 .Add("alphaFunction", "EASE_OUT_SINE")
975 .Add("timePeriod", Property::Map().Add("delay", 0.4f).Add("duration", 3.0f));
978 map4["target"] = "Actor2";
979 map4["property"] = "color";
980 map4["initialValue"] = Color::BLACK;
981 map4["targetValue"] = Color::GREEN;
982 map4["animator"] = Property::Map()
983 .Add("alphaFunction", "EASE_IN_OUT_SINE")
984 .Add("timePeriod", Property::Map().Add("delay", 0.5f).Add("duration", 0.5f));
987 map5["target"] = "Actor2";
988 map5["property"] = "position";
989 map5["initialValue"] = Vector3(100, 0, 0);
990 map5["targetValue"] = Vector3(0, 100, 0);
991 map5["animator"] = Property::Map()
992 .Add("alphaFunction", "BOUNCE")
993 .Add("timePeriod", Property::Map().Add("delay", 0.2f).Add("duration", 2.0f));
996 map6["target"] = "Actor2";
997 map6["property"] = "size";
998 map6["initialValue"] = Vector2(10, 10);
999 map6["targetValue"] = Vector2(100, 100);
1000 map6["animator"] = Property::Map()
1001 .Add("alphaFunction", "SIN")
1002 .Add("timePeriod", Property::Map().Add("delay", 0.4f).Add("duration", 3.0f));
1005 map7["target"] = "Actor4";
1006 map7["property"] = "sizeModeFactor";
1007 map7["initialValue"] = Vector3(1, 1, 1);
1008 map7["targetValue"] = Vector3(2, 2, 2);
1009 map7["animator"] = Property::Map()
1010 .Add("alphaFunction", "EASE_IN_SINE")
1011 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
1014 map8["target"] = "Visual1";
1015 map8["property"] = "opacity";
1016 map8["initialValue"] = 0.0f;
1017 map8["targetValue"] = 1.0f;
1018 map8["animator"] = Property::Map()
1019 .Add("alphaFunction", "EASE_IN")
1020 .Add("timePeriod", Property::Map().Add("delay", 0.3f).Add("duration", 9.0f));
1023 map9["target"] = "Actor2";
1024 map9["property"] = "scale";
1025 map9["initialValue"] = Vector3(0, 0, 0);
1026 map9["targetValue"] = Vector3(1, 1, 1);
1027 map9["animator"] = Property::Map()
1028 .Add("alphaFunction", "REVERSE")
1029 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
1031 Property::Map map10;
1032 map10["target"] = "Actor2";
1033 map10["property"] = "scale";
1034 map10["initialValue"] = Vector3(0, 0, 0);
1035 map10["targetValue"] = Vector3(1, 1, 1);
1036 map10["animator"] = Property::Map()
1037 .Add("alphaFunction", Vector4(.23, .4, .8, 1.2))
1038 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
1040 Property::Map map11;
1041 map11["target"] = "Actor2";
1042 map11["property"] = "scale";
1043 map11["initialValue"] = Vector3(0, 0, 0);
1044 map11["targetValue"] = Vector3(1, 1, 1);
1045 map11["animator"] = Property::Map()
1046 .Add("alphaFunction", Property::Array().Add(.23f).Add(.4f).Add(.8f).Add(.2f))
1047 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 1.0f));
1049 Property::Map map12;
1050 map12["target"] = "Actor1";
1051 map12["property"] = "orientation";
1052 map12["targetValue"] = Quaternion(Radian(Math::PI_2), Vector3::ZAXIS);
1054 Property::Array array;
1055 array.PushBack(map1);
1056 array.PushBack(map2);
1057 array.PushBack(map3);
1058 array.PushBack(map4);
1059 array.PushBack(map5);
1060 array.PushBack(map6);
1061 array.PushBack(map7);
1062 array.PushBack(map8);
1063 array.PushBack(map9);
1064 array.PushBack(map10);
1065 array.PushBack(map11);
1066 array.PushBack(map12);
1068 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1070 DALI_TEST_EQUALS(transition.Count(), array.Count(), TEST_LOCATION);
1072 for(unsigned int i = 0; i < array.Count(); ++i)
1074 Property::Map animatorMap = transition.GetAnimatorAt(i);
1075 Property::Value& value = array.GetElementAt(i);
1076 Property::Map* inputMap = value.GetMap();
1077 DALI_TEST_CHECK(inputMap);
1078 CHECK_MAP_EQUALS(*inputMap, animatorMap);