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