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.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
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.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
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.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
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.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
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.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
1207 int UtcDaliBuilderPathConstraintsP(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\": \"Image1\",\n"
1225 " \"size\": [200, 200, 0],\n"
1226 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1227 " \"effect\": \"Ripple2D\",\n"
1229 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1233 " \"name\": \"onStage\",\n"
1234 " \"action\": \"play\",\n"
1235 " \"animation\": \"pathAnimation\"\n"
1238 " \"name\": \"onStage\",\n"
1239 " \"action\": \"applyConstraint\",\n"
1240 " \"constrainer\": \"constrainer0\",\n"
1241 " \"properties\":\n"
1244 " \"source\": \"Image1\",\n"
1245 " \"sourceProperty\": \"positionX\",\n"
1246 " \"target\": \"Image1\",\n"
1247 " \"targetProperty\": \"colorRed\",\n"
1248 " \"range\": [-300,300]\n"
1253 " \"name\": \"onStage\",\n"
1254 " \"action\": \"applyConstraint\",\n"
1255 " \"constrainer\": \"constrainer1\",\n"
1256 " \"properties\":\n"
1259 " \"source\": \"Image1\",\n"
1260 " \"sourceProperty\": \"positionX\",\n"
1261 " \"target\": \"Image1\",\n"
1262 " \"targetProperty\": \"colorBlue\",\n"
1263 " \"range\": [-300,300]\n"
1268 " \"name\": \"offStage\",\n"
1269 " \"action\": \"removeConstraints\",\n"
1270 " \"constrainer\": \"constrainer0\",\n"
1271 " \"properties\":\n"
1274 " \"source\": \"Image1\",\n"
1275 " \"sourceProperty\": \"positionX\",\n"
1276 " \"target\": \"Image1\",\n"
1277 " \"targetProperty\": \"colorRed\",\n"
1278 " \"range\": [-300,300]\n"
1283 " \"name\": \"offStage\",\n"
1284 " \"action\": \"removeConstraints\",\n"
1285 " \"constrainer\": \"constrainer1\",\n"
1286 " \"properties\":\n"
1289 " \"source\": \"Image1\",\n"
1290 " \"sourceProperty\": \"positionX\",\n"
1291 " \"target\": \"Image1\",\n"
1292 " \"targetProperty\": \"colorBlue\",\n"
1293 " \"range\": [-300,300]\n"
1304 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1305 " \"curvature\":0.35\n"
1308 " \"constrainers\":\n"
1310 " \"constrainer0\":\n"
1312 " \"type\": \"PathConstrainer\",\n"
1313 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1314 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1316 " \"constrainer1\":\n"
1318 " \"type\": \"LinearConstrainer\",\n"
1319 " \"value\": [ 0, 0, 0 ]\n"
1322 " \"animations\": {\n"
1323 " \"pathAnimation\": {\n"
1324 " \"duration\": 3.0,\n"
1325 " \"properties\":\n"
1327 " \"actor\": \"Image1\",\n"
1328 " \"path\":\"path0\",\n"
1329 " \"forward\":[1,0,0],\n"
1330 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1331 " \"timePeriod\": {\n"
1333 " \"duration\": 3\n"
1337 " \"actor\": \"Image1\",\n"
1338 " \"property\": \"uTime\",\n"
1339 " \"value\": 10.0,\n"
1340 " \"alphaFunction\": \"LINEAR\",\n"
1341 " \"timePeriod\": {\n"
1343 " \"duration\": 10.0\n"
1345 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1348 " \"Animation_1\": {\n"
1350 " \"properties\": [\n"
1352 " \"actor\": \"Image1\",\n"
1353 " \"property\": \"uTime\",\n"
1354 " \"value\": 10.0,\n"
1355 " \"alphaFunction\": \"LINEAR\",\n"
1356 " \"timePeriod\": {\n"
1358 " \"duration\": 10.0\n"
1360 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1367 Builder builder = Builder::New();
1369 // frame buffer coverage
1370 builder.LoadFromString( json );
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 Dali::Path path = builder.GetPath( "path0" );
1377 DALI_TEST_CHECK( path );
1379 Dali::Path path2 = builder.GetPath( "path0" );
1380 DALI_TEST_CHECK( path2 );
1381 DALI_TEST_CHECK( path == path2 );
1383 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1384 DALI_TEST_CHECK( constrainer0 );
1386 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1387 DALI_TEST_CHECK( constrainer0_2 );
1388 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1390 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1391 DALI_TEST_CHECK( constrainer1 );
1393 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1394 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1398 Actor actor = Actor::New();
1399 Stage::GetCurrent().Add( actor );
1400 builder.AddActors( actor );
1402 // Render and notify
1403 application.SendNotification();
1404 application.Render();
1406 actor.GetChildAt( 0 ).Unparent();
1411 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1413 Property::Value* value = xMap->Find( xKey ); \
1414 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1415 if( value != NULL ) \
1417 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1419 value->Get(result); \
1420 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1421 std::ostringstream oss; \
1422 oss << "Animation element " << xKey << "= " << result << std::endl; \
1423 tet_printf( oss.str().c_str() ); \
1427 tet_printf("Can't find map element " xKey "\n"); \
1432 int UtcDaliBuilderMapping01(void)
1434 ToolkitTestApplication application;
1440 " \"buttonPressFadeOut\":{\n"
1441 " \"alphaFunction\":\"EASE_OUT\",\n"
1442 " \"timePeriod\":{\n"
1444 " \"duration\":0.4\n"
1447 " \"buttonPressFadeIn\":{\n"
1448 " \"alphaFunction\":\"EASE_IN\",\n"
1449 " \"timePeriod\":{\n"
1451 " \"duration\":0.5\n"
1454 " \"transition:buttonPressed\":\n"
1457 " \"target\": \"unselectedBackgroundRenderer\",\n"
1458 " \"property\": \"opacity\",\n"
1460 " \"animator\":\"<buttonPressFadeOut>\"\n"
1463 " \"transition:buttonReleased\":\n"
1466 " \"target\": \"unselectedBackgroundRenderer\",\n"
1467 " \"property\": \"opacity\",\n"
1469 " \"animator\":\"<buttonPressFadeIn>\"\n"
1472 " \"target\": \"unselectedForegroundRenderer\",\n"
1473 " \"property\": \"scale\",\n"
1474 " \"value\": [ 1, 1, 1 ],\n"
1475 " \"animator\":\"<buttonPressFadeIn>\"\n"
1478 " \"target\": \"selectedBackgroundRenderer\",\n"
1479 " \"property\": \"opacity\",\n"
1481 " \"animator\": \"<buttonPressFadeOut>\"\n"
1484 " \"target\": \"selectedForegroundRenderer\",\n"
1485 " \"property\": \"scale\",\n"
1486 " \"value\": [ 0, 0, 0 ],\n"
1487 " \"animator\":\"<buttonPressFadeOut>\"\n"
1493 " \"testbutton\":\n"
1495 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1496 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1501 Builder builder = Builder::New();
1502 builder.LoadFromString( json );
1504 Test::TestButton testButton = Test::TestButton::New();
1505 Stage::GetCurrent().Add( testButton );
1507 // Render and notify
1508 application.SendNotification();
1509 application.Render();
1511 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1513 // Now check that it has loaded the transition correctly:
1514 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1515 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1516 Property::Array* array = transition.GetArray();
1518 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1519 Property::Value element = array->GetElementAt(0);
1520 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1521 Property::Map* map = element.GetMap();
1523 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1524 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1525 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1526 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1527 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1533 int UtcDaliBuilderMappingCycleCheck(void)
1535 ToolkitTestApplication application;
1541 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1542 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1543 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1545 " \"alphaFunction\":\"EASE_IN\",\n"
1546 " \"timePeriod\":{\n"
1547 " \"delay\":\"<cyclicKey3>\",\n"
1548 " \"duration\":0.6\n"
1551 " \"transition:buttonPressed\":\n"
1554 " \"target\": \"<cyclicKey1>\",\n"
1555 " \"property\": \"<cyclicKey2>\",\n"
1557 " \"animator\":\"<FadeOut>\"\n"
1563 " \"testbutton\":\n"
1565 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1566 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1567 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1568 " \"enabledTransition\":\"<unknownKey>\"\n"
1573 Builder builder = Builder::New();
1574 builder.LoadFromString( json );
1576 Test::TestButton testButton = Test::TestButton::New();
1577 Stage::GetCurrent().Add( testButton );
1579 // Render and notify
1580 application.SendNotification();
1581 application.Render();
1583 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1585 // Now check that it has loaded the transition correctly:
1586 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1587 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1588 Property::Array* array = transition.GetArray();
1590 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1591 Property::Value element = array->GetElementAt(0);
1592 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1593 Property::Map* map = element.GetMap();
1595 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1596 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1597 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1602 int UtcDaliBuilderTypeCasts(void)
1604 ToolkitTestApplication application;
1610 "\"type\": \"Layer\","
1611 "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1612 "\"position\": { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1613 "\"color\": { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1614 "\"sensitive\": { \"typeCast\":\"boolean\", \"value\":false },"
1615 "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1616 "\"colorMode\": { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1617 "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
1618 "\"padding\": { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
1623 Actor rootActor = Actor::New();
1624 Stage::GetCurrent().Add( rootActor );
1626 Builder builder = Builder::New();
1627 builder.LoadFromString( json );
1628 builder.AddActors( rootActor );
1630 application.SendNotification();
1631 application.Render();
1633 Actor createdActor = rootActor.GetChildAt( 0 );
1634 DALI_TEST_EQUALS( createdActor.GetProperty< Vector2 >( Actor::Property::MAXIMUM_SIZE ), Vector2(100.0f,15.0f), TEST_LOCATION );
1635 DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
1636 DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
1637 DALI_TEST_EQUALS( createdActor.GetProperty< bool >( Actor::Property::SENSITIVE ), false, TEST_LOCATION );
1638 DALI_TEST_EQUALS( createdActor.GetProperty< ColorMode >( Actor::Property::COLOR_MODE ), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
1643 int UtcDaliBuilderBuilderControl(void)
1645 ToolkitTestApplication application;
1651 "\"type\": \"BuilderControl\","
1652 "\"integerProperty\": 10,"
1653 "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
1654 "\"matrixProperty\": [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
1655 "\"noneProperty\": 10"
1660 Actor rootActor = Actor::New();
1661 Stage::GetCurrent().Add( rootActor );
1663 Builder builder = Builder::New();
1664 builder.LoadFromString( json );
1665 builder.AddActors( rootActor );
1667 application.SendNotification();
1668 application.Render();
1670 DALI_TEST_EQUALS( BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION );
1675 int UtcDaliBuilderCustomControl(void)
1677 ToolkitTestApplication application;
1683 "\"type\": \"DummyControl\","
1684 "\"name\": \"I can haz custom Control\""
1689 Actor rootActor = Actor::New();
1690 Stage::GetCurrent().Add( rootActor );
1692 Builder builder = Builder::New();
1693 builder.LoadFromString( json );
1694 builder.AddActors( rootActor );
1696 application.SendNotification();
1697 application.Render();
1699 Actor customControl = rootActor.FindChildByName( "I can haz custom Control" );
1701 // Test that we have the correct type of custom control
1702 DummyControl dummyControl = DummyControl::DownCast( customControl );
1703 DALI_TEST_CHECK( dummyControl );
1706 DALI_TEST_CHECK( typeid(dummyControl.GetImplementation()) == typeid(DummyControlImpl) );
1712 int UtcDaliBuilderActionsWithParams(void)
1714 ToolkitTestApplication application;
1716 // JSON with a quit event when the actor is touched
1722 " \"type\": \"ImageView\",\n"
1723 " \"name\": \"image\",\n"
1724 " \"size\": [100,100,1],\n"
1725 " \"signals\": [{\n"
1726 " \"name\": \"touch\",\n"
1727 " \"action\": \"show\",\n"
1728 " \"parameters\": {\n"
1729 " \"property1\" : 10,\n"
1730 " \"property2\" : [1,2],\n"
1731 " \"property3\" : [1,2,3],\n"
1732 " \"property4\" : [1,2,3,4]\n"
1740 Builder builder = Builder::New();
1741 builder.LoadFromString( json );
1742 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
1744 DALI_TEST_CHECK( true ); // For Coverage
1749 int UtcDaliBuilderConfigurationP(void)
1751 ToolkitTestApplication application;
1753 // JSON with a quit event when the actor is touched
1758 " \"alwaysShowFocus\":true\n"
1763 Builder builder = Builder::New();
1764 builder.LoadFromString( json );
1766 Property::Map map = builder.GetConfigurations();
1768 Dali::Property::Value* pValue = map.Find( "alwaysShowFocus" );
1770 DALI_TEST_CHECK( pValue );
1772 bool value = pValue->Get<bool>();
1774 DALI_TEST_CHECK( value );
1780 int UtcDaliBase64EncodingP(void)
1782 std::vector<uint32_t> data = { 0, 1, 2, 3, 4, 5, std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max() };
1784 Property::Value value;
1785 EncodeBase64PropertyData( value, data );
1787 std::cout << "Max uint32_t:" << std::numeric_limits<uint32_t>::max() << std::endl;
1788 std::cout << "Input data: ";
1789 std::ostream_iterator<uint32_t> out_it (std::cout,", ");
1790 std::copy ( data.begin(), data.end(), out_it );
1791 std::cout << std::endl;
1794 DALI_TEST_CHECK( value.Get( output ) );
1795 DALI_TEST_EQUALS( output, "AAAAAAEAAAACAAAAAwAAAAQAAAAFAAAAAAAAAP////8", TEST_LOCATION );
1797 std::cout << "Output data: " << output << std::endl;
1802 int UtcDaliBase64EncodingN(void)
1804 tet_infoline( "Test encoding an empty vector returns empty string" );
1805 std::vector<uint32_t> data;
1807 Property::Value value;
1808 EncodeBase64PropertyData( value, data );
1811 DALI_TEST_CHECK( value.Get( output ) );
1812 DALI_TEST_EQUALS( output.empty(), true, TEST_LOCATION );
1817 template <typename T>
1818 int b64l(std::vector<T>&data)
1820 auto lengthInBytes = 4*data.size();
1821 return ceil( lengthInBytes * 1.33333f );
1824 int UtcDaliBase64EncodingP02(void)
1826 tet_infoline( "Test encoding vectors of lengths m .. m+4 encode and decode back to the same length vectors" );
1828 std::vector<uint32_t> testData;
1829 for(int i=0; i<8; ++i ) // 8 chosen to stay within single string output
1831 testData.push_back(i);
1833 Property::Value value;
1834 EncodeBase64PropertyData( value, testData );
1837 DALI_TEST_CHECK( value.Get( output ) );
1838 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1839 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1841 std::vector<uint32_t> outData;
1842 DecodeBase64PropertyData( value, outData );
1843 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1844 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1847 testData.push_back( 12345 );
1848 EncodeBase64PropertyData( value, testData );
1850 DALI_TEST_CHECK( value.Get( output ) );
1851 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1852 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1855 DecodeBase64PropertyData( value, outData );
1856 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1857 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1860 testData.push_back( 67890 );
1861 EncodeBase64PropertyData( value, testData );
1863 DALI_TEST_CHECK( value.Get( output ) );
1864 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1865 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1868 DecodeBase64PropertyData( value, outData );
1869 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1870 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1873 testData.push_back( -1 );
1874 EncodeBase64PropertyData( value, testData );
1876 DALI_TEST_CHECK( value.Get( output ) );
1877 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1878 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1881 DecodeBase64PropertyData( value, outData );
1882 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1883 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1890 int UtcDaliBase64EncodingP03(void)
1892 tet_infoline( "Test encoding a vector of length 12 has output within single string" );
1894 std::vector<uint32_t> testData;
1895 for(int i=0; i<12; ++i )
1897 testData.push_back(i);
1899 Property::Value value;
1900 EncodeBase64PropertyData( value, testData );
1903 DALI_TEST_CHECK( value.Get( output ) );
1904 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1905 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1907 std::vector<uint32_t> outData;
1908 DecodeBase64PropertyData( value, outData );
1909 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1915 int UtcDaliBase64EncodingP04(void)
1917 tet_infoline( "Test encoding a vector of length 13 has output split over 2 strings" );
1919 std::vector<uint32_t> testData;
1920 for(int i=0; i<13; ++i )
1922 testData.push_back(i);
1924 Property::Value value;
1925 EncodeBase64PropertyData( value, testData );
1927 auto array = value.GetArray();
1928 DALI_TEST_CHECK( array );
1930 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
1932 std::vector<uint32_t> outData;
1933 DecodeBase64PropertyData( value, outData );
1934 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1940 int UtcDaliBase64EncodingP05(void)
1942 tet_infoline( "Test encoding a vector of length 24 has output split over 2 strings" );
1944 std::vector<uint32_t> testData;
1945 for(int i=0; i<24; ++i )
1947 testData.push_back(i);
1949 Property::Value value;
1950 EncodeBase64PropertyData( value, testData );
1952 auto array = value.GetArray();
1953 DALI_TEST_CHECK( array );
1955 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
1957 std::vector<uint32_t> outData;
1958 DecodeBase64PropertyData( value, outData );
1959 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1965 int UtcDaliBase64EncodingP06(void)
1967 tet_infoline( "Test encoding a vector of arbitrary length decodes OK." );
1969 std::vector<uint32_t> testData;
1970 for(int i=0; i<97; ++i )
1972 testData.push_back(i);
1974 Property::Value value;
1975 EncodeBase64PropertyData( value, testData );
1977 auto array = value.GetArray();
1978 DALI_TEST_CHECK( array );
1980 std::vector<uint32_t> outData;
1981 DecodeBase64PropertyData( value, outData );
1982 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1988 int UtcDaliBase64DecodingN01(void)
1990 tet_infoline( "Test decoding empty string results in empty data" );
1992 Property::Value value("");
1993 std::vector<uint32_t> outputData;
1994 DecodeBase64PropertyData( value, outputData);
1995 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2000 int UtcDaliBase64DecodingN02(void)
2002 tet_infoline( "Test decoding array with non-string values results in empty data" );
2004 Property::Array array;
2006 array[0] = "Stuff, things";
2008 Property::Value value(array);
2010 std::vector<uint32_t> outputData;
2011 DecodeBase64PropertyData( value, outputData);
2012 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2016 int UtcDaliBase64DecodingP01(void)
2018 tet_infoline( "Test decoding string of known data gives expected result");
2020 std::string testInput("//////7+/v4DAgEA");
2021 std::vector<uint32_t> expectedResults = { 0xffffffff, 0xfefefefe, 0x00010203 };
2023 std::vector<uint32_t> outputData;
2024 DecodeBase64PropertyData(Property::Value(testInput), outputData);
2026 DALI_TEST_EQUALS( std::equal( expectedResults.begin(), expectedResults.end(), outputData.begin() ), true,