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