Fixed SVACE and related issues in dali-scene-loader.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedImageVisual.cpp
1
2 /*
3  * Copyright (c) 2020 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 int UtcDaliAnimatedImageVisualGetPropertyMap03(void)
162 {
163   ToolkitTestApplication application;
164   tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
165
166   // request AnimatedImageVisual with a property map
167   VisualFactory factory = VisualFactory::Get();
168   Visual::Base animatedImageVisual = factory.CreateVisual(
169     Property::Map()
170     .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
171     .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
172     .Add( ImageVisual::Property::BATCH_SIZE, 1 )
173     .Add( ImageVisual::Property::CACHE_SIZE, 1 )
174     .Add( ImageVisual::Property::SYNCHRONOUS_LOADING, false ));
175
176   Property::Map resultMap;
177   animatedImageVisual.CreatePropertyMap( resultMap );
178
179   // check the property values from the returned map from a visual
180   Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE,  Property::INTEGER );
181   DALI_TEST_CHECK( value );
182   DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
183
184   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
185   DALI_TEST_CHECK( value );
186   DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
187
188   value = resultMap.Find( ImageVisual::Property::BATCH_SIZE,  Property::INTEGER );
189   DALI_TEST_CHECK( value );
190   DALI_TEST_CHECK( value->Get<int>() == 2 );
191
192   value = resultMap.Find( ImageVisual::Property::CACHE_SIZE,  Property::INTEGER );
193   DALI_TEST_CHECK( value );
194   DALI_TEST_CHECK( value->Get<int>() == 2 );
195
196   END_TEST;
197 }
198
199
200 int UtcDaliAnimatedImageVisualSynchronousLoading(void)
201 {
202   ToolkitTestApplication application;
203   TestGlAbstraction& gl = application.GetGlAbstraction();
204
205   {
206     Property::Map propertyMap;
207     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
208     propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
209     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
210     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
211     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
212     propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true);
213
214     VisualFactory factory = VisualFactory::Get();
215     Visual::Base visual = factory.CreateVisual( propertyMap );
216
217     DummyControl dummyControl = DummyControl::New(true);
218     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
219     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
220
221     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
222     application.GetScene().Add( dummyControl );
223
224     TraceCallStack& textureTrace = gl.GetTextureTrace();
225     textureTrace.Enable(true);
226
227     application.SendNotification();
228     application.Render(20);
229
230     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
231
232     application.SendNotification();
233     application.Render();
234
235     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
236     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
237
238     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 3 );
239
240     application.SendNotification();
241     application.Render(20);
242
243     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
244
245     application.SendNotification();
246     application.Render();
247
248     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
249
250     dummyControl.Unparent();
251   }
252   tet_infoline("Test that removing the visual from stage deletes all textures");
253   application.SendNotification();
254   application.Render(16);
255   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
256
257   END_TEST;
258 }
259
260
261 int UtcDaliAnimatedImageVisualJumpToAction(void)
262 {
263   ToolkitTestApplication application;
264   TestGlAbstraction& gl = application.GetGlAbstraction();
265
266   Property::Array urls;
267   CopyUrlsIntoArray( urls );
268
269   {
270     Property::Map propertyMap;
271     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
272     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
273     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
274     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 12);
275     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
276
277     VisualFactory factory = VisualFactory::Get();
278     Visual::Base visual = factory.CreateVisual( propertyMap );
279
280     DummyControl dummyControl = DummyControl::New(true);
281     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
282     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
283
284     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
285     application.GetScene().Add( dummyControl );
286     application.SendNotification();
287     application.Render(20);
288
289     tet_infoline( "Ready the visual after the visual is on stage" );
290     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
291
292     tet_infoline( "Test that a timer has been started" );
293     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
294
295     TraceCallStack& textureTrace = gl.GetTextureTrace();
296     textureTrace.Enable(true);
297
298     application.SendNotification();
299     application.Render(20);
300
301     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
302
303     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
304
305     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
306
307     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 20 );
308
309     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
310
311     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6 );
312
313     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
314     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
315
316     dummyControl.Unparent();
317   }
318   tet_infoline("Test that removing the visual from stage deletes all textures");
319   application.SendNotification();
320   application.Render(16);
321   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
322
323   END_TEST;
324 }
325
326
327 int UtcDaliAnimatedImageVisualStopBehavior(void)
328 {
329   ToolkitTestApplication application;
330   TestGlAbstraction& gl = application.GetGlAbstraction();
331
332   Property::Array urls;
333   CopyUrlsIntoArray( urls );
334
335   {
336     Property::Map propertyMap;
337     propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
338     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
339     propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME);
340     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
341     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
342     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
343
344     VisualFactory factory = VisualFactory::Get();
345     Visual::Base visual = factory.CreateVisual( propertyMap );
346
347     // Expect that a batch of 4 textures has been requested. These will be serially loaded
348     // below.
349
350     DummyControl dummyControl = DummyControl::New(true);
351     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
352     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
353
354     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
355     application.GetScene().Add( dummyControl );
356     application.SendNotification();
357     application.Render(20);
358
359     tet_infoline( "Ready the visual after the visual is on stage" );
360     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
361
362     tet_infoline( "Test that a timer has been started" );
363     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
364
365     TraceCallStack& textureTrace = gl.GetTextureTrace();
366     textureTrace.Enable(true);
367
368     application.SendNotification();
369     application.Render(20);
370
371     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
372
373     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
374
375     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
376
377     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 1 );
378
379     // Expect the second batch has been requested
380     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
381
382     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 4, TEST_LOCATION );
383
384     dummyControl.Unparent();
385   }
386   tet_infoline("Test that removing the visual from stage deletes all textures");
387   application.SendNotification();
388   application.Render(16);
389   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
390
391   END_TEST;
392 }
393
394
395 int UtcDaliAnimatedImageVisualStopBehavior02(void)
396 {
397   ToolkitTestApplication application;
398   TestGlAbstraction& gl = application.GetGlAbstraction();
399
400   Property::Array urls;
401   CopyUrlsIntoArray( urls );
402
403   {
404     Property::Map propertyMap;
405     propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
406     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
407     propertyMap.Insert( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME);
408     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
409     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2);
410     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
411
412     VisualFactory factory = VisualFactory::Get();
413     Visual::Base visual = factory.CreateVisual( propertyMap );
414
415     // Expect that a batch of 4 textures has been requested. These will be serially loaded
416     // below.
417
418     DummyControl dummyControl = DummyControl::New(true);
419     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
420     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
421
422     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
423     application.GetScene().Add( dummyControl );
424
425     tet_infoline( "Ready the visual after the visual is on stage" );
426     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
427
428     TraceCallStack& textureTrace = gl.GetTextureTrace();
429     textureTrace.Enable(true);
430
431     application.SendNotification();
432     application.Render(20);
433
434     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
435
436     Test::EmitGlobalTimerSignal();
437
438     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
439
440     application.SendNotification();
441     application.Render(20);
442
443     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
444
445     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, Property::Map() );
446
447     tet_infoline( "Ready the visual after the visual is on stage" );
448     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
449
450     application.SendNotification();
451     application.Render(20);
452
453     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
454
455     dummyControl.Unparent();
456   }
457   tet_infoline("Test that removing the visual from stage deletes all textures");
458   application.SendNotification();
459   application.Render(16);
460   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
461
462   END_TEST;
463 }
464
465
466 int UtcDaliAnimatedImageVisualAnimatedImage01(void)
467 {
468   ToolkitTestApplication application;
469   TestGlAbstraction& gl = application.GetGlAbstraction();
470
471   {
472     Property::Map propertyMap;
473     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
474     propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
475     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
476     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
477     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
478
479     VisualFactory factory = VisualFactory::Get();
480     Visual::Base visual = factory.CreateVisual( propertyMap );
481
482     // Expect that a batch of 4 textures has been requested. These will be serially loaded
483     // below.
484
485     DummyControl dummyControl = DummyControl::New(true);
486     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
487     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
488
489     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
490     application.GetScene().Add( dummyControl );
491
492     application.SendNotification();
493     application.Render();
494
495     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
496
497     application.SendNotification();
498     application.Render(20);
499
500     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
501
502     tet_infoline( "Test that a timer has been started" );
503
504     TraceCallStack& textureTrace = gl.GetTextureTrace();
505     textureTrace.Enable(true);
506
507     Test::EmitGlobalTimerSignal();
508
509     application.SendNotification();
510     application.Render();
511
512     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
513
514     application.SendNotification();
515     application.Render(20);
516
517     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
518
519     dummyControl.Unparent();
520   }
521   tet_infoline("Test that removing the visual from stage deletes all textures");
522   application.SendNotification();
523   application.Render(20);
524   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
525
526   END_TEST;
527 }
528
529
530 int UtcDaliAnimatedImageVisualMultiImage01(void)
531 {
532   ToolkitTestApplication application;
533   TestGlAbstraction& gl = application.GetGlAbstraction();
534
535   Property::Array urls;
536   CopyUrlsIntoArray( urls );
537
538   {
539     Property::Map propertyMap;
540     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
541     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
542     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
543     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
544     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
545
546     VisualFactory factory = VisualFactory::Get();
547     Visual::Base visual = factory.CreateVisual( propertyMap );
548
549     // Expect that a batch of 4 textures has been requested. These will be serially loaded
550     // below.
551
552     DummyControl dummyControl = DummyControl::New(true);
553     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
554     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
555
556     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
557     application.GetScene().Add( dummyControl );
558     application.SendNotification();
559     application.Render(16);
560
561     tet_infoline( "Ready the visual after the visual is on stage" );
562     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
563
564     tet_infoline( "Test that a timer has been started" );
565     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
566
567     TraceCallStack& textureTrace = gl.GetTextureTrace();
568     textureTrace.Enable(true);
569
570     application.SendNotification();
571     application.Render(16);
572
573     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
574     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
575
576     tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
577     Test::EmitGlobalTimerSignal();
578
579     // Expect the second batch has been requested
580     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
581
582     application.SendNotification();
583     application.Render(16);
584     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
585
586
587     tet_infoline( "Test that after 2 ticks that we have 6 textures" );
588
589     Test::EmitGlobalTimerSignal();
590     application.SendNotification();
591     application.Render(16);
592     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
593
594     tet_infoline("And that at least 2 textures were requested");
595     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
596     application.SendNotification();
597     application.Render(16);
598     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
599
600
601     tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
602     Test::EmitGlobalTimerSignal();
603     application.SendNotification();
604     application.Render(16);
605     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
606
607     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
608     application.SendNotification();
609     application.Render(16);
610     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
611
612     dummyControl.Unparent();
613   }
614   tet_infoline("Test that removing the visual from stage deletes all textures");
615   application.SendNotification();
616   application.Render(16);
617   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
618
619   END_TEST;
620 }
621
622 int UtcDaliAnimatedImageVisualMultiImage02(void)
623 {
624   ToolkitTestApplication application;
625   TestGlAbstraction& gl = application.GetGlAbstraction();
626
627   tet_infoline( "Test that the animated visual has different batch and cache size." );
628
629   {
630     Property::Array urls;
631     CopyUrlsIntoArray( urls );
632
633     Property::Map propertyMap;
634     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
635     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
636     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
637     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
638     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
639
640     VisualFactory factory = VisualFactory::Get();
641     Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
642
643     // Check the batch size and cache size need to have minimum 2.
644     Property::Map resultMap;
645     visual.CreatePropertyMap( resultMap );
646     Property::Value* value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
647     DALI_TEST_CHECK( value );
648     DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
649     value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
650     DALI_TEST_CHECK( value );
651     DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
652     visual.Reset();
653
654     // Batch size is 2 and cache size is 3
655     propertyMap.Clear();
656     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
657     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
658     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
659     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 3);
660     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
661
662     visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
663
664     // Expect that each image is loaded each tick
665     DummyControl dummyControl = DummyControl::New(true);
666     Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
667     dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
668     visual.Reset();
669
670     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
671     application.GetScene().Add( dummyControl );
672     application.SendNotification();
673     application.Render(16);
674
675     tet_infoline( "Ready the visual after the visual is on window" );
676     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
677     application.SendNotification();
678     application.Render(16);//glGenTextures 1 and 2
679     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
680
681     tet_infoline( "Test that each tick, a new image is requested" );
682     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
683     application.SendNotification();
684     application.Render(16);
685     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
686     application.SendNotification();
687     application.Render(16);//glGenTextures 3
688     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
689
690     tet_infoline( "Test that each tick, a new image is requested" );
691     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
692     application.SendNotification();
693     application.Render(16);
694     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
695     application.SendNotification();
696     application.Render(16);//glGenTextures 4
697     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
698
699     dummyImpl1.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
700     dummyControl.Unparent();
701
702
703     // Batch size is 9 and cache size is 4
704     propertyMap.Clear();
705     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
706     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
707     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 3);
708     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 7);
709     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
710
711     visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
712
713     // Expect that each image is loaded each tick
714     dummyControl = DummyControl::New(true);
715     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
716     dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
717     visual.Reset();
718
719     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
720     application.GetScene().Add( dummyControl );
721     application.SendNotification();
722     application.Render(16);
723
724     tet_infoline( "Ready the visual after the visual is on window" );
725     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
726     application.SendNotification();
727     application.Render(16);//glGenTextures 1, 2, and 3
728     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
729
730     tet_infoline( "Test that each tick, a new image is requested" );
731     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
732     application.SendNotification();
733     application.Render(16);
734     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
735     application.SendNotification();
736     application.Render(16);//glGenTextures 4, 5, and 6
737     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 5, TEST_LOCATION );
738
739     tet_infoline( "Test that each tick, a new image is requested" );
740     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
741     application.SendNotification();
742     application.Render(16);
743     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
744     application.SendNotification();
745     application.Render(16);//glGenTextures 7, 1, and 2
746     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
747
748     tet_infoline( "Test that each tick, a new image is requested" );
749     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
750     application.SendNotification();
751     application.Render(16);
752     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
753     application.SendNotification();
754     application.Render(16);//glGenTextures 3
755     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
756
757     dummyControl.Unparent();
758   }
759   tet_infoline("Test that removing the visual from window deletes all textures");
760   application.SendNotification();
761   application.Render(16);
762   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
763
764   END_TEST;
765 }
766
767 int UtcDaliAnimatedImageVisualMultiImage03(void)
768 {
769   ToolkitTestApplication application;
770   TestGlAbstraction& gl = application.GetGlAbstraction();
771
772   {
773     Property::Array urls1, urls2;
774     CopyUrlsIntoArray( urls1 );
775     CopyUrlsIntoArray( urls2 );
776
777     Property::Map animatedImageMap1;
778     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
779     animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
780     animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
781     animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
782     animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
783
784     Property::Map animatedImageMap2;
785     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
786     animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
787     animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
788     animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
789     animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
790
791     VisualFactory factory = VisualFactory::Get();
792     Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
793
794     tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
795
796     DummyControl dummyControl1 = DummyControl::New(true);
797     Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
798     dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
799     dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
800     application.GetScene().Add( dummyControl1 );
801
802     application.SendNotification();
803     application.Render(16);
804
805     tet_infoline( "Ready the requested image after the first visual is on stage" );
806     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
807     application.SendNotification();
808     application.Render(16);
809     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
810
811     Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
812     DummyControl dummyControl2 = DummyControl::New(true);
813     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
814     dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
815     dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
816     application.GetScene().Add( dummyControl2 );
817     application.SendNotification();
818     application.Render(16);
819
820     tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
821     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
822     Texture t1 = ts.GetTexture( 0 );
823     DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
824
825     tet_infoline( "Test that on the first tick, 1 new image is requested" );
826     Test::EmitGlobalTimerSignal(); // Both visuals should tick
827
828     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
829     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
830
831     ts = dummyControl2.GetRendererAt(0).GetTextures();
832     Texture t2 = ts.GetTexture( 0 );
833     DALI_TEST_CHECK( t1 != t2 );
834
835     dummyControl1.Unparent();
836     dummyControl2.Unparent();
837   }
838   tet_infoline("Test that removing the visual from stage deletes all textures");
839   application.SendNotification();
840   application.Render(16);
841   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
842
843   END_TEST;
844 }
845
846
847 int UtcDaliAnimatedImageVisualMultiImage04(void)
848 {
849   ToolkitTestApplication application;
850   TestGlAbstraction& gl = application.GetGlAbstraction();
851   TraceCallStack& textureTrace = gl.GetTextureTrace();
852   textureTrace.Enable(true);
853
854   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" );
855
856   Property::Array urls;
857   CopyUrlsIntoArray( urls );
858
859   {
860     Property::Map propertyMap;
861     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
862     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
863     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
864     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
865     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
866
867     VisualFactory factory = VisualFactory::Get();
868     Visual::Base visual = factory.CreateVisual( propertyMap );
869
870     tet_infoline( "Expect that a batch of 7 textures has been requested." );
871
872     DummyControl dummyControl = DummyControl::New(true);
873     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
874     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
875
876     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
877     application.GetScene().Add( dummyControl );
878     application.SendNotification();
879     application.Render(16);
880
881     tet_infoline( "Wait for the first batch to complete" );
882     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
883
884     tet_infoline( "Test that a timer has been started" );
885     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
886
887     application.SendNotification();
888     application.Render(16);
889
890     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
891     tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
892     Test::EmitGlobalTimerSignal();
893     application.SendNotification();
894     application.Render(16);
895
896     // Expect the second batch has been requested
897     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
898
899     application.SendNotification();
900     application.Render(16);
901     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
902
903     tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
904
905     Test::EmitGlobalTimerSignal();
906     application.SendNotification();
907     application.Render(16);
908     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
909     application.SendNotification();
910     application.Render(16);
911     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
912
913     tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
914     Test::EmitGlobalTimerSignal();
915     application.SendNotification();
916     application.Render(16);
917
918     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
919     application.SendNotification();
920     application.Render(16);
921     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
922
923     dummyControl.Unparent();
924   }
925
926   tet_infoline("Test that removing the visual from stage deletes all textures");
927   application.SendNotification();
928   application.Render(16);
929   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
930
931   END_TEST;
932 }
933
934
935 int UtcDaliAnimatedImageVisualMultiImage05(void)
936 {
937   ToolkitTestApplication application;
938   TestGlAbstraction& gl = application.GetGlAbstraction();
939
940   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" );
941
942   Property::Array urls;
943   CopyUrlsIntoArray( urls );
944
945   {
946     Property::Map propertyMap;
947     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
948     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
949     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
950     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
951     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
952
953     VisualFactory factory = VisualFactory::Get();
954     Visual::Base visual = factory.CreateVisual( propertyMap );
955
956     tet_infoline( "Expect that a batch of 4 textures has been requested." );
957
958     DummyControl dummyControl = DummyControl::New(true);
959     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
960     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
961
962     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
963     application.GetScene().Add( dummyControl );
964     application.SendNotification();
965     application.Render(16);
966
967     tet_infoline( "Wait for the first batch to complete" );
968     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
969
970     tet_infoline( "Test that a timer has been started" );
971     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
972
973     application.SendNotification();
974     application.Render(16);
975
976     tet_infoline( "Test that a timer has been started" );
977     Test::EmitGlobalTimerSignal();
978     application.SendNotification();
979     application.Render(16);
980
981     dummyControl.Unparent();
982   }
983
984   application.SendNotification();
985   application.Render(16);
986   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
987
988   tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
989   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
990   application.SendNotification();
991   application.Render(16);
992   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
993
994   END_TEST;
995 }
996
997 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
998 {
999   TestGlAbstraction& gl = application.GetGlAbstraction();
1000   TraceCallStack& textureTrace = gl.GetTextureTrace();
1001
1002   textureTrace.Enable(true);
1003   application.GetScene().Add( dummyControl );
1004
1005   application.SendNotification();
1006   application.Render(16);
1007
1008   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
1009
1010   application.SendNotification();
1011   application.Render();
1012
1013   tet_infoline( "Test that a timer has been created" );
1014   DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
1015
1016   for ( uint16_t i = 0; i < loopCount; i++ )
1017   {
1018     for ( uint16_t j = 0; j < frameCount; j++ )
1019     {
1020       if( i == 0 && j == 0 )
1021       {
1022         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
1023       }
1024       tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
1025       Test::EmitGlobalTimerSignal();
1026       application.SendNotification();
1027       application.Render(16);
1028
1029       DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
1030
1031       application.SendNotification();
1032       application.Render();
1033       DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
1034       DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
1035     }
1036     tet_printf( "Test Loop %u \n\n", i + 1u );
1037   }
1038
1039   tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
1040   Test::EmitGlobalTimerSignal();
1041   application.SendNotification();
1042   application.Render(16);
1043   DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
1044
1045   dummyControl.Unparent();
1046 }
1047
1048 int UtcDaliAnimatedImageVisualLoopCount(void)
1049 {
1050   ToolkitTestApplication application;
1051
1052   tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
1053
1054   {
1055     // request AnimatedImageVisual with a property map
1056     // Test with no (0) loop count
1057     VisualFactory factory = VisualFactory::Get();
1058     Visual::Base animatedImageVisual = factory.CreateVisual(
1059       Property::Map()
1060       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1061       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1062       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1063       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1064       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1065       .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
1066
1067     DummyControl dummyControl = DummyControl::New(true);
1068     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1069     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1070     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1071
1072     TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
1073
1074     dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1075     animatedImageVisual.Reset();
1076
1077     application.SendNotification();
1078     application.Render(16);
1079
1080     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1081     animatedImageVisual = factory.CreateVisual(
1082       Property::Map()
1083       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1084       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1085       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1086       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1087       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1088       .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
1089
1090     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1091
1092     TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
1093
1094     dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1095     animatedImageVisual.Reset();
1096
1097     application.SendNotification();
1098     application.Render(16);
1099
1100     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1101     animatedImageVisual = factory.CreateVisual(
1102       Property::Map()
1103       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1104       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1105       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1106       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1107       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1108       .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
1109
1110     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1111
1112     TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
1113   }
1114   END_TEST;
1115 }
1116
1117 int UtcDaliAnimatedImageVisualPlayback(void)
1118 {
1119   ToolkitTestApplication application;
1120   TestGlAbstraction& gl = application.GetGlAbstraction();
1121   TraceCallStack& textureTrace = gl.GetTextureTrace();
1122
1123   tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
1124
1125   {
1126     // request AnimatedImageVisual with a property map
1127     // Test with forever (-1) loop count
1128     VisualFactory factory = VisualFactory::Get();
1129     Visual::Base animatedImageVisual = factory.CreateVisual(
1130       Property::Map()
1131       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1132       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1133       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1134       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1135       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1136       .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
1137
1138     DummyControl dummyControl = DummyControl::New(true);
1139     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1140     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1141     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1142
1143     textureTrace.Enable(true);
1144     application.GetScene().Add( dummyControl );
1145     application.SendNotification();
1146     application.Render(16);
1147
1148     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1149
1150     application.SendNotification();
1151     application.Render();
1152
1153     tet_infoline( "Test that a timer has been created" );
1154     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1155
1156     Test::EmitGlobalTimerSignal();
1157     application.SendNotification();
1158     application.Render(16);
1159
1160     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1161
1162     application.SendNotification();
1163     application.Render();
1164     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1165
1166     Property::Map attributes;
1167     tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1168     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1169     Test::EmitGlobalTimerSignal();
1170     application.SendNotification();
1171     application.Render(16);
1172     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1173
1174     tet_infoline( "Test Play action. Timer should Restart after Play action" );
1175     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1176     Test::EmitGlobalTimerSignal();
1177     application.SendNotification();
1178     application.Render(16);
1179
1180     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1181
1182     application.SendNotification();
1183     application.Render();
1184     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1185
1186     tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1187     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1188     Test::EmitGlobalTimerSignal();
1189     application.SendNotification();
1190     application.Render(16);
1191     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1192
1193     tet_infoline( "Test Play action. Timer should Restart after Play action" );
1194     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1195     Test::EmitGlobalTimerSignal();
1196     application.SendNotification();
1197     application.Render(16);
1198
1199     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1200
1201     application.SendNotification();
1202     application.Render();
1203     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1204
1205     dummyControl.Unparent();
1206   }
1207
1208   END_TEST;
1209 }