2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/devel-api/builder/builder.h>
26 #include <dali-toolkit/devel-api/builder/base64-encoding.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <test-button.h>
30 #include <test-animation-data.h>
31 #include <dummy-control.h>
34 #define STRINGIFY(A)#A
37 using namespace Toolkit;
39 namespace BuilderControlProperty
44 INTEGER_PROPERTY = Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1,
55 return Toolkit::Control::New();
58 int gSetPropertyCalledCount = 0;
60 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
62 ++gSetPropertyCalledCount;
65 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
67 return Property::Value();
70 } // unnamed namespace
73 Dali::TypeRegistration typeRegistration( "BuilderControl", typeid( Toolkit::Control ), Create );
75 Dali::PropertyRegistration propertyInteger( typeRegistration, "integerProperty", INTEGER_PROPERTY, Property::INTEGER, &SetProperty, &GetProperty );
76 Dali::PropertyRegistration propertyMatrix3( typeRegistration, "matrix3Property", MATRIX3_PROPERTY, Property::MATRIX3, &SetProperty, &GetProperty );
77 Dali::PropertyRegistration propertyMatrix( typeRegistration, "matrixProperty", MATRIX_PROPERTY, Property::MATRIX, &SetProperty, &GetProperty );
78 Dali::PropertyRegistration propertyNone( typeRegistration, "noneProperty", NONE_PROPERTY, Property::NONE, &SetProperty, &GetProperty );
87 BuilderFunctor( bool& called ) : mCalled( called )
104 void builder_startup(void)
106 test_return_value = TET_UNDEF;
109 void builder_cleanup(void)
111 test_return_value = TET_PASS;
114 int UtcDaliBuilderQuitSignal(void)
116 ToolkitTestApplication application;
118 // JSON with a quit event when the actor is touched
123 "\"type\": \"Layer\","
124 "\"size\": [100,100,1],"
125 "\"parentOrigin\": \"TOP_LEFT\","
126 "\"anchorPoint\": \"TOP_LEFT\","
127 "\"maximumSize\": [100,100],"
128 "\"orientation\": [10,10,10,10],"
129 "\"clippingBox\": [10,10,10,10],"
131 "\"name\": \"touch\","
132 "\"action\": \"quit\""
137 Builder builder = Builder::New();
138 builder.LoadFromString( json );
139 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
141 // Connect to builder's quit signal
142 bool functorCalled( false );
143 builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
146 application.SendNotification();
147 application.Render();
149 // Emit touch event and check that our quit method is called
150 Integration::TouchEvent touchEvent;
151 Integration::Point point;
152 point.SetState( PointState::DOWN );
153 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
154 touchEvent.points.push_back( point );
155 application.ProcessEvent( touchEvent );
156 DALI_TEST_CHECK( functorCalled );
162 int UtcDaliBuilderAnimationP(void)
164 ToolkitTestApplication application;
166 // JSON with a quit event when the actor is touched
171 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
177 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
178 " \"curvature\":0.35"
184 " \"endAction\": \"BAKE\","
185 " \"disconnectAction\": \"BAKE\","
188 " \"actor\": \"greeting\","
189 " \"property\": \"position\","
190 " \"value\": [300, 300, -1000],"
191 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
192 " \"relative\": true,"
199 " \"actor\": \"greeting\","
200 " \"property\": \"visible\","
201 " \"alphaFunction\": \"LINEAR\","
205 " \"actor\": \"greeting\","
206 " \"property\": \"sizeWidth\","
207 " \"alphaFunction\": \"REVERSE\","
211 " \"actor\": \"greeting\","
212 " \"property\": \"orientation\","
213 " \"alphaFunction\": \"EASE_IN\","
214 " \"value\": [10.0,20.0,30.0]"
217 " \"actor\": \"greeting\","
218 " \"property\": \"orientation\","
219 " \"alphaFunction\": \"EASE_OUT\","
220 " \"value\": [0.0, 0.0, 0.0, 1.0]"
223 " \"actor\": \"greeting\","
224 " \"property\": \"orientation\","
225 " \"alphaFunction\": \"EASE_IN_OUT\","
226 " \"value\": [0.0, 0.0, 0.0, 1.0]"
229 " \"actor\": \"greeting\","
230 " \"property\": \"orientation\","
231 " \"alphaFunction\": \"EASE_IN_SINE\","
232 " \"value\": [0.0, 0.0, 0.0, 1.0]"
235 " \"actor\": \"greeting\","
236 " \"property\": \"orientation\","
237 " \"alphaFunction\": \"EASE_OUT_SINE\","
238 " \"value\": [0.0, 0.0, 0.0, 1.0]"
241 " \"actor\": \"greeting\","
242 " \"property\": \"orientation\","
243 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
244 " \"value\": [0.0, 0.0, 0.0, 1.0]"
247 " \"actor\": \"greeting\","
248 " \"property\": \"orientation\","
249 " \"alphaFunction\": \"BOUNCE\","
250 " \"value\": [0.0, 0.0, 0.0, 1.0]"
253 " \"actor\": \"greeting\","
254 " \"property\": \"orientation\","
255 " \"alphaFunction\": \"SIN\","
256 " \"value\": [0.0, 0.0, 0.0, 1.0]"
259 " \"actor\": \"greeting\","
260 " \"property\": \"orientation\","
261 " \"alphaFunction\": \"EASE_OUT_BACK\","
262 " \"value\": [0.0, 0.0, 0.0, 1.0]"
266 " \"pathAnimation\": {"
267 " \"duration\": 3.0,"
268 " \"endAction\": \"DISCARD\","
269 " \"disconnectAction\": \"BAKE_FINAL\","
270 " \"properties\": [{"
271 " \"actor\": \"greeting\","
272 " \"path\":\"path0\","
273 " \"forward\":[1,0,0],"
274 " \"alphaFunction\": \"EASE_IN_OUT\","
283 " \"name\": \"greeting\","
284 " \"type\": \"TextLabel\","
285 " \"text\": \"Touch me\","
286 " \"inherit\": [\"basicText\"],"
287 " \"position\": [0, -120, 0],"
288 " \"size\": [200, 200, 1],"
289 " \"orientation\": [0, 0, 30],"
291 " \"name\": \"touch\","
292 " \"action\": \"play\","
293 " \"animation\": \"animate\""
298 Builder builder = Builder::New();
299 builder.LoadFromString( json );
300 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
302 Animation anim = builder.CreateAnimation("animate");
304 DALI_TEST_CHECK( anim );
307 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
308 anim = builder.CreateAnimation("animate", map);
310 DALI_TEST_CHECK( anim );
312 anim = builder.CreateAnimation("pathAnimation");
314 DALI_TEST_CHECK( anim );
317 // Emit touch event and check that our quit method is called
318 Integration::TouchEvent touchEvent;
319 Integration::Point point;
320 point.SetState( PointState::DOWN );
321 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
322 touchEvent.points.push_back( point );
323 application.ProcessEvent( touchEvent );
326 application.SendNotification();
327 application.Render();
333 int UtcDaliBuilderAnimationN(void)
335 ToolkitTestApplication application;
337 // JSON with a quit event when the actor is touched
342 " \"TEXT\": \"Touch Me\","
343 " \"NAME\": \"greeting\" "
349 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
350 " \"curvature\":0.35"
356 " \"endAction\": \"BAKE\","
357 " \"disconnectAction\": \"BAKE\","
360 " \"actor\": \"{NAME}\","
361 " \"property\": \"positioninvalid\","
362 " \"value\": [300, 300, -1000],"
363 " \"alphaFunction\": \"EASE_IN_OUT\","
364 " \"relative\": true,"
374 " \"endAction\": \"BAKE\","
375 " \"disconnectAction\": \"BAKE\","
378 " \"actor\": \"{NAME}\","
379 " \"property\": \"positioninvalid\","
380 " \"value\": [300, 300, -1000],"
381 " \"alphaFunction\": \"EGGS_OVER_EASY\","
382 " \"relative\": true,"
390 " \"pathAnimation\": {"
391 " \"duration\": 3.0,"
392 " \"endAction\": \"DISCARD\","
393 " \"disconnectAction\": \"BAKE_FINAL\","
394 " \"properties\": [{"
395 " \"actor\": \"greeting\","
396 " \"path\":\"pathDoesntExist\","
397 " \"forward\":[1,0,0],"
398 " \"alphaFunction\": \"EASE_IN_OUT\","
407 " \"name\": \"greeting\","
408 " \"type\": \"TextLabel\","
409 " \"text\": \"Touch me\","
410 " \"inherit\": [\"basicText\"],"
411 " \"position\": [0, -120, 0],"
412 " \"size\": [200, 200, 1],"
413 " \"orientation\": [0, 0, 30],"
415 " \"name\": \"touch\","
416 " \"action\": \"play\","
417 " \"animation\": \"animate\""
421 " \"name\": \"greeting2\","
422 " \"type\": \"TextLabel\","
423 " \"text\": \"Touch me\""
428 Builder builder = Builder::New();
429 builder.LoadFromString( json );
430 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
432 Animation anim = builder.CreateAnimation("animate");
434 // log warning line coverage
435 anim = builder.CreateAnimation("pathAnimation");
436 DALI_TEST_CHECK(anim);
438 anim = builder.CreateAnimation("animate");
439 DALI_TEST_CHECK(anim);
441 anim = builder.CreateAnimation("animate2");
442 DALI_TEST_CHECK(anim);
444 // create referencing a different actor aka animation templates
446 map["NAME"] = "greeting2";
447 anim = builder.CreateAnimation("animate2", map);
448 DALI_TEST_CHECK(anim);
450 // alternative actor to use for FindChildByName
451 anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
452 DALI_TEST_CHECK(anim);
454 // alternative actor to use for FindChildByName
455 anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
456 DALI_TEST_CHECK(anim);
463 int UtcDaliBuilderConstantsP(void)
465 ToolkitTestApplication application;
467 // JSON with a quit event when the actor is touched
472 " \"IMAGE_PATH\": \"apath\","
474 " \"ANCHOR\": \"TOP_LEFT\","
475 " \"PADDING\": [1,2,3,4]"
479 " \"type\": \"ImageView\","
480 " \"name\": \"{NAME}\","
481 " \"size\": [100,100,1],"
482 " \"parentOrigin\": \"TOP_LEFT\","
483 " \"anchorPoint\": \"{ANCHOR}\","
484 " \"padding\": \"{PADDING}\","
485 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
486 " \"sizeWidth\": \"{WIDTH}\","
488 " \"name\": \"touch\","
489 " \"action\": \"quit\""
495 Builder builder = Builder::New();
496 builder.LoadFromString( json );
498 builder.AddConstant( "NAME", "image" );
500 Property::Map map = builder.GetConstants();
502 Dali::Property::Value* pValue = map.Find( "NAME" );
504 DALI_TEST_CHECK( pValue );
506 pValue = map.Find( "IMAGE_PATH" );
508 DALI_TEST_CHECK( pValue );
510 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
512 DALI_TEST_CHECK( value.GetType() != Property::NONE );
514 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
515 DALI_TEST_CHECK( builder );
517 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
518 DALI_TEST_CHECK( actor );
523 int UtcDaliBuilderTemplatesAndStylesP(void)
525 ToolkitTestApplication application;
527 // JSON with a quit event when the actor is touched
532 " \"SIZE\": [10,20,30]"
536 " \"imageStyle\": \n"
538 " \"color\": [1,0,0,1],\n"
540 " \"childImage\": {\n"
541 " \"color\": \"34\"\n"
548 " \"imageViewTemplate\": { \n"
549 " \"type\": \"ImageView\",\n"
550 " \"styles\": [\"imageStyle\"]\n"
552 " \"imageTree\": { \n"
553 " \"type\": \"ImageView\",\n"
554 " \"styles\": [\"imageStyle\"],\n"
555 " \"name\": \"image\",\n"
556 " \"size\": \"{SIZE}\",\n"
558 " \"name\": \"touch\",\n"
559 " \"action\": \"quit\"\n"
563 " \"type\":\"ImageView\",\n"
564 " \"name\":\"childImage\", \n"
574 " \"type\":\"imageViewTemplate\",\n"
575 " \"name\":\"childImage2\"\n"
582 " \"type\": \"imageTree\","
583 " \"size\": [100,100,1]"
588 std::string stylejson(
590 " \"color\": [1,0,0,1],\n"
592 " \"childImage\": {\n"
593 " \"color\": \"#344353\"\n"
599 std::string templatejson(
601 " \"type\": \"ImageView\",\n"
602 " \"styles\": [\"imageStyle\"],\n"
603 " \"name\": \"image\",\n"
604 " \"size\": \"{SIZE}\",\n"
606 " \"name\": \"touch\",\n"
607 " \"action\": \"quit\"\n"
611 " \"type\":\"ImageView\",\n"
612 " \"name\":\"childImage\" \n"
618 Builder builder = Builder::New();
619 builder.LoadFromString( json );
621 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
622 DALI_TEST_CHECK( actor );
624 Dali::Property::Map map;
625 map["SIZE"] = Vector3(100,100,1);
626 actor = ImageView::DownCast( builder.Create( "imageTree", map ) );
627 DALI_TEST_CHECK( actor );
629 // create from json snippet
630 actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
631 DALI_TEST_CHECK( actor );
634 // NB: already applied in create
635 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
637 // apply from json snippet
638 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
643 int UtcDaliBuilderRenderTasksP(void)
645 ToolkitTestApplication application;
647 // JSON with a quit event when the actor is touched
653 " \"sourceActor\": \"image\",\n"
654 " \"cameraActor\": \"camera\" \n"
660 " \"type\": \"CameraActor\",\n"
661 " \"name\": \"camera\"\n"
664 " \"type\": \"ImageView\",\n"
665 " \"name\": \"image\",\n"
666 " \"size\": [100,100,1],\n"
668 " \"name\": \"touch\",\n"
669 " \"action\": \"quit\"\n"
673 " \"type\":\"ImageView\",\n"
674 " \"name\":\"childImage\" \n"
682 Builder builder = Builder::New();
683 builder.LoadFromString( json );
685 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
688 builder.CreateRenderTask( "task0" );
690 DALI_TEST_CHECK( count <
691 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
696 int UtcDaliBuilderChildActionP(void)
698 ToolkitTestApplication application;
700 // JSON with a quit event when the actor is touched
705 " \"type\": \"Actor\",\n"
706 " \"name\": \"actor\",\n"
707 " \"size\": [100,100,1],\n"
708 " \"parentOrigin\": \"TOP_LEFT\",\n"
709 " \"anchorPoint\": \"TOP_LEFT\",\n"
711 " \"type\": \"Actor\",\n"
712 " \"name\": \"subActor\"\n"
715 " \"name\": \"touch\",\n"
716 " \"action\": \"hide\",\n"
717 " \"actor\": \"actor\",\n"
718 " \"childActor\": \"subActor\"\n"
724 Builder builder = Builder::New();
725 builder.LoadFromString( json );
726 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
729 application.SendNotification();
730 application.Render();
732 // Emit touch event and check that our quit method is called
733 Integration::TouchEvent touchEvent;
734 Integration::Point point;
735 point.SetState( PointState::DOWN );
736 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
737 touchEvent.points.push_back( point );
738 application.ProcessEvent( touchEvent );
741 application.SendNotification();
742 application.Render();
744 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
745 DALI_TEST_CHECK( actor );
747 DALI_TEST_CHECK( !actor.IsVisible() );
752 int UtcDaliBuilderSetPropertyActionP(void)
754 ToolkitTestApplication application;
756 // JSON with a quit event when the actor is touched
761 " \"type\": \"Actor\",\n"
762 " \"name\": \"actor\",\n"
763 " \"size\": [100,100,1],\n"
764 " \"parentOrigin\": \"TOP_LEFT\",\n"
765 " \"anchorPoint\": \"TOP_LEFT\",\n"
767 " \"type\": \"Actor\",\n"
768 " \"name\": \"subActor\"\n"
771 " \"name\": \"touch\",\n"
772 " \"action\": \"set\",\n"
773 " \"actor\": \"subActor\",\n"
774 " \"property\": \"visible\",\n"
775 " \"value\": false\n"
781 Builder builder = Builder::New();
782 builder.LoadFromString( json );
783 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
786 application.SendNotification();
787 application.Render();
789 // Emit touch event and check that our quit method is called
790 Integration::TouchEvent touchEvent;
791 Integration::Point point;
792 point.SetState( PointState::DOWN );
793 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
794 touchEvent.points.push_back( point );
795 application.ProcessEvent( touchEvent );
798 application.SendNotification();
799 application.Render();
801 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
802 DALI_TEST_CHECK( actor );
804 DALI_TEST_CHECK( !actor.IsVisible() );
809 int UtcDaliBuilderGenericActionP(void)
811 ToolkitTestApplication application;
813 // JSON with a quit event when the actor is touched
818 " \"type\": \"Actor\",\n"
819 " \"name\": \"actor\",\n"
820 " \"size\": [100,100,1],\n"
821 " \"parentOrigin\": \"TOP_LEFT\",\n"
822 " \"anchorPoint\": \"TOP_LEFT\",\n"
824 " \"type\": \"Actor\",\n"
825 " \"name\": \"subActor\"\n"
828 " \"name\": \"touch\",\n"
829 " \"action\": \"hide\"\n"
835 Builder builder = Builder::New();
836 builder.LoadFromString( json );
837 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
840 application.SendNotification();
841 application.Render();
843 // Emit touch event and check that our quit method is called
844 Integration::TouchEvent touchEvent;
845 Integration::Point point;
846 point.SetState( PointState::DOWN );
847 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
848 touchEvent.points.push_back( point );
849 application.ProcessEvent( touchEvent );
852 application.SendNotification();
853 application.Render();
855 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
856 DALI_TEST_CHECK( actor );
858 DALI_TEST_CHECK( !actor.IsVisible() );
863 int UtcDaliBuilderPropertyNotificationP(void)
865 ToolkitTestApplication application;
867 // JSON with a quit event when the actor is touched
872 " \"type\": \"Actor\",\n"
873 " \"name\": \"actor\",\n"
874 " \"size\": [100,100,1],\n"
875 " \"parentOrigin\": \"TOP_LEFT\",\n"
876 " \"anchorPoint\": \"TOP_LEFT\",\n"
878 " \"type\": \"Actor\",\n"
879 " \"name\": \"subActor\"\n"
882 " \"name\": \"touch\",\n"
883 " \"action\": \"hide\"\n"
885 " \"notifications\": [{\n"
886 " \"property\": \"visible\",\n"
887 " \"condition\": \"False\",\n"
888 " \"action\": \"show\"\n"
891 " \"property\": \"positionX\",\n"
892 " \"condition\": \"LessThan\",\n"
894 " \"action\": \"show\"\n"
897 " \"property\": \"positionY\",\n"
898 " \"condition\": \"GreaterThan\",\n"
899 " \"arg0\": 200.0,\n"
900 " \"action\": \"show\"\n"
903 " \"property\": \"positionZ\",\n"
904 " \"condition\": \"Inside\",\n"
907 " \"action\": \"show\"\n"
910 " \"property\": \"positionZ\",\n"
911 " \"condition\": \"Outside\",\n"
914 " \"action\": \"show\"\n"
920 Builder builder = Builder::New();
921 builder.LoadFromString( json );
922 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
925 application.SendNotification();
926 application.Render();
928 // Emit touch event and check that our quit method is called
929 Integration::TouchEvent touchEvent;
930 Integration::Point point;
931 point.SetState( PointState::DOWN );
932 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
933 touchEvent.points.push_back( point );
934 application.ProcessEvent( touchEvent );
937 application.SendNotification();
938 application.Render();
941 application.SendNotification();
942 application.Render();
944 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
945 DALI_TEST_CHECK( actor );
947 DALI_TEST_CHECK( actor.IsVisible() );
952 int UtcDaliBuilderPropertyNotificationN(void)
954 ToolkitTestApplication application;
956 // JSON with a quit event when the actor is touched
961 " \"type\": \"Actor\",\n"
962 " \"notifications\": [{\n"
963 " \"property\": \"visible\",\n"
964 " \"condition\": \"ErrorCondition\",\n"
965 " \"action\": \"show\"\n"
973 Builder builder = Builder::New();
974 builder.LoadFromString( json );
975 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
976 DALI_TEST_CHECK( false );
980 DALI_TEST_CHECK( true );
988 int UtcDaliBuilderCustomPropertyP(void)
990 ToolkitTestApplication application;
992 // JSON with a quit event when the actor is touched
997 " \"imageTree\": { \n"
998 " \"type\": \"ImageView\",\n"
999 " \"name\": \"image\",\n"
1000 " \"size\": [100,100,1],\n"
1001 " \"signals\": [{\n"
1002 " \"name\": \"touch\",\n"
1003 " \"action\": \"quit\"\n"
1005 " \"properties\": {\n"
1006 " \"newproperty\": true\n"
1008 " \"animatableProperties\": {\n"
1009 " \"newAnimatableproperty\": 3\n"
1013 " \"type\":\"ImageView\",\n"
1014 " \"name\":\"childImage\" \n"
1022 Builder builder = Builder::New();
1023 builder.LoadFromString( json );
1025 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
1026 DALI_TEST_CHECK( actor );
1028 // NB: already applied in create
1029 Property::Index index = actor.GetPropertyIndex("newproperty");
1030 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
1031 Property::Value value = actor.GetProperty(index);
1032 DALI_TEST_CHECK( value.Get<bool>() == true );
1034 index = actor.GetPropertyIndex("newAnimatableproperty");
1035 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
1036 value = actor.GetProperty(index);
1037 DALI_TEST_CHECK( value.Get<int>() == 3 );
1042 int UtcDaliBuilderCustomShaderP(void)
1044 ToolkitTestApplication application;
1046 // JSON with a quit event when the actor is touched
1051 " \"type\": \"ImageView\",\n"
1052 " \"name\": \"Image1\",\n"
1053 " \"position\": [\n"
1054 " 0.40461349487305,\n"
1058 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1059 " \"size\": [200, 200, 0],\n"
1060 " \"effect\": \"Ripple2D\",\n"
1062 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1063 " \"desiredWidth\": 200,\n"
1064 " \"desiredHeight\": 80,\n"
1066 " \"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"
1069 " \"customAnimatableProperties\": {\n"
1070 " \"uAmplitude\": 0.02,\n"
1075 " \"name\": \"onStage\",\n"
1076 " \"action\": \"play\",\n"
1077 " \"animation\": \"Animation_1\"\n"
1082 " \"animations\": {\n"
1083 " \"Animation_1\": {\n"
1085 " \"properties\": [\n"
1087 " \"actor\": \"Image1\",\n"
1088 " \"property\": \"uTime\",\n"
1089 " \"value\": 10.0,\n"
1090 " \"alphaFunction\": \"LINEAR\",\n"
1091 " \"timePeriod\": {\n"
1093 " \"duration\": 10.0\n"
1103 Builder builder = Builder::New();
1104 builder.LoadFromString( json );
1106 builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
1108 // Render and notify
1109 application.SendNotification();
1110 application.Render();
1112 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
1115 DALI_TEST_CHECK( actor );
1121 int UtcDaliBuilderLoadFromStringN(void)
1123 ToolkitTestApplication application;
1125 // JSON with a quit event when the actor is touched
1127 "asdfsadf dsf asdf asdf {"
1130 "\"type\": \"Actor\","
1131 "\"size\": [100,100,1],"
1132 "\"parentOrigin\": \"TOP_LEFT\","
1133 "\"anchorPoint\": \"TOP_LEFT\","
1135 "\"name\": \"touch\","
1136 "\"action\": \"quit\""
1141 Builder builder = Builder::New();
1143 bool assert1 = false;
1147 builder.LoadFromString( json );
1149 catch( Dali::DaliException& e )
1151 DALI_TEST_PRINT_ASSERT( e );
1152 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1156 DALI_TEST_CHECK( assert1 );
1162 int UtcDaliBuilderAddActorsP(void)
1164 ToolkitTestApplication application;
1166 // JSON with a quit event when the actor is touched
1169 " \"arbitarysection\":\n"
1171 " \"type\": \"Actor\",\n"
1172 " \"name\": \"actor\",\n"
1173 " \"size\": [100,100,1],\n"
1174 " \"parentOrigin\": \"TOP_LEFT\",\n"
1175 " \"anchorPoint\": \"TOP_LEFT\",\n"
1177 " \"type\": \"Actor\",\n"
1178 " \"name\": \"subActor\",\n"
1179 " \"visible\": false\n"
1181 " \"signals\": [{\n"
1182 " \"name\": \"touch\",\n"
1183 " \"action\": \"hide\",\n"
1184 " \"actor\": \"actor\",\n"
1185 " \"childActor\": \"subActor\"\n"
1191 Builder builder = Builder::New();
1192 builder.LoadFromString( json );
1193 builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1195 // Render and notify
1196 application.SendNotification();
1197 application.Render();
1199 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1200 DALI_TEST_CHECK( actor );
1202 DALI_TEST_CHECK( !actor.IsVisible() );
1207 int UtcDaliBuilderFrameBufferP(void)
1209 ToolkitTestApplication application;
1211 // JSON with a quit event when the actor is touched
1216 " \"FB_WIDTH\": 200.0,\n"
1217 " \"FB_HEIGHT\": 200.0,\n"
1218 " \"FB_SIZE\": [200,200],\n"
1219 " \"FB_ASPECT_RATIO\": 1\n"
1223 " \"type\": \"ImageView\",\n"
1224 " \"name\": \"fbOnStage\",\n"
1225 " \"position\": [\n"
1226 " 0.40461349487305,\n"
1230 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1231 " \"size\": [300, 300, 0],\n"
1232 " \"image\": \"fb0\",\n"
1233 " \"clearColor\": [1,0,0,1]\n"
1236 " \"type\": \"ImageView\",\n"
1237 " \"name\": \"Image1\",\n"
1238 " \"size\": [200, 200, 0],\n"
1239 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1240 " \"effect\": \"Ripple2D\",\n"
1242 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1246 " \"name\": \"onStage\",\n"
1247 " \"action\": \"play\",\n"
1248 " \"animation\": \"Animation_1\"\n"
1253 " \"type\":\"CameraActor\",\n"
1254 " \"name\":\"fbCam\",\n"
1255 " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1256 " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1257 " \"fieldOfView\": 0.785,\n"
1258 " \"invertYAxis\": true\n"
1261 " \"frameBufferImages\":\n"
1265 " \"type\": \"FrameBufferImage\",\n"
1266 " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1267 " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1270 " \"renderTasks\":\n"
1275 " \"sourceActor\": \"fbOnStage\"\n"
1278 " \"sourceActor\": \"Image1\",\n"
1279 " \"targetFrameBuffer\": \"fb0\",\n"
1280 " \"viewportSize\":\"{FB_SIZE}\",\n"
1281 " \"cameraActor\":\"fbCam\"\n"
1286 " \"animations\": {\n"
1287 " \"Animation_1\": {\n"
1289 " \"properties\": [\n"
1291 " \"actor\": \"Image1\",\n"
1292 " \"property\": \"uTime\",\n"
1293 " \"value\": 10.0,\n"
1294 " \"alphaFunction\": \"LINEAR\",\n"
1295 " \"timePeriod\": {\n"
1297 " \"duration\": 10.0\n"
1299 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1306 Builder builder = Builder::New();
1308 // frame buffer coverage
1309 builder.LoadFromString( json );
1311 // Render and notify
1312 application.SendNotification();
1313 application.Render();
1315 Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1316 DALI_TEST_CHECK( frameBuffer );
1318 Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1319 DALI_TEST_CHECK( frameBuffer2 );
1320 DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1322 DALI_TEST_CHECK( true );
1327 int UtcDaliBuilderPathConstraintsP(void)
1329 ToolkitTestApplication application;
1331 // JSON with a quit event when the actor is touched
1336 " \"FB_WIDTH\": 200.0,\n"
1337 " \"FB_HEIGHT\": 200.0,\n"
1338 " \"FB_SIZE\": [200,200],\n"
1339 " \"FB_ASPECT_RATIO\": 1\n"
1343 " \"type\": \"ImageView\",\n"
1344 " \"name\": \"Image1\",\n"
1345 " \"size\": [200, 200, 0],\n"
1346 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1347 " \"effect\": \"Ripple2D\",\n"
1349 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1353 " \"name\": \"onStage\",\n"
1354 " \"action\": \"play\",\n"
1355 " \"animation\": \"pathAnimation\"\n"
1358 " \"name\": \"onStage\",\n"
1359 " \"action\": \"applyConstraint\",\n"
1360 " \"constrainer\": \"constrainer0\",\n"
1361 " \"properties\":\n"
1364 " \"source\": \"Image1\",\n"
1365 " \"sourceProperty\": \"positionX\",\n"
1366 " \"target\": \"Image1\",\n"
1367 " \"targetProperty\": \"colorRed\",\n"
1368 " \"range\": [-300,300]\n"
1373 " \"name\": \"onStage\",\n"
1374 " \"action\": \"applyConstraint\",\n"
1375 " \"constrainer\": \"constrainer1\",\n"
1376 " \"properties\":\n"
1379 " \"source\": \"Image1\",\n"
1380 " \"sourceProperty\": \"positionX\",\n"
1381 " \"target\": \"Image1\",\n"
1382 " \"targetProperty\": \"colorBlue\",\n"
1383 " \"range\": [-300,300]\n"
1388 " \"name\": \"offStage\",\n"
1389 " \"action\": \"removeConstraints\",\n"
1390 " \"constrainer\": \"constrainer0\",\n"
1391 " \"properties\":\n"
1394 " \"source\": \"Image1\",\n"
1395 " \"sourceProperty\": \"positionX\",\n"
1396 " \"target\": \"Image1\",\n"
1397 " \"targetProperty\": \"colorRed\",\n"
1398 " \"range\": [-300,300]\n"
1403 " \"name\": \"offStage\",\n"
1404 " \"action\": \"removeConstraints\",\n"
1405 " \"constrainer\": \"constrainer1\",\n"
1406 " \"properties\":\n"
1409 " \"source\": \"Image1\",\n"
1410 " \"sourceProperty\": \"positionX\",\n"
1411 " \"target\": \"Image1\",\n"
1412 " \"targetProperty\": \"colorBlue\",\n"
1413 " \"range\": [-300,300]\n"
1424 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1425 " \"curvature\":0.35\n"
1428 " \"constrainers\":\n"
1430 " \"constrainer0\":\n"
1432 " \"type\": \"PathConstrainer\",\n"
1433 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1434 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1436 " \"constrainer1\":\n"
1438 " \"type\": \"LinearConstrainer\",\n"
1439 " \"value\": [ 0, 0, 0 ]\n"
1442 " \"animations\": {\n"
1443 " \"pathAnimation\": {\n"
1444 " \"duration\": 3.0,\n"
1445 " \"properties\":\n"
1447 " \"actor\": \"Image1\",\n"
1448 " \"path\":\"path0\",\n"
1449 " \"forward\":[1,0,0],\n"
1450 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1451 " \"timePeriod\": {\n"
1453 " \"duration\": 3\n"
1457 " \"actor\": \"Image1\",\n"
1458 " \"property\": \"uTime\",\n"
1459 " \"value\": 10.0,\n"
1460 " \"alphaFunction\": \"LINEAR\",\n"
1461 " \"timePeriod\": {\n"
1463 " \"duration\": 10.0\n"
1465 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1468 " \"Animation_1\": {\n"
1470 " \"properties\": [\n"
1472 " \"actor\": \"Image1\",\n"
1473 " \"property\": \"uTime\",\n"
1474 " \"value\": 10.0,\n"
1475 " \"alphaFunction\": \"LINEAR\",\n"
1476 " \"timePeriod\": {\n"
1478 " \"duration\": 10.0\n"
1480 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1487 Builder builder = Builder::New();
1489 // frame buffer coverage
1490 builder.LoadFromString( json );
1492 // Render and notify
1493 application.SendNotification();
1494 application.Render();
1496 Dali::Path path = builder.GetPath( "path0" );
1497 DALI_TEST_CHECK( path );
1499 Dali::Path path2 = builder.GetPath( "path0" );
1500 DALI_TEST_CHECK( path2 );
1501 DALI_TEST_CHECK( path == path2 );
1503 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1504 DALI_TEST_CHECK( constrainer0 );
1506 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1507 DALI_TEST_CHECK( constrainer0_2 );
1508 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1510 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1511 DALI_TEST_CHECK( constrainer1 );
1513 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1514 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1518 Actor actor = Actor::New();
1519 Stage::GetCurrent().Add( actor );
1520 builder.AddActors( actor );
1522 // Render and notify
1523 application.SendNotification();
1524 application.Render();
1526 actor.GetChildAt( 0 ).Unparent();
1531 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1533 Property::Value* value = xMap->Find( xKey ); \
1534 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1535 if( value != NULL ) \
1537 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1539 value->Get(result); \
1540 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1541 std::ostringstream oss; \
1542 oss << "Animation element " << xKey << "= " << result << std::endl; \
1543 tet_printf( oss.str().c_str() ); \
1547 tet_printf("Can't find map element " xKey "\n"); \
1552 int UtcDaliBuilderMapping01(void)
1554 ToolkitTestApplication application;
1560 " \"buttonPressFadeOut\":{\n"
1561 " \"alphaFunction\":\"EASE_OUT\",\n"
1562 " \"timePeriod\":{\n"
1564 " \"duration\":0.4\n"
1567 " \"buttonPressFadeIn\":{\n"
1568 " \"alphaFunction\":\"EASE_IN\",\n"
1569 " \"timePeriod\":{\n"
1571 " \"duration\":0.5\n"
1574 " \"transition:buttonPressed\":\n"
1577 " \"target\": \"unselectedBackgroundRenderer\",\n"
1578 " \"property\": \"opacity\",\n"
1580 " \"animator\":\"<buttonPressFadeOut>\"\n"
1583 " \"transition:buttonReleased\":\n"
1586 " \"target\": \"unselectedBackgroundRenderer\",\n"
1587 " \"property\": \"opacity\",\n"
1589 " \"animator\":\"<buttonPressFadeIn>\"\n"
1592 " \"target\": \"unselectedForegroundRenderer\",\n"
1593 " \"property\": \"scale\",\n"
1594 " \"value\": [ 1, 1, 1 ],\n"
1595 " \"animator\":\"<buttonPressFadeIn>\"\n"
1598 " \"target\": \"selectedBackgroundRenderer\",\n"
1599 " \"property\": \"opacity\",\n"
1601 " \"animator\": \"<buttonPressFadeOut>\"\n"
1604 " \"target\": \"selectedForegroundRenderer\",\n"
1605 " \"property\": \"scale\",\n"
1606 " \"value\": [ 0, 0, 0 ],\n"
1607 " \"animator\":\"<buttonPressFadeOut>\"\n"
1613 " \"testbutton\":\n"
1615 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1616 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1621 Builder builder = Builder::New();
1622 builder.LoadFromString( json );
1624 Test::TestButton testButton = Test::TestButton::New();
1625 Stage::GetCurrent().Add( testButton );
1627 // Render and notify
1628 application.SendNotification();
1629 application.Render();
1631 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1633 // Now check that it has loaded the transition correctly:
1634 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1635 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1636 Property::Array* array = transition.GetArray();
1638 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1639 Property::Value element = array->GetElementAt(0);
1640 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1641 Property::Map* map = element.GetMap();
1643 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1644 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1645 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1646 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1647 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1653 int UtcDaliBuilderMappingCycleCheck(void)
1655 ToolkitTestApplication application;
1661 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1662 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1663 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1665 " \"alphaFunction\":\"EASE_IN\",\n"
1666 " \"timePeriod\":{\n"
1667 " \"delay\":\"<cyclicKey3>\",\n"
1668 " \"duration\":0.6\n"
1671 " \"transition:buttonPressed\":\n"
1674 " \"target\": \"<cyclicKey1>\",\n"
1675 " \"property\": \"<cyclicKey2>\",\n"
1677 " \"animator\":\"<FadeOut>\"\n"
1683 " \"testbutton\":\n"
1685 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1686 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1687 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1688 " \"enabledTransition\":\"<unknownKey>\"\n"
1693 Builder builder = Builder::New();
1694 builder.LoadFromString( json );
1696 Test::TestButton testButton = Test::TestButton::New();
1697 Stage::GetCurrent().Add( testButton );
1699 // Render and notify
1700 application.SendNotification();
1701 application.Render();
1703 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1705 // Now check that it has loaded the transition correctly:
1706 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1707 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1708 Property::Array* array = transition.GetArray();
1710 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1711 Property::Value element = array->GetElementAt(0);
1712 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1713 Property::Map* map = element.GetMap();
1715 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1716 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1717 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1722 int UtcDaliBuilderTypeCasts(void)
1724 ToolkitTestApplication application;
1730 "\"type\": \"Layer\","
1731 "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1732 "\"position\": { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1733 "\"color\": { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1734 "\"sensitive\": { \"typeCast\":\"boolean\", \"value\":false },"
1735 "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1736 "\"colorMode\": { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1737 "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
1738 "\"padding\": { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
1743 Actor rootActor = Actor::New();
1744 Stage::GetCurrent().Add( rootActor );
1746 Builder builder = Builder::New();
1747 builder.LoadFromString( json );
1748 builder.AddActors( rootActor );
1750 application.SendNotification();
1751 application.Render();
1753 Actor createdActor = rootActor.GetChildAt( 0 );
1754 DALI_TEST_EQUALS( createdActor.GetMaximumSize(), Vector2(100.0f,15.0f), TEST_LOCATION );
1755 DALI_TEST_EQUALS( createdActor.GetCurrentPosition(), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
1756 DALI_TEST_EQUALS( createdActor.GetCurrentColor(), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
1757 DALI_TEST_EQUALS( createdActor.IsSensitive(), false, TEST_LOCATION );
1758 DALI_TEST_EQUALS( createdActor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
1763 int UtcDaliBuilderBuilderControl(void)
1765 ToolkitTestApplication application;
1771 "\"type\": \"BuilderControl\","
1772 "\"integerProperty\": 10,"
1773 "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
1774 "\"matrixProperty\": [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
1775 "\"noneProperty\": 10"
1780 Actor rootActor = Actor::New();
1781 Stage::GetCurrent().Add( rootActor );
1783 Builder builder = Builder::New();
1784 builder.LoadFromString( json );
1785 builder.AddActors( rootActor );
1787 application.SendNotification();
1788 application.Render();
1790 DALI_TEST_EQUALS( BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION );
1795 int UtcDaliBuilderCustomControl(void)
1797 ToolkitTestApplication application;
1803 "\"type\": \"DummyControl\","
1804 "\"name\": \"I can haz custom Control\""
1809 Actor rootActor = Actor::New();
1810 Stage::GetCurrent().Add( rootActor );
1812 Builder builder = Builder::New();
1813 builder.LoadFromString( json );
1814 builder.AddActors( rootActor );
1816 application.SendNotification();
1817 application.Render();
1819 Actor customControl = rootActor.FindChildByName( "I can haz custom Control" );
1821 // Test that we have the correct type of custom control
1822 DummyControl dummyControl = DummyControl::DownCast( customControl );
1823 DALI_TEST_CHECK( dummyControl );
1826 DALI_TEST_CHECK( typeid(dummyControl.GetImplementation()) == typeid(DummyControlImpl) );
1832 int UtcDaliBuilderActionsWithParams(void)
1834 ToolkitTestApplication application;
1836 // JSON with a quit event when the actor is touched
1842 " \"type\": \"ImageView\",\n"
1843 " \"name\": \"image\",\n"
1844 " \"size\": [100,100,1],\n"
1845 " \"signals\": [{\n"
1846 " \"name\": \"touch\",\n"
1847 " \"action\": \"show\",\n"
1848 " \"parameters\": {\n"
1849 " \"property1\" : 10,\n"
1850 " \"property2\" : [1,2],\n"
1851 " \"property3\" : [1,2,3],\n"
1852 " \"property4\" : [1,2,3,4]\n"
1860 Builder builder = Builder::New();
1861 builder.LoadFromString( json );
1862 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
1864 DALI_TEST_CHECK( true ); // For Coverage
1869 int UtcDaliBuilderConfigurationP(void)
1871 ToolkitTestApplication application;
1873 // JSON with a quit event when the actor is touched
1878 " \"alwaysShowFocus\":true\n"
1883 Builder builder = Builder::New();
1884 builder.LoadFromString( json );
1886 Property::Map map = builder.GetConfigurations();
1888 Dali::Property::Value* pValue = map.Find( "alwaysShowFocus" );
1890 DALI_TEST_CHECK( pValue );
1892 bool value = pValue->Get<bool>();
1894 DALI_TEST_CHECK( value );
1900 int UtcDaliBase64EncodingP(void)
1902 std::vector<uint32_t> data = { 0, 1, 2, 3, 4, 5, std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max() };
1904 Property::Value value;
1905 EncodeBase64PropertyData( value, data );
1907 std::cout << "Max uint32_t:" << std::numeric_limits<uint32_t>::max() << std::endl;
1908 std::cout << "Input data: ";
1909 std::ostream_iterator<uint32_t> out_it (std::cout,", ");
1910 std::copy ( data.begin(), data.end(), out_it );
1911 std::cout << std::endl;
1914 DALI_TEST_CHECK( value.Get( output ) );
1915 DALI_TEST_EQUALS( output, "AAAAAAEAAAACAAAAAwAAAAQAAAAFAAAAAAAAAP////8", TEST_LOCATION );
1917 std::cout << "Output data: " << output << std::endl;
1922 int UtcDaliBase64EncodingN(void)
1924 tet_infoline( "Test encoding an empty vector returns empty string" );
1925 std::vector<uint32_t> data;
1927 Property::Value value;
1928 EncodeBase64PropertyData( value, data );
1931 DALI_TEST_CHECK( value.Get( output ) );
1932 DALI_TEST_EQUALS( output.empty(), true, TEST_LOCATION );
1937 template <typename T>
1938 int b64l(std::vector<T>&data)
1940 auto lengthInBytes = 4*data.size();
1941 return ceil( lengthInBytes * 1.33333f );
1944 int UtcDaliBase64EncodingP02(void)
1946 tet_infoline( "Test encoding vectors of lengths m .. m+4 encode and decode back to the same length vectors" );
1948 std::vector<uint32_t> testData;
1949 for(int i=0; i<8; ++i ) // 8 chosen to stay within single string output
1951 testData.push_back(i);
1953 Property::Value value;
1954 EncodeBase64PropertyData( value, testData );
1957 DALI_TEST_CHECK( value.Get( output ) );
1958 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1959 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1961 std::vector<uint32_t> outData;
1962 DecodeBase64PropertyData( value, outData );
1963 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1964 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1967 testData.push_back( 12345 );
1968 EncodeBase64PropertyData( value, testData );
1970 DALI_TEST_CHECK( value.Get( output ) );
1971 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1972 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1975 DecodeBase64PropertyData( value, outData );
1976 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1977 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1980 testData.push_back( 67890 );
1981 EncodeBase64PropertyData( value, testData );
1983 DALI_TEST_CHECK( value.Get( output ) );
1984 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1985 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1988 DecodeBase64PropertyData( value, outData );
1989 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1990 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1993 testData.push_back( -1 );
1994 EncodeBase64PropertyData( value, testData );
1996 DALI_TEST_CHECK( value.Get( output ) );
1997 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1998 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
2001 DecodeBase64PropertyData( value, outData );
2002 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2003 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
2010 int UtcDaliBase64EncodingP03(void)
2012 tet_infoline( "Test encoding a vector of length 12 has output within single string" );
2014 std::vector<uint32_t> testData;
2015 for(int i=0; i<12; ++i )
2017 testData.push_back(i);
2019 Property::Value value;
2020 EncodeBase64PropertyData( value, testData );
2023 DALI_TEST_CHECK( value.Get( output ) );
2024 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
2025 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
2027 std::vector<uint32_t> outData;
2028 DecodeBase64PropertyData( value, outData );
2029 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2035 int UtcDaliBase64EncodingP04(void)
2037 tet_infoline( "Test encoding a vector of length 13 has output split over 2 strings" );
2039 std::vector<uint32_t> testData;
2040 for(int i=0; i<13; ++i )
2042 testData.push_back(i);
2044 Property::Value value;
2045 EncodeBase64PropertyData( value, testData );
2047 auto array = value.GetArray();
2048 DALI_TEST_CHECK( array );
2050 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
2052 std::vector<uint32_t> outData;
2053 DecodeBase64PropertyData( value, outData );
2054 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2060 int UtcDaliBase64EncodingP05(void)
2062 tet_infoline( "Test encoding a vector of length 24 has output split over 2 strings" );
2064 std::vector<uint32_t> testData;
2065 for(int i=0; i<24; ++i )
2067 testData.push_back(i);
2069 Property::Value value;
2070 EncodeBase64PropertyData( value, testData );
2072 auto array = value.GetArray();
2073 DALI_TEST_CHECK( array );
2075 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
2077 std::vector<uint32_t> outData;
2078 DecodeBase64PropertyData( value, outData );
2079 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2085 int UtcDaliBase64EncodingP06(void)
2087 tet_infoline( "Test encoding a vector of arbitrary length decodes OK." );
2089 std::vector<uint32_t> testData;
2090 for(int i=0; i<97; ++i )
2092 testData.push_back(i);
2094 Property::Value value;
2095 EncodeBase64PropertyData( value, testData );
2097 auto array = value.GetArray();
2098 DALI_TEST_CHECK( array );
2100 std::vector<uint32_t> outData;
2101 DecodeBase64PropertyData( value, outData );
2102 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2108 int UtcDaliBase64DecodingN01(void)
2110 tet_infoline( "Test decoding empty string results in empty data" );
2112 Property::Value value("");
2113 std::vector<uint32_t> outputData;
2114 DecodeBase64PropertyData( value, outputData);
2115 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2120 int UtcDaliBase64DecodingN02(void)
2122 tet_infoline( "Test decoding array with non-string values results in empty data" );
2124 Property::Array array;
2126 array[0] = "Stuff, things";
2128 Property::Value value(array);
2130 std::vector<uint32_t> outputData;
2131 DecodeBase64PropertyData( value, outputData);
2132 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2136 int UtcDaliBase64DecodingP01(void)
2138 tet_infoline( "Test decoding string of known data gives expected result");
2140 std::string testInput("//////7+/v4DAgEA");
2141 std::vector<uint32_t> expectedResults = { 0xffffffff, 0xfefefefe, 0x00010203 };
2143 std::vector<uint32_t> outputData;
2144 DecodeBase64PropertyData(Property::Value(testInput), outputData);
2146 DALI_TEST_EQUALS( std::equal( expectedResults.begin(), expectedResults.end(), outputData.begin() ), true,