X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-Builder.cpp;h=987916c7d117916edc81fa2a7224ffc6fb252f1e;hp=deb3727ed89ee67dfa0a7cc224a215eb89487d8f;hb=73eaac8af8efb9ac721db3fcf3c71a7a3115282a;hpb=da24507a54c2603006c244b01b5325639baca2d2 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp index deb3727..987916c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -16,27 +16,72 @@ */ #include -#include +#include +#include +#include +#include + #include #include +#include #include +#include +#include +#include +#include + #define STRINGIFY(A)#A 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() +{ + 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 ) { - std::string s(in_s); - // wrong as no embedded quote but had regex link problems - std::replace(s.begin(), s.end(), '\'', '"'); - return s; + 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 ) @@ -75,12 +120,15 @@ int UtcDaliBuilderQuitSignal(void) "{" "\"stage\":" "[{" - "\"type\": \"Actor\"," + "\"type\": \"Layer\"," "\"size\": [100,100,1]," "\"parentOrigin\": \"TOP_LEFT\"," "\"anchorPoint\": \"TOP_LEFT\"," + "\"maximumSize\": [100,100]," + "\"orientation\": [10,10,10,10]," + "\"clippingBox\": [10,10,10,10]," "\"signals\": [{" - "\"name\": \"touched\"," + "\"name\": \"touch\"," "\"action\": \"quit\"" "}]" "}]" @@ -88,7 +136,7 @@ int UtcDaliBuilderQuitSignal(void) ); Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); // Connect to builder's quit signal bool functorCalled( false ); @@ -100,7 +148,10 @@ int UtcDaliBuilderQuitSignal(void) // 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); DALI_TEST_CHECK( functorCalled ); @@ -226,18 +277,33 @@ int UtcDaliBuilderAnimationP(void) " \"duration\": 3" " }" " }]" + " }," + " \"pathAnimation2\": {" + " \"duration\": 3.0," + " \"endAction\": \"BAKE_FINAL\"," + " \"disconnectAction\": \"DISCARD\"," + " \"properties\": [{" + " \"actor\": \"greeting\"," + " \"path\":\"path0\"," + " \"forward\":[1,0,0]," + " \"alphaFunction\": \"EASE_IN_OUT\"," + " \"timePeriod\": {" + " \"delay\": 0," + " \"duration\": 3" + " }" + " }]" " }" " }," " \"stage\": [{" " \"name\": \"greeting\"," " \"type\": \"TextLabel\"," " \"text\": \"Touch me\"," - " \"styles\": [\"basicText\"]," + " \"inherit\": [\"basicText\"]," " \"position\": [0, -120, 0]," " \"size\": [200, 200, 1]," " \"orientation\": [0, 0, 30]," " \"signals\": [{" - " \"name\": \"touched\"," + " \"name\": \"touch\"," " \"action\": \"play\"," " \"animation\": \"animate\"" " }]" @@ -246,7 +312,7 @@ int UtcDaliBuilderAnimationP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors( application.GetScene().GetRootLayer() ); Animation anim = builder.CreateAnimation("animate"); @@ -262,10 +328,17 @@ int UtcDaliBuilderAnimationP(void) DALI_TEST_CHECK( anim ); + anim = builder.CreateAnimation("pathAnimation2"); + + 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); // Render and notify @@ -353,12 +426,12 @@ int UtcDaliBuilderAnimationN(void) " \"name\": \"greeting\"," " \"type\": \"TextLabel\"," " \"text\": \"Touch me\"," - " \"styles\": [\"basicText\"]," + " \"inherit\": [\"basicText\"]," " \"position\": [0, -120, 0]," " \"size\": [200, 200, 1]," " \"orientation\": [0, 0, 30]," " \"signals\": [{" - " \"name\": \"touched\"," + " \"name\": \"touch\"," " \"action\": \"play\"," " \"animation\": \"animate\"" " }]" @@ -373,7 +446,7 @@ int UtcDaliBuilderAnimationN(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors( application.GetScene().GetRootLayer() ); Animation anim = builder.CreateAnimation("animate"); @@ -394,11 +467,11 @@ int UtcDaliBuilderAnimationN(void) DALI_TEST_CHECK(anim); // alternative actor to use for FindChildByName - anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer()); + anim = builder.CreateAnimation("animate2", application.GetScene().GetRootLayer()); DALI_TEST_CHECK(anim); // alternative actor to use for FindChildByName - anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer()); + anim = builder.CreateAnimation("animate2", map, application.GetScene().GetRootLayer()); DALI_TEST_CHECK(anim); @@ -422,16 +495,16 @@ int UtcDaliBuilderConstantsP(void) "}," "\"stage\":" "[{" - " \"type\": \"ImageActor\"," + " \"type\": \"ImageView\"," " \"name\": \"{NAME}\"," " \"size\": [100,100,1]," " \"parentOrigin\": \"TOP_LEFT\"," " \"anchorPoint\": \"{ANCHOR}\"," " \"padding\": \"{PADDING}\"," - " \"image\": { \"filename\": \"dir/{IMAGE_PATH}\" }," + " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" }," " \"sizeWidth\": \"{WIDTH}\"," " \"signals\": [{" - " \"name\": \"touched\"," + " \"name\": \"touch\"," " \"action\": \"quit\"" " }]" "}]" @@ -457,10 +530,10 @@ int UtcDaliBuilderConstantsP(void) DALI_TEST_CHECK( value.GetType() != Property::NONE ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); DALI_TEST_CHECK( builder ); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("image"); DALI_TEST_CHECK( actor ); END_TEST; @@ -484,26 +557,41 @@ int UtcDaliBuilderTemplatesAndStylesP(void) " \"color\": [1,0,0,1],\n" " \"actors\": {\n" " \"childImage\": {\n" - " \"color\": [0,1,0,1]\n" + " \"color\": \"34\"\n" " }\n" " }\n" " }\n" "},\n" "\"templates\":\n" "{\n" + " \"imageViewTemplate\": { \n" + " \"type\": \"ImageView\",\n" + " \"styles\": [\"imageStyle\"]\n" + " },\n" " \"imageTree\": { \n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"styles\": [\"imageStyle\"],\n" " \"name\": \"image\",\n" " \"size\": \"{SIZE}\",\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"quit\"\n" " }],\n" " \"actors\": [\n" " {\n" - " \"type\":\"ImageActor\",\n" - " \"name\":\"childImage\" \n" + " \"type\":\"ImageView\",\n" + " \"name\":\"childImage\", \n" + " \"color\": \n" + " {\n" + " \"r\": 10,\n" + " \"g\": 10,\n" + " \"b\": 10,\n" + " \"a\": 100\n" + " }\n" + " },\n" + " {\n" + " \"type\":\"imageViewTemplate\",\n" + " \"name\":\"childImage2\"\n" " }\n" " ]\n" " }\n" @@ -521,7 +609,7 @@ int UtcDaliBuilderTemplatesAndStylesP(void) " \"color\": [1,0,0,1],\n" " \"actors\": {\n" " \"childImage\": {\n" - " \"color\": [0,1,0,1]\n" + " \"color\": \"#344353\"\n" " }\n" " }\n" "}\n" @@ -529,17 +617,17 @@ int UtcDaliBuilderTemplatesAndStylesP(void) std::string templatejson( "{ \n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"styles\": [\"imageStyle\"],\n" " \"name\": \"image\",\n" " \"size\": \"{SIZE}\",\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"quit\"\n" " }],\n" " \"actors\": [\n" " {\n" - " \"type\":\"ImageActor\",\n" + " \"type\":\"ImageView\",\n" " \"name\":\"childImage\" \n" " }\n" " ]\n" @@ -549,16 +637,16 @@ int UtcDaliBuilderTemplatesAndStylesP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) ); + ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) ); DALI_TEST_CHECK( actor ); Dali::Property::Map map; map["SIZE"] = Vector3(100,100,1); - actor = ImageActor::DownCast( builder.Create( "imageTree", map ) ); + actor = ImageView::DownCast( builder.Create( "imageTree", map ) ); DALI_TEST_CHECK( actor ); // create from json snippet - actor = ImageActor::DownCast( builder.CreateFromJson( templatejson ) ); + actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) ); DALI_TEST_CHECK( actor ); @@ -589,19 +677,19 @@ int UtcDaliBuilderRenderTasksP(void) "[\n" " { \n" " \"type\": \"CameraActor\",\n" - " \"name\": \"image\"\n" + " \"name\": \"camera\"\n" " }, \n" " { \n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"name\": \"image\",\n" " \"size\": [100,100,1],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"quit\"\n" " }],\n" " \"actors\": [\n" " {\n" - " \"type\":\"ImageActor\",\n" + " \"type\":\"ImageView\",\n" " \"name\":\"childImage\" \n" " }\n" " ]\n" @@ -613,13 +701,13 @@ int UtcDaliBuilderRenderTasksP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount(); + unsigned int count = application.GetScene().GetRenderTaskList().GetTaskCount(); // coverage builder.CreateRenderTask( "task0" ); DALI_TEST_CHECK( count < - Stage::GetCurrent().GetRenderTaskList().GetTaskCount() ); + application.GetScene().GetRenderTaskList().GetTaskCount() ); END_TEST; } @@ -643,7 +731,7 @@ int UtcDaliBuilderChildActionP(void) " \"name\": \"subActor\"\n" " }],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"hide\",\n" " \"actor\": \"actor\",\n" " \"childActor\": \"subActor\"\n" @@ -654,7 +742,7 @@ int UtcDaliBuilderChildActionP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); // Render and notify application.SendNotification(); @@ -662,17 +750,20 @@ int UtcDaliBuilderChildActionP(void) // 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); // Render and notify application.SendNotification(); application.Render(); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor"); DALI_TEST_CHECK( actor ); - DALI_TEST_CHECK( !actor.IsVisible() ); + DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); END_TEST; } @@ -696,7 +787,7 @@ int UtcDaliBuilderSetPropertyActionP(void) " \"name\": \"subActor\"\n" " }],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"set\",\n" " \"actor\": \"subActor\",\n" " \"property\": \"visible\",\n" @@ -708,7 +799,7 @@ int UtcDaliBuilderSetPropertyActionP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); // Render and notify application.SendNotification(); @@ -716,17 +807,20 @@ int UtcDaliBuilderSetPropertyActionP(void) // 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); // Render and notify application.SendNotification(); application.Render(); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor"); DALI_TEST_CHECK( actor ); - DALI_TEST_CHECK( !actor.IsVisible() ); + DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); END_TEST; } @@ -750,7 +844,7 @@ int UtcDaliBuilderGenericActionP(void) " \"name\": \"subActor\"\n" " }],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"hide\"\n" " }]\n" " }]\n" @@ -759,7 +853,7 @@ int UtcDaliBuilderGenericActionP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); // Render and notify application.SendNotification(); @@ -767,17 +861,20 @@ int UtcDaliBuilderGenericActionP(void) // 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); // Render and notify application.SendNotification(); application.Render(); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor"); DALI_TEST_CHECK( actor ); - DALI_TEST_CHECK( !actor.IsVisible() ); + DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); END_TEST; } @@ -801,13 +898,39 @@ int UtcDaliBuilderPropertyNotificationP(void) " \"name\": \"subActor\"\n" " }],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"hide\"\n" " }],\n" " \"notifications\": [{\n" " \"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" @@ -815,7 +938,7 @@ int UtcDaliBuilderPropertyNotificationP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( application.GetScene().GetRootLayer() ); // Render and notify application.SendNotification(); @@ -823,7 +946,10 @@ int UtcDaliBuilderPropertyNotificationP(void) // 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 ) ); + Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10.0f, 10.0f ) ); + touchEvent.points.push_back( point ); application.ProcessEvent( touchEvent ); // Render and notify @@ -834,14 +960,50 @@ int UtcDaliBuilderPropertyNotificationP(void) application.SendNotification(); application.Render(); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor"); DALI_TEST_CHECK( actor ); - DALI_TEST_CHECK( actor.IsVisible() ); + DALI_TEST_CHECK( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); + + 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 ( application.GetScene().GetRootLayer() ); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } END_TEST; } + + int UtcDaliBuilderCustomPropertyP(void) { ToolkitTestApplication application; @@ -852,19 +1014,22 @@ int UtcDaliBuilderCustomPropertyP(void) "\"templates\":\n" "{\n" " \"imageTree\": { \n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"name\": \"image\",\n" " \"size\": [100,100,1],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"quit\"\n" " }],\n" - " \"customProperties\": {\n" + " \"properties\": {\n" " \"newproperty\": true\n" " },\n" + " \"animatableProperties\": {\n" + " \"newAnimatableproperty\": 3\n" + " },\n" " \"actors\": [\n" " {\n" - " \"type\":\"ImageActor\",\n" + " \"type\":\"ImageView\",\n" " \"name\":\"childImage\" \n" " }\n" " ]\n" @@ -876,7 +1041,7 @@ int UtcDaliBuilderCustomPropertyP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) ); + ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) ); DALI_TEST_CHECK( actor ); // NB: already applied in create @@ -885,10 +1050,15 @@ int UtcDaliBuilderCustomPropertyP(void) Property::Value value = actor.GetProperty(index); DALI_TEST_CHECK( value.Get() == true ); + index = actor.GetPropertyIndex("newAnimatableproperty"); + DALI_TEST_CHECK( Property::INVALID_INDEX != index ); + value = actor.GetProperty(index); + DALI_TEST_CHECK( value.Get() == 3 ); + END_TEST; } -int UtcDaliBuilderShaderEffectP(void) +int UtcDaliBuilderCustomShaderP(void) { ToolkitTestApplication application; @@ -897,7 +1067,7 @@ int UtcDaliBuilderShaderEffectP(void) "{\n" " \"stage\": [\n" " {\n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"name\": \"Image1\",\n" " \"position\": [\n" " 0.40461349487305,\n" @@ -908,22 +1078,26 @@ int UtcDaliBuilderShaderEffectP(void) " \"size\": [200, 200, 0],\n" " \"effect\": \"Ripple2D\",\n" " \"image\": {\n" - " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n" - " \"width\": 200,\n" - " \"height\": 80,\n" - " \"loadPolicy\": \"IMMEDIATE\",\n" - " \"releasePolicy\": \"NEVER\"\n" + " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n" + " \"desiredWidth\": 200,\n" + " \"desiredHeight\": 80,\n" + " \"shader\": {\n" + " \"fragmentShader\": \"precision mediump float;\\nuniform sampler2D sTexture;\\nuniform vec4 uColor;\\nuniform float uAmplitude;\\nuniform float uTime;\\nvarying vec2 vTexCoord;\\nvoid main()\\n{\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;}\\n\\n\"\n" + " }\n" + " },\n" + " \"customAnimatableProperties\": {\n" + " \"uAmplitude\": 0.02,\n" + " \"uTime\": 0.0\n" " },\n" " \"signals\": [\n" " {\n" - " \"name\": \"onStage\",\n" + " \"name\": \"onScene\",\n" " \"action\": \"play\",\n" " \"animation\": \"Animation_1\"\n" " }\n" " ]\n" " }\n" " ],\n" - " \"paths\": {},\n" " \"animations\": {\n" " \"Animation_1\": {\n" " \"loop\":true,\n" @@ -936,27 +1110,10 @@ int UtcDaliBuilderShaderEffectP(void) " \"timePeriod\": {\n" " \"delay\": 0,\n" " \"duration\": 10.0\n" - " },\n" - " \"gui-builder-timeline-color\": \"#8dc0da\"\n" + " }\n" " }\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 = uTextureRect.zw - uTextureRect.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" @@ -965,10 +1122,16 @@ int UtcDaliBuilderShaderEffectP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - ShaderEffect effect = builder.GetShaderEffect("Ripple2D"); + builder.AddActors ( "stage", application.GetScene().GetRootLayer() ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor actor = application.GetScene().GetRootLayer().FindChildByName("Image1"); // coverage - DALI_TEST_CHECK( effect ); + DALI_TEST_CHECK( actor ); END_TEST; } @@ -988,7 +1151,7 @@ int UtcDaliBuilderLoadFromStringN(void) "\"parentOrigin\": \"TOP_LEFT\"," "\"anchorPoint\": \"TOP_LEFT\"," "\"signals\": [{" - "\"name\": \"touched\"," + "\"name\": \"touch\"," "\"action\": \"quit\"" "}]" "}]" @@ -1014,80 +1177,6 @@ int UtcDaliBuilderLoadFromStringN(void) END_TEST; } -int UtcDaliBuilderShaderEffect2P(void) -{ - ToolkitTestApplication application; - - // JSON with a quit event when the actor is touched - std::string json( - "{\n" - "\"templates\":\n" - "{\n" - " \"imageTree\": { \n" - " \"type\": \"ImageActor\",\n" - " \"size\": [100,100,1],\n" - " \"parentOrigin\": [0.5, 0.5, 0.5],\n" - " \"position\": [\n" - " 0.40461349487305,\n" - " 0.9150390625,\n" - " 0.0\n" - " ],\n" - " \"signals\": [{\n" - " \"name\": \"touched\",\n" - " \"action\": \"quit\"\n" - " }],\n" - " \"actors\": [\n" - " {\n" - " \"type\":\"ImageActor\",\n" - " \"name\":\"childImage\" \n" - " }\n" - " ]\n" - " }\n" - "},\n" - " \"stage\": [\n" - " {\n" - " \"type\": \"imageTree\",\n" - " \"name\": \"Image1\",\n" - " \"effect\": \"Ripple2D\",\n" - " \"image\": \"offscreen\"" - " }\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 = uTextureRect.zw - uTextureRect.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" - " \"frameBufferImages\": {\n" - " \"offscreen\": {\n" - " \"type\": \"FrameBufferImage\"," - " \"pixelFormat\":\"RGBA8888\"," - " \"width\": 400," - " \"height\": 400" - " }" - " }" - "}\n" - - ); - - Builder builder = Builder::New(); - builder.LoadFromString( json ); - - // coverage - DALI_TEST_CHECK( true ); - - END_TEST; -} int UtcDaliBuilderAddActorsP(void) { @@ -1109,7 +1198,7 @@ int UtcDaliBuilderAddActorsP(void) " \"visible\": false\n" " }],\n" " \"signals\": [{\n" - " \"name\": \"touched\",\n" + " \"name\": \"touch\",\n" " \"action\": \"hide\",\n" " \"actor\": \"actor\",\n" " \"childActor\": \"subActor\"\n" @@ -1120,156 +1209,16 @@ int UtcDaliBuilderAddActorsP(void) Builder builder = Builder::New(); builder.LoadFromString( json ); - builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() ); + builder.AddActors ( "arbitarysection", application.GetScene().GetRootLayer() ); // Render and notify application.SendNotification(); application.Render(); - Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor"); + Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor"); DALI_TEST_CHECK( actor ); - DALI_TEST_CHECK( !actor.IsVisible() ); - - END_TEST; -} - -int UtcDaliBuilderFrameBufferP(void) -{ - ToolkitTestApplication application; - - // JSON with a quit event when the actor is touched - std::string json( - "{\n" - " \"constants\":\n" - " {\n" - " \"FB_WIDTH\": 200.0,\n" - " \"FB_HEIGHT\": 200.0,\n" - " \"FB_SIZE\": [200,200],\n" - " \"FB_ASPECT_RATIO\": 1\n" - " },\n" - " \"stage\": [\n" - " {\n" - " \"type\": \"ImageActor\",\n" - " \"name\": \"fbOnStage\",\n" - " \"position\": [\n" - " 0.40461349487305,\n" - " 0.9150390625,\n" - " 0.0\n" - " ],\n" - " \"parentOrigin\": [0.5, 0.5, 0.5],\n" - " \"size\": [300, 300, 0],\n" - " \"image\": \"fb0\",\n" - " \"clearColor\": [1,0,0,1]\n" - " },\n" - " {\n" - " \"type\": \"ImageActor\",\n" - " \"name\": \"Image1\",\n" - " \"size\": [200, 200, 0],\n" - " \"parentOrigin\": [0.5, 0.5, 0.5],\n" - " \"effect\": \"Ripple2D\",\n" - " \"image\": {\n" - " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n" - " \"width\": 200,\n" - " \"height\": 80,\n" - " \"loadPolicy\": \"IMMEDIATE\",\n" - " \"releasePolicy\": \"NEVER\"\n" - " },\n" - " \"signals\": [\n" - " {\n" - " \"name\": \"onStage\",\n" - " \"action\": \"play\",\n" - " \"animation\": \"Animation_1\"\n" - " }\n" - " ]\n" - " },\n" - " {\n" - " \"type\":\"CameraActor\",\n" - " \"name\":\"fbCam\",\n" - " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n" - " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n" - " \"fieldOfView\": 0.785,\n" - " \"invertYAxis\": true\n" - " }\n" - " ],\n" - " \"frameBufferImages\":\n" - " {\n" - " \"fb0\":\n" - " {\n" - " \"type\": \"FrameBufferImage\",\n" - " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n" - " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n" - " }\n" - " },\n" - " \"renderTasks\":\n" - " {\n" - " \"stage\":\n" - " [\n" - " {\n" - " \"sourceActor\": \"fbOnStage\"\n" - " },\n" - " {\n" - " \"sourceActor\": \"Image1\",\n" - " \"targetFrameBuffer\": \"fb0\",\n" - " \"viewportSize\":\"{FB_SIZE}\",\n" - " \"cameraActor\":\"fbCam\"\n" - " }\n" - " ]\n" - " },\n" - " \"paths\": {},\n" - " \"animations\": {\n" - " \"Animation_1\": {\n" - " \"loop\":true,\n" - " \"properties\": [\n" - " {\n" - " \"actor\": \"Image1\",\n" - " \"property\": \"uTime\",\n" - " \"value\": 10.0,\n" - " \"alphaFunction\": \"LINEAR\",\n" - " \"timePeriod\": {\n" - " \"delay\": 0,\n" - " \"duration\": 10.0\n" - " },\n" - " \"gui-builder-timeline-color\": \"#8dc0da\"\n" - " }\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 = uTextureRect.zw - uTextureRect.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"); - - Builder builder = Builder::New(); - - // frame buffer coverage - builder.LoadFromString( json ); - - // Render and notify - application.SendNotification(); - application.Render(); - - Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" ); - DALI_TEST_CHECK( frameBuffer ); - - Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" ); - DALI_TEST_CHECK( frameBuffer2 ); - DALI_TEST_CHECK( frameBuffer == frameBuffer2 ); - - DALI_TEST_CHECK( true ); + DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); END_TEST; } @@ -1290,26 +1239,22 @@ int UtcDaliBuilderPathConstraintsP(void) " },\n" " \"stage\": [\n" " {\n" - " \"type\": \"ImageActor\",\n" + " \"type\": \"ImageView\",\n" " \"name\": \"Image1\",\n" " \"size\": [200, 200, 0],\n" " \"parentOrigin\": [0.5, 0.5, 0.5],\n" " \"effect\": \"Ripple2D\",\n" " \"image\": {\n" - " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n" - " \"width\": 200,\n" - " \"height\": 80,\n" - " \"loadPolicy\": \"IMMEDIATE\",\n" - " \"releasePolicy\": \"NEVER\"\n" + " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n" " },\n" " \"signals\": [\n" " {\n" - " \"name\": \"onStage\",\n" + " \"name\": \"onScene\",\n" " \"action\": \"play\",\n" " \"animation\": \"pathAnimation\"\n" " },\n" " {\n" - " \"name\": \"onStage\",\n" + " \"name\": \"onScene\",\n" " \"action\": \"applyConstraint\",\n" " \"constrainer\": \"constrainer0\",\n" " \"properties\":\n" @@ -1324,7 +1269,7 @@ int UtcDaliBuilderPathConstraintsP(void) " ]\n" " },\n" " {\n" - " \"name\": \"onStage\",\n" + " \"name\": \"onScene\",\n" " \"action\": \"applyConstraint\",\n" " \"constrainer\": \"constrainer1\",\n" " \"properties\":\n" @@ -1337,6 +1282,36 @@ int UtcDaliBuilderPathConstraintsP(void) " \"range\": [-300,300]\n" " }\n" " ]\n" + " },\n" + " {\n" + " \"name\": \"offScene\",\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\": \"offScene\",\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" @@ -1405,22 +1380,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 = uTextureRect.zw - uTextureRect.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"); @@ -1453,5 +1412,638 @@ int UtcDaliBuilderPathConstraintsP(void) Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" ); DALI_TEST_CHECK( constrainer1 == constrainer1_2 ); + // For coverage + + Actor actor = Actor::New(); + application.GetScene().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\":\"\"\n" + " }\n" + " ],\n" + " \"transition:buttonReleased\":\n" + " [\n" + " {\n" + " \"target\": \"unselectedBackgroundRenderer\",\n" + " \"property\": \"opacity\",\n" + " \"value\": 1,\n" + " \"animator\":\"\"\n" + " },\n" + " {\n" + " \"target\": \"unselectedForegroundRenderer\",\n" + " \"property\": \"scale\",\n" + " \"value\": [ 1, 1, 1 ],\n" + " \"animator\":\"\"\n" + " },\n" + " {\n" + " \"target\": \"selectedBackgroundRenderer\",\n" + " \"property\": \"opacity\",\n" + " \"value\": 0,\n" + " \"animator\": \"\"\n" + " },\n" + " {\n" + " \"target\": \"selectedForegroundRenderer\",\n" + " \"property\": \"scale\",\n" + " \"value\": [ 0, 0, 0 ],\n" + " \"animator\":\"\"\n" + " }\n" + " ]\n" + " },\n" + " \"styles\":\n" + " {\n" + " \"testbutton\":\n" + " {\n" + " \"pressTransition\":\"\",\n" + " \"releaseTransition\":\"\"\n" + " }\n" + " }\n" + "}\n"; + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + + Test::TestButton testButton = Test::TestButton::New(); + application.GetScene().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\":\"\",\n" + " \"cyclicKey2\":\"\",\n" + " \"cyclicKey3\":\"\",\n" + " \"FadeOut\":{\n" + " \"alphaFunction\":\"EASE_IN\",\n" + " \"timePeriod\":{\n" + " \"delay\":\"\",\n" + " \"duration\":0.6\n" + " }\n" + " },\n" + " \"transition:buttonPressed\":\n" + " [\n" + " {\n" + " \"target\": \"\",\n" + " \"property\": \"\",\n" + " \"value\": 0,\n" + " \"animator\":\"\"\n" + " }\n" + " ]\n" + " },\n" + " \"styles\":\n" + " {\n" + " \"testbutton\":\n" + " {\n" + " \"pressTransition\":\"\",\n" + " \"releaseTransition\":\"\",\n" + " \"disabledTransition\":\"\",\n" + " \"enabledTransition\":\"\"\n" + " }\n" + " }\n" + "}\n"); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + + Test::TestButton testButton = Test::TestButton::New(); + application.GetScene().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(); + application.GetScene().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.GetProperty< Vector2 >( Actor::Property::MAXIMUM_SIZE ), Vector2(100.0f,15.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION ); + DALI_TEST_EQUALS( createdActor.GetProperty< bool >( Actor::Property::SENSITIVE ), false, TEST_LOCATION ); + DALI_TEST_EQUALS( createdActor.GetProperty< ColorMode >( Actor::Property::COLOR_MODE ), 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(); + application.GetScene().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 UtcDaliBuilderCustomControl(void) +{ + ToolkitTestApplication application; + + std::string json( + "{" + "\"stage\":" + "[{" + "\"type\": \"DummyControl\"," + "\"name\": \"I can haz custom Control\"" + "}]" + "}" + ); + + Actor rootActor = Actor::New(); + application.GetScene().Add( rootActor ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + builder.AddActors( rootActor ); + + application.SendNotification(); + application.Render(); + + Actor customControl = rootActor.FindChildByName( "I can haz custom Control" ); + + // Test that we have the correct type of custom control + DummyControl dummyControl = DummyControl::DownCast( customControl ); + DALI_TEST_CHECK( dummyControl ); + if( dummyControl ) + { + DALI_TEST_CHECK( typeid(dummyControl.GetImplementation()) == typeid(DummyControlImpl) ); + } + + 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( application.GetScene().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(); + + DALI_TEST_CHECK( value ); + + END_TEST; +} + + +int UtcDaliBase64EncodingP(void) +{ + std::vector data = { 0, 1, 2, 3, 4, 5, std::numeric_limits::min(), std::numeric_limits::max() }; + + Property::Value value; + EncodeBase64PropertyData( value, data ); + + std::cout << "Max uint32_t:" << std::numeric_limits::max() << std::endl; + std::cout << "Input data: "; + std::ostream_iterator 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 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 +int b64l(std::vector&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 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 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 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 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 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 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 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 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 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 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 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 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 expectedResults = { 0xffffffff, 0xfefefefe, 0x00010203 }; + + std::vector outputData; + DecodeBase64PropertyData(Property::Value(testInput), outputData); + + DALI_TEST_EQUALS( std::equal( expectedResults.begin(), expectedResults.end(), outputData.begin() ), true, + TEST_LOCATION ); + END_TEST; }