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