(Vector) Flush lottie update informations
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedVectorImageVisual.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdlib.h>
18 #include <chrono>
19 #include <iostream>
20 #include <thread>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-timer.h>
25 #include <toolkit-vector-animation-renderer.h>
26 #include "dummy-control.h"
27
28 #include <dali-toolkit/dali-toolkit.h>
29
30 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
33 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
34 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
35 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
36 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
37
38 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
39 #include <dali/devel-api/adaptor-framework/window-devel.h>
40 #include <dali/devel-api/rendering/renderer-devel.h>
41
42 using namespace Dali;
43 using namespace Dali::Toolkit;
44
45 void dali_animated_vector_image_visual_startup(void)
46 {
47   test_return_value = TET_UNDEF;
48 }
49
50 void dali_animated_vector_image_visual_cleanup(void)
51 {
52   test_return_value = TET_PASS;
53 }
54
55 namespace
56 {
57 const char* TEST_VECTOR_IMAGE_FILE_NAME            = TEST_RESOURCE_DIR "/insta_camera.json";
58 const char* TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP = "framedrop.json";
59 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME    = "invalid.json";
60
61 bool gAnimationFinishedSignalFired = false;
62
63 void VisualEventSignal(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId)
64 {
65   if(visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED)
66   {
67     gAnimationFinishedSignalFired = true;
68   }
69 }
70
71 } // namespace
72
73 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url");
77
78   VisualFactory factory = VisualFactory::Get();
79   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
80   DALI_TEST_CHECK(visual);
81
82   DummyControl      actor     = DummyControl::New(true);
83   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
84   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
85   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
86   application.GetScene().Add(actor);
87
88   application.SendNotification();
89   application.Render();
90
91   // Trigger count is 1 - render a frame
92   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
93
94   // renderer is added to actor
95   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
96   Renderer renderer = actor.GetRendererAt(0u);
97   DALI_TEST_CHECK(renderer);
98
99   // Test SetOffScene().
100   actor.Unparent();
101   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
102
103   END_TEST;
104 }
105
106 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
107 {
108   ToolkitTestApplication application;
109   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map");
110
111   Property::Map propertyMap;
112   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
113     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
114     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
115
116   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
117   DALI_TEST_CHECK(visual);
118
119   DummyControl      actor     = DummyControl::New(true);
120   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
121   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
122   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
123   application.GetScene().Add(actor);
124
125   application.SendNotification();
126   application.Render();
127
128   // Trigger count is 2 - load & render a frame
129   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
130
131   // renderer is added to actor
132   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
133   Renderer renderer = actor.GetRendererAt(0u);
134   DALI_TEST_CHECK(renderer);
135
136   actor.Unparent();
137   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
138
139   END_TEST;
140 }
141
142 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
143 {
144   ToolkitTestApplication application;
145   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map");
146
147   int             startFrame = 1, endFrame = 3;
148   Property::Array playRange;
149   playRange.PushBack(startFrame);
150   playRange.PushBack(endFrame);
151
152   Property::Map propertyMap;
153   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
154     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
155     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
156     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
157     .Add(DevelVisual::Property::CORNER_RADIUS, 50.0f)
158     .Add(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f)
159     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
160
161   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
162   DALI_TEST_CHECK(visual);
163
164   DummyControl      actor     = DummyControl::New(true);
165   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
166   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
167   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
168   application.GetScene().Add(actor);
169
170   application.SendNotification();
171   application.Render();
172
173   // Trigger count is 2 - load & render a frame
174   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
175
176   // renderer is added to actor
177   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
178   Renderer renderer = actor.GetRendererAt(0u);
179   DALI_TEST_CHECK(renderer);
180
181   actor.Unparent();
182   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
183
184   END_TEST;
185 }
186
187 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
188 {
189   ToolkitTestApplication application;
190   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map");
191
192   int             startFrame = 1, endFrame = 3;
193   int             desiredWidth = 100, desiredHeight = 150;
194   float           cornerRadius     = 22.0f;
195   float           borderlineWidth  = 2.0f;
196   Vector4         borderlineColor  = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
197   float           borderlineOffset = 0.1f;
198   Property::Array playRange;
199   playRange.PushBack(startFrame);
200   playRange.PushBack(endFrame);
201
202   Property::Map propertyMap;
203   propertyMap.Add("visualType", DevelVisual::ANIMATED_VECTOR_IMAGE)
204     .Add("url", TEST_VECTOR_IMAGE_FILE_NAME)
205     .Add("loopCount", 3)
206     .Add("playRange", playRange)
207     .Add("stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME)
208     .Add("loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE)
209     .Add("redrawInScalingDown", false)
210     .Add("cornerRadius", cornerRadius)
211     .Add("borderlineWidth", borderlineWidth)
212     .Add("borderlineColor", borderlineColor)
213     .Add("borderlineOffset", borderlineOffset)
214     .Add("desiredWidth", desiredWidth)
215     .Add("desiredHeight", desiredHeight);
216
217   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
218   DALI_TEST_CHECK(visual);
219
220   DummyControl      actor     = DummyControl::New(true);
221   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
222   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
223   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
224   application.GetScene().Add(actor);
225
226   application.SendNotification();
227   application.Render();
228
229   // Trigger count is 1 - render a frame
230   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
231
232   // renderer is added to actor
233   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
234
235   Renderer renderer = actor.GetRendererAt(0u);
236   DALI_TEST_CHECK(renderer);
237
238   Property::Map resultMap;
239   visual.CreatePropertyMap(resultMap);
240
241   // check the property values from the returned map from a visual
242   Property::Value* value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
243   DALI_TEST_CHECK(value);
244   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
245
246   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
247   DALI_TEST_CHECK(value);
248   DALI_TEST_CHECK(value->Get<int>() == 3);
249
250   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
251   DALI_TEST_CHECK(value);
252
253   Property::Array* result = value->GetArray();
254   DALI_TEST_CHECK(result);
255
256   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
257   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
258
259   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
260   DALI_TEST_CHECK(value);
261   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::FIRST_FRAME);
262
263   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
264   DALI_TEST_CHECK(value);
265   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::AUTO_REVERSE);
266
267   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
268   DALI_TEST_CHECK(value);
269   DALI_TEST_CHECK(value->Get<bool>() == false);
270
271   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
272   DALI_TEST_CHECK(value);
273   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION);
274
275   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
276   DALI_TEST_CHECK(value);
277   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
278
279   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
280   DALI_TEST_CHECK(value);
281   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
282
283   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
284   DALI_TEST_CHECK(value);
285   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
286
287   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
288   DALI_TEST_CHECK(value);
289   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
290
291   value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
292   DALI_TEST_CHECK(value);
293   DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
294
295   value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
296   DALI_TEST_CHECK(value);
297   DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
298
299   actor.Unparent();
300   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
301
302   END_TEST;
303 }
304
305 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
306 {
307   ToolkitTestApplication application;
308   tet_infoline("UtcDaliAnimatedVectorImageVisualGetPropertyMap01");
309
310   int             startFrame = 1, endFrame = 3;
311   int             desiredWidth = 100, desiredHeight = 150;
312   Vector4         cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
313   float           borderlineWidth  = 2.3f;
314   Vector4         borderlineColor  = Vector4(0.3f, 0.3f, 1.0f, 1.0f);
315   float           borderlineOffset = 0.3f;
316   Property::Array playRange;
317   playRange.PushBack(startFrame);
318   playRange.PushBack(endFrame);
319
320   Property::Map propertyMap;
321   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
322     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
323     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
324     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
325     .Add(DevelVisual::Property::CORNER_RADIUS, cornerRadius)
326     .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE)
327     .Add(DevelVisual::Property::BORDERLINE_WIDTH, borderlineWidth)
328     .Add(DevelVisual::Property::BORDERLINE_COLOR, borderlineColor)
329     .Add(DevelVisual::Property::BORDERLINE_OFFSET, borderlineOffset)
330     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false)
331     .Add(ImageVisual::Property::DESIRED_WIDTH, desiredWidth)
332     .Add(ImageVisual::Property::DESIRED_HEIGHT, desiredHeight);
333
334   // request AnimatedVectorImageVisual with a property map
335   VisualFactory factory = VisualFactory::Get();
336   Visual::Base  visual  = factory.CreateVisual(propertyMap);
337
338   DummyControl      actor     = DummyControl::New(true);
339   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
340   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
341
342   Vector2 controlSize(20.f, 30.f);
343   actor.SetProperty(Actor::Property::SIZE, controlSize);
344
345   application.GetScene().Add(actor);
346
347   application.SendNotification();
348   application.Render();
349
350   // Trigger count is 2 - load & render a frame
351   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
352
353   Property::Map resultMap;
354   resultMap = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
355
356   // check the property values from the returned map from a visual
357   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
358   DALI_TEST_CHECK(value);
359   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
360
361   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
362   DALI_TEST_CHECK(value);
363   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
364
365   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
366   DALI_TEST_CHECK(value);
367   DALI_TEST_CHECK(value->Get<int>() == 3);
368
369   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
370   DALI_TEST_CHECK(value);
371
372   Property::Array* result = value->GetArray();
373   DALI_TEST_CHECK(result);
374
375   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
376   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
377
378   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
379   DALI_TEST_CHECK(value);
380   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::CURRENT_FRAME);
381
382   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
383   DALI_TEST_CHECK(value);
384   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::RESTART);
385
386   value = resultMap.Find(DevelImageVisual::Property::CONTENT_INFO, Property::MAP);
387   DALI_TEST_CHECK(value);
388
389   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
390   DALI_TEST_CHECK(value);
391   DALI_TEST_CHECK(value->Get<bool>() == true); // Check default value
392
393   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
394   DALI_TEST_CHECK(value);
395   DALI_TEST_EQUALS(value->Get<Vector4>(), cornerRadius, TEST_LOCATION);
396
397   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
398   DALI_TEST_CHECK(value);
399   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
400
401   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
402   DALI_TEST_CHECK(value);
403   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
404
405   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
406   DALI_TEST_CHECK(value);
407   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
408
409   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
410   DALI_TEST_CHECK(value);
411   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
412
413   value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
414   DALI_TEST_CHECK(value);
415   DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
416
417   value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
418   DALI_TEST_CHECK(value);
419   DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
420
421   // request AnimatedVectorImageVisual with an URL
422   Visual::Base visual2 = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
423
424   resultMap.Clear();
425   visual2.CreatePropertyMap(resultMap);
426
427   // check the property values from the returned map from a visual
428   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
429   DALI_TEST_CHECK(value);
430   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
431
432   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
433   DALI_TEST_CHECK(value);
434   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
435
436   END_TEST;
437 }
438
439 int UtcDaliAnimatedVectorImageVisualPlayback(void)
440 {
441   ToolkitTestApplication application;
442
443   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayback");
444
445   {
446     // request AnimatedVectorImageVisual with a property map
447     VisualFactory factory = VisualFactory::Get();
448     Visual::Base  visual  = factory.CreateVisual(
449       Property::Map()
450         .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
451         .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
452         .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
453
454     DummyControl        dummyControl = DummyControl::New(true);
455     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
456     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
457     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
458
459     Property::Map attributes;
460     tet_infoline("Test Play action");
461     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
462
463     application.GetScene().Add(dummyControl);
464     application.SendNotification();
465     application.Render(16);
466
467     Property::Map    map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
468     Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
469     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
470
471     tet_infoline("Test Pause action");
472     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
473
474     application.SendNotification();
475     application.Render(16);
476
477     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
478     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
479     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PAUSED);
480
481     tet_infoline("Test Play action");
482     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
483
484     application.SendNotification();
485     application.Render(16);
486
487     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
488     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
489     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
490
491     tet_infoline("Test Stop action");
492     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
493
494     application.SendNotification();
495     application.Render(16);
496
497     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
498     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
499     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
500
501     tet_infoline("Test Stop action again");
502     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
503
504     application.SendNotification();
505     application.Render(16);
506
507     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
508     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
509     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
510
511     tet_infoline("Test Play action");
512     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
513
514     application.SendNotification();
515     application.Render(16);
516
517     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
518     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
519     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
520
521     tet_infoline("Off stage");
522     dummyControl.Unparent();
523
524     application.SendNotification();
525     application.Render(16);
526
527     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
528     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
529     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
530
531     tet_infoline("On stage again");
532     application.GetScene().Add(dummyControl);
533
534     application.SendNotification();
535     application.Render(16);
536
537     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
538     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
539     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
540
541     tet_infoline("Test Play action");
542     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
543
544     application.SendNotification();
545     application.Render(16);
546
547     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
548     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
549     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
550
551     // Change Size
552     Vector3 newSize(100.0f, 100.0f, 0.0f);
553     dummyControl.SetProperty(Actor::Property::SIZE, newSize);
554
555     application.SendNotification();
556     application.Render(16);
557
558     // Size should be changed
559     Vector3 naturalSize = dummyControl.GetNaturalSize();
560     DALI_TEST_CHECK(naturalSize == newSize);
561
562     dummyControl.Unparent();
563   }
564
565   END_TEST;
566 }
567
568 int UtcDaliAnimatedVectorImageVisualCustomShader(void)
569 {
570   ToolkitTestApplication application;
571   tet_infoline("UtcDaliAnimatedVectorImageVisualCustomShader Test custom shader");
572
573   VisualFactory     factory = VisualFactory::Get();
574   Property::Map     properties;
575   Property::Map     shader;
576   const std::string vertexShader                    = "Foobar";
577   const std::string fragmentShader                  = "Foobar sampler2D Foobar";
578   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
579   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
580
581   properties[Visual::Property::TYPE]     = Visual::IMAGE;
582   properties[Visual::Property::SHADER]   = shader;
583   properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
584
585   Visual::Base visual = factory.CreateVisual(properties);
586
587   // trigger creation through setting on stage
588   DummyControl        dummy     = DummyControl::New(true);
589   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
590   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
591
592   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
593   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
594   application.GetScene().Add(dummy);
595
596   application.SendNotification();
597   application.Render();
598
599   // Trigger count is 1 - render a frame
600   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
601
602   Renderer        renderer = dummy.GetRendererAt(0);
603   Shader          shader2  = renderer.GetShader();
604   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
605   Property::Map*  map      = value.GetMap();
606   DALI_TEST_CHECK(map);
607
608   std::string      resultFragmentShader, resultVertexShader;
609   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
610   fragment->Get(resultFragmentShader);
611   DALI_TEST_CHECK(resultFragmentShader.find(fragmentShader) != std::string::npos);
612
613   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
614   vertex->Get(resultVertexShader);
615   DALI_TEST_CHECK(resultVertexShader.find(vertexShader) != std::string::npos);
616
617   END_TEST;
618 }
619
620 int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
621 {
622   ToolkitTestApplication application;
623   tet_infoline("UtcDaliAnimatedVectorImageVisualNaturalSize");
624
625   VisualFactory factory = VisualFactory::Get();
626   Visual::Base  visual  = factory.CreateVisual(
627     Property::Map()
628       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
629       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
630       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
631   DALI_TEST_CHECK(visual);
632
633   DummyControl      actor     = DummyControl::New(true);
634   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
635   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
636
637   Vector2 controlSize(20.f, 30.f);
638   Vector2 naturalSize;
639
640   application.GetScene().Add(actor);
641
642   application.SendNotification();
643   application.Render();
644
645   // Trigger count is 1 - load
646   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
647
648   visual.GetNaturalSize(naturalSize);
649
650   DALI_TEST_EQUALS(naturalSize, Vector2(100.0f, 100.0f), TEST_LOCATION); // 100x100 is the content default size.
651
652   actor.SetProperty(Actor::Property::SIZE, controlSize);
653
654   application.SendNotification();
655   application.Render();
656
657   visual.GetNaturalSize(naturalSize);
658
659   DALI_TEST_EQUALS(naturalSize, controlSize, TEST_LOCATION);
660
661   END_TEST;
662 }
663
664 int UtcDaliAnimatedVectorImageVisualLoopCount(void)
665 {
666   ToolkitTestApplication application;
667   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopCount");
668
669   Property::Map propertyMap;
670   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
671     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
672     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
673     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
674
675   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
676   DALI_TEST_CHECK(visual);
677
678   DummyControl      actor     = DummyControl::New(true);
679   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
680   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
681
682   Vector2 controlSize(20.f, 30.f);
683   actor.SetProperty(Actor::Property::SIZE, controlSize);
684
685   application.GetScene().Add(actor);
686
687   Property::Map attributes;
688   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
689
690   application.SendNotification();
691   application.Render();
692
693   // Trigger count is 2 - load & render a frame
694   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
695
696   // renderer is added to actor
697   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
698   Renderer renderer = actor.GetRendererAt(0u);
699   DALI_TEST_CHECK(renderer);
700
701   END_TEST;
702 }
703
704 int UtcDaliAnimatedVectorImageVisualPlayRange(void)
705 {
706   ToolkitTestApplication application;
707   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRange");
708
709   int             startFrame = 1, endFrame = 3;
710   Property::Array array;
711   array.PushBack(endFrame);
712   array.PushBack(startFrame);
713
714   Property::Map propertyMap;
715   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
716     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
717     .Add(DevelImageVisual::Property::PLAY_RANGE, array)
718     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
719
720   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
721   DALI_TEST_CHECK(visual);
722
723   DummyControl      actor     = DummyControl::New(true);
724   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
725   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
726
727   Vector2 controlSize(20.f, 30.f);
728   actor.SetProperty(Actor::Property::SIZE, controlSize);
729
730   application.GetScene().Add(actor);
731
732   Property::Map attributes;
733   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
734
735   application.SendNotification();
736   application.Render();
737
738   // Trigger count is 2 - load & render a frame
739   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
740
741   // renderer is added to actor
742   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
743   Renderer renderer = actor.GetRendererAt(0u);
744   DALI_TEST_CHECK(renderer);
745
746   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
747   Property::Value* value            = map.Find(DevelImageVisual::Property::PLAY_RANGE);
748   int              totalFrameNumber = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER)->Get<int>();
749
750   int              resultStartFrame, resultEndFrame;
751   Property::Array* result = value->GetArray();
752   result->GetElementAt(0).Get(resultStartFrame);
753   result->GetElementAt(1).Get(resultEndFrame);
754
755   DALI_TEST_EQUALS(startFrame, resultStartFrame, TEST_LOCATION);
756   DALI_TEST_EQUALS(endFrame, resultEndFrame, TEST_LOCATION);
757
758   // Set invalid play range
759   array.Clear();
760   array.PushBack(1);
761   array.PushBack(100);
762
763   attributes.Clear();
764   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
765   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
766
767   // To make event trigger
768   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
769
770   application.SendNotification();
771   application.Render();
772
773   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
774
775   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
776   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
777
778   result = value->GetArray();
779   result->GetElementAt(0).Get(resultStartFrame);
780   result->GetElementAt(1).Get(resultEndFrame);
781
782   DALI_TEST_EQUALS(resultStartFrame, 1, TEST_LOCATION);
783   DALI_TEST_EQUALS(resultEndFrame, totalFrameNumber - 1, TEST_LOCATION); // Should be clamped
784
785   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Map());
786
787   application.SendNotification();
788   application.Render();
789
790   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
791
792   // To make event trigger
793   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
794
795   application.SendNotification();
796   application.Render();
797
798   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
799
800   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
801   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
802   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
803
804   array.Clear();
805   array.PushBack(0);
806   array.PushBack(2);
807
808   attributes.Clear();
809   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
810   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
811
812   // To make event trigger
813   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
814
815   application.SendNotification();
816   application.Render();
817
818   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
819
820   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
821   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
822
823   result = value->GetArray();
824   result->GetElementAt(0).Get(resultStartFrame);
825   result->GetElementAt(1).Get(resultEndFrame);
826
827   DALI_TEST_EQUALS(0, resultStartFrame, TEST_LOCATION);
828   DALI_TEST_EQUALS(2, resultEndFrame, TEST_LOCATION);
829
830   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
831   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION); // CURRENT_FRAME_NUMBER should be changed also.
832
833   END_TEST;
834 }
835
836 int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
837 {
838   ToolkitTestApplication application;
839   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRangeMarker");
840
841   // Set 1 marker as array
842   Property::Array array;
843   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
844
845   Property::Map propertyMap;
846   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
847     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
848     .Add(DevelImageVisual::Property::PLAY_RANGE, array)
849     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
850
851   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
852   DALI_TEST_CHECK(visual);
853
854   DummyControl      actor     = DummyControl::New(true);
855   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
856   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
857
858   Vector2 controlSize(20.f, 30.f);
859   actor.SetProperty(Actor::Property::SIZE, controlSize);
860
861   application.GetScene().Add(actor);
862
863   Property::Map attributes;
864   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
865
866   application.SendNotification();
867   application.Render();
868
869   // Trigger count is 2 - load & render a frame
870   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
871
872   // renderer is added to actor
873   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
874   Renderer renderer = actor.GetRendererAt(0u);
875   DALI_TEST_CHECK(renderer);
876
877   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
878   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
879
880   int              resultStartFrame, resultEndFrame;
881   Property::Array* result = value->GetArray();
882   result->GetElementAt(0).Get(resultStartFrame);
883   result->GetElementAt(1).Get(resultEndFrame);
884
885   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
886   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
887
888   // Set 1 marker as string
889   array.Clear();
890
891   attributes.Clear();
892   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, VECTOR_ANIMATION_MARKER_NAME_1);
893   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
894
895   // To make event trigger
896   actor.SetProperty(Actor::Property::SIZE, Vector2(40.0f, 40.0f));
897
898   application.SendNotification();
899   application.Render();
900
901   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
902
903   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
904   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
905
906   result = value->GetArray();
907   result->GetElementAt(0).Get(resultStartFrame);
908   result->GetElementAt(1).Get(resultEndFrame);
909
910   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
911   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
912
913   // Set 2 markers
914   array.Clear();
915   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
916   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
917
918   attributes.Clear();
919   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
920   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
921
922   // To make event trigger
923   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
924
925   application.SendNotification();
926   application.Render();
927
928   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
929
930   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
931   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
932
933   result = value->GetArray();
934   result->GetElementAt(0).Get(resultStartFrame);
935   result->GetElementAt(1).Get(resultEndFrame);
936
937   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
938   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
939
940   // Set invalid play range
941   array.Clear();
942   array.PushBack(1);
943   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
944
945   attributes.Clear();
946   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
947   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
948
949   // To make event trigger
950   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
951
952   application.SendNotification();
953   application.Render();
954
955   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
956
957   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
958   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
959
960   result = value->GetArray();
961   result->GetElementAt(0).Get(resultStartFrame);
962   result->GetElementAt(1).Get(resultEndFrame);
963
964   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
965   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
966
967   END_TEST;
968 }
969
970 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
971 {
972   ToolkitTestApplication application;
973   tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
974
975   Property::Map propertyMap;
976   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
977     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
978
979   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
980   DALI_TEST_CHECK(visual);
981
982   DummyControl      actor     = DummyControl::New(true);
983   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
984   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
985
986   DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
987
988   Vector2 controlSize(20.f, 30.f);
989   actor.SetProperty(Actor::Property::SIZE, controlSize);
990
991   application.GetScene().Add(actor);
992
993   application.SendNotification();
994   application.Render();
995
996   // Trigger count is 1 - render a frame
997   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
998
999   propertyMap.Clear();
1000   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1001   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1002
1003   Property::Map attributes;
1004   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1005
1006   application.SendNotification();
1007   application.Render();
1008
1009   // Wait for animation finish
1010   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1011
1012   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1013   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
1014   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
1015
1016   DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
1017
1018   END_TEST;
1019 }
1020
1021 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
1022 {
1023   ToolkitTestApplication application;
1024   tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
1025
1026   Property::Map propertyMap;
1027   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1028     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1029     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1030     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1031
1032   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1033   DALI_TEST_CHECK(visual);
1034
1035   tet_printf("1. Visual is created.\n");
1036
1037   DummyControl      actor     = DummyControl::New(true);
1038   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1039   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1040
1041   Vector2 controlSize(20.f, 30.f);
1042   actor.SetProperty(Actor::Property::SIZE, controlSize);
1043
1044   application.GetScene().Add(actor);
1045
1046   application.SendNotification();
1047   application.Render();
1048
1049   // Trigger count is 2 - load & render a frame
1050   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1051
1052   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1053
1054   // To make event trigger
1055   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1056
1057   application.SendNotification();
1058   application.Render();
1059
1060   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1061
1062   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1063   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1064   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1065
1066   tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1067
1068   Property::Array array;
1069   array.PushBack(0);
1070   array.PushBack(2);
1071
1072   Property::Map attributes;
1073   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1074   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1075
1076   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1077
1078   // To make event trigger
1079   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1080
1081   application.SendNotification();
1082   application.Render();
1083
1084   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1085
1086   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1087   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1088   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1089
1090   tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1091
1092   // Change play range
1093   attributes.Clear();
1094   array.Clear();
1095
1096   array.PushBack(0);
1097   array.PushBack(4);
1098
1099   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1100   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1101
1102   attributes.Clear();
1103   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1104
1105   application.SendNotification();
1106   application.Render();
1107
1108   // Wait for animation finish
1109   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1110
1111   // Jump to 3
1112   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1113
1114   // To make event trigger
1115   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1116
1117   application.SendNotification();
1118   application.Render();
1119
1120   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1121
1122   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1123   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1124   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1125
1126   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1127
1128   // Jump to the same position
1129   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1130
1131   // To make event trigger
1132   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1133
1134   application.SendNotification();
1135   application.Render();
1136
1137   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1138
1139   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1140   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1141   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1142
1143   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1144
1145   END_TEST;
1146 }
1147
1148 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1149 {
1150   ToolkitTestApplication application;
1151   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1152
1153   int             startFrame = 1, endFrame = 3;
1154   Property::Array playRange;
1155   playRange.PushBack(startFrame);
1156   playRange.PushBack(endFrame);
1157
1158   Property::Map propertyMap;
1159   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1160     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1161     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1162     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1163     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1164
1165   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1166   DALI_TEST_CHECK(visual);
1167
1168   DummyControl      actor     = DummyControl::New(true);
1169   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1170   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1171
1172   Vector2 controlSize(20.f, 30.f);
1173   actor.SetProperty(Actor::Property::SIZE, controlSize);
1174
1175   application.GetScene().Add(actor);
1176
1177   application.SendNotification();
1178   application.Render();
1179
1180   // Trigger count is 2 - load & render a frame
1181   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1182
1183   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1184   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1185   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1186
1187   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1188   DALI_TEST_CHECK(value);
1189
1190   Property::Array* result = value->GetArray();
1191   DALI_TEST_CHECK(result);
1192
1193   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1194   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1195
1196   playRange.Clear();
1197   playRange.PushBack(0);
1198   playRange.PushBack(2);
1199
1200   Property::Map attributes;
1201   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1202   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1203
1204   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1205
1206   // To make event trigger
1207   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1208
1209   application.SendNotification();
1210   application.Render();
1211
1212   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1213
1214   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1215   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1216   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1217
1218   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1219   result = value->GetArray();
1220   DALI_TEST_CHECK(result);
1221
1222   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1223   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1224
1225   attributes.Clear();
1226
1227   playRange.Clear();
1228   playRange.PushBack(startFrame);
1229   playRange.PushBack(endFrame);
1230
1231   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1232
1233   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1234
1235   // To make event trigger
1236   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1237
1238   application.SendNotification();
1239   application.Render();
1240
1241   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1242
1243   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1244   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1245
1246   result = value->GetArray();
1247   DALI_TEST_CHECK(result);
1248
1249   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1250   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1251
1252   // Play and update property
1253   attributes.Clear();
1254   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1255
1256   application.SendNotification();
1257   application.Render();
1258
1259   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1260
1261   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1262
1263   application.SendNotification();
1264   application.Render();
1265
1266   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1267   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1268   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1269
1270   END_TEST;
1271 }
1272
1273 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1274 {
1275   ToolkitTestApplication application;
1276   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1277
1278   Property::Map propertyMap;
1279   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1280     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1281     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1282
1283   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1284   DALI_TEST_CHECK(visual);
1285
1286   DummyControl      actor     = DummyControl::New(true);
1287   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1288   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1289
1290   Vector2 controlSize(20.f, 30.f);
1291   actor.SetProperty(Actor::Property::SIZE, controlSize);
1292
1293   application.GetScene().Add(actor);
1294
1295   application.SendNotification();
1296   application.Render();
1297
1298   // Trigger count is 2 - load & render a frame
1299   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1300
1301   propertyMap.Clear();
1302   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1303   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
1304   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1305
1306   Property::Map attributes;
1307   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1308
1309   application.SendNotification();
1310   application.Render();
1311
1312   // Trigger count is 1 - animation finished
1313   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1314
1315   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1316   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1317   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1318
1319   // Change stop behavior
1320   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1321
1322   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1323
1324   attributes.Clear();
1325
1326   // Play again
1327   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1328
1329   application.SendNotification();
1330   application.Render();
1331
1332   // Trigger count is 1 - animation finished
1333   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1334
1335   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1336
1337   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1338   int              totalFrameNumber = value1->Get<int>();
1339
1340   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1341   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1342
1343   // Change stop behavior
1344   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1345   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1346
1347   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1348
1349   attributes.Clear();
1350
1351   // Play again
1352   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1353
1354   application.SendNotification();
1355   application.Render();
1356
1357   // Pause
1358   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1359
1360   // To make event trigger
1361   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1362
1363   application.SendNotification();
1364   application.Render();
1365
1366   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1367
1368   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1369   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1370   int currentFrameNumber = value->Get<int>();
1371
1372   // Stop
1373   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1374
1375   // To make event trigger
1376   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1377
1378   application.SendNotification();
1379   application.Render();
1380
1381   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1382
1383   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1384   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1385   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1386
1387   END_TEST;
1388 }
1389
1390 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1391 {
1392   ToolkitTestApplication application;
1393   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1394
1395   Property::Map propertyMap;
1396   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1397     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1398     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1399
1400   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1401   DALI_TEST_CHECK(visual);
1402
1403   DummyControl      actor     = DummyControl::New(true);
1404   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1405   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1406
1407   Vector2 controlSize(20.f, 30.f);
1408   actor.SetProperty(Actor::Property::SIZE, controlSize);
1409
1410   application.GetScene().Add(actor);
1411
1412   application.SendNotification();
1413   application.Render();
1414
1415   // Trigger count is 2 - load, render
1416   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1417
1418   propertyMap.Clear();
1419   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1420   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1421   propertyMap.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE);
1422   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1423
1424   Property::Map attributes;
1425   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1426
1427   application.SendNotification();
1428   application.Render();
1429
1430   // Trigger count is 1 - animation finished
1431   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1432
1433   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1434   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1435   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1436
1437   // Change stop behavior
1438   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1439
1440   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1441
1442   // Play again
1443   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1444
1445   application.SendNotification();
1446   application.Render();
1447
1448   // Trigger count is 1 - animation finished
1449   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1450
1451   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1452   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1453   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1454
1455   // Change looping mode
1456   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1457
1458   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1459
1460   // Play again
1461   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1462
1463   application.SendNotification();
1464   application.Render();
1465
1466   // Trigger count is 1 - animation finished
1467   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1468
1469   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1470   int              totalFrameNumber = value1->Get<int>();
1471
1472   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1473   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1474   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1475
1476   END_TEST;
1477 }
1478
1479 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1480 {
1481   ToolkitTestApplication application;
1482   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1483
1484   Property::Map propertyMap;
1485   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1486     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1487
1488   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1489   DALI_TEST_CHECK(visual);
1490
1491   DummyControl      actor     = DummyControl::New(true);
1492   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1493   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1494   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1495
1496   application.GetScene().Add(actor);
1497
1498   application.SendNotification();
1499   application.Render();
1500
1501   // Trigger count is 1 - render a frame
1502   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1503
1504   Renderer renderer = actor.GetRendererAt(0u);
1505   DALI_TEST_CHECK(renderer);
1506
1507   Vector2 controlSize(20.f, 30.f);
1508   actor.SetProperty(Actor::Property::SIZE, controlSize);
1509
1510   application.SendNotification();
1511   application.Render();
1512
1513   application.SendNotification();
1514   application.Render();
1515
1516   // Trigger count is 1 - render a frame
1517   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1518
1519   auto textureSet = renderer.GetTextures();
1520   auto texture    = textureSet.GetTexture(0);
1521
1522   DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1523   DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1524
1525   // Change scale
1526   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1527   actor.SetProperty(Actor::Property::SCALE, controlScale);
1528
1529   application.SendNotification();
1530   application.Render();
1531
1532   application.SendNotification();
1533   application.Render();
1534
1535   // Trigger count is 1 - render a frame
1536   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1537
1538   renderer = actor.GetRendererAt(0u);
1539   DALI_TEST_CHECK(renderer);
1540
1541   textureSet = renderer.GetTextures();
1542   texture    = textureSet.GetTexture(0);
1543
1544   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1545   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1546
1547   // Size animation
1548   controlSize         = Vector2(50.0f, 100.0f);
1549   Animation animation = Animation::New(1.0);
1550   animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1551   animation.Play();
1552
1553   application.SendNotification();
1554   application.Render(1100); // After the animation
1555
1556   application.SendNotification();
1557   application.Render();
1558
1559   // Trigger count is 1 - render a frame
1560   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1561
1562   renderer = actor.GetRendererAt(0u);
1563   DALI_TEST_CHECK(renderer);
1564
1565   textureSet = renderer.GetTextures();
1566   texture    = textureSet.GetTexture(0);
1567
1568   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1569   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1570
1571   END_TEST;
1572 }
1573
1574 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1575 {
1576   ToolkitTestApplication application;
1577   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1578
1579   Property::Map propertyMap;
1580   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1581     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1582     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1583
1584   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1585   DALI_TEST_CHECK(visual1);
1586
1587   DummyControl      actor1     = DummyControl::New(true);
1588   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1589   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1590
1591   Vector2 controlSize(20.f, 30.f);
1592   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1593
1594   application.GetScene().Add(actor1);
1595
1596   application.SendNotification();
1597   application.Render();
1598
1599   // Trigger count is 2 - load & render a frame
1600   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1601
1602   propertyMap.Clear();
1603   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1604     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1605     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1606
1607   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1608   DALI_TEST_CHECK(visual2);
1609
1610   DummyControl      actor2     = DummyControl::New(true);
1611   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1612   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1613
1614   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1615
1616   application.GetScene().Add(actor2);
1617
1618   application.SendNotification();
1619   application.Render();
1620
1621   // Trigger count is 2 - load & render a frame
1622   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1623
1624   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1625
1626   // To make event trigger
1627   actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1628
1629   application.SendNotification();
1630   application.Render();
1631
1632   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1633
1634   Property::Map attributes;
1635   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1636
1637   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1638   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1639
1640   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1641
1642   // renderer is added to actor
1643   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1644   Renderer renderer1 = actor1.GetRendererAt(0u);
1645   DALI_TEST_CHECK(renderer1);
1646
1647   // renderer is added to actor
1648   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1649   Renderer renderer2 = actor2.GetRendererAt(0u);
1650   DALI_TEST_CHECK(renderer2);
1651
1652   END_TEST;
1653 }
1654
1655 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1656 {
1657   ToolkitTestApplication application;
1658   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1659
1660   Property::Map propertyMap;
1661   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1662     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1663     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1664
1665   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1666   DALI_TEST_CHECK(visual);
1667
1668   DummyControl      actor     = DummyControl::New(true);
1669   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1670   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1671
1672   Vector2 controlSize(20.f, 30.f);
1673   actor.SetProperty(Actor::Property::SIZE, controlSize);
1674
1675   application.GetScene().Add(actor);
1676
1677   application.SendNotification();
1678   application.Render();
1679
1680   // Trigger count is 2 - load & render a frame
1681   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1682
1683   Property::Map attributes;
1684   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1685
1686   application.SendNotification();
1687   application.Render();
1688
1689   // Check rendering behavior
1690   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1691   Renderer renderer = actor.GetRendererAt(0u);
1692   DALI_TEST_CHECK(renderer);
1693   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1694
1695   actor.SetProperty(Actor::Property::VISIBLE, false);
1696
1697   application.SendNotification();
1698   application.Render();
1699
1700   // Check rendering behavior again
1701   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1702
1703   END_TEST;
1704 }
1705
1706 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1707 {
1708   ToolkitTestApplication application;
1709   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1710
1711   Property::Map propertyMap;
1712   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1713     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1714
1715   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1716   DALI_TEST_CHECK(visual);
1717
1718   DummyControl      actor     = DummyControl::New(true);
1719   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1720   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1721
1722   Vector2 controlSize(20.f, 30.f);
1723   actor.SetProperty(Actor::Property::SIZE, controlSize);
1724
1725   application.GetScene().Add(actor);
1726
1727   application.SendNotification();
1728   application.Render();
1729
1730   // Trigger count is 1 - render a frame
1731   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1732
1733   Property::Map attributes;
1734   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1735
1736   application.SendNotification();
1737   application.Render();
1738
1739   // Check rendering behavior
1740   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1741   Renderer renderer = actor.GetRendererAt(0u);
1742   DALI_TEST_CHECK(renderer);
1743   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1744
1745   Window window = DevelWindow::Get(actor);
1746   window.Hide();
1747
1748   application.SendNotification();
1749   application.Render();
1750
1751   // Check rendering behavior again
1752   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1753
1754   END_TEST;
1755 }
1756
1757 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1758 {
1759   ToolkitTestApplication application;
1760   tet_infoline("Request loading with invalid file - should draw broken image");
1761
1762   TestGlAbstraction& gl           = application.GetGlAbstraction();
1763   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1764   textureTrace.Enable(true);
1765
1766   Property::Map propertyMap;
1767   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1768     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1769     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1770
1771   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1772   DALI_TEST_CHECK(visual);
1773
1774   DummyControl      actor     = DummyControl::New(true);
1775   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1776   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1777
1778   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1779
1780   application.GetScene().Add(actor);
1781
1782   application.SendNotification();
1783   application.Render();
1784
1785   // Trigger count is 1 - load
1786   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1787
1788   application.SendNotification();
1789   application.Render();
1790
1791   // Check resource status
1792   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1793   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1794
1795   // The broken image should be shown.
1796   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1797   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1798
1799   END_TEST;
1800 }
1801
1802 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
1803 {
1804   ToolkitTestApplication application;
1805   tet_infoline("Request loading with invalid file - should draw broken image");
1806
1807   TestGlAbstraction& gl           = application.GetGlAbstraction();
1808   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1809   textureTrace.Enable(true);
1810
1811   Property::Map propertyMap;
1812   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1813     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1814
1815   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1816   DALI_TEST_CHECK(visual);
1817
1818   DummyControl      actor     = DummyControl::New(true);
1819   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1820   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1821
1822   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1823
1824   application.SendNotification();
1825   application.Render();
1826
1827   // Add to the Scene after loading
1828   application.GetScene().Add(actor);
1829
1830   application.SendNotification();
1831   application.Render();
1832
1833   // Check resource status
1834   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1835   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1836
1837   // The broken image should be shown.
1838   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1839   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1840
1841   END_TEST;
1842 }
1843
1844 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
1845 {
1846   ToolkitTestApplication application;
1847   tet_infoline("Request loading with invalid file without size set - should draw broken image");
1848
1849   TestGlAbstraction& gl           = application.GetGlAbstraction();
1850   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1851   textureTrace.Enable(true);
1852
1853   Property::Map propertyMap;
1854   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1855     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1856     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1857
1858   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1859   DALI_TEST_CHECK(visual);
1860
1861   DummyControl      actor     = DummyControl::New(true);
1862   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1863   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1864
1865   application.GetScene().Add(actor);
1866
1867   application.SendNotification();
1868   application.Render();
1869
1870   // Trigger count is 1 - load
1871   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1872
1873   application.SendNotification();
1874   application.Render();
1875
1876   // Check resource status
1877   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1878   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1879
1880   // The broken image should be shown.
1881   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1882   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1883
1884   END_TEST;
1885 }
1886
1887 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1888 {
1889   ToolkitTestApplication application;
1890   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1891
1892   Property::Map propertyMap;
1893   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1894     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
1895     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1896
1897   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1898   DALI_TEST_CHECK(visual);
1899
1900   DummyControl      actor     = DummyControl::New(true);
1901   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1902   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1903
1904   Vector2 controlSize(20.f, 30.f);
1905   actor.SetProperty(Actor::Property::SIZE, controlSize);
1906
1907   application.GetScene().Add(actor);
1908
1909   application.SendNotification();
1910   application.Render();
1911
1912   // Trigger count is 2 - load, render the first frame
1913   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1914
1915   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1916   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1917   int              totalFrameNumber = value->Get<int>();
1918
1919   Property::Map attributes;
1920   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1921
1922   // Make delay to drop frames
1923   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
1924
1925   application.SendNotification();
1926   application.Render();
1927
1928   // Trigger count is 1 - calculating frame drops
1929   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1930
1931   // Check dropped frame
1932   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
1933   DALI_TEST_CHECK(frames > 0);
1934   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
1935
1936   END_TEST;
1937 }
1938
1939 int UtcDaliAnimatedVectorImageVisualSize(void)
1940 {
1941   ToolkitTestApplication application;
1942   tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
1943
1944   TestGlAbstraction& gl           = application.GetGlAbstraction();
1945   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1946
1947   VisualFactory factory = VisualFactory::Get();
1948   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
1949   DALI_TEST_CHECK(visual);
1950
1951   DummyControl      actor     = DummyControl::New(true);
1952   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1953   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1954
1955   application.GetScene().Add(actor);
1956
1957   application.SendNotification();
1958   application.Render();
1959
1960   // Trigger count is 1 - resource ready
1961   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1962
1963   textureTrace.Enable(true);
1964
1965   application.SendNotification();
1966   application.Render();
1967
1968   {
1969     int               width = 100, height = 100; // 100x100 is the content default size.
1970     std::stringstream out;
1971     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1972     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1973   }
1974
1975   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
1976
1977   application.SendNotification();
1978   application.Render();
1979
1980   // Trigger count is 1 - resource ready
1981   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1982
1983   textureTrace.Reset();
1984
1985   application.SendNotification();
1986   application.Render();
1987
1988   {
1989     int               width = 200, height = 200;
1990     std::stringstream out;
1991     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1992     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1993   }
1994
1995   END_TEST;
1996 }
1997
1998 namespace
1999 {
2000 bool gDynamicPropertyCallbackFired = false;
2001
2002 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
2003 {
2004   gDynamicPropertyCallbackFired = true;
2005
2006   if(frameNumber < 3)
2007   {
2008     return Vector3(0, 0, 1);
2009   }
2010   else
2011   {
2012     return Vector3(1, 0, 0);
2013   }
2014 }
2015 } // namespace
2016
2017 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
2018 {
2019   ToolkitTestApplication application;
2020   tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
2021
2022   VisualFactory factory = VisualFactory::Get();
2023   Visual::Base  visual  = factory.CreateVisual(
2024     Property::Map()
2025       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2026       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2027       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
2028   DALI_TEST_CHECK(visual);
2029
2030   DummyControl      actor     = DummyControl::New(true);
2031   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2032   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2033
2034   Vector2 controlSize(20.f, 30.f);
2035   actor.SetProperty(Actor::Property::SIZE, controlSize);
2036
2037   application.GetScene().Add(actor);
2038
2039   gDynamicPropertyCallbackFired = false;
2040
2041   // Set dynamic property
2042   DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
2043   info.id       = 1;
2044   info.keyPath  = "Test.Path";
2045   info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
2046   info.callback = MakeCallback(FillColorCallback);
2047
2048   DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
2049
2050   Property::Map attributes;
2051   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2052
2053   application.SendNotification();
2054   application.Render();
2055
2056   // Trigger count is 2 - load & render a frame
2057   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2058
2059   // Test whether the property callback is called
2060   DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2061
2062   END_TEST;
2063 }
2064
2065 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2066 {
2067   ToolkitTestApplication application;
2068   tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2069
2070   TestGlAbstraction& gl           = application.GetGlAbstraction();
2071   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2072   int                desiredWidth = 150, desiredHeight = 200;
2073
2074   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2075   DALI_TEST_CHECK(visual);
2076
2077   DummyControl      actor     = DummyControl::New(true);
2078   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2079   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2080
2081   application.GetScene().Add(actor);
2082
2083   application.SendNotification();
2084   application.Render();
2085
2086   // Trigger count is 1 - resource ready
2087   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2088
2089   textureTrace.Enable(true);
2090
2091   application.SendNotification();
2092   application.Render();
2093
2094   {
2095     std::stringstream out;
2096     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2097     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2098   }
2099
2100   // Unparent to make next trigger
2101   actor.Unparent();
2102
2103   application.SendNotification();
2104   application.Render();
2105
2106   // Set visual size
2107   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2108   application.GetScene().Add(actor);
2109
2110   application.SendNotification();
2111   application.Render();
2112
2113   // Trigger count is 1 - resource ready
2114   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2115
2116   textureTrace.Reset();
2117
2118   application.SendNotification();
2119   application.Render();
2120
2121   {
2122     std::stringstream out;
2123     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2124     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
2125   }
2126
2127   END_TEST;
2128 }
2129
2130 int UtcDaliAnimatedVectorImageVisualFlushAction(void)
2131 {
2132   ToolkitTestApplication application;
2133
2134   tet_infoline("UtcDaliAnimatedVectorImageVisualFlushAction");
2135
2136   int startFrame = 1;
2137   int endFrame   = 2;
2138
2139   int totalFrameCount = 0;
2140
2141   Property::Array playRange;
2142   playRange.PushBack(startFrame);
2143   playRange.PushBack(endFrame);
2144
2145   Property::Map    resultMap;
2146   Property::Value* value = nullptr;
2147
2148   // request AnimatedVectorImageVisual with a property map
2149   VisualFactory factory = VisualFactory::Get();
2150   Visual::Base  visual  = factory.CreateVisual(
2151     Property::Map()
2152       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2153       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2154       .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
2155       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true));
2156
2157   DummyControl        dummyControl = DummyControl::New(true);
2158   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
2159   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2160   dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
2161
2162   application.GetScene().Add(dummyControl);
2163
2164   // Retry function to get playrange until expect values comes.
2165   auto CheckAndRetryPlayRange = [&](int expectStartFrame, int expectEndFrame, std::vector<std::pair<int, int>> retrialFrames) {
2166     int tryCount    = 0;
2167     int tryCountMax = 30;
2168     while(++tryCount <= tryCountMax)
2169     {
2170       Property::Map resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2171
2172       Property::Value* value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
2173       DALI_TEST_CHECK(value);
2174
2175       Property::Array* result = value->GetArray();
2176       DALI_TEST_CHECK(result);
2177       DALI_TEST_EQUALS(result->Count(), 2, TEST_LOCATION);
2178
2179       bool tryAgain = false;
2180       for(auto& framePair : retrialFrames)
2181       {
2182         if(result->GetElementAt(0).Get<int>() == framePair.first && result->GetElementAt(1).Get<int>() == framePair.second)
2183         {
2184           tryAgain = true;
2185           break;
2186         }
2187       }
2188       if(tryAgain)
2189       {
2190         tet_printf("Retry to get value again! [%d]\n", tryCount);
2191         // Dummy sleep 1 second.
2192         Test::WaitForEventThreadTrigger(1, 1);
2193         continue;
2194       }
2195
2196       DALI_TEST_EQUALS(result->GetElementAt(0).Get<int>(), expectStartFrame, TEST_LOCATION);
2197       DALI_TEST_EQUALS(result->GetElementAt(1).Get<int>(), expectEndFrame, TEST_LOCATION);
2198       break;
2199     }
2200     DALI_TEST_CHECK(tryCount <= tryCountMax);
2201   };
2202
2203   tet_printf("Pause lottie first.\n");
2204
2205   Property::Map attributes;
2206   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
2207
2208   application.SendNotification();
2209   application.Render(16);
2210
2211   do
2212   {
2213     resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2214
2215     value = resultMap.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER, Property::INTEGER);
2216     DALI_TEST_CHECK(value);
2217     totalFrameCount = value->Get<int>();
2218   } while(totalFrameCount == 0);
2219
2220   // Ensure that vector data sended well.
2221   CheckAndRetryPlayRange(startFrame, endFrame, {{0, 0}, {0, totalFrameCount - 1}});
2222
2223   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2224
2225   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2226   DALI_TEST_CHECK(value);
2227   DALI_TEST_EQUALS(value->Get<int>(), startFrame, TEST_LOCATION);
2228
2229   tet_printf("Now logically, range : [%d~%d], current : %d\n", startFrame, endFrame, startFrame);
2230
2231   int changedStartFrame1 = startFrame + 2;
2232   int changedEndFrame1   = endFrame + 2;
2233
2234   playRange.Clear();
2235   playRange.Add(changedStartFrame1);
2236   playRange.Add(changedEndFrame1);
2237
2238   tet_printf("Change play range\n");
2239   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2240   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2241
2242   tet_printf("Jump to changedEndFrame!\n");
2243   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, changedEndFrame1);
2244
2245   attributes.Clear();
2246   tet_infoline("Flush Action!");
2247   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame1, changedEndFrame1, changedEndFrame1);
2248   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::FLUSH, attributes);
2249
2250   int changedStartFrame2 = startFrame + 1;
2251   int changedEndFrame2   = endFrame + 1;
2252
2253   playRange.Clear();
2254   playRange.Add(changedStartFrame2);
2255   playRange.Add(changedEndFrame2);
2256
2257   tet_printf("Change play range again\n");
2258   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame2, changedEndFrame2, changedEndFrame2);
2259   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2260   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2261
2262   application.SendNotification();
2263   application.Render(16);
2264
2265   // Ensure that vector data sended well.
2266   CheckAndRetryPlayRange(changedStartFrame2, changedEndFrame2, {{changedStartFrame1, changedEndFrame1}, {startFrame, endFrame}});
2267
2268   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2269
2270   tet_printf("Test whether current frame number changed well. If Flush not works, current frame become startFrame.");
2271   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2272   DALI_TEST_CHECK(value);
2273   DALI_TEST_EQUALS(value->Get<int>(), changedEndFrame2, TEST_LOCATION);
2274
2275   dummyControl.Unparent();
2276
2277   END_TEST;
2278 }