2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
24 using namespace Dali::Scripting;
35 const StringEnum COLOR_MODE_VALUES[] =
37 { "USE_OWN_COLOR", USE_OWN_COLOR },
38 { "USE_PARENT_COLOR", USE_PARENT_COLOR },
39 { "USE_OWN_MULTIPLY_PARENT_COLOR", USE_OWN_MULTIPLY_PARENT_COLOR },
40 { "USE_OWN_MULTIPLY_PARENT_ALPHA", USE_OWN_MULTIPLY_PARENT_ALPHA },
42 const unsigned int COLOR_MODE_VALUES_COUNT = sizeof( COLOR_MODE_VALUES ) / sizeof( COLOR_MODE_VALUES[0] );
44 const StringEnum POSITION_INHERITANCE_MODE_VALUES[] =
46 { "INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION },
47 { "USE_PARENT_POSITION", USE_PARENT_POSITION },
48 { "USE_PARENT_POSITION_PLUS_LOCAL_POSITION", USE_PARENT_POSITION_PLUS_LOCAL_POSITION },
49 { "DONT_INHERIT_POSITION", DONT_INHERIT_POSITION },
51 const unsigned int POSITION_INHERITANCE_MODE_VALUES_COUNT = sizeof( POSITION_INHERITANCE_MODE_VALUES ) / sizeof( POSITION_INHERITANCE_MODE_VALUES[0] );
53 const StringEnum DRAW_MODE_VALUES[] =
55 { "NORMAL", DrawMode::NORMAL },
56 { "OVERLAY", DrawMode::OVERLAY },
57 { "STENCIL", DrawMode::STENCIL },
59 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( DRAW_MODE_VALUES[0] );
63 //////////////////////////////////////////////////////////////////////////////
64 // Helpers for string to enum comparisons for Image and ImageAttributes
65 //////////////////////////////////////////////////////////////////////////////
68 * Template to check enumerations of type T, with a class of type X
70 template< typename T, typename X >
72 Property::Map& map, // The map used to create instance of type X
73 const StringEnum* values, // An array of string values
74 unsigned int num, // Number of items in the array
75 T ( X::*method )() const, // The member method of X to call to get the enum
76 X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X
79 Property::Map::iterator iter = map.end() - 1;
80 for ( unsigned int i = 0; i < num; ++i )
82 iter->second = values[i].string;
83 tet_printf("Checking: %s: %s\n", iter->first.c_str(), values[i].string );
84 X instance = creator( map );
85 DALI_TEST_EQUALS( values[i].value, ( instance.*method )(), TEST_LOCATION );
89 /// Helper method to create ImageAttributes using an Image
90 ImageAttributes NewImageAttributes( const Property::Value& map )
92 Image image = NewImage( map );
93 return image.GetAttributes();
96 //////////////////////////////////////////////////////////////////////////////
97 // Helpers for string to enum comparisons for Actor to Property::Map
98 //////////////////////////////////////////////////////////////////////////////
101 * Template to check enumerations of type T
103 template< typename T >
104 void TestEnumStrings(
105 const char * const keyName, // The name of the key to check
106 TestApplication& application, // Reference to the application class
107 const StringEnum* values, // An array of string values
108 unsigned int num, // Number of items in the array
109 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
112 for ( unsigned int i = 0; i < num; ++i )
114 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
116 Actor actor = Actor::New();
117 (actor.*method)( ( T ) values[i].value );
119 Stage::GetCurrent().Add( actor );
120 application.SendNotification();
121 application.Render();
124 CreatePropertyMap( actor, map );
126 DALI_TEST_CHECK( !map.empty() );
127 Property::Value value( map );
128 DALI_TEST_CHECK( value.HasKey( keyName ) );
129 DALI_TEST_EQUALS( value.GetValue( keyName ).Get< std::string >(), values[i].string, TEST_LOCATION );
131 Stage::GetCurrent().Remove( actor );
135 //////////////////////////////////////////////////////////////////////////////
142 int UtcDaliScriptingGetColorMode(void)
144 TestApplication application;
146 for ( unsigned int i = 0; i < COLOR_MODE_VALUES_COUNT; ++i )
148 tet_printf( "Checking %s == %d\n", COLOR_MODE_VALUES[i].string, COLOR_MODE_VALUES[i].value );
149 DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].value, GetColorMode( COLOR_MODE_VALUES[i].string ), TEST_LOCATION );
150 DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].string, GetColorMode( (ColorMode) COLOR_MODE_VALUES[i].value ), TEST_LOCATION );
155 (void)GetColorMode("INVALID_ARG");
156 tet_result( TET_FAIL );
158 catch ( DaliException& e )
160 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
165 int UtcDaliScriptingGetPositionInheritanceMode(void)
167 TestApplication application;
169 for ( unsigned int i = 0; i < POSITION_INHERITANCE_MODE_VALUES_COUNT; ++i )
171 tet_printf( "Checking %s == %d\n", POSITION_INHERITANCE_MODE_VALUES[i].string, POSITION_INHERITANCE_MODE_VALUES[i].value );
172 DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].value, GetPositionInheritanceMode( POSITION_INHERITANCE_MODE_VALUES[i].string ), TEST_LOCATION );
173 DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].string, GetPositionInheritanceMode( (PositionInheritanceMode) POSITION_INHERITANCE_MODE_VALUES[i].value ), TEST_LOCATION );
178 (void)GetPositionInheritanceMode("INVALID_ARG");
179 tet_result( TET_FAIL );
181 catch ( DaliException& e )
183 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
189 int UtcDaliScriptingGetDrawMode(void)
191 TestApplication application;
193 for ( unsigned int i = 0; i < DRAW_MODE_VALUES_COUNT; ++i )
195 tet_printf( "Checking %s == %d\n", DRAW_MODE_VALUES[i].string, DRAW_MODE_VALUES[i].value );
196 DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].value, GetDrawMode( DRAW_MODE_VALUES[i].string ), TEST_LOCATION );
197 DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].string, GetDrawMode( (DrawMode::Type) DRAW_MODE_VALUES[i].value ), TEST_LOCATION );
202 (void)GetDrawMode("INVALID_ARG");
203 tet_result( TET_FAIL );
205 catch ( DaliException& e )
207 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
212 int UtcDaliScriptingGetAnchorConstant(void)
214 TestApplication application;
216 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_TOP_LEFT, GetAnchorConstant( "BACK_TOP_LEFT" ), TEST_LOCATION );
217 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_TOP_CENTER, GetAnchorConstant( "BACK_TOP_CENTER" ), TEST_LOCATION );
218 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_TOP_RIGHT, GetAnchorConstant( "BACK_TOP_RIGHT" ), TEST_LOCATION );
219 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_CENTER_LEFT, GetAnchorConstant( "BACK_CENTER_LEFT" ), TEST_LOCATION );
220 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_CENTER, GetAnchorConstant( "BACK_CENTER" ), TEST_LOCATION );
221 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_CENTER_RIGHT, GetAnchorConstant( "BACK_CENTER_RIGHT" ), TEST_LOCATION );
222 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_BOTTOM_LEFT, GetAnchorConstant( "BACK_BOTTOM_LEFT" ), TEST_LOCATION );
223 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_BOTTOM_CENTER, GetAnchorConstant( "BACK_BOTTOM_CENTER" ), TEST_LOCATION );
224 DALI_TEST_EQUALS( Dali::ParentOrigin::BACK_BOTTOM_RIGHT, GetAnchorConstant( "BACK_BOTTOM_RIGHT" ), TEST_LOCATION );
225 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_LEFT, GetAnchorConstant( "TOP_LEFT" ), TEST_LOCATION );
226 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_CENTER, GetAnchorConstant( "TOP_CENTER" ), TEST_LOCATION );
227 DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_RIGHT, GetAnchorConstant( "TOP_RIGHT" ), TEST_LOCATION );
228 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER_LEFT, GetAnchorConstant( "CENTER_LEFT" ), TEST_LOCATION );
229 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER, GetAnchorConstant( "CENTER" ), TEST_LOCATION );
230 DALI_TEST_EQUALS( Dali::ParentOrigin::CENTER_RIGHT, GetAnchorConstant( "CENTER_RIGHT" ), TEST_LOCATION );
231 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_LEFT, GetAnchorConstant( "BOTTOM_LEFT" ), TEST_LOCATION );
232 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_CENTER, GetAnchorConstant( "BOTTOM_CENTER" ), TEST_LOCATION );
233 DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_RIGHT, GetAnchorConstant( "BOTTOM_RIGHT" ), TEST_LOCATION );
234 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_TOP_LEFT, GetAnchorConstant( "FRONT_TOP_LEFT" ), TEST_LOCATION );
235 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_TOP_CENTER, GetAnchorConstant( "FRONT_TOP_CENTER" ), TEST_LOCATION );
236 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_TOP_RIGHT, GetAnchorConstant( "FRONT_TOP_RIGHT" ), TEST_LOCATION );
237 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_CENTER_LEFT, GetAnchorConstant( "FRONT_CENTER_LEFT" ), TEST_LOCATION );
238 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_CENTER, GetAnchorConstant( "FRONT_CENTER" ), TEST_LOCATION );
239 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_CENTER_RIGHT, GetAnchorConstant( "FRONT_CENTER_RIGHT" ), TEST_LOCATION );
240 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_BOTTOM_LEFT, GetAnchorConstant( "FRONT_BOTTOM_LEFT" ), TEST_LOCATION );
241 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_BOTTOM_CENTER, GetAnchorConstant( "FRONT_BOTTOM_CENTER" ), TEST_LOCATION );
242 DALI_TEST_EQUALS( Dali::ParentOrigin::FRONT_BOTTOM_RIGHT, GetAnchorConstant( "FRONT_BOTTOM_RIGHT" ), TEST_LOCATION );
246 (void)GetAnchorConstant("INVALID_ARG");
247 tet_result( TET_FAIL );
249 catch ( DaliException& e )
251 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
256 int UtcDaliScriptingNewImageNegative(void)
258 TestApplication application;
264 map.push_back( Property::StringValuePair( "filename", 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 );
273 // Invalid load-policy
277 map.push_back( Property::StringValuePair( "load-policy", Vector3::ZERO ) );
278 Image image = NewImage( map );
279 tet_result( TET_FAIL );
281 catch ( DaliException& e )
283 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
289 map.push_back( Property::StringValuePair( "load-policy", "INVALID" ) );
290 Image image = NewImage( map );
291 tet_result( TET_FAIL );
293 catch ( DaliException& e )
295 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
299 // Invalid release-policy
303 map.push_back( Property::StringValuePair( "release-policy", Vector3::ZERO ) );
304 Image image = NewImage( map );
305 tet_result( TET_FAIL );
307 catch ( DaliException& e )
309 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
315 map.push_back( Property::StringValuePair( "release-policy", "INVALID" ) );
316 Image image = NewImage( map );
317 tet_result( TET_FAIL );
319 catch ( DaliException& e )
321 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
329 map.push_back( Property::StringValuePair( "width", "Invalid" ) );
330 map.push_back( Property::StringValuePair( "height", "Invalid" ) );
331 Image image = NewImage( map );
332 tet_result( TET_FAIL );
334 catch ( DaliException& e )
336 DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION );
343 map.push_back( Property::StringValuePair( "width", 10 ) );
344 map.push_back( Property::StringValuePair( "height", "Invalid" ) );
345 Image image = NewImage( map );
346 tet_result( TET_FAIL );
348 catch ( DaliException& e )
350 DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION );
353 // Invalid pixel-format
357 map.push_back( Property::StringValuePair( "pixel-format", Vector3::ZERO ) );
358 Image image = NewImage( map );
359 tet_result( TET_FAIL );
361 catch ( DaliException& e )
363 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
369 map.push_back( Property::StringValuePair( "pixel-format", "INVALID" ) );
370 Image image = NewImage( map );
371 tet_result( TET_FAIL );
373 catch ( DaliException& e )
375 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
379 // Invalid scaling-mode
383 map.push_back( Property::StringValuePair( "scaling-mode", Vector3::ZERO ) );
384 Image image = NewImage( map );
385 tet_result( TET_FAIL );
387 catch ( DaliException& e )
389 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
395 map.push_back( Property::StringValuePair( "scaling-mode", "INVALID" ) );
396 Image image = NewImage( map );
397 tet_result( TET_FAIL );
399 catch ( DaliException& e )
401 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
409 map.push_back( Property::StringValuePair( "crop", "Invalid" ) );
410 Image image = NewImage( map );
411 tet_result( TET_FAIL );
413 catch ( DaliException& e )
415 DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION );
422 map.push_back( Property::StringValuePair( "type", Vector3::ZERO ) );
423 Image image = NewImage( map );
424 tet_result( TET_FAIL );
426 catch ( DaliException& e )
428 DALI_TEST_ASSERT( e, "map.GetValue(\"type\").GetType()", TEST_LOCATION );
434 map.push_back( Property::StringValuePair( "type", "INVALID" ) );
435 Image image = NewImage( map );
436 tet_result( TET_FAIL );
438 catch ( DaliException& e )
440 DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION );
447 //////////////////////////////////////////////////////////////////////////////
449 int UtcDaliScriptingNewImage(void)
451 TestApplication application;
454 map.push_back( Property::StringValuePair( "filename", "TEST_FILE" ) );
458 Image image = NewImage( map );
459 DALI_TEST_EQUALS( "TEST_FILE", image.GetFilename(), TEST_LOCATION );
463 map.push_back( Property::StringValuePair( "load-policy", "" ) );
465 const StringEnum values[] =
467 { "IMMEDIATE", Image::Immediate },
468 { "ON_DEMAND", Image::OnDemand }
470 TestEnumStrings< Image::LoadPolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetLoadPolicy, &NewImage );
474 map.push_back( Property::StringValuePair( "release-policy", "" ) );
476 const StringEnum values[] =
478 { "UNUSED", Image::Unused },
479 { "NEVER", Image::Never }
481 TestEnumStrings< Image::ReleasePolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage );
484 // float width and height
485 map.push_back( Property::StringValuePair( "width", (float) 10.0f ) );
486 map.push_back( Property::StringValuePair( "height", (float) 20.0f ) );
488 Image image = NewImage( map );
489 DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION );
490 DALI_TEST_EQUALS( image.GetHeight(), 20.0f, TEST_LOCATION );
493 // int width and height
494 map.erase( map.end() - 2, map.end() );
495 map.push_back( Property::StringValuePair( "width", 50 ) );
496 map.push_back( Property::StringValuePair( "height", 70 ) );
498 Image image = NewImage( map );
499 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
500 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
503 //map.erase( map.end() - 2, map.end() );
506 map.push_back( Property::StringValuePair( "pixel-format", "" ) );
508 const StringEnum values[] =
512 { "LA88", Pixel::LA88 },
513 { "RGB565", Pixel::RGB565 },
514 { "BGR565", Pixel::BGR565 },
515 { "RGBA4444", Pixel::RGBA4444 },
516 { "BGRA4444", Pixel::BGRA4444 },
517 { "RGBA5551", Pixel::RGBA5551 },
518 { "BGRA5551", Pixel::BGRA5551 },
519 { "RGB888", Pixel::RGB888 },
520 { "RGB8888", Pixel::RGB8888 },
521 { "BGR8888", Pixel::BGR8888 },
522 { "RGBA8888", Pixel::RGBA8888 },
523 { "BGRA8888", Pixel::BGRA8888 },
524 { "COMPRESSED_R11_EAC", Pixel::COMPRESSED_R11_EAC },
525 { "COMPRESSED_SIGNED_R11_EAC", Pixel::COMPRESSED_SIGNED_R11_EAC },
526 { "COMPRESSED_RG11_EAC", Pixel::COMPRESSED_RG11_EAC },
527 { "COMPRESSED_SIGNED_RG11_EAC", Pixel::COMPRESSED_SIGNED_RG11_EAC },
528 { "COMPRESSED_RGB8_ETC2", Pixel::COMPRESSED_RGB8_ETC2 },
529 { "COMPRESSED_SRGB8_ETC2", Pixel::COMPRESSED_SRGB8_ETC2 },
530 { "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
531 { "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 },
532 { "COMPRESSED_RGBA8_ETC2_EAC", Pixel::COMPRESSED_RGBA8_ETC2_EAC },
533 { "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC },
534 { "COMPRESSED_RGB8_ETC1", Pixel::COMPRESSED_RGB8_ETC1 },
535 { "COMPRESSED_RGB_PVRTC_4BPPV1", Pixel::COMPRESSED_RGB_PVRTC_4BPPV1 },
536 { "A8", Pixel::A8 }, // Checked already but reset so that BitmapImage works
538 TestEnumStrings< Pixel::Format, ImageAttributes >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ImageAttributes::GetPixelFormat, &NewImageAttributes );
542 map.push_back( Property::StringValuePair( "scaling-mode", "" ) );
544 const StringEnum values[] =
546 { "SHRINK_TO_FIT", ImageAttributes::ShrinkToFit },
547 { "SCALE_TO_FILL", ImageAttributes::ScaleToFill },
548 { "FIT_WIDTH", ImageAttributes::FitWidth },
549 { "FIT_HEIGHT", ImageAttributes::FitHeight },
551 TestEnumStrings< ImageAttributes::ScalingMode, ImageAttributes >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ImageAttributes::GetScalingMode, &NewImageAttributes );
555 map.push_back( Property::StringValuePair( "crop", Vector4( 50, 60, 70, 80 ) ) );
557 Image image = NewImage( map );
558 ImageAttributes attributes = image.GetAttributes();
559 Rect<float> crop = attributes.GetCrop();
560 DALI_TEST_EQUALS( crop.x, 50, TEST_LOCATION );
561 DALI_TEST_EQUALS( crop.y, 60, TEST_LOCATION );
562 DALI_TEST_EQUALS( crop.width, 70, TEST_LOCATION );
563 DALI_TEST_EQUALS( crop.height, 80, TEST_LOCATION );
566 // type FrameBufferImage
567 map.push_back( Property::StringValuePair( "type", "FrameBufferImage" ) );
569 Image image = NewImage( map );
570 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
573 (map.end() - 1)->second = "BitmapImage";
575 Image image = NewImage( map );
576 DALI_TEST_CHECK( BitmapImage::DownCast( image ) );
579 (map.end() - 1)->second = "Image";
581 Image image = NewImage( map );
582 DALI_TEST_CHECK( Image::DownCast( image ) );
583 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
584 DALI_TEST_CHECK( !BitmapImage::DownCast( image ) );
589 int UtcDaliScriptingNewShaderEffect(void)
591 TestApplication application;
593 Property::Map programMap;
594 programMap.push_back( Property::StringValuePair( "vertex-filename", "bump.vert" ) );
595 programMap.push_back( Property::StringValuePair( "fragment-filename", "bump.frag" ) );
597 Property::Map imageMap;
598 imageMap.push_back( Property::StringValuePair( "filename", "image.png" ) );
601 map.push_back( Property::StringValuePair( "image", imageMap ) );
602 map.push_back( Property::StringValuePair( "program", programMap ) );
603 map.push_back( Property::StringValuePair( "uLightPosition", Vector3( 0.0, 0.0, -1.5) ) );
604 map.push_back( Property::StringValuePair( "uAmbientLight", (int)10 ) );
606 ShaderEffect shader = NewShaderEffect( map );
608 DALI_TEST_CHECK( shader );
612 int UtcDaliScriptingNewActorNegative(void)
614 TestApplication application;
618 Actor handle = NewActor( Property::Map() );
619 DALI_TEST_CHECK( !handle );
622 // Map with only properties
625 map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) );
626 map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_CENTER ) );
627 Actor handle = NewActor( map );
628 DALI_TEST_CHECK( !handle );
631 // Add some signals to the map, we should have no signal connections as its not yet supported
634 map.push_back( Property::StringValuePair( "type", "Actor" ) );
635 map.push_back( Property::StringValuePair( "signals", Property::MAP ) );
636 Actor handle = NewActor( map );
637 DALI_TEST_CHECK( handle );
638 DALI_TEST_CHECK( !handle.MouseWheelEventSignal().GetConnectionCount() );
639 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
640 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
641 DALI_TEST_CHECK( !handle.SetSizeSignal().GetConnectionCount() );
642 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
647 int UtcDaliScriptingNewActorProperties(void)
649 TestApplication application;
652 map.push_back( Property::StringValuePair( "type", "Actor" ) );
653 map.push_back( Property::StringValuePair( "size", Vector3::ONE ) );
654 map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) );
655 map.push_back( Property::StringValuePair( "scale", Vector3::ONE ) );
656 map.push_back( Property::StringValuePair( "visible", false ) );
657 map.push_back( Property::StringValuePair( "color", Color::MAGENTA ) );
658 map.push_back( Property::StringValuePair( "name", "MyActor" ) );
659 map.push_back( Property::StringValuePair( "color-mode", "USE_PARENT_COLOR" ) );
660 map.push_back( Property::StringValuePair( "inherit-shader-effect", false ) );
661 map.push_back( Property::StringValuePair( "sensitive", false ) );
662 map.push_back( Property::StringValuePair( "leave-required", true ) );
663 map.push_back( Property::StringValuePair( "position-inheritance", "DONT_INHERIT_POSITION" ) );
664 map.push_back( Property::StringValuePair( "draw-mode", "STENCIL" ) );
665 map.push_back( Property::StringValuePair( "inherit-rotation", false ) );
666 map.push_back( Property::StringValuePair( "inherit-scale", false ) );
668 // Default properties
670 Actor handle = NewActor( map );
671 DALI_TEST_CHECK( handle );
673 Stage::GetCurrent().Add( handle );
674 application.SendNotification();
675 application.Render();
677 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
678 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
679 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
680 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
681 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
682 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
683 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
684 DALI_TEST_EQUALS( handle.GetInheritShaderEffect(), false, TEST_LOCATION );
685 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
686 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
687 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
688 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
689 DALI_TEST_EQUALS( handle.IsRotationInherited(), false, TEST_LOCATION );
690 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
692 Stage::GetCurrent().Remove( handle );
695 // Check Anchor point and parent origin vector3s
696 map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) );
697 map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_LEFT ) );
699 Actor handle = NewActor( map );
700 DALI_TEST_CHECK( handle );
702 Stage::GetCurrent().Add( handle );
703 application.SendNotification();
704 application.Render();
706 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
707 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
709 Stage::GetCurrent().Remove( handle );
712 // Check Anchor point and parent origin STRINGS
713 map.erase( map.end() - 2, map.end() ); // delete previously added parent origin and anchor point
714 map.push_back( Property::StringValuePair( "parent-origin", "BACK_TOP_LEFT" ) );
715 map.push_back( Property::StringValuePair( "anchor-point", "FRONT_CENTER_LEFT" ) );
717 Actor handle = NewActor( map );
718 DALI_TEST_CHECK( handle );
720 Stage::GetCurrent().Add( handle );
721 application.SendNotification();
722 application.Render();
724 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::BACK_TOP_LEFT, TEST_LOCATION );
725 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::FRONT_CENTER_LEFT, TEST_LOCATION );
727 Stage::GetCurrent().Remove( handle );
732 int UtcDaliScriptingNewActorChildren(void)
734 TestApplication application;
737 map.push_back( Property::StringValuePair( "type", "Actor" ) );
738 map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) );
740 Property::Map child1Map;
741 child1Map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
742 child1Map.push_back( Property::StringValuePair( "position", Vector3::YAXIS ) );
744 Property::Map child2Map;
745 child2Map.push_back( Property::StringValuePair( "type", "TextActor" ) );
746 child2Map.push_back( Property::StringValuePair( "position", Vector3::ZAXIS ) );
748 Property::Map grandChildMap;
749 grandChildMap.push_back( Property::StringValuePair( "type", "LightActor" ) );
750 grandChildMap.push_back( Property::StringValuePair( "position", Vector3::ONE ) );
752 // Add arrays to appropriate maps
753 Property::Array grandChildArray;
754 grandChildArray.push_back( grandChildMap );
755 Property::Array childArray;
756 child1Map.push_back( Property::StringValuePair( "actors", grandChildArray ) );
757 childArray.push_back( child1Map );
758 childArray.push_back( child2Map );
759 map.push_back( Property::StringValuePair( "actors", childArray ) );
762 Actor handle = NewActor( map );
763 DALI_TEST_CHECK( handle );
765 Stage::GetCurrent().Add( handle );
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
770 DALI_TEST_EQUALS( handle.GetChildCount(), 2u, TEST_LOCATION );
772 Actor child1 = handle.GetChildAt(0);
773 DALI_TEST_CHECK( child1 );
774 DALI_TEST_CHECK( ImageActor::DownCast( child1 ) );
775 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
776 DALI_TEST_EQUALS( child1.GetChildCount(), 1u, TEST_LOCATION );
778 Actor child2 = handle.GetChildAt(1);
779 DALI_TEST_CHECK( child2 );
780 DALI_TEST_CHECK( TextActor::DownCast( child2 ) );
781 DALI_TEST_EQUALS( child2.GetCurrentPosition(), Vector3::ZAXIS, TEST_LOCATION );
782 DALI_TEST_EQUALS( child2.GetChildCount(), 0u, TEST_LOCATION );
784 Actor grandChild = child1.GetChildAt( 0 );
785 DALI_TEST_CHECK( grandChild );
786 DALI_TEST_CHECK( LightActor::DownCast( grandChild ) );
787 DALI_TEST_EQUALS( grandChild.GetCurrentPosition(), Vector3::ONE, TEST_LOCATION );
788 DALI_TEST_EQUALS( grandChild.GetChildCount(), 0u, TEST_LOCATION );
790 Stage::GetCurrent().Remove( handle );
795 int UtcDaliScriptingCreatePropertyMapActor(void)
797 TestApplication application;
801 Actor actor = Actor::New();
804 CreatePropertyMap( actor, map );
805 DALI_TEST_CHECK( !map.empty() );
806 Property::Value value( map );
807 DALI_TEST_CHECK( value.HasKey( "type" ) );
808 DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "Actor", TEST_LOCATION );
810 Stage::GetCurrent().Remove( actor );
815 Actor actor = ImageActor::New();
818 CreatePropertyMap( actor, map );
819 DALI_TEST_CHECK( !map.empty() );
820 Property::Value value( map );
821 DALI_TEST_CHECK( value.HasKey( "type" ) );
822 DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "ImageActor", TEST_LOCATION );
824 Stage::GetCurrent().Remove( actor );
827 // Default properties
829 Actor actor = Actor::New();
830 actor.SetSize( Vector3::ONE );
831 actor.SetPosition( Vector3::XAXIS );
832 actor.SetScale( Vector3::ZAXIS );
833 actor.SetVisible( false );
834 actor.SetColor( Color::MAGENTA );
835 actor.SetName( "MyActor" );
836 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
837 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
838 actor.SetInheritShaderEffect( false );
839 actor.SetSensitive( false );
840 actor.SetLeaveRequired( true );
841 actor.SetInheritRotation( false );
842 actor.SetInheritScale( false );
844 Stage::GetCurrent().Add( actor );
845 application.SendNotification();
846 application.Render();
849 CreatePropertyMap( actor, map );
851 DALI_TEST_CHECK( !map.empty() );
852 Property::Value value( map );
853 DALI_TEST_CHECK( value.HasKey( "size" ) );
854 DALI_TEST_EQUALS( value.GetValue( "size" ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
855 DALI_TEST_CHECK( value.HasKey( "position" ) );
856 DALI_TEST_EQUALS( value.GetValue( "position" ).Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
857 DALI_TEST_CHECK( value.HasKey( "scale" ) );
858 DALI_TEST_EQUALS( value.GetValue( "scale" ).Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
859 DALI_TEST_CHECK( value.HasKey( "visible" ) );
860 DALI_TEST_EQUALS( value.GetValue( "visible" ).Get< bool >(), false, TEST_LOCATION );
861 DALI_TEST_CHECK( value.HasKey( "color" ) );
862 DALI_TEST_EQUALS( value.GetValue( "color" ).Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
863 DALI_TEST_CHECK( value.HasKey( "name" ) );
864 DALI_TEST_EQUALS( value.GetValue( "name").Get< std::string >(), "MyActor", TEST_LOCATION );
865 DALI_TEST_CHECK( value.HasKey( "anchor-point" ) );
866 DALI_TEST_EQUALS( value.GetValue( "anchor-point" ).Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
867 DALI_TEST_CHECK( value.HasKey( "parent-origin" ) );
868 DALI_TEST_EQUALS( value.GetValue( "parent-origin" ).Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
869 DALI_TEST_CHECK( value.HasKey( "inherit-shader-effect" ) );
870 DALI_TEST_EQUALS( value.GetValue( "inherit-shader-effect" ).Get< bool >(), false, TEST_LOCATION );
871 DALI_TEST_CHECK( value.HasKey( "sensitive" ) );
872 DALI_TEST_EQUALS( value.GetValue( "sensitive" ).Get< bool >(), false, TEST_LOCATION );
873 DALI_TEST_CHECK( value.HasKey( "leave-required" ) );
874 DALI_TEST_EQUALS( value.GetValue( "leave-required" ).Get< bool >(), true, TEST_LOCATION );
875 DALI_TEST_CHECK( value.HasKey( "inherit-rotation" ) );
876 DALI_TEST_EQUALS( value.GetValue( "inherit-rotation" ).Get< bool >(), false, TEST_LOCATION );
877 DALI_TEST_CHECK( value.HasKey( "inherit-scale" ) );
878 DALI_TEST_EQUALS( value.GetValue( "inherit-scale" ).Get< bool >(), false, TEST_LOCATION );
880 Stage::GetCurrent().Remove( actor );
884 TestEnumStrings< ColorMode >( "color-mode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
886 // PositionInheritanceMode
887 TestEnumStrings< PositionInheritanceMode >( "position-inheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
890 TestEnumStrings< DrawMode::Type >( "draw-mode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
894 Actor actor = Actor::New();
895 Actor child = ImageActor::New();
896 Actor grandChild = TextActor::New();
897 Actor grandChild2 = LightActor::New();
899 child.Add( grandChild );
900 child.Add( grandChild2 );
902 Stage::GetCurrent().Add( actor );
903 application.SendNotification();
904 application.Render();
907 CreatePropertyMap( actor, map );
908 DALI_TEST_CHECK( !map.empty() );
910 Property::Value value( map );
911 DALI_TEST_CHECK( value.HasKey( "type" ) );
912 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Actor", TEST_LOCATION );
914 DALI_TEST_CHECK( value.HasKey( "actors" ) );
915 Property::Array children( value.GetValue( "actors").Get< Property::Array >() );
916 DALI_TEST_CHECK( !children.empty() );
917 Property::Map childMap( children[0].Get< Property::Map >() );
918 DALI_TEST_CHECK( !childMap.empty() );
919 Property::Value childValue( childMap );
920 DALI_TEST_CHECK( childValue.HasKey( "type" ) );
921 DALI_TEST_EQUALS( childValue.GetValue( "type" ).Get< std::string >(), "ImageActor", TEST_LOCATION );
923 DALI_TEST_CHECK( childValue.HasKey( "actors" ) );
924 Property::Array grandChildren( childValue.GetValue( "actors").Get< Property::Array >() );
925 DALI_TEST_CHECK( grandChildren.size() == 2u );
927 Property::Map grandChildMap( grandChildren[0].Get< Property::Map >() );
928 DALI_TEST_CHECK( !grandChildMap.empty() );
929 Property::Value grandChildValue( grandChildMap );
930 DALI_TEST_CHECK( grandChildValue.HasKey( "type" ) );
931 DALI_TEST_EQUALS( grandChildValue.GetValue( "type" ).Get< std::string >(), "TextActor", TEST_LOCATION );
933 Property::Map grandChild2Map( grandChildren[1].Get< Property::Map >() );
934 DALI_TEST_CHECK( !grandChild2Map.empty() );
935 Property::Value grandChild2Value( grandChild2Map );
936 DALI_TEST_CHECK( grandChild2Value.HasKey( "type" ) );
937 DALI_TEST_EQUALS( grandChild2Value.GetValue( "type" ).Get< std::string >(), "LightActor", TEST_LOCATION );
939 Stage::GetCurrent().Remove( actor );
944 int UtcDaliScriptingCreatePropertyMapImage(void)
946 TestApplication application;
952 CreatePropertyMap( image, map );
953 DALI_TEST_CHECK( map.empty() );
958 Image image = Image::New( "MY_PATH" );
961 CreatePropertyMap( image, map );
962 DALI_TEST_CHECK( !map.empty() );
964 Property::Value value( map );
965 DALI_TEST_CHECK( value.HasKey( "type" ) );
966 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Image", TEST_LOCATION );
967 DALI_TEST_CHECK( value.HasKey( "filename" ) );
968 DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
969 DALI_TEST_CHECK( value.HasKey( "load-policy") );
970 DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "IMMEDIATE", TEST_LOCATION );
971 DALI_TEST_CHECK( value.HasKey( "release-policy") );
972 DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "NEVER", TEST_LOCATION );
973 DALI_TEST_CHECK( value.HasKey( "pixel-format") );
974 DALI_TEST_EQUALS( value.GetValue( "pixel-format" ).Get< std::string >(), "RGBA8888", TEST_LOCATION );
975 DALI_TEST_CHECK( value.HasKey( "scaling-mode") );
976 DALI_TEST_EQUALS( value.GetValue( "scaling-mode" ).Get< std::string >(), "SHRINK_TO_FIT", TEST_LOCATION );
977 DALI_TEST_CHECK( value.HasKey( "crop" ) );
978 DALI_TEST_EQUALS( value.GetValue( "crop" ).Get< Vector4 >(), Vector4( 0.0f, 0.0f, 1.0f, 1.0f ), TEST_LOCATION );
979 DALI_TEST_CHECK( !value.HasKey( "width" ) );
980 DALI_TEST_CHECK( !value.HasKey( "height" ) );
985 ImageAttributes attributes;
986 attributes.SetPixelFormat( Pixel::A8 );
987 attributes.SetScalingMode( ImageAttributes::FitWidth );
988 attributes.SetCrop( Rect< float >( 0.5f, 0.2f, 0.2f, 0.4f ) );
989 attributes.SetSize( 300, 400 );
990 Image image = Image::New( "MY_PATH", attributes, Image::OnDemand, Image::Unused );
993 CreatePropertyMap( image, map );
994 DALI_TEST_CHECK( !map.empty() );
996 Property::Value value( map );
997 DALI_TEST_CHECK( value.HasKey( "type" ) );
998 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Image", TEST_LOCATION );
999 DALI_TEST_CHECK( value.HasKey( "filename" ) );
1000 DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
1001 DALI_TEST_CHECK( value.HasKey( "load-policy") );
1002 DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "ON_DEMAND", TEST_LOCATION );
1003 DALI_TEST_CHECK( value.HasKey( "release-policy") );
1004 DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "UNUSED", TEST_LOCATION );
1005 DALI_TEST_CHECK( value.HasKey( "pixel-format") );
1006 DALI_TEST_EQUALS( value.GetValue( "pixel-format" ).Get< std::string >(), "A8", TEST_LOCATION );
1007 DALI_TEST_CHECK( value.HasKey( "scaling-mode") );
1008 DALI_TEST_EQUALS( value.GetValue( "scaling-mode" ).Get< std::string >(), "FIT_WIDTH", TEST_LOCATION );
1009 DALI_TEST_CHECK( value.HasKey( "crop" ) );
1010 DALI_TEST_EQUALS( value.GetValue( "crop" ).Get< Vector4 >(), Vector4( 0.5f, 0.2f, 0.2f, 0.4f ), TEST_LOCATION );
1011 DALI_TEST_CHECK( value.HasKey( "width" ) );
1012 DALI_TEST_EQUALS( value.GetValue( "width" ).Get< int >(), 300, TEST_LOCATION );
1013 DALI_TEST_CHECK( value.HasKey( "height" ) );
1014 DALI_TEST_EQUALS( value.GetValue( "height" ).Get< int >(), 400, TEST_LOCATION );
1019 Image image = BitmapImage::New( 200, 300, Pixel::RGBA8888 );
1021 CreatePropertyMap( image, map );
1022 Property::Value value( map );
1023 DALI_TEST_CHECK( value.HasKey( "type" ) );
1024 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "BitmapImage", TEST_LOCATION );
1029 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
1031 CreatePropertyMap( image, map );
1032 Property::Value value( map );
1033 DALI_TEST_CHECK( value.HasKey( "type" ) );
1034 DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "FrameBufferImage", TEST_LOCATION );