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