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 }
54 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( DRAW_MODE_VALUES[0] );
57 ////////////////////////////////////////////////////////////////////////////////
58 // Helpers for string to enum comparisons for Image and Image loading parameters
59 ////////////////////////////////////////////////////////////////////////////////
62 * Template to check enumerations of type T, with a class of type X
64 template< typename T, typename X >
66 Property::Map& map, // The map used to create instance of type X
67 const char * const keyName, // the name of the key to iterate through
68 const StringEnum* 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 // get the key reference so we can change its value
75 Property::Value* value = map.Find( keyName );
76 for ( unsigned int i = 0; i < num; ++i )
78 *value = values[i].string;
79 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
80 X instance = creator( map );
81 DALI_TEST_EQUALS( values[i].value, (int)( instance.*method )(), TEST_LOCATION );
85 /// Helper method to create ResourceImage using property
86 ResourceImage NewResourceImage( const Property::Value& map )
88 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
92 /// Helper method to create ResourceImage using property
93 BufferImage NewBufferImage( const Property::Value& map )
95 BufferImage image = BufferImage::DownCast( NewImage( map ) );
99 //////////////////////////////////////////////////////////////////////////////
100 // Helpers for string to enum comparisons for Actor to Property::Map
101 //////////////////////////////////////////////////////////////////////////////
104 * Template to check enumerations of type T
106 template< typename T >
107 void TestEnumStrings(
108 const char * const keyName, // The name of the key to check
109 TestApplication& application, // Reference to the application class
110 const StringEnum* values, // An array of string values
111 unsigned int num, // Number of items in the array
112 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
115 for ( unsigned int i = 0; i < num; ++i )
117 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
119 Actor actor = Actor::New();
120 (actor.*method)( ( T ) values[i].value );
122 Stage::GetCurrent().Add( actor );
123 application.SendNotification();
124 application.Render();
127 CreatePropertyMap( actor, map );
129 DALI_TEST_CHECK( 0 < map.Count() );
130 DALI_TEST_CHECK( NULL != map.Find( keyName ) );
131 DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION );
133 Stage::GetCurrent().Remove( actor );
137 //////////////////////////////////////////////////////////////////////////////
142 int UtcDaliScriptingNewImageNegative01(void)
146 map[ "filename" ] = Vector3::ZERO;
147 // will give us an empty image handle
148 Image image = NewImage( map );
149 DALI_TEST_CHECK( !image );
153 int UtcDaliScriptingNewImageNegative06(void)
155 TestApplication application; // Image needs application
156 // Invalid width and height
158 map[ "filename" ] = "TEST_FILE";
159 map[ "width" ] = "Invalid";
160 map[ "height" ] = 100;
161 // will give us a valid image
162 Image image = NewImage( map );
163 DALI_TEST_CHECK( image );
164 ResourceImage resImage = ResourceImage::DownCast( image );
165 DALI_TEST_CHECK( resImage );
166 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
167 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
171 int UtcDaliScriptingNewImageNegative07(void)
173 TestApplication application; // Image needs application
176 map[ "filename" ] = "TEST_FILE";
178 map[ "height" ] = "Invalid";
179 // will give us a valid image
180 Image image = NewImage( map );
181 DALI_TEST_CHECK( image );
182 ResourceImage resImage = ResourceImage::DownCast( image );
183 DALI_TEST_CHECK( resImage );
184 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
185 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
189 int UtcDaliScriptingNewImageNegative08(void)
191 TestApplication application; // Image needs application
192 // Invalid fitting-mode
194 map[ "filename" ] = "TEST_FILE";
195 map[ "fittingMode" ] = Vector3::ZERO;
196 // will give us a valid image
197 Image image = NewImage( map );
198 DALI_TEST_CHECK( image );
199 ResourceImage resImage = ResourceImage::DownCast( image );
200 DALI_TEST_CHECK( resImage );
204 int UtcDaliScriptingNewImageNegative09(void)
206 TestApplication application; // Image needs application
209 map[ "filename" ] = "TEST_FILE";
210 map[ "fittingMode" ] = "INVALID";
211 // will give us a valid image
212 Image image = NewImage( map );
213 DALI_TEST_CHECK( image );
214 ResourceImage resImage = ResourceImage::DownCast( image );
215 DALI_TEST_CHECK( resImage );
219 int UtcDaliScriptingNewImageNegative10(void)
221 TestApplication application; // Image needs application
222 // Invalid scaling-mode
224 map[ "filename" ] = "TEST_FILE";
225 map[ "samplingMode" ] = Vector3::ZERO;
226 // will give us a valid image
227 Image image = NewImage( map );
228 DALI_TEST_CHECK( image );
229 ResourceImage resImage = ResourceImage::DownCast( image );
230 DALI_TEST_CHECK( resImage );
234 int UtcDaliScriptingNewImageNegative12(void)
236 TestApplication application; // Image needs application
237 // Invalid orientation-correction
239 map[ "filename" ] = "TEST_FILE";
240 map[ "orientation" ] = Vector3::ZERO;
241 // will give us a valid image
242 Image image = NewImage( map );
243 DALI_TEST_CHECK( image );
244 ResourceImage resImage = ResourceImage::DownCast( image );
245 DALI_TEST_CHECK( resImage );
249 int UtcDaliScriptingNewImageNegative13(void)
251 TestApplication application; // Image needs application
254 map[ "filename" ] = "TEST_FILE";
255 map[ "type" ] = Vector3::ZERO;
256 // will give us a valid image
257 Image image = NewImage( map );
258 DALI_TEST_CHECK( image );
259 ResourceImage resImage = ResourceImage::DownCast( image );
260 DALI_TEST_CHECK( resImage );
264 int UtcDaliScriptingNewImageNegative14(void)
268 map[ "type" ] = "INVALID";
269 Image image = NewImage( map );
270 DALI_TEST_CHECK( !image );
274 int UtcDaliScriptingNewImageNegative15(void)
276 // Invalid pixel-format
278 map[ "pixelFormat" ] = Vector3::ZERO;
279 Image image = NewImage( map );
280 DALI_TEST_CHECK( !image );
284 int UtcDaliScriptingNewImageNegative16(void)
288 map[ "pixelFormat" ] = "INVALID";
289 Image image = NewImage( map );
290 DALI_TEST_CHECK( !image );
294 int UtcDaliScriptingNewImage01P(void)
296 TestApplication application; // Image needs application
299 map[ "filename" ] = "TEST_FILE";
302 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
303 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
307 int UtcDaliScriptingNewImage04P(void)
309 TestApplication application;
312 map[ "filename" ] = "TEST_FILE";
314 // float width and height
315 map[ "width" ] = (float) 10.0f;
316 map[ "height" ] = (float) 20.0f;
317 Image image = NewImage( map );
318 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
319 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
323 int UtcDaliScriptingNewImage05P(void)
325 TestApplication application;
328 map[ "filename" ] = "TEST_FILE";
332 map[ "height" ] = 70;
333 Image image = NewImage( map );
334 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
335 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
339 int UtcDaliScriptingNewImage06P(void)
341 TestApplication application;
344 // type FrameBufferImage
345 map[ "type" ] = "FrameBufferImage";
348 map[ "height" ] = 70;
349 Image image = NewImage( map );
350 DALI_TEST_CHECK( image );
351 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
355 int UtcDaliScriptingNewImage07P(void)
357 TestApplication application;
361 map[ "type" ] = "BufferImage";
364 map[ "height" ] = 70;
365 Image image = NewImage( map );
366 DALI_TEST_CHECK( image );
367 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
368 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
372 int UtcDaliScriptingNewImage08P(void)
374 TestApplication application;
377 map[ "type" ] = "BufferImage";
380 map[ "height" ] = 99;
382 map[ "pixelFormat" ] = "";
383 const StringEnum values[] =
387 { "LA88", Pixel::LA88 },
388 { "RGB565", Pixel::RGB565 },
389 { "BGR565", Pixel::BGR565 },
390 { "RGBA4444", Pixel::RGBA4444 },
391 { "BGRA4444", Pixel::BGRA4444 },
392 { "RGBA5551", Pixel::RGBA5551 },
393 { "BGRA5551", Pixel::BGRA5551 },
394 { "RGB888", Pixel::RGB888 },
395 { "RGB8888", Pixel::RGB8888 },
396 { "BGR8888", Pixel::BGR8888 },
397 { "RGBA8888", Pixel::RGBA8888 },
398 { "BGRA8888", Pixel::BGRA8888 },
399 // BufferImage does not support compressed formats
401 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
406 int UtcDaliScriptingNewImage09P(void)
408 TestApplication application;
412 map[ "type" ] = "ResourceImage";
413 map[ "filename" ] = "TEST_FILE";
416 Image image = NewImage( map );
417 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
418 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
419 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
424 int UtcDaliScriptingNewImage10P(void)
426 TestApplication application;
429 // type FrameBufferImage, empty size gives us stage size
430 map[ "type" ] = "FrameBufferImage";
431 Image image = NewImage( map );
432 DALI_TEST_CHECK( image );
436 int UtcDaliScriptingNewActorNegative(void)
438 TestApplication application;
442 Actor handle = NewActor( Property::Map() );
443 DALI_TEST_CHECK( !handle );
446 // Map with only properties
449 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
450 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
451 Actor handle = NewActor( map );
452 DALI_TEST_CHECK( !handle );
455 // Add some signals to the map, we should have no signal connections as its not yet supported
458 map[ "type" ] = "Actor";
459 map[ "signals" ] = Property::MAP;
460 Actor handle = NewActor( map );
461 DALI_TEST_CHECK( handle );
462 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
463 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
464 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
465 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
470 int UtcDaliScriptingNewActorProperties(void)
472 TestApplication application;
475 map[ "type" ] = "Actor";
476 map[ "size" ] = Vector3::ONE;
477 map[ "position" ] = Vector3::XAXIS;
478 map[ "scale" ] = Vector3::ONE;
479 map[ "visible" ] = false;
480 map[ "color" ] = Color::MAGENTA;
481 map[ "name" ] = "MyActor";
482 map[ "colorMode" ] = "USE_PARENT_COLOR";
483 map[ "sensitive" ] = false;
484 map[ "leaveRequired" ] = true;
485 map[ "positionInheritance" ] = "DONT_INHERIT_POSITION";
486 map[ "drawMode" ] = "OVERLAY_2D";
487 map[ "inheritOrientation" ] = false;
488 map[ "inheritScale" ] = false;
490 // Default properties
492 Actor handle = NewActor( map );
493 DALI_TEST_CHECK( handle );
495 Stage::GetCurrent().Add( handle );
496 application.SendNotification();
497 application.Render();
499 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
500 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
501 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
502 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
503 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
504 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
505 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
506 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
507 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
508 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
509 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
510 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
511 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
513 Stage::GetCurrent().Remove( handle );
516 // Check Anchor point and parent origin vector3s
517 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
518 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
520 Actor handle = NewActor( map );
521 DALI_TEST_CHECK( handle );
523 Stage::GetCurrent().Add( handle );
524 application.SendNotification();
525 application.Render();
527 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
528 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
530 Stage::GetCurrent().Remove( handle );
533 // Check Anchor point and parent origin STRINGS
534 map[ "parentOrigin" ] = "TOP_LEFT";
535 map[ "anchorPoint" ] = "CENTER_LEFT";
537 Actor handle = NewActor( map );
538 DALI_TEST_CHECK( handle );
540 Stage::GetCurrent().Add( handle );
541 application.SendNotification();
542 application.Render();
544 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
545 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
547 Stage::GetCurrent().Remove( handle );
552 int UtcDaliScriptingNewActorChildren(void)
554 TestApplication application;
557 map[ "type" ] = "Actor";
558 map[ "position" ] = Vector3::XAXIS;
560 Property::Map child1Map;
561 child1Map[ "type" ] = "CameraActor";
562 child1Map[ "position" ] = Vector3::YAXIS;
564 Property::Array childArray;
565 childArray.PushBack( child1Map );
566 map[ "actors" ] = childArray;
569 Actor handle = NewActor( map );
570 DALI_TEST_CHECK( handle );
572 Stage::GetCurrent().Add( handle );
573 application.SendNotification();
574 application.Render();
576 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
577 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
579 Actor child1 = handle.GetChildAt(0);
580 DALI_TEST_CHECK( child1 );
581 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
582 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
583 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
585 Stage::GetCurrent().Remove( handle );
590 int UtcDaliScriptingCreatePropertyMapActor(void)
592 TestApplication application;
596 Actor actor = Actor::New();
599 CreatePropertyMap( actor, map );
600 DALI_TEST_CHECK( !map.Empty() );
601 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
602 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
604 Stage::GetCurrent().Remove( actor );
609 Actor actor = Layer::New();
612 CreatePropertyMap( actor, map );
613 DALI_TEST_CHECK( !map.Empty() );
614 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
615 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
617 Stage::GetCurrent().Remove( actor );
620 // Default properties
622 Actor actor = Actor::New();
623 actor.SetSize( Vector3::ONE );
624 actor.SetPosition( Vector3::XAXIS );
625 actor.SetScale( Vector3::ZAXIS );
626 actor.SetVisible( false );
627 actor.SetColor( Color::MAGENTA );
628 actor.SetName( "MyActor" );
629 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
630 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
631 actor.SetSensitive( false );
632 actor.SetLeaveRequired( true );
633 actor.SetInheritOrientation( false );
634 actor.SetInheritScale( false );
635 actor.SetSizeModeFactor( Vector3::ONE );
637 Stage::GetCurrent().Add( actor );
638 application.SendNotification();
639 application.Render();
642 CreatePropertyMap( actor, map );
644 DALI_TEST_CHECK( !map.Empty() );
645 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
646 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
647 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
648 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
649 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
650 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
651 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
652 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
653 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
654 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
655 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
656 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
657 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
658 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
659 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
660 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
661 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
662 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
663 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
664 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
665 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
666 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
667 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
668 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
669 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
670 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
672 Stage::GetCurrent().Remove( actor );
676 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
678 // PositionInheritanceMode
679 TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
682 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
686 Actor actor = Actor::New();
687 Actor child = Layer::New();
690 Stage::GetCurrent().Add( actor );
691 application.SendNotification();
692 application.Render();
695 CreatePropertyMap( actor, map );
696 DALI_TEST_CHECK( !map.Empty() );
698 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
699 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
701 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
702 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
703 DALI_TEST_CHECK( !children.Empty() );
704 Property::Map childMap( children[0].Get< Property::Map >() );
705 DALI_TEST_CHECK( !childMap.Empty() );
706 DALI_TEST_CHECK( childMap.Find( "type" ) );
707 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
709 Stage::GetCurrent().Remove( actor );
714 int UtcDaliScriptingCreatePropertyMapImage(void)
716 TestApplication application;
722 CreatePropertyMap( image, map );
723 DALI_TEST_CHECK( map.Empty() );
728 Image image = ResourceImage::New( "MY_PATH" );
731 CreatePropertyMap( image, map );
732 DALI_TEST_CHECK( !map.Empty() );
734 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
735 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
736 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
737 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
738 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
739 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
744 ResourceImage image = ResourceImage::New( "MY_PATH", ResourceImage::ON_DEMAND, Image::UNUSED, ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
747 CreatePropertyMap( image, map );
748 DALI_TEST_CHECK( !map.Empty() );
750 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
751 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
752 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
753 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
754 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
755 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
756 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
757 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
762 Image image = BufferImage::New( 200, 300, Pixel::A8 );
764 CreatePropertyMap( image, map );
765 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
766 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
767 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
768 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
773 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
775 CreatePropertyMap( image, map );
776 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
777 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
782 int UtcDaliScriptingGetEnumerationTemplates(void)
784 const Scripting::StringEnum myTable[] =
792 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
794 for ( unsigned int i = 0; i < myTableCount; ++i )
796 tet_printf("Checking: %s\n", myTable[ i ].string );
798 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
799 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
802 for ( unsigned int i = 0; i < myTableCount; ++i )
804 tet_printf("Checking: %d\n", myTable[ i ].value );
805 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
811 int UtcDaliScriptingGetEnumerationNameN(void)
813 const char* value = GetEnumerationName( 10, NULL, 0 );
814 DALI_TEST_CHECK( NULL == value );
816 value = GetEnumerationName( 10, NULL, 1 );
817 DALI_TEST_CHECK( NULL == value );
822 int UtcDaliScriptingGetLinearEnumerationNameN(void)
824 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
825 DALI_TEST_CHECK( NULL == value );
827 value = GetLinearEnumerationName( 10, NULL, 1 );
828 DALI_TEST_CHECK( NULL == value );
833 int UtcDaliScriptingGetEnumerationProperty(void)
836 * This test function performs the following checks:
837 * - An enum can be looked up from a Property::Value of type INTEGER.
838 * - An enum can be looked up from a Property::Value of type STRING.
839 * - An enum can NOT be looked up for other Property::Value types.
840 * - The return value is "true" if the property can be successfully converted AND it has changed.
841 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
842 * - The return value is "false" if the property can not be successfully converted.
843 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
846 // String to Enum property table to test with (equivalent to ones used within DALi).
847 const Dali::Scripting::StringEnum testTable[] = {
848 { "NONE", FaceCullingMode::NONE },
849 { "FRONT", FaceCullingMode::FRONT },
850 { "BACK", FaceCullingMode::BACK },
851 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
852 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
854 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
855 // Initialise to first element.
856 FaceCullingMode::Type result = FaceCullingMode::NONE;
857 // Set the input property value to a different value (to emulate a change).
858 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
860 // Perform the lookup.
861 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
863 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
864 // Check the property could be converted.
865 DALI_TEST_CHECK( returnValue );
867 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
869 // Now emulate a property-set with the same value. false should be returned.
870 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
872 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
873 DALI_TEST_CHECK( !returnValue );
875 // The result should remain the same.
876 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
878 // TEST: An enum can be looked up from a Property::Value of type STRING.
879 // Set the input property value to a different value (to emulate a change).
880 Property::Value propertyValueString( "BACK" );
882 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
884 DALI_TEST_CHECK( returnValue );
886 // The result should remain the same.
887 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
889 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
891 DALI_TEST_CHECK( !returnValue );
893 // The result should remain the same.
894 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
896 // TEST: An enum can NOT be looked up for other Property::Value types.
897 Property::Value propertyValueBoolean( true );
899 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
901 // TEST: The return value is "false" if the property can not be successfully converted.
902 // Return value should be false as Property::Value was of an unsupported type for enum properties.
903 DALI_TEST_CHECK( !returnValue );
905 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
906 // The result should remain the same.
907 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
912 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
915 * This test function performs the following checks:
916 * - An enum can be looked up from a Property::Value of type INTEGER.
917 * - An enum can be looked up from a Property::Value of type STRING.
918 * - An enum can NOT be looked up from other Property::Value types.
919 * - The return value is "true" if the property can be successfully converted AND it has changed.
920 * - The return value is "false" if the property can not be successfully converted.
921 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
923 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
924 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
925 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
926 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
927 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
928 * - 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.
929 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
930 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
933 // String to Enum property table to test with (equivalent to ones used within DALi).
934 const Dali::Scripting::StringEnum testTable[] = {
935 { "NONE", FaceCullingMode::NONE },
936 { "FRONT", FaceCullingMode::FRONT },
937 { "BACK", FaceCullingMode::BACK },
938 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
939 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
941 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
942 // Initialise to first element.
943 FaceCullingMode::Type result = FaceCullingMode::NONE;
944 // Set the input property value to a different value (to emulate a change).
945 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
947 // Perform the lookup.
948 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
950 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
951 // Check the property could be converted.
952 DALI_TEST_CHECK( returnValue );
954 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
956 // TEST: An enum can be looked up from a Property::Value of type STRING.
957 // Set the input property value to a different value (to emulate a change).
958 Property::Value propertyValueString( "BACK" );
960 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
962 DALI_TEST_CHECK( returnValue );
964 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
966 // TEST: An enum can NOT be looked up from other Property::Value types.
967 Property::Value propertyValueVector( Vector3::ZERO );
969 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
971 // TEST: The return value is "false" if the property can not be successfully converted.
972 // Return value should be false as Property::Value was of an unsupported type for enum properties.
973 DALI_TEST_CHECK( !returnValue );
975 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
976 // The result should remain the same.
977 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
979 // Test PropertyArrays:
981 // Property array of 2 integers.
982 Property::Array propertyArrayIntegers;
983 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
984 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
985 result = FaceCullingMode::NONE;
987 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
989 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
990 DALI_TEST_CHECK( returnValue );
991 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
992 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
994 // Property array of 2 strings.
995 Property::Array propertyArrayStrings;
996 propertyArrayStrings.PushBack( "FRONT" );
997 propertyArrayStrings.PushBack( "BACK" );
998 result = FaceCullingMode::NONE;
1000 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1002 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1003 DALI_TEST_CHECK( returnValue );
1004 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1005 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1007 // Property array of an int and a string.
1008 Property::Array propertyArrayMixed;
1009 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1010 propertyArrayMixed.PushBack( "BACK" );
1011 result = FaceCullingMode::NONE;
1013 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1015 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1016 DALI_TEST_CHECK( returnValue );
1017 // 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.
1018 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1020 // Property array of an int and a string.
1021 Property::Array propertyArrayInvalid;
1022 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1023 propertyArrayInvalid.PushBack( Vector3::ZERO );
1025 // Set the initial value to non-zero, so we can test it does not change.
1026 result = FaceCullingMode::FRONT_AND_BACK;
1028 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1030 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1031 DALI_TEST_CHECK( !returnValue );
1032 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1033 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1038 int UtcDaliScriptingFindEnumIndexN(void)
1040 const Scripting::StringEnum myTable[] =
1044 { "THREE", (1<<3) },
1048 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1049 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1054 int UtcDaliScriptingEnumStringToIntegerP(void)
1056 const Scripting::StringEnum myTable[] =
1060 { "THREE", (1<<3) },
1064 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1066 int integerEnum = 0;
1067 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1069 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1072 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1073 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1075 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1076 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1078 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1079 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1081 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1082 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1084 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1085 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1087 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1088 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1090 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1091 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1093 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1094 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1100 int UtcDaliScriptingEnumStringToIntegerN(void)
1102 const Scripting::StringEnum myTable[] =
1110 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1112 int integerEnum = 0;
1113 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1115 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1117 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1119 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1121 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1123 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1125 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1130 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1132 const Scripting::StringEnum myTable[] =
1139 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1141 int integerEnum = 0;
1142 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1143 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1148 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1150 const Scripting::StringEnum myTable[] =
1157 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1159 int integerEnum = 0;
1160 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1162 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1164 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1166 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1168 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1170 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );