2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/scripting/scripting.h>
23 #include <dali-test-suite-utils.h>
26 using namespace Dali::Scripting;
31 const StringEnum COLOR_MODE_VALUES[] =
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 },
38 const unsigned int COLOR_MODE_VALUES_COUNT = sizeof( COLOR_MODE_VALUES ) / sizeof( COLOR_MODE_VALUES[0] );
40 const StringEnum POSITION_INHERITANCE_MODE_VALUES[] =
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 },
47 const unsigned int POSITION_INHERITANCE_MODE_VALUES_COUNT = sizeof( POSITION_INHERITANCE_MODE_VALUES ) / sizeof( POSITION_INHERITANCE_MODE_VALUES[0] );
49 const StringEnum DRAW_MODE_VALUES[] =
51 { "NORMAL", DrawMode::NORMAL },
52 { "OVERLAY_2D", DrawMode::OVERLAY_2D },
53 { "STENCIL", DrawMode::STENCIL },
55 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( DRAW_MODE_VALUES[0] );
58 ////////////////////////////////////////////////////////////////////////////////
59 // Helpers for string to enum comparisons for Image and Image loading parameters
60 ////////////////////////////////////////////////////////////////////////////////
63 * Template to check enumerations of type T, with a class of type X
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
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 )
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 );
86 /// Helper method to create ResourceImage using property
87 ResourceImage NewResourceImage( const Property::Value& map )
89 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
93 /// Helper method to create ResourceImage using property
94 BufferImage NewBufferImage( const Property::Value& map )
96 BufferImage image = BufferImage::DownCast( NewImage( map ) );
100 //////////////////////////////////////////////////////////////////////////////
101 // Helpers for string to enum comparisons for Actor to Property::Map
102 //////////////////////////////////////////////////////////////////////////////
105 * Template to check enumerations of type T
107 template< typename T >
108 void TestEnumStrings(
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
116 for ( unsigned int i = 0; i < num; ++i )
118 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
120 Actor actor = Actor::New();
121 (actor.*method)( ( T ) values[i].value );
123 Stage::GetCurrent().Add( actor );
124 application.SendNotification();
125 application.Render();
128 CreatePropertyMap( actor, map );
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 );
134 Stage::GetCurrent().Remove( actor );
138 //////////////////////////////////////////////////////////////////////////////
143 int UtcDaliScriptingNewImageNegative01(void)
147 map[ "filename" ] = Vector3::ZERO;
148 // will give us an empty image handle
149 Image image = NewImage( map );
150 DALI_TEST_CHECK( !image );
154 int UtcDaliScriptingNewImageNegative06(void)
156 TestApplication application; // Image needs application
157 // Invalid width and height
159 map[ "filename" ] = "TEST_FILE";
160 map[ "width" ] = "Invalid";
161 map[ "height" ] = 100;
162 // will give us a valid image
163 Image image = NewImage( map );
164 DALI_TEST_CHECK( image );
165 ResourceImage resImage = ResourceImage::DownCast( image );
166 DALI_TEST_CHECK( resImage );
167 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
168 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
172 int UtcDaliScriptingNewImageNegative07(void)
174 TestApplication application; // Image needs application
177 map[ "filename" ] = "TEST_FILE";
179 map[ "height" ] = "Invalid";
180 // will give us a valid image
181 Image image = NewImage( map );
182 DALI_TEST_CHECK( image );
183 ResourceImage resImage = ResourceImage::DownCast( image );
184 DALI_TEST_CHECK( resImage );
185 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
186 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
190 int UtcDaliScriptingNewImageNegative08(void)
192 TestApplication application; // Image needs application
193 // Invalid fitting-mode
195 map[ "filename" ] = "TEST_FILE";
196 map[ "fittingMode" ] = Vector3::ZERO;
197 // will give us a valid image
198 Image image = NewImage( map );
199 DALI_TEST_CHECK( image );
200 ResourceImage resImage = ResourceImage::DownCast( image );
201 DALI_TEST_CHECK( resImage );
205 int UtcDaliScriptingNewImageNegative09(void)
207 TestApplication application; // Image needs application
210 map[ "filename" ] = "TEST_FILE";
211 map[ "fittingMode" ] = "INVALID";
212 // will give us a valid image
213 Image image = NewImage( map );
214 DALI_TEST_CHECK( image );
215 ResourceImage resImage = ResourceImage::DownCast( image );
216 DALI_TEST_CHECK( resImage );
220 int UtcDaliScriptingNewImageNegative10(void)
222 TestApplication application; // Image needs application
223 // Invalid scaling-mode
225 map[ "filename" ] = "TEST_FILE";
226 map[ "samplingMode" ] = Vector3::ZERO;
227 // will give us a valid image
228 Image image = NewImage( map );
229 DALI_TEST_CHECK( image );
230 ResourceImage resImage = ResourceImage::DownCast( image );
231 DALI_TEST_CHECK( resImage );
235 int UtcDaliScriptingNewImageNegative12(void)
237 TestApplication application; // Image needs application
238 // Invalid orientation-correction
240 map[ "filename" ] = "TEST_FILE";
241 map[ "orientation" ] = Vector3::ZERO;
242 // will give us a valid image
243 Image image = NewImage( map );
244 DALI_TEST_CHECK( image );
245 ResourceImage resImage = ResourceImage::DownCast( image );
246 DALI_TEST_CHECK( resImage );
250 int UtcDaliScriptingNewImageNegative13(void)
252 TestApplication application; // Image needs application
255 map[ "filename" ] = "TEST_FILE";
256 map[ "type" ] = Vector3::ZERO;
257 // will give us a valid image
258 Image image = NewImage( map );
259 DALI_TEST_CHECK( image );
260 ResourceImage resImage = ResourceImage::DownCast( image );
261 DALI_TEST_CHECK( resImage );
265 int UtcDaliScriptingNewImageNegative14(void)
269 map[ "type" ] = "INVALID";
270 Image image = NewImage( map );
271 DALI_TEST_CHECK( !image );
275 int UtcDaliScriptingNewImageNegative15(void)
277 // Invalid pixel-format
279 map[ "pixelFormat" ] = Vector3::ZERO;
280 Image image = NewImage( map );
281 DALI_TEST_CHECK( !image );
285 int UtcDaliScriptingNewImageNegative16(void)
289 map[ "pixelFormat" ] = "INVALID";
290 Image image = NewImage( map );
291 DALI_TEST_CHECK( !image );
295 int UtcDaliScriptingNewImage01P(void)
297 TestApplication application; // Image needs application
300 map[ "filename" ] = "TEST_FILE";
303 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
304 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
308 int UtcDaliScriptingNewImage04P(void)
310 TestApplication application;
313 map[ "filename" ] = "TEST_FILE";
315 // float width and height
316 map[ "width" ] = (float) 10.0f;
317 map[ "height" ] = (float) 20.0f;
318 Image image = NewImage( map );
319 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
320 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
324 int UtcDaliScriptingNewImage05P(void)
326 TestApplication application;
329 map[ "filename" ] = "TEST_FILE";
333 map[ "height" ] = 70;
334 Image image = NewImage( map );
335 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
336 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
340 int UtcDaliScriptingNewImage06P(void)
342 TestApplication application;
345 // type FrameBufferImage
346 map[ "type" ] = "FrameBufferImage";
349 map[ "height" ] = 70;
350 Image image = NewImage( map );
351 DALI_TEST_CHECK( image );
352 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
356 int UtcDaliScriptingNewImage07P(void)
358 TestApplication application;
362 map[ "type" ] = "BufferImage";
365 map[ "height" ] = 70;
366 Image image = NewImage( map );
367 DALI_TEST_CHECK( image );
368 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
369 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
373 int UtcDaliScriptingNewImage08P(void)
375 TestApplication application;
378 map[ "type" ] = "BufferImage";
381 map[ "height" ] = 99;
383 map[ "pixelFormat" ] = "";
384 const StringEnum values[] =
388 { "LA88", Pixel::LA88 },
389 { "RGB565", Pixel::RGB565 },
390 { "BGR565", Pixel::BGR565 },
391 { "RGBA4444", Pixel::RGBA4444 },
392 { "BGRA4444", Pixel::BGRA4444 },
393 { "RGBA5551", Pixel::RGBA5551 },
394 { "BGRA5551", Pixel::BGRA5551 },
395 { "RGB888", Pixel::RGB888 },
396 { "RGB8888", Pixel::RGB8888 },
397 { "BGR8888", Pixel::BGR8888 },
398 { "RGBA8888", Pixel::RGBA8888 },
399 { "BGRA8888", Pixel::BGRA8888 },
400 // BufferImage does not support compressed formats
402 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
407 int UtcDaliScriptingNewImage09P(void)
409 TestApplication application;
413 map[ "type" ] = "ResourceImage";
414 map[ "filename" ] = "TEST_FILE";
417 Image image = NewImage( map );
418 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
419 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
420 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
425 int UtcDaliScriptingNewImage10P(void)
427 TestApplication application;
430 // type FrameBufferImage, empty size gives us stage size
431 map[ "type" ] = "FrameBufferImage";
432 Image image = NewImage( map );
433 DALI_TEST_CHECK( image );
437 int UtcDaliScriptingNewActorNegative(void)
439 TestApplication application;
443 Actor handle = NewActor( Property::Map() );
444 DALI_TEST_CHECK( !handle );
447 // Map with only properties
450 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
451 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
452 Actor handle = NewActor( map );
453 DALI_TEST_CHECK( !handle );
456 // Add some signals to the map, we should have no signal connections as its not yet supported
459 map[ "type" ] = "Actor";
460 map[ "signals" ] = Property::MAP;
461 Actor handle = NewActor( map );
462 DALI_TEST_CHECK( handle );
463 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
464 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
465 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
466 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
471 int UtcDaliScriptingNewActorProperties(void)
473 TestApplication application;
476 map[ "type" ] = "Actor";
477 map[ "size" ] = Vector3::ONE;
478 map[ "position" ] = Vector3::XAXIS;
479 map[ "scale" ] = Vector3::ONE;
480 map[ "visible" ] = false;
481 map[ "color" ] = Color::MAGENTA;
482 map[ "name" ] = "MyActor";
483 map[ "colorMode" ] = "USE_PARENT_COLOR";
484 map[ "sensitive" ] = false;
485 map[ "leaveRequired" ] = true;
486 map[ "positionInheritance" ] = "DONT_INHERIT_POSITION";
487 map[ "drawMode" ] = "STENCIL";
488 map[ "inheritOrientation" ] = false;
489 map[ "inheritScale" ] = false;
491 // Default properties
493 Actor handle = NewActor( map );
494 DALI_TEST_CHECK( handle );
496 Stage::GetCurrent().Add( handle );
497 application.SendNotification();
498 application.Render();
500 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
501 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
502 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
503 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
504 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
505 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
506 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
507 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
508 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
509 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
510 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
511 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
512 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
514 Stage::GetCurrent().Remove( handle );
517 // Check Anchor point and parent origin vector3s
518 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
519 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
521 Actor handle = NewActor( map );
522 DALI_TEST_CHECK( handle );
524 Stage::GetCurrent().Add( handle );
525 application.SendNotification();
526 application.Render();
528 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
529 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
531 Stage::GetCurrent().Remove( handle );
534 // Check Anchor point and parent origin STRINGS
535 map[ "parentOrigin" ] = "TOP_LEFT";
536 map[ "anchorPoint" ] = "CENTER_LEFT";
538 Actor handle = NewActor( map );
539 DALI_TEST_CHECK( handle );
541 Stage::GetCurrent().Add( handle );
542 application.SendNotification();
543 application.Render();
545 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
546 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
548 Stage::GetCurrent().Remove( handle );
553 int UtcDaliScriptingNewActorChildren(void)
555 TestApplication application;
558 map[ "type" ] = "Actor";
559 map[ "position" ] = Vector3::XAXIS;
561 Property::Map child1Map;
562 child1Map[ "type" ] = "CameraActor";
563 child1Map[ "position" ] = Vector3::YAXIS;
565 Property::Array childArray;
566 childArray.PushBack( child1Map );
567 map[ "actors" ] = childArray;
570 Actor handle = NewActor( map );
571 DALI_TEST_CHECK( handle );
573 Stage::GetCurrent().Add( handle );
574 application.SendNotification();
575 application.Render();
577 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
578 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
580 Actor child1 = handle.GetChildAt(0);
581 DALI_TEST_CHECK( child1 );
582 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
583 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
584 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
586 Stage::GetCurrent().Remove( handle );
591 int UtcDaliScriptingCreatePropertyMapActor(void)
593 TestApplication application;
597 Actor actor = Actor::New();
600 CreatePropertyMap( actor, map );
601 DALI_TEST_CHECK( !map.Empty() );
602 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
603 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
605 Stage::GetCurrent().Remove( actor );
610 Actor actor = Layer::New();
613 CreatePropertyMap( actor, map );
614 DALI_TEST_CHECK( !map.Empty() );
615 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
616 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
618 Stage::GetCurrent().Remove( actor );
621 // Default properties
623 Actor actor = Actor::New();
624 actor.SetSize( Vector3::ONE );
625 actor.SetPosition( Vector3::XAXIS );
626 actor.SetScale( Vector3::ZAXIS );
627 actor.SetVisible( false );
628 actor.SetColor( Color::MAGENTA );
629 actor.SetName( "MyActor" );
630 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
631 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
632 actor.SetSensitive( false );
633 actor.SetLeaveRequired( true );
634 actor.SetInheritOrientation( false );
635 actor.SetInheritScale( false );
636 actor.SetSizeModeFactor( Vector3::ONE );
638 Stage::GetCurrent().Add( actor );
639 application.SendNotification();
640 application.Render();
643 CreatePropertyMap( actor, map );
645 DALI_TEST_CHECK( !map.Empty() );
646 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
647 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
648 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
649 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
650 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
651 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
652 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
653 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
654 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
655 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
656 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
657 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
658 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
659 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
660 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
661 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
662 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
663 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
664 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
665 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
666 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
667 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
668 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
669 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
670 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
671 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
673 Stage::GetCurrent().Remove( actor );
677 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
679 // PositionInheritanceMode
680 TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
683 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
687 Actor actor = Actor::New();
688 Actor child = Layer::New();
691 Stage::GetCurrent().Add( actor );
692 application.SendNotification();
693 application.Render();
696 CreatePropertyMap( actor, map );
697 DALI_TEST_CHECK( !map.Empty() );
699 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
700 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
702 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
703 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
704 DALI_TEST_CHECK( !children.Empty() );
705 Property::Map childMap( children[0].Get< Property::Map >() );
706 DALI_TEST_CHECK( !childMap.Empty() );
707 DALI_TEST_CHECK( childMap.Find( "type" ) );
708 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
710 Stage::GetCurrent().Remove( actor );
715 int UtcDaliScriptingCreatePropertyMapImage(void)
717 TestApplication application;
723 CreatePropertyMap( image, map );
724 DALI_TEST_CHECK( map.Empty() );
729 Image image = ResourceImage::New( "MY_PATH" );
732 CreatePropertyMap( image, map );
733 DALI_TEST_CHECK( !map.Empty() );
735 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
736 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
737 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
738 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
739 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
740 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
745 ResourceImage image = ResourceImage::New( "MY_PATH", ResourceImage::ON_DEMAND, Image::UNUSED, ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
748 CreatePropertyMap( image, map );
749 DALI_TEST_CHECK( !map.Empty() );
751 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
752 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
753 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
754 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
755 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
756 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
757 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
758 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
763 Image image = BufferImage::New( 200, 300, Pixel::A8 );
765 CreatePropertyMap( image, map );
766 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
767 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
768 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
769 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
774 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
776 CreatePropertyMap( image, map );
777 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
778 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
783 int UtcDaliScriptingGetEnumerationTemplates(void)
785 const Scripting::StringEnum myTable[] =
793 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
795 for ( unsigned int i = 0; i < myTableCount; ++i )
797 tet_printf("Checking: %s\n", myTable[ i ].string );
799 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
800 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
803 for ( unsigned int i = 0; i < myTableCount; ++i )
805 tet_printf("Checking: %d\n", myTable[ i ].value );
806 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
812 int UtcDaliScriptingGetEnumerationNameN(void)
814 const char* value = GetEnumerationName( 10, NULL, 0 );
815 DALI_TEST_CHECK( NULL == value );
817 value = GetEnumerationName( 10, NULL, 1 );
818 DALI_TEST_CHECK( NULL == value );
823 int UtcDaliScriptingGetLinearEnumerationNameN(void)
825 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
826 DALI_TEST_CHECK( NULL == value );
828 value = GetLinearEnumerationName( 10, NULL, 1 );
829 DALI_TEST_CHECK( NULL == value );
834 int UtcDaliScriptingGetEnumerationProperty(void)
837 * This test function performs the following checks:
838 * - An enum can be looked up from a Property::Value of type INTEGER.
839 * - An enum can be looked up from a Property::Value of type STRING.
840 * - An enum can NOT be looked up for other Property::Value types.
841 * - The return value is "true" if the property can be successfully converted AND it has changed.
842 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
843 * - The return value is "false" if the property can not be successfully converted.
844 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
847 // String to Enum property table to test with (equivalent to ones used within DALi).
848 const Dali::Scripting::StringEnum testTable[] = {
849 { "NONE", FaceCullingMode::NONE },
850 { "FRONT", FaceCullingMode::FRONT },
851 { "BACK", FaceCullingMode::BACK },
852 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
853 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
855 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
856 // Initialise to first element.
857 FaceCullingMode::Type result = FaceCullingMode::NONE;
858 // Set the input property value to a different value (to emulate a change).
859 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
861 // Perform the lookup.
862 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
864 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
865 // Check the property could be converted.
866 DALI_TEST_CHECK( returnValue );
868 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
870 // Now emulate a property-set with the same value. false should be returned.
871 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
873 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
874 DALI_TEST_CHECK( !returnValue );
876 // The result should remain the same.
877 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
879 // TEST: An enum can be looked up from a Property::Value of type STRING.
880 // Set the input property value to a different value (to emulate a change).
881 Property::Value propertyValueString( "BACK" );
883 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
885 DALI_TEST_CHECK( returnValue );
887 // The result should remain the same.
888 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
890 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
892 DALI_TEST_CHECK( !returnValue );
894 // The result should remain the same.
895 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
897 // TEST: An enum can NOT be looked up for other Property::Value types.
898 Property::Value propertyValueBoolean( true );
900 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
902 // TEST: The return value is "false" if the property can not be successfully converted.
903 // Return value should be false as Property::Value was of an unsupported type for enum properties.
904 DALI_TEST_CHECK( !returnValue );
906 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
907 // The result should remain the same.
908 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
913 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
916 * This test function performs the following checks:
917 * - An enum can be looked up from a Property::Value of type INTEGER.
918 * - An enum can be looked up from a Property::Value of type STRING.
919 * - An enum can NOT be looked up from other Property::Value types.
920 * - The return value is "true" if the property can be successfully converted AND it has changed.
921 * - The return value is "false" if the property can not be successfully converted.
922 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
924 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
925 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
926 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
927 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
928 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
929 * - The result value when checking an array with an INTEGER and a STRING is the ORd value of the 2 integer equivalents of the strings.
930 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
931 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
934 // String to Enum property table to test with (equivalent to ones used within DALi).
935 const Dali::Scripting::StringEnum testTable[] = {
936 { "NONE", FaceCullingMode::NONE },
937 { "FRONT", FaceCullingMode::FRONT },
938 { "BACK", FaceCullingMode::BACK },
939 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
940 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
942 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
943 // Initialise to first element.
944 FaceCullingMode::Type result = FaceCullingMode::NONE;
945 // Set the input property value to a different value (to emulate a change).
946 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
948 // Perform the lookup.
949 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
951 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
952 // Check the property could be converted.
953 DALI_TEST_CHECK( returnValue );
955 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
957 // TEST: An enum can be looked up from a Property::Value of type STRING.
958 // Set the input property value to a different value (to emulate a change).
959 Property::Value propertyValueString( "BACK" );
961 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
963 DALI_TEST_CHECK( returnValue );
965 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
967 // TEST: An enum can NOT be looked up from other Property::Value types.
968 Property::Value propertyValueVector( Vector3::ZERO );
970 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
972 // TEST: The return value is "false" if the property can not be successfully converted.
973 // Return value should be false as Property::Value was of an unsupported type for enum properties.
974 DALI_TEST_CHECK( !returnValue );
976 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
977 // The result should remain the same.
978 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
980 // Test PropertyArrays:
982 // Property array of 2 integers.
983 Property::Array propertyArrayIntegers;
984 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
985 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
986 result = FaceCullingMode::NONE;
988 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
990 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
991 DALI_TEST_CHECK( returnValue );
992 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
993 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
995 // Property array of 2 strings.
996 Property::Array propertyArrayStrings;
997 propertyArrayStrings.PushBack( "FRONT" );
998 propertyArrayStrings.PushBack( "BACK" );
999 result = FaceCullingMode::NONE;
1001 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1003 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1004 DALI_TEST_CHECK( returnValue );
1005 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1006 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1008 // Property array of an int and a string.
1009 Property::Array propertyArrayMixed;
1010 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1011 propertyArrayMixed.PushBack( "BACK" );
1012 result = FaceCullingMode::NONE;
1014 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1016 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1017 DALI_TEST_CHECK( returnValue );
1018 // TEST: The result value when checking an array with an INTEGER and a STRING is the ORd value of the 2 integer equivalents of the strings.
1019 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1021 // Property array of an int and a string.
1022 Property::Array propertyArrayInvalid;
1023 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1024 propertyArrayInvalid.PushBack( Vector3::ZERO );
1026 // Set the initial value to non-zero, so we can test it does not change.
1027 result = FaceCullingMode::FRONT_AND_BACK;
1029 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1031 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1032 DALI_TEST_CHECK( !returnValue );
1033 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1034 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1039 int UtcDaliScriptingFindEnumIndexN(void)
1041 const Scripting::StringEnum myTable[] =
1045 { "THREE", (1<<3) },
1049 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1050 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1055 int UtcDaliScriptingEnumStringToIntegerP(void)
1057 const Scripting::StringEnum myTable[] =
1061 { "THREE", (1<<3) },
1065 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1067 int integerEnum = 0;
1068 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1070 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1073 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1074 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1076 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1077 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1079 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1080 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1082 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1083 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1085 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1086 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1088 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1089 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1091 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1092 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1094 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1095 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1101 int UtcDaliScriptingEnumStringToIntegerN(void)
1103 const Scripting::StringEnum myTable[] =
1111 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1113 int integerEnum = 0;
1114 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1116 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1118 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1120 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1122 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1124 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1126 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1131 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1133 const Scripting::StringEnum myTable[] =
1140 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1142 int integerEnum = 0;
1143 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1144 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1149 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1151 const Scripting::StringEnum myTable[] =
1158 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1160 int integerEnum = 0;
1161 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1163 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1165 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1167 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1169 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1171 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );