2 * Copyright (c) 2019 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 UtcDaliValueFromEnum(void)
132 Property::Value v1 = T::V1;
133 Property::Value v2 = T::V2;
136 DALI_TEST_CHECK( v1.Get<T>() == T::V1 );
137 DALI_TEST_CHECK( v2.Get<T>() == T::V2 );
138 DALI_TEST_CHECK( v1.Get(t) && t == T::V1 );
139 DALI_TEST_CHECK( v2.Get(t) && t == T::V2 );
144 int UtcDaliScriptingNewImageNegative01(void)
148 map[ "filename" ] = Vector3::ZERO;
149 // will give us an empty image handle
150 Image image = NewImage( map );
151 DALI_TEST_CHECK( !image );
155 int UtcDaliScriptingNewImageNegative06(void)
157 TestApplication application; // Image needs application
158 // Invalid width and height
160 map[ "filename" ] = "TEST_FILE";
161 map[ "width" ] = "Invalid";
162 map[ "height" ] = 100;
163 // will give us a valid image
164 PrepareResourceImage( application, 0u, 100u, Pixel::RGBA8888 );
165 Image image = NewImage( map );
166 DALI_TEST_CHECK( image );
167 ResourceImage resImage = ResourceImage::DownCast( image );
168 DALI_TEST_CHECK( resImage );
169 DALI_TEST_EQUALS( resImage.GetWidth(), 0u, TEST_LOCATION );
170 DALI_TEST_EQUALS( resImage.GetHeight(), 100u, TEST_LOCATION );
174 int UtcDaliScriptingNewImageNegative07(void)
176 TestApplication application; // Image needs application
179 map[ "filename" ] = "TEST_FILE";
181 map[ "height" ] = "Invalid";
182 // will give us a valid image
183 PrepareResourceImage( application, 10u, 0u, Pixel::RGBA8888 );
184 Image image = NewImage( map );
185 DALI_TEST_CHECK( image );
186 ResourceImage resImage = ResourceImage::DownCast( image );
187 DALI_TEST_CHECK( resImage );
188 DALI_TEST_EQUALS( resImage.GetWidth(), 10u, TEST_LOCATION );
189 DALI_TEST_EQUALS( resImage.GetHeight(), 0u, TEST_LOCATION );
193 int UtcDaliScriptingNewImageNegative08(void)
195 TestApplication application; // Image needs application
196 // Invalid fitting-mode
198 map[ "filename" ] = "TEST_FILE";
199 map[ "fittingMode" ] = Vector3::ZERO;
200 // will give us a valid image
201 Image image = NewImage( map );
202 DALI_TEST_CHECK( image );
203 ResourceImage resImage = ResourceImage::DownCast( image );
204 DALI_TEST_CHECK( resImage );
208 int UtcDaliScriptingNewImageNegative09(void)
210 TestApplication application; // Image needs application
213 map[ "filename" ] = "TEST_FILE";
214 map[ "fittingMode" ] = "INVALID";
215 // will give us a valid image
216 Image image = NewImage( map );
217 DALI_TEST_CHECK( image );
218 ResourceImage resImage = ResourceImage::DownCast( image );
219 DALI_TEST_CHECK( resImage );
223 int UtcDaliScriptingNewImageNegative10(void)
225 TestApplication application; // Image needs application
226 // Invalid scaling-mode
228 map[ "filename" ] = "TEST_FILE";
229 map[ "samplingMode" ] = Vector3::ZERO;
230 // will give us a valid image
231 Image image = NewImage( map );
232 DALI_TEST_CHECK( image );
233 ResourceImage resImage = ResourceImage::DownCast( image );
234 DALI_TEST_CHECK( resImage );
238 int UtcDaliScriptingNewImageNegative12(void)
240 TestApplication application; // Image needs application
241 // Invalid orientation-correction
243 map[ "filename" ] = "TEST_FILE";
244 map[ "orientation" ] = Vector3::ZERO;
245 // will give us a valid image
246 Image image = NewImage( map );
247 DALI_TEST_CHECK( image );
248 ResourceImage resImage = ResourceImage::DownCast( image );
249 DALI_TEST_CHECK( resImage );
253 int UtcDaliScriptingNewImageNegative13(void)
255 TestApplication application; // Image needs application
258 map[ "filename" ] = "TEST_FILE";
259 map[ "type" ] = Vector3::ZERO;
260 // will give us a valid image
261 Image image = NewImage( map );
262 DALI_TEST_CHECK( image );
263 ResourceImage resImage = ResourceImage::DownCast( image );
264 DALI_TEST_CHECK( resImage );
268 int UtcDaliScriptingNewImageNegative14(void)
272 map[ "type" ] = "INVALID";
273 Image image = NewImage( map );
274 DALI_TEST_CHECK( !image );
278 int UtcDaliScriptingNewImageNegative15(void)
280 // Invalid pixel-format
282 map[ "pixelFormat" ] = Vector3::ZERO;
283 Image image = NewImage( map );
284 DALI_TEST_CHECK( !image );
288 int UtcDaliScriptingNewImageNegative16(void)
292 map[ "pixelFormat" ] = "INVALID";
293 Image image = NewImage( map );
294 DALI_TEST_CHECK( !image );
298 int UtcDaliScriptingNewImage01P(void)
300 TestApplication application; // Image needs application
303 map[ "filename" ] = "TEST_FILE";
306 ResourceImage image = ResourceImage::DownCast( NewImage( map ) );
307 DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION );
311 int UtcDaliScriptingNewImage04P(void)
313 TestApplication application;
316 map[ "filename" ] = "TEST_FILE";
318 // float width and height
319 map[ "width" ] = (float) 10.0f;
320 map[ "height" ] = (float) 20.0f;
321 PrepareResourceImage( application, 10u, 20u, Pixel::RGBA8888 );
322 Image image = NewImage( map );
323 DALI_TEST_EQUALS( image.GetWidth(), 10u, TEST_LOCATION );
324 DALI_TEST_EQUALS( image.GetHeight(), 20u, TEST_LOCATION );
328 int UtcDaliScriptingNewImage05P(void)
330 TestApplication application;
333 map[ "filename" ] = "TEST_FILE";
337 map[ "height" ] = 70;
338 PrepareResourceImage( application, 50u, 70u, Pixel::RGBA8888 );
339 Image image = NewImage( map );
340 DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION );
341 DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION );
345 int UtcDaliScriptingNewImage06P(void)
347 TestApplication application;
350 // type FrameBufferImage
351 map[ "type" ] = "FrameBufferImage";
354 map[ "height" ] = 70;
355 Image image = NewImage( map );
356 DALI_TEST_CHECK( image );
357 DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) );
361 int UtcDaliScriptingNewImage07P(void)
363 TestApplication application;
367 map[ "type" ] = "BufferImage";
370 map[ "height" ] = 70;
371 Image image = NewImage( map );
372 DALI_TEST_CHECK( image );
373 DALI_TEST_CHECK( BufferImage::DownCast( image ) );
374 DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
378 int UtcDaliScriptingNewImage08P(void)
380 TestApplication application;
383 map[ "type" ] = "BufferImage";
386 map[ "height" ] = 99;
388 map[ "pixelFormat" ] = "";
389 const StringEnum values[] =
393 { "LA88", Pixel::LA88 },
394 { "RGB565", Pixel::RGB565 },
395 { "BGR565", Pixel::BGR565 },
396 { "RGBA4444", Pixel::RGBA4444 },
397 { "BGRA4444", Pixel::BGRA4444 },
398 { "RGBA5551", Pixel::RGBA5551 },
399 { "BGRA5551", Pixel::BGRA5551 },
400 { "RGB888", Pixel::RGB888 },
401 { "RGB8888", Pixel::RGB8888 },
402 { "BGR8888", Pixel::BGR8888 },
403 { "RGBA8888", Pixel::RGBA8888 },
404 { "BGRA8888", Pixel::BGRA8888 },
405 // BufferImage does not support compressed formats
407 TestEnumStrings< Pixel::Format, BufferImage >( map, "pixelFormat", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage );
412 int UtcDaliScriptingNewImage09P(void)
414 TestApplication application;
418 map[ "type" ] = "ResourceImage";
419 map[ "filename" ] = "TEST_FILE";
422 Image image = NewImage( map );
423 DALI_TEST_CHECK( ResourceImage::DownCast( image ) );
424 DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) );
425 DALI_TEST_CHECK( !BufferImage::DownCast( image ) );
430 int UtcDaliScriptingNewImage10P(void)
432 TestApplication application;
435 // type FrameBufferImage, empty size gives us stage size
436 map[ "type" ] = "FrameBufferImage";
437 Image image = NewImage( map );
438 DALI_TEST_CHECK( image );
442 int UtcDaliScriptingNewActorNegative(void)
444 TestApplication application;
448 Actor handle = NewActor( Property::Map() );
449 DALI_TEST_CHECK( !handle );
452 // Map with only properties
455 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
456 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
457 Actor handle = NewActor( map );
458 DALI_TEST_CHECK( !handle );
461 // Add some signals to the map, we should have no signal connections as its not yet supported
464 map[ "type" ] = "Actor";
465 map[ "signals" ] = Property::MAP;
466 Actor handle = NewActor( map );
467 DALI_TEST_CHECK( handle );
468 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
469 DALI_TEST_CHECK( !handle.OffStageSignal().GetConnectionCount() );
470 DALI_TEST_CHECK( !handle.OnStageSignal().GetConnectionCount() );
471 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
476 int UtcDaliScriptingNewActorProperties(void)
478 TestApplication application;
481 map[ "type" ] = "Actor";
482 map[ "size" ] = Vector3::ONE;
483 map[ "position" ] = Vector3::XAXIS;
484 map[ "scale" ] = Vector3::ONE;
485 map[ "visible" ] = false;
486 map[ "color" ] = Color::MAGENTA;
487 map[ "name" ] = "MyActor";
488 map[ "colorMode" ] = "USE_PARENT_COLOR";
489 map[ "sensitive" ] = false;
490 map[ "leaveRequired" ] = true;
491 map[ "drawMode" ] = "OVERLAY_2D";
492 map[ "inheritOrientation" ] = false;
493 map[ "inheritScale" ] = false;
495 // Default properties
497 Actor handle = NewActor( map );
498 DALI_TEST_CHECK( handle );
500 Stage::GetCurrent().Add( handle );
501 application.SendNotification();
502 application.Render();
504 DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION );
505 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
506 DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
507 DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION );
508 DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
509 DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION );
510 DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION );
511 DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION );
512 DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION );
513 DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
514 DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION );
515 DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION );
517 Stage::GetCurrent().Remove( handle );
520 // Check Anchor point and parent origin vector3s
521 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
522 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
524 Actor handle = NewActor( map );
525 DALI_TEST_CHECK( handle );
527 Stage::GetCurrent().Add( handle );
528 application.SendNotification();
529 application.Render();
531 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION );
532 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION );
534 Stage::GetCurrent().Remove( handle );
537 // Check Anchor point and parent origin STRINGS
538 map[ "parentOrigin" ] = "TOP_LEFT";
539 map[ "anchorPoint" ] = "CENTER_LEFT";
541 Actor handle = NewActor( map );
542 DALI_TEST_CHECK( handle );
544 Stage::GetCurrent().Add( handle );
545 application.SendNotification();
546 application.Render();
548 DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION );
549 DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
551 Stage::GetCurrent().Remove( handle );
556 int UtcDaliScriptingNewAnimation(void)
558 TestApplication application;
561 map["actor"] = "Actor1";
562 map["property"] = "color";
563 map["value"] = Color::MAGENTA;
564 map["alphaFunction"] = "EASE_IN_OUT";
566 Property::Map timePeriod;
567 timePeriod["delay"] = 0.5f;
568 timePeriod["duration"] = 1.0f;
569 map["timePeriod"] = timePeriod;
571 Dali::AnimationData data;
572 Scripting::NewAnimation( map, data );
574 Actor actor = Actor::New();
575 actor.SetName("Actor1");
576 actor.SetColor(Color::CYAN);
577 Stage::GetCurrent().Add(actor);
579 Animation anim = data.CreateAnimation( actor, 0.5f );
582 application.SendNotification();
583 application.Render(0);
584 application.Render(500); // Start animation
585 application.Render(500); // Halfway thru anim
586 application.SendNotification();
587 DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
589 application.Render(500); // Halfway thru anim
590 application.SendNotification();
591 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
596 int UtcDaliScriptingNewActorChildren(void)
598 TestApplication application;
601 map[ "type" ] = "Actor";
602 map[ "position" ] = Vector3::XAXIS;
604 Property::Map child1Map;
605 child1Map[ "type" ] = "Layer";
606 child1Map[ "position" ] = Vector3::YAXIS;
608 Property::Array childArray;
609 childArray.PushBack( child1Map );
610 map[ "actors" ] = childArray;
613 Actor handle = NewActor( map );
614 DALI_TEST_CHECK( handle );
616 Stage::GetCurrent().Add( handle );
617 application.SendNotification();
618 application.Render();
620 DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION );
621 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
623 Actor child1 = handle.GetChildAt(0);
624 DALI_TEST_CHECK( child1 );
625 DALI_TEST_CHECK( Layer::DownCast( child1 ) );
626 DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION );
627 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
629 Stage::GetCurrent().Remove( handle );
634 int UtcDaliScriptingCreatePropertyMapActor(void)
636 TestApplication application;
640 Actor actor = Actor::New();
643 CreatePropertyMap( actor, map );
644 DALI_TEST_CHECK( !map.Empty() );
645 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
646 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
648 Stage::GetCurrent().Remove( actor );
653 Actor actor = Layer::New();
656 CreatePropertyMap( actor, map );
657 DALI_TEST_CHECK( !map.Empty() );
658 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
659 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
661 Stage::GetCurrent().Remove( actor );
664 // Default properties
666 Actor actor = Actor::New();
667 actor.SetSize( Vector3::ONE );
668 actor.SetPosition( Vector3::XAXIS );
669 actor.SetScale( Vector3::ZAXIS );
670 actor.SetVisible( false );
671 actor.SetColor( Color::MAGENTA );
672 actor.SetName( "MyActor" );
673 actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
674 actor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
675 actor.SetSensitive( false );
676 actor.SetLeaveRequired( true );
677 actor.SetInheritOrientation( false );
678 actor.SetInheritScale( false );
679 actor.SetSizeModeFactor( Vector3::ONE );
681 Stage::GetCurrent().Add( actor );
682 application.SendNotification();
683 application.Render();
686 CreatePropertyMap( actor, map );
688 DALI_TEST_CHECK( !map.Empty() );
689 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
690 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
691 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
692 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
693 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
694 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
695 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
696 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
697 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
698 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
699 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
700 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
701 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
702 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
703 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
704 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
705 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
706 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
707 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
708 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
709 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
710 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
711 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
712 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
713 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
714 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
716 Stage::GetCurrent().Remove( actor );
720 TestEnumStrings< ColorMode >( "colorMode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode );
723 TestEnumStrings< DrawMode::Type >( "drawMode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode );
727 Actor actor = Actor::New();
728 Actor child = Layer::New();
731 Stage::GetCurrent().Add( actor );
732 application.SendNotification();
733 application.Render();
736 CreatePropertyMap( actor, map );
737 DALI_TEST_CHECK( !map.Empty() );
739 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
740 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
742 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
743 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
744 DALI_TEST_CHECK( !children.Empty() );
745 Property::Map childMap( children[0].Get< Property::Map >() );
746 DALI_TEST_CHECK( !childMap.Empty() );
747 DALI_TEST_CHECK( childMap.Find( "type" ) );
748 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
750 Stage::GetCurrent().Remove( actor );
755 int UtcDaliScriptingCreatePropertyMapImage(void)
757 TestApplication application;
763 CreatePropertyMap( image, map );
764 DALI_TEST_CHECK( map.Empty() );
769 Image image = ResourceImage::New( "MY_PATH" );
772 CreatePropertyMap( image, map );
773 DALI_TEST_CHECK( !map.Empty() );
775 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
776 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
777 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
778 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
779 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
780 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
785 PrepareResourceImage( application, 300, 400, Pixel::RGBA8888 );
786 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
789 CreatePropertyMap( image, map );
790 DALI_TEST_CHECK( !map.Empty() );
792 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
793 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
794 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
795 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
796 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
797 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
798 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
799 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
804 Image image = BufferImage::New( 200, 300, Pixel::A8 );
806 CreatePropertyMap( image, map );
807 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
808 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
809 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
810 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
815 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
817 CreatePropertyMap( image, map );
818 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
819 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
824 int UtcDaliScriptingGetEnumerationTemplates(void)
826 const Scripting::StringEnum myTable[] =
834 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
836 for ( unsigned int i = 0; i < myTableCount; ++i )
838 tet_printf("Checking: %s\n", myTable[ i ].string );
840 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
841 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
844 for ( unsigned int i = 0; i < myTableCount; ++i )
846 tet_printf("Checking: %d\n", myTable[ i ].value );
847 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
853 int UtcDaliScriptingGetEnumerationNameN(void)
855 const char* value = GetEnumerationName( 10, NULL, 0 );
856 DALI_TEST_CHECK( NULL == value );
858 value = GetEnumerationName( 10, NULL, 1 );
859 DALI_TEST_CHECK( NULL == value );
864 int UtcDaliScriptingGetLinearEnumerationNameN(void)
866 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
867 DALI_TEST_CHECK( NULL == value );
869 value = GetLinearEnumerationName( 10, NULL, 1 );
870 DALI_TEST_CHECK( NULL == value );
875 int UtcDaliScriptingGetEnumerationProperty(void)
878 * This test function performs the following checks:
879 * - An enum can be looked up from a Property::Value of type INTEGER.
880 * - An enum can be looked up from a Property::Value of type STRING.
881 * - An enum can NOT be looked up for other Property::Value types.
882 * - The return value is "true" if the property can be successfully converted AND it has changed.
883 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
884 * - The return value is "false" if the property can not be successfully converted.
885 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
888 // String to Enum property table to test with (equivalent to ones used within DALi).
889 const Dali::Scripting::StringEnum testTable[] = {
890 { "NONE", FaceCullingMode::NONE },
891 { "FRONT", FaceCullingMode::FRONT },
892 { "BACK", FaceCullingMode::BACK },
893 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
894 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
896 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
897 // Initialise to first element.
898 FaceCullingMode::Type result = FaceCullingMode::NONE;
899 // Set the input property value to a different value (to emulate a change).
900 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
902 // Perform the lookup.
903 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
905 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
906 // Check the property could be converted.
907 DALI_TEST_CHECK( returnValue );
909 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
911 // Now emulate a property-set with the same value. false should be returned.
912 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
914 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
915 DALI_TEST_CHECK( !returnValue );
917 // The result should remain the same.
918 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
920 // TEST: An enum can be looked up from a Property::Value of type STRING.
921 // Set the input property value to a different value (to emulate a change).
922 Property::Value propertyValueString( "BACK" );
924 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
926 DALI_TEST_CHECK( returnValue );
928 // The result should remain the same.
929 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
931 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
933 DALI_TEST_CHECK( !returnValue );
935 // The result should remain the same.
936 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
938 // TEST: An enum can NOT be looked up for other Property::Value types.
939 Property::Value propertyValueBoolean( true );
941 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
943 // TEST: The return value is "false" if the property can not be successfully converted.
944 // Return value should be false as Property::Value was of an unsupported type for enum properties.
945 DALI_TEST_CHECK( !returnValue );
947 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
948 // The result should remain the same.
949 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
954 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
957 * This test function performs the following checks:
958 * - An enum can be looked up from a Property::Value of type INTEGER.
959 * - An enum can be looked up from a Property::Value of type STRING.
960 * - An enum can NOT be looked up from other Property::Value types.
961 * - The return value is "true" if the property can be successfully converted AND it has changed.
962 * - The return value is "false" if the property can not be successfully converted.
963 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
965 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
966 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
967 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
968 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
969 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
970 * - 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.
971 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
972 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
975 // String to Enum property table to test with (equivalent to ones used within DALi).
976 const Dali::Scripting::StringEnum testTable[] = {
977 { "NONE", FaceCullingMode::NONE },
978 { "FRONT", FaceCullingMode::FRONT },
979 { "BACK", FaceCullingMode::BACK },
980 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
981 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
983 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
984 // Initialise to first element.
985 FaceCullingMode::Type result = FaceCullingMode::NONE;
986 // Set the input property value to a different value (to emulate a change).
987 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
989 // Perform the lookup.
990 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
992 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
993 // Check the property could be converted.
994 DALI_TEST_CHECK( returnValue );
996 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
998 // TEST: An enum can be looked up from a Property::Value of type STRING.
999 // Set the input property value to a different value (to emulate a change).
1000 Property::Value propertyValueString( "BACK" );
1002 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
1004 DALI_TEST_CHECK( returnValue );
1006 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1008 // TEST: An enum can NOT be looked up from other Property::Value types.
1009 Property::Value propertyValueVector( Vector3::ZERO );
1011 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
1013 // TEST: The return value is "false" if the property can not be successfully converted.
1014 // Return value should be false as Property::Value was of an unsupported type for enum properties.
1015 DALI_TEST_CHECK( !returnValue );
1017 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1018 // The result should remain the same.
1019 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1021 // Test PropertyArrays:
1023 // Property array of 2 integers.
1024 Property::Array propertyArrayIntegers;
1025 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1026 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1027 result = FaceCullingMode::NONE;
1029 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1031 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1032 DALI_TEST_CHECK( returnValue );
1033 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1034 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1036 // Property array of 2 strings.
1037 Property::Array propertyArrayStrings;
1038 propertyArrayStrings.PushBack( "FRONT" );
1039 propertyArrayStrings.PushBack( "BACK" );
1040 result = FaceCullingMode::NONE;
1042 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1044 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1045 DALI_TEST_CHECK( returnValue );
1046 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1047 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1049 // Property array of an int and a string.
1050 Property::Array propertyArrayMixed;
1051 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1052 propertyArrayMixed.PushBack( "BACK" );
1053 result = FaceCullingMode::NONE;
1055 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1057 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1058 DALI_TEST_CHECK( returnValue );
1059 // 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.
1060 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1062 // Property array of an int and a string.
1063 Property::Array propertyArrayInvalid;
1064 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1065 propertyArrayInvalid.PushBack( Vector3::ZERO );
1067 // Set the initial value to non-zero, so we can test it does not change.
1068 result = FaceCullingMode::FRONT_AND_BACK;
1070 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1072 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1073 DALI_TEST_CHECK( !returnValue );
1074 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1075 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1080 int UtcDaliScriptingFindEnumIndexN(void)
1082 const Scripting::StringEnum myTable[] =
1086 { "THREE", (1<<3) },
1090 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1091 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1096 int UtcDaliScriptingEnumStringToIntegerP(void)
1098 const Scripting::StringEnum myTable[] =
1102 { "THREE", (1<<3) },
1106 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1108 int integerEnum = 0;
1109 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1111 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1114 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1115 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1117 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1118 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1120 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1121 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1123 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1124 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1126 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1127 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1129 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
1130 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1132 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1133 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1135 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1136 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1142 int UtcDaliScriptingEnumStringToIntegerN(void)
1144 const Scripting::StringEnum myTable[] =
1152 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1154 int integerEnum = 0;
1155 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1157 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1159 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1161 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1163 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1165 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1167 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1172 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(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( "", myTable, myTableCount, integerEnum ) );
1185 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1190 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1192 const Scripting::StringEnum myTable[] =
1199 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1201 int integerEnum = 0;
1202 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1204 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1206 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1208 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1210 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1212 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );