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