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