2 * Copyright (c) 2014 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< int > 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< int > 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< int > DRAW_MODE_VALUES[] =
51 { "NORMAL", DrawMode::NORMAL },
52 { "OVERLAY", DrawMode::OVERLAY },
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 StringEnum< int >* values, // An array of string values
69 unsigned int num, // Number of items in the array
70 T ( X::*method )() const, // The member method of X to call to get the enum
71 X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X
74 const unsigned int lastIndex( map.Count() - 1 );
75 const std::string& key = map.GetKey( lastIndex );
76 Property::Value& value = map.GetValue( lastIndex );
78 for ( unsigned int i = 0; i < num; ++i )
80 value = values[i].string;
81 tet_printf("Checking: %s: %s\n", key.c_str(), values[i].string );
82 X instance = creator( map );
83 DALI_TEST_EQUALS( values[i].value, ( instance.*method )(), TEST_LOCATION );
87 /// Helper method to create ResourceImage using property
88 ResourceImage NewResourceImage( const Property::Value& map )
90 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
94 /// Helper method to create ResourceImage using property
95 BufferImage NewBufferImage( const Property::Value& map )
97 BufferImage image = BufferImage::DownCast( NewImage( map ) );
101 //////////////////////////////////////////////////////////////////////////////
102 // Helpers for string to enum comparisons for Actor to Property::Map
103 //////////////////////////////////////////////////////////////////////////////
106 * Template to check enumerations of type T
108 template< typename T >
109 void TestEnumStrings(
110 const char * const keyName, // The name of the key to check
111 TestApplication& application, // Reference to the application class
112 const StringEnum< int >* values, // An array of string values
113 unsigned int num, // Number of items in the array
114 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
117 for ( unsigned int i = 0; i < num; ++i )
119 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
121 Actor actor = Actor::New();
122 (actor.*method)( ( T ) values[i].value );
124 Stage::GetCurrent().Add( actor );
125 application.SendNotification();
126 application.Render();
129 CreatePropertyMap( actor, map );
131 DALI_TEST_CHECK( map.Count() );
132 Property::Value value( map );
133 DALI_TEST_CHECK( value.HasKey( keyName ) );
134 DALI_TEST_EQUALS( value.GetValue( keyName ).Get< std::string >(), values[i].string, TEST_LOCATION );
136 Stage::GetCurrent().Remove( actor );
140 //////////////////////////////////////////////////////////////////////////////
147 int UtcDaliScriptingGetColorMode(void)
149 TestApplication application;
151 for ( unsigned int i = 0; i < COLOR_MODE_VALUES_COUNT; ++i )
153 tet_printf( "Checking %s == %d\n", COLOR_MODE_VALUES[i].string, COLOR_MODE_VALUES[i].value );
154 DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].value, GetColorMode( COLOR_MODE_VALUES[i].string ), TEST_LOCATION );
155 DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].string, GetColorMode( (ColorMode) COLOR_MODE_VALUES[i].value ), TEST_LOCATION );
160 (void)GetColorMode("INVALID_ARG");
161 tet_result( TET_FAIL );
163 catch ( DaliException& e )
165 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
170 int UtcDaliScriptingGetPositionInheritanceMode(void)
172 TestApplication application;
174 for ( unsigned int i = 0; i < POSITION_INHERITANCE_MODE_VALUES_COUNT; ++i )
176 tet_printf( "Checking %s == %d\n", POSITION_INHERITANCE_MODE_VALUES[i].string, POSITION_INHERITANCE_MODE_VALUES[i].value );
177 DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].value, GetPositionInheritanceMode( POSITION_INHERITANCE_MODE_VALUES[i].string ), TEST_LOCATION );
178 DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].string, GetPositionInheritanceMode( (PositionInheritanceMode) POSITION_INHERITANCE_MODE_VALUES[i].value ), TEST_LOCATION );
183 (void)GetPositionInheritanceMode("INVALID_ARG");
184 tet_result( TET_FAIL );
186 catch ( DaliException& e )
188 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
194 int UtcDaliScriptingGetDrawMode(void)
196 TestApplication application;
198 for ( unsigned int i = 0; i < DRAW_MODE_VALUES_COUNT; ++i )
200 tet_printf( "Checking %s == %d\n", DRAW_MODE_VALUES[i].string, DRAW_MODE_VALUES[i].value );
201 DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].value, GetDrawMode( DRAW_MODE_VALUES[i].string ), TEST_LOCATION );
202 DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].string, GetDrawMode( (DrawMode::Type) DRAW_MODE_VALUES[i].value ), TEST_LOCATION );
207 (void)GetDrawMode("INVALID_ARG");
208 tet_result( TET_FAIL );
210 catch ( DaliException& e )
212 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
217 int UtcDaliScriptingGetAnchorConstant(void)
219 TestApplication application;
221 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_LEFT, GetAnchorConstant( "TOP_LEFT" ), TEST_LOCATION );
222 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_CENTER, GetAnchorConstant( "TOP_CENTER" ), TEST_LOCATION );
223 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_RIGHT, GetAnchorConstant( "TOP_RIGHT" ), TEST_LOCATION );
224 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER_LEFT, GetAnchorConstant( "CENTER_LEFT" ), TEST_LOCATION );
225 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER, GetAnchorConstant( "CENTER" ), TEST_LOCATION );
226 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER_RIGHT, GetAnchorConstant( "CENTER_RIGHT" ), TEST_LOCATION );
227 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_LEFT, GetAnchorConstant( "BOTTOM_LEFT" ), TEST_LOCATION );
228 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_CENTER, GetAnchorConstant( "BOTTOM_CENTER" ), TEST_LOCATION );
229 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_RIGHT, GetAnchorConstant( "BOTTOM_RIGHT" ), TEST_LOCATION );
233 (void)GetAnchorConstant("INVALID_ARG");
234 tet_result( TET_FAIL );
236 catch ( DaliException& e )
238 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
243 int UtcDaliScriptingNewImageNegative(void)
245 TestApplication application;
251 map[ "filename" ] = Vector3::ZERO;
252 Image image = NewImage( map );
253 tet_result( TET_FAIL );
255 catch ( DaliException& e )
257 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
260 // Invalid load-policy
264 map[ "load-policy" ] = Vector3::ZERO;
265 Image image = NewImage( map );
266 tet_result( TET_FAIL );
268 catch ( DaliException& e )
270 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
276 map[ "load-policy" ] = "INVALID";
277 Image image = NewImage( map );
278 tet_result( TET_FAIL );
280 catch ( DaliException& e )
282 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
286 // Invalid release-policy
290 map[ "release-policy" ] = Vector3::ZERO;
291 Image image = NewImage( map );
292 tet_result( TET_FAIL );
294 catch ( DaliException& e )
296 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
302 map[ "release-policy" ] = "INVALID";
303 Image image = NewImage( map );
304 tet_result( TET_FAIL );
306 catch ( DaliException& e )
308 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
316 map[ "width" ] = "Invalid";
317 map[ "height" ] = "Invalid";
318 Image image = NewImage( map );
319 tet_result( TET_FAIL );
321 catch ( DaliException& e )
323 DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION );
331 map[ "height" ] = "Invalid";
332 Image image = NewImage( map );
333 tet_result( TET_FAIL );
335 catch ( DaliException& e )
337 DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION );
340 // Invalid fitting-mode
344 map[ "fitting-mode" ] = Vector3::ZERO;
345 Image image = NewImage( map );
346 DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION );
348 catch ( DaliException& e )
350 DALI_TEST_ASSERT( e, "value.GetType() == Property::STRING", TEST_LOCATION );
356 map[ "fitting-mode" ] = "INVALID";
357 Image image = NewImage( map );
358 DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION );
360 catch ( DaliException& e )
362 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
366 // Invalid scaling-mode
370 map[ "sampling-mode" ] = Vector3::ZERO;
371 Image image = NewImage( map );
372 DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION );
374 catch ( DaliException& e )
376 DALI_TEST_ASSERT( e, "value.GetType() == Property::STRING", TEST_LOCATION );
382 map[ "sampling-mode" ] = "INVALID";
383 Image image = NewImage( map );
384 DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION );
386 catch ( DaliException& e )
388 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
392 // Invalid orientation-correction
396 map[ "orientation" ] = Vector3::ZERO;
397 Image image = NewImage( map );
398 DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION );
400 catch ( DaliException& e )
402 DALI_TEST_ASSERT( e, "value.GetType() == Property::BOOLEAN", TEST_LOCATION );
409 map[ "type" ] = Vector3::ZERO;
410 Image image = NewImage( map );
411 tet_result( TET_FAIL );
413 catch ( DaliException& e )
415 DALI_TEST_ASSERT( e, "map.GetValue(\"type\").GetType()", TEST_LOCATION );
421 map[ "type" ] = "INVALID";
422 Image image = NewImage( map );
423 tet_result( TET_FAIL );
425 catch ( DaliException& e )
427 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
431 // Invalid pixel-format
435 map[ "pixel-format" ] = Vector3::ZERO;
436 Image image = NewImage( map );
437 tet_result( TET_FAIL );
439 catch ( DaliException& e )
441 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
447 map[ "pixel-format" ] = "INVALID";
448 Image image = NewImage( map );
449 tet_result( TET_FAIL );
451 catch ( DaliException& e )
453 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
461 int UtcDaliScriptingNewImage(void)
463 TestApplication application;
466 map[ "filename" ] = "TEST_FILE";
470 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
471 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
475 map[ "load-policy" ] = "";
477 const StringEnum< int > values[] =
479 { "IMMEDIATE", ResourceImage::IMMEDIATE },
480 { "ON_DEMAND", ResourceImage::ON_DEMAND }
482 TestEnumStrings< ResourceImage::LoadPolicy, ResourceImage >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ResourceImage::GetLoadPolicy, &NewResourceImage );
486 map[ "release-policy" ] = "";
488 const StringEnum< int > values[] =
490 { "UNUSED", Image::UNUSED },
491 { "NEVER", Image::NEVER }
493 TestEnumStrings< Image::ReleasePolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage );
496 // float width and height
497 map[ "width" ] = (float) 10.0f;
498 map[ "height" ] = (float) 20.0f;
500 Image image = NewImage( map );
501 DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION );
502 DALI_TEST_EQUALS( image.GetHeight(), 20.0f, TEST_LOCATION );
505 // int width and height
506 map[ "width"] = (int) 50;
507 map[ "height" ] = (int) 70;
509 Image image = NewImage( map );
510 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
511 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
514 //map.erase( map.end() - 2, map.end() );
516 // type FrameBufferImage
517 map[ "type" ] = "FrameBufferImage";
519 Image image = NewImage( map );
520 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
523 map[ "type" ] = "BufferImage";
525 Image image = NewImage( map );
526 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
527 DALI_TEST_CHECK((BufferImage::DownCast( image )).GetPixelFormat()== Pixel::RGBA8888);
531 map[ "pixel-format" ] = "";
533 const StringEnum< int > values[] =
537 { "LA88", Pixel::LA88 },
538 { "RGB565", Pixel::RGB565 },
539 { "BGR565", Pixel::BGR565 },
540 { "RGBA4444", Pixel::RGBA4444 },
541 { "BGRA4444", Pixel::BGRA4444 },
542 { "RGBA5551", Pixel::RGBA5551 },
543 { "BGRA5551", Pixel::BGRA5551 },
544 { "RGB888", Pixel::RGB888 },
545 { "RGB8888", Pixel::RGB8888 },
546 { "BGR8888", Pixel::BGR8888 },
547 { "RGBA8888", Pixel::RGBA8888 },
548 { "BGRA8888", Pixel::BGRA8888 },
549 /*{ "COMPRESSED_R11_EAC", Pixel::COMPRESSED_R11_EAC },
550 { "COMPRESSED_SIGNED_R11_EAC", Pixel::COMPRESSED_SIGNED_R11_EAC },
551 { "COMPRESSED_RG11_EAC", Pixel::COMPRESSED_RG11_EAC },
552 { "COMPRESSED_SIGNED_RG11_EAC", Pixel::COMPRESSED_SIGNED_RG11_EAC },
553 { "COMPRESSED_RGB8_ETC2", Pixel::COMPRESSED_RGB8_ETC2 },
554 { "COMPRESSED_SRGB8_ETC2", Pixel::COMPRESSED_SRGB8_ETC2 },
555 { "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
556 { "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
557 { "COMPRESSED_RGBA8_ETC2_EAC", Pixel::COMPRESSED_RGBA8_ETC2_EAC },
558 { "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC },
559 { "COMPRESSED_RGB8_ETC1", Pixel::COMPRESSED_RGB8_ETC1 },
560 { "COMPRESSED_RGB_PVRTC_4BPPV1", Pixel::COMPRESSED_RGB_PVRTC_4BPPV1 },*/
561 // BufferImage does not support compressed formats
564 TestEnumStrings< Pixel::Format, BufferImage >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
568 map[ "type" ] = "ResourceImage";
570 Image image = NewImage( map );
571 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
572 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
573 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
578 int UtcDaliScriptingNewShaderEffect(void)
580 TestApplication application;
582 Property::Map programMap;
583 programMap[ "vertex-filename" ] = "bump.vert";
584 programMap[ "fragment-filename" ] = "bump.frag";
586 Property::Map imageMap;
587 imageMap[ "filename" ] = "image.png";
590 map[ "image" ] = imageMap;
591 map[ "program" ] = programMap;
592 map[ "uLightPosition" ] = Vector3( 0.0, 0.0, -1.5);
593 map[ "uAmbientLight" ] = (int)10;
595 ShaderEffect shader = NewShaderEffect( map );
597 DALI_TEST_CHECK( shader );
601 int UtcDaliScriptingNewActorNegative(void)
603 TestApplication application;
607 Actor handle = NewActor( Property::Map() );
608 DALI_TEST_CHECK( !handle );
611 // Map with only properties
614 map[ "parent-origin" ] = ParentOrigin::TOP_CENTER;
615 map[ "anchor-point" ] = AnchorPoint::TOP_CENTER;
616 Actor handle = NewActor( map );
617 DALI_TEST_CHECK( !handle );
620 // Add some signals to the map, we should have no signal connections as its not yet supported
623 map[ "type" ] = "Actor";
624 map[ "signals" ] = Property::MAP;
625 Actor handle = NewActor( map );
626 DALI_TEST_CHECK( handle );
627 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
628 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
629 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
630 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
635 int UtcDaliScriptingNewActorProperties(void)
637 TestApplication application;
640 map[ "type" ] = "Actor";
641 map[ "size" ] = Vector3::ONE;
642 map[ "position" ] = Vector3::XAXIS;
643 map[ "scale" ] = Vector3::ONE;
644 map[ "visible" ] = false;
645 map[ "color" ] = Color::MAGENTA;
646 map[ "name" ] = "MyActor";
647 map[ "color-mode" ] = "USE_PARENT_COLOR";
648 map[ "inherit-shader-effect" ] = false;
649 map[ "sensitive" ] = false;
650 map[ "leave-required" ] = true;
651 map[ "position-inheritance" ] = "DONT_INHERIT_POSITION";
652 map[ "draw-mode" ] = "STENCIL";
653 map[ "inherit-orientation" ] = false;
654 map[ "inherit-scale" ] = false;
656 // Default properties
658 Actor handle = NewActor( map );
659 DALI_TEST_CHECK( handle );
661 Stage::GetCurrent().Add( handle );
662 application.SendNotification();
663 application.Render();
665 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
666 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
667 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
668 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
669 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
670 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
671 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
672 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
673 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
674 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
675 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
676 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
677 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
679 Stage::GetCurrent().Remove( handle );
682 // Check Anchor point and parent origin vector3s
683 map[ "parent-origin" ] = ParentOrigin::TOP_CENTER;
684 map[ "anchor-point" ] = AnchorPoint::TOP_LEFT;
686 Actor handle = NewActor( map );
687 DALI_TEST_CHECK( handle );
689 Stage::GetCurrent().Add( handle );
690 application.SendNotification();
691 application.Render();
693 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
694 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
696 Stage::GetCurrent().Remove( handle );
699 // Check Anchor point and parent origin STRINGS
700 map[ "parent-origin" ] = "TOP_LEFT";
701 map[ "anchor-point" ] = "CENTER_LEFT";
703 Actor handle = NewActor( map );
704 DALI_TEST_CHECK( handle );
706 Stage::GetCurrent().Add( handle );
707 application.SendNotification();
708 application.Render();
710 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
711 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
713 Stage::GetCurrent().Remove( handle );
718 int UtcDaliScriptingNewActorChildren(void)
720 TestApplication application;
723 map[ "type" ] = "Actor";
724 map[ "position" ] = Vector3::XAXIS;
726 Property::Map child1Map;
727 child1Map[ "type" ] = "ImageActor";
728 child1Map[ "position" ] = Vector3::YAXIS;
730 Property::Array childArray;
731 childArray.PushBack( child1Map );
732 map[ "actors" ] = childArray;
735 Actor handle = NewActor( map );
736 DALI_TEST_CHECK( handle );
738 Stage::GetCurrent().Add( handle );
739 application.SendNotification();
740 application.Render();
742 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
743 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
745 Actor child1 = handle.GetChildAt(0);
746 DALI_TEST_CHECK( child1 );
747 DALI_TEST_CHECK( ImageActor::DownCast( child1 ) );
748 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
749 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
751 Stage::GetCurrent().Remove( handle );
756 int UtcDaliScriptingCreatePropertyMapActor(void)
758 TestApplication application;
762 Actor actor = Actor::New();
765 CreatePropertyMap( actor, map );
766 DALI_TEST_CHECK( !map.Empty() );
767 Property::Value value( map );
768 DALI_TEST_CHECK( value.HasKey( "type" ) );
769 DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "Actor", TEST_LOCATION );
771 Stage::GetCurrent().Remove( actor );
776 Actor actor = ImageActor::New();
779 CreatePropertyMap( actor, map );
780 DALI_TEST_CHECK( !map.Empty() );
781 Property::Value value( map );
782 DALI_TEST_CHECK( value.HasKey( "type" ) );
783 DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "ImageActor", TEST_LOCATION );
785 Stage::GetCurrent().Remove( actor );
788 // Default properties
790 Actor actor = Actor::New();
791 actor.SetSize( Vector3::ONE );
792 actor.SetPosition( Vector3::XAXIS );
793 actor.SetScale( Vector3::ZAXIS );
794 actor.SetVisible( false );
795 actor.SetColor( Color::MAGENTA );
796 actor.SetName( "MyActor" );
797 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
798 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
799 actor.SetSensitive( false );
800 actor.SetLeaveRequired( true );
801 actor.SetInheritOrientation( false );
802 actor.SetInheritScale( false );
803 actor.SetSizeModeFactor( Vector3::ONE );
805 Stage::GetCurrent().Add( actor );
806 application.SendNotification();
807 application.Render();
810 CreatePropertyMap( actor, map );
812 DALI_TEST_CHECK( !map.Empty() );
813 Property::Value value( map );
814 DALI_TEST_CHECK( value.HasKey( "size" ) );
815 DALI_TEST_EQUALS( value.GetValue( "size" ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
816 DALI_TEST_CHECK( value.HasKey( "position" ) );
817 DALI_TEST_EQUALS( value.GetValue( "position" ).Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
818 DALI_TEST_CHECK( value.HasKey( "scale" ) );
819 DALI_TEST_EQUALS( value.GetValue( "scale" ).Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
820 DALI_TEST_CHECK( value.HasKey( "visible" ) );
821 DALI_TEST_EQUALS( value.GetValue( "visible" ).Get< bool >(), false, TEST_LOCATION );
822 DALI_TEST_CHECK( value.HasKey( "color" ) );
823 DALI_TEST_EQUALS( value.GetValue( "color" ).Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
824 DALI_TEST_CHECK( value.HasKey( "name" ) );
825 DALI_TEST_EQUALS( value.GetValue( "name").Get< std::string >(), "MyActor", TEST_LOCATION );
826 DALI_TEST_CHECK( value.HasKey( "anchor-point" ) );
827 DALI_TEST_EQUALS( value.GetValue( "anchor-point" ).Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
828 DALI_TEST_CHECK( value.HasKey( "parent-origin" ) );
829 DALI_TEST_EQUALS( value.GetValue( "parent-origin" ).Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
830 DALI_TEST_CHECK( value.HasKey( "sensitive" ) );
831 DALI_TEST_EQUALS( value.GetValue( "sensitive" ).Get< bool >(), false, TEST_LOCATION );
832 DALI_TEST_CHECK( value.HasKey( "leave-required" ) );
833 DALI_TEST_EQUALS( value.GetValue( "leave-required" ).Get< bool >(), true, TEST_LOCATION );
834 DALI_TEST_CHECK( value.HasKey( "inherit-orientation" ) );
835 DALI_TEST_EQUALS( value.GetValue( "inherit-orientation" ).Get< bool >(), false, TEST_LOCATION );
836 DALI_TEST_CHECK( value.HasKey( "inherit-scale" ) );
837 DALI_TEST_EQUALS( value.GetValue( "inherit-scale" ).Get< bool >(), false, TEST_LOCATION );
838 DALI_TEST_CHECK( value.HasKey( "size-mode-factor" ) );
839 DALI_TEST_EQUALS( value.GetValue( "size-mode-factor" ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
841 Stage::GetCurrent().Remove( actor );
845 TestEnumStrings< ColorMode >( "color-mode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
847 // PositionInheritanceMode
848 TestEnumStrings< PositionInheritanceMode >( "position-inheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
851 TestEnumStrings< DrawMode::Type >( "draw-mode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
855 Actor actor = Actor::New();
856 Actor child = ImageActor::New();
859 Stage::GetCurrent().Add( actor );
860 application.SendNotification();
861 application.Render();
864 CreatePropertyMap( actor, map );
865 DALI_TEST_CHECK( !map.Empty() );
867 Property::Value value( map );
868 DALI_TEST_CHECK( value.HasKey( "type" ) );
869 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Actor", TEST_LOCATION );
871 DALI_TEST_CHECK( value.HasKey( "actors" ) );
872 Property::Array children( value.GetValue( "actors").Get< Property::Array >() );
873 DALI_TEST_CHECK( !children.Empty() );
874 Property::Map childMap( children[0].Get< Property::Map >() );
875 DALI_TEST_CHECK( !childMap.Empty() );
876 Property::Value childValue( childMap );
877 DALI_TEST_CHECK( childValue.HasKey( "type" ) );
878 DALI_TEST_EQUALS( childValue.GetValue( "type" ).Get< std::string >(), "ImageActor", TEST_LOCATION );
880 Stage::GetCurrent().Remove( actor );
885 int UtcDaliScriptingCreatePropertyMapImage(void)
887 TestApplication application;
893 CreatePropertyMap( image, map );
894 DALI_TEST_CHECK( map.Empty() );
899 Image image = ResourceImage::New( "MY_PATH" );
902 CreatePropertyMap( image, map );
903 DALI_TEST_CHECK( !map.Empty() );
905 Property::Value value( map );
906 DALI_TEST_CHECK( value.HasKey( "type" ) );
907 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION );
908 DALI_TEST_CHECK( value.HasKey( "filename" ) );
909 DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
910 DALI_TEST_CHECK( value.HasKey( "load-policy") );
911 DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "IMMEDIATE", TEST_LOCATION );
912 DALI_TEST_CHECK( value.HasKey( "release-policy") );
913 DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "NEVER", TEST_LOCATION );
914 DALI_TEST_CHECK( !value.HasKey( "width" ) );
915 DALI_TEST_CHECK( !value.HasKey( "height" ) );
920 ResourceImage image = ResourceImage::New( "MY_PATH", ResourceImage::ON_DEMAND, Image::UNUSED, ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
923 CreatePropertyMap( image, map );
924 DALI_TEST_CHECK( !map.Empty() );
926 Property::Value value( map );
927 DALI_TEST_CHECK( value.HasKey( "type" ) );
928 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION );
929 DALI_TEST_CHECK( value.HasKey( "filename" ) );
930 DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
931 DALI_TEST_CHECK( value.HasKey( "load-policy") );
932 DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "ON_DEMAND", TEST_LOCATION );
933 DALI_TEST_CHECK( value.HasKey( "release-policy") );
934 DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "UNUSED", TEST_LOCATION );
935 DALI_TEST_CHECK( value.HasKey( "width" ) );
936 DALI_TEST_EQUALS( value.GetValue( "width" ).Get< int >(), 300, TEST_LOCATION );
937 DALI_TEST_CHECK( value.HasKey( "height" ) );
938 DALI_TEST_EQUALS( value.GetValue( "height" ).Get< int >(), 400, TEST_LOCATION );
943 Image image = BufferImage::New( 200, 300, Pixel::A8 );
945 CreatePropertyMap( image, map );
946 Property::Value value( map );
947 DALI_TEST_CHECK( value.HasKey( "type" ) );
948 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "BufferImage", TEST_LOCATION );
949 DALI_TEST_CHECK( value.HasKey( "pixel-format") );
950 DALI_TEST_EQUALS( value.GetValue( "pixel-format" ).Get< std::string >(), "A8", TEST_LOCATION );
955 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
957 CreatePropertyMap( image, map );
958 Property::Value value( map );
959 DALI_TEST_CHECK( value.HasKey( "type" ) );
960 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
965 int UtcDaliScriptingGetEnumerationTemplates(void)
967 TestApplication application;
969 const Scripting::StringEnum< int > myTable[] =
977 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
979 for ( unsigned int i = 0; i < myTableCount; ++i )
981 tet_printf("Checking: %s\n", myTable[ i ].string );
982 DALI_TEST_EQUALS( myTable[ i ].value, GetEnumeration( myTable[ i ].string, myTable, myTableCount ), TEST_LOCATION );
985 for ( unsigned int i = 0; i < myTableCount; ++i )
987 tet_printf("Checking: %d\n", myTable[ i ].value );
988 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
994 int UtcDaliScriptingCompareEnums(void)
997 DALI_TEST_CHECK( CompareEnums( "", "" ) );
998 DALI_TEST_CHECK( CompareEnums( "HELLO", "HELLO" ) );
999 DALI_TEST_CHECK( CompareEnums( "HELLO", "hello" ) );
1000 DALI_TEST_CHECK( CompareEnums( "hello", "HELLO" ) );
1001 DALI_TEST_CHECK( CompareEnums( "hello-world", "HELLO_WORLD" ) );
1002 DALI_TEST_CHECK( CompareEnums( "hello_WORLD", "HELLO-world" ) );
1003 DALI_TEST_CHECK( CompareEnums( "hello_WORLD-", "HELLO-world_" ) );
1004 DALI_TEST_CHECK( CompareEnums( "_hello_WORLD-", "-HELLO-world_" ) );
1005 DALI_TEST_CHECK( CompareEnums( "-hello_WORLD-", "_HELLO-world_" ) );
1006 DALI_TEST_CHECK( CompareEnums( "hello123", "HELLO123" ) );
1009 DALI_TEST_CHECK( ! CompareEnums( "hello", "HELLOWORLD" ) );