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