+ // For coverage
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add( actor );
+ builder.AddActors( actor );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ actor.GetChildAt( 0 ).Unparent();
+
+ END_TEST;
+}
+
+#define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
+ { \
+ Property::Value* value = xMap->Find( xKey ); \
+ DALI_TEST_EQUALS( value==NULL, false, xLocation); \
+ if( value != NULL ) \
+ { \
+ DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
+ xType result; \
+ value->Get(result); \
+ DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
+ std::ostringstream oss; \
+ oss << "Animation element " << xKey << "= " << result << std::endl; \
+ tet_printf( oss.str().c_str() ); \
+ } \
+ else \
+ { \
+ tet_printf("Can't find map element " xKey "\n"); \
+ } \
+ }
+
+
+int UtcDaliBuilderMapping01(void)
+{
+ ToolkitTestApplication application;
+
+ const char* json =
+ "{\n"
+ " \"mappings\":\n"
+ " {\n"
+ " \"buttonPressFadeOut\":{\n"
+ " \"alphaFunction\":\"EASE_OUT\",\n"
+ " \"timePeriod\":{\n"
+ " \"delay\":0.0,\n"
+ " \"duration\":0.4\n"
+ " }\n"
+ " },\n"
+ " \"buttonPressFadeIn\":{\n"
+ " \"alphaFunction\":\"EASE_IN\",\n"
+ " \"timePeriod\":{\n"
+ " \"delay\":0.4,\n"
+ " \"duration\":0.5\n"
+ " }\n"
+ " },\n"
+ " \"transition:buttonPressed\":\n"
+ " [\n"
+ " {\n"
+ " \"target\": \"unselectedBackgroundRenderer\",\n"
+ " \"property\": \"opacity\",\n"
+ " \"value\": 0,\n"
+ " \"animator\":\"<buttonPressFadeOut>\"\n"
+ " }\n"
+ " ],\n"
+ " \"transition:buttonReleased\":\n"
+ " [\n"
+ " {\n"
+ " \"target\": \"unselectedBackgroundRenderer\",\n"
+ " \"property\": \"opacity\",\n"
+ " \"value\": 1,\n"
+ " \"animator\":\"<buttonPressFadeIn>\"\n"
+ " },\n"
+ " {\n"
+ " \"target\": \"unselectedForegroundRenderer\",\n"
+ " \"property\": \"scale\",\n"
+ " \"value\": [ 1, 1, 1 ],\n"
+ " \"animator\":\"<buttonPressFadeIn>\"\n"
+ " },\n"
+ " {\n"
+ " \"target\": \"selectedBackgroundRenderer\",\n"
+ " \"property\": \"opacity\",\n"
+ " \"value\": 0,\n"
+ " \"animator\": \"<buttonPressFadeOut>\"\n"
+ " },\n"
+ " {\n"
+ " \"target\": \"selectedForegroundRenderer\",\n"
+ " \"property\": \"scale\",\n"
+ " \"value\": [ 0, 0, 0 ],\n"
+ " \"animator\":\"<buttonPressFadeOut>\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"styles\":\n"
+ " {\n"
+ " \"testbutton\":\n"
+ " {\n"
+ " \"pressTransition\":\"<transition:buttonPressed>\",\n"
+ " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
+ " }\n"
+ " }\n"
+ "}\n";
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+
+ Test::TestButton testButton = Test::TestButton::New();
+ Stage::GetCurrent().Add( testButton );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
+
+ // Now check that it has loaded the transition correctly:
+ Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
+ DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
+ Property::Array* array = transition.GetArray();
+
+ DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
+ Property::Value element = array->GetElementAt(0);
+ DALI_TEST_CHECK( element.GetType() == Property::MAP );
+ Property::Map* map = element.GetMap();
+
+ CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
+
+ END_TEST;
+}
+
+
+int UtcDaliBuilderMappingCycleCheck(void)
+{
+ ToolkitTestApplication application;
+
+ std::string json(
+ "{\n"
+ " \"mappings\":\n"
+ " {\n"
+ " \"cyclicKey1\":\"<cyclicKey1>\",\n"
+ " \"cyclicKey2\":\"<cyclicKey3>\",\n"
+ " \"cyclicKey3\":\"<cyclicKey2>\",\n"
+ " \"FadeOut\":{\n"
+ " \"alphaFunction\":\"EASE_IN\",\n"
+ " \"timePeriod\":{\n"
+ " \"delay\":\"<cyclicKey3>\",\n"
+ " \"duration\":0.6\n"
+ " }\n"
+ " },\n"
+ " \"transition:buttonPressed\":\n"
+ " [\n"
+ " {\n"
+ " \"target\": \"<cyclicKey1>\",\n"
+ " \"property\": \"<cyclicKey2>\",\n"
+ " \"value\": 0,\n"
+ " \"animator\":\"<FadeOut>\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"styles\":\n"
+ " {\n"
+ " \"testbutton\":\n"
+ " {\n"
+ " \"pressTransition\":\"<transition:buttonPressed>\",\n"
+ " \"releaseTransition\":\"<cyclicKey2>\",\n"
+ " \"disabledTransition\":\"<cyclicKey3>\",\n"
+ " \"enabledTransition\":\"<unknownKey>\"\n"
+ " }\n"
+ " }\n"
+ "}\n");
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+
+ Test::TestButton testButton = Test::TestButton::New();
+ Stage::GetCurrent().Add( testButton );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
+
+ // Now check that it has loaded the transition correctly:
+ Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
+ DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
+ Property::Array* array = transition.GetArray();
+
+ DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
+ Property::Value element = array->GetElementAt(0);
+ DALI_TEST_CHECK( element.GetType() == Property::MAP );
+ Property::Map* map = element.GetMap();
+
+ CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
+ CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliBuilderTypeCasts(void)
+{
+ ToolkitTestApplication application;
+
+ std::string json(
+ "{"
+ "\"stage\":"
+ "[{"
+ "\"type\": \"Layer\","
+ "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
+ "\"position\": { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
+ "\"color\": { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
+ "\"sensitive\": { \"typeCast\":\"boolean\", \"value\":false },"
+ "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
+ "\"colorMode\": { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
+ "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
+ "\"padding\": { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
+ "}]"
+ "}"
+ );
+
+ Actor rootActor = Actor::New();
+ Stage::GetCurrent().Add( rootActor );
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+ builder.AddActors( rootActor );
+
+ application.SendNotification();
+ application.Render();
+
+ Actor createdActor = rootActor.GetChildAt( 0 );
+ DALI_TEST_EQUALS( createdActor.GetMaximumSize(), Vector2(100.0f,15.0f), TEST_LOCATION );
+ DALI_TEST_EQUALS( createdActor.GetCurrentPosition(), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
+ DALI_TEST_EQUALS( createdActor.GetCurrentColor(), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
+ DALI_TEST_EQUALS( createdActor.IsSensitive(), false, TEST_LOCATION );
+ DALI_TEST_EQUALS( createdActor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliBuilderBuilderControl(void)
+{
+ ToolkitTestApplication application;
+
+ std::string json(
+ "{"
+ "\"stage\":"
+ "[{"
+ "\"type\": \"BuilderControl\","
+ "\"integerProperty\": 10,"
+ "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
+ "\"matrixProperty\": [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
+ "\"noneProperty\": 10"
+ "}]"
+ "}"
+ );
+
+ Actor rootActor = Actor::New();
+ Stage::GetCurrent().Add( rootActor );
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+ builder.AddActors( rootActor );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliBuilderActionsWithParams(void)
+{
+ ToolkitTestApplication application;
+
+ // JSON with a quit event when the actor is touched
+ std::string json(
+ "{\n"
+ "\"stage\":\n"
+ "[\n"
+ " { \n"
+ " \"type\": \"ImageView\",\n"
+ " \"name\": \"image\",\n"
+ " \"size\": [100,100,1],\n"
+ " \"signals\": [{\n"
+ " \"name\": \"touch\",\n"
+ " \"action\": \"show\",\n"
+ " \"parameters\": {\n"
+ " \"property1\" : 10,\n"
+ " \"property2\" : [1,2],\n"
+ " \"property3\" : [1,2,3],\n"
+ " \"property4\" : [1,2,3,4]\n"
+ " }\n"
+ " }]\n"
+ " }\n"
+ "]\n"
+ "}\n"
+ );
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+ builder.AddActors( Stage::GetCurrent().GetRootLayer() );
+
+ DALI_TEST_CHECK( true ); // For Coverage
+
+ END_TEST;
+}
+
+int UtcDaliBuilderConfigurationP(void)
+{
+ ToolkitTestApplication application;
+
+ // JSON with a quit event when the actor is touched
+ std::string json(
+ "{\n"
+ " \"config\":\n"
+ " {\n"
+ " \"alwaysShowFocus\":true\n"
+ " }\n"
+ "}\n"
+ );
+
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+
+ Property::Map map = builder.GetConfigurations();
+
+ Dali::Property::Value* pValue = map.Find( "alwaysShowFocus" );
+
+ DALI_TEST_CHECK( pValue );
+
+ bool value = pValue->Get<bool>();
+
+ DALI_TEST_CHECK( value );
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64EncodingP(void)
+{
+ std::vector<uint32_t> data = { 0, 1, 2, 3, 4, 5, std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max() };
+
+ Property::Value value;
+ EncodeBase64PropertyData( value, data );
+
+ std::cout << "Max uint32_t:" << std::numeric_limits<uint32_t>::max() << std::endl;
+ std::cout << "Input data: ";
+ std::ostream_iterator<uint32_t> out_it (std::cout,", ");
+ std::copy ( data.begin(), data.end(), out_it );
+ std::cout << std::endl;
+
+ std::string output;
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output, "AAAAAAEAAAACAAAAAwAAAAQAAAAFAAAAAAAAAP////8", TEST_LOCATION );
+
+ std::cout << "Output data: " << output << std::endl;
+
+ END_TEST;
+}
+
+int UtcDaliBase64EncodingN(void)
+{
+ tet_infoline( "Test encoding an empty vector returns empty string" );
+ std::vector<uint32_t> data;
+
+ Property::Value value;
+ EncodeBase64PropertyData( value, data );
+
+ std::string output;
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), true, TEST_LOCATION );
+
+ END_TEST;
+}
+
+template <typename T>
+int b64l(std::vector<T>&data)
+{
+ auto lengthInBytes = 4*data.size();
+ return ceil( lengthInBytes * 1.33333f );
+}
+
+int UtcDaliBase64EncodingP02(void)
+{
+ tet_infoline( "Test encoding vectors of lengths m .. m+4 encode and decode back to the same length vectors" );
+
+ std::vector<uint32_t> testData;
+ for(int i=0; i<8; ++i ) // 8 chosen to stay within single string output
+ {
+ testData.push_back(i);
+ }
+ Property::Value value;
+ EncodeBase64PropertyData( value, testData );
+
+ std::string output;
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
+ DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
+
+ std::vector<uint32_t> outData;
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+ DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
+
+ // n+1
+ testData.push_back( 12345 );
+ EncodeBase64PropertyData( value, testData );
+
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
+ DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
+
+ outData.clear();
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+ DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
+
+ // n+2
+ testData.push_back( 67890 );
+ EncodeBase64PropertyData( value, testData );
+
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
+ DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
+
+ outData.clear();
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+ DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
+
+ // n+3
+ testData.push_back( -1 );
+ EncodeBase64PropertyData( value, testData );
+
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
+ DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
+
+ outData.clear();
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+ DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
+
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64EncodingP03(void)
+{
+ tet_infoline( "Test encoding a vector of length 12 has output within single string" );
+
+ std::vector<uint32_t> testData;
+ for(int i=0; i<12; ++i )
+ {
+ testData.push_back(i);
+ }
+ Property::Value value;
+ EncodeBase64PropertyData( value, testData );
+
+ std::string output;
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
+ DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
+
+ std::vector<uint32_t> outData;
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64EncodingP04(void)
+{
+ tet_infoline( "Test encoding a vector of length 13 has output split over 2 strings" );
+
+ std::vector<uint32_t> testData;
+ for(int i=0; i<13; ++i )
+ {
+ testData.push_back(i);
+ }
+ Property::Value value;
+ EncodeBase64PropertyData( value, testData );
+
+ auto array = value.GetArray();
+ DALI_TEST_CHECK( array );
+
+ DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
+
+ std::vector<uint32_t> outData;
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64EncodingP05(void)
+{
+ tet_infoline( "Test encoding a vector of length 24 has output split over 2 strings" );
+
+ std::vector<uint32_t> testData;
+ for(int i=0; i<24; ++i )
+ {
+ testData.push_back(i);
+ }
+ Property::Value value;
+ EncodeBase64PropertyData( value, testData );
+
+ auto array = value.GetArray();
+ DALI_TEST_CHECK( array );
+
+ DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
+
+ std::vector<uint32_t> outData;
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64EncodingP06(void)
+{
+ tet_infoline( "Test encoding a vector of arbitrary length decodes OK." );
+
+ std::vector<uint32_t> testData;
+ for(int i=0; i<97; ++i )
+ {
+ testData.push_back(i);
+ }
+ Property::Value value;
+ EncodeBase64PropertyData( value, testData );
+
+ auto array = value.GetArray();
+ DALI_TEST_CHECK( array );
+
+ std::vector<uint32_t> outData;
+ DecodeBase64PropertyData( value, outData );
+ DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliBase64DecodingN01(void)
+{
+ tet_infoline( "Test decoding empty string results in empty data" );
+
+ Property::Value value("");
+ std::vector<uint32_t> outputData;
+ DecodeBase64PropertyData( value, outputData);
+ DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
+ END_TEST;
+}
+
+
+int UtcDaliBase64DecodingN02(void)
+{
+ tet_infoline( "Test decoding array with non-string values results in empty data" );
+
+ Property::Array array;
+ array.Resize(2);
+ array[0] = "Stuff, things";
+ array[1] = 1;
+ Property::Value value(array);
+
+ std::vector<uint32_t> outputData;
+ DecodeBase64PropertyData( value, outputData);
+ DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliBase64DecodingP01(void)
+{
+ tet_infoline( "Test decoding string of known data gives expected result");
+
+ std::string testInput("//////7+/v4DAgEA");
+ std::vector<uint32_t> expectedResults = { 0xffffffff, 0xfefefefe, 0x00010203 };
+
+ std::vector<uint32_t> outputData;
+ DecodeBase64PropertyData(Property::Value(testInput), outputData);
+
+ DALI_TEST_EQUALS( std::equal( expectedResults.begin(), expectedResults.end(), outputData.begin() ), true,
+ TEST_LOCATION );
+