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.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ), Vector3::ONE, TEST_LOCATION );
505 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3::XAXIS, TEST_LOCATION );
506 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ), Vector3::ONE, TEST_LOCATION );
507 DALI_TEST_EQUALS( handle.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
508 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::MAGENTA, TEST_LOCATION );
509 DALI_TEST_EQUALS( handle.GetProperty< std::string >( Actor::Property::NAME ), "MyActor", TEST_LOCATION );
510 DALI_TEST_EQUALS( handle.GetProperty< ColorMode >( Actor::Property::COLOR_MODE ), USE_PARENT_COLOR, TEST_LOCATION );
511 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::SENSITIVE ), false, TEST_LOCATION );
512 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::LEAVE_REQUIRED ), true, TEST_LOCATION );
513 DALI_TEST_EQUALS( handle.GetProperty< DrawMode::Type >( Actor::Property::DRAW_MODE ), DrawMode::OVERLAY_2D, TEST_LOCATION );
514 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::INHERIT_ORIENTATION ), false, TEST_LOCATION );
515 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::INHERIT_SCALE ), 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.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ), ParentOrigin::TOP_CENTER, TEST_LOCATION );
532 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ), 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.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ), ParentOrigin::TOP_LEFT, TEST_LOCATION );
549 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ), 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.SetProperty( Actor::Property::NAME,"Actor1");
576 actor.SetProperty( Actor::Property::COLOR,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.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
589 application.Render(500); // Halfway thru anim
590 application.SendNotification();
591 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), 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.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), 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.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), 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.SetProperty( Actor::Property::VISIBLE, false );
671 actor.SetProperty( Actor::Property::COLOR, Color::MAGENTA );
672 actor.SetProperty( Actor::Property::NAME, "MyActor" );
673 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
674 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
675 actor.SetProperty( Actor::Property::SENSITIVE, false );
676 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
677 actor.SetProperty( Actor::Property::INHERIT_ORIENTATION, false );
678 actor.SetProperty( Actor::Property::INHERIT_SCALE, false );
679 actor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, 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 );
721 Actor actor = Actor::New();
722 Actor child = Layer::New();
725 Stage::GetCurrent().Add( actor );
726 application.SendNotification();
727 application.Render();
730 CreatePropertyMap( actor, map );
731 DALI_TEST_CHECK( !map.Empty() );
733 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
734 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
736 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
737 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
738 DALI_TEST_CHECK( !children.Empty() );
739 Property::Map childMap( children[0].Get< Property::Map >() );
740 DALI_TEST_CHECK( !childMap.Empty() );
741 DALI_TEST_CHECK( childMap.Find( "type" ) );
742 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
744 Stage::GetCurrent().Remove( actor );
749 int UtcDaliScriptingCreatePropertyMapImage(void)
751 TestApplication application;
757 CreatePropertyMap( image, map );
758 DALI_TEST_CHECK( map.Empty() );
763 Image image = ResourceImage::New( "MY_PATH" );
766 CreatePropertyMap( image, map );
767 DALI_TEST_CHECK( !map.Empty() );
769 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
770 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
771 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
772 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
773 DALI_TEST_CHECK( NULL == map.Find( "width" ) );
774 DALI_TEST_CHECK( NULL == map.Find( "height" ) );
779 PrepareResourceImage( application, 300, 400, Pixel::RGBA8888 );
780 ResourceImage image = ResourceImage::New( "MY_PATH", ImageDimensions( 300, 400 ), FittingMode::FIT_WIDTH );
783 CreatePropertyMap( image, map );
784 DALI_TEST_CHECK( !map.Empty() );
786 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
787 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION );
788 DALI_TEST_CHECK( NULL != map.Find( "filename" ) );
789 DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION );
790 DALI_TEST_CHECK( NULL != map.Find( "width" ) );
791 DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION );
792 DALI_TEST_CHECK( NULL != map.Find( "height" ) );
793 DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION );
798 Image image = BufferImage::New( 200, 300, Pixel::A8 );
800 CreatePropertyMap( image, map );
801 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
802 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION );
803 DALI_TEST_CHECK( NULL != map.Find( "pixelFormat") );
804 DALI_TEST_EQUALS( map.Find( "pixelFormat" )->Get< std::string >(), "A8", TEST_LOCATION );
809 Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 );
811 CreatePropertyMap( image, map );
812 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
813 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION );
818 int UtcDaliScriptingGetEnumerationTemplates(void)
820 const Scripting::StringEnum myTable[] =
828 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
830 for ( unsigned int i = 0; i < myTableCount; ++i )
832 tet_printf("Checking: %s\n", myTable[ i ].string );
834 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
835 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
838 for ( unsigned int i = 0; i < myTableCount; ++i )
840 tet_printf("Checking: %d\n", myTable[ i ].value );
841 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
847 int UtcDaliScriptingGetEnumerationNameN(void)
849 const char* value = GetEnumerationName( 10, NULL, 0 );
850 DALI_TEST_CHECK( NULL == value );
852 value = GetEnumerationName( 10, NULL, 1 );
853 DALI_TEST_CHECK( NULL == value );
858 int UtcDaliScriptingGetLinearEnumerationNameN(void)
860 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
861 DALI_TEST_CHECK( NULL == value );
863 value = GetLinearEnumerationName( 10, NULL, 1 );
864 DALI_TEST_CHECK( NULL == value );
869 int UtcDaliScriptingGetEnumerationProperty(void)
872 * This test function performs the following checks:
873 * - An enum can be looked up from a Property::Value of type INTEGER.
874 * - An enum can be looked up from a Property::Value of type STRING.
875 * - An enum can NOT be looked up for other Property::Value types.
876 * - The return value is "true" if the property can be successfully converted AND it has changed.
877 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
878 * - The return value is "false" if the property can not be successfully converted.
879 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
882 // String to Enum property table to test with (equivalent to ones used within DALi).
883 const Dali::Scripting::StringEnum testTable[] = {
884 { "NONE", FaceCullingMode::NONE },
885 { "FRONT", FaceCullingMode::FRONT },
886 { "BACK", FaceCullingMode::BACK },
887 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
888 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
890 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
891 // Initialise to first element.
892 FaceCullingMode::Type result = FaceCullingMode::NONE;
893 // Set the input property value to a different value (to emulate a change).
894 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
896 // Perform the lookup.
897 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
899 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
900 // Check the property could be converted.
901 DALI_TEST_CHECK( returnValue );
903 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
905 // Now emulate a property-set with the same value. false should be returned.
906 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
908 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
909 DALI_TEST_CHECK( !returnValue );
911 // The result should remain the same.
912 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
914 // TEST: An enum can be looked up from a Property::Value of type STRING.
915 // Set the input property value to a different value (to emulate a change).
916 Property::Value propertyValueString( "BACK" );
918 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
920 DALI_TEST_CHECK( returnValue );
922 // The result should remain the same.
923 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
925 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
927 DALI_TEST_CHECK( !returnValue );
929 // The result should remain the same.
930 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
932 // TEST: An enum can NOT be looked up for other Property::Value types.
933 Property::Value propertyValueBoolean( true );
935 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
937 // TEST: The return value is "false" if the property can not be successfully converted.
938 // Return value should be false as Property::Value was of an unsupported type for enum properties.
939 DALI_TEST_CHECK( !returnValue );
941 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
942 // The result should remain the same.
943 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
948 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
951 * This test function performs the following checks:
952 * - An enum can be looked up from a Property::Value of type INTEGER.
953 * - An enum can be looked up from a Property::Value of type STRING.
954 * - An enum can NOT be looked up from other Property::Value types.
955 * - The return value is "true" if the property can be successfully converted AND it has changed.
956 * - The return value is "false" if the property can not be successfully converted.
957 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
959 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
960 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
961 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
962 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
963 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
964 * - 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.
965 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
966 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
969 // String to Enum property table to test with (equivalent to ones used within DALi).
970 const Dali::Scripting::StringEnum testTable[] = {
971 { "NONE", FaceCullingMode::NONE },
972 { "FRONT", FaceCullingMode::FRONT },
973 { "BACK", FaceCullingMode::BACK },
974 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
975 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
977 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
978 // Initialise to first element.
979 FaceCullingMode::Type result = FaceCullingMode::NONE;
980 // Set the input property value to a different value (to emulate a change).
981 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
983 // Perform the lookup.
984 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
986 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
987 // Check the property could be converted.
988 DALI_TEST_CHECK( returnValue );
990 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
992 // TEST: An enum can be looked up from a Property::Value of type STRING.
993 // Set the input property value to a different value (to emulate a change).
994 Property::Value propertyValueString( "BACK" );
996 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
998 DALI_TEST_CHECK( returnValue );
1000 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1002 // TEST: An enum can NOT be looked up from other Property::Value types.
1003 Property::Value propertyValueVector( Vector3::ZERO );
1005 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
1007 // TEST: The return value is "false" if the property can not be successfully converted.
1008 // Return value should be false as Property::Value was of an unsupported type for enum properties.
1009 DALI_TEST_CHECK( !returnValue );
1011 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
1012 // The result should remain the same.
1013 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
1015 // Test PropertyArrays:
1017 // Property array of 2 integers.
1018 Property::Array propertyArrayIntegers;
1019 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
1020 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
1021 result = FaceCullingMode::NONE;
1023 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
1025 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
1026 DALI_TEST_CHECK( returnValue );
1027 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
1028 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1030 // Property array of 2 strings.
1031 Property::Array propertyArrayStrings;
1032 propertyArrayStrings.PushBack( "FRONT" );
1033 propertyArrayStrings.PushBack( "BACK" );
1034 result = FaceCullingMode::NONE;
1036 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
1038 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
1039 DALI_TEST_CHECK( returnValue );
1040 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
1041 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1043 // Property array of an int and a string.
1044 Property::Array propertyArrayMixed;
1045 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
1046 propertyArrayMixed.PushBack( "BACK" );
1047 result = FaceCullingMode::NONE;
1049 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
1051 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
1052 DALI_TEST_CHECK( returnValue );
1053 // 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.
1054 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
1056 // Property array of an int and a string.
1057 Property::Array propertyArrayInvalid;
1058 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
1059 propertyArrayInvalid.PushBack( Vector3::ZERO );
1061 // Set the initial value to non-zero, so we can test it does not change.
1062 result = FaceCullingMode::FRONT_AND_BACK;
1064 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
1066 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
1067 DALI_TEST_CHECK( !returnValue );
1068 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
1069 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
1074 int UtcDaliScriptingFindEnumIndexN(void)
1076 const Scripting::StringEnum myTable[] =
1080 { "THREE", (1<<3) },
1084 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1085 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
1090 int UtcDaliScriptingEnumStringToIntegerP(void)
1092 const Scripting::StringEnum myTable[] =
1096 { "THREE", (1<<3) },
1100 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1102 int integerEnum = 0;
1103 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
1105 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1108 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
1109 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1111 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
1112 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1114 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
1115 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
1117 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
1118 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
1120 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
1121 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
1123 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,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( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1127 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1129 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
1130 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
1136 int UtcDaliScriptingEnumStringToIntegerN(void)
1138 const Scripting::StringEnum myTable[] =
1146 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1148 int integerEnum = 0;
1149 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
1151 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1153 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1155 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
1157 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
1159 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
1161 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
1166 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
1168 const Scripting::StringEnum myTable[] =
1175 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1177 int integerEnum = 0;
1178 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
1179 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
1184 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
1186 const Scripting::StringEnum myTable[] =
1193 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
1195 int integerEnum = 0;
1196 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
1198 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
1200 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
1202 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
1204 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
1206 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );