ebfd376877aebf4caecf72fc04c2a501c70ccdf8
[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\": \"Actor\","
82            "\"size\": [100,100,1],"
83            "\"parentOrigin\": \"TOP_LEFT\","
84            "\"anchorPoint\": \"TOP_LEFT\","
85            "\"signals\": [{"
86              "\"name\": \"touched\","
87              "\"action\": \"quit\""
88            "}]"
89          "}]"
90       "}"
91   );
92   Builder builder = Builder::New();
93   builder.LoadFromString( json );
94   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
95
96   // Connect to builder's quit signal
97   bool functorCalled( false );
98   builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
99
100   // Render and notify
101   application.SendNotification();
102   application.Render();
103
104   // Emit touch event and check that our quit method is called
105   Integration::TouchEvent touchEvent;
106   Integration::Point point;
107   point.SetState( PointState::DOWN );
108   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
109   touchEvent.points.push_back( point );
110   application.ProcessEvent( touchEvent );
111   DALI_TEST_CHECK( functorCalled );
112
113   END_TEST;
114 }
115
116
117 int UtcDaliBuilderAnimationP(void)
118 {
119   ToolkitTestApplication application;
120
121   // JSON with a quit event when the actor is touched
122   std::string json(
123         "{"
124         "   \"constants\":"
125         "   {"
126         "     \"ALPHA_FUNCTION\":\"EASE_IN_OUT\""
127         "   },"
128         "   \"paths\":"
129         "   {"
130         "     \"path0\":"
131         "     {"
132         "       \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
133         "       \"curvature\":0.35"
134         "     }"
135         "   },"
136         "  \"animations\": {"
137         "    \"animate\": {"
138         "      \"loop\": true,"
139         "      \"endAction\": \"BAKE\","
140         "      \"disconnectAction\": \"BAKE\","
141         "      \"properties\":"
142         "      [{"
143         "        \"actor\": \"greeting\","
144         "        \"property\": \"position\","
145         "        \"value\": [300, 300, -1000],"
146         "        \"alphaFunction\": \"{ALPHA_FUNCTION}\","
147         "        \"relative\": true,"
148         "        \"timePeriod\": {"
149         "          \"delay\": 0,"
150         "          \"duration\": 3"
151         "        }"
152         "      },"
153         "       {"
154         "         \"actor\": \"greeting\","
155         "         \"property\": \"visible\","
156         "         \"alphaFunction\": \"LINEAR\","
157         "         \"value\": true"
158         "       },"
159         "       {"
160         "         \"actor\": \"greeting\","
161         "         \"property\": \"sizeWidth\","
162         "         \"alphaFunction\": \"REVERSE\","
163         "         \"value\": 10.0"
164         "       },"
165         "       {"
166         "         \"actor\": \"greeting\","
167         "         \"property\": \"orientation\","
168         "         \"alphaFunction\": \"EASE_IN\","
169         "         \"value\": [10.0,20.0,30.0]"
170         "       },"
171         "       {"
172         "         \"actor\": \"greeting\","
173         "         \"property\": \"orientation\","
174         "         \"alphaFunction\": \"EASE_OUT\","
175         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
176         "       },"
177         "       {"
178         "         \"actor\": \"greeting\","
179         "         \"property\": \"orientation\","
180         "         \"alphaFunction\": \"EASE_IN_OUT\","
181         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
182         "       },"
183         "       {"
184         "         \"actor\": \"greeting\","
185         "         \"property\": \"orientation\","
186         "         \"alphaFunction\": \"EASE_IN_SINE\","
187         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
188         "       },"
189         "       {"
190         "         \"actor\": \"greeting\","
191         "         \"property\": \"orientation\","
192         "         \"alphaFunction\": \"EASE_OUT_SINE\","
193         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
194         "       },"
195         "       {"
196         "         \"actor\": \"greeting\","
197         "         \"property\": \"orientation\","
198         "         \"alphaFunction\": \"EASE_IN_OUT_SINE\","
199         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
200         "       },"
201         "       {"
202         "         \"actor\": \"greeting\","
203         "         \"property\": \"orientation\","
204         "         \"alphaFunction\": \"BOUNCE\","
205         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
206         "       },"
207         "       {"
208         "         \"actor\": \"greeting\","
209         "         \"property\": \"orientation\","
210         "         \"alphaFunction\": \"SIN\","
211         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
212         "       },"
213         "       {"
214         "         \"actor\": \"greeting\","
215         "         \"property\": \"orientation\","
216         "         \"alphaFunction\": \"EASE_OUT_BACK\","
217         "         \"value\": [0.0, 0.0, 0.0, 1.0]"
218         "       }"
219         "      ]"
220         "    },"
221         "    \"pathAnimation\": {"
222         "      \"duration\": 3.0,"
223         "      \"endAction\": \"DISCARD\","
224         "      \"disconnectAction\": \"BAKE_FINAL\","
225         "      \"properties\": [{"
226         "        \"actor\": \"greeting\","
227         "        \"path\":\"path0\","
228         "        \"forward\":[1,0,0],"
229         "        \"alphaFunction\": \"EASE_IN_OUT\","
230         "        \"timePeriod\": {"
231         "          \"delay\": 0,"
232         "          \"duration\": 3"
233         "        }"
234         "      }]"
235         "    }"
236         "  },"
237         "  \"stage\": [{"
238         "    \"name\": \"greeting\","
239         "    \"type\": \"TextLabel\","
240         "    \"text\": \"Touch me\","
241         "    \"styles\": [\"basicText\"],"
242         "    \"position\": [0, -120, 0],"
243         "    \"size\": [200, 200, 1],"
244         "    \"orientation\": [0, 0, 30],"
245         "    \"signals\": [{"
246         "      \"name\": \"touched\","
247         "      \"action\": \"play\","
248         "      \"animation\": \"animate\""
249         "    }]"
250         "  }]"
251         "}");
252
253   Builder builder = Builder::New();
254   builder.LoadFromString( json );
255   builder.AddActors( Stage::GetCurrent().GetRootLayer() );
256
257   Animation anim = builder.CreateAnimation("animate");
258
259   DALI_TEST_CHECK( anim );
260
261   Property::Map map;
262   map["ALPHA_FUNCTION"] = "EASE_IN_SQUARE";
263   anim = builder.CreateAnimation("animate", map);
264
265   DALI_TEST_CHECK( anim );
266
267   anim = builder.CreateAnimation("pathAnimation");
268
269   DALI_TEST_CHECK( anim );
270
271   // trigger play
272   // Emit touch event and check that our quit method is called
273   Integration::TouchEvent touchEvent;
274   Integration::Point point;
275   point.SetState( PointState::DOWN );
276   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
277   touchEvent.points.push_back( point );
278   application.ProcessEvent( touchEvent );
279
280   // Render and notify
281   application.SendNotification();
282   application.Render();
283
284
285   END_TEST;
286 }
287
288 int UtcDaliBuilderAnimationN(void)
289 {
290   ToolkitTestApplication application;
291
292   // JSON with a quit event when the actor is touched
293   std::string json(
294         "{"
295         "   \"constants\":"
296         "   {"
297         "     \"TEXT\": \"Touch Me\","
298         "     \"NAME\": \"greeting\" "
299         "   },"
300         "   \"paths\":"
301         "   {"
302         "     \"path0\":"
303         "     {"
304         "       \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
305         "       \"curvature\":0.35"
306         "     }"
307         "   },"
308         "  \"animations\": {"
309         "    \"animate\": {"
310         "      \"loop\": true,"
311         "      \"endAction\": \"BAKE\","
312         "      \"disconnectAction\": \"BAKE\","
313         "      \"properties\":"
314         "      [{"
315         "        \"actor\": \"{NAME}\","
316         "        \"property\": \"positioninvalid\","
317         "        \"value\": [300, 300, -1000],"
318         "        \"alphaFunction\": \"EASE_IN_OUT\","
319         "        \"relative\": true,"
320         "        \"timePeriod\": {"
321         "          \"delay\": 0,"
322         "          \"duration\": 3"
323         "        }"
324         "      }"
325         "      ]"
326         "    },"
327         "    \"animate2\": {"
328         "      \"loop\": true,"
329         "      \"endAction\": \"BAKE\","
330         "      \"disconnectAction\": \"BAKE\","
331         "      \"properties\":"
332         "      [{"
333         "        \"actor\": \"{NAME}\","
334         "        \"property\": \"positioninvalid\","
335         "        \"value\": [300, 300, -1000],"
336         "        \"alphaFunction\": \"EGGS_OVER_EASY\","
337         "        \"relative\": true,"
338         "        \"timePeriod\": {"
339         "          \"delay\": 0,"
340         "          \"duration\": 3"
341         "        }"
342         "      }"
343         "      ]"
344         "    },"
345         "    \"pathAnimation\": {"
346         "      \"duration\": 3.0,"
347         "      \"endAction\": \"DISCARD\","
348         "      \"disconnectAction\": \"BAKE_FINAL\","
349         "      \"properties\": [{"
350         "        \"actor\": \"greeting\","
351         "        \"path\":\"pathDoesntExist\","
352         "        \"forward\":[1,0,0],"
353         "        \"alphaFunction\": \"EASE_IN_OUT\","
354         "        \"timePeriod\": {"
355         "          \"delay\": 0,"
356         "          \"duration\": 3"
357         "        }"
358         "      }]"
359         "    }"
360         "  },"
361         "  \"stage\": [{"
362         "    \"name\": \"greeting\","
363         "    \"type\": \"TextLabel\","
364         "    \"text\": \"Touch me\","
365         "    \"styles\": [\"basicText\"],"
366         "    \"position\": [0, -120, 0],"
367         "    \"size\": [200, 200, 1],"
368         "    \"orientation\": [0, 0, 30],"
369         "    \"signals\": [{"
370         "      \"name\": \"touched\","
371         "      \"action\": \"play\","
372         "      \"animation\": \"animate\""
373         "    }]"
374         "  },"
375         "  {"
376         "    \"name\": \"greeting2\","
377         "    \"type\": \"TextLabel\","
378         "    \"text\": \"Touch me\""
379         "  }]"
380         "}");
381
382
383   Builder builder = Builder::New();
384   builder.LoadFromString( json );
385   builder.AddActors( Stage::GetCurrent().GetRootLayer() );
386
387   Animation anim = builder.CreateAnimation("animate");
388
389   // log warning line coverage
390   anim = builder.CreateAnimation("pathAnimation");
391   DALI_TEST_CHECK(anim);
392
393   anim = builder.CreateAnimation("animate");
394   DALI_TEST_CHECK(anim);
395
396   anim = builder.CreateAnimation("animate2");
397   DALI_TEST_CHECK(anim);
398
399   // create referencing a different actor aka animation templates
400   Property::Map map;
401   map["NAME"] = "greeting2";
402   anim = builder.CreateAnimation("animate2", map);
403   DALI_TEST_CHECK(anim);
404
405   // alternative actor to use for FindChildByName
406   anim = builder.CreateAnimation("animate2", Dali::Stage::GetCurrent().GetRootLayer());
407   DALI_TEST_CHECK(anim);
408
409   // alternative actor to use for FindChildByName
410   anim = builder.CreateAnimation("animate2", map, Dali::Stage::GetCurrent().GetRootLayer());
411   DALI_TEST_CHECK(anim);
412
413
414   END_TEST;
415
416 }
417
418 int UtcDaliBuilderConstantsP(void)
419 {
420   ToolkitTestApplication application;
421
422   // JSON with a quit event when the actor is touched
423   std::string json(
424       "{"
425       "\"constants\":"
426       "{"
427       "  \"IMAGE_PATH\": \"apath\","
428       "  \"WIDTH\": 22.3,"
429       "  \"ANCHOR\": \"TOP_LEFT\","
430       "  \"PADDING\": [1,2,3,4]"
431       "},"
432       "\"stage\":"
433       "[{"
434       "  \"type\": \"ImageView\","
435       "  \"name\": \"{NAME}\","
436       "  \"size\": [100,100,1],"
437       "  \"parentOrigin\": \"TOP_LEFT\","
438       "  \"anchorPoint\": \"{ANCHOR}\","
439       "  \"padding\": \"{PADDING}\","
440       "  \"image\": { \"url\": \"dir/{IMAGE_PATH}\" },"
441       "  \"sizeWidth\": \"{WIDTH}\","
442       "  \"signals\": [{"
443       "    \"name\": \"touched\","
444       "    \"action\": \"quit\""
445       "  }]"
446       "}]"
447       "}"
448   );
449
450   Builder builder = Builder::New();
451   builder.LoadFromString( json );
452
453   builder.AddConstant( "NAME", "image" );
454
455   Property::Map map = builder.GetConstants();
456
457   Dali::Property::Value* pValue = map.Find( "NAME" );
458
459   DALI_TEST_CHECK( pValue );
460
461   pValue = map.Find( "IMAGE_PATH" );
462
463   DALI_TEST_CHECK( pValue );
464
465   Dali::Property::Value value = builder.GetConstant( "WIDTH" );
466
467   DALI_TEST_CHECK( value.GetType() != Property::NONE );
468
469   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
470   DALI_TEST_CHECK( builder );
471
472   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("image");
473   DALI_TEST_CHECK( actor );
474
475   END_TEST;
476 }
477
478 int UtcDaliBuilderTemplatesAndStylesP(void)
479 {
480   ToolkitTestApplication application;
481
482   // JSON with a quit event when the actor is touched
483   std::string json(
484       "{\n"
485       "\"constants\":"
486       "{"
487       "  \"SIZE\": [10,20,30]"
488       "},"
489       "\"styles\":\n"
490       "{\n"
491       "  \"imageStyle\": \n"
492       "  {\n"
493       "    \"color\": [1,0,0,1],\n"
494       "    \"actors\": {\n"
495       "      \"childImage\": {\n"
496       "        \"color\": [0,1,0,1]\n"
497       "      }\n"
498       "    }\n"
499       "  }\n"
500       "},\n"
501       "\"templates\":\n"
502       "{\n"
503       "  \"imageTree\": { \n"
504       "    \"type\": \"ImageView\",\n"
505       "    \"styles\": [\"imageStyle\"],\n"
506       "    \"name\": \"image\",\n"
507       "    \"size\": \"{SIZE}\",\n"
508       "    \"signals\": [{\n"
509       "      \"name\": \"touched\",\n"
510       "      \"action\": \"quit\"\n"
511       "    }],\n"
512       "    \"actors\": [\n"
513       "      {\n"
514       "        \"type\":\"ImageView\",\n"
515       "        \"name\":\"childImage\" \n"
516       "      }\n"
517       "    ]\n"
518       "  }\n"
519       "},\n"
520       "\"stage\":"
521       "[{"
522       "  \"type\": \"imageTree\","
523       "  \"size\": [100,100,1]"
524       "}]"
525       "}\n"
526   );
527
528   std::string stylejson(
529     "{\n"
530     " \"color\": [1,0,0,1],\n"
531     " \"actors\": {\n"
532     "   \"childImage\": {\n"
533     "     \"color\": [0,1,0,1]\n"
534     "   }\n"
535     " }\n"
536     "}\n"
537     );
538
539   std::string templatejson(
540     "{ \n"
541     "  \"type\": \"ImageView\",\n"
542     "  \"styles\": [\"imageStyle\"],\n"
543     "  \"name\": \"image\",\n"
544     "  \"size\": \"{SIZE}\",\n"
545     "  \"signals\": [{\n"
546     "    \"name\": \"touched\",\n"
547     "    \"action\": \"quit\"\n"
548     "  }],\n"
549     "  \"actors\": [\n"
550     "    {\n"
551     "      \"type\":\"ImageView\",\n"
552     "      \"name\":\"childImage\" \n"
553     "    }\n"
554     "  ]\n"
555     "}\n"
556     );
557
558   Builder builder = Builder::New();
559   builder.LoadFromString( json );
560
561   ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
562   DALI_TEST_CHECK( actor );
563
564   Dali::Property::Map map;
565   map["SIZE"] = Vector3(100,100,1);
566   actor = ImageView::DownCast( builder.Create( "imageTree",  map ) );
567   DALI_TEST_CHECK( actor );
568
569   // create from json snippet
570   actor = ImageView::DownCast( builder.CreateFromJson( templatejson ) );
571   DALI_TEST_CHECK( actor );
572
573
574   // NB: already applied in create
575   DALI_TEST_CHECK( builder.ApplyStyle( "imageStyle",  actor ) );
576
577   // apply from json snippet
578   DALI_TEST_CHECK( builder.ApplyFromJson( actor, stylejson ) );
579
580   END_TEST;
581 }
582
583 int UtcDaliBuilderRenderTasksP(void)
584 {
585   ToolkitTestApplication application;
586
587   // JSON with a quit event when the actor is touched
588   std::string json(
589       "{\n"
590       "\"renderTasks\":\n"
591       "{\n"
592       "  \"task0\": {\n"
593       "    \"sourceActor\": \"image\",\n"
594       "    \"cameraActor\": \"camera\" \n"
595       "  }\n"
596       "},\n"
597       "\"stage\":\n"
598       "[\n"
599       "  { \n"
600       "    \"type\": \"CameraActor\",\n"
601       "    \"name\": \"image\"\n"
602       "  }, \n"
603       "  { \n"
604       "    \"type\": \"ImageView\",\n"
605       "    \"name\": \"image\",\n"
606       "    \"size\": [100,100,1],\n"
607       "    \"signals\": [{\n"
608       "      \"name\": \"touched\",\n"
609       "      \"action\": \"quit\"\n"
610       "    }],\n"
611       "    \"actors\": [\n"
612       "      {\n"
613       "        \"type\":\"ImageView\",\n"
614       "        \"name\":\"childImage\" \n"
615       "      }\n"
616       "    ]\n"
617       "  }\n"
618       "]\n"
619       "}\n"
620   );
621
622   Builder builder = Builder::New();
623   builder.LoadFromString( json );
624
625   unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
626
627   // coverage
628   builder.CreateRenderTask( "task0" );
629
630   DALI_TEST_CHECK( count <
631                    Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
632
633   END_TEST;
634 }
635
636 int UtcDaliBuilderChildActionP(void)
637 {
638   ToolkitTestApplication application;
639
640   // JSON with a quit event when the actor is touched
641   std::string json(
642       "{\n"
643       "  \"stage\":\n"
644       "  [{\n"
645       "    \"type\": \"Actor\",\n"
646       "    \"name\": \"actor\",\n"
647       "    \"size\": [100,100,1],\n"
648       "    \"parentOrigin\": \"TOP_LEFT\",\n"
649       "    \"anchorPoint\": \"TOP_LEFT\",\n"
650       "    \"actors\": [{\n"
651       "      \"type\": \"Actor\",\n"
652       "      \"name\": \"subActor\"\n"
653       "    }],\n"
654       "    \"signals\": [{\n"
655       "      \"name\": \"touched\",\n"
656       "      \"action\": \"hide\",\n"
657       "      \"actor\": \"actor\",\n"
658       "      \"childActor\": \"subActor\"\n"
659       "    }]\n"
660       "  }]\n"
661       "}\n"
662   );
663
664   Builder builder = Builder::New();
665   builder.LoadFromString( json );
666   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
667
668   // Render and notify
669   application.SendNotification();
670   application.Render();
671
672   // Emit touch event and check that our quit method is called
673   Integration::TouchEvent touchEvent;
674   Integration::Point point;
675   point.SetState( PointState::DOWN );
676   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
677   touchEvent.points.push_back( point );
678   application.ProcessEvent( touchEvent );
679
680   // Render and notify
681   application.SendNotification();
682   application.Render();
683
684   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
685   DALI_TEST_CHECK( actor );
686
687   DALI_TEST_CHECK( !actor.IsVisible() );
688
689   END_TEST;
690 }
691
692 int UtcDaliBuilderSetPropertyActionP(void)
693 {
694   ToolkitTestApplication application;
695
696   // JSON with a quit event when the actor is touched
697   std::string json(
698       "{\n"
699       "  \"stage\":\n"
700       "  [{\n"
701       "    \"type\": \"Actor\",\n"
702       "    \"name\": \"actor\",\n"
703       "    \"size\": [100,100,1],\n"
704       "    \"parentOrigin\": \"TOP_LEFT\",\n"
705       "    \"anchorPoint\": \"TOP_LEFT\",\n"
706       "    \"actors\": [{\n"
707       "      \"type\": \"Actor\",\n"
708       "      \"name\": \"subActor\"\n"
709       "    }],\n"
710       "    \"signals\": [{\n"
711       "      \"name\": \"touched\",\n"
712       "      \"action\": \"set\",\n"
713       "      \"actor\": \"subActor\",\n"
714       "      \"property\": \"visible\",\n"
715       "      \"value\": false\n"
716       "    }]\n"
717       "  }]\n"
718       "}\n"
719   );
720
721   Builder builder = Builder::New();
722   builder.LoadFromString( json );
723   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
724
725   // Render and notify
726   application.SendNotification();
727   application.Render();
728
729   // Emit touch event and check that our quit method is called
730   Integration::TouchEvent touchEvent;
731   Integration::Point point;
732   point.SetState( PointState::DOWN );
733   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
734   touchEvent.points.push_back( point );
735   application.ProcessEvent( touchEvent );
736
737   // Render and notify
738   application.SendNotification();
739   application.Render();
740
741   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
742   DALI_TEST_CHECK( actor );
743
744   DALI_TEST_CHECK( !actor.IsVisible() );
745
746   END_TEST;
747 }
748
749 int UtcDaliBuilderGenericActionP(void)
750 {
751   ToolkitTestApplication application;
752
753   // JSON with a quit event when the actor is touched
754   std::string json(
755       "{\n"
756       "  \"stage\":\n"
757       "  [{\n"
758       "    \"type\": \"Actor\",\n"
759       "    \"name\": \"actor\",\n"
760       "    \"size\": [100,100,1],\n"
761       "    \"parentOrigin\": \"TOP_LEFT\",\n"
762       "    \"anchorPoint\": \"TOP_LEFT\",\n"
763       "    \"actors\": [{\n"
764       "      \"type\": \"Actor\",\n"
765       "      \"name\": \"subActor\"\n"
766       "    }],\n"
767       "    \"signals\": [{\n"
768       "      \"name\": \"touched\",\n"
769       "      \"action\": \"hide\"\n"
770       "    }]\n"
771       "  }]\n"
772       "}\n"
773   );
774
775   Builder builder = Builder::New();
776   builder.LoadFromString( json );
777   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
778
779   // Render and notify
780   application.SendNotification();
781   application.Render();
782
783   // Emit touch event and check that our quit method is called
784   Integration::TouchEvent touchEvent;
785   Integration::Point point;
786   point.SetState( PointState::DOWN );
787   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
788   touchEvent.points.push_back( point );
789   application.ProcessEvent( touchEvent );
790
791   // Render and notify
792   application.SendNotification();
793   application.Render();
794
795   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
796   DALI_TEST_CHECK( actor );
797
798   DALI_TEST_CHECK( !actor.IsVisible() );
799
800   END_TEST;
801 }
802
803 int UtcDaliBuilderPropertyNotificationP(void)
804 {
805   ToolkitTestApplication application;
806
807   // JSON with a quit event when the actor is touched
808   std::string json(
809       "{\n"
810       "  \"stage\":\n"
811       "  [{\n"
812       "    \"type\": \"Actor\",\n"
813       "    \"name\": \"actor\",\n"
814       "    \"size\": [100,100,1],\n"
815       "    \"parentOrigin\": \"TOP_LEFT\",\n"
816       "    \"anchorPoint\": \"TOP_LEFT\",\n"
817       "    \"actors\": [{\n"
818       "      \"type\": \"Actor\",\n"
819       "      \"name\": \"subActor\"\n"
820       "    }],\n"
821       "    \"signals\": [{\n"
822       "      \"name\": \"touched\",\n"
823       "      \"action\": \"hide\"\n"
824       "    }],\n"
825       "    \"notifications\": [{\n"
826       "      \"property\": \"visible\",\n"
827       "      \"condition\": \"False\",\n"
828       "      \"action\": \"show\"\n"
829       "    }]\n"
830       "  }]\n"
831       "}\n"
832   );
833
834   Builder builder = Builder::New();
835   builder.LoadFromString( json );
836   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
837
838   // Render and notify
839   application.SendNotification();
840   application.Render();
841
842   // Emit touch event and check that our quit method is called
843   Integration::TouchEvent touchEvent;
844   Integration::Point point;
845   point.SetState( PointState::DOWN );
846   point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
847   touchEvent.points.push_back( point );
848   application.ProcessEvent( touchEvent );
849
850   // Render and notify
851   application.SendNotification();
852   application.Render();
853
854   // Render and notify
855   application.SendNotification();
856   application.Render();
857
858   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
859   DALI_TEST_CHECK( actor );
860
861   DALI_TEST_CHECK( actor.IsVisible() );
862
863   END_TEST;
864 }
865
866 int UtcDaliBuilderCustomPropertyP(void)
867 {
868   ToolkitTestApplication application;
869
870   // JSON with a quit event when the actor is touched
871   std::string json(
872       "{\n"
873       "\"templates\":\n"
874       "{\n"
875       "  \"imageTree\": { \n"
876       "    \"type\": \"ImageView\",\n"
877       "    \"name\": \"image\",\n"
878       "    \"size\": [100,100,1],\n"
879       "    \"signals\": [{\n"
880       "      \"name\": \"touched\",\n"
881       "      \"action\": \"quit\"\n"
882       "    }],\n"
883       "    \"properties\": {\n"
884       "      \"newproperty\": true\n"
885       "    },\n"
886       "    \"animatableProperties\": {\n"
887       "      \"newAnimatableproperty\": 3\n"
888       "    },\n"
889       "    \"actors\": [\n"
890       "      {\n"
891       "        \"type\":\"ImageView\",\n"
892       "        \"name\":\"childImage\" \n"
893       "      }\n"
894       "    ]\n"
895       "  }\n"
896       "}\n"
897       "}\n"
898   );
899
900   Builder builder = Builder::New();
901   builder.LoadFromString( json );
902
903   ImageView actor = ImageView::DownCast( builder.Create( "imageTree" ) );
904   DALI_TEST_CHECK( actor );
905
906   // NB: already applied in create
907   Property::Index index = actor.GetPropertyIndex("newproperty");
908   DALI_TEST_CHECK( Property::INVALID_INDEX != index );
909   Property::Value value = actor.GetProperty(index);
910   DALI_TEST_CHECK( value.Get<bool>() == true );
911
912   index = actor.GetPropertyIndex("newAnimatableproperty");
913   DALI_TEST_CHECK( Property::INVALID_INDEX != index );
914   value = actor.GetProperty(index);
915   DALI_TEST_CHECK( value.Get<int>() == 3 );
916
917   END_TEST;
918 }
919
920 int UtcDaliBuilderCustomShaderP(void)
921 {
922   ToolkitTestApplication application;
923
924   // JSON with a quit event when the actor is touched
925   std::string json(
926     "{\n"
927     "  \"stage\": [\n"
928     "    {\n"
929     "      \"type\": \"ImageView\",\n"
930     "      \"name\": \"Image1\",\n"
931     "      \"position\": [\n"
932     "        0.40461349487305,\n"
933     "        0.9150390625,\n"
934     "        0.0\n"
935     "      ],\n"
936     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
937     "      \"size\": [200, 200, 0],\n"
938     "      \"effect\": \"Ripple2D\",\n"
939     "      \"image\": {\n"
940     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
941     "        \"desiredWidth\": 200,\n"
942     "        \"desiredHeight\": 80,\n"
943     "        \"shader\": {\n"
944     "           \"fragmentShader\": \"precision mediump float;\\nuniform sampler2D sTexture;\\nuniform vec4 uColor;\\nuniform float uAmplitude;\\nuniform float uTime;\\nvarying vec2 vTexCoord;\\nvoid main()\\n{\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;}\\n\\n\"\n"
945     "        }\n"
946     "      },\n"
947     "      \"customAnimatableProperties\": {\n"
948     "         \"uAmplitude\": 0.02,\n"
949     "         \"uTime\": 0.0\n"
950     "      },\n"
951     "      \"signals\": [\n"
952     "        {\n"
953     "          \"name\": \"onStage\",\n"
954     "          \"action\": \"play\",\n"
955     "          \"animation\": \"Animation_1\"\n"
956     "        }\n"
957     "      ]\n"
958     "    }\n"
959     "  ],\n"
960     "  \"animations\": {\n"
961     "    \"Animation_1\": {\n"
962     "      \"loop\":true,\n"
963     "      \"properties\": [\n"
964     "        {\n"
965     "          \"actor\": \"Image1\",\n"
966     "          \"property\": \"uTime\",\n"
967     "          \"value\": 10.0,\n"
968     "          \"alphaFunction\": \"LINEAR\",\n"
969     "          \"timePeriod\": {\n"
970     "            \"delay\": 0,\n"
971     "            \"duration\": 10.0\n"
972     "          }\n"
973     "        }\n"
974     "      ]\n"
975     "    }\n"
976     "  }\n"
977     "}\n"
978
979   );
980
981   Builder builder = Builder::New();
982   builder.LoadFromString( json );
983
984   builder.AddActors ( "stage", Stage::GetCurrent().GetRootLayer() );
985
986   // Render and notify
987   application.SendNotification();
988   application.Render();
989
990   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("Image1");
991
992   // coverage
993   DALI_TEST_CHECK( actor );
994
995   END_TEST;
996 }
997
998
999 int UtcDaliBuilderLoadFromStringN(void)
1000 {
1001   ToolkitTestApplication application;
1002
1003   // JSON with a quit event when the actor is touched
1004   std::string json(
1005       "asdfsadf dsf asdf asdf {"
1006          "\"stage\":"
1007          "[{"
1008            "\"type\": \"Actor\","
1009            "\"size\": [100,100,1],"
1010            "\"parentOrigin\": \"TOP_LEFT\","
1011            "\"anchorPoint\": \"TOP_LEFT\","
1012            "\"signals\": [{"
1013              "\"name\": \"touched\","
1014              "\"action\": \"quit\""
1015            "}]"
1016          "}]"
1017       "}"
1018   );
1019   Builder builder = Builder::New();
1020
1021   bool assert1 = false;
1022
1023   try
1024   {
1025     builder.LoadFromString( json );
1026   }
1027   catch( Dali::DaliException& e )
1028   {
1029     DALI_TEST_PRINT_ASSERT( e );
1030     DALI_TEST_EQUALS(e.condition, "!\"Cannot parse JSON\"", TEST_LOCATION);
1031     assert1 = true;
1032   }
1033
1034   DALI_TEST_CHECK( assert1 );
1035
1036   END_TEST;
1037 }
1038
1039
1040 int UtcDaliBuilderAddActorsP(void)
1041 {
1042   ToolkitTestApplication application;
1043
1044   // JSON with a quit event when the actor is touched
1045   std::string json(
1046       "{\n"
1047       "  \"arbitarysection\":\n"
1048       "  [{\n"
1049       "    \"type\": \"Actor\",\n"
1050       "    \"name\": \"actor\",\n"
1051       "    \"size\": [100,100,1],\n"
1052       "    \"parentOrigin\": \"TOP_LEFT\",\n"
1053       "    \"anchorPoint\": \"TOP_LEFT\",\n"
1054       "    \"actors\": [{\n"
1055       "      \"type\": \"Actor\",\n"
1056       "      \"name\": \"subActor\",\n"
1057       "      \"visible\": false\n"
1058       "    }],\n"
1059       "    \"signals\": [{\n"
1060       "      \"name\": \"touched\",\n"
1061       "      \"action\": \"hide\",\n"
1062       "      \"actor\": \"actor\",\n"
1063       "      \"childActor\": \"subActor\"\n"
1064       "    }]\n"
1065       "  }]\n"
1066       "}\n"
1067   );
1068
1069   Builder builder = Builder::New();
1070   builder.LoadFromString( json );
1071   builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1072
1073   // Render and notify
1074   application.SendNotification();
1075   application.Render();
1076
1077   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1078   DALI_TEST_CHECK( actor );
1079
1080   DALI_TEST_CHECK( !actor.IsVisible() );
1081
1082   END_TEST;
1083 }
1084
1085 int UtcDaliBuilderFrameBufferP(void)
1086 {
1087   ToolkitTestApplication application;
1088
1089   // JSON with a quit event when the actor is touched
1090   std::string json(
1091     "{\n"
1092     "  \"constants\":\n"
1093     "  {\n"
1094     "    \"FB_WIDTH\": 200.0,\n"
1095     "    \"FB_HEIGHT\": 200.0,\n"
1096     "    \"FB_SIZE\": [200,200],\n"
1097     "    \"FB_ASPECT_RATIO\": 1\n"
1098     "  },\n"
1099     "  \"stage\": [\n"
1100     "    {\n"
1101     "      \"type\": \"ImageView\",\n"
1102     "      \"name\": \"fbOnStage\",\n"
1103     "      \"position\": [\n"
1104     "        0.40461349487305,\n"
1105     "        0.9150390625,\n"
1106     "        0.0\n"
1107     "      ],\n"
1108     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1109     "      \"size\": [300, 300, 0],\n"
1110     "      \"image\": \"fb0\",\n"
1111     "      \"clearColor\": [1,0,0,1]\n"
1112     "    },\n"
1113     "    {\n"
1114     "      \"type\": \"ImageView\",\n"
1115     "      \"name\": \"Image1\",\n"
1116     "      \"size\": [200, 200, 0],\n"
1117     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1118     "      \"effect\": \"Ripple2D\",\n"
1119     "      \"image\": {\n"
1120     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1121     "      },\n"
1122     "      \"signals\": [\n"
1123     "        {\n"
1124     "          \"name\": \"onStage\",\n"
1125     "          \"action\": \"play\",\n"
1126     "          \"animation\": \"Animation_1\"\n"
1127     "        }\n"
1128     "      ]\n"
1129     "    },\n"
1130     "    {\n"
1131     "      \"type\":\"CameraActor\",\n"
1132     "      \"name\":\"fbCam\",\n"
1133     "      \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1134     "      \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1135     "      \"fieldOfView\": 0.785,\n"
1136     "      \"invertYAxis\": true\n"
1137     "    }\n"
1138     "  ],\n"
1139     "  \"frameBufferImages\":\n"
1140     "  {\n"
1141     "    \"fb0\":\n"
1142     "    {\n"
1143     "      \"type\": \"FrameBufferImage\",\n"
1144     "      \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1145     "      \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1146     "    }\n"
1147     "  },\n"
1148     "  \"renderTasks\":\n"
1149     "  {\n"
1150     "    \"stage\":\n"
1151     "    [\n"
1152     "      {\n"
1153     "        \"sourceActor\": \"fbOnStage\"\n"
1154     "      },\n"
1155     "      {\n"
1156     "        \"sourceActor\": \"Image1\",\n"
1157     "        \"targetFrameBuffer\": \"fb0\",\n"
1158     "        \"viewportSize\":\"{FB_SIZE}\",\n"
1159     "        \"cameraActor\":\"fbCam\"\n"
1160     "      }\n"
1161     "    ]\n"
1162     "  },\n"
1163     "  \"paths\": {},\n"
1164     "  \"animations\": {\n"
1165     "    \"Animation_1\": {\n"
1166     "      \"loop\":true,\n"
1167     "      \"properties\": [\n"
1168     "        {\n"
1169     "          \"actor\": \"Image1\",\n"
1170     "          \"property\": \"uTime\",\n"
1171     "          \"value\": 10.0,\n"
1172     "          \"alphaFunction\": \"LINEAR\",\n"
1173     "          \"timePeriod\": {\n"
1174     "            \"delay\": 0,\n"
1175     "            \"duration\": 10.0\n"
1176     "          },\n"
1177     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1178     "        }\n"
1179     "      ]\n"
1180     "    }\n"
1181     "  },\n"
1182     "  \"shaderEffects\": {\n"
1183     "    \"Ripple2D\": {\n"
1184     "      \"program\": {\n"
1185     "        \"vertexPrefix\": \"\",\n"
1186     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1187     "        \"fragmentPrefix\": \"\",\n"
1188     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1189     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1190     "      },\n"
1191     "      \"geometryHints\": \"HINT_NONE\",\n"
1192     "      \"gridDensity\": 0,\n"
1193     "      \"loop\": true,\n"
1194     "      \"uAmplitude\": 0.02,\n"
1195     "      \"uTime\": 0.0\n"
1196     "    }\n"
1197     "  }\n"
1198     "}\n");
1199
1200   Builder builder = Builder::New();
1201
1202   // frame buffer coverage
1203   builder.LoadFromString( json );
1204
1205   // Render and notify
1206   application.SendNotification();
1207   application.Render();
1208
1209   Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1210   DALI_TEST_CHECK( frameBuffer );
1211
1212   Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1213   DALI_TEST_CHECK( frameBuffer2 );
1214   DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1215
1216   DALI_TEST_CHECK( true );
1217
1218   END_TEST;
1219 }
1220
1221 int UtcDaliBuilderPathConstraintsP(void)
1222 {
1223   ToolkitTestApplication application;
1224
1225   // JSON with a quit event when the actor is touched
1226   std::string json(
1227     "{\n"
1228     "  \"constants\":\n"
1229     "  {\n"
1230     "    \"FB_WIDTH\": 200.0,\n"
1231     "    \"FB_HEIGHT\": 200.0,\n"
1232     "    \"FB_SIZE\": [200,200],\n"
1233     "    \"FB_ASPECT_RATIO\": 1\n"
1234     "  },\n"
1235     "  \"stage\": [\n"
1236     "    {\n"
1237     "      \"type\": \"ImageView\",\n"
1238     "      \"name\": \"Image1\",\n"
1239     "      \"size\": [200, 200, 0],\n"
1240     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1241     "      \"effect\": \"Ripple2D\",\n"
1242     "      \"image\": {\n"
1243     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1244     "      },\n"
1245     "      \"signals\": [\n"
1246     "        {\n"
1247     "          \"name\": \"onStage\",\n"
1248     "          \"action\": \"play\",\n"
1249     "          \"animation\": \"pathAnimation\"\n"
1250     "        },\n"
1251     "        {\n"
1252     "          \"name\": \"onStage\",\n"
1253     "          \"action\": \"applyConstraint\",\n"
1254     "          \"constrainer\": \"constrainer0\",\n"
1255     "          \"properties\":\n"
1256     "          [\n"
1257     "            {\n"
1258     "              \"source\": \"Image1\",\n"
1259     "              \"sourceProperty\": \"positionX\",\n"
1260     "              \"target\": \"Image1\",\n"
1261     "              \"targetProperty\": \"colorRed\",\n"
1262     "              \"range\": [-300,300]\n"
1263     "            }\n"
1264     "          ]\n"
1265     "        },\n"
1266     "        {\n"
1267     "          \"name\": \"onStage\",\n"
1268     "          \"action\": \"applyConstraint\",\n"
1269     "          \"constrainer\": \"constrainer1\",\n"
1270     "          \"properties\":\n"
1271     "          [\n"
1272     "            {\n"
1273     "              \"source\": \"Image1\",\n"
1274     "              \"sourceProperty\": \"positionX\",\n"
1275     "              \"target\": \"Image1\",\n"
1276     "              \"targetProperty\": \"colorBlue\",\n"
1277     "              \"range\": [-300,300]\n"
1278     "            }\n"
1279     "          ]\n"
1280     "        }\n"
1281     "      ]\n"
1282     "    }\n"
1283     "  ],\n"
1284     "  \"paths\":\n"
1285     "  {\n"
1286     "    \"path0\":\n"
1287     "    {\n"
1288     "      \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1289     "      \"curvature\":0.35\n"
1290     "    }\n"
1291     "  },\n"
1292     "  \"constrainers\":\n"
1293     "  {\n"
1294     "    \"constrainer0\":\n"
1295     "    {\n"
1296     "      \"type\": \"PathConstrainer\",\n"
1297     "      \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1298     "      \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1299     "    },\n"
1300     "    \"constrainer1\":\n"
1301     "    {\n"
1302     "      \"type\": \"LinearConstrainer\",\n"
1303     "      \"value\": [ 0, 0, 0 ]\n"
1304     "    }\n"
1305     "  },\n"
1306     "  \"animations\": {\n"
1307     "    \"pathAnimation\": {\n"
1308     "      \"duration\": 3.0,\n"
1309     "      \"properties\":\n"
1310     "      [{\n"
1311     "        \"actor\": \"Image1\",\n"
1312     "        \"path\":\"path0\",\n"
1313     "        \"forward\":[1,0,0],\n"
1314     "        \"alphaFunction\": \"EASE_IN_OUT\",\n"
1315     "        \"timePeriod\": {\n"
1316     "          \"delay\": 0,\n"
1317     "          \"duration\": 3\n"
1318     "        }\n"
1319     "      },\n"
1320     "       {\n"
1321     "         \"actor\": \"Image1\",\n"
1322     "         \"property\": \"uTime\",\n"
1323     "         \"value\": 10.0,\n"
1324     "         \"alphaFunction\": \"LINEAR\",\n"
1325     "         \"timePeriod\": {\n"
1326     "           \"delay\": 0,\n"
1327     "           \"duration\": 10.0\n"
1328     "         },\n"
1329     "         \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1330     "       }]\n"
1331     "    },\n"
1332     "    \"Animation_1\": {\n"
1333     "      \"loop\":true,\n"
1334     "      \"properties\": [\n"
1335     "        {\n"
1336     "          \"actor\": \"Image1\",\n"
1337     "          \"property\": \"uTime\",\n"
1338     "          \"value\": 10.0,\n"
1339     "          \"alphaFunction\": \"LINEAR\",\n"
1340     "          \"timePeriod\": {\n"
1341     "            \"delay\": 0,\n"
1342     "            \"duration\": 10.0\n"
1343     "          },\n"
1344     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1345     "        }\n"
1346     "      ]\n"
1347     "    }\n"
1348     "  },\n"
1349     "  \"shaderEffects\": {\n"
1350     "    \"Ripple2D\": {\n"
1351     "      \"program\": {\n"
1352     "        \"vertexPrefix\": \"\",\n"
1353     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1354     "        \"fragmentPrefix\": \"\",\n"
1355     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1356     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1357     "      },\n"
1358     "      \"geometryHints\": \"HINT_NONE\",\n"
1359     "      \"gridDensity\": 0,\n"
1360     "      \"loop\": true,\n"
1361     "      \"uAmplitude\": 0.02,\n"
1362     "      \"uTime\": 0.0\n"
1363     "    }\n"
1364     "  }\n"
1365     "}\n");
1366
1367   Builder builder = Builder::New();
1368
1369   // frame buffer coverage
1370   builder.LoadFromString( json );
1371
1372   // Render and notify
1373   application.SendNotification();
1374   application.Render();
1375
1376   Dali::Path path =  builder.GetPath( "path0" );
1377   DALI_TEST_CHECK( path );
1378
1379   Dali::Path path2 =  builder.GetPath( "path0" );
1380   DALI_TEST_CHECK( path2 );
1381   DALI_TEST_CHECK( path == path2 );
1382
1383   Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1384   DALI_TEST_CHECK( constrainer0 );
1385
1386   Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1387   DALI_TEST_CHECK( constrainer0_2 );
1388   DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1389
1390   Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1391   DALI_TEST_CHECK( constrainer1 );
1392
1393   Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1394   DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1395
1396   END_TEST;
1397 }
1398
1399 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1400   {                                                                       \
1401     Property::Value* value = xMap->Find( xKey );                          \
1402     DALI_TEST_EQUALS( value==NULL, false, xLocation);                     \
1403     if( value != NULL )                                                   \
1404     {                                                                     \
1405       DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation );         \
1406       xType result;                                                       \
1407       value->Get(result);                                                 \
1408       DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION );               \
1409       std::ostringstream oss;                                             \
1410       oss << "Animation element " << xKey << "= " << result << std::endl; \
1411       tet_printf( oss.str().c_str() );                                    \
1412     }                                                                     \
1413     else                                                                  \
1414     {                                                                     \
1415       tet_printf("Can't find map element " xKey "\n");                    \
1416     }                                                                     \
1417   }
1418
1419
1420 int UtcDaliBuilderMapping01(void)
1421 {
1422   ToolkitTestApplication application;
1423
1424   const char* json =
1425     "{\n"
1426     "  \"mappings\":\n"
1427     "  {\n"
1428     "    \"buttonPressFadeOut\":{\n"
1429     "      \"alphaFunction\":\"EASE_OUT\",\n"
1430     "      \"timePeriod\":{\n"
1431     "        \"delay\":0.0,\n"
1432     "        \"duration\":0.4\n"
1433     "      }\n"
1434     "    },\n"
1435     "    \"buttonPressFadeIn\":{\n"
1436     "      \"alphaFunction\":\"EASE_IN\",\n"
1437     "      \"timePeriod\":{\n"
1438     "        \"delay\":0.4,\n"
1439     "        \"duration\":0.5\n"
1440     "      }\n"
1441     "    },\n"
1442     "    \"transition:buttonPressed\":\n"
1443     "    [\n"
1444     "      {\n"
1445     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1446     "        \"property\": \"opacity\",\n"
1447     "        \"value\": 0,\n"
1448     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1449     "      }\n"
1450     "    ],\n"
1451     "    \"transition:buttonReleased\":\n"
1452     "    [\n"
1453     "      {\n"
1454     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1455     "        \"property\": \"opacity\",\n"
1456     "        \"value\": 1,\n"
1457     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1458     "      },\n"
1459     "      {\n"
1460     "        \"target\": \"unselectedForegroundRenderer\",\n"
1461     "        \"property\": \"scale\",\n"
1462     "        \"value\": [ 1, 1, 1 ],\n"
1463     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1464     "      },\n"
1465     "      {\n"
1466     "        \"target\": \"selectedBackgroundRenderer\",\n"
1467     "        \"property\": \"opacity\",\n"
1468     "        \"value\": 0,\n"
1469     "        \"animator\": \"<buttonPressFadeOut>\"\n"
1470     "      },\n"
1471     "      {\n"
1472     "        \"target\": \"selectedForegroundRenderer\",\n"
1473     "        \"property\": \"scale\",\n"
1474     "        \"value\": [ 0, 0, 0 ],\n"
1475     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1476     "      }\n"
1477     "    ]\n"
1478     "  },\n"
1479     "  \"styles\":\n"
1480     "  {\n"
1481     "    \"testbutton\":\n"
1482     "    {\n"
1483     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1484     "      \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1485     "    }\n"
1486     "  }\n"
1487     "}\n";
1488
1489   Builder builder = Builder::New();
1490   builder.LoadFromString( json );
1491
1492   Test::TestButton testButton = Test::TestButton::New();
1493   Stage::GetCurrent().Add( testButton );
1494
1495   // Render and notify
1496   application.SendNotification();
1497   application.Render();
1498
1499   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1500
1501   // Now check that it has loaded the transition correctly:
1502   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1503   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1504   Property::Array* array = transition.GetArray();
1505
1506   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1507   Property::Value element = array->GetElementAt(0);
1508   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1509   Property::Map* map = element.GetMap();
1510
1511   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1512   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1513   CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1514   CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1515   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1516
1517   END_TEST;
1518 }
1519
1520
1521 int UtcDaliBuilderMappingCycleCheck(void)
1522 {
1523   ToolkitTestApplication application;
1524
1525   std::string json(
1526     "{\n"
1527     "  \"mappings\":\n"
1528     "  {\n"
1529     "    \"cyclicKey1\":\"<cyclicKey1>\",\n"
1530     "    \"cyclicKey2\":\"<cyclicKey3>\",\n"
1531     "    \"cyclicKey3\":\"<cyclicKey2>\",\n"
1532     "    \"FadeOut\":{\n"
1533     "      \"alphaFunction\":\"EASE_IN\",\n"
1534     "      \"timePeriod\":{\n"
1535     "        \"delay\":\"<cyclicKey3>\",\n"
1536     "        \"duration\":0.6\n"
1537     "      }\n"
1538     "    },\n"
1539     "    \"transition:buttonPressed\":\n"
1540     "    [\n"
1541     "      {\n"
1542     "        \"target\": \"<cyclicKey1>\",\n"
1543     "        \"property\": \"<cyclicKey2>\",\n"
1544     "        \"value\": 0,\n"
1545     "        \"animator\":\"<FadeOut>\"\n"
1546     "      }\n"
1547     "    ]\n"
1548     "  },\n"
1549     "  \"styles\":\n"
1550     "  {\n"
1551     "    \"testbutton\":\n"
1552     "    {\n"
1553     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1554     "      \"releaseTransition\":\"<cyclicKey2>\",\n"
1555     "      \"disabledTransition\":\"<cyclicKey3>\",\n"
1556     "      \"enabledTransition\":\"<unknownKey>\"\n"
1557     "    }\n"
1558     "  }\n"
1559     "}\n");
1560
1561   Builder builder = Builder::New();
1562   builder.LoadFromString( json );
1563
1564   Test::TestButton testButton = Test::TestButton::New();
1565   Stage::GetCurrent().Add( testButton );
1566
1567   // Render and notify
1568   application.SendNotification();
1569   application.Render();
1570
1571   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1572
1573   // Now check that it has loaded the transition correctly:
1574   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1575   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1576   Property::Array* array = transition.GetArray();
1577
1578   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1579   Property::Value element = array->GetElementAt(0);
1580   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1581   Property::Map* map = element.GetMap();
1582
1583   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1584   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1585   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1586
1587   END_TEST;
1588 }