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 DRAW_MODE_VALUES[] =
42 { "NORMAL", DrawMode::NORMAL },
43 { "OVERLAY_2D", DrawMode::OVERLAY_2D }
45 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( DRAW_MODE_VALUES[0] );
48 ////////////////////////////////////////////////////////////////////////////////
49 // Helpers for string to enum comparisons for Image and Image loading parameters
50 ////////////////////////////////////////////////////////////////////////////////
53 * Template to check enumerations of type T, with a class of type X
55 template< typename T, typename X >
57 Property::Map& map, // The map used to create instance of type X
58 const char * const keyName, // the name of the key to iterate through
59 const StringEnum* values, // An array of string values
60 unsigned int num, // Number of items in the array
61 T ( X::*method )() const, // The member method of X to call to get the enum
62 X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X
65 // get the key reference so we can change its value
66 Property::Value* value = map.Find( keyName );
67 for ( unsigned int i = 0; i < num; ++i )
69 *value = values[i].string;
70 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
71 X instance = creator( map );
72 DALI_TEST_EQUALS( values[i].value, (int)( instance.*method )(), TEST_LOCATION );
76 /// Helper method to create BufferImage using property
77 BufferImage NewBufferImage( const Property::Value& map )
79 BufferImage image = BufferImage::DownCast( NewImage( map ) );
83 //////////////////////////////////////////////////////////////////////////////
84 // Helpers for string to enum comparisons for Actor to Property::Map
85 //////////////////////////////////////////////////////////////////////////////
88 * Template to check enumerations of type T
90 template< typename T >
92 const char * const keyName, // The name of the key to check
93 TestApplication& application, // Reference to the application class
94 const StringEnum* values, // An array of string values
95 unsigned int num, // Number of items in the array
96 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
99 for ( unsigned int i = 0; i < num; ++i )
101 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
103 Actor actor = Actor::New();
104 (actor.*method)( ( T ) values[i].value );
106 Stage::GetCurrent().Add( actor );
107 application.SendNotification();
108 application.Render();
111 CreatePropertyMap( actor, map );
113 DALI_TEST_CHECK( 0 < map.Count() );
114 DALI_TEST_CHECK( NULL != map.Find( keyName ) );
115 DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION );
117 Stage::GetCurrent().Remove( actor );
121 //////////////////////////////////////////////////////////////////////////////
126 int UtcDaliScriptingNewImageNegative01(void)
130 map[ "filename" ] = Vector3::ZERO;
131 // will give us an empty image handle
132 Image image = NewImage( map );
133 DALI_TEST_CHECK( !image );
137 int UtcDaliScriptingNewImageNegative06(void)
139 TestApplication application; // Image needs application
140 // Invalid width and height
142 map[ "filename" ] = "TEST_FILE";
143 map[ "width" ] = "Invalid";
144 map[ "height" ] = 100;
145 // will give us a valid image
146 PrepareResourceImage( application, 0u, 100u, Pixel::RGBA8888 );
147 Image image = NewImage( map );
148 DALI_TEST_CHECK( image );
149 ResourceImage resImage = ResourceImage::DownCast( image );
150 DALI_TEST_CHECK( resImage );
151 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
152 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
156 int UtcDaliScriptingNewImageNegative07(void)
158 TestApplication application; // Image needs application
161 map[ "filename" ] = "TEST_FILE";
163 map[ "height" ] = "Invalid";
164 // will give us a valid image
165 PrepareResourceImage( application, 10u, 0u, Pixel::RGBA8888 );
166 Image image = NewImage( map );
167 DALI_TEST_CHECK( image );
168 ResourceImage resImage = ResourceImage::DownCast( image );
169 DALI_TEST_CHECK( resImage );
170 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
171 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
175 int UtcDaliScriptingNewImageNegative08(void)
177 TestApplication application; // Image needs application
178 // Invalid fitting-mode
180 map[ "filename" ] = "TEST_FILE";
181 map[ "fittingMode" ] = Vector3::ZERO;
182 // will give us a valid image
183 Image image = NewImage( map );
184 DALI_TEST_CHECK( image );
185 ResourceImage resImage = ResourceImage::DownCast( image );
186 DALI_TEST_CHECK( resImage );
190 int UtcDaliScriptingNewImageNegative09(void)
192 TestApplication application; // Image needs application
195 map[ "filename" ] = "TEST_FILE";
196 map[ "fittingMode" ] = "INVALID";
197 // will give us a valid image
198 Image image = NewImage( map );
199 DALI_TEST_CHECK( image );
200 ResourceImage resImage = ResourceImage::DownCast( image );
201 DALI_TEST_CHECK( resImage );
205 int UtcDaliScriptingNewImageNegative10(void)
207 TestApplication application; // Image needs application
208 // Invalid scaling-mode
210 map[ "filename" ] = "TEST_FILE";
211 map[ "samplingMode" ] = Vector3::ZERO;
212 // will give us a valid image
213 Image image = NewImage( map );
214 DALI_TEST_CHECK( image );
215 ResourceImage resImage = ResourceImage::DownCast( image );
216 DALI_TEST_CHECK( resImage );
220 int UtcDaliScriptingNewImageNegative12(void)
222 TestApplication application; // Image needs application
223 // Invalid orientation-correction
225 map[ "filename" ] = "TEST_FILE";
226 map[ "orientation" ] = Vector3::ZERO;
227 // will give us a valid image
228 Image image = NewImage( map );
229 DALI_TEST_CHECK( image );
230 ResourceImage resImage = ResourceImage::DownCast( image );
231 DALI_TEST_CHECK( resImage );
235 int UtcDaliScriptingNewImageNegative13(void)
237 TestApplication application; // Image needs application
240 map[ "filename" ] = "TEST_FILE";
241 map[ "type" ] = Vector3::ZERO;
242 // will give us a valid image
243 Image image = NewImage( map );
244 DALI_TEST_CHECK( image );
245 ResourceImage resImage = ResourceImage::DownCast( image );
246 DALI_TEST_CHECK( resImage );
250 int UtcDaliScriptingNewImageNegative14(void)
254 map[ "type" ] = "INVALID";
255 Image image = NewImage( map );
256 DALI_TEST_CHECK( !image );
260 int UtcDaliScriptingNewImageNegative15(void)
262 // Invalid pixel-format
264 map[ "pixelFormat" ] = Vector3::ZERO;
265 Image image = NewImage( map );
266 DALI_TEST_CHECK( !image );
270 int UtcDaliScriptingNewImageNegative16(void)
274 map[ "pixelFormat" ] = "INVALID";
275 Image image = NewImage( map );
276 DALI_TEST_CHECK( !image );
280 int UtcDaliScriptingNewImage01P(void)
282 TestApplication application; // Image needs application
285 map[ "filename" ] = "TEST_FILE";
288 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
289 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
293 int UtcDaliScriptingNewImage04P(void)
295 TestApplication application;
298 map[ "filename" ] = "TEST_FILE";
300 // float width and height
301 map[ "width" ] = (float) 10.0f;
302 map[ "height" ] = (float) 20.0f;
303 PrepareResourceImage( application, 10u, 20u, Pixel::RGBA8888 );
304 Image image = NewImage( map );
305 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
306 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
310 int UtcDaliScriptingNewImage05P(void)
312 TestApplication application;
315 map[ "filename" ] = "TEST_FILE";
319 map[ "height" ] = 70;
320 PrepareResourceImage( application, 50u, 70u, Pixel::RGBA8888 );
321 Image image = NewImage( map );
322 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
323 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
327 int UtcDaliScriptingNewImage06P(void)
329 TestApplication application;
332 // type FrameBufferImage
333 map[ "type" ] = "FrameBufferImage";
336 map[ "height" ] = 70;
337 Image image = NewImage( map );
338 DALI_TEST_CHECK( image );
339 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
343 int UtcDaliScriptingNewImage07P(void)
345 TestApplication application;
349 map[ "type" ] = "BufferImage";
352 map[ "height" ] = 70;
353 Image image = NewImage( map );
354 DALI_TEST_CHECK( image );
355 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
356 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
360 int UtcDaliScriptingNewImage08P(void)
362 TestApplication application;
365 map[ "type" ] = "BufferImage";
368 map[ "height" ] = 99;
370 map[ "pixelFormat" ] = "";
371 const StringEnum values[] =
375 { "LA88", Pixel::LA88 },
376 { "RGB565", Pixel::RGB565 },
377 { "BGR565", Pixel::BGR565 },
378 { "RGBA4444", Pixel::RGBA4444 },
379 { "BGRA4444", Pixel::BGRA4444 },
380 { "RGBA5551", Pixel::RGBA5551 },
381 { "BGRA5551", Pixel::BGRA5551 },
382 { "RGB888", Pixel::RGB888 },
383 { "RGB8888", Pixel::RGB8888 },
384 { "BGR8888", Pixel::BGR8888 },
385 { "RGBA8888", Pixel::RGBA8888 },
386 { "BGRA8888", Pixel::BGRA8888 },
387 // BufferImage does not support compressed formats
389 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
394 int UtcDaliScriptingNewImage09P(void)
396 TestApplication application;
400 map[ "type" ] = "ResourceImage";
401 map[ "filename" ] = "TEST_FILE";
404 Image image = NewImage( map );
405 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
406 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
407 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
412 int UtcDaliScriptingNewImage10P(void)
414 TestApplication application;
417 // type FrameBufferImage, empty size gives us stage size
418 map[ "type" ] = "FrameBufferImage";
419 Image image = NewImage( map );
420 DALI_TEST_CHECK( image );
424 int UtcDaliScriptingNewActorNegative(void)
426 TestApplication application;
430 Actor handle = NewActor( Property::Map() );
431 DALI_TEST_CHECK( !handle );
434 // Map with only properties
437 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
438 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
439 Actor handle = NewActor( map );
440 DALI_TEST_CHECK( !handle );
443 // Add some signals to the map, we should have no signal connections as its not yet supported
446 map[ "type" ] = "Actor";
447 map[ "signals" ] = Property::MAP;
448 Actor handle = NewActor( map );
449 DALI_TEST_CHECK( handle );
450 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
451 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
452 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
453 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
458 int UtcDaliScriptingNewActorProperties(void)
460 TestApplication application;
463 map[ "type" ] = "Actor";
464 map[ "size" ] = Vector3::ONE;
465 map[ "position" ] = Vector3::XAXIS;
466 map[ "scale" ] = Vector3::ONE;
467 map[ "visible" ] = false;
468 map[ "color" ] = Color::MAGENTA;
469 map[ "name" ] = "MyActor";
470 map[ "colorMode" ] = "USE_PARENT_COLOR";
471 map[ "sensitive" ] = false;
472 map[ "leaveRequired" ] = true;
473 map[ "drawMode" ] = "OVERLAY_2D";
474 map[ "inheritOrientation" ] = false;
475 map[ "inheritScale" ] = false;
477 // Default properties
479 Actor handle = NewActor( map );
480 DALI_TEST_CHECK( handle );
482 Stage::GetCurrent().Add( handle );
483 application.SendNotification();
484 application.Render();
486 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
487 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
488 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
489 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
490 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
491 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
492 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
493 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
494 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
495 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
496 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
497 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
499 Stage::GetCurrent().Remove( handle );
502 // Check Anchor point and parent origin vector3s
503 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
504 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
506 Actor handle = NewActor( map );
507 DALI_TEST_CHECK( handle );
509 Stage::GetCurrent().Add( handle );
510 application.SendNotification();
511 application.Render();
513 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
514 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
516 Stage::GetCurrent().Remove( handle );
519 // Check Anchor point and parent origin STRINGS
520 map[ "parentOrigin" ] = "TOP_LEFT";
521 map[ "anchorPoint" ] = "CENTER_LEFT";
523 Actor handle = NewActor( map );
524 DALI_TEST_CHECK( handle );
526 Stage::GetCurrent().Add( handle );
527 application.SendNotification();
528 application.Render();
530 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
531 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
533 Stage::GetCurrent().Remove( handle );
538 int UtcDaliScriptingNewAnimation(void)
540 TestApplication application;
543 map["actor"] = "Actor1";
544 map["property"] = "color";
545 map["value"] = Color::MAGENTA;
546 map["alphaFunction"] = "EASE_IN_OUT";
548 Property::Map timePeriod;
549 timePeriod["delay"] = 0.5f;
550 timePeriod["duration"] = 1.0f;
551 map["timePeriod"] = timePeriod;
553 Dali::AnimationData data;
554 Scripting::NewAnimation( map, data );
556 Actor actor = Actor::New();
557 actor.SetName("Actor1");
558 actor.SetColor(Color::CYAN);
559 Stage::GetCurrent().Add(actor);
561 Animation anim = data.CreateAnimation( actor, 0.5f );
564 application.SendNotification();
565 application.Render(0);
566 application.Render(500); // Start animation
567 application.Render(500); // Halfway thru anim
568 application.SendNotification();
569 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
571 application.Render(500); // Halfway thru anim
572 application.SendNotification();
573 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
578 int UtcDaliScriptingNewActorChildren(void)
580 TestApplication application;
583 map[ "type" ] = "Actor";
584 map[ "position" ] = Vector3::XAXIS;
586 Property::Map child1Map;
587 child1Map[ "type" ] = "CameraActor";
588 child1Map[ "position" ] = Vector3::YAXIS;
590 Property::Array childArray;
591 childArray.PushBack( child1Map );
592 map[ "actors" ] = childArray;
595 Actor handle = NewActor( map );
596 DALI_TEST_CHECK( handle );
598 Stage::GetCurrent().Add( handle );
599 application.SendNotification();
600 application.Render();
602 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
603 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
605 Actor child1 = handle.GetChildAt(0);
606 DALI_TEST_CHECK( child1 );
607 DALI_TEST_CHECK( CameraActor::DownCast( child1 ) );
608 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
609 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
611 Stage::GetCurrent().Remove( handle );
616 int UtcDaliScriptingCreatePropertyMapActor(void)
618 TestApplication application;
622 Actor actor = Actor::New();
625 CreatePropertyMap( actor, map );
626 DALI_TEST_CHECK( !map.Empty() );
627 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
628 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
630 Stage::GetCurrent().Remove( actor );
635 Actor actor = Layer::New();
638 CreatePropertyMap( actor, map );
639 DALI_TEST_CHECK( !map.Empty() );
640 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
641 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
643 Stage::GetCurrent().Remove( actor );
646 // Default properties
648 Actor actor = Actor::New();
649 actor.SetSize( Vector3::ONE );
650 actor.SetPosition( Vector3::XAXIS );
651 actor.SetScale( Vector3::ZAXIS );
652 actor.SetVisible( false );
653 actor.SetColor( Color::MAGENTA );
654 actor.SetName( "MyActor" );
655 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
656 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
657 actor.SetSensitive( false );
658 actor.SetLeaveRequired( true );
659 actor.SetInheritOrientation( false );
660 actor.SetInheritScale( false );
661 actor.SetSizeModeFactor( Vector3::ONE );
663 Stage::GetCurrent().Add( actor );
664 application.SendNotification();
665 application.Render();
668 CreatePropertyMap( actor, map );
670 DALI_TEST_CHECK( !map.Empty() );
671 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
672 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
673 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
674 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
675 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
676 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
677 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
678 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
679 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
680 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
681 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
682 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
683 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
684 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
685 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
686 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
687 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
688 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
689 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
690 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
691 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
692 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
693 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
694 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
695 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
696 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
698 Stage::GetCurrent().Remove( actor );
702 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
705 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
709 Actor actor = Actor::New();
710 Actor child = Layer::New();
713 Stage::GetCurrent().Add( actor );
714 application.SendNotification();
715 application.Render();
718 CreatePropertyMap( actor, map );
719 DALI_TEST_CHECK( !map.Empty() );
721 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
722 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
724 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
725 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
726 DALI_TEST_CHECK( !children.Empty() );
727 Property::Map childMap( children[0].Get< Property::Map >() );
728 DALI_TEST_CHECK( !childMap.Empty() );
729 DALI_TEST_CHECK( childMap.Find( "type" ) );
730 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
732 Stage::GetCurrent().Remove( actor );
737 int UtcDaliScriptingCreatePropertyMapImage(void)
739 TestApplication application;
745 CreatePropertyMap( image, map );
746 DALI_TEST_CHECK( map.Empty() );
751 Image image = ResourceImage::New( "MY_PATH" );
754 CreatePropertyMap( image, map );
755 DALI_TEST_CHECK( !map.Empty() );
757 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
758 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
759 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
760 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
761 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
762 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
767 PrepareResourceImage( application, 300, 400, Pixel::RGBA8888 );
768 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
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_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
780 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
781 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
786 Image image = BufferImage::New( 200, 300, Pixel::A8 );
788 CreatePropertyMap( image, map );
789 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
790 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
791 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
792 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
797 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
799 CreatePropertyMap( image, map );
800 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
801 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
806 int UtcDaliScriptingGetEnumerationTemplates(void)
808 const Scripting::StringEnum myTable[] =
816 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
818 for ( unsigned int i = 0; i < myTableCount; ++i )
820 tet_printf("Checking: %s\n", myTable[ i ].string );
822 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
823 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
826 for ( unsigned int i = 0; i < myTableCount; ++i )
828 tet_printf("Checking: %d\n", myTable[ i ].value );
829 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
835 int UtcDaliScriptingGetEnumerationNameN(void)
837 const char* value = GetEnumerationName( 10, NULL, 0 );
838 DALI_TEST_CHECK( NULL == value );
840 value = GetEnumerationName( 10, NULL, 1 );
841 DALI_TEST_CHECK( NULL == value );
846 int UtcDaliScriptingGetLinearEnumerationNameN(void)
848 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
849 DALI_TEST_CHECK( NULL == value );
851 value = GetLinearEnumerationName( 10, NULL, 1 );
852 DALI_TEST_CHECK( NULL == value );
857 int UtcDaliScriptingGetEnumerationProperty(void)
860 * This test function performs the following checks:
861 * - An enum can be looked up from a Property::Value of type INTEGER.
862 * - An enum can be looked up from a Property::Value of type STRING.
863 * - An enum can NOT be looked up for other Property::Value types.
864 * - The return value is "true" if the property can be successfully converted AND it has changed.
865 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
866 * - The return value is "false" if the property can not be successfully converted.
867 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
870 // String to Enum property table to test with (equivalent to ones used within DALi).
871 const Dali::Scripting::StringEnum testTable[] = {
872 { "NONE", FaceCullingMode::NONE },
873 { "FRONT", FaceCullingMode::FRONT },
874 { "BACK", FaceCullingMode::BACK },
875 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
876 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
878 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
879 // Initialise to first element.
880 FaceCullingMode::Type result = FaceCullingMode::NONE;
881 // Set the input property value to a different value (to emulate a change).
882 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
884 // Perform the lookup.
885 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
887 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
888 // Check the property could be converted.
889 DALI_TEST_CHECK( returnValue );
891 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
893 // Now emulate a property-set with the same value. false should be returned.
894 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
896 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
897 DALI_TEST_CHECK( !returnValue );
899 // The result should remain the same.
900 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
902 // TEST: An enum can be looked up from a Property::Value of type STRING.
903 // Set the input property value to a different value (to emulate a change).
904 Property::Value propertyValueString( "BACK" );
906 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
908 DALI_TEST_CHECK( returnValue );
910 // The result should remain the same.
911 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
913 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
915 DALI_TEST_CHECK( !returnValue );
917 // The result should remain the same.
918 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
920 // TEST: An enum can NOT be looked up for other Property::Value types.
921 Property::Value propertyValueBoolean( true );
923 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
925 // TEST: The return value is "false" if the property can not be successfully converted.
926 // Return value should be false as Property::Value was of an unsupported type for enum properties.
927 DALI_TEST_CHECK( !returnValue );
929 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
930 // The result should remain the same.
931 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
936 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
939 * This test function performs the following checks:
940 * - An enum can be looked up from a Property::Value of type INTEGER.
941 * - An enum can be looked up from a Property::Value of type STRING.
942 * - An enum can NOT be looked up from other Property::Value types.
943 * - The return value is "true" if the property can be successfully converted AND it has changed.
944 * - The return value is "false" if the property can not be successfully converted.
945 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
947 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
948 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
949 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
950 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
951 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
952 * - 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.
953 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
954 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
957 // String to Enum property table to test with (equivalent to ones used within DALi).
958 const Dali::Scripting::StringEnum testTable[] = {
959 { "NONE", FaceCullingMode::NONE },
960 { "FRONT", FaceCullingMode::FRONT },
961 { "BACK", FaceCullingMode::BACK },
962 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
963 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
965 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
966 // Initialise to first element.
967 FaceCullingMode::Type result = FaceCullingMode::NONE;
968 // Set the input property value to a different value (to emulate a change).
969 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
971 // Perform the lookup.
972 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
974 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
975 // Check the property could be converted.
976 DALI_TEST_CHECK( returnValue );
978 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
980 // TEST: An enum can be looked up from a Property::Value of type STRING.
981 // Set the input property value to a different value (to emulate a change).
982 Property::Value propertyValueString( "BACK" );
984 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
986 DALI_TEST_CHECK( returnValue );
988 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
990 // TEST: An enum can NOT be looked up from other Property::Value types.
991 Property::Value propertyValueVector( Vector3::ZERO );
993 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
995 // TEST: The return value is "false" if the property can not be successfully converted.
996 // Return value should be false as Property::Value was of an unsupported type for enum properties.
997 DALI_TEST_CHECK( !returnValue );
999 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1000 // The result should remain the same.
1001 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1003 // Test PropertyArrays:
1005 // Property array of 2 integers.
1006 Property::Array propertyArrayIntegers;
1007 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1008 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1009 result = FaceCullingMode::NONE;
1011 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1013 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1014 DALI_TEST_CHECK( returnValue );
1015 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1016 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1018 // Property array of 2 strings.
1019 Property::Array propertyArrayStrings;
1020 propertyArrayStrings.PushBack( "FRONT" );
1021 propertyArrayStrings.PushBack( "BACK" );
1022 result = FaceCullingMode::NONE;
1024 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1026 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1027 DALI_TEST_CHECK( returnValue );
1028 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1029 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1031 // Property array of an int and a string.
1032 Property::Array propertyArrayMixed;
1033 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1034 propertyArrayMixed.PushBack( "BACK" );
1035 result = FaceCullingMode::NONE;
1037 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1039 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1040 DALI_TEST_CHECK( returnValue );
1041 // 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.
1042 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1044 // Property array of an int and a string.
1045 Property::Array propertyArrayInvalid;
1046 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1047 propertyArrayInvalid.PushBack( Vector3::ZERO );
1049 // Set the initial value to non-zero, so we can test it does not change.
1050 result = FaceCullingMode::FRONT_AND_BACK;
1052 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1054 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1055 DALI_TEST_CHECK( !returnValue );
1056 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1057 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1062 int UtcDaliScriptingFindEnumIndexN(void)
1064 const Scripting::StringEnum myTable[] =
1068 { "THREE", (1<<3) },
1072 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1073 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1078 int UtcDaliScriptingEnumStringToIntegerP(void)
1080 const Scripting::StringEnum myTable[] =
1084 { "THREE", (1<<3) },
1088 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1090 int integerEnum = 0;
1091 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1093 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1096 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1097 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1099 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1100 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1102 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1103 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1105 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1106 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1108 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1109 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1111 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1112 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1114 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1115 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1117 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1118 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1124 int UtcDaliScriptingEnumStringToIntegerN(void)
1126 const Scripting::StringEnum myTable[] =
1134 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1136 int integerEnum = 0;
1137 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1139 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1141 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1143 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1145 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1147 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1149 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1154 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1156 const Scripting::StringEnum myTable[] =
1163 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1165 int integerEnum = 0;
1166 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1167 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1172 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1174 const Scripting::StringEnum myTable[] =
1181 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1183 int integerEnum = 0;
1184 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1186 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1188 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1190 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1192 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1194 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );