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