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