[Tizen] visual: Implements rive animation
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-AnimatedVectorImageVisual.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <iostream>
18 #include <stdlib.h>
19 #include <chrono>
20 #include <thread>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <toolkit-timer.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-vector-animation-renderer.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
27 #include <dali-toolkit/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
31 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
32 #include <dali/devel-api/rendering/renderer-devel.h>
33 #include <dali/devel-api/adaptor-framework/window-devel.h>
34 #include "dummy-control.h"
35
36 using namespace Dali;
37 using namespace Dali::Toolkit;
38
39 void dali_animated_vector_image_visual_startup(void)
40 {
41   test_return_value = TET_UNDEF;
42 }
43
44 void dali_animated_vector_image_visual_cleanup(void)
45 {
46   test_return_value = TET_PASS;
47 }
48
49 namespace
50 {
51
52 const char* TEST_VECTOR_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/insta_camera.json";
53 const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME =  "invalid.json";
54
55 const char* TEST_VECTOR_IMAGE_RIVE_FILE_NAME =  TEST_RESOURCE_DIR  "/juice.riv";
56 const char* TEST_VECTOR_IMAGE_INVALID_RIVE_FILE_NAME = "invalid.riv";
57
58 bool gAnimationFinishedSignalFired = false;
59
60 void VisualEventSignal( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId )
61 {
62   if( visualIndex == DummyControl::Property::TEST_VISUAL && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED )
63   {
64     gAnimationFinishedSignalFired = true;
65   }
66 }
67
68 }
69
70 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual01(void)
71 {
72   ToolkitTestApplication application;
73   tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual01: Request animated vector image visual with a json url" );
74
75   VisualFactory factory = VisualFactory::Get();
76   Visual::Base visual = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() );
77   DALI_TEST_CHECK( visual );
78
79   DummyControl actor = DummyControl::New( true );
80   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
81   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
82   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
83   application.GetScene().Add( actor );
84
85   application.SendNotification();
86   application.Render();
87
88   // renderer is added to actor
89   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
90   Renderer renderer = actor.GetRendererAt( 0u );
91   DALI_TEST_CHECK( renderer );
92
93   // Test SetOffScene().
94   actor.Unparent();
95   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
96
97   END_TEST;
98 }
99
100 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual02(void)
101 {
102   ToolkitTestApplication application;
103   tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual02: Request animated vector image visual with a Property::Map" );
104
105   Property::Map propertyMap;
106   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
107              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  );
108
109   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
110   DALI_TEST_CHECK( visual );
111
112   DummyControl actor = DummyControl::New( true );
113   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
114   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
115   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
116   application.GetScene().Add( actor );
117
118   application.SendNotification();
119   application.Render();
120
121   // renderer is added to actor
122   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
123   Renderer renderer = actor.GetRendererAt( 0u );
124   DALI_TEST_CHECK( renderer );
125
126   actor.Unparent( );
127   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
128
129   END_TEST;
130 }
131
132 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void)
133 {
134   ToolkitTestApplication application;
135   tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual03: Request animated vector image visual with a Property::Map" );
136
137   int startFrame = 1, endFrame = 3;
138   Property::Array playRange;
139   playRange.PushBack( startFrame );
140   playRange.PushBack( endFrame );
141
142   Property::Map propertyMap;
143   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
144              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
145              .Add( DevelImageVisual::Property::LOOP_COUNT, 3  )
146              .Add( DevelImageVisual::Property::PLAY_RANGE, playRange  )
147              .Add( DevelVisual::Property::CORNER_RADIUS, 50.0f );
148
149   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
150   DALI_TEST_CHECK( visual );
151
152   DummyControl actor = DummyControl::New( true );
153   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
154   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
155   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
156   application.GetScene().Add( actor );
157
158   application.SendNotification();
159   application.Render();
160
161   // renderer is added to actor
162   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
163   Renderer renderer = actor.GetRendererAt( 0u );
164   DALI_TEST_CHECK( renderer );
165
166   actor.Unparent( );
167   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
168
169   END_TEST;
170 }
171
172 int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void)
173 {
174   ToolkitTestApplication application;
175   tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map" );
176
177   int startFrame = 1, endFrame = 3;
178   float cornerRadius = 22.0f;
179   Property::Array playRange;
180   playRange.PushBack( startFrame );
181   playRange.PushBack( endFrame );
182
183   Property::Map propertyMap;
184   propertyMap.Add( "visualType", DevelVisual::ANIMATED_VECTOR_IMAGE )
185              .Add( "url", TEST_VECTOR_IMAGE_FILE_NAME )
186              .Add( "loopCount", 3 )
187              .Add( "playRange", playRange )
188              .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME )
189              .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE )
190              .Add( "redrawInScalingDown", false )
191              .Add( "cornerRadius", cornerRadius );
192
193   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
194   DALI_TEST_CHECK( visual );
195
196   DummyControl actor = DummyControl::New( true );
197   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
198   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
199   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
200   application.GetScene().Add( actor );
201
202   application.SendNotification();
203   application.Render();
204
205   // Trigger count is 1 - render a frame
206   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
207
208   // renderer is added to actor
209   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
210
211   Renderer renderer = actor.GetRendererAt( 0u );
212   DALI_TEST_CHECK( renderer );
213
214   Property::Map resultMap;
215   visual.CreatePropertyMap( resultMap );
216
217   // check the property values from the returned map from a visual
218   Property::Value* value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
219   DALI_TEST_CHECK( value );
220   DALI_TEST_CHECK( value->Get< std::string >() == TEST_VECTOR_IMAGE_FILE_NAME );
221
222   value = resultMap.Find( DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER );
223   DALI_TEST_CHECK( value );
224   DALI_TEST_CHECK( value->Get< int >() == 3 );
225
226   value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY );
227   DALI_TEST_CHECK( value );
228
229   Property::Array* result = value->GetArray();
230   DALI_TEST_CHECK( result );
231
232   DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
233   DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
234
235   value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER );
236   DALI_TEST_CHECK( value );
237   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::FIRST_FRAME );
238
239   value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER );
240   DALI_TEST_CHECK( value );
241   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::AUTO_REVERSE );
242
243   value = resultMap.Find( DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN );
244   DALI_TEST_CHECK( value );
245   DALI_TEST_CHECK( value->Get< bool >() == false );
246
247   value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4 );
248   DALI_TEST_CHECK( value );
249   DALI_TEST_EQUALS( value->Get< Vector4 >(), Vector4(cornerRadius, cornerRadius, cornerRadius, cornerRadius), TEST_LOCATION );
250
251   value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
252   DALI_TEST_CHECK( value );
253   DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::ABSOLUTE );
254
255   actor.Unparent( );
256   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
257
258   END_TEST;
259 }
260
261 int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void)
262 {
263   ToolkitTestApplication application;
264   tet_infoline( "UtcDaliAnimatedVectorImageVisualGetPropertyMap01" );
265
266   int startFrame = 1, endFrame = 3;
267   Vector4 cornerRadius(50.0f, 22.0f, 0.0f, 3.0f);
268   Property::Array playRange;
269   playRange.PushBack( startFrame );
270   playRange.PushBack( endFrame );
271
272   Property::Map propertyMap;
273   propertyMap.Add( Toolkit::Visual::Property::TYPE,  DevelVisual::ANIMATED_VECTOR_IMAGE )
274              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
275              .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
276              .Add( DevelImageVisual::Property::PLAY_RANGE, playRange )
277              .Add( DevelVisual::Property::CORNER_RADIUS, cornerRadius )
278              .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE);
279
280   // request AnimatedVectorImageVisual with a property map
281   VisualFactory factory = VisualFactory::Get();
282   Visual::Base visual = factory.CreateVisual( propertyMap );
283
284   DummyControl actor = DummyControl::New( true );
285   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
286   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
287
288   Vector2 controlSize( 20.f, 30.f );
289   actor.SetProperty( Actor::Property::SIZE, controlSize );
290
291   application.GetScene().Add( actor );
292
293   application.SendNotification();
294   application.Render();
295
296   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
297
298   Property::Map resultMap;
299   resultMap = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
300
301   // check the property values from the returned map from a visual
302   Property::Value* value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
303   DALI_TEST_CHECK( value );
304   DALI_TEST_CHECK( value->Get< int >() == DevelVisual::ANIMATED_VECTOR_IMAGE );
305
306   value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
307   DALI_TEST_CHECK( value );
308   DALI_TEST_CHECK( value->Get< std::string >() == TEST_VECTOR_IMAGE_FILE_NAME );
309
310   value = resultMap.Find( DevelImageVisual::Property::LOOP_COUNT, Property::INTEGER );
311   DALI_TEST_CHECK( value );
312   DALI_TEST_CHECK( value->Get< int >() == 3 );
313
314   value = resultMap.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY );
315   DALI_TEST_CHECK( value );
316
317   Property::Array* result = value->GetArray();
318   DALI_TEST_CHECK( result );
319
320   DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
321   DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
322
323   value = resultMap.Find( DevelImageVisual::Property::STOP_BEHAVIOR, Property::INTEGER );
324   DALI_TEST_CHECK( value );
325   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::StopBehavior::CURRENT_FRAME );
326
327   value = resultMap.Find( DevelImageVisual::Property::LOOPING_MODE, Property::INTEGER );
328   DALI_TEST_CHECK( value );
329   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::LoopingMode::RESTART );
330
331   value = resultMap.Find( DevelImageVisual::Property::CONTENT_INFO, Property::MAP );
332   DALI_TEST_CHECK( value );
333
334   value = resultMap.Find( DevelImageVisual::Property::REDRAW_IN_SCALING_DOWN, Property::BOOLEAN );
335   DALI_TEST_CHECK( value );
336   DALI_TEST_CHECK( value->Get< bool >() == true );    // Check default value
337
338   value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4 );
339   DALI_TEST_CHECK( value );
340   DALI_TEST_EQUALS( value->Get< Vector4 >(), cornerRadius, TEST_LOCATION );
341
342   value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
343   DALI_TEST_CHECK( value );
344   DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::RELATIVE );
345
346   // request AnimatedVectorImageVisual with an URL
347   Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() );
348
349   resultMap.Clear();
350   visual2.CreatePropertyMap( resultMap );
351
352   // check the property values from the returned map from a visual
353   value = resultMap.Find( Toolkit::Visual::Property::TYPE, Property::INTEGER );
354   DALI_TEST_CHECK( value );
355   DALI_TEST_CHECK( value->Get< int >() == DevelVisual::ANIMATED_VECTOR_IMAGE );
356
357   value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
358   DALI_TEST_CHECK( value );
359   DALI_TEST_CHECK( value->Get< std::string >() == TEST_VECTOR_IMAGE_FILE_NAME );
360
361   END_TEST;
362 }
363
364 int UtcDaliAnimatedVectorImageVisualPlayback(void)
365 {
366   ToolkitTestApplication application;
367
368   tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayback" );
369
370   {
371     // request AnimatedVectorImageVisual with a property map
372     VisualFactory factory = VisualFactory::Get();
373     Visual::Base visual = factory.CreateVisual(
374       Property::Map()
375       .Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
376       .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) );
377
378     DummyControl dummyControl = DummyControl::New( true );
379     Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummyControl.GetImplementation() );
380     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
381     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
382
383     Property::Map attributes;
384     tet_infoline( "Test Play action" );
385     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
386
387     application.GetScene().Add( dummyControl );
388     application.SendNotification();
389     application.Render( 16 );
390
391     Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
392     Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
393     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
394
395     tet_infoline( "Test Pause action" );
396     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
397
398     application.SendNotification();
399     application.Render(16);
400
401     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
402     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
403     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED );
404
405     tet_infoline( "Test Play action" );
406     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
407
408     application.SendNotification();
409     application.Render(16);
410
411     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
412     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
413     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
414
415     tet_infoline( "Test Stop action" );
416     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
417
418     application.SendNotification();
419     application.Render(16);
420
421     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
422     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
423     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
424
425     tet_infoline( "Test Stop action again" );
426     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
427
428     application.SendNotification();
429     application.Render(16);
430
431     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
432     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
433     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
434
435     tet_infoline( "Test Play action" );
436     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
437
438     application.SendNotification();
439     application.Render(16);
440
441     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
442     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
443     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
444
445     tet_infoline( "Off stage" );
446     dummyControl.Unparent();
447
448     application.SendNotification();
449     application.Render(16);
450
451     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
452     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
453     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
454
455     tet_infoline( "On stage again" );
456     application.GetScene().Add( dummyControl );
457
458     application.SendNotification();
459     application.Render(16);
460
461     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
462     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
463     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
464
465     tet_infoline( "Test Play action" );
466     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
467
468     application.SendNotification();
469     application.Render(16);
470
471     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
472     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
473     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
474
475     // Change Size
476     Vector3 newSize( 100.0f, 100.0f, 0.0f );
477     dummyControl.SetProperty( Actor::Property::SIZE, newSize );
478
479     application.SendNotification();
480     application.Render(16);
481
482     // Size should be changed
483     Vector3 naturalSize = dummyControl.GetNaturalSize();
484     DALI_TEST_CHECK( naturalSize == newSize );
485
486     dummyControl.Unparent();
487   }
488
489   END_TEST;
490 }
491
492 int UtcDaliAnimatedVectorImageVisualCustomShader(void)
493 {
494   ToolkitTestApplication application;
495   tet_infoline( "UtcDaliAnimatedVectorImageVisualCustomShader Test custom shader" );
496
497   VisualFactory factory = VisualFactory::Get();
498   Property::Map properties;
499   Property::Map shader;
500   const std::string vertexShader = "Foobar";
501   const std::string fragmentShader = "Foobar sampler2D Foobar";
502   shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
503   shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
504
505   properties[Visual::Property::TYPE] = Visual::IMAGE;
506   properties[Visual::Property::SHADER] = shader;
507   properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
508
509   Visual::Base visual = factory.CreateVisual( properties );
510
511   // trigger creation through setting on stage
512   DummyControl dummy = DummyControl::New( true );
513   Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
514   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
515
516   dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
517   dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
518   application.GetScene().Add( dummy );
519
520   application.SendNotification();
521   application.Render();
522
523   Renderer renderer = dummy.GetRendererAt( 0 );
524   Shader shader2 = renderer.GetShader();
525   Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
526   Property::Map* map = value.GetMap();
527   DALI_TEST_CHECK( map );
528
529   std::string resultFragmentShader, resultVertexShader;
530   Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
531   fragment->Get( resultFragmentShader );
532   DALI_TEST_CHECK( resultFragmentShader.find( fragmentShader ) != std::string::npos );
533
534   Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
535   vertex->Get( resultVertexShader );
536   DALI_TEST_CHECK( resultVertexShader.find( vertexShader ) != std::string::npos );
537
538   END_TEST;
539 }
540
541 int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
542 {
543   ToolkitTestApplication application;
544   tet_infoline( "UtcDaliAnimatedVectorImageVisualNaturalSize" );
545
546   VisualFactory factory = VisualFactory::Get();
547   Visual::Base visual = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() );
548   DALI_TEST_CHECK( visual );
549
550   DummyControl actor = DummyControl::New( true );
551   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
552   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
553
554   Vector2 controlSize( 20.f, 30.f );
555   Vector2 naturalSize;
556
557   application.GetScene().Add( actor );
558
559   application.SendNotification();
560   application.Render();
561
562   visual.GetNaturalSize( naturalSize );
563
564   DALI_TEST_EQUALS( naturalSize, Vector2( 100.0f, 100.0f ), TEST_LOCATION );    // 100x100 is the content default size.
565
566   actor.SetProperty( Actor::Property::SIZE, controlSize );
567
568   application.SendNotification();
569   application.Render();
570
571   visual.GetNaturalSize( naturalSize );
572
573   DALI_TEST_EQUALS( naturalSize, controlSize, TEST_LOCATION );
574
575   END_TEST;
576 }
577
578 int UtcDaliAnimatedVectorImageVisualLoopCount(void)
579 {
580   ToolkitTestApplication application;
581   tet_infoline( "UtcDaliAnimatedVectorImageVisualLoopCount" );
582
583   Property::Map propertyMap;
584   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
585              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
586              .Add( DevelImageVisual::Property::LOOP_COUNT, 3  );
587
588   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
589   DALI_TEST_CHECK( visual );
590
591   DummyControl actor = DummyControl::New( true );
592   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
593   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
594
595   Vector2 controlSize( 20.f, 30.f );
596   actor.SetProperty( Actor::Property::SIZE, controlSize );
597
598   application.GetScene().Add( actor );
599
600   Property::Map attributes;
601   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
602
603   application.SendNotification();
604   application.Render();
605
606   // Trigger count is 1 - render a frame
607   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
608
609   // renderer is added to actor
610   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
611   Renderer renderer = actor.GetRendererAt( 0u );
612   DALI_TEST_CHECK( renderer );
613
614   END_TEST;
615 }
616
617 int UtcDaliAnimatedVectorImageVisualPlayRange(void)
618 {
619   ToolkitTestApplication application;
620   tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayRange" );
621
622   int startFrame = 1, endFrame = 3;
623   Property::Array array;
624   array.PushBack( endFrame );
625   array.PushBack( startFrame );
626
627   Property::Map propertyMap;
628   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
629              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
630              .Add( DevelImageVisual::Property::PLAY_RANGE, array  );
631
632   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
633   DALI_TEST_CHECK( visual );
634
635   DummyControl actor = DummyControl::New( true );
636   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
637   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
638
639   Vector2 controlSize( 20.f, 30.f );
640   actor.SetProperty( Actor::Property::SIZE, controlSize );
641
642   application.GetScene().Add( actor );
643
644   Property::Map attributes;
645   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
646
647   application.SendNotification();
648   application.Render();
649
650   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
651
652   // renderer is added to actor
653   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
654   Renderer renderer = actor.GetRendererAt( 0u );
655   DALI_TEST_CHECK( renderer );
656
657   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
658   Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
659
660   int resultStartFrame, resultEndFrame;
661   Property::Array* result = value->GetArray();
662   result->GetElementAt( 0 ).Get( resultStartFrame );
663   result->GetElementAt( 1 ).Get( resultEndFrame );
664
665   DALI_TEST_EQUALS( startFrame, resultStartFrame, TEST_LOCATION );
666   DALI_TEST_EQUALS( endFrame, resultEndFrame, TEST_LOCATION );
667
668   // Set invalid play range
669   array.Clear();
670   array.PushBack( 1 );
671   array.PushBack( 100 );
672
673   attributes.Clear();
674   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
675   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
676
677   application.SendNotification();
678   application.Render();
679
680   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
681
682   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
683   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
684
685   result = value->GetArray();
686   result->GetElementAt( 0 ).Get( resultStartFrame );
687   result->GetElementAt( 1 ).Get( resultEndFrame );
688
689   DALI_TEST_EQUALS( startFrame, resultStartFrame, TEST_LOCATION );  // Should not be changed
690   DALI_TEST_EQUALS( endFrame, resultEndFrame, TEST_LOCATION );
691
692   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Map() );
693
694   application.SendNotification();
695   application.Render();
696
697   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 );
698
699   application.SendNotification();
700   application.Render();
701
702   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
703
704   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
705   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
706   DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION );
707
708   array.Clear();
709   array.PushBack( 0 );
710   array.PushBack( 2 );
711
712   attributes.Clear();
713   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
714   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
715
716   application.SendNotification();
717   application.Render();
718
719   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
720
721   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
722   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
723
724   result = value->GetArray();
725   result->GetElementAt( 0 ).Get( resultStartFrame );
726   result->GetElementAt( 1 ).Get( resultEndFrame );
727
728   DALI_TEST_EQUALS( 0, resultStartFrame, TEST_LOCATION );
729   DALI_TEST_EQUALS( 2, resultEndFrame, TEST_LOCATION );
730
731   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
732   DALI_TEST_EQUALS( value->Get< int >(), 2, TEST_LOCATION );    // CURRENT_FRAME_NUMBER should be changed also.
733
734   END_TEST;
735 }
736
737 int UtcDaliAnimatedVectorImageVisualPlayRangeMarker(void)
738 {
739   ToolkitTestApplication application;
740   tet_infoline( "UtcDaliAnimatedVectorImageVisualPlayRangeMarker" );
741
742   Property::Array array;
743   array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
744
745   Property::Map propertyMap;
746   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
747              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
748              .Add( DevelImageVisual::Property::PLAY_RANGE, array  );
749
750   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
751   DALI_TEST_CHECK( visual );
752
753   DummyControl actor = DummyControl::New( true );
754   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
755   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
756
757   Vector2 controlSize( 20.f, 30.f );
758   actor.SetProperty( Actor::Property::SIZE, controlSize );
759
760   application.GetScene().Add( actor );
761
762   Property::Map attributes;
763   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
764
765   application.SendNotification();
766   application.Render();
767
768   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
769
770   // renderer is added to actor
771   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
772   Renderer renderer = actor.GetRendererAt( 0u );
773   DALI_TEST_CHECK( renderer );
774
775   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
776   Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
777
778   int resultStartFrame, resultEndFrame;
779   Property::Array* result = value->GetArray();
780   result->GetElementAt( 0 ).Get( resultStartFrame );
781   result->GetElementAt( 1 ).Get( resultEndFrame );
782
783   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
784   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_1, resultEndFrame, TEST_LOCATION );
785
786   // Set 2 markers
787   array.Clear();
788   array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
789   array.PushBack( VECTOR_ANIMATION_MARKER_NAME_2 );
790
791   attributes.Clear();
792   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
793   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
794
795   application.SendNotification();
796   application.Render();
797
798   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
799
800   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
801   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
802
803   result = value->GetArray();
804   result->GetElementAt( 0 ).Get( resultStartFrame );
805   result->GetElementAt( 1 ).Get( resultEndFrame );
806
807   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );
808   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
809
810   // Set invalid play range
811   array.Clear();
812   array.PushBack( 1 );
813   array.PushBack( VECTOR_ANIMATION_MARKER_NAME_1 );
814
815   attributes.Clear();
816   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
817   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
818
819   application.SendNotification();
820   application.Render();
821
822   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
823
824   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
825   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
826
827   result = value->GetArray();
828   result->GetElementAt( 0 ).Get( resultStartFrame );
829   result->GetElementAt( 1 ).Get( resultEndFrame );
830
831   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_START_FRAME_1, resultStartFrame, TEST_LOCATION );  // Should not be changed
832   DALI_TEST_EQUALS( VECTOR_ANIMATION_MARKER_END_FRAME_2, resultEndFrame, TEST_LOCATION );
833
834   END_TEST;
835 }
836
837 int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void)
838 {
839   ToolkitTestApplication application;
840   tet_infoline( "UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal" );
841
842   Property::Map propertyMap;
843   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
844              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
845              .Add( DevelImageVisual::Property::LOOP_COUNT, 3  );
846
847   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
848   DALI_TEST_CHECK( visual );
849
850   DummyControl actor = DummyControl::New( true );
851   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
852   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
853
854   DevelControl::VisualEventSignal( actor ).Connect( &VisualEventSignal );
855
856   Vector2 controlSize( 20.f, 30.f );
857   actor.SetProperty( Actor::Property::SIZE, controlSize );
858
859   application.GetScene().Add( actor );
860
861   Property::Map attributes;
862   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
863
864   application.SendNotification();
865   application.Render();
866
867   // Wait for animation finish
868   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
869
870   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
871   Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
872   DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
873
874   DALI_TEST_EQUALS( gAnimationFinishedSignalFired, true, TEST_LOCATION );
875
876   END_TEST;
877 }
878
879 int UtcDaliAnimatedVectorImageVisualJumpTo(void)
880 {
881   ToolkitTestApplication application;
882   tet_infoline( "UtcDaliAnimatedVectorImageVisualJumpTo" );
883
884   Property::Map propertyMap;
885   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
886              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  );
887
888   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
889   DALI_TEST_CHECK( visual );
890
891   tet_printf( "1. Visual is created.\n" );
892
893   DummyControl actor = DummyControl::New( true );
894   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
895   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
896
897   Vector2 controlSize( 20.f, 30.f );
898   actor.SetProperty( Actor::Property::SIZE, controlSize );
899
900   application.GetScene().Add( actor );
901
902   application.SendNotification();
903   application.Render();
904
905   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 2 );
906
907   application.SendNotification();
908   application.Render();
909
910   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
911
912   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
913   Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
914   DALI_TEST_EQUALS( value->Get< int >(), 2, TEST_LOCATION );
915
916   tet_printf( "2. The current frame number is [%d].\n", value->Get< int >() );
917
918   Property::Array array;
919   array.PushBack( 0 );
920   array.PushBack( 2 );
921
922   Property::Map attributes;
923   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
924   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
925
926   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 );
927
928   application.SendNotification();
929   application.Render();
930
931   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
932
933   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
934   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
935   DALI_TEST_EQUALS( value->Get< int >(), 2, TEST_LOCATION );
936
937   tet_printf( "3. The current frame number is [%d].\n", value->Get< int >() );
938
939   // Change play range
940   attributes.Clear();
941   array.Clear();
942
943   array.PushBack( 0 );
944   array.PushBack( 4 );
945
946   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, array );
947   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
948
949   attributes.Clear();
950   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
951
952   application.SendNotification();
953   application.Render();
954
955   // Stop and jump to 3
956   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
957
958   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 );
959
960   application.SendNotification();
961   application.Render();
962
963   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
964
965   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
966   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
967   DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION );
968
969   tet_printf( "4. The current frame number is [%d].\n", value->Get< int >() );
970
971   // Jump to the same position
972   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::JUMP_TO, 3 );
973
974   application.SendNotification();
975   application.Render();
976
977   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
978
979   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
980   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
981   DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION );
982
983   tet_printf( "5. The current frame number is [%d].\n", value->Get< int >() );
984
985   END_TEST;
986 }
987
988 int UtcDaliAnimatedVectorImageVisualUpdateProperty(void)
989 {
990   ToolkitTestApplication application;
991   tet_infoline( "UtcDaliAnimatedVectorImageVisualUpdateProperty" );
992
993   int startFrame = 1, endFrame = 3;
994   Property::Array playRange;
995   playRange.PushBack( startFrame );
996   playRange.PushBack( endFrame );
997
998   Property::Map propertyMap;
999   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1000              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  )
1001              .Add( DevelImageVisual::Property::LOOP_COUNT, 3  )
1002              .Add( DevelImageVisual::Property::PLAY_RANGE, playRange  );
1003
1004   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1005   DALI_TEST_CHECK( visual );
1006
1007   DummyControl actor = DummyControl::New( true );
1008   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1009   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1010
1011   Vector2 controlSize( 20.f, 30.f );
1012   actor.SetProperty( Actor::Property::SIZE, controlSize );
1013
1014   application.GetScene().Add( actor );
1015
1016   application.SendNotification();
1017   application.Render();
1018
1019   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
1020
1021   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1022   Property::Value* value = map.Find( DevelImageVisual::Property::LOOP_COUNT );
1023   DALI_TEST_EQUALS( value->Get< int >(), 3, TEST_LOCATION );
1024
1025   value = map.Find( DevelImageVisual::Property::PLAY_RANGE, Property::ARRAY );
1026   DALI_TEST_CHECK( value );
1027
1028   Property::Array* result = value->GetArray();
1029   DALI_TEST_CHECK( result );
1030
1031   DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
1032   DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
1033
1034   playRange.Clear();
1035   playRange.PushBack( 0 );
1036   playRange.PushBack( 2 );
1037
1038   Property::Map attributes;
1039   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, playRange );
1040   attributes.Add( DevelImageVisual::Property::LOOP_COUNT, 5 );
1041
1042   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1043
1044   application.SendNotification();
1045   application.Render();
1046
1047   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
1048
1049   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1050   value = map.Find( DevelImageVisual::Property::LOOP_COUNT );
1051   DALI_TEST_EQUALS( value->Get< int >(), 5, TEST_LOCATION );
1052
1053   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
1054   result = value->GetArray();
1055   DALI_TEST_CHECK( result );
1056
1057   DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == 0 );
1058   DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == 2 );
1059
1060   attributes.Clear();
1061
1062   playRange.Clear();
1063   playRange.PushBack( startFrame );
1064   playRange.PushBack( endFrame );
1065
1066   attributes.Add( DevelImageVisual::Property::PLAY_RANGE, playRange );
1067
1068   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1069
1070   application.SendNotification();
1071   application.Render();
1072
1073   std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );    // wait for next rasterize thread run
1074
1075   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1076   value = map.Find( DevelImageVisual::Property::PLAY_RANGE );
1077
1078   result = value->GetArray();
1079   DALI_TEST_CHECK( result );
1080
1081   DALI_TEST_CHECK( result->GetElementAt( 0 ).Get< int >() == startFrame );
1082   DALI_TEST_CHECK( result->GetElementAt( 1 ).Get< int >() == endFrame );
1083
1084   // Play and update property
1085   attributes.Clear();
1086   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1087
1088   application.SendNotification();
1089   application.Render();
1090
1091   attributes.Add( DevelImageVisual::Property::LOOP_COUNT, 10 );
1092
1093   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1094
1095   application.SendNotification();
1096   application.Render();
1097
1098   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1099   value = map.Find( DevelImageVisual::Property::LOOP_COUNT );
1100   DALI_TEST_EQUALS( value->Get< int >(), 10, TEST_LOCATION );
1101
1102   END_TEST;
1103 }
1104
1105 int UtcDaliAnimatedVectorImageVisualStopBehavior(void)
1106 {
1107   ToolkitTestApplication application;
1108   tet_infoline( "UtcDaliAnimatedVectorImageVisualStopBehavior" );
1109
1110   Property::Map propertyMap;
1111   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1112              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
1113              .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
1114              .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME );
1115
1116   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1117   DALI_TEST_CHECK( visual );
1118
1119   DummyControl actor = DummyControl::New( true );
1120   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1121   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1122
1123   Vector2 controlSize( 20.f, 30.f );
1124   actor.SetProperty( Actor::Property::SIZE, controlSize );
1125
1126   application.GetScene().Add( actor );
1127
1128   Property::Map attributes;
1129   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1130
1131   application.SendNotification();
1132   application.Render();
1133
1134   // Trigger count is 1 - animation finished
1135   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1136
1137   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1138   Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1139   DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION );  // Should be the first frame
1140
1141   // Change stop behavior
1142   attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME );
1143
1144   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1145
1146   attributes.Clear();
1147
1148   // Play again
1149   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1150
1151   application.SendNotification();
1152   application.Render();
1153
1154   // Trigger count is 1 - animation finished
1155   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1156
1157   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1158
1159   Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER );
1160   int totalFrameNumber = value1->Get< int >();
1161
1162   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1163   DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION );  // Should be the last frame
1164
1165   // Change stop behavior
1166   attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME );
1167   attributes.Add( DevelImageVisual::Property::LOOP_COUNT, -1 );
1168
1169   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1170
1171   attributes.Clear();
1172
1173   // Play again
1174   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1175
1176   application.SendNotification();
1177   application.Render();
1178
1179   // Pause
1180   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
1181
1182   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1183   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1184   int currentFrameNumber = value->Get< int >();
1185
1186   // Stop
1187   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
1188
1189   application.SendNotification();
1190   application.Render( 16 );
1191
1192   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1193   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1194   DALI_TEST_EQUALS( value->Get< int >(), currentFrameNumber, TEST_LOCATION );  // Should be same with currentFrameNumber
1195
1196   END_TEST;
1197 }
1198
1199 int UtcDaliAnimatedVectorImageVisualLoopingMode(void)
1200 {
1201   ToolkitTestApplication application;
1202   tet_infoline( "UtcDaliAnimatedVectorImageVisualLoopingMode" );
1203
1204   Property::Map propertyMap;
1205   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1206              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME )
1207              .Add( DevelImageVisual::Property::LOOP_COUNT, 3 )
1208              .Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME )
1209              .Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::AUTO_REVERSE );
1210
1211   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1212   DALI_TEST_CHECK( visual );
1213
1214   DummyControl actor = DummyControl::New( true );
1215   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1216   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1217
1218   Vector2 controlSize( 20.f, 30.f );
1219   actor.SetProperty( Actor::Property::SIZE, controlSize );
1220
1221   application.GetScene().Add( actor );
1222
1223   Property::Map attributes;
1224   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1225
1226   application.SendNotification();
1227   application.Render();
1228
1229   // Trigger count is 1 - animation finished
1230   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1231
1232   Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1233   Property::Value* value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1234   DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION );  // Should be the first frame because of auto reverse
1235
1236   // Change stop behavior
1237   attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::CURRENT_FRAME );
1238
1239   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1240
1241   // Play again
1242   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1243
1244   application.SendNotification();
1245   application.Render();
1246
1247   // Trigger count is 1 - animation finished
1248   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1249
1250   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1251   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1252   DALI_TEST_EQUALS( value->Get< int >(), 0, TEST_LOCATION );  // Should be the first frame
1253
1254   // Change looping mode
1255   attributes.Add( DevelImageVisual::Property::LOOPING_MODE, DevelImageVisual::LoopingMode::RESTART );
1256
1257   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1258
1259   // Play again
1260   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1261
1262   application.SendNotification();
1263   application.Render();
1264
1265   // Trigger count is 1 - animation finished
1266   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1267
1268   Property::Value* value1 = map.Find( DevelImageVisual::Property::TOTAL_FRAME_NUMBER );
1269   int totalFrameNumber = value1->Get< int >();
1270
1271   map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1272   value = map.Find( DevelImageVisual::Property::CURRENT_FRAME_NUMBER );
1273   DALI_TEST_EQUALS( value->Get< int >(), totalFrameNumber - 1, TEST_LOCATION );  // Should be the last frame
1274
1275   END_TEST;
1276 }
1277
1278 int UtcDaliAnimatedVectorImageVisualPropertyNotification(void)
1279 {
1280   ToolkitTestApplication application;
1281   tet_infoline( "UtcDaliAnimatedVectorImageVisualPropertyNotification" );
1282
1283   Property::Map propertyMap;
1284   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1285              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME  );
1286
1287   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1288   DALI_TEST_CHECK( visual );
1289
1290   DummyControl actor = DummyControl::New( true );
1291   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1292   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1293
1294   Vector2 controlSize( 20.f, 30.f );
1295   Vector3 controlScale( 2.0f, 2.0f, 1.0f );
1296   actor.SetProperty( Actor::Property::SIZE, controlSize );
1297   actor.SetProperty( Actor::Property::SCALE, controlScale );
1298
1299   application.GetScene().Add( actor );
1300
1301   application.SendNotification();
1302   application.Render();
1303
1304   application.SendNotification();
1305   application.Render();
1306
1307   Renderer renderer = actor.GetRendererAt( 0u );
1308   DALI_TEST_CHECK( renderer );
1309
1310   auto textureSet = renderer.GetTextures();
1311   auto texture = textureSet.GetTexture(0);
1312
1313   DALI_TEST_EQUALS( controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION );
1314   DALI_TEST_EQUALS( controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION );
1315
1316   // Change scale and size
1317   controlSize = Vector2( 50.f, 40.f );
1318   controlScale= Vector3( 0.5f, 0.5f, 1.0f );
1319   actor.SetProperty( Actor::Property::SIZE, controlSize );
1320   actor.SetProperty( Actor::Property::SCALE, controlScale );
1321
1322   application.SendNotification();
1323   application.Render();
1324
1325   application.SendNotification();
1326   application.Render();
1327
1328   renderer = actor.GetRendererAt( 0u );
1329   DALI_TEST_CHECK( renderer );
1330
1331   textureSet = renderer.GetTextures();
1332   texture = textureSet.GetTexture(0);
1333
1334   DALI_TEST_EQUALS( controlSize.width * controlScale.width, texture.GetWidth(), TEST_LOCATION );
1335   DALI_TEST_EQUALS( controlSize.height * controlScale.height, texture.GetHeight(), TEST_LOCATION );
1336
1337   END_TEST;
1338 }
1339
1340 int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
1341 {
1342   ToolkitTestApplication application;
1343   tet_infoline( "UtcDaliAnimatedVectorImageVisualMultipleInstances" );
1344
1345   Property::Map propertyMap;
1346   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1347              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME );
1348
1349   Visual::Base visual1 = VisualFactory::Get().CreateVisual( propertyMap );
1350   DALI_TEST_CHECK( visual1 );
1351
1352   DummyControl actor1 = DummyControl::New( true );
1353   DummyControlImpl& dummyImpl1 = static_cast< DummyControlImpl& >( actor1.GetImplementation() );
1354   dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
1355
1356   Vector2 controlSize( 20.f, 30.f );
1357   actor1.SetProperty( Actor::Property::SIZE, controlSize );
1358
1359   application.GetScene().Add( actor1 );
1360
1361   propertyMap.Clear();
1362   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1363              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME );
1364
1365   Visual::Base visual2 = VisualFactory::Get().CreateVisual( propertyMap );
1366   DALI_TEST_CHECK( visual2 );
1367
1368   DummyControl actor2 = DummyControl::New( true );
1369   DummyControlImpl& dummyImpl2 = static_cast< DummyControlImpl& >( actor2.GetImplementation() );
1370   dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual2 );
1371
1372   actor2.SetProperty( Actor::Property::SIZE, controlSize );
1373
1374   application.GetScene().Add( actor2 );
1375
1376   DevelControl::DoAction( actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map() );
1377
1378   application.SendNotification();
1379   application.Render();
1380
1381   std::this_thread::sleep_for( std::chrono::milliseconds( 200 ) );
1382
1383   Property::Map attributes;
1384   attributes.Add( DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::LAST_FRAME );
1385
1386   DevelControl::DoAction( actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1387   DevelControl::DoAction( actor2, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::UPDATE_PROPERTY, attributes );
1388
1389   DevelControl::DoAction( actor1, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, Property::Map() );
1390
1391   // renderer is added to actor
1392   DALI_TEST_CHECK( actor1.GetRendererCount() == 1u );
1393   Renderer renderer1 = actor1.GetRendererAt( 0u );
1394   DALI_TEST_CHECK( renderer1 );
1395
1396   // renderer is added to actor
1397   DALI_TEST_CHECK( actor2.GetRendererCount() == 1u );
1398   Renderer renderer2 = actor2.GetRendererAt( 0u );
1399   DALI_TEST_CHECK( renderer2 );
1400
1401   END_TEST;
1402 }
1403
1404 int UtcDaliAnimatedVectorImageVisualControlVisibilityChanged(void)
1405 {
1406   ToolkitTestApplication application;
1407   tet_infoline( "UtcDaliAnimatedVectorImageVisualControlVisibilityChanged" );
1408
1409   Property::Map propertyMap;
1410   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1411              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME );
1412
1413   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1414   DALI_TEST_CHECK( visual );
1415
1416   DummyControl actor = DummyControl::New( true );
1417   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1418   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1419
1420   Vector2 controlSize( 20.f, 30.f );
1421   actor.SetProperty( Actor::Property::SIZE, controlSize );
1422
1423   application.GetScene().Add( actor );
1424
1425   application.SendNotification();
1426   application.Render();
1427
1428   Property::Map attributes;
1429   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1430
1431   application.SendNotification();
1432   application.Render();
1433
1434   // Check rendering behavior
1435   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1436   Renderer renderer = actor.GetRendererAt( 0u );
1437   DALI_TEST_CHECK( renderer );
1438   DALI_TEST_CHECK( renderer.GetProperty< int >( DevelRenderer::Property::RENDERING_BEHAVIOR ) == DevelRenderer::Rendering::CONTINUOUSLY );
1439
1440   actor.SetProperty( Actor::Property::VISIBLE, false );
1441
1442   application.SendNotification();
1443   application.Render();
1444
1445   // Check rendering behavior again
1446   DALI_TEST_CHECK( renderer.GetProperty< int >( DevelRenderer::Property::RENDERING_BEHAVIOR ) == DevelRenderer::Rendering::IF_REQUIRED );
1447
1448   END_TEST;
1449 }
1450
1451 int UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged(void)
1452 {
1453   ToolkitTestApplication application;
1454   tet_infoline( "UtcDaliAnimatedVectorImageVisualWindowVisibilityChanged" );
1455
1456   Property::Map propertyMap;
1457   propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1458              .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME );
1459
1460   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1461   DALI_TEST_CHECK( visual );
1462
1463   DummyControl actor = DummyControl::New( true );
1464   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1465   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1466
1467   Vector2 controlSize( 20.f, 30.f );
1468   actor.SetProperty( Actor::Property::SIZE, controlSize );
1469
1470   application.GetScene().Add( actor );
1471
1472   application.SendNotification();
1473   application.Render();
1474
1475   Property::Map attributes;
1476   DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1477
1478   application.SendNotification();
1479   application.Render();
1480
1481   // Check rendering behavior
1482   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1483   Renderer renderer = actor.GetRendererAt( 0u );
1484   DALI_TEST_CHECK( renderer );
1485   DALI_TEST_CHECK( renderer.GetProperty< int >( DevelRenderer::Property::RENDERING_BEHAVIOR ) == DevelRenderer::Rendering::CONTINUOUSLY );
1486
1487   Window window = DevelWindow::Get( actor );
1488   window.Hide();
1489
1490   application.SendNotification();
1491   application.Render();
1492
1493   // Check rendering behavior again
1494   DALI_TEST_CHECK( renderer.GetProperty< int >( DevelRenderer::Property::RENDERING_BEHAVIOR ) == DevelRenderer::Rendering::IF_REQUIRED );
1495
1496   END_TEST;
1497 }
1498
1499 int UtcDaliAnimatedVectorImageVisualInvalidFile(void)
1500 {
1501   ToolkitTestApplication application;
1502   tet_infoline("Request loading with invalid file - should draw broken image");
1503
1504   TestGlAbstraction& gl = application.GetGlAbstraction();
1505   TraceCallStack& textureTrace = gl.GetTextureTrace();
1506   textureTrace.Enable(true);
1507
1508   Property::Map propertyMap;
1509   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1510              .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_FILE_NAME);
1511
1512   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1513   DALI_TEST_CHECK(visual);
1514
1515   DummyControl actor = DummyControl::New(true);
1516   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >(actor.GetImplementation());
1517   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1518
1519   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1520
1521   application.GetScene().Add(actor);
1522
1523   application.SendNotification();
1524   application.Render();
1525
1526   // Check resource status
1527   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1528   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1529
1530   // The broken image should be shown.
1531   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1532   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1533
1534   END_TEST;
1535 }
1536
1537 int UtcDaliAnimatedVectorImageVisualLoadRiveFileP(void)
1538 {
1539   ToolkitTestApplication application;
1540   tet_infoline( "UtcDaliAnimatedVectorImageVisualLoadRiveFile: Request animated vector image visual with a rive url" );
1541
1542   VisualFactory factory = VisualFactory::Get();
1543   Visual::Base visual = factory.CreateVisual( TEST_VECTOR_IMAGE_RIVE_FILE_NAME, ImageDimensions() );
1544   DALI_TEST_CHECK( visual );
1545
1546   DummyControl actor = DummyControl::New( true );
1547   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1548   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1549   actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
1550   application.GetScene().Add( actor );
1551
1552   application.SendNotification();
1553   application.Render();
1554
1555   // renderer is added to actor
1556   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1557   Renderer renderer = actor.GetRendererAt( 0u );
1558   DALI_TEST_CHECK( renderer );
1559
1560   // Test SetOffScene().
1561   actor.Unparent();
1562   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1563
1564   END_TEST;
1565 }
1566
1567 int UtcDaliAnimatedVectorImageVisualLoadRiveFileN(void)
1568 {
1569   ToolkitTestApplication application;
1570   tet_infoline("Request loading with invalid rive file - should draw broken image");
1571
1572   TestGlAbstraction& gl = application.GetGlAbstraction();
1573   TraceCallStack& textureTrace = gl.GetTextureTrace();
1574   textureTrace.Enable(true);
1575
1576   Property::Map propertyMap;
1577   propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE)
1578              .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_RIVE_FILE_NAME);
1579
1580   Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap);
1581   DALI_TEST_CHECK(visual);
1582
1583   DummyControl actor = DummyControl::New(true);
1584   DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >(actor.GetImplementation());
1585   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1586
1587   actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f));
1588
1589   application.GetScene().Add(actor);
1590
1591   application.SendNotification();
1592   application.Render();
1593
1594   // Check resource status
1595   Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
1596   DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1597
1598   // The broken image should be shown.
1599   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1600   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1601
1602   END_TEST;
1603 }
1604
1605 int UtcDaliAnimatedVectorImageVisualPlaybackRiveFile(void)
1606 {
1607   ToolkitTestApplication application;
1608
1609   tet_infoline( "UtcDaliAnimatedVectorImageVisualPlaybackRiveFile" );
1610
1611   {
1612     // request AnimatedVectorImageVisual for Rive with a property map
1613     VisualFactory factory = VisualFactory::Get();
1614     Visual::Base visual = factory.CreateVisual(
1615       Property::Map()
1616       .Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE )
1617       .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_RIVE_FILE_NAME ) );
1618
1619     DummyControl dummyControl = DummyControl::New( true );
1620     Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummyControl.GetImplementation() );
1621     dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1622     dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1623
1624     Property::Map attributes;
1625     tet_infoline( "Test Play action" );
1626     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1627
1628     application.GetScene().Add( dummyControl );
1629     application.SendNotification();
1630     application.Render( 16 );
1631
1632     Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1633     Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1634     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
1635
1636     tet_infoline( "Test Pause action" );
1637     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes );
1638
1639     application.SendNotification();
1640     application.Render(16);
1641
1642     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1643     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1644     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED );
1645
1646     tet_infoline( "Test Play action" );
1647     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1648
1649     application.SendNotification();
1650     application.Render(16);
1651
1652     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1653     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1654     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
1655
1656     tet_infoline( "Test Stop action" );
1657     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
1658
1659     application.SendNotification();
1660     application.Render(16);
1661
1662     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1663     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1664     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
1665
1666     tet_infoline( "Test Stop action again" );
1667     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes );
1668
1669     application.SendNotification();
1670     application.Render(16);
1671
1672     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1673     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1674     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
1675
1676     tet_infoline( "Test Play action" );
1677     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1678
1679     application.SendNotification();
1680     application.Render(16);
1681
1682     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1683     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1684     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
1685
1686     tet_infoline( "Off stage" );
1687     dummyControl.Unparent();
1688
1689     application.SendNotification();
1690     application.Render(16);
1691
1692     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1693     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1694     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
1695
1696     tet_infoline( "On stage again" );
1697     application.GetScene().Add( dummyControl );
1698
1699     application.SendNotification();
1700     application.Render(16);
1701
1702     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1703     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1704     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED );
1705
1706     tet_infoline( "Test Play action" );
1707     DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes );
1708
1709     application.SendNotification();
1710     application.Render(16);
1711
1712     map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL );
1713     value = map.Find( DevelImageVisual::Property::PLAY_STATE );
1714     DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING );
1715
1716     // Change Size
1717     Vector3 newSize( 100.0f, 100.0f, 0.0f );
1718     dummyControl.SetProperty( Actor::Property::SIZE, newSize );
1719
1720     application.SendNotification();
1721     application.Render(16);
1722
1723     // Size should be changed
1724     Vector3 naturalSize = dummyControl.GetNaturalSize();
1725     DALI_TEST_CHECK( naturalSize == newSize );
1726
1727     dummyControl.Unparent();
1728   }
1729
1730   END_TEST;
1731 }