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