Merge "Apply EncodedImageBuffer with Atlas" into devel/master
[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 int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask(void)
529 {
530   ToolkitTestApplication application;
531   TestGlAbstraction&     gl = application.GetGlAbstraction();
532
533   {
534     Property::Map propertyMap;
535     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
536     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
537     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
538     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
539     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
540     propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
541     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
542     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f);
543     propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE);
544
545     VisualFactory factory = VisualFactory::Get();
546     Visual::Base  visual  = factory.CreateVisual(propertyMap);
547
548     Property::Map testMap;
549     visual.CreatePropertyMap(testMap);
550     DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
551
552     DummyControl        dummyControl = DummyControl::New(true);
553     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
554     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
555
556     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
557     application.GetScene().Add(dummyControl);
558
559     TraceCallStack& textureTrace = gl.GetTextureTrace();
560     textureTrace.Enable(true);
561
562     application.SendNotification();
563     application.Render(20);
564
565     // The first frame is loaded synchronously and load next batch with masking
566     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
567
568     application.SendNotification();
569     application.Render();
570
571     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
572     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
573
574     dummyControl.Unparent();
575   }
576   tet_infoline("Test that removing the visual from stage deletes all textures");
577   application.SendNotification();
578   application.Render(16);
579   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
580
581   END_TEST;
582 }
583
584 int UtcDaliAnimatedImageVisualJumpToAction(void)
585 {
586   ToolkitTestApplication application;
587   TestGlAbstraction&     gl = application.GetGlAbstraction();
588
589   Property::Array urls;
590   CopyUrlsIntoArray(urls);
591
592   {
593     Property::Map propertyMap;
594     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
595     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
596     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
597     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 12);
598     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
599
600     VisualFactory factory = VisualFactory::Get();
601     Visual::Base  visual  = factory.CreateVisual(propertyMap);
602
603     DummyControl        dummyControl = DummyControl::New(true);
604     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
605     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
606
607     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
608     application.GetScene().Add(dummyControl);
609     application.SendNotification();
610     application.Render(20);
611
612     tet_infoline("Ready the visual after the visual is on stage");
613     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
614
615     tet_infoline("Test that a timer has been started");
616     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
617
618     TraceCallStack& textureTrace = gl.GetTextureTrace();
619     textureTrace.Enable(true);
620
621     application.SendNotification();
622     application.Render(20);
623
624     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
625
626     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
627
628     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
629
630     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20);
631
632     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
633
634     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6);
635
636     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
637     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
638
639     dummyControl.Unparent();
640   }
641   tet_infoline("Test that removing the visual from stage deletes all textures");
642   application.SendNotification();
643   application.Render(16);
644   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
645
646   END_TEST;
647 }
648
649 int UtcDaliAnimatedImageVisualStopBehavior(void)
650 {
651   ToolkitTestApplication application;
652   TestGlAbstraction&     gl = application.GetGlAbstraction();
653
654   Property::Array urls;
655   CopyUrlsIntoArray(urls);
656
657   {
658     Property::Map propertyMap;
659     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
660     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
661     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
662     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
663     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
664     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
665
666     VisualFactory factory = VisualFactory::Get();
667     Visual::Base  visual  = factory.CreateVisual(propertyMap);
668
669     // Expect that a batch of 4 textures has been requested. These will be serially loaded
670     // below.
671
672     DummyControl        dummyControl = DummyControl::New(true);
673     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
674     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
675
676     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
677     application.GetScene().Add(dummyControl);
678     application.SendNotification();
679     application.Render(20);
680
681     tet_infoline("Ready the visual after the visual is on stage");
682     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
683
684     tet_infoline("Test that a timer has been started");
685     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
686
687     TraceCallStack& textureTrace = gl.GetTextureTrace();
688     textureTrace.Enable(true);
689
690     application.SendNotification();
691     application.Render(20);
692
693     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
694
695     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
696
697     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
698
699     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1);
700
701     // Expect the second batch has been requested
702     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
703
704     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION);
705
706     dummyControl.Unparent();
707   }
708   tet_infoline("Test that removing the visual from stage deletes all textures");
709   application.SendNotification();
710   application.Render(16);
711   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
712
713   END_TEST;
714 }
715
716 int UtcDaliAnimatedImageVisualStopBehavior02(void)
717 {
718   ToolkitTestApplication application;
719   TestGlAbstraction&     gl = application.GetGlAbstraction();
720
721   Property::Array urls;
722   CopyUrlsIntoArray(urls);
723
724   {
725     Property::Map propertyMap;
726     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
727     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
728     propertyMap.Insert(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
729     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
730     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2);
731     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
732
733     VisualFactory factory = VisualFactory::Get();
734     Visual::Base  visual  = factory.CreateVisual(propertyMap);
735
736     // Expect that a batch of 4 textures has been requested. These will be serially loaded
737     // below.
738
739     DummyControl        dummyControl = DummyControl::New(true);
740     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
741     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
742
743     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
744     application.GetScene().Add(dummyControl);
745
746     tet_infoline("Ready the visual after the visual is on stage");
747     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
748
749     TraceCallStack& textureTrace = gl.GetTextureTrace();
750     textureTrace.Enable(true);
751
752     application.SendNotification();
753     application.Render(20);
754
755     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
756
757     Test::EmitGlobalTimerSignal();
758
759     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
760
761     application.SendNotification();
762     application.Render(20);
763
764     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
765
766     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map());
767
768     tet_infoline("Ready the visual after the visual is on stage");
769     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
770
771     application.SendNotification();
772     application.Render(20);
773
774     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
775
776     dummyControl.Unparent();
777   }
778   tet_infoline("Test that removing the visual from stage deletes all textures");
779   application.SendNotification();
780   application.Render(16);
781   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
782
783   END_TEST;
784 }
785
786 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
787 {
788   ToolkitTestApplication application;
789   TestGlAbstraction&     gl = application.GetGlAbstraction();
790
791   tet_infoline("Set cache size same as GIF frame, and try to load same image at another ImageView");
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     // Batch 2 frames. Now frame 0, 1 cached.
819     application.SendNotification();
820     application.Render(20);
821
822     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
823
824     tet_infoline("Test that a timer has been started");
825
826     TraceCallStack& textureTrace = gl.GetTextureTrace();
827     textureTrace.Enable(true);
828
829     Test::EmitGlobalTimerSignal();
830
831     application.SendNotification();
832     application.Render();
833
834     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
835
836     // 0 frame removed. and after, batch 2 frames. Now frame 1, 2, 3 cached.
837     application.SendNotification();
838     application.Render(20);
839
840     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
841
842     Visual::Base        visual2       = factory.CreateVisual(propertyMap);
843     DummyControl        dummyControl2 = DummyControl::New(true);
844     Impl::DummyControl& dummyImpl2    = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
845     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
846     application.GetScene().Add(dummyControl2);
847
848     tet_infoline("Add new view with same url");
849
850     application.SendNotification();
851     application.Render();
852
853     // Note that we only re-load 0 frame.
854     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
855
856     tet_infoline("Test that we don't try to re-load new image cause it cached");
857     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
858
859     // Batch 2 frames. Now visual frame 1, 2, 3 cached and visual2 frame 0, 1 cached.
860     application.SendNotification();
861     application.Render(20);
862
863     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
864
865     textureTrace.Reset();
866
867     tet_infoline("Load some many frames");
868
869     const int repeatCount = 10;
870     for(int repeat = 0; repeat < repeatCount; ++repeat)
871     {
872       Test::EmitGlobalTimerSignal();
873       application.SendNotification();
874       application.Render(2000);
875     }
876
877     DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // A new texture should NOT be generated.
878     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION);
879
880     textureTrace.Reset();
881
882     dummyControl.Unparent();
883     dummyControl2.Unparent();
884   }
885   tet_infoline("Test that removing the visual from stage deletes all textures");
886   application.SendNotification();
887   application.Render(20);
888   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
889
890   END_TEST;
891 }
892
893 int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void)
894 {
895   ToolkitTestApplication application;
896   TestGlAbstraction&     gl = application.GetGlAbstraction();
897
898   {
899     Property::Map propertyMap;
900     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE);
901     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME);
902     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
903     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4);
904     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20);
905     propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
906
907     VisualFactory factory = VisualFactory::Get();
908     Visual::Base  visual  = factory.CreateVisual(propertyMap);
909
910     DummyControl        dummyControl = DummyControl::New(true);
911     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
912     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
913
914     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
915     application.GetScene().Add(dummyControl);
916
917     application.SendNotification();
918     application.Render();
919
920     // load two frame(batch size), load mask image, and request two masking
921     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
922
923     application.SendNotification();
924     application.Render(20);
925
926     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 2, TEST_LOCATION);
927
928     dummyControl.Unparent();
929   }
930   tet_infoline("Test that removing the visual from stage deletes all textures");
931   application.SendNotification();
932   application.Render(20);
933   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
934
935   END_TEST;
936 }
937
938 int UtcDaliAnimatedImageVisualMultiImage01(void)
939 {
940   ToolkitTestApplication application;
941   TestGlAbstraction&     gl = application.GetGlAbstraction();
942
943   Property::Array urls;
944   CopyUrlsIntoArray(urls);
945
946   {
947     Property::Map propertyMap;
948     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
949     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
950     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
951     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 8);
952     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
953
954     VisualFactory factory = VisualFactory::Get();
955     Visual::Base  visual  = factory.CreateVisual(propertyMap);
956
957     // Expect that a batch of 4 textures has been requested. These will be serially loaded
958     // below.
959
960     DummyControl        dummyControl = DummyControl::New(true);
961     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
962     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
963
964     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
965     application.GetScene().Add(dummyControl);
966     application.SendNotification();
967     application.Render(16);
968
969     tet_infoline("Ready the visual after the visual is on stage");
970     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
971
972     tet_infoline("Test that a timer has been started");
973     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
974
975     TraceCallStack& textureTrace = gl.GetTextureTrace();
976     textureTrace.Enable(true);
977
978     application.SendNotification();
979     application.Render(16);
980
981     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION);
982     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
983
984     tet_infoline("Test that after 1 tick, and file loads completed, that we have 7 textures");
985     Test::EmitGlobalTimerSignal();
986
987     // Expect the second batch has been requested
988     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
989
990     application.SendNotification();
991     application.Render(16);
992     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
993
994     tet_infoline("Test that after 2 ticks that we have 6 textures");
995
996     Test::EmitGlobalTimerSignal();
997     application.SendNotification();
998     application.Render(16);
999     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 6, TEST_LOCATION);
1000
1001     tet_infoline("And that at least 2 textures were requested");
1002     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1003     application.SendNotification();
1004     application.Render(16);
1005     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1006
1007     tet_infoline("Test that after 3rd tick that we have 7 textures and 1 request");
1008     Test::EmitGlobalTimerSignal();
1009     application.SendNotification();
1010     application.Render(16);
1011     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1012
1013     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1014     application.SendNotification();
1015     application.Render(16);
1016     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 8, TEST_LOCATION);
1017
1018     dummyControl.Unparent();
1019   }
1020   tet_infoline("Test that removing the visual from stage deletes all textures");
1021   application.SendNotification();
1022   application.Render(16);
1023   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1024
1025   END_TEST;
1026 }
1027
1028 int UtcDaliAnimatedImageVisualMultiImage02(void)
1029 {
1030   ToolkitTestApplication application;
1031   TestGlAbstraction&     gl = application.GetGlAbstraction();
1032
1033   tet_infoline("Test that the animated visual has different batch and cache size.");
1034
1035   {
1036     Property::Array urls;
1037     CopyUrlsIntoArray(urls);
1038
1039     Property::Map propertyMap;
1040     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1041     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1042     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 0);
1043     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 0);
1044     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1045
1046     VisualFactory factory = VisualFactory::Get();
1047     Visual::Base  visual  = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1048
1049     // Check the batch size and cache size need to have minimum 2.
1050     Property::Map resultMap;
1051     visual.CreatePropertyMap(resultMap);
1052     Property::Value* value = resultMap.Find(ImageVisual::Property::BATCH_SIZE, "batchSize");
1053     DALI_TEST_CHECK(value);
1054     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1055     value = resultMap.Find(ImageVisual::Property::CACHE_SIZE, "cacheSize");
1056     DALI_TEST_CHECK(value);
1057     DALI_TEST_EQUALS(value->Get<int>(), 2, TEST_LOCATION);
1058     visual.Reset();
1059
1060     // Batch size is 2 and cache size is 3
1061     propertyMap.Clear();
1062     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1063     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1064     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1065     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1066     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1067
1068     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1069
1070     // Expect that each image is loaded each tick
1071     DummyControl        dummyControl = DummyControl::New(true);
1072     Impl::DummyControl& dummyImpl1   = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1073     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1074     visual.Reset();
1075
1076     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1077     application.GetScene().Add(dummyControl);
1078     application.SendNotification();
1079     application.Render(16);
1080
1081     tet_infoline("Ready the visual after the visual is on window");
1082     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1083     application.SendNotification();
1084     application.Render(16); //glGenTextures 1 and 2
1085     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
1086
1087     tet_infoline("Test that each tick, a new image is requested");
1088     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1089     application.SendNotification();
1090     application.Render(16);
1091     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1092     application.SendNotification();
1093     application.Render(16); //glGenTextures 3
1094     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1095
1096     tet_infoline("Test that each tick, a new image is requested");
1097     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1098     application.SendNotification();
1099     application.Render(16);
1100     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1101     application.SendNotification();
1102     application.Render(16); //glGenTextures 4
1103     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1104
1105     dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1106     dummyControl.Unparent();
1107
1108     // Batch size is 9 and cache size is 4
1109     propertyMap.Clear();
1110     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1111     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1112     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1113     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 7);
1114     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1115
1116     visual = factory.CreateVisual(propertyMap); // TexMgr::Request load tId:0
1117
1118     // Expect that each image is loaded each tick
1119     dummyControl                   = DummyControl::New(true);
1120     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1121     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1122     visual.Reset();
1123
1124     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1125     application.GetScene().Add(dummyControl);
1126     application.SendNotification();
1127     application.Render(16);
1128
1129     tet_infoline("Ready the visual after the visual is on window");
1130     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1131     application.SendNotification();
1132     application.Render(16); //glGenTextures 1, 2, and 3
1133     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1134
1135     tet_infoline("Test that each tick, a new image is requested");
1136     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
1137     application.SendNotification();
1138     application.Render(16);
1139     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1140     application.SendNotification();
1141     application.Render(16); //glGenTextures 4, 5, and 6
1142     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 5, TEST_LOCATION);
1143
1144     tet_infoline("Test that each tick, a new image is requested");
1145     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
1146     application.SendNotification();
1147     application.Render(16);
1148     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1149     application.SendNotification();
1150     application.Render(16); //glGenTextures 7, 1, and 2
1151     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1152
1153     tet_infoline("Test that each tick, a new image is requested");
1154     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
1155     application.SendNotification();
1156     application.Render(16);
1157     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1158     application.SendNotification();
1159     application.Render(16); //glGenTextures 3
1160     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 7, TEST_LOCATION);
1161
1162     dummyControl.Unparent();
1163   }
1164   tet_infoline("Test that removing the visual from window deletes all textures");
1165   application.SendNotification();
1166   application.Render(16);
1167   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1168
1169   END_TEST;
1170 }
1171
1172 int UtcDaliAnimatedImageVisualMultiImage03(void)
1173 {
1174   ToolkitTestApplication application;
1175   TestGlAbstraction&     gl = application.GetGlAbstraction();
1176
1177   {
1178     Property::Array urls1, urls2;
1179     CopyUrlsIntoArray(urls1);
1180     CopyUrlsIntoArray(urls2);
1181
1182     Property::Map animatedImageMap1;
1183     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE);
1184     animatedImageMap1.Insert(ImageVisual::Property::URL, Property::Value(urls1));
1185     animatedImageMap1.Insert(ImageVisual::Property::BATCH_SIZE, 3);
1186     animatedImageMap1.Insert(ImageVisual::Property::CACHE_SIZE, 3);
1187     animatedImageMap1.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1188
1189     Property::Map animatedImageMap2;
1190     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE);
1191     animatedImageMap2.Insert(ImageVisual::Property::URL, Property::Value(urls2));
1192     animatedImageMap2.Insert(ImageVisual::Property::BATCH_SIZE, 2);
1193     animatedImageMap2.Insert(ImageVisual::Property::CACHE_SIZE, 2);
1194     animatedImageMap2.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1195
1196     VisualFactory factory              = VisualFactory::Get();
1197     Visual::Base  animatedImageVisual1 = factory.CreateVisual(animatedImageMap1);
1198
1199     tet_infoline("Create two image views with the same URLs, offset by 1 frame.");
1200
1201     DummyControl        dummyControl1 = DummyControl::New(true);
1202     Impl::DummyControl& dummyImpl1    = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
1203     dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual1);
1204     dummyControl1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1205     application.GetScene().Add(dummyControl1);
1206
1207     application.SendNotification();
1208     application.Render(16);
1209
1210     tet_infoline("Ready the requested image after the first visual is on stage");
1211     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1212     application.SendNotification();
1213     application.Render(16);
1214     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1215
1216     Visual::Base        animatedImageVisual2 = factory.CreateVisual(animatedImageMap2);
1217     DummyControl        dummyControl2        = DummyControl::New(true);
1218     Impl::DummyControl& dummyImpl2           = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
1219     dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual2);
1220     dummyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1221     application.GetScene().Add(dummyControl2);
1222     application.SendNotification();
1223     application.Render(16);
1224
1225     tet_infoline("The texture cache should be holding the requested images; check that the renderer has a texture");
1226     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
1227     Texture    t1 = ts.GetTexture(0);
1228     DALI_TEST_EQUALS(ts.GetTextureCount(), 1, TEST_LOCATION);
1229
1230     tet_infoline("Test that on the first tick, 1 new image is requested");
1231     Test::EmitGlobalTimerSignal(); // Both visuals should tick
1232
1233     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1234     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
1235
1236     ts         = dummyControl2.GetRendererAt(0).GetTextures();
1237     Texture t2 = ts.GetTexture(0);
1238     DALI_TEST_CHECK(t1 != t2);
1239
1240     dummyControl1.Unparent();
1241     dummyControl2.Unparent();
1242   }
1243   tet_infoline("Test that removing the visual from stage deletes all textures");
1244   application.SendNotification();
1245   application.Render(16);
1246   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1247
1248   END_TEST;
1249 }
1250
1251 int UtcDaliAnimatedImageVisualMultiImage04(void)
1252 {
1253   ToolkitTestApplication application;
1254   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1255   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1256   textureTrace.Enable(true);
1257
1258   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");
1259
1260   Property::Array urls;
1261   CopyUrlsIntoArray(urls);
1262
1263   {
1264     Property::Map propertyMap;
1265     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1266     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1267     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 6);
1268     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1269     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1270
1271     VisualFactory factory = VisualFactory::Get();
1272     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1273
1274     tet_infoline("Expect that a batch of 7 textures has been requested.");
1275
1276     DummyControl        dummyControl = DummyControl::New(true);
1277     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1278     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1279
1280     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1281     application.GetScene().Add(dummyControl);
1282     application.SendNotification();
1283     application.Render(16);
1284
1285     tet_infoline("Wait for the first batch to complete");
1286     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION);
1287
1288     tet_infoline("Test that a timer has been started");
1289     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1290
1291     application.SendNotification();
1292     application.Render(16);
1293
1294     DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 6, TEST_LOCATION);
1295     tet_infoline("Test that after 1 tick, and 5 file loads completed, that we have 11 textures");
1296     Test::EmitGlobalTimerSignal();
1297     application.SendNotification();
1298     application.Render(16);
1299
1300     // Expect the second batch has been requested
1301     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5), true, TEST_LOCATION);
1302
1303     application.SendNotification();
1304     application.Render(16);
1305     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1306
1307     tet_infoline("Test that after 2 ticks that we have 11 textures and no requests");
1308
1309     Test::EmitGlobalTimerSignal();
1310     application.SendNotification();
1311     application.Render(16);
1312     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1313     application.SendNotification();
1314     application.Render(16);
1315     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1316
1317     tet_infoline("Test that after 3rd tick that we have 11 textures and no requests");
1318     Test::EmitGlobalTimerSignal();
1319     application.SendNotification();
1320     application.Render(16);
1321
1322     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 5), false, TEST_LOCATION);
1323     application.SendNotification();
1324     application.Render(16);
1325     DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 11, TEST_LOCATION);
1326
1327     dummyControl.Unparent();
1328   }
1329
1330   tet_infoline("Test that removing the visual from stage deletes all textures");
1331   application.SendNotification();
1332   application.Render(16);
1333   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1334
1335   END_TEST;
1336 }
1337
1338 int UtcDaliAnimatedImageVisualMultiImage05(void)
1339 {
1340   ToolkitTestApplication application;
1341   TestGlAbstraction&     gl = application.GetGlAbstraction();
1342
1343   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");
1344
1345   Property::Array urls;
1346   CopyUrlsIntoArray(urls);
1347
1348   {
1349     Property::Map propertyMap;
1350     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1351     propertyMap.Insert(ImageVisual::Property::URL, Property::Value(urls));
1352     propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 4);
1353     propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 11);
1354     propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 100);
1355
1356     VisualFactory factory = VisualFactory::Get();
1357     Visual::Base  visual  = factory.CreateVisual(propertyMap);
1358
1359     tet_infoline("Expect that a batch of 4 textures has been requested.");
1360
1361     DummyControl        dummyControl = DummyControl::New(true);
1362     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1363     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1364
1365     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1366     application.GetScene().Add(dummyControl);
1367     application.SendNotification();
1368     application.Render(16);
1369
1370     tet_infoline("Wait for the first batch to complete");
1371     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1372
1373     tet_infoline("Test that a timer has been started");
1374     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1375
1376     application.SendNotification();
1377     application.Render(16);
1378
1379     tet_infoline("Test that a timer has been started");
1380     Test::EmitGlobalTimerSignal();
1381     application.SendNotification();
1382     application.Render(16);
1383
1384     dummyControl.Unparent();
1385   }
1386
1387   application.SendNotification();
1388   application.Render(16);
1389   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1390
1391   tet_infoline("Test that pending batch of image loads are cancelled instead of uploaded");
1392   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
1393   application.SendNotification();
1394   application.Render(16);
1395   DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION);
1396
1397   END_TEST;
1398 }
1399
1400 void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location)
1401 {
1402   TestGlAbstraction& gl           = application.GetGlAbstraction();
1403   TraceCallStack&    textureTrace = gl.GetTextureTrace();
1404
1405   textureTrace.Enable(true);
1406   application.GetScene().Add(dummyControl);
1407
1408   application.SendNotification();
1409   application.Render(16);
1410
1411   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_INNER_LOCATION(location));
1412
1413   application.SendNotification();
1414   application.Render();
1415
1416   tet_infoline("Test that a timer has been created");
1417   DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_INNER_LOCATION(location));
1418
1419   for(uint16_t i = 0; i < loopCount; i++)
1420   {
1421     for(uint16_t j = 0; j < frameCount; j++)
1422     {
1423       if(i == 0 && j == 0)
1424       {
1425         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1426       }
1427       tet_printf("Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u);
1428       Test::EmitGlobalTimerSignal();
1429       application.SendNotification();
1430       application.Render(16);
1431
1432       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_INNER_LOCATION(location));
1433
1434       application.SendNotification();
1435       application.Render();
1436       DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION(location));
1437       DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_INNER_LOCATION(location));
1438     }
1439     tet_printf("Test Loop %u \n\n", i + 1u);
1440   }
1441
1442   tet_printf("Test that after %u loops, and we have no frame. Timer should stop \n", loopCount);
1443   Test::EmitGlobalTimerSignal();
1444   application.SendNotification();
1445   application.Render(16);
1446   DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_INNER_LOCATION(location));
1447
1448   dummyControl.Unparent();
1449 }
1450
1451 int UtcDaliAnimatedImageVisualLoopCount(void)
1452 {
1453   ToolkitTestApplication application;
1454
1455   tet_infoline("UtcDaliAnimatedImageVisualLoopCount");
1456
1457   {
1458     // request AnimatedImageVisual with a property map
1459     // Test with no (0) loop count
1460     VisualFactory factory             = VisualFactory::Get();
1461     Visual::Base  animatedImageVisual = factory.CreateVisual(
1462       Property::Map()
1463         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1464         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1465         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1466         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1467         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1468         .Add(DevelImageVisual::Property::LOOP_COUNT, 0));
1469
1470     DummyControl        dummyControl = DummyControl::New(true);
1471     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1472     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1473     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1474
1475     TestLoopCount(application, dummyControl, 4, 0, TEST_LOCATION);
1476
1477     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1478     animatedImageVisual.Reset();
1479
1480     application.SendNotification();
1481     application.Render(16);
1482
1483     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1484     animatedImageVisual = factory.CreateVisual(
1485       Property::Map()
1486         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1487         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1488         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1489         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1490         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1491         .Add(DevelImageVisual::Property::LOOP_COUNT, 1));
1492
1493     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1494
1495     TestLoopCount(application, dummyControl, 4, 1, TEST_LOCATION);
1496
1497     dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1498     animatedImageVisual.Reset();
1499
1500     application.SendNotification();
1501     application.Render(16);
1502
1503     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1504     animatedImageVisual = factory.CreateVisual(
1505       Property::Map()
1506         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1507         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1508         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1509         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1510         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1511         .Add(DevelImageVisual::Property::LOOP_COUNT, 100));
1512
1513     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1514
1515     TestLoopCount(application, dummyControl, 4, 100, TEST_LOCATION);
1516   }
1517   END_TEST;
1518 }
1519
1520 int UtcDaliAnimatedImageVisualPlayback(void)
1521 {
1522   ToolkitTestApplication application;
1523   TestGlAbstraction&     gl           = application.GetGlAbstraction();
1524   TraceCallStack&        textureTrace = gl.GetTextureTrace();
1525
1526   tet_infoline("UtcDaliAnimatedImageVisualPlayback");
1527
1528   {
1529     // request AnimatedImageVisual with a property map
1530     // Test with forever (-1) loop count
1531     VisualFactory factory             = VisualFactory::Get();
1532     Visual::Base  animatedImageVisual = factory.CreateVisual(
1533       Property::Map()
1534         .Add(Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE)
1535         .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
1536         .Add(ImageVisual::Property::PIXEL_AREA, Vector4())
1537         .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT)
1538         .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT)
1539         .Add(DevelImageVisual::Property::LOOP_COUNT, -1));
1540
1541     DummyControl        dummyControl = DummyControl::New(true);
1542     Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1543     dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, animatedImageVisual);
1544     dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1545
1546     textureTrace.Enable(true);
1547     application.GetScene().Add(dummyControl);
1548     application.SendNotification();
1549     application.Render(16);
1550
1551     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1552
1553     application.SendNotification();
1554     application.Render();
1555
1556     tet_infoline("Test that a timer has been created");
1557     DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION);
1558
1559     Test::EmitGlobalTimerSignal();
1560     application.SendNotification();
1561     application.Render(16);
1562
1563     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1564
1565     application.SendNotification();
1566     application.Render();
1567     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1568
1569     Property::Map attributes;
1570     tet_infoline("Test Pause action. Timer should stop after Pause action");
1571     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes);
1572     Test::EmitGlobalTimerSignal();
1573     application.SendNotification();
1574     application.Render(16);
1575     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1576
1577     tet_infoline("Test Play action. Timer should Restart after Play action");
1578     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1579     Test::EmitGlobalTimerSignal();
1580     application.SendNotification();
1581     application.Render(16);
1582
1583     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1584
1585     application.SendNotification();
1586     application.Render();
1587     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1588
1589     tet_infoline("Test Stop action. Timer should stop after Stop action");
1590     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes);
1591     Test::EmitGlobalTimerSignal();
1592     application.SendNotification();
1593     application.Render(16);
1594     DALI_TEST_EQUALS(Test::AreTimersRunning(), false, TEST_LOCATION);
1595
1596     tet_infoline("Test Play action. Timer should Restart after Play action");
1597     DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
1598     Test::EmitGlobalTimerSignal();
1599     application.SendNotification();
1600     application.Render(16);
1601
1602     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1603
1604     application.SendNotification();
1605     application.Render();
1606     DALI_TEST_EQUALS(Test::AreTimersRunning(), true, TEST_LOCATION);
1607
1608     dummyControl.Unparent();
1609   }
1610
1611   END_TEST;
1612 }