2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
27 void utc_dali_image_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_image_cleanup(void)
34 test_return_value = TET_PASS;
37 static const char* gTestImageFilename = "icon_wrt.png";
41 int UtcDaliImageNew01(void)
43 TestApplication application;
45 tet_infoline("UtcDaliImageNew01 - Image::New(const std::string&)");
47 // invoke default handle constructor
50 DALI_TEST_CHECK( !image );
53 image = Image::New(gTestImageFilename);
55 DALI_TEST_CHECK( image );
60 int UtcDaliImageNew02(void)
62 TestApplication application;
64 tet_infoline("UtcDaliImageNew02 - Image::New(const std::string&, const ImageAttributes&)");
66 // invoke default handle constructor
69 DALI_TEST_CHECK( !image );
72 Dali::ImageAttributes imageAttributes;
73 imageAttributes.SetSize(128, 256);
74 imageAttributes.SetScalingMode(Dali::ImageAttributes::FitHeight);
75 image = Image::New(gTestImageFilename, imageAttributes);
77 DALI_TEST_CHECK( image );
82 int UtcDaliImageNew03(void)
84 TestApplication application;
86 tet_infoline("UtcDaliImageNew03 - Image::New(NativeImage&)");
88 // invoke default handle constructor
90 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
92 DALI_TEST_CHECK( !image );
95 image = Image::New(*(nativeImage.Get()));
97 DALI_TEST_CHECK( image );
102 int UtcDaliImageNewWithPolicies01(void)
104 TestApplication application;
106 // testing delayed loading
107 tet_infoline("UtcDaliImageNewWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
108 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
109 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never);
111 DALI_TEST_CHECK( image );
113 application.SendNotification();
114 application.Render(16);
116 // request file loading only when actor added to stage
117 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
119 ImageActor actor = ImageActor::New(image);
121 Stage::GetCurrent().Add(actor);
123 application.SendNotification();
124 application.Render(16);
126 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
128 // testing ReleasePolicy::Never
129 // fake loading image
130 std::vector<GLuint> ids;
132 application.GetGlAbstraction().SetNextTextureIds( ids );
133 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
134 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
135 Integration::ResourcePointer resource(bitmap);
136 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
140 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
142 application.Render(16);
143 application.SendNotification();
145 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
147 // never discard texture
148 Stage::GetCurrent().Remove(actor);
149 application.Render(16);
150 application.SendNotification();
151 application.Render(16);
152 application.SendNotification();
153 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
158 int UtcDaliImageNewWithPolicies02(void)
160 TestApplication application;
162 // testing resource deletion when taken off stage
163 tet_infoline("UtcDaliImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
165 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Unused);
167 DALI_TEST_CHECK( image );
169 application.SendNotification();
170 application.Render(16);
172 // request file loading only when actor added to stage
173 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
175 ImageActor actor = ImageActor::New(image);
177 Stage::GetCurrent().Add(actor);
179 application.SendNotification();
180 application.Render(16);
182 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
184 // testing ReleasePolicy::Unused
185 // fake loading image
186 std::vector<GLuint> ids;
188 application.GetGlAbstraction().SetNextTextureIds( ids );
189 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
190 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
191 Integration::ResourcePointer resource(bitmap);
192 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
196 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
198 application.Render(16);
199 application.SendNotification();
201 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
203 // discard texture when actor comes off stage
204 Stage::GetCurrent().Remove(actor);
205 application.Render(16);
206 application.SendNotification();
207 application.Render(16);
208 application.SendNotification();
209 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
214 int UtcDaliImageNewWithPolicies03(void)
216 TestApplication application;
218 // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
219 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
221 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused);
223 DALI_TEST_CHECK( image );
225 application.SendNotification();
226 application.Render(16);
228 // request file loading immediately
229 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
231 ImageActor actor = ImageActor::New(image);
233 Stage::GetCurrent().Add(actor);
235 application.SendNotification();
236 application.Render(16);
238 // testing ReleasePolicy::Unused
239 // fake loading image
240 std::vector<GLuint> ids;
242 application.GetGlAbstraction().SetNextTextureIds( ids );
243 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
244 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
245 Integration::ResourcePointer resource(bitmap);
246 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
250 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
252 application.Render(16);
253 application.SendNotification();
255 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
257 // discard texture when actor comes off stage
258 Stage::GetCurrent().Remove(actor);
259 application.Render(16);
260 application.SendNotification();
261 application.Render(16);
262 application.SendNotification();
263 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
265 // check load request when actor added back to stage
266 application.GetPlatform().ResetTrace();
268 Stage::GetCurrent().Add(actor);
270 application.SendNotification();
271 application.Render(16);
272 application.SendNotification();
273 application.Render(16);
275 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
280 int UtcDaliImageNewWithPolicies04(void)
282 TestApplication application;
284 // load immediately, don't release texture when off stage
285 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
287 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Never);
289 DALI_TEST_CHECK( image );
291 application.SendNotification();
292 application.Render(16);
294 // request file loading immediately
295 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
297 ImageActor actor = ImageActor::New(image);
299 Stage::GetCurrent().Add(actor);
301 application.SendNotification();
302 application.Render(16);
304 // testing ReleasePolicy::Never
305 // fake loading image
306 std::vector<GLuint> ids;
308 application.GetGlAbstraction().SetNextTextureIds( ids );
309 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
310 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
311 Integration::ResourcePointer resource(bitmap);
312 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
316 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
318 application.Render(16);
319 application.SendNotification();
321 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
323 // texture is not discarded
324 Stage::GetCurrent().Remove(actor);
325 application.Render(16);
326 application.SendNotification();
327 application.Render(16);
328 application.SendNotification();
329 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
331 // no load request when actor added back to stage
332 application.GetPlatform().ResetTrace();
334 Stage::GetCurrent().Add(actor);
336 application.SendNotification();
337 application.Render(16);
338 application.SendNotification();
339 application.Render(16);
341 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
346 int UtcDaliImageNewDistanceField(void)
348 TestApplication application;
350 tet_infoline("UtcDaliImageNewDistanceField - Image::NewDistanceField(const std::string&)");
352 // invoke default handle constructor
355 DALI_TEST_CHECK( !image );
358 image = Image::NewDistanceField(gTestImageFilename);
360 DALI_TEST_CHECK( image );
365 int UtcDaliImageNewDistanceFieldWithPolicies01(void)
367 TestApplication application;
369 // testing delayed loading
370 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
371 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
372 Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Never);
374 DALI_TEST_CHECK( image );
376 application.SendNotification();
377 application.Render(16);
379 // request file loading only when actor added to stage
380 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
382 ImageActor actor = ImageActor::New(image);
384 Stage::GetCurrent().Add(actor);
386 application.SendNotification();
387 application.Render(16);
389 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
391 // testing ReleasePolicy::Never
392 // fake loading image
393 std::vector<GLuint> ids;
395 application.GetGlAbstraction().SetNextTextureIds( ids );
396 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
397 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
398 Integration::ResourcePointer resource(bitmap);
399 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
403 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
405 application.Render(16);
406 application.SendNotification();
408 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
410 // never discard texture
411 Stage::GetCurrent().Remove(actor);
412 application.Render(16);
413 application.SendNotification();
414 application.Render(16);
415 application.SendNotification();
416 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
421 int UtcDaliImageNewDistanceFieldWithPolicies02(void)
423 TestApplication application;
425 // testing resource deletion when taken off stage
426 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
428 Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Unused);
430 DALI_TEST_CHECK( image );
432 application.SendNotification();
433 application.Render(16);
435 // request file loading only when actor added to stage
436 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
438 ImageActor actor = ImageActor::New(image);
440 Stage::GetCurrent().Add(actor);
442 application.SendNotification();
443 application.Render(16);
445 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
447 // testing ReleasePolicy::Unused
448 // fake loading image
449 std::vector<GLuint> ids;
451 application.GetGlAbstraction().SetNextTextureIds( ids );
452 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
453 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
454 Integration::ResourcePointer resource(bitmap);
455 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
459 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
461 application.Render(16);
462 application.SendNotification();
464 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
466 // discard texture when actor comes off stage
467 Stage::GetCurrent().Remove(actor);
468 application.Render(16);
469 application.SendNotification();
470 application.Render(16);
471 application.SendNotification();
472 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
477 int UtcDaliImageNewDistanceFieldWithPolicies03(void)
479 TestApplication application;
481 // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
482 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
484 Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Unused);
486 DALI_TEST_CHECK( image );
488 application.SendNotification();
489 application.Render(16);
491 // request file loading immediately
492 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
494 ImageActor actor = ImageActor::New(image);
496 Stage::GetCurrent().Add(actor);
498 application.SendNotification();
499 application.Render(16);
501 // testing ReleasePolicy::Unused
502 // fake loading image
503 std::vector<GLuint> ids;
505 application.GetGlAbstraction().SetNextTextureIds( ids );
506 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
507 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
508 Integration::ResourcePointer resource(bitmap);
509 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
513 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
515 application.Render(16);
516 application.SendNotification();
518 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
520 // discard texture when actor comes off stage
521 Stage::GetCurrent().Remove(actor);
522 application.Render(16);
523 application.SendNotification();
524 application.Render(16);
525 application.SendNotification();
526 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
528 // check load request when actor added back to stage
529 application.GetPlatform().ResetTrace();
531 Stage::GetCurrent().Add(actor);
533 application.SendNotification();
534 application.Render(16);
535 application.SendNotification();
536 application.Render(16);
538 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
543 int UtcDaliImageNewDistanceFieldWithPolicies04(void)
545 TestApplication application;
547 // load immediately, don't release texture when off stage
548 tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies04 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
550 Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Never);
552 DALI_TEST_CHECK( image );
554 application.SendNotification();
555 application.Render(16);
557 // request file loading immediately
558 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
560 ImageActor actor = ImageActor::New(image);
562 Stage::GetCurrent().Add(actor);
564 application.SendNotification();
565 application.Render(16);
567 // testing ReleasePolicy::Never
568 // fake loading image
569 std::vector<GLuint> ids;
571 application.GetGlAbstraction().SetNextTextureIds( ids );
572 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
573 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
574 Integration::ResourcePointer resource(bitmap);
575 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
579 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
581 application.Render(16);
582 application.SendNotification();
584 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
586 // texture is not discarded
587 Stage::GetCurrent().Remove(actor);
588 application.Render(16);
589 application.SendNotification();
590 application.Render(16);
591 application.SendNotification();
592 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
594 // no load request when actor added back to stage
595 application.GetPlatform().ResetTrace();
597 Stage::GetCurrent().Add(actor);
599 application.SendNotification();
600 application.Render(16);
601 application.SendNotification();
602 application.Render(16);
604 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
609 int UtcDaliImageNewDistanceFieldWithAttributes(void)
611 TestApplication application;
613 tet_infoline("UtcDaliImageNewDistanceFieldWithAttributes - Image::NewDistanceField(const std::string&, const ImageAttributes& attributes)");
615 // invoke default handle constructor
617 Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12);
619 DALI_TEST_CHECK( !image );
622 image = Image::NewDistanceField(gTestImageFilename, imageAttributes);
624 DALI_TEST_CHECK( image );
629 int UtcDaliImageNewDistanceFieldWithAttrandPol(void)
631 TestApplication application;
633 tet_infoline("UtcDaliImageNewDistanceFieldWithAttrandPol - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
635 Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12);
637 Image image = Image::NewDistanceField(gTestImageFilename, imageAttributes, Image::OnDemand, Image::Unused);
639 DALI_TEST_CHECK( image );
641 application.SendNotification();
642 application.Render(16);
644 // request file loading only when actor added to stage
645 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
647 ImageActor actor = ImageActor::New(image);
649 Stage::GetCurrent().Add(actor);
651 application.SendNotification();
652 application.Render(16);
654 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
656 // testing ReleasePolicy::Unused
657 // fake loading image
658 std::vector<GLuint> ids;
660 application.GetGlAbstraction().SetNextTextureIds( ids );
661 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
662 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
663 Integration::ResourcePointer resource(bitmap);
664 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
668 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
670 application.Render(16);
671 application.SendNotification();
673 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
675 // discard texture when actor comes off stage
676 Stage::GetCurrent().Remove(actor);
677 application.Render(16);
678 application.SendNotification();
679 application.Render(16);
680 application.SendNotification();
681 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
686 int UtcDaliImageDownCast(void)
688 TestApplication application;
689 tet_infoline("Testing Dali::Image::DownCast()");
691 Image image = Image::New(gTestImageFilename);
693 BaseHandle object(image);
695 Image image2 = Image::DownCast(object);
696 DALI_TEST_CHECK(image2);
698 Image image3 = DownCast< Image >(object);
699 DALI_TEST_CHECK(image3);
701 BaseHandle unInitializedObject;
702 Image image4 = Image::DownCast(unInitializedObject);
703 DALI_TEST_CHECK(!image4);
705 Image image5 = DownCast< Image >(unInitializedObject);
706 DALI_TEST_CHECK(!image5);
711 int UtcDaliImageGetImageSize(void)
713 TestApplication application;
714 TestPlatformAbstraction& platform = application.GetPlatform();
716 tet_infoline("UtcDaliImageGetImageSize - Image::GetImageSize()");
718 Vector2 testSize(8.0f, 16.0f);
719 platform.SetClosestImageSize(testSize);
721 Vector2 size = Image::GetImageSize(gTestImageFilename);
723 DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
724 DALI_TEST_EQUALS( size, testSize, TEST_LOCATION);
729 int UtcDaliImageGetFilename(void)
731 TestApplication application;
733 tet_infoline("UtcDaliImageGetFilename");
735 // invoke default handle constructor
738 DALI_TEST_CHECK( !image );
741 image = Image::New(gTestImageFilename);
743 DALI_TEST_EQUALS( image.GetFilename(), gTestImageFilename, TEST_LOCATION);
748 int UtcDaliImageGetLoadingState01(void)
750 TestApplication application;
751 tet_infoline("UtcDaliImageGetLoadingState01");
753 Image image = Image::New(gTestImageFilename);
754 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
755 application.SendNotification();
756 application.Render(16);
758 // simulate load success
759 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
760 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
761 Integration::ResourcePointer resource(bitmap);
762 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
766 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
768 application.Render(16);
769 application.SendNotification();
771 // Test state == ResourceLoadingSucceeded
772 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
777 int UtcDaliImageGetLoadingState02(void)
779 TestApplication application;
781 tet_infoline("UtcDaliImageGetLoadingState02");
783 // invoke default handle constructor
786 DALI_TEST_CHECK( !image );
789 image = Image::New(gTestImageFilename);
791 // Test state == ResourceLoading
792 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
793 application.SendNotification();
794 application.Render(16);
796 // simulate load failure
797 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
800 application.GetPlatform().SetResourceLoadFailed(request->GetId(), Integration::FailureUnknown);
802 application.Render(16);
803 application.SendNotification();
805 // Test state == ResourceLoadingFailed
806 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
811 int UtcDaliImageGetReleasePolicy(void)
813 TestApplication application;
815 tet_infoline("UtcDaliImageGetReleasePolicy");
817 Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused);
819 DALI_TEST_CHECK( image );
821 DALI_TEST_CHECK( Image::Unused == image.GetReleasePolicy() );
827 int UtcDaliImageGetLoadPolicy(void)
829 TestApplication application;
831 tet_infoline("UtcDaliImageGetLoadPolicy");
833 Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never);
835 DALI_TEST_CHECK( image );
837 DALI_TEST_CHECK( Image::OnDemand == image.GetLoadPolicy());
841 static bool SignalLoadFlag = false;
843 static void SignalLoadHandler(Image image)
845 tet_infoline("Received image load finished signal");
847 SignalLoadFlag = true;
850 static bool SignalUploadedFlag = false;
852 static void SignalUploadedHandler(Image image)
854 tet_infoline("Received image uploaded signal");
856 SignalUploadedFlag = true;
860 int UtcDaliImageSignalLoadingFinished(void)
862 TestApplication application;
864 tet_infoline("UtcDaliImageSignalLoadingFinished");
866 SignalLoadFlag = false;
868 Image image = Image::New(gTestImageFilename);
870 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
871 application.SendNotification();
872 application.Render(16);
874 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
877 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true)));
880 application.Render(16);
881 application.SendNotification();
883 DALI_TEST_CHECK( SignalLoadFlag == true );
888 int UtcDaliImageSignalUploaded(void)
890 TestApplication application;
891 tet_infoline("UtcDaliImageSignalUploaded - Image::SignalUploaded()");
893 // set up image in fake platform abstraction
894 Vector2 testSize(80.0f, 80.0f);
895 application.GetPlatform().SetClosestImageSize(testSize);
897 Image image = Image::New(gTestImageFilename);
898 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
901 application.SendNotification();
902 application.Render(16);
903 std::vector<GLuint> ids;
905 application.GetGlAbstraction().SetNextTextureIds( ids );
906 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
907 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
908 Integration::ResourcePointer resource(bitmap);
909 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
912 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
914 application.Render(16);
915 application.SendNotification();
917 image.UploadedSignal().Connect( SignalUploadedHandler );
919 Dali::ImageActor imageActor = ImageActor::New(image);
920 Stage::GetCurrent().Add(imageActor);
921 imageActor.SetSize(80, 80);
922 imageActor.SetVisible(true);
924 application.SendNotification();
925 application.Render(0);
926 application.Render(16);
927 application.SendNotification();
928 application.Render(16);
929 application.SendNotification();
930 application.Render(16);
931 application.SendNotification();
932 application.Render(16);
933 application.SendNotification();
935 DALI_TEST_CHECK( SignalLoadFlag == true );
936 DALI_TEST_CHECK( SignalUploadedFlag == true );
937 SignalLoadFlag = false;
938 SignalUploadedFlag = false;
941 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 160, 160, 160, 160);
943 application.SendNotification();
944 application.Render(16);
945 application.Render(16);
946 application.SendNotification();
947 DALI_TEST_CHECK( SignalLoadFlag == true );
949 application.Render(16);
950 application.SendNotification();
951 application.Render(16);
952 application.SendNotification();
953 DALI_TEST_CHECK( SignalUploadedFlag == true );
959 int UtcDaliImageDiscard01(void)
961 TestApplication application;
962 tet_infoline("UtcDaliImageDiscard01 - no actors");
965 Image image = Image::New(gTestImageFilename);
968 application.SendNotification();
969 application.Render(16);
970 std::vector<GLuint> ids;
972 application.GetGlAbstraction().SetNextTextureIds( ids );
973 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
974 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
975 Integration::ResourcePointer resource(bitmap);
976 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
979 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
981 application.Render(16);
982 application.SendNotification();
983 } // Drop image handle
985 application.SendNotification();
986 application.Render(16);
987 application.Render(16);
988 application.SendNotification();
990 // Shouldn't have been sent to GL...
991 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
992 DALI_TEST_CHECK( texIds.size() == 1 );
993 DALI_TEST_CHECK( texIds[0] == 23 );
998 int UtcDaliImageDiscard02(void)
1000 TestApplication application;
1001 tet_infoline("UtcDaliImageDiscard02 - one actor, tests TextureCache::DiscardTexture");
1007 Image image = Image::New(gTestImageFilename);
1008 actor = ImageActor::New(image);
1009 Stage::GetCurrent().Add(actor);
1011 application.SendNotification();
1012 application.Render(16);
1014 std::vector<GLuint> ids;
1015 ids.push_back( 23 );
1016 application.GetGlAbstraction().SetNextTextureIds( ids );
1018 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
1019 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
1020 Integration::ResourcePointer resource(bitmap);
1021 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
1024 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
1026 application.Render(16);
1027 application.SendNotification();
1028 } // lose image handle, actor should still keep one
1029 application.SendNotification();
1030 application.Render(16);
1032 Stage::GetCurrent().Remove(actor);
1033 application.SendNotification();
1034 application.Render(16);
1036 application.SendNotification();
1037 application.Render(16);
1041 application.SendNotification();
1042 application.Render(16);
1043 application.Render(16);
1044 application.SendNotification();
1046 // texture should have been removed:
1047 DALI_TEST_CHECK( application.GetGlAbstraction().CheckTextureDeleted( 23 ));
1052 int UtcDaliImageDiscard03(void)
1054 TestApplication application;
1055 tet_infoline("UtcDaliImageDiscard03 - one actor, tests TextureCache::RemoveObserver");
1057 Image image = Image::New(gTestImageFilename);
1058 ImageActor actor = ImageActor::New(image);
1059 Stage::GetCurrent().Add(actor);
1061 application.SendNotification();
1062 application.Render(16);
1064 std::vector<GLuint> ids;
1065 ids.push_back( 23 );
1066 application.GetGlAbstraction().SetNextTextureIds( ids );
1068 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
1069 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
1070 Integration::ResourcePointer resource(bitmap);
1071 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
1074 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
1076 application.Render(16);
1077 application.SendNotification();
1078 application.SendNotification();
1079 application.Render(16);
1081 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
1082 DALI_TEST_CHECK( texIds.size() == 0 );
1083 const std::vector<GLuint>& boundTexIds = application.GetGlAbstraction().GetBoundTextures();
1084 DALI_TEST_CHECK( boundTexIds[0] == 23 );
1086 Stage::GetCurrent().Remove(actor);
1087 application.SendNotification();
1088 application.Render(16);
1089 application.SendNotification();
1090 application.Render(16);
1091 application.SendNotification();
1092 application.Render(16); // Should remove image renderer