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 Integration::Point point;
107 point.SetState( PointState::DOWN );
108 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
109 touchEvent.points.push_back( point );
110 application.ProcessEvent( touchEvent );
111 DALI_TEST_CHECK( functorCalled );
117 int UtcDaliBuilderAnimationP(void)
119 ToolkitTestApplication application;
121 // JSON with a quit event when the actor is touched
126 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
132 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
133 " \"curvature\":0.35"
139 " \"endAction\": \"BAKE\","
140 " \"disconnectAction\": \"BAKE\","
143 " \"actor\": \"greeting\","
144 " \"property\": \"position\","
145 " \"value\": [300, 300, -1000],"
146 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
147 " \"relative\": true,"
154 " \"actor\": \"greeting\","
155 " \"property\": \"visible\","
156 " \"alphaFunction\": \"LINEAR\","
160 " \"actor\": \"greeting\","
161 " \"property\": \"sizeWidth\","
162 " \"alphaFunction\": \"REVERSE\","
166 " \"actor\": \"greeting\","
167 " \"property\": \"orientation\","
168 " \"alphaFunction\": \"EASE_IN\","
169 " \"value\": [10.0,20.0,30.0]"
172 " \"actor\": \"greeting\","
173 " \"property\": \"orientation\","
174 " \"alphaFunction\": \"EASE_OUT\","
175 " \"value\": [0.0, 0.0, 0.0, 1.0]"
178 " \"actor\": \"greeting\","
179 " \"property\": \"orientation\","
180 " \"alphaFunction\": \"EASE_IN_OUT\","
181 " \"value\": [0.0, 0.0, 0.0, 1.0]"
184 " \"actor\": \"greeting\","
185 " \"property\": \"orientation\","
186 " \"alphaFunction\": \"EASE_IN_SINE\","
187 " \"value\": [0.0, 0.0, 0.0, 1.0]"
190 " \"actor\": \"greeting\","
191 " \"property\": \"orientation\","
192 " \"alphaFunction\": \"EASE_OUT_SINE\","
193 " \"value\": [0.0, 0.0, 0.0, 1.0]"
196 " \"actor\": \"greeting\","
197 " \"property\": \"orientation\","
198 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
199 " \"value\": [0.0, 0.0, 0.0, 1.0]"
202 " \"actor\": \"greeting\","
203 " \"property\": \"orientation\","
204 " \"alphaFunction\": \"BOUNCE\","
205 " \"value\": [0.0, 0.0, 0.0, 1.0]"
208 " \"actor\": \"greeting\","
209 " \"property\": \"orientation\","
210 " \"alphaFunction\": \"SIN\","
211 " \"value\": [0.0, 0.0, 0.0, 1.0]"
214 " \"actor\": \"greeting\","
215 " \"property\": \"orientation\","
216 " \"alphaFunction\": \"EASE_OUT_BACK\","
217 " \"value\": [0.0, 0.0, 0.0, 1.0]"
221 " \"pathAnimation\": {"
222 " \"duration\": 3.0,"
223 " \"endAction\": \"DISCARD\","
224 " \"disconnectAction\": \"BAKE_FINAL\","
225 " \"properties\": [{"
226 " \"actor\": \"greeting\","
227 " \"path\":\"path0\","
228 " \"forward\":[1,0,0],"
229 " \"alphaFunction\": \"EASE_IN_OUT\","
238 " \"name\": \"greeting\","
239 " \"type\": \"TextLabel\","
240 " \"text\": \"Touch me\","
241 " \"styles\": [\"basicText\"],"
242 " \"position\": [0, -120, 0],"
243 " \"size\": [200, 200, 1],"
244 " \"orientation\": [0, 0, 30],"
246 " \"name\": \"touched\","
247 " \"action\": \"play\","
248 " \"animation\": \"animate\""
253 Builder builder = Builder::New();
254 builder.LoadFromString( json );
255 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
257 Animation anim = builder.CreateAnimation("animate");
259 DALI_TEST_CHECK( anim );
262 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
263 anim = builder.CreateAnimation("animate", map);
265 DALI_TEST_CHECK( anim );
267 anim = builder.CreateAnimation("pathAnimation");
269 DALI_TEST_CHECK( anim );
272 // Emit touch event and check that our quit method is called
273 Integration::TouchEvent touchEvent;
274 Integration::Point point;
275 point.SetState( PointState::DOWN );
276 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
277 touchEvent.points.push_back( point );
278 application.ProcessEvent( touchEvent );
281 application.SendNotification();
282 application.Render();
288 int UtcDaliBuilderAnimationN(void)
290 ToolkitTestApplication application;
292 // JSON with a quit event when the actor is touched
297 " \"TEXT\": \"Touch Me\","
298 " \"NAME\": \"greeting\" "
304 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
305 " \"curvature\":0.35"
311 " \"endAction\": \"BAKE\","
312 " \"disconnectAction\": \"BAKE\","
315 " \"actor\": \"{NAME}\","
316 " \"property\": \"positioninvalid\","
317 " \"value\": [300, 300, -1000],"
318 " \"alphaFunction\": \"EASE_IN_OUT\","
319 " \"relative\": true,"
329 " \"endAction\": \"BAKE\","
330 " \"disconnectAction\": \"BAKE\","
333 " \"actor\": \"{NAME}\","
334 " \"property\": \"positioninvalid\","
335 " \"value\": [300, 300, -1000],"
336 " \"alphaFunction\": \"EGGS_OVER_EASY\","
337 " \"relative\": true,"
345 " \"pathAnimation\": {"
346 " \"duration\": 3.0,"
347 " \"endAction\": \"DISCARD\","
348 " \"disconnectAction\": \"BAKE_FINAL\","
349 " \"properties\": [{"
350 " \"actor\": \"greeting\","
351 " \"path\":\"pathDoesntExist\","
352 " \"forward\":[1,0,0],"
353 " \"alphaFunction\": \"EASE_IN_OUT\","
362 " \"name\": \"greeting\","
363 " \"type\": \"TextLabel\","
364 " \"text\": \"Touch me\","
365 " \"styles\": [\"basicText\"],"
366 " \"position\": [0, -120, 0],"
367 " \"size\": [200, 200, 1],"
368 " \"orientation\": [0, 0, 30],"
370 " \"name\": \"touched\","
371 " \"action\": \"play\","
372 " \"animation\": \"animate\""
376 " \"name\": \"greeting2\","
377 " \"type\": \"TextLabel\","
378 " \"text\": \"Touch me\""
383 Builder builder = Builder::New();
384 builder.LoadFromString( json );
385 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
387 Animation anim = builder.CreateAnimation("animate");
389 // log warning line coverage
390 anim = builder.CreateAnimation("pathAnimation");
391 DALI_TEST_CHECK(anim);
393 anim = builder.CreateAnimation("animate");
394 DALI_TEST_CHECK(anim);
396 anim = builder.CreateAnimation("animate2");
397 DALI_TEST_CHECK(anim);
399 // create referencing a different actor aka animation templates
401 map["NAME"] = "greeting2";
402 anim = builder.CreateAnimation("animate2", map);
403 DALI_TEST_CHECK(anim);
405 // alternative actor to use for FindChildByName
406 anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
407 DALI_TEST_CHECK(anim);
409 // alternative actor to use for FindChildByName
410 anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
411 DALI_TEST_CHECK(anim);
418 int UtcDaliBuilderConstantsP(void)
420 ToolkitTestApplication application;
422 // JSON with a quit event when the actor is touched
427 " \"IMAGE_PATH\": \"apath\","
429 " \"ANCHOR\": \"TOP_LEFT\","
430 " \"PADDING\": [1,2,3,4]"
434 " \"type\": \"ImageView\","
435 " \"name\": \"{NAME}\","
436 " \"size\": [100,100,1],"
437 " \"parentOrigin\": \"TOP_LEFT\","
438 " \"anchorPoint\": \"{ANCHOR}\","
439 " \"padding\": \"{PADDING}\","
440 " \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
441 " \"sizeWidth\": \"{WIDTH}\","
443 " \"name\": \"touched\","
444 " \"action\": \"quit\""
450 Builder builder = Builder::New();
451 builder.LoadFromString( json );
453 builder.AddConstant( "NAME", "image" );
455 Property::Map map = builder.GetConstants();
457 Dali::Property::Value* pValue = map.Find( "NAME" );
459 DALI_TEST_CHECK( pValue );
461 pValue = map.Find( "IMAGE_PATH" );
463 DALI_TEST_CHECK( pValue );
465 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
467 DALI_TEST_CHECK( value.GetType() != Property::NONE );
469 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
470 DALI_TEST_CHECK( builder );
472 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
473 DALI_TEST_CHECK( actor );
478 int UtcDaliBuilderTemplatesAndStylesP(void)
480 ToolkitTestApplication application;
482 // JSON with a quit event when the actor is touched
487 " \"SIZE\": [10,20,30]"
491 " \"imageStyle\": \n"
493 " \"color\": [1,0,0,1],\n"
495 " \"childImage\": {\n"
496 " \"color\": [0,1,0,1]\n"
503 " \"imageTree\": { \n"
504 " \"type\": \"ImageView\",\n"
505 " \"styles\": [\"imageStyle\"],\n"
506 " \"name\": \"image\",\n"
507 " \"size\": \"{SIZE}\",\n"
509 " \"name\": \"touched\",\n"
510 " \"action\": \"quit\"\n"
514 " \"type\":\"ImageView\",\n"
515 " \"name\":\"childImage\" \n"
522 " \"type\": \"imageTree\","
523 " \"size\": [100,100,1]"
528 std::string stylejson(
530 " \"color\": [1,0,0,1],\n"
532 " \"childImage\": {\n"
533 " \"color\": [0,1,0,1]\n"
539 std::string templatejson(
541 " \"type\": \"ImageView\",\n"
542 " \"styles\": [\"imageStyle\"],\n"
543 " \"name\": \"image\",\n"
544 " \"size\": \"{SIZE}\",\n"
546 " \"name\": \"touched\",\n"
547 " \"action\": \"quit\"\n"
551 " \"type\":\"ImageView\",\n"
552 " \"name\":\"childImage\" \n"
558 Builder builder = Builder::New();
559 builder.LoadFromString( json );
561 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
562 DALI_TEST_CHECK( actor );
564 Dali::Property::Map map;
565 map["SIZE"] = Vector3(100,100,1);
566 actor = ImageView::DownCast( builder.Create( "imageTree", map ) );
567 DALI_TEST_CHECK( actor );
569 // create from json snippet
570 actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
571 DALI_TEST_CHECK( actor );
574 // NB: already applied in create
575 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
577 // apply from json snippet
578 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
583 int UtcDaliBuilderRenderTasksP(void)
585 ToolkitTestApplication application;
587 // JSON with a quit event when the actor is touched
593 " \"sourceActor\": \"image\",\n"
594 " \"cameraActor\": \"camera\" \n"
600 " \"type\": \"CameraActor\",\n"
601 " \"name\": \"image\"\n"
604 " \"type\": \"ImageView\",\n"
605 " \"name\": \"image\",\n"
606 " \"size\": [100,100,1],\n"
608 " \"name\": \"touched\",\n"
609 " \"action\": \"quit\"\n"
613 " \"type\":\"ImageView\",\n"
614 " \"name\":\"childImage\" \n"
622 Builder builder = Builder::New();
623 builder.LoadFromString( json );
625 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
628 builder.CreateRenderTask( "task0" );
630 DALI_TEST_CHECK( count <
631 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
636 int UtcDaliBuilderChildActionP(void)
638 ToolkitTestApplication application;
640 // JSON with a quit event when the actor is touched
645 " \"type\": \"Actor\",\n"
646 " \"name\": \"actor\",\n"
647 " \"size\": [100,100,1],\n"
648 " \"parentOrigin\": \"TOP_LEFT\",\n"
649 " \"anchorPoint\": \"TOP_LEFT\",\n"
651 " \"type\": \"Actor\",\n"
652 " \"name\": \"subActor\"\n"
655 " \"name\": \"touched\",\n"
656 " \"action\": \"hide\",\n"
657 " \"actor\": \"actor\",\n"
658 " \"childActor\": \"subActor\"\n"
664 Builder builder = Builder::New();
665 builder.LoadFromString( json );
666 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
669 application.SendNotification();
670 application.Render();
672 // Emit touch event and check that our quit method is called
673 Integration::TouchEvent touchEvent;
674 Integration::Point point;
675 point.SetState( PointState::DOWN );
676 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
677 touchEvent.points.push_back( point );
678 application.ProcessEvent( touchEvent );
681 application.SendNotification();
682 application.Render();
684 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
685 DALI_TEST_CHECK( actor );
687 DALI_TEST_CHECK( !actor.IsVisible() );
692 int UtcDaliBuilderSetPropertyActionP(void)
694 ToolkitTestApplication application;
696 // JSON with a quit event when the actor is touched
701 " \"type\": \"Actor\",\n"
702 " \"name\": \"actor\",\n"
703 " \"size\": [100,100,1],\n"
704 " \"parentOrigin\": \"TOP_LEFT\",\n"
705 " \"anchorPoint\": \"TOP_LEFT\",\n"
707 " \"type\": \"Actor\",\n"
708 " \"name\": \"subActor\"\n"
711 " \"name\": \"touched\",\n"
712 " \"action\": \"set\",\n"
713 " \"actor\": \"subActor\",\n"
714 " \"property\": \"visible\",\n"
715 " \"value\": false\n"
721 Builder builder = Builder::New();
722 builder.LoadFromString( json );
723 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
726 application.SendNotification();
727 application.Render();
729 // Emit touch event and check that our quit method is called
730 Integration::TouchEvent touchEvent;
731 Integration::Point point;
732 point.SetState( PointState::DOWN );
733 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
734 touchEvent.points.push_back( point );
735 application.ProcessEvent( touchEvent );
738 application.SendNotification();
739 application.Render();
741 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
742 DALI_TEST_CHECK( actor );
744 DALI_TEST_CHECK( !actor.IsVisible() );
749 int UtcDaliBuilderGenericActionP(void)
751 ToolkitTestApplication application;
753 // JSON with a quit event when the actor is touched
758 " \"type\": \"Actor\",\n"
759 " \"name\": \"actor\",\n"
760 " \"size\": [100,100,1],\n"
761 " \"parentOrigin\": \"TOP_LEFT\",\n"
762 " \"anchorPoint\": \"TOP_LEFT\",\n"
764 " \"type\": \"Actor\",\n"
765 " \"name\": \"subActor\"\n"
768 " \"name\": \"touched\",\n"
769 " \"action\": \"hide\"\n"
775 Builder builder = Builder::New();
776 builder.LoadFromString( json );
777 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
780 application.SendNotification();
781 application.Render();
783 // Emit touch event and check that our quit method is called
784 Integration::TouchEvent touchEvent;
785 Integration::Point point;
786 point.SetState( PointState::DOWN );
787 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
788 touchEvent.points.push_back( point );
789 application.ProcessEvent( touchEvent );
792 application.SendNotification();
793 application.Render();
795 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
796 DALI_TEST_CHECK( actor );
798 DALI_TEST_CHECK( !actor.IsVisible() );
803 int UtcDaliBuilderPropertyNotificationP(void)
805 ToolkitTestApplication application;
807 // JSON with a quit event when the actor is touched
812 " \"type\": \"Actor\",\n"
813 " \"name\": \"actor\",\n"
814 " \"size\": [100,100,1],\n"
815 " \"parentOrigin\": \"TOP_LEFT\",\n"
816 " \"anchorPoint\": \"TOP_LEFT\",\n"
818 " \"type\": \"Actor\",\n"
819 " \"name\": \"subActor\"\n"
822 " \"name\": \"touched\",\n"
823 " \"action\": \"hide\"\n"
825 " \"notifications\": [{\n"
826 " \"property\": \"visible\",\n"
827 " \"condition\": \"False\",\n"
828 " \"action\": \"show\"\n"
834 Builder builder = Builder::New();
835 builder.LoadFromString( json );
836 builder.AddActors ( Stage::GetCurrent().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();
855 application.SendNotification();
856 application.Render();
858 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
859 DALI_TEST_CHECK( actor );
861 DALI_TEST_CHECK( actor.IsVisible() );
866 int UtcDaliBuilderCustomPropertyP(void)
868 ToolkitTestApplication application;
870 // JSON with a quit event when the actor is touched
875 " \"imageTree\": { \n"
876 " \"type\": \"ImageView\",\n"
877 " \"name\": \"image\",\n"
878 " \"size\": [100,100,1],\n"
880 " \"name\": \"touched\",\n"
881 " \"action\": \"quit\"\n"
883 " \"properties\": {\n"
884 " \"newproperty\": true\n"
886 " \"animatableProperties\": {\n"
887 " \"newAnimatableproperty\": 3\n"
891 " \"type\":\"ImageView\",\n"
892 " \"name\":\"childImage\" \n"
900 Builder builder = Builder::New();
901 builder.LoadFromString( json );
903 ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
904 DALI_TEST_CHECK( actor );
906 // NB: already applied in create
907 Property::Index index = actor.GetPropertyIndex("newproperty");
908 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
909 Property::Value value = actor.GetProperty(index);
910 DALI_TEST_CHECK( value.Get<bool>() == true );
912 index = actor.GetPropertyIndex("newAnimatableproperty");
913 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
914 value = actor.GetProperty(index);
915 DALI_TEST_CHECK( value.Get<int>() == 3 );
920 int UtcDaliBuilderCustomShaderP(void)
922 ToolkitTestApplication application;
924 // JSON with a quit event when the actor is touched
929 " \"type\": \"ImageView\",\n"
930 " \"name\": \"Image1\",\n"
932 " 0.40461349487305,\n"
936 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
937 " \"size\": [200, 200, 0],\n"
938 " \"effect\": \"Ripple2D\",\n"
940 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
941 " \"desiredWidth\": 200,\n"
942 " \"desiredHeight\": 80,\n"
944 " \"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"
947 " \"customAnimatableProperties\": {\n"
948 " \"uAmplitude\": 0.02,\n"
953 " \"name\": \"onStage\",\n"
954 " \"action\": \"play\",\n"
955 " \"animation\": \"Animation_1\"\n"
960 " \"animations\": {\n"
961 " \"Animation_1\": {\n"
963 " \"properties\": [\n"
965 " \"actor\": \"Image1\",\n"
966 " \"property\": \"uTime\",\n"
967 " \"value\": 10.0,\n"
968 " \"alphaFunction\": \"LINEAR\",\n"
969 " \"timePeriod\": {\n"
971 " \"duration\": 10.0\n"
981 Builder builder = Builder::New();
982 builder.LoadFromString( json );
984 builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
987 application.SendNotification();
988 application.Render();
990 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
993 DALI_TEST_CHECK( actor );
999 int UtcDaliBuilderLoadFromStringN(void)
1001 ToolkitTestApplication application;
1003 // JSON with a quit event when the actor is touched
1005 "asdfsadf dsf asdf asdf {"
1008 "\"type\": \"Actor\","
1009 "\"size\": [100,100,1],"
1010 "\"parentOrigin\": \"TOP_LEFT\","
1011 "\"anchorPoint\": \"TOP_LEFT\","
1013 "\"name\": \"touched\","
1014 "\"action\": \"quit\""
1019 Builder builder = Builder::New();
1021 bool assert1 = false;
1025 builder.LoadFromString( json );
1027 catch( Dali::DaliException& e )
1029 DALI_TEST_PRINT_ASSERT( e );
1030 DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1034 DALI_TEST_CHECK( assert1 );
1040 int UtcDaliBuilderAddActorsP(void)
1042 ToolkitTestApplication application;
1044 // JSON with a quit event when the actor is touched
1047 " \"arbitarysection\":\n"
1049 " \"type\": \"Actor\",\n"
1050 " \"name\": \"actor\",\n"
1051 " \"size\": [100,100,1],\n"
1052 " \"parentOrigin\": \"TOP_LEFT\",\n"
1053 " \"anchorPoint\": \"TOP_LEFT\",\n"
1055 " \"type\": \"Actor\",\n"
1056 " \"name\": \"subActor\",\n"
1057 " \"visible\": false\n"
1059 " \"signals\": [{\n"
1060 " \"name\": \"touched\",\n"
1061 " \"action\": \"hide\",\n"
1062 " \"actor\": \"actor\",\n"
1063 " \"childActor\": \"subActor\"\n"
1069 Builder builder = Builder::New();
1070 builder.LoadFromString( json );
1071 builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1073 // Render and notify
1074 application.SendNotification();
1075 application.Render();
1077 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1078 DALI_TEST_CHECK( actor );
1080 DALI_TEST_CHECK( !actor.IsVisible() );
1085 int UtcDaliBuilderFrameBufferP(void)
1087 ToolkitTestApplication application;
1089 // JSON with a quit event when the actor is touched
1094 " \"FB_WIDTH\": 200.0,\n"
1095 " \"FB_HEIGHT\": 200.0,\n"
1096 " \"FB_SIZE\": [200,200],\n"
1097 " \"FB_ASPECT_RATIO\": 1\n"
1101 " \"type\": \"ImageView\",\n"
1102 " \"name\": \"fbOnStage\",\n"
1103 " \"position\": [\n"
1104 " 0.40461349487305,\n"
1108 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1109 " \"size\": [300, 300, 0],\n"
1110 " \"image\": \"fb0\",\n"
1111 " \"clearColor\": [1,0,0,1]\n"
1114 " \"type\": \"ImageView\",\n"
1115 " \"name\": \"Image1\",\n"
1116 " \"size\": [200, 200, 0],\n"
1117 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1118 " \"effect\": \"Ripple2D\",\n"
1120 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1124 " \"name\": \"onStage\",\n"
1125 " \"action\": \"play\",\n"
1126 " \"animation\": \"Animation_1\"\n"
1131 " \"type\":\"CameraActor\",\n"
1132 " \"name\":\"fbCam\",\n"
1133 " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1134 " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1135 " \"fieldOfView\": 0.785,\n"
1136 " \"invertYAxis\": true\n"
1139 " \"frameBufferImages\":\n"
1143 " \"type\": \"FrameBufferImage\",\n"
1144 " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1145 " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1148 " \"renderTasks\":\n"
1153 " \"sourceActor\": \"fbOnStage\"\n"
1156 " \"sourceActor\": \"Image1\",\n"
1157 " \"targetFrameBuffer\": \"fb0\",\n"
1158 " \"viewportSize\":\"{FB_SIZE}\",\n"
1159 " \"cameraActor\":\"fbCam\"\n"
1164 " \"animations\": {\n"
1165 " \"Animation_1\": {\n"
1167 " \"properties\": [\n"
1169 " \"actor\": \"Image1\",\n"
1170 " \"property\": \"uTime\",\n"
1171 " \"value\": 10.0,\n"
1172 " \"alphaFunction\": \"LINEAR\",\n"
1173 " \"timePeriod\": {\n"
1175 " \"duration\": 10.0\n"
1177 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1182 " \"shaderEffects\": {\n"
1183 " \"Ripple2D\": {\n"
1185 " \"vertexPrefix\": \"\",\n"
1186 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1187 " \"fragmentPrefix\": \"\",\n"
1188 " \"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"
1189 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1191 " \"geometryHints\": \"HINT_NONE\",\n"
1192 " \"gridDensity\": 0,\n"
1193 " \"loop\": true,\n"
1194 " \"uAmplitude\": 0.02,\n"
1200 Builder builder = Builder::New();
1202 // frame buffer coverage
1203 builder.LoadFromString( json );
1205 // Render and notify
1206 application.SendNotification();
1207 application.Render();
1209 Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1210 DALI_TEST_CHECK( frameBuffer );
1212 Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1213 DALI_TEST_CHECK( frameBuffer2 );
1214 DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1216 DALI_TEST_CHECK( true );
1221 int UtcDaliBuilderPathConstraintsP(void)
1223 ToolkitTestApplication application;
1225 // JSON with a quit event when the actor is touched
1230 " \"FB_WIDTH\": 200.0,\n"
1231 " \"FB_HEIGHT\": 200.0,\n"
1232 " \"FB_SIZE\": [200,200],\n"
1233 " \"FB_ASPECT_RATIO\": 1\n"
1237 " \"type\": \"ImageView\",\n"
1238 " \"name\": \"Image1\",\n"
1239 " \"size\": [200, 200, 0],\n"
1240 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1241 " \"effect\": \"Ripple2D\",\n"
1243 " \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1247 " \"name\": \"onStage\",\n"
1248 " \"action\": \"play\",\n"
1249 " \"animation\": \"pathAnimation\"\n"
1252 " \"name\": \"onStage\",\n"
1253 " \"action\": \"applyConstraint\",\n"
1254 " \"constrainer\": \"constrainer0\",\n"
1255 " \"properties\":\n"
1258 " \"source\": \"Image1\",\n"
1259 " \"sourceProperty\": \"positionX\",\n"
1260 " \"target\": \"Image1\",\n"
1261 " \"targetProperty\": \"colorRed\",\n"
1262 " \"range\": [-300,300]\n"
1267 " \"name\": \"onStage\",\n"
1268 " \"action\": \"applyConstraint\",\n"
1269 " \"constrainer\": \"constrainer1\",\n"
1270 " \"properties\":\n"
1273 " \"source\": \"Image1\",\n"
1274 " \"sourceProperty\": \"positionX\",\n"
1275 " \"target\": \"Image1\",\n"
1276 " \"targetProperty\": \"colorBlue\",\n"
1277 " \"range\": [-300,300]\n"
1288 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1289 " \"curvature\":0.35\n"
1292 " \"constrainers\":\n"
1294 " \"constrainer0\":\n"
1296 " \"type\": \"PathConstrainer\",\n"
1297 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1298 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1300 " \"constrainer1\":\n"
1302 " \"type\": \"LinearConstrainer\",\n"
1303 " \"value\": [ 0, 0, 0 ]\n"
1306 " \"animations\": {\n"
1307 " \"pathAnimation\": {\n"
1308 " \"duration\": 3.0,\n"
1309 " \"properties\":\n"
1311 " \"actor\": \"Image1\",\n"
1312 " \"path\":\"path0\",\n"
1313 " \"forward\":[1,0,0],\n"
1314 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1315 " \"timePeriod\": {\n"
1317 " \"duration\": 3\n"
1321 " \"actor\": \"Image1\",\n"
1322 " \"property\": \"uTime\",\n"
1323 " \"value\": 10.0,\n"
1324 " \"alphaFunction\": \"LINEAR\",\n"
1325 " \"timePeriod\": {\n"
1327 " \"duration\": 10.0\n"
1329 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1332 " \"Animation_1\": {\n"
1334 " \"properties\": [\n"
1336 " \"actor\": \"Image1\",\n"
1337 " \"property\": \"uTime\",\n"
1338 " \"value\": 10.0,\n"
1339 " \"alphaFunction\": \"LINEAR\",\n"
1340 " \"timePeriod\": {\n"
1342 " \"duration\": 10.0\n"
1344 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1349 " \"shaderEffects\": {\n"
1350 " \"Ripple2D\": {\n"
1352 " \"vertexPrefix\": \"\",\n"
1353 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1354 " \"fragmentPrefix\": \"\",\n"
1355 " \"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"
1356 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1358 " \"geometryHints\": \"HINT_NONE\",\n"
1359 " \"gridDensity\": 0,\n"
1360 " \"loop\": true,\n"
1361 " \"uAmplitude\": 0.02,\n"
1367 Builder builder = Builder::New();
1369 // frame buffer coverage
1370 builder.LoadFromString( json );
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 Dali::Path path = builder.GetPath( "path0" );
1377 DALI_TEST_CHECK( path );
1379 Dali::Path path2 = builder.GetPath( "path0" );
1380 DALI_TEST_CHECK( path2 );
1381 DALI_TEST_CHECK( path == path2 );
1383 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1384 DALI_TEST_CHECK( constrainer0 );
1386 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1387 DALI_TEST_CHECK( constrainer0_2 );
1388 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1390 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1391 DALI_TEST_CHECK( constrainer1 );
1393 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1394 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1399 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1401 Property::Value* value = xMap->Find( xKey ); \
1402 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1403 if( value != NULL ) \
1405 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1407 value->Get(result); \
1408 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1409 std::ostringstream oss; \
1410 oss << "Animation element " << xKey << "= " << result << std::endl; \
1411 tet_printf( oss.str().c_str() ); \
1415 tet_printf("Can't find map element " xKey "\n"); \
1420 int UtcDaliBuilderMapping01(void)
1422 ToolkitTestApplication application;
1428 " \"buttonPressFadeOut\":{\n"
1429 " \"alphaFunction\":\"EASE_OUT\",\n"
1430 " \"timePeriod\":{\n"
1432 " \"duration\":0.4\n"
1435 " \"buttonPressFadeIn\":{\n"
1436 " \"alphaFunction\":\"EASE_IN\",\n"
1437 " \"timePeriod\":{\n"
1439 " \"duration\":0.5\n"
1442 " \"transition:buttonPressed\":\n"
1445 " \"target\": \"unselectedBackgroundRenderer\",\n"
1446 " \"property\": \"opacity\",\n"
1448 " \"animator\":\"<buttonPressFadeOut>\"\n"
1451 " \"transition:buttonReleased\":\n"
1454 " \"target\": \"unselectedBackgroundRenderer\",\n"
1455 " \"property\": \"opacity\",\n"
1457 " \"animator\":\"<buttonPressFadeIn>\"\n"
1460 " \"target\": \"unselectedForegroundRenderer\",\n"
1461 " \"property\": \"scale\",\n"
1462 " \"value\": [ 1, 1, 1 ],\n"
1463 " \"animator\":\"<buttonPressFadeIn>\"\n"
1466 " \"target\": \"selectedBackgroundRenderer\",\n"
1467 " \"property\": \"opacity\",\n"
1469 " \"animator\": \"<buttonPressFadeOut>\"\n"
1472 " \"target\": \"selectedForegroundRenderer\",\n"
1473 " \"property\": \"scale\",\n"
1474 " \"value\": [ 0, 0, 0 ],\n"
1475 " \"animator\":\"<buttonPressFadeOut>\"\n"
1481 " \"testbutton\":\n"
1483 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1484 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1489 Builder builder = Builder::New();
1490 builder.LoadFromString( json );
1492 Test::TestButton testButton = Test::TestButton::New();
1493 Stage::GetCurrent().Add( testButton );
1495 // Render and notify
1496 application.SendNotification();
1497 application.Render();
1499 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1501 // Now check that it has loaded the transition correctly:
1502 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1503 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1504 Property::Array* array = transition.GetArray();
1506 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1507 Property::Value element = array->GetElementAt(0);
1508 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1509 Property::Map* map = element.GetMap();
1511 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1512 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1513 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1514 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1515 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 Stage::GetCurrent().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);