[dali_2.3.21] Merge branch 'devel/master'
[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   Property::Array array;
842   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
843
844   Property::Map propertyMap;
845   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
846     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
847     .Add(DevelImageVisual::Property::PLAY_RANGE, array)
848     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
849
850   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
851   DALI_TEST_CHECK(visual);
852
853   DummyControl      actor     = DummyControl::New(true);
854   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
855   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
856
857   Vector2 controlSize(20.f, 30.f);
858   actor.SetProperty(Actor::Property::SIZE, controlSize);
859
860   application.GetScene().Add(actor);
861
862   Property::Map attributes;
863   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
864
865   application.SendNotification();
866   application.Render();
867
868   // Trigger count is 2 - load & render a frame
869   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
870
871   // renderer is added to actor
872   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
873   Renderer renderer = actor.GetRendererAt(0u);
874   DALI_TEST_CHECK(renderer);
875
876   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
877   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
878
879   int              resultStartFrame, resultEndFrame;
880   Property::Array* result = value->GetArray();
881   result->GetElementAt(0).Get(resultStartFrame);
882   result->GetElementAt(1).Get(resultEndFrame);
883
884   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
885   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
886
887   // Set 2 markers
888   array.Clear();
889   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
890   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
891
892   attributes.Clear();
893   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
894   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
895
896   // To make event trigger
897   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
898
899   application.SendNotification();
900   application.Render();
901
902   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
903
904   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
905   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
906
907   result = value->GetArray();
908   result->GetElementAt(0).Get(resultStartFrame);
909   result->GetElementAt(1).Get(resultEndFrame);
910
911   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
912   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
913
914   // Set invalid play range
915   array.Clear();
916   array.PushBack(1);
917   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
918
919   attributes.Clear();
920   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
921   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
922
923   // To make event trigger
924   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
925
926   application.SendNotification();
927   application.Render();
928
929   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
930
931   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
932   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
933
934   result = value->GetArray();
935   result->GetElementAt(0).Get(resultStartFrame);
936   result->GetElementAt(1).Get(resultEndFrame);
937
938   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
939   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
940
941   END_TEST;
942 }
943
944 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
945 {
946   ToolkitTestApplication application;
947   tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
948
949   Property::Map propertyMap;
950   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
951     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
952     .Add(DevelImageVisual::Property::LOOP_COUNT, 3);
953
954   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
955   DALI_TEST_CHECK(visual);
956
957   DummyControl      actor     = DummyControl::New(true);
958   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
959   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
960
961   DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
962
963   Vector2 controlSize(20.f, 30.f);
964   actor.SetProperty(Actor::Property::SIZE, controlSize);
965
966   application.GetScene().Add(actor);
967
968   Property::Map attributes;
969   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
970
971   application.SendNotification();
972   application.Render();
973
974   // Wait for animation finish - render, finish
975   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
976
977   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
978   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
979   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
980
981   DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
982
983   END_TEST;
984 }
985
986 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
987 {
988   ToolkitTestApplication application;
989   tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
990
991   Property::Map propertyMap;
992   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
993     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
994     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
995     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
996
997   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
998   DALI_TEST_CHECK(visual);
999
1000   tet_printf("1. Visual is created.\n");
1001
1002   DummyControl      actor     = DummyControl::New(true);
1003   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1004   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1005
1006   Vector2 controlSize(20.f, 30.f);
1007   actor.SetProperty(Actor::Property::SIZE, controlSize);
1008
1009   application.GetScene().Add(actor);
1010
1011   application.SendNotification();
1012   application.Render();
1013
1014   // Trigger count is 2 - load & render a frame
1015   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1016
1017   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
1018
1019   // To make event trigger
1020   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1021
1022   application.SendNotification();
1023   application.Render();
1024
1025   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1026
1027   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1028   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1029   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1030
1031   tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
1032
1033   Property::Array array;
1034   array.PushBack(0);
1035   array.PushBack(2);
1036
1037   Property::Map attributes;
1038   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
1039   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1040
1041   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1042
1043   // To make event trigger
1044   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1045
1046   application.SendNotification();
1047   application.Render();
1048
1049   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1050
1051   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1052   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1053   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1054
1055   tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
1056
1057   // Change play range
1058   attributes.Clear();
1059   array.Clear();
1060
1061   array.PushBack(0);
1062   array.PushBack(4);
1063
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   attributes.Clear();
1068   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1069
1070   application.SendNotification();
1071   application.Render();
1072
1073   // Wait for animation finish
1074   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1075
1076   // Jump to 3
1077   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1078
1079   // To make event trigger
1080   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1081
1082   application.SendNotification();
1083   application.Render();
1084
1085   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1086
1087   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1088   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1089   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1090
1091   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1092
1093   // Jump to the same position
1094   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1095
1096   // To make event trigger
1097   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1098
1099   application.SendNotification();
1100   application.Render();
1101
1102   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1103
1104   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1105   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1106   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1107
1108   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1109
1110   END_TEST;
1111 }
1112
1113 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1114 {
1115   ToolkitTestApplication application;
1116   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1117
1118   int             startFrame = 1, endFrame = 3;
1119   Property::Array playRange;
1120   playRange.PushBack(startFrame);
1121   playRange.PushBack(endFrame);
1122
1123   Property::Map propertyMap;
1124   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1125     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1126     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1127     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
1128     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1129
1130   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1131   DALI_TEST_CHECK(visual);
1132
1133   DummyControl      actor     = DummyControl::New(true);
1134   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1135   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1136
1137   Vector2 controlSize(20.f, 30.f);
1138   actor.SetProperty(Actor::Property::SIZE, controlSize);
1139
1140   application.GetScene().Add(actor);
1141
1142   application.SendNotification();
1143   application.Render();
1144
1145   // Trigger count is 2 - load & render a frame
1146   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1147
1148   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1149   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1150   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1151
1152   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1153   DALI_TEST_CHECK(value);
1154
1155   Property::Array* result = value->GetArray();
1156   DALI_TEST_CHECK(result);
1157
1158   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1159   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1160
1161   playRange.Clear();
1162   playRange.PushBack(0);
1163   playRange.PushBack(2);
1164
1165   Property::Map attributes;
1166   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1167   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1168
1169   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1170
1171   // To make event trigger
1172   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1173
1174   application.SendNotification();
1175   application.Render();
1176
1177   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1178
1179   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1180   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1181   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1182
1183   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1184   result = value->GetArray();
1185   DALI_TEST_CHECK(result);
1186
1187   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1188   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1189
1190   attributes.Clear();
1191
1192   playRange.Clear();
1193   playRange.PushBack(startFrame);
1194   playRange.PushBack(endFrame);
1195
1196   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1197
1198   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1199
1200   // To make event trigger
1201   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1202
1203   application.SendNotification();
1204   application.Render();
1205
1206   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1207
1208   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1209   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1210
1211   result = value->GetArray();
1212   DALI_TEST_CHECK(result);
1213
1214   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1215   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1216
1217   // Play and update property
1218   attributes.Clear();
1219   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1220
1221   application.SendNotification();
1222   application.Render();
1223
1224   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1225
1226   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1227
1228   application.SendNotification();
1229   application.Render();
1230
1231   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1232   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1233   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1234
1235   END_TEST;
1236 }
1237
1238 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1239 {
1240   ToolkitTestApplication application;
1241   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1242
1243   Property::Map propertyMap;
1244   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1245     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1246     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1247     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
1248     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1249
1250   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1251   DALI_TEST_CHECK(visual);
1252
1253   DummyControl      actor     = DummyControl::New(true);
1254   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1255   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1256
1257   Vector2 controlSize(20.f, 30.f);
1258   actor.SetProperty(Actor::Property::SIZE, controlSize);
1259
1260   application.GetScene().Add(actor);
1261
1262   Property::Map attributes;
1263   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1264
1265   application.SendNotification();
1266   application.Render();
1267
1268   // Trigger count is 3 - load, render, animation finished
1269   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1270
1271   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1272   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1273   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1274
1275   // Change stop behavior
1276   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1277
1278   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1279
1280   attributes.Clear();
1281
1282   // Play again
1283   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1284
1285   application.SendNotification();
1286   application.Render();
1287
1288   // Trigger count is 1 - animation finished
1289   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1290
1291   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1292
1293   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1294   int              totalFrameNumber = value1->Get<int>();
1295
1296   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1297   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1298
1299   // Change stop behavior
1300   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1301   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1302
1303   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1304
1305   attributes.Clear();
1306
1307   // Play again
1308   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1309
1310   application.SendNotification();
1311   application.Render();
1312
1313   // Pause
1314   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1315
1316   // To make event trigger
1317   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1318
1319   application.SendNotification();
1320   application.Render();
1321
1322   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1323
1324   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1325   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1326   int currentFrameNumber = value->Get<int>();
1327
1328   // Stop
1329   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1330
1331   // To make event trigger
1332   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1333
1334   application.SendNotification();
1335   application.Render();
1336
1337   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1338
1339   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1340   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1341   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1342
1343   END_TEST;
1344 }
1345
1346 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1347 {
1348   ToolkitTestApplication application;
1349   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1350
1351   Property::Map propertyMap;
1352   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1353     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1354     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1355     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME)
1356     .Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE)
1357     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1358
1359   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1360   DALI_TEST_CHECK(visual);
1361
1362   DummyControl      actor     = DummyControl::New(true);
1363   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1364   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1365
1366   Vector2 controlSize(20.f, 30.f);
1367   actor.SetProperty(Actor::Property::SIZE, controlSize);
1368
1369   application.GetScene().Add(actor);
1370
1371   Property::Map attributes;
1372   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1373
1374   application.SendNotification();
1375   application.Render();
1376
1377   // Trigger count is 3 - load, render, animation finished
1378   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1379
1380   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1381   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1382   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1383
1384   // Change stop behavior
1385   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1386
1387   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1388
1389   // Play again
1390   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1391
1392   application.SendNotification();
1393   application.Render();
1394
1395   // Trigger count is 1 - animation finished
1396   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1397
1398   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1399   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1400   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1401
1402   // Change looping mode
1403   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1404
1405   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1406
1407   // Play again
1408   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1409
1410   application.SendNotification();
1411   application.Render();
1412
1413   // Trigger count is 1 - animation finished
1414   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1415
1416   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1417   int              totalFrameNumber = value1->Get<int>();
1418
1419   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1420   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1421   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1422
1423   END_TEST;
1424 }
1425
1426 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1427 {
1428   ToolkitTestApplication application;
1429   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1430
1431   Property::Map propertyMap;
1432   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1433     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1434
1435   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1436   DALI_TEST_CHECK(visual);
1437
1438   DummyControl      actor     = DummyControl::New(true);
1439   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1440   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1441   actor.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1442
1443   application.GetScene().Add(actor);
1444
1445   application.SendNotification();
1446   application.Render();
1447
1448   // Trigger count is 1 - render a frame
1449   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1450
1451   Renderer renderer = actor.GetRendererAt(0u);
1452   DALI_TEST_CHECK(renderer);
1453
1454   Vector2 controlSize(20.f, 30.f);
1455   actor.SetProperty(Actor::Property::SIZE, controlSize);
1456
1457   application.SendNotification();
1458   application.Render();
1459
1460   application.SendNotification();
1461   application.Render();
1462
1463   // Trigger count is 1 - render a frame
1464   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1465
1466   auto textureSet = renderer.GetTextures();
1467   auto texture    = textureSet.GetTexture(0);
1468
1469   DALI_TEST_EQUALS(controlSize.width, texture.GetWidth(), TEST_LOCATION);
1470   DALI_TEST_EQUALS(controlSize.height, texture.GetHeight(), TEST_LOCATION);
1471
1472   // Change scale
1473   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1474   actor.SetProperty(Actor::Property::SCALE, controlScale);
1475
1476   application.SendNotification();
1477   application.Render();
1478
1479   application.SendNotification();
1480   application.Render();
1481
1482   // Trigger count is 1 - render a frame
1483   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1484
1485   renderer = actor.GetRendererAt(0u);
1486   DALI_TEST_CHECK(renderer);
1487
1488   textureSet = renderer.GetTextures();
1489   texture    = textureSet.GetTexture(0);
1490
1491   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1492   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1493
1494   // Size animation
1495   controlSize         = Vector2(50.0f, 100.0f);
1496   Animation animation = Animation::New(1.0);
1497   animation.AnimateTo(Property(actor, Actor::Property::SIZE), Vector3(controlSize.x, controlSize.y, 0.0f));
1498   animation.Play();
1499
1500   application.SendNotification();
1501   application.Render(1100); // After the animation
1502
1503   application.SendNotification();
1504   application.Render();
1505
1506   // Trigger count is 1 - render a frame
1507   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1508
1509   renderer = actor.GetRendererAt(0u);
1510   DALI_TEST_CHECK(renderer);
1511
1512   textureSet = renderer.GetTextures();
1513   texture    = textureSet.GetTexture(0);
1514
1515   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1516   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1517
1518   END_TEST;
1519 }
1520
1521 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1522 {
1523   ToolkitTestApplication application;
1524   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1525
1526   Property::Map propertyMap;
1527   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1528     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1529     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1530
1531   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1532   DALI_TEST_CHECK(visual1);
1533
1534   DummyControl      actor1     = DummyControl::New(true);
1535   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1536   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1537
1538   Vector2 controlSize(20.f, 30.f);
1539   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1540
1541   application.GetScene().Add(actor1);
1542
1543   propertyMap.Clear();
1544   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1545     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1546     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1547
1548   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1549   DALI_TEST_CHECK(visual2);
1550
1551   DummyControl      actor2     = DummyControl::New(true);
1552   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1553   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1554
1555   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1556
1557   application.GetScene().Add(actor2);
1558
1559   application.SendNotification();
1560   application.Render();
1561
1562   // Trigger count is 4 - load & render a frame for each instance
1563   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1564
1565   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1566
1567   // To make event trigger
1568   actor2.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f));
1569
1570   application.SendNotification();
1571   application.Render();
1572
1573   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1574
1575   Property::Map attributes;
1576   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1577
1578   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1579   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1580
1581   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1582
1583   // renderer is added to actor
1584   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1585   Renderer renderer1 = actor1.GetRendererAt(0u);
1586   DALI_TEST_CHECK(renderer1);
1587
1588   // renderer is added to actor
1589   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1590   Renderer renderer2 = actor2.GetRendererAt(0u);
1591   DALI_TEST_CHECK(renderer2);
1592
1593   END_TEST;
1594 }
1595
1596 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1597 {
1598   ToolkitTestApplication application;
1599   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1600
1601   Property::Map propertyMap;
1602   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1603     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1604     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1605
1606   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1607   DALI_TEST_CHECK(visual);
1608
1609   DummyControl      actor     = DummyControl::New(true);
1610   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1611   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1612
1613   Vector2 controlSize(20.f, 30.f);
1614   actor.SetProperty(Actor::Property::SIZE, controlSize);
1615
1616   application.GetScene().Add(actor);
1617
1618   application.SendNotification();
1619   application.Render();
1620
1621   // Trigger count is 2 - load & render a frame
1622   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1623
1624   Property::Map attributes;
1625   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1626
1627   application.SendNotification();
1628   application.Render();
1629
1630   // Check rendering behavior
1631   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1632   Renderer renderer = actor.GetRendererAt(0u);
1633   DALI_TEST_CHECK(renderer);
1634   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1635
1636   actor.SetProperty(Actor::Property::VISIBLE, false);
1637
1638   application.SendNotification();
1639   application.Render();
1640
1641   // Check rendering behavior again
1642   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1643
1644   END_TEST;
1645 }
1646
1647 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1648 {
1649   ToolkitTestApplication application;
1650   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1651
1652   Property::Map propertyMap;
1653   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1654     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1655
1656   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1657   DALI_TEST_CHECK(visual);
1658
1659   DummyControl      actor     = DummyControl::New(true);
1660   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1661   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1662
1663   Vector2 controlSize(20.f, 30.f);
1664   actor.SetProperty(Actor::Property::SIZE, controlSize);
1665
1666   application.GetScene().Add(actor);
1667
1668   application.SendNotification();
1669   application.Render();
1670
1671   // Trigger count is 1 - render a frame
1672   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1673
1674   Property::Map attributes;
1675   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1676
1677   application.SendNotification();
1678   application.Render();
1679
1680   // Check rendering behavior
1681   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1682   Renderer renderer = actor.GetRendererAt(0u);
1683   DALI_TEST_CHECK(renderer);
1684   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1685
1686   Window window = DevelWindow::Get(actor);
1687   window.Hide();
1688
1689   application.SendNotification();
1690   application.Render();
1691
1692   // Check rendering behavior again
1693   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1694
1695   END_TEST;
1696 }
1697
1698 int UtcDaliAnimatedVectorImageVisualInvalidFile01(void)
1699 {
1700   ToolkitTestApplication application;
1701   tet_infoline("Request loading with invalid file - should draw broken image");
1702
1703   TestGlAbstraction& gl           = application.GetGlAbstraction();
1704   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1705   textureTrace.Enable(true);
1706
1707   Property::Map propertyMap;
1708   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1709     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1710     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1711
1712   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1713   DALI_TEST_CHECK(visual);
1714
1715   DummyControl      actor     = DummyControl::New(true);
1716   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1717   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1718
1719   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1720
1721   application.GetScene().Add(actor);
1722
1723   application.SendNotification();
1724   application.Render();
1725
1726   // Trigger count is 1 - load
1727   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1728
1729   application.SendNotification();
1730   application.Render();
1731
1732   // Check resource status
1733   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1734   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1735
1736   // The broken image should be shown.
1737   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1738   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1739
1740   END_TEST;
1741 }
1742
1743 int UtcDaliAnimatedVectorImageVisualInvalidFile02(void)
1744 {
1745   ToolkitTestApplication application;
1746   tet_infoline("Request loading with invalid file - should draw broken image");
1747
1748   TestGlAbstraction& gl           = application.GetGlAbstraction();
1749   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1750   textureTrace.Enable(true);
1751
1752   Property::Map propertyMap;
1753   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1754     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1755
1756   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1757   DALI_TEST_CHECK(visual);
1758
1759   DummyControl      actor     = DummyControl::New(true);
1760   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1761   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1762
1763   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1764
1765   application.SendNotification();
1766   application.Render();
1767
1768   // Add to the Scene after loading
1769   application.GetScene().Add(actor);
1770
1771   application.SendNotification();
1772   application.Render();
1773
1774   // Check resource status
1775   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1776   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1777
1778   // The broken image should be shown.
1779   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1780   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1781
1782   END_TEST;
1783 }
1784
1785 int UtcDaliAnimatedVectorImageVisualInvalidFile03(void)
1786 {
1787   ToolkitTestApplication application;
1788   tet_infoline("Request loading with invalid file without size set - should draw broken image");
1789
1790   TestGlAbstraction& gl           = application.GetGlAbstraction();
1791   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1792   textureTrace.Enable(true);
1793
1794   Property::Map propertyMap;
1795   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1796     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME)
1797     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1798
1799   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1800   DALI_TEST_CHECK(visual);
1801
1802   DummyControl      actor     = DummyControl::New(true);
1803   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1804   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1805
1806   application.GetScene().Add(actor);
1807
1808   application.SendNotification();
1809   application.Render();
1810
1811   // Trigger count is 1 - load
1812   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1813
1814   application.SendNotification();
1815   application.Render();
1816
1817   // Check resource status
1818   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1819   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1820
1821   // The broken image should be shown.
1822   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1823   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1824
1825   END_TEST;
1826 }
1827
1828 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1829 {
1830   ToolkitTestApplication application;
1831   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1832
1833   Property::Map propertyMap;
1834   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1835     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP)
1836     .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1837
1838   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1839   DALI_TEST_CHECK(visual);
1840
1841   DummyControl      actor     = DummyControl::New(true);
1842   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1843   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1844
1845   Vector2 controlSize(20.f, 30.f);
1846   actor.SetProperty(Actor::Property::SIZE, controlSize);
1847
1848   application.GetScene().Add(actor);
1849
1850   application.SendNotification();
1851   application.Render();
1852
1853   // Trigger count is 2 - load, render the first frame
1854   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1855
1856   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1857   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1858   int              totalFrameNumber = value->Get<int>();
1859
1860   Property::Map attributes;
1861   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1862
1863   // Make delay to drop frames
1864   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
1865
1866   application.SendNotification();
1867   application.Render();
1868
1869   // Trigger count is 1 - calculating frame drops
1870   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1871
1872   // Check dropped frame
1873   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
1874   DALI_TEST_CHECK(frames > 0);
1875   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
1876
1877   END_TEST;
1878 }
1879
1880 int UtcDaliAnimatedVectorImageVisualSize(void)
1881 {
1882   ToolkitTestApplication application;
1883   tet_infoline("UtcDaliAnimatedVectorImageVisualSize");
1884
1885   TestGlAbstraction& gl           = application.GetGlAbstraction();
1886   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1887
1888   VisualFactory factory = VisualFactory::Get();
1889   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
1890   DALI_TEST_CHECK(visual);
1891
1892   DummyControl      actor     = DummyControl::New(true);
1893   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1894   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1895
1896   application.GetScene().Add(actor);
1897
1898   application.SendNotification();
1899   application.Render();
1900
1901   // Trigger count is 1 - resource ready
1902   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1903
1904   textureTrace.Enable(true);
1905
1906   application.SendNotification();
1907   application.Render();
1908
1909   {
1910     int               width = 100, height = 100; // 100x100 is the content default size.
1911     std::stringstream out;
1912     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1913     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1914   }
1915
1916   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
1917
1918   application.SendNotification();
1919   application.Render();
1920
1921   // Trigger count is 1 - resource ready
1922   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1923
1924   textureTrace.Reset();
1925
1926   application.SendNotification();
1927   application.Render();
1928
1929   {
1930     int               width = 200, height = 200;
1931     std::stringstream out;
1932     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1933     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
1934   }
1935
1936   END_TEST;
1937 }
1938
1939 namespace
1940 {
1941 bool gDynamicPropertyCallbackFired = false;
1942
1943 Property::Value FillColorCallback(int32_t id, VectorAnimationRenderer::VectorProperty property, uint32_t frameNumber)
1944 {
1945   gDynamicPropertyCallbackFired = true;
1946
1947   if(frameNumber < 3)
1948   {
1949     return Vector3(0, 0, 1);
1950   }
1951   else
1952   {
1953     return Vector3(1, 0, 0);
1954   }
1955 }
1956 } // namespace
1957
1958 int UtcDaliAnimatedVectorImageVisualDynamicProperty(void)
1959 {
1960   ToolkitTestApplication application;
1961   tet_infoline("UtcDaliAnimatedVectorImageVisualDynamicProperty");
1962
1963   VisualFactory factory = VisualFactory::Get();
1964   Visual::Base  visual  = factory.CreateVisual(
1965     Property::Map()
1966       .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1967       .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1968       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false));
1969   DALI_TEST_CHECK(visual);
1970
1971   DummyControl      actor     = DummyControl::New(true);
1972   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1973   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1974
1975   Vector2 controlSize(20.f, 30.f);
1976   actor.SetProperty(Actor::Property::SIZE, controlSize);
1977
1978   application.GetScene().Add(actor);
1979
1980   gDynamicPropertyCallbackFired = false;
1981
1982   // Set dynamic property
1983   DevelAnimatedVectorImageVisual::DynamicPropertyInfo info;
1984   info.id       = 1;
1985   info.keyPath  = "Test.Path";
1986   info.property = static_cast<int>(VectorAnimationRenderer::VectorProperty::FILL_COLOR);
1987   info.callback = MakeCallback(FillColorCallback);
1988
1989   DevelControl::DoActionExtension(actor, DummyControl::Property::TEST_VISUAL, DevelAnimatedVectorImageVisual::Action::SET_DYNAMIC_PROPERTY, Any(info));
1990
1991   Property::Map attributes;
1992   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1993
1994   application.SendNotification();
1995   application.Render();
1996
1997   // Trigger count is 2 - load & render a frame
1998   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1999
2000   // Test whether the property callback is called
2001   DALI_TEST_EQUALS(gDynamicPropertyCallbackFired, true, TEST_LOCATION);
2002
2003   END_TEST;
2004 }
2005
2006 int UtcDaliAnimatedVectorImageVisualDesiredSize(void)
2007 {
2008   ToolkitTestApplication application;
2009   tet_infoline("UtcDaliAnimatedVectorImageVisualDesiredSize");
2010
2011   TestGlAbstraction& gl           = application.GetGlAbstraction();
2012   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2013   int                desiredWidth = 150, desiredHeight = 200;
2014
2015   Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
2016   DALI_TEST_CHECK(visual);
2017
2018   DummyControl      actor     = DummyControl::New(true);
2019   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2020   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2021
2022   application.GetScene().Add(actor);
2023
2024   application.SendNotification();
2025   application.Render();
2026
2027   // Trigger count is 1 - resource ready
2028   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2029
2030   textureTrace.Enable(true);
2031
2032   application.SendNotification();
2033   application.Render();
2034
2035   {
2036     std::stringstream out;
2037     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2038     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
2039   }
2040
2041   // Unparent to make next trigger
2042   actor.Unparent();
2043
2044   application.SendNotification();
2045   application.Render();
2046
2047   // Set visual size
2048   actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
2049   application.GetScene().Add(actor);
2050
2051   application.SendNotification();
2052   application.Render();
2053
2054   // Trigger count is 1 - resource ready
2055   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2056
2057   textureTrace.Reset();
2058
2059   application.SendNotification();
2060   application.Render();
2061
2062   {
2063     std::stringstream out;
2064     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
2065     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should not be changed
2066   }
2067
2068   END_TEST;
2069 }