DALi Version 2.1.22
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedImageVisual.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 <iostream>
19
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <toolkit-event-thread-callback.h>
23 #include <toolkit-timer.h>
24
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
28 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31
32 #include "dummy-control.h"
33
34 using namespace Dali;
35 using namespace Dali::Toolkit;
36
37 void dali_animated_image_visual_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void dali_animated_image_visual_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47 namespace
48 {
49 const char* TEST_IMAGE_FILE_NAME      = TEST_RESOURCE_DIR "/application-icon-%02d.png";
50 const char* TEST_GIF_FILE_NAME        = TEST_RESOURCE_DIR "/anim.gif";
51 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
52 } // namespace
53
54 void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0)
55 {
56   for(int i = 20 + startIndex; i <= 30; ++i)
57   {
58     char* url;
59     if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
60     {
61       Property::Value value(url);
62       urls.Add(value);
63       free(url);
64     }
65   }
66 }
67
68 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
69 {
70   ToolkitTestApplication application;
71   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
72
73   // request AnimatedImageVisual with a property map
74   VisualFactory factory             = VisualFactory::Get();
75   Visual::Base  animatedImageVisual = factory.CreateVisual(
76     Property::Map()
77       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
78       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
79       .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
80       .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
81       .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
82       .Add(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME)
83       .Add(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f)
84       .Add(ImageVisual::Property::CROP_TO_MASK, true)
85       .Add(DevelVisual::Property::CORNER_RADIUS, 22.2f)
86       .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE)
87       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 33.3f)
88       .Add(DevelVisual::Property::BORDERLINE_COLOR, Color::RED)
89       .Add(DevelVisual::Property::BORDERLINE_OFFSET, 0.3f));
90
91   Property::Map resultMap;
92   animatedImageVisual.CreatePropertyMap(resultMap);
93   // check the property values from the returned map from a visual
94   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
95   DALI_TEST_CHECK(value);
96   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
97
98   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
99   DALI_TEST_CHECK(value);
100   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
101
102   value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
103   DALI_TEST_CHECK(value);
104   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION);
105
106   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER);
107   DALI_TEST_CHECK(value);
108   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
109
110   value = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT);
111   DALI_TEST_CHECK(value);
112   DALI_TEST_EQUALS(value->Get<float>(), 33.3f, TEST_LOCATION);
113
114   value = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4);
115   DALI_TEST_CHECK(value);
116   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::RED, TEST_LOCATION);
117
118   value = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT);
119   DALI_TEST_CHECK(value);
120   DALI_TEST_EQUALS(value->Get<float>(), 0.3f, TEST_LOCATION);
121
122   // Check mask properties
123   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, Property::STRING);
124   DALI_TEST_CHECK(value);
125   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
126
127   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, Property::FLOAT);
128   DALI_TEST_CHECK(value);
129   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
130
131   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, Property::BOOLEAN);
132   DALI_TEST_CHECK(value);
133   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
134
135   Vector2 naturalSize;
136   animatedImageVisual.GetNaturalSize(naturalSize);
137   DALI_TEST_EQUALS(naturalSize, Vector2(100, 100), TEST_LOCATION);
138
139   // request AnimatedImageVisual with an URL
140   Visual::Base animatedImageVisual2 = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions());
141   resultMap.Clear();
142   animatedImageVisual2.CreatePropertyMap(resultMap);
143   // check the property values from the returned map from a visual
144   value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
145   DALI_TEST_CHECK(value);
146   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
147
148   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
149   DALI_TEST_CHECK(value);
150   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
151
152   END_TEST;
153 }
154
155 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
156 {
157   ToolkitTestApplication application;
158   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image with fixed cache");
159
160   // request AnimatedImageVisual with a property map
161   VisualFactory   factory = VisualFactory::Get();
162   Property::Array urls;
163   CopyUrlsIntoArray(urls);
164
165   Visual::Base animatedImageVisual = factory.CreateVisual(
166     Property::Map()
167       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
168       .Add("url", urls)
169       .Add("batchSize", 4)
170       .Add("cacheSize", 20)
171       .Add("loopCount", 10)
172       .Add("frameDelay", 200)
173       .Add("pixelArea", Vector4())
174       .Add("wrapModeU", WrapMode::REPEAT)
175       .Add("wrapModeV", WrapMode::DEFAULT)
176       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
177       .Add("maskContentScale", 1.6f)
178       .Add("cropToMask", true)
179       .Add("cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f))
180       .Add("cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE)
181       .Add("borderlineWidth", 20.0f)
182       .Add("borderlineColor", Vector4())
183       .Add("borderlineOffset", -1.0f));
184
185   Property::Map resultMap;
186   animatedImageVisual.CreatePropertyMap(resultMap);
187   // check the property values from the returned map from a visual
188   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
189   DALI_TEST_CHECK(value);
190   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
191
192   value = resultMap.Find(ImageVisual::Property::URL, "url");
193   DALI_TEST_CHECK(value);
194   Property::Array* resultUrls = value->GetArray();
195   DALI_TEST_CHECK(resultUrls);
196   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
197
198   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
199   DALI_TEST_CHECK(value);
200   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
201
202   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
203   DALI_TEST_CHECK(value);
204   DALI_TEST_EQUALS(value->Get<int>(), 20, TEST_LOCATION);
205
206   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
207   DALI_TEST_CHECK(value);
208   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
209
210   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
211   DALI_TEST_CHECK(value);
212   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
213
214   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
215   DALI_TEST_CHECK(value);
216   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
217
218   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
219   DALI_TEST_CHECK(value);
220   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION);
221
222   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
223   DALI_TEST_CHECK(value);
224   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::RELATIVE);
225
226   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
227   DALI_TEST_CHECK(value);
228   DALI_TEST_EQUALS(value->Get<float>(), 20.0f, TEST_LOCATION);
229
230   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
231   DALI_TEST_CHECK(value);
232   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
233
234   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
235   DALI_TEST_CHECK(value);
236   DALI_TEST_EQUALS(value->Get<float>(), -1.0f, TEST_LOCATION);
237
238   // Check mask properties
239   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
240   DALI_TEST_CHECK(value);
241   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
242
243   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
244   DALI_TEST_CHECK(value);
245   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
246
247   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
248   DALI_TEST_CHECK(value);
249   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
250
251   END_TEST;
252 }
253
254 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
255 {
256   ToolkitTestApplication application;
257   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap for multi image rolling cache");
258
259   // request AnimatedImageVisual with a property map
260   VisualFactory   factory = VisualFactory::Get();
261   Property::Array urls;
262   CopyUrlsIntoArray(urls);
263
264   Visual::Base animatedImageVisual = factory.CreateVisual(
265     Property::Map()
266       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
267       .Add("url", urls)
268       .Add("batchSize", 4)
269       .Add("cacheSize", 8)
270       .Add("loopCount", 10)
271       .Add("frameDelay", 200)
272       .Add("pixelArea", Vector4())
273       .Add("wrapModeU", WrapMode::REPEAT)
274       .Add("wrapModeV", WrapMode::DEFAULT)
275       .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME)
276       .Add("maskContentScale", 1.6f)
277       .Add("cropToMask", true)
278       .Add("cornerRadius", 50.5f));
279
280   Property::Map resultMap;
281   animatedImageVisual.CreatePropertyMap(resultMap);
282   // check the property values from the returned map from a visual
283   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
284   DALI_TEST_CHECK(value);
285   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
286
287   value = resultMap.Find(ImageVisual::Property::URL, "url");
288   DALI_TEST_CHECK(value);
289   Property::Array* resultUrls = value->GetArray();
290   DALI_TEST_CHECK(resultUrls);
291   DALI_TEST_EQUALS(resultUrls->Count(), urls.Count(), TEST_LOCATION);
292
293   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
294   DALI_TEST_CHECK(value);
295   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
296
297   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
298   DALI_TEST_CHECK(value);
299   DALI_TEST_EQUALS(value->Get<int>(), 8, TEST_LOCATION);
300
301   value = resultMap.Find(Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount");
302   DALI_TEST_CHECK(value);
303   DALI_TEST_EQUALS(value->Get<int>(), 10, TEST_LOCATION);
304
305   value = resultMap.Find(ImageVisual::Property::FRAME_DELAY, "frameDelay");
306   DALI_TEST_CHECK(value);
307   DALI_TEST_EQUALS(value->Get<int>(), 200, TEST_LOCATION);
308
309   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
310   DALI_TEST_CHECK(value);
311   DALI_TEST_EQUALS(value->Get<int>(), 11, TEST_LOCATION);
312
313   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius");
314   DALI_TEST_CHECK(value);
315   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(50.5f, 50.5f, 50.5f, 50.5f), TEST_LOCATION);
316
317   value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy");
318   DALI_TEST_CHECK(value);
319   DALI_TEST_CHECK(value->Get<int>() == Visual::Transform::Policy::ABSOLUTE);
320
321   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
322   DALI_TEST_CHECK(value);
323   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
324
325   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
326   DALI_TEST_CHECK(value);
327   DALI_TEST_EQUALS(value->Get<Vector4>(), Color::BLACK, TEST_LOCATION);
328
329   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
330   DALI_TEST_CHECK(value);
331   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
332
333   // Check mask properties
334   value = resultMap.Find(ImageVisual::Property::ALPHA_MASK_URL, "alphaMaskUrl");
335   DALI_TEST_CHECK(value);
336   DALI_TEST_CHECK(value->Get<std::string>() == TEST_MASK_IMAGE_FILE_NAME);
337
338   value = resultMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE, "maskContentScale");
339   DALI_TEST_CHECK(value);
340   DALI_TEST_EQUALS(value->Get<float>(), 1.6f, TEST_LOCATION);
341
342   value = resultMap.Find(ImageVisual::Property::CROP_TO_MASK, "cropToMask");
343   DALI_TEST_CHECK(value);
344   DALI_TEST_EQUALS(value->Get<bool>(), true, TEST_LOCATION);
345
346   END_TEST;
347 }
348
349 int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
350 {
351   ToolkitTestApplication application;
352   tet_infoline("UtcDaliAnimatedImageVisualGetPropertyMap");
353
354   // request AnimatedImageVisual with a property map
355   VisualFactory factory             = VisualFactory::Get();
356   Visual::Base  animatedImageVisual = factory.CreateVisual(
357     Property::Map()
358       .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
359       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
360       .Add(ImageVisual::Property::BATCH_SIZE, 1)
361       .Add(ImageVisual::Property::CACHE_SIZE, 1)
362       .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true)
363       .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED)
364       .Add(ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED)
365       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 0.4f));
366
367   Property::Map resultMap;
368   animatedImageVisual.CreatePropertyMap(resultMap);
369
370   // check the property values from the returned map from a visual
371   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
372   DALI_TEST_CHECK(value);
373   DALI_TEST_CHECK(value->Get<int>() == Visual::ANIMATED_IMAGE);
374
375   value = resultMap.Find(ImageVisual::Property::URL, Property::STRING);
376   DALI_TEST_CHECK(value);
377   DALI_TEST_CHECK(value->Get<std::string>() == TEST_GIF_FILE_NAME);
378
379   value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, Property::INTEGER);
380   DALI_TEST_CHECK(value);
381   DALI_TEST_CHECK(value->Get<int>() == 2);
382
383   value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, Property::INTEGER);
384   DALI_TEST_CHECK(value);
385   DALI_TEST_CHECK(value->Get<int>() == 2);
386
387   value = resultMap.Find(ImageVisual::Property::SYNCHRONOUS_LOADING, Property::BOOLEAN);
388   DALI_TEST_CHECK(value);
389   DALI_TEST_CHECK(value->Get<bool>() == true);
390
391   value = resultMap.Find(ImageVisual::Property::RELEASE_POLICY, Property::INTEGER);
392   DALI_TEST_CHECK(value);
393   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::ReleasePolicy::DETACHED);
394
395   value = resultMap.Find(ImageVisual::Property::LOAD_POLICY, Property::INTEGER);
396   DALI_TEST_CHECK(value);
397   DALI_TEST_CHECK(value->Get<int>() == ImageVisual::LoadPolicy::ATTACHED);
398
399   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
400   DALI_TEST_CHECK(value);
401   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
402
403   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth");
404   DALI_TEST_CHECK(value);
405   DALI_TEST_EQUALS(value->Get<float>(), 0.4f, TEST_LOCATION);
406
407   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, "borderlineColor");
408   DALI_TEST_CHECK(value);
409   DALI_TEST_EQUALS(value->Get<Vector4>(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
410
411   value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, "borderlineOffset");
412   DALI_TEST_CHECK(value);
413   DALI_TEST_EQUALS(value->Get<float>(), 0.0f, TEST_LOCATION);
414
415   END_TEST;
416 }
417
418 int UtcDaliAnimatedImageVisualImageLoadingFail01(void)
419 {
420   ToolkitTestApplication application;
421   TestGlAbstraction&     gl = application.GetGlAbstraction();
422
423   {
424     Property::Map propertyMap;
425     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
426     propertyMap.Insert(ImageVisual::Property::URL, "dummy.gif");
427     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
428     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
429     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
430     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
431     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
432     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
433
434     VisualFactory factory = VisualFactory::Get();
435     Visual::Base  visual  = factory.CreateVisual(propertyMap);
436
437     DummyControl        dummyControl = DummyControl::New(true);
438     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
439     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
440
441     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
442     application.GetScene().Add(dummyControl);
443
444     TraceCallStack& textureTrace = gl.GetTextureTrace();
445     textureTrace.Enable(true);
446
447     application.SendNotification();
448     application.Render(20);
449
450     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
451
452     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
453
454     application.SendNotification();
455     application.Render(20);
456
457     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 1, TEST_LOCATION);
458
459     dummyControl.Unparent();
460   }
461
462   END_TEST;
463 }
464
465 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
466 {
467   ToolkitTestApplication application;
468   TestGlAbstraction&     gl = application.GetGlAbstraction();
469
470   {
471     Property::Map propertyMap;
472     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
473     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
474     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
475     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
476     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
477     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
478     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
479     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
480
481     VisualFactory factory = VisualFactory::Get();
482     Visual::Base  visual  = factory.CreateVisual(propertyMap);
483
484     DummyControl        dummyControl = DummyControl::New(true);
485     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
486     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
487
488     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
489     application.GetScene().Add(dummyControl);
490
491     TraceCallStack& textureTrace = gl.GetTextureTrace();
492     textureTrace.Enable(true);
493
494     application.SendNotification();
495     application.Render(20);
496
497     // The first frame is loaded synchronously and load next batch.
498     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
499
500     application.SendNotification();
501     application.Render();
502
503     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
504     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
505
506     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3);
507
508     application.SendNotification();
509     application.Render(20);
510
511     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
512
513     application.SendNotification();
514     application.Render();
515
516     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
517
518     dummyControl.Unparent();
519   }
520   tet_infoline("Test that removing the visual from stage deletes all textures");
521   application.SendNotification();
522   application.Render(16);
523   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
524
525   END_TEST;
526 }
527
528
529 int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask(void)
530 {
531   ToolkitTestApplication application;
532   TestGlAbstraction&     gl = application.GetGlAbstraction();
533
534   {
535     Property::Map propertyMap;
536     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
537     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
538     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
539     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
540     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
541     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
542     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
543     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
544     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
545
546     VisualFactory factory = VisualFactory::Get();
547     Visual::Base  visual  = factory.CreateVisual(propertyMap);
548
549     Property::Map testMap;
550     visual.CreatePropertyMap(testMap);
551     DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
552
553     DummyControl        dummyControl = DummyControl::New(true);
554     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
555     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
556
557     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
558     application.GetScene().Add(dummyControl);
559
560     TraceCallStack& textureTrace = gl.GetTextureTrace();
561     textureTrace.Enable(true);
562
563     application.SendNotification();
564     application.Render(20);
565
566     // The first frame is loaded synchronously and load next batch with masking
567     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
568
569     application.SendNotification();
570     application.Render();
571
572     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
573     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
574
575     dummyControl.Unparent();
576   }
577   tet_infoline("Test that removing the visual from stage deletes all textures");
578   application.SendNotification();
579   application.Render(16);
580   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
581
582   END_TEST;
583 }
584
585 int UtcDaliAnimatedImageVisualJumpToAction(void)
586 {
587   ToolkitTestApplication application;
588   TestGlAbstraction&     gl = application.GetGlAbstraction();
589
590   Property::Array urls;
591   CopyUrlsIntoArray(urls);
592
593   {
594     Property::Map propertyMap;
595     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
596     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
597     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
598     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
599     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
600
601     VisualFactory factory = VisualFactory::Get();
602     Visual::Base  visual  = factory.CreateVisual(propertyMap);
603
604     DummyControl        dummyControl = DummyControl::New(true);
605     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
606     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
607
608     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
609     application.GetScene().Add(dummyControl);
610     application.SendNotification();
611     application.Render(20);
612
613     tet_infoline("Ready the visual after the visual is on stage");
614     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
615
616     tet_infoline("Test that a timer has been started");
617     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
618
619     TraceCallStack& textureTrace = gl.GetTextureTrace();
620     textureTrace.Enable(true);
621
622     application.SendNotification();
623     application.Render(20);
624
625     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
626
627     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
628
629     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
630
631     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
632
633     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
634
635     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
636
637     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
638     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
639
640     dummyControl.Unparent();
641   }
642   tet_infoline("Test that removing the visual from stage deletes all textures");
643   application.SendNotification();
644   application.Render(16);
645   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
646
647   END_TEST;
648 }
649
650 int UtcDaliAnimatedImageVisualStopBehavior(void)
651 {
652   ToolkitTestApplication application;
653   TestGlAbstraction&     gl = application.GetGlAbstraction();
654
655   Property::Array urls;
656   CopyUrlsIntoArray(urls);
657
658   {
659     Property::Map propertyMap;
660     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
661     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
662     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
663     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
664     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
665     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
666
667     VisualFactory factory = VisualFactory::Get();
668     Visual::Base  visual  = factory.CreateVisual(propertyMap);
669
670     // Expect that a batch of 4 textures has been requested. These will be serially loaded
671     // below.
672
673     DummyControl        dummyControl = DummyControl::New(true);
674     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
675     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
676
677     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
678     application.GetScene().Add(dummyControl);
679     application.SendNotification();
680     application.Render(20);
681
682     tet_infoline("Ready the visual after the visual is on stage");
683     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
684
685     tet_infoline("Test that a timer has been started");
686     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
687
688     TraceCallStack& textureTrace = gl.GetTextureTrace();
689     textureTrace.Enable(true);
690
691     application.SendNotification();
692     application.Render(20);
693
694     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
695
696     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
697
698     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
699
700     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
701
702     // Expect the second batch has been requested
703     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
704
705     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
706
707     dummyControl.Unparent();
708   }
709   tet_infoline("Test that removing the visual from stage deletes all textures");
710   application.SendNotification();
711   application.Render(16);
712   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
713
714   END_TEST;
715 }
716
717 int UtcDaliAnimatedImageVisualStopBehavior02(void)
718 {
719   ToolkitTestApplication application;
720   TestGlAbstraction&     gl = application.GetGlAbstraction();
721
722   Property::Array urls;
723   CopyUrlsIntoArray(urls);
724
725   {
726     Property::Map propertyMap;
727     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
728     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
729     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
730     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
731     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
732     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
733
734     VisualFactory factory = VisualFactory::Get();
735     Visual::Base  visual  = factory.CreateVisual(propertyMap);
736
737     // Expect that a batch of 4 textures has been requested. These will be serially loaded
738     // below.
739
740     DummyControl        dummyControl = DummyControl::New(true);
741     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
742     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
743
744     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
745     application.GetScene().Add(dummyControl);
746
747     tet_infoline("Ready the visual after the visual is on stage");
748     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
749
750     TraceCallStack& textureTrace = gl.GetTextureTrace();
751     textureTrace.Enable(true);
752
753     application.SendNotification();
754     application.Render(20);
755
756     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
757
758     Test::EmitGlobalTimerSignal();
759
760     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
761
762     application.SendNotification();
763     application.Render(20);
764
765     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
766
767     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
768
769     tet_infoline("Ready the visual after the visual is on stage");
770     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
771
772     application.SendNotification();
773     application.Render(20);
774
775     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
776
777     dummyControl.Unparent();
778   }
779   tet_infoline("Test that removing the visual from stage deletes all textures");
780   application.SendNotification();
781   application.Render(16);
782   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
783
784   END_TEST;
785 }
786
787 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
788 {
789   ToolkitTestApplication application;
790   TestGlAbstraction&     gl = application.GetGlAbstraction();
791
792   {
793     Property::Map propertyMap;
794     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
795     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
796     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
797     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
798     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
799
800     VisualFactory factory = VisualFactory::Get();
801     Visual::Base  visual  = factory.CreateVisual(propertyMap);
802
803     // Expect that a batch of 4 textures has been requested. These will be serially loaded
804     // below.
805
806     DummyControl        dummyControl = DummyControl::New(true);
807     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
808     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
809
810     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
811     application.GetScene().Add(dummyControl);
812
813     application.SendNotification();
814     application.Render();
815
816     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
817
818     application.SendNotification();
819     application.Render(20);
820
821     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
822
823     tet_infoline("Test that a timer has been started");
824
825     TraceCallStack& textureTrace = gl.GetTextureTrace();
826     textureTrace.Enable(true);
827
828     Test::EmitGlobalTimerSignal();
829
830     application.SendNotification();
831     application.Render();
832
833     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
834
835     application.SendNotification();
836     application.Render(20);
837
838     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
839
840     dummyControl.Unparent();
841   }
842   tet_infoline("Test that removing the visual from stage deletes all textures");
843   application.SendNotification();
844   application.Render(20);
845   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
846
847   END_TEST;
848 }
849
850 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void)
851 {
852   ToolkitTestApplication application;
853   TestGlAbstraction&     gl = application.GetGlAbstraction();
854
855   {
856     Property::Map propertyMap;
857     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
858     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
859     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
860     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
861     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
862     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
863
864
865     VisualFactory factory = VisualFactory::Get();
866     Visual::Base  visual  = factory.CreateVisual(propertyMap);
867
868     DummyControl        dummyControl = DummyControl::New(true);
869     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
870     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
871
872     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
873     application.GetScene().Add(dummyControl);
874
875     application.SendNotification();
876     application.Render();
877
878     // load two frame(batch size), load mask image, and request two masking
879     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
880
881     application.SendNotification();
882     application.Render(20);
883
884     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
885
886     dummyControl.Unparent();
887   }
888   tet_infoline("Test that removing the visual from stage deletes all textures");
889   application.SendNotification();
890   application.Render(20);
891   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
892
893   END_TEST;
894 }
895
896 int UtcDaliAnimatedImageVisualMultiImage01(void)
897 {
898   ToolkitTestApplication application;
899   TestGlAbstraction&     gl = application.GetGlAbstraction();
900
901   Property::Array urls;
902   CopyUrlsIntoArray(urls);
903
904   {
905     Property::Map propertyMap;
906     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
907     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
908     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
909     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
910     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
911
912     VisualFactory factory = VisualFactory::Get();
913     Visual::Base  visual  = factory.CreateVisual(propertyMap);
914
915     // Expect that a batch of 4 textures has been requested. These will be serially loaded
916     // below.
917
918     DummyControl        dummyControl = DummyControl::New(true);
919     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
920     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
921
922     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
923     application.GetScene().Add(dummyControl);
924     application.SendNotification();
925     application.Render(16);
926
927     tet_infoline("Ready the visual after the visual is on stage");
928     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
929
930     tet_infoline("Test that a timer has been started");
931     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
932
933     TraceCallStack& textureTrace = gl.GetTextureTrace();
934     textureTrace.Enable(true);
935
936     application.SendNotification();
937     application.Render(16);
938
939     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
940     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
941
942     tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
943     Test::EmitGlobalTimerSignal();
944
945     // Expect the second batch has been requested
946     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
947
948     application.SendNotification();
949     application.Render(16);
950     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
951
952     tet_infoline("Test that after 2 ticks that we have 6 textures");
953
954     Test::EmitGlobalTimerSignal();
955     application.SendNotification();
956     application.Render(16);
957     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
958
959     tet_infoline("And that at least 2 textures were requested");
960     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
961     application.SendNotification();
962     application.Render(16);
963     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
964
965     tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
966     Test::EmitGlobalTimerSignal();
967     application.SendNotification();
968     application.Render(16);
969     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
970
971     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
972     application.SendNotification();
973     application.Render(16);
974     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
975
976     dummyControl.Unparent();
977   }
978   tet_infoline("Test that removing the visual from stage deletes all textures");
979   application.SendNotification();
980   application.Render(16);
981   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
982
983   END_TEST;
984 }
985
986 int UtcDaliAnimatedImageVisualMultiImage02(void)
987 {
988   ToolkitTestApplication application;
989   TestGlAbstraction&     gl = application.GetGlAbstraction();
990
991   tet_infoline("Test that the animated visual has different batch and cache size.");
992
993   {
994     Property::Array urls;
995     CopyUrlsIntoArray(urls);
996
997     Property::Map propertyMap;
998     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
999     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1000     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
1001     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
1002     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1003
1004     VisualFactory factory = VisualFactory::Get();
1005     Visual::Base  visual  = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1006
1007     // Check the batch size and cache size need to have minimum 2.
1008     Property::Map resultMap;
1009     visual.CreatePropertyMap(resultMap);
1010     Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
1011     DALI_TEST_CHECK(value);
1012     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1013     value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
1014     DALI_TEST_CHECK(value);
1015     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1016     visual.Reset();
1017
1018     // Batch size is 2 and cache size is 3
1019     propertyMap.Clear();
1020     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1021     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1022     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1023     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1024     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1025
1026     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1027
1028     // Expect that each image is loaded each tick
1029     DummyControl        dummyControl = DummyControl::New(true);
1030     Impl::DummyControl& dummyImpl1   = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1031     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1032     visual.Reset();
1033
1034     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1035     application.GetScene().Add(dummyControl);
1036     application.SendNotification();
1037     application.Render(16);
1038
1039     tet_infoline("Ready the visual after the visual is on window");
1040     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1041     application.SendNotification();
1042     application.Render(16); //glGenTextures 1 and 2
1043     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
1044
1045     tet_infoline("Test that each tick, a new image is requested");
1046     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1047     application.SendNotification();
1048     application.Render(16);
1049     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1050     application.SendNotification();
1051     application.Render(16); //glGenTextures 3
1052     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1053
1054     tet_infoline("Test that each tick, a new image is requested");
1055     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1056     application.SendNotification();
1057     application.Render(16);
1058     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1059     application.SendNotification();
1060     application.Render(16); //glGenTextures 4
1061     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1062
1063     dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1064     dummyControl.Unparent();
1065
1066     // Batch size is 9 and cache size is 4
1067     propertyMap.Clear();
1068     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1069     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1070     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1071     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
1072     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1073
1074     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1075
1076     // Expect that each image is loaded each tick
1077     dummyControl                   = DummyControl::New(true);
1078     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1079     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1080     visual.Reset();
1081
1082     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1083     application.GetScene().Add(dummyControl);
1084     application.SendNotification();
1085     application.Render(16);
1086
1087     tet_infoline("Ready the visual after the visual is on window");
1088     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1089     application.SendNotification();
1090     application.Render(16); //glGenTextures 1, 2, and 3
1091     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1092
1093     tet_infoline("Test that each tick, a new image is requested");
1094     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1095     application.SendNotification();
1096     application.Render(16);
1097     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1098     application.SendNotification();
1099     application.Render(16); //glGenTextures 4, 5, and 6
1100     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
1101
1102     tet_infoline("Test that each tick, a new image is requested");
1103     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1104     application.SendNotification();
1105     application.Render(16);
1106     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1107     application.SendNotification();
1108     application.Render(16); //glGenTextures 7, 1, and 2
1109     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1110
1111     tet_infoline("Test that each tick, a new image is requested");
1112     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
1113     application.SendNotification();
1114     application.Render(16);
1115     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1116     application.SendNotification();
1117     application.Render(16); //glGenTextures 3
1118     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1119
1120     dummyControl.Unparent();
1121   }
1122   tet_infoline("Test that removing the visual from window deletes all textures");
1123   application.SendNotification();
1124   application.Render(16);
1125   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1126
1127   END_TEST;
1128 }
1129
1130 int UtcDaliAnimatedImageVisualMultiImage03(void)
1131 {
1132   ToolkitTestApplication application;
1133   TestGlAbstraction&     gl = application.GetGlAbstraction();
1134
1135   {
1136     Property::Array urls1, urls2;
1137     CopyUrlsIntoArray(urls1);
1138     CopyUrlsIntoArray(urls2);
1139
1140     Property::Map animatedImageMap1;
1141     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
1142     animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
1143     animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1144     animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1145     animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1146
1147     Property::Map animatedImageMap2;
1148     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
1149     animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
1150     animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1151     animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
1152     animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1153
1154     VisualFactory factory              = VisualFactory::Get();
1155     Visual::Base  animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
1156
1157     tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
1158
1159     DummyControl        dummyControl1 = DummyControl::New(true);
1160     Impl::DummyControl& dummyImpl1    = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
1161     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
1162     dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1163     application.GetScene().Add(dummyControl1);
1164
1165     application.SendNotification();
1166     application.Render(16);
1167
1168     tet_infoline("Ready the requested image after the first visual is on stage");
1169     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1170     application.SendNotification();
1171     application.Render(16);
1172     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1173
1174     Visual::Base        animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1175     DummyControl        dummyControl2        = DummyControl::New(true);
1176     Impl::DummyControl& dummyImpl2           = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1177     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1178     dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1179     application.GetScene().Add(dummyControl2);
1180     application.SendNotification();
1181     application.Render(16);
1182
1183     tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1184     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1185     Texture    t1 = ts.GetTexture(0);
1186     DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1187
1188     tet_infoline("Test that on the first tick, 1 new image is requested");
1189     Test::EmitGlobalTimerSignal(); // Both visuals should tick
1190
1191     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1192     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1193
1194     ts         = dummyControl2.GetRendererAt(0).GetTextures();
1195     Texture t2 = ts.GetTexture(0);
1196     DALI_TEST_CHECK(t1 != t2);
1197
1198     dummyControl1.Unparent();
1199     dummyControl2.Unparent();
1200   }
1201   tet_infoline("Test that removing the visual from stage deletes all textures");
1202   application.SendNotification();
1203   application.Render(16);
1204   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1205
1206   END_TEST;
1207 }
1208
1209 int UtcDaliAnimatedImageVisualMultiImage04(void)
1210 {
1211   ToolkitTestApplication application;
1212   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1213   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1214   textureTrace.Enable(true);
1215
1216   tet_infoline("Test that if the cache size is the same as the number of urls, that once the cache is full, no new images are loaded");
1217
1218   Property::Array urls;
1219   CopyUrlsIntoArray(urls);
1220
1221   {
1222     Property::Map propertyMap;
1223     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1224     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1225     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1226     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1227     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1228
1229     VisualFactory factory = VisualFactory::Get();
1230     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1231
1232     tet_infoline("Expect that a batch of 7 textures has been requested.");
1233
1234     DummyControl        dummyControl = DummyControl::New(true);
1235     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1236     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1237
1238     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1239     application.GetScene().Add(dummyControl);
1240     application.SendNotification();
1241     application.Render(16);
1242
1243     tet_infoline("Wait for the first batch to complete");
1244     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1245
1246     tet_infoline("Test that a timer has been started");
1247     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1248
1249     application.SendNotification();
1250     application.Render(16);
1251
1252     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1253     tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1254     Test::EmitGlobalTimerSignal();
1255     application.SendNotification();
1256     application.Render(16);
1257
1258     // Expect the second batch has been requested
1259     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1260
1261     application.SendNotification();
1262     application.Render(16);
1263     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1264
1265     tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1266
1267     Test::EmitGlobalTimerSignal();
1268     application.SendNotification();
1269     application.Render(16);
1270     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1271     application.SendNotification();
1272     application.Render(16);
1273     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1274
1275     tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1276     Test::EmitGlobalTimerSignal();
1277     application.SendNotification();
1278     application.Render(16);
1279
1280     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1281     application.SendNotification();
1282     application.Render(16);
1283     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1284
1285     dummyControl.Unparent();
1286   }
1287
1288   tet_infoline("Test that removing the visual from stage deletes all textures");
1289   application.SendNotification();
1290   application.Render(16);
1291   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1292
1293   END_TEST;
1294 }
1295
1296 int UtcDaliAnimatedImageVisualMultiImage05(void)
1297 {
1298   ToolkitTestApplication application;
1299   TestGlAbstraction&     gl = application.GetGlAbstraction();
1300
1301   tet_infoline("Test that if the cache size is the same as the number of urls, that removing a partially loaded visual removes all textures");
1302
1303   Property::Array urls;
1304   CopyUrlsIntoArray(urls);
1305
1306   {
1307     Property::Map propertyMap;
1308     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1309     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1310     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1311     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1312     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1313
1314     VisualFactory factory = VisualFactory::Get();
1315     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1316
1317     tet_infoline("Expect that a batch of 4 textures has been requested.");
1318
1319     DummyControl        dummyControl = DummyControl::New(true);
1320     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1321     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1322
1323     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1324     application.GetScene().Add(dummyControl);
1325     application.SendNotification();
1326     application.Render(16);
1327
1328     tet_infoline("Wait for the first batch to complete");
1329     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1330
1331     tet_infoline("Test that a timer has been started");
1332     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1333
1334     application.SendNotification();
1335     application.Render(16);
1336
1337     tet_infoline("Test that a timer has been started");
1338     Test::EmitGlobalTimerSignal();
1339     application.SendNotification();
1340     application.Render(16);
1341
1342     dummyControl.Unparent();
1343   }
1344
1345   application.SendNotification();
1346   application.Render(16);
1347   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1348
1349   tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1350   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1351   application.SendNotification();
1352   application.Render(16);
1353   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1354
1355   END_TEST;
1356 }
1357
1358 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1359 {
1360   TestGlAbstraction& gl           = application.GetGlAbstraction();
1361   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1362
1363   textureTrace.Enable(true);
1364   application.GetScene().Add(dummyControl);
1365
1366   application.SendNotification();
1367   application.Render(16);
1368
1369   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1370
1371   application.SendNotification();
1372   application.Render();
1373
1374   tet_infoline("Test that a timer has been created");
1375   DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1376
1377   for(uint16_t i = 0; i < loopCount; i++)
1378   {
1379     for(uint16_t j = 0; j < frameCount; j++)
1380     {
1381       if(i == 0 && j == 0)
1382       {
1383         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1384       }
1385       tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1386       Test::EmitGlobalTimerSignal();
1387       application.SendNotification();
1388       application.Render(16);
1389
1390       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1391
1392       application.SendNotification();
1393       application.Render();
1394       DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1395       DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1396     }
1397     tet_printf("Test Loop %u \n\n", i + 1u);
1398   }
1399
1400   tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1401   Test::EmitGlobalTimerSignal();
1402   application.SendNotification();
1403   application.Render(16);
1404   DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1405
1406   dummyControl.Unparent();
1407 }
1408
1409 int UtcDaliAnimatedImageVisualLoopCount(void)
1410 {
1411   ToolkitTestApplication application;
1412
1413   tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1414
1415   {
1416     // request AnimatedImageVisual with a property map
1417     // Test with no (0) loop count
1418     VisualFactory factory             = VisualFactory::Get();
1419     Visual::Base  animatedImageVisual = factory.CreateVisual(
1420       Property::Map()
1421         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1422         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1423         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1424         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1425         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1426         .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1427
1428     DummyControl        dummyControl = DummyControl::New(true);
1429     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1430     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1431     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1432
1433     TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1434
1435     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1436     animatedImageVisual.Reset();
1437
1438     application.SendNotification();
1439     application.Render(16);
1440
1441     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1442     animatedImageVisual = factory.CreateVisual(
1443       Property::Map()
1444         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1445         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1446         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1447         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1448         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1449         .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1450
1451     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1452
1453     TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1454
1455     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1456     animatedImageVisual.Reset();
1457
1458     application.SendNotification();
1459     application.Render(16);
1460
1461     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1462     animatedImageVisual = factory.CreateVisual(
1463       Property::Map()
1464         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1465         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1466         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1467         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1468         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1469         .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1470
1471     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1472
1473     TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1474   }
1475   END_TEST;
1476 }
1477
1478 int UtcDaliAnimatedImageVisualPlayback(void)
1479 {
1480   ToolkitTestApplication application;
1481   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1482   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1483
1484   tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1485
1486   {
1487     // request AnimatedImageVisual with a property map
1488     // Test with forever (-1) loop count
1489     VisualFactory factory             = VisualFactory::Get();
1490     Visual::Base  animatedImageVisual = factory.CreateVisual(
1491       Property::Map()
1492         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1493         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1494         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1495         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1496         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1497         .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1498
1499     DummyControl        dummyControl = DummyControl::New(true);
1500     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1501     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1502     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1503
1504     textureTrace.Enable(true);
1505     application.GetScene().Add(dummyControl);
1506     application.SendNotification();
1507     application.Render(16);
1508
1509     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1510
1511     application.SendNotification();
1512     application.Render();
1513
1514     tet_infoline("Test that a timer has been created");
1515     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1516
1517     Test::EmitGlobalTimerSignal();
1518     application.SendNotification();
1519     application.Render(16);
1520
1521     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1522
1523     application.SendNotification();
1524     application.Render();
1525     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1526
1527     Property::Map attributes;
1528     tet_infoline("Test Pause action. Timer should stop after Pause action");
1529     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1530     Test::EmitGlobalTimerSignal();
1531     application.SendNotification();
1532     application.Render(16);
1533     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1534
1535     tet_infoline("Test Play action. Timer should Restart after Play action");
1536     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1537     Test::EmitGlobalTimerSignal();
1538     application.SendNotification();
1539     application.Render(16);
1540
1541     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1542
1543     application.SendNotification();
1544     application.Render();
1545     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1546
1547     tet_infoline("Test Stop action. Timer should stop after Stop action");
1548     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1549     Test::EmitGlobalTimerSignal();
1550     application.SendNotification();
1551     application.Render(16);
1552     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1553
1554     tet_infoline("Test Play action. Timer should Restart after Play action");
1555     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1556     Test::EmitGlobalTimerSignal();
1557     application.SendNotification();
1558     application.Render(16);
1559
1560     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1561
1562     application.SendNotification();
1563     application.Render();
1564     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1565
1566     dummyControl.Unparent();
1567   }
1568
1569   END_TEST;
1570 }