(AnimatedVector) Get marker informations
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedVectorImageVisual.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18 #include <chrono>
19 #include <iostream>
20 #include <thread>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-timer.h>
25 #include <toolkit-vector-animation-renderer.h>
26 #include "dummy-control.h"
27
28 #include <dali-toolkit/dali-toolkit.h>
29
30 #include <dali-toolkit/devel-api/controls/control-devel.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
33 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
34 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
35 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
36 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
37
38 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
39 #include <dali/devel-api/adaptor-framework/window-devel.h>
40 #include <dali/devel-api/rendering/renderer-devel.h>
41
42 using namespace Dali;
43 using namespace Dali::Toolkit;
44
45 void dali_animated_vector_image_visual_startup(void)
46 {
47   test_return_value = TET_UNDEF;
48 }
49
50 void dali_animated_vector_image_visual_cleanup(void)
51 {
52   test_return_value = TET_PASS;
53 }
54
55 namespace
56 {
57 const char* TEST_VECTOR_IMAGE_FILE_NAME            = TEST_RESOURCE_DIR "/insta_camera.json";
58 const char* TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP = "framedrop.json";
59 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME    = "invalid.json";
60
61 bool gAnimationFinishedSignalFired = false;
62
63 void VisualEventSignal(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId)
64 {
65   if(visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED)
66   {
67     gAnimationFinishedSignalFired = true;
68   }
69 }
70
71 } // namespace
72
73 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url");
77
78   VisualFactory factory = VisualFactory::Get();
79   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
80   DALI_TEST_CHECK(visual);
81
82   DummyControl      actor     = DummyControl::New(true);
83   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
84   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
85   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
86   application.GetScene().Add(actor);
87
88   application.SendNotification();
89   application.Render();
90
91   // Trigger count is 1 - render a frame
92   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
93
94   // renderer is added to actor
95   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
96   Renderer renderer = actor.GetRendererAt(0u);
97   DALI_TEST_CHECK(renderer);
98
99   // Test SetOffScene().
100   actor.Unparent();
101   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
102
103   END_TEST;
104 }
105
106 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
107 {
108   ToolkitTestApplication application;
109   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map");
110
111   Property::Map propertyMap;
112   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
113     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
114     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
115
116   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
117   DALI_TEST_CHECK(visual);
118
119   DummyControl      actor     = DummyControl::New(true);
120   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
121   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
122   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
123   application.GetScene().Add(actor);
124
125   application.SendNotification();
126   application.Render();
127
128   // Trigger count is 2 - load & render a frame
129   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
130
131   // renderer is added to actor
132   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
133   Renderer renderer = actor.GetRendererAt(0u);
134   DALI_TEST_CHECK(renderer);
135
136   actor.Unparent();
137   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
138
139   END_TEST;
140 }
141
142 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
143 {
144   ToolkitTestApplication application;
145   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map");
146
147   int             startFrame = 1, endFrame = 3;
148   Property::Array playRange;
149   playRange.PushBack(startFrame);
150   playRange.PushBack(endFrame);
151
152   Property::Map propertyMap;
153   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
154     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
155     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
156     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
157     .Add(DevelVisual::Property::CORNER_RADIUS, 50.0f)
158     .Add(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f)
159     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
160
161   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
162   DALI_TEST_CHECK(visual);
163
164   DummyControl      actor     = DummyControl::New(true);
165   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
166   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
167   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
168   application.GetScene().Add(actor);
169
170   application.SendNotification();
171   application.Render();
172
173   // Trigger count is 2 - load & render a frame
174   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
175
176   // renderer is added to actor
177   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
178   Renderer renderer = actor.GetRendererAt(0u);
179   DALI_TEST_CHECK(renderer);
180
181   actor.Unparent();
182   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
183
184   END_TEST;
185 }
186
187 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
188 {
189   ToolkitTestApplication application;
190   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map");
191
192   int             startFrame = 1, endFrame = 3;
193   int             desiredWidth = 100, desiredHeight = 150;
194   float           cornerRadius     = 22.0f;
195   float           borderlineWidth  = 2.0f;
196   Vector4         borderlineColor  = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
197   float           borderlineOffset = 0.1f;
198   Property::Array playRange;
199   playRange.PushBack(startFrame);
200   playRange.PushBack(endFrame);
201
202   Property::Map propertyMap;
203   propertyMap.Add("visualType", DevelVisual::ANIMATED_VECTOR_IMAGE)
204     .Add("url", TEST_VECTOR_IMAGE_FILE_NAME)
205     .Add("loopCount", 3)
206     .Add("playRange", playRange)
207     .Add("stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME)
208     .Add("loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE)
209     .Add("redrawInScalingDown", false)
210     .Add("cornerRadius", cornerRadius)
211     .Add("borderlineWidth", borderlineWidth)
212     .Add("borderlineColor", borderlineColor)
213     .Add("borderlineOffset", borderlineOffset)
214     .Add("desiredWidth", desiredWidth)
215     .Add("desiredHeight", desiredHeight);
216
217   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
218   DALI_TEST_CHECK(visual);
219
220   DummyControl      actor     = DummyControl::New(true);
221   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
222   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
223   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
224   application.GetScene().Add(actor);
225
226   application.SendNotification();
227   application.Render();
228
229   // Trigger count is 1 - render a frame
230   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
231
232   // renderer is added to actor
233   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
234
235   Renderer renderer = actor.GetRendererAt(0u);
236   DALI_TEST_CHECK(renderer);
237
238   Property::Map resultMap;
239   visual.CreatePropertyMap(resultMap);
240
241   // check the property values from the returned map from a visual
242   Property::Value* value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
243   DALI_TEST_CHECK(value);
244   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
245
246   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
247   DALI_TEST_CHECK(value);
248   DALI_TEST_CHECK(value->Get<int>() == 3);
249
250   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
251   DALI_TEST_CHECK(value);
252
253   Property::Array* result = value->GetArray();
254   DALI_TEST_CHECK(result);
255
256   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
257   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
258
259   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
260   DALI_TEST_CHECK(value);
261   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::FIRST_FRAME);
262
263   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
264   DALI_TEST_CHECK(value);
265   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::AUTO_REVERSE);
266
267   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
268   DALI_TEST_CHECK(value);
269   DALI_TEST_CHECK(value->Get<bool>() == false);
270
271   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
272   DALI_TEST_CHECK(value);
273   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION);
274
275   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
276   DALI_TEST_CHECK(value);
277   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
278
279   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
280   DALI_TEST_CHECK(value);
281   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
282
283   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
284   DALI_TEST_CHECK(value);
285   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
286
287   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
288   DALI_TEST_CHECK(value);
289   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
290
291   value = resultMap.Find(ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER);
292   DALI_TEST_CHECK(value);
293   DALI_TEST_EQUALS(value->Get<int>(), desiredWidth, TEST_LOCATION);
294
295   value = resultMap.Find(ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER);
296   DALI_TEST_CHECK(value);
297   DALI_TEST_EQUALS(value->Get<int>(), desiredHeight, TEST_LOCATION);
298
299   actor.Unparent();
300   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
301
302   END_TEST;
303 }
304
305 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
306 {
307   ToolkitTestApplication application;
308   tet_infoline("UtcDaliAnimatedVectorImageVisualGetPropertyMap01");
309
310   int             startFrame = 1, endFrame = 3;
311   int             desiredWidth = 100, desiredHeight = 150;
312   Vector4         cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
313   float           borderlineWidth  = 2.3f;
314   Vector4         borderlineColor  = Vector4(0.3f, 0.3f, 1.0f, 1.0f);
315   float           borderlineOffset = 0.3f;
316   Property::Array playRange;
317   playRange.PushBack(startFrame);
318   playRange.PushBack(endFrame);
319
320   Property::Map propertyMap;
321   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
322     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
323     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
324     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
325     .Add(DevelVisual::Property::CORNER_RADIUS, cornerRadius)
326     .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE)
327     .Add(DevelVisual::Property::BORDERLINE_WIDTH, borderlineWidth)
328     .Add(DevelVisual::Property::BORDERLINE_COLOR, borderlineColor)
329     .Add(DevelVisual::Property::BORDERLINE_OFFSET, borderlineOffset)
330     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false)
331     .Add(ImageVisual::Property::DESIRED_WIDTH, desiredWidth)
332     .Add(ImageVisual::Property::DESIRED_HEIGHT, desiredHeight);
333
334   // request AnimatedVectorImageVisual with a property map
335   VisualFactory factory = VisualFactory::Get();
336   Visual::Base  visual  = factory.CreateVisual(propertyMap);
337
338   DummyControl      actor     = DummyControl::New(true);
339   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
340   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
341
342   Vector2 controlSize(20.f, 30.f);
343   actor.SetProperty(Actor::Property::SIZE, controlSize);
344
345   application.GetScene().Add(actor);
346
347   application.SendNotification();
348   application.Render();
349
350   // Trigger count is 2 - load & render a frame
351   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
352
353   Property::Map resultMap;
354   resultMap = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
355
356   // check the property values from the returned map from a visual
357   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
358   DALI_TEST_CHECK(value);
359   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
360
361   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
362   DALI_TEST_CHECK(value);
363   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
364
365   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
366   DALI_TEST_CHECK(value);
367   DALI_TEST_CHECK(value->Get<int>() == 3);
368
369   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
370   DALI_TEST_CHECK(value);
371
372   Property::Array* result = value->GetArray();
373   DALI_TEST_CHECK(result);
374
375   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
376   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
377
378   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
379   DALI_TEST_CHECK(value);
380   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::CURRENT_FRAME);
381
382   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
383   DALI_TEST_CHECK(value);
384   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::RESTART);
385
386   value = resultMap.Find(DevelImageVisual::Property::CONTENT_INFO, Property::MAP);
387   DALI_TEST_CHECK(value);
388
389   value = resultMap.Find(DevelImageVisual::Property::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 UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
1053 {
1054   ToolkitTestApplication application;
1055   tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
1056
1057   Property::Map propertyMap;
1058   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1059     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1060
1061   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1062   DALI_TEST_CHECK(visual);
1063
1064   DummyControl      actor     = DummyControl::New(true);
1065   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1066   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1067
1068   DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
1069
1070   Vector2 controlSize(20.f, 30.f);
1071   actor.SetProperty(Actor::Property::SIZE, controlSize);
1072
1073   application.GetScene().Add(actor);
1074
1075   application.SendNotification();
1076   application.Render();
1077
1078   // Trigger count is 1 - render a frame
1079   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1080
1081   propertyMap.Clear();
1082   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1083   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1084
1085   Property::Map attributes;
1086   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1087
1088   application.SendNotification();
1089   application.Render();
1090
1091   // Wait for animation finish
1092   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1093
1094   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1095   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
1096   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
1097
1098   DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
1099
1100   END_TEST;
1101 }
1102
1103 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
1104 {
1105   ToolkitTestApplication application;
1106   tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
1107
1108   Property::Map propertyMap;
1109   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1110     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1111     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1112     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1113
1114   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1115   DALI_TEST_CHECK(visual);
1116
1117   tet_printf("1. Visual is created.\n");
1118
1119   DummyControl      actor     = DummyControl::New(true);
1120   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1121   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1122
1123   Vector2 controlSize(20.f, 30.f);
1124   actor.SetProperty(Actor::Property::SIZE, controlSize);
1125
1126   application.GetScene().Add(actor);
1127
1128   application.SendNotification();
1129   application.Render();
1130
1131   // Trigger count is 2 - load & render a frame
1132   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1133
1134   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1135
1136   // To make event trigger
1137   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1138
1139   application.SendNotification();
1140   application.Render();
1141
1142   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1143
1144   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1145   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1146   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1147
1148   tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1149
1150   Property::Array array;
1151   array.PushBack(0);
1152   array.PushBack(2);
1153
1154   Property::Map attributes;
1155   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1156   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1157
1158   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1159
1160   // To make event trigger
1161   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1162
1163   application.SendNotification();
1164   application.Render();
1165
1166   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1167
1168   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1169   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1170   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1171
1172   tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1173
1174   // Change play range
1175   attributes.Clear();
1176   array.Clear();
1177
1178   array.PushBack(0);
1179   array.PushBack(4);
1180
1181   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1182   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1183
1184   attributes.Clear();
1185   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1186
1187   application.SendNotification();
1188   application.Render();
1189
1190   // Wait for animation finish
1191   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1192
1193   // Jump to 3
1194   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1195
1196   // To make event trigger
1197   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1198
1199   application.SendNotification();
1200   application.Render();
1201
1202   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1203
1204   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1205   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1206   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1207
1208   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1209
1210   // Jump to the same position
1211   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1212
1213   // To make event trigger
1214   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1215
1216   application.SendNotification();
1217   application.Render();
1218
1219   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1220
1221   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1222   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1223   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1224
1225   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1226
1227   END_TEST;
1228 }
1229
1230 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1231 {
1232   ToolkitTestApplication application;
1233   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1234
1235   int             startFrame = 1, endFrame = 3;
1236   Property::Array playRange;
1237   playRange.PushBack(startFrame);
1238   playRange.PushBack(endFrame);
1239
1240   Property::Map propertyMap;
1241   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1242     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1243     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1244     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1245     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1246
1247   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1248   DALI_TEST_CHECK(visual);
1249
1250   DummyControl      actor     = DummyControl::New(true);
1251   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1252   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1253
1254   Vector2 controlSize(20.f, 30.f);
1255   actor.SetProperty(Actor::Property::SIZE, controlSize);
1256
1257   application.GetScene().Add(actor);
1258
1259   application.SendNotification();
1260   application.Render();
1261
1262   // Trigger count is 2 - load & render a frame
1263   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1264
1265   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1266   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1267   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1268
1269   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1270   DALI_TEST_CHECK(value);
1271
1272   Property::Array* result = value->GetArray();
1273   DALI_TEST_CHECK(result);
1274
1275   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1276   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1277
1278   playRange.Clear();
1279   playRange.PushBack(0);
1280   playRange.PushBack(2);
1281
1282   Property::Map attributes;
1283   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1284   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1285
1286   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1287
1288   // To make event trigger
1289   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1290
1291   application.SendNotification();
1292   application.Render();
1293
1294   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1295
1296   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1297   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1298   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1299
1300   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1301   result = value->GetArray();
1302   DALI_TEST_CHECK(result);
1303
1304   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1305   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1306
1307   attributes.Clear();
1308
1309   playRange.Clear();
1310   playRange.PushBack(startFrame);
1311   playRange.PushBack(endFrame);
1312
1313   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1314
1315   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1316
1317   // To make event trigger
1318   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1319
1320   application.SendNotification();
1321   application.Render();
1322
1323   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1324
1325   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1326   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1327
1328   result = value->GetArray();
1329   DALI_TEST_CHECK(result);
1330
1331   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1332   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1333
1334   // Play and update property
1335   attributes.Clear();
1336   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1337
1338   application.SendNotification();
1339   application.Render();
1340
1341   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1342
1343   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1344
1345   application.SendNotification();
1346   application.Render();
1347
1348   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1349   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1350   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1351
1352   END_TEST;
1353 }
1354
1355 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1356 {
1357   ToolkitTestApplication application;
1358   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1359
1360   Property::Map propertyMap;
1361   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1362     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1363     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1364
1365   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1366   DALI_TEST_CHECK(visual);
1367
1368   DummyControl      actor     = DummyControl::New(true);
1369   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1370   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1371
1372   Vector2 controlSize(20.f, 30.f);
1373   actor.SetProperty(Actor::Property::SIZE, controlSize);
1374
1375   application.GetScene().Add(actor);
1376
1377   application.SendNotification();
1378   application.Render();
1379
1380   // Trigger count is 2 - load & render a frame
1381   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1382
1383   propertyMap.Clear();
1384   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1385   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
1386   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1387
1388   Property::Map attributes;
1389   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1390
1391   application.SendNotification();
1392   application.Render();
1393
1394   // Trigger count is 1 - animation finished
1395   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1396
1397   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1398   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1399   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1400
1401   // Change stop behavior
1402   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1403
1404   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1405
1406   attributes.Clear();
1407
1408   // Play again
1409   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1410
1411   application.SendNotification();
1412   application.Render();
1413
1414   // Trigger count is 1 - animation finished
1415   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1416
1417   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1418
1419   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1420   int              totalFrameNumber = value1->Get<int>();
1421
1422   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1423   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1424
1425   // Change stop behavior
1426   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1427   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1428
1429   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1430
1431   attributes.Clear();
1432
1433   // Play again
1434   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1435
1436   application.SendNotification();
1437   application.Render();
1438
1439   // Pause
1440   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1441
1442   // To make event trigger
1443   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1444
1445   application.SendNotification();
1446   application.Render();
1447
1448   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1449
1450   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1451   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1452   int currentFrameNumber = value->Get<int>();
1453
1454   // Stop
1455   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1456
1457   // To make event trigger
1458   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1459
1460   application.SendNotification();
1461   application.Render();
1462
1463   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1464
1465   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1466   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1467   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1468
1469   END_TEST;
1470 }
1471
1472 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1473 {
1474   ToolkitTestApplication application;
1475   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1476
1477   Property::Map propertyMap;
1478   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1479     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1480     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1481
1482   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1483   DALI_TEST_CHECK(visual);
1484
1485   DummyControl      actor     = DummyControl::New(true);
1486   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1487   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1488
1489   Vector2 controlSize(20.f, 30.f);
1490   actor.SetProperty(Actor::Property::SIZE, controlSize);
1491
1492   application.GetScene().Add(actor);
1493
1494   application.SendNotification();
1495   application.Render();
1496
1497   // Trigger count is 2 - load, render
1498   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1499
1500   propertyMap.Clear();
1501   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1502   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1503   propertyMap.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE);
1504   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1505
1506   Property::Map attributes;
1507   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1508
1509   application.SendNotification();
1510   application.Render();
1511
1512   // Trigger count is 1 - animation finished
1513   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1514
1515   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1516   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1517   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1518
1519   // Change stop behavior
1520   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1521
1522   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1523
1524   // Play again
1525   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1526
1527   application.SendNotification();
1528   application.Render();
1529
1530   // Trigger count is 1 - animation finished
1531   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1532
1533   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1534   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1535   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1536
1537   // Change looping mode
1538   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1539
1540   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1541
1542   // Play again
1543   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1544
1545   application.SendNotification();
1546   application.Render();
1547
1548   // Trigger count is 1 - animation finished
1549   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1550
1551   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1552   int              totalFrameNumber = value1->Get<int>();
1553
1554   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1555   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1556   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1557
1558   END_TEST;
1559 }
1560
1561 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1562 {
1563   ToolkitTestApplication application;
1564   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1565
1566   Property::Map propertyMap;
1567   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1568     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1569
1570   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1571   DALI_TEST_CHECK(visual);
1572
1573   DummyControl      actor     = DummyControl::New(true);
1574   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1575   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1576   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1577
1578   application.GetScene().Add(actor);
1579
1580   application.SendNotification();
1581   application.Render();
1582
1583   // Trigger count is 1 - render a frame
1584   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1585
1586   Renderer renderer = actor.GetRendererAt(0u);
1587   DALI_TEST_CHECK(renderer);
1588
1589   Vector2 controlSize(20.f, 30.f);
1590   actor.SetProperty(Actor::Property::SIZE, controlSize);
1591
1592   application.SendNotification();
1593   application.Render();
1594
1595   application.SendNotification();
1596   application.Render();
1597
1598   // Trigger count is 1 - render a frame
1599   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1600
1601   auto textureSet = renderer.GetTextures();
1602   auto texture    = textureSet.GetTexture(0);
1603
1604   DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1605   DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1606
1607   // Change scale
1608   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1609   actor.SetProperty(Actor::Property::SCALE, controlScale);
1610
1611   application.SendNotification();
1612   application.Render();
1613
1614   application.SendNotification();
1615   application.Render();
1616
1617   // Trigger count is 1 - render a frame
1618   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1619
1620   renderer = actor.GetRendererAt(0u);
1621   DALI_TEST_CHECK(renderer);
1622
1623   textureSet = renderer.GetTextures();
1624   texture    = textureSet.GetTexture(0);
1625
1626   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1627   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1628
1629   // Size animation
1630   controlSize         = Vector2(50.0f, 100.0f);
1631   Animation animation = Animation::New(1.0);
1632   animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1633   animation.Play();
1634
1635   application.SendNotification();
1636   application.Render(1100); // After the animation
1637
1638   application.SendNotification();
1639   application.Render();
1640
1641   // Trigger count is 1 - render a frame
1642   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1643
1644   renderer = actor.GetRendererAt(0u);
1645   DALI_TEST_CHECK(renderer);
1646
1647   textureSet = renderer.GetTextures();
1648   texture    = textureSet.GetTexture(0);
1649
1650   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1651   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1652
1653   END_TEST;
1654 }
1655
1656 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1657 {
1658   ToolkitTestApplication application;
1659   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1660
1661   Property::Map propertyMap;
1662   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1663     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1664     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1665
1666   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1667   DALI_TEST_CHECK(visual1);
1668
1669   DummyControl      actor1     = DummyControl::New(true);
1670   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1671   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1672
1673   Vector2 controlSize(20.f, 30.f);
1674   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1675
1676   application.GetScene().Add(actor1);
1677
1678   application.SendNotification();
1679   application.Render();
1680
1681   // Trigger count is 2 - load & render a frame
1682   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1683
1684   propertyMap.Clear();
1685   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1686     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1687     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1688
1689   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1690   DALI_TEST_CHECK(visual2);
1691
1692   DummyControl      actor2     = DummyControl::New(true);
1693   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1694   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1695
1696   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1697
1698   application.GetScene().Add(actor2);
1699
1700   application.SendNotification();
1701   application.Render();
1702
1703   // Trigger count is 2 - load & render a frame
1704   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1705
1706   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1707
1708   // To make event trigger
1709   actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1710
1711   application.SendNotification();
1712   application.Render();
1713
1714   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1715
1716   Property::Map attributes;
1717   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1718
1719   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1720   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1721
1722   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1723
1724   // renderer is added to actor
1725   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1726   Renderer renderer1 = actor1.GetRendererAt(0u);
1727   DALI_TEST_CHECK(renderer1);
1728
1729   // renderer is added to actor
1730   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1731   Renderer renderer2 = actor2.GetRendererAt(0u);
1732   DALI_TEST_CHECK(renderer2);
1733
1734   END_TEST;
1735 }
1736
1737 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1738 {
1739   ToolkitTestApplication application;
1740   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1741
1742   Property::Map propertyMap;
1743   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1744     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1745     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1746
1747   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1748   DALI_TEST_CHECK(visual);
1749
1750   DummyControl      actor     = DummyControl::New(true);
1751   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1752   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1753
1754   Vector2 controlSize(20.f, 30.f);
1755   actor.SetProperty(Actor::Property::SIZE, controlSize);
1756
1757   application.GetScene().Add(actor);
1758
1759   application.SendNotification();
1760   application.Render();
1761
1762   // Trigger count is 2 - load & render a frame
1763   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1764
1765   Property::Map attributes;
1766   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1767
1768   application.SendNotification();
1769   application.Render();
1770
1771   // Check rendering behavior
1772   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1773   Renderer renderer = actor.GetRendererAt(0u);
1774   DALI_TEST_CHECK(renderer);
1775   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1776
1777   actor.SetProperty(Actor::Property::VISIBLE, false);
1778
1779   application.SendNotification();
1780   application.Render();
1781
1782   // Check rendering behavior again
1783   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1784
1785   END_TEST;
1786 }
1787
1788 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1789 {
1790   ToolkitTestApplication application;
1791   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1792
1793   Property::Map propertyMap;
1794   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1795     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1796
1797   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1798   DALI_TEST_CHECK(visual);
1799
1800   DummyControl      actor     = DummyControl::New(true);
1801   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1802   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1803
1804   Vector2 controlSize(20.f, 30.f);
1805   actor.SetProperty(Actor::Property::SIZE, controlSize);
1806
1807   application.GetScene().Add(actor);
1808
1809   application.SendNotification();
1810   application.Render();
1811
1812   // Trigger count is 1 - render a frame
1813   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1814
1815   Property::Map attributes;
1816   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1817
1818   application.SendNotification();
1819   application.Render();
1820
1821   // Check rendering behavior
1822   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1823   Renderer renderer = actor.GetRendererAt(0u);
1824   DALI_TEST_CHECK(renderer);
1825   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1826
1827   Window window = DevelWindow::Get(actor);
1828   window.Hide();
1829
1830   application.SendNotification();
1831   application.Render();
1832
1833   // Check rendering behavior again
1834   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1835
1836   END_TEST;
1837 }
1838
1839 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1840 {
1841   ToolkitTestApplication application;
1842   tet_infoline("Request loading with invalid file - should draw broken image");
1843
1844   TestGlAbstraction& gl           = application.GetGlAbstraction();
1845   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1846   textureTrace.Enable(true);
1847
1848   Property::Map propertyMap;
1849   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1850     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1851     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1852
1853   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1854   DALI_TEST_CHECK(visual);
1855
1856   DummyControl      actor     = DummyControl::New(true);
1857   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1858   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1859
1860   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1861
1862   application.GetScene().Add(actor);
1863
1864   application.SendNotification();
1865   application.Render();
1866
1867   // Trigger count is 1 - load
1868   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1869
1870   application.SendNotification();
1871   application.Render();
1872
1873   // Check resource status
1874   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1875   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1876
1877   // The broken image should be shown.
1878   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1879   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1880
1881   END_TEST;
1882 }
1883
1884 int UtcDaliAnimatedVectorImageVisualInvalidFile02(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
1897   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1898   DALI_TEST_CHECK(visual);
1899
1900   DummyControl      actor     = DummyControl::New(true);
1901   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1902   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1903
1904   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1905
1906   application.SendNotification();
1907   application.Render();
1908
1909   // Add to the Scene after loading
1910   application.GetScene().Add(actor);
1911
1912   application.SendNotification();
1913   application.Render();
1914
1915   // Check resource status
1916   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1917   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1918
1919   // The broken image should be shown.
1920   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1921   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1922
1923   END_TEST;
1924 }
1925
1926 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
1927 {
1928   ToolkitTestApplication application;
1929   tet_infoline("Request loading with invalid file without size set - should draw broken image");
1930
1931   TestGlAbstraction& gl           = application.GetGlAbstraction();
1932   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1933   textureTrace.Enable(true);
1934
1935   Property::Map propertyMap;
1936   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1937     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1938     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1939
1940   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1941   DALI_TEST_CHECK(visual);
1942
1943   DummyControl      actor     = DummyControl::New(true);
1944   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1945   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1946
1947   application.GetScene().Add(actor);
1948
1949   application.SendNotification();
1950   application.Render();
1951
1952   // Trigger count is 1 - load
1953   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1954
1955   application.SendNotification();
1956   application.Render();
1957
1958   // Check resource status
1959   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1960   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1961
1962   // The broken image should be shown.
1963   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1964   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1965
1966   END_TEST;
1967 }
1968
1969 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1970 {
1971   ToolkitTestApplication application;
1972   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1973
1974   Property::Map propertyMap;
1975   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1976     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
1977     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1978
1979   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1980   DALI_TEST_CHECK(visual);
1981
1982   DummyControl      actor     = DummyControl::New(true);
1983   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1984   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1985
1986   Vector2 controlSize(20.f, 30.f);
1987   actor.SetProperty(Actor::Property::SIZE, controlSize);
1988
1989   application.GetScene().Add(actor);
1990
1991   application.SendNotification();
1992   application.Render();
1993
1994   // Trigger count is 2 - load, render the first frame
1995   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1996
1997   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1998   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1999   int              totalFrameNumber = value->Get<int>();
2000
2001   Property::Map attributes;
2002   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2003
2004   // Make delay to drop frames
2005   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
2006
2007   application.SendNotification();
2008   application.Render();
2009
2010   // Trigger count is 1 - calculating frame drops
2011   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2012
2013   // Check dropped frame
2014   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
2015   DALI_TEST_CHECK(frames > 0);
2016   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
2017
2018   END_TEST;
2019 }
2020
2021 int UtcDaliAnimatedVectorImageVisualSize(void)
2022 {
2023   ToolkitTestApplication application;
2024   tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
2025
2026   TestGlAbstraction& gl           = application.GetGlAbstraction();
2027   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2028
2029   VisualFactory factory = VisualFactory::Get();
2030   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
2031   DALI_TEST_CHECK(visual);
2032
2033   DummyControl      actor     = DummyControl::New(true);
2034   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2035   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2036
2037   application.GetScene().Add(actor);
2038
2039   application.SendNotification();
2040   application.Render();
2041
2042   // Trigger count is 1 - resource ready
2043   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2044
2045   textureTrace.Enable(true);
2046
2047   application.SendNotification();
2048   application.Render();
2049
2050   {
2051     int               width = 100, height = 100; // 100x100 is the content default size.
2052     std::stringstream out;
2053     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2054     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2055   }
2056
2057   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
2058
2059   application.SendNotification();
2060   application.Render();
2061
2062   // Trigger count is 1 - resource ready
2063   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2064
2065   textureTrace.Reset();
2066
2067   application.SendNotification();
2068   application.Render();
2069
2070   {
2071     int               width = 200, height = 200;
2072     std::stringstream out;
2073     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2074     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2075   }
2076
2077   END_TEST;
2078 }
2079
2080 namespace
2081 {
2082 bool gDynamicPropertyCallbackFired = false;
2083
2084 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
2085 {
2086   gDynamicPropertyCallbackFired = true;
2087
2088   if(frameNumber < 3)
2089   {
2090     return Vector3(0, 0, 1);
2091   }
2092   else
2093   {
2094     return Vector3(1, 0, 0);
2095   }
2096 }
2097 } // namespace
2098
2099 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
2100 {
2101   ToolkitTestApplication application;
2102   tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
2103
2104   VisualFactory factory = VisualFactory::Get();
2105   Visual::Base  visual  = factory.CreateVisual(
2106     Property::Map()
2107       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2108       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2109       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
2110   DALI_TEST_CHECK(visual);
2111
2112   DummyControl      actor     = DummyControl::New(true);
2113   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2114   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2115
2116   Vector2 controlSize(20.f, 30.f);
2117   actor.SetProperty(Actor::Property::SIZE, controlSize);
2118
2119   application.GetScene().Add(actor);
2120
2121   gDynamicPropertyCallbackFired = false;
2122
2123   // Set dynamic property
2124   DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
2125   info.id       = 1;
2126   info.keyPath  = "Test.Path";
2127   info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
2128   info.callback = MakeCallback(FillColorCallback);
2129
2130   DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
2131
2132   Property::Map attributes;
2133   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2134
2135   application.SendNotification();
2136   application.Render();
2137
2138   // Trigger count is 2 - load & render a frame
2139   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2140
2141   // Test whether the property callback is called
2142   DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2143
2144   END_TEST;
2145 }
2146
2147 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2148 {
2149   ToolkitTestApplication application;
2150   tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2151
2152   TestGlAbstraction& gl           = application.GetGlAbstraction();
2153   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2154   int                desiredWidth = 150, desiredHeight = 200;
2155
2156   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2157   DALI_TEST_CHECK(visual);
2158
2159   DummyControl      actor     = DummyControl::New(true);
2160   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2161   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2162
2163   application.GetScene().Add(actor);
2164
2165   application.SendNotification();
2166   application.Render();
2167
2168   // Trigger count is 1 - resource ready
2169   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2170
2171   textureTrace.Enable(true);
2172
2173   application.SendNotification();
2174   application.Render();
2175
2176   {
2177     std::stringstream out;
2178     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2179     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2180   }
2181
2182   // Unparent to make next trigger
2183   actor.Unparent();
2184
2185   application.SendNotification();
2186   application.Render();
2187
2188   // Set visual size
2189   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2190   application.GetScene().Add(actor);
2191
2192   application.SendNotification();
2193   application.Render();
2194
2195   // Trigger count is 1 - resource ready
2196   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2197
2198   textureTrace.Reset();
2199
2200   application.SendNotification();
2201   application.Render();
2202
2203   {
2204     std::stringstream out;
2205     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2206     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
2207   }
2208
2209   END_TEST;
2210 }
2211
2212 int UtcDaliAnimatedVectorImageVisualFlushAction(void)
2213 {
2214   ToolkitTestApplication application;
2215
2216   tet_infoline("UtcDaliAnimatedVectorImageVisualFlushAction");
2217
2218   int startFrame = 1;
2219   int endFrame   = 2;
2220
2221   int totalFrameCount = 0;
2222
2223   Property::Array playRange;
2224   playRange.PushBack(startFrame);
2225   playRange.PushBack(endFrame);
2226
2227   Property::Map    resultMap;
2228   Property::Value* value = nullptr;
2229
2230   // request AnimatedVectorImageVisual with a property map
2231   VisualFactory factory = VisualFactory::Get();
2232   Visual::Base  visual  = factory.CreateVisual(
2233     Property::Map()
2234       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2235       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2236       .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
2237       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true));
2238
2239   DummyControl        dummyControl = DummyControl::New(true);
2240   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
2241   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2242   dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
2243
2244   application.GetScene().Add(dummyControl);
2245
2246   // Retry function to get playrange until expect values comes.
2247   auto CheckAndRetryPlayRange = [&](int expectStartFrame, int expectEndFrame, std::vector<std::pair<int, int>> retrialFrames) {
2248     int tryCount    = 0;
2249     int tryCountMax = 30;
2250     while(++tryCount <= tryCountMax)
2251     {
2252       Property::Map resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2253
2254       Property::Value* value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
2255       DALI_TEST_CHECK(value);
2256
2257       Property::Array* result = value->GetArray();
2258       DALI_TEST_CHECK(result);
2259       DALI_TEST_EQUALS(result->Count(), 2, TEST_LOCATION);
2260
2261       bool tryAgain = false;
2262       for(auto& framePair : retrialFrames)
2263       {
2264         if(result->GetElementAt(0).Get<int>() == framePair.first && result->GetElementAt(1).Get<int>() == framePair.second)
2265         {
2266           tryAgain = true;
2267           break;
2268         }
2269       }
2270       if(tryAgain)
2271       {
2272         tet_printf("Retry to get value again! [%d]\n", tryCount);
2273         // Dummy sleep 1 second.
2274         Test::WaitForEventThreadTrigger(1, 1);
2275         continue;
2276       }
2277
2278       DALI_TEST_EQUALS(result->GetElementAt(0).Get<int>(), expectStartFrame, TEST_LOCATION);
2279       DALI_TEST_EQUALS(result->GetElementAt(1).Get<int>(), expectEndFrame, TEST_LOCATION);
2280       break;
2281     }
2282     DALI_TEST_CHECK(tryCount <= tryCountMax);
2283   };
2284
2285   tet_printf("Pause lottie first.\n");
2286
2287   Property::Map attributes;
2288   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
2289
2290   application.SendNotification();
2291   application.Render(16);
2292
2293   do
2294   {
2295     resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2296
2297     value = resultMap.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER, Property::INTEGER);
2298     DALI_TEST_CHECK(value);
2299     totalFrameCount = value->Get<int>();
2300   } while(totalFrameCount == 0);
2301
2302   // Ensure that vector data sended well.
2303   CheckAndRetryPlayRange(startFrame, endFrame, {{0, 0}, {0, totalFrameCount - 1}});
2304
2305   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2306
2307   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2308   DALI_TEST_CHECK(value);
2309   DALI_TEST_EQUALS(value->Get<int>(), startFrame, TEST_LOCATION);
2310
2311   tet_printf("Now logically, range : [%d~%d], current : %d\n", startFrame, endFrame, startFrame);
2312
2313   int changedStartFrame1 = startFrame + 2;
2314   int changedEndFrame1   = endFrame + 2;
2315
2316   playRange.Clear();
2317   playRange.Add(changedStartFrame1);
2318   playRange.Add(changedEndFrame1);
2319
2320   tet_printf("Change play range\n");
2321   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2322   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2323
2324   tet_printf("Jump to changedEndFrame!\n");
2325   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, changedEndFrame1);
2326
2327   attributes.Clear();
2328   tet_infoline("Flush Action!");
2329   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame1, changedEndFrame1, changedEndFrame1);
2330   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::FLUSH, attributes);
2331
2332   int changedStartFrame2 = startFrame + 1;
2333   int changedEndFrame2   = endFrame + 1;
2334
2335   playRange.Clear();
2336   playRange.Add(changedStartFrame2);
2337   playRange.Add(changedEndFrame2);
2338
2339   tet_printf("Change play range again\n");
2340   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame2, changedEndFrame2, changedEndFrame2);
2341   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2342   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2343
2344   application.SendNotification();
2345   application.Render(16);
2346
2347   // Ensure that vector data sended well.
2348   CheckAndRetryPlayRange(changedStartFrame2, changedEndFrame2, {{changedStartFrame1, changedEndFrame1}, {startFrame, endFrame}});
2349
2350   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2351
2352   tet_printf("Test whether current frame number changed well. If Flush not works, current frame become startFrame.");
2353   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2354   DALI_TEST_CHECK(value);
2355   DALI_TEST_EQUALS(value->Get<int>(), changedEndFrame2, TEST_LOCATION);
2356
2357   dummyControl.Unparent();
2358
2359   END_TEST;
2360 }