Dali 3D User Interface Engine
utc-Dali-Scripting.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 
18 #include <iostream>
19 
20 #include <stdlib.h>
23 #include <dali-test-suite-utils.h>
24 
25 using namespace Dali;
26 using namespace Dali::Scripting;
27 
28 namespace
29 {
30 
32 {
33  { "USE_OWN_COLOR", USE_OWN_COLOR },
34  { "USE_PARENT_COLOR", USE_PARENT_COLOR },
35  { "USE_OWN_MULTIPLY_PARENT_COLOR", USE_OWN_MULTIPLY_PARENT_COLOR },
36  { "USE_OWN_MULTIPLY_PARENT_ALPHA", USE_OWN_MULTIPLY_PARENT_ALPHA },
37 };
38 const unsigned int COLOR_MODE_VALUES_COUNT = sizeof( COLOR_MODE_VALUES ) / sizeof( COLOR_MODE_VALUES[0] );
39 
41 {
42  { "INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION },
43  { "USE_PARENT_POSITION", USE_PARENT_POSITION },
44  { "USE_PARENT_POSITION_PLUS_LOCAL_POSITION", USE_PARENT_POSITION_PLUS_LOCAL_POSITION },
45  { "DONT_INHERIT_POSITION", DONT_INHERIT_POSITION },
46 };
47 const unsigned int POSITION_INHERITANCE_MODE_VALUES_COUNT = sizeof( POSITION_INHERITANCE_MODE_VALUES ) / sizeof( POSITION_INHERITANCE_MODE_VALUES[0] );
48 
50 {
51  { "NORMAL", DrawMode::NORMAL },
52  { "OVERLAY_2D", DrawMode::OVERLAY_2D },
53  { "STENCIL", DrawMode::STENCIL },
54 };
55 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( DRAW_MODE_VALUES[0] );
56 
57 
59 // Helpers for string to enum comparisons for Image and Image loading parameters
61 
65 template< typename T, typename X >
67  Property::Map& map, // The map used to create instance of type X
68  const char * const keyName, // the name of the key to iterate through
69  const StringEnum* values, // An array of string values
70  unsigned int num, // Number of items in the array
71  T ( X::*method )() const, // The member method of X to call to get the enum
72  X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X
73 )
74 {
75  // get the key reference so we can change its value
76  Property::Value* value = map.Find( keyName );
77  for ( unsigned int i = 0; i < num; ++i )
78  {
79  *value = values[i].string;
80  tet_printf("Checking: %s: %s\n", keyName, values[i].string );
81  X instance = creator( map );
82  DALI_TEST_EQUALS( values[i].value, (int)( instance.*method )(), TEST_LOCATION );
83  }
84 }
85 
88 {
90  return image;
91 }
92 
95 {
96  BufferImage image = BufferImage::DownCast( NewImage( map ) );
97  return image;
98 }
99 
101 // Helpers for string to enum comparisons for Actor to Property::Map
103 
107 template< typename T >
109  const char * const keyName, // The name of the key to check
110  TestApplication& application, // Reference to the application class
111  const StringEnum* values, // An array of string values
112  unsigned int num, // Number of items in the array
113  void ( Actor::*method )( T ) // The Actor member method to set the enumeration
114 )
115 {
116  for ( unsigned int i = 0; i < num; ++i )
117  {
118  tet_printf("Checking: %s: %s\n", keyName, values[i].string );
119 
120  Actor actor = Actor::New();
121  (actor.*method)( ( T ) values[i].value );
122 
123  Stage::GetCurrent().Add( actor );
124  application.SendNotification();
125  application.Render();
126 
127  Property::Map map;
128  CreatePropertyMap( actor, map );
129 
130  DALI_TEST_CHECK( 0 < map.Count() );
131  DALI_TEST_CHECK( NULL != map.Find( keyName ) );
132  DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION );
133 
134  Stage::GetCurrent().Remove( actor );
135  }
136 }
137 
139 
140 
141 } // anon namespace
142 
143 
144 
146 {
147  for ( unsigned int i = 0; i < COLOR_MODE_VALUES_COUNT; ++i )
148  {
149  tet_printf( "Checking %s == %d\n", COLOR_MODE_VALUES[i].string, COLOR_MODE_VALUES[i].value );
150  DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].value, (int)GetColorMode( COLOR_MODE_VALUES[i].string ), TEST_LOCATION );
151  DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].string, GetColorMode( (ColorMode) COLOR_MODE_VALUES[i].value ), TEST_LOCATION );
152  }
153 
155  END_TEST;
156 }
157 
159 {
160  for ( unsigned int i = 0; i < POSITION_INHERITANCE_MODE_VALUES_COUNT; ++i )
161  {
162  tet_printf( "Checking %s == %d\n", POSITION_INHERITANCE_MODE_VALUES[i].string, POSITION_INHERITANCE_MODE_VALUES[i].value );
163  DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].value, (int)GetPositionInheritanceMode( POSITION_INHERITANCE_MODE_VALUES[i].string ), TEST_LOCATION );
164  DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].string, GetPositionInheritanceMode( (PositionInheritanceMode) POSITION_INHERITANCE_MODE_VALUES[i].value ), TEST_LOCATION );
165  }
166 
167  DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[0].value, (int)GetPositionInheritanceMode("INVALID_ARG"), TEST_LOCATION );
168  END_TEST;
169 }
170 
171 
173 {
174  for ( unsigned int i = 0; i < DRAW_MODE_VALUES_COUNT; ++i )
175  {
176  tet_printf( "Checking %s == %d\n", DRAW_MODE_VALUES[i].string, DRAW_MODE_VALUES[i].value );
177  DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].value, (int)GetDrawMode( DRAW_MODE_VALUES[i].string ), TEST_LOCATION );
178  DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].string, GetDrawMode( (DrawMode::Type) DRAW_MODE_VALUES[i].value ), TEST_LOCATION );
179  }
180 
181  DALI_TEST_EQUALS( DRAW_MODE_VALUES[0].value, (int)GetDrawMode( "INVALID_ARG" ), TEST_LOCATION );
182 
183  END_TEST;
184 }
185 
187 {
197 
199  END_TEST;
200 }
201 
203 {
204  // Invalid filename
205  Property::Map map;
206  map[ "filename" ] = Vector3::ZERO;
207  // will give us an empty image handle
208  Image image = NewImage( map );
209  DALI_TEST_CHECK( !image );
210  END_TEST;
211 }
212 
214 {
215  TestApplication application; // Image needs application
216  // Invalid load-policy value type
217  Property::Map map;
218  map[ "filename" ] = "TEST_FILE";
219  map[ "loadPolicy" ] = Vector3::ZERO;
220  // will give us a valid image handle with default load policy
221  Image image = NewImage( map );
222  DALI_TEST_CHECK( image );
223  ResourceImage resImage = ResourceImage::DownCast( image );
224  DALI_TEST_CHECK( resImage );
226  END_TEST;
227 }
228 
230 {
231  TestApplication application; // Image needs application
232  // Invalid load-policy value
233  Property::Map map;
234  map[ "filename" ] = "TEST_FILE";
235  map[ "loadPolicy" ] = "INVALID";
236  // will give us a valid image with default load policy
237  Image image = NewImage( map );
238  DALI_TEST_CHECK( image );
239  ResourceImage resImage = ResourceImage::DownCast( image );
240  DALI_TEST_CHECK( resImage );
242  END_TEST;
243 }
244 
246 {
247  TestApplication application; // Image needs application
248  // Invalid release-policy value type
249  Property::Map map;
250  map[ "filename" ] = "TEST_FILE";
251  map[ "releasePolicy" ] = Vector3::ZERO;
252  // will give us a valid image with default release policy
253  Image image = NewImage( map );
254  DALI_TEST_CHECK( image );
255  ResourceImage resImage = ResourceImage::DownCast( image );
256  DALI_TEST_CHECK( resImage );
258  END_TEST;
259 }
260 
262 {
263  TestApplication application; // Image needs application
264  // Invalid release-policy value
265  Property::Map map;
266  map[ "filename" ] = "TEST_FILE";
267  map[ "releasePolicy" ] = "INVALID";
268  // will give us a valid image with default release policy
269  Image image = NewImage( map );
270  DALI_TEST_CHECK( image );
271  ResourceImage resImage = ResourceImage::DownCast( image );
272  DALI_TEST_CHECK( resImage );
274  END_TEST;
275 }
276 
278 {
279  TestApplication application; // Image needs application
280  // Invalid width and height
281  Property::Map map;
282  map[ "filename" ] = "TEST_FILE";
283  map[ "width" ] = "Invalid";
284  map[ "height" ] = 100;
285  // will give us a valid image
286  Image image = NewImage( map );
287  DALI_TEST_CHECK( image );
288  ResourceImage resImage = ResourceImage::DownCast( image );
289  DALI_TEST_CHECK( resImage );
290  DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
291  DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
292  END_TEST;
293 }
294 
296 {
297  TestApplication application; // Image needs application
298  // Invalid height
299  Property::Map map;
300  map[ "filename" ] = "TEST_FILE";
301  map[ "width" ] = 10;
302  map[ "height" ] = "Invalid";
303  // will give us a valid image
304  Image image = NewImage( map );
305  DALI_TEST_CHECK( image );
306  ResourceImage resImage = ResourceImage::DownCast( image );
307  DALI_TEST_CHECK( resImage );
308  DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
309  DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
310  END_TEST;
311 }
312 
314 {
315  TestApplication application; // Image needs application
316  // Invalid fitting-mode
317  Property::Map map;
318  map[ "filename" ] = "TEST_FILE";
319  map[ "fittingMode" ] = Vector3::ZERO;
320  // will give us a valid image
321  Image image = NewImage( map );
322  DALI_TEST_CHECK( image );
323  ResourceImage resImage = ResourceImage::DownCast( image );
324  DALI_TEST_CHECK( resImage );
325  END_TEST;
326 }
327 
329 {
330  TestApplication application; // Image needs application
331  // Invalid value
332  Property::Map map;
333  map[ "filename" ] = "TEST_FILE";
334  map[ "fittingMode" ] = "INVALID";
335  // will give us a valid image
336  Image image = NewImage( map );
337  DALI_TEST_CHECK( image );
338  ResourceImage resImage = ResourceImage::DownCast( image );
339  DALI_TEST_CHECK( resImage );
340  END_TEST;
341 }
342 
344 {
345  TestApplication application; // Image needs application
346  // Invalid scaling-mode
347  Property::Map map;
348  map[ "filename" ] = "TEST_FILE";
349  map[ "samplingMode" ] = Vector3::ZERO;
350  // will give us a valid image
351  Image image = NewImage( map );
352  DALI_TEST_CHECK( image );
353  ResourceImage resImage = ResourceImage::DownCast( image );
354  DALI_TEST_CHECK( resImage );
355  END_TEST;
356 }
357 
359 {
360  TestApplication application; // Image needs application
361  // Invalid orientation-correction
362  Property::Map map;
363  map[ "filename" ] = "TEST_FILE";
364  map[ "orientation" ] = Vector3::ZERO;
365  // will give us a valid image
366  Image image = NewImage( map );
367  DALI_TEST_CHECK( image );
368  ResourceImage resImage = ResourceImage::DownCast( image );
369  DALI_TEST_CHECK( resImage );
370  END_TEST;
371 }
372 
374 {
375  TestApplication application; // Image needs application
376  // Invalid type
377  Property::Map map;
378  map[ "filename" ] = "TEST_FILE";
379  map[ "type" ] = Vector3::ZERO;
380  // will give us a valid image
381  Image image = NewImage( map );
382  DALI_TEST_CHECK( image );
383  ResourceImage resImage = ResourceImage::DownCast( image );
384  DALI_TEST_CHECK( resImage );
385  END_TEST;
386 }
387 
389 {
390  // Invalid value
391  Property::Map map;
392  map[ "type" ] = "INVALID";
393  Image image = NewImage( map );
394  DALI_TEST_CHECK( !image );
395  END_TEST;
396 }
397 
399 {
400  // Invalid pixel-format
401  Property::Map map;
402  map[ "pixelFormat" ] = Vector3::ZERO;
403  Image image = NewImage( map );
404  DALI_TEST_CHECK( !image );
405  END_TEST;
406 }
407 
409 {
410  // Invalid value
411  Property::Map map;
412  map[ "pixelFormat" ] = "INVALID";
413  Image image = NewImage( map );
414  DALI_TEST_CHECK( !image );
415  END_TEST;
416 }
417 
419 {
420  TestApplication application; // Image needs application
421 
422  Property::Map map;
423  map[ "filename" ] = "TEST_FILE";
424 
425  // Filename only
427  DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
428  END_TEST;
429 }
430 
432 {
433  TestApplication application;
434 
435  Property::Map map;
436  map[ "filename" ] = "TEST_FILE";
437 
438  // load-policy
439  map[ "loadPolicy" ] = "";
440  const StringEnum values[] =
441  {
442  { "IMMEDIATE", ResourceImage::IMMEDIATE },
443  { "ON_DEMAND", ResourceImage::ON_DEMAND }
444  };
445  TestEnumStrings< ResourceImage::LoadPolicy, ResourceImage >( map, "loadPolicy", values, ( sizeof( values ) / sizeof ( values[0] ) ), &ResourceImage::GetLoadPolicy, &NewResourceImage );
446  END_TEST;
447 }
448 
450 {
451  TestApplication application;
452 
453  Property::Map map;
454  map[ "filename" ] = "TEST_FILE";
455 
456  // release-policy
457  map[ "releasePolicy" ] = "";
458  const StringEnum values[] =
459  {
460  { "UNUSED", Image::UNUSED },
461  { "NEVER", Image::NEVER }
462  };
463  TestEnumStrings< Image::ReleasePolicy, Image >( map, "releasePolicy", values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage );
464  END_TEST;
465 }
466 
468 {
469  TestApplication application;
470 
471  Property::Map map;
472  map[ "filename" ] = "TEST_FILE";
473 
474  // float width and height
475  map[ "width" ] = (float) 10.0f;
476  map[ "height" ] = (float) 20.0f;
477  Image image = NewImage( map );
478  DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
479  DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
480  END_TEST;
481 }
482 
484 {
485  TestApplication application;
486 
487  Property::Map map;
488  map[ "filename" ] = "TEST_FILE";
489 
490  // width and height
491  map[ "width"] = 50;
492  map[ "height" ] = 70;
493  Image image = NewImage( map );
494  DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
495  DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
496  END_TEST;
497 }
498 
500 {
501  TestApplication application;
502 
503  Property::Map map;
504  // type FrameBufferImage
505  map[ "type" ] = "FrameBufferImage";
506  // width and height
507  map[ "width"] = 50;
508  map[ "height" ] = 70;
509  Image image = NewImage( map );
510  DALI_TEST_CHECK( image );
512  END_TEST;
513 }
514 
516 {
517  TestApplication application;
518 
519  Property::Map map;
520  // type BufferImage
521  map[ "type" ] = "BufferImage";
522  // width and height
523  map[ "width"] = 50;
524  map[ "height" ] = 70;
525  Image image = NewImage( map );
526  DALI_TEST_CHECK( image );
528  DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
529  END_TEST;
530 }
531 
533 {
534  TestApplication application;
535 
536  Property::Map map;
537  map[ "type" ] = "BufferImage";
538  // width and height
539  map[ "width"] = 66;
540  map[ "height" ] = 99;
541  // pixel-format
542  map[ "pixelFormat" ] = "";
543  const StringEnum values[] =
544  {
545  { "A8", Pixel::A8 },
546  { "L8", Pixel::L8 },
547  { "LA88", Pixel::LA88 },
548  { "RGB565", Pixel::RGB565 },
549  { "BGR565", Pixel::BGR565 },
550  { "RGBA4444", Pixel::RGBA4444 },
551  { "BGRA4444", Pixel::BGRA4444 },
552  { "RGBA5551", Pixel::RGBA5551 },
553  { "BGRA5551", Pixel::BGRA5551 },
554  { "RGB888", Pixel::RGB888 },
555  { "RGB8888", Pixel::RGB8888 },
556  { "BGR8888", Pixel::BGR8888 },
557  { "RGBA8888", Pixel::RGBA8888 },
558  { "BGRA8888", Pixel::BGRA8888 },
559  // BufferImage does not support compressed formats
560  };
561  TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
562 
563  END_TEST;
564 }
565 
567 {
568  TestApplication application;
569 
570  Property::Map map;
571  // type Image
572  map[ "type" ] = "ResourceImage";
573  map[ "filename" ] = "TEST_FILE";
574 
575  {
576  Image image = NewImage( map );
580  }
581  END_TEST;
582 }
583 
585 {
586  TestApplication application;
587 
588  Property::Map map;
589  // type FrameBufferImage, empty size gives us stage size
590  map[ "type" ] = "FrameBufferImage";
591  Image image = NewImage( map );
592  DALI_TEST_CHECK( image );
593  END_TEST;
594 }
595 
597 {
598  TestApplication application;
599 
600  Property::Map programMap;
601  programMap[ "vertexFilename" ] = "bump.vert";
602  programMap[ "fragmentFilename" ] = "bump.frag";
603 
604  Property::Map imageMap;
605  imageMap[ "filename" ] = "image.png";
606 
607  Property::Map map;
608  map[ "image" ] = imageMap;
609  map[ "program" ] = programMap;
610  map[ "uLightPosition" ] = Vector3( 0.0, 0.0, -1.5);
611  map[ "uAmbientLight" ] = (int)10;
612 
613  ShaderEffect shader = NewShaderEffect( map );
614 
615  DALI_TEST_CHECK( shader );
616  END_TEST;
617 }
618 
620 {
621  TestApplication application;
622 
623  // Empty map
624  {
625  Actor handle = NewActor( Property::Map() );
626  DALI_TEST_CHECK( !handle );
627  }
628 
629  // Map with only properties
630  {
631  Property::Map map;
632  map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
633  map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
634  Actor handle = NewActor( map );
635  DALI_TEST_CHECK( !handle );
636  }
637 
638  // Add some signals to the map, we should have no signal connections as its not yet supported
639  {
640  Property::Map map;
641  map[ "type" ] = "Actor";
642  map[ "signals" ] = Property::MAP;
643  Actor handle = NewActor( map );
644  DALI_TEST_CHECK( handle );
645  DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
646  DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
647  DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
648  DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
649  }
650  END_TEST;
651 }
652 
654 {
655  TestApplication application;
656 
657  Property::Map map;
658  map[ "type" ] = "Actor";
659  map[ "size" ] = Vector3::ONE;
660  map[ "position" ] = Vector3::XAXIS;
661  map[ "scale" ] = Vector3::ONE;
662  map[ "visible" ] = false;
663  map[ "color" ] = Color::MAGENTA;
664  map[ "name" ] = "MyActor";
665  map[ "colorMode" ] = "USE_PARENT_COLOR";
666  map[ "inheritShaderEffect" ] = false;
667  map[ "sensitive" ] = false;
668  map[ "leaveRequired" ] = true;
669  map[ "positionInheritance" ] = "DONT_INHERIT_POSITION";
670  map[ "drawMode" ] = "STENCIL";
671  map[ "inheritOrientation" ] = false;
672  map[ "inheritScale" ] = false;
673 
674  // Default properties
675  {
676  Actor handle = NewActor( map );
677  DALI_TEST_CHECK( handle );
678 
679  Stage::GetCurrent().Add( handle );
680  application.SendNotification();
681  application.Render();
682 
686  DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
688  DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
690  DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
695  DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
696 
697  Stage::GetCurrent().Remove( handle );
698  }
699 
700  // Check Anchor point and parent origin vector3s
701  map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
702  map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
703  {
704  Actor handle = NewActor( map );
705  DALI_TEST_CHECK( handle );
706 
707  Stage::GetCurrent().Add( handle );
708  application.SendNotification();
709  application.Render();
710 
713 
714  Stage::GetCurrent().Remove( handle );
715  }
716 
717  // Check Anchor point and parent origin STRINGS
718  map[ "parentOrigin" ] = "TOP_LEFT";
719  map[ "anchorPoint" ] = "CENTER_LEFT";
720  {
721  Actor handle = NewActor( map );
722  DALI_TEST_CHECK( handle );
723 
724  Stage::GetCurrent().Add( handle );
725  application.SendNotification();
726  application.Render();
727 
730 
731  Stage::GetCurrent().Remove( handle );
732  }
733  END_TEST;
734 }
735 
737 {
738  TestApplication application;
739 
740  Property::Map map;
741  map[ "type" ] = "Actor";
742  map[ "position" ] = Vector3::XAXIS;
743 
744  Property::Map child1Map;
745  child1Map[ "type" ] = "ImageActor";
746  child1Map[ "position" ] = Vector3::YAXIS;
747 
748  Property::Array childArray;
749  childArray.PushBack( child1Map );
750  map[ "actors" ] = childArray;
751 
752  // Create
753  Actor handle = NewActor( map );
754  DALI_TEST_CHECK( handle );
755 
756  Stage::GetCurrent().Add( handle );
757  application.SendNotification();
758  application.Render();
759 
762 
763  Actor child1 = handle.GetChildAt(0);
764  DALI_TEST_CHECK( child1 );
766  DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
767  DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
768 
769  Stage::GetCurrent().Remove( handle );
770  END_TEST;
771 }
772 
773 
775 {
776  TestApplication application;
777 
778  // Actor Type
779  {
780  Actor actor = Actor::New();
781 
782  Property::Map map;
783  CreatePropertyMap( actor, map );
784  DALI_TEST_CHECK( !map.Empty() );
785  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
786  DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
787 
788  Stage::GetCurrent().Remove( actor );
789  }
790 
791  // ImageActor Type
792  {
793  Actor actor = ImageActor::New();
794 
795  Property::Map map;
796  CreatePropertyMap( actor, map );
797  DALI_TEST_CHECK( !map.Empty() );
798  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
799  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION );
800 
801  Stage::GetCurrent().Remove( actor );
802  }
803 
804  // Default properties
805  {
806  Actor actor = Actor::New();
807  actor.SetSize( Vector3::ONE );
808  actor.SetPosition( Vector3::XAXIS );
809  actor.SetScale( Vector3::ZAXIS );
810  actor.SetVisible( false );
811  actor.SetColor( Color::MAGENTA );
812  actor.SetName( "MyActor" );
815  actor.SetSensitive( false );
816  actor.SetLeaveRequired( true );
817  actor.SetInheritOrientation( false );
818  actor.SetInheritScale( false );
820 
821  Stage::GetCurrent().Add( actor );
822  application.SendNotification();
823  application.Render();
824 
825  Property::Map map;
826  CreatePropertyMap( actor, map );
827 
828  DALI_TEST_CHECK( !map.Empty() );
829  DALI_TEST_CHECK( NULL != map.Find( "size" ) );
830  DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
831  DALI_TEST_CHECK( NULL != map.Find( "position" ) );
832  DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
833  DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
834  DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
835  DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
836  DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
837  DALI_TEST_CHECK( NULL != map.Find( "color" ) );
838  DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
839  DALI_TEST_CHECK( NULL != map.Find( "name" ) );
840  DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
841  DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
842  DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
843  DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
844  DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
845  DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
846  DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
847  DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
848  DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
849  DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
850  DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
851  DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
852  DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
853  DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
854  DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
855 
856  Stage::GetCurrent().Remove( actor );
857  }
858 
859  // ColorMode
860  TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
861 
862  // PositionInheritanceMode
863  TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
864 
865  // DrawMode
866  TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
867 
868  // Children
869  {
870  Actor actor = Actor::New();
871  Actor child = ImageActor::New();
872  actor.Add( child );
873 
874  Stage::GetCurrent().Add( actor );
875  application.SendNotification();
876  application.Render();
877 
878  Property::Map map;
879  CreatePropertyMap( actor, map );
880  DALI_TEST_CHECK( !map.Empty() );
881 
882  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
883  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
884 
885  DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
886  Property::Array children( map.Find( "actors")->Get< Property::Array >() );
887  DALI_TEST_CHECK( !children.Empty() );
888  Property::Map childMap( children[0].Get< Property::Map >() );
889  DALI_TEST_CHECK( !childMap.Empty() );
890  DALI_TEST_CHECK( childMap.Find( "type" ) );
891  DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION );
892 
893  Stage::GetCurrent().Remove( actor );
894  }
895  END_TEST;
896 }
897 
899 {
900  TestApplication application;
901 
902  // Empty
903  {
904  Image image;
905  Property::Map map;
906  CreatePropertyMap( image, map );
907  DALI_TEST_CHECK( map.Empty() );
908  }
909 
910  // Default
911  {
912  Image image = ResourceImage::New( "MY_PATH" );
913 
914  Property::Map map;
915  CreatePropertyMap( image, map );
916  DALI_TEST_CHECK( !map.Empty() );
917 
918  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
919  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
920  DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
921  DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
922  DALI_TEST_CHECK( NULL != map.Find( "loadPolicy") );
923  DALI_TEST_EQUALS( map.Find( "loadPolicy" )->Get< std::string >(), "IMMEDIATE", TEST_LOCATION );
924  DALI_TEST_CHECK( NULL != map.Find( "releasePolicy") );
925  DALI_TEST_EQUALS( map.Find( "releasePolicy" )->Get< std::string >(), "NEVER", TEST_LOCATION );
926  DALI_TEST_CHECK( NULL == map.Find( "width" ) );
927  DALI_TEST_CHECK( NULL == map.Find( "height" ) );
928  }
929 
930  // Change values
931  {
933 
934  Property::Map map;
935  CreatePropertyMap( image, map );
936  DALI_TEST_CHECK( !map.Empty() );
937 
938  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
939  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
940  DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
941  DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
942  DALI_TEST_CHECK( NULL != map.Find( "loadPolicy") );
943  DALI_TEST_EQUALS( map.Find( "loadPolicy" )->Get< std::string >(), "ON_DEMAND", TEST_LOCATION );
944  DALI_TEST_CHECK( NULL != map.Find( "releasePolicy") );
945  DALI_TEST_EQUALS( map.Find( "releasePolicy" )->Get< std::string >(), "UNUSED", TEST_LOCATION );
946  DALI_TEST_CHECK( NULL != map.Find( "width" ) );
947  DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
948  DALI_TEST_CHECK( NULL != map.Find( "height" ) );
949  DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
950  }
951 
952  // BufferImage
953  {
954  Image image = BufferImage::New( 200, 300, Pixel::A8 );
955  Property::Map map;
956  CreatePropertyMap( image, map );
957  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
958  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
959  DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
960  DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
961  }
962 
963  // FrameBufferImage
964  {
965  Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
966  Property::Map map;
967  CreatePropertyMap( image, map );
968  DALI_TEST_CHECK( NULL != map.Find( "type" ) );
969  DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
970  }
971  END_TEST;
972 }
973 
975 {
976  const Scripting::StringEnum myTable[] =
977  {
978  { "ONE", 1 },
979  { "TWO", 2 },
980  { "THREE", 3 },
981  { "FOUR", 4 },
982  { "FIVE", 5 },
983  };
984  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
985 
986  for ( unsigned int i = 0; i < myTableCount; ++i )
987  {
988  tet_printf("Checking: %s\n", myTable[ i ].string );
989  int value;
990  DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
991  DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
992  }
993 
994  for ( unsigned int i = 0; i < myTableCount; ++i )
995  {
996  tet_printf("Checking: %d\n", myTable[ i ].value );
997  DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
998  }
999 
1000  END_TEST;
1001 }
1002 
1004 {
1005  const char* value = GetEnumerationName( 10, NULL, 0 );
1006  DALI_TEST_CHECK( NULL == value );
1007 
1008  value = GetEnumerationName( 10, NULL, 1 );
1009  DALI_TEST_CHECK( NULL == value );
1010 
1011  END_TEST;
1012 }
1013 
1015 {
1016  const char* value = GetLinearEnumerationName( 10, NULL, 0 );
1017  DALI_TEST_CHECK( NULL == value );
1018 
1019  value = GetLinearEnumerationName( 10, NULL, 1 );
1020  DALI_TEST_CHECK( NULL == value );
1021 
1022  END_TEST;
1023 }
1024 
1026 {
1027  const Scripting::StringEnum myTable[] =
1028  {
1029  { "ONE", (1<<1) },
1030  { "TWO", (1<<2) },
1031  { "THREE", (1<<3) },
1032  { "FOUR", (1<<4) },
1033  { "FIVE", (1<<5) },
1034  };
1035  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1036  DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1037 
1038  END_TEST;
1039 }
1040 
1042 {
1043  const Scripting::StringEnum myTable[] =
1044  {
1045  { "ONE", (1<<1) },
1046  { "TWO", (1<<2) },
1047  { "THREE", (1<<3) },
1048  { "FOUR", (1<<4) },
1049  { "FIVE", (1<<5) },
1050  };
1051  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1052 
1053  unsigned int integerEnum = 0;
1054  DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1055 
1056  DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1057 
1058  integerEnum = 0;
1059  DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1060  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1061 
1062  DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1063  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1064 
1065  DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1066  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1067 
1068  DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1069  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1070 
1071  DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1072  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1073 
1074  DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1075  DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1076 
1077  DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1078  DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1079 
1080  DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1081  DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1082 
1083 
1084  END_TEST;
1085 }
1086 
1088 {
1089  const Scripting::StringEnum myTable[] =
1090  {
1091  { "ONE", 1 },
1092  { "TWO", 2 },
1093  { "THREE", 3 },
1094  { "FOUR", 4 },
1095  { "FIVE", 5 },
1096  };
1097  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1098 
1099  unsigned int integerEnum = 0;
1100  DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1101 
1102  DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1103 
1104  DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1105 
1106  DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1107 
1108  DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1109 
1110  DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1111 
1112  DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1113 
1114  END_TEST;
1115 }
1116 
1118 {
1119  const Scripting::StringEnum myTable[] =
1120  {
1121  { "", 1 },
1122  { "", 2 },
1123  { "", 3 },
1124  };
1125 
1126  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1127 
1128  unsigned int integerEnum = 0;
1129  DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1130  DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1131 
1132  END_TEST;
1133 }
1134 
1136 {
1137  const Scripting::StringEnum myTable[] =
1138  {
1139  { "", 1 },
1140  { "", 1 },
1141  { "", 1 },
1142  };
1143 
1144  const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1145 
1146  unsigned int integerEnum = 0;
1147  DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1148 
1149  DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1150 
1151  DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1152 
1153  DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1154 
1155  DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1156 
1157  DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1158 
1159  END_TEST;
1160 }
Dali Docs Home
Read more about Dali