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 PrepareResourceImage( application, 0u, 100u, Pixel::RGBA8888 );
156 Image image = NewImage( map );
157 DALI_TEST_CHECK( image );
158 ResourceImage resImage = ResourceImage::DownCast( image );
159 DALI_TEST_CHECK( resImage );
160 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
161 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
165 int UtcDaliScriptingNewImageNegative07(void)
167 TestApplication application; // Image needs application
170 map[ "filename" ] = "TEST_FILE";
172 map[ "height" ] = "Invalid";
173 // will give us a valid image
174 PrepareResourceImage( application, 10u, 0u, Pixel::RGBA8888 );
175 Image image = NewImage( map );
176 DALI_TEST_CHECK( image );
177 ResourceImage resImage = ResourceImage::DownCast( image );
178 DALI_TEST_CHECK( resImage );
179 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
180 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
184 int UtcDaliScriptingNewImageNegative08(void)
186 TestApplication application; // Image needs application
187 // Invalid fitting-mode
189 map[ "filename" ] = "TEST_FILE";
190 map[ "fittingMode" ] = Vector3::ZERO;
191 // will give us a valid image
192 Image image = NewImage( map );
193 DALI_TEST_CHECK( image );
194 ResourceImage resImage = ResourceImage::DownCast( image );
195 DALI_TEST_CHECK( resImage );
199 int UtcDaliScriptingNewImageNegative09(void)
201 TestApplication application; // Image needs application
204 map[ "filename" ] = "TEST_FILE";
205 map[ "fittingMode" ] = "INVALID";
206 // will give us a valid image
207 Image image = NewImage( map );
208 DALI_TEST_CHECK( image );
209 ResourceImage resImage = ResourceImage::DownCast( image );
210 DALI_TEST_CHECK( resImage );
214 int UtcDaliScriptingNewImageNegative10(void)
216 TestApplication application; // Image needs application
217 // Invalid scaling-mode
219 map[ "filename" ] = "TEST_FILE";
220 map[ "samplingMode" ] = Vector3::ZERO;
221 // will give us a valid image
222 Image image = NewImage( map );
223 DALI_TEST_CHECK( image );
224 ResourceImage resImage = ResourceImage::DownCast( image );
225 DALI_TEST_CHECK( resImage );
229 int UtcDaliScriptingNewImageNegative12(void)
231 TestApplication application; // Image needs application
232 // Invalid orientation-correction
234 map[ "filename" ] = "TEST_FILE";
235 map[ "orientation" ] = Vector3::ZERO;
236 // will give us a valid image
237 Image image = NewImage( map );
238 DALI_TEST_CHECK( image );
239 ResourceImage resImage = ResourceImage::DownCast( image );
240 DALI_TEST_CHECK( resImage );
244 int UtcDaliScriptingNewImageNegative13(void)
246 TestApplication application; // Image needs application
249 map[ "filename" ] = "TEST_FILE";
250 map[ "type" ] = Vector3::ZERO;
251 // will give us a valid image
252 Image image = NewImage( map );
253 DALI_TEST_CHECK( image );
254 ResourceImage resImage = ResourceImage::DownCast( image );
255 DALI_TEST_CHECK( resImage );
259 int UtcDaliScriptingNewImageNegative14(void)
263 map[ "type" ] = "INVALID";
264 Image image = NewImage( map );
265 DALI_TEST_CHECK( !image );
269 int UtcDaliScriptingNewImageNegative15(void)
271 // Invalid pixel-format
273 map[ "pixelFormat" ] = Vector3::ZERO;
274 Image image = NewImage( map );
275 DALI_TEST_CHECK( !image );
279 int UtcDaliScriptingNewImageNegative16(void)
283 map[ "pixelFormat" ] = "INVALID";
284 Image image = NewImage( map );
285 DALI_TEST_CHECK( !image );
289 int UtcDaliScriptingNewImage01P(void)
291 TestApplication application; // Image needs application
294 map[ "filename" ] = "TEST_FILE";
297 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
298 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
302 int UtcDaliScriptingNewImage04P(void)
304 TestApplication application;
307 map[ "filename" ] = "TEST_FILE";
309 // float width and height
310 map[ "width" ] = (float) 10.0f;
311 map[ "height" ] = (float) 20.0f;
312 PrepareResourceImage( application, 10u, 20u, Pixel::RGBA8888 );
313 Image image = NewImage( map );
314 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
315 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
319 int UtcDaliScriptingNewImage05P(void)
321 TestApplication application;
324 map[ "filename" ] = "TEST_FILE";
328 map[ "height" ] = 70;
329 PrepareResourceImage( application, 50u, 70u, Pixel::RGBA8888 );
330 Image image = NewImage( map );
331 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
332 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
336 int UtcDaliScriptingNewImage06P(void)
338 TestApplication application;
341 // type FrameBufferImage
342 map[ "type" ] = "FrameBufferImage";
345 map[ "height" ] = 70;
346 Image image = NewImage( map );
347 DALI_TEST_CHECK( image );
348 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
352 int UtcDaliScriptingNewImage07P(void)
354 TestApplication application;
358 map[ "type" ] = "BufferImage";
361 map[ "height" ] = 70;
362 Image image = NewImage( map );
363 DALI_TEST_CHECK( image );
364 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
365 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
369 int UtcDaliScriptingNewImage08P(void)
371 TestApplication application;
374 map[ "type" ] = "BufferImage";
377 map[ "height" ] = 99;
379 map[ "pixelFormat" ] = "";
380 const StringEnum values[] =
384 { "LA88", Pixel::LA88 },
385 { "RGB565", Pixel::RGB565 },
386 { "BGR565", Pixel::BGR565 },
387 { "RGBA4444", Pixel::RGBA4444 },
388 { "BGRA4444", Pixel::BGRA4444 },
389 { "RGBA5551", Pixel::RGBA5551 },
390 { "BGRA5551", Pixel::BGRA5551 },
391 { "RGB888", Pixel::RGB888 },
392 { "RGB8888", Pixel::RGB8888 },
393 { "BGR8888", Pixel::BGR8888 },
394 { "RGBA8888", Pixel::RGBA8888 },
395 { "BGRA8888", Pixel::BGRA8888 },
396 // BufferImage does not support compressed formats
398 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
403 int UtcDaliScriptingNewImage09P(void)
405 TestApplication application;
409 map[ "type" ] = "ResourceImage";
410 map[ "filename" ] = "TEST_FILE";
413 Image image = NewImage( map );
414 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
415 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
416 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
421 int UtcDaliScriptingNewImage10P(void)
423 TestApplication application;
426 // type FrameBufferImage, empty size gives us stage size
427 map[ "type" ] = "FrameBufferImage";
428 Image image = NewImage( map );
429 DALI_TEST_CHECK( image );
433 int UtcDaliScriptingNewActorNegative(void)
435 TestApplication application;
439 Actor handle = NewActor( Property::Map() );
440 DALI_TEST_CHECK( !handle );
443 // Map with only properties
446 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
447 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
448 Actor handle = NewActor( map );
449 DALI_TEST_CHECK( !handle );
452 // Add some signals to the map, we should have no signal connections as its not yet supported
455 map[ "type" ] = "Actor";
456 map[ "signals" ] = Property::MAP;
457 Actor handle = NewActor( map );
458 DALI_TEST_CHECK( handle );
459 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
460 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
461 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
462 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
467 int UtcDaliScriptingNewActorProperties(void)
469 TestApplication application;
472 map[ "type" ] = "Actor";
473 map[ "size" ] = Vector3::ONE;
474 map[ "position" ] = Vector3::XAXIS;
475 map[ "scale" ] = Vector3::ONE;
476 map[ "visible" ] = false;
477 map[ "color" ] = Color::MAGENTA;
478 map[ "name" ] = "MyActor";
479 map[ "colorMode" ] = "USE_PARENT_COLOR";
480 map[ "sensitive" ] = false;
481 map[ "leaveRequired" ] = true;
482 map[ "positionInheritance" ] = "DONT_INHERIT_POSITION";
483 map[ "drawMode" ] = "OVERLAY_2D";
484 map[ "inheritOrientation" ] = false;
485 map[ "inheritScale" ] = false;
487 // Default properties
489 Actor handle = NewActor( map );
490 DALI_TEST_CHECK( handle );
492 Stage::GetCurrent().Add( handle );
493 application.SendNotification();
494 application.Render();
496 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
497 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
498 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
499 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
500 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
501 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
502 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
503 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
504 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
505 DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
506 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
507 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
508 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
510 Stage::GetCurrent().Remove( handle );
513 // Check Anchor point and parent origin vector3s
514 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
515 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
517 Actor handle = NewActor( map );
518 DALI_TEST_CHECK( handle );
520 Stage::GetCurrent().Add( handle );
521 application.SendNotification();
522 application.Render();
524 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
525 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
527 Stage::GetCurrent().Remove( handle );
530 // Check Anchor point and parent origin STRINGS
531 map[ "parentOrigin" ] = "TOP_LEFT";
532 map[ "anchorPoint" ] = "CENTER_LEFT";
534 Actor handle = NewActor( map );
535 DALI_TEST_CHECK( handle );
537 Stage::GetCurrent().Add( handle );
538 application.SendNotification();
539 application.Render();
541 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
542 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
544 Stage::GetCurrent().Remove( handle );
549 int UtcDaliScriptingNewAnimation(void)
551 TestApplication application;
554 map["actor"] = "Actor1";
555 map["property"] = "color";
556 map["value"] = Color::MAGENTA;
557 map["alphaFunction"] = "EASE_IN_OUT";
559 Property::Map timePeriod;
560 timePeriod["delay"] = 0.5f;
561 timePeriod["duration"] = 1.0f;
562 map["timePeriod"] = timePeriod;
564 Dali::AnimationData data;
565 Scripting::NewAnimation( map, data );
567 Actor actor = Actor::New();
568 actor.SetName("Actor1");
569 actor.SetColor(Color::CYAN);
570 Stage::GetCurrent().Add(actor);
572 Animation anim = data.CreateAnimation( actor, 0.5f );
575 application.SendNotification();
576 application.Render(0);
577 application.Render(500); // Start animation
578 application.Render(500); // Halfway thru anim
579 application.SendNotification();
580 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
582 application.Render(500); // Halfway thru anim
583 application.SendNotification();
584 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
589 int UtcDaliScriptingNewActorChildren(void)
591 TestApplication application;
594 map[ "type" ] = "Actor";
595 map[ "position" ] = Vector3::XAXIS;
597 Property::Map child1Map;
598 child1Map[ "type" ] = "CameraActor";
599 child1Map[ "position" ] = Vector3::YAXIS;
601 Property::Array childArray;
602 childArray.PushBack( child1Map );
603 map[ "actors" ] = childArray;
606 Actor handle = NewActor( map );
607 DALI_TEST_CHECK( handle );
609 Stage::GetCurrent().Add( handle );
610 application.SendNotification();
611 application.Render();
613 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
614 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
616 Actor child1 = handle.GetChildAt(0);
617 DALI_TEST_CHECK( child1 );
618 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
619 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
620 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
622 Stage::GetCurrent().Remove( handle );
627 int UtcDaliScriptingCreatePropertyMapActor(void)
629 TestApplication application;
633 Actor actor = Actor::New();
636 CreatePropertyMap( actor, map );
637 DALI_TEST_CHECK( !map.Empty() );
638 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
639 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
641 Stage::GetCurrent().Remove( actor );
646 Actor actor = Layer::New();
649 CreatePropertyMap( actor, map );
650 DALI_TEST_CHECK( !map.Empty() );
651 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
652 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
654 Stage::GetCurrent().Remove( actor );
657 // Default properties
659 Actor actor = Actor::New();
660 actor.SetSize( Vector3::ONE );
661 actor.SetPosition( Vector3::XAXIS );
662 actor.SetScale( Vector3::ZAXIS );
663 actor.SetVisible( false );
664 actor.SetColor( Color::MAGENTA );
665 actor.SetName( "MyActor" );
666 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
667 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
668 actor.SetSensitive( false );
669 actor.SetLeaveRequired( true );
670 actor.SetInheritOrientation( false );
671 actor.SetInheritScale( false );
672 actor.SetSizeModeFactor( Vector3::ONE );
674 Stage::GetCurrent().Add( actor );
675 application.SendNotification();
676 application.Render();
679 CreatePropertyMap( actor, map );
681 DALI_TEST_CHECK( !map.Empty() );
682 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
683 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
684 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
685 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
686 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
687 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
688 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
689 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
690 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
691 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
692 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
693 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
694 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
695 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
696 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
697 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
698 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
699 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
700 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
701 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
702 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
703 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
704 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
705 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
706 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
707 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
709 Stage::GetCurrent().Remove( actor );
713 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
715 // PositionInheritanceMode
716 TestEnumStrings< PositionInheritanceMode >( "positionInheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode );
719 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
723 Actor actor = Actor::New();
724 Actor child = Layer::New();
727 Stage::GetCurrent().Add( actor );
728 application.SendNotification();
729 application.Render();
732 CreatePropertyMap( actor, map );
733 DALI_TEST_CHECK( !map.Empty() );
735 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
736 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
738 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
739 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
740 DALI_TEST_CHECK( !children.Empty() );
741 Property::Map childMap( children[0].Get< Property::Map >() );
742 DALI_TEST_CHECK( !childMap.Empty() );
743 DALI_TEST_CHECK( childMap.Find( "type" ) );
744 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
746 Stage::GetCurrent().Remove( actor );
751 int UtcDaliScriptingCreatePropertyMapImage(void)
753 TestApplication application;
759 CreatePropertyMap( image, map );
760 DALI_TEST_CHECK( map.Empty() );
765 Image image = ResourceImage::New( "MY_PATH" );
768 CreatePropertyMap( image, map );
769 DALI_TEST_CHECK( !map.Empty() );
771 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
772 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
773 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
774 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
775 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
776 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
781 PrepareResourceImage( application, 300, 400, Pixel::RGBA8888 );
782 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
785 CreatePropertyMap( image, map );
786 DALI_TEST_CHECK( !map.Empty() );
788 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
789 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
790 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
791 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
792 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
793 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
794 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
795 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
800 Image image = BufferImage::New( 200, 300, Pixel::A8 );
802 CreatePropertyMap( image, map );
803 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
804 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
805 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
806 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
811 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
813 CreatePropertyMap( image, map );
814 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
815 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
820 int UtcDaliScriptingGetEnumerationTemplates(void)
822 const Scripting::StringEnum myTable[] =
830 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
832 for ( unsigned int i = 0; i < myTableCount; ++i )
834 tet_printf("Checking: %s\n", myTable[ i ].string );
836 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
837 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
840 for ( unsigned int i = 0; i < myTableCount; ++i )
842 tet_printf("Checking: %d\n", myTable[ i ].value );
843 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
849 int UtcDaliScriptingGetEnumerationNameN(void)
851 const char* value = GetEnumerationName( 10, NULL, 0 );
852 DALI_TEST_CHECK( NULL == value );
854 value = GetEnumerationName( 10, NULL, 1 );
855 DALI_TEST_CHECK( NULL == value );
860 int UtcDaliScriptingGetLinearEnumerationNameN(void)
862 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
863 DALI_TEST_CHECK( NULL == value );
865 value = GetLinearEnumerationName( 10, NULL, 1 );
866 DALI_TEST_CHECK( NULL == value );
871 int UtcDaliScriptingGetEnumerationProperty(void)
874 * This test function performs the following checks:
875 * - An enum can be looked up from a Property::Value of type INTEGER.
876 * - An enum can be looked up from a Property::Value of type STRING.
877 * - An enum can NOT be looked up for other Property::Value types.
878 * - The return value is "true" if the property can be successfully converted AND it has changed.
879 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
880 * - The return value is "false" if the property can not be successfully converted.
881 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
884 // String to Enum property table to test with (equivalent to ones used within DALi).
885 const Dali::Scripting::StringEnum testTable[] = {
886 { "NONE", FaceCullingMode::NONE },
887 { "FRONT", FaceCullingMode::FRONT },
888 { "BACK", FaceCullingMode::BACK },
889 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
890 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
892 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
893 // Initialise to first element.
894 FaceCullingMode::Type result = FaceCullingMode::NONE;
895 // Set the input property value to a different value (to emulate a change).
896 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
898 // Perform the lookup.
899 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
901 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
902 // Check the property could be converted.
903 DALI_TEST_CHECK( returnValue );
905 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
907 // Now emulate a property-set with the same value. false should be returned.
908 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
910 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
911 DALI_TEST_CHECK( !returnValue );
913 // The result should remain the same.
914 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
916 // TEST: An enum can be looked up from a Property::Value of type STRING.
917 // Set the input property value to a different value (to emulate a change).
918 Property::Value propertyValueString( "BACK" );
920 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
922 DALI_TEST_CHECK( returnValue );
924 // The result should remain the same.
925 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
927 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
929 DALI_TEST_CHECK( !returnValue );
931 // The result should remain the same.
932 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
934 // TEST: An enum can NOT be looked up for other Property::Value types.
935 Property::Value propertyValueBoolean( true );
937 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
939 // TEST: The return value is "false" if the property can not be successfully converted.
940 // Return value should be false as Property::Value was of an unsupported type for enum properties.
941 DALI_TEST_CHECK( !returnValue );
943 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
944 // The result should remain the same.
945 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
950 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
953 * This test function performs the following checks:
954 * - An enum can be looked up from a Property::Value of type INTEGER.
955 * - An enum can be looked up from a Property::Value of type STRING.
956 * - An enum can NOT be looked up from other Property::Value types.
957 * - The return value is "true" if the property can be successfully converted AND it has changed.
958 * - The return value is "false" if the property can not be successfully converted.
959 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
961 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
962 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
963 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
964 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
965 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
966 * - 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.
967 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
968 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
971 // String to Enum property table to test with (equivalent to ones used within DALi).
972 const Dali::Scripting::StringEnum testTable[] = {
973 { "NONE", FaceCullingMode::NONE },
974 { "FRONT", FaceCullingMode::FRONT },
975 { "BACK", FaceCullingMode::BACK },
976 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
977 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
979 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
980 // Initialise to first element.
981 FaceCullingMode::Type result = FaceCullingMode::NONE;
982 // Set the input property value to a different value (to emulate a change).
983 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
985 // Perform the lookup.
986 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
988 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
989 // Check the property could be converted.
990 DALI_TEST_CHECK( returnValue );
992 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
994 // TEST: An enum can be looked up from a Property::Value of type STRING.
995 // Set the input property value to a different value (to emulate a change).
996 Property::Value propertyValueString( "BACK" );
998 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
1000 DALI_TEST_CHECK( returnValue );
1002 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1004 // TEST: An enum can NOT be looked up from other Property::Value types.
1005 Property::Value propertyValueVector( Vector3::ZERO );
1007 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
1009 // TEST: The return value is "false" if the property can not be successfully converted.
1010 // Return value should be false as Property::Value was of an unsupported type for enum properties.
1011 DALI_TEST_CHECK( !returnValue );
1013 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1014 // The result should remain the same.
1015 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1017 // Test PropertyArrays:
1019 // Property array of 2 integers.
1020 Property::Array propertyArrayIntegers;
1021 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1022 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1023 result = FaceCullingMode::NONE;
1025 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1027 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1028 DALI_TEST_CHECK( returnValue );
1029 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1030 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1032 // Property array of 2 strings.
1033 Property::Array propertyArrayStrings;
1034 propertyArrayStrings.PushBack( "FRONT" );
1035 propertyArrayStrings.PushBack( "BACK" );
1036 result = FaceCullingMode::NONE;
1038 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1040 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1041 DALI_TEST_CHECK( returnValue );
1042 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1043 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1045 // Property array of an int and a string.
1046 Property::Array propertyArrayMixed;
1047 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1048 propertyArrayMixed.PushBack( "BACK" );
1049 result = FaceCullingMode::NONE;
1051 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1053 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1054 DALI_TEST_CHECK( returnValue );
1055 // 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.
1056 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1058 // Property array of an int and a string.
1059 Property::Array propertyArrayInvalid;
1060 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1061 propertyArrayInvalid.PushBack( Vector3::ZERO );
1063 // Set the initial value to non-zero, so we can test it does not change.
1064 result = FaceCullingMode::FRONT_AND_BACK;
1066 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1068 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1069 DALI_TEST_CHECK( !returnValue );
1070 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1071 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1076 int UtcDaliScriptingFindEnumIndexN(void)
1078 const Scripting::StringEnum myTable[] =
1082 { "THREE", (1<<3) },
1086 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1087 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1092 int UtcDaliScriptingEnumStringToIntegerP(void)
1094 const Scripting::StringEnum myTable[] =
1098 { "THREE", (1<<3) },
1102 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1104 int integerEnum = 0;
1105 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1107 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1110 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1111 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1113 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1114 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1116 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1117 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1119 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1120 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1122 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1123 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1125 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1126 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1128 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1129 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1131 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1132 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1138 int UtcDaliScriptingEnumStringToIntegerN(void)
1140 const Scripting::StringEnum myTable[] =
1148 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1150 int integerEnum = 0;
1151 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1153 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1155 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1157 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1159 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1161 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1163 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1168 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1170 const Scripting::StringEnum myTable[] =
1177 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1179 int integerEnum = 0;
1180 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1181 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1186 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1188 const Scripting::StringEnum myTable[] =
1195 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1197 int integerEnum = 0;
1198 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1200 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1202 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1204 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1206 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1208 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );