2 * Copyright (c) 2020 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 //////////////////////////////////////////////////////////////////////////////
77 // Helpers for string to enum comparisons for Actor to Property::Map
78 //////////////////////////////////////////////////////////////////////////////
81 * Template to check enumerations of type T
83 template< typename T >
85 const char * const keyName, // The name of the key to check
86 TestApplication& application, // Reference to the application class
87 const StringEnum* values, // An array of string values
88 unsigned int num, // Number of items in the array
89 void ( Actor::*method )( T ) // The Actor member method to set the enumeration
92 for ( unsigned int i = 0; i < num; ++i )
94 tet_printf("Checking: %s: %s\n", keyName, values[i].string );
96 Actor actor = Actor::New();
97 (actor.*method)( ( T ) values[i].value );
99 application.GetScene().Add( actor );
100 application.SendNotification();
101 application.Render();
104 CreatePropertyMap( actor, map );
106 DALI_TEST_CHECK( 0 < map.Count() );
107 DALI_TEST_CHECK( NULL != map.Find( keyName ) );
108 DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION );
110 application.GetScene().Remove( actor );
114 //////////////////////////////////////////////////////////////////////////////
119 int UtcDaliValueFromEnum(void)
125 Property::Value v1 = T::V1;
126 Property::Value v2 = T::V2;
129 DALI_TEST_CHECK( v1.Get<T>() == T::V1 );
130 DALI_TEST_CHECK( v2.Get<T>() == T::V2 );
131 DALI_TEST_CHECK( v1.Get(t) && t == T::V1 );
132 DALI_TEST_CHECK( v2.Get(t) && t == T::V2 );
137 int UtcDaliScriptingNewActorNegative(void)
139 TestApplication application;
143 Actor handle = NewActor( Property::Map() );
144 DALI_TEST_CHECK( !handle );
147 // Map with only properties
150 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
151 map[ "anchorPoint" ] = AnchorPoint::TOP_CENTER;
152 Actor handle = NewActor( map );
153 DALI_TEST_CHECK( !handle );
156 // Add some signals to the map, we should have no signal connections as its not yet supported
159 map[ "type" ] = "Actor";
160 map[ "signals" ] = Property::MAP;
161 Actor handle = NewActor( map );
162 DALI_TEST_CHECK( handle );
163 DALI_TEST_CHECK( !handle.WheelEventSignal().GetConnectionCount() );
164 DALI_TEST_CHECK( !handle.OffSceneSignal().GetConnectionCount() );
165 DALI_TEST_CHECK( !handle.OnSceneSignal().GetConnectionCount() );
166 DALI_TEST_CHECK( !handle.TouchedSignal().GetConnectionCount() );
171 int UtcDaliScriptingNewActorProperties(void)
173 TestApplication application;
176 map[ "type" ] = "Actor";
177 map[ "size" ] = Vector3::ONE;
178 map[ "position" ] = Vector3::XAXIS;
179 map[ "scale" ] = Vector3::ONE;
180 map[ "visible" ] = false;
181 map[ "color" ] = Color::MAGENTA;
182 map[ "name" ] = "MyActor";
183 map[ "colorMode" ] = "USE_PARENT_COLOR";
184 map[ "sensitive" ] = false;
185 map[ "leaveRequired" ] = true;
186 map[ "drawMode" ] = "OVERLAY_2D";
187 map[ "inheritOrientation" ] = false;
188 map[ "inheritScale" ] = false;
190 // Default properties
192 Actor handle = NewActor( map );
193 DALI_TEST_CHECK( handle );
195 application.GetScene().Add( handle );
196 application.SendNotification();
197 application.Render();
199 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ), Vector3::ONE, TEST_LOCATION );
200 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3::XAXIS, TEST_LOCATION );
201 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ), Vector3::ONE, TEST_LOCATION );
202 DALI_TEST_EQUALS( handle.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
203 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::MAGENTA, TEST_LOCATION );
204 DALI_TEST_EQUALS( handle.GetProperty< std::string >( Actor::Property::NAME ), "MyActor", TEST_LOCATION );
205 DALI_TEST_EQUALS( handle.GetProperty< ColorMode >( Actor::Property::COLOR_MODE ), USE_PARENT_COLOR, TEST_LOCATION );
206 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::SENSITIVE ), false, TEST_LOCATION );
207 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::LEAVE_REQUIRED ), true, TEST_LOCATION );
208 DALI_TEST_EQUALS( handle.GetProperty< DrawMode::Type >( Actor::Property::DRAW_MODE ), DrawMode::OVERLAY_2D, TEST_LOCATION );
209 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::INHERIT_ORIENTATION ), false, TEST_LOCATION );
210 DALI_TEST_EQUALS( handle.GetProperty< bool >( Actor::Property::INHERIT_SCALE ), false, TEST_LOCATION );
212 application.GetScene().Remove( handle );
215 // Check Anchor point and parent origin vector3s
216 map[ "parentOrigin" ] = ParentOrigin::TOP_CENTER;
217 map[ "anchorPoint" ] = AnchorPoint::TOP_LEFT;
219 Actor handle = NewActor( map );
220 DALI_TEST_CHECK( handle );
222 application.GetScene().Add( handle );
223 application.SendNotification();
224 application.Render();
226 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ), ParentOrigin::TOP_CENTER, TEST_LOCATION );
227 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ), AnchorPoint::TOP_LEFT, TEST_LOCATION );
229 application.GetScene().Remove( handle );
232 // Check Anchor point and parent origin STRINGS
233 map[ "parentOrigin" ] = "TOP_LEFT";
234 map[ "anchorPoint" ] = "CENTER_LEFT";
236 Actor handle = NewActor( map );
237 DALI_TEST_CHECK( handle );
239 application.GetScene().Add( handle );
240 application.SendNotification();
241 application.Render();
243 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ), ParentOrigin::TOP_LEFT, TEST_LOCATION );
244 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
246 application.GetScene().Remove( handle );
251 int UtcDaliScriptingNewAnimation(void)
253 TestApplication application;
256 map["actor"] = "Actor1";
257 map["property"] = "color";
258 map["value"] = Color::MAGENTA;
259 map["alphaFunction"] = "EASE_IN_OUT";
261 Property::Map timePeriod;
262 timePeriod["delay"] = 0.5f;
263 timePeriod["duration"] = 1.0f;
264 map["timePeriod"] = timePeriod;
266 Dali::AnimationData data;
267 Scripting::NewAnimation( map, data );
269 Actor actor = Actor::New();
270 actor.SetProperty( Actor::Property::NAME,"Actor1");
271 actor.SetProperty( Actor::Property::COLOR,Color::CYAN);
272 application.GetScene().Add(actor);
274 Animation anim = data.CreateAnimation( actor, 0.5f );
277 application.SendNotification();
278 application.Render(0);
279 application.Render(500); // Start animation
280 application.Render(500); // Halfway thru anim
281 application.SendNotification();
282 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
284 application.Render(500); // Halfway thru anim
285 application.SendNotification();
286 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::MAGENTA, TEST_LOCATION );
291 int UtcDaliScriptingNewActorChildren(void)
293 TestApplication application;
296 map[ "type" ] = "Actor";
297 map[ "position" ] = Vector3::XAXIS;
299 Property::Map child1Map;
300 child1Map[ "type" ] = "Layer";
301 child1Map[ "position" ] = Vector3::YAXIS;
303 Property::Array childArray;
304 childArray.PushBack( child1Map );
305 map[ "actors" ] = childArray;
308 Actor handle = NewActor( map );
309 DALI_TEST_CHECK( handle );
311 application.GetScene().Add( handle );
312 application.SendNotification();
313 application.Render();
315 DALI_TEST_EQUALS( handle.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3::XAXIS, TEST_LOCATION );
316 DALI_TEST_EQUALS( handle.GetChildCount(), 1u, TEST_LOCATION );
318 Actor child1 = handle.GetChildAt(0);
319 DALI_TEST_CHECK( child1 );
320 DALI_TEST_CHECK( Layer::DownCast( child1 ) );
321 DALI_TEST_EQUALS( child1.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3::YAXIS, TEST_LOCATION );
322 DALI_TEST_EQUALS( child1.GetChildCount(), 0u, TEST_LOCATION );
324 application.GetScene().Remove( handle );
329 int UtcDaliScriptingCreatePropertyMapActor(void)
331 TestApplication application;
335 Actor actor = Actor::New();
338 CreatePropertyMap( actor, map );
339 DALI_TEST_CHECK( !map.Empty() );
340 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
341 DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION );
343 application.GetScene().Remove( actor );
348 Actor actor = Layer::New();
351 CreatePropertyMap( actor, map );
352 DALI_TEST_CHECK( !map.Empty() );
353 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
354 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
356 application.GetScene().Remove( actor );
359 // Default properties
361 Actor actor = Actor::New();
362 actor.SetProperty( Actor::Property::SIZE, Vector3::ONE );
363 actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS );
364 actor.SetProperty( Actor::Property::SCALE, Vector3::ZAXIS );
365 actor.SetProperty( Actor::Property::VISIBLE, false );
366 actor.SetProperty( Actor::Property::COLOR, Color::MAGENTA );
367 actor.SetProperty( Actor::Property::NAME, "MyActor" );
368 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
369 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
370 actor.SetProperty( Actor::Property::SENSITIVE, false );
371 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
372 actor.SetProperty( Actor::Property::INHERIT_ORIENTATION, false );
373 actor.SetProperty( Actor::Property::INHERIT_SCALE, false );
374 actor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3::ONE );
376 application.GetScene().Add( actor );
377 application.SendNotification();
378 application.Render();
381 CreatePropertyMap( actor, map );
383 DALI_TEST_CHECK( !map.Empty() );
384 DALI_TEST_CHECK( NULL != map.Find( "size" ) );
385 DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
386 DALI_TEST_CHECK( NULL != map.Find( "position" ) );
387 DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION );
388 DALI_TEST_CHECK( NULL != map.Find( "scale" ) );
389 DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION );
390 DALI_TEST_CHECK( NULL != map.Find( "visible" ) );
391 DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION );
392 DALI_TEST_CHECK( NULL != map.Find( "color" ) );
393 DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION );
394 DALI_TEST_CHECK( NULL != map.Find( "name" ) );
395 DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION );
396 DALI_TEST_CHECK( NULL != map.Find( "anchorPoint" ) );
397 DALI_TEST_EQUALS( map.Find( "anchorPoint" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION );
398 DALI_TEST_CHECK( NULL != map.Find( "parentOrigin" ) );
399 DALI_TEST_EQUALS( map.Find( "parentOrigin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION );
400 DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) );
401 DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION );
402 DALI_TEST_CHECK( NULL != map.Find( "leaveRequired" ) );
403 DALI_TEST_EQUALS( map.Find( "leaveRequired" )->Get< bool >(), true, TEST_LOCATION );
404 DALI_TEST_CHECK( NULL != map.Find( "inheritOrientation" ) );
405 DALI_TEST_EQUALS( map.Find( "inheritOrientation" )->Get< bool >(), false, TEST_LOCATION );
406 DALI_TEST_CHECK( NULL != map.Find( "inheritScale" ) );
407 DALI_TEST_EQUALS( map.Find( "inheritScale" )->Get< bool >(), false, TEST_LOCATION );
408 DALI_TEST_CHECK( NULL != map.Find( "sizeModeFactor" ) );
409 DALI_TEST_EQUALS( map.Find( "sizeModeFactor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION );
411 application.GetScene().Remove( actor );
416 Actor actor = Actor::New();
417 Actor child = Layer::New();
420 application.GetScene().Add( actor );
421 application.SendNotification();
422 application.Render();
425 CreatePropertyMap( actor, map );
426 DALI_TEST_CHECK( !map.Empty() );
428 DALI_TEST_CHECK( NULL != map.Find( "type" ) );
429 DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION );
431 DALI_TEST_CHECK( NULL != map.Find( "actors" ) );
432 Property::Array children( map.Find( "actors")->Get< Property::Array >() );
433 DALI_TEST_CHECK( !children.Empty() );
434 Property::Map childMap( children[0].Get< Property::Map >() );
435 DALI_TEST_CHECK( !childMap.Empty() );
436 DALI_TEST_CHECK( childMap.Find( "type" ) );
437 DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "Layer", TEST_LOCATION );
439 application.GetScene().Remove( actor );
444 int UtcDaliScriptingGetEnumerationTemplates(void)
446 const Scripting::StringEnum myTable[] =
454 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
456 for ( unsigned int i = 0; i < myTableCount; ++i )
458 tet_printf("Checking: %s\n", myTable[ i ].string );
460 DALI_TEST_CHECK( GetEnumeration<int>( myTable[ i ].string, myTable, myTableCount, value ) );
461 DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION );
464 for ( unsigned int i = 0; i < myTableCount; ++i )
466 tet_printf("Checking: %d\n", myTable[ i ].value );
467 DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
473 int UtcDaliScriptingGetEnumerationNameN(void)
475 const char* value = GetEnumerationName( 10, NULL, 0 );
476 DALI_TEST_CHECK( NULL == value );
478 value = GetEnumerationName( 10, NULL, 1 );
479 DALI_TEST_CHECK( NULL == value );
484 int UtcDaliScriptingGetLinearEnumerationNameN(void)
486 const char* value = GetLinearEnumerationName( 10, NULL, 0 );
487 DALI_TEST_CHECK( NULL == value );
489 value = GetLinearEnumerationName( 10, NULL, 1 );
490 DALI_TEST_CHECK( NULL == value );
495 int UtcDaliScriptingGetEnumerationProperty(void)
498 * This test function performs the following checks:
499 * - An enum can be looked up from a Property::Value of type INTEGER.
500 * - An enum can be looked up from a Property::Value of type STRING.
501 * - An enum can NOT be looked up for other Property::Value types.
502 * - The return value is "true" if the property can be successfully converted AND it has changed.
503 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
504 * - The return value is "false" if the property can not be successfully converted.
505 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
508 // String to Enum property table to test with (equivalent to ones used within DALi).
509 const Dali::Scripting::StringEnum testTable[] = {
510 { "NONE", FaceCullingMode::NONE },
511 { "FRONT", FaceCullingMode::FRONT },
512 { "BACK", FaceCullingMode::BACK },
513 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
514 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
516 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
517 // Initialise to first element.
518 FaceCullingMode::Type result = FaceCullingMode::NONE;
519 // Set the input property value to a different value (to emulate a change).
520 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
522 // Perform the lookup.
523 bool returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
525 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
526 // Check the property could be converted.
527 DALI_TEST_CHECK( returnValue );
529 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
531 // Now emulate a property-set with the same value. false should be returned.
532 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
534 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
535 DALI_TEST_CHECK( !returnValue );
537 // The result should remain the same.
538 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
540 // TEST: An enum can be looked up from a Property::Value of type STRING.
541 // Set the input property value to a different value (to emulate a change).
542 Property::Value propertyValueString( "BACK" );
544 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
546 DALI_TEST_CHECK( returnValue );
548 // The result should remain the same.
549 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
551 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
553 DALI_TEST_CHECK( !returnValue );
555 // The result should remain the same.
556 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
558 // TEST: An enum can NOT be looked up for other Property::Value types.
559 Property::Value propertyValueBoolean( true );
561 returnValue = GetEnumerationProperty< FaceCullingMode::Type >( propertyValueBoolean, testTable, testTableCount, result );
563 // TEST: The return value is "false" if the property can not be successfully converted.
564 // Return value should be false as Property::Value was of an unsupported type for enum properties.
565 DALI_TEST_CHECK( !returnValue );
567 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
568 // The result should remain the same.
569 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
574 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
577 * This test function performs the following checks:
578 * - An enum can be looked up from a Property::Value of type INTEGER.
579 * - An enum can be looked up from a Property::Value of type STRING.
580 * - An enum can NOT be looked up from other Property::Value types.
581 * - The return value is "true" if the property can be successfully converted AND it has changed.
582 * - The return value is "false" if the property can not be successfully converted.
583 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
585 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
586 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
587 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
588 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
589 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
590 * - 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.
591 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
592 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
595 // String to Enum property table to test with (equivalent to ones used within DALi).
596 const Dali::Scripting::StringEnum testTable[] = {
597 { "NONE", FaceCullingMode::NONE },
598 { "FRONT", FaceCullingMode::FRONT },
599 { "BACK", FaceCullingMode::BACK },
600 { "FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK }
601 }; const unsigned int testTableCount = sizeof( testTable ) / sizeof( testTable[0] );
603 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
604 // Initialise to first element.
605 FaceCullingMode::Type result = FaceCullingMode::NONE;
606 // Set the input property value to a different value (to emulate a change).
607 Property::Value propertyValueInteger( FaceCullingMode::FRONT );
609 // Perform the lookup.
610 bool returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueInteger, testTable, testTableCount, result );
612 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
613 // Check the property could be converted.
614 DALI_TEST_CHECK( returnValue );
616 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::FRONT ), TEST_LOCATION );
618 // TEST: An enum can be looked up from a Property::Value of type STRING.
619 // Set the input property value to a different value (to emulate a change).
620 Property::Value propertyValueString( "BACK" );
622 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueString, testTable, testTableCount, result );
624 DALI_TEST_CHECK( returnValue );
626 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
628 // TEST: An enum can NOT be looked up from other Property::Value types.
629 Property::Value propertyValueVector( Vector3::ZERO );
631 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyValueVector, testTable, testTableCount, result );
633 // TEST: The return value is "false" if the property can not be successfully converted.
634 // Return value should be false as Property::Value was of an unsupported type for enum properties.
635 DALI_TEST_CHECK( !returnValue );
637 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
638 // The result should remain the same.
639 DALI_TEST_EQUALS( static_cast<int>( result ), static_cast<int>( FaceCullingMode::BACK ), TEST_LOCATION );
641 // Test PropertyArrays:
643 // Property array of 2 integers.
644 Property::Array propertyArrayIntegers;
645 propertyArrayIntegers.PushBack( FaceCullingMode::FRONT );
646 propertyArrayIntegers.PushBack( FaceCullingMode::BACK );
647 result = FaceCullingMode::NONE;
649 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayIntegers, testTable, testTableCount, result );
651 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
652 DALI_TEST_CHECK( returnValue );
653 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
654 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
656 // Property array of 2 strings.
657 Property::Array propertyArrayStrings;
658 propertyArrayStrings.PushBack( "FRONT" );
659 propertyArrayStrings.PushBack( "BACK" );
660 result = FaceCullingMode::NONE;
662 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayStrings, testTable, testTableCount, result );
664 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
665 DALI_TEST_CHECK( returnValue );
666 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
667 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
669 // Property array of an int and a string.
670 Property::Array propertyArrayMixed;
671 propertyArrayMixed.PushBack( FaceCullingMode::FRONT );
672 propertyArrayMixed.PushBack( "BACK" );
673 result = FaceCullingMode::NONE;
675 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayMixed, testTable, testTableCount, result );
677 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
678 DALI_TEST_CHECK( returnValue );
679 // 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.
680 DALI_TEST_CHECK( result == ( FaceCullingMode::FRONT | FaceCullingMode::BACK ) );
682 // Property array of an int and a string.
683 Property::Array propertyArrayInvalid;
684 propertyArrayInvalid.PushBack( FaceCullingMode::FRONT );
685 propertyArrayInvalid.PushBack( Vector3::ZERO );
687 // Set the initial value to non-zero, so we can test it does not change.
688 result = FaceCullingMode::FRONT_AND_BACK;
690 returnValue = GetBitmaskEnumerationProperty< FaceCullingMode::Type >( propertyArrayInvalid, testTable, testTableCount, result );
692 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
693 DALI_TEST_CHECK( !returnValue );
694 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
695 DALI_TEST_CHECK( result == FaceCullingMode::FRONT_AND_BACK );
700 int UtcDaliScriptingFindEnumIndexN(void)
702 const Scripting::StringEnum myTable[] =
710 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
711 DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION );
716 int UtcDaliScriptingEnumStringToIntegerP(void)
718 const Scripting::StringEnum myTable[] =
726 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
729 DALI_TEST_CHECK( EnumStringToInteger( "ONE", myTable, myTableCount, integerEnum ) );
731 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
734 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO", myTable, myTableCount, integerEnum ) );
735 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
737 DALI_TEST_CHECK( EnumStringToInteger( "ONE,,TWO", myTable, myTableCount, integerEnum ) );
738 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
740 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE", myTable, myTableCount, integerEnum ) );
741 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3), TEST_LOCATION );
743 DALI_TEST_CHECK( EnumStringToInteger( "ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum ) );
744 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
746 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE", myTable, myTableCount, integerEnum ) );
747 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2), TEST_LOCATION );
749 DALI_TEST_CHECK( EnumStringToInteger( "TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum ) );
750 DALI_TEST_EQUALS( integerEnum, (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5), TEST_LOCATION );
752 DALI_TEST_CHECK( EnumStringToInteger( "ONE,SEVEN", myTable, myTableCount, integerEnum ) );
753 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
755 DALI_TEST_CHECK( EnumStringToInteger( "ONE,", myTable, myTableCount, integerEnum ) );
756 DALI_TEST_EQUALS( integerEnum, (1<<1), TEST_LOCATION );
762 int UtcDaliScriptingEnumStringToIntegerN(void)
764 const Scripting::StringEnum myTable[] =
772 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
775 DALI_TEST_CHECK( !EnumStringToInteger( "Foo", myTable, myTableCount, integerEnum ) );
777 DALI_TEST_CHECK( !EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
779 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
781 DALI_TEST_CHECK( !EnumStringToInteger( ",ONE,SEVEN", myTable, myTableCount, integerEnum ) );
783 DALI_TEST_CHECK( !EnumStringToInteger( ",", myTable, myTableCount, integerEnum ) );
785 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", myTable, 0, integerEnum ) );
787 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );
792 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
794 const Scripting::StringEnum myTable[] =
801 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
804 DALI_TEST_CHECK( EnumStringToInteger( "", myTable, myTableCount, integerEnum ) );
805 DALI_TEST_EQUALS( integerEnum, 1, TEST_LOCATION );
810 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
812 const Scripting::StringEnum myTable[] =
819 const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
822 DALI_TEST_CHECK( !EnumStringToInteger( NULL, NULL, 0, integerEnum ) );
824 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, 0, integerEnum ) );
826 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, 0, integerEnum ) );
828 DALI_TEST_CHECK( !EnumStringToInteger( NULL, myTable, myTableCount, integerEnum ) );
830 DALI_TEST_CHECK( !EnumStringToInteger( "ONE", NULL, myTableCount, integerEnum ) );
832 DALI_TEST_EQUALS( integerEnum, 0, TEST_LOCATION );