Force call KeepRendering when lottie animation stopped, or frame changed
[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   // EventThread will be triggered after animation finished (For render forcibly).
1338   // TODO : Is this logic will works well on server-side?
1339   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1340
1341   // Jump to 3
1342   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1343
1344   // To make event trigger
1345   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1346
1347   application.SendNotification();
1348   application.Render();
1349
1350   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1351
1352   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1353   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1354   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1355
1356   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1357
1358   // Jump to the same position
1359   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1360
1361   // To make event trigger
1362   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1363
1364   application.SendNotification();
1365   application.Render();
1366
1367   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1368
1369   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1370   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1371   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1372
1373   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1374
1375   END_TEST;
1376 }
1377
1378 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1379 {
1380   ToolkitTestApplication application;
1381   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1382
1383   int             startFrame = 1, endFrame = 3;
1384   Property::Array playRange;
1385   playRange.PushBack(startFrame);
1386   playRange.PushBack(endFrame);
1387
1388   Property::Map propertyMap;
1389   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1390     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1391     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1392     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1393     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1394
1395   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1396   DALI_TEST_CHECK(visual);
1397
1398   DummyControl      actor     = DummyControl::New(true);
1399   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1400   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1401
1402   Vector2 controlSize(20.f, 30.f);
1403   actor.SetProperty(Actor::Property::SIZE, controlSize);
1404
1405   application.GetScene().Add(actor);
1406
1407   application.SendNotification();
1408   application.Render();
1409
1410   // Trigger count is 2 - load & render a frame
1411   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1412
1413   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1414   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1415   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1416
1417   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1418   DALI_TEST_CHECK(value);
1419
1420   Property::Array* result = value->GetArray();
1421   DALI_TEST_CHECK(result);
1422
1423   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1424   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1425
1426   playRange.Clear();
1427   playRange.PushBack(0);
1428   playRange.PushBack(2);
1429
1430   Property::Map attributes;
1431   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1432   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1433
1434   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1435
1436   // To make event trigger
1437   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1438
1439   application.SendNotification();
1440   application.Render();
1441
1442   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1443
1444   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1445   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1446   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1447
1448   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1449   result = value->GetArray();
1450   DALI_TEST_CHECK(result);
1451
1452   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1453   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1454
1455   attributes.Clear();
1456
1457   playRange.Clear();
1458   playRange.PushBack(startFrame);
1459   playRange.PushBack(endFrame);
1460
1461   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1462
1463   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1464
1465   // To make event trigger
1466   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1467
1468   application.SendNotification();
1469   application.Render();
1470
1471   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1472
1473   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1474   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1475
1476   result = value->GetArray();
1477   DALI_TEST_CHECK(result);
1478
1479   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1480   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1481
1482   // Play and update property
1483   attributes.Clear();
1484   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1485
1486   application.SendNotification();
1487   application.Render();
1488
1489   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1490
1491   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1492
1493   application.SendNotification();
1494   application.Render();
1495
1496   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1497   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1498   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1499
1500   END_TEST;
1501 }
1502
1503 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1504 {
1505   ToolkitTestApplication application;
1506   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1507
1508   Property::Map propertyMap;
1509   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1510     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1511     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1512
1513   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1514   DALI_TEST_CHECK(visual);
1515
1516   DummyControl      actor     = DummyControl::New(true);
1517   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1518   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1519
1520   Vector2 controlSize(20.f, 30.f);
1521   actor.SetProperty(Actor::Property::SIZE, controlSize);
1522
1523   application.GetScene().Add(actor);
1524
1525   application.SendNotification();
1526   application.Render();
1527
1528   // Trigger count is 2 - load & render a frame
1529   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1530
1531   propertyMap.Clear();
1532   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1533   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
1534   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1535
1536   Property::Map attributes;
1537   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1538
1539   application.SendNotification();
1540   application.Render();
1541
1542   // Trigger count is 1 - animation finished
1543   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1544
1545   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1546   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1547   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1548
1549   // Change stop behavior
1550   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1551
1552   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1553
1554   attributes.Clear();
1555
1556   // Play again
1557   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1558
1559   application.SendNotification();
1560   application.Render();
1561
1562   // Trigger count is 1 - animation finished
1563   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1564
1565   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1566
1567   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1568   int              totalFrameNumber = value1->Get<int>();
1569
1570   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1571   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1572
1573   // Change stop behavior
1574   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1575   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1576
1577   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1578
1579   attributes.Clear();
1580
1581   // Play again
1582   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1583
1584   application.SendNotification();
1585   application.Render();
1586
1587   // Pause
1588   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1589
1590   // To make event trigger
1591   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1592
1593   application.SendNotification();
1594   application.Render();
1595
1596   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1597
1598   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1599   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1600   int currentFrameNumber = value->Get<int>();
1601
1602   // Stop
1603   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1604
1605   // To make event trigger
1606   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1607
1608   application.SendNotification();
1609   application.Render();
1610
1611   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1612
1613   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1614   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1615   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1616
1617   END_TEST;
1618 }
1619
1620 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1621 {
1622   ToolkitTestApplication application;
1623   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1624
1625   Property::Map propertyMap;
1626   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1627     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1628     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1629
1630   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1631   DALI_TEST_CHECK(visual);
1632
1633   DummyControl      actor     = DummyControl::New(true);
1634   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1635   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1636
1637   Vector2 controlSize(20.f, 30.f);
1638   actor.SetProperty(Actor::Property::SIZE, controlSize);
1639
1640   application.GetScene().Add(actor);
1641
1642   application.SendNotification();
1643   application.Render();
1644
1645   // Trigger count is 2 - load, render
1646   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1647
1648   propertyMap.Clear();
1649   propertyMap.Add(DevelImageVisual::Property::LOOP_COUNT, 3);
1650   propertyMap.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1651   propertyMap.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE);
1652   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, propertyMap);
1653
1654   Property::Map attributes;
1655   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1656
1657   application.SendNotification();
1658   application.Render();
1659
1660   // Trigger count is 1 - animation finished
1661   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1662
1663   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1664   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1665   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1666
1667   // Change stop behavior
1668   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1669
1670   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1671
1672   // Play again
1673   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1674
1675   application.SendNotification();
1676   application.Render();
1677
1678   // Trigger count is 1 - animation finished
1679   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1680
1681   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1682   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1683   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1684
1685   // Change looping mode
1686   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1687
1688   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1689
1690   // Play again
1691   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1692
1693   application.SendNotification();
1694   application.Render();
1695
1696   // Trigger count is 1 - animation finished
1697   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1698
1699   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1700   int              totalFrameNumber = value1->Get<int>();
1701
1702   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1703   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1704   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1705
1706   END_TEST;
1707 }
1708
1709 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1710 {
1711   ToolkitTestApplication application;
1712   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1713
1714   Property::Map propertyMap;
1715   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1716     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1717
1718   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1719   DALI_TEST_CHECK(visual);
1720
1721   DummyControl      actor     = DummyControl::New(true);
1722   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1723   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1724   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1725
1726   application.GetScene().Add(actor);
1727
1728   application.SendNotification();
1729   application.Render();
1730
1731   // Trigger count is 1 - render a frame
1732   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1733
1734   Renderer renderer = actor.GetRendererAt(0u);
1735   DALI_TEST_CHECK(renderer);
1736
1737   Vector2 controlSize(20.f, 30.f);
1738   actor.SetProperty(Actor::Property::SIZE, controlSize);
1739
1740   application.SendNotification();
1741   application.Render();
1742
1743   application.SendNotification();
1744   application.Render();
1745
1746   // Trigger count is 1 - render a frame
1747   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1748
1749   auto textureSet = renderer.GetTextures();
1750   auto texture    = textureSet.GetTexture(0);
1751
1752   DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1753   DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1754
1755   // Change scale
1756   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1757   actor.SetProperty(Actor::Property::SCALE, controlScale);
1758
1759   application.SendNotification();
1760   application.Render();
1761
1762   application.SendNotification();
1763   application.Render();
1764
1765   // Trigger count is 1 - render a frame
1766   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1767
1768   renderer = actor.GetRendererAt(0u);
1769   DALI_TEST_CHECK(renderer);
1770
1771   textureSet = renderer.GetTextures();
1772   texture    = textureSet.GetTexture(0);
1773
1774   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1775   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1776
1777   // Size animation
1778   controlSize         = Vector2(50.0f, 100.0f);
1779   Animation animation = Animation::New(1.0);
1780   animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1781   animation.Play();
1782
1783   application.SendNotification();
1784   application.Render(1100); // After the animation
1785
1786   application.SendNotification();
1787   application.Render();
1788
1789   // Trigger count is 1 - render a frame
1790   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1791
1792   renderer = actor.GetRendererAt(0u);
1793   DALI_TEST_CHECK(renderer);
1794
1795   textureSet = renderer.GetTextures();
1796   texture    = textureSet.GetTexture(0);
1797
1798   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1799   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1800
1801   END_TEST;
1802 }
1803
1804 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1805 {
1806   ToolkitTestApplication application;
1807   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1808
1809   Property::Map propertyMap;
1810   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1811     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1812     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1813
1814   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1815   DALI_TEST_CHECK(visual1);
1816
1817   DummyControl      actor1     = DummyControl::New(true);
1818   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1819   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1820
1821   Vector2 controlSize(20.f, 30.f);
1822   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1823
1824   application.GetScene().Add(actor1);
1825
1826   application.SendNotification();
1827   application.Render();
1828
1829   // Trigger count is 2 - load & render a frame
1830   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1831
1832   propertyMap.Clear();
1833   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1834     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1835     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1836
1837   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1838   DALI_TEST_CHECK(visual2);
1839
1840   DummyControl      actor2     = DummyControl::New(true);
1841   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1842   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1843
1844   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1845
1846   application.GetScene().Add(actor2);
1847
1848   application.SendNotification();
1849   application.Render();
1850
1851   // Trigger count is 2 - load & render a frame
1852   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1853
1854   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1855
1856   // To make event trigger
1857   actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1858
1859   application.SendNotification();
1860   application.Render();
1861
1862   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1863
1864   Property::Map attributes;
1865   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1866
1867   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1868   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1869
1870   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1871
1872   // renderer is added to actor
1873   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1874   Renderer renderer1 = actor1.GetRendererAt(0u);
1875   DALI_TEST_CHECK(renderer1);
1876
1877   // renderer is added to actor
1878   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1879   Renderer renderer2 = actor2.GetRendererAt(0u);
1880   DALI_TEST_CHECK(renderer2);
1881
1882   END_TEST;
1883 }
1884
1885 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1886 {
1887   ToolkitTestApplication application;
1888   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1889
1890   Property::Map propertyMap;
1891   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1892     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1893     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1894
1895   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1896   DALI_TEST_CHECK(visual);
1897
1898   DummyControl      actor     = DummyControl::New(true);
1899   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1900   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1901
1902   Vector2 controlSize(20.f, 30.f);
1903   actor.SetProperty(Actor::Property::SIZE, controlSize);
1904
1905   application.GetScene().Add(actor);
1906
1907   application.SendNotification();
1908   application.Render();
1909
1910   // Trigger count is 2 - load & render a frame
1911   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1912
1913   Property::Map attributes;
1914   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1915
1916   application.SendNotification();
1917   application.Render();
1918
1919   // Check rendering behavior
1920   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1921   Renderer renderer = actor.GetRendererAt(0u);
1922   DALI_TEST_CHECK(renderer);
1923   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1924
1925   actor.SetProperty(Actor::Property::VISIBLE, false);
1926
1927   application.SendNotification();
1928   application.Render();
1929
1930   // Check rendering behavior again
1931   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1932
1933   END_TEST;
1934 }
1935
1936 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1937 {
1938   ToolkitTestApplication application;
1939   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1940
1941   Property::Map propertyMap;
1942   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1943     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1944
1945   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1946   DALI_TEST_CHECK(visual);
1947
1948   DummyControl      actor     = DummyControl::New(true);
1949   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1950   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1951
1952   Vector2 controlSize(20.f, 30.f);
1953   actor.SetProperty(Actor::Property::SIZE, controlSize);
1954
1955   application.GetScene().Add(actor);
1956
1957   application.SendNotification();
1958   application.Render();
1959
1960   // Trigger count is 1 - render a frame
1961   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1962
1963   Property::Map attributes;
1964   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1965
1966   application.SendNotification();
1967   application.Render();
1968
1969   // Check rendering behavior
1970   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1971   Renderer renderer = actor.GetRendererAt(0u);
1972   DALI_TEST_CHECK(renderer);
1973   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1974
1975   Window window = DevelWindow::Get(actor);
1976   window.Hide();
1977
1978   application.SendNotification();
1979   application.Render();
1980
1981   // Check rendering behavior again
1982   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1983
1984   END_TEST;
1985 }
1986
1987 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1988 {
1989   ToolkitTestApplication application;
1990   tet_infoline("Request loading with invalid file - should draw broken image");
1991
1992   TestGlAbstraction& gl           = application.GetGlAbstraction();
1993   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1994   textureTrace.Enable(true);
1995
1996   Property::Map propertyMap;
1997   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1998     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1999     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2000
2001   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2002   DALI_TEST_CHECK(visual);
2003
2004   DummyControl      actor     = DummyControl::New(true);
2005   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2006   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2007
2008   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
2009
2010   application.GetScene().Add(actor);
2011
2012   application.SendNotification();
2013   application.Render();
2014
2015   // Trigger count is 1 - load
2016   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2017
2018   application.SendNotification();
2019   application.Render();
2020
2021   // Check resource status
2022   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2023   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2024
2025   // The broken image should be shown.
2026   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2027   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2028
2029   END_TEST;
2030 }
2031
2032 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
2033 {
2034   ToolkitTestApplication application;
2035   tet_infoline("Request loading with invalid file - should draw broken image");
2036
2037   TestGlAbstraction& gl           = application.GetGlAbstraction();
2038   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2039   textureTrace.Enable(true);
2040
2041   Property::Map propertyMap;
2042   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2043     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
2044
2045   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2046   DALI_TEST_CHECK(visual);
2047
2048   DummyControl      actor     = DummyControl::New(true);
2049   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2050   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2051
2052   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
2053
2054   application.SendNotification();
2055   application.Render();
2056
2057   // Add to the Scene after loading
2058   application.GetScene().Add(actor);
2059
2060   application.SendNotification();
2061   application.Render();
2062
2063   // Check resource status
2064   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2065   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2066
2067   // The broken image should be shown.
2068   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2069   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2070
2071   END_TEST;
2072 }
2073
2074 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
2075 {
2076   ToolkitTestApplication application;
2077   tet_infoline("Request loading with invalid file without size set - should draw broken image");
2078
2079   TestGlAbstraction& gl           = application.GetGlAbstraction();
2080   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2081   textureTrace.Enable(true);
2082
2083   Property::Map propertyMap;
2084   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2085     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
2086     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2087
2088   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2089   DALI_TEST_CHECK(visual);
2090
2091   DummyControl      actor     = DummyControl::New(true);
2092   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2093   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2094
2095   application.GetScene().Add(actor);
2096
2097   application.SendNotification();
2098   application.Render();
2099
2100   // Trigger count is 1 - load
2101   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2102
2103   application.SendNotification();
2104   application.Render();
2105
2106   // Check resource status
2107   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
2108   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2109
2110   // The broken image should be shown.
2111   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2112   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2113
2114   END_TEST;
2115 }
2116
2117 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
2118 {
2119   ToolkitTestApplication application;
2120   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
2121
2122   Property::Map propertyMap;
2123   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2124     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
2125     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2126
2127   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
2128   DALI_TEST_CHECK(visual);
2129
2130   DummyControl      actor     = DummyControl::New(true);
2131   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2132   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2133
2134   Vector2 controlSize(20.f, 30.f);
2135   actor.SetProperty(Actor::Property::SIZE, controlSize);
2136
2137   application.GetScene().Add(actor);
2138
2139   application.SendNotification();
2140   application.Render();
2141
2142   // Trigger count is 2 - load, render the first frame
2143   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2144
2145   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2146   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
2147   int              totalFrameNumber = value->Get<int>();
2148
2149   Property::Map attributes;
2150   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2151
2152   // Make delay to drop frames
2153   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
2154
2155   application.SendNotification();
2156   application.Render();
2157
2158   // Trigger count is 1 - calculating frame drops
2159   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2160
2161   // Check dropped frame
2162   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
2163   DALI_TEST_CHECK(frames > 0);
2164   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
2165
2166   END_TEST;
2167 }
2168
2169 int UtcDaliAnimatedVectorImageVisualSize(void)
2170 {
2171   ToolkitTestApplication application;
2172   tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
2173
2174   TestGlAbstraction& gl           = application.GetGlAbstraction();
2175   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2176
2177   VisualFactory factory = VisualFactory::Get();
2178   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
2179   DALI_TEST_CHECK(visual);
2180
2181   DummyControl      actor     = DummyControl::New(true);
2182   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2183   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2184
2185   application.GetScene().Add(actor);
2186
2187   application.SendNotification();
2188   application.Render();
2189
2190   // Trigger count is 1 - resource ready
2191   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2192
2193   textureTrace.Enable(true);
2194
2195   application.SendNotification();
2196   application.Render();
2197
2198   {
2199     int               width = 100, height = 100; // 100x100 is the content default size.
2200     std::stringstream out;
2201     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2202     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2203   }
2204
2205   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
2206
2207   application.SendNotification();
2208   application.Render();
2209
2210   // Trigger count is 1 - resource ready
2211   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2212
2213   textureTrace.Reset();
2214
2215   application.SendNotification();
2216   application.Render();
2217
2218   {
2219     int               width = 200, height = 200;
2220     std::stringstream out;
2221     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
2222     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2223   }
2224
2225   END_TEST;
2226 }
2227
2228 namespace
2229 {
2230 bool gDynamicPropertyCallbackFired = false;
2231
2232 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
2233 {
2234   gDynamicPropertyCallbackFired = true;
2235
2236   if(frameNumber < 3)
2237   {
2238     return Vector3(0, 0, 1);
2239   }
2240   else
2241   {
2242     return Vector3(1, 0, 0);
2243   }
2244 }
2245 } // namespace
2246
2247 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
2248 {
2249   ToolkitTestApplication application;
2250   tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
2251
2252   VisualFactory factory = VisualFactory::Get();
2253   Visual::Base  visual  = factory.CreateVisual(
2254     Property::Map()
2255       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2256       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2257       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
2258   DALI_TEST_CHECK(visual);
2259
2260   DummyControl      actor     = DummyControl::New(true);
2261   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2262   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2263
2264   Vector2 controlSize(20.f, 30.f);
2265   actor.SetProperty(Actor::Property::SIZE, controlSize);
2266
2267   application.GetScene().Add(actor);
2268
2269   gDynamicPropertyCallbackFired = false;
2270
2271   // Set dynamic property
2272   DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
2273   info.id       = 1;
2274   info.keyPath  = "Test.Path";
2275   info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
2276   info.callback = MakeCallback(FillColorCallback);
2277
2278   DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
2279
2280   Property::Map attributes;
2281   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
2282
2283   application.SendNotification();
2284   application.Render();
2285
2286   // Trigger count is 2 - load & render a frame
2287   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2288
2289   // Test whether the property callback is called
2290   DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2291
2292   END_TEST;
2293 }
2294
2295 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2296 {
2297   ToolkitTestApplication application;
2298   tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2299
2300   TestGlAbstraction& gl           = application.GetGlAbstraction();
2301   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2302   int                desiredWidth = 150, desiredHeight = 200;
2303
2304   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2305   DALI_TEST_CHECK(visual);
2306
2307   DummyControl      actor     = DummyControl::New(true);
2308   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2309   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2310
2311   application.GetScene().Add(actor);
2312
2313   application.SendNotification();
2314   application.Render();
2315
2316   // Trigger count is 1 - resource ready
2317   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2318
2319   textureTrace.Enable(true);
2320
2321   application.SendNotification();
2322   application.Render();
2323
2324   {
2325     std::stringstream out;
2326     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2327     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2328   }
2329
2330   // Unparent to make next trigger
2331   actor.Unparent();
2332
2333   application.SendNotification();
2334   application.Render();
2335
2336   // Set visual size
2337   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2338   application.GetScene().Add(actor);
2339
2340   application.SendNotification();
2341   application.Render();
2342
2343   // Trigger count is 1 - resource ready
2344   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2345
2346   textureTrace.Reset();
2347
2348   application.SendNotification();
2349   application.Render();
2350
2351   {
2352     std::stringstream out;
2353     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2354     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
2355   }
2356
2357   END_TEST;
2358 }
2359
2360 int UtcDaliAnimatedVectorImageVisualFlushAction(void)
2361 {
2362   ToolkitTestApplication application;
2363
2364   tet_infoline("UtcDaliAnimatedVectorImageVisualFlushAction");
2365
2366   int startFrame = 1;
2367   int endFrame   = 2;
2368
2369   int totalFrameCount = 0;
2370
2371   Property::Array playRange;
2372   playRange.PushBack(startFrame);
2373   playRange.PushBack(endFrame);
2374
2375   Property::Map    resultMap;
2376   Property::Value* value = nullptr;
2377
2378   // request AnimatedVectorImageVisual with a property map
2379   VisualFactory factory = VisualFactory::Get();
2380   Visual::Base  visual  = factory.CreateVisual(
2381     Property::Map()
2382       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
2383       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
2384       .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
2385       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true));
2386
2387   DummyControl        dummyControl = DummyControl::New(true);
2388   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
2389   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2390   dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
2391
2392   application.GetScene().Add(dummyControl);
2393
2394   // Retry function to get playrange until expect values comes.
2395   auto CheckAndRetryPlayRange = [&](int expectStartFrame, int expectEndFrame, std::vector<std::pair<int, int>> retrialFrames) {
2396     int tryCount    = 0;
2397     int tryCountMax = 30;
2398     while(++tryCount <= tryCountMax)
2399     {
2400       Property::Map resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2401
2402       Property::Value* value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
2403       DALI_TEST_CHECK(value);
2404
2405       Property::Array* result = value->GetArray();
2406       DALI_TEST_CHECK(result);
2407       DALI_TEST_EQUALS(result->Count(), 2, TEST_LOCATION);
2408
2409       bool tryAgain = false;
2410       for(auto& framePair : retrialFrames)
2411       {
2412         if(result->GetElementAt(0).Get<int>() == framePair.first && result->GetElementAt(1).Get<int>() == framePair.second)
2413         {
2414           tryAgain = true;
2415           break;
2416         }
2417       }
2418       if(tryAgain)
2419       {
2420         tet_printf("Retry to get value again! [%d]\n", tryCount);
2421         // Dummy sleep 1 second.
2422         Test::WaitForEventThreadTrigger(1, 1);
2423         continue;
2424       }
2425
2426       DALI_TEST_EQUALS(result->GetElementAt(0).Get<int>(), expectStartFrame, TEST_LOCATION);
2427       DALI_TEST_EQUALS(result->GetElementAt(1).Get<int>(), expectEndFrame, TEST_LOCATION);
2428       break;
2429     }
2430     DALI_TEST_CHECK(tryCount <= tryCountMax);
2431   };
2432
2433   tet_printf("Pause lottie first.\n");
2434
2435   Property::Map attributes;
2436   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
2437
2438   application.SendNotification();
2439   application.Render(16);
2440
2441   do
2442   {
2443     resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2444
2445     value = resultMap.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER, Property::INTEGER);
2446     DALI_TEST_CHECK(value);
2447     totalFrameCount = value->Get<int>();
2448   } while(totalFrameCount == 0);
2449
2450   // Ensure that vector data sended well.
2451   CheckAndRetryPlayRange(startFrame, endFrame, {{0, 0}, {0, totalFrameCount - 1}});
2452
2453   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2454
2455   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2456   DALI_TEST_CHECK(value);
2457   DALI_TEST_EQUALS(value->Get<int>(), startFrame, TEST_LOCATION);
2458
2459   tet_printf("Now logically, range : [%d~%d], current : %d\n", startFrame, endFrame, startFrame);
2460
2461   int changedStartFrame1 = startFrame + 2;
2462   int changedEndFrame1   = endFrame + 2;
2463
2464   playRange.Clear();
2465   playRange.Add(changedStartFrame1);
2466   playRange.Add(changedEndFrame1);
2467
2468   tet_printf("Change play range\n");
2469   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2470   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2471
2472   tet_printf("Jump to changedEndFrame!\n");
2473   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, changedEndFrame1);
2474
2475   attributes.Clear();
2476   tet_infoline("Flush Action!");
2477   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame1, changedEndFrame1, changedEndFrame1);
2478   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::FLUSH, attributes);
2479
2480   int changedStartFrame2 = startFrame + 1;
2481   int changedEndFrame2   = endFrame + 1;
2482
2483   playRange.Clear();
2484   playRange.Add(changedStartFrame2);
2485   playRange.Add(changedEndFrame2);
2486
2487   tet_printf("Change play range again\n");
2488   tet_printf("Now logically, range : [%d~%d], current : %d\n", changedStartFrame2, changedEndFrame2, changedEndFrame2);
2489   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
2490   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
2491
2492   application.SendNotification();
2493   application.Render(16);
2494
2495   // Ensure that vector data sended well.
2496   CheckAndRetryPlayRange(changedStartFrame2, changedEndFrame2, {{changedStartFrame1, changedEndFrame1}, {startFrame, endFrame}});
2497
2498   resultMap = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
2499
2500   tet_printf("Test whether current frame number changed well. If Flush not works, current frame become startFrame.");
2501   value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER, Property::INTEGER);
2502   DALI_TEST_CHECK(value);
2503   DALI_TEST_EQUALS(value->Get<int>(), changedEndFrame2, TEST_LOCATION);
2504
2505   dummyControl.Unparent();
2506
2507   END_TEST;
2508 }
2509
2510 int UtcDaliAnimatedVectorImageNativeTextureChangeShader(void)
2511 {
2512   ToolkitTestApplication application;
2513   tet_infoline("UtcDaliAnimatedVectorImageNativeTextureChangeShader");
2514
2515   VisualFactory factory = VisualFactory::Get();
2516   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
2517   DALI_TEST_CHECK(visual);
2518
2519   DummyControl      actor     = DummyControl::New(true);
2520   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2521   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2522
2523   // Make we use native texture now.
2524   Test::VectorAnimationRenderer::UseNativeImageTexture(true);
2525
2526   application.GetScene().Add(actor);
2527
2528   application.SendNotification();
2529   application.Render();
2530
2531   // Trigger count is 1 - resource ready
2532   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2533
2534   application.SendNotification();
2535   application.Render();
2536
2537   Renderer        renderer = actor.GetRendererAt(0);
2538   Shader          shader   = renderer.GetShader();
2539   Property::Value value    = shader.GetProperty(Shader::Property::PROGRAM);
2540   Property::Map*  map      = value.GetMap();
2541   DALI_TEST_CHECK(map);
2542
2543   std::string      resultFragmentShader, resultVertexShader;
2544   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2545   fragment->Get(resultFragmentShader);
2546   DALI_TEST_CHECK(resultFragmentShader.find(NativeImageSourceTest::GetCustomFragmentPrefix()) != std::string::npos);
2547
2548   // Reset to make we use normal texture again.
2549   Test::VectorAnimationRenderer::UseNativeImageTexture(false);
2550
2551   END_TEST;
2552 }