2 * Copyright (c) 2014-2016 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/devel-api/builder/builder.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <test-button.h>
25 #include <test-animation-data.h>
27 #define STRINGIFY(A)#A
30 using namespace Toolkit;
35 std::string ReplaceQuotes(const std::string &in_s)
38 // wrong as no embedded quote but had regex link problems
39 std::replace(s.begin(), s.end(), '\'', '"');
45 BuilderFunctor( bool& called ) : mCalled( called )
62 void builder_startup(void)
64 test_return_value = TET_UNDEF;
67 void builder_cleanup(void)
69 test_return_value = TET_PASS;
72 int UtcDaliBuilderQuitSignal(void)
74 ToolkitTestApplication application;
76 // JSON with a quit event when the actor is touched
81 "\"type\": \"Actor\","
82 "\"size\": [100,100,1],"
83 "\"parentOrigin\": \"TOP_LEFT\","
84 "\"anchorPoint\": \"TOP_LEFT\","
86 "\"name\": \"touched\","
87 "\"action\": \"quit\""
92 Builder builder = Builder::New();
93 builder.LoadFromString( json );
94 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
96 // Connect to builder's quit signal
97 bool functorCalled( false );
98 builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
101 application.SendNotification();
102 application.Render();
104 // Emit touch event and check that our quit method is called
105 Integration::TouchEvent touchEvent;
106 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
107 application.ProcessEvent( touchEvent );
108 DALI_TEST_CHECK( functorCalled );
114 int UtcDaliBuilderAnimationP(void)
116 ToolkitTestApplication application;
118 // JSON with a quit event when the actor is touched
123 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
129 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
130 " \"curvature\":0.35"
136 " \"endAction\": \"BAKE\","
137 " \"disconnectAction\": \"BAKE\","
140 " \"actor\": \"greeting\","
141 " \"property\": \"position\","
142 " \"value\": [300, 300, -1000],"
143 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
144 " \"relative\": true,"
151 " \"actor\": \"greeting\","
152 " \"property\": \"visible\","
153 " \"alphaFunction\": \"LINEAR\","
157 " \"actor\": \"greeting\","
158 " \"property\": \"sizeWidth\","
159 " \"alphaFunction\": \"REVERSE\","
163 " \"actor\": \"greeting\","
164 " \"property\": \"orientation\","
165 " \"alphaFunction\": \"EASE_IN\","
166 " \"value\": [10.0,20.0,30.0]"
169 " \"actor\": \"greeting\","
170 " \"property\": \"orientation\","
171 " \"alphaFunction\": \"EASE_OUT\","
172 " \"value\": [0.0, 0.0, 0.0, 1.0]"
175 " \"actor\": \"greeting\","
176 " \"property\": \"orientation\","
177 " \"alphaFunction\": \"EASE_IN_OUT\","
178 " \"value\": [0.0, 0.0, 0.0, 1.0]"
181 " \"actor\": \"greeting\","
182 " \"property\": \"orientation\","
183 " \"alphaFunction\": \"EASE_IN_SINE\","
184 " \"value\": [0.0, 0.0, 0.0, 1.0]"
187 " \"actor\": \"greeting\","
188 " \"property\": \"orientation\","
189 " \"alphaFunction\": \"EASE_OUT_SINE\","
190 " \"value\": [0.0, 0.0, 0.0, 1.0]"
193 " \"actor\": \"greeting\","
194 " \"property\": \"orientation\","
195 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
196 " \"value\": [0.0, 0.0, 0.0, 1.0]"
199 " \"actor\": \"greeting\","
200 " \"property\": \"orientation\","
201 " \"alphaFunction\": \"BOUNCE\","
202 " \"value\": [0.0, 0.0, 0.0, 1.0]"
205 " \"actor\": \"greeting\","
206 " \"property\": \"orientation\","
207 " \"alphaFunction\": \"SIN\","
208 " \"value\": [0.0, 0.0, 0.0, 1.0]"
211 " \"actor\": \"greeting\","
212 " \"property\": \"orientation\","
213 " \"alphaFunction\": \"EASE_OUT_BACK\","
214 " \"value\": [0.0, 0.0, 0.0, 1.0]"
218 " \"pathAnimation\": {"
219 " \"duration\": 3.0,"
220 " \"endAction\": \"DISCARD\","
221 " \"disconnectAction\": \"BAKE_FINAL\","
222 " \"properties\": [{"
223 " \"actor\": \"greeting\","
224 " \"path\":\"path0\","
225 " \"forward\":[1,0,0],"
226 " \"alphaFunction\": \"EASE_IN_OUT\","
235 " \"name\": \"greeting\","
236 " \"type\": \"TextLabel\","
237 " \"text\": \"Touch me\","
238 " \"styles\": [\"basicText\"],"
239 " \"position\": [0, -120, 0],"
240 " \"size\": [200, 200, 1],"
241 " \"orientation\": [0, 0, 30],"
243 " \"name\": \"touched\","
244 " \"action\": \"play\","
245 " \"animation\": \"animate\""
250 Builder builder = Builder::New();
251 builder.LoadFromString( json );
252 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
254 Animation anim = builder.CreateAnimation("animate");
256 DALI_TEST_CHECK( anim );
259 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
260 anim = builder.CreateAnimation("animate", map);
262 DALI_TEST_CHECK( anim );
264 anim = builder.CreateAnimation("pathAnimation");
266 DALI_TEST_CHECK( anim );
269 // Emit touch event and check that our quit method is called
270 Integration::TouchEvent touchEvent;
271 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
272 application.ProcessEvent( touchEvent );
275 application.SendNotification();
276 application.Render();
282 int UtcDaliBuilderAnimationN(void)
284 ToolkitTestApplication application;
286 // JSON with a quit event when the actor is touched
291 " \"TEXT\": \"Touch Me\","
292 " \"NAME\": \"greeting\" "
298 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
299 " \"curvature\":0.35"
305 " \"endAction\": \"BAKE\","
306 " \"disconnectAction\": \"BAKE\","
309 " \"actor\": \"{NAME}\","
310 " \"property\": \"positioninvalid\","
311 " \"value\": [300, 300, -1000],"
312 " \"alphaFunction\": \"EASE_IN_OUT\","
313 " \"relative\": true,"
323 " \"endAction\": \"BAKE\","
324 " \"disconnectAction\": \"BAKE\","
327 " \"actor\": \"{NAME}\","
328 " \"property\": \"positioninvalid\","
329 " \"value\": [300, 300, -1000],"
330 " \"alphaFunction\": \"EGGS_OVER_EASY\","
331 " \"relative\": true,"
339 " \"pathAnimation\": {"
340 " \"duration\": 3.0,"
341 " \"endAction\": \"DISCARD\","
342 " \"disconnectAction\": \"BAKE_FINAL\","
343 " \"properties\": [{"
344 " \"actor\": \"greeting\","
345 " \"path\":\"pathDoesntExist\","
346 " \"forward\":[1,0,0],"
347 " \"alphaFunction\": \"EASE_IN_OUT\","
356 " \"name\": \"greeting\","
357 " \"type\": \"TextLabel\","
358 " \"text\": \"Touch me\","
359 " \"styles\": [\"basicText\"],"
360 " \"position\": [0, -120, 0],"
361 " \"size\": [200, 200, 1],"
362 " \"orientation\": [0, 0, 30],"
364 " \"name\": \"touched\","
365 " \"action\": \"play\","
366 " \"animation\": \"animate\""
370 " \"name\": \"greeting2\","
371 " \"type\": \"TextLabel\","
372 " \"text\": \"Touch me\""
377 Builder builder = Builder::New();
378 builder.LoadFromString( json );
379 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
381 Animation anim = builder.CreateAnimation("animate");
383 // log warning line coverage
384 anim = builder.CreateAnimation("pathAnimation");
385 DALI_TEST_CHECK(anim);
387 anim = builder.CreateAnimation("animate");
388 DALI_TEST_CHECK(anim);
390 anim = builder.CreateAnimation("animate2");
391 DALI_TEST_CHECK(anim);
393 // create referencing a different actor aka animation templates
395 map["NAME"] = "greeting2";
396 anim = builder.CreateAnimation("animate2", map);
397 DALI_TEST_CHECK(anim);
399 // alternative actor to use for FindChildByName
400 anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
401 DALI_TEST_CHECK(anim);
403 // alternative actor to use for FindChildByName
404 anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
405 DALI_TEST_CHECK(anim);
412 int UtcDaliBuilderConstantsP(void)
414 ToolkitTestApplication application;
416 // JSON with a quit event when the actor is touched
421 " \"IMAGE_PATH\": \"apath\","
423 " \"ANCHOR\": \"TOP_LEFT\","
424 " \"PADDING\": [1,2,3,4]"
428 " \"type\": \"ImageView\","
429 " \"name\": \"{NAME}\","
430 " \"size\": [100,100,1],"
431 " \"parentOrigin\": \"TOP_LEFT\","
432 " \"anchorPoint\": \"{ANCHOR}\","
433 " \"padding\": \"{PADDING}\","
434 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
435 " \"sizeWidth\": \"{WIDTH}\","
437 " \"name\": \"touched\","
438 " \"action\": \"quit\""
444 Builder builder = Builder::New();
445 builder.LoadFromString( json );
447 builder.AddConstant( "NAME", "image" );
449 Property::Map map = builder.GetConstants();
451 Dali::Property::Value* pValue = map.Find( "NAME" );
453 DALI_TEST_CHECK( pValue );
455 pValue = map.Find( "IMAGE_PATH" );
457 DALI_TEST_CHECK( pValue );
459 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
461 DALI_TEST_CHECK( value.GetType() != Property::NONE );
463 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
464 DALI_TEST_CHECK( builder );
466 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
467 DALI_TEST_CHECK( actor );
472 int UtcDaliBuilderTemplatesAndStylesP(void)
474 ToolkitTestApplication application;
476 // JSON with a quit event when the actor is touched
481 " \"SIZE\": [10,20,30]"
485 " \"imageStyle\": \n"
487 " \"color\": [1,0,0,1],\n"
489 " \"childImage\": {\n"
490 " \"color\": [0,1,0,1]\n"
497 " \"imageTree\": { \n"
498 " \"type\": \"ImageView\",\n"
499 " \"styles\": [\"imageStyle\"],\n"
500 " \"name\": \"image\",\n"
501 " \"size\": \"{SIZE}\",\n"
503 " \"name\": \"touched\",\n"
504 " \"action\": \"quit\"\n"
508 " \"type\":\"ImageView\",\n"
509 " \"name\":\"childImage\" \n"
516 " \"type\": \"imageTree\","
517 " \"size\": [100,100,1]"
522 std::string stylejson(
524 " \"color\": [1,0,0,1],\n"
526 " \"childImage\": {\n"
527 " \"color\": [0,1,0,1]\n"
533 std::string templatejson(
535 " \"type\": \"ImageView\",\n"
536 " \"styles\": [\"imageStyle\"],\n"
537 " \"name\": \"image\",\n"
538 " \"size\": \"{SIZE}\",\n"
540 " \"name\": \"touched\",\n"
541 " \"action\": \"quit\"\n"
545 " \"type\":\"ImageView\",\n"
546 " \"name\":\"childImage\" \n"
552 Builder builder = Builder::New();
553 builder.LoadFromString( json );
555 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
556 DALI_TEST_CHECK( actor );
558 Dali::Property::Map map;
559 map["SIZE"] = Vector3(100,100,1);
560 actor = ImageView::DownCast( builder.Create( "imageTree", map ) );
561 DALI_TEST_CHECK( actor );
563 // create from json snippet
564 actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
565 DALI_TEST_CHECK( actor );
568 // NB: already applied in create
569 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
571 // apply from json snippet
572 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
577 int UtcDaliBuilderRenderTasksP(void)
579 ToolkitTestApplication application;
581 // JSON with a quit event when the actor is touched
587 " \"sourceActor\": \"image\",\n"
588 " \"cameraActor\": \"camera\" \n"
594 " \"type\": \"CameraActor\",\n"
595 " \"name\": \"image\"\n"
598 " \"type\": \"ImageView\",\n"
599 " \"name\": \"image\",\n"
600 " \"size\": [100,100,1],\n"
602 " \"name\": \"touched\",\n"
603 " \"action\": \"quit\"\n"
607 " \"type\":\"ImageView\",\n"
608 " \"name\":\"childImage\" \n"
616 Builder builder = Builder::New();
617 builder.LoadFromString( json );
619 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
622 builder.CreateRenderTask( "task0" );
624 DALI_TEST_CHECK( count <
625 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
630 int UtcDaliBuilderChildActionP(void)
632 ToolkitTestApplication application;
634 // JSON with a quit event when the actor is touched
639 " \"type\": \"Actor\",\n"
640 " \"name\": \"actor\",\n"
641 " \"size\": [100,100,1],\n"
642 " \"parentOrigin\": \"TOP_LEFT\",\n"
643 " \"anchorPoint\": \"TOP_LEFT\",\n"
645 " \"type\": \"Actor\",\n"
646 " \"name\": \"subActor\"\n"
649 " \"name\": \"touched\",\n"
650 " \"action\": \"hide\",\n"
651 " \"actor\": \"actor\",\n"
652 " \"childActor\": \"subActor\"\n"
658 Builder builder = Builder::New();
659 builder.LoadFromString( json );
660 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
663 application.SendNotification();
664 application.Render();
666 // Emit touch event and check that our quit method is called
667 Integration::TouchEvent touchEvent;
668 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
669 application.ProcessEvent( touchEvent );
672 application.SendNotification();
673 application.Render();
675 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
676 DALI_TEST_CHECK( actor );
678 DALI_TEST_CHECK( !actor.IsVisible() );
683 int UtcDaliBuilderSetPropertyActionP(void)
685 ToolkitTestApplication application;
687 // JSON with a quit event when the actor is touched
692 " \"type\": \"Actor\",\n"
693 " \"name\": \"actor\",\n"
694 " \"size\": [100,100,1],\n"
695 " \"parentOrigin\": \"TOP_LEFT\",\n"
696 " \"anchorPoint\": \"TOP_LEFT\",\n"
698 " \"type\": \"Actor\",\n"
699 " \"name\": \"subActor\"\n"
702 " \"name\": \"touched\",\n"
703 " \"action\": \"set\",\n"
704 " \"actor\": \"subActor\",\n"
705 " \"property\": \"visible\",\n"
706 " \"value\": false\n"
712 Builder builder = Builder::New();
713 builder.LoadFromString( json );
714 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
717 application.SendNotification();
718 application.Render();
720 // Emit touch event and check that our quit method is called
721 Integration::TouchEvent touchEvent;
722 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
723 application.ProcessEvent( touchEvent );
726 application.SendNotification();
727 application.Render();
729 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
730 DALI_TEST_CHECK( actor );
732 DALI_TEST_CHECK( !actor.IsVisible() );
737 int UtcDaliBuilderGenericActionP(void)
739 ToolkitTestApplication application;
741 // JSON with a quit event when the actor is touched
746 " \"type\": \"Actor\",\n"
747 " \"name\": \"actor\",\n"
748 " \"size\": [100,100,1],\n"
749 " \"parentOrigin\": \"TOP_LEFT\",\n"
750 " \"anchorPoint\": \"TOP_LEFT\",\n"
752 " \"type\": \"Actor\",\n"
753 " \"name\": \"subActor\"\n"
756 " \"name\": \"touched\",\n"
757 " \"action\": \"hide\"\n"
763 Builder builder = Builder::New();
764 builder.LoadFromString( json );
765 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
768 application.SendNotification();
769 application.Render();
771 // Emit touch event and check that our quit method is called
772 Integration::TouchEvent touchEvent;
773 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
774 application.ProcessEvent( touchEvent );
777 application.SendNotification();
778 application.Render();
780 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
781 DALI_TEST_CHECK( actor );
783 DALI_TEST_CHECK( !actor.IsVisible() );
788 int UtcDaliBuilderPropertyNotificationP(void)
790 ToolkitTestApplication application;
792 // JSON with a quit event when the actor is touched
797 " \"type\": \"Actor\",\n"
798 " \"name\": \"actor\",\n"
799 " \"size\": [100,100,1],\n"
800 " \"parentOrigin\": \"TOP_LEFT\",\n"
801 " \"anchorPoint\": \"TOP_LEFT\",\n"
803 " \"type\": \"Actor\",\n"
804 " \"name\": \"subActor\"\n"
807 " \"name\": \"touched\",\n"
808 " \"action\": \"hide\"\n"
810 " \"notifications\": [{\n"
811 " \"property\": \"visible\",\n"
812 " \"condition\": \"False\",\n"
813 " \"action\": \"show\"\n"
819 Builder builder = Builder::New();
820 builder.LoadFromString( json );
821 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
824 application.SendNotification();
825 application.Render();
827 // Emit touch event and check that our quit method is called
828 Integration::TouchEvent touchEvent;
829 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
830 application.ProcessEvent( touchEvent );
833 application.SendNotification();
834 application.Render();
837 application.SendNotification();
838 application.Render();
840 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
841 DALI_TEST_CHECK( actor );
843 DALI_TEST_CHECK( actor.IsVisible() );
848 int UtcDaliBuilderCustomPropertyP(void)
850 ToolkitTestApplication application;
852 // JSON with a quit event when the actor is touched
857 " \"imageTree\": { \n"
858 " \"type\": \"ImageView\",\n"
859 " \"name\": \"image\",\n"
860 " \"size\": [100,100,1],\n"
862 " \"name\": \"touched\",\n"
863 " \"action\": \"quit\"\n"
865 " \"properties\": {\n"
866 " \"newproperty\": true\n"
868 " \"animatableProperties\": {\n"
869 " \"newAnimatableproperty\": 3\n"
873 " \"type\":\"ImageView\",\n"
874 " \"name\":\"childImage\" \n"
882 Builder builder = Builder::New();
883 builder.LoadFromString( json );
885 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
886 DALI_TEST_CHECK( actor );
888 // NB: already applied in create
889 Property::Index index = actor.GetPropertyIndex("newproperty");
890 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
891 Property::Value value = actor.GetProperty(index);
892 DALI_TEST_CHECK( value.Get<bool>() == true );
894 index = actor.GetPropertyIndex("newAnimatableproperty");
895 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
896 value = actor.GetProperty(index);
897 DALI_TEST_CHECK( value.Get<int>() == 3 );
902 int UtcDaliBuilderCustomShaderP(void)
904 ToolkitTestApplication application;
906 // JSON with a quit event when the actor is touched
911 " \"type\": \"ImageView\",\n"
912 " \"name\": \"Image1\",\n"
914 " 0.40461349487305,\n"
918 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
919 " \"size\": [200, 200, 0],\n"
920 " \"effect\": \"Ripple2D\",\n"
922 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
923 " \"desiredWidth\": 200,\n"
924 " \"desiredHeight\": 80,\n"
926 " \"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"
929 " \"customAnimatableProperties\": {\n"
930 " \"uAmplitude\": 0.02,\n"
935 " \"name\": \"onStage\",\n"
936 " \"action\": \"play\",\n"
937 " \"animation\": \"Animation_1\"\n"
942 " \"animations\": {\n"
943 " \"Animation_1\": {\n"
945 " \"properties\": [\n"
947 " \"actor\": \"Image1\",\n"
948 " \"property\": \"uTime\",\n"
949 " \"value\": 10.0,\n"
950 " \"alphaFunction\": \"LINEAR\",\n"
951 " \"timePeriod\": {\n"
953 " \"duration\": 10.0\n"
963 Builder builder = Builder::New();
964 builder.LoadFromString( json );
966 builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
969 application.SendNotification();
970 application.Render();
972 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
975 DALI_TEST_CHECK( actor );
981 int UtcDaliBuilderLoadFromStringN(void)
983 ToolkitTestApplication application;
985 // JSON with a quit event when the actor is touched
987 "asdfsadf dsf asdf asdf {"
990 "\"type\": \"Actor\","
991 "\"size\": [100,100,1],"
992 "\"parentOrigin\": \"TOP_LEFT\","
993 "\"anchorPoint\": \"TOP_LEFT\","
995 "\"name\": \"touched\","
996 "\"action\": \"quit\""
1001 Builder builder = Builder::New();
1003 bool assert1 = false;
1007 builder.LoadFromString( json );
1009 catch( Dali::DaliException& e )
1011 DALI_TEST_PRINT_ASSERT( e );
1012 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1016 DALI_TEST_CHECK( assert1 );
1022 int UtcDaliBuilderAddActorsP(void)
1024 ToolkitTestApplication application;
1026 // JSON with a quit event when the actor is touched
1029 " \"arbitarysection\":\n"
1031 " \"type\": \"Actor\",\n"
1032 " \"name\": \"actor\",\n"
1033 " \"size\": [100,100,1],\n"
1034 " \"parentOrigin\": \"TOP_LEFT\",\n"
1035 " \"anchorPoint\": \"TOP_LEFT\",\n"
1037 " \"type\": \"Actor\",\n"
1038 " \"name\": \"subActor\",\n"
1039 " \"visible\": false\n"
1041 " \"signals\": [{\n"
1042 " \"name\": \"touched\",\n"
1043 " \"action\": \"hide\",\n"
1044 " \"actor\": \"actor\",\n"
1045 " \"childActor\": \"subActor\"\n"
1051 Builder builder = Builder::New();
1052 builder.LoadFromString( json );
1053 builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1055 // Render and notify
1056 application.SendNotification();
1057 application.Render();
1059 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1060 DALI_TEST_CHECK( actor );
1062 DALI_TEST_CHECK( !actor.IsVisible() );
1067 int UtcDaliBuilderFrameBufferP(void)
1069 ToolkitTestApplication application;
1071 // JSON with a quit event when the actor is touched
1076 " \"FB_WIDTH\": 200.0,\n"
1077 " \"FB_HEIGHT\": 200.0,\n"
1078 " \"FB_SIZE\": [200,200],\n"
1079 " \"FB_ASPECT_RATIO\": 1\n"
1083 " \"type\": \"ImageView\",\n"
1084 " \"name\": \"fbOnStage\",\n"
1085 " \"position\": [\n"
1086 " 0.40461349487305,\n"
1090 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1091 " \"size\": [300, 300, 0],\n"
1092 " \"image\": \"fb0\",\n"
1093 " \"clearColor\": [1,0,0,1]\n"
1096 " \"type\": \"ImageView\",\n"
1097 " \"name\": \"Image1\",\n"
1098 " \"size\": [200, 200, 0],\n"
1099 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1100 " \"effect\": \"Ripple2D\",\n"
1102 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1106 " \"name\": \"onStage\",\n"
1107 " \"action\": \"play\",\n"
1108 " \"animation\": \"Animation_1\"\n"
1113 " \"type\":\"CameraActor\",\n"
1114 " \"name\":\"fbCam\",\n"
1115 " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1116 " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1117 " \"fieldOfView\": 0.785,\n"
1118 " \"invertYAxis\": true\n"
1121 " \"frameBufferImages\":\n"
1125 " \"type\": \"FrameBufferImage\",\n"
1126 " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1127 " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1130 " \"renderTasks\":\n"
1135 " \"sourceActor\": \"fbOnStage\"\n"
1138 " \"sourceActor\": \"Image1\",\n"
1139 " \"targetFrameBuffer\": \"fb0\",\n"
1140 " \"viewportSize\":\"{FB_SIZE}\",\n"
1141 " \"cameraActor\":\"fbCam\"\n"
1146 " \"animations\": {\n"
1147 " \"Animation_1\": {\n"
1149 " \"properties\": [\n"
1151 " \"actor\": \"Image1\",\n"
1152 " \"property\": \"uTime\",\n"
1153 " \"value\": 10.0,\n"
1154 " \"alphaFunction\": \"LINEAR\",\n"
1155 " \"timePeriod\": {\n"
1157 " \"duration\": 10.0\n"
1159 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1164 " \"shaderEffects\": {\n"
1165 " \"Ripple2D\": {\n"
1167 " \"vertexPrefix\": \"\",\n"
1168 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1169 " \"fragmentPrefix\": \"\",\n"
1170 " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1171 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1173 " \"geometryHints\": \"HINT_NONE\",\n"
1174 " \"gridDensity\": 0,\n"
1175 " \"loop\": true,\n"
1176 " \"uAmplitude\": 0.02,\n"
1182 Builder builder = Builder::New();
1184 // frame buffer coverage
1185 builder.LoadFromString( json );
1187 // Render and notify
1188 application.SendNotification();
1189 application.Render();
1191 Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1192 DALI_TEST_CHECK( frameBuffer );
1194 Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1195 DALI_TEST_CHECK( frameBuffer2 );
1196 DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1198 DALI_TEST_CHECK( true );
1203 int UtcDaliBuilderPathConstraintsP(void)
1205 ToolkitTestApplication application;
1207 // JSON with a quit event when the actor is touched
1212 " \"FB_WIDTH\": 200.0,\n"
1213 " \"FB_HEIGHT\": 200.0,\n"
1214 " \"FB_SIZE\": [200,200],\n"
1215 " \"FB_ASPECT_RATIO\": 1\n"
1219 " \"type\": \"ImageView\",\n"
1220 " \"name\": \"Image1\",\n"
1221 " \"size\": [200, 200, 0],\n"
1222 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1223 " \"effect\": \"Ripple2D\",\n"
1225 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1229 " \"name\": \"onStage\",\n"
1230 " \"action\": \"play\",\n"
1231 " \"animation\": \"pathAnimation\"\n"
1234 " \"name\": \"onStage\",\n"
1235 " \"action\": \"applyConstraint\",\n"
1236 " \"constrainer\": \"constrainer0\",\n"
1237 " \"properties\":\n"
1240 " \"source\": \"Image1\",\n"
1241 " \"sourceProperty\": \"positionX\",\n"
1242 " \"target\": \"Image1\",\n"
1243 " \"targetProperty\": \"colorRed\",\n"
1244 " \"range\": [-300,300]\n"
1249 " \"name\": \"onStage\",\n"
1250 " \"action\": \"applyConstraint\",\n"
1251 " \"constrainer\": \"constrainer1\",\n"
1252 " \"properties\":\n"
1255 " \"source\": \"Image1\",\n"
1256 " \"sourceProperty\": \"positionX\",\n"
1257 " \"target\": \"Image1\",\n"
1258 " \"targetProperty\": \"colorBlue\",\n"
1259 " \"range\": [-300,300]\n"
1270 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1271 " \"curvature\":0.35\n"
1274 " \"constrainers\":\n"
1276 " \"constrainer0\":\n"
1278 " \"type\": \"PathConstrainer\",\n"
1279 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1280 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1282 " \"constrainer1\":\n"
1284 " \"type\": \"LinearConstrainer\",\n"
1285 " \"value\": [ 0, 0, 0 ]\n"
1288 " \"animations\": {\n"
1289 " \"pathAnimation\": {\n"
1290 " \"duration\": 3.0,\n"
1291 " \"properties\":\n"
1293 " \"actor\": \"Image1\",\n"
1294 " \"path\":\"path0\",\n"
1295 " \"forward\":[1,0,0],\n"
1296 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1297 " \"timePeriod\": {\n"
1299 " \"duration\": 3\n"
1303 " \"actor\": \"Image1\",\n"
1304 " \"property\": \"uTime\",\n"
1305 " \"value\": 10.0,\n"
1306 " \"alphaFunction\": \"LINEAR\",\n"
1307 " \"timePeriod\": {\n"
1309 " \"duration\": 10.0\n"
1311 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1314 " \"Animation_1\": {\n"
1316 " \"properties\": [\n"
1318 " \"actor\": \"Image1\",\n"
1319 " \"property\": \"uTime\",\n"
1320 " \"value\": 10.0,\n"
1321 " \"alphaFunction\": \"LINEAR\",\n"
1322 " \"timePeriod\": {\n"
1324 " \"duration\": 10.0\n"
1326 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1331 " \"shaderEffects\": {\n"
1332 " \"Ripple2D\": {\n"
1334 " \"vertexPrefix\": \"\",\n"
1335 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1336 " \"fragmentPrefix\": \"\",\n"
1337 " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1338 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1340 " \"geometryHints\": \"HINT_NONE\",\n"
1341 " \"gridDensity\": 0,\n"
1342 " \"loop\": true,\n"
1343 " \"uAmplitude\": 0.02,\n"
1349 Builder builder = Builder::New();
1351 // frame buffer coverage
1352 builder.LoadFromString( json );
1354 // Render and notify
1355 application.SendNotification();
1356 application.Render();
1358 Dali::Path path = builder.GetPath( "path0" );
1359 DALI_TEST_CHECK( path );
1361 Dali::Path path2 = builder.GetPath( "path0" );
1362 DALI_TEST_CHECK( path2 );
1363 DALI_TEST_CHECK( path == path2 );
1365 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1366 DALI_TEST_CHECK( constrainer0 );
1368 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1369 DALI_TEST_CHECK( constrainer0_2 );
1370 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1372 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1373 DALI_TEST_CHECK( constrainer1 );
1375 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1376 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1381 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1383 Property::Value* value = xMap->Find( xKey ); \
1384 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1385 if( value != NULL ) \
1387 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1389 value->Get(result); \
1390 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1391 std::ostringstream oss; \
1392 oss << "Animation element " << xKey << "= " << result << std::endl; \
1393 tet_printf( oss.str().c_str() ); \
1397 tet_printf("Can't find map element " xKey "\n"); \
1402 int UtcDaliBuilderMapping01(void)
1404 ToolkitTestApplication application;
1410 " \"buttonPressFadeOut\":{\n"
1411 " \"alphaFunction\":\"EASE_OUT\",\n"
1412 " \"timePeriod\":{\n"
1414 " \"duration\":0.4\n"
1417 " \"buttonPressFadeIn\":{\n"
1418 " \"alphaFunction\":\"EASE_IN\",\n"
1419 " \"timePeriod\":{\n"
1421 " \"duration\":0.5\n"
1424 " \"transition:buttonPressed\":\n"
1427 " \"target\": \"unselectedBackgroundRenderer\",\n"
1428 " \"property\": \"opacity\",\n"
1430 " \"animator\":\"<buttonPressFadeOut>\"\n"
1433 " \"transition:buttonReleased\":\n"
1436 " \"target\": \"unselectedBackgroundRenderer\",\n"
1437 " \"property\": \"opacity\",\n"
1439 " \"animator\":\"<buttonPressFadeIn>\"\n"
1442 " \"target\": \"unselectedForegroundRenderer\",\n"
1443 " \"property\": \"scale\",\n"
1444 " \"value\": [ 1, 1, 1 ],\n"
1445 " \"animator\":\"<buttonPressFadeIn>\"\n"
1448 " \"target\": \"selectedBackgroundRenderer\",\n"
1449 " \"property\": \"opacity\",\n"
1451 " \"animator\": \"<buttonPressFadeOut>\"\n"
1454 " \"target\": \"selectedForegroundRenderer\",\n"
1455 " \"property\": \"scale\",\n"
1456 " \"value\": [ 0, 0, 0 ],\n"
1457 " \"animator\":\"<buttonPressFadeOut>\"\n"
1463 " \"testbutton\":\n"
1465 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1466 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1471 Builder builder = Builder::New();
1472 builder.LoadFromString( json );
1474 Test::TestButton testButton = Test::TestButton::New();
1475 Stage::GetCurrent().Add( testButton );
1477 // Render and notify
1478 application.SendNotification();
1479 application.Render();
1481 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1483 // Now check that it has loaded the transition correctly:
1484 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1485 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1486 Property::Array* array = transition.GetArray();
1488 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1489 Property::Value element = array->GetElementAt(0);
1490 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1491 Property::Map* map = element.GetMap();
1493 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1494 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1495 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1496 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1497 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1503 int UtcDaliBuilderMappingCycleCheck(void)
1505 ToolkitTestApplication application;
1511 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1512 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1513 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1515 " \"alphaFunction\":\"EASE_IN\",\n"
1516 " \"timePeriod\":{\n"
1517 " \"delay\":\"<cyclicKey3>\",\n"
1518 " \"duration\":0.6\n"
1521 " \"transition:buttonPressed\":\n"
1524 " \"target\": \"<cyclicKey1>\",\n"
1525 " \"property\": \"<cyclicKey2>\",\n"
1527 " \"animator\":\"<FadeOut>\"\n"
1533 " \"testbutton\":\n"
1535 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1536 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1537 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1538 " \"enabledTransition\":\"<unknownKey>\"\n"
1543 Builder builder = Builder::New();
1544 builder.LoadFromString( json );
1546 Test::TestButton testButton = Test::TestButton::New();
1547 Stage::GetCurrent().Add( testButton );
1549 // Render and notify
1550 application.SendNotification();
1551 application.Render();
1553 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1555 // Now check that it has loaded the transition correctly:
1556 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1557 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1558 Property::Array* array = transition.GetArray();
1560 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1561 Property::Value element = array->GetElementAt(0);
1562 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1563 Property::Map* map = element.GetMap();
1565 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1566 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1567 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);