Button Upgrade to use Text Visual
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Builder.cpp
1 /*
2  * Copyright (c) 2016-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     "}\n");
1306
1307   Builder builder = Builder::New();
1308
1309   // frame buffer coverage
1310   builder.LoadFromString( json );
1311
1312   // Render and notify
1313   application.SendNotification();
1314   application.Render();
1315
1316   Dali::FrameBufferImage frameBuffer = builder.GetFrameBufferImage( "fb0" );
1317   DALI_TEST_CHECK( frameBuffer );
1318
1319   Dali::FrameBufferImage frameBuffer2 = builder.GetFrameBufferImage( "fb0" );
1320   DALI_TEST_CHECK( frameBuffer2 );
1321   DALI_TEST_CHECK( frameBuffer == frameBuffer2 );
1322
1323   DALI_TEST_CHECK( true );
1324
1325   END_TEST;
1326 }
1327
1328 int UtcDaliBuilderPathConstraintsP(void)
1329 {
1330   ToolkitTestApplication application;
1331
1332   // JSON with a quit event when the actor is touched
1333   std::string json(
1334     "{\n"
1335     "  \"constants\":\n"
1336     "  {\n"
1337     "    \"FB_WIDTH\": 200.0,\n"
1338     "    \"FB_HEIGHT\": 200.0,\n"
1339     "    \"FB_SIZE\": [200,200],\n"
1340     "    \"FB_ASPECT_RATIO\": 1\n"
1341     "  },\n"
1342     "  \"stage\": [\n"
1343     "    {\n"
1344     "      \"type\": \"ImageView\",\n"
1345     "      \"name\": \"Image1\",\n"
1346     "      \"size\": [200, 200, 0],\n"
1347     "      \"parentOrigin\": [0.5, 0.5, 0.5],\n"
1348     "      \"effect\": \"Ripple2D\",\n"
1349     "      \"image\": {\n"
1350     "        \"url\": \"{DALI_IMAGE_DIR}gallery-medium-25.jpg\"\n"
1351     "      },\n"
1352     "      \"signals\": [\n"
1353     "        {\n"
1354     "          \"name\": \"onStage\",\n"
1355     "          \"action\": \"play\",\n"
1356     "          \"animation\": \"pathAnimation\"\n"
1357     "        },\n"
1358     "        {\n"
1359     "          \"name\": \"onStage\",\n"
1360     "          \"action\": \"applyConstraint\",\n"
1361     "          \"constrainer\": \"constrainer0\",\n"
1362     "          \"properties\":\n"
1363     "          [\n"
1364     "            {\n"
1365     "              \"source\": \"Image1\",\n"
1366     "              \"sourceProperty\": \"positionX\",\n"
1367     "              \"target\": \"Image1\",\n"
1368     "              \"targetProperty\": \"colorRed\",\n"
1369     "              \"range\": [-300,300]\n"
1370     "            }\n"
1371     "          ]\n"
1372     "        },\n"
1373     "        {\n"
1374     "          \"name\": \"onStage\",\n"
1375     "          \"action\": \"applyConstraint\",\n"
1376     "          \"constrainer\": \"constrainer1\",\n"
1377     "          \"properties\":\n"
1378     "          [\n"
1379     "            {\n"
1380     "              \"source\": \"Image1\",\n"
1381     "              \"sourceProperty\": \"positionX\",\n"
1382     "              \"target\": \"Image1\",\n"
1383     "              \"targetProperty\": \"colorBlue\",\n"
1384     "              \"range\": [-300,300]\n"
1385     "            }\n"
1386     "          ]\n"
1387     "        },\n"
1388     "        {\n"
1389     "          \"name\": \"offStage\",\n"
1390     "          \"action\": \"removeConstraints\",\n"
1391     "          \"constrainer\": \"constrainer0\",\n"
1392     "          \"properties\":\n"
1393     "          [\n"
1394     "            {\n"
1395     "              \"source\": \"Image1\",\n"
1396     "              \"sourceProperty\": \"positionX\",\n"
1397     "              \"target\": \"Image1\",\n"
1398     "              \"targetProperty\": \"colorRed\",\n"
1399     "              \"range\": [-300,300]\n"
1400     "            }\n"
1401     "          ]\n"
1402     "        },\n"
1403     "        {\n"
1404     "          \"name\": \"offStage\",\n"
1405     "          \"action\": \"removeConstraints\",\n"
1406     "          \"constrainer\": \"constrainer1\",\n"
1407     "          \"properties\":\n"
1408     "          [\n"
1409     "            {\n"
1410     "              \"source\": \"Image1\",\n"
1411     "              \"sourceProperty\": \"positionX\",\n"
1412     "              \"target\": \"Image1\",\n"
1413     "              \"targetProperty\": \"colorBlue\",\n"
1414     "              \"range\": [-300,300]\n"
1415     "            }\n"
1416     "          ]\n"
1417     "        }\n"
1418     "      ]\n"
1419     "    }\n"
1420     "  ],\n"
1421     "  \"paths\":\n"
1422     "  {\n"
1423     "    \"path0\":\n"
1424     "    {\n"
1425     "      \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],\n"
1426     "      \"curvature\":0.35\n"
1427     "    }\n"
1428     "  },\n"
1429     "  \"constrainers\":\n"
1430     "  {\n"
1431     "    \"constrainer0\":\n"
1432     "    {\n"
1433     "      \"type\": \"PathConstrainer\",\n"
1434     "      \"points\": [ [0, 0, 0], [0,0,0], [0,0,0] ],\n"
1435     "      \"controlPoints\": [ [0, 0, 0], [0,0,0], [0,0,0] ]\n"
1436     "    },\n"
1437     "    \"constrainer1\":\n"
1438     "    {\n"
1439     "      \"type\": \"LinearConstrainer\",\n"
1440     "      \"value\": [ 0, 0, 0 ]\n"
1441     "    }\n"
1442     "  },\n"
1443     "  \"animations\": {\n"
1444     "    \"pathAnimation\": {\n"
1445     "      \"duration\": 3.0,\n"
1446     "      \"properties\":\n"
1447     "      [{\n"
1448     "        \"actor\": \"Image1\",\n"
1449     "        \"path\":\"path0\",\n"
1450     "        \"forward\":[1,0,0],\n"
1451     "        \"alphaFunction\": \"EASE_IN_OUT\",\n"
1452     "        \"timePeriod\": {\n"
1453     "          \"delay\": 0,\n"
1454     "          \"duration\": 3\n"
1455     "        }\n"
1456     "      },\n"
1457     "       {\n"
1458     "         \"actor\": \"Image1\",\n"
1459     "         \"property\": \"uTime\",\n"
1460     "         \"value\": 10.0,\n"
1461     "         \"alphaFunction\": \"LINEAR\",\n"
1462     "         \"timePeriod\": {\n"
1463     "           \"delay\": 0,\n"
1464     "           \"duration\": 10.0\n"
1465     "         },\n"
1466     "         \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1467     "       }]\n"
1468     "    },\n"
1469     "    \"Animation_1\": {\n"
1470     "      \"loop\":true,\n"
1471     "      \"properties\": [\n"
1472     "        {\n"
1473     "          \"actor\": \"Image1\",\n"
1474     "          \"property\": \"uTime\",\n"
1475     "          \"value\": 10.0,\n"
1476     "          \"alphaFunction\": \"LINEAR\",\n"
1477     "          \"timePeriod\": {\n"
1478     "            \"delay\": 0,\n"
1479     "            \"duration\": 10.0\n"
1480     "          },\n"
1481     "          \"gui-builder-timeline-color\": \"#8dc0da\"\n"
1482     "        }\n"
1483     "      ]\n"
1484     "    }\n"
1485     "  }\n"
1486     "}\n");
1487
1488   Builder builder = Builder::New();
1489
1490   // frame buffer coverage
1491   builder.LoadFromString( json );
1492
1493   // Render and notify
1494   application.SendNotification();
1495   application.Render();
1496
1497   Dali::Path path =  builder.GetPath( "path0" );
1498   DALI_TEST_CHECK( path );
1499
1500   Dali::Path path2 =  builder.GetPath( "path0" );
1501   DALI_TEST_CHECK( path2 );
1502   DALI_TEST_CHECK( path == path2 );
1503
1504   Dali::PathConstrainer constrainer0 = builder.GetPathConstrainer( "constrainer0" );
1505   DALI_TEST_CHECK( constrainer0 );
1506
1507   Dali::PathConstrainer constrainer0_2 = builder.GetPathConstrainer( "constrainer0" );
1508   DALI_TEST_CHECK( constrainer0_2 );
1509   DALI_TEST_CHECK( constrainer0 == constrainer0_2 );
1510
1511   Dali::LinearConstrainer constrainer1 = builder.GetLinearConstrainer( "constrainer1" );
1512   DALI_TEST_CHECK( constrainer1 );
1513
1514   Dali::LinearConstrainer constrainer1_2 = builder.GetLinearConstrainer( "constrainer1" );
1515   DALI_TEST_CHECK( constrainer1 == constrainer1_2 );
1516
1517   // For coverage
1518
1519   Actor actor = Actor::New();
1520   Stage::GetCurrent().Add( actor );
1521   builder.AddActors( actor );
1522
1523   // Render and notify
1524   application.SendNotification();
1525   application.Render();
1526
1527   actor.GetChildAt( 0 ).Unparent();
1528
1529   END_TEST;
1530 }
1531
1532 #define CHECK_MAP_ELEMENT( xMap, xKey, xType, xPropType, xExpected, xLocation ) \
1533   {                                                                       \
1534     Property::Value* value = xMap->Find( xKey );                          \
1535     DALI_TEST_EQUALS( value==NULL, false, xLocation);                     \
1536     if( value != NULL )                                                   \
1537     {                                                                     \
1538       DALI_TEST_EQUALS( value->GetType(), xPropType, xLocation );         \
1539       xType result;                                                       \
1540       value->Get(result);                                                 \
1541       DALI_TEST_EQUALS( result, xExpected, TEST_LOCATION );               \
1542       std::ostringstream oss;                                             \
1543       oss << "Animation element " << xKey << "= " << result << std::endl; \
1544       tet_printf( oss.str().c_str() );                                    \
1545     }                                                                     \
1546     else                                                                  \
1547     {                                                                     \
1548       tet_printf("Can't find map element " xKey "\n");                    \
1549     }                                                                     \
1550   }
1551
1552
1553 int UtcDaliBuilderMapping01(void)
1554 {
1555   ToolkitTestApplication application;
1556
1557   const char* json =
1558     "{\n"
1559     "  \"mappings\":\n"
1560     "  {\n"
1561     "    \"buttonPressFadeOut\":{\n"
1562     "      \"alphaFunction\":\"EASE_OUT\",\n"
1563     "      \"timePeriod\":{\n"
1564     "        \"delay\":0.0,\n"
1565     "        \"duration\":0.4\n"
1566     "      }\n"
1567     "    },\n"
1568     "    \"buttonPressFadeIn\":{\n"
1569     "      \"alphaFunction\":\"EASE_IN\",\n"
1570     "      \"timePeriod\":{\n"
1571     "        \"delay\":0.4,\n"
1572     "        \"duration\":0.5\n"
1573     "      }\n"
1574     "    },\n"
1575     "    \"transition:buttonPressed\":\n"
1576     "    [\n"
1577     "      {\n"
1578     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1579     "        \"property\": \"opacity\",\n"
1580     "        \"value\": 0,\n"
1581     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1582     "      }\n"
1583     "    ],\n"
1584     "    \"transition:buttonReleased\":\n"
1585     "    [\n"
1586     "      {\n"
1587     "        \"target\": \"unselectedBackgroundRenderer\",\n"
1588     "        \"property\": \"opacity\",\n"
1589     "        \"value\": 1,\n"
1590     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1591     "      },\n"
1592     "      {\n"
1593     "        \"target\": \"unselectedForegroundRenderer\",\n"
1594     "        \"property\": \"scale\",\n"
1595     "        \"value\": [ 1, 1, 1 ],\n"
1596     "        \"animator\":\"<buttonPressFadeIn>\"\n"
1597     "      },\n"
1598     "      {\n"
1599     "        \"target\": \"selectedBackgroundRenderer\",\n"
1600     "        \"property\": \"opacity\",\n"
1601     "        \"value\": 0,\n"
1602     "        \"animator\": \"<buttonPressFadeOut>\"\n"
1603     "      },\n"
1604     "      {\n"
1605     "        \"target\": \"selectedForegroundRenderer\",\n"
1606     "        \"property\": \"scale\",\n"
1607     "        \"value\": [ 0, 0, 0 ],\n"
1608     "        \"animator\":\"<buttonPressFadeOut>\"\n"
1609     "      }\n"
1610     "    ]\n"
1611     "  },\n"
1612     "  \"styles\":\n"
1613     "  {\n"
1614     "    \"testbutton\":\n"
1615     "    {\n"
1616     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1617     "      \"releaseTransition\":\"<transition:buttonReleased>\"\n"
1618     "    }\n"
1619     "  }\n"
1620     "}\n";
1621
1622   Builder builder = Builder::New();
1623   builder.LoadFromString( json );
1624
1625   Test::TestButton testButton = Test::TestButton::New();
1626   Stage::GetCurrent().Add( testButton );
1627
1628   // Render and notify
1629   application.SendNotification();
1630   application.Render();
1631
1632   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1633
1634   // Now check that it has loaded the transition correctly:
1635   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1636   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1637   Property::Array* array = transition.GetArray();
1638
1639   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1640   Property::Value element = array->GetElementAt(0);
1641   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1642   Property::Map* map = element.GetMap();
1643
1644   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "unselectedBackgroundRenderer", TEST_LOCATION);
1645   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "opacity", TEST_LOCATION);
1646   CHECK_MAP_ELEMENT(map, "alphaFunction", int, Property::INTEGER, (int)Dali::AlphaFunction::EASE_OUT, TEST_LOCATION);
1647   CHECK_MAP_ELEMENT(map, "timePeriodDelay", float, Property::FLOAT, 0.0f, TEST_LOCATION);
1648   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.4f, TEST_LOCATION);
1649
1650   END_TEST;
1651 }
1652
1653
1654 int UtcDaliBuilderMappingCycleCheck(void)
1655 {
1656   ToolkitTestApplication application;
1657
1658   std::string json(
1659     "{\n"
1660     "  \"mappings\":\n"
1661     "  {\n"
1662     "    \"cyclicKey1\":\"<cyclicKey1>\",\n"
1663     "    \"cyclicKey2\":\"<cyclicKey3>\",\n"
1664     "    \"cyclicKey3\":\"<cyclicKey2>\",\n"
1665     "    \"FadeOut\":{\n"
1666     "      \"alphaFunction\":\"EASE_IN\",\n"
1667     "      \"timePeriod\":{\n"
1668     "        \"delay\":\"<cyclicKey3>\",\n"
1669     "        \"duration\":0.6\n"
1670     "      }\n"
1671     "    },\n"
1672     "    \"transition:buttonPressed\":\n"
1673     "    [\n"
1674     "      {\n"
1675     "        \"target\": \"<cyclicKey1>\",\n"
1676     "        \"property\": \"<cyclicKey2>\",\n"
1677     "        \"value\": 0,\n"
1678     "        \"animator\":\"<FadeOut>\"\n"
1679     "      }\n"
1680     "    ]\n"
1681     "  },\n"
1682     "  \"styles\":\n"
1683     "  {\n"
1684     "    \"testbutton\":\n"
1685     "    {\n"
1686     "      \"pressTransition\":\"<transition:buttonPressed>\",\n"
1687     "      \"releaseTransition\":\"<cyclicKey2>\",\n"
1688     "      \"disabledTransition\":\"<cyclicKey3>\",\n"
1689     "      \"enabledTransition\":\"<unknownKey>\"\n"
1690     "    }\n"
1691     "  }\n"
1692     "}\n");
1693
1694   Builder builder = Builder::New();
1695   builder.LoadFromString( json );
1696
1697   Test::TestButton testButton = Test::TestButton::New();
1698   Stage::GetCurrent().Add( testButton );
1699
1700   // Render and notify
1701   application.SendNotification();
1702   application.Render();
1703
1704   DALI_TEST_CHECK( builder.ApplyStyle( "testbutton", testButton ) );
1705
1706   // Now check that it has loaded the transition correctly:
1707   Property::Value transition = testButton.GetProperty(Test::TestButton::Property::PRESS_TRANSITION);
1708   DALI_TEST_EQUALS( transition.GetType(), Property::ARRAY, TEST_LOCATION );
1709   Property::Array* array = transition.GetArray();
1710
1711   DALI_TEST_EQUALS( array->Size(), 1, TEST_LOCATION );
1712   Property::Value element = array->GetElementAt(0);
1713   DALI_TEST_CHECK( element.GetType() == Property::MAP );
1714   Property::Map* map = element.GetMap();
1715
1716   CHECK_MAP_ELEMENT(map, "target", std::string, Property::STRING, "", TEST_LOCATION);
1717   CHECK_MAP_ELEMENT(map, "property", std::string, Property::STRING, "", TEST_LOCATION);
1718   CHECK_MAP_ELEMENT(map, "timePeriodDuration", float, Property::FLOAT, 0.6f, TEST_LOCATION);
1719
1720   END_TEST;
1721 }
1722
1723 int UtcDaliBuilderTypeCasts(void)
1724 {
1725   ToolkitTestApplication application;
1726
1727   std::string json(
1728     "{"
1729        "\"stage\":"
1730        "[{"
1731          "\"type\": \"Layer\","
1732          "\"maximumSize\": { \"typeCast\":\"vector2\", \"value\":[100,15] },"
1733          "\"position\":    { \"typeCast\":\"vector3\", \"value\":[100,10,1] },"
1734          "\"color\":       { \"typeCast\":\"vector4\", \"value\":[0.5,0.5,0.5,1] },"
1735          "\"sensitive\":   { \"typeCast\":\"boolean\", \"value\":false },"
1736          "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
1737          "\"colorMode\":   { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
1738          "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] }"
1739       "}]"
1740     "}"
1741   );
1742
1743   Actor rootActor = Actor::New();
1744   Stage::GetCurrent().Add( rootActor );
1745
1746   Builder builder = Builder::New();
1747   builder.LoadFromString( json );
1748   builder.AddActors( rootActor );
1749
1750   application.SendNotification();
1751   application.Render();
1752
1753   Actor createdActor = rootActor.GetChildAt( 0 );
1754   DALI_TEST_EQUALS( createdActor.GetMaximumSize(), Vector2(100.0f,15.0f), TEST_LOCATION );
1755   DALI_TEST_EQUALS( createdActor.GetCurrentPosition(), Vector3(100.0f,10.0f,1.0f), TEST_LOCATION );
1756   DALI_TEST_EQUALS( createdActor.GetCurrentColor(), Vector4(0.5f,0.5f,0.5f,1.0f), TEST_LOCATION );
1757   DALI_TEST_EQUALS( createdActor.IsSensitive(), false, TEST_LOCATION );
1758   DALI_TEST_EQUALS( createdActor.GetColorMode(), USE_OWN_MULTIPLY_PARENT_COLOR, TEST_LOCATION );
1759
1760   END_TEST;
1761 }
1762
1763 int UtcDaliBuilderBuilderControl(void)
1764 {
1765   ToolkitTestApplication application;
1766
1767   std::string json(
1768     "{"
1769        "\"stage\":"
1770        "[{"
1771          "\"type\": \"BuilderControl\","
1772          "\"integerProperty\": 10,"
1773          "\"matrix3Property\": [ 1,2,3,4,5,6,7,8,9 ],"
1774          "\"matrixProperty\":  [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],"
1775          "\"noneProperty\": 10"
1776       "}]"
1777     "}"
1778   );
1779
1780   Actor rootActor = Actor::New();
1781   Stage::GetCurrent().Add( rootActor );
1782
1783   Builder builder = Builder::New();
1784   builder.LoadFromString( json );
1785   builder.AddActors( rootActor );
1786
1787   application.SendNotification();
1788   application.Render();
1789
1790   DALI_TEST_EQUALS( BuilderControlProperty::gSetPropertyCalledCount, 4, TEST_LOCATION );
1791
1792   END_TEST;
1793 }
1794
1795 int UtcDaliBuilderActionsWithParams(void)
1796 {
1797   ToolkitTestApplication application;
1798
1799   // JSON with a quit event when the actor is touched
1800   std::string json(
1801       "{\n"
1802       "\"stage\":\n"
1803       "[\n"
1804       "  { \n"
1805       "    \"type\": \"ImageView\",\n"
1806       "    \"name\": \"image\",\n"
1807       "    \"size\": [100,100,1],\n"
1808       "    \"signals\": [{\n"
1809       "      \"name\": \"touch\",\n"
1810       "      \"action\": \"show\",\n"
1811       "      \"parameters\": {\n"
1812       "        \"property1\" : 10,\n"
1813       "        \"property2\" : [1,2],\n"
1814       "        \"property3\" : [1,2,3],\n"
1815       "        \"property4\" : [1,2,3,4]\n"
1816       "      }\n"
1817       "    }]\n"
1818       "  }\n"
1819       "]\n"
1820       "}\n"
1821   );
1822
1823   Builder builder = Builder::New();
1824   builder.LoadFromString( json );
1825   builder.AddActors( Stage::GetCurrent().GetRootLayer() );
1826
1827   DALI_TEST_CHECK( true ); // For Coverage
1828
1829   END_TEST;
1830 }