[dali_2.3.24] Merge branch 'devel/master'
[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 UtcDaliShaderGetShaderLanguageVersion(void)
355 {
356   TestApplication application;
357
358   tet_infoline("Test get shader language version");
359
360   auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
361
362   try
363   {
364     uint32_t expectVersion                                = 100;
365     application.GetGlAbstraction().mShaderLanguageVersion = expectVersion;
366
367     DALI_TEST_EQUALS(Dali::Shader::GetShaderLanguageVersion(), expectVersion, TEST_LOCATION);
368
369     expectVersion                                         = 200;
370     application.GetGlAbstraction().mShaderLanguageVersion = expectVersion;
371
372     DALI_TEST_EQUALS(Dali::Shader::GetShaderLanguageVersion(), expectVersion, TEST_LOCATION);
373   }
374   catch(...)
375   {
376     DALI_TEST_CHECK(false);
377   }
378
379   application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
380
381   END_TEST;
382 }
383
384 int UtcDaliShaderAnimatedProperty02(void)
385 {
386   TestApplication application;
387
388   tet_infoline("Test that a uniform map shader property can be animated");
389
390   Shader   shader   = Shader::New(VertexSource, FragmentSource);
391   Geometry geometry = CreateQuadGeometry();
392   Renderer renderer = Renderer::New(geometry, shader);
393
394   Actor actor = Actor::New();
395   actor.AddRenderer(renderer);
396   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
397   application.GetScene().Add(actor);
398   application.SendNotification();
399   application.Render(0);
400
401   Vector4         initialColor = Color::WHITE;
402   Property::Index colorIndex   = shader.RegisterProperty("uFadeColor", initialColor);
403
404   TestGlAbstraction& gl = application.GetGlAbstraction();
405
406   application.SendNotification();
407   application.Render(0);
408
409   Vector4 actualValue(Vector4::ZERO);
410   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
411   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
412
413   Animation animation = Animation::New(1.0f);
414   KeyFrames keyFrames = KeyFrames::New();
415   keyFrames.Add(0.0f, initialColor);
416   keyFrames.Add(1.0f, Color::TRANSPARENT);
417   animation.AnimateBetween(Property(shader, colorIndex), keyFrames);
418   animation.Play();
419
420   application.SendNotification();
421   application.Render(500);
422
423   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
424   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
425
426   application.Render(500);
427   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
428   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
429
430   // change shader program
431   Property::Map map;
432   map["vertex"]   = VertexSource;
433   map["fragment"] = FragmentSource;
434   map["hints"]    = "MODIFIES_GEOMETRY";
435   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
436   application.SendNotification();
437   application.Render(100);
438
439   // register another custom property as well
440   Property::Index customIndex = shader.RegisterProperty("uCustom3", Vector3(1, 2, 3));
441   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
442
443   application.SendNotification();
444   application.Render(100);
445
446   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
447   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
448
449   Vector3 customValue;
450   DALI_TEST_CHECK(gl.GetUniformValue<Vector3>("uCustom3", customValue));
451   DALI_TEST_EQUALS(customValue, Vector3(1, 2, 3), TEST_LOCATION);
452   END_TEST;
453 }
454
455 int UtcDaliShaderProgramProperty(void)
456 {
457   TestApplication application;
458
459   tet_infoline("Test get/set progam property");
460
461   Shader      shader  = Shader::New("", "");
462   std::string hintSet = "MODIFIES_GEOMETRY";
463
464   Property::Map map;
465   map["vertex"]   = VertexSource;
466   map["fragment"] = FragmentSource;
467   map["hints"]    = hintSet;
468
469   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
470   // register a custom property as well
471   Property::Index customIndex = shader.RegisterProperty("custom", Vector3(1, 2, 3));
472   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
473
474   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
475   DALI_TEST_CHECK(value.GetType() == Property::MAP);
476   const Property::Map* outMap = value.GetMap();
477
478   std::string v = (*outMap)["vertex"].Get<std::string>();
479   std::string f = (*outMap)["fragment"].Get<std::string>();
480   std::string h = (*outMap)["hints"].Get<std::string>();
481
482   DALI_TEST_CHECK(v == VertexSource);
483   DALI_TEST_CHECK(f == FragmentSource);
484   DALI_TEST_CHECK(h == hintSet);
485
486   value = shader.GetCurrentProperty(Shader::Property::PROGRAM);
487   DALI_TEST_CHECK(value.GetType() == Property::MAP);
488   outMap = value.GetMap();
489   // check that changing the shader did not cause us to loose custom property
490   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
491   using Dali::Animation;
492   Animation animation = Animation::New(0.1f);
493   animation.AnimateTo(Property(shader, customIndex), Vector3(4, 5, 6));
494   animation.Play();
495   application.SendNotification();
496   application.Render(100);
497   DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(4, 5, 6), TEST_LOCATION);
498
499   v = (*outMap)["vertex"].Get<std::string>();
500   f = (*outMap)["fragment"].Get<std::string>();
501   h = (*outMap)["hints"].Get<std::string>();
502
503   DALI_TEST_CHECK(v == VertexSource);
504   DALI_TEST_CHECK(f == FragmentSource);
505   DALI_TEST_CHECK(h == hintSet);
506
507   std::string hintGot;
508
509   hintSet      = "OUTPUT_IS_TRANSPARENT,MODIFIES_GEOMETRY";
510   map["hints"] = hintSet;
511   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
512   value   = shader.GetProperty(Shader::Property::PROGRAM);
513   hintGot = (*value.GetMap())["hints"].Get<std::string>();
514   DALI_TEST_CHECK(hintGot == hintSet);
515
516   hintSet      = "OUTPUT_IS_TRANSPARENT";
517   map["hints"] = hintSet;
518   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
519   value   = shader.GetProperty(Shader::Property::PROGRAM);
520   hintGot = (*value.GetMap())["hints"].Get<std::string>();
521   DALI_TEST_CHECK(hintGot == hintSet);
522
523   hintSet      = "NONE";
524   map["hints"] = hintSet;
525   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
526   value   = shader.GetProperty(Shader::Property::PROGRAM);
527   hintGot = (*value.GetMap())["hints"].Get<std::string>();
528   DALI_TEST_CHECK(hintGot == hintSet);
529
530   hintSet      = "";
531   map["hints"] = hintSet;
532   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(map));
533   value   = shader.GetProperty(Shader::Property::PROGRAM);
534   hintGot = (*value.GetMap())["hints"].Get<std::string>();
535   DALI_TEST_CHECK(hintGot == "NONE");
536
537   END_TEST;
538 }
539
540 int UtcDaliShaderPropertyValueConstructorMap(void)
541 {
542   TestApplication application;
543
544   tet_infoline("UtcDaliShaderPropertyValueConstructorMap");
545
546   std::string   hintSet = "MODIFIES_GEOMETRY";
547   Property::Map map;
548   map["vertex"]        = VertexSource;
549   map["fragment"]      = FragmentSource;
550   map["renderPassTag"] = 0;
551   map["hints"]         = hintSet;
552   map["name"]          = "Test";
553
554   Shader shader = Shader::New(map);
555
556   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
557   DALI_TEST_CHECK(value.GetType() == Property::MAP);
558
559   const Property::Map* outMap = value.GetMap();
560   std::string          v      = (*outMap)["vertex"].Get<std::string>();
561   std::string          f      = (*outMap)["fragment"].Get<std::string>();
562   std::string          h      = (*outMap)["hints"].Get<std::string>();
563   int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
564   std::string          n      = (*outMap)["name"].Get<std::string>();
565
566   DALI_TEST_CHECK(v == map["vertex"].Get<std::string>());
567   DALI_TEST_CHECK(f == map["fragment"].Get<std::string>());
568   DALI_TEST_CHECK(h == map["hints"].Get<std::string>());
569   DALI_TEST_CHECK(r == map["renderPassTag"].Get<int32_t>());
570   DALI_TEST_CHECK(n == map["name"].Get<std::string>());
571
572   END_TEST;
573 }
574
575 int UtcDaliShaderPropertyValueConstructorMap2(void)
576 {
577   TestApplication application;
578
579   tet_infoline("UtcDaliShaderPropertyValueConstructorMap2");
580
581   std::string   hintSet = "MODIFIES_GEOMETRY";
582   Property::Map map;
583   map["vertex"]        = VertexSource;
584   map["fragment"]      = FragmentSource;
585   map["renderPassTag"] = 0;
586   map["hints"]         = Shader::Hint::Value::MODIFIES_GEOMETRY;
587   map["name"]          = "Test";
588
589   Shader shader = Shader::New(map);
590
591   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
592   DALI_TEST_CHECK(value.GetType() == Property::MAP);
593
594   const Property::Map* outMap = value.GetMap();
595   std::string          v      = (*outMap)["vertex"].Get<std::string>();
596   std::string          f      = (*outMap)["fragment"].Get<std::string>();
597   std::string          h      = (*outMap)["hints"].Get<std::string>();
598   int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
599   std::string          n      = (*outMap)["name"].Get<std::string>();
600
601   DALI_TEST_CHECK(v == map["vertex"].Get<std::string>());
602   DALI_TEST_CHECK(f == map["fragment"].Get<std::string>());
603   // Note : shader.GetProperty return string even we input hints as enum.
604   DALI_TEST_CHECK(h == hintSet);
605   DALI_TEST_CHECK(r == map["renderPassTag"].Get<int32_t>());
606   DALI_TEST_CHECK(n == map["name"].Get<std::string>());
607
608   END_TEST;
609 }
610
611 int UtcDaliShaderPropertyValueConstructorArray(void)
612 {
613   TestApplication application;
614
615   tet_infoline("UtcDaliShaderPropertyValueConstructorArray");
616
617   std::string   hintSet = "MODIFIES_GEOMETRY";
618   Property::Map map[2];
619   map[0]["vertex"]        = VertexSource;
620   map[0]["fragment"]      = FragmentSource;
621   map[0]["renderPassTag"] = 0;
622   map[0]["hints"]         = hintSet;
623   map[0]["name"]          = "Test0";
624
625   map[1]["vertex"]        = VertexSource2;
626   map[1]["fragment"]      = FragmentSource2;
627   map[1]["renderPassTag"] = 1;
628   map[1]["hints"]         = hintSet;
629   map[1]["name"]          = "Test1";
630
631   Property::Array array;
632   array.PushBack(map[0]);
633   array.PushBack(map[1]);
634
635   Shader shader = Shader::New(array);
636
637   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
638   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
639
640   const Property::Array* outArray   = value.GetArray();
641   uint32_t               arrayCount = outArray->Size();
642   DALI_TEST_CHECK(arrayCount == 2u);
643
644   for(uint32_t i = 0; i < arrayCount; ++i)
645   {
646     const Property::Map* outMap = outArray->GetElementAt(i).GetMap();
647     std::string          v      = (*outMap)["vertex"].Get<std::string>();
648     std::string          f      = (*outMap)["fragment"].Get<std::string>();
649     std::string          h      = (*outMap)["hints"].Get<std::string>();
650     int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
651     std::string          n      = (*outMap)["name"].Get<std::string>();
652
653     DALI_TEST_CHECK(v == map[i]["vertex"].Get<std::string>());
654     DALI_TEST_CHECK(f == map[i]["fragment"].Get<std::string>());
655     DALI_TEST_CHECK(h == map[i]["hints"].Get<std::string>());
656     DALI_TEST_CHECK(r == map[i]["renderPassTag"].Get<int32_t>());
657     DALI_TEST_CHECK(n == map[i]["name"].Get<std::string>());
658   }
659
660   END_TEST;
661 }
662
663 int UtcDaliShaderProgramPropertyArray(void)
664 {
665   TestApplication application;
666
667   tet_infoline("Test get/set progam property array");
668
669   Shader      shader  = Shader::New("", "");
670   std::string hintSet = "MODIFIES_GEOMETRY";
671
672   Property::Map map[2];
673   map[0]["vertex"]        = VertexSource;
674   map[0]["fragment"]      = FragmentSource;
675   map[0]["renderPassTag"] = 0;
676   map[0]["hints"]         = hintSet;
677   map[0]["name"]          = "Test0";
678
679   map[1]["vertex"]        = VertexSource2;
680   map[1]["fragment"]      = FragmentSource2;
681   map[1]["renderPassTag"] = 1;
682   map[1]["hints"]         = hintSet;
683   map[1]["name"]          = "Test1";
684
685   Property::Array array;
686   array.PushBack(map[0]);
687   array.PushBack(map[1]);
688
689   shader.SetProperty(Shader::Property::PROGRAM, Property::Value(array));
690
691   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
692   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
693
694   const Property::Array* outArray   = value.GetArray();
695   uint32_t               arrayCount = outArray->Size();
696   DALI_TEST_CHECK(arrayCount == 2u);
697
698   for(uint32_t i = 0; i < arrayCount; ++i)
699   {
700     const Property::Map* outMap = outArray->GetElementAt(i).GetMap();
701     std::string          v      = (*outMap)["vertex"].Get<std::string>();
702     std::string          f      = (*outMap)["fragment"].Get<std::string>();
703     std::string          h      = (*outMap)["hints"].Get<std::string>();
704     int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
705     std::string          n      = (*outMap)["name"].Get<std::string>();
706
707     DALI_TEST_CHECK(v == map[i]["vertex"].Get<std::string>());
708     DALI_TEST_CHECK(f == map[i]["fragment"].Get<std::string>());
709     DALI_TEST_CHECK(h == map[i]["hints"].Get<std::string>());
710     DALI_TEST_CHECK(r == map[i]["renderPassTag"].Get<int32_t>());
711     DALI_TEST_CHECK(n == map[i]["name"].Get<std::string>());
712   }
713
714   END_TEST;
715 }
716
717 int UtcDaliShaderWrongData(void)
718 {
719   TestApplication application;
720
721   tet_infoline("Test get/set wrong data");
722
723   Shader shader = Shader::New(Property::Value(1.0f));
724
725   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
726   DALI_TEST_CHECK(value.GetType() == Property::ARRAY);
727
728   const Property::Array* outArray   = value.GetArray();
729   uint32_t               arrayCount = outArray->Size();
730   DALI_TEST_CHECK(arrayCount == 0u);
731
732   END_TEST;
733 }