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