2 * Copyright (c) 2022 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/common/dali-vector.h>
20 #include <dali/public-api/images/pixel-data.h>
21 #include <dali/public-api/images/pixel.h>
27 int UtcDaliPixelData01(void)
29 TestApplication application;
31 unsigned int width = 10u;
32 unsigned int height = 10u;
33 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
35 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
36 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
38 DALI_TEST_CHECK(pixelData);
39 DALI_TEST_CHECK(pixelData.GetWidth() == width);
40 DALI_TEST_CHECK(pixelData.GetHeight() == height);
41 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
46 int UtcDaliPixelData02(void)
48 TestApplication application;
50 unsigned int width = 10u;
51 unsigned int height = 10u;
52 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
53 unsigned char* buffer = new unsigned char[bufferSize];
56 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
58 DALI_TEST_CHECK(pixelData);
59 DALI_TEST_CHECK(pixelData.GetWidth() == width);
60 DALI_TEST_CHECK(pixelData.GetHeight() == height);
61 DALI_TEST_CHECK(pixelData.GetStride() == 0);
62 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
67 int UtcDaliPixelData03(void)
69 TestApplication application;
72 uint32_t height = 10u;
73 uint32_t stride = 12u;
74 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
76 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
77 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE);
79 DALI_TEST_CHECK(pixelData);
80 DALI_TEST_CHECK(pixelData.GetWidth() == width);
81 DALI_TEST_CHECK(pixelData.GetHeight() == height);
82 DALI_TEST_CHECK(pixelData.GetStride() == stride);
83 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
88 int UtcDaliPixelData04(void)
90 TestApplication application;
93 uint32_t height = 10u;
94 uint32_t stride = 12u;
95 uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
96 uint8_t* buffer = new uint8_t[bufferSize];
99 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
101 DALI_TEST_CHECK(pixelData);
102 DALI_TEST_CHECK(pixelData.GetWidth() == width);
103 DALI_TEST_CHECK(pixelData.GetHeight() == height);
104 DALI_TEST_CHECK(pixelData.GetStride() == stride);
105 DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
110 int UtcDaliPixelDataCopyConstructor(void)
112 TestApplication application;
114 unsigned int width = 10u;
115 unsigned int height = 10u;
116 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
117 unsigned char* buffer = new unsigned char[bufferSize];
118 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
120 PixelData pixelDataCopy(pixelData);
122 DALI_TEST_EQUALS((bool)pixelDataCopy, true, TEST_LOCATION);
126 int UtcDaliPixelDataAssignmentOperator(void)
128 TestApplication application;
130 unsigned int width = 10u;
131 unsigned int height = 10u;
132 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
133 unsigned char* buffer = new unsigned char[bufferSize];
134 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
136 PixelData pixelData2;
137 DALI_TEST_EQUALS((bool)pixelData2, false, TEST_LOCATION);
139 pixelData2 = pixelData;
140 DALI_TEST_EQUALS((bool)pixelData2, true, TEST_LOCATION);
145 int UtcDaliPixelDataMoveConstructor(void)
147 TestApplication application;
149 unsigned int width = 10u;
150 unsigned int height = 10u;
151 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
152 unsigned char* buffer = new unsigned char[bufferSize];
154 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
155 DALI_TEST_CHECK(pixelData);
156 DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
157 DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
159 PixelData moved = std::move(pixelData);
160 DALI_TEST_CHECK(moved);
161 DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
162 DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
163 DALI_TEST_CHECK(!pixelData);
168 int UtcDaliPixelDataMoveAssignment(void)
170 TestApplication application;
172 unsigned int width = 10u;
173 unsigned int height = 10u;
174 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
175 unsigned char* buffer = new unsigned char[bufferSize];
177 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
178 DALI_TEST_CHECK(pixelData);
179 DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
180 DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
183 moved = std::move(pixelData);
184 DALI_TEST_CHECK(moved);
185 DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
186 DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
187 DALI_TEST_CHECK(!pixelData);
192 int UtcDaliPixelDataGetPixelFormatNegative(void)
194 TestApplication application;
195 Dali::PixelData instance;
198 instance.GetPixelFormat();
199 DALI_TEST_CHECK(false); // Should not get here
203 DALI_TEST_CHECK(true); // We expect an assert
208 int UtcDaliPixelDataGetWidthNegative(void)
210 TestApplication application;
211 Dali::PixelData instance;
215 DALI_TEST_CHECK(false); // Should not get here
219 DALI_TEST_CHECK(true); // We expect an assert
224 int UtcDaliPixelDataGetHeightNegative(void)
226 TestApplication application;
227 Dali::PixelData instance;
230 instance.GetHeight();
231 DALI_TEST_CHECK(false); // Should not get here
235 DALI_TEST_CHECK(true); // We expect an assert