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 #include "image_mime_type.h"
25
26 using namespace testing::ext;
27
28 struct OH_ImageSource_Info {
29 int32_t width = 0;
30 int32_t height = 0;
31 bool isHdr = false;
32 Image_MimeType mimeType;
33 };
34
35 namespace OHOS {
36 namespace Media {
37 class ImagSourceNdk2Test : public testing::Test {
38 public:
ImagSourceNdk2Test()39 ImagSourceNdk2Test() {}
~ImagSourceNdk2Test()40 ~ImagSourceNdk2Test() {}
41 };
42
43 static constexpr int32_t TestLength = 2;
44 static const std::string IMAGE_JPEG_PATH_TEST = "/data/local/tmp/image/test.jpg";
45 static const std::string IMAGE_JPEG_PATH = "/data/local/tmp/image/test_picture.jpg";
46 static const std::string IMAGE_JPEG_HDR_PATH = "/data/local/tmp/image/test_jpeg_hdr.jpg";
47 static const std::string IMAGE_HEIF_PATH = "/data/local/tmp/image/test_allocator_heif.heic";
48 static const std::string IMAGE_HEIF_HDR_PATH = "/data/local/tmp/image/test_heif_hdr.heic";
49 static const std::string IMAGE_PNG_PATH = "/data/local/tmp/image/test_picture_png.png";
50 static const std::string IMAGE_GIF_MOVING_PATH = "/data/local/tmp/image/moving_test.gif";
51 static const std::string IMAGE_GIF_LARGE_PATH = "/data/local/tmp/image/fake_large_size_test.gif"; // 50000x50000
52 static const std::string IMAGE_GIF_INCOMPLETE_PATH = "/data/local/tmp/image/incomplete_test.gif";
53 static const size_t IMAGE_GIF_MOVING_FRAME_COUNT = 3;
54 static const size_t IMAGE_GIF_INCOMPLETE_FRAME_INDEX = 16;
55 static const int32_t MAX_BUFFER_SIZE = 256;
56 static const int32_t INVALID_INDEX = 1000;
57
CreateImageSourceNative(std::string IMAGE_PATH)58 static OH_ImageSourceNative *CreateImageSourceNative(std::string IMAGE_PATH)
59 {
60 std::string realPath;
61 if (!ImageUtils::PathToRealPath(IMAGE_PATH.c_str(), realPath) || realPath.empty()) {
62 return nullptr;
63 }
64 char filePath[MAX_BUFFER_SIZE];
65 if (strcpy_s(filePath, sizeof(filePath), realPath.c_str()) != EOK) {
66 return nullptr;
67 }
68 size_t length = realPath.size();
69 OH_ImageSourceNative *source = nullptr;
70 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(filePath, length, &source);
71 if (ret != Image_ErrorCode::IMAGE_SUCCESS || source == nullptr) {
72 return nullptr;
73 }
74 return source;
75 }
76
77 /**
78 * @tc.name: OH_ImageSourceInfo_Create
79 * @tc.desc: test OH_ImageSourceInfo_Create
80 * @tc.type: FUNC
81 */
82 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Create, TestSize.Level3)
83 {
84 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create start";
85 OH_ImageSource_Info *ops = nullptr;
86 Image_ErrorCode ret = OH_ImageSourceInfo_Create(&ops);
87 ASSERT_EQ(ret, IMAGE_SUCCESS);
88 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create end";
89 }
90
91 /**
92 * @tc.name: OH_ImageSourceInfo_GetWidth
93 * @tc.desc: test OH_ImageSourceInfo_GetWidth
94 * @tc.type: FUNC
95 */
96 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetWidth, TestSize.Level3)
97 {
98 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth start";
99 OH_ImageSource_Info *ops = nullptr;
100 uint32_t *width = nullptr;
101 Image_ErrorCode ret = OH_ImageSourceInfo_GetWidth(ops, width);
102 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
103 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth end";
104 }
105
106 /**
107 * @tc.name: OH_ImageSourceInfo_GetHeight
108 * @tc.desc: test OH_ImageSourceInfo_GetHeight
109 * @tc.type: FUNC
110 */
111 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetHeight, TestSize.Level3)
112 {
113 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight start";
114 OH_ImageSource_Info *ops = nullptr;
115 uint32_t *width = nullptr;
116 Image_ErrorCode ret = OH_ImageSourceInfo_GetHeight(ops, width);
117 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
118 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight end";
119 }
120
121 /**
122 * @tc.name: OH_ImageSourceInfo_Release
123 * @tc.desc: test OH_ImageSourceInfo_Release
124 * @tc.type: FUNC
125 */
126 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Release, TestSize.Level3)
127 {
128 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release start";
129 OH_ImageSource_Info *ops = nullptr;
130 Image_ErrorCode ret = OH_ImageSourceInfo_Release(ops);
131 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
132 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release end";
133 }
134
135 /**
136 * @tc.name: OH_DecodingOptions_Create
137 * @tc.desc: test OH_DecodingOptions_Create
138 * @tc.type: FUNC
139 */
140 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptions_Create, TestSize.Level3)
141 {
142 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create start";
143 OH_DecodingOptions *ops = nullptr;
144 Image_ErrorCode ret = OH_DecodingOptions_Create(&ops);
145 ASSERT_EQ(ret, IMAGE_SUCCESS);
146 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create end";
147 }
148
149 /**
150 * @tc.name: OH_ImageSource_DecodingOptionsSetGetPixelFormat
151 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetPixelFormat
152 * @tc.type: FUNC
153 */
154 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetPixelFormat, TestSize.Level3)
155 {
156 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat start";
157 OH_DecodingOptions *ops = nullptr;
158 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
159 int32_t pixelFormat = 0;
160 ret = OH_DecodingOptions_Create(&ops);
161 ASSERT_EQ(ret, IMAGE_SUCCESS);
162 OH_DecodingOptions_SetPixelFormat(ops, 1);
163 OH_DecodingOptions_GetPixelFormat(ops, &pixelFormat);
164 ASSERT_EQ(pixelFormat, 1);
165 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat end";
166 }
167
168 /**
169 * @tc.name: OH_ImageSource_DecodingOptionsSetGetIndex
170 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetIndex
171 * @tc.type: FUNC
172 */
173 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetIndex, TestSize.Level3)
174 {
175 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex start";
176 OH_DecodingOptions *ops = nullptr;
177 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
178 uint32_t index = 0;
179 ret = OH_DecodingOptions_Create(&ops);
180 ASSERT_EQ(ret, IMAGE_SUCCESS);
181 OH_DecodingOptions_SetIndex(ops, 1);
182 OH_DecodingOptions_GetIndex(ops, &index);
183 ASSERT_EQ(index, 1);
184 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex end";
185 }
186
187 /**
188 * @tc.name: OH_ImageSource_DecodingOptionsSetGetRotate
189 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetRotate
190 * @tc.type: FUNC
191 */
192 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetRotate, TestSize.Level3)
193 {
194 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate start";
195 OH_DecodingOptions *ops = nullptr;
196 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
197 float rotate = 0;
198 ret = OH_DecodingOptions_Create(&ops);
199 ASSERT_EQ(ret, IMAGE_SUCCESS);
200 OH_DecodingOptions_SetRotate(ops, 1);
201 OH_DecodingOptions_GetRotate(ops, &rotate);
202 ASSERT_EQ(rotate, 1);
203 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate end";
204 }
205
206 /**
207 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredSize
208 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredSize
209 * @tc.type: FUNC
210 */
211 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredSize, TestSize.Level3)
212 {
213 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize start";
214 OH_DecodingOptions *ops = nullptr;
215 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
216 Image_Size desiredSize = {0, 0};
217 Image_Size desiredSize2 = {1, 2};
218 ret = OH_DecodingOptions_Create(&ops);
219 ASSERT_EQ(ret, IMAGE_SUCCESS);
220 OH_DecodingOptions_SetDesiredSize(ops, &desiredSize2);
221 OH_DecodingOptions_GetDesiredSize(ops, &desiredSize);
222 ASSERT_EQ(desiredSize.width, desiredSize2.width);
223 ASSERT_EQ(desiredSize.height, desiredSize2.height);
224 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize end";
225 }
226
227 /**
228 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredRegion
229 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredRegion
230 * @tc.type: FUNC
231 */
232 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredRegion, TestSize.Level3)
233 {
234 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion start";
235 OH_DecodingOptions *ops = nullptr;
236 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR;
237 Image_Region desiredRegion = {0, 0, 0, 0};
238 Image_Region desiredRegion2 = {1, 2, 3, 4};
239 ret = OH_DecodingOptions_Create(&ops);
240 ASSERT_EQ(ret, IMAGE_SUCCESS);
241 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
242 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
243 ASSERT_EQ(desiredRegion.x, 1);
244 ASSERT_EQ(desiredRegion.y, 2);
245 ASSERT_EQ(desiredRegion.width, 3);
246 ASSERT_EQ(desiredRegion.height, 4);
247 ret = OH_DecodingOptions_Release(ops);
248 ASSERT_EQ(ret, IMAGE_SUCCESS);
249 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion end";
250 }
251
252 /**
253 * @tc.name: OH_ImageSourceNative_CreateFromUri
254 * @tc.desc: test OH_ImageSourceNative_CreateFromUri
255 * @tc.type: FUNC
256 */
257 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromUri, TestSize.Level3)
258 {
259 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri start";
260 OH_ImageSourceNative *imageSource = nullptr;
261 char *uri = nullptr;
262 size_t uriSize = 0;
263 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(uri, uriSize, &imageSource);
264 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
265 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri end";
266 }
267
268 /**
269 * @tc.name: OH_ImageSourceNative_CreateFromFd
270 * @tc.desc: test OH_ImageSourceNative_CreateFromFd
271 * @tc.type: FUNC
272 */
273 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromFd, TestSize.Level3)
274 {
275 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd start";
276 OH_ImageSourceNative *imageSource = nullptr;
277 int32_t fd = 0;
278 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromFd(fd, &imageSource);
279 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
280 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd end";
281 }
282
283 /**
284 * @tc.name: OH_ImageSourceNative_CreateFromData
285 * @tc.desc: test OH_ImageSourceNative_CreateFromData
286 * @tc.type: FUNC
287 */
288 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromData, TestSize.Level3)
289 {
290 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData start";
291 OH_ImageSourceNative *imageSource = nullptr;
292 uint8_t* data = nullptr;
293 size_t dataSize = 0;
294 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromData(data, dataSize, &imageSource);
295 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
296 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData end";
297 }
298
299 /**
300 * @tc.name: OH_ImageSourceNative_CreateFromDataWithUserBuffer001
301 * @tc.desc: test OH_ImageSourceNative_CreateFromDataWithUserBuffer001
302 * @tc.type: FUNC
303 */
304 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromDataWithUserBuffer001, TestSize.Level3)
305 {
306 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromDataWithUserBuffer001 start";
307 OH_ImageSourceNative *imageSource = nullptr;
308 uint8_t* data = nullptr;
309 size_t dataSize = 0;
310 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromDataWithUserBuffer(data, dataSize, &imageSource);
311 ASSERT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
312 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromDataWithUserBuffer001 end";
313 }
314
315 /**
316 * @tc.name: OH_ImageSourceNative_CreateFromDataWithUserBuffer002
317 * @tc.desc: test OH_ImageSourceNative_CreateFromDataWithUserBuffer002
318 * @tc.type: FUNC
319 */
320 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromDataWithUserBuffer002, TestSize.Level3)
321 {
322 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromDataWithUserBuffer002 start";
323 void *data = malloc(100);
324 size_t dataSize = 100;
325 memset_s(data, dataSize, 0, dataSize);
326 OH_ImageSourceNative *imageSource = nullptr;
327 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromDataWithUserBuffer((uint8_t*)data, dataSize, &imageSource);
328 ASSERT_EQ(ret, IMAGE_SUCCESS);
329 ASSERT_NE(imageSource, nullptr);
330 if (imageSource != nullptr) {
331 ret = OH_ImageSourceNative_Release(imageSource);
332 }
333 free(data);
334 data = nullptr;
335 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromDataWithUserBuffer002 end";
336 }
337
338 /**
339 * @tc.name: OH_ImageSourceNative_CreateFromRawFile002
340 * @tc.desc: test OH_ImageSourceNative_CreateFromRawFile
341 * @tc.type: FUNC
342 */
343 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromRawFile002, TestSize.Level3)
344 {
345 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 start";
346 OH_ImageSourceNative *imageSource = nullptr;
347 RawFileDescriptor *rawFile = nullptr;
348 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromRawFile(rawFile, &imageSource);
349 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
350 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 end";
351 }
352
353 /**
354 * @tc.name: OH_ImageSourceNative_CreatePixelmap
355 * @tc.desc: test OH_ImageSourceNative_CreatePixelmap
356 * @tc.type: FUNC
357 */
358 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmap, TestSize.Level3)
359 {
360 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap start";
361 OH_ImageSourceNative *imageSource = nullptr;
362 OH_DecodingOptions* ops = nullptr;
363 OH_PixelmapNative* resPixMap = nullptr;
364 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
365 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
366 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap end";
367 }
368
369 /**
370 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest001
371 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest001
372 * @tc.type: FUNC
373 */
374 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest001, TestSize.Level3)
375 {
376 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest001 start";
377 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
378 ASSERT_NE(imageSource, nullptr);
379 OH_DecodingOptions* ops = nullptr;
380 Image_Region desiredRegion = {0, 0, 0, 0};
381 Image_Region desiredRegion2 = {1920, 1080, 1920, 1080};
382 OH_DecodingOptions_Create(&ops);
383 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
384 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
385 ASSERT_EQ(desiredRegion.x, 1920);
386 ASSERT_EQ(desiredRegion.y, 1080);
387 ASSERT_EQ(desiredRegion.width, 1920);
388 ASSERT_EQ(desiredRegion.height, 1080);
389 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
390 OH_PixelmapNative* resPixMap = nullptr;
391 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
392 EXPECT_EQ(ret, IMAGE_SUCCESS);
393 OH_ImageSourceNative_Release(imageSource);
394 OH_DecodingOptions_Release(ops);
395 OH_PixelmapNative_Release(resPixMap);
396 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest001 end";
397 }
398
399 /**
400 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest002
401 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest002
402 * @tc.type: FUNC
403 */
404 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest002, TestSize.Level3)
405 {
406 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest002 start";
407 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
408 ASSERT_NE(imageSource, nullptr);
409 OH_DecodingOptions* ops = nullptr;
410 Image_Region desiredRegion = {0, 0, 0, 0};
411 Image_Region desiredRegion2 = {0, 0, 1920, 2160};
412 OH_DecodingOptions_Create(&ops);
413 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
414 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
415 ASSERT_EQ(desiredRegion.x, 0);
416 ASSERT_EQ(desiredRegion.y, 0);
417 ASSERT_EQ(desiredRegion.width, 1920);
418 ASSERT_EQ(desiredRegion.height, 2160);
419 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
420 OH_PixelmapNative* resPixMap = nullptr;
421 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
422 EXPECT_EQ(ret, IMAGE_SUCCESS);
423 OH_ImageSourceNative_Release(imageSource);
424 OH_DecodingOptions_Release(ops);
425 OH_PixelmapNative_Release(resPixMap);
426 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest002 end";
427 }
428
429 /**
430 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest003
431 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest003
432 * @tc.type: FUNC
433 */
434 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest003, TestSize.Level3)
435 {
436 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest003 start";
437 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
438 ASSERT_NE(imageSource, nullptr);
439 OH_DecodingOptions* ops = nullptr;
440 Image_Region desiredRegion = {0, 0, 0, 0};
441 Image_Region desiredRegion2 = {0, 0, 3840, 1080};
442 OH_DecodingOptions_Create(&ops);
443 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
444 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
445 ASSERT_EQ(desiredRegion.x, 0);
446 ASSERT_EQ(desiredRegion.y, 0);
447 ASSERT_EQ(desiredRegion.width, 3840);
448 ASSERT_EQ(desiredRegion.height, 1080);
449 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
450 OH_PixelmapNative* resPixMap = nullptr;
451 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
452 EXPECT_EQ(ret, IMAGE_SUCCESS);
453 OH_ImageSourceNative_Release(imageSource);
454 OH_DecodingOptions_Release(ops);
455 OH_PixelmapNative_Release(resPixMap);
456 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest003 end";
457 }
458
459 /**
460 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest004
461 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest004
462 * @tc.type: FUNC
463 */
464 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest004, TestSize.Level3)
465 {
466 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest004 start";
467 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
468 ASSERT_NE(imageSource, nullptr);
469 OH_DecodingOptions* ops = nullptr;
470 Image_Region desiredRegion = {0, 0, 0, 0};
471 Image_Region desiredRegion2 = {1920, 1080, 3840, 1080};
472 OH_DecodingOptions_Create(&ops);
473 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
474 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
475 ASSERT_EQ(desiredRegion.x, 1920);
476 ASSERT_EQ(desiredRegion.y, 1080);
477 ASSERT_EQ(desiredRegion.width, 3840);
478 ASSERT_EQ(desiredRegion.height, 1080);
479 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
480 OH_PixelmapNative* resPixMap = nullptr;
481 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
482 EXPECT_EQ(ret, IMAGE_SUCCESS);
483 OH_ImageSourceNative_Release(imageSource);
484 OH_DecodingOptions_Release(ops);
485 OH_PixelmapNative_Release(resPixMap);
486 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest004 end";
487 }
488
489 /**
490 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest005
491 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest005
492 * @tc.type: FUNC
493 */
494 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest005, TestSize.Level3)
495 {
496 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest005 start";
497 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
498 ASSERT_NE(imageSource, nullptr);
499 OH_DecodingOptions* ops = nullptr;
500 Image_Region desiredRegion = {0, 0, 0, 0};
501 Image_Region desiredRegion2 = {3840, 2160, 1920, 1080};
502 OH_DecodingOptions_Create(&ops);
503 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
504 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
505 ASSERT_EQ(desiredRegion.x, 3840);
506 ASSERT_EQ(desiredRegion.y, 2160);
507 ASSERT_EQ(desiredRegion.width, 1920);
508 ASSERT_EQ(desiredRegion.height, 1080);
509 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
510 OH_PixelmapNative* resPixMap = nullptr;
511 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
512 EXPECT_EQ(ret, IMAGE_SUCCESS);
513 OH_ImageSourceNative_Release(imageSource);
514 OH_DecodingOptions_Release(ops);
515 OH_PixelmapNative_Release(resPixMap);
516 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest005 end";
517 }
518
519 /**
520 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest006
521 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest006
522 * @tc.type: FUNC
523 */
524 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest006, TestSize.Level3)
525 {
526 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest006 start";
527 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
528 ASSERT_NE(imageSource, nullptr);
529 OH_DecodingOptions* ops = nullptr;
530 Image_Region desiredRegion = {0, 0, 0, 0};
531 Image_Region desiredRegion2 = {1920, 1080, 1920, 1080};
532 OH_DecodingOptions_Create(&ops);
533 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
534 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
535 ASSERT_EQ(desiredRegion.x, 1920);
536 ASSERT_EQ(desiredRegion.y, 1080);
537 ASSERT_EQ(desiredRegion.width, 1920);
538 ASSERT_EQ(desiredRegion.height, 1080);
539 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
540 OH_PixelmapNative* resPixMap = nullptr;
541 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
542 EXPECT_EQ(ret, IMAGE_SUCCESS);
543 OH_ImageSourceNative_Release(imageSource);
544 OH_DecodingOptions_Release(ops);
545 OH_PixelmapNative_Release(resPixMap);
546 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest006 end";
547 }
548
549 /**
550 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest007
551 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest007
552 * @tc.type: FUNC
553 */
554 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest007, TestSize.Level3)
555 {
556 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest007 start";
557 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
558 ASSERT_NE(imageSource, nullptr);
559 OH_DecodingOptions* ops = nullptr;
560 Image_Region desiredRegion = {0, 0, 0, 0};
561 Image_Region desiredRegion2 = {0, 0, 1920, 2160};
562 OH_DecodingOptions_Create(&ops);
563 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
564 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
565 ASSERT_EQ(desiredRegion.x, 0);
566 ASSERT_EQ(desiredRegion.y, 0);
567 ASSERT_EQ(desiredRegion.width, 1920);
568 ASSERT_EQ(desiredRegion.height, 2160);
569 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
570 OH_PixelmapNative* resPixMap = nullptr;
571 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
572 EXPECT_EQ(ret, IMAGE_SUCCESS);
573 OH_ImageSourceNative_Release(imageSource);
574 OH_DecodingOptions_Release(ops);
575 OH_PixelmapNative_Release(resPixMap);
576 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest007 end";
577 }
578
579 /**
580 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest008
581 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest008
582 * @tc.type: FUNC
583 */
584 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest008, TestSize.Level3)
585 {
586 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest008 start";
587 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
588 ASSERT_NE(imageSource, nullptr);
589 OH_DecodingOptions* ops = nullptr;
590 Image_Region desiredRegion = {0, 0, 0, 0};
591 Image_Region desiredRegion2 = {0, 0, 3840, 1080};
592 OH_DecodingOptions_Create(&ops);
593 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
594 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
595 ASSERT_EQ(desiredRegion.x, 0);
596 ASSERT_EQ(desiredRegion.y, 0);
597 ASSERT_EQ(desiredRegion.width, 3840);
598 ASSERT_EQ(desiredRegion.height, 1080);
599 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
600 OH_PixelmapNative* resPixMap = nullptr;
601 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
602 EXPECT_EQ(ret, IMAGE_SUCCESS);
603 OH_ImageSourceNative_Release(imageSource);
604 OH_DecodingOptions_Release(ops);
605 OH_PixelmapNative_Release(resPixMap);
606 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest008 end";
607 }
608
609 /**
610 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest009
611 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest009
612 * @tc.type: FUNC
613 */
614 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest009, TestSize.Level3)
615 {
616 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest009 start";
617 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
618 ASSERT_NE(imageSource, nullptr);
619 OH_DecodingOptions* ops = nullptr;
620 Image_Region desiredRegion = {0, 0, 0, 0};
621 Image_Region desiredRegion2 = {1920, 1080, 3840, 1080};
622 OH_DecodingOptions_Create(&ops);
623 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
624 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
625 ASSERT_EQ(desiredRegion.x, 1920);
626 ASSERT_EQ(desiredRegion.y, 1080);
627 ASSERT_EQ(desiredRegion.width, 3840);
628 ASSERT_EQ(desiredRegion.height, 1080);
629 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
630 OH_PixelmapNative* resPixMap = nullptr;
631 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
632 EXPECT_EQ(ret, IMAGE_SUCCESS);
633 OH_ImageSourceNative_Release(imageSource);
634 OH_DecodingOptions_Release(ops);
635 OH_PixelmapNative_Release(resPixMap);
636 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest009 end";
637 }
638
639 /**
640 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest010
641 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest010
642 * @tc.type: FUNC
643 */
644 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest010, TestSize.Level3)
645 {
646 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest010 start";
647 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
648 ASSERT_NE(imageSource, nullptr);
649 OH_DecodingOptions* ops = nullptr;
650 Image_Region desiredRegion = {0, 0, 0, 0};
651 Image_Region desiredRegion2 = {3840, 2160, 1920, 1080};
652 OH_DecodingOptions_Create(&ops);
653 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
654 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
655 ASSERT_EQ(desiredRegion.x, 3840);
656 ASSERT_EQ(desiredRegion.y, 2160);
657 ASSERT_EQ(desiredRegion.width, 1920);
658 ASSERT_EQ(desiredRegion.height, 1080);
659 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
660 OH_PixelmapNative* resPixMap = nullptr;
661 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
662 EXPECT_EQ(ret, IMAGE_SUCCESS);
663 OH_ImageSourceNative_Release(imageSource);
664 OH_DecodingOptions_Release(ops);
665 OH_PixelmapNative_Release(resPixMap);
666 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest010 end";
667 }
668
669 /**
670 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest011
671 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest011
672 * @tc.type: FUNC
673 */
674 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest011, TestSize.Level3)
675 {
676 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest011 start";
677 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
678 ASSERT_NE(imageSource, nullptr);
679 OH_DecodingOptions* ops = nullptr;
680 Image_Region desiredRegion = {0, 0, 0, 0};
681 Image_Region desiredRegion2 = {960, 540, 1920, 1080};
682 OH_DecodingOptions_Create(&ops);
683 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
684 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
685 ASSERT_EQ(desiredRegion.x, 960);
686 ASSERT_EQ(desiredRegion.y, 540);
687 ASSERT_EQ(desiredRegion.width, 1920);
688 ASSERT_EQ(desiredRegion.height, 1080);
689 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
690 OH_PixelmapNative* resPixMap = nullptr;
691 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
692 EXPECT_EQ(ret, IMAGE_SUCCESS);
693 OH_ImageSourceNative_Release(imageSource);
694 OH_DecodingOptions_Release(ops);
695 OH_PixelmapNative_Release(resPixMap);
696 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest011 end";
697 }
698
699 /**
700 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest012
701 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest012
702 * @tc.type: FUNC
703 */
704 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest012, TestSize.Level3)
705 {
706 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest012 start";
707 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
708 ASSERT_NE(imageSource, nullptr);
709 OH_DecodingOptions* ops = nullptr;
710 Image_Region desiredRegion = {0, 0, 0, 0};
711 Image_Region desiredRegion2 = {960, 540, 1920, 1080};
712 OH_DecodingOptions_Create(&ops);
713 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
714 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
715 ASSERT_EQ(desiredRegion.x, 960);
716 ASSERT_EQ(desiredRegion.y, 540);
717 ASSERT_EQ(desiredRegion.width, 1920);
718 ASSERT_EQ(desiredRegion.height, 1080);
719 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
720 OH_PixelmapNative* resPixMap = nullptr;
721 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
722 EXPECT_EQ(ret, IMAGE_SUCCESS);
723 OH_ImageSourceNative_Release(imageSource);
724 OH_DecodingOptions_Release(ops);
725 OH_PixelmapNative_Release(resPixMap);
726 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest012 end";
727 }
728
729 /**
730 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest013
731 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest013
732 * @tc.type: FUNC
733 */
734 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest013, TestSize.Level3)
735 {
736 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest013 start";
737 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
738 ASSERT_NE(imageSource, nullptr);
739 OH_DecodingOptions* ops = nullptr;
740 Image_Region desiredRegion = {0, 0, 0, 0};
741 Image_Region desiredRegion2 = {0, 0, 3840, 2160};
742 OH_DecodingOptions_Create(&ops);
743 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
744 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
745 ASSERT_EQ(desiredRegion.x, 0);
746 ASSERT_EQ(desiredRegion.y, 0);
747 ASSERT_EQ(desiredRegion.width, 3840);
748 ASSERT_EQ(desiredRegion.height, 2160);
749 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
750 OH_PixelmapNative* resPixMap = nullptr;
751 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
752 EXPECT_EQ(ret, IMAGE_SUCCESS);
753 OH_ImageSourceNative_Release(imageSource);
754 OH_DecodingOptions_Release(ops);
755 OH_PixelmapNative_Release(resPixMap);
756 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest013 end";
757 }
758
759 /**
760 * @tc.name: OH_ImageSourceNative_CreatePixelmapTest014
761 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapTest014
762 * @tc.type: FUNC
763 */
764 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapTest014, TestSize.Level3)
765 {
766 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest014 start";
767 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_PNG_PATH);
768 ASSERT_NE(imageSource, nullptr);
769 OH_DecodingOptions* ops = nullptr;
770 Image_Region desiredRegion = {0, 0, 0, 0};
771 Image_Region desiredRegion2 = {0, 0, 3840, 2160};
772 OH_DecodingOptions_Create(&ops);
773 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2);
774 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion);
775 ASSERT_EQ(desiredRegion.x, 0);
776 ASSERT_EQ(desiredRegion.y, 0);
777 ASSERT_EQ(desiredRegion.width, 3840);
778 ASSERT_EQ(desiredRegion.height, 2160);
779 OH_DecodingOptions_SetCropAndScaleStrategy(ops, 2);
780 OH_PixelmapNative* resPixMap = nullptr;
781 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap);
782 EXPECT_EQ(ret, IMAGE_SUCCESS);
783 OH_ImageSourceNative_Release(imageSource);
784 OH_DecodingOptions_Release(ops);
785 OH_PixelmapNative_Release(resPixMap);
786 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapTest014 end";
787 }
788
789 /**
790 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest001
791 * @tc.desc: Test create Pixelmap use DMA.
792 * @tc.type: FUNC
793 */
794 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest001, TestSize.Level1)
795 {
796 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
797 ASSERT_NE(imageSource, nullptr);
798 OH_DecodingOptions *opts = nullptr;
799 OH_DecodingOptions_Create(&opts);
800 ASSERT_NE(opts, nullptr);
801 OH_PixelmapNative* resPixMap = nullptr;
802 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
803 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
804 EXPECT_EQ(ret, IMAGE_SUCCESS);
805 EXPECT_NE(resPixMap, nullptr);
806 OH_ImageSourceNative_Release(imageSource);
807 OH_DecodingOptions_Release(opts);
808 OH_PixelmapNative_Release(resPixMap);
809 }
810
811 /**
812 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest002
813 * @tc.desc: Test create Pixelmap use SHARE_MEMORY.
814 * @tc.type: FUNC
815 */
816 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest002, TestSize.Level1)
817 {
818 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
819 ASSERT_NE(imageSource, nullptr);
820 OH_DecodingOptions *opts = nullptr;
821 OH_DecodingOptions_Create(&opts);
822 ASSERT_NE(opts, nullptr);
823 OH_PixelmapNative* resPixMap = nullptr;
824 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
825 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
826 EXPECT_EQ(ret, IMAGE_SUCCESS);
827 EXPECT_NE(resPixMap, nullptr);
828 OH_ImageSourceNative_Release(imageSource);
829 OH_DecodingOptions_Release(opts);
830 OH_PixelmapNative_Release(resPixMap);
831 }
832
833 /**
834 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest003
835 * @tc.desc: Test create Pixelmap if source is nullptr.
836 * @tc.type: FUNC
837 */
838 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest003, TestSize.Level1)
839 {
840 OH_ImageSourceNative *imageSource = nullptr;
841 OH_DecodingOptions* opts = nullptr;
842 OH_PixelmapNative* resPixMap = nullptr;
843 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
844 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
845 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
846 EXPECT_EQ(resPixMap, nullptr);
847 OH_ImageSourceNative_Release(imageSource);
848 }
849
850 /**
851 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest004
852 * @tc.desc: Test create Pixelmap if index is invalid.
853 * @tc.type: FUNC
854 */
855 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest004, TestSize.Level1)
856 {
857 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
858 ASSERT_NE(imageSource, nullptr);
859 OH_DecodingOptions *opts = nullptr;
860 OH_DecodingOptions_Create(&opts);
861 ASSERT_NE(opts, nullptr);
862 uint32_t tempIndex = INVALID_INDEX;
863 Image_ErrorCode ret = OH_DecodingOptions_SetIndex(opts, tempIndex);
864 OH_PixelmapNative* resPixMap = nullptr;
865 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
866 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
867 EXPECT_EQ(ret, IMAGE_DECODE_FAILED);
868 EXPECT_EQ(resPixMap, nullptr);
869 OH_ImageSourceNative_Release(imageSource);
870 OH_DecodingOptions_Release(opts);
871 }
872
873 /**
874 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest005
875 * @tc.desc: Test the creation of a pixelmap using AUTO allocator for JPEG image format, expecting success.
876 * @tc.type: FUNC
877 */
878 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest005, TestSize.Level1)
879 {
880 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
881 ASSERT_NE(imageSource, nullptr);
882 OH_DecodingOptions *opts = nullptr;
883 OH_DecodingOptions_Create(&opts);
884 ASSERT_NE(opts, nullptr);
885 OH_PixelmapNative* resPixMap = nullptr;
886 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_AUTO;
887 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
888 EXPECT_EQ(ret, IMAGE_SUCCESS);
889 EXPECT_NE(resPixMap, nullptr);
890 OH_ImageSourceNative_Release(imageSource);
891 OH_DecodingOptions_Release(opts);
892 OH_PixelmapNative_Release(resPixMap);
893 }
894
895 /**
896 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest006
897 * @tc.desc: Test the creation of a pixelmap using DMA allocator with invalid decoding options (nullptr) for JPEG image
898 * format, expecting IMAGE_BAD_PARAMETER error.
899 * @tc.type: FUNC
900 */
901 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest006, TestSize.Level1)
902 {
903 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
904 ASSERT_NE(imageSource, nullptr);
905 OH_DecodingOptions* opts = nullptr;
906 OH_PixelmapNative* resPixMap = nullptr;
907 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
908 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
909 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
910 EXPECT_EQ(resPixMap, nullptr);
911 OH_ImageSourceNative_Release(imageSource);
912 OH_DecodingOptions_Release(opts);
913 OH_PixelmapNative_Release(resPixMap);
914 }
915
916 /**
917 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest007
918 * @tc.desc: Test the creation of a pixelmap using DMA allocator, with NV21 pixel format for HEIF image format,
919 * expecting success.
920 * @tc.type: FUNC
921 */
922 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest007, TestSize.Level1)
923 {
924 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
925 ASSERT_NE(imageSource, nullptr);
926 OH_DecodingOptions *opts = nullptr;
927 OH_DecodingOptions_Create(&opts);
928 ASSERT_NE(opts, nullptr);
929 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
930 EXPECT_EQ(ret, IMAGE_SUCCESS);
931 OH_PixelmapNative* resPixMap = nullptr;
932 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
933 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
934 EXPECT_EQ(ret, IMAGE_SUCCESS);
935 EXPECT_NE(resPixMap, nullptr);
936 OH_ImageSourceNative_Release(imageSource);
937 OH_DecodingOptions_Release(opts);
938 OH_PixelmapNative_Release(resPixMap);
939 }
940
941 /**
942 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest008
943 * @tc.desc: Test the creation of a pixelmap using DMA allocator, with RGBA_8888 pixel format for HEIF image format,
944 * expecting success.
945 * @tc.type: FUNC
946 */
947 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest008, TestSize.Level1)
948 {
949 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
950 ASSERT_NE(imageSource, nullptr);
951 OH_DecodingOptions *opts = nullptr;
952 OH_DecodingOptions_Create(&opts);
953 ASSERT_NE(opts, nullptr);
954 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
955 EXPECT_EQ(ret, IMAGE_SUCCESS);
956 OH_PixelmapNative* resPixMap = nullptr;
957 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
958 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
959 EXPECT_EQ(ret, IMAGE_SUCCESS);
960 EXPECT_NE(resPixMap, nullptr);
961 OH_ImageSourceNative_Release(imageSource);
962 OH_DecodingOptions_Release(opts);
963 OH_PixelmapNative_Release(resPixMap);
964 }
965
966 /**
967 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest009
968 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with NV21 pixel format for HEIF image
969 * format, expecting unsupported operation.
970 * @tc.type: FUNC
971 */
972 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest009, TestSize.Level1)
973 {
974 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
975 ASSERT_NE(imageSource, nullptr);
976 OH_DecodingOptions *opts = nullptr;
977 OH_DecodingOptions_Create(&opts);
978 ASSERT_NE(opts, nullptr);
979 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
980 EXPECT_EQ(ret, IMAGE_SUCCESS);
981 OH_PixelmapNative* resPixMap = nullptr;
982 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
983 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
984 EXPECT_EQ(ret, IMAGE_SUCCESS);
985 EXPECT_NE(resPixMap, nullptr);
986 OH_ImageSourceNative_Release(imageSource);
987 OH_DecodingOptions_Release(opts);
988 OH_PixelmapNative_Release(resPixMap);
989 }
990
991 /**
992 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest010
993 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format for HEIF image
994 * format, expecting success.
995 * @tc.type: FUNC
996 */
997 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest010, TestSize.Level1)
998 {
999 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_PATH);
1000 ASSERT_NE(imageSource, nullptr);
1001 OH_DecodingOptions *opts = nullptr;
1002 OH_DecodingOptions_Create(&opts);
1003 ASSERT_NE(opts, nullptr);
1004 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1005 EXPECT_EQ(ret, IMAGE_SUCCESS);
1006 OH_PixelmapNative* resPixMap = nullptr;
1007 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1008 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1009 EXPECT_EQ(ret, IMAGE_SUCCESS);
1010 EXPECT_NE(resPixMap, nullptr);
1011 OH_ImageSourceNative_Release(imageSource);
1012 OH_DecodingOptions_Release(opts);
1013 OH_PixelmapNative_Release(resPixMap);
1014 }
1015
1016 /**
1017 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest011
1018 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format and HDR dynamic
1019 * range, expecting unsupported operation.
1020 * @tc.type: FUNC
1021 */
1022 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest011, TestSize.Level1)
1023 {
1024 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1025 ASSERT_NE(imageSource, nullptr);
1026 OH_DecodingOptions *opts = nullptr;
1027 OH_DecodingOptions_Create(&opts);
1028 ASSERT_NE(opts, nullptr);
1029 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1030 EXPECT_EQ(ret, IMAGE_SUCCESS);
1031 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1032 EXPECT_EQ(ret, IMAGE_SUCCESS);
1033 OH_PixelmapNative* resPixMap = nullptr;
1034 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1035 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1036 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1037 EXPECT_EQ(resPixMap, nullptr);
1038 OH_ImageSourceNative_Release(imageSource);
1039 OH_DecodingOptions_Release(opts);
1040 OH_PixelmapNative_Release(resPixMap);
1041 }
1042
1043 /**
1044 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest012
1045 * @tc.desc: Test the creation of a pixelmap using shared memory allocator, with RGBA_8888 pixel format and auto
1046 * dynamic range, expecting unsupported operation.
1047 * @tc.type: FUNC
1048 */
1049 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest012, TestSize.Level1)
1050 {
1051 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1052 ASSERT_NE(imageSource, nullptr);
1053 OH_DecodingOptions *opts = nullptr;
1054 OH_DecodingOptions_Create(&opts);
1055 ASSERT_NE(opts, nullptr);
1056 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1057 EXPECT_EQ(ret, IMAGE_SUCCESS);
1058 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1059 EXPECT_EQ(ret, IMAGE_SUCCESS);
1060 OH_PixelmapNative* resPixMap = nullptr;
1061 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1062 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1063 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1064 EXPECT_EQ(resPixMap, nullptr);
1065 OH_ImageSourceNative_Release(imageSource);
1066 OH_DecodingOptions_Release(opts);
1067 OH_PixelmapNative_Release(resPixMap);
1068 }
1069
1070 /**
1071 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest013
1072 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and HDR dynamic range,
1073 * expecting successful operation.
1074 * @tc.type: FUNC
1075 */
1076 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest013, TestSize.Level1)
1077 {
1078 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1079 ASSERT_NE(imageSource, nullptr);
1080 OH_DecodingOptions *opts = nullptr;
1081 OH_DecodingOptions_Create(&opts);
1082 ASSERT_NE(opts, nullptr);
1083 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1084 EXPECT_EQ(ret, IMAGE_SUCCESS);
1085 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1086 EXPECT_EQ(ret, IMAGE_SUCCESS);
1087 OH_PixelmapNative* resPixMap = nullptr;
1088 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1089 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1090 EXPECT_EQ(ret, IMAGE_SUCCESS);
1091 EXPECT_NE(resPixMap, nullptr);
1092 OH_ImageSourceNative_Release(imageSource);
1093 OH_DecodingOptions_Release(opts);
1094 OH_PixelmapNative_Release(resPixMap);
1095 }
1096
1097 /**
1098 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest014
1099 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and auto dynamic range,
1100 * expecting successful operation.
1101 * @tc.type: FUNC
1102 */
1103 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest014, TestSize.Level1)
1104 {
1105 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1106 ASSERT_NE(imageSource, nullptr);
1107 OH_DecodingOptions *opts = nullptr;
1108 OH_DecodingOptions_Create(&opts);
1109 ASSERT_NE(opts, nullptr);
1110 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1111 EXPECT_EQ(ret, IMAGE_SUCCESS);
1112 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1113 EXPECT_EQ(ret, IMAGE_SUCCESS);
1114 OH_PixelmapNative* resPixMap = nullptr;
1115 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1116 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1117 EXPECT_EQ(ret, IMAGE_SUCCESS);
1118 EXPECT_NE(resPixMap, nullptr);
1119 OH_ImageSourceNative_Release(imageSource);
1120 OH_DecodingOptions_Release(opts);
1121 OH_PixelmapNative_Release(resPixMap);
1122 }
1123
1124 /**
1125 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest015
1126 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and HDR dynamic range,
1127 * expecting successful operation.
1128 * @tc.type: FUNC
1129 */
1130 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest015, TestSize.Level1)
1131 {
1132 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1133 ASSERT_NE(imageSource, nullptr);
1134 OH_DecodingOptions *opts = nullptr;
1135 OH_DecodingOptions_Create(&opts);
1136 ASSERT_NE(opts, nullptr);
1137 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1138 EXPECT_EQ(ret, IMAGE_SUCCESS);
1139 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1140 EXPECT_EQ(ret, IMAGE_SUCCESS);
1141 OH_PixelmapNative* resPixMap = nullptr;
1142 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1143 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1144 EXPECT_EQ(ret, IMAGE_SUCCESS);
1145 EXPECT_NE(resPixMap, nullptr);
1146 OH_ImageSourceNative_Release(imageSource);
1147 OH_DecodingOptions_Release(opts);
1148 OH_PixelmapNative_Release(resPixMap);
1149 }
1150
1151 /**
1152 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest016
1153 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and auto dynamic range,
1154 * expecting successful operation.
1155 * @tc.type: FUNC
1156 */
1157 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest016, TestSize.Level1)
1158 {
1159 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1160 ASSERT_NE(imageSource, nullptr);
1161 OH_DecodingOptions *opts = nullptr;
1162 OH_DecodingOptions_Create(&opts);
1163 ASSERT_NE(opts, nullptr);
1164 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1165 EXPECT_EQ(ret, IMAGE_SUCCESS);
1166 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1167 EXPECT_EQ(ret, IMAGE_SUCCESS);
1168 OH_PixelmapNative* resPixMap = nullptr;
1169 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1170 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1171 EXPECT_EQ(ret, IMAGE_SUCCESS);
1172 EXPECT_NE(resPixMap, nullptr);
1173 OH_ImageSourceNative_Release(imageSource);
1174 OH_DecodingOptions_Release(opts);
1175 OH_PixelmapNative_Release(resPixMap);
1176 }
1177
1178 /**
1179 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest017
1180 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and HDR dynamic
1181 * range, expecting unsupported operation.
1182 * @tc.type: FUNC
1183 */
1184 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest017, TestSize.Level1)
1185 {
1186 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1187 ASSERT_NE(imageSource, nullptr);
1188 OH_DecodingOptions *opts = nullptr;
1189 OH_DecodingOptions_Create(&opts);
1190 ASSERT_NE(opts, nullptr);
1191 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1192 EXPECT_EQ(ret, IMAGE_SUCCESS);
1193 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1194 EXPECT_EQ(ret, IMAGE_SUCCESS);
1195 OH_PixelmapNative* resPixMap = nullptr;
1196 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1197 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1198 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1199 EXPECT_EQ(resPixMap, nullptr);
1200 OH_ImageSourceNative_Release(imageSource);
1201 OH_DecodingOptions_Release(opts);
1202 OH_PixelmapNative_Release(resPixMap);
1203 }
1204
1205 /**
1206 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest018
1207 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and auto
1208 * dynamic range, expecting unsupported operation.
1209 * @tc.type: FUNC
1210 */
1211 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest018, TestSize.Level1)
1212 {
1213 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_HDR_PATH);
1214 ASSERT_NE(imageSource, nullptr);
1215 OH_DecodingOptions *opts = nullptr;
1216 OH_DecodingOptions_Create(&opts);
1217 ASSERT_NE(opts, nullptr);
1218 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1219 EXPECT_EQ(ret, IMAGE_SUCCESS);
1220 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1221 EXPECT_EQ(ret, IMAGE_SUCCESS);
1222 OH_PixelmapNative* resPixMap = nullptr;
1223 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1224 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1225 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1226 EXPECT_EQ(resPixMap, nullptr);
1227 OH_ImageSourceNative_Release(imageSource);
1228 OH_DecodingOptions_Release(opts);
1229 OH_PixelmapNative_Release(resPixMap);
1230 }
1231
1232 /**
1233 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest019
1234 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with RGBA_8888 pixel format and HDR
1235 * dynamic range, expecting unsupported operation.
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest019, TestSize.Level1)
1239 {
1240 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1241 ASSERT_NE(imageSource, nullptr);
1242 OH_DecodingOptions *opts = nullptr;
1243 OH_DecodingOptions_Create(&opts);
1244 ASSERT_NE(opts, nullptr);
1245 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1246 EXPECT_EQ(ret, IMAGE_SUCCESS);
1247 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1248 EXPECT_EQ(ret, IMAGE_SUCCESS);
1249 OH_PixelmapNative* resPixMap = nullptr;
1250 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1251 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1252 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1253 EXPECT_EQ(resPixMap, nullptr);
1254 OH_ImageSourceNative_Release(imageSource);
1255 OH_DecodingOptions_Release(opts);
1256 OH_PixelmapNative_Release(resPixMap);
1257 }
1258
1259 /**
1260 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest020
1261 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with RGBA_8888 pixel format and auto
1262 * dynamic range, expecting unsupported operation.
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest020, TestSize.Level1)
1266 {
1267 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1268 ASSERT_NE(imageSource, nullptr);
1269 OH_DecodingOptions *opts = nullptr;
1270 OH_DecodingOptions_Create(&opts);
1271 ASSERT_NE(opts, nullptr);
1272 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1273 EXPECT_EQ(ret, IMAGE_SUCCESS);
1274 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1275 EXPECT_EQ(ret, IMAGE_SUCCESS);
1276 OH_PixelmapNative* resPixMap = nullptr;
1277 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1278 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1279 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1280 EXPECT_EQ(resPixMap, nullptr);
1281 OH_ImageSourceNative_Release(imageSource);
1282 OH_DecodingOptions_Release(opts);
1283 OH_PixelmapNative_Release(resPixMap);
1284 }
1285
1286 /**
1287 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest021
1288 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and HDR dynamic range.
1289 * @tc.type: FUNC
1290 */
1291 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest021, TestSize.Level1)
1292 {
1293 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1294 ASSERT_NE(imageSource, nullptr);
1295 OH_DecodingOptions *opts = nullptr;
1296 OH_DecodingOptions_Create(&opts);
1297 ASSERT_NE(opts, nullptr);
1298 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1299 EXPECT_EQ(ret, IMAGE_SUCCESS);
1300 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1301 EXPECT_EQ(ret, IMAGE_SUCCESS);
1302 OH_PixelmapNative* resPixMap = nullptr;
1303 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1304 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1305 EXPECT_EQ(ret, IMAGE_SUCCESS);
1306 EXPECT_NE(resPixMap, nullptr);
1307 OH_ImageSourceNative_Release(imageSource);
1308 OH_DecodingOptions_Release(opts);
1309 OH_PixelmapNative_Release(resPixMap);
1310 }
1311
1312 /**
1313 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest022
1314 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with RGBA_8888 pixel format and auto dynamic range.
1315 * @tc.type: FUNC
1316 */
1317 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest022, TestSize.Level1)
1318 {
1319 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1320 ASSERT_NE(imageSource, nullptr);
1321 OH_DecodingOptions *opts = nullptr;
1322 OH_DecodingOptions_Create(&opts);
1323 ASSERT_NE(opts, nullptr);
1324 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_RGBA_8888);
1325 EXPECT_EQ(ret, IMAGE_SUCCESS);
1326 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1327 EXPECT_EQ(ret, IMAGE_SUCCESS);
1328 OH_PixelmapNative* resPixMap = nullptr;
1329 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1330 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1331 EXPECT_EQ(ret, IMAGE_SUCCESS);
1332 EXPECT_NE(resPixMap, nullptr);
1333 OH_ImageSourceNative_Release(imageSource);
1334 OH_DecodingOptions_Release(opts);
1335 OH_PixelmapNative_Release(resPixMap);
1336 }
1337
1338 /**
1339 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest023
1340 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and HDR dynamic range.
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest023, TestSize.Level1)
1344 {
1345 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1346 ASSERT_NE(imageSource, nullptr);
1347 OH_DecodingOptions *opts = nullptr;
1348 OH_DecodingOptions_Create(&opts);
1349 ASSERT_NE(opts, nullptr);
1350 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1351 EXPECT_EQ(ret, IMAGE_SUCCESS);
1352 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1353 EXPECT_EQ(ret, IMAGE_SUCCESS);
1354 OH_PixelmapNative* resPixMap = nullptr;
1355 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1356 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1357 EXPECT_EQ(ret, IMAGE_SUCCESS);
1358 EXPECT_NE(resPixMap, nullptr);
1359 OH_ImageSourceNative_Release(imageSource);
1360 OH_DecodingOptions_Release(opts);
1361 OH_PixelmapNative_Release(resPixMap);
1362 }
1363
1364 /**
1365 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest024
1366 * @tc.desc: Test the creation of a pixelmap using a DMA allocator, with NV21 pixel format and auto dynamic range.
1367 * @tc.type: FUNC
1368 */
1369 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest024, TestSize.Level1)
1370 {
1371 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1372 ASSERT_NE(imageSource, nullptr);
1373 OH_DecodingOptions *opts = nullptr;
1374 OH_DecodingOptions_Create(&opts);
1375 ASSERT_NE(opts, nullptr);
1376 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1377 EXPECT_EQ(ret, IMAGE_SUCCESS);
1378 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1379 EXPECT_EQ(ret, IMAGE_SUCCESS);
1380 OH_PixelmapNative* resPixMap = nullptr;
1381 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_DMA;
1382 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1383 EXPECT_EQ(ret, IMAGE_SUCCESS);
1384 EXPECT_NE(resPixMap, nullptr);
1385 OH_ImageSourceNative_Release(imageSource);
1386 OH_DecodingOptions_Release(opts);
1387 OH_PixelmapNative_Release(resPixMap);
1388 }
1389
1390 /**
1391 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest025
1392 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with HDR dynamic range.
1393 * @tc.type: FUNC
1394 */
1395 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest025, TestSize.Level1)
1396 {
1397 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1398 ASSERT_NE(imageSource, nullptr);
1399 OH_DecodingOptions *opts = nullptr;
1400 OH_DecodingOptions_Create(&opts);
1401 ASSERT_NE(opts, nullptr);
1402 auto ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_HDR);
1403 EXPECT_EQ(ret, IMAGE_SUCCESS);
1404 OH_PixelmapNative* resPixMap = nullptr;
1405 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1406 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1407 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1408 EXPECT_EQ(resPixMap, nullptr);
1409 OH_ImageSourceNative_Release(imageSource);
1410 OH_DecodingOptions_Release(opts);
1411 OH_PixelmapNative_Release(resPixMap);
1412 }
1413
1414 /**
1415 * @tc.name: OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest026
1416 * @tc.desc: Test the creation of a pixelmap using a shared memory allocator, with NV21 pixel format and auto
1417 * dynamic range.
1418 * @tc.type: FUNC
1419 */
1420 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapUsingAllocatorTest026, TestSize.Level1)
1421 {
1422 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_HEIF_HDR_PATH);
1423 ASSERT_NE(imageSource, nullptr);
1424 OH_DecodingOptions *opts = nullptr;
1425 OH_DecodingOptions_Create(&opts);
1426 ASSERT_NE(opts, nullptr);
1427 Image_ErrorCode ret = OH_DecodingOptions_SetPixelFormat(opts, PIXEL_FORMAT_NV21);
1428 ASSERT_EQ(ret, IMAGE_SUCCESS);
1429 ret = OH_DecodingOptions_SetDesiredDynamicRange(opts, IMAGE_DYNAMIC_RANGE::IMAGE_DYNAMIC_RANGE_AUTO);
1430 ASSERT_EQ(ret, IMAGE_SUCCESS);
1431 OH_PixelmapNative* resPixMap = nullptr;
1432 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1433 ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1434 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_ALLOCATOR_TYPE);
1435 EXPECT_EQ(resPixMap, nullptr);
1436 OH_ImageSourceNative_Release(imageSource);
1437 OH_DecodingOptions_Release(opts);
1438 OH_PixelmapNative_Release(resPixMap);
1439 }
1440
1441 /**
1442 * @tc.name: OH_ImageSourceNative_CreatePixelmapList
1443 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapList
1444 * @tc.type: FUNC
1445 */
1446 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapList, TestSize.Level3)
1447 {
1448 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList start";
1449 OH_DecodingOptions *ops = nullptr;
1450 OH_ImageSourceNative *imageSource = nullptr;
1451 OH_PixelmapNative** resVecPixMap = nullptr;
1452 size_t outSize = 0;
1453 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapList(imageSource, ops, resVecPixMap, outSize);
1454 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1455 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList end";
1456 }
1457
1458 /**
1459 * @tc.name: OH_ImageSourceNative_GetDelayTimeList
1460 * @tc.desc: test OH_ImageSourceNative_GetDelayTimeList
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetDelayTimeList, TestSize.Level3)
1464 {
1465 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList start";
1466 OH_ImageSourceNative *imageSource = nullptr;
1467 int32_t* delayTimeList = nullptr;
1468 size_t size = 0;
1469 Image_ErrorCode ret = OH_ImageSourceNative_GetDelayTimeList(imageSource, delayTimeList, size);
1470 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1471 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList end";
1472 }
1473
1474 /**
1475 * @tc.name: OH_ImageSourceNative_GetImageInfo
1476 * @tc.desc: test OH_ImageSourceNative_GetImageInfo
1477 * @tc.type: FUNC
1478 */
1479 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageInfo, TestSize.Level3)
1480 {
1481 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo start";
1482 OH_ImageSourceNative *imageSource = nullptr;
1483 int32_t index = 0;
1484 OH_ImageSource_Info* info = nullptr;
1485 Image_ErrorCode ret = OH_ImageSourceNative_GetImageInfo(imageSource, index, info);
1486 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1487 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo end";
1488 }
1489
1490 /**
1491 * @tc.name: OH_ImageSourceNative_GetImageProperty
1492 * @tc.desc: test OH_ImageSourceNative_GetImageProperty
1493 * @tc.type: FUNC
1494 */
1495 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageProperty, TestSize.Level3)
1496 {
1497 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty start";
1498 OH_ImageSourceNative *imageSource = nullptr;
1499 Image_String* key = nullptr;
1500 Image_String* value = nullptr;
1501 Image_ErrorCode ret = OH_ImageSourceNative_GetImageProperty(imageSource, key, value);
1502 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1503 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty end";
1504 }
1505
1506 /**
1507 * @tc.name: OH_ImageSourceNative_ModifyImageProperty
1508 * @tc.desc: test OH_ImageSourceNative_ModifyImageProperty
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_ModifyImageProperty, TestSize.Level3)
1512 {
1513 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty start";
1514 OH_ImageSourceNative *imageSource = nullptr;
1515 Image_String* key = nullptr;
1516 Image_String* value = nullptr;
1517 Image_ErrorCode ret = OH_ImageSourceNative_ModifyImageProperty(imageSource, key, value);
1518 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1519 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty end";
1520 }
1521
1522 /**
1523 * @tc.name: OH_ImageSourceNative_GetFrameCount
1524 * @tc.desc: test OH_ImageSourceNative_GetFrameCount
1525 * @tc.type: FUNC
1526 */
1527 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetFrameCount, TestSize.Level3)
1528 {
1529 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount start";
1530 OH_ImageSourceNative *imageSource = nullptr;
1531 uint32_t* res = nullptr;
1532 Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, res);
1533 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1534 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount end";
1535 }
1536
1537 /**
1538 * @tc.name: OH_ImageSourceNative_Release
1539 * @tc.desc: test OH_ImageSourceNative_Release
1540 * @tc.type: FUNC
1541 */
1542 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_Release, TestSize.Level3)
1543 {
1544 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release start";
1545 OH_ImageSourceNative *imageSource = nullptr;
1546 Image_ErrorCode ret = OH_ImageSourceNative_Release(imageSource);
1547 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1548 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release end";
1549 }
1550
1551 /**
1552 * @tc.name: OH_ImageSourceInfo_GetMimeType001
1553 * @tc.desc: Verify that OH_ImageSourceInfo_GetMimeType correctly handles null input parameters by returning
1554 * IMAGE_SOURCE_INVALID_PARAMETER when either info or mimeType output pointer is null.
1555 * @tc.type: FUNC
1556 */
1557 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetMimeType001, TestSize.Level3)
1558 {
1559 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetMimeType001 start";
1560 OH_ImageSource_Info *info1 = nullptr;
1561 Image_ErrorCode ret = OH_ImageSourceInfo_Create(&info1);
1562 ASSERT_EQ(ret, IMAGE_SUCCESS);
1563 ASSERT_NE(info1, nullptr);
1564 OH_ImageSource_Info *info2 = nullptr;
1565
1566 Image_MimeType mimeType1;
1567 Image_MimeType *mimeType2 = nullptr;
1568 ret = OH_ImageSourceInfo_GetMimeType(info2, &mimeType1);
1569 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
1570 ret = OH_ImageSourceInfo_GetMimeType(info1, mimeType2);
1571 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
1572 ret = OH_ImageSourceInfo_GetMimeType(info2, mimeType2);
1573 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
1574
1575 ret = OH_ImageSourceInfo_Release(info1);
1576 EXPECT_EQ(ret, IMAGE_SUCCESS);
1577 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetMimeType001 end";
1578 }
1579
1580 /**
1581 * @tc.name: OH_ImageSourceInfo_GetMimeType002
1582 * @tc.desc: Verify that OH_ImageSourceInfo_GetMimeType can correctly get the MIME type (JPEG in this case)
1583 * from an image source.
1584 * @tc.type: FUNC
1585 */
1586 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetMimeType002, TestSize.Level3)
1587 {
1588 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetMimeType002 start";
1589 size_t length = IMAGE_JPEG_PATH_TEST.size();
1590 char filePath[length + 1];
1591 strcpy_s(filePath, sizeof(filePath), IMAGE_JPEG_PATH_TEST.c_str());
1592
1593 OH_ImageSourceNative *source = nullptr;
1594 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(filePath, length, &source);
1595 EXPECT_EQ(ret, IMAGE_SUCCESS);
1596 ASSERT_NE(source, nullptr);
1597
1598 OH_ImageSource_Info *info = nullptr;
1599 ret = OH_ImageSourceInfo_Create(&info);
1600 ASSERT_EQ(ret, IMAGE_SUCCESS);
1601 int32_t index = 0;
1602 ret = OH_ImageSourceNative_GetImageInfo(source, index, info);
1603 ASSERT_EQ(ret, IMAGE_SUCCESS);
1604
1605 Image_MimeType mimeType;
1606 ret = OH_ImageSourceInfo_GetMimeType(info, &mimeType);
1607 EXPECT_EQ(ret, IMAGE_SUCCESS);
1608 ASSERT_NE(mimeType.data, nullptr);
1609 EXPECT_EQ(strcmp(mimeType.data, IMAGE_JPEG_FORMAT.c_str()), 0);
1610 ret = OH_ImageSourceNative_Release(source);
1611 EXPECT_EQ(ret, IMAGE_SUCCESS);
1612 ret = OH_ImageSourceInfo_Release(info);
1613 EXPECT_EQ(ret, IMAGE_SUCCESS);
1614 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetMimeType002 end";
1615 }
1616
1617 /**
1618 * @tc.name: OH_DecodingOptionsForPicture_CreateTest001
1619 * @tc.desc: Tests the creation of decoding options for a picture.
1620 * The test checks if the decoding options are created successfully.
1621 * @tc.type: FUNC
1622 */
1623 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptionsForPicture_CreateTest001, TestSize.Level1)
1624 {
1625 OH_DecodingOptionsForPicture *options = nullptr;
1626 Image_ErrorCode ret;
1627 ret = OH_DecodingOptionsForPicture_Create(&options);
1628 EXPECT_EQ(ret, IMAGE_SUCCESS);
1629 ret = OH_DecodingOptionsForPicture_Release(options);
1630 EXPECT_EQ(ret, IMAGE_SUCCESS);
1631 }
1632
1633 /**
1634 * @tc.name: OH_DecodingOptionsForPicture_ReleaseTest001
1635 * @tc.desc: test OH_DecodingOptionsForPicture_Release with a null pointer.
1636 * @tc.type: FUNC
1637 */
1638 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptionsForPicture_ReleaseTest001, TestSize.Level3)
1639 {
1640 Image_ErrorCode ret = OH_DecodingOptionsForPicture_Release(nullptr);
1641 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
1642 }
1643
1644 /**
1645 * @tc.name: OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPicturesTest001
1646 * @tc.desc: Tests getting the desired auxiliary pictures from decoding options.
1647 * The test checks if the set and get functions work correctly.
1648 * @tc.type: FUNC
1649 */
1650 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPicturesTest001, TestSize.Level1)
1651 {
1652 OH_DecodingOptionsForPicture *options = nullptr;
1653 Image_ErrorCode ret = OH_DecodingOptionsForPicture_Create(&options);
1654 EXPECT_EQ(ret, IMAGE_SUCCESS);
1655 ASSERT_NE(options, nullptr);
1656 size_t srcLength = TestLength;
1657 Image_AuxiliaryPictureType srcAuxTypeList[srcLength];
1658 srcAuxTypeList[0] = AUXILIARY_PICTURE_TYPE_GAINMAP;
1659 srcAuxTypeList[1] = AUXILIARY_PICTURE_TYPE_DEPTH_MAP;
1660 OH_DecodingOptionsForPicture_SetDesiredAuxiliaryPictures(options, srcAuxTypeList, srcLength);
1661 Image_AuxiliaryPictureType *dstAuxTypeList = nullptr;
1662 size_t dstLength = 0;
1663 ret = OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPictures(options, &dstAuxTypeList, &dstLength);
1664 EXPECT_EQ(ret, IMAGE_SUCCESS);
1665 ASSERT_NE(dstAuxTypeList, nullptr);
1666 EXPECT_EQ(srcLength, dstLength);
1667 for (size_t index = 0; index < srcLength; index++) {
1668 EXPECT_EQ(srcAuxTypeList[index], dstAuxTypeList[index]);
1669 }
1670 delete[] dstAuxTypeList;
1671 ret = OH_DecodingOptionsForPicture_Release(options);
1672 EXPECT_EQ(ret, IMAGE_SUCCESS);
1673 }
1674
1675 /**
1676 * @tc.name: OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPicturesTest002
1677 * @tc.desc: test OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPictures with null pointers.
1678 * @tc.type: FUNC
1679 */
1680 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPicturesTest002, TestSize.Level3)
1681 {
1682 Image_ErrorCode ret = OH_DecodingOptionsForPicture_GetDesiredAuxiliaryPictures(nullptr, nullptr, nullptr);
1683 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
1684 }
1685
1686 /**
1687 * @tc.name: OH_DecodingOptionsForPicture_SetDesiredAuxiliaryPicturesTest001
1688 * @tc.desc: test OH_DecodingOptionsForPicture_SetDesiredAuxiliaryPictures with null pointers.
1689 * @tc.type: FUNC
1690 */
1691 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptionsForPicture_SetDesiredAuxiliaryPicturesTest001, TestSize.Level3)
1692 {
1693 Image_ErrorCode ret = OH_DecodingOptionsForPicture_SetDesiredAuxiliaryPictures(nullptr, nullptr, 0);
1694 EXPECT_EQ(ret, IMAGE_BAD_PARAMETER);
1695 }
1696
1697 /**
1698 * @tc.name: OH_ImageSourceNative_CreatePictureTest001
1699 * @tc.desc: test OH_ImageSourceNative_CreatePicture with null pointers.
1700 * @tc.type: FUNC
1701 */
1702 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureTest001, TestSize.Level3)
1703 {
1704 OH_ImageSourceNative *source = nullptr;
1705 OH_DecodingOptionsForPicture *options = nullptr;
1706 OH_PictureNative **picture = nullptr;
1707 Image_ErrorCode ret = OH_ImageSourceNative_CreatePicture(source, options, picture);
1708 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER);
1709 }
1710
1711 /**
1712 * @tc.name: OH_ImageSourceNative_CreatePictureTest002
1713 * @tc.desc: Tests creating an image from a raw buffer and then extracting a picture from it.
1714 * The test checks if the creation and release of resources are successful
1715 * @tc.type: FUNC
1716 */
1717 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureTest002, TestSize.Level1)
1718 {
1719 size_t length = IMAGE_JPEG_PATH.size();
1720 char filePath[length + 1];
1721 strcpy_s(filePath, sizeof(filePath), IMAGE_JPEG_PATH.c_str());
1722
1723 OH_ImageSourceNative *source = nullptr;
1724 OH_DecodingOptionsForPicture *options = nullptr;
1725 OH_PictureNative *picture = nullptr;
1726 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(filePath, length, &source);
1727 EXPECT_EQ(ret, IMAGE_SUCCESS);
1728 ASSERT_NE(source, nullptr);
1729
1730 ret = OH_DecodingOptionsForPicture_Create(&options);
1731 EXPECT_EQ(ret, IMAGE_SUCCESS);
1732 ASSERT_NE(options, nullptr);
1733
1734 ret = OH_ImageSourceNative_CreatePicture(source, options, &picture);
1735 ASSERT_EQ(ret, IMAGE_SUCCESS);
1736 ASSERT_NE(picture, nullptr);
1737
1738 ret = OH_ImageSourceNative_Release(source);
1739 ASSERT_EQ(ret, IMAGE_SUCCESS);
1740 ret = OH_DecodingOptionsForPicture_Release(options);
1741 ASSERT_EQ(ret, IMAGE_SUCCESS);
1742 OH_PictureNative_Release(picture);
1743 ASSERT_EQ(ret, IMAGE_SUCCESS);
1744 }
1745
1746 /**
1747 * @tc.name: ImageRegionDecode001
1748 * @tc.desc: Test Region decode, CropAndScaleStrategy is DEFAULT, Showing the original image.
1749 * @tc.type: FUNC
1750 */
1751 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode001, TestSize.Level3)
1752 {
1753 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1754 ASSERT_NE(imageSource, nullptr);
1755 OH_DecodingOptions *opts = nullptr;
1756 OH_DecodingOptions_Create(&opts);
1757 ASSERT_NE(opts, nullptr);
1758 OH_PixelmapNative* resPixMap = nullptr;
1759 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1760 Image_Region desiredRegion = {0, 0, 1920, 1080};
1761 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1762 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1763 EXPECT_EQ(ret, IMAGE_SUCCESS);
1764 EXPECT_NE(resPixMap, nullptr);
1765 OH_ImageSourceNative_Release(imageSource);
1766 OH_DecodingOptions_Release(opts);
1767 OH_PixelmapNative_Release(resPixMap);
1768 }
1769
1770 /**
1771 * @tc.name: ImageRegionDecode002
1772 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing the original image.
1773 * @tc.type: FUNC
1774 */
1775 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode002, TestSize.Level3)
1776 {
1777 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1778 ASSERT_NE(imageSource, nullptr);
1779 OH_DecodingOptions *opts = nullptr;
1780 OH_DecodingOptions_Create(&opts);
1781 ASSERT_NE(opts, nullptr);
1782 OH_PixelmapNative* resPixMap = nullptr;
1783 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1784 Image_Region desiredRegion = {0, 0, 1000, 1000};
1785 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1786 int32_t cropAndScaleStrategy = 1;
1787 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1788 Image_Size desiredSize = {1000, 1000};
1789 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1790 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1791 EXPECT_EQ(ret, IMAGE_SUCCESS);
1792 EXPECT_NE(resPixMap, nullptr);
1793 OH_ImageSourceNative_Release(imageSource);
1794 OH_DecodingOptions_Release(opts);
1795 OH_PixelmapNative_Release(resPixMap);
1796 }
1797
1798 /**
1799 * @tc.name: ImageRegionDecode003
1800 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing the left half image.
1801 * @tc.type: FUNC
1802 */
1803 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode003, TestSize.Level3)
1804 {
1805 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1806 ASSERT_NE(imageSource, nullptr);
1807 OH_DecodingOptions *opts = nullptr;
1808 OH_DecodingOptions_Create(&opts);
1809 ASSERT_NE(opts, nullptr);
1810 OH_PixelmapNative* resPixMap = nullptr;
1811 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1812 Image_Region desiredRegion = {0, 0, 500, 1000};
1813 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1814 int32_t cropAndScaleStrategy = 1;
1815 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1816 Image_Size desiredSize = {1000, 1000};
1817 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1818 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1819 EXPECT_EQ(ret, IMAGE_SUCCESS);
1820 EXPECT_NE(resPixMap, nullptr);
1821 OH_ImageSourceNative_Release(imageSource);
1822 OH_DecodingOptions_Release(opts);
1823 OH_PixelmapNative_Release(resPixMap);
1824 }
1825
1826 /**
1827 * @tc.name: ImageRegionDecode004
1828 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing the top half image.
1829 * @tc.type: FUNC
1830 */
1831 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode004, TestSize.Level3)
1832 {
1833 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1834 ASSERT_NE(imageSource, nullptr);
1835 OH_DecodingOptions *opts = nullptr;
1836 OH_DecodingOptions_Create(&opts);
1837 ASSERT_NE(opts, nullptr);
1838 OH_PixelmapNative* resPixMap = nullptr;
1839 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1840 Image_Region desiredRegion = {0, 0, 1000, 500};
1841 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1842 int32_t cropAndScaleStrategy = 1;
1843 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1844 Image_Size desiredSize = {1000, 1000};
1845 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1846 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1847 EXPECT_EQ(ret, IMAGE_SUCCESS);
1848 EXPECT_NE(resPixMap, nullptr);
1849 OH_ImageSourceNative_Release(imageSource);
1850 OH_DecodingOptions_Release(opts);
1851 OH_PixelmapNative_Release(resPixMap);
1852 }
1853
1854 /**
1855 * @tc.name: ImageRegionDecode005
1856 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing the right bottom image.
1857 * @tc.type: FUNC
1858 */
1859 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode005, TestSize.Level3)
1860 {
1861 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1862 ASSERT_NE(imageSource, nullptr);
1863 OH_DecodingOptions *opts = nullptr;
1864 OH_DecodingOptions_Create(&opts);
1865 ASSERT_NE(opts, nullptr);
1866 OH_PixelmapNative* resPixMap = nullptr;
1867 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1868 Image_Region desiredRegion = {500, 500, 500, 500};
1869 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1870 int32_t cropAndScaleStrategy = 1;
1871 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1872 Image_Size desiredSize = {1000, 1000};
1873 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1874 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1875 EXPECT_EQ(ret, IMAGE_SUCCESS);
1876 EXPECT_NE(resPixMap, nullptr);
1877 OH_ImageSourceNative_Release(imageSource);
1878 OH_DecodingOptions_Release(opts);
1879 OH_PixelmapNative_Release(resPixMap);
1880 }
1881
1882 /**
1883 * @tc.name: ImageRegionDecode006
1884 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing NULL.
1885 * @tc.type: FUNC
1886 */
1887 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode006, TestSize.Level3)
1888 {
1889 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1890 ASSERT_NE(imageSource, nullptr);
1891 OH_DecodingOptions *opts = nullptr;
1892 OH_DecodingOptions_Create(&opts);
1893 ASSERT_NE(opts, nullptr);
1894 OH_PixelmapNative* resPixMap = nullptr;
1895 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1896 Image_Region desiredRegion = {500, 500, 1000, 500};
1897 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1898 int32_t cropAndScaleStrategy = 1;
1899 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1900 Image_Size desiredSize = {1000, 1000};
1901 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1902 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1903 EXPECT_NE(ret, IMAGE_SUCCESS);
1904 EXPECT_EQ(resPixMap, nullptr);
1905 OH_ImageSourceNative_Release(imageSource);
1906 OH_DecodingOptions_Release(opts);
1907 OH_PixelmapNative_Release(resPixMap);
1908 }
1909
1910 /**
1911 * @tc.name: ImageRegionDecode007
1912 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing NULL.
1913 * @tc.type: FUNC
1914 */
1915 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode007, TestSize.Level3)
1916 {
1917 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1918 ASSERT_NE(imageSource, nullptr);
1919 OH_DecodingOptions *opts = nullptr;
1920 OH_DecodingOptions_Create(&opts);
1921 ASSERT_NE(opts, nullptr);
1922 OH_PixelmapNative* resPixMap = nullptr;
1923 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1924 Image_Region desiredRegion = {1000, 1000, 500, 500};
1925 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1926 int32_t cropAndScaleStrategy = 1;
1927 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1928 Image_Size desiredSize = {1000, 1000};
1929 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1930 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1931 EXPECT_NE(ret, IMAGE_SUCCESS);
1932 EXPECT_EQ(resPixMap, nullptr);
1933 OH_ImageSourceNative_Release(imageSource);
1934 OH_DecodingOptions_Release(opts);
1935 OH_PixelmapNative_Release(resPixMap);
1936 }
1937
1938 /**
1939 * @tc.name: ImageRegionDecode008
1940 * @tc.desc: Test Region decode, CropAndScaleStrategy is SCALE_FIRST, Showing the middle quarter image.
1941 * @tc.type: FUNC
1942 */
1943 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode008, TestSize.Level3)
1944 {
1945 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1946 ASSERT_NE(imageSource, nullptr);
1947 OH_DecodingOptions *opts = nullptr;
1948 OH_DecodingOptions_Create(&opts);
1949 ASSERT_NE(opts, nullptr);
1950 OH_PixelmapNative* resPixMap = nullptr;
1951 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1952 Image_Region desiredRegion = {250, 250, 500, 500};
1953 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1954 int32_t cropAndScaleStrategy = 1;
1955 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1956 Image_Size desiredSize = {1000, 1000};
1957 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1958 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1959 EXPECT_EQ(ret, IMAGE_SUCCESS);
1960 EXPECT_NE(resPixMap, nullptr);
1961 OH_ImageSourceNative_Release(imageSource);
1962 OH_DecodingOptions_Release(opts);
1963 OH_PixelmapNative_Release(resPixMap);
1964 }
1965
1966 /**
1967 * @tc.name: ImageRegionDecode009
1968 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing the original image.
1969 * @tc.type: FUNC
1970 */
1971 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode009, TestSize.Level3)
1972 {
1973 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
1974 ASSERT_NE(imageSource, nullptr);
1975 OH_DecodingOptions *opts = nullptr;
1976 OH_DecodingOptions_Create(&opts);
1977 ASSERT_NE(opts, nullptr);
1978 OH_PixelmapNative* resPixMap = nullptr;
1979 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
1980 Image_Region desiredRegion = {0, 0, 3840, 2160};
1981 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
1982 int32_t cropAndScaleStrategy = 2;
1983 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
1984 Image_Size desiredSize = {1000, 1000};
1985 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
1986 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
1987 EXPECT_EQ(ret, IMAGE_SUCCESS);
1988 EXPECT_NE(resPixMap, nullptr);
1989 OH_ImageSourceNative_Release(imageSource);
1990 OH_DecodingOptions_Release(opts);
1991 OH_PixelmapNative_Release(resPixMap);
1992 }
1993
1994 /**
1995 * @tc.name: ImageRegionDecode010
1996 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing the left half image.
1997 * @tc.type: FUNC
1998 */
1999 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode010, TestSize.Level3)
2000 {
2001 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2002 ASSERT_NE(imageSource, nullptr);
2003 OH_DecodingOptions *opts = nullptr;
2004 OH_DecodingOptions_Create(&opts);
2005 ASSERT_NE(opts, nullptr);
2006 OH_PixelmapNative* resPixMap = nullptr;
2007 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2008 Image_Region desiredRegion = {0, 0, 1920, 2160};
2009 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2010 int32_t cropAndScaleStrategy = 2;
2011 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2012 Image_Size desiredSize = {1000, 1000};
2013 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2014 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2015 EXPECT_EQ(ret, IMAGE_SUCCESS);
2016 EXPECT_NE(resPixMap, nullptr);
2017 OH_ImageSourceNative_Release(imageSource);
2018 OH_DecodingOptions_Release(opts);
2019 OH_PixelmapNative_Release(resPixMap);
2020 }
2021
2022 /**
2023 * @tc.name: ImageRegionDecode011
2024 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing the top half image.
2025 * @tc.type: FUNC
2026 */
2027 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode011, TestSize.Level3)
2028 {
2029 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2030 ASSERT_NE(imageSource, nullptr);
2031 OH_DecodingOptions *opts = nullptr;
2032 OH_DecodingOptions_Create(&opts);
2033 ASSERT_NE(opts, nullptr);
2034 OH_PixelmapNative* resPixMap = nullptr;
2035 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2036 Image_Region desiredRegion = {0, 0, 3840, 1080};
2037 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2038 int32_t cropAndScaleStrategy = 2;
2039 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2040 Image_Size desiredSize = {1000, 1000};
2041 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2042 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2043 EXPECT_EQ(ret, IMAGE_SUCCESS);
2044 EXPECT_NE(resPixMap, nullptr);
2045 OH_ImageSourceNative_Release(imageSource);
2046 OH_DecodingOptions_Release(opts);
2047 OH_PixelmapNative_Release(resPixMap);
2048 }
2049
2050 /**
2051 * @tc.name: ImageRegionDecode012
2052 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing the right bottom image.
2053 * @tc.type: FUNC
2054 */
2055 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode012, TestSize.Level3)
2056 {
2057 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2058 ASSERT_NE(imageSource, nullptr);
2059 OH_DecodingOptions *opts = nullptr;
2060 OH_DecodingOptions_Create(&opts);
2061 ASSERT_NE(opts, nullptr);
2062 OH_PixelmapNative* resPixMap = nullptr;
2063 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2064 Image_Region desiredRegion = {1920, 1080, 1920, 1080};
2065 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2066 int32_t cropAndScaleStrategy = 2;
2067 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2068 Image_Size desiredSize = {1000, 1000};
2069 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2070 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2071 EXPECT_EQ(ret, IMAGE_SUCCESS);
2072 EXPECT_NE(resPixMap, nullptr);
2073 OH_ImageSourceNative_Release(imageSource);
2074 OH_DecodingOptions_Release(opts);
2075 OH_PixelmapNative_Release(resPixMap);
2076 }
2077
2078 /**
2079 * @tc.name: ImageRegionDecode013
2080 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing NULL.
2081 * @tc.type: FUNC
2082 */
2083 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode013, TestSize.Level3)
2084 {
2085 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2086 ASSERT_NE(imageSource, nullptr);
2087 OH_DecodingOptions *opts = nullptr;
2088 OH_DecodingOptions_Create(&opts);
2089 ASSERT_NE(opts, nullptr);
2090 OH_PixelmapNative* resPixMap = nullptr;
2091 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2092 Image_Region desiredRegion = {1920, 1080, 3840, 1080};
2093 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2094 int32_t cropAndScaleStrategy = 2;
2095 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2096 Image_Size desiredSize = {1000, 1000};
2097 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2098 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2099 EXPECT_NE(ret, IMAGE_SUCCESS);
2100 EXPECT_EQ(resPixMap, nullptr);
2101 OH_ImageSourceNative_Release(imageSource);
2102 OH_DecodingOptions_Release(opts);
2103 OH_PixelmapNative_Release(resPixMap);
2104 }
2105
2106 /**
2107 * @tc.name: ImageRegionDecode014
2108 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing NULL.
2109 * @tc.type: FUNC
2110 */
2111 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode014, TestSize.Level3)
2112 {
2113 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2114 ASSERT_NE(imageSource, nullptr);
2115 OH_DecodingOptions *opts = nullptr;
2116 OH_DecodingOptions_Create(&opts);
2117 ASSERT_NE(opts, nullptr);
2118 OH_PixelmapNative* resPixMap = nullptr;
2119 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2120 Image_Region desiredRegion = {3840, 2160, 1920, 1080};
2121 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2122 int32_t cropAndScaleStrategy = 2;
2123 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2124 Image_Size desiredSize = {1000, 1000};
2125 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2126 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2127 EXPECT_NE(ret, IMAGE_SUCCESS);
2128 EXPECT_EQ(resPixMap, nullptr);
2129 OH_ImageSourceNative_Release(imageSource);
2130 OH_DecodingOptions_Release(opts);
2131 OH_PixelmapNative_Release(resPixMap);
2132 }
2133
2134 /**
2135 * @tc.name: ImageRegionDecode015
2136 * @tc.desc: Test Region decode, CropAndScaleStrategy is CROP_FIRST, Showing the middle quarter image.
2137 * @tc.type: FUNC
2138 */
2139 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode015, TestSize.Level3)
2140 {
2141 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2142 ASSERT_NE(imageSource, nullptr);
2143 OH_DecodingOptions *opts = nullptr;
2144 OH_DecodingOptions_Create(&opts);
2145 ASSERT_NE(opts, nullptr);
2146 OH_PixelmapNative* resPixMap = nullptr;
2147 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2148 Image_Region desiredRegion = {960, 540, 1920, 1080};
2149 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2150 int32_t cropAndScaleStrategy = 2;
2151 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2152 Image_Size desiredSize = {1000, 1000};
2153 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2154 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2155 EXPECT_EQ(ret, IMAGE_SUCCESS);
2156 EXPECT_NE(resPixMap, nullptr);
2157 OH_ImageSourceNative_Release(imageSource);
2158 OH_DecodingOptions_Release(opts);
2159 OH_PixelmapNative_Release(resPixMap);
2160 }
2161
2162 /**
2163 * @tc.name: ImageRegionDecode016
2164 * @tc.desc: Test Region decode, CropAndScaleStrategy is OTHER, Showing the original image.
2165 * @tc.type: FUNC
2166 */
2167 HWTEST_F(ImagSourceNdk2Test, ImageRegionDecode016, TestSize.Level3)
2168 {
2169 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2170 ASSERT_NE(imageSource, nullptr);
2171 OH_DecodingOptions *opts = nullptr;
2172 OH_DecodingOptions_Create(&opts);
2173 ASSERT_NE(opts, nullptr);
2174 OH_PixelmapNative* resPixMap = nullptr;
2175 IMAGE_ALLOCATOR_TYPE allocator = IMAGE_ALLOCATOR_TYPE::IMAGE_ALLOCATOR_TYPE_SHARE_MEMORY;
2176 Image_Region desiredRegion = {0, 0, 1920, 1080};
2177 OH_DecodingOptions_SetDesiredRegion(opts, &desiredRegion);
2178 int32_t cropAndScaleStrategy = 3;
2179 OH_DecodingOptions_SetCropAndScaleStrategy(opts, cropAndScaleStrategy);
2180 Image_Size desiredSize = {1920, 1080};
2181 OH_DecodingOptions_SetDesiredSize(opts, &desiredSize);
2182 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapUsingAllocator(imageSource, opts, allocator, &resPixMap);
2183 EXPECT_EQ(ret, IMAGE_SUCCESS);
2184 EXPECT_NE(resPixMap, nullptr);
2185 OH_ImageSourceNative_Release(imageSource);
2186 OH_DecodingOptions_Release(opts);
2187 OH_PixelmapNative_Release(resPixMap);
2188 }
2189
2190 /**
2191 * @tc.name: OH_ImageSourceNative_GetSupportedFormatTest001
2192 * @tc.desc: Verify ImageSource can retrieve supported formats with valid data structure.
2193 * @tc.type: FUNC
2194 */
2195 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetSupportedFormatTest001, TestSize.Level3)
2196 {
2197 Image_MimeType* supportedFormat = nullptr;
2198 size_t length = 0;
2199 Image_ErrorCode ret = OH_ImageSourceNative_GetSupportedFormats(&supportedFormat, &length);
2200 EXPECT_EQ(ret, IMAGE_SUCCESS);
2201 for (size_t i = 0; i < length; i++) {
2202 EXPECT_NE(supportedFormat[i].data, nullptr);
2203 EXPECT_NE(supportedFormat[i].size, 0);
2204 }
2205 EXPECT_NE(length, 0);
2206 }
2207
2208 /**
2209 * @tc.name: OH_ImageSourceNative_GetSupportedFormatTest002
2210 * @tc.desc: Verify null parameter validation for GetSupportedFormat API.
2211 * @tc.type: FUNC
2212 */
2213 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetSupportedFormatTest002, TestSize.Level3)
2214 {
2215 Image_MimeType* supportedFormat = nullptr;
2216 size_t length = 0;
2217 Image_ErrorCode ret = OH_ImageSourceNative_GetSupportedFormats(nullptr, &length);
2218 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
2219 ret = OH_ImageSourceNative_GetSupportedFormats(&supportedFormat, nullptr);
2220 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
2221 ret = OH_ImageSourceNative_GetSupportedFormats(nullptr, nullptr);
2222 EXPECT_EQ(ret, IMAGE_SOURCE_INVALID_PARAMETER);
2223 }
2224
2225 /**
2226 * @tc.name: OH_ImageSourceNative_GetImagePropertyWithNullTest001
2227 * @tc.desc: test OH_ImageSourceNative_GetImagePropertyWithNull with null pointer
2228 * @tc.type: FUNC
2229 */
2230 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImagePropertyWithNullTest001, TestSize.Level3)
2231 {
2232 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImagePropertyWithNullTest001 start";
2233 OH_ImageSourceNative *imageSource = nullptr;
2234 Image_String* key = nullptr;
2235 Image_String* value = nullptr;
2236 Image_ErrorCode ret = OH_ImageSourceNative_GetImagePropertyWithNull(imageSource, key, value);
2237 ASSERT_NE(ret, IMAGE_SUCCESS);
2238 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImagePropertyWithNullTest001 end";
2239 }
2240
2241 /**
2242 * @tc.name: OH_ImageSourceNative_GetImagePropertyWithNullTest002
2243 * @tc.desc: test OH_ImageSourceNative_GetImagePropertyWithNull with right value
2244 * @tc.type: FUNC
2245 */
2246 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImagePropertyWithNullTest002, TestSize.Level3)
2247 {
2248 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImagePropertyWithNullTest002 start";
2249 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH);
2250 ASSERT_NE(imageSource, nullptr);
2251 Image_String key;
2252 Image_String value;
2253 key.data = const_cast<char*>(OHOS_IMAGE_PROPERTY_EXIF_VERSION);
2254 key.size = strlen(OHOS_IMAGE_PROPERTY_EXIF_VERSION);
2255 value.data = nullptr;
2256 value.size = 100;
2257 Image_ErrorCode ret = OH_ImageSourceNative_GetImagePropertyWithNull(imageSource, &key, &value);
2258 ASSERT_EQ(ret, IMAGE_SUCCESS);
2259 OH_ImageSourceNative_Release(imageSource);
2260 if (ret == IMAGE_SUCCESS) {
2261 free(value.data);
2262 }
2263 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImagePropertyWithNullTest002 end";
2264 }
2265
2266 /**
2267 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex001
2268 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex001
2269 * @tc.type: FUNC
2270 */
2271 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex001, TestSize.Level3)
2272 {
2273 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex001 start";
2274 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_GIF_MOVING_PATH);
2275 ASSERT_NE(imageSource, nullptr);
2276 uint32_t frameCount = 0;
2277 Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, &frameCount);
2278 ASSERT_EQ(ret, IMAGE_SUCCESS);
2279 ASSERT_EQ(frameCount, IMAGE_GIF_MOVING_FRAME_COUNT);
2280 OH_PictureNative *picture = nullptr;
2281
2282 ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, 0, &picture);
2283 EXPECT_EQ(ret, IMAGE_SUCCESS);
2284 OH_PictureMetadata *gifMetadata = nullptr;
2285 ret = OH_PictureNative_GetMetadata(picture, GIF_METADATA, &gifMetadata);
2286 EXPECT_EQ(ret, IMAGE_SUCCESS);
2287
2288 Image_String keyDelayTime;
2289 keyDelayTime.data = strdup(IMAGE_PROPERTY_GIF_DELAY_TIME);
2290 keyDelayTime.size = strlen(keyDelayTime.data);
2291 Image_String valueDelayTime;
2292 ret = OH_PictureMetadata_GetProperty(gifMetadata, &keyDelayTime, &valueDelayTime);
2293 EXPECT_EQ(ret, IMAGE_SUCCESS);
2294 EXPECT_EQ(strncmp(valueDelayTime.data, "70", valueDelayTime.size), 0);
2295
2296 Image_String keyDisposalType;
2297 keyDisposalType.data = strdup(IMAGE_PROPERTY_GIF_DISPOSAL_TYPE);
2298 keyDisposalType.size = strlen(keyDisposalType.data);
2299 Image_String valueDisposalType;
2300 ret = OH_PictureMetadata_GetProperty(gifMetadata, &keyDisposalType, &valueDisposalType);
2301 EXPECT_EQ(ret, IMAGE_SUCCESS);
2302 EXPECT_EQ(strncmp(valueDisposalType.data, "1", valueDisposalType.size), 0);
2303
2304 OH_ImageSourceNative_Release(imageSource);
2305 OH_PictureNative_Release(picture);
2306 OH_PictureMetadata_Release(gifMetadata);
2307 free(keyDelayTime.data);
2308 free(keyDisposalType.data);
2309 delete[] valueDelayTime.data;
2310 delete[] valueDisposalType.data;
2311 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex001 end";
2312 }
2313
2314 /**
2315 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex002
2316 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex002
2317 * @tc.type: FUNC
2318 */
2319 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex002, TestSize.Level3)
2320 {
2321 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex002 start";
2322 OH_ImageSourceNative *imageSource = nullptr;
2323 OH_PictureNative *picture = nullptr;
2324 Image_ErrorCode ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, 0, &picture);
2325 EXPECT_EQ(ret, IMAGE_BAD_SOURCE);
2326 OH_ImageSourceNative_Release(imageSource);
2327 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex002 end";
2328 }
2329
2330 /**
2331 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex003
2332 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex003
2333 * @tc.type: FUNC
2334 */
2335 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex003, TestSize.Level3)
2336 {
2337 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex003 start";
2338 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_GIF_MOVING_PATH);
2339 ASSERT_NE(imageSource, nullptr);
2340 OH_PictureNative **picture = nullptr;
2341 Image_ErrorCode ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, 0, picture);
2342 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_OPTIONS);
2343 OH_ImageSourceNative_Release(imageSource);
2344 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex003 end";
2345 }
2346
2347 /**
2348 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex004
2349 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex004
2350 * @tc.type: FUNC
2351 */
2352 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex004, TestSize.Level3)
2353 {
2354 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex004 start";
2355 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_JPEG_PATH_TEST);
2356 ASSERT_NE(imageSource, nullptr);
2357 OH_PictureNative *picture = nullptr;
2358 Image_ErrorCode ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, 0, &picture);
2359 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_MIMETYPE);
2360 OH_ImageSourceNative_Release(imageSource);
2361 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex004 end";
2362 }
2363
2364 /**
2365 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex005
2366 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex005
2367 * @tc.type: FUNC
2368 */
2369 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex005, TestSize.Level3)
2370 {
2371 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex005 start";
2372 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_GIF_MOVING_PATH);
2373 ASSERT_NE(imageSource, nullptr);
2374 uint32_t frameCount = 0;
2375 Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, &frameCount);
2376 ASSERT_EQ(ret, IMAGE_SUCCESS);
2377 ASSERT_EQ(frameCount, IMAGE_GIF_MOVING_FRAME_COUNT);
2378 OH_PictureNative *picture = nullptr;
2379 ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, frameCount, &picture);
2380 EXPECT_EQ(ret, IMAGE_SOURCE_UNSUPPORTED_OPTIONS);
2381 OH_ImageSourceNative_Release(imageSource);
2382 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex005 end";
2383 }
2384
2385 /**
2386 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex006
2387 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex006
2388 * @tc.type: FUNC
2389 */
2390 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex006, TestSize.Level3)
2391 {
2392 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex006 start";
2393 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_GIF_LARGE_PATH);
2394 ASSERT_NE(imageSource, nullptr);
2395 OH_PictureNative *picture = nullptr;
2396 Image_ErrorCode ret = OH_ImageSourceNative_CreatePictureAtIndex(imageSource, 0, &picture);
2397 EXPECT_EQ(ret, IMAGE_SOURCE_TOO_LARGE);
2398 OH_ImageSourceNative_Release(imageSource);
2399 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex006 end";
2400 }
2401
2402 /**
2403 * @tc.name: OH_ImageSourceNative_CreatePictureAtIndex007
2404 * @tc.desc: test OH_ImageSourceNative_CreatePictureAtIndex007
2405 * @tc.type: FUNC
2406 */
2407 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePictureAtIndex007, TestSize.Level3)
2408 {
2409 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex007 start";
2410 OH_ImageSourceNative *imageSource = CreateImageSourceNative(IMAGE_GIF_INCOMPLETE_PATH);
2411 ASSERT_NE(imageSource, nullptr);
2412 OH_PictureNative *picture = nullptr;
2413 Image_ErrorCode ret =
2414 OH_ImageSourceNative_CreatePictureAtIndex(imageSource, IMAGE_GIF_INCOMPLETE_FRAME_INDEX, &picture);
2415 EXPECT_EQ(ret, IMAGE_DECODE_FAILED);
2416 OH_ImageSourceNative_Release(imageSource);
2417 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePictureAtIndex007 end";
2418 }
2419 }
2420 }
2421