Migrating to new test framework
[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 Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali/dali.h>
20 #include "dali-test-suite-utils/dali-test-suite-utils.h"
21
22 using namespace Dali;
23
24 static const char* TestImageFilename = "icon_wrt.png";
25
26 void image_actor_test_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void image_actor_test_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36
37 int UtcDaliImageActorConstructorVoid(void)
38 {
39   TestApplication application;
40   tet_infoline("Testing Dali::ImageActor::ImageActor()");
41
42   ImageActor actor;
43
44   DALI_TEST_CHECK(!actor);
45   END_TEST;
46 }
47
48 int UtcDaliImageActorDestructor(void)
49 {
50   TestApplication application;
51
52   ImageActor* actor = new ImageActor();
53   delete actor;
54
55   DALI_TEST_CHECK( true );
56   END_TEST;
57 }
58
59 int UtcDaliImageActorNew01(void)
60 {
61   TestApplication application;
62   tet_infoline("Positive test for Dali::ImageActor::New()");
63
64   Image image = Image::New(TestImageFilename);
65   ImageActor actor = ImageActor::New(image);
66   Stage::GetCurrent().Add(actor);
67
68   application.SendNotification();
69   application.Render();
70   application.Render();
71   application.SendNotification();
72
73   DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
74
75   DALI_TEST_CHECK(actor);
76   END_TEST;
77 }
78
79 int UtcDaliImageActorNew02(void)
80 {
81   TestApplication application;
82   tet_infoline("Negative test for Dali::ImageActor::New()");
83
84   Image image = Image::New("hopefully-this-image-file-does-not-exist");
85   ImageActor actor = ImageActor::New(image);
86
87   DALI_TEST_CHECK(actor);
88   END_TEST;
89 }
90
91 int UtcDaliImageActorDownCast(void)
92 {
93   TestApplication application;
94   tet_infoline("Testing Dali::ImageActor::DownCast()");
95
96   Image image = Image::New("IncorrectImageName");
97   ImageActor actor1 = ImageActor::New(image);
98   Actor anActor = Actor::New();
99   anActor.Add(actor1);
100
101   Actor child = anActor.GetChildAt(0);
102   ImageActor imageActor = DownCast< ImageActor >(child);
103
104   DALI_TEST_CHECK(imageActor);
105   END_TEST;
106 }
107
108 int UtcDaliImageActorDownCast2(void)
109 {
110   TestApplication application;
111   tet_infoline("Testing Dali::ImageActor::DownCast()");
112
113   Actor actor1 = Actor::New();
114   Actor anActor = Actor::New();
115   anActor.Add(actor1);
116
117   Actor child = anActor.GetChildAt(0);
118   ImageActor imageActor = ImageActor::DownCast(child);
119   DALI_TEST_CHECK(!imageActor);
120
121   Actor unInitialzedActor;
122   imageActor = ImageActor::DownCast( unInitialzedActor );
123   DALI_TEST_CHECK(!imageActor);
124   END_TEST;
125 }
126
127 int UtcDaliImageActor9Patch(void)
128 {
129   TestApplication application;
130   tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
131
132   Image image = Image::New(TestImageFilename);
133   ImageActor actor = ImageActor::New(image);
134
135   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
136   Vector4 border(0.1,0.2,0.3,0.4);
137   actor.SetNinePatchBorder(border);
138
139   DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
140   DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
141   DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
142   DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
143   END_TEST;
144 }
145
146 int UtcDaliImageActorPixelArea(void)
147 {
148   TestApplication application;
149   tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
150
151   BitmapImage img = BitmapImage::New( 10, 10 );
152   ImageActor actor = ImageActor::New( img );
153
154   DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
155
156   ImageActor::PixelArea area( 1, 2, 3, 4 );
157   actor.SetPixelArea( area );
158
159   DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
160
161   DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
162   DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
163   DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
164   DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
165
166   ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
167   DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );
168
169   DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
170   DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
171   DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
172   DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
173   END_TEST;
174 }
175
176 int UtcDaliImageActorGetCurrentImageSize01(void)
177 {
178   TestApplication application;
179   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");
180
181   Vector2 initialImageSize(100, 50);
182   BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
183   ImageActor actor = ImageActor::New( image );
184   Stage::GetCurrent().Add(actor);
185
186   application.SendNotification();
187   application.Render();
188
189   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
190
191   Vector2 size(200.0f, 200.0f);
192   actor.SetSize(size);
193
194   // flush the queue and render once
195   application.SendNotification();
196   application.Render();
197   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
198
199   size.x = 200.0f;
200   size.y = 200.0f;
201   actor.SetSize(size);
202   application.Render(8);
203
204   // Test when a pixel area is set
205   ImageActor::PixelArea area(0, 0, 10, 10);
206   actor.SetPixelArea(area);
207   application.Render(9);
208   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
209   END_TEST;
210 }
211
212
213 int UtcDaliImageActorGetCurrentImageSize02(void)
214 {
215   TestApplication application;
216   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
217
218   Vector2 initialImageSize(100, 50);
219
220   application.GetPlatform().SetClosestImageSize(initialImageSize);
221
222   Image image = Image::New("image.jpg");
223   ImageActor actor = ImageActor::New( image );
224   Stage::GetCurrent().Add(actor);
225
226   application.SendNotification(); // Flush update messages
227   application.Render();           // Process resource request
228   application.SendNotification(); // Flush update messages
229   application.Render();           // Process resource request
230
231   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
232
233   // Now complete the image load
234   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
235   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
236   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
237
238   Integration::ResourcePointer resourcePtr(bitmap); // reference it
239   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
240   application.Render();           // Process LoadComplete
241   application.SendNotification(); // Process event messages
242   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
243   application.GetPlatform().ClearReadyResources(); //
244
245   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
246
247   Vector2 size(200.0f, 200.0f);
248   actor.SetSize(size);
249
250   // flush the queue and render once
251   application.SendNotification();
252   application.Render();
253   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
254
255   actor.SetToNaturalSize();
256   application.SendNotification();
257   application.Render();
258   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
259   END_TEST;
260 }
261
262
263 int UtcDaliImageActorGetCurrentImageSize03(void)
264 {
265   TestApplication application;
266   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
267
268   Vector2 closestImageSize( 80, 45);
269
270   application.GetPlatform().SetClosestImageSize(closestImageSize);
271
272   ImageAttributes attrs;
273   attrs.SetSize(40, 30);
274   Image image = Image::New("image.jpg", attrs);
275   ImageActor actor = ImageActor::New( image );
276   Stage::GetCurrent().Add(actor);
277
278   application.SendNotification(); // Flush update messages
279   application.Render();           // Process resource request
280   application.SendNotification(); // Flush update messages
281   application.Render();           // Process resource request
282
283   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
284
285   // Now complete the image load
286   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
287   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
288   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
289
290   Integration::ResourcePointer resourcePtr(bitmap); // reference it
291   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
292   application.Render();           // Process LoadComplete
293   application.SendNotification(); // Process event messages
294   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
295   application.GetPlatform().ClearReadyResources(); //
296
297   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
298
299   // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
300   Vector2 size(200.0f, 200.0f);
301   actor.SetSize(size);
302
303   // flush the queue and render once
304   application.SendNotification();
305   application.Render();
306   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
307
308   actor.SetToNaturalSize();
309   application.SendNotification();
310   application.Render();
311   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
312   END_TEST;
313 }
314
315
316 int UtcDaliImageActorGetCurrentImageSize04(void)
317 {
318   TestApplication application;
319   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doesn't change a set actor size");
320
321   Vector2 closestImageSize( 80, 45);
322   application.GetPlatform().SetClosestImageSize(closestImageSize);
323
324   ImageAttributes attrs;
325   attrs.SetSize(40, 30); // Request a really small size we won't get.
326   Image image = Image::New("image.jpg", attrs);
327   ImageActor actor = ImageActor::New( image );
328   Stage::GetCurrent().Add(actor);
329
330   application.SendNotification(); // Flush update messages
331   application.Render();           // Process resource request
332
333   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
334
335   // Now complete the image load
336   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
337   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
338   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
339
340   Integration::ResourcePointer resourcePtr(bitmap); // reference it
341   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
342   application.Render();           // Process LoadComplete
343   application.SendNotification(); // Process event messages
344   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
345   application.GetPlatform().ClearReadyResources(); //
346
347   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
348
349   Vector2 size(200.0f, 200.0f);
350   actor.SetSize(size);
351
352   // flush the queue and render once
353   application.SendNotification();
354   application.Render();
355   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
356
357   // Load a different image
358
359   Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
360   application.GetPlatform().SetClosestImageSize(image2ClosestSize);
361
362   attrs.SetSize(100, 100);
363   Image image2 = Image::New("image2.jpg", attrs);
364   actor.SetImage(image2);
365
366   application.SendNotification(); // Flush update messages
367   application.Render();           // Process resource request
368   application.SendNotification(); // Flush update messages
369   application.Render();           // Process resource request
370
371   // Ensure the actor size is kept
372   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
373
374   // Now complete the image load
375   req = application.GetPlatform().GetRequest();
376   Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
377   bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
378
379   Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
380   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
381   application.Render();           // Process LoadComplete
382   application.SendNotification(); // Process event messages
383   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
384   application.GetPlatform().ClearReadyResources(); //
385
386   // Ensure the actor size is kept
387   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
388
389   actor.SetToNaturalSize();
390   application.SendNotification();
391   application.Render();
392   // Ensure the actor size gets the new image's natural size
393   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
394   END_TEST;
395 }
396
397
398 int UtcDaliImageActorGetCurrentImageSize05(void)
399 {
400   TestApplication application;
401   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
402
403   Vector2 closestImageSize( 80, 45);
404   application.GetPlatform().SetClosestImageSize(closestImageSize);
405
406   ImageAttributes attrs;
407   attrs.SetSize(40, 30); // Request a really small size we won't get.
408   Image image = Image::New("image.jpg", attrs);
409   ImageActor actor = ImageActor::New( image );
410   Stage::GetCurrent().Add(actor);
411
412   application.SendNotification(); // Flush update messages
413   application.Render();           // Process resource request
414
415   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
416
417   // Now complete the image load
418   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
419   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
420   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
421
422   Integration::ResourcePointer resourcePtr(bitmap); // reference it
423   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
424   application.Render();           // Process LoadComplete
425   application.SendNotification(); // Process event messages
426   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
427   application.GetPlatform().ClearReadyResources(); //
428
429   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
430
431   // Load a different image
432
433   Vector2 image2ClosestSize = Vector2(240, 150);
434   application.GetPlatform().SetClosestImageSize(image2ClosestSize);
435
436   attrs.SetSize(100, 100);
437   Image image2 = Image::New("image2.jpg", attrs);
438   actor.SetImage(image2);
439
440   application.SendNotification(); // Flush update messages
441   application.Render();           // Process resource request
442   application.SendNotification(); // Flush update messages
443   application.Render();           // Process resource request
444
445   // Ensure the actor size is kept
446   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
447
448   // Now complete the image load
449   req = application.GetPlatform().GetRequest();
450   Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
451   bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
452
453   Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
454   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
455   application.Render();           // Process LoadComplete
456   application.SendNotification(); // Process event messages
457   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
458   application.GetPlatform().ClearReadyResources(); //
459
460   application.SendNotification(); // Process event messages
461   application.Render();           // Process LoadComplete
462
463   // Ensure the actor size gets the new image's natural size
464   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
465   END_TEST;
466 }
467
468 int UtcDaliImageActorNaturalPixelAreaSize01(void)
469 {
470   TestApplication application;
471   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
472
473 //If an image is loaded without setting size, then the actor gets the natural size of the image
474 //Setting the pixel area will change the actor size to match the pixel area
475 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
476 //to the new size.
477 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
478
479
480   Vector2 closestImageSize( 80, 45);
481   application.GetPlatform().SetClosestImageSize(closestImageSize);
482
483   ImageAttributes attrs;
484   attrs.SetSize(40, 30); // Request a really small size we won't get.
485   Image image = Image::New("image.jpg", attrs);
486   ImageActor actor = ImageActor::New( image );
487   Stage::GetCurrent().Add(actor);
488
489   application.SendNotification(); // Flush update messages
490   application.Render();           // Process resource request
491
492   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
493   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
494
495   // Now complete the image load
496   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
497   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
498   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
499
500   Integration::ResourcePointer resourcePtr(bitmap); // reference it
501   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
502   application.Render();           // Process LoadComplete
503   application.SendNotification(); // Process event messages
504   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
505   application.GetPlatform().ClearReadyResources(); //
506
507   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
508   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
509
510   // Set a pixel area on a naturally sized actor - expect the actor to take the
511   // pixel area as size
512   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
513   application.SendNotification(); // Process event messages
514   application.Render();           // Process LoadComplete
515   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
516   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
517
518   // Set a size. Expect the partial image to stretch to fill the new size
519   actor.SetSize(100, 100);
520   application.SendNotification(); // Process event messages
521   application.Render();           // Process LoadComplete
522   application.Render();           // Process LoadComplete
523   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
524   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
525
526   // Clear the pixel area. Expect the whole image to be shown, filling the set size.
527   actor.ClearPixelArea();
528   application.SendNotification(); // Process event messages
529   application.Render();           // Process LoadComplete
530   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
531   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
532   END_TEST;
533 }
534
535 int UtcDaliImageActorNaturalPixelAreaSize02(void)
536 {
537   TestApplication application;
538   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
539
540 //If an image is loaded without setting size, then the actor gets the natural size of the image
541 //Setting the pixel area will change the actor size to match the pixel area
542 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
543 //to the new size.
544 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
545
546
547   Vector2 closestImageSize( 80, 45);
548   application.GetPlatform().SetClosestImageSize(closestImageSize);
549
550   ImageAttributes attrs;
551   attrs.SetSize(40, 30); // Request a really small size we won't get.
552   Image image = Image::New("image.jpg", attrs);
553   ImageActor actor = ImageActor::New( image );
554   Stage::GetCurrent().Add(actor);
555
556   application.SendNotification(); // Flush update messages
557   application.Render();           // Process resource request
558
559   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
560   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
561
562   // Now complete the image load
563   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
564   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
565   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
566
567   Integration::ResourcePointer resourcePtr(bitmap); // reference it
568   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
569   application.Render();           // Process LoadComplete
570   application.SendNotification(); // Process event messages
571   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
572   application.GetPlatform().ClearReadyResources(); //
573
574   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
575   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
576
577   // Set a pixel area on a naturally sized actor - expect the actor to take the
578   // pixel area as size
579   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
580   application.SendNotification(); // Process event messages
581   application.Render();           // Process LoadComplete
582   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
583   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
584
585   // Clear the pixel area. Expect the whole image to be shown, changing actor size
586   actor.ClearPixelArea();
587   application.SendNotification(); // Process event messages
588   application.Render();           // Process LoadComplete
589   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
590   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
591
592   // Set a size. Expect the partial image to stretch to fill the new size
593   actor.SetSize(100, 100);
594   application.SendNotification(); // Process event messages
595   application.Render();           // Process LoadComplete
596   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
597   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
598
599   // Set a pixel area, don't expect size to change
600   actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
601   application.SendNotification(); // Process event messages
602   application.Render();           // Process LoadComplete
603   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
604   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
605
606   // Use natural size - expect actor to change to pixel area
607   actor.SetToNaturalSize();
608   application.SendNotification(); // Process event messages
609   application.Render();           // Process LoadComplete
610   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
611   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
612
613   // Clearing pixel area should change actor size to image size
614   actor.ClearPixelArea();
615   application.SendNotification(); // Process event messages
616   application.Render();           // Process LoadComplete
617   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
618   DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
619   END_TEST;
620 }
621
622
623
624 int UtcDaliImageActorDefaultProperties(void)
625 {
626   TestApplication application;
627   tet_infoline("Testing Dali::ImageActor DefaultProperties");
628
629   BitmapImage img = BitmapImage::New( 10, 10 );
630   ImageActor actor = ImageActor::New( img );
631
632   std::vector<Property::Index> indices;
633   indices.push_back(ImageActor::PIXEL_AREA      );
634   indices.push_back(ImageActor::FADE_IN         );
635   indices.push_back(ImageActor::FADE_IN_DURATION);
636   indices.push_back(ImageActor::STYLE           );
637   indices.push_back(ImageActor::BORDER          );
638   indices.push_back(ImageActor::IMAGE           );
639
640   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
641
642   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
643   {
644     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
645     DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
646     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
647     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
648   }
649
650   // set/get one of them
651   actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
652
653   ImageActor::PixelArea area( 1, 2, 3, 4 );
654   actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect<int>(area)));
655
656   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA));
657
658   Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA);
659
660   DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
661
662   END_TEST;
663 }
664
665 int UtcDaliImageActorUseImageAlpha01(void)
666 {
667   TestApplication application;
668
669   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
670
671   BitmapImage image = BitmapImage::New( 100, 50 );
672   ImageActor actor = ImageActor::New( image );
673   actor.SetBlendMode( BlendingMode::ON );
674   actor.SetSize(100, 50);
675   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
676   Stage::GetCurrent().Add(actor);
677
678   application.SendNotification();
679   application.Render();
680
681   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
682   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
683   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
684   END_TEST;
685 }
686
687 int UtcDaliImageActorUseImageAlpha02(void)
688 {
689   TestApplication application;
690
691   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
692
693   BitmapImage image = BitmapImage::New( 100, 50 );
694   ImageActor actor = ImageActor::New( image );
695   actor.SetBlendMode( BlendingMode::OFF );
696   actor.SetSize(100, 50);
697   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
698   Stage::GetCurrent().Add(actor);
699
700   application.SendNotification();
701   application.Render();
702
703   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
704   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
705   DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
706   END_TEST;
707 }
708
709 int UtcDaliImageActorUseImageAlpha03(void)
710 {
711   TestApplication application;
712
713   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
714
715   BitmapImage image = BitmapImage::New( 100, 50 );
716   ImageActor actor = ImageActor::New( image );
717   actor.SetBlendMode( BlendingMode::AUTO );
718   actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
719   actor.SetSize(100, 50);
720   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
721   Stage::GetCurrent().Add(actor);
722
723   application.SendNotification();
724   application.Render();
725
726   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
727   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
728   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
729   END_TEST;
730 }
731
732 int UtcDaliImageActorUseImageAlpha04(void)
733 {
734   TestApplication application;
735
736   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
737
738   FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
739   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
740   RenderTask task = taskList.GetTask( 0u );
741   task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
742   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
743   application.SendNotification();
744   application.Render(0);
745
746   ImageActor actor = ImageActor::New( image );
747   application.SendNotification();
748   application.Render(0);
749
750   actor.SetBlendMode( BlendingMode::ON );
751   actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
752   actor.SetSize(100, 50);
753   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
754   Stage::GetCurrent().Add(actor);
755
756   application.SendNotification();
757   application.Render();
758
759   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
760   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
761   DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
762   END_TEST;
763 }
764
765 int UtcDaliImageActorUseImageAlpha05(void)
766 {
767   TestApplication application;
768
769   tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
770
771   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
772   ImageActor actor = ImageActor::New( image );
773   actor.SetBlendMode( BlendingMode::AUTO );
774   actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
775   actor.SetSize(100, 50);
776   application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
777   Stage::GetCurrent().Add(actor);
778
779   application.SendNotification();
780   application.Render();
781
782   const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
783   DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
784   DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
785   END_TEST;
786 }
787
788 int UtcDaliImageActorClearPixelArea(void)
789 {
790   TestApplication application;
791
792   BitmapImage img = BitmapImage::New( 10, 10 );
793   ImageActor actor = ImageActor::New( img );
794
795   DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
796
797   ImageActor::PixelArea area( 1, 2, 3, 4 );
798   actor.SetPixelArea( area );
799
800   DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
801
802   actor.ClearPixelArea();
803
804   DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
805   END_TEST;
806 }
807
808 int UtcDaliImageGetStyle(void)
809 {
810   TestApplication application;
811
812   Image image = Image::New(TestImageFilename);
813   ImageActor actor = ImageActor::New(image);
814
815   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
816
817   // flush the queue and render once
818   application.SendNotification();
819   application.Render();
820
821   DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
822   END_TEST;
823 }
824
825 int UtcDaliImageSetNinePatchBorder(void)
826 {
827   TestApplication application;
828
829   Image image = Image::New(TestImageFilename);
830   ImageActor actor = ImageActor::New(image);
831
832   actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
833   actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
834
835   DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
836   DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
837   DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
838   DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
839   END_TEST;
840 }
841
842 int UtcDaliImageSetFadeIn(void)
843 {
844   TestApplication application;
845
846   Image image = Image::New(TestImageFilename);
847   ImageActor actor = ImageActor::New(image);
848
849   actor.SetFadeIn(true);
850
851   // flush the queue and render once
852   application.SendNotification();
853   application.Render();
854
855   DALI_TEST_EQUALS( true, actor.GetFadeIn(), TEST_LOCATION );
856
857   actor.SetFadeIn(false);
858
859   // flush the queue and render once
860   application.SendNotification();
861   application.Render();
862
863   DALI_TEST_EQUALS( false, actor.GetFadeIn(), TEST_LOCATION );
864   END_TEST;
865 }
866
867
868 int UtcDaliImageSetFadeInDuration(void)
869 {
870   TestApplication application;
871
872   Image image = Image::New(TestImageFilename);
873   ImageActor actor = ImageActor::New(image);
874
875   actor.SetFadeInDuration( 1.0f );
876
877   // flush the queue and render once
878   application.SendNotification();
879   application.Render();
880
881   DALI_TEST_EQUALS( 1.0f, actor.GetFadeInDuration(), TEST_LOCATION );
882
883   actor.SetFadeInDuration( 3.0f );
884
885   // flush the queue and render once
886   application.SendNotification();
887   application.Render();
888
889   DALI_TEST_EQUALS( 3.0f, actor.GetFadeInDuration(), TEST_LOCATION );
890   END_TEST;
891 }
892
893 int UtcDaliImageActorNewNull(void)
894 {
895   TestApplication application;
896
897   ImageActor actor = ImageActor::New(Image());
898
899   DALI_TEST_CHECK(actor);
900   END_TEST;
901 }
902
903 int UtcDaliImageActorNewNullWithArea(void)
904 {
905   TestApplication application;
906
907   ImageActor::PixelArea area( 1, 2, 3, 4 );
908
909   ImageActor actor = ImageActor::New(Image(), area);
910
911   DALI_TEST_CHECK(actor);
912   END_TEST;
913 }
914
915 int UtcDaliImageActorSetImage(void)
916 {
917   TestApplication application;
918
919   ImageActor actor = ImageActor::New(Image());
920
921   DALI_TEST_CHECK(actor);
922
923   actor.SetImage( Image() );
924
925   DALI_TEST_CHECK(!actor.GetImage());
926   END_TEST;
927 }
928
929 int UtcDaliImageActorPropertyIndices(void)
930 {
931   TestApplication application;
932   Actor basicActor = Actor::New();
933   ImageActor imageActor = ImageActor::New();
934
935   Property::IndexContainer indices;
936   imageActor.GetPropertyIndices( indices );
937   DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
938   DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
939   END_TEST;
940 }