Merge "Add a TextEditor property to limit input to maximum characters" into devel...
[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 UtcDaliAnimatedImageVisualAnimatedImage01(void)
396 {
397   ToolkitTestApplication application;
398   TestGlAbstraction& gl = application.GetGlAbstraction();
399
400   {
401     Property::Map propertyMap;
402     propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE );
403     propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME );
404     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
405     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 4);
406     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20);
407
408     VisualFactory factory = VisualFactory::Get();
409     Visual::Base visual = factory.CreateVisual( propertyMap );
410
411     // Expect that a batch of 4 textures has been requested. These will be serially loaded
412     // below.
413
414     DummyControl dummyControl = DummyControl::New(true);
415     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
416     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
417
418     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
419     application.GetScene().Add( dummyControl );
420
421     application.SendNotification();
422     application.Render();
423
424     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
425
426     application.SendNotification();
427     application.Render(20);
428
429     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 2, TEST_LOCATION );
430
431     tet_infoline( "Test that a timer has been started" );
432
433     TraceCallStack& textureTrace = gl.GetTextureTrace();
434     textureTrace.Enable(true);
435
436     Test::EmitGlobalTimerSignal();
437
438     application.SendNotification();
439     application.Render();
440
441     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
442
443     application.SendNotification();
444     application.Render(20);
445
446     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
447
448     dummyControl.Unparent();
449   }
450   tet_infoline("Test that removing the visual from stage deletes all textures");
451   application.SendNotification();
452   application.Render(20);
453   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
454
455   END_TEST;
456 }
457
458
459 int UtcDaliAnimatedImageVisualMultiImage01(void)
460 {
461   ToolkitTestApplication application;
462   TestGlAbstraction& gl = application.GetGlAbstraction();
463
464   Property::Array urls;
465   CopyUrlsIntoArray( urls );
466
467   {
468     Property::Map propertyMap;
469     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
470     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
471     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
472     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
473     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
474
475     VisualFactory factory = VisualFactory::Get();
476     Visual::Base visual = factory.CreateVisual( propertyMap );
477
478     // Expect that a batch of 4 textures has been requested. These will be serially loaded
479     // below.
480
481     DummyControl dummyControl = DummyControl::New(true);
482     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
483     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
484
485     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
486     application.GetScene().Add( dummyControl );
487     application.SendNotification();
488     application.Render(16);
489
490     tet_infoline( "Ready the visual after the visual is on stage" );
491     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
492
493     tet_infoline( "Test that a timer has been started" );
494     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
495
496     TraceCallStack& textureTrace = gl.GetTextureTrace();
497     textureTrace.Enable(true);
498
499     application.SendNotification();
500     application.Render(16);
501
502     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
503     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
504
505     tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
506     Test::EmitGlobalTimerSignal();
507
508     // Expect the second batch has been requested
509     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
510
511     application.SendNotification();
512     application.Render(16);
513     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
514
515
516     tet_infoline( "Test that after 2 ticks that we have 6 textures" );
517
518     Test::EmitGlobalTimerSignal();
519     application.SendNotification();
520     application.Render(16);
521     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
522
523     tet_infoline("And that at least 2 textures were requested");
524     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
525     application.SendNotification();
526     application.Render(16);
527     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
528
529
530     tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
531     Test::EmitGlobalTimerSignal();
532     application.SendNotification();
533     application.Render(16);
534     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
535
536     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
537     application.SendNotification();
538     application.Render(16);
539     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
540
541     dummyControl.Unparent();
542   }
543   tet_infoline("Test that removing the visual from stage deletes all textures");
544   application.SendNotification();
545   application.Render(16);
546   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
547
548   END_TEST;
549 }
550
551 int UtcDaliAnimatedImageVisualMultiImage02(void)
552 {
553   ToolkitTestApplication application;
554   TestGlAbstraction& gl = application.GetGlAbstraction();
555
556   tet_infoline( "Test that the animated visual has different batch and cache size." );
557
558   {
559     Property::Array urls;
560     CopyUrlsIntoArray( urls );
561
562     Property::Map propertyMap;
563     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
564     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
565     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
566     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
567     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
568
569     VisualFactory factory = VisualFactory::Get();
570     Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
571
572     // Check the batch size and cache size need to have minimum 2.
573     Property::Map resultMap;
574     visual.CreatePropertyMap( resultMap );
575     Property::Value* value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
576     DALI_TEST_CHECK( value );
577     DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
578     value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
579     DALI_TEST_CHECK( value );
580     DALI_TEST_EQUALS( value->Get<int>(), 2, TEST_LOCATION );
581     visual.Reset();
582
583     // Batch size is 2 and cache size is 3
584     propertyMap.Clear();
585     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
586     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
587     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2);
588     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 3);
589     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
590
591     visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
592
593     // Expect that each image is loaded each tick
594     DummyControl dummyControl = DummyControl::New(true);
595     Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
596     dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
597     visual.Reset();
598
599     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
600     application.GetScene().Add( dummyControl );
601     application.SendNotification();
602     application.Render(16);
603
604     tet_infoline( "Ready the visual after the visual is on window" );
605     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
606     application.SendNotification();
607     application.Render(16);//glGenTextures 1 and 2
608     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_LOCATION );
609
610     tet_infoline( "Test that each tick, a new image is requested" );
611     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
612     application.SendNotification();
613     application.Render(16);
614     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
615     application.SendNotification();
616     application.Render(16);//glGenTextures 3
617     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
618
619     tet_infoline( "Test that each tick, a new image is requested" );
620     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
621     application.SendNotification();
622     application.Render(16);
623     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
624     application.SendNotification();
625     application.Render(16);//glGenTextures 4
626     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
627
628     dummyImpl1.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
629     dummyControl.Unparent();
630
631
632     // Batch size is 9 and cache size is 4
633     propertyMap.Clear();
634     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
635     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
636     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 3);
637     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 7);
638     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
639
640     visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
641
642     // Expect that each image is loaded each tick
643     dummyControl = DummyControl::New(true);
644     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
645     dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
646     visual.Reset();
647
648     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
649     application.GetScene().Add( dummyControl );
650     application.SendNotification();
651     application.Render(16);
652
653     tet_infoline( "Ready the visual after the visual is on window" );
654     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
655     application.SendNotification();
656     application.Render(16);//glGenTextures 1, 2, and 3
657     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
658
659     tet_infoline( "Test that each tick, a new image is requested" );
660     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
661     application.SendNotification();
662     application.Render(16);
663     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
664     application.SendNotification();
665     application.Render(16);//glGenTextures 4, 5, and 6
666     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 5, TEST_LOCATION );
667
668     tet_infoline( "Test that each tick, a new image is requested" );
669     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:1
670     application.SendNotification();
671     application.Render(16);
672     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
673     application.SendNotification();
674     application.Render(16);//glGenTextures 7, 1, and 2
675     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
676
677     tet_infoline( "Test that each tick, a new image is requested" );
678     Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:2
679     application.SendNotification();
680     application.Render(16);
681     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
682     application.SendNotification();
683     application.Render(16);//glGenTextures 3
684     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
685
686     dummyControl.Unparent();
687   }
688   tet_infoline("Test that removing the visual from window deletes all textures");
689   application.SendNotification();
690   application.Render(16);
691   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
692
693   END_TEST;
694 }
695
696 int UtcDaliAnimatedImageVisualMultiImage03(void)
697 {
698   ToolkitTestApplication application;
699   TestGlAbstraction& gl = application.GetGlAbstraction();
700
701   {
702     Property::Array urls1, urls2;
703     CopyUrlsIntoArray( urls1 );
704     CopyUrlsIntoArray( urls2 );
705
706     Property::Map animatedImageMap1;
707     animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
708     animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
709     animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
710     animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
711     animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
712
713     Property::Map animatedImageMap2;
714     animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
715     animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
716     animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
717     animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
718     animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
719
720     VisualFactory factory = VisualFactory::Get();
721     Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
722
723     tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
724
725     DummyControl dummyControl1 = DummyControl::New(true);
726     Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
727     dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
728     dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
729     application.GetScene().Add( dummyControl1 );
730
731     application.SendNotification();
732     application.Render(16);
733
734     tet_infoline( "Ready the requested image after the first visual is on stage" );
735     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
736     application.SendNotification();
737     application.Render(16);
738     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
739
740     Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
741     DummyControl dummyControl2 = DummyControl::New(true);
742     Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
743     dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
744     dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
745     application.GetScene().Add( dummyControl2 );
746     application.SendNotification();
747     application.Render(16);
748
749     tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
750     TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
751     Texture t1 = ts.GetTexture( 0 );
752     DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
753
754     tet_infoline( "Test that on the first tick, 1 new image is requested" );
755     Test::EmitGlobalTimerSignal(); // Both visuals should tick
756
757     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
758     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
759
760     ts = dummyControl2.GetRendererAt(0).GetTextures();
761     Texture t2 = ts.GetTexture( 0 );
762     DALI_TEST_CHECK( t1 != t2 );
763
764     dummyControl1.Unparent();
765     dummyControl2.Unparent();
766   }
767   tet_infoline("Test that removing the visual from stage deletes all textures");
768   application.SendNotification();
769   application.Render(16);
770   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
771
772   END_TEST;
773 }
774
775
776 int UtcDaliAnimatedImageVisualMultiImage04(void)
777 {
778   ToolkitTestApplication application;
779   TestGlAbstraction& gl = application.GetGlAbstraction();
780   TraceCallStack& textureTrace = gl.GetTextureTrace();
781   textureTrace.Enable(true);
782
783   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" );
784
785   Property::Array urls;
786   CopyUrlsIntoArray( urls );
787
788   {
789     Property::Map propertyMap;
790     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
791     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
792     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
793     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
794     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
795
796     VisualFactory factory = VisualFactory::Get();
797     Visual::Base visual = factory.CreateVisual( propertyMap );
798
799     tet_infoline( "Expect that a batch of 7 textures has been requested." );
800
801     DummyControl dummyControl = DummyControl::New(true);
802     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
803     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
804
805     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
806     application.GetScene().Add( dummyControl );
807     application.SendNotification();
808     application.Render(16);
809
810     tet_infoline( "Wait for the first batch to complete" );
811     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
812
813     tet_infoline( "Test that a timer has been started" );
814     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
815
816     application.SendNotification();
817     application.Render(16);
818
819     DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
820     tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
821     Test::EmitGlobalTimerSignal();
822     application.SendNotification();
823     application.Render(16);
824
825     // Expect the second batch has been requested
826     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
827
828     application.SendNotification();
829     application.Render(16);
830     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
831
832     tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
833
834     Test::EmitGlobalTimerSignal();
835     application.SendNotification();
836     application.Render(16);
837     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
838     application.SendNotification();
839     application.Render(16);
840     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
841
842     tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
843     Test::EmitGlobalTimerSignal();
844     application.SendNotification();
845     application.Render(16);
846
847     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
848     application.SendNotification();
849     application.Render(16);
850     DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
851
852     dummyControl.Unparent();
853   }
854
855   tet_infoline("Test that removing the visual from stage deletes all textures");
856   application.SendNotification();
857   application.Render(16);
858   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
859
860   END_TEST;
861 }
862
863
864 int UtcDaliAnimatedImageVisualMultiImage05(void)
865 {
866   ToolkitTestApplication application;
867   TestGlAbstraction& gl = application.GetGlAbstraction();
868
869   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" );
870
871   Property::Array urls;
872   CopyUrlsIntoArray( urls );
873
874   {
875     Property::Map propertyMap;
876     propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
877     propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
878     propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
879     propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
880     propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
881
882     VisualFactory factory = VisualFactory::Get();
883     Visual::Base visual = factory.CreateVisual( propertyMap );
884
885     tet_infoline( "Expect that a batch of 4 textures has been requested." );
886
887     DummyControl dummyControl = DummyControl::New(true);
888     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
889     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
890
891     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
892     application.GetScene().Add( dummyControl );
893     application.SendNotification();
894     application.Render(16);
895
896     tet_infoline( "Wait for the first batch to complete" );
897     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
898
899     tet_infoline( "Test that a timer has been started" );
900     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
901
902     application.SendNotification();
903     application.Render(16);
904
905     tet_infoline( "Test that a timer has been started" );
906     Test::EmitGlobalTimerSignal();
907     application.SendNotification();
908     application.Render(16);
909
910     dummyControl.Unparent();
911   }
912
913   application.SendNotification();
914   application.Render(16);
915   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
916
917   tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
918   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
919   application.SendNotification();
920   application.Render(16);
921   DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
922
923   END_TEST;
924 }
925
926 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
927 {
928   TestGlAbstraction& gl = application.GetGlAbstraction();
929   TraceCallStack& textureTrace = gl.GetTextureTrace();
930
931   textureTrace.Enable(true);
932   application.GetScene().Add( dummyControl );
933
934   application.SendNotification();
935   application.Render(16);
936
937   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_INNER_LOCATION( location ) );
938
939   application.SendNotification();
940   application.Render();
941
942   tet_infoline( "Test that a timer has been created" );
943   DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
944
945   for ( uint16_t i = 0; i < loopCount; i++ )
946   {
947     for ( uint16_t j = 0; j < frameCount; j++ )
948     {
949       if( i == 0 && j == 0 )
950       {
951         continue; // Because first frame is already showed and we call 2nd frame at the first time of timer animation.
952       }
953       tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
954       Test::EmitGlobalTimerSignal();
955       application.SendNotification();
956       application.Render(16);
957
958       DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_INNER_LOCATION( location ) );
959
960       application.SendNotification();
961       application.Render();
962       DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 2, TEST_INNER_LOCATION( location ) );
963       DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
964     }
965     tet_printf( "Test Loop %u \n\n", i + 1u );
966   }
967
968   tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
969   Test::EmitGlobalTimerSignal();
970   application.SendNotification();
971   application.Render(16);
972   DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
973
974   dummyControl.Unparent();
975 }
976
977 int UtcDaliAnimatedImageVisualLoopCount(void)
978 {
979   ToolkitTestApplication application;
980
981   tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
982
983   {
984     // request AnimatedImageVisual with a property map
985     // Test with no (0) loop count
986     VisualFactory factory = VisualFactory::Get();
987     Visual::Base animatedImageVisual = factory.CreateVisual(
988       Property::Map()
989       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
990       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
991       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
992       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
993       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
994       .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
995
996     DummyControl dummyControl = DummyControl::New(true);
997     Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
998     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
999     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1000
1001     TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
1002
1003     dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1004     animatedImageVisual.Reset();
1005
1006     application.SendNotification();
1007     application.Render(16);
1008
1009     // Test with no (1) loop count. Request AnimatedImageVisual with a property map
1010     animatedImageVisual = factory.CreateVisual(
1011       Property::Map()
1012       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1013       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1014       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1015       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1016       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1017       .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
1018
1019     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1020
1021     TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
1022
1023     dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1024     animatedImageVisual.Reset();
1025
1026     application.SendNotification();
1027     application.Render(16);
1028
1029     // Test with no (100) loop count. Request AnimatedImageVisual with a property map
1030     animatedImageVisual = factory.CreateVisual(
1031       Property::Map()
1032       .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
1033       .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1034       .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
1035       .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
1036       .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
1037       .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
1038
1039     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
1040
1041     TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
1042   }
1043   END_TEST;
1044 }
1045
1046 int UtcDaliAnimatedImageVisualPlayback(void)
1047 {
1048   ToolkitTestApplication application;
1049   TestGlAbstraction& gl = application.GetGlAbstraction();
1050   TraceCallStack& textureTrace = gl.GetTextureTrace();
1051
1052   tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
1053
1054   {
1055     // request AnimatedImageVisual with a property map
1056     // Test with forever (-1) 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, -1 ));
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     textureTrace.Enable(true);
1073     application.GetScene().Add( dummyControl );
1074     application.SendNotification();
1075     application.Render(16);
1076
1077     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1078
1079     application.SendNotification();
1080     application.Render();
1081
1082     tet_infoline( "Test that a timer has been created" );
1083     DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
1084
1085     Test::EmitGlobalTimerSignal();
1086     application.SendNotification();
1087     application.Render(16);
1088
1089     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1090
1091     application.SendNotification();
1092     application.Render();
1093     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1094
1095     Property::Map attributes;
1096     tet_infoline( "Test Pause action. Timer should stop after Pause action" );
1097     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
1098     Test::EmitGlobalTimerSignal();
1099     application.SendNotification();
1100     application.Render(16);
1101     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1102
1103     tet_infoline( "Test Play action. Timer should Restart after Play action" );
1104     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1105     Test::EmitGlobalTimerSignal();
1106     application.SendNotification();
1107     application.Render(16);
1108
1109     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1110
1111     application.SendNotification();
1112     application.Render();
1113     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1114
1115     tet_infoline( "Test Stop action. Timer should stop after Stop action" );
1116     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
1117     Test::EmitGlobalTimerSignal();
1118     application.SendNotification();
1119     application.Render(16);
1120     DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
1121
1122     tet_infoline( "Test Play action. Timer should Restart after Play action" );
1123     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
1124     Test::EmitGlobalTimerSignal();
1125     application.SendNotification();
1126     application.Render(16);
1127
1128     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1129
1130     application.SendNotification();
1131     application.Render();
1132     DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
1133
1134     dummyControl.Unparent();
1135   }
1136
1137   END_TEST;
1138 }