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\": \"Layer\","
82 "\"size\": [100,100,1],"
83 "\"parentOrigin\": \"TOP_LEFT\","
84 "\"anchorPoint\": \"TOP_LEFT\","
85 "\"maximumSize\": [100,100],"
86 "\"orientation\": [10,10,10,10],"
87 "\"clippingBox\": [10,10,10,10],"
89 "\"name\": \"touch\","
90 "\"action\": \"quit\""
95 Builder builder = Builder::New();
96 builder.LoadFromString( json );
97 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
99 // Connect to builder's quit signal
100 bool functorCalled( false );
101 builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
104 application.SendNotification();
105 application.Render();
107 // Emit touch event and check that our quit method is called
108 Integration::TouchEvent touchEvent;
109 Integration::Point point;
110 point.SetState( PointState::DOWN );
111 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
112 touchEvent.points.push_back( point );
113 application.ProcessEvent( touchEvent );
114 DALI_TEST_CHECK( functorCalled );
120 int UtcDaliBuilderAnimationP(void)
122 ToolkitTestApplication application;
124 // JSON with a quit event when the actor is touched
129 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
135 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
136 " \"curvature\":0.35"
142 " \"endAction\": \"BAKE\","
143 " \"disconnectAction\": \"BAKE\","
146 " \"actor\": \"greeting\","
147 " \"property\": \"position\","
148 " \"value\": [300, 300, -1000],"
149 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
150 " \"relative\": true,"
157 " \"actor\": \"greeting\","
158 " \"property\": \"visible\","
159 " \"alphaFunction\": \"LINEAR\","
163 " \"actor\": \"greeting\","
164 " \"property\": \"sizeWidth\","
165 " \"alphaFunction\": \"REVERSE\","
169 " \"actor\": \"greeting\","
170 " \"property\": \"orientation\","
171 " \"alphaFunction\": \"EASE_IN\","
172 " \"value\": [10.0,20.0,30.0]"
175 " \"actor\": \"greeting\","
176 " \"property\": \"orientation\","
177 " \"alphaFunction\": \"EASE_OUT\","
178 " \"value\": [0.0, 0.0, 0.0, 1.0]"
181 " \"actor\": \"greeting\","
182 " \"property\": \"orientation\","
183 " \"alphaFunction\": \"EASE_IN_OUT\","
184 " \"value\": [0.0, 0.0, 0.0, 1.0]"
187 " \"actor\": \"greeting\","
188 " \"property\": \"orientation\","
189 " \"alphaFunction\": \"EASE_IN_SINE\","
190 " \"value\": [0.0, 0.0, 0.0, 1.0]"
193 " \"actor\": \"greeting\","
194 " \"property\": \"orientation\","
195 " \"alphaFunction\": \"EASE_OUT_SINE\","
196 " \"value\": [0.0, 0.0, 0.0, 1.0]"
199 " \"actor\": \"greeting\","
200 " \"property\": \"orientation\","
201 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
202 " \"value\": [0.0, 0.0, 0.0, 1.0]"
205 " \"actor\": \"greeting\","
206 " \"property\": \"orientation\","
207 " \"alphaFunction\": \"BOUNCE\","
208 " \"value\": [0.0, 0.0, 0.0, 1.0]"
211 " \"actor\": \"greeting\","
212 " \"property\": \"orientation\","
213 " \"alphaFunction\": \"SIN\","
214 " \"value\": [0.0, 0.0, 0.0, 1.0]"
217 " \"actor\": \"greeting\","
218 " \"property\": \"orientation\","
219 " \"alphaFunction\": \"EASE_OUT_BACK\","
220 " \"value\": [0.0, 0.0, 0.0, 1.0]"
224 " \"pathAnimation\": {"
225 " \"duration\": 3.0,"
226 " \"endAction\": \"DISCARD\","
227 " \"disconnectAction\": \"BAKE_FINAL\","
228 " \"properties\": [{"
229 " \"actor\": \"greeting\","
230 " \"path\":\"path0\","
231 " \"forward\":[1,0,0],"
232 " \"alphaFunction\": \"EASE_IN_OUT\","
241 " \"name\": \"greeting\","
242 " \"type\": \"TextLabel\","
243 " \"text\": \"Touch me\","
244 " \"styles\": [\"basicText\"],"
245 " \"position\": [0, -120, 0],"
246 " \"size\": [200, 200, 1],"
247 " \"orientation\": [0, 0, 30],"
249 " \"name\": \"touch\","
250 " \"action\": \"play\","
251 " \"animation\": \"animate\""
256 Builder builder = Builder::New();
257 builder.LoadFromString( json );
258 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
260 Animation anim = builder.CreateAnimation("animate");
262 DALI_TEST_CHECK( anim );
265 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
266 anim = builder.CreateAnimation("animate", map);
268 DALI_TEST_CHECK( anim );
270 anim = builder.CreateAnimation("pathAnimation");
272 DALI_TEST_CHECK( anim );
275 // Emit touch event and check that our quit method is called
276 Integration::TouchEvent touchEvent;
277 Integration::Point point;
278 point.SetState( PointState::DOWN );
279 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
280 touchEvent.points.push_back( point );
281 application.ProcessEvent( touchEvent );
284 application.SendNotification();
285 application.Render();
291 int UtcDaliBuilderAnimationN(void)
293 ToolkitTestApplication application;
295 // JSON with a quit event when the actor is touched
300 " \"TEXT\": \"Touch Me\","
301 " \"NAME\": \"greeting\" "
307 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
308 " \"curvature\":0.35"
314 " \"endAction\": \"BAKE\","
315 " \"disconnectAction\": \"BAKE\","
318 " \"actor\": \"{NAME}\","
319 " \"property\": \"positioninvalid\","
320 " \"value\": [300, 300, -1000],"
321 " \"alphaFunction\": \"EASE_IN_OUT\","
322 " \"relative\": true,"
332 " \"endAction\": \"BAKE\","
333 " \"disconnectAction\": \"BAKE\","
336 " \"actor\": \"{NAME}\","
337 " \"property\": \"positioninvalid\","
338 " \"value\": [300, 300, -1000],"
339 " \"alphaFunction\": \"EGGS_OVER_EASY\","
340 " \"relative\": true,"
348 " \"pathAnimation\": {"
349 " \"duration\": 3.0,"
350 " \"endAction\": \"DISCARD\","
351 " \"disconnectAction\": \"BAKE_FINAL\","
352 " \"properties\": [{"
353 " \"actor\": \"greeting\","
354 " \"path\":\"pathDoesntExist\","
355 " \"forward\":[1,0,0],"
356 " \"alphaFunction\": \"EASE_IN_OUT\","
365 " \"name\": \"greeting\","
366 " \"type\": \"TextLabel\","
367 " \"text\": \"Touch me\","
368 " \"styles\": [\"basicText\"],"
369 " \"position\": [0, -120, 0],"
370 " \"size\": [200, 200, 1],"
371 " \"orientation\": [0, 0, 30],"
373 " \"name\": \"touch\","
374 " \"action\": \"play\","
375 " \"animation\": \"animate\""
379 " \"name\": \"greeting2\","
380 " \"type\": \"TextLabel\","
381 " \"text\": \"Touch me\""
386 Builder builder = Builder::New();
387 builder.LoadFromString( json );
388 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
390 Animation anim = builder.CreateAnimation("animate");
392 // log warning line coverage
393 anim = builder.CreateAnimation("pathAnimation");
394 DALI_TEST_CHECK(anim);
396 anim = builder.CreateAnimation("animate");
397 DALI_TEST_CHECK(anim);
399 anim = builder.CreateAnimation("animate2");
400 DALI_TEST_CHECK(anim);
402 // create referencing a different actor aka animation templates
404 map["NAME"] = "greeting2";
405 anim = builder.CreateAnimation("animate2", map);
406 DALI_TEST_CHECK(anim);
408 // alternative actor to use for FindChildByName
409 anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
410 DALI_TEST_CHECK(anim);
412 // alternative actor to use for FindChildByName
413 anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
414 DALI_TEST_CHECK(anim);
421 int UtcDaliBuilderConstantsP(void)
423 ToolkitTestApplication application;
425 // JSON with a quit event when the actor is touched
430 " \"IMAGE_PATH\": \"apath\","
432 " \"ANCHOR\": \"TOP_LEFT\","
433 " \"PADDING\": [1,2,3,4]"
437 " \"type\": \"ImageView\","
438 " \"name\": \"{NAME}\","
439 " \"size\": [100,100,1],"
440 " \"parentOrigin\": \"TOP_LEFT\","
441 " \"anchorPoint\": \"{ANCHOR}\","
442 " \"padding\": \"{PADDING}\","
443 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
444 " \"sizeWidth\": \"{WIDTH}\","
446 " \"name\": \"touch\","
447 " \"action\": \"quit\""
453 Builder builder = Builder::New();
454 builder.LoadFromString( json );
456 builder.AddConstant( "NAME", "image" );
458 Property::Map map = builder.GetConstants();
460 Dali::Property::Value* pValue = map.Find( "NAME" );
462 DALI_TEST_CHECK( pValue );
464 pValue = map.Find( "IMAGE_PATH" );
466 DALI_TEST_CHECK( pValue );
468 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
470 DALI_TEST_CHECK( value.GetType() != Property::NONE );
472 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
473 DALI_TEST_CHECK( builder );
475 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
476 DALI_TEST_CHECK( actor );
481 int UtcDaliBuilderTemplatesAndStylesP(void)
483 ToolkitTestApplication application;
485 // JSON with a quit event when the actor is touched
490 " \"SIZE\": [10,20,30]"
494 " \"imageStyle\": \n"
496 " \"color\": [1,0,0,1],\n"
498 " \"childImage\": {\n"
499 " \"color\": \"34\"\n"
506 " \"imageViewTemplate\": { \n"
507 " \"type\": \"ImageView\",\n"
508 " \"styles\": [\"imageStyle\"]\n"
510 " \"imageTree\": { \n"
511 " \"type\": \"ImageView\",\n"
512 " \"styles\": [\"imageStyle\"],\n"
513 " \"name\": \"image\",\n"
514 " \"size\": \"{SIZE}\",\n"
516 " \"name\": \"touch\",\n"
517 " \"action\": \"quit\"\n"
521 " \"type\":\"ImageView\",\n"
522 " \"name\":\"childImage\", \n"
532 " \"type\":\"imageViewTemplate\",\n"
533 " \"name\":\"childImage2\"\n"
540 " \"type\": \"imageTree\","
541 " \"size\": [100,100,1]"
546 std::string stylejson(
548 " \"color\": [1,0,0,1],\n"
550 " \"childImage\": {\n"
551 " \"color\": \"#344353\"\n"
557 std::string templatejson(
559 " \"type\": \"ImageView\",\n"
560 " \"styles\": [\"imageStyle\"],\n"
561 " \"name\": \"image\",\n"
562 " \"size\": \"{SIZE}\",\n"
564 " \"name\": \"touch\",\n"
565 " \"action\": \"quit\"\n"
569 " \"type\":\"ImageView\",\n"
570 " \"name\":\"childImage\" \n"
576 Builder builder = Builder::New();
577 builder.LoadFromString( json );
579 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
580 DALI_TEST_CHECK( actor );
582 Dali::Property::Map map;
583 map["SIZE"] = Vector3(100,100,1);
584 actor = ImageView::DownCast( builder.Create( "imageTree", map ) );
585 DALI_TEST_CHECK( actor );
587 // create from json snippet
588 actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
589 DALI_TEST_CHECK( actor );
592 // NB: already applied in create
593 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
595 // apply from json snippet
596 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
601 int UtcDaliBuilderRenderTasksP(void)
603 ToolkitTestApplication application;
605 // JSON with a quit event when the actor is touched
611 " \"sourceActor\": \"image\",\n"
612 " \"cameraActor\": \"camera\" \n"
618 " \"type\": \"CameraActor\",\n"
619 " \"name\": \"camera\"\n"
622 " \"type\": \"ImageView\",\n"
623 " \"name\": \"image\",\n"
624 " \"size\": [100,100,1],\n"
626 " \"name\": \"touch\",\n"
627 " \"action\": \"quit\"\n"
631 " \"type\":\"ImageView\",\n"
632 " \"name\":\"childImage\" \n"
640 Builder builder = Builder::New();
641 builder.LoadFromString( json );
643 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
646 builder.CreateRenderTask( "task0" );
648 DALI_TEST_CHECK( count <
649 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
654 int UtcDaliBuilderChildActionP(void)
656 ToolkitTestApplication application;
658 // JSON with a quit event when the actor is touched
663 " \"type\": \"Actor\",\n"
664 " \"name\": \"actor\",\n"
665 " \"size\": [100,100,1],\n"
666 " \"parentOrigin\": \"TOP_LEFT\",\n"
667 " \"anchorPoint\": \"TOP_LEFT\",\n"
669 " \"type\": \"Actor\",\n"
670 " \"name\": \"subActor\"\n"
673 " \"name\": \"touch\",\n"
674 " \"action\": \"hide\",\n"
675 " \"actor\": \"actor\",\n"
676 " \"childActor\": \"subActor\"\n"
682 Builder builder = Builder::New();
683 builder.LoadFromString( json );
684 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
687 application.SendNotification();
688 application.Render();
690 // Emit touch event and check that our quit method is called
691 Integration::TouchEvent touchEvent;
692 Integration::Point point;
693 point.SetState( PointState::DOWN );
694 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
695 touchEvent.points.push_back( point );
696 application.ProcessEvent( touchEvent );
699 application.SendNotification();
700 application.Render();
702 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
703 DALI_TEST_CHECK( actor );
705 DALI_TEST_CHECK( !actor.IsVisible() );
710 int UtcDaliBuilderSetPropertyActionP(void)
712 ToolkitTestApplication application;
714 // JSON with a quit event when the actor is touched
719 " \"type\": \"Actor\",\n"
720 " \"name\": \"actor\",\n"
721 " \"size\": [100,100,1],\n"
722 " \"parentOrigin\": \"TOP_LEFT\",\n"
723 " \"anchorPoint\": \"TOP_LEFT\",\n"
725 " \"type\": \"Actor\",\n"
726 " \"name\": \"subActor\"\n"
729 " \"name\": \"touch\",\n"
730 " \"action\": \"set\",\n"
731 " \"actor\": \"subActor\",\n"
732 " \"property\": \"visible\",\n"
733 " \"value\": false\n"
739 Builder builder = Builder::New();
740 builder.LoadFromString( json );
741 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
744 application.SendNotification();
745 application.Render();
747 // Emit touch event and check that our quit method is called
748 Integration::TouchEvent touchEvent;
749 Integration::Point point;
750 point.SetState( PointState::DOWN );
751 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
752 touchEvent.points.push_back( point );
753 application.ProcessEvent( touchEvent );
756 application.SendNotification();
757 application.Render();
759 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
760 DALI_TEST_CHECK( actor );
762 DALI_TEST_CHECK( !actor.IsVisible() );
767 int UtcDaliBuilderGenericActionP(void)
769 ToolkitTestApplication application;
771 // JSON with a quit event when the actor is touched
776 " \"type\": \"Actor\",\n"
777 " \"name\": \"actor\",\n"
778 " \"size\": [100,100,1],\n"
779 " \"parentOrigin\": \"TOP_LEFT\",\n"
780 " \"anchorPoint\": \"TOP_LEFT\",\n"
782 " \"type\": \"Actor\",\n"
783 " \"name\": \"subActor\"\n"
786 " \"name\": \"touch\",\n"
787 " \"action\": \"hide\"\n"
793 Builder builder = Builder::New();
794 builder.LoadFromString( json );
795 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
798 application.SendNotification();
799 application.Render();
801 // Emit touch event and check that our quit method is called
802 Integration::TouchEvent touchEvent;
803 Integration::Point point;
804 point.SetState( PointState::DOWN );
805 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
806 touchEvent.points.push_back( point );
807 application.ProcessEvent( touchEvent );
810 application.SendNotification();
811 application.Render();
813 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
814 DALI_TEST_CHECK( actor );
816 DALI_TEST_CHECK( !actor.IsVisible() );
821 int UtcDaliBuilderPropertyNotificationP(void)
823 ToolkitTestApplication application;
825 // JSON with a quit event when the actor is touched
830 " \"type\": \"Actor\",\n"
831 " \"name\": \"actor\",\n"
832 " \"size\": [100,100,1],\n"
833 " \"parentOrigin\": \"TOP_LEFT\",\n"
834 " \"anchorPoint\": \"TOP_LEFT\",\n"
836 " \"type\": \"Actor\",\n"
837 " \"name\": \"subActor\"\n"
840 " \"name\": \"touch\",\n"
841 " \"action\": \"hide\"\n"
843 " \"notifications\": [{\n"
844 " \"property\": \"visible\",\n"
845 " \"condition\": \"False\",\n"
846 " \"action\": \"show\"\n"
852 Builder builder = Builder::New();
853 builder.LoadFromString( json );
854 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
857 application.SendNotification();
858 application.Render();
860 // Emit touch event and check that our quit method is called
861 Integration::TouchEvent touchEvent;
862 Integration::Point point;
863 point.SetState( PointState::DOWN );
864 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
865 touchEvent.points.push_back( point );
866 application.ProcessEvent( touchEvent );
869 application.SendNotification();
870 application.Render();
873 application.SendNotification();
874 application.Render();
876 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
877 DALI_TEST_CHECK( actor );
879 DALI_TEST_CHECK( actor.IsVisible() );
884 int UtcDaliBuilderCustomPropertyP(void)
886 ToolkitTestApplication application;
888 // JSON with a quit event when the actor is touched
893 " \"imageTree\": { \n"
894 " \"type\": \"ImageView\",\n"
895 " \"name\": \"image\",\n"
896 " \"size\": [100,100,1],\n"
898 " \"name\": \"touch\",\n"
899 " \"action\": \"quit\"\n"
901 " \"properties\": {\n"
902 " \"newproperty\": true\n"
904 " \"animatableProperties\": {\n"
905 " \"newAnimatableproperty\": 3\n"
909 " \"type\":\"ImageView\",\n"
910 " \"name\":\"childImage\" \n"
918 Builder builder = Builder::New();
919 builder.LoadFromString( json );
921 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
922 DALI_TEST_CHECK( actor );
924 // NB: already applied in create
925 Property::Index index = actor.GetPropertyIndex("newproperty");
926 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
927 Property::Value value = actor.GetProperty(index);
928 DALI_TEST_CHECK( value.Get<bool>() == true );
930 index = actor.GetPropertyIndex("newAnimatableproperty");
931 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
932 value = actor.GetProperty(index);
933 DALI_TEST_CHECK( value.Get<int>() == 3 );
938 int UtcDaliBuilderCustomShaderP(void)
940 ToolkitTestApplication application;
942 // JSON with a quit event when the actor is touched
947 " \"type\": \"ImageView\",\n"
948 " \"name\": \"Image1\",\n"
950 " 0.40461349487305,\n"
954 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
955 " \"size\": [200, 200, 0],\n"
956 " \"effect\": \"Ripple2D\",\n"
958 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
959 " \"desiredWidth\": 200,\n"
960 " \"desiredHeight\": 80,\n"
962 " \"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"
965 " \"customAnimatableProperties\": {\n"
966 " \"uAmplitude\": 0.02,\n"
971 " \"name\": \"onStage\",\n"
972 " \"action\": \"play\",\n"
973 " \"animation\": \"Animation_1\"\n"
978 " \"animations\": {\n"
979 " \"Animation_1\": {\n"
981 " \"properties\": [\n"
983 " \"actor\": \"Image1\",\n"
984 " \"property\": \"uTime\",\n"
985 " \"value\": 10.0,\n"
986 " \"alphaFunction\": \"LINEAR\",\n"
987 " \"timePeriod\": {\n"
989 " \"duration\": 10.0\n"
999 Builder builder = Builder::New();
1000 builder.LoadFromString( json );
1002 builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
1004 // Render and notify
1005 application.SendNotification();
1006 application.Render();
1008 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
1011 DALI_TEST_CHECK( actor );
1017 int UtcDaliBuilderLoadFromStringN(void)
1019 ToolkitTestApplication application;
1021 // JSON with a quit event when the actor is touched
1023 "asdfsadf dsf asdf asdf {"
1026 "\"type\": \"Actor\","
1027 "\"size\": [100,100,1],"
1028 "\"parentOrigin\": \"TOP_LEFT\","
1029 "\"anchorPoint\": \"TOP_LEFT\","
1031 "\"name\": \"touch\","
1032 "\"action\": \"quit\""
1037 Builder builder = Builder::New();
1039 bool assert1 = false;
1043 builder.LoadFromString( json );
1045 catch( Dali::DaliException& e )
1047 DALI_TEST_PRINT_ASSERT( e );
1048 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1052 DALI_TEST_CHECK( assert1 );
1058 int UtcDaliBuilderAddActorsP(void)
1060 ToolkitTestApplication application;
1062 // JSON with a quit event when the actor is touched
1065 " \"arbitarysection\":\n"
1067 " \"type\": \"Actor\",\n"
1068 " \"name\": \"actor\",\n"
1069 " \"size\": [100,100,1],\n"
1070 " \"parentOrigin\": \"TOP_LEFT\",\n"
1071 " \"anchorPoint\": \"TOP_LEFT\",\n"
1073 " \"type\": \"Actor\",\n"
1074 " \"name\": \"subActor\",\n"
1075 " \"visible\": false\n"
1077 " \"signals\": [{\n"
1078 " \"name\": \"touch\",\n"
1079 " \"action\": \"hide\",\n"
1080 " \"actor\": \"actor\",\n"
1081 " \"childActor\": \"subActor\"\n"
1087 Builder builder = Builder::New();
1088 builder.LoadFromString( json );
1089 builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1091 // Render and notify
1092 application.SendNotification();
1093 application.Render();
1095 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1096 DALI_TEST_CHECK( actor );
1098 DALI_TEST_CHECK( !actor.IsVisible() );
1103 int UtcDaliBuilderFrameBufferP(void)
1105 ToolkitTestApplication application;
1107 // JSON with a quit event when the actor is touched
1112 " \"FB_WIDTH\": 200.0,\n"
1113 " \"FB_HEIGHT\": 200.0,\n"
1114 " \"FB_SIZE\": [200,200],\n"
1115 " \"FB_ASPECT_RATIO\": 1\n"
1119 " \"type\": \"ImageView\",\n"
1120 " \"name\": \"fbOnStage\",\n"
1121 " \"position\": [\n"
1122 " 0.40461349487305,\n"
1126 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1127 " \"size\": [300, 300, 0],\n"
1128 " \"image\": \"fb0\",\n"
1129 " \"clearColor\": [1,0,0,1]\n"
1132 " \"type\": \"ImageView\",\n"
1133 " \"name\": \"Image1\",\n"
1134 " \"size\": [200, 200, 0],\n"
1135 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1136 " \"effect\": \"Ripple2D\",\n"
1138 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1142 " \"name\": \"onStage\",\n"
1143 " \"action\": \"play\",\n"
1144 " \"animation\": \"Animation_1\"\n"
1149 " \"type\":\"CameraActor\",\n"
1150 " \"name\":\"fbCam\",\n"
1151 " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1152 " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1153 " \"fieldOfView\": 0.785,\n"
1154 " \"invertYAxis\": true\n"
1157 " \"frameBufferImages\":\n"
1161 " \"type\": \"FrameBufferImage\",\n"
1162 " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1163 " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1166 " \"renderTasks\":\n"
1171 " \"sourceActor\": \"fbOnStage\"\n"
1174 " \"sourceActor\": \"Image1\",\n"
1175 " \"targetFrameBuffer\": \"fb0\",\n"
1176 " \"viewportSize\":\"{FB_SIZE}\",\n"
1177 " \"cameraActor\":\"fbCam\"\n"
1182 " \"animations\": {\n"
1183 " \"Animation_1\": {\n"
1185 " \"properties\": [\n"
1187 " \"actor\": \"Image1\",\n"
1188 " \"property\": \"uTime\",\n"
1189 " \"value\": 10.0,\n"
1190 " \"alphaFunction\": \"LINEAR\",\n"
1191 " \"timePeriod\": {\n"
1193 " \"duration\": 10.0\n"
1195 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1200 " \"shaderEffects\": {\n"
1201 " \"Ripple2D\": {\n"
1203 " \"vertexPrefix\": \"\",\n"
1204 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1205 " \"fragmentPrefix\": \"\",\n"
1206 " \"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"
1207 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1209 " \"geometryHints\": \"HINT_NONE\",\n"
1210 " \"gridDensity\": 0,\n"
1211 " \"loop\": true,\n"
1212 " \"uAmplitude\": 0.02,\n"
1218 Builder builder = Builder::New();
1220 // frame buffer coverage
1221 builder.LoadFromString( json );
1223 // Render and notify
1224 application.SendNotification();
1225 application.Render();
1227 Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1228 DALI_TEST_CHECK( frameBuffer );
1230 Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1231 DALI_TEST_CHECK( frameBuffer2 );
1232 DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1234 DALI_TEST_CHECK( true );
1239 int UtcDaliBuilderPathConstraintsP(void)
1241 ToolkitTestApplication application;
1243 // JSON with a quit event when the actor is touched
1248 " \"FB_WIDTH\": 200.0,\n"
1249 " \"FB_HEIGHT\": 200.0,\n"
1250 " \"FB_SIZE\": [200,200],\n"
1251 " \"FB_ASPECT_RATIO\": 1\n"
1255 " \"type\": \"ImageView\",\n"
1256 " \"name\": \"Image1\",\n"
1257 " \"size\": [200, 200, 0],\n"
1258 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1259 " \"effect\": \"Ripple2D\",\n"
1261 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1265 " \"name\": \"onStage\",\n"
1266 " \"action\": \"play\",\n"
1267 " \"animation\": \"pathAnimation\"\n"
1270 " \"name\": \"onStage\",\n"
1271 " \"action\": \"applyConstraint\",\n"
1272 " \"constrainer\": \"constrainer0\",\n"
1273 " \"properties\":\n"
1276 " \"source\": \"Image1\",\n"
1277 " \"sourceProperty\": \"positionX\",\n"
1278 " \"target\": \"Image1\",\n"
1279 " \"targetProperty\": \"colorRed\",\n"
1280 " \"range\": [-300,300]\n"
1285 " \"name\": \"onStage\",\n"
1286 " \"action\": \"applyConstraint\",\n"
1287 " \"constrainer\": \"constrainer1\",\n"
1288 " \"properties\":\n"
1291 " \"source\": \"Image1\",\n"
1292 " \"sourceProperty\": \"positionX\",\n"
1293 " \"target\": \"Image1\",\n"
1294 " \"targetProperty\": \"colorBlue\",\n"
1295 " \"range\": [-300,300]\n"
1306 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1307 " \"curvature\":0.35\n"
1310 " \"constrainers\":\n"
1312 " \"constrainer0\":\n"
1314 " \"type\": \"PathConstrainer\",\n"
1315 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1316 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1318 " \"constrainer1\":\n"
1320 " \"type\": \"LinearConstrainer\",\n"
1321 " \"value\": [ 0, 0, 0 ]\n"
1324 " \"animations\": {\n"
1325 " \"pathAnimation\": {\n"
1326 " \"duration\": 3.0,\n"
1327 " \"properties\":\n"
1329 " \"actor\": \"Image1\",\n"
1330 " \"path\":\"path0\",\n"
1331 " \"forward\":[1,0,0],\n"
1332 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1333 " \"timePeriod\": {\n"
1335 " \"duration\": 3\n"
1339 " \"actor\": \"Image1\",\n"
1340 " \"property\": \"uTime\",\n"
1341 " \"value\": 10.0,\n"
1342 " \"alphaFunction\": \"LINEAR\",\n"
1343 " \"timePeriod\": {\n"
1345 " \"duration\": 10.0\n"
1347 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1350 " \"Animation_1\": {\n"
1352 " \"properties\": [\n"
1354 " \"actor\": \"Image1\",\n"
1355 " \"property\": \"uTime\",\n"
1356 " \"value\": 10.0,\n"
1357 " \"alphaFunction\": \"LINEAR\",\n"
1358 " \"timePeriod\": {\n"
1360 " \"duration\": 10.0\n"
1362 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1367 " \"shaderEffects\": {\n"
1368 " \"Ripple2D\": {\n"
1370 " \"vertexPrefix\": \"\",\n"
1371 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1372 " \"fragmentPrefix\": \"\",\n"
1373 " \"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"
1374 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1376 " \"geometryHints\": \"HINT_NONE\",\n"
1377 " \"gridDensity\": 0,\n"
1378 " \"loop\": true,\n"
1379 " \"uAmplitude\": 0.02,\n"
1385 Builder builder = Builder::New();
1387 // frame buffer coverage
1388 builder.LoadFromString( json );
1390 // Render and notify
1391 application.SendNotification();
1392 application.Render();
1394 Dali::Path path = builder.GetPath( "path0" );
1395 DALI_TEST_CHECK( path );
1397 Dali::Path path2 = builder.GetPath( "path0" );
1398 DALI_TEST_CHECK( path2 );
1399 DALI_TEST_CHECK( path == path2 );
1401 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1402 DALI_TEST_CHECK( constrainer0 );
1404 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1405 DALI_TEST_CHECK( constrainer0_2 );
1406 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1408 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1409 DALI_TEST_CHECK( constrainer1 );
1411 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1412 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1417 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1419 Property::Value* value = xMap->Find( xKey ); \
1420 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1421 if( value != NULL ) \
1423 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1425 value->Get(result); \
1426 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1427 std::ostringstream oss; \
1428 oss << "Animation element " << xKey << "= " << result << std::endl; \
1429 tet_printf( oss.str().c_str() ); \
1433 tet_printf("Can't find map element " xKey "\n"); \
1438 int UtcDaliBuilderMapping01(void)
1440 ToolkitTestApplication application;
1446 " \"buttonPressFadeOut\":{\n"
1447 " \"alphaFunction\":\"EASE_OUT\",\n"
1448 " \"timePeriod\":{\n"
1450 " \"duration\":0.4\n"
1453 " \"buttonPressFadeIn\":{\n"
1454 " \"alphaFunction\":\"EASE_IN\",\n"
1455 " \"timePeriod\":{\n"
1457 " \"duration\":0.5\n"
1460 " \"transition:buttonPressed\":\n"
1463 " \"target\": \"unselectedBackgroundRenderer\",\n"
1464 " \"property\": \"opacity\",\n"
1466 " \"animator\":\"<buttonPressFadeOut>\"\n"
1469 " \"transition:buttonReleased\":\n"
1472 " \"target\": \"unselectedBackgroundRenderer\",\n"
1473 " \"property\": \"opacity\",\n"
1475 " \"animator\":\"<buttonPressFadeIn>\"\n"
1478 " \"target\": \"unselectedForegroundRenderer\",\n"
1479 " \"property\": \"scale\",\n"
1480 " \"value\": [ 1, 1, 1 ],\n"
1481 " \"animator\":\"<buttonPressFadeIn>\"\n"
1484 " \"target\": \"selectedBackgroundRenderer\",\n"
1485 " \"property\": \"opacity\",\n"
1487 " \"animator\": \"<buttonPressFadeOut>\"\n"
1490 " \"target\": \"selectedForegroundRenderer\",\n"
1491 " \"property\": \"scale\",\n"
1492 " \"value\": [ 0, 0, 0 ],\n"
1493 " \"animator\":\"<buttonPressFadeOut>\"\n"
1499 " \"testbutton\":\n"
1501 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1502 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1507 Builder builder = Builder::New();
1508 builder.LoadFromString( json );
1510 Test::TestButton testButton = Test::TestButton::New();
1511 Stage::GetCurrent().Add( testButton );
1513 // Render and notify
1514 application.SendNotification();
1515 application.Render();
1517 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1519 // Now check that it has loaded the transition correctly:
1520 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1521 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1522 Property::Array* array = transition.GetArray();
1524 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1525 Property::Value element = array->GetElementAt(0);
1526 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1527 Property::Map* map = element.GetMap();
1529 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1530 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1531 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1532 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1533 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1539 int UtcDaliBuilderMappingCycleCheck(void)
1541 ToolkitTestApplication application;
1547 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1548 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1549 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1551 " \"alphaFunction\":\"EASE_IN\",\n"
1552 " \"timePeriod\":{\n"
1553 " \"delay\":\"<cyclicKey3>\",\n"
1554 " \"duration\":0.6\n"
1557 " \"transition:buttonPressed\":\n"
1560 " \"target\": \"<cyclicKey1>\",\n"
1561 " \"property\": \"<cyclicKey2>\",\n"
1563 " \"animator\":\"<FadeOut>\"\n"
1569 " \"testbutton\":\n"
1571 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1572 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1573 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1574 " \"enabledTransition\":\"<unknownKey>\"\n"
1579 Builder builder = Builder::New();
1580 builder.LoadFromString( json );
1582 Test::TestButton testButton = Test::TestButton::New();
1583 Stage::GetCurrent().Add( testButton );
1585 // Render and notify
1586 application.SendNotification();
1587 application.Render();
1589 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1591 // Now check that it has loaded the transition correctly:
1592 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1593 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1594 Property::Array* array = transition.GetArray();
1596 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1597 Property::Value element = array->GetElementAt(0);
1598 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1599 Property::Map* map = element.GetMap();
1601 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1602 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1603 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);