From dc056f92bcd20241d6215e3f1614eb117c54b1e6 Mon Sep 17 00:00:00 2001 From: Lee Morgan Date: Thu, 11 Jun 2015 10:43:42 +0100 Subject: [PATCH] UTC Increase builder line coverage Change-Id: I6db8d02c8a6b4d6e16f30217774064eef0cbbd37 --- .../src/dali-toolkit/utc-Dali-Builder.cpp | 628 +++++++++++++++++++++ dali-toolkit/internal/builder/builder-actor.cpp | 8 +- .../internal/builder/builder-animations.cpp | 2 +- 3 files changed, 633 insertions(+), 5 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp index 5fa3d17..6d8ddff 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp @@ -21,6 +21,8 @@ #include #include +#define STRINGIFY(A)#A + using namespace Dali; using namespace Toolkit; @@ -104,3 +106,629 @@ int UtcDaliBuilderQuitSignal(void) END_TEST; } + + +int UtcDaliBuilderAnimationP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{" + " \"paths\":" + " {" + " \"path0\":" + " {" + " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ]," + " \"curvature\":0.35" + " }" + " }," + " \"animations\": {" + " \"animate\": {" + " \"loop\": true," + " \"end-action\": \"BAKE\"," + " \"disconnect-action\": \"BAKE\"," + " \"properties\":" + " [{" + " \"actor\": \"greeting\"," + " \"property\": \"position\"," + " \"value\": [300, 300, -1000]," + " \"alpha-function\": \"EASE_IN_OUT\"," + " \"relative\": true," + " \"time-period\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"visible\"," + " \"alpha-function\": \"LINEAR\"," + " \"value\": true" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"size-width\"," + " \"alpha-function\": \"REVERSE\"," + " \"value\": 10.0" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_IN\"," + " \"value\": [10.0,20.0,30.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_OUT\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_IN_OUT\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_IN_SINE\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_OUT_SINE\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_IN_OUT_SINE\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"BOUNCE\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"SIN\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }," + " {" + " \"actor\": \"greeting\"," + " \"property\": \"orientation\"," + " \"alpha-function\": \"EASE_OUT_BACK\"," + " \"value\": [0.0, 0.0, 0.0, 1.0]" + " }" + " ]" + " }," + " \"path-animation\": {" + " \"duration\": 3.0," + " \"end-action\": \"DISCARD\"," + " \"disconnect-action\": \"BAKE_FINAL\"," + " \"properties\": [{" + " \"actor\": \"greeting\"," + " \"path\":\"path0\"," + " \"forward\":[1,0,0]," + " \"alpha-function\": \"EASE_IN_OUT\"," + " \"time-period\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }]" + " }" + " }," + " \"stage\": [{" + " \"name\": \"greeting\"," + " \"type\": \"TextLabel\"," + " \"text\": \"Touch me\"," + " \"styles\": [\"basic-text\"]," + " \"position\": [0, -120, 0]," + " \"size\": [200, 200, 1]," + " \"orientation\": [0, 0, 30]," + " \"signals\": [{" + " \"name\": \"touched\"," + " \"action\": \"play\"," + " \"animation\": \"animate\"" + " }]" + " }]" + "}"); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors( Stage::GetCurrent().GetRootLayer() ); + + Animation anim = builder.CreateAnimation("animate"); + + DALI_TEST_CHECK( anim ); + + anim = builder.CreateAnimation("path-animation"); + + DALI_TEST_CHECK( anim ); + + // trigger play + // Emit touch event and check that our quit method is called + Integration::TouchEvent touchEvent; + touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) ); + application.ProcessEvent( touchEvent ); + + // Render and notify + application.SendNotification(); + application.Render(); + + + END_TEST; +} + +int UtcDaliBuilderAnimationN(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{" + " \"paths\":" + " {" + " \"path0\":" + " {" + " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ]," + " \"curvature\":0.35" + " }" + " }," + " \"animations\": {" + " \"animate\": {" + " \"loop\": true," + " \"end-action\": \"BAKE\"," + " \"disconnect-action\": \"BAKE\"," + " \"properties\":" + " [{" + " \"actor\": \"greeting\"," + " \"property\": \"positioninvalid\"," + " \"value\": [300, 300, -1000]," + " \"alpha-function\": \"EASE_IN_OUT\"," + " \"relative\": true," + " \"time-period\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }" + " ]" + " }," + " \"animate2\": {" + " \"loop\": true," + " \"end-action\": \"BAKE\"," + " \"disconnect-action\": \"BAKE\"," + " \"properties\":" + " [{" + " \"actor\": \"greeting\"," + " \"property\": \"positioninvalid\"," + " \"value\": [300, 300, -1000]," + " \"alpha-function\": \"EGGS_OVER_EASY\"," + " \"relative\": true," + " \"time-period\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }" + " ]" + " }," + " \"path-animation\": {" + " \"duration\": 3.0," + " \"end-action\": \"DISCARD\"," + " \"disconnect-action\": \"BAKE_FINAL\"," + " \"properties\": [{" + " \"actor\": \"greeting\"," + " \"path\":\"pathDoesntExist\"," + " \"forward\":[1,0,0]," + " \"alpha-function\": \"EASE_IN_OUT\"," + " \"time-period\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }]" + " }" + " }," + " \"stage\": [{" + " \"name\": \"greeting\"," + " \"type\": \"TextLabel\"," + " \"text\": \"Touch me\"," + " \"styles\": [\"basic-text\"]," + " \"position\": [0, -120, 0]," + " \"size\": [200, 200, 1]," + " \"orientation\": [0, 0, 30]," + " \"signals\": [{" + " \"name\": \"touched\"," + " \"action\": \"play\"," + " \"animation\": \"animate\"" + " }]" + " }]" + "}"); + + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors( Stage::GetCurrent().GetRootLayer() ); + + Animation anim = builder.CreateAnimation("animate"); + + // log warning line coverage + anim = builder.CreateAnimation("path-animation"); + + anim = builder.CreateAnimation("animate"); + + anim = builder.CreateAnimation("animate2"); + + DALI_TEST_CHECK(true); + + END_TEST; + +} + +int UtcDaliBuilderConstantsP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{" + "\"constants\":" + "{" + " \"IMAGE_PATH\": \"apath\"," + " \"WIDTH\": 22.3," + " \"ANCHOR\": \"TOP_LEFT\"," + " \"PADDING\": [1,2,3,4]" + "}," + "\"stage\":" + "[{" + " \"type\": \"ImageActor\"," + " \"size\": [100,100,1]," + " \"parent-origin\": \"TOP_LEFT\"," + " \"anchor-point\": \"{ANCHOR}\"," + " \"padding\": \"{PADDING}\"," + " \"image\": { \"filename\": \"dir/{IMAGE_PATH}\" }," + " \"size-width\": \"{WIDTH}\"," + " \"signals\": [{" + " \"name\": \"touched\"," + " \"action\": \"quit\"" + " }]" + "}]" + "}" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + DALI_TEST_CHECK( builder ); + + END_TEST; +} + +int UtcDaliBuilderTemplatesAndStylesP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + "\"styles\":\n" + "{\n" + " \"image-style\": \n" + " {\n" + " \"color\": [1,0,0,1],\n" + " \"actors\": {\n" + " \"child-image\": {\n" + " \"color\": [0,1,0,1]\n" + " }\n" + " }\n" + " }\n" + "},\n" + "\"templates\":\n" + "{\n" + " \"image-tree\": { \n" + " \"type\": \"ImageActor\",\n" + " \"styles\": [\"image-style\"],\n" + " \"name\": \"image\",\n" + " \"size\": [100,100,1],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"quit\"\n" + " }],\n" + " \"actors\": [\n" + " {\n" + " \"type\":\"ImageActor\",\n" + " \"name\":\"child-image\" \n" + " }\n" + " ]\n" + " }\n" + "}\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + + ImageActor actor = ImageActor::DownCast( builder.Create( "image-tree" ) ); + DALI_TEST_CHECK( actor ); + + // NB: already applied in create + DALI_TEST_CHECK( builder.ApplyStyle( "image-style", actor ) ); + + END_TEST; +} + +int UtcDaliBuilderRenderTasksP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + "\"render-tasks\":\n" + "{\n" + " \"task0\": {\n" + " \"source-actor\": \"image\",\n" + " \"camera-actor\": \"camera\" \n" + " }\n" + "},\n" + "\"stage\":\n" + "[\n" + " { \n" + " \"type\": \"CameraActor\",\n" + " \"name\": \"image\"\n" + " }, \n" + " { \n" + " \"type\": \"ImageActor\",\n" + " \"name\": \"image\",\n" + " \"size\": [100,100,1],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"quit\"\n" + " }],\n" + " \"actors\": [\n" + " {\n" + " \"type\":\"ImageActor\",\n" + " \"name\":\"child-image\" \n" + " }\n" + " ]\n" + " }\n" + "]\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + + unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount(); + + // coverage + builder.CreateRenderTask( "task0" ); + + DALI_TEST_CHECK( count < + Stage::GetCurrent().GetRenderTaskList().GetTaskCount() ); + + END_TEST; +} + +int UtcDaliBuilderChildActionP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + " \"stage\":\n" + " [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"actor\",\n" + " \"size\": [100,100,1],\n" + " \"parent-origin\": \"TOP_LEFT\",\n" + " \"anchor-point\": \"TOP_LEFT\",\n" + " \"actors\": [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"sub-actor\"\n" + " }],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"hide\",\n" + " \"actor\": \"actor\",\n" + " \"child-actor\": \"sub-actor\"\n" + " }]\n" + " }]\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit touch event and check that our quit method is called + Integration::TouchEvent touchEvent; + touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) ); + application.ProcessEvent( touchEvent ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("sub-actor"); + DALI_TEST_CHECK( actor ); + + DALI_TEST_CHECK( !actor.IsVisible() ); + + END_TEST; +} + +int UtcDaliBuilderSetPropertyActionP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + " \"stage\":\n" + " [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"actor\",\n" + " \"size\": [100,100,1],\n" + " \"parent-origin\": \"TOP_LEFT\",\n" + " \"anchor-point\": \"TOP_LEFT\",\n" + " \"actors\": [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"sub-actor\"\n" + " }],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"set\",\n" + " \"actor\": \"sub-actor\",\n" + " \"property\": \"visible\",\n" + " \"value\": false\n" + " }]\n" + " }]\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit touch event and check that our quit method is called + Integration::TouchEvent touchEvent; + touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) ); + application.ProcessEvent( touchEvent ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("sub-actor"); + DALI_TEST_CHECK( actor ); + + DALI_TEST_CHECK( !actor.IsVisible() ); + + END_TEST; +} + +int UtcDaliBuilderGenericActionP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + " \"stage\":\n" + " [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"actor\",\n" + " \"size\": [100,100,1],\n" + " \"parent-origin\": \"TOP_LEFT\",\n" + " \"anchor-point\": \"TOP_LEFT\",\n" + " \"actors\": [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"sub-actor\"\n" + " }],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"hide\"\n" + " }]\n" + " }]\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit touch event and check that our quit method is called + Integration::TouchEvent touchEvent; + touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) ); + application.ProcessEvent( touchEvent ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor"); + DALI_TEST_CHECK( actor ); + + DALI_TEST_CHECK( !actor.IsVisible() ); + + END_TEST; +} + +int UtcDaliBuilderPropertyNotificationP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + " \"stage\":\n" + " [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"actor\",\n" + " \"size\": [100,100,1],\n" + " \"parent-origin\": \"TOP_LEFT\",\n" + " \"anchor-point\": \"TOP_LEFT\",\n" + " \"actors\": [{\n" + " \"type\": \"Actor\",\n" + " \"name\": \"sub-actor\"\n" + " }],\n" + " \"signals\": [{\n" + " \"name\": \"touched\",\n" + " \"action\": \"hide\"\n" + " }],\n" + " \"notifications\": [{\n" + " \"property\": \"visible\",\n" + " \"condition\": \"False\",\n" + " \"action\": \"show\"\n" + " }]\n" + " }]\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Emit touch event and check that our quit method is called + Integration::TouchEvent touchEvent; + touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) ); + application.ProcessEvent( touchEvent ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor"); + DALI_TEST_CHECK( actor ); + + DALI_TEST_CHECK( actor.IsVisible() ); + + END_TEST; +} diff --git a/dali-toolkit/internal/builder/builder-actor.cpp b/dali-toolkit/internal/builder/builder-actor.cpp index 287663c..6ef44c0 100644 --- a/dali-toolkit/internal/builder/builder-actor.cpp +++ b/dali-toolkit/internal/builder/builder-actor.cpp @@ -49,11 +49,11 @@ Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& consta // this has already been set as a generic property. if( !IsVector3( child, "parent-origin") ) { - if( OptionalVector3 v = IsVector3(child, "parent-origin") ) + if( OptionalVector3 v = constant.IsVector3( IsChild(child, "parent-origin") ) ) { actor.SetParentOrigin( *v ); } - else if( OptionalString origin = IsString(child, "parent-origin") ) + else if( OptionalString origin = constant.IsString( IsChild(child, "parent-origin") ) ) { actor.SetParentOrigin( GetAnchorConstant(*origin) ); } @@ -61,11 +61,11 @@ Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& consta if( !IsVector3(child, "anchor-point") ) { - if( OptionalVector3 v = IsVector3(child, "anchor-point") ) + if( OptionalVector3 v = constant.IsVector3( IsChild(child, "anchor-point") ) ) { actor.SetAnchorPoint( *v ); } - else if( OptionalString anchor = IsString(child, "anchor-point") ) + else if( OptionalString anchor = constant.IsString( IsChild(child, "anchor-point") ) ) { actor.SetAnchorPoint( GetAnchorConstant(*anchor) ); } diff --git a/dali-toolkit/internal/builder/builder-animations.cpp b/dali-toolkit/internal/builder/builder-animations.cpp index 6caf392..93f3623 100644 --- a/dali-toolkit/internal/builder/builder-animations.cpp +++ b/dali-toolkit/internal/builder/builder-animations.cpp @@ -134,7 +134,7 @@ AlphaFunction GetAlphaFunction( const std::string& alphaFunction ) } else { - DALI_ASSERT_ALWAYS( iter != alphaFunctionLut.end() && "Unknown Anchor Constant" ); + DALI_ASSERT_ALWAYS( iter != alphaFunctionLut.end() && "Unknown Alpha Constant" ); return Dali::AlphaFunction::DEFAULT; } } -- 2.7.4