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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/scripting/scripting.h>
20 #include <dali/public-api/dali-core.h>
26 using namespace Dali::Scripting;
30 const StringEnum COLOR_MODE_VALUES[] =
32 {"USE_OWN_COLOR", USE_OWN_COLOR},
33 {"USE_PARENT_COLOR", USE_PARENT_COLOR},
34 {"USE_OWN_MULTIPLY_PARENT_COLOR", USE_OWN_MULTIPLY_PARENT_COLOR},
35 {"USE_OWN_MULTIPLY_PARENT_ALPHA", USE_OWN_MULTIPLY_PARENT_ALPHA},
37 const unsigned int COLOR_MODE_VALUES_COUNT = sizeof(COLOR_MODE_VALUES) / sizeof(COLOR_MODE_VALUES[0]);
39 const StringEnum DRAW_MODE_VALUES[] =
41 {"NORMAL", DrawMode::NORMAL},
42 {"OVERLAY_2D", DrawMode::OVERLAY_2D}};
43 const unsigned int DRAW_MODE_VALUES_COUNT = sizeof(DRAW_MODE_VALUES) / sizeof(DRAW_MODE_VALUES[0]);
45 ////////////////////////////////////////////////////////////////////////////////
46 // Helpers for string to enum comparisons for Image and Image loading parameters
47 ////////////////////////////////////////////////////////////////////////////////
50 * Template to check enumerations of type T, with a class of type X
52 template<typename T, typename X>
54 Property::Map& map, // The map used to create instance of type X
55 const char* const keyName, // the name of the key to iterate through
56 const StringEnum* values, // An array of string values
57 unsigned int num, // Number of items in the array
58 T (X::*method)() const, // The member method of X to call to get the enum
59 X (*creator)(const Property::Value&) // The method which creates an instance of type X
62 // get the key reference so we can change its value
63 Property::Value* value = map.Find(keyName);
64 for(unsigned int i = 0; i < num; ++i)
66 *value = values[i].string;
67 tet_printf("Checking: %s: %s\n", keyName, values[i].string);
68 X instance = creator(map);
69 DALI_TEST_EQUALS(values[i].value, (int)(instance.*method)(), TEST_LOCATION);
73 //////////////////////////////////////////////////////////////////////////////
74 // Helpers for string to enum comparisons for Actor to Property::Map
75 //////////////////////////////////////////////////////////////////////////////
78 * Template to check enumerations of type T
82 const char* const keyName, // The name of the key to check
83 TestApplication& application, // Reference to the application class
84 const StringEnum* values, // An array of string values
85 unsigned int num, // Number of items in the array
86 void (Actor::*method)(T) // The Actor member method to set the enumeration
89 for(unsigned int i = 0; i < num; ++i)
91 tet_printf("Checking: %s: %s\n", keyName, values[i].string);
93 Actor actor = Actor::New();
94 (actor.*method)((T)values[i].value);
96 application.GetScene().Add(actor);
97 application.SendNotification();
101 CreatePropertyMap(actor, map);
103 DALI_TEST_CHECK(0 < map.Count());
104 DALI_TEST_CHECK(NULL != map.Find(keyName));
105 DALI_TEST_EQUALS(map.Find(keyName)->Get<std::string>(), values[i].string, TEST_LOCATION);
107 application.GetScene().Remove(actor);
111 //////////////////////////////////////////////////////////////////////////////
115 int UtcDaliValueFromEnum(void)
124 Property::Value v1 = T::V1;
125 Property::Value v2 = T::V2;
128 DALI_TEST_CHECK(v1.Get<T>() == T::V1);
129 DALI_TEST_CHECK(v2.Get<T>() == T::V2);
130 DALI_TEST_CHECK(v1.Get(t) && t == T::V1);
131 DALI_TEST_CHECK(v2.Get(t) && t == T::V2);
136 int UtcDaliScriptingNewActorNegative(void)
138 TestApplication application;
142 Actor handle = NewActor(Property::Map());
143 DALI_TEST_CHECK(!handle);
146 // Map with only properties
149 map["parentOrigin"] = ParentOrigin::TOP_CENTER;
150 map["anchorPoint"] = AnchorPoint::TOP_CENTER;
151 Actor handle = NewActor(map);
152 DALI_TEST_CHECK(!handle);
155 // Add some signals to the map, we should have no signal connections as its not yet supported
158 map["type"] = "Actor";
159 map["signals"] = Property::MAP;
160 Actor handle = NewActor(map);
161 DALI_TEST_CHECK(handle);
162 DALI_TEST_CHECK(!handle.WheelEventSignal().GetConnectionCount());
163 DALI_TEST_CHECK(!handle.OffSceneSignal().GetConnectionCount());
164 DALI_TEST_CHECK(!handle.OnSceneSignal().GetConnectionCount());
165 DALI_TEST_CHECK(!handle.TouchedSignal().GetConnectionCount());
170 int UtcDaliScriptingNewActorProperties(void)
172 TestApplication application;
175 map["type"] = "Actor";
176 map["size"] = Vector3::ONE;
177 map["position"] = Vector3::XAXIS;
178 map["scale"] = Vector3::ONE;
179 map["visible"] = false;
180 map["color"] = Color::MAGENTA;
181 map["name"] = "MyActor";
182 map["colorMode"] = "USE_PARENT_COLOR";
183 map["sensitive"] = false;
184 map["leaveRequired"] = true;
185 map["drawMode"] = "OVERLAY_2D";
186 map["inheritOrientation"] = false;
187 map["inheritScale"] = false;
189 // Default properties
191 Actor handle = NewActor(map);
192 DALI_TEST_CHECK(handle);
194 application.GetScene().Add(handle);
195 application.SendNotification();
196 application.Render();
198 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::SIZE), Vector3::ONE, TEST_LOCATION);
199 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3::XAXIS, TEST_LOCATION);
200 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::SCALE), Vector3::ONE, TEST_LOCATION);
201 DALI_TEST_EQUALS(handle.GetCurrentProperty<bool>(Actor::Property::VISIBLE), false, TEST_LOCATION);
202 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::MAGENTA, TEST_LOCATION);
203 DALI_TEST_EQUALS(handle.GetProperty<std::string>(Actor::Property::NAME), "MyActor", TEST_LOCATION);
204 DALI_TEST_EQUALS(handle.GetProperty<ColorMode>(Actor::Property::COLOR_MODE), USE_PARENT_COLOR, TEST_LOCATION);
205 DALI_TEST_EQUALS(handle.GetProperty<bool>(Actor::Property::SENSITIVE), false, TEST_LOCATION);
206 DALI_TEST_EQUALS(handle.GetProperty<bool>(Actor::Property::LEAVE_REQUIRED), true, TEST_LOCATION);
207 DALI_TEST_EQUALS(handle.GetProperty<DrawMode::Type>(Actor::Property::DRAW_MODE), DrawMode::OVERLAY_2D, TEST_LOCATION);
208 DALI_TEST_EQUALS(handle.GetProperty<bool>(Actor::Property::INHERIT_ORIENTATION), false, TEST_LOCATION);
209 DALI_TEST_EQUALS(handle.GetProperty<bool>(Actor::Property::INHERIT_SCALE), false, TEST_LOCATION);
211 application.GetScene().Remove(handle);
214 // Check Anchor point and parent origin vector3s
215 map["parentOrigin"] = ParentOrigin::TOP_CENTER;
216 map["anchorPoint"] = AnchorPoint::TOP_LEFT;
218 Actor handle = NewActor(map);
219 DALI_TEST_CHECK(handle);
221 application.GetScene().Add(handle);
222 application.SendNotification();
223 application.Render();
225 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::PARENT_ORIGIN), ParentOrigin::TOP_CENTER, TEST_LOCATION);
226 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT), AnchorPoint::TOP_LEFT, TEST_LOCATION);
228 application.GetScene().Remove(handle);
231 // Check Anchor point and parent origin STRINGS
232 map["parentOrigin"] = "TOP_LEFT";
233 map["anchorPoint"] = "CENTER_LEFT";
235 Actor handle = NewActor(map);
236 DALI_TEST_CHECK(handle);
238 application.GetScene().Add(handle);
239 application.SendNotification();
240 application.Render();
242 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::PARENT_ORIGIN), ParentOrigin::TOP_LEFT, TEST_LOCATION);
243 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT), AnchorPoint::CENTER_LEFT, TEST_LOCATION);
245 application.GetScene().Remove(handle);
250 int UtcDaliScriptingNewAnimation(void)
252 TestApplication application;
255 map["actor"] = "Actor1";
256 map["property"] = "color";
257 map["value"] = Color::MAGENTA;
258 map["alphaFunction"] = "EASE_IN_OUT";
260 Property::Map timePeriod;
261 timePeriod["delay"] = 0.5f;
262 timePeriod["duration"] = 1.0f;
263 map["timePeriod"] = timePeriod;
265 Dali::AnimationData data;
266 Scripting::NewAnimation(map, data);
268 Actor actor = Actor::New();
269 actor.SetProperty(Actor::Property::NAME, "Actor1");
270 actor.SetProperty(Actor::Property::COLOR, Color::CYAN);
271 application.GetScene().Add(actor);
273 Animation anim = data.CreateAnimation(actor, 0.5f);
276 application.SendNotification();
277 application.Render(0);
278 application.Render(500); // Start animation
279 application.Render(500); // Halfway thru anim
280 application.SendNotification();
281 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), (Color::MAGENTA + Color::CYAN) * 0.5f, TEST_LOCATION);
283 application.Render(500); // Halfway thru anim
284 application.SendNotification();
285 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::MAGENTA, TEST_LOCATION);
290 int UtcDaliScriptingNewActorChildren(void)
292 TestApplication application;
295 map["type"] = "Actor";
296 map["position"] = Vector3::XAXIS;
298 Property::Map child1Map;
299 child1Map["type"] = "Layer";
300 child1Map["position"] = Vector3::YAXIS;
302 Property::Array childArray;
303 childArray.PushBack(child1Map);
304 map["actors"] = childArray;
307 Actor handle = NewActor(map);
308 DALI_TEST_CHECK(handle);
310 application.GetScene().Add(handle);
311 application.SendNotification();
312 application.Render();
314 DALI_TEST_EQUALS(handle.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3::XAXIS, TEST_LOCATION);
315 DALI_TEST_EQUALS(handle.GetChildCount(), 1u, TEST_LOCATION);
317 Actor child1 = handle.GetChildAt(0);
318 DALI_TEST_CHECK(child1);
319 DALI_TEST_CHECK(Layer::DownCast(child1));
320 DALI_TEST_EQUALS(child1.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3::YAXIS, TEST_LOCATION);
321 DALI_TEST_EQUALS(child1.GetChildCount(), 0u, TEST_LOCATION);
323 application.GetScene().Remove(handle);
327 int UtcDaliScriptingCreatePropertyMapActor(void)
329 TestApplication application;
333 Actor actor = Actor::New();
336 CreatePropertyMap(actor, map);
337 DALI_TEST_CHECK(!map.Empty());
338 DALI_TEST_CHECK(NULL != map.Find("type"));
339 DALI_TEST_EQUALS(map.Find("type")->Get<std::string>(), "Actor", TEST_LOCATION);
341 application.GetScene().Remove(actor);
346 Actor actor = Layer::New();
349 CreatePropertyMap(actor, map);
350 DALI_TEST_CHECK(!map.Empty());
351 DALI_TEST_CHECK(NULL != map.Find("type"));
352 DALI_TEST_EQUALS(map.Find("type")->Get<std::string>(), "Layer", TEST_LOCATION);
354 application.GetScene().Remove(actor);
357 // Default properties
359 Actor actor = Actor::New();
360 actor.SetProperty(Actor::Property::SIZE, Vector3::ONE);
361 actor.SetProperty(Actor::Property::POSITION, Vector3::XAXIS);
362 actor.SetProperty(Actor::Property::SCALE, Vector3::ZAXIS);
363 actor.SetProperty(Actor::Property::VISIBLE, false);
364 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
365 actor.SetProperty(Actor::Property::NAME, "MyActor");
366 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT);
367 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
368 actor.SetProperty(Actor::Property::SENSITIVE, false);
369 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
370 actor.SetProperty(Actor::Property::INHERIT_ORIENTATION, false);
371 actor.SetProperty(Actor::Property::INHERIT_SCALE, false);
372 actor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3::ONE);
374 application.GetScene().Add(actor);
375 application.SendNotification();
376 application.Render();
379 CreatePropertyMap(actor, map);
381 DALI_TEST_CHECK(!map.Empty());
382 DALI_TEST_CHECK(NULL != map.Find("size"));
383 DALI_TEST_EQUALS(map.Find("size")->Get<Vector3>(), Vector3::ONE, TEST_LOCATION);
384 DALI_TEST_CHECK(NULL != map.Find("position"));
385 DALI_TEST_EQUALS(map.Find("position")->Get<Vector3>(), Vector3::XAXIS, TEST_LOCATION);
386 DALI_TEST_CHECK(NULL != map.Find("scale"));
387 DALI_TEST_EQUALS(map.Find("scale")->Get<Vector3>(), Vector3::ZAXIS, TEST_LOCATION);
388 DALI_TEST_CHECK(NULL != map.Find("visible"));
389 DALI_TEST_EQUALS(map.Find("visible")->Get<bool>(), false, TEST_LOCATION);
390 DALI_TEST_CHECK(NULL != map.Find("color"));
391 DALI_TEST_EQUALS(map.Find("color")->Get<Vector4>(), Color::MAGENTA, TEST_LOCATION);
392 DALI_TEST_CHECK(NULL != map.Find("name"));
393 DALI_TEST_EQUALS(map.Find("name")->Get<std::string>(), "MyActor", TEST_LOCATION);
394 DALI_TEST_CHECK(NULL != map.Find("anchorPoint"));
395 DALI_TEST_EQUALS(map.Find("anchorPoint")->Get<Vector3>(), AnchorPoint::CENTER_LEFT, TEST_LOCATION);
396 DALI_TEST_CHECK(NULL != map.Find("parentOrigin"));
397 DALI_TEST_EQUALS(map.Find("parentOrigin")->Get<Vector3>(), ParentOrigin::TOP_RIGHT, TEST_LOCATION);
398 DALI_TEST_CHECK(NULL != map.Find("sensitive"));
399 DALI_TEST_EQUALS(map.Find("sensitive")->Get<bool>(), false, TEST_LOCATION);
400 DALI_TEST_CHECK(NULL != map.Find("leaveRequired"));
401 DALI_TEST_EQUALS(map.Find("leaveRequired")->Get<bool>(), true, TEST_LOCATION);
402 DALI_TEST_CHECK(NULL != map.Find("inheritOrientation"));
403 DALI_TEST_EQUALS(map.Find("inheritOrientation")->Get<bool>(), false, TEST_LOCATION);
404 DALI_TEST_CHECK(NULL != map.Find("inheritScale"));
405 DALI_TEST_EQUALS(map.Find("inheritScale")->Get<bool>(), false, TEST_LOCATION);
406 DALI_TEST_CHECK(NULL != map.Find("sizeModeFactor"));
407 DALI_TEST_EQUALS(map.Find("sizeModeFactor")->Get<Vector3>(), Vector3::ONE, TEST_LOCATION);
409 application.GetScene().Remove(actor);
414 Actor actor = Actor::New();
415 Actor child = Layer::New();
418 application.GetScene().Add(actor);
419 application.SendNotification();
420 application.Render();
423 CreatePropertyMap(actor, map);
424 DALI_TEST_CHECK(!map.Empty());
426 DALI_TEST_CHECK(NULL != map.Find("type"));
427 DALI_TEST_EQUALS(map.Find("type")->Get<std::string>(), "Actor", TEST_LOCATION);
429 DALI_TEST_CHECK(NULL != map.Find("actors"));
430 Property::Array children(map.Find("actors")->Get<Property::Array>());
431 DALI_TEST_CHECK(!children.Empty());
432 Property::Map childMap(children[0].Get<Property::Map>());
433 DALI_TEST_CHECK(!childMap.Empty());
434 DALI_TEST_CHECK(childMap.Find("type"));
435 DALI_TEST_EQUALS(childMap.Find("type")->Get<std::string>(), "Layer", TEST_LOCATION);
437 application.GetScene().Remove(actor);
442 int UtcDaliScriptingGetEnumerationTemplates(void)
444 const Scripting::StringEnum myTable[] =
452 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
454 for(unsigned int i = 0; i < myTableCount; ++i)
456 tet_printf("Checking: %s\n", myTable[i].string);
458 DALI_TEST_CHECK(GetEnumeration<int>(myTable[i].string, myTable, myTableCount, value));
459 DALI_TEST_EQUALS(myTable[i].value, value, TEST_LOCATION);
462 for(unsigned int i = 0; i < myTableCount; ++i)
464 tet_printf("Checking: %d\n", myTable[i].value);
465 DALI_TEST_EQUALS(myTable[i].string, GetEnumerationName(myTable[i].value, myTable, myTableCount), TEST_LOCATION);
471 int UtcDaliScriptingGetEnumerationNameN(void)
473 const char* value = GetEnumerationName(10, NULL, 0);
474 DALI_TEST_CHECK(NULL == value);
476 value = GetEnumerationName(10, NULL, 1);
477 DALI_TEST_CHECK(NULL == value);
482 int UtcDaliScriptingGetLinearEnumerationNameN(void)
484 const char* value = GetLinearEnumerationName(10, NULL, 0);
485 DALI_TEST_CHECK(NULL == value);
487 value = GetLinearEnumerationName(10, NULL, 1);
488 DALI_TEST_CHECK(NULL == value);
493 int UtcDaliScriptingGetEnumerationProperty(void)
496 * This test function performs the following checks:
497 * - An enum can be looked up from a Property::Value of type INTEGER.
498 * - An enum can be looked up from a Property::Value of type STRING.
499 * - An enum can NOT be looked up for other Property::Value types.
500 * - The return value is "true" if the property can be successfully converted AND it has changed.
501 * - The return value is "false" if the property can be successfully converted BUT it has NOT changed.
502 * - The return value is "false" if the property can not be successfully converted.
503 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
506 // String to Enum property table to test with (equivalent to ones used within DALi).
507 const Dali::Scripting::StringEnum testTable[] = {
508 {"NONE", FaceCullingMode::NONE},
509 {"FRONT", FaceCullingMode::FRONT},
510 {"BACK", FaceCullingMode::BACK},
511 {"FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK}};
512 const unsigned int testTableCount = sizeof(testTable) / sizeof(testTable[0]);
514 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
515 // Initialise to first element.
516 FaceCullingMode::Type result = FaceCullingMode::NONE;
517 // Set the input property value to a different value (to emulate a change).
518 Property::Value propertyValueInteger(FaceCullingMode::FRONT);
520 // Perform the lookup.
521 bool returnValue = GetEnumerationProperty<FaceCullingMode::Type>(propertyValueInteger, testTable, testTableCount, result);
523 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
524 // Check the property could be converted.
525 DALI_TEST_CHECK(returnValue);
527 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::FRONT), TEST_LOCATION);
529 // Now emulate a property-set with the same value. false should be returned.
530 returnValue = GetEnumerationProperty<FaceCullingMode::Type>(propertyValueInteger, testTable, testTableCount, result);
532 // TEST: The return value is "false" if the property can be successfully converted BUT it has NOT changed.
533 DALI_TEST_CHECK(!returnValue);
535 // The result should remain the same.
536 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::FRONT), TEST_LOCATION);
538 // TEST: An enum can be looked up from a Property::Value of type STRING.
539 // Set the input property value to a different value (to emulate a change).
540 Property::Value propertyValueString("BACK");
542 returnValue = GetEnumerationProperty<FaceCullingMode::Type>(propertyValueString, testTable, testTableCount, result);
544 DALI_TEST_CHECK(returnValue);
546 // The result should remain the same.
547 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::BACK), TEST_LOCATION);
549 returnValue = GetEnumerationProperty<FaceCullingMode::Type>(propertyValueString, testTable, testTableCount, result);
551 DALI_TEST_CHECK(!returnValue);
553 // The result should remain the same.
554 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::BACK), TEST_LOCATION);
556 // TEST: An enum can NOT be looked up for other Property::Value types.
557 Property::Value propertyValueBoolean(true);
559 returnValue = GetEnumerationProperty<FaceCullingMode::Type>(propertyValueBoolean, testTable, testTableCount, result);
561 // TEST: The return value is "false" if the property can not be successfully converted.
562 // Return value should be false as Property::Value was of an unsupported type for enum properties.
563 DALI_TEST_CHECK(!returnValue);
565 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
566 // The result should remain the same.
567 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::BACK), TEST_LOCATION);
572 int UtcDaliScriptingGetBitmaskEnumerationProperty(void)
575 * This test function performs the following checks:
576 * - An enum can be looked up from a Property::Value of type INTEGER.
577 * - An enum can be looked up from a Property::Value of type STRING.
578 * - An enum can NOT be looked up from other Property::Value types.
579 * - The return value is "true" if the property can be successfully converted AND it has changed.
580 * - The return value is "false" if the property can not be successfully converted.
581 * - The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
583 * - The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
584 * - The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
585 * - The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
586 * - The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
587 * - The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
588 * - 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.
589 * - The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
590 * - The result value when checking an array with an INTEGER and a Vector3 is unchanged.
593 // String to Enum property table to test with (equivalent to ones used within DALi).
594 const Dali::Scripting::StringEnum testTable[] = {
595 {"NONE", FaceCullingMode::NONE},
596 {"FRONT", FaceCullingMode::FRONT},
597 {"BACK", FaceCullingMode::BACK},
598 {"FRONT_AND_BACK", FaceCullingMode::FRONT_AND_BACK}};
599 const unsigned int testTableCount = sizeof(testTable) / sizeof(testTable[0]);
601 // TEST: An enum can be looked up from a Property::Value of type INTEGER.
602 // Initialise to first element.
603 FaceCullingMode::Type result = FaceCullingMode::NONE;
604 // Set the input property value to a different value (to emulate a change).
605 Property::Value propertyValueInteger(FaceCullingMode::FRONT);
607 // Perform the lookup.
608 bool returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyValueInteger, testTable, testTableCount, result);
610 // TEST: The return value is "true" if the property can be successfully converted AND it has changed
611 // Check the property could be converted.
612 DALI_TEST_CHECK(returnValue);
614 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::FRONT), TEST_LOCATION);
616 // TEST: An enum can be looked up from a Property::Value of type STRING.
617 // Set the input property value to a different value (to emulate a change).
618 Property::Value propertyValueString("BACK");
620 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyValueString, testTable, testTableCount, result);
622 DALI_TEST_CHECK(returnValue);
624 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::BACK), TEST_LOCATION);
626 // TEST: An enum can NOT be looked up from other Property::Value types.
627 Property::Value propertyValueVector(Vector3::ZERO);
629 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyValueVector, testTable, testTableCount, result);
631 // TEST: The return value is "false" if the property can not be successfully converted.
632 // Return value should be false as Property::Value was of an unsupported type for enum properties.
633 DALI_TEST_CHECK(!returnValue);
635 // TEST: The result value is only updated if the return value is "true" (IE. successful conversion and property value has changed).
636 // The result should remain the same.
637 DALI_TEST_EQUALS(static_cast<int>(result), static_cast<int>(FaceCullingMode::BACK), TEST_LOCATION);
639 // Test PropertyArrays:
641 // Property array of 2 integers.
642 Property::Array propertyArrayIntegers;
643 propertyArrayIntegers.PushBack(FaceCullingMode::FRONT);
644 propertyArrayIntegers.PushBack(FaceCullingMode::BACK);
645 result = FaceCullingMode::NONE;
647 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyArrayIntegers, testTable, testTableCount, result);
649 // TEST: The return value when checking an array with 2 INTEGERS is "true" if the properties can be successfully converted.
650 DALI_TEST_CHECK(returnValue);
651 // TEST: The result value when checking an array with 2 INTEGERS is the ORd value of the 2 integers.
652 DALI_TEST_CHECK(result == (FaceCullingMode::FRONT | FaceCullingMode::BACK));
654 // Property array of 2 strings.
655 Property::Array propertyArrayStrings;
656 propertyArrayStrings.PushBack("FRONT");
657 propertyArrayStrings.PushBack("BACK");
658 result = FaceCullingMode::NONE;
660 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyArrayStrings, testTable, testTableCount, result);
662 // TEST: The return value when checking an array with 2 STRINGS is "true" if the properties can be successfully converted.
663 DALI_TEST_CHECK(returnValue);
664 // TEST: The result value when checking an array with 2 STRINGS is the ORd value of the 2 integer equivalents of the strings.
665 DALI_TEST_CHECK(result == (FaceCullingMode::FRONT | FaceCullingMode::BACK));
667 // Property array of an int and a string.
668 Property::Array propertyArrayMixed;
669 propertyArrayMixed.PushBack(FaceCullingMode::FRONT);
670 propertyArrayMixed.PushBack("BACK");
671 result = FaceCullingMode::NONE;
673 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyArrayMixed, testTable, testTableCount, result);
675 // TEST: The return value when checking an array with an INTEGER and a STRING is "true" if the properties can be successfully converted.
676 DALI_TEST_CHECK(returnValue);
677 // 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.
678 DALI_TEST_CHECK(result == (FaceCullingMode::FRONT | FaceCullingMode::BACK));
680 // Property array of an int and a string.
681 Property::Array propertyArrayInvalid;
682 propertyArrayInvalid.PushBack(FaceCullingMode::FRONT);
683 propertyArrayInvalid.PushBack(Vector3::ZERO);
685 // Set the initial value to non-zero, so we can test it does not change.
686 result = FaceCullingMode::FRONT_AND_BACK;
688 returnValue = GetBitmaskEnumerationProperty<FaceCullingMode::Type>(propertyArrayInvalid, testTable, testTableCount, result);
690 // TEST: The return value when checking an array with an INTEGER and a Vector3 is "false" as the properties can not be successfully converted.
691 DALI_TEST_CHECK(!returnValue);
692 // TEST: The result value when checking an array with an INTEGER and a Vector3 is unchanged.
693 DALI_TEST_CHECK(result == FaceCullingMode::FRONT_AND_BACK);
698 int UtcDaliScriptingFindEnumIndexN(void)
700 const Scripting::StringEnum myTable[] =
708 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
709 DALI_TEST_EQUALS(myTableCount, FindEnumIndex("Foo", myTable, myTableCount), TEST_LOCATION);
714 int UtcDaliScriptingEnumStringToIntegerP(void)
716 const Scripting::StringEnum myTable[] =
724 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
727 DALI_TEST_CHECK(EnumStringToInteger("ONE", myTable, myTableCount, integerEnum));
729 DALI_TEST_EQUALS(integerEnum, (1 << 1), TEST_LOCATION);
732 DALI_TEST_CHECK(EnumStringToInteger("ONE,TWO", myTable, myTableCount, integerEnum));
733 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2), TEST_LOCATION);
735 DALI_TEST_CHECK(EnumStringToInteger("ONE,,TWO", myTable, myTableCount, integerEnum));
736 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2), TEST_LOCATION);
738 DALI_TEST_CHECK(EnumStringToInteger("ONE,TWO,THREE", myTable, myTableCount, integerEnum));
739 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2) | (1 << 3), TEST_LOCATION);
741 DALI_TEST_CHECK(EnumStringToInteger("ONE,TWO,THREE,FOUR,FIVE", myTable, myTableCount, integerEnum));
742 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5), TEST_LOCATION);
744 DALI_TEST_CHECK(EnumStringToInteger("TWO,ONE", myTable, myTableCount, integerEnum));
745 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2), TEST_LOCATION);
747 DALI_TEST_CHECK(EnumStringToInteger("TWO,ONE,FOUR,THREE,FIVE", myTable, myTableCount, integerEnum));
748 DALI_TEST_EQUALS(integerEnum, (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5), TEST_LOCATION);
750 DALI_TEST_CHECK(EnumStringToInteger("ONE,SEVEN", myTable, myTableCount, integerEnum));
751 DALI_TEST_EQUALS(integerEnum, (1 << 1), TEST_LOCATION);
753 DALI_TEST_CHECK(EnumStringToInteger("ONE,", myTable, myTableCount, integerEnum));
754 DALI_TEST_EQUALS(integerEnum, (1 << 1), TEST_LOCATION);
759 int UtcDaliScriptingEnumStringToIntegerN(void)
761 const Scripting::StringEnum myTable[] =
769 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
772 DALI_TEST_CHECK(!EnumStringToInteger("Foo", myTable, myTableCount, integerEnum));
774 DALI_TEST_CHECK(!EnumStringToInteger("", myTable, myTableCount, integerEnum));
776 DALI_TEST_CHECK(!EnumStringToInteger(",", myTable, myTableCount, integerEnum));
778 DALI_TEST_CHECK(!EnumStringToInteger(",ONE,SEVEN", myTable, myTableCount, integerEnum));
780 DALI_TEST_CHECK(!EnumStringToInteger(",", myTable, myTableCount, integerEnum));
782 DALI_TEST_CHECK(!EnumStringToInteger("ONE", myTable, 0, integerEnum));
784 DALI_TEST_EQUALS(integerEnum, 0, TEST_LOCATION);
789 int UtcDaliScriptingEnumStringToIntegerInvalidEnumP(void)
791 const Scripting::StringEnum myTable[] =
798 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
801 DALI_TEST_CHECK(EnumStringToInteger("", myTable, myTableCount, integerEnum));
802 DALI_TEST_EQUALS(integerEnum, 1, TEST_LOCATION);
807 int UtcDaliScriptingEnumStringToIntegerInvalidEnumN(void)
809 const Scripting::StringEnum myTable[] =
816 const unsigned int myTableCount = sizeof(myTable) / sizeof(myTable[0]);
819 DALI_TEST_CHECK(!EnumStringToInteger(NULL, NULL, 0, integerEnum));
821 DALI_TEST_CHECK(!EnumStringToInteger("ONE", NULL, 0, integerEnum));
823 DALI_TEST_CHECK(!EnumStringToInteger(NULL, myTable, 0, integerEnum));
825 DALI_TEST_CHECK(!EnumStringToInteger(NULL, myTable, myTableCount, integerEnum));
827 DALI_TEST_CHECK(!EnumStringToInteger("ONE", NULL, myTableCount, integerEnum));
829 DALI_TEST_EQUALS(integerEnum, 0, TEST_LOCATION);