[dali_2.3.33] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TextureSet.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 // EXTERNAL INCLUDES
19 #include <dali/devel-api/threading/thread.h>
20 #include <dali/public-api/dali-core.h>
21
22 // INTERNAL INCLUDES
23 #include <dali-test-suite-utils.h>
24 #include <mesh-builder.h>
25
26 using namespace Dali;
27
28 namespace
29 {
30 enum SetSampler
31 {
32   SET_SAMPLER,
33   DONT_SET_SAMPLER
34 };
35
36 Actor CreateActor(SetSampler setSamplerOption)
37 {
38   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
39
40   Shader     shader     = CreateShader();
41   TextureSet textureSet = CreateTextureSet();
42
43   Sampler sampler = Sampler::New();
44   sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST);
45   textureSet.SetTexture(0u, texture);
46   if(setSamplerOption == SET_SAMPLER)
47   {
48     textureSet.SetSampler(0u, sampler);
49   }
50
51   Geometry geometry = CreateQuadGeometry();
52   Renderer renderer = Renderer::New(geometry, shader);
53   renderer.SetTextures(textureSet);
54
55   Actor actor = Actor::New();
56   actor.AddRenderer(renderer);
57   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
58   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
59
60   return actor;
61 }
62
63 } // namespace
64
65 void texture_set_test_startup(void)
66 {
67   test_return_value = TET_UNDEF;
68 }
69
70 void texture_set_test_cleanup(void)
71 {
72   test_return_value = TET_PASS;
73 }
74
75 int UtcDaliTextureSetNew01(void)
76 {
77   TestApplication application;
78
79   TextureSet textureSet = TextureSet::New();
80
81   DALI_TEST_CHECK(textureSet);
82   END_TEST;
83 }
84
85 int UtcDaliTextureSetNew02(void)
86 {
87   TestApplication application;
88   TextureSet      textureSet;
89   DALI_TEST_CHECK(!textureSet);
90   END_TEST;
91 }
92
93 int UtcDaliTextureSetCopyConstructor(void)
94 {
95   TestApplication application;
96
97   Texture    image      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32);
98   TextureSet textureSet = TextureSet::New();
99   textureSet.SetTexture(0u, image);
100
101   TextureSet textureSetCopy(textureSet);
102
103   DALI_TEST_CHECK(textureSetCopy);
104
105   END_TEST;
106 }
107
108 int UtcDaliTextureSetAssignmentOperator(void)
109 {
110   TestApplication application;
111   TextureSet      textureSet = TextureSet::New();
112
113   TextureSet textureSet2;
114   DALI_TEST_CHECK(!textureSet2);
115
116   textureSet2 = textureSet;
117   DALI_TEST_CHECK(textureSet2);
118
119   END_TEST;
120 }
121
122 int UtcDaliTextureSetMoveConstructor(void)
123 {
124   TestApplication application;
125
126   TextureSet textureSet = TextureSet::New();
127   DALI_TEST_CHECK(textureSet);
128   DALI_TEST_EQUALS(1, textureSet.GetBaseObject().ReferenceCount(), TEST_LOCATION);
129
130   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32);
131   textureSet.SetTexture(0u, texture);
132   DALI_TEST_EQUALS(textureSet.GetTexture(0u), texture, TEST_LOCATION);
133
134   TextureSet move = std::move(textureSet);
135   DALI_TEST_CHECK(move);
136   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
137   DALI_TEST_EQUALS(move.GetTexture(0u), texture, TEST_LOCATION);
138   DALI_TEST_CHECK(!textureSet);
139
140   END_TEST;
141 }
142
143 int UtcDaliTextureSetMoveAssignment(void)
144 {
145   TestApplication application;
146
147   TextureSet textureSet = TextureSet::New();
148   DALI_TEST_CHECK(textureSet);
149   DALI_TEST_EQUALS(1, textureSet.GetBaseObject().ReferenceCount(), TEST_LOCATION);
150
151   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32);
152   textureSet.SetTexture(0u, texture);
153   DALI_TEST_EQUALS(textureSet.GetTexture(0u), texture, TEST_LOCATION);
154
155   TextureSet move;
156   move = std::move(textureSet);
157   DALI_TEST_CHECK(move);
158   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
159   DALI_TEST_EQUALS(move.GetTexture(0u), texture, TEST_LOCATION);
160   DALI_TEST_CHECK(!textureSet);
161
162   END_TEST;
163 }
164
165 int UtcDaliTextureSetDownCast01(void)
166 {
167   TestApplication application;
168   TextureSet      textureSet = TextureSet::New();
169
170   BaseHandle handle(textureSet);
171   TextureSet textureSet2 = TextureSet::DownCast(handle);
172   DALI_TEST_CHECK(textureSet2);
173
174   END_TEST;
175 }
176
177 int UtcDaliTextureSetDownCast02(void)
178 {
179   TestApplication application;
180
181   Handle     handle     = Handle::New(); // Create a custom object
182   TextureSet textureSet = TextureSet::DownCast(handle);
183   DALI_TEST_CHECK(!textureSet);
184   END_TEST;
185 }
186
187 int UtcDaliTextureSetTexture01(void)
188 {
189   TestApplication application;
190
191   Actor actor = CreateActor(DONT_SET_SAMPLER);
192
193   application.GetScene().Add(actor);
194
195   TestGlAbstraction& gl = application.GetGlAbstraction();
196
197   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
198   texParameterTrace.Reset();
199   texParameterTrace.Enable(true);
200   application.SendNotification();
201   application.Render();
202
203   int textureUnit = -1;
204   DALI_TEST_CHECK(gl.GetUniformValue<int>("sTexture", textureUnit));
205   DALI_TEST_EQUALS(textureUnit, 0, TEST_LOCATION);
206
207   texParameterTrace.Enable(false);
208
209   // Verify gl state
210   // There are four calls to TexParameteri when the texture is first created
211   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
212   DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 4, TEST_LOCATION);
213
214   END_TEST;
215 }
216
217 int UtcDaliTextureSetTexture02(void)
218 {
219   TestApplication application;
220
221   Actor actor = CreateActor(SET_SAMPLER);
222
223   application.GetScene().Add(actor);
224
225   TestGlAbstraction& gl = application.GetGlAbstraction();
226
227   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
228   texParameterTrace.Reset();
229   texParameterTrace.Enable(true);
230   application.SendNotification();
231   application.Render();
232
233   int textureUnit = -1;
234   DALI_TEST_CHECK(gl.GetUniformValue<int>("sTexture", textureUnit));
235   DALI_TEST_EQUALS(textureUnit, 0, TEST_LOCATION);
236
237   texParameterTrace.Enable(false);
238
239   // Verify gl state
240   // There are four calls to TexParameteri when the texture is first created
241   // Texture minification and magnification filters are now different than default so
242   //there should have been two extra TexParameteri calls to set the new filter mode
243   DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 6, TEST_LOCATION);
244
245   END_TEST;
246 }
247
248 int UtcDaliTextureSetMultiple(void)
249 {
250   TestApplication application;
251
252   Actor actor1 = CreateActor(SET_SAMPLER);
253   Actor actor2 = CreateActor(SET_SAMPLER);
254
255   application.GetScene().Add(actor1);
256   application.GetScene().Add(actor2);
257
258   TestGlAbstraction& gl = application.GetGlAbstraction();
259
260   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
261   texParameterTrace.Reset();
262   texParameterTrace.Enable(true);
263   texParameterTrace.EnableLogging(true);
264   application.SendNotification();
265   application.Render();
266
267   int textureUnit = -1;
268   DALI_TEST_CHECK(gl.GetUniformValue<int>("sTexture", textureUnit));
269   DALI_TEST_EQUALS(textureUnit, 0, TEST_LOCATION);
270
271   texParameterTrace.Enable(false);
272
273   // Verify gl state
274   // For each actor there are four calls to TexParameteri when the texture is first created
275   // Texture minification and magnification filters are now different than default so
276   // there should have been two extra TexParameteri calls to set the new filter mode
277   DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 2 * 6, TEST_LOCATION);
278
279   END_TEST;
280 }
281
282 int UtcDaliTextureSetSetSampler(void)
283 {
284   TestApplication application;
285
286   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
287
288   Shader     shader     = CreateShader();
289   TextureSet textureSet = CreateTextureSet(image);
290
291   Geometry geometry = CreateQuadGeometry();
292   Renderer renderer = Renderer::New(geometry, shader);
293   renderer.SetTextures(textureSet);
294
295   Actor actor = Actor::New();
296   actor.AddRenderer(renderer);
297   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
298   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
299
300   application.GetScene().Add(actor);
301
302   TestGlAbstraction& gl = application.GetGlAbstraction();
303
304   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
305   texParameterTrace.Reset();
306   texParameterTrace.EnableLogging(true);
307   texParameterTrace.Enable(true);
308   application.SendNotification();
309   application.Render();
310
311   int textureUnit = -1;
312   DALI_TEST_CHECK(gl.GetUniformValue<int>("sTexture", textureUnit));
313   DALI_TEST_EQUALS(textureUnit, 0, TEST_LOCATION);
314
315   texParameterTrace.Enable(false);
316
317   // Verify gl state
318   // There are 4 calls to TexParameteri when the texture is first created
319   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
320   DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 4, TEST_LOCATION);
321
322   texParameterTrace.Reset();
323   texParameterTrace.Enable(true);
324
325   Sampler sampler = Sampler::New();
326   sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST);
327   textureSet.SetSampler(0u, sampler);
328
329   application.SendNotification();
330   application.Render();
331
332   texParameterTrace.Enable(false);
333
334   // Verify gl state
335   //There should have been two calls to TexParameteri to set the new filtering mode
336   DALI_TEST_EQUALS(texParameterTrace.CountMethod("TexParameteri"), 2, TEST_LOCATION);
337
338   END_TEST;
339 }
340
341 int UtcDaliTextureSetGetTexture(void)
342 {
343   TestApplication application;
344
345   TextureSet textureSet = CreateTextureSet();
346   DALI_TEST_EQUALS(textureSet.GetTexture(0), Texture(), TEST_LOCATION);
347   DALI_TEST_EQUALS(textureSet.GetTexture(1), Texture(), TEST_LOCATION);
348   DALI_TEST_EQUALS(textureSet.GetTexture(2), Texture(), TEST_LOCATION);
349
350   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
351   textureSet.SetTexture(0u, texture);
352
353   DALI_TEST_EQUALS(textureSet.GetTexture(0), texture, TEST_LOCATION);
354   DALI_TEST_EQUALS(textureSet.GetTexture(1), Texture(), TEST_LOCATION);
355   DALI_TEST_EQUALS(textureSet.GetTexture(2), Texture(), TEST_LOCATION);
356
357   textureSet.SetTexture(2u, texture);
358   DALI_TEST_EQUALS(textureSet.GetTexture(0), texture, TEST_LOCATION);
359   DALI_TEST_EQUALS(textureSet.GetTexture(1), Texture(), TEST_LOCATION);
360   DALI_TEST_EQUALS(textureSet.GetTexture(2), texture, TEST_LOCATION);
361
362   textureSet.SetTexture(2u, Texture());
363   DALI_TEST_EQUALS(textureSet.GetTexture(0), texture, TEST_LOCATION);
364   DALI_TEST_EQUALS(textureSet.GetTexture(1), Texture(), TEST_LOCATION);
365   DALI_TEST_EQUALS(textureSet.GetTexture(2), Texture(), TEST_LOCATION);
366
367   END_TEST;
368 }
369
370 int UtcDaliTextureSetGetSampler(void)
371 {
372   TestApplication application;
373
374   TextureSet textureSet = CreateTextureSet();
375   DALI_TEST_EQUALS(textureSet.GetSampler(0), Sampler(), TEST_LOCATION);
376   DALI_TEST_EQUALS(textureSet.GetSampler(1), Sampler(), TEST_LOCATION);
377   DALI_TEST_EQUALS(textureSet.GetSampler(2), Sampler(), TEST_LOCATION);
378
379   Sampler sampler = Sampler::New();
380   sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST);
381   textureSet.SetSampler(0u, sampler);
382
383   DALI_TEST_EQUALS(textureSet.GetSampler(0), sampler, TEST_LOCATION);
384   DALI_TEST_EQUALS(textureSet.GetSampler(1), Sampler(), TEST_LOCATION);
385   DALI_TEST_EQUALS(textureSet.GetSampler(2), Sampler(), TEST_LOCATION);
386
387   textureSet.SetSampler(2u, sampler);
388   DALI_TEST_EQUALS(textureSet.GetSampler(0), sampler, TEST_LOCATION);
389   DALI_TEST_EQUALS(textureSet.GetSampler(1), Sampler(), TEST_LOCATION);
390   DALI_TEST_EQUALS(textureSet.GetSampler(2), sampler, TEST_LOCATION);
391
392   textureSet.SetSampler(2u, Sampler());
393   DALI_TEST_EQUALS(textureSet.GetSampler(0), sampler, TEST_LOCATION);
394   DALI_TEST_EQUALS(textureSet.GetSampler(1), Sampler(), TEST_LOCATION);
395   DALI_TEST_EQUALS(textureSet.GetSampler(2), Sampler(), TEST_LOCATION);
396
397   END_TEST;
398 }
399
400 int UtcDaliTextureSetGetTextureCount0(void)
401 {
402   TestApplication application;
403
404   TextureSet textureSet = CreateTextureSet();
405   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 0u, TEST_LOCATION);
406
407   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
408   textureSet.SetTexture(0u, image);
409   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 1u, TEST_LOCATION);
410
411   textureSet.SetTexture(1u, image);
412   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 2u, TEST_LOCATION);
413
414   Sampler sampler = Sampler::New();
415   sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST);
416   textureSet.SetSampler(2u, sampler);
417   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 2u, TEST_LOCATION);
418
419   textureSet.SetTexture(2u, image);
420   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 3u, TEST_LOCATION);
421   DALI_TEST_EQUALS(textureSet.GetSampler(2u), sampler, TEST_LOCATION);
422
423   END_TEST;
424 }
425
426 int UtcDaliTextureSetGetTextureCount1(void)
427 {
428   TestApplication application;
429
430   TextureSet textureSet = CreateTextureSet();
431   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 0u, TEST_LOCATION);
432
433   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
434   textureSet.SetTexture(0u, texture);
435   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 1u, TEST_LOCATION);
436
437   textureSet.SetTexture(1u, texture);
438   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 2u, TEST_LOCATION);
439
440   Sampler sampler = Sampler::New();
441   sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST);
442   textureSet.SetSampler(2u, sampler);
443   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 2u, TEST_LOCATION);
444
445   textureSet.SetTexture(2u, texture);
446   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 3u, TEST_LOCATION);
447   DALI_TEST_EQUALS(textureSet.GetSampler(2u), sampler, TEST_LOCATION);
448
449   END_TEST;
450 }
451
452 int UtcDaliTextureSetRemoveTextureAndGetTextureCount(void)
453 {
454   TestApplication application;
455
456   TextureSet textureSet = CreateTextureSet();
457   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 0u, TEST_LOCATION);
458
459   Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
460   Texture image1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
461   Texture image2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
462
463   textureSet.SetTexture(0u, image0);
464   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 1u, TEST_LOCATION);
465   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
466
467   textureSet.SetTexture(1u, image1);
468   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 2u, TEST_LOCATION);
469   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
470   DALI_TEST_EQUALS(textureSet.GetTexture(1u), image1, TEST_LOCATION);
471
472   // Set empty texture so we can remove it.
473   textureSet.SetTexture(1u, Texture());
474
475   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 1u, TEST_LOCATION);
476   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
477
478   application.SendNotification();
479   application.Render();
480
481   textureSet.SetTexture(2u, image2);
482
483   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 3u, TEST_LOCATION);
484   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
485   DALI_TEST_EQUALS(textureSet.GetTexture(1u), Texture(), TEST_LOCATION);
486   DALI_TEST_EQUALS(textureSet.GetTexture(2u), image2, TEST_LOCATION);
487
488   textureSet.SetTexture(1u, image1);
489
490   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 3u, TEST_LOCATION);
491   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
492   DALI_TEST_EQUALS(textureSet.GetTexture(1u), image1, TEST_LOCATION);
493   DALI_TEST_EQUALS(textureSet.GetTexture(2u), image2, TEST_LOCATION);
494
495   // Set empty texture middle of textureset.
496   textureSet.SetTexture(1u, Texture());
497
498   application.SendNotification();
499   application.Render();
500
501   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 3u, TEST_LOCATION);
502   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
503   DALI_TEST_EQUALS(textureSet.GetTexture(1u), Texture(), TEST_LOCATION);
504   DALI_TEST_EQUALS(textureSet.GetTexture(2u), image2, TEST_LOCATION);
505
506   // Set empty texture end of textureset.
507   textureSet.SetTexture(2u, Texture());
508
509   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 1u, TEST_LOCATION);
510   DALI_TEST_EQUALS(textureSet.GetTexture(0u), image0, TEST_LOCATION);
511
512   application.SendNotification();
513   application.Render();
514
515   END_TEST;
516 }
517 int UtcDaliTextureSetSetSamplerNegative(void)
518 {
519   TestApplication  application;
520   Dali::TextureSet instance;
521   try
522   {
523     unsigned long arg1(0u);
524     Dali::Sampler arg2;
525     instance.SetSampler(arg1, arg2);
526     DALI_TEST_CHECK(false); // Should not get here
527   }
528   catch(...)
529   {
530     DALI_TEST_CHECK(true); // We expect an assert
531   }
532   END_TEST;
533 }
534
535 int UtcDaliTextureSetSetTextureNegative(void)
536 {
537   TestApplication  application;
538   Dali::TextureSet instance;
539   try
540   {
541     unsigned long arg1(0u);
542     Dali::Texture arg2;
543     instance.SetTexture(arg1, arg2);
544     DALI_TEST_CHECK(false); // Should not get here
545   }
546   catch(...)
547   {
548     DALI_TEST_CHECK(true); // We expect an assert
549   }
550   END_TEST;
551 }
552
553 int UtcDaliTextureSetGetSamplerNegative(void)
554 {
555   TestApplication  application;
556   Dali::TextureSet instance;
557   try
558   {
559     unsigned long arg1(0u);
560     instance.GetSampler(arg1);
561     DALI_TEST_CHECK(false); // Should not get here
562   }
563   catch(...)
564   {
565     DALI_TEST_CHECK(true); // We expect an assert
566   }
567   END_TEST;
568 }
569
570 int UtcDaliTextureSetGetTextureNegative(void)
571 {
572   TestApplication  application;
573   Dali::TextureSet instance;
574   try
575   {
576     unsigned long arg1(0u);
577     instance.GetTexture(arg1);
578     DALI_TEST_CHECK(false); // Should not get here
579   }
580   catch(...)
581   {
582     DALI_TEST_CHECK(true); // We expect an assert
583   }
584   END_TEST;
585 }
586
587 int UtcDaliTextureSetGetTextureCountNegative(void)
588 {
589   TestApplication  application;
590   Dali::TextureSet instance;
591   try
592   {
593     instance.GetTextureCount();
594     DALI_TEST_CHECK(false); // Should not get here
595   }
596   catch(...)
597   {
598     DALI_TEST_CHECK(true); // We expect an assert
599   }
600   END_TEST;
601 }
602
603 int UtcDaliTextureSetMultipleTextures(void)
604 {
605   TestApplication application;
606
607   Shader     shader     = CreateShader();
608   TextureSet textureSet = CreateTextureSet();
609
610   // Set 2 textures
611   Texture texture1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
612   textureSet.SetTexture(0u, texture1);
613
614   Texture texture2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
615   textureSet.SetTexture(1u, texture2);
616
617   Geometry geometry = CreateQuadGeometry();
618   Renderer renderer = Renderer::New(geometry, shader);
619   renderer.SetTextures(textureSet);
620
621   Actor actor = Actor::New();
622   actor.AddRenderer(renderer);
623   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
624   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
625
626   application.GetScene().Add(actor);
627
628   application.SendNotification();
629   application.Render();
630
631   const std::vector<GLuint>& boundTextures0 = application.GetGlAbstraction().GetBoundTextures(GL_TEXTURE0);
632   DALI_TEST_CHECK(boundTextures0[boundTextures0.size() - 1] == 1u); // the latest one should be 0.
633
634   const std::vector<GLuint>& boundTextures1 = application.GetGlAbstraction().GetBoundTextures(GL_TEXTURE1);
635   size_t                     count          = boundTextures1.size();
636   DALI_TEST_CHECK(boundTextures1[count - 1] == 2u); // the latest one should be 1.
637
638   // Create a new TextureSet
639   textureSet = CreateTextureSet();
640
641   // Set 1 texture
642   textureSet.SetTexture(0u, texture1);
643
644   renderer.SetTextures(textureSet);
645
646   application.SendNotification();
647   application.Render();
648
649   TestGlAbstraction& gl = application.GetGlAbstraction();
650   DALI_TEST_CHECK(gl.GetActiveTextureUnit() == GL_TEXTURE0);
651
652   DALI_TEST_CHECK(boundTextures0[boundTextures0.size() - 1] == 1u);
653   DALI_TEST_CHECK(boundTextures1.size() == count); // The bound texture count of GL_TEXTURE1 should not be changed.
654
655   END_TEST;
656 }
657
658 int UtcDaliTextureSetDestructWorkerThreadN(void)
659 {
660   TestApplication application;
661   tet_infoline("UtcDaliTextureSetDestructWorkerThreadN Test, for line coverage");
662
663   try
664   {
665     class TestThread : public Thread
666     {
667     public:
668       virtual void Run()
669       {
670         tet_printf("Run TestThread\n");
671         // Destruct at worker thread.
672         mTextureSet.Reset();
673       }
674
675       Dali::TextureSet mTextureSet;
676     };
677     TestThread thread;
678
679     Dali::TextureSet textureSet = Dali::TextureSet::New();
680     thread.mTextureSet          = std::move(textureSet);
681     textureSet.Reset();
682
683     thread.Start();
684
685     thread.Join();
686   }
687   catch(...)
688   {
689   }
690
691   // Always success
692   DALI_TEST_CHECK(true);
693
694   END_TEST;
695 }