Merge "Fix for text cursor." 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\": \"ImageActor\","
430       "  \"name\": \"{NAME}\","
431       "  \"size\": [100,100,1],"
432       "  \"parentOrigin\": \"TOP_LEFT\","
433       "  \"anchorPoint\": \"{ANCHOR}\","
434       "  \"padding\": \"{PADDING}\","
435       "  \"image\": { \"filename\": \"dir/{IMAGE_PATH}\" },"
436       "  \"sizeWidth\": \"{WIDTH}\","
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\": \"ImageActor\",\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\":\"ImageActor\",\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\": \"ImageActor\",\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\":\"ImageActor\",\n"
547     "      \"name\":\"childImage\" \n"
548     "    }\n"
549     "  ]\n"
550     "}\n"
551     );
552
553   Builder builder = Builder::New();
554   builder.LoadFromString( json );
555
556   ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) );
557   DALI_TEST_CHECK( actor );
558
559   Dali::Property::Map map;
560   map["SIZE"] = Vector3(100,100,1);
561   actor = ImageActor::DownCast( builder.Create( "imageTree",  map ) );
562   DALI_TEST_CHECK( actor );
563
564   // create from json snippet
565   actor = ImageActor::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\": \"ImageActor\",\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\":\"ImageActor\",\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\": \"ImageActor\",\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       "    \"customProperties\": {\n"
867       "      \"newproperty\": true\n"
868       "    },\n"
869       "    \"actors\": [\n"
870       "      {\n"
871       "        \"type\":\"ImageActor\",\n"
872       "        \"name\":\"childImage\" \n"
873       "      }\n"
874       "    ]\n"
875       "  }\n"
876       "}\n"
877       "}\n"
878   );
879
880   Builder builder = Builder::New();
881   builder.LoadFromString( json );
882
883   ImageActor actor = ImageActor::DownCast( builder.Create( "imageTree" ) );
884   DALI_TEST_CHECK( actor );
885
886   // NB: already applied in create
887   Property::Index index = actor.GetPropertyIndex("newproperty");
888   DALI_TEST_CHECK( Property::INVALID_INDEX != index );
889   Property::Value value = actor.GetProperty(index);
890   DALI_TEST_CHECK( value.Get<bool>() == true );
891
892   END_TEST;
893 }
894
895 int UtcDaliBuilderShaderEffectP(void)
896 {
897   ToolkitTestApplication application;
898
899   // JSON with a quit event when the actor is touched
900   std::string json(
901     "{\n"
902     "  \"stage\": [\n"
903     "    {\n"
904     "      \"type\": \"ImageActor\",\n"
905     "      \"name\": \"Image1\",\n"
906     "      \"position\": [\n"
907     "        0.40461349487305,\n"
908     "        0.9150390625,\n"
909     "        0.0\n"
910     "      ],\n"
911     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
912     "      \"size\": [200, 200, 0],\n"
913     "      \"effect\": \"Ripple2D\",\n"
914     "      \"image\": {\n"
915     "        \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
916     "        \"width\": 200,\n"
917     "        \"height\": 80,\n"
918     "        \"loadPolicy\": \"IMMEDIATE\",\n"
919     "        \"releasePolicy\": \"NEVER\"\n"
920     "      },\n"
921     "      \"signals\": [\n"
922     "        {\n"
923     "          \"name\": \"onStage\",\n"
924     "          \"action\": \"play\",\n"
925     "          \"animation\": \"Animation_1\"\n"
926     "        }\n"
927     "      ]\n"
928     "    }\n"
929     "  ],\n"
930     "  \"paths\": {},\n"
931     "  \"animations\": {\n"
932     "    \"Animation_1\": {\n"
933     "      \"loop\":true,\n"
934     "      \"properties\": [\n"
935     "        {\n"
936     "          \"actor\": \"Image1\",\n"
937     "          \"property\": \"uTime\",\n"
938     "          \"value\": 10.0,\n"
939     "          \"alphaFunction\": \"LINEAR\",\n"
940     "          \"timePeriod\": {\n"
941     "            \"delay\": 0,\n"
942     "            \"duration\": 10.0\n"
943     "          },\n"
944     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
945     "        }\n"
946     "      ]\n"
947     "    }\n"
948     "  },\n"
949     "  \"shaderEffects\": {\n"
950     "    \"Ripple2D\": {\n"
951     "      \"program\": {\n"
952     "        \"vertexPrefix\": \"\",\n"
953     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
954     "        \"fragmentPrefix\": \"\",\n"
955     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
956     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
957     "      },\n"
958     "      \"geometryHints\": \"HINT_NONE\",\n"
959     "      \"gridDensity\": 0,\n"
960     "      \"loop\": true,\n"
961     "      \"uAmplitude\": 0.02,\n"
962     "      \"uTime\": 0.0\n"
963     "    }\n"
964     "  }\n"
965     "}\n"
966
967   );
968
969   Builder builder = Builder::New();
970   builder.LoadFromString( json );
971
972   ShaderEffect effect = builder.GetShaderEffect("Ripple2D");
973
974   // coverage
975   DALI_TEST_CHECK( effect );
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 int UtcDaliBuilderShaderEffect2P(void)
1022 {
1023   ToolkitTestApplication application;
1024
1025   // JSON with a quit event when the actor is touched
1026   std::string json(
1027     "{\n"
1028     "\"templates\":\n"
1029     "{\n"
1030     "  \"imageTree\": { \n"
1031     "    \"type\": \"ImageActor\",\n"
1032     "    \"size\": [100,100,1],\n"
1033     "    \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1034     "    \"position\": [\n"
1035     "      0.40461349487305,\n"
1036     "      0.9150390625,\n"
1037     "      0.0\n"
1038     "    ],\n"
1039     "    \"signals\": [{\n"
1040     "      \"name\": \"touched\",\n"
1041     "      \"action\": \"quit\"\n"
1042     "    }],\n"
1043     "    \"actors\": [\n"
1044     "      {\n"
1045     "        \"type\":\"ImageActor\",\n"
1046     "        \"name\":\"childImage\" \n"
1047     "      }\n"
1048     "    ]\n"
1049     "  }\n"
1050     "},\n"
1051     "  \"stage\": [\n"
1052     "    {\n"
1053     "      \"type\": \"imageTree\",\n"
1054     "      \"name\": \"Image1\",\n"
1055     "      \"effect\": \"Ripple2D\",\n"
1056     "      \"image\": \"offscreen\""
1057     "    }\n"
1058     "  ],\n"
1059     "  \"shaderEffects\": {\n"
1060     "    \"Ripple2D\": {\n"
1061     "      \"program\": {\n"
1062     "        \"vertexPrefix\": \"\",\n"
1063     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1064     "        \"fragmentPrefix\": \"\",\n"
1065     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1066     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1067     "      },\n"
1068     "      \"geometryHints\": \"HINT_NONE\",\n"
1069     "      \"gridDensity\": 0,\n"
1070     "      \"loop\": true,\n"
1071     "      \"uAmplitude\": 0.02,\n"
1072     "      \"uTime\": 0.0\n"
1073     "    }\n"
1074     "  },\n"
1075     "  \"frameBufferImages\": {\n"
1076     "    \"offscreen\": {\n"
1077     "      \"type\": \"FrameBufferImage\","
1078     "      \"pixelFormat\":\"RGBA8888\","
1079     "      \"width\": 400,"
1080     "      \"height\": 400"
1081     "    }"
1082     "   }"
1083     "}\n"
1084
1085   );
1086
1087   Builder builder = Builder::New();
1088   builder.LoadFromString( json );
1089
1090   // coverage
1091   DALI_TEST_CHECK( true );
1092
1093   END_TEST;
1094 }
1095
1096 int UtcDaliBuilderAddActorsP(void)
1097 {
1098   ToolkitTestApplication application;
1099
1100   // JSON with a quit event when the actor is touched
1101   std::string json(
1102       "{\n"
1103       "  \"arbitarysection\":\n"
1104       "  [{\n"
1105       "    \"type\": \"Actor\",\n"
1106       "    \"name\": \"actor\",\n"
1107       "    \"size\": [100,100,1],\n"
1108       "    \"parentOrigin\": \"TOP_LEFT\",\n"
1109       "    \"anchorPoint\": \"TOP_LEFT\",\n"
1110       "    \"actors\": [{\n"
1111       "      \"type\": \"Actor\",\n"
1112       "      \"name\": \"subActor\",\n"
1113       "      \"visible\": false\n"
1114       "    }],\n"
1115       "    \"signals\": [{\n"
1116       "      \"name\": \"touched\",\n"
1117       "      \"action\": \"hide\",\n"
1118       "      \"actor\": \"actor\",\n"
1119       "      \"childActor\": \"subActor\"\n"
1120       "    }]\n"
1121       "  }]\n"
1122       "}\n"
1123   );
1124
1125   Builder builder = Builder::New();
1126   builder.LoadFromString( json );
1127   builder.AddActors ( "arbitarysection", Stage::GetCurrent().GetRootLayer() );
1128
1129   // Render and notify
1130   application.SendNotification();
1131   application.Render();
1132
1133   Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("subActor");
1134   DALI_TEST_CHECK( actor );
1135
1136   DALI_TEST_CHECK( !actor.IsVisible() );
1137
1138   END_TEST;
1139 }
1140
1141 int UtcDaliBuilderFrameBufferP(void)
1142 {
1143   ToolkitTestApplication application;
1144
1145   // JSON with a quit event when the actor is touched
1146   std::string json(
1147     "{\n"
1148     "  \"constants\":\n"
1149     "  {\n"
1150     "    \"FB_WIDTH\": 200.0,\n"
1151     "    \"FB_HEIGHT\": 200.0,\n"
1152     "    \"FB_SIZE\": [200,200],\n"
1153     "    \"FB_ASPECT_RATIO\": 1\n"
1154     "  },\n"
1155     "  \"stage\": [\n"
1156     "    {\n"
1157     "      \"type\": \"ImageActor\",\n"
1158     "      \"name\": \"fbOnStage\",\n"
1159     "      \"position\": [\n"
1160     "        0.40461349487305,\n"
1161     "        0.9150390625,\n"
1162     "        0.0\n"
1163     "      ],\n"
1164     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1165     "      \"size\": [300, 300, 0],\n"
1166     "      \"image\": \"fb0\",\n"
1167     "      \"clearColor\": [1,0,0,1]\n"
1168     "    },\n"
1169     "    {\n"
1170     "      \"type\": \"ImageActor\",\n"
1171     "      \"name\": \"Image1\",\n"
1172     "      \"size\": [200, 200, 0],\n"
1173     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1174     "      \"effect\": \"Ripple2D\",\n"
1175     "      \"image\": {\n"
1176     "        \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1177     "        \"width\": 200,\n"
1178     "        \"height\": 80,\n"
1179     "        \"loadPolicy\": \"IMMEDIATE\",\n"
1180     "        \"releasePolicy\": \"NEVER\"\n"
1181     "      },\n"
1182     "      \"signals\": [\n"
1183     "        {\n"
1184     "          \"name\": \"onStage\",\n"
1185     "          \"action\": \"play\",\n"
1186     "          \"animation\": \"Animation_1\"\n"
1187     "        }\n"
1188     "      ]\n"
1189     "    },\n"
1190     "    {\n"
1191     "      \"type\":\"CameraActor\",\n"
1192     "      \"name\":\"fbCam\",\n"
1193     "      \"aspectRatio\": \"{FB_ASPECT_RATIO}\",\n"
1194     "      \"projectionMode\": \"PERSPECTIVE_PROJECTION\",\n"
1195     "      \"fieldOfView\": 0.785,\n"
1196     "      \"invertYAxis\": true\n"
1197     "    }\n"
1198     "  ],\n"
1199     "  \"frameBufferImages\":\n"
1200     "  {\n"
1201     "    \"fb0\":\n"
1202     "    {\n"
1203     "      \"type\": \"FrameBufferImage\",\n"
1204     "      \"width\": { \"typeCast\":\"float\", \"value\":\"{FB_WIDTH}\" },\n"
1205     "      \"height\": { \"typeCast\":\"float\", \"value\":\"{FB_HEIGHT}\" }\n"
1206     "    }\n"
1207     "  },\n"
1208     "  \"renderTasks\":\n"
1209     "  {\n"
1210     "    \"stage\":\n"
1211     "    [\n"
1212     "      {\n"
1213     "        \"sourceActor\": \"fbOnStage\"\n"
1214     "      },\n"
1215     "      {\n"
1216     "        \"sourceActor\": \"Image1\",\n"
1217     "        \"targetFrameBuffer\": \"fb0\",\n"
1218     "        \"viewportSize\":\"{FB_SIZE}\",\n"
1219     "        \"cameraActor\":\"fbCam\"\n"
1220     "      }\n"
1221     "    ]\n"
1222     "  },\n"
1223     "  \"paths\": {},\n"
1224     "  \"animations\": {\n"
1225     "    \"Animation_1\": {\n"
1226     "      \"loop\":true,\n"
1227     "      \"properties\": [\n"
1228     "        {\n"
1229     "          \"actor\": \"Image1\",\n"
1230     "          \"property\": \"uTime\",\n"
1231     "          \"value\": 10.0,\n"
1232     "          \"alphaFunction\": \"LINEAR\",\n"
1233     "          \"timePeriod\": {\n"
1234     "            \"delay\": 0,\n"
1235     "            \"duration\": 10.0\n"
1236     "          },\n"
1237     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1238     "        }\n"
1239     "      ]\n"
1240     "    }\n"
1241     "  },\n"
1242     "  \"shaderEffects\": {\n"
1243     "    \"Ripple2D\": {\n"
1244     "      \"program\": {\n"
1245     "        \"vertexPrefix\": \"\",\n"
1246     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1247     "        \"fragmentPrefix\": \"\",\n"
1248     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1249     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1250     "      },\n"
1251     "      \"geometryHints\": \"HINT_NONE\",\n"
1252     "      \"gridDensity\": 0,\n"
1253     "      \"loop\": true,\n"
1254     "      \"uAmplitude\": 0.02,\n"
1255     "      \"uTime\": 0.0\n"
1256     "    }\n"
1257     "  }\n"
1258     "}\n");
1259
1260   Builder builder = Builder::New();
1261
1262   // frame buffer coverage
1263   builder.LoadFromString( json );
1264
1265   // Render and notify
1266   application.SendNotification();
1267   application.Render();
1268
1269   Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1270   DALI_TEST_CHECK( frameBuffer );
1271
1272   Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1273   DALI_TEST_CHECK( frameBuffer2 );
1274   DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1275
1276   DALI_TEST_CHECK( true );
1277
1278   END_TEST;
1279 }
1280
1281 int UtcDaliBuilderPathConstraintsP(void)
1282 {
1283   ToolkitTestApplication application;
1284
1285   // JSON with a quit event when the actor is touched
1286   std::string json(
1287     "{\n"
1288     "  \"constants\":\n"
1289     "  {\n"
1290     "    \"FB_WIDTH\": 200.0,\n"
1291     "    \"FB_HEIGHT\": 200.0,\n"
1292     "    \"FB_SIZE\": [200,200],\n"
1293     "    \"FB_ASPECT_RATIO\": 1\n"
1294     "  },\n"
1295     "  \"stage\": [\n"
1296     "    {\n"
1297     "      \"type\": \"ImageActor\",\n"
1298     "      \"name\": \"Image1\",\n"
1299     "      \"size\": [200, 200, 0],\n"
1300     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1301     "      \"effect\": \"Ripple2D\",\n"
1302     "      \"image\": {\n"
1303     "        \"filename\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\",\n"
1304     "        \"width\": 200,\n"
1305     "        \"height\": 80,\n"
1306     "        \"loadPolicy\": \"IMMEDIATE\",\n"
1307     "        \"releasePolicy\": \"NEVER\"\n"
1308     "      },\n"
1309     "      \"signals\": [\n"
1310     "        {\n"
1311     "          \"name\": \"onStage\",\n"
1312     "          \"action\": \"play\",\n"
1313     "          \"animation\": \"pathAnimation\"\n"
1314     "        },\n"
1315     "        {\n"
1316     "          \"name\": \"onStage\",\n"
1317     "          \"action\": \"applyConstraint\",\n"
1318     "          \"constrainer\": \"constrainer0\",\n"
1319     "          \"properties\":\n"
1320     "          [\n"
1321     "            {\n"
1322     "              \"source\": \"Image1\",\n"
1323     "              \"sourceProperty\": \"positionX\",\n"
1324     "              \"target\": \"Image1\",\n"
1325     "              \"targetProperty\": \"colorRed\",\n"
1326     "              \"range\": [-300,300]\n"
1327     "            }\n"
1328     "          ]\n"
1329     "        },\n"
1330     "        {\n"
1331     "          \"name\": \"onStage\",\n"
1332     "          \"action\": \"applyConstraint\",\n"
1333     "          \"constrainer\": \"constrainer1\",\n"
1334     "          \"properties\":\n"
1335     "          [\n"
1336     "            {\n"
1337     "              \"source\": \"Image1\",\n"
1338     "              \"sourceProperty\": \"positionX\",\n"
1339     "              \"target\": \"Image1\",\n"
1340     "              \"targetProperty\": \"colorBlue\",\n"
1341     "              \"range\": [-300,300]\n"
1342     "            }\n"
1343     "          ]\n"
1344     "        }\n"
1345     "      ]\n"
1346     "    }\n"
1347     "  ],\n"
1348     "  \"paths\":\n"
1349     "  {\n"
1350     "    \"path0\":\n"
1351     "    {\n"
1352     "      \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1353     "      \"curvature\":0.35\n"
1354     "    }\n"
1355     "  },\n"
1356     "  \"constrainers\":\n"
1357     "  {\n"
1358     "    \"constrainer0\":\n"
1359     "    {\n"
1360     "      \"type\": \"PathConstrainer\",\n"
1361     "      \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1362     "      \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1363     "    },\n"
1364     "    \"constrainer1\":\n"
1365     "    {\n"
1366     "      \"type\": \"LinearConstrainer\",\n"
1367     "      \"value\": [ 0, 0, 0 ]\n"
1368     "    }\n"
1369     "  },\n"
1370     "  \"animations\": {\n"
1371     "    \"pathAnimation\": {\n"
1372     "      \"duration\": 3.0,\n"
1373     "      \"properties\":\n"
1374     "      [{\n"
1375     "        \"actor\": \"Image1\",\n"
1376     "        \"path\":\"path0\",\n"
1377     "        \"forward\":[1,0,0],\n"
1378     "        \"alphaFunction\": \"EASE_IN_OUT\",\n"
1379     "        \"timePeriod\": {\n"
1380     "          \"delay\": 0,\n"
1381     "          \"duration\": 3\n"
1382     "        }\n"
1383     "      },\n"
1384     "       {\n"
1385     "         \"actor\": \"Image1\",\n"
1386     "         \"property\": \"uTime\",\n"
1387     "         \"value\": 10.0,\n"
1388     "         \"alphaFunction\": \"LINEAR\",\n"
1389     "         \"timePeriod\": {\n"
1390     "           \"delay\": 0,\n"
1391     "           \"duration\": 10.0\n"
1392     "         },\n"
1393     "         \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1394     "       }]\n"
1395     "    },\n"
1396     "    \"Animation_1\": {\n"
1397     "      \"loop\":true,\n"
1398     "      \"properties\": [\n"
1399     "        {\n"
1400     "          \"actor\": \"Image1\",\n"
1401     "          \"property\": \"uTime\",\n"
1402     "          \"value\": 10.0,\n"
1403     "          \"alphaFunction\": \"LINEAR\",\n"
1404     "          \"timePeriod\": {\n"
1405     "            \"delay\": 0,\n"
1406     "            \"duration\": 10.0\n"
1407     "          },\n"
1408     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1409     "        }\n"
1410     "      ]\n"
1411     "    }\n"
1412     "  },\n"
1413     "  \"shaderEffects\": {\n"
1414     "    \"Ripple2D\": {\n"
1415     "      \"program\": {\n"
1416     "        \"vertexPrefix\": \"\",\n"
1417     "        \"vertex\": \"void main(void)\\n{\\n  gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n  vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
1418     "        \"fragmentPrefix\": \"\",\n"
1419     "        \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n  highp float len = length(pos);\\n  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
1420     "        \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
1421     "      },\n"
1422     "      \"geometryHints\": \"HINT_NONE\",\n"
1423     "      \"gridDensity\": 0,\n"
1424     "      \"loop\": true,\n"
1425     "      \"uAmplitude\": 0.02,\n"
1426     "      \"uTime\": 0.0\n"
1427     "    }\n"
1428     "  }\n"
1429     "}\n");
1430
1431   Builder builder = Builder::New();
1432
1433   // frame buffer coverage
1434   builder.LoadFromString( json );
1435
1436   // Render and notify
1437   application.SendNotification();
1438   application.Render();
1439
1440   Dali::Path path =  builder.GetPath( "path0" );
1441   DALI_TEST_CHECK( path );
1442
1443   Dali::Path path2 =  builder.GetPath( "path0" );
1444   DALI_TEST_CHECK( path2 );
1445   DALI_TEST_CHECK( path == path2 );
1446
1447   Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1448   DALI_TEST_CHECK( constrainer0 );
1449
1450   Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1451   DALI_TEST_CHECK( constrainer0_2 );
1452   DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1453
1454   Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1455   DALI_TEST_CHECK( constrainer1 );
1456
1457   Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1458   DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1459
1460   END_TEST;
1461 }
1462
1463 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1464   {                                                                       \
1465     Property::Value* value = xMap->Find( xKey );                          \
1466     DALI_TEST_EQUALS( value==NULL, false, xLocation);                     \
1467     if( value != NULL )                                                   \
1468     {                                                                     \
1469       DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation );         \
1470       xType result;                                                       \
1471       value->Get(result);                                                 \
1472       DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION );               \
1473       std::ostringstream oss;                                             \
1474       oss << "Animation element " << xKey << "= " << result << std::endl; \
1475       tet_printf( oss.str().c_str() );                                    \
1476     }                                                                     \
1477     else                                                                  \
1478     {                                                                     \
1479       tet_printf("Can't find map element " xKey "\n");                    \
1480     }                                                                     \
1481   }
1482
1483
1484 int UtcDaliBuilderMapping01(void)
1485 {
1486   ToolkitTestApplication application;
1487
1488   const char* json =
1489     "{\n"
1490     "  \"mappings\":\n"
1491     "  {\n"
1492     "    \"buttonPressFadeOut\":{\n"
1493     "      \"alphaFunction\":\"EASE_OUT\",\n"
1494     "      \"timePeriod\":{\n"
1495     "        \"delay\":0.0,\n"
1496     "        \"duration\":0.4\n"
1497     "      }\n"
1498     "    },\n"
1499     "    \"buttonPressFadeIn\":{\n"
1500     "      \"alphaFunction\":\"EASE_IN\",\n"
1501     "      \"timePeriod\":{\n"
1502     "        \"delay\":0.4,\n"
1503     "        \"duration\":0.5\n"
1504     "      }\n"
1505     "    },\n"
1506     "    \"transition:buttonPressed\":\n"
1507     "    [\n"
1508     "      {\n"
1509     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1510     "        \"property\": \"opacity\",\n"
1511     "        \"value\": 0,\n"
1512     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1513     "      }\n"
1514     "    ],\n"
1515     "    \"transition:buttonReleased\":\n"
1516     "    [\n"
1517     "      {\n"
1518     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1519     "        \"property\": \"opacity\",\n"
1520     "        \"value\": 1,\n"
1521     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1522     "      },\n"
1523     "      {\n"
1524     "        \"target\": \"unselectedForegroundRenderer\",\n"
1525     "        \"property\": \"scale\",\n"
1526     "        \"value\": [ 1, 1, 1 ],\n"
1527     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1528     "      },\n"
1529     "      {\n"
1530     "        \"target\": \"selectedBackgroundRenderer\",\n"
1531     "        \"property\": \"opacity\",\n"
1532     "        \"value\": 0,\n"
1533     "        \"animator\": \"<buttonPressFadeOut>\"\n"
1534     "      },\n"
1535     "      {\n"
1536     "        \"target\": \"selectedForegroundRenderer\",\n"
1537     "        \"property\": \"scale\",\n"
1538     "        \"value\": [ 0, 0, 0 ],\n"
1539     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1540     "      }\n"
1541     "    ]\n"
1542     "  },\n"
1543     "  \"styles\":\n"
1544     "  {\n"
1545     "    \"testbutton\":\n"
1546     "    {\n"
1547     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1548     "      \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1549     "    }\n"
1550     "  }\n"
1551     "}\n";
1552
1553   Builder builder = Builder::New();
1554   builder.LoadFromString( json );
1555
1556   Test::TestButton testButton = Test::TestButton::New();
1557   Stage::GetCurrent().Add( testButton );
1558
1559   // Render and notify
1560   application.SendNotification();
1561   application.Render();
1562
1563   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1564
1565   // Now check that it has loaded the transition correctly:
1566   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1567   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1568   Property::Array* array = transition.GetArray();
1569
1570   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1571   Property::Value element = array->GetElementAt(0);
1572   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1573   Property::Map* map = element.GetMap();
1574
1575   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1576   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1577   CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1578   CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1579   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1580
1581   END_TEST;
1582 }
1583
1584
1585 int UtcDaliBuilderMappingCycleCheck(void)
1586 {
1587   ToolkitTestApplication application;
1588
1589   std::string json(
1590     "{\n"
1591     "  \"mappings\":\n"
1592     "  {\n"
1593     "    \"cyclicKey1\":\"<cyclicKey1>\",\n"
1594     "    \"cyclicKey2\":\"<cyclicKey3>\",\n"
1595     "    \"cyclicKey3\":\"<cyclicKey2>\",\n"
1596     "    \"FadeOut\":{\n"
1597     "      \"alphaFunction\":\"EASE_IN\",\n"
1598     "      \"timePeriod\":{\n"
1599     "        \"delay\":\"<cyclicKey3>\",\n"
1600     "        \"duration\":0.6\n"
1601     "      }\n"
1602     "    },\n"
1603     "    \"transition:buttonPressed\":\n"
1604     "    [\n"
1605     "      {\n"
1606     "        \"target\": \"<cyclicKey1>\",\n"
1607     "        \"property\": \"<cyclicKey2>\",\n"
1608     "        \"value\": 0,\n"
1609     "        \"animator\":\"<FadeOut>\"\n"
1610     "      }\n"
1611     "    ]\n"
1612     "  },\n"
1613     "  \"styles\":\n"
1614     "  {\n"
1615     "    \"testbutton\":\n"
1616     "    {\n"
1617     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1618     "      \"releaseTransition\":\"<cyclicKey2>\",\n"
1619     "      \"disabledTransition\":\"<cyclicKey3>\",\n"
1620     "      \"enabledTransition\":\"<unknownKey>\"\n"
1621     "    }\n"
1622     "  }\n"
1623     "}\n");
1624
1625   Builder builder = Builder::New();
1626   builder.LoadFromString( json );
1627
1628   Test::TestButton testButton = Test::TestButton::New();
1629   Stage::GetCurrent().Add( testButton );
1630
1631   // Render and notify
1632   application.SendNotification();
1633   application.Render();
1634
1635   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1636
1637   // Now check that it has loaded the transition correctly:
1638   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1639   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1640   Property::Array* array = transition.GetArray();
1641
1642   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1643   Property::Value element = array->GetElementAt(0);
1644   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1645   Property::Map* map = element.GetMap();
1646
1647   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1648   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1649   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1650
1651   END_TEST;
1652 }