2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
22 #include <test-native-image.h>
26 void utc_dali_image_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_image_cleanup(void)
33 test_return_value = TET_PASS;
36 static const char* gTestImageFilename = "icon_wrt.png";
40 int UtcDaliImageNew01(void)
42 TestApplication application;
44 tet_infoline("UtcDaliImageNew01 - Image::New(const std::string&)");
46 // invoke default handle constructor
49 DALI_TEST_CHECK( !image );
52 image = Image::New(gTestImageFilename);
54 DALI_TEST_CHECK( image );
59 int UtcDaliImageNew02(void)
61 TestApplication application;
63 tet_infoline("UtcDaliImageNew02 - Image::New(const std::string&, const ImageAttributes&)");
65 // invoke default handle constructor
68 DALI_TEST_CHECK( !image );
71 Dali::ImageAttributes imageAttributes;
72 imageAttributes.SetSize(128, 256);
73 imageAttributes.SetScalingMode(Dali::ImageAttributes::FitHeight);
74 image = Image::New(gTestImageFilename, imageAttributes);
76 DALI_TEST_CHECK( image );
81 int UtcDaliImageNew03(void)
83 TestApplication application;
85 tet_infoline("UtcDaliImageNew03 - Image::New(NativeImage&)");
87 // invoke default handle constructor
89 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
91 DALI_TEST_CHECK( !image );
94 image = Image::New(*(nativeImage.Get()));
96 DALI_TEST_CHECK( image );
101 int UtcDaliImageNewWithPolicies01(void)
103 TestApplication application;
105 // testing delayed loading
106 tet_infoline("UtcDaliImageNewWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
107 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
108 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never);
110 DALI_TEST_CHECK( image );
112 application.SendNotification();
113 application.Render(16);
115 // request file loading only when actor added to stage
116 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
118 ImageActor actor = ImageActor::New(image);
120 Stage::GetCurrent().Add(actor);
122 application.SendNotification();
123 application.Render(16);
125 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
127 // testing ReleasePolicy::Never
128 // fake loading image
129 std::vector<GLuint> ids;
131 application.GetGlAbstraction().SetNextTextureIds( ids );
132 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
133 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
134 Integration::ResourcePointer resource(bitmap);
135 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
139 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
141 application.Render(16);
142 application.SendNotification();
144 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
146 // never discard texture
147 Stage::GetCurrent().Remove(actor);
148 application.Render(16);
149 application.SendNotification();
150 application.Render(16);
151 application.SendNotification();
152 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
157 int UtcDaliImageNewWithPolicies02(void)
159 TestApplication application;
161 // testing resource deletion when taken off stage
162 tet_infoline("UtcDaliImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
164 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Unused);
166 DALI_TEST_CHECK( image );
168 application.SendNotification();
169 application.Render(16);
171 // request file loading only when actor added to stage
172 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
174 ImageActor actor = ImageActor::New(image);
176 Stage::GetCurrent().Add(actor);
178 application.SendNotification();
179 application.Render(16);
181 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
183 // testing ReleasePolicy::Unused
184 // fake loading image
185 std::vector<GLuint> ids;
187 application.GetGlAbstraction().SetNextTextureIds( ids );
188 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
189 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
190 Integration::ResourcePointer resource(bitmap);
191 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
195 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
197 application.Render(16);
198 application.SendNotification();
200 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
202 // discard texture when actor comes off stage
203 Stage::GetCurrent().Remove(actor);
204 application.Render(16);
205 application.SendNotification();
206 application.Render(16);
207 application.SendNotification();
208 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
213 int UtcDaliImageNewWithPolicies03(void)
215 TestApplication application;
217 // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
218 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
220 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused);
222 DALI_TEST_CHECK( image );
224 application.SendNotification();
225 application.Render(16);
227 // request file loading immediately
228 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
230 ImageActor actor = ImageActor::New(image);
232 Stage::GetCurrent().Add(actor);
234 application.SendNotification();
235 application.Render(16);
237 // testing ReleasePolicy::Unused
238 // fake loading image
239 std::vector<GLuint> ids;
241 application.GetGlAbstraction().SetNextTextureIds( ids );
242 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
243 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
244 Integration::ResourcePointer resource(bitmap);
245 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
249 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
251 application.Render(16);
252 application.SendNotification();
254 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
256 // discard texture when actor comes off stage
257 Stage::GetCurrent().Remove(actor);
258 application.Render(16);
259 application.SendNotification();
260 application.Render(16);
261 application.SendNotification();
262 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
264 // check load request when actor added back to stage
265 application.GetPlatform().ResetTrace();
267 Stage::GetCurrent().Add(actor);
269 application.SendNotification();
270 application.Render(16);
271 application.SendNotification();
272 application.Render(16);
274 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
279 int UtcDaliImageNewWithPolicies04(void)
281 TestApplication application;
283 // load immediately, don't release texture when off stage
284 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
286 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Never);
288 DALI_TEST_CHECK( image );
290 application.SendNotification();
291 application.Render(16);
293 // request file loading immediately
294 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
296 ImageActor actor = ImageActor::New(image);
298 Stage::GetCurrent().Add(actor);
300 application.SendNotification();
301 application.Render(16);
303 // testing ReleasePolicy::Never
304 // fake loading image
305 std::vector<GLuint> ids;
307 application.GetGlAbstraction().SetNextTextureIds( ids );
308 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
309 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
310 Integration::ResourcePointer resource(bitmap);
311 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
315 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
317 application.Render(16);
318 application.SendNotification();
320 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
322 // texture is not discarded
323 Stage::GetCurrent().Remove(actor);
324 application.Render(16);
325 application.SendNotification();
326 application.Render(16);
327 application.SendNotification();
328 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
330 // no load request when actor added back to stage
331 application.GetPlatform().ResetTrace();
333 Stage::GetCurrent().Add(actor);
335 application.SendNotification();
336 application.Render(16);
337 application.SendNotification();
338 application.Render(16);
340 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
345 int UtcDaliImageNewDistanceField(void)
347 TestApplication application;
349 tet_infoline("UtcDaliImageNewDistanceField - Image::NewDistanceField(const std::string&)");
351 // invoke default handle constructor
354 DALI_TEST_CHECK( !image );
357 image = Image::NewDistanceField(gTestImageFilename);
359 DALI_TEST_CHECK( image );
364 int UtcDaliImageNewDistanceFieldWithPolicies01(void)
366 TestApplication application;
368 // testing delayed loading
369 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
370 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
371 Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Never);
373 DALI_TEST_CHECK( image );
375 application.SendNotification();
376 application.Render(16);
378 // request file loading only when actor added to stage
379 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
381 ImageActor actor = ImageActor::New(image);
383 Stage::GetCurrent().Add(actor);
385 application.SendNotification();
386 application.Render(16);
388 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
390 // testing ReleasePolicy::Never
391 // fake loading image
392 std::vector<GLuint> ids;
394 application.GetGlAbstraction().SetNextTextureIds( ids );
395 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
396 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
397 Integration::ResourcePointer resource(bitmap);
398 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
402 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
404 application.Render(16);
405 application.SendNotification();
407 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
409 // never discard texture
410 Stage::GetCurrent().Remove(actor);
411 application.Render(16);
412 application.SendNotification();
413 application.Render(16);
414 application.SendNotification();
415 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
420 int UtcDaliImageNewDistanceFieldWithPolicies02(void)
422 TestApplication application;
424 // testing resource deletion when taken off stage
425 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
427 Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Unused);
429 DALI_TEST_CHECK( image );
431 application.SendNotification();
432 application.Render(16);
434 // request file loading only when actor added to stage
435 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
437 ImageActor actor = ImageActor::New(image);
439 Stage::GetCurrent().Add(actor);
441 application.SendNotification();
442 application.Render(16);
444 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
446 // testing ReleasePolicy::Unused
447 // fake loading image
448 std::vector<GLuint> ids;
450 application.GetGlAbstraction().SetNextTextureIds( ids );
451 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
452 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
453 Integration::ResourcePointer resource(bitmap);
454 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
458 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
460 application.Render(16);
461 application.SendNotification();
463 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
465 // discard texture when actor comes off stage
466 Stage::GetCurrent().Remove(actor);
467 application.Render(16);
468 application.SendNotification();
469 application.Render(16);
470 application.SendNotification();
471 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
476 int UtcDaliImageNewDistanceFieldWithPolicies03(void)
478 TestApplication application;
480 // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
481 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
483 Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Unused);
485 DALI_TEST_CHECK( image );
487 application.SendNotification();
488 application.Render(16);
490 // request file loading immediately
491 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
493 ImageActor actor = ImageActor::New(image);
495 Stage::GetCurrent().Add(actor);
497 application.SendNotification();
498 application.Render(16);
500 // testing ReleasePolicy::Unused
501 // fake loading image
502 std::vector<GLuint> ids;
504 application.GetGlAbstraction().SetNextTextureIds( ids );
505 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
506 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
507 Integration::ResourcePointer resource(bitmap);
508 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
512 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
514 application.Render(16);
515 application.SendNotification();
517 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
519 // discard texture when actor comes off stage
520 Stage::GetCurrent().Remove(actor);
521 application.Render(16);
522 application.SendNotification();
523 application.Render(16);
524 application.SendNotification();
525 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
527 // check load request when actor added back to stage
528 application.GetPlatform().ResetTrace();
530 Stage::GetCurrent().Add(actor);
532 application.SendNotification();
533 application.Render(16);
534 application.SendNotification();
535 application.Render(16);
537 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
542 int UtcDaliImageNewDistanceFieldWithPolicies04(void)
544 TestApplication application;
546 // load immediately, don't release texture when off stage
547 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies04 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
549 Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Never);
551 DALI_TEST_CHECK( image );
553 application.SendNotification();
554 application.Render(16);
556 // request file loading immediately
557 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
559 ImageActor actor = ImageActor::New(image);
561 Stage::GetCurrent().Add(actor);
563 application.SendNotification();
564 application.Render(16);
566 // testing ReleasePolicy::Never
567 // fake loading image
568 std::vector<GLuint> ids;
570 application.GetGlAbstraction().SetNextTextureIds( ids );
571 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
572 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
573 Integration::ResourcePointer resource(bitmap);
574 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
578 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
580 application.Render(16);
581 application.SendNotification();
583 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
585 // texture is not discarded
586 Stage::GetCurrent().Remove(actor);
587 application.Render(16);
588 application.SendNotification();
589 application.Render(16);
590 application.SendNotification();
591 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
593 // no load request when actor added back to stage
594 application.GetPlatform().ResetTrace();
596 Stage::GetCurrent().Add(actor);
598 application.SendNotification();
599 application.Render(16);
600 application.SendNotification();
601 application.Render(16);
603 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
608 int UtcDaliImageNewDistanceFieldWithAttributes(void)
610 TestApplication application;
612 tet_infoline("UtcDaliImageNewDistanceFieldWithAttributes - Image::NewDistanceField(const std::string&, const ImageAttributes& attributes)");
614 // invoke default handle constructor
616 Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12);
618 DALI_TEST_CHECK( !image );
621 image = Image::NewDistanceField(gTestImageFilename, imageAttributes);
623 DALI_TEST_CHECK( image );
628 int UtcDaliImageNewDistanceFieldWithAttrandPol(void)
630 TestApplication application;
632 tet_infoline("UtcDaliImageNewDistanceFieldWithAttrandPol - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
634 Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12);
636 Image image = Image::NewDistanceField(gTestImageFilename, imageAttributes, Image::OnDemand, Image::Unused);
638 DALI_TEST_CHECK( image );
640 application.SendNotification();
641 application.Render(16);
643 // request file loading only when actor added to stage
644 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
646 ImageActor actor = ImageActor::New(image);
648 Stage::GetCurrent().Add(actor);
650 application.SendNotification();
651 application.Render(16);
653 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
655 // testing ReleasePolicy::Unused
656 // fake loading image
657 std::vector<GLuint> ids;
659 application.GetGlAbstraction().SetNextTextureIds( ids );
660 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
661 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
662 Integration::ResourcePointer resource(bitmap);
663 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
667 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
669 application.Render(16);
670 application.SendNotification();
672 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
674 // discard texture when actor comes off stage
675 Stage::GetCurrent().Remove(actor);
676 application.Render(16);
677 application.SendNotification();
678 application.Render(16);
679 application.SendNotification();
680 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
685 int UtcDaliImageDownCast(void)
687 TestApplication application;
688 tet_infoline("Testing Dali::Image::DownCast()");
690 Image image = Image::New(gTestImageFilename);
692 BaseHandle object(image);
694 Image image2 = Image::DownCast(object);
695 DALI_TEST_CHECK(image2);
697 Image image3 = DownCast< Image >(object);
698 DALI_TEST_CHECK(image3);
700 BaseHandle unInitializedObject;
701 Image image4 = Image::DownCast(unInitializedObject);
702 DALI_TEST_CHECK(!image4);
704 Image image5 = DownCast< Image >(unInitializedObject);
705 DALI_TEST_CHECK(!image5);
710 int UtcDaliImageGetImageSize(void)
712 TestApplication application;
713 TestPlatformAbstraction& platform = application.GetPlatform();
715 tet_infoline("UtcDaliImageGetImageSize - Image::GetImageSize()");
717 Vector2 testSize(8.0f, 16.0f);
718 platform.SetClosestImageSize(testSize);
720 Vector2 size = Image::GetImageSize(gTestImageFilename);
722 DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
723 DALI_TEST_EQUALS( size, testSize, TEST_LOCATION);
728 int UtcDaliImageGetFilename(void)
730 TestApplication application;
732 tet_infoline("UtcDaliImageGetFilename");
734 // invoke default handle constructor
737 DALI_TEST_CHECK( !image );
740 image = Image::New(gTestImageFilename);
742 DALI_TEST_EQUALS( image.GetFilename(), gTestImageFilename, TEST_LOCATION);
747 int UtcDaliImageGetLoadingState01(void)
749 TestApplication application;
750 tet_infoline("UtcDaliImageGetLoadingState01");
752 Image image = Image::New(gTestImageFilename);
753 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
754 application.SendNotification();
755 application.Render(16);
757 // simulate load success
758 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
759 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
760 Integration::ResourcePointer resource(bitmap);
761 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
765 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
767 application.Render(16);
768 application.SendNotification();
770 // Test state == ResourceLoadingSucceeded
771 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
776 int UtcDaliImageGetLoadingState02(void)
778 TestApplication application;
780 tet_infoline("UtcDaliImageGetLoadingState02");
782 // invoke default handle constructor
785 DALI_TEST_CHECK( !image );
788 image = Image::New(gTestImageFilename);
790 // Test state == ResourceLoading
791 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
792 application.SendNotification();
793 application.Render(16);
795 // simulate load failure
796 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
799 application.GetPlatform().SetResourceLoadFailed(request->GetId(), Integration::FailureUnknown);
801 application.Render(16);
802 application.SendNotification();
804 // Test state == ResourceLoadingFailed
805 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
810 int UtcDaliImageGetReleasePolicy(void)
812 TestApplication application;
814 tet_infoline("UtcDaliImageGetReleasePolicy");
816 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused);
818 DALI_TEST_CHECK( image );
820 DALI_TEST_CHECK( Image::Unused == image.GetReleasePolicy() );
826 int UtcDaliImageGetLoadPolicy(void)
828 TestApplication application;
830 tet_infoline("UtcDaliImageGetLoadPolicy");
832 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never);
834 DALI_TEST_CHECK( image );
836 DALI_TEST_CHECK( Image::OnDemand == image.GetLoadPolicy());
840 static bool SignalLoadFlag = false;
842 static void SignalLoadHandler(Image image)
844 tet_infoline("Received image load finished signal");
846 SignalLoadFlag = true;
849 static bool SignalUploadedFlag = false;
851 static void SignalUploadedHandler(Image image)
853 tet_infoline("Received image uploaded signal");
855 SignalUploadedFlag = true;
859 int UtcDaliImageSignalLoadingFinished(void)
861 TestApplication application;
863 tet_infoline("UtcDaliImageSignalLoadingFinished");
865 SignalLoadFlag = false;
867 Image image = Image::New(gTestImageFilename);
869 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
870 application.SendNotification();
871 application.Render(16);
873 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
876 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true)));
879 application.Render(16);
880 application.SendNotification();
882 DALI_TEST_CHECK( SignalLoadFlag == true );
887 int UtcDaliImageSignalUploaded(void)
889 TestApplication application;
890 tet_infoline("UtcDaliImageSignalUploaded - Image::SignalUploaded()");
892 // set up image in fake platform abstraction
893 Vector2 testSize(80.0f, 80.0f);
894 application.GetPlatform().SetClosestImageSize(testSize);
896 Image image = Image::New(gTestImageFilename);
897 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
900 application.SendNotification();
901 application.Render(16);
902 std::vector<GLuint> ids;
904 application.GetGlAbstraction().SetNextTextureIds( ids );
905 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
906 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
907 Integration::ResourcePointer resource(bitmap);
908 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
911 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
913 application.Render(16);
914 application.SendNotification();
916 image.UploadedSignal().Connect( SignalUploadedHandler );
918 Dali::ImageActor imageActor = ImageActor::New(image);
919 Stage::GetCurrent().Add(imageActor);
920 imageActor.SetSize(80, 80);
921 imageActor.SetVisible(true);
923 application.SendNotification();
924 application.Render(0);
925 application.Render(16);
926 application.SendNotification();
927 application.Render(16);
928 application.SendNotification();
929 application.Render(16);
930 application.SendNotification();
931 application.Render(16);
932 application.SendNotification();
934 DALI_TEST_CHECK( SignalLoadFlag == true );
935 DALI_TEST_CHECK( SignalUploadedFlag == true );
936 SignalLoadFlag = false;
937 SignalUploadedFlag = false;
940 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 160, 160, 160, 160);
942 application.SendNotification();
943 application.Render(16);
944 application.Render(16);
945 application.SendNotification();
946 DALI_TEST_CHECK( SignalLoadFlag == true );
948 application.Render(16);
949 application.SendNotification();
950 application.Render(16);
951 application.SendNotification();
952 DALI_TEST_CHECK( SignalUploadedFlag == true );
958 int UtcDaliImageDiscard01(void)
960 TestApplication application;
961 tet_infoline("UtcDaliImageDiscard01 - no actors");
964 Image image = Image::New(gTestImageFilename);
967 application.SendNotification();
968 application.Render(16);
969 std::vector<GLuint> ids;
971 application.GetGlAbstraction().SetNextTextureIds( ids );
972 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
973 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
974 Integration::ResourcePointer resource(bitmap);
975 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
978 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
980 application.Render(16);
981 application.SendNotification();
982 } // Drop image handle
984 application.SendNotification();
985 application.Render(16);
986 application.Render(16);
987 application.SendNotification();
989 // Shouldn't have been sent to GL...
990 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
991 DALI_TEST_CHECK( texIds.size() == 1 );
992 DALI_TEST_CHECK( texIds[0] == 23 );
997 int UtcDaliImageDiscard02(void)
999 TestApplication application;
1000 tet_infoline("UtcDaliImageDiscard02 - one actor, tests TextureCache::DiscardTexture");
1006 Image image = Image::New(gTestImageFilename);
1007 actor = ImageActor::New(image);
1008 Stage::GetCurrent().Add(actor);
1010 application.SendNotification();
1011 application.Render(16);
1013 std::vector<GLuint> ids;
1014 ids.push_back( 23 );
1015 application.GetGlAbstraction().SetNextTextureIds( ids );
1017 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
1018 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
1019 Integration::ResourcePointer resource(bitmap);
1020 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
1023 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
1025 application.Render(16);
1026 application.SendNotification();
1027 } // lose image handle, actor should still keep one
1028 application.SendNotification();
1029 application.Render(16);
1031 Stage::GetCurrent().Remove(actor);
1032 application.SendNotification();
1033 application.Render(16);
1035 application.SendNotification();
1036 application.Render(16);
1040 application.SendNotification();
1041 application.Render(16);
1042 application.Render(16);
1043 application.SendNotification();
1045 // texture should have been removed:
1046 DALI_TEST_CHECK( application.GetGlAbstraction().CheckTextureDeleted( 23 ));
1051 int UtcDaliImageDiscard03(void)
1053 TestApplication application;
1054 tet_infoline("UtcDaliImageDiscard03 - one actor, tests TextureCache::RemoveObserver");
1056 Image image = Image::New(gTestImageFilename);
1057 ImageActor actor = ImageActor::New(image);
1058 Stage::GetCurrent().Add(actor);
1060 application.SendNotification();
1061 application.Render(16);
1063 std::vector<GLuint> ids;
1064 ids.push_back( 23 );
1065 application.GetGlAbstraction().SetNextTextureIds( ids );
1067 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
1068 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
1069 Integration::ResourcePointer resource(bitmap);
1070 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
1073 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
1075 application.Render(16);
1076 application.SendNotification();
1077 application.SendNotification();
1078 application.Render(16);
1080 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
1081 DALI_TEST_CHECK( texIds.size() == 0 );
1082 const std::vector<GLuint>& boundTexIds = application.GetGlAbstraction().GetBoundTextures();
1083 DALI_TEST_CHECK( boundTexIds[0] == 23 );
1085 Stage::GetCurrent().Remove(actor);
1086 application.SendNotification();
1087 application.Render(16);
1088 application.SendNotification();
1089 application.Render(16);
1090 application.SendNotification();
1091 application.Render(16); // Should remove image renderer