1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include "common_utils.h"
18
19 #include "image_source_native.h"
20 #include "image_source_native_impl.h"
21 #include "image_utils.h"
22 #include "pixelmap_native.h"
23 #include "securec.h"
24
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace Media {
28 class ImagSourceNdk2Test : public testing::Test {
29 public:
ImagSourceNdk2Test()30 ImagSourceNdk2Test() {}
~ImagSourceNdk2Test()31 ~ImagSourceNdk2Test() {}
32 };
33
34 static const std::string IMAGE_JPEG_PATH = "/data/local/tmp/image/test_picture.jpg";
35 static const std::string IMAGE_JPEG_HDR_PATH = "/data/local/tmp/image/test_jpeg_hdr.jpg";
36 static const std::string IMAGE_HEIF_PATH = "/data/local/tmp/image/test_allocator_heif.heic";
37 static const std::string IMAGE_HEIF_HDR_PATH = "/data/local/tmp/image/test_heif_hdr.heic";
38 static const int32_t MAX_BUFFER_SIZE = 256;
39 static const int32_t INVALID_INDEX = 1000;
40
CreateImageSourceNative(std::string IMAGE_PATH)41 static OH_ImageSourceNative *CreateImageSourceNative(std::string IMAGE_PATH)
42 {
43 std::string realPath;
44 if (!ImageUtils::PathToRealPath(IMAGE_PATH.c_str(), realPath) || realPath.empty()) {
45 return nullptr;
46 }
47 char filePath[MAX_BUFFER_SIZE];
48 if (strcpy_s(filePath, sizeof(filePath), realPath.c_str()) != EOK) {
49 return nullptr;
50 }
51 size_t length = realPath.size();
52 OH_ImageSourceNative *source = nullptr;
53 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(filePath, length, &source);
54 if (ret != Image_ErrorCode::IMAGE_SUCCESS || source == nullptr) {
55 return nullptr;
56 }
57 return source;
58 }
59
60 /**
61 * @tc.name: OH_ImageSourceInfo_Create
62 * @tc.desc: test OH_ImageSourceInfo_Create
63 * @tc.type: FUNC
64 */
65 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Create, TestSize.Level3)
66 {
67 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create start";
68 OH_ImageSource_Info *ops = nullptr;
69 Image_ErrorCode ret = OH_ImageSourceInfo_Create(&ops);
70 ASSERT_EQ(ret, IMAGE_SUCCESS);
71 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create end";
72 }
73
74 /**
75 * @tc.name: OH_ImageSourceInfo_GetWidth
76 * @tc.desc: test OH_ImageSourceInfo_GetWidth
77 * @tc.type: FUNC
78 */
79 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetWidth, TestSize.Level3)
80 {
81 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth start";
82 OH_ImageSource_Info *ops = nullptr;
83 uint32_t *width = nullptr;
84 Image_ErrorCode ret = OH_ImageSourceInfo_GetWidth(ops, width);
85 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
86 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth end";
87 }
88
89 /**
90 * @tc.name: OH_ImageSourceInfo_GetHeight
91 * @tc.desc: test OH_ImageSourceInfo_GetHeight
92 * @tc.type: FUNC
93 */
94 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetHeight, TestSize.Level3)
95 {
96 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight start";
97 OH_ImageSource_Info *ops = nullptr;
98 uint32_t *width = nullptr;
99 Image_ErrorCode ret = OH_ImageSourceInfo_GetHeight(ops, width);
100 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
101 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight end";
102 }
103
104 /**
105 * @tc.name: OH_ImageSourceInfo_Release
106 * @tc.desc: test OH_ImageSourceInfo_Release
107 * @tc.type: FUNC
108 */
109 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Release, TestSize.Level3)
110 {
111 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release start";
112 OH_ImageSource_Info *ops = nullptr;
113 Image_ErrorCode ret = OH_ImageSourceInfo_Release(ops);
114 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
115 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release end";
116 }
117
118 /**
119 * @tc.name: OH_DecodingOptions_Create
120 * @tc.desc: test OH_DecodingOptions_Create
121 * @tc.type: FUNC
122 */
123 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptions_Create, TestSize.Level3)
124 {
125 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create start";
126 OH_DecodingOptions *ops = nullptr;
127 Image_ErrorCode ret = OH_DecodingOptions_Create(&ops);
128 ASSERT_EQ(ret, IMAGE_SUCCESS);
129 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create end";
130 }
131
132 /**
133 * @tc.name: OH_ImageSource_DecodingOptionsSetGetPixelFormat
134 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetPixelFormat
135 * @tc.type: FUNC
136 */
137 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetPixelFormat, TestSize.Level3)
138 {
139 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat start";
140 OH_DecodingOptions *ops = nullptr;
141 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
142 int32_t pixelFormat = 0;
143 ret = OH_DecodingOptions_Create(&ops);
144 ASSERT_EQ(ret, IMAGE_SUCCESS);
145 OH_DecodingOptions_SetPixelFormat(ops, 1);
146 OH_DecodingOptions_GetPixelFormat(ops, &pixelFormat);
147 ASSERT_EQ(pixelFormat, 1);
148 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat end";
149 }
150
151 /**
152 * @tc.name: OH_ImageSource_DecodingOptionsSetGetIndex
153 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetIndex
154 * @tc.type: FUNC
155 */
156 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetIndex, TestSize.Level3)
157 {
158 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex start";
159 OH_DecodingOptions *ops = nullptr;
160 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
161 uint32_t index = 0;
162 ret = OH_DecodingOptions_Create(&ops);
163 ASSERT_EQ(ret, IMAGE_SUCCESS);
164 OH_DecodingOptions_SetIndex(ops, 1);
165 OH_DecodingOptions_GetIndex(ops, &index);
166 ASSERT_EQ(index, 1);
167 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex end";
168 }
169
170 /**
171 * @tc.name: OH_ImageSource_DecodingOptionsSetGetRotate
172 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetRotate
173 * @tc.type: FUNC
174 */
175 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetRotate, TestSize.Level3)
176 {
177 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate start";
178 OH_DecodingOptions *ops = nullptr;
179 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
180 float rotate = 0;
181 ret = OH_DecodingOptions_Create(&ops);
182 ASSERT_EQ(ret, IMAGE_SUCCESS);
183 OH_DecodingOptions_SetRotate(ops, 1);
184 OH_DecodingOptions_GetRotate(ops, &rotate);
185 ASSERT_EQ(rotate, 1);
186 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate end";
187 }
188
189 /**
190 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredSize
191 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredSize
192 * @tc.type: FUNC
193 */
194 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredSize, TestSize.Level3)
195 {
196 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize start";
197 OH_DecodingOptions *ops = nullptr;
198 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
199 Image_Size desiredSize = {0, 0};
200 Image_Size desiredSize2 = {1, 2};
201 ret = OH_DecodingOptions_Create(&ops);
202 ASSERT_EQ(ret, IMAGE_SUCCESS);
203 OH_DecodingOptions_SetDesiredSize(ops, &desiredSize2);
204 OH_DecodingOptions_GetDesiredSize(ops, &desiredSize);
205 ASSERT_EQ(desiredSize.width, desiredSize2.width);
206 ASSERT_EQ(desiredSize.height, desiredSize2.height);
207 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize end";
208 }
209
210 /**
211 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredRegion
212 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredRegion
213 * @tc.type: FUNC
214 */
215 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredRegion, TestSize.Level3)
216 {
217 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion start";
218 OH_DecodingOptions *ops = nullptr;
219 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
220 Image_Region desiredRegion = {0, 0, 0, 0};
221 Image_Region desiredRegion2 = {1, 2, 3, 4};
222 ret = OH_DecodingOptions_Create(&ops);
223 ASSERT_EQ(ret, IMAGE_SUCCESS);
224 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
225 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
226 ASSERT_EQ(desiredRegion.x, 1);
227 ASSERT_EQ(desiredRegion.y, 2);
228 ASSERT_EQ(desiredRegion.width, 3);
229 ASSERT_EQ(desiredRegion.height, 4);
230 ret = OH_DecodingOptions_Release(ops);
231 ASSERT_EQ(ret, IMAGE_SUCCESS);
232 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion end";
233 }
234
235 /**
236 * @tc.name: OH_ImageSourceNative_CreateFromUri
237 * @tc.desc: test OH_ImageSourceNative_CreateFromUri
238 * @tc.type: FUNC
239 */
240 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromUri, TestSize.Level3)
241 {
242 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri start";
243 OH_ImageSourceNative *imageSource = nullptr;
244 char *uri = nullptr;
245 size_t uriSize = 0;
246 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(uri, uriSize, &imageSource);
247 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
248 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri end";
249 }
250
251 /**
252 * @tc.name: OH_ImageSourceNative_CreateFromFd
253 * @tc.desc: test OH_ImageSourceNative_CreateFromFd
254 * @tc.type: FUNC
255 */
256 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromFd, TestSize.Level3)
257 {
258 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd start";
259 OH_ImageSourceNative *imageSource = nullptr;
260 int32_t fd = 0;
261 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromFd(fd, &imageSource);
262 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
263 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd end";
264 }
265
266 /**
267 * @tc.name: OH_ImageSourceNative_CreateFromData
268 * @tc.desc: test OH_ImageSourceNative_CreateFromData
269 * @tc.type: FUNC
270 */
271 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromData, TestSize.Level3)
272 {
273 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData start";
274 OH_ImageSourceNative *imageSource = nullptr;
275 uint8_t* data = nullptr;
276 size_t dataSize = 0;
277 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromData(data, dataSize, &imageSource);
278 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
279 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData end";
280 }
281
282 /**
283 * @tc.name: OH_ImageSourceNative_CreateFromRawFile002
284 * @tc.desc: test OH_ImageSourceNative_CreateFromRawFile
285 * @tc.type: FUNC
286 */
287 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromRawFile002, TestSize.Level3)
288 {
289 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 start";
290 OH_ImageSourceNative *imageSource = nullptr;
291 RawFileDescriptor *rawFile = nullptr;
292 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromRawFile(rawFile, &imageSource);
293 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
294 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 end";
295 }
296
297 /**
298 * @tc.name: OH_ImageSourceNative_CreatePixelmap
299 * @tc.desc: test OH_ImageSourceNative_CreatePixelmap
300 * @tc.type: FUNC
301 */
302 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmap, TestSize.Level3)
303 {
304 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap start";
305 OH_ImageSourceNative *imageSource = nullptr;
306 OH_DecodingOptions* ops = nullptr;
307 OH_PixelmapNative* resPixMap = nullptr;
308 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
309 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
310 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap end";
311 }
312
313 /**
314 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest001
315 * @tc.desc: Test create Pixelmap use DMA.
316 * @tc.type: FUNC
317 */
318 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest001, TestSize.Level1)
319 {
320 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
321 ASSERT_NE(imageSource, nullptr);
322 OH_DecodingOptions *opts = nullptr;
323 OH_DecodingOptions_Create(&opts);
324 ASSERT_NE(opts, nullptr);
325 OH_PixelmapNative* resPixMap = nullptr;
326 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
327 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
328 EXPECT_EQ(ret, IMAGE_SUCCESS);
329 EXPECT_NE(resPixMap, nullptr);
330 OH_ImageSourceNative_Release(imageSource);
331 OH_DecodingOptions_Release(opts);
332 OH_PixelmapNative_Release(resPixMap);
333 }
334
335 /**
336 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest002
337 * @tc.desc: Test create Pixelmap use SHARE_MEMORY.
338 * @tc.type: FUNC
339 */
340 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest002, TestSize.Level1)
341 {
342 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
343 ASSERT_NE(imageSource, nullptr);
344 OH_DecodingOptions *opts = nullptr;
345 OH_DecodingOptions_Create(&opts);
346 ASSERT_NE(opts, nullptr);
347 OH_PixelmapNative* resPixMap = nullptr;
348 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
349 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
350 EXPECT_EQ(ret, IMAGE_SUCCESS);
351 EXPECT_NE(resPixMap, nullptr);
352 OH_ImageSourceNative_Release(imageSource);
353 OH_DecodingOptions_Release(opts);
354 OH_PixelmapNative_Release(resPixMap);
355 }
356
357 /**
358 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest003
359 * @tc.desc: Test create Pixelmap if source is nullptr.
360 * @tc.type: FUNC
361 */
362 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest003, TestSize.Level1)
363 {
364 OH_ImageSourceNative *imageSource = nullptr;
365 OH_DecodingOptions* opts = nullptr;
366 OH_PixelmapNative* resPixMap = nullptr;
367 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
368 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
369 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
370 EXPECT_EQ(resPixMap, nullptr);
371 OH_ImageSourceNative_Release(imageSource);
372 }
373
374 /**
375 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest004
376 * @tc.desc: Test create Pixelmap if index is invalid.
377 * @tc.type: FUNC
378 */
379 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest004, TestSize.Level1)
380 {
381 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
382 ASSERT_NE(imageSource, nullptr);
383 OH_DecodingOptions *opts = nullptr;
384 OH_DecodingOptions_Create(&opts);
385 ASSERT_NE(opts, nullptr);
386 uint32_t tempIndex = INVALID_INDEX;
387 Image_ErrorCode ret = OH_DecodingOptions_SetIndex(opts, tempIndex);
388 OH_PixelmapNative* resPixMap = nullptr;
389 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
390 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
391 EXPECT_EQ(ret, IMAGE_DECODE_FAILED);
392 EXPECT_EQ(resPixMap, nullptr);
393 OH_ImageSourceNative_Release(imageSource);
394 OH_DecodingOptions_Release(opts);
395 }
396
397 /**
398 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest005
399 * @tc.desc: Test the creation of a pixelmap using AUTO allocator for JPEG image format, expecting success.
400 * @tc.type: FUNC
401 */
402 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest005, TestSize.Level1)
403 {
404 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
405 ASSERT_NE(imageSource, nullptr);
406 OH_DecodingOptions *opts = nullptr;
407 OH_DecodingOptions_Create(&opts);
408 ASSERT_NE(opts, nullptr);
409 OH_PixelmapNative* resPixMap = nullptr;
410 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_AUTO;
411 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
412 EXPECT_EQ(ret, IMAGE_SUCCESS);
413 EXPECT_NE(resPixMap, nullptr);
414 OH_ImageSourceNative_Release(imageSource);
415 OH_DecodingOptions_Release(opts);
416 OH_PixelmapNative_Release(resPixMap);
417 }
418
419 /**
420 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest006
421 * @tc.desc: Test the creation of a pixelmap using DMA allocator with invalid decoding options (nullptr) for JPEG image
422 * format, expecting IMAGE_BAD_PARAMETER error.
423 * @tc.type: FUNC
424 */
425 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest006, TestSize.Level1)
426 {
427 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
428 ASSERT_NE(imageSource, nullptr);
429 OH_DecodingOptions* opts = nullptr;
430 OH_PixelmapNative* resPixMap = nullptr;
431 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
432 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
433 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
434 EXPECT_EQ(resPixMap, nullptr);
435 OH_ImageSourceNative_Release(imageSource);
436 OH_DecodingOptions_Release(opts);
437 OH_PixelmapNative_Release(resPixMap);
438 }
439
440 /**
441 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest007
442 * @tc.desc: Test the creation of a pixelmap using DMA allocator, with NV21 pixel format for HEIF image format,
443 * expecting success.
444 * @tc.type: FUNC
445 */
446 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest007, TestSize.Level1)
447 {
448 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
449 ASSERT_NE(imageSource, nullptr);
450 OH_DecodingOptions *opts = nullptr;
451 OH_DecodingOptions_Create(&opts);
452 ASSERT_NE(opts, nullptr);
453 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
454 EXPECT_EQ(ret, IMAGE_SUCCESS);
455 OH_PixelmapNative* resPixMap = nullptr;
456 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
457 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
458 EXPECT_EQ(ret, IMAGE_SUCCESS);
459 EXPECT_NE(resPixMap, nullptr);
460 OH_ImageSourceNative_Release(imageSource);
461 OH_DecodingOptions_Release(opts);
462 OH_PixelmapNative_Release(resPixMap);
463 }
464
465 /**
466 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest008
467 * @tc.desc: Test the creation of a pixelmap using DMA allocator, with RGBA_8888 pixel format for HEIF image format,
468 * expecting success.
469 * @tc.type: FUNC
470 */
471 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest008, TestSize.Level1)
472 {
473 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
474 ASSERT_NE(imageSource, nullptr);
475 OH_DecodingOptions *opts = nullptr;
476 OH_DecodingOptions_Create(&opts);
477 ASSERT_NE(opts, nullptr);
478 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
479 EXPECT_EQ(ret, IMAGE_SUCCESS);
480 OH_PixelmapNative* resPixMap = nullptr;
481 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
482 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
483 EXPECT_EQ(ret, IMAGE_SUCCESS);
484 EXPECT_NE(resPixMap, nullptr);
485 OH_ImageSourceNative_Release(imageSource);
486 OH_DecodingOptions_Release(opts);
487 OH_PixelmapNative_Release(resPixMap);
488 }
489
490 /**
491 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest009
492 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with NV21 pixel format for HEIF image
493 * format, expecting unsupported operation.
494 * @tc.type: FUNC
495 */
496 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest009, TestSize.Level1)
497 {
498 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
499 ASSERT_NE(imageSource, nullptr);
500 OH_DecodingOptions *opts = nullptr;
501 OH_DecodingOptions_Create(&opts);
502 ASSERT_NE(opts, nullptr);
503 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
504 EXPECT_EQ(ret, IMAGE_SUCCESS);
505 OH_PixelmapNative* resPixMap = nullptr;
506 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
507 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
508 EXPECT_EQ(ret, IMAGE_SUCCESS);
509 EXPECT_NE(resPixMap, nullptr);
510 OH_ImageSourceNative_Release(imageSource);
511 OH_DecodingOptions_Release(opts);
512 OH_PixelmapNative_Release(resPixMap);
513 }
514
515 /**
516 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest010
517 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format for HEIF image
518 * format, expecting success.
519 * @tc.type: FUNC
520 */
521 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest010, TestSize.Level1)
522 {
523 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
524 ASSERT_NE(imageSource, nullptr);
525 OH_DecodingOptions *opts = nullptr;
526 OH_DecodingOptions_Create(&opts);
527 ASSERT_NE(opts, nullptr);
528 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
529 EXPECT_EQ(ret, IMAGE_SUCCESS);
530 OH_PixelmapNative* resPixMap = nullptr;
531 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
532 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
533 EXPECT_EQ(ret, IMAGE_SUCCESS);
534 EXPECT_NE(resPixMap, nullptr);
535 OH_ImageSourceNative_Release(imageSource);
536 OH_DecodingOptions_Release(opts);
537 OH_PixelmapNative_Release(resPixMap);
538 }
539
540 /**
541 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest011
542 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format and HDR dynamic
543 * range, expecting unsupported operation.
544 * @tc.type: FUNC
545 */
546 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest011, TestSize.Level1)
547 {
548 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
549 ASSERT_NE(imageSource, nullptr);
550 OH_DecodingOptions *opts = nullptr;
551 OH_DecodingOptions_Create(&opts);
552 ASSERT_NE(opts, nullptr);
553 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
554 EXPECT_EQ(ret, IMAGE_SUCCESS);
555 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
556 EXPECT_EQ(ret, IMAGE_SUCCESS);
557 OH_PixelmapNative* resPixMap = nullptr;
558 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
559 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
560 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
561 EXPECT_EQ(resPixMap, nullptr);
562 OH_ImageSourceNative_Release(imageSource);
563 OH_DecodingOptions_Release(opts);
564 OH_PixelmapNative_Release(resPixMap);
565 }
566
567 /**
568 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest012
569 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format and auto
570 * dynamic range, expecting unsupported operation.
571 * @tc.type: FUNC
572 */
573 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest012, TestSize.Level1)
574 {
575 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
576 ASSERT_NE(imageSource, nullptr);
577 OH_DecodingOptions *opts = nullptr;
578 OH_DecodingOptions_Create(&opts);
579 ASSERT_NE(opts, nullptr);
580 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
581 EXPECT_EQ(ret, IMAGE_SUCCESS);
582 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
583 EXPECT_EQ(ret, IMAGE_SUCCESS);
584 OH_PixelmapNative* resPixMap = nullptr;
585 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
586 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
587 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
588 EXPECT_EQ(resPixMap, nullptr);
589 OH_ImageSourceNative_Release(imageSource);
590 OH_DecodingOptions_Release(opts);
591 OH_PixelmapNative_Release(resPixMap);
592 }
593
594 /**
595 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest013
596 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and HDR dynamic range,
597 * expecting successful operation.
598 * @tc.type: FUNC
599 */
600 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest013, TestSize.Level1)
601 {
602 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
603 ASSERT_NE(imageSource, nullptr);
604 OH_DecodingOptions *opts = nullptr;
605 OH_DecodingOptions_Create(&opts);
606 ASSERT_NE(opts, nullptr);
607 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
608 EXPECT_EQ(ret, IMAGE_SUCCESS);
609 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
610 EXPECT_EQ(ret, IMAGE_SUCCESS);
611 OH_PixelmapNative* resPixMap = nullptr;
612 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
613 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
614 EXPECT_EQ(ret, IMAGE_SUCCESS);
615 EXPECT_NE(resPixMap, nullptr);
616 OH_ImageSourceNative_Release(imageSource);
617 OH_DecodingOptions_Release(opts);
618 OH_PixelmapNative_Release(resPixMap);
619 }
620
621 /**
622 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest014
623 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and auto dynamic range,
624 * expecting successful operation.
625 * @tc.type: FUNC
626 */
627 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest014, TestSize.Level1)
628 {
629 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
630 ASSERT_NE(imageSource, nullptr);
631 OH_DecodingOptions *opts = nullptr;
632 OH_DecodingOptions_Create(&opts);
633 ASSERT_NE(opts, nullptr);
634 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
635 EXPECT_EQ(ret, IMAGE_SUCCESS);
636 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
637 EXPECT_EQ(ret, IMAGE_SUCCESS);
638 OH_PixelmapNative* resPixMap = nullptr;
639 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
640 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
641 EXPECT_EQ(ret, IMAGE_SUCCESS);
642 EXPECT_NE(resPixMap, nullptr);
643 OH_ImageSourceNative_Release(imageSource);
644 OH_DecodingOptions_Release(opts);
645 OH_PixelmapNative_Release(resPixMap);
646 }
647
648 /**
649 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest015
650 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and HDR dynamic range,
651 * expecting successful operation.
652 * @tc.type: FUNC
653 */
654 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest015, TestSize.Level1)
655 {
656 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
657 ASSERT_NE(imageSource, nullptr);
658 OH_DecodingOptions *opts = nullptr;
659 OH_DecodingOptions_Create(&opts);
660 ASSERT_NE(opts, nullptr);
661 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
662 EXPECT_EQ(ret, IMAGE_SUCCESS);
663 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
664 EXPECT_EQ(ret, IMAGE_SUCCESS);
665 OH_PixelmapNative* resPixMap = nullptr;
666 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
667 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
668 EXPECT_EQ(ret, IMAGE_SUCCESS);
669 EXPECT_NE(resPixMap, nullptr);
670 OH_ImageSourceNative_Release(imageSource);
671 OH_DecodingOptions_Release(opts);
672 OH_PixelmapNative_Release(resPixMap);
673 }
674
675 /**
676 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest016
677 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and auto dynamic range,
678 * expecting successful operation.
679 * @tc.type: FUNC
680 */
681 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest016, TestSize.Level1)
682 {
683 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
684 ASSERT_NE(imageSource, nullptr);
685 OH_DecodingOptions *opts = nullptr;
686 OH_DecodingOptions_Create(&opts);
687 ASSERT_NE(opts, nullptr);
688 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
689 EXPECT_EQ(ret, IMAGE_SUCCESS);
690 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
691 EXPECT_EQ(ret, IMAGE_SUCCESS);
692 OH_PixelmapNative* resPixMap = nullptr;
693 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
694 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
695 EXPECT_EQ(ret, IMAGE_SUCCESS);
696 EXPECT_NE(resPixMap, nullptr);
697 OH_ImageSourceNative_Release(imageSource);
698 OH_DecodingOptions_Release(opts);
699 OH_PixelmapNative_Release(resPixMap);
700 }
701
702 /**
703 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest017
704 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and HDR dynamic
705 * range, expecting unsupported operation.
706 * @tc.type: FUNC
707 */
708 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest017, TestSize.Level1)
709 {
710 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
711 ASSERT_NE(imageSource, nullptr);
712 OH_DecodingOptions *opts = nullptr;
713 OH_DecodingOptions_Create(&opts);
714 ASSERT_NE(opts, nullptr);
715 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
716 EXPECT_EQ(ret, IMAGE_SUCCESS);
717 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
718 EXPECT_EQ(ret, IMAGE_SUCCESS);
719 OH_PixelmapNative* resPixMap = nullptr;
720 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
721 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
722 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
723 EXPECT_EQ(resPixMap, nullptr);
724 OH_ImageSourceNative_Release(imageSource);
725 OH_DecodingOptions_Release(opts);
726 OH_PixelmapNative_Release(resPixMap);
727 }
728
729 /**
730 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest018
731 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and auto
732 * dynamic range, expecting unsupported operation.
733 * @tc.type: FUNC
734 */
735 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest018, TestSize.Level1)
736 {
737 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
738 ASSERT_NE(imageSource, nullptr);
739 OH_DecodingOptions *opts = nullptr;
740 OH_DecodingOptions_Create(&opts);
741 ASSERT_NE(opts, nullptr);
742 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
743 EXPECT_EQ(ret, IMAGE_SUCCESS);
744 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
745 EXPECT_EQ(ret, IMAGE_SUCCESS);
746 OH_PixelmapNative* resPixMap = nullptr;
747 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
748 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
749 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
750 EXPECT_EQ(resPixMap, nullptr);
751 OH_ImageSourceNative_Release(imageSource);
752 OH_DecodingOptions_Release(opts);
753 OH_PixelmapNative_Release(resPixMap);
754 }
755
756 /**
757 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest019
758 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with RGBA_8888 pixel format and HDR
759 * dynamic range, expecting unsupported operation.
760 * @tc.type: FUNC
761 */
762 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest019, TestSize.Level1)
763 {
764 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
765 ASSERT_NE(imageSource, nullptr);
766 OH_DecodingOptions *opts = nullptr;
767 OH_DecodingOptions_Create(&opts);
768 ASSERT_NE(opts, nullptr);
769 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
770 EXPECT_EQ(ret, IMAGE_SUCCESS);
771 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
772 EXPECT_EQ(ret, IMAGE_SUCCESS);
773 OH_PixelmapNative* resPixMap = nullptr;
774 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
775 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
776 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
777 EXPECT_EQ(resPixMap, nullptr);
778 OH_ImageSourceNative_Release(imageSource);
779 OH_DecodingOptions_Release(opts);
780 OH_PixelmapNative_Release(resPixMap);
781 }
782
783 /**
784 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest020
785 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with RGBA_8888 pixel format and auto
786 * dynamic range, expecting unsupported operation.
787 * @tc.type: FUNC
788 */
789 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest020, TestSize.Level1)
790 {
791 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
792 ASSERT_NE(imageSource, nullptr);
793 OH_DecodingOptions *opts = nullptr;
794 OH_DecodingOptions_Create(&opts);
795 ASSERT_NE(opts, nullptr);
796 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
797 EXPECT_EQ(ret, IMAGE_SUCCESS);
798 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
799 EXPECT_EQ(ret, IMAGE_SUCCESS);
800 OH_PixelmapNative* resPixMap = nullptr;
801 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
802 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
803 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
804 EXPECT_EQ(resPixMap, nullptr);
805 OH_ImageSourceNative_Release(imageSource);
806 OH_DecodingOptions_Release(opts);
807 OH_PixelmapNative_Release(resPixMap);
808 }
809
810 /**
811 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest021
812 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and HDR dynamic range.
813 * @tc.type: FUNC
814 */
815 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest021, TestSize.Level1)
816 {
817 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
818 ASSERT_NE(imageSource, nullptr);
819 OH_DecodingOptions *opts = nullptr;
820 OH_DecodingOptions_Create(&opts);
821 ASSERT_NE(opts, nullptr);
822 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
823 EXPECT_EQ(ret, IMAGE_SUCCESS);
824 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
825 EXPECT_EQ(ret, IMAGE_SUCCESS);
826 OH_PixelmapNative* resPixMap = nullptr;
827 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
828 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
829 EXPECT_EQ(ret, IMAGE_SUCCESS);
830 EXPECT_NE(resPixMap, nullptr);
831 OH_ImageSourceNative_Release(imageSource);
832 OH_DecodingOptions_Release(opts);
833 OH_PixelmapNative_Release(resPixMap);
834 }
835
836 /**
837 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest022
838 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and auto dynamic range.
839 * @tc.type: FUNC
840 */
841 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest022, TestSize.Level1)
842 {
843 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
844 ASSERT_NE(imageSource, nullptr);
845 OH_DecodingOptions *opts = nullptr;
846 OH_DecodingOptions_Create(&opts);
847 ASSERT_NE(opts, nullptr);
848 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
849 EXPECT_EQ(ret, IMAGE_SUCCESS);
850 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
851 EXPECT_EQ(ret, IMAGE_SUCCESS);
852 OH_PixelmapNative* resPixMap = nullptr;
853 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
854 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
855 EXPECT_EQ(ret, IMAGE_SUCCESS);
856 EXPECT_NE(resPixMap, nullptr);
857 OH_ImageSourceNative_Release(imageSource);
858 OH_DecodingOptions_Release(opts);
859 OH_PixelmapNative_Release(resPixMap);
860 }
861
862 /**
863 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest023
864 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and HDR dynamic range.
865 * @tc.type: FUNC
866 */
867 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest023, TestSize.Level1)
868 {
869 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
870 ASSERT_NE(imageSource, nullptr);
871 OH_DecodingOptions *opts = nullptr;
872 OH_DecodingOptions_Create(&opts);
873 ASSERT_NE(opts, nullptr);
874 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
875 EXPECT_EQ(ret, IMAGE_SUCCESS);
876 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
877 EXPECT_EQ(ret, IMAGE_SUCCESS);
878 OH_PixelmapNative* resPixMap = nullptr;
879 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
880 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
881 EXPECT_EQ(ret, IMAGE_SUCCESS);
882 EXPECT_NE(resPixMap, nullptr);
883 OH_ImageSourceNative_Release(imageSource);
884 OH_DecodingOptions_Release(opts);
885 OH_PixelmapNative_Release(resPixMap);
886 }
887
888 /**
889 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest024
890 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and auto dynamic range.
891 * @tc.type: FUNC
892 */
893 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest024, TestSize.Level1)
894 {
895 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
896 ASSERT_NE(imageSource, nullptr);
897 OH_DecodingOptions *opts = nullptr;
898 OH_DecodingOptions_Create(&opts);
899 ASSERT_NE(opts, nullptr);
900 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
901 EXPECT_EQ(ret, IMAGE_SUCCESS);
902 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
903 EXPECT_EQ(ret, IMAGE_SUCCESS);
904 OH_PixelmapNative* resPixMap = nullptr;
905 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
906 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
907 EXPECT_EQ(ret, IMAGE_SUCCESS);
908 EXPECT_NE(resPixMap, nullptr);
909 OH_ImageSourceNative_Release(imageSource);
910 OH_DecodingOptions_Release(opts);
911 OH_PixelmapNative_Release(resPixMap);
912 }
913
914 /**
915 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest025
916 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with HDR dynamic range.
917 * @tc.type: FUNC
918 */
919 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest025, TestSize.Level1)
920 {
921 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
922 ASSERT_NE(imageSource, nullptr);
923 OH_DecodingOptions *opts = nullptr;
924 OH_DecodingOptions_Create(&opts);
925 ASSERT_NE(opts, nullptr);
926 auto ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
927 EXPECT_EQ(ret, IMAGE_SUCCESS);
928 OH_PixelmapNative* resPixMap = nullptr;
929 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
930 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
931 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
932 EXPECT_EQ(resPixMap, nullptr);
933 OH_ImageSourceNative_Release(imageSource);
934 OH_DecodingOptions_Release(opts);
935 OH_PixelmapNative_Release(resPixMap);
936 }
937
938 /**
939 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest026
940 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and auto
941 * dynamic range.
942 * @tc.type: FUNC
943 */
944 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest026, TestSize.Level1)
945 {
946 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
947 ASSERT_NE(imageSource, nullptr);
948 OH_DecodingOptions *opts = nullptr;
949 OH_DecodingOptions_Create(&opts);
950 ASSERT_NE(opts, nullptr);
951 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
952 ASSERT_EQ(ret, IMAGE_SUCCESS);
953 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
954 ASSERT_EQ(ret, IMAGE_SUCCESS);
955 OH_PixelmapNative* resPixMap = nullptr;
956 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
957 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
958 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
959 EXPECT_EQ(resPixMap, nullptr);
960 OH_ImageSourceNative_Release(imageSource);
961 OH_DecodingOptions_Release(opts);
962 OH_PixelmapNative_Release(resPixMap);
963 }
964
965 /**
966 * @tc.name: OH_ImageSourceNative_CreatePixelmapList
967 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapList
968 * @tc.type: FUNC
969 */
970 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapList, TestSize.Level3)
971 {
972 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList start";
973 OH_DecodingOptions *ops = nullptr;
974 OH_ImageSourceNative *imageSource = nullptr;
975 OH_PixelmapNative** resVecPixMap = nullptr;
976 size_t outSize = 0;
977 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapList(imageSource, ops, resVecPixMap, outSize);
978 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
979 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList end";
980 }
981
982 /**
983 * @tc.name: OH_ImageSourceNative_GetDelayTimeList
984 * @tc.desc: test OH_ImageSourceNative_GetDelayTimeList
985 * @tc.type: FUNC
986 */
987 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetDelayTimeList, TestSize.Level3)
988 {
989 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList start";
990 OH_ImageSourceNative *imageSource = nullptr;
991 int32_t* delayTimeList = nullptr;
992 size_t size = 0;
993 Image_ErrorCode ret = OH_ImageSourceNative_GetDelayTimeList(imageSource, delayTimeList, size);
994 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
995 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList end";
996 }
997
998 /**
999 * @tc.name: OH_ImageSourceNative_GetImageInfo
1000 * @tc.desc: test OH_ImageSourceNative_GetImageInfo
1001 * @tc.type: FUNC
1002 */
1003 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageInfo, TestSize.Level3)
1004 {
1005 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo start";
1006 OH_ImageSourceNative *imageSource = nullptr;
1007 int32_t index = 0;
1008 OH_ImageSource_Info* info = nullptr;
1009 Image_ErrorCode ret = OH_ImageSourceNative_GetImageInfo(imageSource, index, info);
1010 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1011 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo end";
1012 }
1013
1014 /**
1015 * @tc.name: OH_ImageSourceNative_GetImageProperty
1016 * @tc.desc: test OH_ImageSourceNative_GetImageProperty
1017 * @tc.type: FUNC
1018 */
1019 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageProperty, TestSize.Level3)
1020 {
1021 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty start";
1022 OH_ImageSourceNative *imageSource = nullptr;
1023 Image_String* key = nullptr;
1024 Image_String* value = nullptr;
1025 Image_ErrorCode ret = OH_ImageSourceNative_GetImageProperty(imageSource, key, value);
1026 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1027 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty end";
1028 }
1029
1030 /**
1031 * @tc.name: OH_ImageSourceNative_ModifyImageProperty
1032 * @tc.desc: test OH_ImageSourceNative_ModifyImageProperty
1033 * @tc.type: FUNC
1034 */
1035 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_ModifyImageProperty, TestSize.Level3)
1036 {
1037 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty start";
1038 OH_ImageSourceNative *imageSource = nullptr;
1039 Image_String* key = nullptr;
1040 Image_String* value = nullptr;
1041 Image_ErrorCode ret = OH_ImageSourceNative_ModifyImageProperty(imageSource, key, value);
1042 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1043 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty end";
1044 }
1045
1046 /**
1047 * @tc.name: OH_ImageSourceNative_GetFrameCount
1048 * @tc.desc: test OH_ImageSourceNative_GetFrameCount
1049 * @tc.type: FUNC
1050 */
1051 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetFrameCount, TestSize.Level3)
1052 {
1053 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount start";
1054 OH_ImageSourceNative *imageSource = nullptr;
1055 uint32_t* res = nullptr;
1056 Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, res);
1057 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1058 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount end";
1059 }
1060
1061 /**
1062 * @tc.name: OH_ImageSourceNative_Release
1063 * @tc.desc: test OH_ImageSourceNative_Release
1064 * @tc.type: FUNC
1065 */
1066 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_Release, TestSize.Level3)
1067 {
1068 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release start";
1069 OH_ImageSourceNative *imageSource = nullptr;
1070 Image_ErrorCode ret = OH_ImageSourceNative_Release(imageSource);
1071 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1072 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release end";
1073 }
1074
1075 }
1076 }
1077