(GCC 6.2) Remove unused functions from automated-tests
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Builder.cpp
index 32946a0..cb84952 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 using namespace Dali;
 using namespace Toolkit;
 
+namespace BuilderControlProperty
+{
+
+enum
+{
+  INTEGER_PROPERTY = Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1,
+  MATRIX3_PROPERTY,
+  MATRIX_PROPERTY,
+  NONE_PROPERTY
+};
+
 namespace
 {
 
-std::string ReplaceQuotes(const std::string &in_s)
+BaseHandle Create()
 {
-  std::string s(in_s);
-  // wrong as no embedded quote but had regex link problems
-  std::replace(s.begin(), s.end(), '\'', '"');
-  return s;
+  return Toolkit::Control::New();
 }
 
+int gSetPropertyCalledCount = 0;
+
+void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+{
+  ++gSetPropertyCalledCount;
+}
+
+Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
+{
+  return Property::Value();
+}
+
+} // unnamed namespace
+
+// Properties
+Dali::TypeRegistration typeRegistration( "BuilderControl", typeid( Toolkit::Control ), Create );
+
+Dali::PropertyRegistration propertyInteger( typeRegistration, "integerProperty", INTEGER_PROPERTY, Property::INTEGER, &SetProperty, &GetProperty );
+Dali::PropertyRegistration propertyMatrix3( typeRegistration, "matrix3Property", MATRIX3_PROPERTY, Property::MATRIX3, &SetProperty, &GetProperty );
+Dali::PropertyRegistration propertyMatrix(  typeRegistration, "matrixProperty",  MATRIX_PROPERTY,  Property::MATRIX,  &SetProperty, &GetProperty );
+Dali::PropertyRegistration propertyNone(    typeRegistration, "noneProperty",    NONE_PROPERTY,    Property::NONE,    &SetProperty, &GetProperty );
+
+}
+
+namespace
+{
+
 struct BuilderFunctor
 {
   BuilderFunctor( bool& called ) : mCalled( called )
@@ -844,6 +879,32 @@ int UtcDaliBuilderPropertyNotificationP(void)
       "      \"property\": \"visible\",\n"
       "      \"condition\": \"False\",\n"
       "      \"action\": \"show\"\n"
+      "    },\n"
+      "    {\n"
+      "      \"property\": \"positionX\",\n"
+      "      \"condition\": \"LessThan\",\n"
+      "      \"arg0\": 0.0,\n"
+      "      \"action\": \"show\"\n"
+      "    },\n"
+      "    {\n"
+      "      \"property\": \"positionY\",\n"
+      "      \"condition\": \"GreaterThan\",\n"
+      "      \"arg0\": 200.0,\n"
+      "      \"action\": \"show\"\n"
+      "    },\n"
+      "    {\n"
+      "      \"property\": \"positionZ\",\n"
+      "      \"condition\": \"Inside\",\n"
+      "      \"arg0\": 0.0,\n"
+      "      \"arg1\": 10.0,\n"
+      "      \"action\": \"show\"\n"
+      "    },\n"
+      "    {\n"
+      "      \"property\": \"positionZ\",\n"
+      "      \"condition\": \"Outside\",\n"
+      "      \"arg0\": 40.0,\n"
+      "      \"arg1\": 50.0,\n"
+      "      \"action\": \"show\"\n"
       "    }]\n"
       "  }]\n"
       "}\n"
@@ -881,6 +942,42 @@ int UtcDaliBuilderPropertyNotificationP(void)
   END_TEST;
 }
 
+int UtcDaliBuilderPropertyNotificationN(void)
+{
+  ToolkitTestApplication application;
+
+  // JSON with a quit event when the actor is touched
+  std::string json(
+      "{\n"
+      "  \"stage\":\n"
+      "  [{\n"
+      "    \"type\": \"Actor\",\n"
+      "    \"notifications\": [{\n"
+      "      \"property\": \"visible\",\n"
+      "      \"condition\": \"ErrorCondition\",\n"
+      "      \"action\": \"show\"\n"
+      "    }]\n"
+      "  }]\n"
+      "}\n"
+  );
+
+  try
+  {
+    Builder builder = Builder::New();
+    builder.LoadFromString( json );
+    builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
+    DALI_TEST_CHECK( false );
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK( true );
+  }
+
+  END_TEST;
+}
+
+
+
 int UtcDaliBuilderCustomPropertyP(void)
 {
   ToolkitTestApplication application;
@@ -1196,22 +1293,6 @@ int UtcDaliBuilderFrameBufferP(void)
     "        }\n"
     "      ]\n"
     "    }\n"
-    "  },\n"
-    "  \"shaderEffects\": {\n"
-    "    \"Ripple2D\": {\n"
-    "      \"program\": {\n"
-    "        \"vertexPrefix\": \"\",\n"
-    "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
-    "        \"fragmentPrefix\": \"\",\n"
-    "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
-    "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
-    "      },\n"
-    "      \"geometryHints\": \"HINT_NONE\",\n"
-    "      \"gridDensity\": 0,\n"
-    "      \"loop\": true,\n"
-    "      \"uAmplitude\": 0.02,\n"
-    "      \"uTime\": 0.0\n"
-    "    }\n"
     "  }\n"
     "}\n");
 
@@ -1295,6 +1376,36 @@ int UtcDaliBuilderPathConstraintsP(void)
     "              \"range\": [-300,300]\n"
     "            }\n"
     "          ]\n"
+    "        },\n"
+    "        {\n"
+    "          \"name\": \"offStage\",\n"
+    "          \"action\": \"removeConstraints\",\n"
+    "          \"constrainer\": \"constrainer0\",\n"
+    "          \"properties\":\n"
+    "          [\n"
+    "            {\n"
+    "              \"source\": \"Image1\",\n"
+    "              \"sourceProperty\": \"positionX\",\n"
+    "              \"target\": \"Image1\",\n"
+    "              \"targetProperty\": \"colorRed\",\n"
+    "              \"range\": [-300,300]\n"
+    "            }\n"
+    "          ]\n"
+    "        },\n"
+    "        {\n"
+    "          \"name\": \"offStage\",\n"
+    "          \"action\": \"removeConstraints\",\n"
+    "          \"constrainer\": \"constrainer1\",\n"
+    "          \"properties\":\n"
+    "          [\n"
+    "            {\n"
+    "              \"source\": \"Image1\",\n"
+    "              \"sourceProperty\": \"positionX\",\n"
+    "              \"target\": \"Image1\",\n"
+    "              \"targetProperty\": \"colorBlue\",\n"
+    "              \"range\": [-300,300]\n"
+    "            }\n"
+    "          ]\n"
     "        }\n"
     "      ]\n"
     "    }\n"
@@ -1363,22 +1474,6 @@ int UtcDaliBuilderPathConstraintsP(void)
     "        }\n"
     "      ]\n"
     "    }\n"
-    "  },\n"
-    "  \"shaderEffects\": {\n"
-    "    \"Ripple2D\": {\n"
-    "      \"program\": {\n"
-    "        \"vertexPrefix\": \"\",\n"
-    "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
-    "        \"fragmentPrefix\": \"\",\n"
-    "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
-    "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
-    "      },\n"
-    "      \"geometryHints\": \"HINT_NONE\",\n"
-    "      \"gridDensity\": 0,\n"
-    "      \"loop\": true,\n"
-    "      \"uAmplitude\": 0.02,\n"
-    "      \"uTime\": 0.0\n"
-    "    }\n"
     "  }\n"
     "}\n");
 
@@ -1411,6 +1506,18 @@ int UtcDaliBuilderPathConstraintsP(void)
   Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
   DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
 
+  // 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;
 }
 
@@ -1604,3 +1711,112 @@ int UtcDaliBuilderMappingCycleCheck(void)
 
   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] }"
+      "}]"
+    "}"
+  );
+
+  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;
+}