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