b6080c3705971a0b655560845241e70a3972e2a2
[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   END_TEST;
191 }
192
193 int UtcDaliVisualSetOnOffStage(void)
194 {
195   ToolkitTestApplication application;
196   tet_infoline( "UtcDaliVisualSetDepthIndex" );
197
198   VisualFactory factory = VisualFactory::Get();
199   Property::Map propertyMap;
200   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
201   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
202   Visual::Base visual = factory.CreateVisual( propertyMap );
203
204   Actor actor = Actor::New();
205   actor.SetSize(200.f, 200.f);
206   Stage::GetCurrent().Add( actor );
207
208   application.SendNotification();
209   application.Render(0);
210   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
211
212   visual.SetOnStage( actor );
213   application.SendNotification();
214   application.Render(0);
215   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
216
217   visual.SetOffStage( actor );
218   application.SendNotification();
219   application.Render(0);
220   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
221
222   END_TEST;
223 }
224
225 int UtcDaliVisualRemoveAndReset(void)
226 {
227   ToolkitTestApplication application;
228   tet_infoline( "intUtcDaliVisualRemoveAndReset" );
229
230   VisualFactory factory = VisualFactory::Get();
231
232   Actor actor = Actor::New();
233   actor.SetSize(200.f, 200.f);
234   Stage::GetCurrent().Add( actor );
235
236   Visual::Base imageVisual;
237   // test calling RemoveAndReset with an empty handle
238   try
239   {
240     imageVisual.RemoveAndReset( actor );
241     tet_result(TET_PASS);
242   }
243   catch (DaliException& exception)
244   {
245     tet_result(TET_FAIL);
246   }
247
248   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
249   imageVisual = factory.CreateVisual(image);
250   DALI_TEST_CHECK( imageVisual );
251
252   imageVisual.SetOnStage( actor );
253   application.SendNotification();
254   application.Render(0);
255   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
256
257   imageVisual.RemoveAndReset( actor );
258   application.SendNotification();
259   application.Render(0);
260   DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); // visual is removed from actor
261   DALI_TEST_CHECK( !imageVisual ); // visual is reset
262
263   END_TEST;
264 }
265
266 int UtcDaliVisualGetPropertyMap1(void)
267 {
268   ToolkitTestApplication application;
269   tet_infoline( "UtcDaliVisualGetPropertyMap1: ColorVisual" );
270
271   VisualFactory factory = VisualFactory::Get();
272   Property::Map propertyMap;
273   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
274   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
275   Visual::Base colorVisual = factory.CreateVisual( propertyMap );
276
277   Property::Map resultMap;
278   colorVisual.CreatePropertyMap( resultMap );
279
280   Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
281   DALI_TEST_CHECK( typeValue );
282   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::COLOR );
283
284   Property::Value* colorValue = resultMap.Find( ColorVisual::Property::MIX_COLOR,  Property::VECTOR4 );
285   DALI_TEST_CHECK( colorValue );
286   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
287
288   // change the blend color
289   Actor actor;
290   colorVisual.RemoveAndReset( actor );
291   propertyMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
292   colorVisual = factory.CreateVisual( propertyMap  );
293   colorVisual.CreatePropertyMap( resultMap );
294
295   colorValue = resultMap.Find( ColorVisual::Property::MIX_COLOR,  Property::VECTOR4 );
296   DALI_TEST_CHECK( colorValue );
297   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
298
299   END_TEST;
300 }
301
302 int UtcDaliVisualGetPropertyMap2(void)
303 {
304   ToolkitTestApplication application;
305   tet_infoline( "UtcDaliVisualGetPropertyMap2: BorderVisual" );
306
307   VisualFactory factory = VisualFactory::Get();
308   Property::Map propertyMap;
309   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
310   propertyMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
311   propertyMap.Insert(BorderVisual::Property::SIZE,  5.f);
312   Visual::Base borderVisual = factory.CreateVisual( propertyMap );
313
314   Property::Map resultMap;
315   borderVisual.CreatePropertyMap( resultMap );
316
317   // check the property values from the returned map from visual
318   Property::Value* typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
319   DALI_TEST_CHECK( typeValue );
320   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::BORDER );
321
322   Property::Value* colorValue = resultMap.Find( BorderVisual::Property::COLOR,  Property::VECTOR4 );
323   DALI_TEST_CHECK( colorValue );
324   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
325
326   Property::Value* sizeValue = resultMap.Find( BorderVisual::Property::SIZE,  Property::FLOAT );
327   DALI_TEST_CHECK( sizeValue );
328   DALI_TEST_CHECK( sizeValue->Get<float>() == 5.f );
329
330   Property::Map propertyMap1;
331   propertyMap1[ Visual::Property::TYPE ] = Visual::BORDER;
332   propertyMap1[ BorderVisual::Property::COLOR  ] = Color::CYAN;
333   propertyMap1[ BorderVisual::Property::SIZE   ] = 10.0f;
334   borderVisual = factory.CreateVisual( propertyMap1 );
335   borderVisual.CreatePropertyMap( resultMap );
336
337   typeValue = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
338   DALI_TEST_CHECK( typeValue );
339   DALI_TEST_CHECK( typeValue->Get<int>() == Visual::BORDER );
340
341   colorValue = resultMap.Find( BorderVisual::Property::COLOR,  Property::VECTOR4 );
342   DALI_TEST_CHECK( colorValue );
343   DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
344
345   colorValue = resultMap.Find( BorderVisual::Property::SIZE,  Property::FLOAT );
346   DALI_TEST_CHECK( colorValue );
347   DALI_TEST_CHECK( colorValue->Get<float>() == 10.f );
348
349   END_TEST;
350 }
351
352 int UtcDaliVisualGetPropertyMap3(void)
353 {
354   ToolkitTestApplication application;
355   tet_infoline( "UtcDaliVisualGetPropertyMap3: linear GradientVisual" );
356
357   VisualFactory factory = VisualFactory::Get();
358   DALI_TEST_CHECK( factory );
359
360   Property::Map propertyMap;
361   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
362
363   Vector2 start(-1.f, -1.f);
364   Vector2 end(1.f, 1.f);
365   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
366   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
367   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
368
369   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   Vector2(0.2f, 0.8f));
370
371   Property::Array stopColors;
372   stopColors.PushBack( Color::RED );
373   stopColors.PushBack( Color::GREEN );
374   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
375
376   Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
377
378   Property::Map resultMap;
379   gradientVisual.CreatePropertyMap( resultMap );
380
381   // check the property values from the returned map from visual
382   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
383   DALI_TEST_CHECK( value );
384   DALI_TEST_CHECK( value->Get<int>() == Visual::GRADIENT );
385
386   value = resultMap.Find( GradientVisual::Property::UNITS,  Property::INTEGER );
387   DALI_TEST_CHECK( value );
388   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::Units::OBJECT_BOUNDING_BOX );
389
390   value = resultMap.Find( GradientVisual::Property::SPREAD_METHOD,   Property::INTEGER );
391   DALI_TEST_CHECK( value );
392   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::SpreadMethod::REPEAT );
393
394   value = resultMap.Find( GradientVisual::Property::START_POSITION,   Property::VECTOR2 );
395   DALI_TEST_CHECK( value );
396   DALI_TEST_EQUALS( value->Get<Vector2>(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION );
397
398   value = resultMap.Find( GradientVisual::Property::END_POSITION,   Property::VECTOR2 );
399   DALI_TEST_CHECK( value );
400   DALI_TEST_EQUALS( value->Get<Vector2>(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION );
401
402   value = resultMap.Find( GradientVisual::Property::STOP_OFFSET,   Property::ARRAY );
403   DALI_TEST_CHECK( value );
404   Property::Array* offsetArray = value->GetArray();
405   DALI_TEST_CHECK( offsetArray->Count() == 2 );
406   DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
407   DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
408
409   value = resultMap.Find( GradientVisual::Property::STOP_COLOR,   Property::ARRAY );
410   DALI_TEST_CHECK( value );
411   Property::Array* colorArray = value->GetArray();
412   DALI_TEST_CHECK( colorArray->Count() == 2 );
413   DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
414   DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
415
416   END_TEST;
417 }
418
419 int UtcDaliVisualGetPropertyMap4(void)
420 {
421   ToolkitTestApplication application;
422   tet_infoline( "UtcDaliVisualGetPropertyMap4: radial GradientVisual" );
423
424   VisualFactory factory = VisualFactory::Get();
425   DALI_TEST_CHECK( factory );
426
427   Property::Map propertyMap;
428   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
429
430   Vector2 center(100.f, 100.f);
431   float radius = 100.f;
432   propertyMap.Insert(GradientVisual::Property::UNITS,  GradientVisual::Units::USER_SPACE);
433   propertyMap.Insert(GradientVisual::Property::CENTER,  center);
434   propertyMap.Insert(GradientVisual::Property::RADIUS,  radius);
435   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   Vector3(0.1f, 0.3f, 1.1f));
436
437   Property::Array stopColors;
438   stopColors.PushBack( Color::RED );
439   stopColors.PushBack( Color::BLACK );
440   stopColors.PushBack( Color::GREEN );
441   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
442
443   Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
444   DALI_TEST_CHECK( gradientVisual );
445
446   Property::Map resultMap;
447   gradientVisual.CreatePropertyMap( resultMap );
448
449   // check the property values from the returned map from visual
450   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
451   DALI_TEST_CHECK( value );
452   DALI_TEST_CHECK( value->Get<int>() == Visual::GRADIENT );
453
454   value = resultMap.Find( GradientVisual::Property::UNITS,  Property::INTEGER );
455   DALI_TEST_CHECK( value );
456   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::Units::USER_SPACE );
457
458   value = resultMap.Find( GradientVisual::Property::SPREAD_METHOD,   Property::INTEGER );
459   DALI_TEST_CHECK( value );
460   DALI_TEST_CHECK( value->Get<int>() == GradientVisual::SpreadMethod::PAD );
461
462   value = resultMap.Find( GradientVisual::Property::CENTER,  Property::VECTOR2 );
463   DALI_TEST_CHECK( value );
464   DALI_TEST_EQUALS( value->Get<Vector2>(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION );
465
466   value = resultMap.Find( GradientVisual::Property::RADIUS,  Property::FLOAT );
467   DALI_TEST_CHECK( value );
468   DALI_TEST_EQUALS( value->Get<float>(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION );
469
470   value = resultMap.Find( GradientVisual::Property::STOP_OFFSET,   Property::ARRAY );
471   DALI_TEST_CHECK( value );
472   Property::Array* offsetArray = value->GetArray();
473   DALI_TEST_CHECK( offsetArray->Count() == 3 );
474   DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
475   DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
476   // any stop value will be clamped to [0.0, 1.0];
477   DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get<float>(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
478
479   value = resultMap.Find( GradientVisual::Property::STOP_COLOR,   Property::ARRAY );
480   DALI_TEST_CHECK( value );
481   Property::Array* colorArray = value->GetArray();
482   DALI_TEST_CHECK( colorArray->Count() == 3 );
483   DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
484   DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION );
485   DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
486
487   END_TEST;
488 }
489
490 int UtcDaliVisualGetPropertyMap5(void)
491 {
492   ToolkitTestApplication application;
493   tet_infoline( "UtcDaliVisualGetPropertyMap5: ImageVisual" );
494
495   VisualFactory factory = VisualFactory::Get();
496   Property::Map propertyMap;
497   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
498   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
499   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH,   20 );
500   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT,   30 );
501   propertyMap.Insert( ImageVisual::Property::FITTING_MODE,   FittingMode::FIT_HEIGHT );
502   propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE,   SamplingMode::BOX_THEN_NEAREST );
503   propertyMap.Insert( "synchronousLoading",   true );
504
505   Visual::Base imageVisual = factory.CreateVisual(propertyMap);
506   DALI_TEST_CHECK( imageVisual );
507
508   Property::Map resultMap;
509   imageVisual.CreatePropertyMap( resultMap );
510
511   // check the property values from the returned map from visual
512   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
513   DALI_TEST_CHECK( value );
514   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
515
516   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
517   DALI_TEST_CHECK( value );
518   DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
519
520   value = resultMap.Find( ImageVisual::Property::FITTING_MODE,   Property::INTEGER );
521   DALI_TEST_CHECK( value );
522   DALI_TEST_CHECK( value->Get<int>() == FittingMode::FIT_HEIGHT );
523
524   value = resultMap.Find( ImageVisual::Property::SAMPLING_MODE,   Property::INTEGER );
525   DALI_TEST_CHECK( value );
526   DALI_TEST_CHECK( value->Get<int>() == SamplingMode::BOX_THEN_NEAREST );
527
528   value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH,   Property::INTEGER );
529   DALI_TEST_CHECK( value );
530   DALI_TEST_CHECK( value->Get<int>() == 20 );
531
532   value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT,   Property::INTEGER );
533   DALI_TEST_CHECK( value );
534   DALI_TEST_CHECK( value->Get<int>() == 30 );
535
536   value = resultMap.Find( "synchronousLoading",   Property::BOOLEAN );
537   DALI_TEST_CHECK( value );
538   DALI_TEST_CHECK( value->Get<bool>() == true );
539
540   // Get an image visual with an image handle, and test the default property values
541   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
542   imageVisual = factory.CreateVisual(image);
543   imageVisual.CreatePropertyMap( resultMap );
544
545   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::SHRINK_TO_FIT );
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 );
560
561   value = resultMap.Find( ImageVisual::Property::DESIRED_WIDTH,   Property::INTEGER );
562   DALI_TEST_CHECK( value );
563   DALI_TEST_CHECK( value->Get<int>() == 100 );
564
565   value = resultMap.Find( ImageVisual::Property::DESIRED_HEIGHT,   Property::INTEGER );
566   DALI_TEST_CHECK( value );
567   DALI_TEST_CHECK( value->Get<int>() == 200 );
568
569   value = resultMap.Find( "synchronousLoading",   Property::BOOLEAN );
570   DALI_TEST_CHECK( value );
571   DALI_TEST_CHECK( value->Get<bool>() == false );
572
573   END_TEST;
574 }
575
576 int UtcDaliVisualGetPropertyMap6(void)
577 {
578   ToolkitTestApplication application;
579   tet_infoline( "UtcDaliVisualGetPropertyMap6: NPatchVisual" );
580
581   VisualFactory factory = VisualFactory::Get();
582   Property::Map propertyMap;
583   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
584   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
585   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
586   Visual::Base nPatchVisual = factory.CreateVisual( propertyMap );
587
588   Property::Map resultMap;
589   nPatchVisual.CreatePropertyMap( resultMap );
590
591   // check the property values from the returned map from visual
592   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
593   DALI_TEST_CHECK( value );
594   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
595
596   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
597   DALI_TEST_CHECK( value );
598   DALI_TEST_CHECK( value->Get<std::string>() == TEST_NPATCH_FILE_NAME );
599
600   value = resultMap.Find( ImageVisual::Property::BORDER_ONLY,  Property::BOOLEAN );
601   DALI_TEST_CHECK( value );
602   DALI_TEST_CHECK( value->Get<bool>() );
603
604   END_TEST;
605 }
606
607 int UtcDaliVisualGetPropertyMap7(void)
608 {
609   ToolkitTestApplication application;
610   tet_infoline( "UtcDaliVisualGetPropertyMap7: SvgVisual" );
611
612   // request SvgVisual with a property map
613   VisualFactory factory = VisualFactory::Get();
614   Property::Map propertyMap;
615   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
616   propertyMap.Insert( ImageVisual::Property::URL,  TEST_SVG_FILE_NAME );
617   Visual::Base svgVisual = factory.CreateVisual( propertyMap );
618
619   Property::Map resultMap;
620   svgVisual.CreatePropertyMap( resultMap );
621   // check the property values from the returned map from a visual
622   Property::Value* value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
623   DALI_TEST_CHECK( value );
624   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
625
626   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
627   DALI_TEST_CHECK( value );
628   DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
629
630   // request SvgVisual with an URL
631   Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
632   resultMap.Clear();
633   svgVisual2.CreatePropertyMap( resultMap );
634   // check the property values from the returned map from a visual
635   value = resultMap.Find( Visual::Property::TYPE,  Property::INTEGER );
636   DALI_TEST_CHECK( value );
637   DALI_TEST_CHECK( value->Get<int>() == Visual::IMAGE );
638
639   value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
640   DALI_TEST_CHECK( value );
641   DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
642
643   END_TEST;
644 }
645
646 //Mesh visual
647 int UtcDaliVisualGetPropertyMap8(void)
648 {
649   ToolkitTestApplication application;
650   tet_infoline( "UtcDaliVisualGetPropertyMap8: MeshVisual" );
651
652   //Request MeshVisual using a property map.
653   VisualFactory factory = VisualFactory::Get();
654   Property::Map propertyMap;
655   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
656   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
657   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
658   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_LOCATION );
659   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
660   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 5.0f, 10.0f, 15.0f) );
661   Visual::Base meshVisual = factory.CreateVisual( propertyMap );
662
663   Property::Map resultMap;
664   meshVisual.CreatePropertyMap( resultMap );
665
666   //Check values in the result map are identical to the initial map's values.
667   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
668   DALI_TEST_CHECK( value );
669   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::MESH, TEST_LOCATION );
670
671   value = resultMap.Find( MeshVisual::Property::OBJECT_URL, Property::STRING );
672   DALI_TEST_CHECK( value );
673   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_OBJ_FILE_NAME, TEST_LOCATION );
674
675   value = resultMap.Find( MeshVisual::Property::MATERIAL_URL, Property::STRING );
676   DALI_TEST_CHECK( value );
677   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_MTL_FILE_NAME, TEST_LOCATION );
678
679   value = resultMap.Find( MeshVisual::Property::TEXTURES_PATH, Property::STRING );
680   DALI_TEST_CHECK( value );
681   DALI_TEST_EQUALS( value->Get<std::string>(), TEST_RESOURCE_LOCATION, TEST_LOCATION );
682
683   value = resultMap.Find( MeshVisual::Property::SHADING_MODE, Property::INTEGER );
684   DALI_TEST_CHECK( value );
685   DALI_TEST_EQUALS( value->Get<int>(), (int)MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING, TEST_LOCATION );
686
687   value = resultMap.Find( MeshVisual::Property::LIGHT_POSITION, Property::VECTOR3 );
688   DALI_TEST_CHECK( value );
689   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
690
691   END_TEST;
692 }
693
694 //Primitive shape visual
695 int UtcDaliVisualGetPropertyMap9(void)
696 {
697   ToolkitTestApplication application;
698   tet_infoline( "UtcDaliVisualGetPropertyMap9: PrimitiveVisual" );
699
700   Vector4 color = Vector4( 1.0, 0.8, 0.6, 1.0);
701   Vector3 dimensions = Vector3( 1.0, 2.0, 3.0 );
702
703   //Request PrimitiveVisual using a property map.
704   VisualFactory factory = VisualFactory::Get();
705   Property::Map propertyMap;
706   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
707   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
708   propertyMap.Insert( PrimitiveVisual::Property::COLOR, color );
709   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
710   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
711   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
712   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
713   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
714   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
715   propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, dimensions );
716   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.3f );
717   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.6f );
718   propertyMap.Insert( PrimitiveVisual::Property::LIGHT_POSITION, Vector3( 5.0f, 10.0f, 15.0f) );
719   Visual::Base primitiveVisual = factory.CreateVisual( propertyMap );
720
721   Property::Map resultMap;
722   primitiveVisual.CreatePropertyMap( resultMap );
723
724   //Check values in the result map are identical to the initial map's values.
725   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
726   DALI_TEST_CHECK( value );
727   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::PRIMITIVE, TEST_LOCATION );
728
729   value = resultMap.Find( PrimitiveVisual::Property::SHAPE, Property::INTEGER );
730   DALI_TEST_CHECK( value );
731   DALI_TEST_EQUALS( value->Get<int>(), (int)PrimitiveVisual::Shape::CUBE, TEST_LOCATION );
732
733   value = resultMap.Find( PrimitiveVisual::Property::COLOR, Property::VECTOR4 );
734   DALI_TEST_CHECK( value );
735   DALI_TEST_CHECK( value->Get<Vector4>() == color );
736   DALI_TEST_EQUALS( value->Get<Vector4>(), color, Math::MACHINE_EPSILON_100, TEST_LOCATION );
737
738   value = resultMap.Find( PrimitiveVisual::Property::SLICES, Property::INTEGER );
739   DALI_TEST_CHECK( value );
740   DALI_TEST_EQUALS( value->Get<int>(), 10, TEST_LOCATION );
741
742   value = resultMap.Find( PrimitiveVisual::Property::STACKS, Property::INTEGER );
743   DALI_TEST_CHECK( value );
744   DALI_TEST_EQUALS( value->Get<int>(), 20, TEST_LOCATION );
745
746   value = resultMap.Find( PrimitiveVisual::Property::SCALE_TOP_RADIUS, Property::FLOAT );
747   DALI_TEST_CHECK( value );
748   DALI_TEST_EQUALS( value->Get<float>(), 30.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
749
750   value = resultMap.Find( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, Property::FLOAT );
751   DALI_TEST_CHECK( value );
752   DALI_TEST_EQUALS( value->Get<float>(), 40.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
753
754   value = resultMap.Find( PrimitiveVisual::Property::SCALE_HEIGHT, Property::FLOAT );
755   DALI_TEST_CHECK( value );
756   DALI_TEST_EQUALS( value->Get<float>(), 50.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
757
758   value = resultMap.Find( PrimitiveVisual::Property::SCALE_RADIUS, Property::FLOAT );
759   DALI_TEST_CHECK( value );
760   DALI_TEST_EQUALS( value->Get<float>(), 60.0f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
761
762   value = resultMap.Find( PrimitiveVisual::Property::SCALE_DIMENSIONS, Property::VECTOR3 );
763   DALI_TEST_CHECK( value );
764   DALI_TEST_EQUALS( value->Get<Vector3>(), dimensions, Math::MACHINE_EPSILON_100, TEST_LOCATION );
765
766   value = resultMap.Find( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::FLOAT );
767   DALI_TEST_CHECK( value );
768   DALI_TEST_EQUALS( value->Get<float>(), 0.3f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
769
770   value = resultMap.Find( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::FLOAT );
771   DALI_TEST_CHECK( value );
772   DALI_TEST_EQUALS( value->Get<float>(), 0.6f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
773
774   value = resultMap.Find( PrimitiveVisual::Property::LIGHT_POSITION, Property::VECTOR3 );
775   DALI_TEST_CHECK( value );
776   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
777
778   END_TEST;
779 }