3 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_animated_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_animated_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-%02d.png";
46 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
50 void CopyUrlsIntoArray( Property::Array& urls, int startIndex=0 )
52 for( int i=20+startIndex;i<=30;++i)
55 if(asprintf(&url, TEST_IMAGE_FILE_NAME, i) > 0)
57 Property::Value value(url);
64 int UtcDaliAnimatedImageVisualGetPropertyMap01(void)
66 ToolkitTestApplication application;
67 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap" );
69 // request AnimatedImageVisual with a property map
70 VisualFactory factory = VisualFactory::Get();
71 Visual::Base animatedImageVisual = factory.CreateVisual(
73 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
74 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
75 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
76 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
77 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT ));
79 Property::Map resultMap;
80 animatedImageVisual.CreatePropertyMap( resultMap );
81 // check the property values from the returned map from a visual
82 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
83 DALI_TEST_CHECK( value );
84 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
86 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
87 DALI_TEST_CHECK( value );
88 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
90 // request AnimatedImageVisual with an URL
91 Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
93 animatedImageVisual2.CreatePropertyMap( resultMap );
94 // check the property values from the returned map from a visual
95 value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
96 DALI_TEST_CHECK( value );
97 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
99 value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
100 DALI_TEST_CHECK( value );
101 DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
107 int UtcDaliAnimatedImageVisualGetPropertyMap02(void)
109 ToolkitTestApplication application;
110 tet_infoline( "UtcDaliAnimatedImageVisualGetPropertyMap for multi image" );
112 // request AnimatedImageVisual with a property map
113 VisualFactory factory = VisualFactory::Get();
114 Property::Array urls;
115 CopyUrlsIntoArray( urls );
117 Visual::Base animatedImageVisual = factory.CreateVisual(
119 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
121 .Add( "batchSize", 4 )
122 .Add( "cacheSize", 8 )
123 .Add( "loopCount", 10 )
124 .Add( "frameDelay", 200 )
125 .Add( "pixelArea", Vector4() )
126 .Add( "wrapModeU", WrapMode::REPEAT )
127 .Add( "wrapModeV", WrapMode::DEFAULT ));
129 Property::Map resultMap;
130 animatedImageVisual.CreatePropertyMap( resultMap );
131 // check the property values from the returned map from a visual
132 Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
133 DALI_TEST_CHECK( value );
134 DALI_TEST_CHECK( value->Get<int>() == Visual::ANIMATED_IMAGE );
136 value = resultMap.Find( ImageVisual::Property::URL, "url" );
137 DALI_TEST_CHECK( value );
138 Property::Array* resultUrls = value->GetArray();
139 DALI_TEST_CHECK( resultUrls );
140 DALI_TEST_EQUALS( resultUrls->Count(), urls.Count(), TEST_LOCATION );
142 value = resultMap.Find( ImageVisual::Property::BATCH_SIZE, "batchSize" );
143 DALI_TEST_CHECK( value );
144 DALI_TEST_EQUALS( value->Get<int>(), 4, TEST_LOCATION );
146 value = resultMap.Find( ImageVisual::Property::CACHE_SIZE, "cacheSize" );
147 DALI_TEST_CHECK( value );
148 DALI_TEST_EQUALS( value->Get<int>(), 8, TEST_LOCATION );
150 value = resultMap.Find( Toolkit::DevelImageVisual::Property::LOOP_COUNT, "loopCount" );
151 DALI_TEST_CHECK( value );
152 DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
154 value = resultMap.Find( ImageVisual::Property::FRAME_DELAY, "frameDelay" );
155 DALI_TEST_CHECK( value );
156 DALI_TEST_EQUALS( value->Get<int>(), 200, TEST_LOCATION );
164 int UtcDaliAnimatedImageVisualMultiImage01(void)
166 ToolkitTestApplication application;
167 TestGlAbstraction& gl = application.GetGlAbstraction();
169 Property::Array urls;
170 CopyUrlsIntoArray( urls );
173 Property::Map propertyMap;
174 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
175 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
176 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
177 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 8);
178 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
180 VisualFactory factory = VisualFactory::Get();
181 Visual::Base visual = factory.CreateVisual( propertyMap );
183 // Expect that a batch of 4 textures has been requested. These will be serially loaded
186 DummyControl dummyControl = DummyControl::New(true);
187 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
188 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
190 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
191 Stage::GetCurrent().Add( dummyControl );
192 application.SendNotification();
193 application.Render(16);
195 tet_infoline( "Ready the visual after the visual is on stage" );
196 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
198 tet_infoline( "Test that a timer has been started" );
199 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
201 TraceCallStack& textureTrace = gl.GetTextureTrace();
202 textureTrace.Enable(true);
204 application.SendNotification();
205 application.Render(16);
207 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 4, TEST_LOCATION );
208 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
210 tet_infoline( "Test that after 1 tick, and file loads completed, that we have 7 textures" );
211 Test::EmitGlobalTimerSignal();
213 // Expect the second batch has been requested
214 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
216 application.SendNotification();
217 application.Render(16);
218 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
221 tet_infoline( "Test that after 2 ticks that we have 6 textures" );
223 Test::EmitGlobalTimerSignal();
224 application.SendNotification();
225 application.Render(16);
226 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 6, TEST_LOCATION );
228 tet_infoline("And that at least 2 textures were requested");
229 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
230 application.SendNotification();
231 application.Render(16);
232 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
235 tet_infoline( "Test that after 3rd tick that we have 7 textures and 1 request" );
236 Test::EmitGlobalTimerSignal();
237 application.SendNotification();
238 application.Render(16);
239 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 7, TEST_LOCATION );
241 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
242 application.SendNotification();
243 application.Render(16);
244 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 8, TEST_LOCATION );
246 dummyControl.Unparent();
248 tet_infoline("Test that removing the visual from stage deletes all textures");
249 application.SendNotification();
250 application.Render(16);
251 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
256 int UtcDaliAnimatedImageVisualMultiImage02(void)
258 ToolkitTestApplication application;
259 TestGlAbstraction& gl = application.GetGlAbstraction();
261 tet_infoline( "Test that the animated visual still works with zero sized cache" );
264 Property::Array urls;
265 CopyUrlsIntoArray( urls );
267 Property::Map propertyMap;
268 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
269 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
270 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 0);
271 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 0);
272 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
274 VisualFactory factory = VisualFactory::Get();
275 Visual::Base visual = factory.CreateVisual( propertyMap ); // TexMgr::Request load tId:0
277 // Expect that each image is loaded each tick
279 DummyControl dummyControl = DummyControl::New(true);
280 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
281 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
283 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
284 Stage::GetCurrent().Add( dummyControl );
285 application.SendNotification();
286 application.Render(16);
288 tet_infoline( "Ready the visual after the visual is on stage" );
289 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
290 application.SendNotification();
291 application.Render(16);//glGenTextures 1
292 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
294 tet_infoline( "Test that each tick, a new image is requested" );
295 Test::EmitGlobalTimerSignal(); // TexMgr::Remove tId:0
296 application.SendNotification();
297 application.Render(16);
298 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
299 application.SendNotification();
300 application.Render(16);//glGenTextures 2
301 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
303 tet_infoline( "Test that each tick, a new image is requested" );
304 Test::EmitGlobalTimerSignal(); // Internal::~TextureSet()
305 application.SendNotification();
306 application.Render(16);//glDeleteTextures 2
307 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
308 application.SendNotification();
309 application.Render(16);//glGenTextures 3
310 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
312 tet_infoline( "Test that each tick, a new image is requested" );
313 Test::EmitGlobalTimerSignal();
314 application.SendNotification();
315 application.Render(16);//glDeleteTextures 3
316 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 10 ), true, TEST_LOCATION );
317 application.SendNotification();
318 application.Render(16);//Gen4
319 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_LOCATION );
320 dummyControl.Unparent();
322 tet_infoline("Test that removing the visual from stage deletes all textures");
323 application.SendNotification();
324 application.Render(16);
325 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
330 int UtcDaliAnimatedImageVisualMultiImage03(void)
332 ToolkitTestApplication application;
333 TestGlAbstraction& gl = application.GetGlAbstraction();
336 Property::Array urls1, urls2;
337 CopyUrlsIntoArray( urls1 );
338 CopyUrlsIntoArray( urls2 );
340 Property::Map animatedImageMap1;
341 animatedImageMap1.Insert(Visual::Property::TYPE, Visual::IMAGE );
342 animatedImageMap1.Insert( ImageVisual::Property::URL, Property::Value(urls1) );
343 animatedImageMap1.Insert( ImageVisual::Property::BATCH_SIZE, 3);
344 animatedImageMap1.Insert( ImageVisual::Property::CACHE_SIZE, 3);
345 animatedImageMap1.Insert( ImageVisual::Property::FRAME_DELAY, 100);
347 Property::Map animatedImageMap2;
348 animatedImageMap2.Insert(Visual::Property::TYPE, Visual::IMAGE );
349 animatedImageMap2.Insert( ImageVisual::Property::URL, Property::Value(urls2) );
350 animatedImageMap2.Insert( ImageVisual::Property::BATCH_SIZE, 2);
351 animatedImageMap2.Insert( ImageVisual::Property::CACHE_SIZE, 2);
352 animatedImageMap2.Insert( ImageVisual::Property::FRAME_DELAY, 100);
354 VisualFactory factory = VisualFactory::Get();
355 Visual::Base animatedImageVisual1 = factory.CreateVisual( animatedImageMap1 );
357 tet_infoline( "Create two image views with the same URLs, offset by 1 frame.");
359 DummyControl dummyControl1 = DummyControl::New(true);
360 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummyControl1.GetImplementation());
361 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual1 );
362 dummyControl1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
363 Stage::GetCurrent().Add( dummyControl1 );
365 application.SendNotification();
366 application.Render(16);
368 tet_infoline( "Ready the requested image after the first visual is on stage" );
369 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
370 application.SendNotification();
371 application.Render(16);
372 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
374 Visual::Base animatedImageVisual2 = factory.CreateVisual( animatedImageMap2 );
375 DummyControl dummyControl2 = DummyControl::New(true);
376 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(dummyControl2.GetImplementation());
377 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual2 );
378 dummyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
379 Stage::GetCurrent().Add( dummyControl2 );
380 application.SendNotification();
381 application.Render(16);
383 tet_infoline( "The texture cache should be holding the requested images; check that the renderer has a texture" );
384 TextureSet ts = dummyControl2.GetRendererAt(0).GetTextures();
385 Texture t1 = ts.GetTexture( 0 );
386 DALI_TEST_EQUALS( ts.GetTextureCount(), 1, TEST_LOCATION );
388 tet_infoline( "Test that on the first tick, 1 new image is requested" );
389 Test::EmitGlobalTimerSignal(); // Both visuals should tick
391 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
392 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 3, TEST_LOCATION );
394 ts = dummyControl2.GetRendererAt(0).GetTextures();
395 Texture t2 = ts.GetTexture( 0 );
396 DALI_TEST_CHECK( t1 != t2 );
398 dummyControl1.Unparent();
399 dummyControl2.Unparent();
401 tet_infoline("Test that removing the visual from stage deletes all textures");
402 application.SendNotification();
403 application.Render(16);
404 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
410 int UtcDaliAnimatedImageVisualMultiImage04(void)
412 ToolkitTestApplication application;
413 TestGlAbstraction& gl = application.GetGlAbstraction();
414 TraceCallStack& textureTrace = gl.GetTextureTrace();
415 textureTrace.Enable(true);
417 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" );
419 Property::Array urls;
420 CopyUrlsIntoArray( urls );
423 Property::Map propertyMap;
424 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
425 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
426 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 6);
427 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
428 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
430 VisualFactory factory = VisualFactory::Get();
431 Visual::Base visual = factory.CreateVisual( propertyMap );
433 tet_infoline( "Expect that a batch of 7 textures has been requested." );
435 DummyControl dummyControl = DummyControl::New(true);
436 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
437 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
439 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
440 Stage::GetCurrent().Add( dummyControl );
441 application.SendNotification();
442 application.Render(16);
444 tet_infoline( "Wait for the first batch to complete" );
445 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 6 ), true, TEST_LOCATION );
447 tet_infoline( "Test that a timer has been started" );
448 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
450 application.SendNotification();
451 application.Render(16);
453 DALI_TEST_EQUALS( gl.GetLastGenTextureId(), 6, TEST_LOCATION );
454 tet_infoline( "Test that after 1 tick, and 5 file loads completed, that we have 11 textures" );
455 Test::EmitGlobalTimerSignal();
456 application.SendNotification();
457 application.Render(16);
459 // Expect the second batch has been requested
460 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 5 ), true, TEST_LOCATION );
462 application.SendNotification();
463 application.Render(16);
464 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
466 tet_infoline( "Test that after 2 ticks that we have 11 textures and no requests" );
468 Test::EmitGlobalTimerSignal();
469 application.SendNotification();
470 application.Render(16);
471 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
472 application.SendNotification();
473 application.Render(16);
474 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
476 tet_infoline( "Test that after 3rd tick that we have 11 textures and no requests" );
477 Test::EmitGlobalTimerSignal();
478 application.SendNotification();
479 application.Render(16);
481 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, 5 ), false, TEST_LOCATION );
482 application.SendNotification();
483 application.Render(16);
484 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 11, TEST_LOCATION );
486 dummyControl.Unparent();
489 tet_infoline("Test that removing the visual from stage deletes all textures");
490 application.SendNotification();
491 application.Render(16);
492 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
498 int UtcDaliAnimatedImageVisualMultiImage05(void)
500 ToolkitTestApplication application;
501 TestGlAbstraction& gl = application.GetGlAbstraction();
503 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" );
505 Property::Array urls;
506 CopyUrlsIntoArray( urls );
509 Property::Map propertyMap;
510 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE );
511 propertyMap.Insert( ImageVisual::Property::URL, Property::Value(urls) );
512 propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 4);
513 propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 11);
514 propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 100);
516 VisualFactory factory = VisualFactory::Get();
517 Visual::Base visual = factory.CreateVisual( propertyMap );
519 tet_infoline( "Expect that a batch of 4 textures has been requested." );
521 DummyControl dummyControl = DummyControl::New(true);
522 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
523 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
525 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
526 Stage::GetCurrent().Add( dummyControl );
527 application.SendNotification();
528 application.Render(16);
530 tet_infoline( "Wait for the first batch to complete" );
531 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
533 tet_infoline( "Test that a timer has been started" );
534 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
536 application.SendNotification();
537 application.Render(16);
539 tet_infoline( "Test that a timer has been started" );
540 Test::EmitGlobalTimerSignal();
541 application.SendNotification();
542 application.Render(16);
544 dummyControl.Unparent();
547 application.SendNotification();
548 application.Render(16);
549 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
551 tet_infoline( "Test that pending batch of image loads are cancelled instead of uploaded");
552 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 4 ), true, TEST_LOCATION );
553 application.SendNotification();
554 application.Render(16);
555 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 0, TEST_LOCATION );
560 void TestLoopCount( ToolkitTestApplication &application, DummyControl &dummyControl, uint16_t frameCount, uint16_t loopCount, const char * location )
562 TestGlAbstraction& gl = application.GetGlAbstraction();
563 TraceCallStack& textureTrace = gl.GetTextureTrace();
565 textureTrace.Enable(true);
566 Stage::GetCurrent().Add( dummyControl );
567 application.SendNotification();
568 application.Render(16);
570 tet_infoline( "Test that a timer has been created" );
571 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_INNER_LOCATION( location ) );
573 for ( uint16_t i = 0; i <= loopCount; i++ )
575 for ( uint16_t j = 0; j < frameCount; j++ )
577 tet_printf( "Test that after %u ticks, and we have %u frame \n", j + 1u, j + 1u );
578 Test::EmitGlobalTimerSignal();
579 application.SendNotification();
580 application.Render(16);
581 DALI_TEST_EQUALS( gl.GetNumGeneratedTextures(), 1, TEST_INNER_LOCATION( location ) );
582 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_INNER_LOCATION( location ) );
584 tet_printf( "\nTest Loop %u \n", i );
587 tet_printf( "Test that after %u loops, and we have no frame. Timer should stop \n", loopCount );
588 Test::EmitGlobalTimerSignal();
589 application.SendNotification();
590 application.Render(16);
591 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_INNER_LOCATION( location ) );
593 dummyControl.Unparent();
596 int UtcDaliAnimatedImageVisualLoopCount(void)
598 ToolkitTestApplication application;
600 tet_infoline( "UtcDaliAnimatedImageVisualLoopCount" );
603 // request AnimatedImageVisual with a property map
604 // Test with no (0) loop count
605 VisualFactory factory = VisualFactory::Get();
606 Visual::Base animatedImageVisual = factory.CreateVisual(
608 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
609 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
610 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
611 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
612 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
613 .Add( DevelImageVisual::Property::LOOP_COUNT, 0 ));
615 DummyControl dummyControl = DummyControl::New(true);
616 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
617 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
618 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
620 TestLoopCount( application, dummyControl, 4, 0, TEST_LOCATION );
622 // Test with no (1) loop count. Request AnimatedImageVisual with a property map
623 animatedImageVisual = factory.CreateVisual(
625 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
626 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
627 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
628 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
629 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
630 .Add( DevelImageVisual::Property::LOOP_COUNT, 1 ));
632 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
634 TestLoopCount( application, dummyControl, 4, 1, TEST_LOCATION );
636 // Test with no (100) loop count. Request AnimatedImageVisual with a property map
637 animatedImageVisual = factory.CreateVisual(
639 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
640 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
641 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
642 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
643 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
644 .Add( DevelImageVisual::Property::LOOP_COUNT, 100 ));
646 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
648 TestLoopCount( application, dummyControl, 4, 100, TEST_LOCATION );
654 int UtcDaliAnimatedImageVisualPlayback(void)
656 ToolkitTestApplication application;
657 TestGlAbstraction& gl = application.GetGlAbstraction();
658 TraceCallStack& textureTrace = gl.GetTextureTrace();
660 tet_infoline( "UtcDaliAnimatedImageVisualPlayback" );
663 // request AnimatedImageVisual with a property map
664 // Test with forever (-1) loop count
665 VisualFactory factory = VisualFactory::Get();
666 Visual::Base animatedImageVisual = factory.CreateVisual(
668 .Add( Toolkit::Visual::Property::TYPE, Visual::ANIMATED_IMAGE )
669 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
670 .Add( ImageVisual::Property::PIXEL_AREA, Vector4() )
671 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT )
672 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )
673 .Add( DevelImageVisual::Property::LOOP_COUNT, -1 ));
675 DummyControl dummyControl = DummyControl::New(true);
676 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
677 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, animatedImageVisual );
678 dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
680 textureTrace.Enable(true);
681 Stage::GetCurrent().Add( dummyControl );
682 application.SendNotification();
683 application.Render(16);
685 tet_infoline( "Test that a timer has been created" );
686 DALI_TEST_EQUALS( Test::GetTimerCount(), 1, TEST_LOCATION );
688 Test::EmitGlobalTimerSignal();
689 application.SendNotification();
690 application.Render(16);
691 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
693 Property::Map attributes;
694 tet_infoline( "Test Pause action. Timer should stop after Pause action" );
695 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PAUSE, attributes );
696 Test::EmitGlobalTimerSignal();
697 application.SendNotification();
698 application.Render(16);
699 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
701 tet_infoline( "Test Play action. Timer should Restart after Play action" );
702 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
703 Test::EmitGlobalTimerSignal();
704 application.SendNotification();
705 application.Render(16);
706 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
708 tet_infoline( "Test Stop action. Timer should stop after Stop action" );
709 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes );
710 Test::EmitGlobalTimerSignal();
711 application.SendNotification();
712 application.Render(16);
713 DALI_TEST_EQUALS( Test::AreTimersRunning(), false, TEST_LOCATION );
715 tet_infoline( "Test Play action. Timer should Restart after Play action" );
716 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes );
717 Test::EmitGlobalTimerSignal();
718 application.SendNotification();
719 application.Render(16);
720 DALI_TEST_EQUALS( Test::AreTimersRunning(), true, TEST_LOCATION );
722 dummyControl.Unparent();