RenderSurface interface change in automated test utils
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedImageVisual.cpp
1
2 /*
3  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
28 #include "dummy-control.h"
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 void dali_animated_image_visual_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void dali_animated_image_visual_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/application-icon-%02d.png";
46 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
47 }
48
49
50 void CopyUrlsIntoArray( Property::Array& urls, int startIndex=0 )
51 {
52   for( int i=20+startIndex;i<=30;++i)
53   {
54     char* url;
55     if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
56     {
57       Property::Value value(url);
58       urls.Add(value);
59       free(url);
60     }
61   }
62 }
63
64 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
65 {
66   ToolkitTestApplication application;
67   tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
68
69   // request AnimatedImageVisual with a property map
70   VisualFactory factory = VisualFactory::Get();
71   Visual::Base animatedImageVisual = factory.CreateVisual(
72     Property::Map()
73     .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
74     .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
75     .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
76     .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
77     .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT ));
78
79   Property::Map resultMap;
80   animatedImageVisual.CreatePropertyMap( resultMap );
81   // check the property values from the returned map from a visual
82   Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE,  Property::INTEGER );
83   DALI_TEST_CHECK( value );
84   DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
85
86   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
87   DALI_TEST_CHECK( value );
88   DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
89
90   // request AnimatedImageVisual with an URL
91   Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
92   resultMap.Clear();
93   animatedImageVisual2.CreatePropertyMap( resultMap );
94   // check the property values from the returned map from a visual
95   value = resultMap.Find( Toolkit::Visual::Property::TYPE,  Property::INTEGER );
96   DALI_TEST_CHECK( value );
97   DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
98
99   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
100   DALI_TEST_CHECK( value );
101   DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
102
103   END_TEST;
104 }
105
106
107 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
108 {
109   ToolkitTestApplication application;
110   tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image" );
111
112   // request AnimatedImageVisual with a property map
113   VisualFactory factory = VisualFactory::Get();
114   Property::Array urls;
115   CopyUrlsIntoArray( urls );
116
117   Visual::Base animatedImageVisual = factory.CreateVisual(
118     Property::Map()
119     .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
120     .Add( "url", urls )
121     .Add( "batchSize", 4 )
122     .Add( "cacheSize", 8 )
123     .Add( "loopCount", 10 )
124     .Add( "frameDelay", 200 )
125     .Add( "pixelArea", Vector4() )
126     .Add( "wrapModeU", WrapMode::REPEAT )
127     .Add( "wrapModeV", WrapMode::DEFAULT ));
128
129   Property::Map resultMap;
130   animatedImageVisual.CreatePropertyMap( resultMap );
131   // check the property values from the returned map from a visual
132   Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE,  Property::INTEGER );
133   DALI_TEST_CHECK( value );
134   DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
135
136   value = resultMap.Find( ImageVisual::Property::URL, "url" );
137   DALI_TEST_CHECK( value );
138   Property::Array* resultUrls = value->GetArray();
139   DALI_TEST_CHECK( resultUrls );
140   DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
141
142   value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
143   DALI_TEST_CHECK( value );
144   DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
145
146   value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
147   DALI_TEST_CHECK( value );
148   DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
149
150   value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
151   DALI_TEST_CHECK( value );
152   DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
153
154   value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
155   DALI_TEST_CHECK( value );
156   DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
157
158   END_TEST;
159 }
160
161
162
163
164 int UtcDaliAnimatedImageVisualMultiImage01(void)
165 {
166   ToolkitTestApplication application;
167   TestGlAbstraction& gl = application.GetGlAbstraction();
168
169   Property::Array urls;
170   CopyUrlsIntoArray( urls );
171
172   {
173     Property::Map propertyMap;
174     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
175     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
176     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
177     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
178     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
179
180     VisualFactory factory = VisualFactory::Get();
181     Visual::Base visual = factory.CreateVisual( propertyMap );
182
183     // Expect that a batch of 4 textures has been requested. These will be serially loaded
184     // below.
185
186     DummyControl dummyControl = DummyControl::New(true);
187     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
188     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
189
190     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
191     Stage::GetCurrent().Add( dummyControl );
192     application.SendNotification();
193     application.Render(16);
194
195     tet_infoline( "Ready the visual after the visual is on stage" );
196     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
197
198     tet_infoline( "Test that a timer has been started" );
199     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
200
201     TraceCallStack& textureTrace = gl.GetTextureTrace();
202     textureTrace.Enable(true);
203
204     application.SendNotification();
205     application.Render(16);
206
207     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
208     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
209
210     tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
211     Test::EmitGlobalTimerSignal();
212
213     // Expect the second batch has been requested
214     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
215
216     application.SendNotification();
217     application.Render(16);
218     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
219
220
221     tet_infoline( "Test that after 2 ticks that we have 6 textures" );
222
223     Test::EmitGlobalTimerSignal();
224     application.SendNotification();
225     application.Render(16);
226     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
227
228     tet_infoline("And that at least 2 textures were requested");
229     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
230     application.SendNotification();
231     application.Render(16);
232     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
233
234
235     tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
236     Test::EmitGlobalTimerSignal();
237     application.SendNotification();
238     application.Render(16);
239     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
240
241     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
242     application.SendNotification();
243     application.Render(16);
244     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
245
246     dummyControl.Unparent();
247   }
248   tet_infoline("Test that removing the visual from stage deletes all textures");
249   application.SendNotification();
250   application.Render(16);
251   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
252
253   END_TEST;
254 }
255
256 int UtcDaliAnimatedImageVisualMultiImage02(void)
257 {
258   ToolkitTestApplication application;
259   TestGlAbstraction& gl = application.GetGlAbstraction();
260
261   tet_infoline( "Test that the animated visual still works with zero sized cache" );
262
263   {
264     Property::Array urls;
265     CopyUrlsIntoArray( urls );
266
267     Property::Map propertyMap;
268     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
269     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
270     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
271     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
272     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
273
274     VisualFactory factory = VisualFactory::Get();
275     Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
276
277     // Expect that each image is loaded each tick
278
279     DummyControl dummyControl = DummyControl::New(true);
280     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
281     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
282
283     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
284     Stage::GetCurrent().Add( dummyControl );
285     application.SendNotification();
286     application.Render(16);
287
288     tet_infoline( "Ready the visual after the visual is on stage" );
289     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
290     application.SendNotification();
291     application.Render(16);//glGenTextures 1
292     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
293
294     tet_infoline( "Test that each tick, a new image is requested" );
295     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
296     application.SendNotification();
297     application.Render(16);
298     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
299     application.SendNotification();
300     application.Render(16);//glGenTextures 2
301     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
302
303     tet_infoline( "Test that each tick, a new image is requested" );
304     Test::EmitGlobalTimerSignal(); // Internal::~TextureSet()
305     application.SendNotification();
306     application.Render(16);//glDeleteTextures 2
307     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
308     application.SendNotification();
309     application.Render(16);//glGenTextures 3
310     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
311
312     tet_infoline( "Test that each tick, a new image is requested" );
313     Test::EmitGlobalTimerSignal();
314     application.SendNotification();
315     application.Render(16);//glDeleteTextures 3
316     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
317     application.SendNotification();
318     application.Render(16);//Gen4
319     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
320     dummyControl.Unparent();
321   }
322   tet_infoline("Test that removing the visual from stage deletes all textures");
323   application.SendNotification();
324   application.Render(16);
325   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
326
327   END_TEST;
328 }
329
330 int UtcDaliAnimatedImageVisualMultiImage03(void)
331 {
332   ToolkitTestApplication application;
333   TestGlAbstraction& gl = application.GetGlAbstraction();
334
335   {
336     Property::Array urls1, urls2;
337     CopyUrlsIntoArray( urls1 );
338     CopyUrlsIntoArray( urls2 );
339
340     Property::Map animatedImageMap1;
341     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
342     animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
343     animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
344     animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
345     animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
346
347     Property::Map animatedImageMap2;
348     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
349     animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
350     animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
351     animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
352     animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
353
354     VisualFactory factory = VisualFactory::Get();
355     Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
356
357     tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
358
359     DummyControl dummyControl1 = DummyControl::New(true);
360     Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
361     dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
362     dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
363     Stage::GetCurrent().Add( dummyControl1 );
364
365     application.SendNotification();
366     application.Render(16);
367
368     tet_infoline( "Ready the requested image after the first visual is on stage" );
369     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
370     application.SendNotification();
371     application.Render(16);
372     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
373
374     Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
375     DummyControl dummyControl2 = DummyControl::New(true);
376     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
377     dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
378     dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
379     Stage::GetCurrent().Add( dummyControl2 );
380     application.SendNotification();
381     application.Render(16);
382
383     tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
384     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
385     Texture t1 = ts.GetTexture( 0 );
386     DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
387
388     tet_infoline( "Test that on the first tick, 1 new image is requested" );
389     Test::EmitGlobalTimerSignal(); // Both visuals should tick
390
391     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
392     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
393
394     ts = dummyControl2.GetRendererAt(0).GetTextures();
395     Texture t2 = ts.GetTexture( 0 );
396     DALI_TEST_CHECK( t1 != t2 );
397
398     dummyControl1.Unparent();
399     dummyControl2.Unparent();
400   }
401   tet_infoline("Test that removing the visual from stage deletes all textures");
402   application.SendNotification();
403   application.Render(16);
404   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
405
406   END_TEST;
407 }
408
409
410 int UtcDaliAnimatedImageVisualMultiImage04(void)
411 {
412   ToolkitTestApplication application;
413   TestGlAbstraction& gl = application.GetGlAbstraction();
414   TraceCallStack& textureTrace = gl.GetTextureTrace();
415   textureTrace.Enable(true);
416
417   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" );
418
419   Property::Array urls;
420   CopyUrlsIntoArray( urls );
421
422   {
423     Property::Map propertyMap;
424     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
425     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
426     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
427     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
428     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
429
430     VisualFactory factory = VisualFactory::Get();
431     Visual::Base visual = factory.CreateVisual( propertyMap );
432
433     tet_infoline( "Expect that a batch of 7 textures has been requested." );
434
435     DummyControl dummyControl = DummyControl::New(true);
436     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
437     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
438
439     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
440     Stage::GetCurrent().Add( dummyControl );
441     application.SendNotification();
442     application.Render(16);
443
444     tet_infoline( "Wait for the first batch to complete" );
445     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
446
447     tet_infoline( "Test that a timer has been started" );
448     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
449
450     application.SendNotification();
451     application.Render(16);
452
453     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
454     tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
455     Test::EmitGlobalTimerSignal();
456     application.SendNotification();
457     application.Render(16);
458
459     // Expect the second batch has been requested
460     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
461
462     application.SendNotification();
463     application.Render(16);
464     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
465
466     tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
467
468     Test::EmitGlobalTimerSignal();
469     application.SendNotification();
470     application.Render(16);
471     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
472     application.SendNotification();
473     application.Render(16);
474     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
475
476     tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
477     Test::EmitGlobalTimerSignal();
478     application.SendNotification();
479     application.Render(16);
480
481     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
482     application.SendNotification();
483     application.Render(16);
484     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
485
486     dummyControl.Unparent();
487   }
488
489   tet_infoline("Test that removing the visual from stage deletes all textures");
490   application.SendNotification();
491   application.Render(16);
492   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
493
494   END_TEST;
495 }
496
497
498 int UtcDaliAnimatedImageVisualMultiImage05(void)
499 {
500   ToolkitTestApplication application;
501   TestGlAbstraction& gl = application.GetGlAbstraction();
502
503   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" );
504
505   Property::Array urls;
506   CopyUrlsIntoArray( urls );
507
508   {
509     Property::Map propertyMap;
510     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
511     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
512     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
513     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
514     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
515
516     VisualFactory factory = VisualFactory::Get();
517     Visual::Base visual = factory.CreateVisual( propertyMap );
518
519     tet_infoline( "Expect that a batch of 4 textures has been requested." );
520
521     DummyControl dummyControl = DummyControl::New(true);
522     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
523     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
524
525     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
526     Stage::GetCurrent().Add( dummyControl );
527     application.SendNotification();
528     application.Render(16);
529
530     tet_infoline( "Wait for the first batch to complete" );
531     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
532
533     tet_infoline( "Test that a timer has been started" );
534     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
535
536     application.SendNotification();
537     application.Render(16);
538
539     tet_infoline( "Test that a timer has been started" );
540     Test::EmitGlobalTimerSignal();
541     application.SendNotification();
542     application.Render(16);
543
544     dummyControl.Unparent();
545   }
546
547   application.SendNotification();
548   application.Render(16);
549   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
550
551   tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
552   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
553   application.SendNotification();
554   application.Render(16);
555   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
556
557   END_TEST;
558 }
559
560 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
561 {
562   TestGlAbstraction& gl = application.GetGlAbstraction();
563   TraceCallStack& textureTrace = gl.GetTextureTrace();
564
565   textureTrace.Enable(true);
566   Stage::GetCurrent().Add( dummyControl );
567   application.SendNotification();
568   application.Render(16);
569
570   tet_infoline( "Test that a timer has been created" );
571   DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
572
573   for ( uint16_t i = 0; i <= loopCount; i++ )
574   {
575     for ( uint16_t j = 0; j < frameCount; j++ )
576     {
577       tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
578       Test::EmitGlobalTimerSignal();
579       application.SendNotification();
580       application.Render(16);
581       DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_INNER_LOCATION( location ) );
582       DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
583     }
584     tet_printf( "\nTest Loop %u \n", i );
585   }
586
587   tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
588   Test::EmitGlobalTimerSignal();
589   application.SendNotification();
590   application.Render(16);
591   DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
592
593   dummyControl.Unparent();
594 }
595
596 int UtcDaliAnimatedImageVisualLoopCount(void)
597 {
598   ToolkitTestApplication application;
599
600   tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
601
602   {
603     // request AnimatedImageVisual with a property map
604     // Test with no (0) loop count
605     VisualFactory factory = VisualFactory::Get();
606     Visual::Base animatedImageVisual = factory.CreateVisual(
607       Property::Map()
608       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
609       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
610       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
611       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
612       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
613       .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
614
615     DummyControl dummyControl = DummyControl::New(true);
616     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
617     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
618     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
619
620     TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
621
622     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
623     animatedImageVisual = factory.CreateVisual(
624       Property::Map()
625       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
626       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
627       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
628       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
629       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
630       .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
631
632     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
633
634     TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
635
636     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
637     animatedImageVisual = factory.CreateVisual(
638       Property::Map()
639       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
640       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
641       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
642       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
643       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
644       .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
645
646     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
647
648     TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
649   }
650
651   END_TEST;
652 }
653
654 int UtcDaliAnimatedImageVisualPlayback(void)
655 {
656   ToolkitTestApplication application;
657   TestGlAbstraction& gl = application.GetGlAbstraction();
658   TraceCallStack& textureTrace = gl.GetTextureTrace();
659
660   tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
661
662   {
663     // request AnimatedImageVisual with a property map
664     // Test with forever (-1) loop count
665     VisualFactory factory = VisualFactory::Get();
666     Visual::Base animatedImageVisual = factory.CreateVisual(
667       Property::Map()
668       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
669       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
670       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
671       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
672       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
673       .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
674
675     DummyControl dummyControl = DummyControl::New(true);
676     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
677     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
678     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
679
680     textureTrace.Enable(true);
681     Stage::GetCurrent().Add( dummyControl );
682     application.SendNotification();
683     application.Render(16);
684
685     tet_infoline( "Test that a timer has been created" );
686     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
687
688     Test::EmitGlobalTimerSignal();
689     application.SendNotification();
690     application.Render(16);
691     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
692
693     Property::Map attributes;
694     tet_infoline( "Test Pause action. Timer should stop after Pause action" );
695     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
696     Test::EmitGlobalTimerSignal();
697     application.SendNotification();
698     application.Render(16);
699     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
700
701     tet_infoline( "Test Play action. Timer should Restart after Play action" );
702     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
703     Test::EmitGlobalTimerSignal();
704     application.SendNotification();
705     application.Render(16);
706     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
707
708     tet_infoline( "Test Stop action. Timer should stop after Stop action" );
709     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
710     Test::EmitGlobalTimerSignal();
711     application.SendNotification();
712     application.Render(16);
713     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
714
715     tet_infoline( "Test Play action. Timer should Restart after Play action" );
716     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
717     Test::EmitGlobalTimerSignal();
718     application.SendNotification();
719     application.Render(16);
720     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
721
722     dummyControl.Unparent();
723   }
724
725   END_TEST;
726 }