2 * Copyright (c) 2016 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/integration-api/bitmap.h>
23 #include <dali-test-suite-utils.h>
24 #include <test-native-image.h>
28 void utc_dali_image_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_image_cleanup(void)
35 test_return_value = TET_PASS;
38 static const char* gTestImageFilename = "icon_wrt.png";
42 void LoadBitmapResource(TestPlatformAbstraction& platform)
44 Integration::ResourceRequest* request = platform.GetRequest();
45 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
46 Integration::ResourcePointer resource(bitmap);
47 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
51 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
57 int UtcDaliImageDownCast(void)
59 TestApplication application;
60 tet_infoline("Testing Dali::Image::DownCast()");
62 Image image = ResourceImage::New(gTestImageFilename);
64 BaseHandle object(image);
66 Image image2 = Image::DownCast(object);
67 DALI_TEST_CHECK(image2);
69 Image image3 = DownCast< Image >(object);
70 DALI_TEST_CHECK(image3);
72 BaseHandle unInitializedObject;
73 Image image4 = Image::DownCast(unInitializedObject);
74 DALI_TEST_CHECK(!image4);
76 Image image5 = DownCast< Image >(unInitializedObject);
77 DALI_TEST_CHECK(!image5);
81 int UtcDaliImageGetWidthHeight(void)
83 TestApplication application;
85 tet_infoline("UtcDaliImageGetWidthHeight - Image::GetWidth() & Image::GetHeight");
87 Vector2 testSize(8.0f, 16.0f);
88 application.GetPlatform().SetClosestImageSize(testSize);
89 PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
90 Image image1 = ResourceImage::New(gTestImageFilename);
91 DALI_TEST_EQUALS( image1.GetWidth(), testSize.x, TEST_LOCATION );
92 DALI_TEST_EQUALS( image1.GetHeight(), testSize.y, TEST_LOCATION );
94 testSize = Vector2(128.0f, 256.0f);
95 PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
96 Image image2 = ResourceImage::New( gTestImageFilename, ImageDimensions(testSize.x, testSize.y), FittingMode::SCALE_TO_FILL, SamplingMode::DEFAULT );
97 DALI_TEST_EQUALS( image2.GetWidth(), testSize.x, TEST_LOCATION );
98 DALI_TEST_EQUALS( image2.GetHeight(), testSize.y, TEST_LOCATION );
100 testSize = Vector2(16.0f, 32.0f);
101 Image image3 = FrameBufferImage::New(testSize.x, testSize.y);
102 DALI_TEST_EQUALS(image3.GetWidth(), testSize.x, TEST_LOCATION);
103 DALI_TEST_EQUALS(image3.GetHeight(), testSize.y, TEST_LOCATION);
105 testSize = Vector2(32.0f, 64.0f);
106 PrepareResourceImage( application, testSize.x, testSize.y, Pixel::RGBA8888 );
107 TestNativeImagePointer nativeImage = TestNativeImage::New(testSize.x, testSize.y);
108 Image image4 = NativeImage::New(*(nativeImage.Get()));
109 DALI_TEST_EQUALS(image4.GetWidth(), testSize.x, TEST_LOCATION);
110 DALI_TEST_EQUALS(image4.GetHeight(), testSize.y, TEST_LOCATION);
115 int UtcDaliImageDiscard01(void)
117 TestApplication application;
118 tet_infoline("UtcDaliImageDiscard01 - no actors");
121 Image image = ResourceImage::New(gTestImageFilename);
124 application.SendNotification();
125 application.Render(16);
126 std::vector<GLuint> ids;
128 application.GetGlAbstraction().SetNextTextureIds( ids );
129 TestPlatformAbstraction& platform = application.GetPlatform();
130 LoadBitmapResource( platform );
131 application.Render(16);
132 application.SendNotification();
133 } // Drop image handle
135 application.SendNotification();
136 application.Render(16);
137 application.Render(16);
138 application.SendNotification();
140 // Shouldn't have been sent to GL...
141 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
142 DALI_TEST_CHECK( texIds.size() == 1 );
143 DALI_TEST_CHECK( texIds[0] == 23 );