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 BufferImage using property
86 BufferImage NewBufferImage( const Property::Value& map )
88 BufferImage image = BufferImage::DownCast( NewImage( map ) );
92 //////////////////////////////////////////////////////////////////////////////
93 // Helpers for string to enum comparisons for Actor to Property::Map
94 //////////////////////////////////////////////////////////////////////////////
97 * Template to check enumerations of type T
99 template< typename T >
100 void TestEnumStrings(
101 const char * const keyName, // The name of the key to check
102 TestApplication& application, // Reference to the application class
103 const StringEnum* values, // An array of string values
104 unsigned int num, // Number of items in the array
105 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
108 for ( unsigned int i = 0; i < num; ++i )
110 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
112 Actor actor = Actor::New();
113 (actor.*method)( ( T ) values[i].value );
115 Stage::GetCurrent().Add( actor );
116 application.SendNotification();
117 application.Render();
120 CreatePropertyMap( actor, map );
122 DALI_TEST_CHECK( 0 < map.Count() );
123 DALI_TEST_CHECK( NULL != map.Find( keyName ) );
124 DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION );
126 Stage::GetCurrent().Remove( actor );
130 //////////////////////////////////////////////////////////////////////////////
135 int UtcDaliScriptingNewImageNegative01(void)
139 map[ "filename" ] = Vector3::ZERO;
140 // will give us an empty image handle
141 Image image = NewImage( map );
142 DALI_TEST_CHECK( !image );
146 int UtcDaliScriptingNewImageNegative06(void)
148 TestApplication application; // Image needs application
149 // Invalid width and height
151 map[ "filename" ] = "TEST_FILE";
152 map[ "width" ] = "Invalid";
153 map[ "height" ] = 100;
154 // will give us a valid image
155 Image image = NewImage( map );
156 DALI_TEST_CHECK( image );
157 ResourceImage resImage = ResourceImage::DownCast( image );
158 DALI_TEST_CHECK( resImage );
159 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
160 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
164 int UtcDaliScriptingNewImageNegative07(void)
166 TestApplication application; // Image needs application
169 map[ "filename" ] = "TEST_FILE";
171 map[ "height" ] = "Invalid";
172 // will give us a valid image
173 Image image = NewImage( map );
174 DALI_TEST_CHECK( image );
175 ResourceImage resImage = ResourceImage::DownCast( image );
176 DALI_TEST_CHECK( resImage );
177 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
178 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
182 int UtcDaliScriptingNewImageNegative08(void)
184 TestApplication application; // Image needs application
185 // Invalid fitting-mode
187 map[ "filename" ] = "TEST_FILE";
188 map[ "fittingMode" ] = Vector3::ZERO;
189 // will give us a valid image
190 Image image = NewImage( map );
191 DALI_TEST_CHECK( image );
192 ResourceImage resImage = ResourceImage::DownCast( image );
193 DALI_TEST_CHECK( resImage );
197 int UtcDaliScriptingNewImageNegative09(void)
199 TestApplication application; // Image needs application
202 map[ "filename" ] = "TEST_FILE";
203 map[ "fittingMode" ] = "INVALID";
204 // will give us a valid image
205 Image image = NewImage( map );
206 DALI_TEST_CHECK( image );
207 ResourceImage resImage = ResourceImage::DownCast( image );
208 DALI_TEST_CHECK( resImage );
212 int UtcDaliScriptingNewImageNegative10(void)
214 TestApplication application; // Image needs application
215 // Invalid scaling-mode
217 map[ "filename" ] = "TEST_FILE";
218 map[ "samplingMode" ] = Vector3::ZERO;
219 // will give us a valid image
220 Image image = NewImage( map );
221 DALI_TEST_CHECK( image );
222 ResourceImage resImage = ResourceImage::DownCast( image );
223 DALI_TEST_CHECK( resImage );
227 int UtcDaliScriptingNewImageNegative12(void)
229 TestApplication application; // Image needs application
230 // Invalid orientation-correction
232 map[ "filename" ] = "TEST_FILE";
233 map[ "orientation" ] = Vector3::ZERO;
234 // will give us a valid image
235 Image image = NewImage( map );
236 DALI_TEST_CHECK( image );
237 ResourceImage resImage = ResourceImage::DownCast( image );
238 DALI_TEST_CHECK( resImage );
242 int UtcDaliScriptingNewImageNegative13(void)
244 TestApplication application; // Image needs application
247 map[ "filename" ] = "TEST_FILE";
248 map[ "type" ] = Vector3::ZERO;
249 // will give us a valid image
250 Image image = NewImage( map );
251 DALI_TEST_CHECK( image );
252 ResourceImage resImage = ResourceImage::DownCast( image );
253 DALI_TEST_CHECK( resImage );
257 int UtcDaliScriptingNewImageNegative14(void)
261 map[ "type" ] = "INVALID";
262 Image image = NewImage( map );
263 DALI_TEST_CHECK( !image );
267 int UtcDaliScriptingNewImageNegative15(void)
269 // Invalid pixel-format
271 map[ "pixelFormat" ] = Vector3::ZERO;
272 Image image = NewImage( map );
273 DALI_TEST_CHECK( !image );
277 int UtcDaliScriptingNewImageNegative16(void)
281 map[ "pixelFormat" ] = "INVALID";
282 Image image = NewImage( map );
283 DALI_TEST_CHECK( !image );
287 int UtcDaliScriptingNewImage01P(void)
289 TestApplication application; // Image needs application
292 map[ "filename" ] = "TEST_FILE";
295 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
296 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
300 int UtcDaliScriptingNewImage04P(void)
302 TestApplication application;
305 map[ "filename" ] = "TEST_FILE";
307 // float width and height
308 map[ "width" ] = (float) 10.0f;
309 map[ "height" ] = (float) 20.0f;
310 Image image = NewImage( map );
311 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
312 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
316 int UtcDaliScriptingNewImage05P(void)
318 TestApplication application;
321 map[ "filename" ] = "TEST_FILE";
325 map[ "height" ] = 70;
326 Image image = NewImage( map );
327 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
328 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
332 int UtcDaliScriptingNewImage06P(void)
334 TestApplication application;
337 // type FrameBufferImage
338 map[ "type" ] = "FrameBufferImage";
341 map[ "height" ] = 70;
342 Image image = NewImage( map );
343 DALI_TEST_CHECK( image );
344 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
348 int UtcDaliScriptingNewImage07P(void)
350 TestApplication application;
354 map[ "type" ] = "BufferImage";
357 map[ "height" ] = 70;
358 Image image = NewImage( map );
359 DALI_TEST_CHECK( image );
360 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
361 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
365 int UtcDaliScriptingNewImage08P(void)
367 TestApplication application;
370 map[ "type" ] = "BufferImage";
373 map[ "height" ] = 99;
375 map[ "pixelFormat" ] = "";
376 const StringEnum values[] =
380 { "LA88", Pixel::LA88 },
381 { "RGB565", Pixel::RGB565 },
382 { "BGR565", Pixel::BGR565 },
383 { "RGBA4444", Pixel::RGBA4444 },
384 { "BGRA4444", Pixel::BGRA4444 },
385 { "RGBA5551", Pixel::RGBA5551 },
386 { "BGRA5551", Pixel::BGRA5551 },
387 { "RGB888", Pixel::RGB888 },
388 { "RGB8888", Pixel::RGB8888 },
389 { "BGR8888", Pixel::BGR8888 },
390 { "RGBA8888", Pixel::RGBA8888 },
391 { "BGRA8888", Pixel::BGRA8888 },
392 // BufferImage does not support compressed formats
394 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
399 int UtcDaliScriptingNewImage09P(void)
401 TestApplication application;
405 map[ "type" ] = "ResourceImage";
406 map[ "filename" ] = "TEST_FILE";
409 Image image = NewImage( map );
410 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
411 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
412 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
417 int UtcDaliScriptingNewImage10P(void)
419 TestApplication application;
422 // type FrameBufferImage, empty size gives us stage size
423 map[ "type" ] = "FrameBufferImage";
424 Image image = NewImage( map );
425 DALI_TEST_CHECK( image );
429 int UtcDaliScriptingNewActorNegative(void)
431 TestApplication application;
435 Actor handle = NewActor( Property::Map() );
436 DALI_TEST_CHECK( !handle );
439 // Map with only properties
442 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
443 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
444 Actor handle = NewActor( map );
445 DALI_TEST_CHECK( !handle );
448 // Add some signals to the map, we should have no signal connections as its not yet supported
451 map[ "type" ] = "Actor";
452 map[ "signals" ] = Property::MAP;
453 Actor handle = NewActor( map );
454 DALI_TEST_CHECK( handle );
455 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
456 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
457 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
458 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
463 int UtcDaliScriptingNewActorProperties(void)
465 TestApplication application;
468 map[ "type" ] = "Actor";
469 map[ "size" ] = Vector3::ONE;
470 map[ "position" ] = Vector3::XAXIS;
471 map[ "scale" ] = Vector3::ONE;
472 map[ "visible" ] = false;
473 map[ "color" ] = Color::MAGENTA;
474 map[ "name" ] = "MyActor";
475 map[ "colorMode" ] = "USE_PARENT_COLOR";
476 map[ "sensitive" ] = false;
477 map[ "leaveRequired" ] = true;
478 map[ "positionInheritance" ] = "DONT_INHERIT_POSITION";
479 map[ "drawMode" ] = "OVERLAY_2D";
480 map[ "inheritOrientation" ] = false;
481 map[ "inheritScale" ] = false;
483 // Default properties
485 Actor handle = NewActor( map );
486 DALI_TEST_CHECK( handle );
488 Stage::GetCurrent().Add( handle );
489 application.SendNotification();
490 application.Render();
492 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
493 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
494 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
495 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
496 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
497 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
498 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
499 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
500 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
501 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
502 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
503 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
504 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
506 Stage::GetCurrent().Remove( handle );
509 // Check Anchor point and parent origin vector3s
510 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
511 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
513 Actor handle = NewActor( map );
514 DALI_TEST_CHECK( handle );
516 Stage::GetCurrent().Add( handle );
517 application.SendNotification();
518 application.Render();
520 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
521 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
523 Stage::GetCurrent().Remove( handle );
526 // Check Anchor point and parent origin STRINGS
527 map[ "parentOrigin" ] = "TOP_LEFT";
528 map[ "anchorPoint" ] = "CENTER_LEFT";
530 Actor handle = NewActor( map );
531 DALI_TEST_CHECK( handle );
533 Stage::GetCurrent().Add( handle );
534 application.SendNotification();
535 application.Render();
537 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
538 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
540 Stage::GetCurrent().Remove( handle );
545 int UtcDaliScriptingNewAnimation(void)
547 TestApplication application;
550 map["actor"] = "Actor1";
551 map["property"] = "color";
552 map["value"] = Color::MAGENTA;
553 map["alphaFunction"] = "EASE_IN_OUT";
555 Property::Map timePeriod;
556 timePeriod["delay"] = 0.5f;
557 timePeriod["duration"] = 1.0f;
558 map["timePeriod"] = timePeriod;
560 Dali::AnimationData data;
561 Scripting::NewAnimation( map, data );
563 Actor actor = Actor::New();
564 actor.SetName("Actor1");
565 actor.SetColor(Color::CYAN);
566 Stage::GetCurrent().Add(actor);
568 Animation anim = data.CreateAnimation( actor, 0.5f );
571 application.SendNotification();
572 application.Render(0);
573 application.Render(500); // Start animation
574 application.Render(500); // Halfway thru anim
575 application.SendNotification();
576 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
578 application.Render(500); // Halfway thru anim
579 application.SendNotification();
580 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
585 int UtcDaliScriptingNewActorChildren(void)
587 TestApplication application;
590 map[ "type" ] = "Actor";
591 map[ "position" ] = Vector3::XAXIS;
593 Property::Map child1Map;
594 child1Map[ "type" ] = "CameraActor";
595 child1Map[ "position" ] = Vector3::YAXIS;
597 Property::Array childArray;
598 childArray.PushBack( child1Map );
599 map[ "actors" ] = childArray;
602 Actor handle = NewActor( map );
603 DALI_TEST_CHECK( handle );
605 Stage::GetCurrent().Add( handle );
606 application.SendNotification();
607 application.Render();
609 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
610 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
612 Actor child1 = handle.GetChildAt(0);
613 DALI_TEST_CHECK( child1 );
614 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
615 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
616 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
618 Stage::GetCurrent().Remove( handle );
623 int UtcDaliScriptingCreatePropertyMapActor(void)
625 TestApplication application;
629 Actor actor = Actor::New();
632 CreatePropertyMap( actor, map );
633 DALI_TEST_CHECK( !map.Empty() );
634 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
635 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
637 Stage::GetCurrent().Remove( actor );
642 Actor actor = Layer::New();
645 CreatePropertyMap( actor, map );
646 DALI_TEST_CHECK( !map.Empty() );
647 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
648 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
650 Stage::GetCurrent().Remove( actor );
653 // Default properties
655 Actor actor = Actor::New();
656 actor.SetSize( Vector3::ONE );
657 actor.SetPosition( Vector3::XAXIS );
658 actor.SetScale( Vector3::ZAXIS );
659 actor.SetVisible( false );
660 actor.SetColor( Color::MAGENTA );
661 actor.SetName( "MyActor" );
662 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
663 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
664 actor.SetSensitive( false );
665 actor.SetLeaveRequired( true );
666 actor.SetInheritOrientation( false );
667 actor.SetInheritScale( false );
668 actor.SetSizeModeFactor( Vector3::ONE );
670 Stage::GetCurrent().Add( actor );
671 application.SendNotification();
672 application.Render();
675 CreatePropertyMap( actor, map );
677 DALI_TEST_CHECK( !map.Empty() );
678 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
679 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
680 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
681 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
682 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
683 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
684 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
685 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
686 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
687 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
688 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
689 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
690 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
691 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
692 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
693 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
694 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
695 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
696 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
697 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
698 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
699 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
700 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
701 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
702 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
703 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
705 Stage::GetCurrent().Remove( actor );
709 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
711 // PositionInheritanceMode
712 TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
715 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
719 Actor actor = Actor::New();
720 Actor child = Layer::New();
723 Stage::GetCurrent().Add( actor );
724 application.SendNotification();
725 application.Render();
728 CreatePropertyMap( actor, map );
729 DALI_TEST_CHECK( !map.Empty() );
731 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
732 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
734 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
735 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
736 DALI_TEST_CHECK( !children.Empty() );
737 Property::Map childMap( children[0].Get< Property::Map >() );
738 DALI_TEST_CHECK( !childMap.Empty() );
739 DALI_TEST_CHECK( childMap.Find( "type" ) );
740 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
742 Stage::GetCurrent().Remove( actor );
747 int UtcDaliScriptingCreatePropertyMapImage(void)
749 TestApplication application;
755 CreatePropertyMap( image, map );
756 DALI_TEST_CHECK( map.Empty() );
761 Image image = ResourceImage::New( "MY_PATH" );
764 CreatePropertyMap( image, map );
765 DALI_TEST_CHECK( !map.Empty() );
767 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
768 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
769 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
770 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
771 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
772 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
777 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
780 CreatePropertyMap( image, map );
781 DALI_TEST_CHECK( !map.Empty() );
783 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
784 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
785 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
786 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
787 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
788 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
789 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
790 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
795 Image image = BufferImage::New( 200, 300, Pixel::A8 );
797 CreatePropertyMap( image, map );
798 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
799 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
800 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
801 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
806 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
808 CreatePropertyMap( image, map );
809 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
810 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
815 int UtcDaliScriptingGetEnumerationTemplates(void)
817 const Scripting::StringEnum myTable[] =
825 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
827 for ( unsigned int i = 0; i < myTableCount; ++i )
829 tet_printf("Checking: %s\n", myTable[ i ].string );
831 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
832 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
835 for ( unsigned int i = 0; i < myTableCount; ++i )
837 tet_printf("Checking: %d\n", myTable[ i ].value );
838 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
844 int UtcDaliScriptingGetEnumerationNameN(void)
846 const char* value = GetEnumerationName( 10, NULL, 0 );
847 DALI_TEST_CHECK( NULL == value );
849 value = GetEnumerationName( 10, NULL, 1 );
850 DALI_TEST_CHECK( NULL == value );
855 int UtcDaliScriptingGetLinearEnumerationNameN(void)
857 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
858 DALI_TEST_CHECK( NULL == value );
860 value = GetLinearEnumerationName( 10, NULL, 1 );
861 DALI_TEST_CHECK( NULL == value );
866 int UtcDaliScriptingGetEnumerationProperty(void)
869 * This test function performs the following checks:
870 * - An enum can be looked up from a Property::Value of type INTEGER.
871 * - An enum can be looked up from a Property::Value of type STRING.
872 * - An enum can NOT be looked up for other Property::Value types.
873 * - The return value is "true" if the property can be successfully converted AND it has changed.
874 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
875 * - The return value is "false" if the property can not be successfully converted.
876 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
879 // String to Enum property table to test with (equivalent to ones used within DALi).
880 const Dali::Scripting::StringEnum testTable[] = {
881 { "NONE", FaceCullingMode::NONE },
882 { "FRONT", FaceCullingMode::FRONT },
883 { "BACK", FaceCullingMode::BACK },
884 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
885 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
887 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
888 // Initialise to first element.
889 FaceCullingMode::Type result = FaceCullingMode::NONE;
890 // Set the input property value to a different value (to emulate a change).
891 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
893 // Perform the lookup.
894 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
896 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
897 // Check the property could be converted.
898 DALI_TEST_CHECK( returnValue );
900 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
902 // Now emulate a property-set with the same value. false should be returned.
903 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
905 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
906 DALI_TEST_CHECK( !returnValue );
908 // The result should remain the same.
909 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
911 // TEST: An enum can be looked up from a Property::Value of type STRING.
912 // Set the input property value to a different value (to emulate a change).
913 Property::Value propertyValueString( "BACK" );
915 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
917 DALI_TEST_CHECK( returnValue );
919 // The result should remain the same.
920 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
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 // TEST: An enum can NOT be looked up for other Property::Value types.
930 Property::Value propertyValueBoolean( true );
932 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
934 // TEST: The return value is "false" if the property can not be successfully converted.
935 // Return value should be false as Property::Value was of an unsupported type for enum properties.
936 DALI_TEST_CHECK( !returnValue );
938 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
939 // The result should remain the same.
940 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
945 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
948 * This test function performs the following checks:
949 * - An enum can be looked up from a Property::Value of type INTEGER.
950 * - An enum can be looked up from a Property::Value of type STRING.
951 * - An enum can NOT be looked up from other Property::Value types.
952 * - The return value is "true" if the property can be successfully converted AND it has changed.
953 * - The return value is "false" if the property can not be successfully converted.
954 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
956 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
957 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
958 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
959 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
960 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
961 * - 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.
962 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
963 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
966 // String to Enum property table to test with (equivalent to ones used within DALi).
967 const Dali::Scripting::StringEnum testTable[] = {
968 { "NONE", FaceCullingMode::NONE },
969 { "FRONT", FaceCullingMode::FRONT },
970 { "BACK", FaceCullingMode::BACK },
971 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
972 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
974 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
975 // Initialise to first element.
976 FaceCullingMode::Type result = FaceCullingMode::NONE;
977 // Set the input property value to a different value (to emulate a change).
978 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
980 // Perform the lookup.
981 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
983 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
984 // Check the property could be converted.
985 DALI_TEST_CHECK( returnValue );
987 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
989 // TEST: An enum can be looked up from a Property::Value of type STRING.
990 // Set the input property value to a different value (to emulate a change).
991 Property::Value propertyValueString( "BACK" );
993 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
995 DALI_TEST_CHECK( returnValue );
997 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
999 // TEST: An enum can NOT be looked up from other Property::Value types.
1000 Property::Value propertyValueVector( Vector3::ZERO );
1002 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
1004 // TEST: The return value is "false" if the property can not be successfully converted.
1005 // Return value should be false as Property::Value was of an unsupported type for enum properties.
1006 DALI_TEST_CHECK( !returnValue );
1008 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1009 // The result should remain the same.
1010 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1012 // Test PropertyArrays:
1014 // Property array of 2 integers.
1015 Property::Array propertyArrayIntegers;
1016 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1017 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1018 result = FaceCullingMode::NONE;
1020 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1022 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1023 DALI_TEST_CHECK( returnValue );
1024 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1025 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1027 // Property array of 2 strings.
1028 Property::Array propertyArrayStrings;
1029 propertyArrayStrings.PushBack( "FRONT" );
1030 propertyArrayStrings.PushBack( "BACK" );
1031 result = FaceCullingMode::NONE;
1033 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1035 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1036 DALI_TEST_CHECK( returnValue );
1037 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1038 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1040 // Property array of an int and a string.
1041 Property::Array propertyArrayMixed;
1042 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1043 propertyArrayMixed.PushBack( "BACK" );
1044 result = FaceCullingMode::NONE;
1046 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1048 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1049 DALI_TEST_CHECK( returnValue );
1050 // 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.
1051 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1053 // Property array of an int and a string.
1054 Property::Array propertyArrayInvalid;
1055 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1056 propertyArrayInvalid.PushBack( Vector3::ZERO );
1058 // Set the initial value to non-zero, so we can test it does not change.
1059 result = FaceCullingMode::FRONT_AND_BACK;
1061 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1063 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1064 DALI_TEST_CHECK( !returnValue );
1065 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1066 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1071 int UtcDaliScriptingFindEnumIndexN(void)
1073 const Scripting::StringEnum myTable[] =
1077 { "THREE", (1<<3) },
1081 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1082 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1087 int UtcDaliScriptingEnumStringToIntegerP(void)
1089 const Scripting::StringEnum myTable[] =
1093 { "THREE", (1<<3) },
1097 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1099 int integerEnum = 0;
1100 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1102 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1105 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1106 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1108 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1109 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1111 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1112 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1114 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1115 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1117 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1118 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1120 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1121 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1123 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1124 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1126 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1127 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1133 int UtcDaliScriptingEnumStringToIntegerN(void)
1135 const Scripting::StringEnum myTable[] =
1143 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1145 int integerEnum = 0;
1146 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1148 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1150 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1152 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1154 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1156 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1158 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1163 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1165 const Scripting::StringEnum myTable[] =
1172 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1174 int integerEnum = 0;
1175 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1176 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1181 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1183 const Scripting::StringEnum myTable[] =
1190 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1192 int integerEnum = 0;
1193 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1195 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1197 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1199 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1201 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1203 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );