Merge "Text decorator - It consumes tap, double tap and long press events on handles...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Builder.cpp
1 /*
2  * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
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>
26
27 #define STRINGIFY(A)#A
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 namespace
33 {
34
35 std::string ReplaceQuotes(const std::string &in_s)
36 {
37   std::string s(in_s);
38   // wrong as no embedded quote but had regex link problems
39   std::replace(s.begin(), s.end(), '\'', '"');
40   return s;
41 }
42
43 struct BuilderFunctor
44 {
45   BuilderFunctor( bool& called ) : mCalled( called )
46   {
47     mCalled = false;
48   }
49
50   void operator()()
51   {
52     mCalled = true;
53   }
54
55   bool& mCalled;
56 };
57
58 } // namespace
59
60
61
62 void builder_startup(void)
63 {
64   test_return_value = TET_UNDEF;
65 }
66
67 void builder_cleanup(void)
68 {
69   test_return_value = TET_PASS;
70 }
71
72 int UtcDaliBuilderQuitSignal(void)
73 {
74   ToolkitTestApplication application;
75
76   // JSON with a quit event when the actor is touched
77   std::string json(
78       "{"
79          "\"stage\":"
80          "[{"
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],"
88            "\"signals\": [{"
89              "\"name\": \"touch\","
90              "\"action\": \"quit\""
91            "}]"
92          "}]"
93       "}"
94   );
95   Builder builder = Builder::New();
96   builder.LoadFromString( json );
97   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
98
99   // Connect to builder's quit signal
100   bool functorCalled( false );
101   builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
102
103   // Render and notify
104   application.SendNotification();
105   application.Render();
106
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 );
115
116   END_TEST;
117 }
118
119
120 int UtcDaliBuilderAnimationP(void)
121 {
122   ToolkitTestApplication application;
123
124   // JSON with a quit event when the actor is touched
125   std::string json(
126         "{"
127         "   \"constants\":"
128         "   {"
129         "     \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
130         "   },"
131         "   \"paths\":"
132         "   {"
133         "     \"path0\":"
134         "     {"
135         "       \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
136         "       \"curvature\":0.35"
137         "     }"
138         "   },"
139         "  \"animations\": {"
140         "    \"animate\": {"
141         "      \"loop\": true,"
142         "      \"endAction\": \"BAKE\","
143         "      \"disconnectAction\": \"BAKE\","
144         "      \"properties\":"
145         "      [{"
146         "        \"actor\": \"greeting\","
147         "        \"property\": \"position\","
148         "        \"value\": [300, 300, -1000],"
149         "        \"alphaFunction\": \"{ALPHA_FUNCTION}\","
150         "        \"relative\": true,"
151         "        \"timePeriod\": {"
152         "          \"delay\": 0,"
153         "          \"duration\": 3"
154         "        }"
155         "      },"
156         "       {"
157         "         \"actor\": \"greeting\","
158         "         \"property\": \"visible\","
159         "         \"alphaFunction\": \"LINEAR\","
160         "         \"value\": true"
161         "       },"
162         "       {"
163         "         \"actor\": \"greeting\","
164         "         \"property\": \"sizeWidth\","
165         "         \"alphaFunction\": \"REVERSE\","
166         "         \"value\": 10.0"
167         "       },"
168         "       {"
169         "         \"actor\": \"greeting\","
170         "         \"property\": \"orientation\","
171         "         \"alphaFunction\": \"EASE_IN\","
172         "         \"value\": [10.0,20.0,30.0]"
173         "       },"
174         "       {"
175         "         \"actor\": \"greeting\","
176         "         \"property\": \"orientation\","
177         "         \"alphaFunction\": \"EASE_OUT\","
178         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
179         "       },"
180         "       {"
181         "         \"actor\": \"greeting\","
182         "         \"property\": \"orientation\","
183         "         \"alphaFunction\": \"EASE_IN_OUT\","
184         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
185         "       },"
186         "       {"
187         "         \"actor\": \"greeting\","
188         "         \"property\": \"orientation\","
189         "         \"alphaFunction\": \"EASE_IN_SINE\","
190         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
191         "       },"
192         "       {"
193         "         \"actor\": \"greeting\","
194         "         \"property\": \"orientation\","
195         "         \"alphaFunction\": \"EASE_OUT_SINE\","
196         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
197         "       },"
198         "       {"
199         "         \"actor\": \"greeting\","
200         "         \"property\": \"orientation\","
201         "         \"alphaFunction\": \"EASE_IN_OUT_SINE\","
202         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
203         "       },"
204         "       {"
205         "         \"actor\": \"greeting\","
206         "         \"property\": \"orientation\","
207         "         \"alphaFunction\": \"BOUNCE\","
208         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
209         "       },"
210         "       {"
211         "         \"actor\": \"greeting\","
212         "         \"property\": \"orientation\","
213         "         \"alphaFunction\": \"SIN\","
214         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
215         "       },"
216         "       {"
217         "         \"actor\": \"greeting\","
218         "         \"property\": \"orientation\","
219         "         \"alphaFunction\": \"EASE_OUT_BACK\","
220         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
221         "       }"
222         "      ]"
223         "    },"
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\","
233         "        \"timePeriod\": {"
234         "          \"delay\": 0,"
235         "          \"duration\": 3"
236         "        }"
237         "      }]"
238         "    }"
239         "  },"
240         "  \"stage\": [{"
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],"
248         "    \"signals\": [{"
249         "      \"name\": \"touch\","
250         "      \"action\": \"play\","
251         "      \"animation\": \"animate\""
252         "    }]"
253         "  }]"
254         "}");
255
256   Builder builder = Builder::New();
257   builder.LoadFromString( json );
258   builder.AddActors( Stage::GetCurrent().GetRootLayer() );
259
260   Animation anim = builder.CreateAnimation("animate");
261
262   DALI_TEST_CHECK( anim );
263
264   Property::Map map;
265   map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
266   anim = builder.CreateAnimation("animate", map);
267
268   DALI_TEST_CHECK( anim );
269
270   anim = builder.CreateAnimation("pathAnimation");
271
272   DALI_TEST_CHECK( anim );
273
274   // trigger play
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 );
282
283   // Render and notify
284   application.SendNotification();
285   application.Render();
286
287
288   END_TEST;
289 }
290
291 int UtcDaliBuilderAnimationN(void)
292 {
293   ToolkitTestApplication application;
294
295   // JSON with a quit event when the actor is touched
296   std::string json(
297         "{"
298         "   \"constants\":"
299         "   {"
300         "     \"TEXT\": \"Touch Me\","
301         "     \"NAME\": \"greeting\" "
302         "   },"
303         "   \"paths\":"
304         "   {"
305         "     \"path0\":"
306         "     {"
307         "       \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
308         "       \"curvature\":0.35"
309         "     }"
310         "   },"
311         "  \"animations\": {"
312         "    \"animate\": {"
313         "      \"loop\": true,"
314         "      \"endAction\": \"BAKE\","
315         "      \"disconnectAction\": \"BAKE\","
316         "      \"properties\":"
317         "      [{"
318         "        \"actor\": \"{NAME}\","
319         "        \"property\": \"positioninvalid\","
320         "        \"value\": [300, 300, -1000],"
321         "        \"alphaFunction\": \"EASE_IN_OUT\","
322         "        \"relative\": true,"
323         "        \"timePeriod\": {"
324         "          \"delay\": 0,"
325         "          \"duration\": 3"
326         "        }"
327         "      }"
328         "      ]"
329         "    },"
330         "    \"animate2\": {"
331         "      \"loop\": true,"
332         "      \"endAction\": \"BAKE\","
333         "      \"disconnectAction\": \"BAKE\","
334         "      \"properties\":"
335         "      [{"
336         "        \"actor\": \"{NAME}\","
337         "        \"property\": \"positioninvalid\","
338         "        \"value\": [300, 300, -1000],"
339         "        \"alphaFunction\": \"EGGS_OVER_EASY\","
340         "        \"relative\": true,"
341         "        \"timePeriod\": {"
342         "          \"delay\": 0,"
343         "          \"duration\": 3"
344         "        }"
345         "      }"
346         "      ]"
347         "    },"
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\","
357         "        \"timePeriod\": {"
358         "          \"delay\": 0,"
359         "          \"duration\": 3"
360         "        }"
361         "      }]"
362         "    }"
363         "  },"
364         "  \"stage\": [{"
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],"
372         "    \"signals\": [{"
373         "      \"name\": \"touch\","
374         "      \"action\": \"play\","
375         "      \"animation\": \"animate\""
376         "    }]"
377         "  },"
378         "  {"
379         "    \"name\": \"greeting2\","
380         "    \"type\": \"TextLabel\","
381         "    \"text\": \"Touch me\""
382         "  }]"
383         "}");
384
385
386   Builder builder = Builder::New();
387   builder.LoadFromString( json );
388   builder.AddActors( Stage::GetCurrent().GetRootLayer() );
389
390   Animation anim = builder.CreateAnimation("animate");
391
392   // log warning line coverage
393   anim = builder.CreateAnimation("pathAnimation");
394   DALI_TEST_CHECK(anim);
395
396   anim = builder.CreateAnimation("animate");
397   DALI_TEST_CHECK(anim);
398
399   anim = builder.CreateAnimation("animate2");
400   DALI_TEST_CHECK(anim);
401
402   // create referencing a different actor aka animation templates
403   Property::Map map;
404   map["NAME"] = "greeting2";
405   anim = builder.CreateAnimation("animate2", map);
406   DALI_TEST_CHECK(anim);
407
408   // alternative actor to use for FindChildByName
409   anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
410   DALI_TEST_CHECK(anim);
411
412   // alternative actor to use for FindChildByName
413   anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
414   DALI_TEST_CHECK(anim);
415
416
417   END_TEST;
418
419 }
420
421 int UtcDaliBuilderConstantsP(void)
422 {
423   ToolkitTestApplication application;
424
425   // JSON with a quit event when the actor is touched
426   std::string json(
427       "{"
428       "\"constants\":"
429       "{"
430       "  \"IMAGE_PATH\": \"apath\","
431       "  \"WIDTH\": 22.3,"
432       "  \"ANCHOR\": \"TOP_LEFT\","
433       "  \"PADDING\": [1,2,3,4]"
434       "},"
435       "\"stage\":"
436       "[{"
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}\","
445       "  \"signals\": [{"
446       "    \"name\": \"touch\","
447       "    \"action\": \"quit\""
448       "  }]"
449       "}]"
450       "}"
451   );
452
453   Builder builder = Builder::New();
454   builder.LoadFromString( json );
455
456   builder.AddConstant( "NAME", "image" );
457
458   Property::Map map = builder.GetConstants();
459
460   Dali::Property::Value* pValue = map.Find( "NAME" );
461
462   DALI_TEST_CHECK( pValue );
463
464   pValue = map.Find( "IMAGE_PATH" );
465
466   DALI_TEST_CHECK( pValue );
467
468   Dali::Property::Value value = builder.GetConstant( "WIDTH" );
469
470   DALI_TEST_CHECK( value.GetType() != Property::NONE );
471
472   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
473   DALI_TEST_CHECK( builder );
474
475   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
476   DALI_TEST_CHECK( actor );
477
478   END_TEST;
479 }
480
481 int UtcDaliBuilderTemplatesAndStylesP(void)
482 {
483   ToolkitTestApplication application;
484
485   // JSON with a quit event when the actor is touched
486   std::string json(
487       "{\n"
488       "\"constants\":"
489       "{"
490       "  \"SIZE\": [10,20,30]"
491       "},"
492       "\"styles\":\n"
493       "{\n"
494       "  \"imageStyle\": \n"
495       "  {\n"
496       "    \"color\": [1,0,0,1],\n"
497       "    \"actors\": {\n"
498       "      \"childImage\": {\n"
499       "        \"color\": \"34\"\n"
500       "      }\n"
501       "    }\n"
502       "  }\n"
503       "},\n"
504       "\"templates\":\n"
505       "{\n"
506       "  \"imageViewTemplate\": { \n"
507       "    \"type\": \"ImageView\",\n"
508       "    \"styles\": [\"imageStyle\"]\n"
509       "  },\n"
510       "  \"imageTree\": { \n"
511       "    \"type\": \"ImageView\",\n"
512       "    \"styles\": [\"imageStyle\"],\n"
513       "    \"name\": \"image\",\n"
514       "    \"size\": \"{SIZE}\",\n"
515       "    \"signals\": [{\n"
516       "      \"name\": \"touch\",\n"
517       "      \"action\": \"quit\"\n"
518       "    }],\n"
519       "    \"actors\": [\n"
520       "      {\n"
521       "        \"type\":\"ImageView\",\n"
522       "        \"name\":\"childImage\", \n"
523       "        \"color\": \n"
524       "          {\n"
525       "            \"r\": 10,\n"
526       "            \"g\": 10,\n"
527       "            \"b\": 10,\n"
528       "            \"a\": 100\n"
529       "          }\n"
530       "      },\n"
531       "      {\n"
532       "        \"type\":\"imageViewTemplate\",\n"
533       "        \"name\":\"childImage2\"\n"
534       "      }\n"
535       "    ]\n"
536       "  }\n"
537       "},\n"
538       "\"stage\":"
539       "[{"
540       "  \"type\": \"imageTree\","
541       "  \"size\": [100,100,1]"
542       "}]"
543       "}\n"
544   );
545
546   std::string stylejson(
547     "{\n"
548     " \"color\": [1,0,0,1],\n"
549     " \"actors\": {\n"
550     "   \"childImage\": {\n"
551     "     \"color\": \"#344353\"\n"
552     "   }\n"
553     " }\n"
554     "}\n"
555     );
556
557   std::string templatejson(
558     "{ \n"
559     "  \"type\": \"ImageView\",\n"
560     "  \"styles\": [\"imageStyle\"],\n"
561     "  \"name\": \"image\",\n"
562     "  \"size\": \"{SIZE}\",\n"
563     "  \"signals\": [{\n"
564     "    \"name\": \"touch\",\n"
565     "    \"action\": \"quit\"\n"
566     "  }],\n"
567     "  \"actors\": [\n"
568     "    {\n"
569     "      \"type\":\"ImageView\",\n"
570     "      \"name\":\"childImage\" \n"
571     "    }\n"
572     "  ]\n"
573     "}\n"
574     );
575
576   Builder builder = Builder::New();
577   builder.LoadFromString( json );
578
579   ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
580   DALI_TEST_CHECK( actor );
581
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 );
586
587   // create from json snippet
588   actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
589   DALI_TEST_CHECK( actor );
590
591
592   // NB: already applied in create
593   DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle",  actor ) );
594
595   // apply from json snippet
596   DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
597
598   END_TEST;
599 }
600
601 int UtcDaliBuilderRenderTasksP(void)
602 {
603   ToolkitTestApplication application;
604
605   // JSON with a quit event when the actor is touched
606   std::string json(
607       "{\n"
608       "\"renderTasks\":\n"
609       "{\n"
610       "  \"task0\": {\n"
611       "    \"sourceActor\": \"image\",\n"
612       "    \"cameraActor\": \"camera\" \n"
613       "  }\n"
614       "},\n"
615       "\"stage\":\n"
616       "[\n"
617       "  { \n"
618       "    \"type\": \"CameraActor\",\n"
619       "    \"name\": \"camera\"\n"
620       "  }, \n"
621       "  { \n"
622       "    \"type\": \"ImageView\",\n"
623       "    \"name\": \"image\",\n"
624       "    \"size\": [100,100,1],\n"
625       "    \"signals\": [{\n"
626       "      \"name\": \"touch\",\n"
627       "      \"action\": \"quit\"\n"
628       "    }],\n"
629       "    \"actors\": [\n"
630       "      {\n"
631       "        \"type\":\"ImageView\",\n"
632       "        \"name\":\"childImage\" \n"
633       "      }\n"
634       "    ]\n"
635       "  }\n"
636       "]\n"
637       "}\n"
638   );
639
640   Builder builder = Builder::New();
641   builder.LoadFromString( json );
642
643   unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
644
645   // coverage
646   builder.CreateRenderTask( "task0" );
647
648   DALI_TEST_CHECK( count <
649                    Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
650
651   END_TEST;
652 }
653
654 int UtcDaliBuilderChildActionP(void)
655 {
656   ToolkitTestApplication application;
657
658   // JSON with a quit event when the actor is touched
659   std::string json(
660       "{\n"
661       "  \"stage\":\n"
662       "  [{\n"
663       "    \"type\": \"Actor\",\n"
664       "    \"name\": \"actor\",\n"
665       "    \"size\": [100,100,1],\n"
666       "    \"parentOrigin\": \"TOP_LEFT\",\n"
667       "    \"anchorPoint\": \"TOP_LEFT\",\n"
668       "    \"actors\": [{\n"
669       "      \"type\": \"Actor\",\n"
670       "      \"name\": \"subActor\"\n"
671       "    }],\n"
672       "    \"signals\": [{\n"
673       "      \"name\": \"touch\",\n"
674       "      \"action\": \"hide\",\n"
675       "      \"actor\": \"actor\",\n"
676       "      \"childActor\": \"subActor\"\n"
677       "    }]\n"
678       "  }]\n"
679       "}\n"
680   );
681
682   Builder builder = Builder::New();
683   builder.LoadFromString( json );
684   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
685
686   // Render and notify
687   application.SendNotification();
688   application.Render();
689
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 );
697
698   // Render and notify
699   application.SendNotification();
700   application.Render();
701
702   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
703   DALI_TEST_CHECK( actor );
704
705   DALI_TEST_CHECK( !actor.IsVisible() );
706
707   END_TEST;
708 }
709
710 int UtcDaliBuilderSetPropertyActionP(void)
711 {
712   ToolkitTestApplication application;
713
714   // JSON with a quit event when the actor is touched
715   std::string json(
716       "{\n"
717       "  \"stage\":\n"
718       "  [{\n"
719       "    \"type\": \"Actor\",\n"
720       "    \"name\": \"actor\",\n"
721       "    \"size\": [100,100,1],\n"
722       "    \"parentOrigin\": \"TOP_LEFT\",\n"
723       "    \"anchorPoint\": \"TOP_LEFT\",\n"
724       "    \"actors\": [{\n"
725       "      \"type\": \"Actor\",\n"
726       "      \"name\": \"subActor\"\n"
727       "    }],\n"
728       "    \"signals\": [{\n"
729       "      \"name\": \"touch\",\n"
730       "      \"action\": \"set\",\n"
731       "      \"actor\": \"subActor\",\n"
732       "      \"property\": \"visible\",\n"
733       "      \"value\": false\n"
734       "    }]\n"
735       "  }]\n"
736       "}\n"
737   );
738
739   Builder builder = Builder::New();
740   builder.LoadFromString( json );
741   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
742
743   // Render and notify
744   application.SendNotification();
745   application.Render();
746
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 );
754
755   // Render and notify
756   application.SendNotification();
757   application.Render();
758
759   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
760   DALI_TEST_CHECK( actor );
761
762   DALI_TEST_CHECK( !actor.IsVisible() );
763
764   END_TEST;
765 }
766
767 int UtcDaliBuilderGenericActionP(void)
768 {
769   ToolkitTestApplication application;
770
771   // JSON with a quit event when the actor is touched
772   std::string json(
773       "{\n"
774       "  \"stage\":\n"
775       "  [{\n"
776       "    \"type\": \"Actor\",\n"
777       "    \"name\": \"actor\",\n"
778       "    \"size\": [100,100,1],\n"
779       "    \"parentOrigin\": \"TOP_LEFT\",\n"
780       "    \"anchorPoint\": \"TOP_LEFT\",\n"
781       "    \"actors\": [{\n"
782       "      \"type\": \"Actor\",\n"
783       "      \"name\": \"subActor\"\n"
784       "    }],\n"
785       "    \"signals\": [{\n"
786       "      \"name\": \"touch\",\n"
787       "      \"action\": \"hide\"\n"
788       "    }]\n"
789       "  }]\n"
790       "}\n"
791   );
792
793   Builder builder = Builder::New();
794   builder.LoadFromString( json );
795   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
796
797   // Render and notify
798   application.SendNotification();
799   application.Render();
800
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 );
808
809   // Render and notify
810   application.SendNotification();
811   application.Render();
812
813   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
814   DALI_TEST_CHECK( actor );
815
816   DALI_TEST_CHECK( !actor.IsVisible() );
817
818   END_TEST;
819 }
820
821 int UtcDaliBuilderPropertyNotificationP(void)
822 {
823   ToolkitTestApplication application;
824
825   // JSON with a quit event when the actor is touched
826   std::string json(
827       "{\n"
828       "  \"stage\":\n"
829       "  [{\n"
830       "    \"type\": \"Actor\",\n"
831       "    \"name\": \"actor\",\n"
832       "    \"size\": [100,100,1],\n"
833       "    \"parentOrigin\": \"TOP_LEFT\",\n"
834       "    \"anchorPoint\": \"TOP_LEFT\",\n"
835       "    \"actors\": [{\n"
836       "      \"type\": \"Actor\",\n"
837       "      \"name\": \"subActor\"\n"
838       "    }],\n"
839       "    \"signals\": [{\n"
840       "      \"name\": \"touch\",\n"
841       "      \"action\": \"hide\"\n"
842       "    }],\n"
843       "    \"notifications\": [{\n"
844       "      \"property\": \"visible\",\n"
845       "      \"condition\": \"False\",\n"
846       "      \"action\": \"show\"\n"
847       "    }]\n"
848       "  }]\n"
849       "}\n"
850   );
851
852   Builder builder = Builder::New();
853   builder.LoadFromString( json );
854   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
855
856   // Render and notify
857   application.SendNotification();
858   application.Render();
859
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 );
867
868   // Render and notify
869   application.SendNotification();
870   application.Render();
871
872   // Render and notify
873   application.SendNotification();
874   application.Render();
875
876   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
877   DALI_TEST_CHECK( actor );
878
879   DALI_TEST_CHECK( actor.IsVisible() );
880
881   END_TEST;
882 }
883
884 int UtcDaliBuilderCustomPropertyP(void)
885 {
886   ToolkitTestApplication application;
887
888   // JSON with a quit event when the actor is touched
889   std::string json(
890       "{\n"
891       "\"templates\":\n"
892       "{\n"
893       "  \"imageTree\": { \n"
894       "    \"type\": \"ImageView\",\n"
895       "    \"name\": \"image\",\n"
896       "    \"size\": [100,100,1],\n"
897       "    \"signals\": [{\n"
898       "      \"name\": \"touch\",\n"
899       "      \"action\": \"quit\"\n"
900       "    }],\n"
901       "    \"properties\": {\n"
902       "      \"newproperty\": true\n"
903       "    },\n"
904       "    \"animatableProperties\": {\n"
905       "      \"newAnimatableproperty\": 3\n"
906       "    },\n"
907       "    \"actors\": [\n"
908       "      {\n"
909       "        \"type\":\"ImageView\",\n"
910       "        \"name\":\"childImage\" \n"
911       "      }\n"
912       "    ]\n"
913       "  }\n"
914       "}\n"
915       "}\n"
916   );
917
918   Builder builder = Builder::New();
919   builder.LoadFromString( json );
920
921   ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
922   DALI_TEST_CHECK( actor );
923
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 );
929
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 );
934
935   END_TEST;
936 }
937
938 int UtcDaliBuilderCustomShaderP(void)
939 {
940   ToolkitTestApplication application;
941
942   // JSON with a quit event when the actor is touched
943   std::string json(
944     "{\n"
945     "  \"stage\": [\n"
946     "    {\n"
947     "      \"type\": \"ImageView\",\n"
948     "      \"name\": \"Image1\",\n"
949     "      \"position\": [\n"
950     "        0.40461349487305,\n"
951     "        0.9150390625,\n"
952     "        0.0\n"
953     "      ],\n"
954     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
955     "      \"size\": [200, 200, 0],\n"
956     "      \"effect\": \"Ripple2D\",\n"
957     "      \"image\": {\n"
958     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
959     "        \"desiredWidth\": 200,\n"
960     "        \"desiredHeight\": 80,\n"
961     "        \"shader\": {\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"
963     "        }\n"
964     "      },\n"
965     "      \"customAnimatableProperties\": {\n"
966     "         \"uAmplitude\": 0.02,\n"
967     "         \"uTime\": 0.0\n"
968     "      },\n"
969     "      \"signals\": [\n"
970     "        {\n"
971     "          \"name\": \"onStage\",\n"
972     "          \"action\": \"play\",\n"
973     "          \"animation\": \"Animation_1\"\n"
974     "        }\n"
975     "      ]\n"
976     "    }\n"
977     "  ],\n"
978     "  \"animations\": {\n"
979     "    \"Animation_1\": {\n"
980     "      \"loop\":true,\n"
981     "      \"properties\": [\n"
982     "        {\n"
983     "          \"actor\": \"Image1\",\n"
984     "          \"property\": \"uTime\",\n"
985     "          \"value\": 10.0,\n"
986     "          \"alphaFunction\": \"LINEAR\",\n"
987     "          \"timePeriod\": {\n"
988     "            \"delay\": 0,\n"
989     "            \"duration\": 10.0\n"
990     "          }\n"
991     "        }\n"
992     "      ]\n"
993     "    }\n"
994     "  }\n"
995     "}\n"
996
997   );
998
999   Builder builder = Builder::New();
1000   builder.LoadFromString( json );
1001
1002   builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
1003
1004   // Render and notify
1005   application.SendNotification();
1006   application.Render();
1007
1008   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
1009
1010   // coverage
1011   DALI_TEST_CHECK( actor );
1012
1013   END_TEST;
1014 }
1015
1016
1017 int UtcDaliBuilderLoadFromStringN(void)
1018 {
1019   ToolkitTestApplication application;
1020
1021   // JSON with a quit event when the actor is touched
1022   std::string json(
1023       "asdfsadf dsf asdf asdf {"
1024          "\"stage\":"
1025          "[{"
1026            "\"type\": \"Actor\","
1027            "\"size\": [100,100,1],"
1028            "\"parentOrigin\": \"TOP_LEFT\","
1029            "\"anchorPoint\": \"TOP_LEFT\","
1030            "\"signals\": [{"
1031              "\"name\": \"touch\","
1032              "\"action\": \"quit\""
1033            "}]"
1034          "}]"
1035       "}"
1036   );
1037   Builder builder = Builder::New();
1038
1039   bool assert1 = false;
1040
1041   try
1042   {
1043     builder.LoadFromString( json );
1044   }
1045   catch( Dali::DaliException& e )
1046   {
1047     DALI_TEST_PRINT_ASSERT( e );
1048     DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1049     assert1 = true;
1050   }
1051
1052   DALI_TEST_CHECK( assert1 );
1053
1054   END_TEST;
1055 }
1056
1057
1058 int UtcDaliBuilderAddActorsP(void)
1059 {
1060   ToolkitTestApplication application;
1061
1062   // JSON with a quit event when the actor is touched
1063   std::string json(
1064       "{\n"
1065       "  \"arbitarysection\":\n"
1066       "  [{\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"
1072       "    \"actors\": [{\n"
1073       "      \"type\": \"Actor\",\n"
1074       "      \"name\": \"subActor\",\n"
1075       "      \"visible\": false\n"
1076       "    }],\n"
1077       "    \"signals\": [{\n"
1078       "      \"name\": \"touch\",\n"
1079       "      \"action\": \"hide\",\n"
1080       "      \"actor\": \"actor\",\n"
1081       "      \"childActor\": \"subActor\"\n"
1082       "    }]\n"
1083       "  }]\n"
1084       "}\n"
1085   );
1086
1087   Builder builder = Builder::New();
1088   builder.LoadFromString( json );
1089   builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1090
1091   // Render and notify
1092   application.SendNotification();
1093   application.Render();
1094
1095   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1096   DALI_TEST_CHECK( actor );
1097
1098   DALI_TEST_CHECK( !actor.IsVisible() );
1099
1100   END_TEST;
1101 }
1102
1103 int UtcDaliBuilderFrameBufferP(void)
1104 {
1105   ToolkitTestApplication application;
1106
1107   // JSON with a quit event when the actor is touched
1108   std::string json(
1109     "{\n"
1110     "  \"constants\":\n"
1111     "  {\n"
1112     "    \"FB_WIDTH\": 200.0,\n"
1113     "    \"FB_HEIGHT\": 200.0,\n"
1114     "    \"FB_SIZE\": [200,200],\n"
1115     "    \"FB_ASPECT_RATIO\": 1\n"
1116     "  },\n"
1117     "  \"stage\": [\n"
1118     "    {\n"
1119     "      \"type\": \"ImageView\",\n"
1120     "      \"name\": \"fbOnStage\",\n"
1121     "      \"position\": [\n"
1122     "        0.40461349487305,\n"
1123     "        0.9150390625,\n"
1124     "        0.0\n"
1125     "      ],\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"
1130     "    },\n"
1131     "    {\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"
1137     "      \"image\": {\n"
1138     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1139     "      },\n"
1140     "      \"signals\": [\n"
1141     "        {\n"
1142     "          \"name\": \"onStage\",\n"
1143     "          \"action\": \"play\",\n"
1144     "          \"animation\": \"Animation_1\"\n"
1145     "        }\n"
1146     "      ]\n"
1147     "    },\n"
1148     "    {\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"
1155     "    }\n"
1156     "  ],\n"
1157     "  \"frameBufferImages\":\n"
1158     "  {\n"
1159     "    \"fb0\":\n"
1160     "    {\n"
1161     "      \"type\": \"FrameBufferImage\",\n"
1162     "      \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1163     "      \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1164     "    }\n"
1165     "  },\n"
1166     "  \"renderTasks\":\n"
1167     "  {\n"
1168     "    \"stage\":\n"
1169     "    [\n"
1170     "      {\n"
1171     "        \"sourceActor\": \"fbOnStage\"\n"
1172     "      },\n"
1173     "      {\n"
1174     "        \"sourceActor\": \"Image1\",\n"
1175     "        \"targetFrameBuffer\": \"fb0\",\n"
1176     "        \"viewportSize\":\"{FB_SIZE}\",\n"
1177     "        \"cameraActor\":\"fbCam\"\n"
1178     "      }\n"
1179     "    ]\n"
1180     "  },\n"
1181     "  \"paths\": {},\n"
1182     "  \"animations\": {\n"
1183     "    \"Animation_1\": {\n"
1184     "      \"loop\":true,\n"
1185     "      \"properties\": [\n"
1186     "        {\n"
1187     "          \"actor\": \"Image1\",\n"
1188     "          \"property\": \"uTime\",\n"
1189     "          \"value\": 10.0,\n"
1190     "          \"alphaFunction\": \"LINEAR\",\n"
1191     "          \"timePeriod\": {\n"
1192     "            \"delay\": 0,\n"
1193     "            \"duration\": 10.0\n"
1194     "          },\n"
1195     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1196     "        }\n"
1197     "      ]\n"
1198     "    }\n"
1199     "  },\n"
1200     "  \"shaderEffects\": {\n"
1201     "    \"Ripple2D\": {\n"
1202     "      \"program\": {\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"
1208     "      },\n"
1209     "      \"geometryHints\": \"HINT_NONE\",\n"
1210     "      \"gridDensity\": 0,\n"
1211     "      \"loop\": true,\n"
1212     "      \"uAmplitude\": 0.02,\n"
1213     "      \"uTime\": 0.0\n"
1214     "    }\n"
1215     "  }\n"
1216     "}\n");
1217
1218   Builder builder = Builder::New();
1219
1220   // frame buffer coverage
1221   builder.LoadFromString( json );
1222
1223   // Render and notify
1224   application.SendNotification();
1225   application.Render();
1226
1227   Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1228   DALI_TEST_CHECK( frameBuffer );
1229
1230   Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1231   DALI_TEST_CHECK( frameBuffer2 );
1232   DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1233
1234   DALI_TEST_CHECK( true );
1235
1236   END_TEST;
1237 }
1238
1239 int UtcDaliBuilderPathConstraintsP(void)
1240 {
1241   ToolkitTestApplication application;
1242
1243   // JSON with a quit event when the actor is touched
1244   std::string json(
1245     "{\n"
1246     "  \"constants\":\n"
1247     "  {\n"
1248     "    \"FB_WIDTH\": 200.0,\n"
1249     "    \"FB_HEIGHT\": 200.0,\n"
1250     "    \"FB_SIZE\": [200,200],\n"
1251     "    \"FB_ASPECT_RATIO\": 1\n"
1252     "  },\n"
1253     "  \"stage\": [\n"
1254     "    {\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"
1260     "      \"image\": {\n"
1261     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1262     "      },\n"
1263     "      \"signals\": [\n"
1264     "        {\n"
1265     "          \"name\": \"onStage\",\n"
1266     "          \"action\": \"play\",\n"
1267     "          \"animation\": \"pathAnimation\"\n"
1268     "        },\n"
1269     "        {\n"
1270     "          \"name\": \"onStage\",\n"
1271     "          \"action\": \"applyConstraint\",\n"
1272     "          \"constrainer\": \"constrainer0\",\n"
1273     "          \"properties\":\n"
1274     "          [\n"
1275     "            {\n"
1276     "              \"source\": \"Image1\",\n"
1277     "              \"sourceProperty\": \"positionX\",\n"
1278     "              \"target\": \"Image1\",\n"
1279     "              \"targetProperty\": \"colorRed\",\n"
1280     "              \"range\": [-300,300]\n"
1281     "            }\n"
1282     "          ]\n"
1283     "        },\n"
1284     "        {\n"
1285     "          \"name\": \"onStage\",\n"
1286     "          \"action\": \"applyConstraint\",\n"
1287     "          \"constrainer\": \"constrainer1\",\n"
1288     "          \"properties\":\n"
1289     "          [\n"
1290     "            {\n"
1291     "              \"source\": \"Image1\",\n"
1292     "              \"sourceProperty\": \"positionX\",\n"
1293     "              \"target\": \"Image1\",\n"
1294     "              \"targetProperty\": \"colorBlue\",\n"
1295     "              \"range\": [-300,300]\n"
1296     "            }\n"
1297     "          ]\n"
1298     "        }\n"
1299     "      ]\n"
1300     "    }\n"
1301     "  ],\n"
1302     "  \"paths\":\n"
1303     "  {\n"
1304     "    \"path0\":\n"
1305     "    {\n"
1306     "      \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1307     "      \"curvature\":0.35\n"
1308     "    }\n"
1309     "  },\n"
1310     "  \"constrainers\":\n"
1311     "  {\n"
1312     "    \"constrainer0\":\n"
1313     "    {\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"
1317     "    },\n"
1318     "    \"constrainer1\":\n"
1319     "    {\n"
1320     "      \"type\": \"LinearConstrainer\",\n"
1321     "      \"value\": [ 0, 0, 0 ]\n"
1322     "    }\n"
1323     "  },\n"
1324     "  \"animations\": {\n"
1325     "    \"pathAnimation\": {\n"
1326     "      \"duration\": 3.0,\n"
1327     "      \"properties\":\n"
1328     "      [{\n"
1329     "        \"actor\": \"Image1\",\n"
1330     "        \"path\":\"path0\",\n"
1331     "        \"forward\":[1,0,0],\n"
1332     "        \"alphaFunction\": \"EASE_IN_OUT\",\n"
1333     "        \"timePeriod\": {\n"
1334     "          \"delay\": 0,\n"
1335     "          \"duration\": 3\n"
1336     "        }\n"
1337     "      },\n"
1338     "       {\n"
1339     "         \"actor\": \"Image1\",\n"
1340     "         \"property\": \"uTime\",\n"
1341     "         \"value\": 10.0,\n"
1342     "         \"alphaFunction\": \"LINEAR\",\n"
1343     "         \"timePeriod\": {\n"
1344     "           \"delay\": 0,\n"
1345     "           \"duration\": 10.0\n"
1346     "         },\n"
1347     "         \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1348     "       }]\n"
1349     "    },\n"
1350     "    \"Animation_1\": {\n"
1351     "      \"loop\":true,\n"
1352     "      \"properties\": [\n"
1353     "        {\n"
1354     "          \"actor\": \"Image1\",\n"
1355     "          \"property\": \"uTime\",\n"
1356     "          \"value\": 10.0,\n"
1357     "          \"alphaFunction\": \"LINEAR\",\n"
1358     "          \"timePeriod\": {\n"
1359     "            \"delay\": 0,\n"
1360     "            \"duration\": 10.0\n"
1361     "          },\n"
1362     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1363     "        }\n"
1364     "      ]\n"
1365     "    }\n"
1366     "  },\n"
1367     "  \"shaderEffects\": {\n"
1368     "    \"Ripple2D\": {\n"
1369     "      \"program\": {\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"
1375     "      },\n"
1376     "      \"geometryHints\": \"HINT_NONE\",\n"
1377     "      \"gridDensity\": 0,\n"
1378     "      \"loop\": true,\n"
1379     "      \"uAmplitude\": 0.02,\n"
1380     "      \"uTime\": 0.0\n"
1381     "    }\n"
1382     "  }\n"
1383     "}\n");
1384
1385   Builder builder = Builder::New();
1386
1387   // frame buffer coverage
1388   builder.LoadFromString( json );
1389
1390   // Render and notify
1391   application.SendNotification();
1392   application.Render();
1393
1394   Dali::Path path =  builder.GetPath( "path0" );
1395   DALI_TEST_CHECK( path );
1396
1397   Dali::Path path2 =  builder.GetPath( "path0" );
1398   DALI_TEST_CHECK( path2 );
1399   DALI_TEST_CHECK( path == path2 );
1400
1401   Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1402   DALI_TEST_CHECK( constrainer0 );
1403
1404   Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1405   DALI_TEST_CHECK( constrainer0_2 );
1406   DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1407
1408   Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1409   DALI_TEST_CHECK( constrainer1 );
1410
1411   Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1412   DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1413
1414   END_TEST;
1415 }
1416
1417 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1418   {                                                                       \
1419     Property::Value* value = xMap->Find( xKey );                          \
1420     DALI_TEST_EQUALS( value==NULL, false, xLocation);                     \
1421     if( value != NULL )                                                   \
1422     {                                                                     \
1423       DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation );         \
1424       xType result;                                                       \
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() );                                    \
1430     }                                                                     \
1431     else                                                                  \
1432     {                                                                     \
1433       tet_printf("Can't find map element " xKey "\n");                    \
1434     }                                                                     \
1435   }
1436
1437
1438 int UtcDaliBuilderMapping01(void)
1439 {
1440   ToolkitTestApplication application;
1441
1442   const char* json =
1443     "{\n"
1444     "  \"mappings\":\n"
1445     "  {\n"
1446     "    \"buttonPressFadeOut\":{\n"
1447     "      \"alphaFunction\":\"EASE_OUT\",\n"
1448     "      \"timePeriod\":{\n"
1449     "        \"delay\":0.0,\n"
1450     "        \"duration\":0.4\n"
1451     "      }\n"
1452     "    },\n"
1453     "    \"buttonPressFadeIn\":{\n"
1454     "      \"alphaFunction\":\"EASE_IN\",\n"
1455     "      \"timePeriod\":{\n"
1456     "        \"delay\":0.4,\n"
1457     "        \"duration\":0.5\n"
1458     "      }\n"
1459     "    },\n"
1460     "    \"transition:buttonPressed\":\n"
1461     "    [\n"
1462     "      {\n"
1463     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1464     "        \"property\": \"opacity\",\n"
1465     "        \"value\": 0,\n"
1466     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1467     "      }\n"
1468     "    ],\n"
1469     "    \"transition:buttonReleased\":\n"
1470     "    [\n"
1471     "      {\n"
1472     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1473     "        \"property\": \"opacity\",\n"
1474     "        \"value\": 1,\n"
1475     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1476     "      },\n"
1477     "      {\n"
1478     "        \"target\": \"unselectedForegroundRenderer\",\n"
1479     "        \"property\": \"scale\",\n"
1480     "        \"value\": [ 1, 1, 1 ],\n"
1481     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1482     "      },\n"
1483     "      {\n"
1484     "        \"target\": \"selectedBackgroundRenderer\",\n"
1485     "        \"property\": \"opacity\",\n"
1486     "        \"value\": 0,\n"
1487     "        \"animator\": \"<buttonPressFadeOut>\"\n"
1488     "      },\n"
1489     "      {\n"
1490     "        \"target\": \"selectedForegroundRenderer\",\n"
1491     "        \"property\": \"scale\",\n"
1492     "        \"value\": [ 0, 0, 0 ],\n"
1493     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1494     "      }\n"
1495     "    ]\n"
1496     "  },\n"
1497     "  \"styles\":\n"
1498     "  {\n"
1499     "    \"testbutton\":\n"
1500     "    {\n"
1501     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1502     "      \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1503     "    }\n"
1504     "  }\n"
1505     "}\n";
1506
1507   Builder builder = Builder::New();
1508   builder.LoadFromString( json );
1509
1510   Test::TestButton testButton = Test::TestButton::New();
1511   Stage::GetCurrent().Add( testButton );
1512
1513   // Render and notify
1514   application.SendNotification();
1515   application.Render();
1516
1517   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1518
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();
1523
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();
1528
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);
1534
1535   END_TEST;
1536 }
1537
1538
1539 int UtcDaliBuilderMappingCycleCheck(void)
1540 {
1541   ToolkitTestApplication application;
1542
1543   std::string json(
1544     "{\n"
1545     "  \"mappings\":\n"
1546     "  {\n"
1547     "    \"cyclicKey1\":\"<cyclicKey1>\",\n"
1548     "    \"cyclicKey2\":\"<cyclicKey3>\",\n"
1549     "    \"cyclicKey3\":\"<cyclicKey2>\",\n"
1550     "    \"FadeOut\":{\n"
1551     "      \"alphaFunction\":\"EASE_IN\",\n"
1552     "      \"timePeriod\":{\n"
1553     "        \"delay\":\"<cyclicKey3>\",\n"
1554     "        \"duration\":0.6\n"
1555     "      }\n"
1556     "    },\n"
1557     "    \"transition:buttonPressed\":\n"
1558     "    [\n"
1559     "      {\n"
1560     "        \"target\": \"<cyclicKey1>\",\n"
1561     "        \"property\": \"<cyclicKey2>\",\n"
1562     "        \"value\": 0,\n"
1563     "        \"animator\":\"<FadeOut>\"\n"
1564     "      }\n"
1565     "    ]\n"
1566     "  },\n"
1567     "  \"styles\":\n"
1568     "  {\n"
1569     "    \"testbutton\":\n"
1570     "    {\n"
1571     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1572     "      \"releaseTransition\":\"<cyclicKey2>\",\n"
1573     "      \"disabledTransition\":\"<cyclicKey3>\",\n"
1574     "      \"enabledTransition\":\"<unknownKey>\"\n"
1575     "    }\n"
1576     "  }\n"
1577     "}\n");
1578
1579   Builder builder = Builder::New();
1580   builder.LoadFromString( json );
1581
1582   Test::TestButton testButton = Test::TestButton::New();
1583   Stage::GetCurrent().Add( testButton );
1584
1585   // Render and notify
1586   application.SendNotification();
1587   application.Render();
1588
1589   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1590
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();
1595
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();
1600
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);
1604
1605   END_TEST;
1606 }
1607
1608 int UtcDaliBuilderTypeCasts(void)
1609 {
1610   ToolkitTestApplication application;
1611
1612   std::string json(
1613     "{"
1614        "\"stage\":"
1615        "[{"
1616          "\"type\": \"Layer\","
1617          "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1618          "\"position\":    { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1619          "\"color\":       { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1620          "\"sensitive\":   { \"typeCast\":\"boolean\", \"value\":false },"
1621          "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1622          "\"colorMode\":   { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1623          "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] }"
1624       "}]"
1625     "}"
1626   );
1627
1628   Actor rootActor = Actor::New();
1629   Stage::GetCurrent().Add( rootActor );
1630
1631   Builder builder = Builder::New();
1632   builder.LoadFromString( json );
1633   builder.AddActors( rootActor );
1634
1635   application.SendNotification();
1636   application.Render();
1637
1638   Actor createdActor = rootActor.GetChildAt( 0 );
1639   DALI_TEST_EQUALS( createdActor.GetMaximumSize(), Vector2(100.0f,15.0f), TEST_LOCATION );
1640   DALI_TEST_EQUALS( createdActor.GetCurrentPosition(), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
1641   DALI_TEST_EQUALS( createdActor.GetCurrentColor(), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
1642   DALI_TEST_EQUALS( createdActor.IsSensitive(), false, TEST_LOCATION );
1643   DALI_TEST_EQUALS( createdActor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
1644
1645   END_TEST;
1646 }