2 * Copyright (c) 2020 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\": \"touched\","
132 "\"action\": \"quit\""
137 Builder builder = Builder::New();
138 builder.LoadFromString( json );
139 builder.AddActors ( application.GetScene().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\","
281 " \"pathAnimation2\": {"
282 " \"duration\": 3.0,"
283 " \"endAction\": \"BAKE_FINAL\","
284 " \"disconnectAction\": \"DISCARD\","
285 " \"properties\": [{"
286 " \"actor\": \"greeting\","
287 " \"path\":\"path0\","
288 " \"forward\":[1,0,0],"
289 " \"alphaFunction\": \"EASE_IN_OUT\","
298 " \"name\": \"greeting\","
299 " \"type\": \"TextLabel\","
300 " \"text\": \"Touch me\","
301 " \"inherit\": [\"basicText\"],"
302 " \"position\": [0, -120, 0],"
303 " \"size\": [200, 200, 1],"
304 " \"orientation\": [0, 0, 30],"
306 " \"name\": \"touched\","
307 " \"action\": \"play\","
308 " \"animation\": \"animate\""
313 Builder builder = Builder::New();
314 builder.LoadFromString( json );
315 builder.AddActors( application.GetScene().GetRootLayer() );
317 Animation anim = builder.CreateAnimation("animate");
319 DALI_TEST_CHECK( anim );
322 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
323 anim = builder.CreateAnimation("animate", map);
325 DALI_TEST_CHECK( anim );
327 anim = builder.CreateAnimation("pathAnimation");
329 DALI_TEST_CHECK( anim );
331 anim = builder.CreateAnimation("pathAnimation2");
333 DALI_TEST_CHECK( anim );
336 // Emit touch event and check that our quit method is called
337 Integration::TouchEvent touchEvent;
338 Integration::Point point;
339 point.SetState( PointState::DOWN );
340 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
341 touchEvent.points.push_back( point );
342 application.ProcessEvent( touchEvent );
345 application.SendNotification();
346 application.Render();
352 int UtcDaliBuilderAnimationN(void)
354 ToolkitTestApplication application;
356 // JSON with a quit event when the actor is touched
361 " \"TEXT\": \"Touch Me\","
362 " \"NAME\": \"greeting\" "
368 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
369 " \"curvature\":0.35"
375 " \"endAction\": \"BAKE\","
376 " \"disconnectAction\": \"BAKE\","
379 " \"actor\": \"{NAME}\","
380 " \"property\": \"positioninvalid\","
381 " \"value\": [300, 300, -1000],"
382 " \"alphaFunction\": \"EASE_IN_OUT\","
383 " \"relative\": true,"
393 " \"endAction\": \"BAKE\","
394 " \"disconnectAction\": \"BAKE\","
397 " \"actor\": \"{NAME}\","
398 " \"property\": \"positioninvalid\","
399 " \"value\": [300, 300, -1000],"
400 " \"alphaFunction\": \"EGGS_OVER_EASY\","
401 " \"relative\": true,"
409 " \"pathAnimation\": {"
410 " \"duration\": 3.0,"
411 " \"endAction\": \"DISCARD\","
412 " \"disconnectAction\": \"BAKE_FINAL\","
413 " \"properties\": [{"
414 " \"actor\": \"greeting\","
415 " \"path\":\"pathDoesntExist\","
416 " \"forward\":[1,0,0],"
417 " \"alphaFunction\": \"EASE_IN_OUT\","
426 " \"name\": \"greeting\","
427 " \"type\": \"TextLabel\","
428 " \"text\": \"Touch me\","
429 " \"inherit\": [\"basicText\"],"
430 " \"position\": [0, -120, 0],"
431 " \"size\": [200, 200, 1],"
432 " \"orientation\": [0, 0, 30],"
434 " \"name\": \"touched\","
435 " \"action\": \"play\","
436 " \"animation\": \"animate\""
440 " \"name\": \"greeting2\","
441 " \"type\": \"TextLabel\","
442 " \"text\": \"Touch me\""
447 Builder builder = Builder::New();
448 builder.LoadFromString( json );
449 builder.AddActors( application.GetScene().GetRootLayer() );
451 Animation anim = builder.CreateAnimation("animate");
453 // log warning line coverage
454 anim = builder.CreateAnimation("pathAnimation");
455 DALI_TEST_CHECK(anim);
457 anim = builder.CreateAnimation("animate");
458 DALI_TEST_CHECK(anim);
460 anim = builder.CreateAnimation("animate2");
461 DALI_TEST_CHECK(anim);
463 // create referencing a different actor aka animation templates
465 map["NAME"] = "greeting2";
466 anim = builder.CreateAnimation("animate2", map);
467 DALI_TEST_CHECK(anim);
469 // alternative actor to use for FindChildByName
470 anim = builder.CreateAnimation("animate2", application.GetScene().GetRootLayer());
471 DALI_TEST_CHECK(anim);
473 // alternative actor to use for FindChildByName
474 anim = builder.CreateAnimation("animate2", map, application.GetScene().GetRootLayer());
475 DALI_TEST_CHECK(anim);
482 int UtcDaliBuilderConstantsP(void)
484 ToolkitTestApplication application;
486 // JSON with a quit event when the actor is touched
491 " \"IMAGE_PATH\": \"apath\","
493 " \"ANCHOR\": \"TOP_LEFT\","
494 " \"PADDING\": [1,2,3,4]"
498 " \"type\": \"ImageView\","
499 " \"name\": \"{NAME}\","
500 " \"size\": [100,100,1],"
501 " \"parentOrigin\": \"TOP_LEFT\","
502 " \"anchorPoint\": \"{ANCHOR}\","
503 " \"padding\": \"{PADDING}\","
504 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
505 " \"sizeWidth\": \"{WIDTH}\","
507 " \"name\": \"touched\","
508 " \"action\": \"quit\""
514 Builder builder = Builder::New();
515 builder.LoadFromString( json );
517 builder.AddConstant( "NAME", "image" );
519 Property::Map map = builder.GetConstants();
521 Dali::Property::Value* pValue = map.Find( "NAME" );
523 DALI_TEST_CHECK( pValue );
525 pValue = map.Find( "IMAGE_PATH" );
527 DALI_TEST_CHECK( pValue );
529 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
531 DALI_TEST_CHECK( value.GetType() != Property::NONE );
533 builder.AddActors ( application.GetScene().GetRootLayer() );
534 DALI_TEST_CHECK( builder );
536 Actor actor = application.GetScene().GetRootLayer().FindChildByName("image");
537 DALI_TEST_CHECK( actor );
542 int UtcDaliBuilderTemplatesAndStylesP(void)
544 ToolkitTestApplication application;
546 // JSON with a quit event when the actor is touched
551 " \"SIZE\": [10,20,30]"
555 " \"imageStyle\": \n"
557 " \"color\": [1,0,0,1],\n"
559 " \"childImage\": {\n"
560 " \"color\": \"34\"\n"
567 " \"imageViewTemplate\": { \n"
568 " \"type\": \"ImageView\",\n"
569 " \"styles\": [\"imageStyle\"]\n"
571 " \"imageTree\": { \n"
572 " \"type\": \"ImageView\",\n"
573 " \"styles\": [\"imageStyle\"],\n"
574 " \"name\": \"image\",\n"
575 " \"size\": \"{SIZE}\",\n"
577 " \"name\": \"touched\",\n"
578 " \"action\": \"quit\"\n"
582 " \"type\":\"ImageView\",\n"
583 " \"name\":\"childImage\", \n"
593 " \"type\":\"imageViewTemplate\",\n"
594 " \"name\":\"childImage2\"\n"
601 " \"type\": \"imageTree\","
602 " \"size\": [100,100,1]"
607 std::string stylejson(
609 " \"color\": [1,0,0,1],\n"
611 " \"childImage\": {\n"
612 " \"color\": \"#344353\"\n"
618 std::string templatejson(
620 " \"type\": \"ImageView\",\n"
621 " \"styles\": [\"imageStyle\"],\n"
622 " \"name\": \"image\",\n"
623 " \"size\": \"{SIZE}\",\n"
625 " \"name\": \"touched\",\n"
626 " \"action\": \"quit\"\n"
630 " \"type\":\"ImageView\",\n"
631 " \"name\":\"childImage\" \n"
637 Builder builder = Builder::New();
638 builder.LoadFromString( json );
640 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
641 DALI_TEST_CHECK( actor );
643 Dali::Property::Map map;
644 map["SIZE"] = Vector3(100,100,1);
645 actor = ImageView::DownCast( builder.Create( "imageTree", map ) );
646 DALI_TEST_CHECK( actor );
648 // create from json snippet
649 actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
650 DALI_TEST_CHECK( actor );
653 // NB: already applied in create
654 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
656 // apply from json snippet
657 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
662 int UtcDaliBuilderRenderTasksP(void)
664 ToolkitTestApplication application;
666 // JSON with a quit event when the actor is touched
672 " \"sourceActor\": \"image\",\n"
673 " \"cameraActor\": \"camera\" \n"
679 " \"type\": \"CameraActor\",\n"
680 " \"name\": \"camera\"\n"
683 " \"type\": \"ImageView\",\n"
684 " \"name\": \"image\",\n"
685 " \"size\": [100,100,1],\n"
687 " \"name\": \"touched\",\n"
688 " \"action\": \"quit\"\n"
692 " \"type\":\"ImageView\",\n"
693 " \"name\":\"childImage\" \n"
701 Builder builder = Builder::New();
702 builder.LoadFromString( json );
704 unsigned int count = application.GetScene().GetRenderTaskList().GetTaskCount();
707 builder.CreateRenderTask( "task0" );
709 DALI_TEST_CHECK( count <
710 application.GetScene().GetRenderTaskList().GetTaskCount() );
715 int UtcDaliBuilderChildActionP(void)
717 ToolkitTestApplication application;
719 // JSON with a quit event when the actor is touched
724 " \"type\": \"Actor\",\n"
725 " \"name\": \"actor\",\n"
726 " \"size\": [100,100,1],\n"
727 " \"parentOrigin\": \"TOP_LEFT\",\n"
728 " \"anchorPoint\": \"TOP_LEFT\",\n"
730 " \"type\": \"Actor\",\n"
731 " \"name\": \"subActor\"\n"
734 " \"name\": \"touched\",\n"
735 " \"action\": \"hide\",\n"
736 " \"actor\": \"actor\",\n"
737 " \"childActor\": \"subActor\"\n"
743 Builder builder = Builder::New();
744 builder.LoadFromString( json );
745 builder.AddActors ( application.GetScene().GetRootLayer() );
748 application.SendNotification();
749 application.Render();
751 // Emit touch event and check that our quit method is called
752 Integration::TouchEvent touchEvent;
753 Integration::Point point;
754 point.SetState( PointState::DOWN );
755 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
756 touchEvent.points.push_back( point );
757 application.ProcessEvent( touchEvent );
760 application.SendNotification();
761 application.Render();
763 Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor");
764 DALI_TEST_CHECK( actor );
766 DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
771 int UtcDaliBuilderSetPropertyActionP(void)
773 ToolkitTestApplication application;
775 // JSON with a quit event when the actor is touched
780 " \"type\": \"Actor\",\n"
781 " \"name\": \"actor\",\n"
782 " \"size\": [100,100,1],\n"
783 " \"parentOrigin\": \"TOP_LEFT\",\n"
784 " \"anchorPoint\": \"TOP_LEFT\",\n"
786 " \"type\": \"Actor\",\n"
787 " \"name\": \"subActor\"\n"
790 " \"name\": \"touched\",\n"
791 " \"action\": \"set\",\n"
792 " \"actor\": \"subActor\",\n"
793 " \"property\": \"visible\",\n"
794 " \"value\": false\n"
800 Builder builder = Builder::New();
801 builder.LoadFromString( json );
802 builder.AddActors ( application.GetScene().GetRootLayer() );
805 application.SendNotification();
806 application.Render();
808 // Emit touch event and check that our quit method is called
809 Integration::TouchEvent touchEvent;
810 Integration::Point point;
811 point.SetState( PointState::DOWN );
812 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
813 touchEvent.points.push_back( point );
814 application.ProcessEvent( touchEvent );
817 application.SendNotification();
818 application.Render();
820 Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor");
821 DALI_TEST_CHECK( actor );
823 DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
828 int UtcDaliBuilderGenericActionP(void)
830 ToolkitTestApplication application;
832 // JSON with a quit event when the actor is touched
837 " \"type\": \"Actor\",\n"
838 " \"name\": \"actor\",\n"
839 " \"size\": [100,100,1],\n"
840 " \"parentOrigin\": \"TOP_LEFT\",\n"
841 " \"anchorPoint\": \"TOP_LEFT\",\n"
843 " \"type\": \"Actor\",\n"
844 " \"name\": \"subActor\"\n"
847 " \"name\": \"touched\",\n"
848 " \"action\": \"hide\"\n"
854 Builder builder = Builder::New();
855 builder.LoadFromString( json );
856 builder.AddActors ( application.GetScene().GetRootLayer() );
859 application.SendNotification();
860 application.Render();
862 // Emit touch event and check that our quit method is called
863 Integration::TouchEvent touchEvent;
864 Integration::Point point;
865 point.SetState( PointState::DOWN );
866 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
867 touchEvent.points.push_back( point );
868 application.ProcessEvent( touchEvent );
871 application.SendNotification();
872 application.Render();
874 Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor");
875 DALI_TEST_CHECK( actor );
877 DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
882 int UtcDaliBuilderPropertyNotificationP(void)
884 ToolkitTestApplication application;
886 // JSON with a quit event when the actor is touched
891 " \"type\": \"Actor\",\n"
892 " \"name\": \"actor\",\n"
893 " \"size\": [100,100,1],\n"
894 " \"parentOrigin\": \"TOP_LEFT\",\n"
895 " \"anchorPoint\": \"TOP_LEFT\",\n"
897 " \"type\": \"Actor\",\n"
898 " \"name\": \"subActor\"\n"
901 " \"name\": \"touched\",\n"
902 " \"action\": \"hide\"\n"
904 " \"notifications\": [{\n"
905 " \"property\": \"visible\",\n"
906 " \"condition\": \"False\",\n"
907 " \"action\": \"show\"\n"
910 " \"property\": \"positionX\",\n"
911 " \"condition\": \"LessThan\",\n"
913 " \"action\": \"show\"\n"
916 " \"property\": \"positionY\",\n"
917 " \"condition\": \"GreaterThan\",\n"
918 " \"arg0\": 200.0,\n"
919 " \"action\": \"show\"\n"
922 " \"property\": \"positionZ\",\n"
923 " \"condition\": \"Inside\",\n"
926 " \"action\": \"show\"\n"
929 " \"property\": \"positionZ\",\n"
930 " \"condition\": \"Outside\",\n"
933 " \"action\": \"show\"\n"
939 Builder builder = Builder::New();
940 builder.LoadFromString( json );
941 builder.AddActors ( application.GetScene().GetRootLayer() );
944 application.SendNotification();
945 application.Render();
947 // Emit touch event and check that our quit method is called
948 Integration::TouchEvent touchEvent;
949 Integration::Point point;
950 point.SetState( PointState::DOWN );
951 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
952 touchEvent.points.push_back( point );
953 application.ProcessEvent( touchEvent );
956 application.SendNotification();
957 application.Render();
960 application.SendNotification();
961 application.Render();
963 Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor");
964 DALI_TEST_CHECK( actor );
966 DALI_TEST_CHECK( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
971 int UtcDaliBuilderPropertyNotificationN(void)
973 ToolkitTestApplication application;
975 // JSON with a quit event when the actor is touched
980 " \"type\": \"Actor\",\n"
981 " \"notifications\": [{\n"
982 " \"property\": \"visible\",\n"
983 " \"condition\": \"ErrorCondition\",\n"
984 " \"action\": \"show\"\n"
992 Builder builder = Builder::New();
993 builder.LoadFromString( json );
994 builder.AddActors ( application.GetScene().GetRootLayer() );
995 DALI_TEST_CHECK( false );
999 DALI_TEST_CHECK( true );
1007 int UtcDaliBuilderCustomPropertyP(void)
1009 ToolkitTestApplication application;
1011 // JSON with a quit event when the actor is touched
1016 " \"imageTree\": { \n"
1017 " \"type\": \"ImageView\",\n"
1018 " \"name\": \"image\",\n"
1019 " \"size\": [100,100,1],\n"
1020 " \"signals\": [{\n"
1021 " \"name\": \"touched\",\n"
1022 " \"action\": \"quit\"\n"
1024 " \"properties\": {\n"
1025 " \"newproperty\": true\n"
1027 " \"animatableProperties\": {\n"
1028 " \"newAnimatableproperty\": 3\n"
1032 " \"type\":\"ImageView\",\n"
1033 " \"name\":\"childImage\" \n"
1041 Builder builder = Builder::New();
1042 builder.LoadFromString( json );
1044 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
1045 DALI_TEST_CHECK( actor );
1047 // NB: already applied in create
1048 Property::Index index = actor.GetPropertyIndex("newproperty");
1049 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
1050 Property::Value value = actor.GetProperty(index);
1051 DALI_TEST_CHECK( value.Get<bool>() == true );
1053 index = actor.GetPropertyIndex("newAnimatableproperty");
1054 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
1055 value = actor.GetProperty(index);
1056 DALI_TEST_CHECK( value.Get<int>() == 3 );
1061 int UtcDaliBuilderCustomShaderP(void)
1063 ToolkitTestApplication application;
1065 // JSON with a quit event when the actor is touched
1070 " \"type\": \"ImageView\",\n"
1071 " \"name\": \"Image1\",\n"
1072 " \"position\": [\n"
1073 " 0.40461349487305,\n"
1077 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1078 " \"size\": [200, 200, 0],\n"
1079 " \"effect\": \"Ripple2D\",\n"
1081 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1082 " \"desiredWidth\": 200,\n"
1083 " \"desiredHeight\": 80,\n"
1085 " \"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"
1088 " \"customAnimatableProperties\": {\n"
1089 " \"uAmplitude\": 0.02,\n"
1094 " \"name\": \"onScene\",\n"
1095 " \"action\": \"play\",\n"
1096 " \"animation\": \"Animation_1\"\n"
1101 " \"animations\": {\n"
1102 " \"Animation_1\": {\n"
1104 " \"properties\": [\n"
1106 " \"actor\": \"Image1\",\n"
1107 " \"property\": \"uTime\",\n"
1108 " \"value\": 10.0,\n"
1109 " \"alphaFunction\": \"LINEAR\",\n"
1110 " \"timePeriod\": {\n"
1112 " \"duration\": 10.0\n"
1122 Builder builder = Builder::New();
1123 builder.LoadFromString( json );
1125 builder.AddActors ( "stage", application.GetScene().GetRootLayer() );
1127 // Render and notify
1128 application.SendNotification();
1129 application.Render();
1131 Actor actor = application.GetScene().GetRootLayer().FindChildByName("Image1");
1134 DALI_TEST_CHECK( actor );
1140 int UtcDaliBuilderLoadFromStringN(void)
1142 ToolkitTestApplication application;
1144 // JSON with a quit event when the actor is touched
1146 "asdfsadf dsf asdf asdf {"
1149 "\"type\": \"Actor\","
1150 "\"size\": [100,100,1],"
1151 "\"parentOrigin\": \"TOP_LEFT\","
1152 "\"anchorPoint\": \"TOP_LEFT\","
1154 "\"name\": \"touched\","
1155 "\"action\": \"quit\""
1160 Builder builder = Builder::New();
1162 bool assert1 = false;
1166 builder.LoadFromString( json );
1168 catch( Dali::DaliException& e )
1170 DALI_TEST_PRINT_ASSERT( e );
1171 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1175 DALI_TEST_CHECK( assert1 );
1181 int UtcDaliBuilderAddActorsP(void)
1183 ToolkitTestApplication application;
1185 // JSON with a quit event when the actor is touched
1188 " \"arbitarysection\":\n"
1190 " \"type\": \"Actor\",\n"
1191 " \"name\": \"actor\",\n"
1192 " \"size\": [100,100,1],\n"
1193 " \"parentOrigin\": \"TOP_LEFT\",\n"
1194 " \"anchorPoint\": \"TOP_LEFT\",\n"
1196 " \"type\": \"Actor\",\n"
1197 " \"name\": \"subActor\",\n"
1198 " \"visible\": false\n"
1200 " \"signals\": [{\n"
1201 " \"name\": \"touched\",\n"
1202 " \"action\": \"hide\",\n"
1203 " \"actor\": \"actor\",\n"
1204 " \"childActor\": \"subActor\"\n"
1210 Builder builder = Builder::New();
1211 builder.LoadFromString( json );
1212 builder.AddActors ( "arbitarysection", application.GetScene().GetRootLayer() );
1214 // Render and notify
1215 application.SendNotification();
1216 application.Render();
1218 Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor");
1219 DALI_TEST_CHECK( actor );
1221 DALI_TEST_CHECK( !actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) );
1226 int UtcDaliBuilderPathConstraintsP(void)
1228 ToolkitTestApplication application;
1230 // JSON with a quit event when the actor is touched
1235 " \"FB_WIDTH\": 200.0,\n"
1236 " \"FB_HEIGHT\": 200.0,\n"
1237 " \"FB_SIZE\": [200,200],\n"
1238 " \"FB_ASPECT_RATIO\": 1\n"
1242 " \"type\": \"ImageView\",\n"
1243 " \"name\": \"Image1\",\n"
1244 " \"size\": [200, 200, 0],\n"
1245 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1246 " \"effect\": \"Ripple2D\",\n"
1248 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1252 " \"name\": \"onScene\",\n"
1253 " \"action\": \"play\",\n"
1254 " \"animation\": \"pathAnimation\"\n"
1257 " \"name\": \"onScene\",\n"
1258 " \"action\": \"applyConstraint\",\n"
1259 " \"constrainer\": \"constrainer0\",\n"
1260 " \"properties\":\n"
1263 " \"source\": \"Image1\",\n"
1264 " \"sourceProperty\": \"positionX\",\n"
1265 " \"target\": \"Image1\",\n"
1266 " \"targetProperty\": \"colorRed\",\n"
1267 " \"range\": [-300,300]\n"
1272 " \"name\": \"onScene\",\n"
1273 " \"action\": \"applyConstraint\",\n"
1274 " \"constrainer\": \"constrainer1\",\n"
1275 " \"properties\":\n"
1278 " \"source\": \"Image1\",\n"
1279 " \"sourceProperty\": \"positionX\",\n"
1280 " \"target\": \"Image1\",\n"
1281 " \"targetProperty\": \"colorBlue\",\n"
1282 " \"range\": [-300,300]\n"
1287 " \"name\": \"offScene\",\n"
1288 " \"action\": \"removeConstraints\",\n"
1289 " \"constrainer\": \"constrainer0\",\n"
1290 " \"properties\":\n"
1293 " \"source\": \"Image1\",\n"
1294 " \"sourceProperty\": \"positionX\",\n"
1295 " \"target\": \"Image1\",\n"
1296 " \"targetProperty\": \"colorRed\",\n"
1297 " \"range\": [-300,300]\n"
1302 " \"name\": \"offScene\",\n"
1303 " \"action\": \"removeConstraints\",\n"
1304 " \"constrainer\": \"constrainer1\",\n"
1305 " \"properties\":\n"
1308 " \"source\": \"Image1\",\n"
1309 " \"sourceProperty\": \"positionX\",\n"
1310 " \"target\": \"Image1\",\n"
1311 " \"targetProperty\": \"colorBlue\",\n"
1312 " \"range\": [-300,300]\n"
1323 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1324 " \"curvature\":0.35\n"
1327 " \"constrainers\":\n"
1329 " \"constrainer0\":\n"
1331 " \"type\": \"PathConstrainer\",\n"
1332 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1333 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1335 " \"constrainer1\":\n"
1337 " \"type\": \"LinearConstrainer\",\n"
1338 " \"value\": [ 0, 0, 0 ]\n"
1341 " \"animations\": {\n"
1342 " \"pathAnimation\": {\n"
1343 " \"duration\": 3.0,\n"
1344 " \"properties\":\n"
1346 " \"actor\": \"Image1\",\n"
1347 " \"path\":\"path0\",\n"
1348 " \"forward\":[1,0,0],\n"
1349 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1350 " \"timePeriod\": {\n"
1352 " \"duration\": 3\n"
1356 " \"actor\": \"Image1\",\n"
1357 " \"property\": \"uTime\",\n"
1358 " \"value\": 10.0,\n"
1359 " \"alphaFunction\": \"LINEAR\",\n"
1360 " \"timePeriod\": {\n"
1362 " \"duration\": 10.0\n"
1364 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1367 " \"Animation_1\": {\n"
1369 " \"properties\": [\n"
1371 " \"actor\": \"Image1\",\n"
1372 " \"property\": \"uTime\",\n"
1373 " \"value\": 10.0,\n"
1374 " \"alphaFunction\": \"LINEAR\",\n"
1375 " \"timePeriod\": {\n"
1377 " \"duration\": 10.0\n"
1379 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1386 Builder builder = Builder::New();
1388 // frame buffer coverage
1389 builder.LoadFromString( json );
1391 // Render and notify
1392 application.SendNotification();
1393 application.Render();
1395 Dali::Path path = builder.GetPath( "path0" );
1396 DALI_TEST_CHECK( path );
1398 Dali::Path path2 = builder.GetPath( "path0" );
1399 DALI_TEST_CHECK( path2 );
1400 DALI_TEST_CHECK( path == path2 );
1402 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1403 DALI_TEST_CHECK( constrainer0 );
1405 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1406 DALI_TEST_CHECK( constrainer0_2 );
1407 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1409 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1410 DALI_TEST_CHECK( constrainer1 );
1412 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1413 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1417 Actor actor = Actor::New();
1418 application.GetScene().Add( actor );
1419 builder.AddActors( actor );
1421 // Render and notify
1422 application.SendNotification();
1423 application.Render();
1425 actor.GetChildAt( 0 ).Unparent();
1430 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1432 Property::Value* value = xMap->Find( xKey ); \
1433 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1434 if( value != NULL ) \
1436 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1438 value->Get(result); \
1439 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1440 std::ostringstream oss; \
1441 oss << "Animation element " << xKey << "= " << result << std::endl; \
1442 tet_printf( oss.str().c_str() ); \
1446 tet_printf("Can't find map element " xKey "\n"); \
1451 int UtcDaliBuilderMapping01(void)
1453 ToolkitTestApplication application;
1459 " \"buttonPressFadeOut\":{\n"
1460 " \"alphaFunction\":\"EASE_OUT\",\n"
1461 " \"timePeriod\":{\n"
1463 " \"duration\":0.4\n"
1466 " \"buttonPressFadeIn\":{\n"
1467 " \"alphaFunction\":\"EASE_IN\",\n"
1468 " \"timePeriod\":{\n"
1470 " \"duration\":0.5\n"
1473 " \"transition:buttonPressed\":\n"
1476 " \"target\": \"unselectedBackgroundRenderer\",\n"
1477 " \"property\": \"opacity\",\n"
1479 " \"animator\":\"<buttonPressFadeOut>\"\n"
1482 " \"transition:buttonReleased\":\n"
1485 " \"target\": \"unselectedBackgroundRenderer\",\n"
1486 " \"property\": \"opacity\",\n"
1488 " \"animator\":\"<buttonPressFadeIn>\"\n"
1491 " \"target\": \"unselectedForegroundRenderer\",\n"
1492 " \"property\": \"scale\",\n"
1493 " \"value\": [ 1, 1, 1 ],\n"
1494 " \"animator\":\"<buttonPressFadeIn>\"\n"
1497 " \"target\": \"selectedBackgroundRenderer\",\n"
1498 " \"property\": \"opacity\",\n"
1500 " \"animator\": \"<buttonPressFadeOut>\"\n"
1503 " \"target\": \"selectedForegroundRenderer\",\n"
1504 " \"property\": \"scale\",\n"
1505 " \"value\": [ 0, 0, 0 ],\n"
1506 " \"animator\":\"<buttonPressFadeOut>\"\n"
1512 " \"testbutton\":\n"
1514 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1515 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1520 Builder builder = Builder::New();
1521 builder.LoadFromString( json );
1523 Test::TestButton testButton = Test::TestButton::New();
1524 application.GetScene().Add( testButton );
1526 // Render and notify
1527 application.SendNotification();
1528 application.Render();
1530 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1532 // Now check that it has loaded the transition correctly:
1533 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1534 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1535 Property::Array* array = transition.GetArray();
1537 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1538 Property::Value element = array->GetElementAt(0);
1539 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1540 Property::Map* map = element.GetMap();
1542 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1543 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1544 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1545 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1546 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1552 int UtcDaliBuilderMappingCycleCheck(void)
1554 ToolkitTestApplication application;
1560 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1561 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1562 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1564 " \"alphaFunction\":\"EASE_IN\",\n"
1565 " \"timePeriod\":{\n"
1566 " \"delay\":\"<cyclicKey3>\",\n"
1567 " \"duration\":0.6\n"
1570 " \"transition:buttonPressed\":\n"
1573 " \"target\": \"<cyclicKey1>\",\n"
1574 " \"property\": \"<cyclicKey2>\",\n"
1576 " \"animator\":\"<FadeOut>\"\n"
1582 " \"testbutton\":\n"
1584 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1585 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1586 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1587 " \"enabledTransition\":\"<unknownKey>\"\n"
1592 Builder builder = Builder::New();
1593 builder.LoadFromString( json );
1595 Test::TestButton testButton = Test::TestButton::New();
1596 application.GetScene().Add( testButton );
1598 // Render and notify
1599 application.SendNotification();
1600 application.Render();
1602 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1604 // Now check that it has loaded the transition correctly:
1605 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1606 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1607 Property::Array* array = transition.GetArray();
1609 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1610 Property::Value element = array->GetElementAt(0);
1611 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1612 Property::Map* map = element.GetMap();
1614 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1615 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1616 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1621 int UtcDaliBuilderTypeCasts(void)
1623 ToolkitTestApplication application;
1629 "\"type\": \"Layer\","
1630 "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1631 "\"position\": { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1632 "\"color\": { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1633 "\"sensitive\": { \"typeCast\":\"boolean\", \"value\":false },"
1634 "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1635 "\"colorMode\": { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1636 "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
1637 "\"padding\": { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
1642 Actor rootActor = Actor::New();
1643 application.GetScene().Add( rootActor );
1645 Builder builder = Builder::New();
1646 builder.LoadFromString( json );
1647 builder.AddActors( rootActor );
1649 application.SendNotification();
1650 application.Render();
1652 Actor createdActor = rootActor.GetChildAt( 0 );
1653 DALI_TEST_EQUALS( createdActor.GetProperty< Vector2 >( Actor::Property::MAXIMUM_SIZE ), Vector2(100.0f,15.0f), TEST_LOCATION );
1654 DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
1655 DALI_TEST_EQUALS( createdActor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
1656 DALI_TEST_EQUALS( createdActor.GetProperty< bool >( Actor::Property::SENSITIVE ), false, TEST_LOCATION );
1657 DALI_TEST_EQUALS( createdActor.GetProperty< ColorMode >( Actor::Property::COLOR_MODE ), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
1662 int UtcDaliBuilderBuilderControl(void)
1664 ToolkitTestApplication application;
1670 "\"type\": \"BuilderControl\","
1671 "\"integerProperty\": 10,"
1672 "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
1673 "\"matrixProperty\": [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
1674 "\"noneProperty\": 10"
1679 Actor rootActor = Actor::New();
1680 application.GetScene().Add( rootActor );
1682 Builder builder = Builder::New();
1683 builder.LoadFromString( json );
1684 builder.AddActors( rootActor );
1686 application.SendNotification();
1687 application.Render();
1689 DALI_TEST_EQUALS( BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION );
1694 int UtcDaliBuilderCustomControl(void)
1696 ToolkitTestApplication application;
1702 "\"type\": \"DummyControl\","
1703 "\"name\": \"I can haz custom Control\""
1708 Actor rootActor = Actor::New();
1709 application.GetScene().Add( rootActor );
1711 Builder builder = Builder::New();
1712 builder.LoadFromString( json );
1713 builder.AddActors( rootActor );
1715 application.SendNotification();
1716 application.Render();
1718 Actor customControl = rootActor.FindChildByName( "I can haz custom Control" );
1720 // Test that we have the correct type of custom control
1721 DummyControl dummyControl = DummyControl::DownCast( customControl );
1722 DALI_TEST_CHECK( dummyControl );
1725 DALI_TEST_CHECK( typeid(dummyControl.GetImplementation()) == typeid(DummyControlImpl) );
1731 int UtcDaliBuilderActionsWithParams(void)
1733 ToolkitTestApplication application;
1735 // JSON with a quit event when the actor is touched
1741 " \"type\": \"ImageView\",\n"
1742 " \"name\": \"image\",\n"
1743 " \"size\": [100,100,1],\n"
1744 " \"signals\": [{\n"
1745 " \"name\": \"touched\",\n"
1746 " \"action\": \"show\",\n"
1747 " \"parameters\": {\n"
1748 " \"property1\" : 10,\n"
1749 " \"property2\" : [1,2],\n"
1750 " \"property3\" : [1,2,3],\n"
1751 " \"property4\" : [1,2,3,4]\n"
1759 Builder builder = Builder::New();
1760 builder.LoadFromString( json );
1761 builder.AddActors( application.GetScene().GetRootLayer() );
1763 DALI_TEST_CHECK( true ); // For Coverage
1768 int UtcDaliBuilderConfigurationP(void)
1770 ToolkitTestApplication application;
1772 // JSON with a quit event when the actor is touched
1777 " \"alwaysShowFocus\":true\n"
1782 Builder builder = Builder::New();
1783 builder.LoadFromString( json );
1785 Property::Map map = builder.GetConfigurations();
1787 Dali::Property::Value* pValue = map.Find( "alwaysShowFocus" );
1789 DALI_TEST_CHECK( pValue );
1791 bool value = pValue->Get<bool>();
1793 DALI_TEST_CHECK( value );
1799 int UtcDaliBase64EncodingP(void)
1801 std::vector<uint32_t> data = { 0, 1, 2, 3, 4, 5, std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max() };
1803 Property::Value value;
1804 EncodeBase64PropertyData( value, data );
1806 std::cout << "Max uint32_t:" << std::numeric_limits<uint32_t>::max() << std::endl;
1807 std::cout << "Input data: ";
1808 std::ostream_iterator<uint32_t> out_it (std::cout,", ");
1809 std::copy ( data.begin(), data.end(), out_it );
1810 std::cout << std::endl;
1813 DALI_TEST_CHECK( value.Get( output ) );
1814 DALI_TEST_EQUALS( output, "AAAAAAEAAAACAAAAAwAAAAQAAAAFAAAAAAAAAP////8", TEST_LOCATION );
1816 std::cout << "Output data: " << output << std::endl;
1821 int UtcDaliBase64EncodingN(void)
1823 tet_infoline( "Test encoding an empty vector returns empty string" );
1824 std::vector<uint32_t> data;
1826 Property::Value value;
1827 EncodeBase64PropertyData( value, data );
1830 DALI_TEST_CHECK( value.Get( output ) );
1831 DALI_TEST_EQUALS( output.empty(), true, TEST_LOCATION );
1836 template <typename T>
1837 int b64l(std::vector<T>&data)
1839 auto lengthInBytes = 4*data.size();
1840 return ceil( lengthInBytes * 1.33333f );
1843 int UtcDaliBase64EncodingP02(void)
1845 tet_infoline( "Test encoding vectors of lengths m .. m+4 encode and decode back to the same length vectors" );
1847 std::vector<uint32_t> testData;
1848 for(int i=0; i<8; ++i ) // 8 chosen to stay within single string output
1850 testData.push_back(i);
1852 Property::Value value;
1853 EncodeBase64PropertyData( value, testData );
1856 DALI_TEST_CHECK( value.Get( output ) );
1857 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1858 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1860 std::vector<uint32_t> outData;
1861 DecodeBase64PropertyData( value, outData );
1862 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1863 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1866 testData.push_back( 12345 );
1867 EncodeBase64PropertyData( value, testData );
1869 DALI_TEST_CHECK( value.Get( output ) );
1870 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1871 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1874 DecodeBase64PropertyData( value, outData );
1875 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1876 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1879 testData.push_back( 67890 );
1880 EncodeBase64PropertyData( value, testData );
1882 DALI_TEST_CHECK( value.Get( output ) );
1883 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1884 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1887 DecodeBase64PropertyData( value, outData );
1888 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1889 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1892 testData.push_back( -1 );
1893 EncodeBase64PropertyData( value, testData );
1895 DALI_TEST_CHECK( value.Get( output ) );
1896 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1897 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1900 DecodeBase64PropertyData( value, outData );
1901 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1902 DALI_TEST_EQUALS( std::equal( testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION );
1909 int UtcDaliBase64EncodingP03(void)
1911 tet_infoline( "Test encoding a vector of length 12 has output within single string" );
1913 std::vector<uint32_t> testData;
1914 for(int i=0; i<12; ++i )
1916 testData.push_back(i);
1918 Property::Value value;
1919 EncodeBase64PropertyData( value, testData );
1922 DALI_TEST_CHECK( value.Get( output ) );
1923 DALI_TEST_EQUALS( output.empty(), false, TEST_LOCATION);
1924 DALI_TEST_EQUALS( output.length(), b64l(testData), TEST_LOCATION );
1926 std::vector<uint32_t> outData;
1927 DecodeBase64PropertyData( value, outData );
1928 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1934 int UtcDaliBase64EncodingP04(void)
1936 tet_infoline( "Test encoding a vector of length 13 has output split over 2 strings" );
1938 std::vector<uint32_t> testData;
1939 for(int i=0; i<13; ++i )
1941 testData.push_back(i);
1943 Property::Value value;
1944 EncodeBase64PropertyData( value, testData );
1946 auto array = value.GetArray();
1947 DALI_TEST_CHECK( array );
1949 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
1951 std::vector<uint32_t> outData;
1952 DecodeBase64PropertyData( value, outData );
1953 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1959 int UtcDaliBase64EncodingP05(void)
1961 tet_infoline( "Test encoding a vector of length 24 has output split over 2 strings" );
1963 std::vector<uint32_t> testData;
1964 for(int i=0; i<24; ++i )
1966 testData.push_back(i);
1968 Property::Value value;
1969 EncodeBase64PropertyData( value, testData );
1971 auto array = value.GetArray();
1972 DALI_TEST_CHECK( array );
1974 DALI_TEST_EQUALS( array->Count(), 2, TEST_LOCATION );
1976 std::vector<uint32_t> outData;
1977 DecodeBase64PropertyData( value, outData );
1978 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
1984 int UtcDaliBase64EncodingP06(void)
1986 tet_infoline( "Test encoding a vector of arbitrary length decodes OK." );
1988 std::vector<uint32_t> testData;
1989 for(int i=0; i<97; ++i )
1991 testData.push_back(i);
1993 Property::Value value;
1994 EncodeBase64PropertyData( value, testData );
1996 auto array = value.GetArray();
1997 DALI_TEST_CHECK( array );
1999 std::vector<uint32_t> outData;
2000 DecodeBase64PropertyData( value, outData );
2001 DALI_TEST_EQUALS( testData.size(), outData.size(), TEST_LOCATION );
2007 int UtcDaliBase64DecodingN01(void)
2009 tet_infoline( "Test decoding empty string results in empty data" );
2011 Property::Value value("");
2012 std::vector<uint32_t> outputData;
2013 DecodeBase64PropertyData( value, outputData);
2014 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2019 int UtcDaliBase64DecodingN02(void)
2021 tet_infoline( "Test decoding array with non-string values results in empty data" );
2023 Property::Array array;
2025 array[0] = "Stuff, things";
2027 Property::Value value(array);
2029 std::vector<uint32_t> outputData;
2030 DecodeBase64PropertyData( value, outputData);
2031 DALI_TEST_EQUALS( outputData.size(), 0, TEST_LOCATION );
2035 int UtcDaliBase64DecodingP01(void)
2037 tet_infoline( "Test decoding string of known data gives expected result");
2039 std::string testInput("//////7+/v4DAgEA");
2040 std::vector<uint32_t> expectedResults = { 0xffffffff, 0xfefefefe, 0x00010203 };
2042 std::vector<uint32_t> outputData;
2043 DecodeBase64PropertyData(Property::Value(testInput), outputData);
2045 DALI_TEST_EQUALS( std::equal( expectedResults.begin(), expectedResults.end(), outputData.begin() ), true,