Remove RenderableActor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-ImageActor.cpp
1 /*
2  * Copyright (c) 2014 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 <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali/integration-api/bitmap.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
23
24 using namespace Dali;
25
26 static const char* TestImageFilename = "icon_wrt.png";
27
28 void image_actor_test_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void image_actor_test_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38
39 int UtcDaliImageActorConstructorVoid(void)
40 {
41   TestApplication application;
42   tet_infoline("Testing Dali::ImageActor::ImageActor()");
43
44   ImageActor actor;
45
46   DALI_TEST_CHECK(!actor);
47   END_TEST;
48 }
49
50 int UtcDaliImageActorDestructor(void)
51 {
52   TestApplication application;
53
54   ImageActor* actor = new ImageActor();
55   delete actor;
56
57   DALI_TEST_CHECK( true );
58   END_TEST;
59 }
60
61 int UtcDaliImageActorNew01(void)
62 {
63   TestApplication application;
64   tet_infoline("Positive test for Dali::ImageActor::New()");
65
66   Image image = ResourceImage::New(TestImageFilename);
67   ImageActor actor = ImageActor::New(image);
68   Stage::GetCurrent().Add(actor);
69
70   application.SendNotification();
71   application.Render();
72   application.Render();
73   application.SendNotification();
74
75   DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
76
77   DALI_TEST_CHECK(actor);
78   END_TEST;
79 }
80
81 int UtcDaliImageActorNew02(void)
82 {
83   TestApplication application;
84   tet_infoline("Negative test for Dali::ImageActor::New()");
85
86   Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
87   ImageActor actor = ImageActor::New(image);
88
89   DALI_TEST_CHECK(actor);
90   END_TEST;
91 }
92
93 int UtcDaliImageActorDownCast(void)
94 {
95   TestApplication application;
96   tet_infoline("Testing Dali::ImageActor::DownCast()");
97
98   Image image = ResourceImage::New("IncorrectImageName");
99   ImageActor actor1 = ImageActor::New(image);
100   Actor anActor = Actor::New();
101   anActor.Add(actor1);
102
103   Actor child = anActor.GetChildAt(0);
104   ImageActor imageActor = DownCast< ImageActor >(child);
105
106   DALI_TEST_CHECK(imageActor);
107   END_TEST;
108 }
109
110 int UtcDaliImageActorDownCast2(void)
111 {
112   TestApplication application;
113   tet_infoline("Testing Dali::ImageActor::DownCast()");
114
115   Actor actor1 = Actor::New();
116   Actor anActor = Actor::New();
117   anActor.Add(actor1);
118
119   Actor child = anActor.GetChildAt(0);
120   ImageActor imageActor = ImageActor::DownCast(child);
121   DALI_TEST_CHECK(!imageActor);
122
123   Actor unInitialzedActor;
124   imageActor = ImageActor::DownCast( unInitialzedActor );
125   DALI_TEST_CHECK(!imageActor);
126   END_TEST;
127 }
128
129 int UtcDaliImageActorCopyConstructor(void)
130 {
131   TestApplication application;
132   tet_infoline("Testing Dali::ImageActor::ImageActor(const ImageActor& )");
133
134   Image image = ResourceImage::New("IncorrectImageName");
135   ImageActor actor1 = ImageActor::New(image);
136
137   ImageActor actor2(actor1);
138   DALI_TEST_CHECK(actor2);
139   DALI_TEST_EQUALS( actor2, actor1, TEST_LOCATION );
140   DALI_TEST_EQUALS( actor2.GetImage(), image, TEST_LOCATION );
141
142   END_TEST;
143 }
144
145 int UtcDaliImageActor9Patch(void)
146 {
147   TestApplication application;
148   tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
149
150   Image image = ResourceImage::New(TestImageFilename);
151   ImageActor actor = ImageActor::New(image);
152
153   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
154   Vector4 border(0.1,0.2,0.3,0.4);
155   actor.SetNinePatchBorder(border);
156
157   DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
158   DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
159   DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
160   DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
161   END_TEST;
162 }
163
164 int UtcDaliImageActorPixelArea(void)
165 {
166   TestApplication application;
167   tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
168
169   BufferImage img = BufferImage::New( 10, 10 );
170   ImageActor actor = ImageActor::New( img );
171
172   ImageActor::PixelArea area( 1, 2, 3, 4 );
173   actor.SetPixelArea( area );
174
175   DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
176   DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
177   DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
178   DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
179
180   ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
181
182   DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
183   DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
184   DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
185   DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
186   END_TEST;
187 }
188
189 // Set a size that is too large on an Image with a shader that requires grid
190 int UtcDaliImageActorSetSize01(void)
191 {
192   TestApplication application;
193
194   BufferImage img = BufferImage::New( 1,1 );
195   ImageActor actor = ImageActor::New( img );
196
197   ShaderEffect effect = ShaderEffect::New( " ", " ", ShaderEffect::HINT_GRID );
198   actor.SetShaderEffect( effect );
199
200   const float INVALID_SIZE = float(1u<<31);
201   Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
202
203   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
204
205   actor.SetSize(vector);
206   Stage::GetCurrent().Add(actor);
207
208   // flush the queue and render once
209   application.SendNotification();
210   application.Render();
211
212   DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
213   END_TEST;
214 }
215
216 int UtcDaliImageActorGetCurrentSize01(void)
217 {
218   TestApplication application;
219   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
220
221   Vector2 initialImageSize(100, 50);
222   BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
223   ImageActor actor = ImageActor::New( image );
224   Stage::GetCurrent().Add(actor);
225
226   application.SendNotification();
227   application.Render();
228
229   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
230
231   Vector2 size(200.0f, 200.0f);
232   actor.SetSize(size);
233
234   // flush the queue and render once
235   application.SendNotification();
236   application.Render();
237   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
238
239   size.x = 200.0f;
240   size.y = 200.0f;
241   actor.SetSize(size);
242   application.Render(8);
243
244   // Test when a pixel area is set
245   ImageActor::PixelArea area(0, 0, 10, 10);
246   actor.SetPixelArea(area);
247   application.Render(9);
248   // natural size is not used as setsize is called
249   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
250
251   END_TEST;
252 }
253
254
255 int UtcDaliImageActorGetCurrentSize02(void)
256 {
257   TestApplication application;
258   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
259
260   Vector2 initialImageSize(100, 50);
261
262   application.GetPlatform().SetClosestImageSize(initialImageSize);
263
264   Image image = ResourceImage::New("image.jpg");
265   ImageActor actor = ImageActor::New( image );
266   Stage::GetCurrent().Add(actor);
267
268   application.SendNotification(); // Flush update messages
269   application.Render();           // Process resource request
270   application.SendNotification(); // Flush update messages
271   application.Render();           // Process resource request
272
273   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
274
275   // Now complete the image load
276   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
277   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
278   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
279
280   Integration::ResourcePointer resourcePtr(bitmap); // reference it
281   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
282   application.Render();           // Process LoadComplete
283   application.SendNotification(); // Process event messages
284   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
285   application.GetPlatform().ClearReadyResources(); //
286
287   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
288
289   Vector2 size(200.0f, 200.0f);
290   actor.SetSize(size);
291
292   // flush the queue and render once
293   application.SendNotification();
294   application.Render();
295   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
296
297   END_TEST;
298 }
299
300
301 int UtcDaliImageActorGetCurrentSize03(void)
302 {
303   TestApplication application;
304   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
305
306   const Vector2 closestImageSize( 80, 45);
307   application.GetPlatform().SetClosestImageSize(closestImageSize);
308
309   Vector2 requestedSize( 40, 30 );
310   Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
311   ImageActor actor = ImageActor::New( image );
312   Stage::GetCurrent().Add(actor);
313
314   application.SendNotification(); // Flush update messages
315   application.Render();           // Process resource request
316   application.SendNotification(); // Flush update messages
317   application.Render();           // Process resource request
318
319   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
320
321   // Now complete the image load
322   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
323   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
324   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
325
326   Integration::ResourcePointer resourcePtr(bitmap); // reference it
327   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
328   application.Render();           // Process LoadComplete
329   application.SendNotification(); // Process event messages
330   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
331   application.GetPlatform().ClearReadyResources(); //
332
333   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
334
335   END_TEST;
336 }
337
338
339 int UtcDaliImageActorGetCurrentSize04(void)
340 {
341   TestApplication application;
342   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
343
344   const Vector2 closestImageSize( 80, 45);
345   application.GetPlatform().SetClosestImageSize(closestImageSize);
346
347   Vector2 requestedSize( 40, 30 );
348   Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
349   ImageActor actor = ImageActor::New( image );
350   Stage::GetCurrent().Add(actor);
351
352   application.SendNotification(); // Flush update messages
353   application.Render();           // Process resource request
354
355   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
356
357   // Now complete the image load
358   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
359   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
360   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
361
362   Integration::ResourcePointer resourcePtr(bitmap); // reference it
363   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
364   application.Render();           // Process LoadComplete
365   application.SendNotification(); // Process event messages
366   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
367   application.GetPlatform().ClearReadyResources(); //
368
369   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
370
371   Vector2 size(200.0f, 200.0f);
372   actor.SetSize(size);
373
374   // flush the queue and render once
375   application.SendNotification();
376   application.Render();
377   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
378
379   // Load a different image
380
381   Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
382   application.GetPlatform().SetClosestImageSize(image2ClosestSize);
383
384   const Vector2 request2Size( 100, 100 );
385   Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
386   actor.SetImage(image2);
387
388   application.SendNotification(); // Flush update messages
389   application.Render();           // Process resource request
390   application.SendNotification(); // Flush update messages
391   application.Render();           // Process resource request
392
393   // Ensure the actor size is kept
394   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
395
396   // Now complete the image load
397   req = application.GetPlatform().GetRequest();
398   Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
399   bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
400
401   Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
402   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
403   application.Render();           // Process LoadComplete
404   application.SendNotification(); // Process event messages
405   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
406   application.GetPlatform().ClearReadyResources(); //
407
408   // Ensure the actor size is kept
409   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
410
411   END_TEST;
412 }
413
414
415 int UtcDaliImageActorGetCurrentSize05(void)
416 {
417   TestApplication application;
418   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
419
420   Vector2 closestImageSize( 80, 45);
421   application.GetPlatform().SetClosestImageSize(closestImageSize);
422
423   Vector2 requestedSize( 40, 30 );
424   Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
425   ImageActor actor = ImageActor::New( image );
426   Stage::GetCurrent().Add(actor);
427
428   application.SendNotification(); // Flush update messages
429   application.Render();           // Process resource request
430
431   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
432
433   // Now complete the image load
434   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
435   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
436   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
437
438   Integration::ResourcePointer resourcePtr(bitmap); // reference it
439   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
440   application.Render();           // Process LoadComplete
441   application.SendNotification(); // Process event messages
442   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
443   application.GetPlatform().ClearReadyResources(); //
444
445   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
446
447   // Load a different image
448
449   Vector2 image2ClosestSize = Vector2(240, 150);
450   application.GetPlatform().SetClosestImageSize(image2ClosestSize);
451
452   const Vector2 requestedSize2( 100, 100 );
453   Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
454   actor.SetImage(image2);
455
456   application.SendNotification(); // Flush update messages
457   application.Render();           // Process resource request
458   application.SendNotification(); // Flush update messages
459   application.Render();           // Process resource request
460
461   // Ensure the actor size is kept
462   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
463
464   // Now complete the image load
465   req = application.GetPlatform().GetRequest();
466   Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
467   bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
468
469   Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
470   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
471   application.Render();           // Process LoadComplete
472   application.SendNotification(); // Process event messages
473   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
474   application.GetPlatform().ClearReadyResources(); //
475
476   application.SendNotification(); // Process event messages
477   application.Render();           // Process LoadComplete
478
479   // Ensure the actor size gets the new image's natural size
480   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
481   END_TEST;
482 }
483
484 int UtcDaliImageActorNaturalPixelAreaSize01(void)
485 {
486   TestApplication application;
487   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
488
489 //If an image is loaded without setting size, then the actor gets the natural size of the image
490 //Setting the pixel area will change the actor size to match the pixel area
491 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
492 //to the new size.
493 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
494
495
496   Vector2 closestImageSize( 80, 45);
497   application.GetPlatform().SetClosestImageSize(closestImageSize);
498
499   Vector2 requestedSize( 40, 30 );
500   Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
501   ImageActor actor = ImageActor::New( image );
502   Stage::GetCurrent().Add(actor);
503
504   application.SendNotification(); // Flush update messages
505   application.Render();           // Process resource request
506
507   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
508
509   // Now complete the image load
510   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
511   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
512   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
513
514   Integration::ResourcePointer resourcePtr(bitmap); // reference it
515   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
516   application.Render();           // Process LoadComplete
517   application.SendNotification(); // Process event messages
518   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
519   application.GetPlatform().ClearReadyResources(); //
520
521   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
522
523   // Set a pixel area on a naturally sized actor - expect the actor to take the
524   // pixel area as size
525   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
526   application.SendNotification(); // Process event messages
527   application.Render();           // Process LoadComplete
528   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
529
530   // Set a size. Expect the partial image to stretch to fill the new size
531   actor.SetSize(100, 100);
532   application.SendNotification(); // Process event messages
533   application.Render();           // Process LoadComplete
534   application.Render();           // Process LoadComplete
535   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
536
537   // Clear the pixel area. Expect the whole image to be shown, filling the set size.
538   actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
539   application.SendNotification(); // Process event messages
540   application.Render();           // Process LoadComplete
541   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
542   END_TEST;
543 }
544
545 int UtcDaliImageActorNaturalPixelAreaSize02(void)
546 {
547   TestApplication application;
548   tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
549
550 //If an image is loaded without setting size, then the actor gets the natural size of the image
551 //Setting the pixel area will change the actor size to match the pixel area
552 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
553 //to the new size.
554 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
555
556
557   Vector2 closestImageSize( 80, 45);
558   application.GetPlatform().SetClosestImageSize(closestImageSize);
559
560   Vector2 requestedSize( 40, 30 );
561   Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
562   ImageActor actor = ImageActor::New( image );
563   Stage::GetCurrent().Add(actor);
564
565   application.SendNotification(); // Flush update messages
566   application.Render();           // Process resource request
567
568   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
569
570   // Now complete the image load
571   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
572   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
573   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
574
575   Integration::ResourcePointer resourcePtr(bitmap); // reference it
576   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
577   application.Render();           // Process LoadComplete
578   application.SendNotification(); // Process event messages
579   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
580   application.GetPlatform().ClearReadyResources(); //
581
582   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
583
584   // Set a pixel area on a naturally sized actor - expect the actor to take the
585   // pixel area as size
586   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
587   application.SendNotification(); // Process event messages
588   application.Render();           // Process LoadComplete
589   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
590
591   // Clear the pixel area. Expect the whole image to be shown, changing actor size
592   actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
593   application.SendNotification(); // Process event messages
594   application.Render();           // Process LoadComplete
595   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
596
597   // Set a size. Expect the partial image to stretch to fill the new size
598   actor.SetSize(100, 100);
599   application.SendNotification(); // Process event messages
600   application.Render();           // Process LoadComplete
601   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
602
603   // Set a pixel area, don't expect size to change
604   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
605   application.SendNotification(); // Process event messages
606   application.Render();           // Process LoadComplete
607   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
608
609   // Clearing pixel area should change actor size to image size
610   actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
611   actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
612   application.SendNotification(); // Process event messages
613   application.Render();           // Process LoadComplete
614   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
615   END_TEST;
616 }
617
618
619
620 int UtcDaliImageActorDefaultProperties(void)
621 {
622   TestApplication application;
623   tet_infoline("Testing Dali::ImageActor DefaultProperties");
624
625   BufferImage img = BufferImage::New( 10, 10 );
626   ImageActor actor = ImageActor::New( img );
627
628   std::vector<Property::Index> indices;
629   indices.push_back(ImageActor::Property::PIXEL_AREA      );
630   indices.push_back(ImageActor::Property::STYLE           );
631   indices.push_back(ImageActor::Property::BORDER          );
632   indices.push_back(ImageActor::Property::IMAGE           );
633
634   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
635
636   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
637   {
638     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
639     DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
640     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
641     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
642   }
643
644   // set/get one of them
645   actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
646
647   ImageActor::PixelArea area( 1, 2, 3, 4 );
648   actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
649
650   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
651
652   Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
653
654   DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
655
656   END_TEST;
657 }
658
659 int UtcDaliImageActorUseImageAlpha01(void)
660 {
661   TestApplication application;
662
663   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
664
665   BufferImage image = BufferImage::New( 100, 50 );
666   ImageActor actor = ImageActor::New( image );
667   actor.SetBlendMode( BlendingMode::ON );
668   actor.SetSize(100, 50);
669   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
670   Stage::GetCurrent().Add(actor);
671
672   application.SendNotification();
673   application.Render();
674
675   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
676   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
677   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
678   END_TEST;
679 }
680
681 int UtcDaliImageActorUseImageAlpha02(void)
682 {
683   TestApplication application;
684
685   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
686
687   BufferImage image = BufferImage::New( 100, 50 );
688   ImageActor actor = ImageActor::New( image );
689   actor.SetBlendMode( BlendingMode::OFF );
690   actor.SetSize(100, 50);
691   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
692   Stage::GetCurrent().Add(actor);
693
694   application.SendNotification();
695   application.Render();
696
697   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
698   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
699   DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
700   END_TEST;
701 }
702
703 int UtcDaliImageActorUseImageAlpha03(void)
704 {
705   TestApplication application;
706
707   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
708
709   BufferImage image = BufferImage::New( 100, 50 );
710   ImageActor actor = ImageActor::New( image );
711   actor.SetBlendMode( BlendingMode::AUTO );
712   actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
713   actor.SetSize(100, 50);
714   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
715   Stage::GetCurrent().Add(actor);
716
717   application.SendNotification();
718   application.Render();
719
720   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
721   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
722   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
723   END_TEST;
724 }
725
726 int UtcDaliImageActorUseImageAlpha04(void)
727 {
728   TestApplication application;
729
730   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
731
732   FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
733   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
734   RenderTask task = taskList.GetTask( 0u );
735   task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
736   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
737   application.SendNotification();
738   application.Render(0);
739
740   ImageActor actor = ImageActor::New( image );
741   application.SendNotification();
742   application.Render(0);
743
744   actor.SetBlendMode( BlendingMode::ON );
745   actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
746   actor.SetSize(100, 50);
747   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
748   Stage::GetCurrent().Add(actor);
749
750   application.SendNotification();
751   application.Render();
752
753   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
754   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
755   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
756   END_TEST;
757 }
758
759 int UtcDaliImageActorUseImageAlpha05(void)
760 {
761   TestApplication application;
762
763   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
764
765   BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
766   ImageActor actor = ImageActor::New( image );
767   actor.SetBlendMode( BlendingMode::AUTO );
768   actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
769   actor.SetSize(100, 50);
770   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
771   Stage::GetCurrent().Add(actor);
772
773   application.SendNotification();
774   application.Render();
775
776   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
777   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
778   DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
779   END_TEST;
780 }
781
782 int UtcDaliImageGetStyle(void)
783 {
784   TestApplication application;
785
786   Image image = ResourceImage::New(TestImageFilename);
787   ImageActor actor = ImageActor::New(image);
788
789   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
790
791   // flush the queue and render once
792   application.SendNotification();
793   application.Render();
794
795   DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
796   END_TEST;
797 }
798
799 int UtcDaliImageSetNinePatchBorder(void)
800 {
801   TestApplication application;
802
803   Image image = ResourceImage::New(TestImageFilename);
804   ImageActor actor = ImageActor::New(image);
805
806   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
807   actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
808
809   DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
810   DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
811   DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
812   DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
813   END_TEST;
814 }
815
816 int UtcDaliImageActorNewNull(void)
817 {
818   TestApplication application;
819
820   ImageActor actor = ImageActor::New(Image());
821
822   DALI_TEST_CHECK(actor);
823   END_TEST;
824 }
825
826 int UtcDaliImageActorNewNullWithArea(void)
827 {
828   TestApplication application;
829
830   ImageActor::PixelArea area( 1, 2, 3, 4 );
831
832   ImageActor actor = ImageActor::New(Image(), area);
833
834   DALI_TEST_CHECK(actor);
835   END_TEST;
836 }
837
838 int UtcDaliImageActorSetImage(void)
839 {
840   TestApplication application;
841
842   ImageActor actor = ImageActor::New(Image());
843
844   DALI_TEST_CHECK(actor);
845
846   actor.SetImage( Image() );
847
848   DALI_TEST_CHECK(!actor.GetImage());
849   END_TEST;
850 }
851
852 int UtcDaliImageActorPropertyIndices(void)
853 {
854   TestApplication application;
855   Actor basicActor = Actor::New();
856   ImageActor imageActor = ImageActor::New();
857
858   Property::IndexContainer indices;
859   imageActor.GetPropertyIndices( indices );
860   DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
861   DALI_TEST_EQUALS( indices.Size(), imageActor.GetPropertyCount(), TEST_LOCATION );
862   END_TEST;
863 }
864
865 int UtcDaliImageActorImageProperty(void)
866 {
867   TestApplication application;
868   Image image = ResourceImage::New( "MY_PATH" );
869   ImageActor imageActor = ImageActor::New( image );
870
871   Stage::GetCurrent().Add( imageActor );
872   application.SendNotification();
873   application.Render();
874
875   Property::Value imageProperty = imageActor.GetProperty( ImageActor::Property::IMAGE );
876   Property::Map* imageMap = imageProperty.GetMap();
877   DALI_TEST_CHECK( imageMap != NULL );
878   DALI_TEST_CHECK( NULL != imageMap->Find( "filename" ) );
879   DALI_TEST_EQUALS( (*imageMap)[ "filename" ].Get< std::string >(), "MY_PATH", TEST_LOCATION );
880   END_TEST;
881 }
882
883 int UtcDaliImageActorNinePatch01(void)
884 {
885   TestApplication application;
886   TestPlatformAbstraction& platform = application.GetPlatform();
887   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
888   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
889   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
890
891   tet_infoline("Test the successful loading of a nine-patch image\n");
892
893   platform.SetClosestImageSize(Vector2(4, 4));
894   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
895   Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  4,4,4,4 );
896   memset( pixels, 0, 64 );
897
898   Integration::ResourcePointer resourcePtr(bitmap); // reference it
899   platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
900
901   Image ninePatchImage = ResourceImage::New( "blah.#.png" );
902   DALI_TEST_CHECK( ninePatchImage );
903
904   ImageActor imageActor = ImageActor::New( ninePatchImage );
905   DALI_TEST_CHECK( imageActor );
906   Stage::GetCurrent().Add( imageActor );
907
908   drawTrace.Reset();
909   textureTrace.Reset();
910   drawTrace.Enable(true);
911   textureTrace.Enable(true);
912   glAbstraction.ClearBoundTextures();
913   std::vector<GLuint> ids;
914   ids.push_back( 23 );
915   glAbstraction.SetNextTextureIds( ids );
916
917   application.SendNotification();
918   application.Render();
919
920   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
921   typedef std::vector<GLuint> TexVec;
922   const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
923   DALI_TEST_CHECK( textures.size() > 0 );
924   if( textures.size() > 0 )
925   {
926     DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
927   }
928
929   END_TEST;
930 }
931
932
933 int UtcDaliImageActorNinePatch02(void)
934 {
935   TestApplication application;
936   TestPlatformAbstraction& platform = application.GetPlatform();
937   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
938   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
939   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
940
941   tet_infoline("Test the failed loading of a nine-patch image\n");
942
943   platform.SetClosestImageSize(Vector2(0, 0));
944   Integration::ResourcePointer resourcePtr;
945   platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
946
947   Image ninePatchImage = ResourceImage::New( "blah.#.png" );
948   DALI_TEST_CHECK( ninePatchImage );
949
950   ImageActor imageActor = ImageActor::New( ninePatchImage );
951   DALI_TEST_CHECK( imageActor );
952   Stage::GetCurrent().Add( imageActor );
953
954   drawTrace.Reset();
955   textureTrace.Reset();
956   drawTrace.Enable(true);
957   textureTrace.Enable(true);
958   glAbstraction.ClearBoundTextures();
959   std::vector<GLuint> ids;
960   ids.push_back( 23 );
961   glAbstraction.SetNextTextureIds( ids );
962
963   application.SendNotification();
964   application.Render();
965
966   // Check that nothing was drawn.
967   DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
968   typedef std::vector<GLuint> TexVec;
969   const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
970   DALI_TEST_CHECK( textures.size() == 0u );
971
972   END_TEST;
973 }
974
975
976 int UtcDaliImageActorNinePatch03(void)
977 {
978   TestApplication application;
979   TestPlatformAbstraction& platform = application.GetPlatform();
980   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
981   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
982   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
983
984   tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
985
986   platform.SetClosestImageSize(Vector2(4, 4));
987   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
988   Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  4,4,4,4 );
989   memset( pixels, 0, 64 );
990
991   Integration::ResourcePointer resourcePtr(bitmap); // reference it
992   platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
993
994   Image ninePatchImage = ResourceImage::New( "blah.#.png" );
995   DALI_TEST_CHECK( ninePatchImage );
996
997   ImageActor imageActor = ImageActor::New();
998   DALI_TEST_CHECK( imageActor );
999   Stage::GetCurrent().Add( imageActor );
1000
1001   imageActor.SetImage( ninePatchImage );
1002
1003   drawTrace.Reset();
1004   textureTrace.Reset();
1005   drawTrace.Enable(true);
1006   textureTrace.Enable(true);
1007   glAbstraction.ClearBoundTextures();
1008   std::vector<GLuint> ids;
1009   ids.push_back( 23 );
1010   glAbstraction.SetNextTextureIds( ids );
1011
1012   application.SendNotification();
1013   application.Render();
1014
1015   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1016   typedef std::vector<GLuint> TexVec;
1017   const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1018   DALI_TEST_CHECK( textures.size() > 0 );
1019   if( textures.size() > 0 )
1020   {
1021     DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1022   }
1023
1024   END_TEST;
1025 }
1026
1027
1028 int UtcDaliImageActorNinePatch04(void)
1029 {
1030   TestApplication application;
1031   TestPlatformAbstraction& platform = application.GetPlatform();
1032   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1033   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1034   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1035
1036   tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1037
1038   platform.SetClosestImageSize(Vector2(0, 0));
1039   Integration::ResourcePointer resourcePtr;
1040   platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1041
1042   Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1043   DALI_TEST_CHECK( ninePatchImage );
1044
1045   ImageActor imageActor = ImageActor::New();
1046   DALI_TEST_CHECK( imageActor );
1047   Stage::GetCurrent().Add( imageActor );
1048
1049   imageActor.SetImage( ninePatchImage );
1050
1051   drawTrace.Reset();
1052   textureTrace.Reset();
1053   drawTrace.Enable(true);
1054   textureTrace.Enable(true);
1055   glAbstraction.ClearBoundTextures();
1056   std::vector<GLuint> ids;
1057   ids.push_back( 23 );
1058   glAbstraction.SetNextTextureIds( ids );
1059
1060   application.SendNotification();
1061   application.Render();
1062
1063   // Check that nothing was drawn.
1064   DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1065   typedef std::vector<GLuint> TexVec;
1066   const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1067   DALI_TEST_CHECK( textures.size() == 0u );
1068
1069   END_TEST;
1070 }
1071
1072 int UtcDaliImageActorGetNaturalSize(void)
1073 {
1074   TestApplication application;
1075
1076   // Standard image
1077   BufferImage img = BufferImage::New( 10, 10 );
1078   ImageActor actor = ImageActor::New( img );
1079
1080   DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1081
1082   // Pixel area set
1083   ImageActor::PixelArea area( 1, 2, 3, 4 );
1084   actor.SetPixelArea( area );
1085
1086   DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );
1087
1088   END_TEST;
1089 }
1090
1091 int UtcDaliImageActorGetSortModifier(void)
1092 {
1093   TestApplication application;
1094
1095   tet_infoline("Testing Dali::ImageActor::GetSortModifier()");
1096
1097   ImageActor actor = ImageActor::New();
1098   Stage::GetCurrent().Add(actor);
1099
1100   DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION);
1101
1102   Stage::GetCurrent().Remove(actor);
1103   END_TEST;
1104 }
1105
1106 int UtcDaliImageActorSetGetBlendMode(void)
1107 {
1108   TestApplication application;
1109
1110   tet_infoline("Testing Dali::ImageActor::SetBlendMode() / Dali::ImageActor::GetBlendMode()");
1111
1112   ImageActor actor = ImageActor::New();
1113
1114   actor.SetBlendMode( BlendingMode::OFF );
1115   DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() );
1116
1117   actor.SetBlendMode( BlendingMode::AUTO );
1118   DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() );
1119
1120   actor.SetBlendMode( BlendingMode::ON );
1121   DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() );
1122   END_TEST;
1123 }
1124
1125 int UtcDaliImageActorSetGetBlendFunc(void)
1126 {
1127   TestApplication application;
1128   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1129
1130   tet_infoline("Testing Dali::ImageActor::UtcDaliImageActorSetGetBlendFunc()");
1131
1132   BufferImage img = BufferImage::New( 1,1 );
1133   ImageActor actor = ImageActor::New( img );
1134   Stage::GetCurrent().Add( actor );
1135   application.SendNotification();
1136   application.Render();
1137
1138   // Test the defaults as documented int blending.h
1139   {
1140     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1141     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1142     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1143     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1144     actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1145     DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA,           srcFactorRgb,    TEST_LOCATION );
1146     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb,   TEST_LOCATION );
1147     DALI_TEST_EQUALS( BlendingFactor::ONE,                 srcFactorAlpha,  TEST_LOCATION );
1148     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1149   }
1150
1151   // Set to non-default values
1152   actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE, BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
1153
1154   // Test that Set was successful
1155   {
1156     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1157     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1158     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1159     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1160     actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1161     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
1162     DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
1163     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
1164     DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
1165   }
1166
1167   // Render & check GL commands
1168   application.SendNotification();
1169   application.Render();
1170   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
1171   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
1172   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1173   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1174
1175   // Set using separate alpha settings
1176   actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
1177                       BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
1178
1179   // Test that Set was successful
1180   {
1181     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1182     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1183     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1184     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1185     actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1186     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
1187     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
1188     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
1189     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
1190   }
1191
1192   // Render & check GL commands
1193   application.SendNotification();
1194   application.Render();
1195   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
1196   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
1197   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1198   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1199   END_TEST;
1200 }
1201
1202 int UtcDaliImageActorSetGetAlpha(void)
1203 {
1204   TestApplication application;
1205
1206   tet_infoline("Testing Dali::ImageActor::SetGetAlpha()");
1207
1208   BufferImage img = BufferImage::New( 1,1 );
1209   ImageActor actor = ImageActor::New( img );
1210   Stage::GetCurrent().Add( actor );
1211   application.SendNotification();
1212   application.Render();
1213
1214   // use the image alpha on actor
1215   actor.SetBlendMode(BlendingMode::ON);
1216
1217   // Test that Set was successful
1218   DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION );
1219
1220   // Now test that it can be set to false
1221   actor.SetBlendMode(BlendingMode::OFF);
1222   DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION );
1223   END_TEST;
1224 }
1225
1226 int UtcDaliImageActorSetGetFilterModes(void)
1227 {
1228   TestApplication application;
1229
1230   tet_infoline("Testing Dali::ImageActor::SetFilterMode() / Dali::ImageActor::GetFilterMode()");
1231
1232   ImageActor actor = ImageActor::New();
1233
1234   FilterMode::Type minifyFilter = FilterMode::NEAREST;
1235   FilterMode::Type magnifyFilter = FilterMode::NEAREST;
1236
1237   // Default test
1238   actor.GetFilterMode( minifyFilter, magnifyFilter );
1239   DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1240   DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1241
1242   // Default/Default
1243   actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1244   actor.GetFilterMode( minifyFilter, magnifyFilter );
1245   DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1246   DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1247
1248   // Nearest/Nearest
1249   actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1250   actor.GetFilterMode( minifyFilter, magnifyFilter );
1251   DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1252   DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1253
1254   // Linear/Linear
1255   actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1256   actor.GetFilterMode( minifyFilter, magnifyFilter );
1257   DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1258   DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1259
1260   // Nearest/Linear
1261   actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1262   actor.GetFilterMode( minifyFilter, magnifyFilter );
1263   DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1264   DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1265
1266   // Linear/Nearest
1267   actor.SetFilterMode( FilterMode::LINEAR, FilterMode::NEAREST );
1268   actor.GetFilterMode( minifyFilter, magnifyFilter );
1269   DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1270   DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1271
1272   END_TEST;
1273 }
1274
1275 int UtcDaliImageActorSetFilterMode(void)
1276 {
1277   TestApplication application;
1278
1279   tet_infoline("Testing Dali::ImageActor::SetFilterMode()");
1280
1281   BufferImage img = BufferImage::New( 1,1 );
1282   ImageActor actor = ImageActor::New( img );
1283
1284   actor.SetSize(100.0f, 100.0f);
1285   actor.SetParentOrigin(ParentOrigin::CENTER);
1286   actor.SetAnchorPoint(AnchorPoint::CENTER);
1287
1288   Stage::GetCurrent().Add(actor);
1289
1290   /**************************************************************/
1291
1292   // Default/Default
1293   TraceCallStack& texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1294   texParameterTrace.Reset();
1295   texParameterTrace.Enable( true );
1296
1297   actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1298
1299   // Flush the queue and render once
1300   application.SendNotification();
1301   application.Render();
1302
1303   texParameterTrace.Enable( false );
1304
1305   std::stringstream out;
1306
1307   // Verify actor gl state
1308
1309   // There are two calls to TexParameteri when the texture is first created
1310   // Texture mag filter is not called as the first time set it uses the system default
1311   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1312
1313   out.str("");
1314   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1315   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
1316
1317   /**************************************************************/
1318
1319   // Default/Default
1320   texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1321   texParameterTrace.Reset();
1322   texParameterTrace.Enable( true );
1323
1324   actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1325
1326   // Flush the queue and render once
1327   application.SendNotification();
1328   application.Render();
1329
1330   texParameterTrace.Enable( false );
1331
1332   // Verify actor gl state
1333
1334   // Should not make any calls when settings are the same
1335   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
1336
1337   /**************************************************************/
1338
1339   // Nearest/Nearest
1340   texParameterTrace.Reset();
1341   texParameterTrace.Enable( true );
1342
1343   actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1344
1345   // Flush the queue and render once
1346   application.SendNotification();
1347   application.Render();
1348
1349   texParameterTrace.Enable( false );
1350
1351   // Verify actor gl state
1352   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1353
1354   out.str("");
1355   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1356   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1357
1358   out.str("");
1359   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
1360   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1361
1362   /**************************************************************/
1363
1364   // Linear/Linear
1365   texParameterTrace.Reset();
1366   texParameterTrace.Enable( true );
1367
1368   actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1369
1370   // Flush the queue and render once
1371   application.SendNotification();
1372   application.Render();
1373
1374   texParameterTrace.Enable( false );
1375
1376   // Verify actor gl state
1377   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1378
1379   out.str("");
1380   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1381   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1382
1383   out.str("");
1384   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
1385   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1386
1387
1388   /**************************************************************/
1389
1390   // Nearest/Linear
1391   texParameterTrace.Reset();
1392   texParameterTrace.Enable( true );
1393
1394   actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1395
1396   // Flush the queue and render once
1397   application.SendNotification();
1398   application.Render();
1399
1400   texParameterTrace.Enable( false );
1401
1402   // Verify actor gl state
1403   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1404
1405   out.str("");
1406   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1407   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1408
1409   /**************************************************************/
1410
1411   // Default/Default
1412   texParameterTrace.Reset();
1413   texParameterTrace.Enable( true );
1414
1415   actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1416
1417   // Flush the queue and render once
1418   application.SendNotification();
1419   application.Render();
1420
1421   texParameterTrace.Enable( false );
1422
1423   // Verify actor gl state
1424   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1425
1426   out.str("");
1427   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1428   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1429
1430   /**************************************************************/
1431
1432   // None/None
1433   texParameterTrace.Reset();
1434   texParameterTrace.Enable( true );
1435
1436   actor.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
1437
1438   // Flush the queue and render once
1439   application.SendNotification();
1440   application.Render();
1441
1442   texParameterTrace.Enable( false );
1443
1444   // Verify actor gl state
1445   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1446
1447   out.str("");
1448   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
1449   DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1450
1451   /**************************************************************/
1452
1453   Stage::GetCurrent().Remove(actor);
1454
1455   END_TEST;
1456 }
1457
1458 int UtcDaliImageActorSetShaderEffect(void)
1459 {
1460   TestApplication application;
1461   BufferImage img = BufferImage::New( 1,1 );
1462   ImageActor actor = ImageActor::New( img );
1463   Stage::GetCurrent().Add( actor );
1464
1465   // flush the queue and render once
1466   application.SendNotification();
1467   application.Render();
1468   GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1469
1470   application.GetGlAbstraction().EnableShaderCallTrace( true );
1471
1472   const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1473   const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1474   ShaderEffect effect = ShaderEffect::New(vertexShader, fragmentShader );
1475   DALI_TEST_CHECK( effect != actor.GetShaderEffect() );
1476
1477   actor.SetShaderEffect( effect );
1478   DALI_TEST_CHECK( effect == actor.GetShaderEffect() );
1479
1480   // flush the queue and render once
1481   application.SendNotification();
1482   application.Render();
1483
1484   GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1485   DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1486
1487   std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1488   DALI_TEST_EQUALS( vertexShader,
1489                     actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1490   std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1491   DALI_TEST_EQUALS( fragmentShader,
1492                     actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1493
1494   END_TEST;
1495 }
1496
1497 int UtcDaliImageActorGetShaderEffect(void)
1498 {
1499   TestApplication application;
1500   ImageActor actor = ImageActor::New();
1501
1502   ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorGetShaderEffect-VertexSource", "UtcDaliImageActorGetShaderEffect-FragmentSource" );
1503   actor.SetShaderEffect(effect);
1504
1505   DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1506   END_TEST;
1507 }
1508
1509 int UtcDaliImageActorRemoveShaderEffect01(void)
1510 {
1511   TestApplication application;
1512   ImageActor actor = ImageActor::New();
1513
1514   ShaderEffect defaultEffect = actor.GetShaderEffect();
1515
1516   ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorRemoveShaderEffect-VertexSource", "UtcDaliImageActorRemoveShaderEffect-FragmentSource" );
1517   actor.SetShaderEffect(effect);
1518
1519   DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1520
1521   actor.RemoveShaderEffect();
1522
1523   DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1524   END_TEST;
1525 }
1526
1527 int UtcDaliImageActorRemoveShaderEffect02(void)
1528 {
1529   TestApplication application;
1530   ImageActor actor = ImageActor::New();
1531
1532   ShaderEffect defaultEffect = actor.GetShaderEffect();
1533
1534   actor.RemoveShaderEffect();
1535
1536   DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1537   END_TEST;
1538 }
1539
1540 int UtcDaliSetShaderEffectRecursively(void)
1541 {
1542   TestApplication application;
1543   /**
1544    * create a tree
1545    *                 actor1
1546    *           actor2       actor4
1547    *       actor3 imageactor1
1548    * imageactor2
1549    */
1550   BufferImage img = BufferImage::New( 1,1 );
1551   ImageActor actor1 = ImageActor::New( img );
1552   Actor actor2 = Actor::New();
1553   actor1.Add( actor2 );
1554   Actor actor3 = Actor::New();
1555   actor2.Add( actor3 );
1556   ImageActor imageactor1 = ImageActor::New( img );
1557   actor2.Add( imageactor1 );
1558   ImageActor imageactor2 = ImageActor::New( img );
1559   actor3.Add( imageactor2 );
1560   Actor actor4 = Actor::New();
1561   actor1.Add( actor4 );
1562   Stage::GetCurrent().Add( actor1 );
1563
1564   // flush the queue and render once
1565   application.SendNotification();
1566   application.Render();
1567   GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1568
1569   application.GetGlAbstraction().EnableShaderCallTrace( true );
1570
1571   const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1572   const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1573   // test with empty effect
1574   ShaderEffect effect;
1575   SetShaderEffectRecursively( actor1, effect );
1576
1577   effect = ShaderEffect::New(vertexShader, fragmentShader );
1578
1579   DALI_TEST_CHECK( effect != actor1.GetShaderEffect() );
1580   DALI_TEST_CHECK( effect != imageactor1.GetShaderEffect() );
1581   DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1582
1583   SetShaderEffectRecursively( actor1, effect );
1584   DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1585   DALI_TEST_CHECK( effect == imageactor2.GetShaderEffect() );
1586
1587   // flush the queue and render once
1588   application.SendNotification();
1589   application.Render();
1590
1591   GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1592   DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1593
1594   std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1595   DALI_TEST_EQUALS( vertexShader,
1596                     actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1597   std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1598   DALI_TEST_EQUALS( fragmentShader,
1599                     actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1600
1601   // remove from one that does not have shader
1602   RemoveShaderEffectRecursively( actor4 );
1603
1604   // remove partially
1605   RemoveShaderEffectRecursively( actor3 );
1606   DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1607   DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1608
1609   // test with empty actor just to check it does not crash
1610   Actor empty;
1611   SetShaderEffectRecursively( empty, effect );
1612   RemoveShaderEffectRecursively( empty );
1613
1614   // test with actor with no children just to check it does not crash
1615   Actor loner = Actor::New();
1616   Stage::GetCurrent().Add( loner );
1617   SetShaderEffectRecursively( loner, effect );
1618   RemoveShaderEffectRecursively( loner );
1619
1620   END_TEST;
1621 }
1622
1623 int UtcDaliImageActorTestClearCache(void)
1624 {
1625   // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
1626   TestApplication application;
1627
1628   tet_infoline("Testing Dali::ImageActor::ClearCache()");
1629
1630   BufferImage img = BufferImage::New( 1,1 );
1631   ImageActor actor = ImageActor::New( img );
1632
1633   actor.SetParentOrigin(ParentOrigin::CENTER);
1634   actor.SetAnchorPoint(AnchorPoint::CENTER);
1635
1636   Stage::GetCurrent().Add(actor);
1637
1638   /**************************************************************/
1639   // Flush the queue and render once
1640   application.SendNotification();
1641   application.Render();
1642
1643   // There should be a single call to Clear
1644   DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 1u, TEST_LOCATION );
1645
1646   // the last set clear mask should be COLOR, DEPTH & STENCIL which occurs at the start of each frame
1647   GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
1648   DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT );
1649   DALI_TEST_CHECK( mask & GL_STENCIL_BUFFER_BIT );
1650   DALI_TEST_CHECK( mask & GL_COLOR_BUFFER_BIT );
1651
1652   END_TEST;
1653 }