Implemented a primitive shape renderer to display simple shapes like cubes.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-RendererFactory.cpp
index aef0a65..19df59d 100644 (file)
@@ -293,7 +293,7 @@ int UtcDaliRendererFactoryGetColorRenderer1(void)
 
   Property::Map propertyMap;
   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
-  propertyMap.Insert("rendererType",  "color");
+  propertyMap.Insert("rendererType",  "COLOR");
   propertyMap.Insert("mixColor",  testColor);
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
@@ -320,7 +320,7 @@ int UtcDaliRendererFactoryGetColorRenderer2(void)
 
   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
   Dali::Property::Map map;
-  map[ "rendererType" ] = "color";
+  map[ "rendererType" ] = "COLOR";
   map[ "mixColor" ] = testColor;
   ControlRenderer controlRenderer = factory.CreateControlRenderer( map );
   DALI_TEST_CHECK( controlRenderer );
@@ -350,7 +350,7 @@ int UtcDaliRendererFactoryGetBorderRenderer1(void)
   Property::Map propertyMap;
   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
   float testSize = 5.f;
-  propertyMap.Insert("rendererType",  "border");
+  propertyMap.Insert("rendererType",  "BORDER");
   propertyMap.Insert("borderColor",  testColor);
   propertyMap.Insert("borderSize",  testSize);
 
@@ -398,7 +398,7 @@ int UtcDaliRendererFactoryGetBorderRenderer2(void)
   float testSize = 5.f;
 
   Dali::Property::Map propertyMap;
-  propertyMap[ "rendererType" ] = "border";
+  propertyMap[ "rendererType" ] = "BORDER";
   propertyMap[ "borderColor"  ] = testColor;
   propertyMap[ "borderSize"   ] = testSize;
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
@@ -432,7 +432,7 @@ int UtcDaliRendererFactoryGetBorderRenderer2(void)
 
   // enable the anti-aliasing
   Dali::Property::Map map;
-  map[ "rendererType" ] = "border";
+  map[ "rendererType" ] = "BORDER";
   map[ "borderColor"  ] = testColor;
   map[ "borderSize"   ] = testSize;
   map[ "antiAliasing"   ] = true;
@@ -456,23 +456,23 @@ int UtcDaliRendererFactoryGetLinearGradientRenderer(void)
   DALI_TEST_CHECK( factory );
 
   Property::Map propertyMap;
-  propertyMap.Insert("rendererType",  "gradient");
+  propertyMap.Insert("rendererType",  "GRADIENT");
 
   Vector2 start(-1.f, -1.f);
   Vector2 end(1.f, 1.f);
-  propertyMap.Insert("startPosition",   start);
-  propertyMap.Insert("endPosition",   end);
-  propertyMap.Insert("spreadMethod",   "repeat");
+  propertyMap.Insert("startPosition", start);
+  propertyMap.Insert("endPosition", end);
+  propertyMap.Insert("spreadMethod", "REPEAT");
 
   Property::Array stopOffsets;
   stopOffsets.PushBack( 0.2f );
   stopOffsets.PushBack( 0.8f );
-  propertyMap.Insert("stopOffset",   stopOffsets);
+  propertyMap.Insert("stopOffset", stopOffsets);
 
   Property::Array stopColors;
   stopColors.PushBack( Color::RED );
   stopColors.PushBack( Color::GREEN );
-  propertyMap.Insert("stopColor",   stopColors);
+  propertyMap.Insert("stopColor", stopColors);
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
   DALI_TEST_CHECK( controlRenderer );
@@ -496,11 +496,11 @@ int UtcDaliRendererFactoryGetRadialGradientRenderer(void)
   DALI_TEST_CHECK( factory );
 
   Property::Map propertyMap;
-  propertyMap.Insert("rendererType",  "gradient");
+  propertyMap.Insert("rendererType",  "GRADIENT");
 
   Vector2 center(100.f, 100.f);
   float radius = 100.f;
-  propertyMap.Insert("units",  "userSpace");
+  propertyMap.Insert("units",  "USER_SPACE");
   propertyMap.Insert("center",  center);
   propertyMap.Insert("radius",  radius);
 
@@ -541,18 +541,18 @@ int UtcDaliRendererFactoryDefaultOffsetsGradientRenderer(void)
   DALI_TEST_CHECK( factory );
 
   Property::Map propertyMap;
-  propertyMap.Insert("rendererType",  "gradient");
+  propertyMap.Insert("rendererType",  "GRADIENT");
 
   Vector2 start(-1.f, -1.f);
   Vector2 end(1.f, 1.f);
-  propertyMap.Insert("startPosition",   start);
-  propertyMap.Insert("endPosition",   end);
-  propertyMap.Insert("spreadMethod",   "repeat");
+  propertyMap.Insert("startPosition", start);
+  propertyMap.Insert("endPosition", end);
+  propertyMap.Insert("spreadMethod", "REPEAT");
 
   Property::Array stopColors;
   stopColors.PushBack( Color::RED );
   stopColors.PushBack( Color::GREEN );
-  propertyMap.Insert("stopColor",   stopColors);
+  propertyMap.Insert("stopColor", stopColors);
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
   DALI_TEST_CHECK( controlRenderer );
@@ -576,7 +576,7 @@ int UtcDaliRendererFactoryGetImageRenderer1(void)
   DALI_TEST_CHECK( factory );
 
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "image" );
+  propertyMap.Insert( "rendererType",  "IMAGE" );
   propertyMap.Insert( "url",  TEST_IMAGE_FILE_NAME );
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
@@ -658,7 +658,7 @@ int UtcDaliRendererFactoryGetNPatchRenderer1(void)
   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
 
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "image" );
+  propertyMap.Insert( "rendererType",  "IMAGE" );
   propertyMap.Insert( "url",  TEST_NPATCH_FILE_NAME );
   {
     tet_infoline( "whole grid" );
@@ -722,7 +722,7 @@ int UtcDaliRendererFactoryGetNPatchRenderer2(void)
   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
 
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "image" );
+  propertyMap.Insert( "rendererType",  "IMAGE" );
   propertyMap.Insert( "url",  TEST_NPATCH_FILE_NAME );
   {
     ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
@@ -960,7 +960,7 @@ int UtcDaliRendererFactoryGetMeshRenderer1(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
@@ -1012,7 +1012,7 @@ int UtcDaliRendererFactoryGetMeshRenderer2(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", "" );
   propertyMap.Insert( "texturesPath", "" );
@@ -1068,7 +1068,7 @@ int UtcDaliRendererFactoryGetMeshRenderer3(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
@@ -1124,7 +1124,7 @@ int UtcDaliRendererFactoryGetMeshRenderer4(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", TEST_SIMPLE_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
@@ -1180,7 +1180,7 @@ int UtcDaliRendererFactoryGetMeshRendererN1(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
@@ -1231,7 +1231,7 @@ int UtcDaliRendererFactoryGetMeshRendererN2(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", "invalid" );
   propertyMap.Insert( "texturesPath", "also invalid" );
@@ -1283,7 +1283,7 @@ int UtcDaliRendererFactoryGetMeshRendererN3(void)
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "mesh" );
+  propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", "invalid" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
@@ -1323,3 +1323,235 @@ int UtcDaliRendererFactoryGetMeshRendererN3(void)
 
   END_TEST;
 }
+
+//Creates a primitive renderer with the given property map and tests to see if it correctly loads in the given application.
+void TestPrimitiveRendererWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
+{
+  RendererFactory factory = RendererFactory::Get();
+  DALI_TEST_CHECK( factory );
+
+  //Create a primitive renderer.
+  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
+  DALI_TEST_CHECK( controlRenderer );
+
+  //Create an actor on stage to house the renderer.
+  Actor actor = Actor::New();
+  actor.SetSize( 200.f, 200.f );
+  Stage::GetCurrent().Add( actor );
+  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
+  controlRenderer.SetOnStage( actor );
+
+  //Ensure set on stage.
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+
+  //Tell test application to load the renderer.
+  application.SendNotification();
+  application.Render(0);
+
+  Matrix testScaleMatrix;
+  testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
+  Matrix actualScaleMatrix;
+
+  //Test to see if the object has been successfully loaded.
+  DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
+  DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+  //Finish by setting off stage, and ensuring this was successful.
+  controlRenderer.SetOffStage( actor );
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
+}
+
+//Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
+int UtcDaliRendererFactoryGetPrimitiveRenderer1(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer1:  Request primitive renderer with a shape only" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "CUBE" );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads correctly when supplied with all possible parameters
+int UtcDaliRendererFactoryGetPrimitiveRenderer2(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer2:  Request primitive renderer with everything" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "CUBE" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "slices", 10 );
+  propertyMap.Insert( "stacks", 20 );
+  propertyMap.Insert( "scaleTopRadius", 30.0f );
+  propertyMap.Insert( "scaleBottomRadius", 40.0f );
+  propertyMap.Insert( "scaleHeight", 50.0f );
+  propertyMap.Insert( "scaleRadius", 60.0f );
+  propertyMap.Insert( "bevelPercentage", 0.7f );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads a sphere correctly.
+int UtcDaliRendererFactoryGetPrimitiveRenderer3(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer3:  Request primitive renderer to display a sphere" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "SPHERE" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "slices", 10 );
+  propertyMap.Insert( "stacks", 20 );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads a conic section correctly.
+int UtcDaliRendererFactoryGetPrimitiveRenderer4(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer4:  Request primitive renderer to display a conic section" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "CONICAL_FRUSTRUM" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "slices", 10 );
+  propertyMap.Insert( "scaleTopRadius", 30.0f );
+  propertyMap.Insert( "scaleBottomRadius", 40.0f );
+  propertyMap.Insert( "scaleHeight", 50.0f );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads a bevelled cube correctly.
+int UtcDaliRendererFactoryGetPrimitiveRenderer5(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer5:  Request primitive renderer to display a bevelled cube" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "BEVELLED_CUBE" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "bevelPercentage", 0.7f );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads an octahedron correctly.
+int UtcDaliRendererFactoryGetPrimitiveRenderer6(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer6:  Request primitive renderer to display an octahedron" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "OCTAHEDRON" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads a cone correctly.
+int UtcDaliRendererFactoryGetPrimitiveRenderer7(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer7:  Request primitive renderer to display a cone" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "CONE" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "slices", 10 );
+  propertyMap.Insert( "scaleTopRadius", 30.0f );
+  propertyMap.Insert( "scaleHeight", 50.0f );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape loads correctly when light position is manually set.
+int UtcDaliRendererFactoryGetPrimitiveRenderer8(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer8:  Request primitive renderer with set light position" );
+
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+  propertyMap.Insert( "shape", "SPHERE" );
+  propertyMap.Insert( "color", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
+  propertyMap.Insert( "uLightPosition", Vector3( 0.0, 1.0, 2.0 ) );
+
+  //Test to see if shape loads correctly.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}
+
+//Test if primitive shape renderer handles the case of not being passed a specific shape to use.
+int UtcDaliRendererFactoryGetPrimitiveRendererN1(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRendererN1:  Request primitive renderer without shape" );
+
+  //Set up renderer properties, without supplying shape.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "PRIMITIVE" );
+
+  //Test to see if shape loads regardless of missing input.
+  TestPrimitiveRendererWithProperties( propertyMap, application );
+
+  END_TEST;
+}