cc2f064cb6585ac286107e873687329ca83cd44c
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Shader.cpp
1 /*
2  * Copyright (c) 2024 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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <mesh-builder.h>
21 #include <stdlib.h>
22
23 #include <iostream>
24
25 using namespace Dali;
26
27 void utc_dali_shader_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_shader_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39 static const char* VertexSource =
40   "This is a custom vertex shader\n"
41   "made on purpose to look nothing like a normal vertex shader inside dali\n";
42
43 static const char* FragmentSource =
44   "This is a custom fragment shader\n"
45   "made on purpose to look nothing like a normal fragment shader inside dali\n";
46
47 static const char* VertexSource2 =
48   "This is a custom vertex shader2\n"
49   "made on purpose to look nothing like a normal vertex shader inside dali\n";
50
51 static const char* FragmentSource2 =
52   "This is a custom fragment shader2\n"
53   "made on purpose to look nothing like a normal fragment shader inside dali\n";
54
55 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
56 {
57   current.b = 0.0f;
58 }
59
60 } // namespace
61
62 int UtcDaliShaderMethodNew01(void)
63 {
64   TestApplication application;
65
66   Shader shader = Shader::New(VertexSource, FragmentSource);
67   DALI_TEST_EQUALS((bool)shader, true, TEST_LOCATION);
68   END_TEST;
69 }
70
71 int UtcDaliShaderMethodNew02(void)
72 {
73   TestApplication application;
74
75   Property::Map map;
76   Shader        shader = Shader::New(map);
77   DALI_TEST_EQUALS((bool)shader, true, TEST_LOCATION);
78   END_TEST;
79 }
80
81 int UtcDaliShaderMethodNew03(void)
82 {
83   TestApplication application;
84
85   Property::Map array;
86   Shader        shader = Shader::New(array);
87   DALI_TEST_EQUALS((bool)shader, true, TEST_LOCATION);
88   END_TEST;
89 }
90
91 int UtcDaliShaderMethodNew04(void)
92 {
93   TestApplication application;
94
95   Shader shader;
96   DALI_TEST_EQUALS((bool)shader, false, TEST_LOCATION);
97   END_TEST;
98 }
99
100 int UtcDaliShaderMethodNew05(void)
101 {
102   TestApplication application;
103
104   Shader shader = Shader::New(VertexSource, FragmentSource, Shader::Hint::NONE, "testShader");
105   DALI_TEST_EQUALS((bool)shader, true, TEST_LOCATION);
106   END_TEST;
107 }
108
109 int UtcDaliShaderAssignmentOperator(void)
110 {
111   TestApplication application;
112
113   Shader shader1 = Shader::New(VertexSource, FragmentSource);
114
115   Shader shader2;
116
117   DALI_TEST_CHECK(!(shader1 == shader2));
118
119   shader2 = shader1;
120
121   DALI_TEST_CHECK(shader1 == shader2);
122
123   shader2 = Shader::New(VertexSource, FragmentSource);
124   ;
125
126   DALI_TEST_CHECK(!(shader1 == shader2));
127
128   END_TEST;
129 }
130
131 int UtcDaliShaderMoveConstructor(void)
132 {
133   TestApplication application;
134
135   Shader shader = Shader::New(VertexSource, FragmentSource);
136   DALI_TEST_CHECK(shader);
137   DALI_TEST_EQUALS(1, shader.GetBaseObject().ReferenceCount(), TEST_LOCATION);
138
139   // Register a custom property
140   Vector2         vec(1.0f, 2.0f);
141   Property::Index customIndex = shader.RegisterProperty("custom", vec);
142   DALI_TEST_EQUALS(shader.GetProperty<Vector2>(customIndex), vec, TEST_LOCATION);
143
144   Shader move = std::move(shader);
145   DALI_TEST_CHECK(move);
146   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
147   DALI_TEST_EQUALS(move.GetProperty<Vector2>(customIndex), vec, TEST_LOCATION);
148   DALI_TEST_CHECK(!shader);
149
150   END_TEST;
151 }
152
153 int UtcDaliShaderMoveAssignment(void)
154 {
155   TestApplication application;
156
157   Shader shader = Shader::New(VertexSource, FragmentSource);
158   DALI_TEST_CHECK(shader);
159   DALI_TEST_EQUALS(1, shader.GetBaseObject().ReferenceCount(), TEST_LOCATION);
160
161   // Register a custom property
162   Vector2         vec(1.0f, 2.0f);
163   Property::Index customIndex = shader.RegisterProperty("custom", vec);
164   DALI_TEST_EQUALS(shader.GetProperty<Vector2>(customIndex), vec, TEST_LOCATION);
165
166   Shader move;
167   move = std::move(shader);
168   DALI_TEST_CHECK(move);
169   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
170   DALI_TEST_EQUALS(move.GetProperty<Vector2>(customIndex), vec, TEST_LOCATION);
171   DALI_TEST_CHECK(!shader);
172
173   END_TEST;
174 }
175
176 int UtcDaliShaderDownCast01(void)
177 {
178   TestApplication application;
179
180   Shader shader = Shader::New(VertexSource, FragmentSource);
181
182   BaseHandle handle(shader);
183   Shader     shader2 = Shader::DownCast(handle);
184   DALI_TEST_EQUALS((bool)shader2, true, TEST_LOCATION);
185   END_TEST;
186 }
187
188 int UtcDaliShaderDownCast02(void)
189 {
190   TestApplication application;
191
192   Handle handle = Handle::New(); // Create a custom object
193   Shader shader = Shader::DownCast(handle);
194   DALI_TEST_EQUALS((bool)shader, false, TEST_LOCATION);
195   END_TEST;
196 }
197
198 int UtcDaliShaderDefaultProperties(void)
199 {
200   TestApplication application;
201   // from shader-impl.cpp
202   // DALI_PROPERTY( "program",       MAP,     true,     false,     false,  Dali::Shader::Property::PROGRAM )
203
204   Shader shader = Shader::New(VertexSource, FragmentSource);
205   DALI_TEST_EQUALS(shader.GetPropertyCount(), 1, TEST_LOCATION);
206
207   DALI_TEST_EQUALS(shader.GetPropertyName(Shader::Property::PROGRAM), "program", TEST_LOCATION);
208   DALI_TEST_EQUALS(shader.GetPropertyIndex("program"), (Property::Index)Shader::Property::PROGRAM, TEST_LOCATION);
209   DALI_TEST_EQUALS(shader.GetPropertyType(Shader::Property::PROGRAM), Property::MAP, TEST_LOCATION);
210   DALI_TEST_EQUALS(shader.IsPropertyWritable(Shader::Property::PROGRAM), true, TEST_LOCATION);
211   DALI_TEST_EQUALS(shader.IsPropertyAnimatable(Shader::Property::PROGRAM), false, TEST_LOCATION);
212   DALI_TEST_EQUALS(shader.IsPropertyAConstraintInput(Shader::Property::PROGRAM), false, TEST_LOCATION);
213
214   END_TEST;
215 }
216
217 int UtcDaliShaderConstraint01(void)
218 {
219   TestApplication application;
220
221   tet_infoline("Test that a non-uniform shader property can be constrained");
222
223   Shader   shader   = Shader::New(VertexSource, FragmentSource);
224   Geometry geometry = CreateQuadGeometry();
225   Renderer renderer = Renderer::New(geometry, shader);
226
227   Actor actor = Actor::New();
228   actor.AddRenderer(renderer);
229   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
230   application.GetScene().Add(actor);
231
232   Vector4         initialColor = Color::WHITE;
233   Property::Index colorIndex   = shader.RegisterProperty("uFadeColor", initialColor);
234
235   application.SendNotification();
236   application.Render(0);
237   DALI_TEST_EQUALS(shader.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
238
239   // Apply constraint
240   Constraint constraint = Constraint::New<Vector4>(shader, colorIndex, TestConstraintNoBlue);
241   constraint.Apply();
242   application.SendNotification();
243   application.Render(0);
244
245   // Expect no blue component in either buffer - yellow
246   DALI_TEST_EQUALS(shader.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
247   application.Render(0);
248   DALI_TEST_EQUALS(shader.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
249
250   shader.RemoveConstraints();
251   shader.SetProperty(colorIndex, Color::WHITE);
252   application.SendNotification();
253   application.Render(0);
254   DALI_TEST_EQUALS(shader.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
255
256   END_TEST;
257 }
258
259 int UtcDaliShaderConstraint02(void)
260 {
261   TestApplication application;
262
263   tet_infoline("Test that a uniform map shader property can be constrained");
264
265   Shader   shader   = Shader::New(VertexSource, FragmentSource);
266   Geometry geometry = CreateQuadGeometry();
267   Renderer renderer = Renderer::New(geometry, shader);
268
269   Actor actor = Actor::New();
270   actor.AddRenderer(renderer);
271   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
272   application.GetScene().Add(actor);
273   application.SendNotification();
274   application.Render(0);
275
276   Vector4         initialColor = Color::WHITE;
277   Property::Index colorIndex   = shader.RegisterProperty("uFadeColor", initialColor);
278
279   TestGlAbstraction& gl = application.GetGlAbstraction();
280
281   application.SendNotification();
282   application.Render(0);
283
284   Vector4 actualValue(Vector4::ZERO);
285   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
286   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
287
288   // Apply constraint
289   Constraint constraint = Constraint::New<Vector4>(shader, colorIndex, TestConstraintNoBlue);
290   constraint.Apply();
291   application.SendNotification();
292   application.Render(0);
293
294   // Expect no blue component in either buffer - yellow
295   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
296   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
297
298   application.Render(0);
299   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
300   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
301
302   shader.RemoveConstraints();
303   shader.SetProperty(colorIndex, Color::WHITE);
304   application.SendNotification();
305   application.Render(0);
306
307   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
308   DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
309
310   END_TEST;
311 }
312
313 int UtcDaliShaderAnimatedProperty01(void)
314 {
315   TestApplication application;
316
317   tet_infoline("Test that a non-uniform shader property can be animated");
318
319   Shader   shader   = Shader::New(VertexSource, FragmentSource);
320   Geometry geometry = CreateQuadGeometry();
321   Renderer renderer = Renderer::New(geometry, shader);
322
323   Actor actor = Actor::New();
324   actor.AddRenderer(renderer);
325   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
326   application.GetScene().Add(actor);
327
328   Vector4         initialColor = Color::WHITE;
329   Property::Index colorIndex   = shader.RegisterProperty("uFadeColor", initialColor);
330
331   application.SendNotification();
332   application.Render(0);
333   DALI_TEST_EQUALS(shader.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
334
335   Animation animation = Animation::New(1.0f);
336   KeyFrames keyFrames = KeyFrames::New();
337   keyFrames.Add(0.0f, initialColor);
338   keyFrames.Add(1.0f, Color::TRANSPARENT);
339   animation.AnimateBetween(Property(shader, colorIndex), keyFrames);
340   animation.Play();
341
342   application.SendNotification();
343   application.Render(500);
344
345   DALI_TEST_EQUALS(shader.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
346
347   application.Render(500);
348
349   DALI_TEST_EQUALS(shader.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
350
351   END_TEST;
352 }
353
354 int UtcDaliShaderAnimatedProperty02(void)
355 {
356   TestApplication application;
357
358   tet_infoline("Test that a uniform map shader property can be animated");
359
360   Shader   shader   = Shader::New(VertexSource, FragmentSource);
361   Geometry geometry = CreateQuadGeometry();
362   Renderer renderer = Renderer::New(geometry, shader);
363
364   Actor actor = Actor::New();
365   actor.AddRenderer(renderer);
366   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
367   application.GetScene().Add(actor);
368   application.SendNotification();
369   application.Render(0);
370
371   Vector4         initialColor = Color::WHITE;
372   Property::Index colorIndex   = shader.RegisterProperty("uFadeColor", initialColor);
373
374   TestGlAbstraction& gl = application.GetGlAbstraction();
375
376   application.SendNotification();
377   application.Render(0);
378
379   Vector4 actualValue(Vector4::ZERO);
380   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
381   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
382
383   Animation animation = Animation::New(1.0f);
384   KeyFrames keyFrames = KeyFrames::New();
385   keyFrames.Add(0.0f, initialColor);
386   keyFrames.Add(1.0f, Color::TRANSPARENT);
387   animation.AnimateBetween(Property(shader, colorIndex), keyFrames);
388   animation.Play();
389
390   application.SendNotification();
391   application.Render(500);
392
393   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
394   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
395
396   application.Render(500);
397   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
398   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
399
400   // change shader program
401   Property::Map map;
402   map["vertex"]   = VertexSource;
403   map["fragment"] = FragmentSource;
404   map["hints"]    = "MODIFIES_GEOMETRY";
405   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
406   application.SendNotification();
407   application.Render(100);
408
409   // register another custom property as well
410   Property::Index customIndex = shader.RegisterProperty("uCustom3", Vector3(1, 2, 3));
411   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
412
413   application.SendNotification();
414   application.Render(100);
415
416   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
417   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
418
419   Vector3 customValue;
420   DALI_TEST_CHECK(gl.GetUniformValue<Vector3>("uCustom3", customValue));
421   DALI_TEST_EQUALS(customValue, Vector3(1, 2, 3), TEST_LOCATION);
422   END_TEST;
423 }
424
425 int UtcDaliShaderProgramProperty(void)
426 {
427   TestApplication application;
428
429   tet_infoline("Test get/set progam property");
430
431   Shader      shader  = Shader::New("", "");
432   std::string hintSet = "MODIFIES_GEOMETRY";
433
434   Property::Map map;
435   map["vertex"]   = VertexSource;
436   map["fragment"] = FragmentSource;
437   map["hints"]    = hintSet;
438
439   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
440   // register a custom property as well
441   Property::Index customIndex = shader.RegisterProperty("custom", Vector3(1, 2, 3));
442   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
443
444   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
445   DALI_TEST_CHECK(value.GetType() == Property::MAP);
446   const Property::Map* outMap = value.GetMap();
447
448   std::string v = (*outMap)["vertex"].Get<std::string>();
449   std::string f = (*outMap)["fragment"].Get<std::string>();
450   std::string h = (*outMap)["hints"].Get<std::string>();
451
452   DALI_TEST_CHECK(v == VertexSource);
453   DALI_TEST_CHECK(f == FragmentSource);
454   DALI_TEST_CHECK(h == hintSet);
455
456   value = shader.GetCurrentProperty(Shader::Property::PROGRAM);
457   DALI_TEST_CHECK(value.GetType() == Property::MAP);
458   outMap = value.GetMap();
459   // check that changing the shader did not cause us to loose custom property
460   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
461   using Dali::Animation;
462   Animation animation = Animation::New(0.1f);
463   animation.AnimateTo(Property(shader, customIndex), Vector3(4, 5, 6));
464   animation.Play();
465   application.SendNotification();
466   application.Render(100);
467   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(4, 5, 6), TEST_LOCATION);
468
469   v = (*outMap)["vertex"].Get<std::string>();
470   f = (*outMap)["fragment"].Get<std::string>();
471   h = (*outMap)["hints"].Get<std::string>();
472
473   DALI_TEST_CHECK(v == VertexSource);
474   DALI_TEST_CHECK(f == FragmentSource);
475   DALI_TEST_CHECK(h == hintSet);
476
477   std::string hintGot;
478
479   hintSet      = "OUTPUT_IS_TRANSPARENT,MODIFIES_GEOMETRY";
480   map["hints"] = hintSet;
481   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
482   value   = shader.GetProperty(Shader::Property::PROGRAM);
483   hintGot = (*value.GetMap())["hints"].Get<std::string>();
484   DALI_TEST_CHECK(hintGot == hintSet);
485
486   hintSet      = "OUTPUT_IS_TRANSPARENT";
487   map["hints"] = hintSet;
488   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
489   value   = shader.GetProperty(Shader::Property::PROGRAM);
490   hintGot = (*value.GetMap())["hints"].Get<std::string>();
491   DALI_TEST_CHECK(hintGot == hintSet);
492
493   hintSet      = "NONE";
494   map["hints"] = hintSet;
495   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
496   value   = shader.GetProperty(Shader::Property::PROGRAM);
497   hintGot = (*value.GetMap())["hints"].Get<std::string>();
498   DALI_TEST_CHECK(hintGot == hintSet);
499
500   hintSet      = "";
501   map["hints"] = hintSet;
502   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
503   value   = shader.GetProperty(Shader::Property::PROGRAM);
504   hintGot = (*value.GetMap())["hints"].Get<std::string>();
505   DALI_TEST_CHECK(hintGot == "NONE");
506
507   END_TEST;
508 }
509
510 int UtcDaliShaderPropertyValueConstructorMap(void)
511 {
512   TestApplication application;
513
514   tet_infoline("UtcDaliShaderPropertyValueConstructorMap");
515
516   std::string   hintSet = "MODIFIES_GEOMETRY";
517   Property::Map map;
518   map["vertex"]        = VertexSource;
519   map["fragment"]      = FragmentSource;
520   map["renderPassTag"] = 0;
521   map["hints"]         = hintSet;
522   map["name"]          = "Test";
523
524   Shader shader = Shader::New(map);
525
526   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
527   DALI_TEST_CHECK(value.GetType() == Property::MAP);
528
529   const Property::Map* outMap = value.GetMap();
530   std::string          v      = (*outMap)["vertex"].Get<std::string>();
531   std::string          f      = (*outMap)["fragment"].Get<std::string>();
532   std::string          h      = (*outMap)["hints"].Get<std::string>();
533   int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
534   std::string          n      = (*outMap)["name"].Get<std::string>();
535
536   DALI_TEST_CHECK(v == map["vertex"].Get<std::string>());
537   DALI_TEST_CHECK(f == map["fragment"].Get<std::string>());
538   DALI_TEST_CHECK(h == map["hints"].Get<std::string>());
539   DALI_TEST_CHECK(r == map["renderPassTag"].Get<int32_t>());
540   DALI_TEST_CHECK(n == map["name"].Get<std::string>());
541
542   END_TEST;
543 }
544
545 int UtcDaliShaderPropertyValueConstructorMap2(void)
546 {
547   TestApplication application;
548
549   tet_infoline("UtcDaliShaderPropertyValueConstructorMap2");
550
551   std::string   hintSet = "MODIFIES_GEOMETRY";
552   Property::Map map;
553   map["vertex"]        = VertexSource;
554   map["fragment"]      = FragmentSource;
555   map["renderPassTag"] = 0;
556   map["hints"]         = Shader::Hint::Value::MODIFIES_GEOMETRY;
557   map["name"]          = "Test";
558
559   Shader shader = Shader::New(map);
560
561   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
562   DALI_TEST_CHECK(value.GetType() == Property::MAP);
563
564   const Property::Map* outMap = value.GetMap();
565   std::string          v      = (*outMap)["vertex"].Get<std::string>();
566   std::string          f      = (*outMap)["fragment"].Get<std::string>();
567   std::string          h      = (*outMap)["hints"].Get<std::string>();
568   int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
569   std::string          n      = (*outMap)["name"].Get<std::string>();
570
571   DALI_TEST_CHECK(v == map["vertex"].Get<std::string>());
572   DALI_TEST_CHECK(f == map["fragment"].Get<std::string>());
573   // Note : shader.GetProperty return string even we input hints as enum.
574   DALI_TEST_CHECK(h == hintSet);
575   DALI_TEST_CHECK(r == map["renderPassTag"].Get<int32_t>());
576   DALI_TEST_CHECK(n == map["name"].Get<std::string>());
577
578   END_TEST;
579 }
580
581 int UtcDaliShaderPropertyValueConstructorArray(void)
582 {
583   TestApplication application;
584
585   tet_infoline("UtcDaliShaderPropertyValueConstructorArray");
586
587   std::string   hintSet = "MODIFIES_GEOMETRY";
588   Property::Map map[2];
589   map[0]["vertex"]        = VertexSource;
590   map[0]["fragment"]      = FragmentSource;
591   map[0]["renderPassTag"] = 0;
592   map[0]["hints"]         = hintSet;
593   map[0]["name"]          = "Test0";
594
595   map[1]["vertex"]        = VertexSource2;
596   map[1]["fragment"]      = FragmentSource2;
597   map[1]["renderPassTag"] = 1;
598   map[1]["hints"]         = hintSet;
599   map[1]["name"]          = "Test1";
600
601   Property::Array array;
602   array.PushBack(map[0]);
603   array.PushBack(map[1]);
604
605   Shader shader = Shader::New(array);
606
607   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
608   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
609
610   const Property::Array* outArray   = value.GetArray();
611   uint32_t               arrayCount = outArray->Size();
612   DALI_TEST_CHECK(arrayCount == 2u);
613
614   for(uint32_t i = 0; i < arrayCount; ++i)
615   {
616     const Property::Map* outMap = outArray->GetElementAt(i).GetMap();
617     std::string          v      = (*outMap)["vertex"].Get<std::string>();
618     std::string          f      = (*outMap)["fragment"].Get<std::string>();
619     std::string          h      = (*outMap)["hints"].Get<std::string>();
620     int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
621     std::string          n      = (*outMap)["name"].Get<std::string>();
622
623     DALI_TEST_CHECK(v == map[i]["vertex"].Get<std::string>());
624     DALI_TEST_CHECK(f == map[i]["fragment"].Get<std::string>());
625     DALI_TEST_CHECK(h == map[i]["hints"].Get<std::string>());
626     DALI_TEST_CHECK(r == map[i]["renderPassTag"].Get<int32_t>());
627     DALI_TEST_CHECK(n == map[i]["name"].Get<std::string>());
628   }
629
630   END_TEST;
631 }
632
633 int UtcDaliShaderProgramPropertyArray(void)
634 {
635   TestApplication application;
636
637   tet_infoline("Test get/set progam property array");
638
639   Shader      shader  = Shader::New("", "");
640   std::string hintSet = "MODIFIES_GEOMETRY";
641
642   Property::Map map[2];
643   map[0]["vertex"]        = VertexSource;
644   map[0]["fragment"]      = FragmentSource;
645   map[0]["renderPassTag"] = 0;
646   map[0]["hints"]         = hintSet;
647   map[0]["name"]          = "Test0";
648
649   map[1]["vertex"]        = VertexSource2;
650   map[1]["fragment"]      = FragmentSource2;
651   map[1]["renderPassTag"] = 1;
652   map[1]["hints"]         = hintSet;
653   map[1]["name"]          = "Test1";
654
655   Property::Array array;
656   array.PushBack(map[0]);
657   array.PushBack(map[1]);
658
659   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(array));
660
661   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
662   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
663
664   const Property::Array* outArray   = value.GetArray();
665   uint32_t               arrayCount = outArray->Size();
666   DALI_TEST_CHECK(arrayCount == 2u);
667
668   for(uint32_t i = 0; i < arrayCount; ++i)
669   {
670     const Property::Map* outMap = outArray->GetElementAt(i).GetMap();
671     std::string          v      = (*outMap)["vertex"].Get<std::string>();
672     std::string          f      = (*outMap)["fragment"].Get<std::string>();
673     std::string          h      = (*outMap)["hints"].Get<std::string>();
674     int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
675     std::string          n      = (*outMap)["name"].Get<std::string>();
676
677     DALI_TEST_CHECK(v == map[i]["vertex"].Get<std::string>());
678     DALI_TEST_CHECK(f == map[i]["fragment"].Get<std::string>());
679     DALI_TEST_CHECK(h == map[i]["hints"].Get<std::string>());
680     DALI_TEST_CHECK(r == map[i]["renderPassTag"].Get<int32_t>());
681     DALI_TEST_CHECK(n == map[i]["name"].Get<std::string>());
682   }
683
684   END_TEST;
685 }
686
687 int UtcDaliShaderWrongData(void)
688 {
689   TestApplication application;
690
691   tet_infoline("Test get/set wrong data");
692
693   Shader shader = Shader::New(Property::Value(1.0f));
694
695   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
696   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
697
698   const Property::Array* outArray   = value.GetArray();
699   uint32_t               arrayCount = outArray->Size();
700   DALI_TEST_CHECK(arrayCount == 0u);
701
702   END_TEST;
703 }