c329ccc377c8dacf8b6f5f8cf11896d2d3c01704
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Visual.cpp
1 /*
2  * Copyright (c) 2016 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 <dali-toolkit-test-suite-utils.h>
20 #include <dali/public-api/rendering/renderer.h>
21 #include <dali/public-api/rendering/texture-set.h>
22 #include <dali/public-api/rendering/shader.h>
23 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 using namespace Dali;
27 using namespace Dali::Toolkit;
28
29 namespace
30 {
31 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
32 const char* TEST_NPATCH_FILE_NAME =  "gallery_image_01.9.jpg";
33 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
34 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
35 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
36 const char* TEST_RESOURCE_LOCATION = TEST_RESOURCE_DIR "/";
37 }
38
39 void dali_visual_startup(void)
40 {
41   test_return_value = TET_UNDEF;
42 }
43
44 void dali_visual_cleanup(void)
45 {
46   test_return_value = TET_PASS;
47 }
48
49 int UtcDaliVisualCopyAndAssignment(void)
50 {
51   ToolkitTestApplication application;
52   tet_infoline( "UtcDaliVisualCopyAndAssignment" );
53
54   VisualFactory factory = VisualFactory::Get();
55   Property::Map propertyMap;
56   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
57   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
58   Visual::Base visual = factory.CreateVisual( propertyMap );
59
60   Visual::Base visualCopy( visual );
61   DALI_TEST_CHECK(visual == visualCopy);
62
63   Visual::Base emptyVisual;
64   Visual::Base emptyVisualCopy( emptyVisual );
65   DALI_TEST_CHECK(emptyVisual == emptyVisualCopy);
66
67   Visual::Base visualEquals;
68   visualEquals = visual;
69   DALI_TEST_CHECK(visual == visualEquals);
70
71   Visual::Base emptyVisualEquals;
72   emptyVisualEquals = emptyVisual;
73   DALI_TEST_CHECK( emptyVisual == emptyVisualEquals );
74
75   //self assignment
76   visual = visual;
77   DALI_TEST_CHECK( visual = visualCopy );
78
79   END_TEST;
80 }
81
82 int UtcDaliVisualSetGetDepthIndex(void)
83 {
84   ToolkitTestApplication application;
85   tet_infoline( "UtcDaliVisualSetDepthIndex" );
86
87   VisualFactory factory = VisualFactory::Get();
88   Property::Map propertyMap;
89   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
90   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
91   Visual::Base visual = factory.CreateVisual( propertyMap );
92
93   visual.SetDepthIndex( 1.f );
94
95   Actor actor = Actor::New();
96   actor.SetSize(200.f, 200.f);
97   Stage::GetCurrent().Add( actor );
98   visual.SetOnStage( actor );
99
100   int depthIndex = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::DEPTH_INDEX );
101   DALI_TEST_EQUALS( depthIndex, 1, TEST_LOCATION );
102   DALI_TEST_EQUALS( visual.GetDepthIndex(), 1.f, TEST_LOCATION );
103
104   visual.SetDepthIndex( -1.f );
105   depthIndex = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::DEPTH_INDEX );
106   DALI_TEST_EQUALS( depthIndex, -1, TEST_LOCATION );
107   DALI_TEST_EQUALS( visual.GetDepthIndex(), -1.f, TEST_LOCATION );
108
109   END_TEST;
110 }
111
112 int UtcDaliVisualSize(void)
113 {
114   ToolkitTestApplication application;
115   tet_infoline( "UtcDaliVisualGetNaturalSize" );
116
117   VisualFactory factory = VisualFactory::Get();
118   Vector2 visualSize( 20.f, 30.f );
119   Vector2 naturalSize;
120
121   // color colorVisual
122   Dali::Property::Map map;
123   map[ Visual::Property::TYPE ] = Visual::COLOR;
124   map[ ColorVisual::Property::MIX_COLOR ] = Color::MAGENTA;
125   Visual::Base colorVisual = factory.CreateVisual( map );
126   colorVisual.SetSize( visualSize );
127   DALI_TEST_EQUALS( colorVisual.GetSize(), visualSize, TEST_LOCATION );
128   colorVisual.GetNaturalSize(naturalSize);
129   DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );
130
131   // image visual
132   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
133   Visual::Base imageVisual = factory.CreateVisual( image );
134   imageVisual.SetSize( visualSize );
135   DALI_TEST_EQUALS( imageVisual.GetSize(), visualSize, TEST_LOCATION );
136   imageVisual.GetNaturalSize(naturalSize);
137   DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 200.f), TEST_LOCATION );
138
139   // n patch visual
140   TestPlatformAbstraction& platform = application.GetPlatform();
141   Vector2 testSize(80.f, 160.f);
142   platform.SetClosestImageSize(testSize);
143   image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
144   Visual::Base nPatchVisual = factory.CreateVisual( image );
145   nPatchVisual.SetSize( visualSize );
146   DALI_TEST_EQUALS( nPatchVisual.GetSize(), visualSize, TEST_LOCATION );
147   nPatchVisual.GetNaturalSize(naturalSize);
148   DALI_TEST_EQUALS( naturalSize, testSize, TEST_LOCATION );
149
150   // border visual
151   float borderSize = 5.f;
152   map.Clear();
153   map[ Visual::Property::TYPE ] = Visual::BORDER;
154   map[ BorderVisual::Property::COLOR  ] = Color::RED;
155   map[ BorderVisual::Property::SIZE   ] = borderSize;
156   Visual::Base borderVisual = factory.CreateVisual( map );
157   borderVisual.SetSize( visualSize );
158   DALI_TEST_EQUALS( borderVisual.GetSize(), visualSize, TEST_LOCATION );
159   borderVisual.GetNaturalSize(naturalSize);
160   DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );
161
162   // gradient gradientVisual
163   Property::Map propertyMap;
164   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
165   Vector2 start(-1.f, -1.f);
166   Vector2 end(1.f, 1.f);
167   propertyMap.Insert(GradientVisual::Property::START_POSITION,   start);
168   propertyMap.Insert(GradientVisual::Property::END_POSITION,   end);
169   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   Vector2(0.f, 1.f));
170   Property::Array stopColors;
171   stopColors.PushBack( Color::RED );
172   stopColors.PushBack( Color::GREEN );
173   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
174   Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
175   gradientVisual.SetSize( visualSize );
176   DALI_TEST_EQUALS( gradientVisual.GetSize(), visualSize, TEST_LOCATION );
177   gradientVisual.GetNaturalSize(naturalSize);
178   DALI_TEST_EQUALS( naturalSize, Vector2::ZERO,TEST_LOCATION );
179
180   // svg visual
181   Visual::Base svgVisual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
182   svgVisual.SetSize( visualSize );
183   DALI_TEST_EQUALS( svgVisual.GetSize(), visualSize, TEST_LOCATION );
184   svgVisual.GetNaturalSize(naturalSize);
185   // TEST_SVG_FILE:
186   //  <svg width="100" height="100">
187   //  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
188   //  </svg>
189   DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION );
190
191   // svg visual with a size
192   Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions(200, 200) );
193   DALI_TEST_EQUALS( svgVisual2.GetSize(), Vector2( 200.f, 200.f ), TEST_LOCATION );
194   svgVisual2.GetNaturalSize(naturalSize);
195   DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); // Natural size should still be 100, 100
196
197   // Batch Image visual
198   propertyMap.Clear();
199   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
200   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
201   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
202   Visual::Base batchImageVisual = factory.CreateVisual( propertyMap );
203   batchImageVisual.SetSize( visualSize );
204   DALI_TEST_EQUALS( batchImageVisual.GetSize(), visualSize, TEST_LOCATION );
205   batchImageVisual.GetNaturalSize( naturalSize );
206   DALI_TEST_EQUALS( naturalSize, Vector2( 80.0f, 160.0f ), TEST_LOCATION );
207
208   END_TEST;
209 }
210
211 int UtcDaliVisualSetOnOffStage(void)
212 {
213   ToolkitTestApplication application;
214   tet_infoline( "UtcDaliVisualSetDepthIndex" );
215
216   VisualFactory factory = VisualFactory::Get();
217   Property::Map propertyMap;
218   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
219   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
220   Visual::Base visual = factory.CreateVisual( propertyMap );
221
222   Actor actor = Actor::New();
223   actor.SetSize(200.f, 200.f);
224   Stage::GetCurrent().Add( actor );
225
226   application.SendNotification();
227   application.Render(0);
228   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
229
230   visual.SetOnStage( actor );
231   application.SendNotification();
232   application.Render(0);
233   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
234
235   visual.SetOffStage( actor );
236   application.SendNotification();
237   application.Render(0);
238   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
239
240   END_TEST;
241 }
242
243 int UtcDaliVisualRemoveAndReset(void)
244 {
245   ToolkitTestApplication application;
246   tet_infoline( "intUtcDaliVisualRemoveAndReset" );
247
248   VisualFactory factory = VisualFactory::Get();
249
250   Actor actor = Actor::New();
251   actor.SetSize(200.f, 200.f);
252   Stage::GetCurrent().Add( actor );
253
254   Visual::Base imageVisual;
255   // test calling RemoveAndReset with an empty handle
256   try
257   {
258     imageVisual.RemoveAndReset( actor );
259     tet_result(TET_PASS);
260   }
261   catch (DaliException& exception)
262   {
263     tet_result(TET_FAIL);
264   }
265
266   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
267   imageVisual = factory.CreateVisual(image);
268   DALI_TEST_CHECK( imageVisual );
269
270   imageVisual.SetOnStage( actor );
271   application.SendNotification();
272   application.Render(0);
273   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
274
275   imageVisual.RemoveAndReset( actor );
276   application.SendNotification();
277   application.Render(0);
278   DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); // visual is removed from actor
279   DALI_TEST_CHECK( !imageVisual ); // visual is reset
280
281   END_TEST;
282 }
283
284 int UtcDaliVisualGetPropertyMap1(void)
285 {
286   ToolkitTestApplication application;
287   tet_infoline( "UtcDaliVisualGetPropertyMap1: ColorVisual" );
288
289   VisualFactory factory = VisualFactory::Get();
290   Property::Map propertyMap;
291   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
292   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
293   Visual::Base colorVisual = factory.CreateVisual( propertyMap );
294
295   Property::Map resultMap;
296   colorVisual.CreatePropertyMap( resultMap );
297
298   Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
299   DALI_TEST_CHECK( typeValue );
300   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::COLOR );
301
302   Property::Value* colorValue = resultMap.Find( ColorVisual::Property::MIX_COLOR,  Property::VECTOR4 );
303   DALI_TEST_CHECK( colorValue );
304   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
305
306   // change the blend color
307   Actor actor;
308   colorVisual.RemoveAndReset( actor );
309   propertyMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
310   colorVisual = factory.CreateVisual( propertyMap  );
311   colorVisual.CreatePropertyMap( resultMap );
312
313   colorValue = resultMap.Find( ColorVisual::Property::MIX_COLOR,  Property::VECTOR4 );
314   DALI_TEST_CHECK( colorValue );
315   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
316
317   // Test the properties. TODO: to be completed.
318   colorVisual.SetProperty( ColorVisual::Property::MIX_COLOR, Color::RED );
319   Property::Value value = colorVisual.GetProperty( ColorVisual::Property::MIX_COLOR );
320
321   END_TEST;
322 }
323
324 int UtcDaliVisualGetPropertyMap2(void)
325 {
326   ToolkitTestApplication application;
327   tet_infoline( "UtcDaliVisualGetPropertyMap2: BorderVisual" );
328
329   VisualFactory factory = VisualFactory::Get();
330   Property::Map propertyMap;
331   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
332   propertyMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
333   propertyMap.Insert(BorderVisual::Property::SIZE,  5.f);
334   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
335
336   Property::Map resultMap;
337   borderVisual.CreatePropertyMap( resultMap );
338
339   // check the property values from the returned map from visual
340   Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
341   DALI_TEST_CHECK( typeValue );
342   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::BORDER );
343
344   Property::Value* colorValue = resultMap.Find( BorderVisual::Property::COLOR,  Property::VECTOR4 );
345   DALI_TEST_CHECK( colorValue );
346   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
347
348   Property::Value* sizeValue = resultMap.Find( BorderVisual::Property::SIZE,  Property::FLOAT );
349   DALI_TEST_CHECK( sizeValue );
350   DALI_TEST_CHECK( sizeValue->Get<float>() == 5.f );
351
352   Property::Map propertyMap1;
353   propertyMap1[ Visual::Property::TYPE ] = Visual::BORDER;
354   propertyMap1[ BorderVisual::Property::COLOR  ] = Color::CYAN;
355   propertyMap1[ BorderVisual::Property::SIZE   ] = 10.0f;
356   borderVisual = factory.CreateVisual( propertyMap1 );
357   borderVisual.CreatePropertyMap( resultMap );
358
359   typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
360   DALI_TEST_CHECK( typeValue );
361   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::BORDER );
362
363   colorValue = resultMap.Find( BorderVisual::Property::COLOR,  Property::VECTOR4 );
364   DALI_TEST_CHECK( colorValue );
365   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
366
367   colorValue = resultMap.Find( BorderVisual::Property::SIZE,  Property::FLOAT );
368   DALI_TEST_CHECK( colorValue );
369   DALI_TEST_CHECK( colorValue->Get<float>() == 10.f );
370
371   // Test the properties. TODO: to be completed.
372   borderVisual.SetProperty( BorderVisual::Property::COLOR, Color::RED );
373   Property::Value value = borderVisual.GetProperty( BorderVisual::Property::COLOR );
374
375   END_TEST;
376 }
377
378 int UtcDaliVisualGetPropertyMap3(void)
379 {
380   ToolkitTestApplication application;
381   tet_infoline( "UtcDaliVisualGetPropertyMap3: linear GradientVisual" );
382
383   VisualFactory factory = VisualFactory::Get();
384   DALI_TEST_CHECK( factory );
385
386   Property::Map propertyMap;
387   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
388
389   Vector2 start(-1.f, -1.f);
390   Vector2 end(1.f, 1.f);
391   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
392   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
393   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
394
395   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   Vector2(0.2f, 0.8f));
396
397   Property::Array stopColors;
398   stopColors.PushBack( Color::RED );
399   stopColors.PushBack( Color::GREEN );
400   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
401
402   Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
403
404   Property::Map resultMap;
405   gradientVisual.CreatePropertyMap( resultMap );
406
407   // check the property values from the returned map from visual
408   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
409   DALI_TEST_CHECK( value );
410   DALI_TEST_CHECK( value->Get<int>() == Visual::GRADIENT );
411
412   value = resultMap.Find( GradientVisual::Property::UNITS,  Property::INTEGER );
413   DALI_TEST_CHECK( value );
414   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::Units::OBJECT_BOUNDING_BOX );
415
416   value = resultMap.Find( GradientVisual::Property::SPREAD_METHOD,   Property::INTEGER );
417   DALI_TEST_CHECK( value );
418   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::SpreadMethod::REPEAT );
419
420   value = resultMap.Find( GradientVisual::Property::START_POSITION,   Property::VECTOR2 );
421   DALI_TEST_CHECK( value );
422   DALI_TEST_EQUALS( value->Get<Vector2>(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION );
423
424   value = resultMap.Find( GradientVisual::Property::END_POSITION,   Property::VECTOR2 );
425   DALI_TEST_CHECK( value );
426   DALI_TEST_EQUALS( value->Get<Vector2>(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION );
427
428   value = resultMap.Find( GradientVisual::Property::STOP_OFFSET,   Property::ARRAY );
429   DALI_TEST_CHECK( value );
430   Property::Array* offsetArray = value->GetArray();
431   DALI_TEST_CHECK( offsetArray->Count() == 2 );
432   DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
433   DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
434
435   value = resultMap.Find( GradientVisual::Property::STOP_COLOR,   Property::ARRAY );
436   DALI_TEST_CHECK( value );
437   Property::Array* colorArray = value->GetArray();
438   DALI_TEST_CHECK( colorArray->Count() == 2 );
439   DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
440   DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
441
442   // Test the properties. TODO: to be completed.
443   gradientVisual.SetProperty( GradientVisual::Property::STOP_COLOR, Color::RED );
444   Property::Value gradientValue = gradientVisual.GetProperty( GradientVisual::Property::STOP_COLOR );
445
446   END_TEST;
447 }
448
449 int UtcDaliVisualGetPropertyMap4(void)
450 {
451   ToolkitTestApplication application;
452   tet_infoline( "UtcDaliVisualGetPropertyMap4: radial GradientVisual" );
453
454   VisualFactory factory = VisualFactory::Get();
455   DALI_TEST_CHECK( factory );
456
457   Property::Map propertyMap;
458   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
459
460   Vector2 center(100.f, 100.f);
461   float radius = 100.f;
462   propertyMap.Insert(GradientVisual::Property::UNITS,  GradientVisual::Units::USER_SPACE);
463   propertyMap.Insert(GradientVisual::Property::CENTER,  center);
464   propertyMap.Insert(GradientVisual::Property::RADIUS,  radius);
465   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   Vector3(0.1f, 0.3f, 1.1f));
466
467   Property::Array stopColors;
468   stopColors.PushBack( Color::RED );
469   stopColors.PushBack( Color::BLACK );
470   stopColors.PushBack( Color::GREEN );
471   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
472
473   Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
474   DALI_TEST_CHECK( gradientVisual );
475
476   Property::Map resultMap;
477   gradientVisual.CreatePropertyMap( resultMap );
478
479   // check the property values from the returned map from visual
480   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
481   DALI_TEST_CHECK( value );
482   DALI_TEST_CHECK( value->Get<int>() == Visual::GRADIENT );
483
484   value = resultMap.Find( GradientVisual::Property::UNITS,  Property::INTEGER );
485   DALI_TEST_CHECK( value );
486   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::Units::USER_SPACE );
487
488   value = resultMap.Find( GradientVisual::Property::SPREAD_METHOD,   Property::INTEGER );
489   DALI_TEST_CHECK( value );
490   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::SpreadMethod::PAD );
491
492   value = resultMap.Find( GradientVisual::Property::CENTER,  Property::VECTOR2 );
493   DALI_TEST_CHECK( value );
494   DALI_TEST_EQUALS( value->Get<Vector2>(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION );
495
496   value = resultMap.Find( GradientVisual::Property::RADIUS,  Property::FLOAT );
497   DALI_TEST_CHECK( value );
498   DALI_TEST_EQUALS( value->Get<float>(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION );
499
500   value = resultMap.Find( GradientVisual::Property::STOP_OFFSET,   Property::ARRAY );
501   DALI_TEST_CHECK( value );
502   Property::Array* offsetArray = value->GetArray();
503   DALI_TEST_CHECK( offsetArray->Count() == 3 );
504   DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
505   DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
506   // any stop value will be clamped to [0.0, 1.0];
507   DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get<float>(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
508
509   value = resultMap.Find( GradientVisual::Property::STOP_COLOR,   Property::ARRAY );
510   DALI_TEST_CHECK( value );
511   Property::Array* colorArray = value->GetArray();
512   DALI_TEST_CHECK( colorArray->Count() == 3 );
513   DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
514   DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION );
515   DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
516
517   END_TEST;
518 }
519
520 int UtcDaliVisualGetPropertyMap5(void)
521 {
522   ToolkitTestApplication application;
523   tet_infoline( "UtcDaliVisualGetPropertyMap5: ImageVisual" );
524
525   VisualFactory factory = VisualFactory::Get();
526   Property::Map propertyMap;
527   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
528   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
529   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
530   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
531   propertyMap.Insert( ImageVisual::Property::FITTING_MODE,   FittingMode::FIT_HEIGHT );
532   propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE,   SamplingMode::BOX_THEN_NEAREST );
533   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, Vector4( 0.25f, 0.25f, 0.5f, 0.5f ) );
534   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT );
535   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::MIRRORED_REPEAT );
536   propertyMap.Insert( "synchronousLoading",   true );
537
538   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
539   DALI_TEST_CHECK( imageVisual );
540
541   Property::Map resultMap;
542   imageVisual.CreatePropertyMap( resultMap );
543
544   // check the property values from the returned map from visual
545   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
546   DALI_TEST_CHECK( value );
547   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
548
549   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
550   DALI_TEST_CHECK( value );
551   DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
552
553   value = resultMap.Find( ImageVisual::Property::FITTING_MODE,   Property::INTEGER );
554   DALI_TEST_CHECK( value );
555   DALI_TEST_CHECK( value->Get<int>() == FittingMode::FIT_HEIGHT );
556
557   value = resultMap.Find( ImageVisual::Property::SAMPLING_MODE,   Property::INTEGER );
558   DALI_TEST_CHECK( value );
559   DALI_TEST_CHECK( value->Get<int>() == SamplingMode::BOX_THEN_NEAREST );
560
561   value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH,   Property::INTEGER );
562   DALI_TEST_CHECK( value );
563   DALI_TEST_CHECK( value->Get<int>() == 20 );
564
565   value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT,   Property::INTEGER );
566   DALI_TEST_CHECK( value );
567   DALI_TEST_CHECK( value->Get<int>() == 30 );
568
569   value = resultMap.Find( ImageVisual::Property::PIXEL_AREA, Property::VECTOR4 );
570   DALI_TEST_CHECK( value );
571   DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4( 0.25f, 0.25f, 0.5f, 0.5f ), Math::MACHINE_EPSILON_100, TEST_LOCATION );
572
573   value = resultMap.Find( ImageVisual::Property::WRAP_MODE_U, Property::INTEGER );
574   DALI_TEST_CHECK( value );
575   DALI_TEST_CHECK(  value->Get<int>() == WrapMode::REPEAT);
576
577   value = resultMap.Find( ImageVisual::Property::WRAP_MODE_V, Property::INTEGER );
578   DALI_TEST_CHECK( value );
579   DALI_TEST_CHECK(  value->Get<int>() == WrapMode::MIRRORED_REPEAT);
580
581   value = resultMap.Find( "synchronousLoading",   Property::BOOLEAN );
582   DALI_TEST_CHECK( value );
583   DALI_TEST_CHECK( value->Get<bool>() == true );
584
585   // Get an image visual with an image handle, and test the default property values
586   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
587   imageVisual = factory.CreateVisual(image);
588   imageVisual.CreatePropertyMap( resultMap );
589
590   value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
591   DALI_TEST_CHECK( value );
592   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
593
594   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
595   DALI_TEST_CHECK( value );
596   DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
597
598   value = resultMap.Find( ImageVisual::Property::FITTING_MODE,   Property::INTEGER );
599   DALI_TEST_CHECK( value );
600   DALI_TEST_CHECK( value->Get<int>() == FittingMode::SHRINK_TO_FIT );
601
602   value = resultMap.Find( ImageVisual::Property::SAMPLING_MODE,   Property::INTEGER );
603   DALI_TEST_CHECK( value );
604   DALI_TEST_CHECK( value->Get<int>() == SamplingMode::BOX );
605
606   value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH,   Property::INTEGER );
607   DALI_TEST_CHECK( value );
608   DALI_TEST_CHECK( value->Get<int>() == 100 );
609
610   value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT,   Property::INTEGER );
611   DALI_TEST_CHECK( value );
612   DALI_TEST_CHECK( value->Get<int>() == 200 );
613
614   value = resultMap.Find( ImageVisual::Property::PIXEL_AREA, Property::VECTOR4 );
615   DALI_TEST_CHECK( value );
616   DALI_TEST_EQUALS( value->Get<Vector4>(), Vector4( 0.f, 0.f, 1.f, 1.f ), Math::MACHINE_EPSILON_100, TEST_LOCATION );
617
618   value = resultMap.Find( ImageVisual::Property::WRAP_MODE_U, Property::INTEGER );
619   DALI_TEST_CHECK( value );
620   DALI_TEST_CHECK(  value->Get<int>() == WrapMode::DEFAULT);
621
622   value = resultMap.Find( ImageVisual::Property::WRAP_MODE_V, Property::INTEGER );
623   DALI_TEST_CHECK( value );
624   DALI_TEST_CHECK(  value->Get<int>() == WrapMode::DEFAULT);
625
626   value = resultMap.Find( "synchronousLoading",   Property::BOOLEAN );
627   DALI_TEST_CHECK( value );
628   DALI_TEST_CHECK( value->Get<bool>() == false );
629
630   // Test the properties. TODO: to be completed.
631   imageVisual.SetProperty( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
632   Property::Value imageValue = imageVisual.GetProperty( ImageVisual::Property::URL );
633
634   END_TEST;
635 }
636
637 int UtcDaliVisualGetPropertyMap6(void)
638 {
639   ToolkitTestApplication application;
640   tet_infoline( "UtcDaliVisualGetPropertyMap6: NPatchVisual" );
641
642   VisualFactory factory = VisualFactory::Get();
643   Property::Map propertyMap;
644   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
645   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
646   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
647   Visual::Base nPatchVisual = factory.CreateVisual( propertyMap );
648
649   Property::Map resultMap;
650   nPatchVisual.CreatePropertyMap( resultMap );
651
652   // check the property values from the returned map from visual
653   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
654   DALI_TEST_CHECK( value );
655   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
656
657   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
658   DALI_TEST_CHECK( value );
659   DALI_TEST_CHECK( value->Get<std::string>() == TEST_NPATCH_FILE_NAME );
660
661   value = resultMap.Find( ImageVisual::Property::BORDER_ONLY,  Property::BOOLEAN );
662   DALI_TEST_CHECK( value );
663   DALI_TEST_CHECK( value->Get<bool>() );
664
665   // Test the properties. TODO: to be completed.
666   nPatchVisual.SetProperty( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
667   Property::Value nPatchValue = nPatchVisual.GetProperty( ImageVisual::Property::URL );
668
669   END_TEST;
670 }
671
672 int UtcDaliVisualGetPropertyMap7(void)
673 {
674   ToolkitTestApplication application;
675   tet_infoline( "UtcDaliVisualGetPropertyMap7: SvgVisual" );
676
677   // request SvgVisual with a property map
678   VisualFactory factory = VisualFactory::Get();
679   Property::Map propertyMap;
680   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
681   propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
682   Visual::Base svgVisual = factory.CreateVisual( propertyMap );
683
684   Property::Map resultMap;
685   svgVisual.CreatePropertyMap( resultMap );
686   // check the property values from the returned map from a visual
687   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
688   DALI_TEST_CHECK( value );
689   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
690
691   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
692   DALI_TEST_CHECK( value );
693   DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
694
695   // request SvgVisual with an URL
696   Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
697   resultMap.Clear();
698   svgVisual2.CreatePropertyMap( resultMap );
699   // check the property values from the returned map from a visual
700   value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
701   DALI_TEST_CHECK( value );
702   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
703
704   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
705   DALI_TEST_CHECK( value );
706   DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
707
708   // Test the properties. TODO: to be completed.
709   svgVisual.SetProperty( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
710   Property::Value svgValue = svgVisual.GetProperty( ImageVisual::Property::URL );
711
712   END_TEST;
713 }
714
715 //Mesh visual
716 int UtcDaliVisualGetPropertyMap8(void)
717 {
718   ToolkitTestApplication application;
719   tet_infoline( "UtcDaliVisualGetPropertyMap8: MeshVisual" );
720
721   //Request MeshVisual using a property map.
722   VisualFactory factory = VisualFactory::Get();
723   Property::Map propertyMap;
724   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
725   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
726   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
727   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_LOCATION );
728   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
729   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 5.0f, 10.0f, 15.0f) );
730   Visual::Base meshVisual = factory.CreateVisual( propertyMap );
731
732   Property::Map resultMap;
733   meshVisual.CreatePropertyMap( resultMap );
734
735   //Check values in the result map are identical to the initial map's values.
736   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
737   DALI_TEST_CHECK( value );
738   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::MESH, TEST_LOCATION );
739
740   value = resultMap.Find( MeshVisual::Property::OBJECT_URL, Property::STRING );
741   DALI_TEST_CHECK( value );
742   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_OBJ_FILE_NAME, TEST_LOCATION );
743
744   value = resultMap.Find( MeshVisual::Property::MATERIAL_URL, Property::STRING );
745   DALI_TEST_CHECK( value );
746   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_MTL_FILE_NAME, TEST_LOCATION );
747
748   value = resultMap.Find( MeshVisual::Property::TEXTURES_PATH, Property::STRING );
749   DALI_TEST_CHECK( value );
750   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_RESOURCE_LOCATION, TEST_LOCATION );
751
752   value = resultMap.Find( MeshVisual::Property::SHADING_MODE, Property::INTEGER );
753   DALI_TEST_CHECK( value );
754   DALI_TEST_EQUALS( value->Get<int>(), (int)MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING, TEST_LOCATION );
755
756   value = resultMap.Find( MeshVisual::Property::LIGHT_POSITION, Property::VECTOR3 );
757   DALI_TEST_CHECK( value );
758   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
759
760   // Test the properties. TODO: to be completed.
761   meshVisual.SetProperty( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
762   Property::Value meshValue = meshVisual.GetProperty( MeshVisual::Property::OBJECT_URL );
763
764   END_TEST;
765 }
766
767 //Primitive shape visual
768 int UtcDaliVisualGetPropertyMap9(void)
769 {
770   ToolkitTestApplication application;
771   tet_infoline( "UtcDaliVisualGetPropertyMap9: PrimitiveVisual" );
772
773   Vector4 color = Vector4( 1.0, 0.8, 0.6, 1.0);
774   Vector3 dimensions = Vector3( 1.0, 2.0, 3.0 );
775
776   //Request PrimitiveVisual using a property map.
777   VisualFactory factory = VisualFactory::Get();
778   Property::Map propertyMap;
779   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
780   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
781   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, color );
782   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
783   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
784   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
785   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
786   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
787   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
788   propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, dimensions );
789   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.3f );
790   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.6f );
791   propertyMap.Insert( PrimitiveVisual::Property::LIGHT_POSITION, Vector3( 5.0f, 10.0f, 15.0f) );
792   Visual::Base primitiveVisual = factory.CreateVisual( propertyMap );
793
794   Property::Map resultMap;
795   primitiveVisual.CreatePropertyMap( resultMap );
796
797   //Check values in the result map are identical to the initial map's values.
798   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
799   DALI_TEST_CHECK( value );
800   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::PRIMITIVE, TEST_LOCATION );
801
802   value = resultMap.Find( PrimitiveVisual::Property::SHAPE, Property::INTEGER );
803   DALI_TEST_CHECK( value );
804   DALI_TEST_EQUALS( value->Get<int>(), (int)PrimitiveVisual::Shape::CUBE, TEST_LOCATION );
805
806   value = resultMap.Find( PrimitiveVisual::Property::MIX_COLOR, Property::VECTOR4 );
807   DALI_TEST_CHECK( value );
808   DALI_TEST_CHECK( value->Get<Vector4>() == color );
809   DALI_TEST_EQUALS( value->Get<Vector4>(), color, Math::MACHINE_EPSILON_100, TEST_LOCATION );
810
811   value = resultMap.Find( PrimitiveVisual::Property::SLICES, Property::INTEGER );
812   DALI_TEST_CHECK( value );
813   DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
814
815   value = resultMap.Find( PrimitiveVisual::Property::STACKS, Property::INTEGER );
816   DALI_TEST_CHECK( value );
817   DALI_TEST_EQUALS( value->Get<int>(), 20, TEST_LOCATION );
818
819   value = resultMap.Find( PrimitiveVisual::Property::SCALE_TOP_RADIUS, Property::FLOAT );
820   DALI_TEST_CHECK( value );
821   DALI_TEST_EQUALS( value->Get<float>(), 30.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
822
823   value = resultMap.Find( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, Property::FLOAT );
824   DALI_TEST_CHECK( value );
825   DALI_TEST_EQUALS( value->Get<float>(), 40.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
826
827   value = resultMap.Find( PrimitiveVisual::Property::SCALE_HEIGHT, Property::FLOAT );
828   DALI_TEST_CHECK( value );
829   DALI_TEST_EQUALS( value->Get<float>(), 50.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
830
831   value = resultMap.Find( PrimitiveVisual::Property::SCALE_RADIUS, Property::FLOAT );
832   DALI_TEST_CHECK( value );
833   DALI_TEST_EQUALS( value->Get<float>(), 60.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
834
835   value = resultMap.Find( PrimitiveVisual::Property::SCALE_DIMENSIONS, Property::VECTOR3 );
836   DALI_TEST_CHECK( value );
837   DALI_TEST_EQUALS( value->Get<Vector3>(), dimensions, Math::MACHINE_EPSILON_100, TEST_LOCATION );
838
839   value = resultMap.Find( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::FLOAT );
840   DALI_TEST_CHECK( value );
841   DALI_TEST_EQUALS( value->Get<float>(), 0.3f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
842
843   value = resultMap.Find( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::FLOAT );
844   DALI_TEST_CHECK( value );
845   DALI_TEST_EQUALS( value->Get<float>(), 0.6f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
846
847   value = resultMap.Find( PrimitiveVisual::Property::LIGHT_POSITION, Property::VECTOR3 );
848   DALI_TEST_CHECK( value );
849   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
850
851   // Test the properties. TODO: to be completed.
852   primitiveVisual.SetProperty( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
853   Property::Value primitiveValue = primitiveVisual.GetProperty( PrimitiveVisual::Property::SHAPE );
854
855   END_TEST;
856 }
857
858 int UtcDaliVisualGetPropertyMapBatchImageVisual(void)
859 {
860   ToolkitTestApplication application;
861   tet_infoline( "UtcDaliVisualGetPropertyMapBatchImageVisual:" );
862
863   VisualFactory factory = VisualFactory::Get();
864   Property::Map propertyMap;
865   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
866   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
867   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
868   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
869   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
870
871   Visual::Base batchImageVisual = factory.CreateVisual( propertyMap );
872   DALI_TEST_CHECK( batchImageVisual );
873
874   Property::Map resultMap;
875   batchImageVisual.CreatePropertyMap( resultMap );
876
877   // Check the property values from the returned map from visual
878   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
879   DALI_TEST_CHECK( value );
880   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
881
882   value = resultMap.Find( ImageVisual::Property::URL, Property::STRING );
883   DALI_TEST_CHECK( value );
884   DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
885
886   value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER );
887   DALI_TEST_CHECK( value );
888   DALI_TEST_CHECK( value->Get<int>() == 20 );
889
890   value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER );
891   DALI_TEST_CHECK( value );
892   DALI_TEST_CHECK( value->Get<int>() == 30 );
893
894   // Test the properties. TODO: to be completed.
895   batchImageVisual.SetProperty( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
896   Property::Value primitiveValue = batchImageVisual.GetProperty( ImageVisual::Property::URL );
897
898   END_TEST;
899 }
900
901 int UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas(void)
902 {
903   ToolkitTestApplication application;
904   tet_infoline( "UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas:" );
905
906   VisualFactory factory = VisualFactory::Get();
907   Property::Map propertyMap;
908   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
909   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
910   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
911
912   // Set the desired size to be larger than the atlas limit of 1024x1024.
913   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 2048 );
914   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 2048 );
915
916   // Create the visual.
917   Visual::Base batchImageVisual = factory.CreateVisual( propertyMap );
918
919   DALI_TEST_CHECK( batchImageVisual );
920
921   Actor actor = Actor::New();
922   batchImageVisual.SetOnStage( actor );
923
924   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
925
926   END_TEST;
927 }
928
929 int UtcDaliVisualAnimateBorderVisual01(void)
930 {
931   ToolkitTestApplication application;
932   tet_infoline( "UtcDaliAnimateBorderVisual Color" );
933
934   VisualFactory factory = VisualFactory::Get();
935   Property::Map propertyMap;
936   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
937   propertyMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
938   propertyMap.Insert(BorderVisual::Property::SIZE,  5.f);
939   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
940
941   Actor actor = Actor::New();
942   actor.SetSize(2000, 2000);
943   actor.SetParentOrigin(ParentOrigin::CENTER);
944   Stage::GetCurrent().Add(actor);
945   borderVisual.SetOnStage( actor );
946
947   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
948
949   Renderer renderer = actor.GetRendererAt(0);
950   Property::Index index = renderer.GetPropertyIndex( BorderVisual::Property::COLOR );
951
952   Animation animation = Animation::New(4.0f);
953   animation.AnimateTo( Property(renderer, index), Color::WHITE );
954   animation.Play();
955
956   application.SendNotification();
957   application.Render(0);
958   application.Render(2000u); // halfway point between blue and white
959
960   Vector4 color = renderer.GetProperty<Vector4>( index );
961   Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f;
962   DALI_TEST_EQUALS( color, testColor, TEST_LOCATION );
963   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("borderColor", testColor ), true, TEST_LOCATION );
964
965   application.Render(2000u); // halfway point between blue and white
966
967   color = renderer.GetProperty<Vector4>( index );
968   DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION );
969   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("borderColor", Color::WHITE ), true, TEST_LOCATION );
970
971   END_TEST;
972 }
973
974
975 int UtcDaliVisualAnimateBorderVisual02(void)
976 {
977   ToolkitTestApplication application;
978   tet_infoline( "UtcDaliAnimateBorderVisual Size" );
979
980   VisualFactory factory = VisualFactory::Get();
981   Property::Map propertyMap;
982   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
983   propertyMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
984   propertyMap.Insert(BorderVisual::Property::SIZE,  5.f);
985   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
986
987   Actor actor = Actor::New();
988   actor.SetSize(2000, 2000);
989   actor.SetParentOrigin(ParentOrigin::CENTER);
990   Stage::GetCurrent().Add(actor);
991   borderVisual.SetOnStage( actor );
992
993   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
994
995   Renderer renderer = actor.GetRendererAt(0);
996   Property::Index index = renderer.GetPropertyIndex( BorderVisual::Property::SIZE );
997
998   Animation animation = Animation::New(4.0f);
999   animation.AnimateTo( Property(renderer, index), 9.0f );
1000   animation.Play();
1001
1002   application.SendNotification();
1003   application.Render(0);
1004   application.Render(2000u); // halfway point
1005
1006   float size = renderer.GetProperty<float>( index );
1007   DALI_TEST_EQUALS( size, 7.0f, 0.0001f, TEST_LOCATION );
1008   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("borderSize", 7.0f ), true, TEST_LOCATION );
1009
1010   application.Render(2000u); // halfway point between blue and white
1011
1012   size = renderer.GetProperty<float>( index );
1013   DALI_TEST_EQUALS( size, 9.0f, 0.0001f, TEST_LOCATION );
1014   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("borderSize", 9.0f ), true, TEST_LOCATION );
1015
1016   END_TEST;
1017 }
1018
1019 int UtcDaliVisualAnimateColorVisual(void)
1020 {
1021   ToolkitTestApplication application;
1022   tet_infoline( "UtcDaliAnimateColorVisual mixColor" );
1023
1024   VisualFactory factory = VisualFactory::Get();
1025   Property::Map propertyMap;
1026   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1027   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1028   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
1029
1030   Actor actor = Actor::New();
1031   actor.SetSize(2000, 2000);
1032   actor.SetParentOrigin(ParentOrigin::CENTER);
1033   Stage::GetCurrent().Add(actor);
1034   borderVisual.SetOnStage( actor );
1035
1036   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1037
1038   Renderer renderer = actor.GetRendererAt(0);
1039   Property::Index index = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
1040
1041   Animation animation = Animation::New(4.0f);
1042   animation.AnimateTo( Property(renderer, index), Color::WHITE );
1043   animation.Play();
1044
1045   application.SendNotification();
1046   application.Render(0);
1047   application.Render(2000u); // halfway point
1048
1049   Vector4 color = renderer.GetProperty<Vector4>( index );
1050   Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f;
1051   DALI_TEST_EQUALS( color, testColor, TEST_LOCATION );
1052
1053   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("mixColor", testColor ), true, TEST_LOCATION );
1054
1055   application.Render(2000u); // halfway point between blue and white
1056
1057   color = renderer.GetProperty<Vector4>( index );
1058   DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION );
1059
1060   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("mixColor", Color::WHITE ), true, TEST_LOCATION );
1061
1062
1063   END_TEST;
1064 }
1065
1066
1067 int UtcDaliVisualAnimatePrimitiveVisual(void)
1068 {
1069   ToolkitTestApplication application;
1070   tet_infoline( "UtcDaliAnimatePrimitiveVisual color" );
1071
1072   VisualFactory factory = VisualFactory::Get();
1073   Property::Map propertyMap;
1074   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1075   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1076   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
1077
1078   Actor actor = Actor::New();
1079   actor.SetSize(2000, 2000);
1080   actor.SetParentOrigin(ParentOrigin::CENTER);
1081   actor.SetColor(Color::BLACK);
1082   Stage::GetCurrent().Add(actor);
1083   borderVisual.SetOnStage( actor );
1084
1085   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1086
1087   Renderer renderer = actor.GetRendererAt(0);
1088   Property::Index index = renderer.GetPropertyIndex( PrimitiveVisual::Property::MIX_COLOR );
1089
1090   // The property isn't registered on the renderer, it's instead registered on the shader.
1091   DALI_TEST_EQUALS( index, Property::INVALID_INDEX, TEST_LOCATION );
1092
1093   Animation animation = Animation::New(4.0f);
1094   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1095   animation.Play();
1096
1097   application.SendNotification();
1098   application.Render(0);
1099   application.Render(2000u); // halfway point
1100
1101   // Actor color overrides renderer color.
1102   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
1103
1104   application.Render(2000u); // halfway point between blue and white
1105
1106   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1107   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
1108
1109
1110   END_TEST;
1111 }
1112
1113 int UtcDaliVisualWireframeVisual(void)
1114 {
1115   ToolkitTestApplication application;
1116
1117   VisualFactory factory = VisualFactory::Get();
1118   Property::Map propertyMap;
1119   propertyMap.Insert( Visual::Property::TYPE, Visual::WIREFRAME );
1120
1121   // Create the visual.
1122   Visual::Base visual = factory.CreateVisual( propertyMap );
1123
1124   DALI_TEST_CHECK( visual );
1125
1126   Property::Map resultMap;
1127   visual.CreatePropertyMap( resultMap );
1128
1129   // Check the property values from the returned map from visual
1130   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1131   DALI_TEST_CHECK( value );
1132   DALI_TEST_CHECK( value->Get<int>() == Visual::WIREFRAME );
1133
1134   // Test the properties. TODO: to be completed.
1135   Property::Value primitiveValue = visual.GetProperty( Visual::Property::TYPE );
1136
1137   END_TEST;
1138 }