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