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