2 * Copyright (c) 2022 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/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/builder/base64-encoding.h>
27 #include <dali-toolkit/devel-api/builder/builder.h>
28 #include <dali/integration-api/events/touch-event-integ.h>
29 #include <dummy-control.h>
30 #include <test-animation-data.h>
31 #include <test-button.h>
33 #define STRINGIFY(A) #A
36 using namespace Toolkit;
38 namespace BuilderControlProperty
42 INTEGER_PROPERTY = Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1,
52 return Toolkit::Control::New();
55 int gSetPropertyCalledCount = 0;
57 void SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value)
59 ++gSetPropertyCalledCount;
62 Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex)
64 return Property::Value();
67 } // unnamed namespace
70 Dali::TypeRegistration typeRegistration("BuilderControl", typeid(Toolkit::Control), Create);
72 Dali::PropertyRegistration propertyInteger(typeRegistration, "integerProperty", INTEGER_PROPERTY, Property::INTEGER, &SetProperty, &GetProperty);
73 Dali::PropertyRegistration propertyMatrix3(typeRegistration, "matrix3Property", MATRIX3_PROPERTY, Property::MATRIX3, &SetProperty, &GetProperty);
74 Dali::PropertyRegistration propertyMatrix(typeRegistration, "matrixProperty", MATRIX_PROPERTY, Property::MATRIX, &SetProperty, &GetProperty);
75 Dali::PropertyRegistration propertyNone(typeRegistration, "noneProperty", NONE_PROPERTY, Property::NONE, &SetProperty, &GetProperty);
77 } // namespace BuilderControlProperty
83 BuilderFunctor(bool& called)
99 void builder_startup(void)
101 test_return_value = TET_UNDEF;
104 void builder_cleanup(void)
106 test_return_value = TET_PASS;
109 int UtcDaliBuilderQuitSignal(void)
111 ToolkitTestApplication application;
113 // JSON with a quit event when the actor is touched
118 "\"type\": \"Layer\","
119 "\"size\": [100,100,1],"
120 "\"parentOrigin\": \"TOP_LEFT\","
121 "\"anchorPoint\": \"TOP_LEFT\","
122 "\"maximumSize\": [100,100],"
123 "\"orientation\": [10,10,10,10],"
124 "\"clippingBox\": [10,10,10,10],"
126 "\"name\": \"touched\","
127 "\"action\": \"quit\""
131 Builder builder = Builder::New();
132 builder.LoadFromString(json);
133 builder.AddActors(application.GetScene().GetRootLayer());
135 // Connect to builder's quit signal
136 bool functorCalled(false);
137 builder.QuitSignal().Connect(&application, BuilderFunctor(functorCalled));
140 application.SendNotification();
141 application.Render();
143 // Emit touch event and check that our quit method is called
144 Integration::TouchEvent touchEvent;
145 Integration::Point point;
146 point.SetState(PointState::DOWN);
147 point.SetScreenPosition(Vector2(10.0f, 10.0f));
148 touchEvent.points.push_back(point);
149 application.ProcessEvent(touchEvent);
150 DALI_TEST_CHECK(functorCalled);
155 int UtcDaliBuilderAnimationP(void)
157 ToolkitTestApplication application;
159 // JSON with a quit event when the actor is touched
164 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
170 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
171 " \"curvature\":0.35"
177 " \"endAction\": \"BAKE\","
178 " \"disconnectAction\": \"BAKE\","
181 " \"actor\": \"greeting\","
182 " \"property\": \"position\","
183 " \"value\": [300, 300, -1000],"
184 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
185 " \"relative\": true,"
192 " \"actor\": \"greeting\","
193 " \"property\": \"visible\","
194 " \"alphaFunction\": \"LINEAR\","
198 " \"actor\": \"greeting\","
199 " \"property\": \"sizeWidth\","
200 " \"alphaFunction\": \"REVERSE\","
204 " \"actor\": \"greeting\","
205 " \"property\": \"orientation\","
206 " \"alphaFunction\": \"EASE_IN\","
207 " \"value\": [10.0,20.0,30.0]"
210 " \"actor\": \"greeting\","
211 " \"property\": \"orientation\","
212 " \"alphaFunction\": \"EASE_OUT\","
213 " \"value\": [0.0, 0.0, 0.0, 1.0]"
216 " \"actor\": \"greeting\","
217 " \"property\": \"orientation\","
218 " \"alphaFunction\": \"EASE_IN_OUT\","
219 " \"value\": [0.0, 0.0, 0.0, 1.0]"
222 " \"actor\": \"greeting\","
223 " \"property\": \"orientation\","
224 " \"alphaFunction\": \"EASE_IN_SINE\","
225 " \"value\": [0.0, 0.0, 0.0, 1.0]"
228 " \"actor\": \"greeting\","
229 " \"property\": \"orientation\","
230 " \"alphaFunction\": \"EASE_OUT_SINE\","
231 " \"value\": [0.0, 0.0, 0.0, 1.0]"
234 " \"actor\": \"greeting\","
235 " \"property\": \"orientation\","
236 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
237 " \"value\": [0.0, 0.0, 0.0, 1.0]"
240 " \"actor\": \"greeting\","
241 " \"property\": \"orientation\","
242 " \"alphaFunction\": \"BOUNCE\","
243 " \"value\": [0.0, 0.0, 0.0, 1.0]"
246 " \"actor\": \"greeting\","
247 " \"property\": \"orientation\","
248 " \"alphaFunction\": \"SIN\","
249 " \"value\": [0.0, 0.0, 0.0, 1.0]"
252 " \"actor\": \"greeting\","
253 " \"property\": \"orientation\","
254 " \"alphaFunction\": \"EASE_OUT_BACK\","
255 " \"value\": [0.0, 0.0, 0.0, 1.0]"
259 " \"pathAnimation\": {"
260 " \"duration\": 3.0,"
261 " \"endAction\": \"DISCARD\","
262 " \"disconnectAction\": \"BAKE_FINAL\","
263 " \"properties\": [{"
264 " \"actor\": \"greeting\","
265 " \"path\":\"path0\","
266 " \"forward\":[1,0,0],"
267 " \"alphaFunction\": \"EASE_IN_OUT\","
274 " \"pathAnimation2\": {"
275 " \"duration\": 3.0,"
276 " \"endAction\": \"BAKE_FINAL\","
277 " \"disconnectAction\": \"DISCARD\","
278 " \"properties\": [{"
279 " \"actor\": \"greeting\","
280 " \"path\":\"path0\","
281 " \"forward\":[1,0,0],"
282 " \"alphaFunction\": \"EASE_IN_OUT\","
291 " \"name\": \"greeting\","
292 " \"type\": \"TextLabel\","
293 " \"text\": \"Touch me\","
294 " \"inherit\": [\"basicText\"],"
295 " \"position\": [0, -120, 0],"
296 " \"size\": [200, 200, 1],"
297 " \"orientation\": [0, 0, 30],"
299 " \"name\": \"touched\","
300 " \"action\": \"play\","
301 " \"animation\": \"animate\""
306 Builder builder = Builder::New();
307 builder.LoadFromString(json);
308 builder.AddActors(application.GetScene().GetRootLayer());
310 Animation anim = builder.CreateAnimation("animate");
312 DALI_TEST_CHECK(anim);
315 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
316 anim = builder.CreateAnimation("animate", map);
318 DALI_TEST_CHECK(anim);
320 anim = builder.CreateAnimation("pathAnimation");
322 DALI_TEST_CHECK(anim);
324 anim = builder.CreateAnimation("pathAnimation2");
326 DALI_TEST_CHECK(anim);
329 // Emit touch event and check that our quit method is called
330 Integration::TouchEvent touchEvent;
331 Integration::Point point;
332 point.SetState(PointState::DOWN);
333 point.SetScreenPosition(Vector2(10.0f, 10.0f));
334 touchEvent.points.push_back(point);
335 application.ProcessEvent(touchEvent);
338 application.SendNotification();
339 application.Render();
344 int UtcDaliBuilderAnimationN(void)
346 ToolkitTestApplication application;
348 // JSON with a quit event when the actor is touched
353 " \"TEXT\": \"Touch Me\","
354 " \"NAME\": \"greeting\" "
360 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
361 " \"curvature\":0.35"
367 " \"endAction\": \"BAKE\","
368 " \"disconnectAction\": \"BAKE\","
371 " \"actor\": \"{NAME}\","
372 " \"property\": \"positioninvalid\","
373 " \"value\": [300, 300, -1000],"
374 " \"alphaFunction\": \"EASE_IN_OUT\","
375 " \"relative\": true,"
385 " \"endAction\": \"BAKE\","
386 " \"disconnectAction\": \"BAKE\","
389 " \"actor\": \"{NAME}\","
390 " \"property\": \"positioninvalid\","
391 " \"value\": [300, 300, -1000],"
392 " \"alphaFunction\": \"EGGS_OVER_EASY\","
393 " \"relative\": true,"
401 " \"pathAnimation\": {"
402 " \"duration\": 3.0,"
403 " \"endAction\": \"DISCARD\","
404 " \"disconnectAction\": \"BAKE_FINAL\","
405 " \"properties\": [{"
406 " \"actor\": \"greeting\","
407 " \"path\":\"pathDoesntExist\","
408 " \"forward\":[1,0,0],"
409 " \"alphaFunction\": \"EASE_IN_OUT\","
418 " \"name\": \"greeting\","
419 " \"type\": \"TextLabel\","
420 " \"text\": \"Touch me\","
421 " \"inherit\": [\"basicText\"],"
422 " \"position\": [0, -120, 0],"
423 " \"size\": [200, 200, 1],"
424 " \"orientation\": [0, 0, 30],"
426 " \"name\": \"touched\","
427 " \"action\": \"play\","
428 " \"animation\": \"animate\""
432 " \"name\": \"greeting2\","
433 " \"type\": \"TextLabel\","
434 " \"text\": \"Touch me\""
438 Builder builder = Builder::New();
439 builder.LoadFromString(json);
440 builder.AddActors(application.GetScene().GetRootLayer());
442 Animation anim = builder.CreateAnimation("animate");
444 // log warning line coverage
445 anim = builder.CreateAnimation("pathAnimation");
446 DALI_TEST_CHECK(anim);
448 anim = builder.CreateAnimation("animate");
449 DALI_TEST_CHECK(anim);
451 anim = builder.CreateAnimation("animate2");
452 DALI_TEST_CHECK(anim);
454 // create referencing a different actor aka animation templates
456 map["NAME"] = "greeting2";
457 anim = builder.CreateAnimation("animate2", map);
458 DALI_TEST_CHECK(anim);
460 // alternative actor to use for FindChildByName
461 anim = builder.CreateAnimation("animate2", application.GetScene().GetRootLayer());
462 DALI_TEST_CHECK(anim);
464 // alternative actor to use for FindChildByName
465 anim = builder.CreateAnimation("animate2", map, application.GetScene().GetRootLayer());
466 DALI_TEST_CHECK(anim);
471 int UtcDaliBuilderConstantsP(void)
473 ToolkitTestApplication application;
475 // JSON with a quit event when the actor is touched
480 " \"IMAGE_PATH\": \"apath\","
482 " \"ANCHOR\": \"TOP_LEFT\","
483 " \"PADDING\": [1,2,3,4]"
487 " \"type\": \"ImageView\","
488 " \"name\": \"{NAME}\","
489 " \"size\": [100,100,1],"
490 " \"parentOrigin\": \"TOP_LEFT\","
491 " \"anchorPoint\": \"{ANCHOR}\","
492 " \"padding\": \"{PADDING}\","
493 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
494 " \"sizeWidth\": \"{WIDTH}\","
496 " \"name\": \"touched\","
497 " \"action\": \"quit\""
502 Builder builder = Builder::New();
503 builder.LoadFromString(json);
505 builder.AddConstant("NAME", "image");
507 Property::Map map = builder.GetConstants();
509 Dali::Property::Value* pValue = map.Find("NAME");
511 DALI_TEST_CHECK(pValue);
513 pValue = map.Find("IMAGE_PATH");
515 DALI_TEST_CHECK(pValue);
517 Dali::Property::Value value = builder.GetConstant("WIDTH");
519 DALI_TEST_CHECK(value.GetType() != Property::NONE);
521 builder.AddActors(application.GetScene().GetRootLayer());
522 DALI_TEST_CHECK(builder);
524 Actor actor = application.GetScene().GetRootLayer().FindChildByName("image");
525 DALI_TEST_CHECK(actor);
530 int UtcDaliBuilderTemplatesAndStylesP(void)
532 ToolkitTestApplication application;
534 // JSON with a quit event when the actor is touched
539 " \"SIZE\": [10,20,30]"
543 " \"imageStyle\": \n"
545 " \"color\": [1,0,0,1],\n"
547 " \"childImage\": {\n"
548 " \"color\": \"34\"\n"
555 " \"imageViewTemplate\": { \n"
556 " \"type\": \"ImageView\",\n"
557 " \"styles\": [\"imageStyle\"]\n"
559 " \"imageTree\": { \n"
560 " \"type\": \"ImageView\",\n"
561 " \"styles\": [\"imageStyle\"],\n"
562 " \"name\": \"image\",\n"
563 " \"size\": \"{SIZE}\",\n"
565 " \"name\": \"touched\",\n"
566 " \"action\": \"quit\"\n"
570 " \"type\":\"ImageView\",\n"
571 " \"name\":\"childImage\", \n"
581 " \"type\":\"imageViewTemplate\",\n"
582 " \"name\":\"childImage2\"\n"
589 " \"type\": \"imageTree\","
590 " \"size\": [100,100,1]"
594 std::string stylejson(
596 " \"color\": [1,0,0,1],\n"
598 " \"childImage\": {\n"
599 " \"color\": \"#344353\"\n"
604 std::string templatejson(
606 " \"type\": \"ImageView\",\n"
607 " \"styles\": [\"imageStyle\"],\n"
608 " \"name\": \"image\",\n"
609 " \"size\": \"{SIZE}\",\n"
611 " \"name\": \"touched\",\n"
612 " \"action\": \"quit\"\n"
616 " \"type\":\"ImageView\",\n"
617 " \"name\":\"childImage\" \n"
622 Builder builder = Builder::New();
623 builder.LoadFromString(json);
625 ImageView actor = ImageView::DownCast(builder.Create("imageTree"));
626 DALI_TEST_CHECK(actor);
628 Dali::Property::Map map;
629 map["SIZE"] = Vector3(100, 100, 1);
630 actor = ImageView::DownCast(builder.Create("imageTree", map));
631 DALI_TEST_CHECK(actor);
633 // create from json snippet
634 actor = ImageView::DownCast(builder.CreateFromJson(templatejson));
635 DALI_TEST_CHECK(actor);
637 // NB: already applied in create
638 DALI_TEST_CHECK(builder.ApplyStyle("imageStyle", actor));
640 // apply from json snippet
641 DALI_TEST_CHECK(builder.ApplyFromJson(actor, stylejson));
646 int UtcDaliBuilderRenderTasksP(void)
648 ToolkitTestApplication application;
650 // JSON with a quit event when the actor is touched
656 " \"sourceActor\": \"image\",\n"
657 " \"cameraActor\": \"camera\" \n"
663 " \"type\": \"CameraActor\",\n"
664 " \"name\": \"camera\"\n"
667 " \"type\": \"ImageView\",\n"
668 " \"name\": \"image\",\n"
669 " \"size\": [100,100,1],\n"
671 " \"name\": \"touched\",\n"
672 " \"action\": \"quit\"\n"
676 " \"type\":\"ImageView\",\n"
677 " \"name\":\"childImage\" \n"
684 Builder builder = Builder::New();
685 builder.LoadFromString(json);
687 unsigned int count = application.GetScene().GetRenderTaskList().GetTaskCount();
690 builder.CreateRenderTask("task0");
692 DALI_TEST_CHECK(count <
693 application.GetScene().GetRenderTaskList().GetTaskCount());
698 int UtcDaliBuilderChildActionP(void)
700 ToolkitTestApplication application;
702 // JSON with a quit event when the actor is touched
707 " \"type\": \"Actor\",\n"
708 " \"name\": \"actor\",\n"
709 " \"size\": [100,100,1],\n"
710 " \"parentOrigin\": \"TOP_LEFT\",\n"
711 " \"anchorPoint\": \"TOP_LEFT\",\n"
713 " \"type\": \"Actor\",\n"
714 " \"name\": \"subActor\"\n"
717 " \"name\": \"touched\",\n"
718 " \"action\": \"hide\",\n"
719 " \"actor\": \"actor\",\n"
720 " \"childActor\": \"subActor\"\n"
725 Builder builder = Builder::New();
726 builder.LoadFromString(json);
727 builder.AddActors(application.GetScene().GetRootLayer());
730 application.SendNotification();
731 application.Render();
733 // Emit touch event and check that our quit method is called
734 Integration::TouchEvent touchEvent;
735 Integration::Point point;
736 point.SetState(PointState::DOWN);
737 point.SetScreenPosition(Vector2(10.0f, 10.0f));
738 touchEvent.points.push_back(point);
739 application.ProcessEvent(touchEvent);
742 application.SendNotification();
743 application.Render();
745 Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor");
746 DALI_TEST_CHECK(actor);
748 DALI_TEST_CHECK(!actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE));
753 int UtcDaliBuilderSetPropertyActionP(void)
755 ToolkitTestApplication application;
757 // JSON with a quit event when the actor is touched
762 " \"type\": \"Actor\",\n"
763 " \"name\": \"actor\",\n"
764 " \"size\": [100,100,1],\n"
765 " \"parentOrigin\": \"TOP_LEFT\",\n"
766 " \"anchorPoint\": \"TOP_LEFT\",\n"
768 " \"type\": \"Actor\",\n"
769 " \"name\": \"subActor\"\n"
772 " \"name\": \"touched\",\n"
773 " \"action\": \"set\",\n"
774 " \"actor\": \"subActor\",\n"
775 " \"property\": \"visible\",\n"
776 " \"value\": false\n"
781 Builder builder = Builder::New();
782 builder.LoadFromString(json);
783 builder.AddActors(application.GetScene().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 = application.GetScene().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\": \"touched\",\n"
829 " \"action\": \"hide\"\n"
834 Builder builder = Builder::New();
835 builder.LoadFromString(json);
836 builder.AddActors(application.GetScene().GetRootLayer());
839 application.SendNotification();
840 application.Render();
842 // Emit touch event and check that our quit method is called
843 Integration::TouchEvent touchEvent;
844 Integration::Point point;
845 point.SetState(PointState::DOWN);
846 point.SetScreenPosition(Vector2(10.0f, 10.0f));
847 touchEvent.points.push_back(point);
848 application.ProcessEvent(touchEvent);
851 application.SendNotification();
852 application.Render();
854 Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor");
855 DALI_TEST_CHECK(actor);
857 DALI_TEST_CHECK(!actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE));
862 int UtcDaliBuilderPropertyNotificationP(void)
864 ToolkitTestApplication application;
866 // JSON with a quit event when the actor is touched
871 " \"type\": \"Actor\",\n"
872 " \"name\": \"actor\",\n"
873 " \"size\": [100,100,1],\n"
874 " \"parentOrigin\": \"TOP_LEFT\",\n"
875 " \"anchorPoint\": \"TOP_LEFT\",\n"
877 " \"type\": \"Actor\",\n"
878 " \"name\": \"subActor\"\n"
881 " \"name\": \"touched\",\n"
882 " \"action\": \"hide\"\n"
884 " \"notifications\": [{\n"
885 " \"property\": \"visible\",\n"
886 " \"condition\": \"False\",\n"
887 " \"action\": \"show\"\n"
890 " \"property\": \"positionX\",\n"
891 " \"condition\": \"LessThan\",\n"
893 " \"action\": \"show\"\n"
896 " \"property\": \"positionY\",\n"
897 " \"condition\": \"GreaterThan\",\n"
898 " \"arg0\": 200.0,\n"
899 " \"action\": \"show\"\n"
902 " \"property\": \"positionZ\",\n"
903 " \"condition\": \"Inside\",\n"
906 " \"action\": \"show\"\n"
909 " \"property\": \"positionZ\",\n"
910 " \"condition\": \"Outside\",\n"
913 " \"action\": \"show\"\n"
918 Builder builder = Builder::New();
919 builder.LoadFromString(json);
920 builder.AddActors(application.GetScene().GetRootLayer());
923 application.SendNotification();
924 application.Render();
926 // Emit touch event and check that our quit method is called
927 Integration::TouchEvent touchEvent;
928 Integration::Point point;
929 point.SetState(PointState::DOWN);
930 point.SetScreenPosition(Vector2(10.0f, 10.0f));
931 touchEvent.points.push_back(point);
932 application.ProcessEvent(touchEvent);
935 application.SendNotification();
936 application.Render();
939 application.SendNotification();
940 application.Render();
942 Actor actor = application.GetScene().GetRootLayer().FindChildByName("actor");
943 DALI_TEST_CHECK(actor);
945 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE));
950 int UtcDaliBuilderPropertyNotificationN(void)
952 ToolkitTestApplication application;
954 // JSON with a quit event when the actor is touched
959 " \"type\": \"Actor\",\n"
960 " \"notifications\": [{\n"
961 " \"property\": \"visible\",\n"
962 " \"condition\": \"ErrorCondition\",\n"
963 " \"action\": \"show\"\n"
970 Builder builder = Builder::New();
971 builder.LoadFromString(json);
972 builder.AddActors(application.GetScene().GetRootLayer());
973 DALI_TEST_CHECK(false);
977 DALI_TEST_CHECK(true);
983 int UtcDaliBuilderCustomPropertyP(void)
985 ToolkitTestApplication application;
987 // JSON with a quit event when the actor is touched
992 " \"imageTree\": { \n"
993 " \"type\": \"ImageView\",\n"
994 " \"name\": \"image\",\n"
995 " \"size\": [100,100,1],\n"
997 " \"name\": \"touched\",\n"
998 " \"action\": \"quit\"\n"
1000 " \"properties\": {\n"
1001 " \"newproperty\": true\n"
1003 " \"animatableProperties\": {\n"
1004 " \"newAnimatableproperty\": 3\n"
1008 " \"type\":\"ImageView\",\n"
1009 " \"name\":\"childImage\" \n"
1016 Builder builder = Builder::New();
1017 builder.LoadFromString(json);
1019 ImageView actor = ImageView::DownCast(builder.Create("imageTree"));
1020 DALI_TEST_CHECK(actor);
1022 // NB: already applied in create
1023 Property::Index index = actor.GetPropertyIndex("newproperty");
1024 DALI_TEST_CHECK(Property::INVALID_INDEX != index);
1025 Property::Value value = actor.GetProperty(index);
1026 DALI_TEST_CHECK(value.Get<bool>() == true);
1028 index = actor.GetPropertyIndex("newAnimatableproperty");
1029 DALI_TEST_CHECK(Property::INVALID_INDEX != index);
1030 value = actor.GetProperty(index);
1031 DALI_TEST_CHECK(value.Get<int>() == 3);
1036 int UtcDaliBuilderCustomShaderP(void)
1038 ToolkitTestApplication application;
1040 // JSON with a quit event when the actor is touched
1045 " \"type\": \"ImageView\",\n"
1046 " \"name\": \"Image1\",\n"
1047 " \"position\": [\n"
1048 " 0.40461349487305,\n"
1052 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1053 " \"size\": [200, 200, 0],\n"
1054 " \"effect\": \"Ripple2D\",\n"
1056 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1057 " \"desiredWidth\": 200,\n"
1058 " \"desiredHeight\": 80,\n"
1060 " \"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"
1063 " \"customAnimatableProperties\": {\n"
1064 " \"uAmplitude\": 0.02,\n"
1069 " \"name\": \"onScene\",\n"
1070 " \"action\": \"play\",\n"
1071 " \"animation\": \"Animation_1\"\n"
1076 " \"animations\": {\n"
1077 " \"Animation_1\": {\n"
1079 " \"properties\": [\n"
1081 " \"actor\": \"Image1\",\n"
1082 " \"property\": \"uTime\",\n"
1083 " \"value\": 10.0,\n"
1084 " \"alphaFunction\": \"LINEAR\",\n"
1085 " \"timePeriod\": {\n"
1087 " \"duration\": 10.0\n"
1097 Builder builder = Builder::New();
1098 builder.LoadFromString(json);
1100 builder.AddActors("stage", application.GetScene().GetRootLayer());
1102 // Render and notify
1103 application.SendNotification();
1104 application.Render();
1106 Actor actor = application.GetScene().GetRootLayer().FindChildByName("Image1");
1109 DALI_TEST_CHECK(actor);
1114 int UtcDaliBuilderLoadFromStringN(void)
1116 ToolkitTestApplication application;
1118 // JSON with a quit event when the actor is touched
1120 "asdfsadf dsf asdf asdf {"
1123 "\"type\": \"Actor\","
1124 "\"size\": [100,100,1],"
1125 "\"parentOrigin\": \"TOP_LEFT\","
1126 "\"anchorPoint\": \"TOP_LEFT\","
1128 "\"name\": \"touched\","
1129 "\"action\": \"quit\""
1133 Builder builder = Builder::New();
1135 bool assert1 = false;
1139 builder.LoadFromString(json);
1141 catch(Dali::DaliException& e)
1143 DALI_TEST_PRINT_ASSERT(e);
1144 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1148 DALI_TEST_CHECK(assert1);
1153 int UtcDaliBuilderAddActorsP(void)
1155 ToolkitTestApplication application;
1157 // JSON with a quit event when the actor is touched
1160 " \"arbitarysection\":\n"
1162 " \"type\": \"Actor\",\n"
1163 " \"name\": \"actor\",\n"
1164 " \"size\": [100,100,1],\n"
1165 " \"parentOrigin\": \"TOP_LEFT\",\n"
1166 " \"anchorPoint\": \"TOP_LEFT\",\n"
1168 " \"type\": \"Actor\",\n"
1169 " \"name\": \"subActor\",\n"
1170 " \"visible\": false\n"
1172 " \"signals\": [{\n"
1173 " \"name\": \"touched\",\n"
1174 " \"action\": \"hide\",\n"
1175 " \"actor\": \"actor\",\n"
1176 " \"childActor\": \"subActor\"\n"
1181 Builder builder = Builder::New();
1182 builder.LoadFromString(json);
1183 builder.AddActors("arbitarysection", application.GetScene().GetRootLayer());
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 Actor actor = application.GetScene().GetRootLayer().FindChildByName("subActor");
1190 DALI_TEST_CHECK(actor);
1192 DALI_TEST_CHECK(!actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE));
1197 int UtcDaliBuilderPathConstraintsP(void)
1199 ToolkitTestApplication application;
1201 // JSON with a quit event when the actor is touched
1206 " \"FB_WIDTH\": 200.0,\n"
1207 " \"FB_HEIGHT\": 200.0,\n"
1208 " \"FB_SIZE\": [200,200],\n"
1209 " \"FB_ASPECT_RATIO\": 1\n"
1213 " \"type\": \"ImageView\",\n"
1214 " \"name\": \"Image1\",\n"
1215 " \"size\": [200, 200, 0],\n"
1216 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1217 " \"effect\": \"Ripple2D\",\n"
1219 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1223 " \"name\": \"onScene\",\n"
1224 " \"action\": \"play\",\n"
1225 " \"animation\": \"pathAnimation\"\n"
1228 " \"name\": \"onScene\",\n"
1229 " \"action\": \"applyConstraint\",\n"
1230 " \"constrainer\": \"constrainer0\",\n"
1231 " \"properties\":\n"
1234 " \"source\": \"Image1\",\n"
1235 " \"sourceProperty\": \"positionX\",\n"
1236 " \"target\": \"Image1\",\n"
1237 " \"targetProperty\": \"colorRed\",\n"
1238 " \"range\": [-300,300]\n"
1243 " \"name\": \"onScene\",\n"
1244 " \"action\": \"applyConstraint\",\n"
1245 " \"constrainer\": \"constrainer1\",\n"
1246 " \"properties\":\n"
1249 " \"source\": \"Image1\",\n"
1250 " \"sourceProperty\": \"positionX\",\n"
1251 " \"target\": \"Image1\",\n"
1252 " \"targetProperty\": \"colorBlue\",\n"
1253 " \"range\": [-300,300]\n"
1258 " \"name\": \"offScene\",\n"
1259 " \"action\": \"removeConstraints\",\n"
1260 " \"constrainer\": \"constrainer0\",\n"
1261 " \"properties\":\n"
1264 " \"source\": \"Image1\",\n"
1265 " \"sourceProperty\": \"positionX\",\n"
1266 " \"target\": \"Image1\",\n"
1267 " \"targetProperty\": \"colorRed\",\n"
1268 " \"range\": [-300,300]\n"
1273 " \"name\": \"offScene\",\n"
1274 " \"action\": \"removeConstraints\",\n"
1275 " \"constrainer\": \"constrainer1\",\n"
1276 " \"properties\":\n"
1279 " \"source\": \"Image1\",\n"
1280 " \"sourceProperty\": \"positionX\",\n"
1281 " \"target\": \"Image1\",\n"
1282 " \"targetProperty\": \"colorBlue\",\n"
1283 " \"range\": [-300,300]\n"
1294 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1295 " \"curvature\":0.35\n"
1298 " \"constrainers\":\n"
1300 " \"constrainer0\":\n"
1302 " \"type\": \"PathConstrainer\",\n"
1303 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1304 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1306 " \"constrainer1\":\n"
1308 " \"type\": \"LinearConstrainer\",\n"
1309 " \"value\": [ 0, 0, 0 ]\n"
1312 " \"animations\": {\n"
1313 " \"pathAnimation\": {\n"
1314 " \"duration\": 3.0,\n"
1315 " \"properties\":\n"
1317 " \"actor\": \"Image1\",\n"
1318 " \"path\":\"path0\",\n"
1319 " \"forward\":[1,0,0],\n"
1320 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1321 " \"timePeriod\": {\n"
1323 " \"duration\": 3\n"
1327 " \"actor\": \"Image1\",\n"
1328 " \"property\": \"uTime\",\n"
1329 " \"value\": 10.0,\n"
1330 " \"alphaFunction\": \"LINEAR\",\n"
1331 " \"timePeriod\": {\n"
1333 " \"duration\": 10.0\n"
1335 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1338 " \"Animation_1\": {\n"
1340 " \"properties\": [\n"
1342 " \"actor\": \"Image1\",\n"
1343 " \"property\": \"uTime\",\n"
1344 " \"value\": 10.0,\n"
1345 " \"alphaFunction\": \"LINEAR\",\n"
1346 " \"timePeriod\": {\n"
1348 " \"duration\": 10.0\n"
1350 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1357 Builder builder = Builder::New();
1359 // frame buffer coverage
1360 builder.LoadFromString(json);
1362 // Render and notify
1363 application.SendNotification();
1364 application.Render();
1366 Dali::Path path = builder.GetPath("path0");
1367 DALI_TEST_CHECK(path);
1369 Dali::Path path2 = builder.GetPath("path0");
1370 DALI_TEST_CHECK(path2);
1371 DALI_TEST_CHECK(path == path2);
1373 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer("constrainer0");
1374 DALI_TEST_CHECK(constrainer0);
1376 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer("constrainer0");
1377 DALI_TEST_CHECK(constrainer0_2);
1378 DALI_TEST_CHECK(constrainer0 == constrainer0_2);
1380 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer("constrainer1");
1381 DALI_TEST_CHECK(constrainer1);
1383 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer("constrainer1");
1384 DALI_TEST_CHECK(constrainer1 == constrainer1_2);
1388 Actor actor = Actor::New();
1389 application.GetScene().Add(actor);
1390 builder.AddActors(actor);
1392 // Render and notify
1393 application.SendNotification();
1394 application.Render();
1396 actor.GetChildAt(0).Unparent();
1401 #define CHECK_MAP_ELEMENT(xMap, xKey, xType, xPropType, xExpected, xLocation) \
1403 Property::Value* value = xMap->Find(xKey); \
1404 DALI_TEST_EQUALS(value == NULL, false, xLocation); \
1407 DALI_TEST_EQUALS(value->GetType(), xPropType, xLocation); \
1409 value->Get(result); \
1410 DALI_TEST_EQUALS(result, xExpected, TEST_LOCATION); \
1411 std::ostringstream oss; \
1412 oss << "Animation element " << xKey << "= " << result << std::endl; \
1413 tet_printf(oss.str().c_str()); \
1417 tet_printf("Can't find map element " xKey "\n"); \
1421 int UtcDaliBuilderMapping01(void)
1423 ToolkitTestApplication application;
1429 " \"buttonPressFadeOut\":{\n"
1430 " \"alphaFunction\":\"EASE_OUT\",\n"
1431 " \"timePeriod\":{\n"
1433 " \"duration\":0.4\n"
1436 " \"buttonPressFadeIn\":{\n"
1437 " \"alphaFunction\":\"EASE_IN\",\n"
1438 " \"timePeriod\":{\n"
1440 " \"duration\":0.5\n"
1443 " \"transition:buttonPressed\":\n"
1446 " \"target\": \"unselectedBackgroundRenderer\",\n"
1447 " \"property\": \"opacity\",\n"
1449 " \"animator\":\"<buttonPressFadeOut>\"\n"
1452 " \"transition:buttonReleased\":\n"
1455 " \"target\": \"unselectedBackgroundRenderer\",\n"
1456 " \"property\": \"opacity\",\n"
1458 " \"animator\":\"<buttonPressFadeIn>\"\n"
1461 " \"target\": \"unselectedForegroundRenderer\",\n"
1462 " \"property\": \"scale\",\n"
1463 " \"value\": [ 1, 1, 1 ],\n"
1464 " \"animator\":\"<buttonPressFadeIn>\"\n"
1467 " \"target\": \"selectedBackgroundRenderer\",\n"
1468 " \"property\": \"opacity\",\n"
1470 " \"animator\": \"<buttonPressFadeOut>\"\n"
1473 " \"target\": \"selectedForegroundRenderer\",\n"
1474 " \"property\": \"scale\",\n"
1475 " \"value\": [ 0, 0, 0 ],\n"
1476 " \"animator\":\"<buttonPressFadeOut>\"\n"
1482 " \"testbutton\":\n"
1484 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1485 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1490 Builder builder = Builder::New();
1491 builder.LoadFromString(json);
1493 Test::TestButton testButton = Test::TestButton::New();
1494 application.GetScene().Add(testButton);
1496 // Render and notify
1497 application.SendNotification();
1498 application.Render();
1500 DALI_TEST_CHECK(builder.ApplyStyle("testbutton", testButton));
1502 // Now check that it has loaded the transition correctly:
1503 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1504 DALI_TEST_EQUALS(transition.GetType(), Property::ARRAY, TEST_LOCATION);
1505 Property::Array* array = transition.GetArray();
1507 DALI_TEST_EQUALS(array->Size(), 1, TEST_LOCATION);
1508 Property::Value element = array->GetElementAt(0);
1509 DALI_TEST_CHECK(element.GetType() == Property::MAP);
1510 Property::Map* map = element.GetMap();
1512 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1513 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1514 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1515 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1516 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1521 int UtcDaliBuilderMappingCycleCheck(void)
1523 ToolkitTestApplication application;
1529 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1530 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1531 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1533 " \"alphaFunction\":\"EASE_IN\",\n"
1534 " \"timePeriod\":{\n"
1535 " \"delay\":\"<cyclicKey3>\",\n"
1536 " \"duration\":0.6\n"
1539 " \"transition:buttonPressed\":\n"
1542 " \"target\": \"<cyclicKey1>\",\n"
1543 " \"property\": \"<cyclicKey2>\",\n"
1545 " \"animator\":\"<FadeOut>\"\n"
1551 " \"testbutton\":\n"
1553 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1554 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1555 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1556 " \"enabledTransition\":\"<unknownKey>\"\n"
1561 Builder builder = Builder::New();
1562 builder.LoadFromString(json);
1564 Test::TestButton testButton = Test::TestButton::New();
1565 application.GetScene().Add(testButton);
1567 // Render and notify
1568 application.SendNotification();
1569 application.Render();
1571 DALI_TEST_CHECK(builder.ApplyStyle("testbutton", testButton));
1573 // Now check that it has loaded the transition correctly:
1574 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1575 DALI_TEST_EQUALS(transition.GetType(), Property::ARRAY, TEST_LOCATION);
1576 Property::Array* array = transition.GetArray();
1578 DALI_TEST_EQUALS(array->Size(), 1, TEST_LOCATION);
1579 Property::Value element = array->GetElementAt(0);
1580 DALI_TEST_CHECK(element.GetType() == Property::MAP);
1581 Property::Map* map = element.GetMap();
1583 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1584 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1585 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1590 int UtcDaliBuilderTypeCasts(void)
1592 ToolkitTestApplication application;
1598 "\"type\": \"Layer\","
1599 "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1600 "\"position\": { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1601 "\"color\": { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1602 "\"sensitive\": { \"typeCast\":\"boolean\", \"value\":false },"
1603 "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1604 "\"colorMode\": { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1605 "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
1606 "\"padding\": { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
1610 Actor rootActor = Actor::New();
1611 application.GetScene().Add(rootActor);
1613 Builder builder = Builder::New();
1614 builder.LoadFromString(json);
1615 builder.AddActors(rootActor);
1617 application.SendNotification();
1618 application.Render();
1620 Actor createdActor = rootActor.GetChildAt(0);
1621 DALI_TEST_EQUALS(createdActor.GetProperty<Vector2>(Actor::Property::MAXIMUM_SIZE), Vector2(100.0f, 15.0f), TEST_LOCATION);
1622 DALI_TEST_EQUALS(createdActor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(100.0f, 10.0f, 1.0f), TEST_LOCATION);
1623 DALI_TEST_EQUALS(createdActor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Vector4(0.5f, 0.5f, 0.5f, 1.0f), TEST_LOCATION);
1624 DALI_TEST_EQUALS(createdActor.GetProperty<bool>(Actor::Property::SENSITIVE), false, TEST_LOCATION);
1625 DALI_TEST_EQUALS(createdActor.GetProperty<ColorMode>(Actor::Property::COLOR_MODE), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION);
1630 int UtcDaliBuilderBuilderControl(void)
1632 ToolkitTestApplication application;
1638 "\"type\": \"BuilderControl\","
1639 "\"integerProperty\": 10,"
1640 "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
1641 "\"matrixProperty\": [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
1642 "\"noneProperty\": 10"
1646 Actor rootActor = Actor::New();
1647 application.GetScene().Add(rootActor);
1649 Builder builder = Builder::New();
1650 builder.LoadFromString(json);
1651 builder.AddActors(rootActor);
1653 application.SendNotification();
1654 application.Render();
1656 DALI_TEST_EQUALS(BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION);
1661 int UtcDaliBuilderCustomControl(void)
1663 ToolkitTestApplication application;
1669 "\"type\": \"DummyControl\","
1670 "\"name\": \"I can haz custom Control\""
1674 Actor rootActor = Actor::New();
1675 application.GetScene().Add(rootActor);
1677 Builder builder = Builder::New();
1678 builder.LoadFromString(json);
1679 builder.AddActors(rootActor);
1681 application.SendNotification();
1682 application.Render();
1684 Actor customControl = rootActor.FindChildByName("I can haz custom Control");
1686 // Test that we have the correct type of custom control
1687 DummyControl dummyControl = DummyControl::DownCast(customControl);
1688 DALI_TEST_CHECK(dummyControl);
1691 DALI_TEST_CHECK(typeid(dummyControl.GetImplementation()) == typeid(DummyControlImpl));
1697 int UtcDaliBuilderActionsWithParams(void)
1699 ToolkitTestApplication application;
1701 // JSON with a quit event when the actor is touched
1707 " \"type\": \"ImageView\",\n"
1708 " \"name\": \"image\",\n"
1709 " \"size\": [100,100,1],\n"
1710 " \"signals\": [{\n"
1711 " \"name\": \"touched\",\n"
1712 " \"action\": \"show\",\n"
1713 " \"parameters\": {\n"
1714 " \"property1\" : 10,\n"
1715 " \"property2\" : [1,2],\n"
1716 " \"property3\" : [1,2,3],\n"
1717 " \"property4\" : [1,2,3,4]\n"
1724 Builder builder = Builder::New();
1725 builder.LoadFromString(json);
1726 builder.AddActors(application.GetScene().GetRootLayer());
1728 DALI_TEST_CHECK(true); // For Coverage
1733 int UtcDaliBuilderConfigurationP(void)
1735 ToolkitTestApplication application;
1737 // JSON with a quit event when the actor is touched
1742 " \"alwaysShowFocus\":true\n"
1746 Builder builder = Builder::New();
1747 builder.LoadFromString(json);
1749 Property::Map map = builder.GetConfigurations();
1751 Dali::Property::Value* pValue = map.Find("alwaysShowFocus");
1753 DALI_TEST_CHECK(pValue);
1755 bool value = pValue->Get<bool>();
1757 DALI_TEST_CHECK(value);
1762 int UtcDaliBase64EncodingP(void)
1764 std::vector<uint32_t> data = {0, 1, 2, 3, 4, 5, std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max()};
1766 Property::Value value;
1767 EncodeBase64PropertyData(value, data);
1769 std::cout << "Max uint32_t:" << std::numeric_limits<uint32_t>::max() << std::endl;
1770 std::cout << "Input data: ";
1771 std::ostream_iterator<uint32_t> out_it(std::cout, ", ");
1772 std::copy(data.begin(), data.end(), out_it);
1773 std::cout << std::endl;
1776 DALI_TEST_CHECK(value.Get(output));
1777 DALI_TEST_EQUALS(output, "AAAAAAEAAAACAAAAAwAAAAQAAAAFAAAAAAAAAP////8", TEST_LOCATION);
1779 std::cout << "Output data: " << output << std::endl;
1784 int UtcDaliBase64EncodingN(void)
1786 tet_infoline("Test encoding an empty vector returns empty string");
1787 std::vector<uint32_t> data;
1789 Property::Value value;
1790 EncodeBase64PropertyData(value, data);
1793 DALI_TEST_CHECK(value.Get(output));
1794 DALI_TEST_EQUALS(output.empty(), true, TEST_LOCATION);
1799 template<typename T>
1800 int b64l(std::vector<T>& data)
1802 auto lengthInBytes = 4 * data.size();
1803 return ceil(lengthInBytes * 1.33333f);
1806 int UtcDaliBase64EncodingP02(void)
1808 tet_infoline("Test encoding vectors of lengths m .. m+4 encode and decode back to the same length vectors");
1810 std::vector<uint32_t> testData;
1811 for(int i = 0; i < 8; ++i) // 8 chosen to stay within single string output
1813 testData.push_back(i);
1815 Property::Value value;
1816 EncodeBase64PropertyData(value, testData);
1819 DALI_TEST_CHECK(value.Get(output));
1820 DALI_TEST_EQUALS(output.empty(), false, TEST_LOCATION);
1821 DALI_TEST_EQUALS(output.length(), b64l(testData), TEST_LOCATION);
1823 std::vector<uint32_t> outData;
1824 DecodeBase64PropertyData(value, outData);
1825 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1826 DALI_TEST_EQUALS(std::equal(testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION);
1829 testData.push_back(12345);
1830 EncodeBase64PropertyData(value, testData);
1832 DALI_TEST_CHECK(value.Get(output));
1833 DALI_TEST_EQUALS(output.empty(), false, TEST_LOCATION);
1834 DALI_TEST_EQUALS(output.length(), b64l(testData), TEST_LOCATION);
1837 DecodeBase64PropertyData(value, outData);
1838 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1839 DALI_TEST_EQUALS(std::equal(testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION);
1842 testData.push_back(67890);
1843 EncodeBase64PropertyData(value, testData);
1845 DALI_TEST_CHECK(value.Get(output));
1846 DALI_TEST_EQUALS(output.empty(), false, TEST_LOCATION);
1847 DALI_TEST_EQUALS(output.length(), b64l(testData), TEST_LOCATION);
1850 DecodeBase64PropertyData(value, outData);
1851 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1852 DALI_TEST_EQUALS(std::equal(testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION);
1855 testData.push_back(-1);
1856 EncodeBase64PropertyData(value, testData);
1858 DALI_TEST_CHECK(value.Get(output));
1859 DALI_TEST_EQUALS(output.empty(), false, TEST_LOCATION);
1860 DALI_TEST_EQUALS(output.length(), b64l(testData), TEST_LOCATION);
1863 DecodeBase64PropertyData(value, outData);
1864 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1865 DALI_TEST_EQUALS(std::equal(testData.begin(), testData.end(), outData.begin()), true, TEST_LOCATION);
1870 int UtcDaliBase64EncodingP03(void)
1872 tet_infoline("Test encoding a vector of length 12 has output within single string");
1874 std::vector<uint32_t> testData;
1875 for(int i = 0; i < 12; ++i)
1877 testData.push_back(i);
1879 Property::Value value;
1880 EncodeBase64PropertyData(value, testData);
1883 DALI_TEST_CHECK(value.Get(output));
1884 DALI_TEST_EQUALS(output.empty(), false, TEST_LOCATION);
1885 DALI_TEST_EQUALS(output.length(), b64l(testData), TEST_LOCATION);
1887 std::vector<uint32_t> outData;
1888 DecodeBase64PropertyData(value, outData);
1889 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1894 int UtcDaliBase64EncodingP04(void)
1896 tet_infoline("Test encoding a vector of length 13 has output split over 2 strings");
1898 std::vector<uint32_t> testData;
1899 for(int i = 0; i < 13; ++i)
1901 testData.push_back(i);
1903 Property::Value value;
1904 EncodeBase64PropertyData(value, testData);
1906 auto array = value.GetArray();
1907 DALI_TEST_CHECK(array);
1909 DALI_TEST_EQUALS(array->Count(), 2, TEST_LOCATION);
1911 std::vector<uint32_t> outData;
1912 DecodeBase64PropertyData(value, outData);
1913 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1918 int UtcDaliBase64EncodingP05(void)
1920 tet_infoline("Test encoding a vector of length 24 has output split over 2 strings");
1922 std::vector<uint32_t> testData;
1923 for(int i = 0; i < 24; ++i)
1925 testData.push_back(i);
1927 Property::Value value;
1928 EncodeBase64PropertyData(value, testData);
1930 auto array = value.GetArray();
1931 DALI_TEST_CHECK(array);
1933 DALI_TEST_EQUALS(array->Count(), 2, TEST_LOCATION);
1935 std::vector<uint32_t> outData;
1936 DecodeBase64PropertyData(value, outData);
1937 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1942 int UtcDaliBase64EncodingP06(void)
1944 tet_infoline("Test encoding a vector of arbitrary length decodes OK.");
1946 std::vector<uint32_t> testData;
1947 for(int i = 0; i < 97; ++i)
1949 testData.push_back(i);
1951 Property::Value value;
1952 EncodeBase64PropertyData(value, testData);
1954 auto array = value.GetArray();
1955 DALI_TEST_CHECK(array);
1957 std::vector<uint32_t> outData;
1958 DecodeBase64PropertyData(value, outData);
1959 DALI_TEST_EQUALS(testData.size(), outData.size(), TEST_LOCATION);
1964 int UtcDaliBase64DecodingN01(void)
1966 tet_infoline("Test decoding empty string results in empty data");
1968 Property::Value value("");
1969 std::vector<uint32_t> outputData;
1970 DecodeBase64PropertyData(value, outputData);
1971 DALI_TEST_EQUALS(outputData.size(), 0, TEST_LOCATION);
1975 int UtcDaliBase64DecodingN02(void)
1977 tet_infoline("Test decoding array with non-string values results in empty data");
1979 Property::Array array;
1981 array[0] = "Stuff, things";
1983 Property::Value value(array);
1985 std::vector<uint32_t> outputData;
1986 DecodeBase64PropertyData(value, outputData);
1987 DALI_TEST_EQUALS(outputData.size(), 0, TEST_LOCATION);
1991 int UtcDaliBase64DecodingP01(void)
1993 tet_infoline("Test decoding string of known data gives expected result");
1995 std::string testInput("//////7+/v4DAgEA");
1996 std::vector<uint32_t> expectedResults = {0xffffffff, 0xfefefefe, 0x00010203};
1998 std::vector<uint32_t> outputData;
1999 DecodeBase64PropertyData(Property::Value(testInput), outputData);
2001 DALI_TEST_EQUALS(std::equal(expectedResults.begin(), expectedResults.end(), outputData.begin()), true, TEST_LOCATION);