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 <dali/devel-api/object/type-registry-helper.h>
25 #include <test-button.h>
26 #include <test-animation-data.h>
28 #define STRINGIFY(A)#A
31 using namespace Toolkit;
36 std::string ReplaceQuotes(const std::string &in_s)
39 // wrong as no embedded quote but had regex link problems
40 std::replace(s.begin(), s.end(), '\'', '"');
46 BuilderFunctor( bool& called ) : mCalled( called )
63 void builder_startup(void)
65 test_return_value = TET_UNDEF;
68 void builder_cleanup(void)
70 test_return_value = TET_PASS;
73 int UtcDaliBuilderQuitSignal(void)
75 ToolkitTestApplication application;
77 // JSON with a quit event when the actor is touched
82 "\"type\": \"Actor\","
83 "\"size\": [100,100,1],"
84 "\"parentOrigin\": \"TOP_LEFT\","
85 "\"anchorPoint\": \"TOP_LEFT\","
87 "\"name\": \"touched\","
88 "\"action\": \"quit\""
93 Builder builder = Builder::New();
94 builder.LoadFromString( json );
95 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
97 // Connect to builder's quit signal
98 bool functorCalled( false );
99 builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
102 application.SendNotification();
103 application.Render();
105 // Emit touch event and check that our quit method is called
106 Integration::TouchEvent touchEvent;
107 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
108 application.ProcessEvent( touchEvent );
109 DALI_TEST_CHECK( functorCalled );
115 int UtcDaliBuilderAnimationP(void)
117 ToolkitTestApplication application;
119 // JSON with a quit event when the actor is touched
124 " \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
130 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
131 " \"curvature\":0.35"
137 " \"endAction\": \"BAKE\","
138 " \"disconnectAction\": \"BAKE\","
141 " \"actor\": \"greeting\","
142 " \"property\": \"position\","
143 " \"value\": [300, 300, -1000],"
144 " \"alphaFunction\": \"{ALPHA_FUNCTION}\","
145 " \"relative\": true,"
152 " \"actor\": \"greeting\","
153 " \"property\": \"visible\","
154 " \"alphaFunction\": \"LINEAR\","
158 " \"actor\": \"greeting\","
159 " \"property\": \"sizeWidth\","
160 " \"alphaFunction\": \"REVERSE\","
164 " \"actor\": \"greeting\","
165 " \"property\": \"orientation\","
166 " \"alphaFunction\": \"EASE_IN\","
167 " \"value\": [10.0,20.0,30.0]"
170 " \"actor\": \"greeting\","
171 " \"property\": \"orientation\","
172 " \"alphaFunction\": \"EASE_OUT\","
173 " \"value\": [0.0, 0.0, 0.0, 1.0]"
176 " \"actor\": \"greeting\","
177 " \"property\": \"orientation\","
178 " \"alphaFunction\": \"EASE_IN_OUT\","
179 " \"value\": [0.0, 0.0, 0.0, 1.0]"
182 " \"actor\": \"greeting\","
183 " \"property\": \"orientation\","
184 " \"alphaFunction\": \"EASE_IN_SINE\","
185 " \"value\": [0.0, 0.0, 0.0, 1.0]"
188 " \"actor\": \"greeting\","
189 " \"property\": \"orientation\","
190 " \"alphaFunction\": \"EASE_OUT_SINE\","
191 " \"value\": [0.0, 0.0, 0.0, 1.0]"
194 " \"actor\": \"greeting\","
195 " \"property\": \"orientation\","
196 " \"alphaFunction\": \"EASE_IN_OUT_SINE\","
197 " \"value\": [0.0, 0.0, 0.0, 1.0]"
200 " \"actor\": \"greeting\","
201 " \"property\": \"orientation\","
202 " \"alphaFunction\": \"BOUNCE\","
203 " \"value\": [0.0, 0.0, 0.0, 1.0]"
206 " \"actor\": \"greeting\","
207 " \"property\": \"orientation\","
208 " \"alphaFunction\": \"SIN\","
209 " \"value\": [0.0, 0.0, 0.0, 1.0]"
212 " \"actor\": \"greeting\","
213 " \"property\": \"orientation\","
214 " \"alphaFunction\": \"EASE_OUT_BACK\","
215 " \"value\": [0.0, 0.0, 0.0, 1.0]"
219 " \"pathAnimation\": {"
220 " \"duration\": 3.0,"
221 " \"endAction\": \"DISCARD\","
222 " \"disconnectAction\": \"BAKE_FINAL\","
223 " \"properties\": [{"
224 " \"actor\": \"greeting\","
225 " \"path\":\"path0\","
226 " \"forward\":[1,0,0],"
227 " \"alphaFunction\": \"EASE_IN_OUT\","
236 " \"name\": \"greeting\","
237 " \"type\": \"TextLabel\","
238 " \"text\": \"Touch me\","
239 " \"styles\": [\"basicText\"],"
240 " \"position\": [0, -120, 0],"
241 " \"size\": [200, 200, 1],"
242 " \"orientation\": [0, 0, 30],"
244 " \"name\": \"touched\","
245 " \"action\": \"play\","
246 " \"animation\": \"animate\""
251 Builder builder = Builder::New();
252 builder.LoadFromString( json );
253 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
255 Animation anim = builder.CreateAnimation("animate");
257 DALI_TEST_CHECK( anim );
260 map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
261 anim = builder.CreateAnimation("animate", map);
263 DALI_TEST_CHECK( anim );
265 anim = builder.CreateAnimation("pathAnimation");
267 DALI_TEST_CHECK( anim );
270 // Emit touch event and check that our quit method is called
271 Integration::TouchEvent touchEvent;
272 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
273 application.ProcessEvent( touchEvent );
276 application.SendNotification();
277 application.Render();
283 int UtcDaliBuilderAnimationN(void)
285 ToolkitTestApplication application;
287 // JSON with a quit event when the actor is touched
292 " \"TEXT\": \"Touch Me\","
293 " \"NAME\": \"greeting\" "
299 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
300 " \"curvature\":0.35"
306 " \"endAction\": \"BAKE\","
307 " \"disconnectAction\": \"BAKE\","
310 " \"actor\": \"{NAME}\","
311 " \"property\": \"positioninvalid\","
312 " \"value\": [300, 300, -1000],"
313 " \"alphaFunction\": \"EASE_IN_OUT\","
314 " \"relative\": true,"
324 " \"endAction\": \"BAKE\","
325 " \"disconnectAction\": \"BAKE\","
328 " \"actor\": \"{NAME}\","
329 " \"property\": \"positioninvalid\","
330 " \"value\": [300, 300, -1000],"
331 " \"alphaFunction\": \"EGGS_OVER_EASY\","
332 " \"relative\": true,"
340 " \"pathAnimation\": {"
341 " \"duration\": 3.0,"
342 " \"endAction\": \"DISCARD\","
343 " \"disconnectAction\": \"BAKE_FINAL\","
344 " \"properties\": [{"
345 " \"actor\": \"greeting\","
346 " \"path\":\"pathDoesntExist\","
347 " \"forward\":[1,0,0],"
348 " \"alphaFunction\": \"EASE_IN_OUT\","
357 " \"name\": \"greeting\","
358 " \"type\": \"TextLabel\","
359 " \"text\": \"Touch me\","
360 " \"styles\": [\"basicText\"],"
361 " \"position\": [0, -120, 0],"
362 " \"size\": [200, 200, 1],"
363 " \"orientation\": [0, 0, 30],"
365 " \"name\": \"touched\","
366 " \"action\": \"play\","
367 " \"animation\": \"animate\""
371 " \"name\": \"greeting2\","
372 " \"type\": \"TextLabel\","
373 " \"text\": \"Touch me\""
378 Builder builder = Builder::New();
379 builder.LoadFromString( json );
380 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
382 Animation anim = builder.CreateAnimation("animate");
384 // log warning line coverage
385 anim = builder.CreateAnimation("pathAnimation");
386 DALI_TEST_CHECK(anim);
388 anim = builder.CreateAnimation("animate");
389 DALI_TEST_CHECK(anim);
391 anim = builder.CreateAnimation("animate2");
392 DALI_TEST_CHECK(anim);
394 // create referencing a different actor aka animation templates
396 map["NAME"] = "greeting2";
397 anim = builder.CreateAnimation("animate2", map);
398 DALI_TEST_CHECK(anim);
400 // alternative actor to use for FindChildByName
401 anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
402 DALI_TEST_CHECK(anim);
404 // alternative actor to use for FindChildByName
405 anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
406 DALI_TEST_CHECK(anim);
413 int UtcDaliBuilderConstantsP(void)
415 ToolkitTestApplication application;
417 // JSON with a quit event when the actor is touched
422 " \"IMAGE_PATH\": \"apath\","
424 " \"ANCHOR\": \"TOP_LEFT\","
425 " \"PADDING\": [1,2,3,4]"
429 " \"type\": \"ImageActor\","
430 " \"name\": \"{NAME}\","
431 " \"size\": [100,100,1],"
432 " \"parentOrigin\": \"TOP_LEFT\","
433 " \"anchorPoint\": \"{ANCHOR}\","
434 " \"padding\": \"{PADDING}\","
435 " \"image\": { \"filename\": \"dir/{IMAGE_PATH}\" },"
436 " \"sizeWidth\": \"{WIDTH}\","
438 " \"name\": \"touched\","
439 " \"action\": \"quit\""
445 Builder builder = Builder::New();
446 builder.LoadFromString( json );
448 builder.AddConstant( "NAME", "image" );
450 Property::Map map = builder.GetConstants();
452 Dali::Property::Value* pValue = map.Find( "NAME" );
454 DALI_TEST_CHECK( pValue );
456 pValue = map.Find( "IMAGE_PATH" );
458 DALI_TEST_CHECK( pValue );
460 Dali::Property::Value value = builder.GetConstant( "WIDTH" );
462 DALI_TEST_CHECK( value.GetType() != Property::NONE );
464 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
465 DALI_TEST_CHECK( builder );
467 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
468 DALI_TEST_CHECK( actor );
473 int UtcDaliBuilderTemplatesAndStylesP(void)
475 ToolkitTestApplication application;
477 // JSON with a quit event when the actor is touched
482 " \"SIZE\": [10,20,30]"
486 " \"imageStyle\": \n"
488 " \"color\": [1,0,0,1],\n"
490 " \"childImage\": {\n"
491 " \"color\": [0,1,0,1]\n"
498 " \"imageTree\": { \n"
499 " \"type\": \"ImageActor\",\n"
500 " \"styles\": [\"imageStyle\"],\n"
501 " \"name\": \"image\",\n"
502 " \"size\": \"{SIZE}\",\n"
504 " \"name\": \"touched\",\n"
505 " \"action\": \"quit\"\n"
509 " \"type\":\"ImageActor\",\n"
510 " \"name\":\"childImage\" \n"
517 " \"type\": \"imageTree\","
518 " \"size\": [100,100,1]"
523 std::string stylejson(
525 " \"color\": [1,0,0,1],\n"
527 " \"childImage\": {\n"
528 " \"color\": [0,1,0,1]\n"
534 std::string templatejson(
536 " \"type\": \"ImageActor\",\n"
537 " \"styles\": [\"imageStyle\"],\n"
538 " \"name\": \"image\",\n"
539 " \"size\": \"{SIZE}\",\n"
541 " \"name\": \"touched\",\n"
542 " \"action\": \"quit\"\n"
546 " \"type\":\"ImageActor\",\n"
547 " \"name\":\"childImage\" \n"
553 Builder builder = Builder::New();
554 builder.LoadFromString( json );
556 ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) );
557 DALI_TEST_CHECK( actor );
559 Dali::Property::Map map;
560 map["SIZE"] = Vector3(100,100,1);
561 actor = ImageActor::DownCast( builder.Create( "imageTree", map ) );
562 DALI_TEST_CHECK( actor );
564 // create from json snippet
565 actor = ImageActor::DownCast( builder.CreateFromJson( templatejson ) );
566 DALI_TEST_CHECK( actor );
569 // NB: already applied in create
570 DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle", actor ) );
572 // apply from json snippet
573 DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
578 int UtcDaliBuilderRenderTasksP(void)
580 ToolkitTestApplication application;
582 // JSON with a quit event when the actor is touched
588 " \"sourceActor\": \"image\",\n"
589 " \"cameraActor\": \"camera\" \n"
595 " \"type\": \"CameraActor\",\n"
596 " \"name\": \"image\"\n"
599 " \"type\": \"ImageActor\",\n"
600 " \"name\": \"image\",\n"
601 " \"size\": [100,100,1],\n"
603 " \"name\": \"touched\",\n"
604 " \"action\": \"quit\"\n"
608 " \"type\":\"ImageActor\",\n"
609 " \"name\":\"childImage\" \n"
617 Builder builder = Builder::New();
618 builder.LoadFromString( json );
620 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
623 builder.CreateRenderTask( "task0" );
625 DALI_TEST_CHECK( count <
626 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
631 int UtcDaliBuilderChildActionP(void)
633 ToolkitTestApplication application;
635 // JSON with a quit event when the actor is touched
640 " \"type\": \"Actor\",\n"
641 " \"name\": \"actor\",\n"
642 " \"size\": [100,100,1],\n"
643 " \"parentOrigin\": \"TOP_LEFT\",\n"
644 " \"anchorPoint\": \"TOP_LEFT\",\n"
646 " \"type\": \"Actor\",\n"
647 " \"name\": \"subActor\"\n"
650 " \"name\": \"touched\",\n"
651 " \"action\": \"hide\",\n"
652 " \"actor\": \"actor\",\n"
653 " \"childActor\": \"subActor\"\n"
659 Builder builder = Builder::New();
660 builder.LoadFromString( json );
661 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
664 application.SendNotification();
665 application.Render();
667 // Emit touch event and check that our quit method is called
668 Integration::TouchEvent touchEvent;
669 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
670 application.ProcessEvent( touchEvent );
673 application.SendNotification();
674 application.Render();
676 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
677 DALI_TEST_CHECK( actor );
679 DALI_TEST_CHECK( !actor.IsVisible() );
684 int UtcDaliBuilderSetPropertyActionP(void)
686 ToolkitTestApplication application;
688 // JSON with a quit event when the actor is touched
693 " \"type\": \"Actor\",\n"
694 " \"name\": \"actor\",\n"
695 " \"size\": [100,100,1],\n"
696 " \"parentOrigin\": \"TOP_LEFT\",\n"
697 " \"anchorPoint\": \"TOP_LEFT\",\n"
699 " \"type\": \"Actor\",\n"
700 " \"name\": \"subActor\"\n"
703 " \"name\": \"touched\",\n"
704 " \"action\": \"set\",\n"
705 " \"actor\": \"subActor\",\n"
706 " \"property\": \"visible\",\n"
707 " \"value\": false\n"
713 Builder builder = Builder::New();
714 builder.LoadFromString( json );
715 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
718 application.SendNotification();
719 application.Render();
721 // Emit touch event and check that our quit method is called
722 Integration::TouchEvent touchEvent;
723 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
724 application.ProcessEvent( touchEvent );
727 application.SendNotification();
728 application.Render();
730 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
731 DALI_TEST_CHECK( actor );
733 DALI_TEST_CHECK( !actor.IsVisible() );
738 int UtcDaliBuilderGenericActionP(void)
740 ToolkitTestApplication application;
742 // JSON with a quit event when the actor is touched
747 " \"type\": \"Actor\",\n"
748 " \"name\": \"actor\",\n"
749 " \"size\": [100,100,1],\n"
750 " \"parentOrigin\": \"TOP_LEFT\",\n"
751 " \"anchorPoint\": \"TOP_LEFT\",\n"
753 " \"type\": \"Actor\",\n"
754 " \"name\": \"subActor\"\n"
757 " \"name\": \"touched\",\n"
758 " \"action\": \"hide\"\n"
764 Builder builder = Builder::New();
765 builder.LoadFromString( json );
766 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
769 application.SendNotification();
770 application.Render();
772 // Emit touch event and check that our quit method is called
773 Integration::TouchEvent touchEvent;
774 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
775 application.ProcessEvent( touchEvent );
778 application.SendNotification();
779 application.Render();
781 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
782 DALI_TEST_CHECK( actor );
784 DALI_TEST_CHECK( !actor.IsVisible() );
789 int UtcDaliBuilderPropertyNotificationP(void)
791 ToolkitTestApplication application;
793 // JSON with a quit event when the actor is touched
798 " \"type\": \"Actor\",\n"
799 " \"name\": \"actor\",\n"
800 " \"size\": [100,100,1],\n"
801 " \"parentOrigin\": \"TOP_LEFT\",\n"
802 " \"anchorPoint\": \"TOP_LEFT\",\n"
804 " \"type\": \"Actor\",\n"
805 " \"name\": \"subActor\"\n"
808 " \"name\": \"touched\",\n"
809 " \"action\": \"hide\"\n"
811 " \"notifications\": [{\n"
812 " \"property\": \"visible\",\n"
813 " \"condition\": \"False\",\n"
814 " \"action\": \"show\"\n"
820 Builder builder = Builder::New();
821 builder.LoadFromString( json );
822 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
825 application.SendNotification();
826 application.Render();
828 // Emit touch event and check that our quit method is called
829 Integration::TouchEvent touchEvent;
830 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
831 application.ProcessEvent( touchEvent );
834 application.SendNotification();
835 application.Render();
838 application.SendNotification();
839 application.Render();
841 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
842 DALI_TEST_CHECK( actor );
844 DALI_TEST_CHECK( actor.IsVisible() );
849 int UtcDaliBuilderCustomPropertyP(void)
851 ToolkitTestApplication application;
853 // JSON with a quit event when the actor is touched
858 " \"imageTree\": { \n"
859 " \"type\": \"ImageActor\",\n"
860 " \"name\": \"image\",\n"
861 " \"size\": [100,100,1],\n"
863 " \"name\": \"touched\",\n"
864 " \"action\": \"quit\"\n"
866 " \"customProperties\": {\n"
867 " \"newproperty\": true\n"
871 " \"type\":\"ImageActor\",\n"
872 " \"name\":\"childImage\" \n"
880 Builder builder = Builder::New();
881 builder.LoadFromString( json );
883 ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) );
884 DALI_TEST_CHECK( actor );
886 // NB: already applied in create
887 Property::Index index = actor.GetPropertyIndex("newproperty");
888 DALI_TEST_CHECK( Property::INVALID_INDEX != index );
889 Property::Value value = actor.GetProperty(index);
890 DALI_TEST_CHECK( value.Get<bool>() == true );
895 int UtcDaliBuilderShaderEffectP(void)
897 ToolkitTestApplication application;
899 // JSON with a quit event when the actor is touched
904 " \"type\": \"ImageActor\",\n"
905 " \"name\": \"Image1\",\n"
907 " 0.40461349487305,\n"
911 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
912 " \"size\": [200, 200, 0],\n"
913 " \"effect\": \"Ripple2D\",\n"
915 " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
918 " \"loadPolicy\": \"IMMEDIATE\",\n"
919 " \"releasePolicy\": \"NEVER\"\n"
923 " \"name\": \"onStage\",\n"
924 " \"action\": \"play\",\n"
925 " \"animation\": \"Animation_1\"\n"
931 " \"animations\": {\n"
932 " \"Animation_1\": {\n"
934 " \"properties\": [\n"
936 " \"actor\": \"Image1\",\n"
937 " \"property\": \"uTime\",\n"
938 " \"value\": 10.0,\n"
939 " \"alphaFunction\": \"LINEAR\",\n"
940 " \"timePeriod\": {\n"
942 " \"duration\": 10.0\n"
944 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
949 " \"shaderEffects\": {\n"
952 " \"vertexPrefix\": \"\",\n"
953 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
954 " \"fragmentPrefix\": \"\",\n"
955 " \"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"
956 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
958 " \"geometryHints\": \"HINT_NONE\",\n"
959 " \"gridDensity\": 0,\n"
961 " \"uAmplitude\": 0.02,\n"
969 Builder builder = Builder::New();
970 builder.LoadFromString( json );
972 ShaderEffect effect = builder.GetShaderEffect("Ripple2D");
975 DALI_TEST_CHECK( effect );
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 );
1021 int UtcDaliBuilderShaderEffect2P(void)
1023 ToolkitTestApplication application;
1025 // JSON with a quit event when the actor is touched
1030 " \"imageTree\": { \n"
1031 " \"type\": \"ImageActor\",\n"
1032 " \"size\": [100,100,1],\n"
1033 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1034 " \"position\": [\n"
1035 " 0.40461349487305,\n"
1039 " \"signals\": [{\n"
1040 " \"name\": \"touched\",\n"
1041 " \"action\": \"quit\"\n"
1045 " \"type\":\"ImageActor\",\n"
1046 " \"name\":\"childImage\" \n"
1053 " \"type\": \"imageTree\",\n"
1054 " \"name\": \"Image1\",\n"
1055 " \"effect\": \"Ripple2D\",\n"
1056 " \"image\": \"offscreen\""
1059 " \"shaderEffects\": {\n"
1060 " \"Ripple2D\": {\n"
1062 " \"vertexPrefix\": \"\",\n"
1063 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1064 " \"fragmentPrefix\": \"\",\n"
1065 " \"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"
1066 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1068 " \"geometryHints\": \"HINT_NONE\",\n"
1069 " \"gridDensity\": 0,\n"
1070 " \"loop\": true,\n"
1071 " \"uAmplitude\": 0.02,\n"
1075 " \"frameBufferImages\": {\n"
1076 " \"offscreen\": {\n"
1077 " \"type\": \"FrameBufferImage\","
1078 " \"pixelFormat\":\"RGBA8888\","
1087 Builder builder = Builder::New();
1088 builder.LoadFromString( json );
1091 DALI_TEST_CHECK( true );
1096 int UtcDaliBuilderAddActorsP(void)
1098 ToolkitTestApplication application;
1100 // JSON with a quit event when the actor is touched
1103 " \"arbitarysection\":\n"
1105 " \"type\": \"Actor\",\n"
1106 " \"name\": \"actor\",\n"
1107 " \"size\": [100,100,1],\n"
1108 " \"parentOrigin\": \"TOP_LEFT\",\n"
1109 " \"anchorPoint\": \"TOP_LEFT\",\n"
1111 " \"type\": \"Actor\",\n"
1112 " \"name\": \"subActor\",\n"
1113 " \"visible\": false\n"
1115 " \"signals\": [{\n"
1116 " \"name\": \"touched\",\n"
1117 " \"action\": \"hide\",\n"
1118 " \"actor\": \"actor\",\n"
1119 " \"childActor\": \"subActor\"\n"
1125 Builder builder = Builder::New();
1126 builder.LoadFromString( json );
1127 builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1129 // Render and notify
1130 application.SendNotification();
1131 application.Render();
1133 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1134 DALI_TEST_CHECK( actor );
1136 DALI_TEST_CHECK( !actor.IsVisible() );
1141 int UtcDaliBuilderFrameBufferP(void)
1143 ToolkitTestApplication application;
1145 // JSON with a quit event when the actor is touched
1150 " \"FB_WIDTH\": 200.0,\n"
1151 " \"FB_HEIGHT\": 200.0,\n"
1152 " \"FB_SIZE\": [200,200],\n"
1153 " \"FB_ASPECT_RATIO\": 1\n"
1157 " \"type\": \"ImageActor\",\n"
1158 " \"name\": \"fbOnStage\",\n"
1159 " \"position\": [\n"
1160 " 0.40461349487305,\n"
1164 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1165 " \"size\": [300, 300, 0],\n"
1166 " \"image\": \"fb0\",\n"
1167 " \"clearColor\": [1,0,0,1]\n"
1170 " \"type\": \"ImageActor\",\n"
1171 " \"name\": \"Image1\",\n"
1172 " \"size\": [200, 200, 0],\n"
1173 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1174 " \"effect\": \"Ripple2D\",\n"
1176 " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1177 " \"width\": 200,\n"
1178 " \"height\": 80,\n"
1179 " \"loadPolicy\": \"IMMEDIATE\",\n"
1180 " \"releasePolicy\": \"NEVER\"\n"
1184 " \"name\": \"onStage\",\n"
1185 " \"action\": \"play\",\n"
1186 " \"animation\": \"Animation_1\"\n"
1191 " \"type\":\"CameraActor\",\n"
1192 " \"name\":\"fbCam\",\n"
1193 " \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1194 " \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1195 " \"fieldOfView\": 0.785,\n"
1196 " \"invertYAxis\": true\n"
1199 " \"frameBufferImages\":\n"
1203 " \"type\": \"FrameBufferImage\",\n"
1204 " \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1205 " \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1208 " \"renderTasks\":\n"
1213 " \"sourceActor\": \"fbOnStage\"\n"
1216 " \"sourceActor\": \"Image1\",\n"
1217 " \"targetFrameBuffer\": \"fb0\",\n"
1218 " \"viewportSize\":\"{FB_SIZE}\",\n"
1219 " \"cameraActor\":\"fbCam\"\n"
1224 " \"animations\": {\n"
1225 " \"Animation_1\": {\n"
1227 " \"properties\": [\n"
1229 " \"actor\": \"Image1\",\n"
1230 " \"property\": \"uTime\",\n"
1231 " \"value\": 10.0,\n"
1232 " \"alphaFunction\": \"LINEAR\",\n"
1233 " \"timePeriod\": {\n"
1235 " \"duration\": 10.0\n"
1237 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1242 " \"shaderEffects\": {\n"
1243 " \"Ripple2D\": {\n"
1245 " \"vertexPrefix\": \"\",\n"
1246 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1247 " \"fragmentPrefix\": \"\",\n"
1248 " \"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"
1249 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1251 " \"geometryHints\": \"HINT_NONE\",\n"
1252 " \"gridDensity\": 0,\n"
1253 " \"loop\": true,\n"
1254 " \"uAmplitude\": 0.02,\n"
1260 Builder builder = Builder::New();
1262 // frame buffer coverage
1263 builder.LoadFromString( json );
1265 // Render and notify
1266 application.SendNotification();
1267 application.Render();
1269 Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1270 DALI_TEST_CHECK( frameBuffer );
1272 Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1273 DALI_TEST_CHECK( frameBuffer2 );
1274 DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1276 DALI_TEST_CHECK( true );
1281 int UtcDaliBuilderPathConstraintsP(void)
1283 ToolkitTestApplication application;
1285 // JSON with a quit event when the actor is touched
1290 " \"FB_WIDTH\": 200.0,\n"
1291 " \"FB_HEIGHT\": 200.0,\n"
1292 " \"FB_SIZE\": [200,200],\n"
1293 " \"FB_ASPECT_RATIO\": 1\n"
1297 " \"type\": \"ImageActor\",\n"
1298 " \"name\": \"Image1\",\n"
1299 " \"size\": [200, 200, 0],\n"
1300 " \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1301 " \"effect\": \"Ripple2D\",\n"
1303 " \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1304 " \"width\": 200,\n"
1305 " \"height\": 80,\n"
1306 " \"loadPolicy\": \"IMMEDIATE\",\n"
1307 " \"releasePolicy\": \"NEVER\"\n"
1311 " \"name\": \"onStage\",\n"
1312 " \"action\": \"play\",\n"
1313 " \"animation\": \"pathAnimation\"\n"
1316 " \"name\": \"onStage\",\n"
1317 " \"action\": \"applyConstraint\",\n"
1318 " \"constrainer\": \"constrainer0\",\n"
1319 " \"properties\":\n"
1322 " \"source\": \"Image1\",\n"
1323 " \"sourceProperty\": \"positionX\",\n"
1324 " \"target\": \"Image1\",\n"
1325 " \"targetProperty\": \"colorRed\",\n"
1326 " \"range\": [-300,300]\n"
1331 " \"name\": \"onStage\",\n"
1332 " \"action\": \"applyConstraint\",\n"
1333 " \"constrainer\": \"constrainer1\",\n"
1334 " \"properties\":\n"
1337 " \"source\": \"Image1\",\n"
1338 " \"sourceProperty\": \"positionX\",\n"
1339 " \"target\": \"Image1\",\n"
1340 " \"targetProperty\": \"colorBlue\",\n"
1341 " \"range\": [-300,300]\n"
1352 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1353 " \"curvature\":0.35\n"
1356 " \"constrainers\":\n"
1358 " \"constrainer0\":\n"
1360 " \"type\": \"PathConstrainer\",\n"
1361 " \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1362 " \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1364 " \"constrainer1\":\n"
1366 " \"type\": \"LinearConstrainer\",\n"
1367 " \"value\": [ 0, 0, 0 ]\n"
1370 " \"animations\": {\n"
1371 " \"pathAnimation\": {\n"
1372 " \"duration\": 3.0,\n"
1373 " \"properties\":\n"
1375 " \"actor\": \"Image1\",\n"
1376 " \"path\":\"path0\",\n"
1377 " \"forward\":[1,0,0],\n"
1378 " \"alphaFunction\": \"EASE_IN_OUT\",\n"
1379 " \"timePeriod\": {\n"
1381 " \"duration\": 3\n"
1385 " \"actor\": \"Image1\",\n"
1386 " \"property\": \"uTime\",\n"
1387 " \"value\": 10.0,\n"
1388 " \"alphaFunction\": \"LINEAR\",\n"
1389 " \"timePeriod\": {\n"
1391 " \"duration\": 10.0\n"
1393 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1396 " \"Animation_1\": {\n"
1398 " \"properties\": [\n"
1400 " \"actor\": \"Image1\",\n"
1401 " \"property\": \"uTime\",\n"
1402 " \"value\": 10.0,\n"
1403 " \"alphaFunction\": \"LINEAR\",\n"
1404 " \"timePeriod\": {\n"
1406 " \"duration\": 10.0\n"
1408 " \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1413 " \"shaderEffects\": {\n"
1414 " \"Ripple2D\": {\n"
1416 " \"vertexPrefix\": \"\",\n"
1417 " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1418 " \"fragmentPrefix\": \"\",\n"
1419 " \"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"
1420 " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1422 " \"geometryHints\": \"HINT_NONE\",\n"
1423 " \"gridDensity\": 0,\n"
1424 " \"loop\": true,\n"
1425 " \"uAmplitude\": 0.02,\n"
1431 Builder builder = Builder::New();
1433 // frame buffer coverage
1434 builder.LoadFromString( json );
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 Dali::Path path = builder.GetPath( "path0" );
1441 DALI_TEST_CHECK( path );
1443 Dali::Path path2 = builder.GetPath( "path0" );
1444 DALI_TEST_CHECK( path2 );
1445 DALI_TEST_CHECK( path == path2 );
1447 Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1448 DALI_TEST_CHECK( constrainer0 );
1450 Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1451 DALI_TEST_CHECK( constrainer0_2 );
1452 DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1454 Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1455 DALI_TEST_CHECK( constrainer1 );
1457 Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1458 DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1463 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1465 Property::Value* value = xMap->Find( xKey ); \
1466 DALI_TEST_EQUALS( value==NULL, false, xLocation); \
1467 if( value != NULL ) \
1469 DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation ); \
1471 value->Get(result); \
1472 DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION ); \
1473 std::ostringstream oss; \
1474 oss << "Animation element " << xKey << "= " << result << std::endl; \
1475 tet_printf( oss.str().c_str() ); \
1479 tet_printf("Can't find map element " xKey "\n"); \
1484 int UtcDaliBuilderMapping01(void)
1486 ToolkitTestApplication application;
1492 " \"buttonPressFadeOut\":{\n"
1493 " \"alphaFunction\":\"EASE_OUT\",\n"
1494 " \"timePeriod\":{\n"
1496 " \"duration\":0.4\n"
1499 " \"buttonPressFadeIn\":{\n"
1500 " \"alphaFunction\":\"EASE_IN\",\n"
1501 " \"timePeriod\":{\n"
1503 " \"duration\":0.5\n"
1506 " \"transition:buttonPressed\":\n"
1509 " \"target\": \"unselectedBackgroundRenderer\",\n"
1510 " \"property\": \"opacity\",\n"
1512 " \"animator\":\"<buttonPressFadeOut>\"\n"
1515 " \"transition:buttonReleased\":\n"
1518 " \"target\": \"unselectedBackgroundRenderer\",\n"
1519 " \"property\": \"opacity\",\n"
1521 " \"animator\":\"<buttonPressFadeIn>\"\n"
1524 " \"target\": \"unselectedForegroundRenderer\",\n"
1525 " \"property\": \"scale\",\n"
1526 " \"value\": [ 1, 1, 1 ],\n"
1527 " \"animator\":\"<buttonPressFadeIn>\"\n"
1530 " \"target\": \"selectedBackgroundRenderer\",\n"
1531 " \"property\": \"opacity\",\n"
1533 " \"animator\": \"<buttonPressFadeOut>\"\n"
1536 " \"target\": \"selectedForegroundRenderer\",\n"
1537 " \"property\": \"scale\",\n"
1538 " \"value\": [ 0, 0, 0 ],\n"
1539 " \"animator\":\"<buttonPressFadeOut>\"\n"
1545 " \"testbutton\":\n"
1547 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1548 " \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1553 Builder builder = Builder::New();
1554 builder.LoadFromString( json );
1556 Test::TestButton testButton = Test::TestButton::New();
1557 Stage::GetCurrent().Add( testButton );
1559 // Render and notify
1560 application.SendNotification();
1561 application.Render();
1563 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1565 // Now check that it has loaded the transition correctly:
1566 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1567 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1568 Property::Array* array = transition.GetArray();
1570 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1571 Property::Value element = array->GetElementAt(0);
1572 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1573 Property::Map* map = element.GetMap();
1575 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1576 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1577 CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1578 CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1579 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1585 int UtcDaliBuilderMappingCycleCheck(void)
1587 ToolkitTestApplication application;
1593 " \"cyclicKey1\":\"<cyclicKey1>\",\n"
1594 " \"cyclicKey2\":\"<cyclicKey3>\",\n"
1595 " \"cyclicKey3\":\"<cyclicKey2>\",\n"
1597 " \"alphaFunction\":\"EASE_IN\",\n"
1598 " \"timePeriod\":{\n"
1599 " \"delay\":\"<cyclicKey3>\",\n"
1600 " \"duration\":0.6\n"
1603 " \"transition:buttonPressed\":\n"
1606 " \"target\": \"<cyclicKey1>\",\n"
1607 " \"property\": \"<cyclicKey2>\",\n"
1609 " \"animator\":\"<FadeOut>\"\n"
1615 " \"testbutton\":\n"
1617 " \"pressTransition\":\"<transition:buttonPressed>\",\n"
1618 " \"releaseTransition\":\"<cyclicKey2>\",\n"
1619 " \"disabledTransition\":\"<cyclicKey3>\",\n"
1620 " \"enabledTransition\":\"<unknownKey>\"\n"
1625 Builder builder = Builder::New();
1626 builder.LoadFromString( json );
1628 Test::TestButton testButton = Test::TestButton::New();
1629 Stage::GetCurrent().Add( testButton );
1631 // Render and notify
1632 application.SendNotification();
1633 application.Render();
1635 DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1637 // Now check that it has loaded the transition correctly:
1638 Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1639 DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1640 Property::Array* array = transition.GetArray();
1642 DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1643 Property::Value element = array->GetElementAt(0);
1644 DALI_TEST_CHECK( element.GetType() == Property::MAP );
1645 Property::Map* map = element.GetMap();
1647 CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1648 CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1649 CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);