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