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