[dali_2.1.30] 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 #include <dali/devel-api/adaptor-framework/window-devel.h>
38 #include <dali/devel-api/rendering/renderer-devel.h>
39
40 using namespace Dali;
41 using namespace Dali::Toolkit;
42
43 void dali_animated_vector_image_visual_startup(void)
44 {
45   test_return_value = TET_UNDEF;
46 }
47
48 void dali_animated_vector_image_visual_cleanup(void)
49 {
50   test_return_value = TET_PASS;
51 }
52
53 namespace
54 {
55 const char* TEST_VECTOR_IMAGE_FILE_NAME            = TEST_RESOURCE_DIR "/insta_camera.json";
56 const char* TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP = "framedrop.json";
57 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME    = "invalid.json";
58
59 bool gAnimationFinishedSignalFired = false;
60
61 void VisualEventSignal(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId)
62 {
63   if(visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED)
64   {
65     gAnimationFinishedSignalFired = true;
66   }
67 }
68
69 } // namespace
70
71 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
72 {
73   ToolkitTestApplication application;
74   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url");
75
76   VisualFactory factory = VisualFactory::Get();
77   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
78   DALI_TEST_CHECK(visual);
79
80   DummyControl      actor     = DummyControl::New(true);
81   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
82   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
83   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
84   application.GetScene().Add(actor);
85
86   application.SendNotification();
87   application.Render();
88
89   // renderer is added to actor
90   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
91   Renderer renderer = actor.GetRendererAt(0u);
92   DALI_TEST_CHECK(renderer);
93
94   // Test SetOffScene().
95   actor.Unparent();
96   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
97
98   END_TEST;
99 }
100
101 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
102 {
103   ToolkitTestApplication application;
104   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map");
105
106   Property::Map propertyMap;
107   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
108     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
109
110   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
111   DALI_TEST_CHECK(visual);
112
113   DummyControl      actor     = DummyControl::New(true);
114   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
115   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
116   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
117   application.GetScene().Add(actor);
118
119   application.SendNotification();
120   application.Render();
121
122   // renderer is added to actor
123   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
124   Renderer renderer = actor.GetRendererAt(0u);
125   DALI_TEST_CHECK(renderer);
126
127   actor.Unparent();
128   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
129
130   END_TEST;
131 }
132
133 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
134 {
135   ToolkitTestApplication application;
136   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map");
137
138   int             startFrame = 1, endFrame = 3;
139   Property::Array playRange;
140   playRange.PushBack(startFrame);
141   playRange.PushBack(endFrame);
142
143   Property::Map propertyMap;
144   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
145     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
146     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
147     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
148     .Add(DevelVisual::Property::CORNER_RADIUS, 50.0f)
149     .Add(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f);
150
151   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
152   DALI_TEST_CHECK(visual);
153
154   DummyControl      actor     = DummyControl::New(true);
155   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
156   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
157   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
158   application.GetScene().Add(actor);
159
160   application.SendNotification();
161   application.Render();
162
163   // renderer is added to actor
164   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
165   Renderer renderer = actor.GetRendererAt(0u);
166   DALI_TEST_CHECK(renderer);
167
168   actor.Unparent();
169   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
170
171   END_TEST;
172 }
173
174 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
175 {
176   ToolkitTestApplication application;
177   tet_infoline("UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map");
178
179   int             startFrame = 1, endFrame = 3;
180   float           cornerRadius     = 22.0f;
181   float           borderlineWidth  = 2.0f;
182   Vector4         borderlineColor  = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
183   float           borderlineOffset = 0.1f;
184   Property::Array playRange;
185   playRange.PushBack(startFrame);
186   playRange.PushBack(endFrame);
187
188   Property::Map propertyMap;
189   propertyMap.Add("visualType", DevelVisual::ANIMATED_VECTOR_IMAGE)
190     .Add("url", TEST_VECTOR_IMAGE_FILE_NAME)
191     .Add("loopCount", 3)
192     .Add("playRange", playRange)
193     .Add("stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME)
194     .Add("loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE)
195     .Add("redrawInScalingDown", false)
196     .Add("cornerRadius", cornerRadius)
197     .Add("borderlineWidth", borderlineWidth)
198     .Add("borderlineColor", borderlineColor)
199     .Add("borderlineOffset", borderlineOffset);
200
201   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
202   DALI_TEST_CHECK(visual);
203
204   DummyControl      actor     = DummyControl::New(true);
205   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
206   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
207   actor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
208   application.GetScene().Add(actor);
209
210   application.SendNotification();
211   application.Render();
212
213   // Trigger count is 1 - render a frame
214   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
215
216   // renderer is added to actor
217   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
218
219   Renderer renderer = actor.GetRendererAt(0u);
220   DALI_TEST_CHECK(renderer);
221
222   Property::Map resultMap;
223   visual.CreatePropertyMap(resultMap);
224
225   // check the property values from the returned map from a visual
226   Property::Value* value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
227   DALI_TEST_CHECK(value);
228   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
229
230   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
231   DALI_TEST_CHECK(value);
232   DALI_TEST_CHECK(value->Get<int>() == 3);
233
234   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
235   DALI_TEST_CHECK(value);
236
237   Property::Array* result = value->GetArray();
238   DALI_TEST_CHECK(result);
239
240   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
241   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
242
243   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
244   DALI_TEST_CHECK(value);
245   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::FIRST_FRAME);
246
247   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
248   DALI_TEST_CHECK(value);
249   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::AUTO_REVERSE);
250
251   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
252   DALI_TEST_CHECK(value);
253   DALI_TEST_CHECK(value->Get<bool>() == false);
254
255   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
256   DALI_TEST_CHECK(value);
257   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION);
258
259   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
260   DALI_TEST_CHECK(value);
261   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
262
263   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
264   DALI_TEST_CHECK(value);
265   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
266
267   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
268   DALI_TEST_CHECK(value);
269   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
270
271   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
272   DALI_TEST_CHECK(value);
273   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
274
275   actor.Unparent();
276   DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
277
278   END_TEST;
279 }
280
281 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
282 {
283   ToolkitTestApplication application;
284   tet_infoline("UtcDaliAnimatedVectorImageVisualGetPropertyMap01");
285
286   int             startFrame = 1, endFrame = 3;
287   Vector4         cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
288   float           borderlineWidth  = 2.3f;
289   Vector4         borderlineColor  = Vector4(0.3f, 0.3f, 1.0f, 1.0f);
290   float           borderlineOffset = 0.3f;
291   Property::Array playRange;
292   playRange.PushBack(startFrame);
293   playRange.PushBack(endFrame);
294
295   Property::Map propertyMap;
296   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
297     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
298     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
299     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange)
300     .Add(DevelVisual::Property::CORNER_RADIUS, cornerRadius)
301     .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE)
302     .Add(DevelVisual::Property::BORDERLINE_WIDTH, borderlineWidth)
303     .Add(DevelVisual::Property::BORDERLINE_COLOR, borderlineColor)
304     .Add(DevelVisual::Property::BORDERLINE_OFFSET, borderlineOffset);
305
306   // request AnimatedVectorImageVisual with a property map
307   VisualFactory factory = VisualFactory::Get();
308   Visual::Base  visual  = factory.CreateVisual(propertyMap);
309
310   DummyControl      actor     = DummyControl::New(true);
311   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
312   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
313
314   Vector2 controlSize(20.f, 30.f);
315   actor.SetProperty(Actor::Property::SIZE, controlSize);
316
317   application.GetScene().Add(actor);
318
319   application.SendNotification();
320   application.Render();
321
322   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
323
324   Property::Map resultMap;
325   resultMap = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
326
327   // check the property values from the returned map from a visual
328   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
329   DALI_TEST_CHECK(value);
330   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
331
332   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
333   DALI_TEST_CHECK(value);
334   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
335
336   value = resultMap.Find(DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER);
337   DALI_TEST_CHECK(value);
338   DALI_TEST_CHECK(value->Get<int>() == 3);
339
340   value = resultMap.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
341   DALI_TEST_CHECK(value);
342
343   Property::Array* result = value->GetArray();
344   DALI_TEST_CHECK(result);
345
346   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
347   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
348
349   value = resultMap.Find(DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER);
350   DALI_TEST_CHECK(value);
351   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::StopBehavior::CURRENT_FRAME);
352
353   value = resultMap.Find(DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER);
354   DALI_TEST_CHECK(value);
355   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::LoopingMode::RESTART);
356
357   value = resultMap.Find(DevelImageVisual::Property::CONTENT_INFO, Property::MAP);
358   DALI_TEST_CHECK(value);
359
360   value = resultMap.Find(DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN);
361   DALI_TEST_CHECK(value);
362   DALI_TEST_CHECK(value->Get<bool>() == true); // Check default value
363
364   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
365   DALI_TEST_CHECK(value);
366   DALI_TEST_EQUALS(value->Get<Vector4>(), cornerRadius, TEST_LOCATION);
367
368   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
369   DALI_TEST_CHECK(value);
370   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
371
372   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
373   DALI_TEST_CHECK(value);
374   DALI_TEST_EQUALS(value->Get<float>(), borderlineWidth, TEST_LOCATION);
375
376   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
377   DALI_TEST_CHECK(value);
378   DALI_TEST_EQUALS(value->Get<Vector4>(), borderlineColor, TEST_LOCATION);
379
380   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
381   DALI_TEST_CHECK(value);
382   DALI_TEST_EQUALS(value->Get<float>(), borderlineOffset, TEST_LOCATION);
383
384   // request AnimatedVectorImageVisual with an URL
385   Visual::Base visual2 = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
386
387   resultMap.Clear();
388   visual2.CreatePropertyMap(resultMap);
389
390   // check the property values from the returned map from a visual
391   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
392   DALI_TEST_CHECK(value);
393   DALI_TEST_CHECK(value->Get<int>() == DevelVisual::ANIMATED_VECTOR_IMAGE);
394
395   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
396   DALI_TEST_CHECK(value);
397   DALI_TEST_CHECK(value->Get<std::string>() == TEST_VECTOR_IMAGE_FILE_NAME);
398
399   END_TEST;
400 }
401
402 int UtcDaliAnimatedVectorImageVisualPlayback(void)
403 {
404   ToolkitTestApplication application;
405
406   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayback");
407
408   {
409     // request AnimatedVectorImageVisual with a property map
410     VisualFactory factory = VisualFactory::Get();
411     Visual::Base  visual  = factory.CreateVisual(
412       Property::Map()
413         .Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
414         .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME));
415
416     DummyControl        dummyControl = DummyControl::New(true);
417     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
418     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
419     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
420
421     Property::Map attributes;
422     tet_infoline("Test Play action");
423     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
424
425     application.GetScene().Add(dummyControl);
426     application.SendNotification();
427     application.Render(16);
428
429     Property::Map    map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
430     Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
431     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
432
433     tet_infoline("Test Pause action");
434     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
435
436     application.SendNotification();
437     application.Render(16);
438
439     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
440     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
441     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PAUSED);
442
443     tet_infoline("Test Play action");
444     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
445
446     application.SendNotification();
447     application.Render(16);
448
449     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
450     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
451     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
452
453     tet_infoline("Test Stop action");
454     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
455
456     application.SendNotification();
457     application.Render(16);
458
459     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
460     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
461     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
462
463     tet_infoline("Test Stop action again");
464     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
465
466     application.SendNotification();
467     application.Render(16);
468
469     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
470     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
471     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
472
473     tet_infoline("Test Play action");
474     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
475
476     application.SendNotification();
477     application.Render(16);
478
479     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
480     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
481     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
482
483     tet_infoline("Off stage");
484     dummyControl.Unparent();
485
486     application.SendNotification();
487     application.Render(16);
488
489     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
490     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
491     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
492
493     tet_infoline("On stage again");
494     application.GetScene().Add(dummyControl);
495
496     application.SendNotification();
497     application.Render(16);
498
499     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
500     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
501     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
502
503     tet_infoline("Test Play action");
504     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
505
506     application.SendNotification();
507     application.Render(16);
508
509     map   = dummyControl.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
510     value = map.Find(DevelImageVisual::Property::PLAY_STATE);
511     DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::PLAYING);
512
513     // Change Size
514     Vector3 newSize(100.0f, 100.0f, 0.0f);
515     dummyControl.SetProperty(Actor::Property::SIZE, newSize);
516
517     application.SendNotification();
518     application.Render(16);
519
520     // Size should be changed
521     Vector3 naturalSize = dummyControl.GetNaturalSize();
522     DALI_TEST_CHECK(naturalSize == newSize);
523
524     dummyControl.Unparent();
525   }
526
527   END_TEST;
528 }
529
530 int UtcDaliAnimatedVectorImageVisualCustomShader(void)
531 {
532   ToolkitTestApplication application;
533   tet_infoline("UtcDaliAnimatedVectorImageVisualCustomShader Test custom shader");
534
535   VisualFactory     factory = VisualFactory::Get();
536   Property::Map     properties;
537   Property::Map     shader;
538   const std::string vertexShader                    = "Foobar";
539   const std::string fragmentShader                  = "Foobar sampler2D Foobar";
540   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
541   shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
542
543   properties[Visual::Property::TYPE]     = Visual::IMAGE;
544   properties[Visual::Property::SHADER]   = shader;
545   properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
546
547   Visual::Base visual = factory.CreateVisual(properties);
548
549   // trigger creation through setting on stage
550   DummyControl        dummy     = DummyControl::New(true);
551   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
552   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
553
554   dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
555   dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
556   application.GetScene().Add(dummy);
557
558   application.SendNotification();
559   application.Render();
560
561   Renderer        renderer = dummy.GetRendererAt(0);
562   Shader          shader2  = renderer.GetShader();
563   Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
564   Property::Map*  map      = value.GetMap();
565   DALI_TEST_CHECK(map);
566
567   std::string      resultFragmentShader, resultVertexShader;
568   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
569   fragment->Get(resultFragmentShader);
570   DALI_TEST_CHECK(resultFragmentShader.find(fragmentShader) != std::string::npos);
571
572   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
573   vertex->Get(resultVertexShader);
574   DALI_TEST_CHECK(resultVertexShader.find(vertexShader) != std::string::npos);
575
576   END_TEST;
577 }
578
579 int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
580 {
581   ToolkitTestApplication application;
582   tet_infoline("UtcDaliAnimatedVectorImageVisualNaturalSize");
583
584   VisualFactory factory = VisualFactory::Get();
585   Visual::Base  visual  = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions());
586   DALI_TEST_CHECK(visual);
587
588   DummyControl      actor     = DummyControl::New(true);
589   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
590   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
591
592   Vector2 controlSize(20.f, 30.f);
593   Vector2 naturalSize;
594
595   application.GetScene().Add(actor);
596
597   application.SendNotification();
598   application.Render();
599
600   visual.GetNaturalSize(naturalSize);
601
602   DALI_TEST_EQUALS(naturalSize, Vector2(100.0f, 100.0f), TEST_LOCATION); // 100x100 is the content default size.
603
604   actor.SetProperty(Actor::Property::SIZE, controlSize);
605
606   application.SendNotification();
607   application.Render();
608
609   visual.GetNaturalSize(naturalSize);
610
611   DALI_TEST_EQUALS(naturalSize, controlSize, TEST_LOCATION);
612
613   END_TEST;
614 }
615
616 int UtcDaliAnimatedVectorImageVisualLoopCount(void)
617 {
618   ToolkitTestApplication application;
619   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopCount");
620
621   Property::Map propertyMap;
622   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
623     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
624     .Add(DevelImageVisual::Property::LOOP_COUNT, 3);
625
626   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
627   DALI_TEST_CHECK(visual);
628
629   DummyControl      actor     = DummyControl::New(true);
630   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
631   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
632
633   Vector2 controlSize(20.f, 30.f);
634   actor.SetProperty(Actor::Property::SIZE, controlSize);
635
636   application.GetScene().Add(actor);
637
638   Property::Map attributes;
639   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
640
641   application.SendNotification();
642   application.Render();
643
644   // Trigger count is 1 - render a frame
645   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
646
647   // renderer is added to actor
648   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
649   Renderer renderer = actor.GetRendererAt(0u);
650   DALI_TEST_CHECK(renderer);
651
652   END_TEST;
653 }
654
655 int UtcDaliAnimatedVectorImageVisualPlayRange(void)
656 {
657   ToolkitTestApplication application;
658   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRange");
659
660   int             startFrame = 1, endFrame = 3;
661   Property::Array array;
662   array.PushBack(endFrame);
663   array.PushBack(startFrame);
664
665   Property::Map propertyMap;
666   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
667     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
668     .Add(DevelImageVisual::Property::PLAY_RANGE, array);
669
670   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
671   DALI_TEST_CHECK(visual);
672
673   DummyControl      actor     = DummyControl::New(true);
674   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
675   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
676
677   Vector2 controlSize(20.f, 30.f);
678   actor.SetProperty(Actor::Property::SIZE, controlSize);
679
680   application.GetScene().Add(actor);
681
682   Property::Map attributes;
683   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
684
685   application.SendNotification();
686   application.Render();
687
688   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
689
690   // renderer is added to actor
691   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
692   Renderer renderer = actor.GetRendererAt(0u);
693   DALI_TEST_CHECK(renderer);
694
695   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
696   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
697
698   int              resultStartFrame, resultEndFrame;
699   Property::Array* result = value->GetArray();
700   result->GetElementAt(0).Get(resultStartFrame);
701   result->GetElementAt(1).Get(resultEndFrame);
702
703   DALI_TEST_EQUALS(startFrame, resultStartFrame, TEST_LOCATION);
704   DALI_TEST_EQUALS(endFrame, resultEndFrame, TEST_LOCATION);
705
706   // Set invalid play range
707   array.Clear();
708   array.PushBack(1);
709   array.PushBack(100);
710
711   attributes.Clear();
712   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
713   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
714
715   application.SendNotification();
716   application.Render();
717
718   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
719
720   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
721   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
722
723   result = value->GetArray();
724   result->GetElementAt(0).Get(resultStartFrame);
725   result->GetElementAt(1).Get(resultEndFrame);
726
727   DALI_TEST_EQUALS(startFrame, resultStartFrame, TEST_LOCATION); // Should not be changed
728   DALI_TEST_EQUALS(endFrame, resultEndFrame, TEST_LOCATION);
729
730   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Map());
731
732   application.SendNotification();
733   application.Render();
734
735   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
736
737   application.SendNotification();
738   application.Render();
739
740   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
741
742   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
743   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
744   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
745
746   array.Clear();
747   array.PushBack(0);
748   array.PushBack(2);
749
750   attributes.Clear();
751   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
752   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
753
754   application.SendNotification();
755   application.Render();
756
757   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
758
759   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
760   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
761
762   result = value->GetArray();
763   result->GetElementAt(0).Get(resultStartFrame);
764   result->GetElementAt(1).Get(resultEndFrame);
765
766   DALI_TEST_EQUALS(0, resultStartFrame, TEST_LOCATION);
767   DALI_TEST_EQUALS(2, resultEndFrame, TEST_LOCATION);
768
769   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
770   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION); // CURRENT_FRAME_NUMBER should be changed also.
771
772   END_TEST;
773 }
774
775 int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
776 {
777   ToolkitTestApplication application;
778   tet_infoline("UtcDaliAnimatedVectorImageVisualPlayRangeMarker");
779
780   Property::Array array;
781   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
782
783   Property::Map propertyMap;
784   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
785     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
786     .Add(DevelImageVisual::Property::PLAY_RANGE, array);
787
788   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
789   DALI_TEST_CHECK(visual);
790
791   DummyControl      actor     = DummyControl::New(true);
792   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
793   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
794
795   Vector2 controlSize(20.f, 30.f);
796   actor.SetProperty(Actor::Property::SIZE, controlSize);
797
798   application.GetScene().Add(actor);
799
800   Property::Map attributes;
801   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
802
803   application.SendNotification();
804   application.Render();
805
806   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
807
808   // renderer is added to actor
809   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
810   Renderer renderer = actor.GetRendererAt(0u);
811   DALI_TEST_CHECK(renderer);
812
813   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
814   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
815
816   int              resultStartFrame, resultEndFrame;
817   Property::Array* result = value->GetArray();
818   result->GetElementAt(0).Get(resultStartFrame);
819   result->GetElementAt(1).Get(resultEndFrame);
820
821   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
822   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION);
823
824   // Set 2 markers
825   array.Clear();
826   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
827   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_2);
828
829   attributes.Clear();
830   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
831   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
832
833   application.SendNotification();
834   application.Render();
835
836   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
837
838   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
839   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
840
841   result = value->GetArray();
842   result->GetElementAt(0).Get(resultStartFrame);
843   result->GetElementAt(1).Get(resultEndFrame);
844
845   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION);
846   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
847
848   // Set invalid play range
849   array.Clear();
850   array.PushBack(1);
851   array.PushBack(VECTOR_ANIMATION_MARKER_NAME_1);
852
853   attributes.Clear();
854   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
855   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
856
857   application.SendNotification();
858   application.Render();
859
860   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
861
862   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
863   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
864
865   result = value->GetArray();
866   result->GetElementAt(0).Get(resultStartFrame);
867   result->GetElementAt(1).Get(resultEndFrame);
868
869   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION); // Should not be changed
870   DALI_TEST_EQUALS(VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION);
871
872   END_TEST;
873 }
874
875 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
876 {
877   ToolkitTestApplication application;
878   tet_infoline("UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal");
879
880   Property::Map propertyMap;
881   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
882     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
883     .Add(DevelImageVisual::Property::LOOP_COUNT, 3);
884
885   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
886   DALI_TEST_CHECK(visual);
887
888   DummyControl      actor     = DummyControl::New(true);
889   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
890   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
891
892   DevelControl::VisualEventSignal(actor).Connect(&VisualEventSignal);
893
894   Vector2 controlSize(20.f, 30.f);
895   actor.SetProperty(Actor::Property::SIZE, controlSize);
896
897   application.GetScene().Add(actor);
898
899   Property::Map attributes;
900   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
901
902   application.SendNotification();
903   application.Render();
904
905   // Wait for animation finish
906   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
907
908   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
909   Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE);
910   DALI_TEST_CHECK(value->Get<int>() == DevelImageVisual::PlayState::STOPPED);
911
912   DALI_TEST_EQUALS(gAnimationFinishedSignalFired, true, TEST_LOCATION);
913
914   END_TEST;
915 }
916
917 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
918 {
919   ToolkitTestApplication application;
920   tet_infoline("UtcDaliAnimatedVectorImageVisualJumpTo");
921
922   Property::Map propertyMap;
923   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
924     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
925
926   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
927   DALI_TEST_CHECK(visual);
928
929   tet_printf("1. Visual is created.\n");
930
931   DummyControl      actor     = DummyControl::New(true);
932   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
933   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
934
935   Vector2 controlSize(20.f, 30.f);
936   actor.SetProperty(Actor::Property::SIZE, controlSize);
937
938   application.GetScene().Add(actor);
939
940   application.SendNotification();
941   application.Render();
942
943   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2);
944
945   application.SendNotification();
946   application.Render();
947
948   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
949
950   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
951   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
952   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
953
954   tet_printf("2. The current frame number is [%d].\n", value->Get<int>());
955
956   Property::Array array;
957   array.PushBack(0);
958   array.PushBack(2);
959
960   Property::Map attributes;
961   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
962   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
963
964   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
965
966   application.SendNotification();
967   application.Render();
968
969   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
970
971   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
972   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
973   DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
974
975   tet_printf("3. The current frame number is [%d].\n", value->Get<int>());
976
977   // Change play range
978   attributes.Clear();
979   array.Clear();
980
981   array.PushBack(0);
982   array.PushBack(4);
983
984   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, array);
985   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
986
987   attributes.Clear();
988   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
989
990   application.SendNotification();
991   application.Render();
992
993   // Stop and jump to 3
994   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
995
996   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
997
998   application.SendNotification();
999   application.Render();
1000
1001   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
1002
1003   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1004   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1005   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1006
1007   tet_printf("4. The current frame number is [%d].\n", value->Get<int>());
1008
1009   // Jump to the same position
1010   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3);
1011
1012   application.SendNotification();
1013   application.Render();
1014
1015   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
1016
1017   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1018   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1019   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1020
1021   tet_printf("5. The current frame number is [%d].\n", value->Get<int>());
1022
1023   END_TEST;
1024 }
1025
1026 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
1027 {
1028   ToolkitTestApplication application;
1029   tet_infoline("UtcDaliAnimatedVectorImageVisualUpdateProperty");
1030
1031   int             startFrame = 1, endFrame = 3;
1032   Property::Array playRange;
1033   playRange.PushBack(startFrame);
1034   playRange.PushBack(endFrame);
1035
1036   Property::Map propertyMap;
1037   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1038     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1039     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1040     .Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1041
1042   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1043   DALI_TEST_CHECK(visual);
1044
1045   DummyControl      actor     = DummyControl::New(true);
1046   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1047   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1048
1049   Vector2 controlSize(20.f, 30.f);
1050   actor.SetProperty(Actor::Property::SIZE, controlSize);
1051
1052   application.GetScene().Add(actor);
1053
1054   application.SendNotification();
1055   application.Render();
1056
1057   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
1058
1059   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1060   Property::Value* value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1061   DALI_TEST_EQUALS(value->Get<int>(), 3, TEST_LOCATION);
1062
1063   value = map.Find(DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY);
1064   DALI_TEST_CHECK(value);
1065
1066   Property::Array* result = value->GetArray();
1067   DALI_TEST_CHECK(result);
1068
1069   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1070   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1071
1072   playRange.Clear();
1073   playRange.PushBack(0);
1074   playRange.PushBack(2);
1075
1076   Property::Map attributes;
1077   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1078   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 5);
1079
1080   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1081
1082   application.SendNotification();
1083   application.Render();
1084
1085   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
1086
1087   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1088   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1089   DALI_TEST_EQUALS(value->Get<int>(), 5, TEST_LOCATION);
1090
1091   value  = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1092   result = value->GetArray();
1093   DALI_TEST_CHECK(result);
1094
1095   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == 0);
1096   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == 2);
1097
1098   attributes.Clear();
1099
1100   playRange.Clear();
1101   playRange.PushBack(startFrame);
1102   playRange.PushBack(endFrame);
1103
1104   attributes.Add(DevelImageVisual::Property::PLAY_RANGE, playRange);
1105
1106   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1107
1108   application.SendNotification();
1109   application.Render();
1110
1111   std::this_thread::sleep_for(std::chrono::milliseconds(20)); // wait for next rasterize thread run
1112
1113   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1114   value = map.Find(DevelImageVisual::Property::PLAY_RANGE);
1115
1116   result = value->GetArray();
1117   DALI_TEST_CHECK(result);
1118
1119   DALI_TEST_CHECK(result->GetElementAt(0).Get<int>() == startFrame);
1120   DALI_TEST_CHECK(result->GetElementAt(1).Get<int>() == endFrame);
1121
1122   // Play and update property
1123   attributes.Clear();
1124   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1125
1126   application.SendNotification();
1127   application.Render();
1128
1129   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, 10);
1130
1131   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1132
1133   application.SendNotification();
1134   application.Render();
1135
1136   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1137   value = map.Find(DevelImageVisual::Property::LOOP_COUNT);
1138   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
1139
1140   END_TEST;
1141 }
1142
1143 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1144 {
1145   ToolkitTestApplication application;
1146   tet_infoline("UtcDaliAnimatedVectorImageVisualStopBehavior");
1147
1148   Property::Map propertyMap;
1149   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1150     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1151     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1152     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
1153
1154   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1155   DALI_TEST_CHECK(visual);
1156
1157   DummyControl      actor     = DummyControl::New(true);
1158   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1159   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1160
1161   Vector2 controlSize(20.f, 30.f);
1162   actor.SetProperty(Actor::Property::SIZE, controlSize);
1163
1164   application.GetScene().Add(actor);
1165
1166   Property::Map attributes;
1167   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1168
1169   application.SendNotification();
1170   application.Render();
1171
1172   // Trigger count is 1 - animation finished
1173   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1174
1175   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1176   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1177   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1178
1179   // Change stop behavior
1180   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1181
1182   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1183
1184   attributes.Clear();
1185
1186   // Play again
1187   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1188
1189   application.SendNotification();
1190   application.Render();
1191
1192   // Trigger count is 1 - animation finished
1193   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1194
1195   map = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1196
1197   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1198   int              totalFrameNumber = value1->Get<int>();
1199
1200   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1201   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1202
1203   // Change stop behavior
1204   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1205   attributes.Add(DevelImageVisual::Property::LOOP_COUNT, -1);
1206
1207   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1208
1209   attributes.Clear();
1210
1211   // Play again
1212   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1213
1214   application.SendNotification();
1215   application.Render();
1216
1217   // Pause
1218   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes);
1219
1220   map                    = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1221   value                  = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1222   int currentFrameNumber = value->Get<int>();
1223
1224   // Stop
1225   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes);
1226
1227   application.SendNotification();
1228   application.Render(16);
1229
1230   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1231   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1232   DALI_TEST_EQUALS(value->Get<int>(), currentFrameNumber, TEST_LOCATION); // Should be same with currentFrameNumber
1233
1234   END_TEST;
1235 }
1236
1237 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1238 {
1239   ToolkitTestApplication application;
1240   tet_infoline("UtcDaliAnimatedVectorImageVisualLoopingMode");
1241
1242   Property::Map propertyMap;
1243   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1244     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME)
1245     .Add(DevelImageVisual::Property::LOOP_COUNT, 3)
1246     .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME)
1247     .Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE);
1248
1249   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1250   DALI_TEST_CHECK(visual);
1251
1252   DummyControl      actor     = DummyControl::New(true);
1253   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1254   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1255
1256   Vector2 controlSize(20.f, 30.f);
1257   actor.SetProperty(Actor::Property::SIZE, controlSize);
1258
1259   application.GetScene().Add(actor);
1260
1261   Property::Map attributes;
1262   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1263
1264   application.SendNotification();
1265   application.Render();
1266
1267   // Trigger count is 1 - animation finished
1268   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1269
1270   Property::Map    map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1271   Property::Value* value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1272   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame because of auto reverse
1273
1274   // Change stop behavior
1275   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME);
1276
1277   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1278
1279   // Play again
1280   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1281
1282   application.SendNotification();
1283   application.Render();
1284
1285   // Trigger count is 1 - animation finished
1286   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1287
1288   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1289   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1290   DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION); // Should be the first frame
1291
1292   // Change looping mode
1293   attributes.Add(DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART);
1294
1295   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1296
1297   // Play again
1298   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1299
1300   application.SendNotification();
1301   application.Render();
1302
1303   // Trigger count is 1 - animation finished
1304   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1305
1306   Property::Value* value1           = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1307   int              totalFrameNumber = value1->Get<int>();
1308
1309   map   = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1310   value = map.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
1311   DALI_TEST_EQUALS(value->Get<int>(), totalFrameNumber - 1, TEST_LOCATION); // Should be the last frame
1312
1313   END_TEST;
1314 }
1315
1316 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1317 {
1318   ToolkitTestApplication application;
1319   tet_infoline("UtcDaliAnimatedVectorImageVisualPropertyNotification");
1320
1321   Property::Map propertyMap;
1322   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1323     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1324
1325   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1326   DALI_TEST_CHECK(visual);
1327
1328   DummyControl      actor     = DummyControl::New(true);
1329   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1330   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1331
1332   Vector2 controlSize(20.f, 30.f);
1333   Vector3 controlScale(2.0f, 2.0f, 1.0f);
1334   actor.SetProperty(Actor::Property::SIZE, controlSize);
1335   actor.SetProperty(Actor::Property::SCALE, controlScale);
1336
1337   application.GetScene().Add(actor);
1338
1339   application.SendNotification();
1340   application.Render();
1341
1342   application.SendNotification();
1343   application.Render();
1344
1345   Renderer renderer = actor.GetRendererAt(0u);
1346   DALI_TEST_CHECK(renderer);
1347
1348   auto textureSet = renderer.GetTextures();
1349   auto texture    = textureSet.GetTexture(0);
1350
1351   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1352   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1353
1354   // Change scale and size
1355   controlSize  = Vector2(50.f, 40.f);
1356   controlScale = Vector3(0.5f, 0.5f, 1.0f);
1357   actor.SetProperty(Actor::Property::SIZE, controlSize);
1358   actor.SetProperty(Actor::Property::SCALE, controlScale);
1359
1360   application.SendNotification();
1361   application.Render();
1362
1363   application.SendNotification();
1364   application.Render();
1365
1366   renderer = actor.GetRendererAt(0u);
1367   DALI_TEST_CHECK(renderer);
1368
1369   textureSet = renderer.GetTextures();
1370   texture    = textureSet.GetTexture(0);
1371
1372   DALI_TEST_EQUALS(controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION);
1373   DALI_TEST_EQUALS(controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION);
1374
1375   END_TEST;
1376 }
1377
1378 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1379 {
1380   ToolkitTestApplication application;
1381   tet_infoline("UtcDaliAnimatedVectorImageVisualMultipleInstances");
1382
1383   Property::Map propertyMap;
1384   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1385     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1386
1387   Visual::Base visual1 = VisualFactory::Get().CreateVisual(propertyMap);
1388   DALI_TEST_CHECK(visual1);
1389
1390   DummyControl      actor1     = DummyControl::New(true);
1391   DummyControlImpl& dummyImpl1 = static_cast<DummyControlImpl&>(actor1.GetImplementation());
1392   dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
1393
1394   Vector2 controlSize(20.f, 30.f);
1395   actor1.SetProperty(Actor::Property::SIZE, controlSize);
1396
1397   application.GetScene().Add(actor1);
1398
1399   propertyMap.Clear();
1400   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1401     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1402
1403   Visual::Base visual2 = VisualFactory::Get().CreateVisual(propertyMap);
1404   DALI_TEST_CHECK(visual2);
1405
1406   DummyControl      actor2     = DummyControl::New(true);
1407   DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
1408   dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
1409
1410   actor2.SetProperty(Actor::Property::SIZE, controlSize);
1411
1412   application.GetScene().Add(actor2);
1413
1414   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1415
1416   application.SendNotification();
1417   application.Render();
1418
1419   std::this_thread::sleep_for(std::chrono::milliseconds(200));
1420
1421   Property::Map attributes;
1422   attributes.Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
1423
1424   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1425   DevelControl::DoAction(actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, attributes);
1426
1427   DevelControl::DoAction(actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map());
1428
1429   // renderer is added to actor
1430   DALI_TEST_CHECK(actor1.GetRendererCount() == 1u);
1431   Renderer renderer1 = actor1.GetRendererAt(0u);
1432   DALI_TEST_CHECK(renderer1);
1433
1434   // renderer is added to actor
1435   DALI_TEST_CHECK(actor2.GetRendererCount() == 1u);
1436   Renderer renderer2 = actor2.GetRendererAt(0u);
1437   DALI_TEST_CHECK(renderer2);
1438
1439   END_TEST;
1440 }
1441
1442 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1443 {
1444   ToolkitTestApplication application;
1445   tet_infoline("UtcDaliAnimatedVectorImageVisualControlVisibilityChanged");
1446
1447   Property::Map propertyMap;
1448   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1449     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1450
1451   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1452   DALI_TEST_CHECK(visual);
1453
1454   DummyControl      actor     = DummyControl::New(true);
1455   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1456   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1457
1458   Vector2 controlSize(20.f, 30.f);
1459   actor.SetProperty(Actor::Property::SIZE, controlSize);
1460
1461   application.GetScene().Add(actor);
1462
1463   application.SendNotification();
1464   application.Render();
1465
1466   Property::Map attributes;
1467   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1468
1469   application.SendNotification();
1470   application.Render();
1471
1472   // Check rendering behavior
1473   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1474   Renderer renderer = actor.GetRendererAt(0u);
1475   DALI_TEST_CHECK(renderer);
1476   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1477
1478   actor.SetProperty(Actor::Property::VISIBLE, false);
1479
1480   application.SendNotification();
1481   application.Render();
1482
1483   // Check rendering behavior again
1484   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1485
1486   END_TEST;
1487 }
1488
1489 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1490 {
1491   ToolkitTestApplication application;
1492   tet_infoline("UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged");
1493
1494   Property::Map propertyMap;
1495   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1496     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
1497
1498   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1499   DALI_TEST_CHECK(visual);
1500
1501   DummyControl      actor     = DummyControl::New(true);
1502   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1503   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1504
1505   Vector2 controlSize(20.f, 30.f);
1506   actor.SetProperty(Actor::Property::SIZE, controlSize);
1507
1508   application.GetScene().Add(actor);
1509
1510   application.SendNotification();
1511   application.Render();
1512
1513   Property::Map attributes;
1514   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1515
1516   application.SendNotification();
1517   application.Render();
1518
1519   // Check rendering behavior
1520   DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1521   Renderer renderer = actor.GetRendererAt(0u);
1522   DALI_TEST_CHECK(renderer);
1523   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::CONTINUOUSLY);
1524
1525   Window window = DevelWindow::Get(actor);
1526   window.Hide();
1527
1528   application.SendNotification();
1529   application.Render();
1530
1531   // Check rendering behavior again
1532   DALI_TEST_CHECK(renderer.GetProperty<int>(DevelRenderer::Property::RENDERING_BEHAVIOR) == DevelRenderer::Rendering::IF_REQUIRED);
1533
1534   END_TEST;
1535 }
1536
1537 int UtcDaliAnimatedVectorImageVisualInvalidFile(void)
1538 {
1539   ToolkitTestApplication application;
1540   tet_infoline("Request loading with invalid file - should draw broken image");
1541
1542   TestGlAbstraction& gl           = application.GetGlAbstraction();
1543   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1544   textureTrace.Enable(true);
1545
1546   Property::Map propertyMap;
1547   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1548     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1549
1550   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1551   DALI_TEST_CHECK(visual);
1552
1553   DummyControl      actor     = DummyControl::New(true);
1554   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1555   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1556
1557   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1558
1559   application.GetScene().Add(actor);
1560
1561   application.SendNotification();
1562   application.Render();
1563
1564   // Check resource status
1565   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1566   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1567
1568   // The broken image should be shown.
1569   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1570   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1571
1572   END_TEST;
1573 }
1574
1575 int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
1576 {
1577   ToolkitTestApplication application;
1578   tet_infoline("UtcDaliAnimatedVectorImageVisualFrameDrops");
1579
1580   Property::Map propertyMap;
1581   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1582     .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME_FRAME_DROP);
1583
1584   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1585   DALI_TEST_CHECK(visual);
1586
1587   DummyControl      actor     = DummyControl::New(true);
1588   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1589   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1590
1591   Vector2 controlSize(20.f, 30.f);
1592   actor.SetProperty(Actor::Property::SIZE, controlSize);
1593
1594   application.GetScene().Add(actor);
1595
1596   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
1597   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
1598   int              totalFrameNumber = value->Get<int>();
1599
1600   Property::Map attributes;
1601   DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes);
1602
1603   // Make delay to drop frames
1604   Test::VectorAnimationRenderer::DelayRendering(170); // longer than 16.6 * 10frames
1605
1606   application.SendNotification();
1607   application.Render();
1608
1609   // Trigger count is 2 - render the first frame & calculating frame drops
1610   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1611
1612   // Check dropped frame
1613   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
1614   DALI_TEST_CHECK(frames > 0);
1615   DALI_TEST_CHECK(frames <= static_cast<uint32_t>(totalFrameNumber));
1616
1617   END_TEST;
1618 }