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 UtcDaliScriptingNewAnimation(void)
554 TestApplication application;
557 map["actor"] = "Actor1";
558 map["property"] = "color";
559 map["value"] = Color::MAGENTA;
560 map["alphaFunction"] = "EASE_IN_OUT";
562 Property::Map timePeriod;
563 timePeriod["delay"] = 0.5f;
564 timePeriod["duration"] = 1.0f;
565 map["timePeriod"] = timePeriod;
567 Dali::AnimationData data;
568 Scripting::NewAnimation( map, data );
570 Actor actor = Actor::New();
571 actor.SetName("Actor1");
572 actor.SetColor(Color::CYAN);
573 Stage::GetCurrent().Add(actor);
575 Animation anim = data.CreateAnimation( actor, 0.5f );
578 application.SendNotification();
579 application.Render(0);
580 application.Render(500); // Start animation
581 application.Render(500); // Halfway thru anim
582 application.SendNotification();
583 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
585 application.Render(500); // Halfway thru anim
586 application.SendNotification();
587 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
592 int UtcDaliScriptingNewActorChildren(void)
594 TestApplication application;
597 map[ "type" ] = "Actor";
598 map[ "position" ] = Vector3::XAXIS;
600 Property::Map child1Map;
601 child1Map[ "type" ] = "CameraActor";
602 child1Map[ "position" ] = Vector3::YAXIS;
604 Property::Array childArray;
605 childArray.PushBack( child1Map );
606 map[ "actors" ] = childArray;
609 Actor handle = NewActor( map );
610 DALI_TEST_CHECK( handle );
612 Stage::GetCurrent().Add( handle );
613 application.SendNotification();
614 application.Render();
616 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
617 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
619 Actor child1 = handle.GetChildAt(0);
620 DALI_TEST_CHECK( child1 );
621 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
622 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
623 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
625 Stage::GetCurrent().Remove( handle );
630 int UtcDaliScriptingCreatePropertyMapActor(void)
632 TestApplication application;
636 Actor actor = Actor::New();
639 CreatePropertyMap( actor, map );
640 DALI_TEST_CHECK( !map.Empty() );
641 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
642 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
644 Stage::GetCurrent().Remove( actor );
649 Actor actor = Layer::New();
652 CreatePropertyMap( actor, map );
653 DALI_TEST_CHECK( !map.Empty() );
654 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
655 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
657 Stage::GetCurrent().Remove( actor );
660 // Default properties
662 Actor actor = Actor::New();
663 actor.SetSize( Vector3::ONE );
664 actor.SetPosition( Vector3::XAXIS );
665 actor.SetScale( Vector3::ZAXIS );
666 actor.SetVisible( false );
667 actor.SetColor( Color::MAGENTA );
668 actor.SetName( "MyActor" );
669 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
670 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
671 actor.SetSensitive( false );
672 actor.SetLeaveRequired( true );
673 actor.SetInheritOrientation( false );
674 actor.SetInheritScale( false );
675 actor.SetSizeModeFactor( Vector3::ONE );
677 Stage::GetCurrent().Add( actor );
678 application.SendNotification();
679 application.Render();
682 CreatePropertyMap( actor, map );
684 DALI_TEST_CHECK( !map.Empty() );
685 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
686 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
687 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
688 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
689 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
690 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
691 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
692 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
693 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
694 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
695 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
696 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
697 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
698 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
699 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
700 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
701 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
702 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
703 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
704 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
705 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
706 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
707 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
708 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
709 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
710 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
712 Stage::GetCurrent().Remove( actor );
716 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
718 // PositionInheritanceMode
719 TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
722 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
726 Actor actor = Actor::New();
727 Actor child = Layer::New();
730 Stage::GetCurrent().Add( actor );
731 application.SendNotification();
732 application.Render();
735 CreatePropertyMap( actor, map );
736 DALI_TEST_CHECK( !map.Empty() );
738 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
739 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
741 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
742 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
743 DALI_TEST_CHECK( !children.Empty() );
744 Property::Map childMap( children[0].Get< Property::Map >() );
745 DALI_TEST_CHECK( !childMap.Empty() );
746 DALI_TEST_CHECK( childMap.Find( "type" ) );
747 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
749 Stage::GetCurrent().Remove( actor );
754 int UtcDaliScriptingCreatePropertyMapImage(void)
756 TestApplication application;
762 CreatePropertyMap( image, map );
763 DALI_TEST_CHECK( map.Empty() );
768 Image image = ResourceImage::New( "MY_PATH" );
771 CreatePropertyMap( image, map );
772 DALI_TEST_CHECK( !map.Empty() );
774 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
775 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
776 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
777 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
778 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
779 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
784 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
787 CreatePropertyMap( image, map );
788 DALI_TEST_CHECK( !map.Empty() );
790 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
791 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
792 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
793 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
794 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
795 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
796 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
797 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
802 Image image = BufferImage::New( 200, 300, Pixel::A8 );
804 CreatePropertyMap( image, map );
805 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
806 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
807 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
808 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
813 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
815 CreatePropertyMap( image, map );
816 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
817 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
822 int UtcDaliScriptingGetEnumerationTemplates(void)
824 const Scripting::StringEnum myTable[] =
832 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
834 for ( unsigned int i = 0; i < myTableCount; ++i )
836 tet_printf("Checking: %s\n", myTable[ i ].string );
838 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
839 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
842 for ( unsigned int i = 0; i < myTableCount; ++i )
844 tet_printf("Checking: %d\n", myTable[ i ].value );
845 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
851 int UtcDaliScriptingGetEnumerationNameN(void)
853 const char* value = GetEnumerationName( 10, NULL, 0 );
854 DALI_TEST_CHECK( NULL == value );
856 value = GetEnumerationName( 10, NULL, 1 );
857 DALI_TEST_CHECK( NULL == value );
862 int UtcDaliScriptingGetLinearEnumerationNameN(void)
864 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
865 DALI_TEST_CHECK( NULL == value );
867 value = GetLinearEnumerationName( 10, NULL, 1 );
868 DALI_TEST_CHECK( NULL == value );
873 int UtcDaliScriptingGetEnumerationProperty(void)
876 * This test function performs the following checks:
877 * - An enum can be looked up from a Property::Value of type INTEGER.
878 * - An enum can be looked up from a Property::Value of type STRING.
879 * - An enum can NOT be looked up for other Property::Value types.
880 * - The return value is "true" if the property can be successfully converted AND it has changed.
881 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
882 * - The return value is "false" if the property can not be successfully converted.
883 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
886 // String to Enum property table to test with (equivalent to ones used within DALi).
887 const Dali::Scripting::StringEnum testTable[] = {
888 { "NONE", FaceCullingMode::NONE },
889 { "FRONT", FaceCullingMode::FRONT },
890 { "BACK", FaceCullingMode::BACK },
891 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
892 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
894 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
895 // Initialise to first element.
896 FaceCullingMode::Type result = FaceCullingMode::NONE;
897 // Set the input property value to a different value (to emulate a change).
898 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
900 // Perform the lookup.
901 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
903 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
904 // Check the property could be converted.
905 DALI_TEST_CHECK( returnValue );
907 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
909 // Now emulate a property-set with the same value. false should be returned.
910 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
912 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
913 DALI_TEST_CHECK( !returnValue );
915 // The result should remain the same.
916 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
918 // TEST: An enum can be looked up from a Property::Value of type STRING.
919 // Set the input property value to a different value (to emulate a change).
920 Property::Value propertyValueString( "BACK" );
922 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
924 DALI_TEST_CHECK( returnValue );
926 // The result should remain the same.
927 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
929 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
931 DALI_TEST_CHECK( !returnValue );
933 // The result should remain the same.
934 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
936 // TEST: An enum can NOT be looked up for other Property::Value types.
937 Property::Value propertyValueBoolean( true );
939 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
941 // TEST: The return value is "false" if the property can not be successfully converted.
942 // Return value should be false as Property::Value was of an unsupported type for enum properties.
943 DALI_TEST_CHECK( !returnValue );
945 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
946 // The result should remain the same.
947 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
952 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
955 * This test function performs the following checks:
956 * - An enum can be looked up from a Property::Value of type INTEGER.
957 * - An enum can be looked up from a Property::Value of type STRING.
958 * - An enum can NOT be looked up from other Property::Value types.
959 * - The return value is "true" if the property can be successfully converted AND it has changed.
960 * - The return value is "false" if the property can not be successfully converted.
961 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
963 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
964 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
965 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
966 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
967 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
968 * - 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.
969 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
970 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
973 // String to Enum property table to test with (equivalent to ones used within DALi).
974 const Dali::Scripting::StringEnum testTable[] = {
975 { "NONE", FaceCullingMode::NONE },
976 { "FRONT", FaceCullingMode::FRONT },
977 { "BACK", FaceCullingMode::BACK },
978 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
979 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
981 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
982 // Initialise to first element.
983 FaceCullingMode::Type result = FaceCullingMode::NONE;
984 // Set the input property value to a different value (to emulate a change).
985 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
987 // Perform the lookup.
988 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
990 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
991 // Check the property could be converted.
992 DALI_TEST_CHECK( returnValue );
994 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
996 // TEST: An enum can be looked up from a Property::Value of type STRING.
997 // Set the input property value to a different value (to emulate a change).
998 Property::Value propertyValueString( "BACK" );
1000 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
1002 DALI_TEST_CHECK( returnValue );
1004 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1006 // TEST: An enum can NOT be looked up from other Property::Value types.
1007 Property::Value propertyValueVector( Vector3::ZERO );
1009 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
1011 // TEST: The return value is "false" if the property can not be successfully converted.
1012 // Return value should be false as Property::Value was of an unsupported type for enum properties.
1013 DALI_TEST_CHECK( !returnValue );
1015 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1016 // The result should remain the same.
1017 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1019 // Test PropertyArrays:
1021 // Property array of 2 integers.
1022 Property::Array propertyArrayIntegers;
1023 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1024 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1025 result = FaceCullingMode::NONE;
1027 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1029 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1030 DALI_TEST_CHECK( returnValue );
1031 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1032 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1034 // Property array of 2 strings.
1035 Property::Array propertyArrayStrings;
1036 propertyArrayStrings.PushBack( "FRONT" );
1037 propertyArrayStrings.PushBack( "BACK" );
1038 result = FaceCullingMode::NONE;
1040 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1042 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1043 DALI_TEST_CHECK( returnValue );
1044 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1045 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1047 // Property array of an int and a string.
1048 Property::Array propertyArrayMixed;
1049 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1050 propertyArrayMixed.PushBack( "BACK" );
1051 result = FaceCullingMode::NONE;
1053 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1055 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1056 DALI_TEST_CHECK( returnValue );
1057 // 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.
1058 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1060 // Property array of an int and a string.
1061 Property::Array propertyArrayInvalid;
1062 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1063 propertyArrayInvalid.PushBack( Vector3::ZERO );
1065 // Set the initial value to non-zero, so we can test it does not change.
1066 result = FaceCullingMode::FRONT_AND_BACK;
1068 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1070 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1071 DALI_TEST_CHECK( !returnValue );
1072 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1073 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1078 int UtcDaliScriptingFindEnumIndexN(void)
1080 const Scripting::StringEnum myTable[] =
1084 { "THREE", (1<<3) },
1088 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1089 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1094 int UtcDaliScriptingEnumStringToIntegerP(void)
1096 const Scripting::StringEnum myTable[] =
1100 { "THREE", (1<<3) },
1104 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1106 int integerEnum = 0;
1107 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1109 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1112 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1113 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1115 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1116 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1118 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1119 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1121 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1122 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1124 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1125 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1127 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1128 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1130 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1131 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1133 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1134 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1140 int UtcDaliScriptingEnumStringToIntegerN(void)
1142 const Scripting::StringEnum myTable[] =
1150 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1152 int integerEnum = 0;
1153 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1155 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1157 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1159 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1161 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1163 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1165 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1170 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1172 const Scripting::StringEnum myTable[] =
1179 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1181 int integerEnum = 0;
1182 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1183 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1188 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1190 const Scripting::StringEnum myTable[] =
1197 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1199 int integerEnum = 0;
1200 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1202 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1204 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1206 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1208 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1210 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );