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