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 22 using namespace testing::ext; 23 namespace OHOS { 24 namespace Media { 25 class ImagSourceNdk2Test : public testing::Test { 26 public: ImagSourceNdk2Test()27 ImagSourceNdk2Test() {} ~ImagSourceNdk2Test()28 ~ImagSourceNdk2Test() {} 29 }; 30 31 /** 32 * @tc.name: OH_ImageSourceInfo_Create 33 * @tc.desc: test OH_ImageSourceInfo_Create 34 * @tc.type: FUNC 35 */ 36 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Create, TestSize.Level3) 37 { 38 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create start"; 39 OH_ImageSource_Info *ops = nullptr; 40 Image_ErrorCode ret = OH_ImageSourceInfo_Create(&ops); 41 ASSERT_EQ(ret, IMAGE_SUCCESS); 42 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create end"; 43 } 44 45 /** 46 * @tc.name: OH_ImageSourceInfo_GetWidth 47 * @tc.desc: test OH_ImageSourceInfo_GetWidth 48 * @tc.type: FUNC 49 */ 50 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetWidth, TestSize.Level3) 51 { 52 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth start"; 53 OH_ImageSource_Info *ops = nullptr; 54 uint32_t *width = nullptr; 55 Image_ErrorCode ret = OH_ImageSourceInfo_GetWidth(ops, width); 56 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 57 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth end"; 58 } 59 60 /** 61 * @tc.name: OH_ImageSourceInfo_GetHeight 62 * @tc.desc: test OH_ImageSourceInfo_GetHeight 63 * @tc.type: FUNC 64 */ 65 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetHeight, TestSize.Level3) 66 { 67 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight start"; 68 OH_ImageSource_Info *ops = nullptr; 69 uint32_t *width = nullptr; 70 Image_ErrorCode ret = OH_ImageSourceInfo_GetHeight(ops, width); 71 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 72 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight end"; 73 } 74 75 /** 76 * @tc.name: OH_ImageSourceInfo_Release 77 * @tc.desc: test OH_ImageSourceInfo_Release 78 * @tc.type: FUNC 79 */ 80 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Release, TestSize.Level3) 81 { 82 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release start"; 83 OH_ImageSource_Info *ops = nullptr; 84 Image_ErrorCode ret = OH_ImageSourceInfo_Release(ops); 85 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 86 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release end"; 87 } 88 89 /** 90 * @tc.name: OH_DecodingOptions_Create 91 * @tc.desc: test OH_DecodingOptions_Create 92 * @tc.type: FUNC 93 */ 94 HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptions_Create, TestSize.Level3) 95 { 96 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create start"; 97 OH_DecodingOptions *ops = nullptr; 98 Image_ErrorCode ret = OH_DecodingOptions_Create(&ops); 99 ASSERT_EQ(ret, IMAGE_SUCCESS); 100 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create end"; 101 } 102 103 /** 104 * @tc.name: OH_ImageSource_DecodingOptionsSetGetPixelFormat 105 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetPixelFormat 106 * @tc.type: FUNC 107 */ 108 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetPixelFormat, TestSize.Level3) 109 { 110 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat start"; 111 OH_DecodingOptions *ops = nullptr; 112 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; 113 int32_t pixelFormat = 0; 114 ret = OH_DecodingOptions_Create(&ops); 115 ASSERT_EQ(ret, IMAGE_SUCCESS); 116 OH_DecodingOptions_SetPixelFormat(ops, 1); 117 OH_DecodingOptions_GetPixelFormat(ops, &pixelFormat); 118 ASSERT_EQ(pixelFormat, 1); 119 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat end"; 120 } 121 122 /** 123 * @tc.name: OH_ImageSource_DecodingOptionsSetGetIndex 124 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetIndex 125 * @tc.type: FUNC 126 */ 127 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetIndex, TestSize.Level3) 128 { 129 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex start"; 130 OH_DecodingOptions *ops = nullptr; 131 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; 132 uint32_t index = 0; 133 ret = OH_DecodingOptions_Create(&ops); 134 ASSERT_EQ(ret, IMAGE_SUCCESS); 135 OH_DecodingOptions_SetIndex(ops, 1); 136 OH_DecodingOptions_GetIndex(ops, &index); 137 ASSERT_EQ(index, 1); 138 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex end"; 139 } 140 141 /** 142 * @tc.name: OH_ImageSource_DecodingOptionsSetGetRotate 143 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetRotate 144 * @tc.type: FUNC 145 */ 146 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetRotate, TestSize.Level3) 147 { 148 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate start"; 149 OH_DecodingOptions *ops = nullptr; 150 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; 151 float rotate = 0; 152 ret = OH_DecodingOptions_Create(&ops); 153 ASSERT_EQ(ret, IMAGE_SUCCESS); 154 OH_DecodingOptions_SetRotate(ops, 1); 155 OH_DecodingOptions_GetRotate(ops, &rotate); 156 ASSERT_EQ(rotate, 1); 157 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate end"; 158 } 159 160 /** 161 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredSize 162 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredSize 163 * @tc.type: FUNC 164 */ 165 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredSize, TestSize.Level3) 166 { 167 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize start"; 168 OH_DecodingOptions *ops = nullptr; 169 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; 170 Image_Size desiredSize = {0, 0}; 171 Image_Size desiredSize2 = {1, 2}; 172 ret = OH_DecodingOptions_Create(&ops); 173 ASSERT_EQ(ret, IMAGE_SUCCESS); 174 OH_DecodingOptions_SetDesiredSize(ops, &desiredSize2); 175 OH_DecodingOptions_GetDesiredSize(ops, &desiredSize); 176 ASSERT_EQ(desiredSize.width, desiredSize2.width); 177 ASSERT_EQ(desiredSize.height, desiredSize2.height); 178 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize end"; 179 } 180 181 /** 182 * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredRegion 183 * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredRegion 184 * @tc.type: FUNC 185 */ 186 HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredRegion, TestSize.Level3) 187 { 188 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion start"; 189 OH_DecodingOptions *ops = nullptr; 190 Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; 191 Image_Region desiredRegion = {0, 0, 0, 0}; 192 Image_Region desiredRegion2 = {1, 2, 3, 4}; 193 ret = OH_DecodingOptions_Create(&ops); 194 ASSERT_EQ(ret, IMAGE_SUCCESS); 195 OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2); 196 OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion); 197 ASSERT_EQ(desiredRegion.x, 1); 198 ASSERT_EQ(desiredRegion.y, 2); 199 ASSERT_EQ(desiredRegion.width, 3); 200 ASSERT_EQ(desiredRegion.height, 4); 201 ret = OH_DecodingOptions_Release(ops); 202 ASSERT_EQ(ret, IMAGE_SUCCESS); 203 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion end"; 204 } 205 206 /** 207 * @tc.name: OH_ImageSourceNative_CreateFromUri 208 * @tc.desc: test OH_ImageSourceNative_CreateFromUri 209 * @tc.type: FUNC 210 */ 211 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromUri, TestSize.Level3) 212 { 213 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri start"; 214 OH_ImageSourceNative *imageSource = nullptr; 215 char *uri = nullptr; 216 size_t uriSize = 0; 217 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(uri, uriSize, &imageSource); 218 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 219 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri end"; 220 } 221 222 /** 223 * @tc.name: OH_ImageSourceNative_CreateFromFd 224 * @tc.desc: test OH_ImageSourceNative_CreateFromFd 225 * @tc.type: FUNC 226 */ 227 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromFd, TestSize.Level3) 228 { 229 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd start"; 230 OH_ImageSourceNative *imageSource = nullptr; 231 int32_t fd = 0; 232 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromFd(fd, &imageSource); 233 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 234 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd end"; 235 } 236 237 /** 238 * @tc.name: OH_ImageSourceNative_CreateFromData 239 * @tc.desc: test OH_ImageSourceNative_CreateFromData 240 * @tc.type: FUNC 241 */ 242 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromData, TestSize.Level3) 243 { 244 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData start"; 245 OH_ImageSourceNative *imageSource = nullptr; 246 uint8_t* data = nullptr; 247 size_t dataSize = 0; 248 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromData(data, dataSize, &imageSource); 249 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 250 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData end"; 251 } 252 253 /** 254 * @tc.name: OH_ImageSourceNative_CreateFromRawFile002 255 * @tc.desc: test OH_ImageSourceNative_CreateFromRawFile 256 * @tc.type: FUNC 257 */ 258 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromRawFile002, TestSize.Level3) 259 { 260 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 start"; 261 OH_ImageSourceNative *imageSource = nullptr; 262 RawFileDescriptor *rawFile = nullptr; 263 Image_ErrorCode ret = OH_ImageSourceNative_CreateFromRawFile(rawFile, &imageSource); 264 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 265 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile002 end"; 266 } 267 268 /** 269 * @tc.name: OH_ImageSourceNative_CreatePixelmap 270 * @tc.desc: test OH_ImageSourceNative_CreatePixelmap 271 * @tc.type: FUNC 272 */ 273 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmap, TestSize.Level3) 274 { 275 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap start"; 276 OH_ImageSourceNative *imageSource = nullptr; 277 OH_DecodingOptions* ops = nullptr; 278 OH_PixelmapNative* resPixMap = nullptr; 279 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap); 280 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 281 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap end"; 282 } 283 284 /** 285 * @tc.name: OH_ImageSourceNative_CreatePixelmapList 286 * @tc.desc: test OH_ImageSourceNative_CreatePixelmapList 287 * @tc.type: FUNC 288 */ 289 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapList, TestSize.Level3) 290 { 291 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList start"; 292 OH_DecodingOptions *ops = nullptr; 293 OH_ImageSourceNative *imageSource = nullptr; 294 OH_PixelmapNative** resVecPixMap = nullptr; 295 size_t outSize = 0; 296 Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapList(imageSource, ops, resVecPixMap, outSize); 297 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 298 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList end"; 299 } 300 301 /** 302 * @tc.name: OH_ImageSourceNative_GetDelayTimeList 303 * @tc.desc: test OH_ImageSourceNative_GetDelayTimeList 304 * @tc.type: FUNC 305 */ 306 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetDelayTimeList, TestSize.Level3) 307 { 308 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList start"; 309 OH_ImageSourceNative *imageSource = nullptr; 310 int32_t* delayTimeList = nullptr; 311 size_t size = 0; 312 Image_ErrorCode ret = OH_ImageSourceNative_GetDelayTimeList(imageSource, delayTimeList, size); 313 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 314 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList end"; 315 } 316 317 /** 318 * @tc.name: OH_ImageSourceNative_GetImageInfo 319 * @tc.desc: test OH_ImageSourceNative_GetImageInfo 320 * @tc.type: FUNC 321 */ 322 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageInfo, TestSize.Level3) 323 { 324 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo start"; 325 OH_ImageSourceNative *imageSource = nullptr; 326 int32_t index = 0; 327 OH_ImageSource_Info* info = nullptr; 328 Image_ErrorCode ret = OH_ImageSourceNative_GetImageInfo(imageSource, index, info); 329 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 330 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo end"; 331 } 332 333 /** 334 * @tc.name: OH_ImageSourceNative_GetImageProperty 335 * @tc.desc: test OH_ImageSourceNative_GetImageProperty 336 * @tc.type: FUNC 337 */ 338 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageProperty, TestSize.Level3) 339 { 340 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty start"; 341 OH_ImageSourceNative *imageSource = nullptr; 342 Image_String* key = nullptr; 343 Image_String* value = nullptr; 344 Image_ErrorCode ret = OH_ImageSourceNative_GetImageProperty(imageSource, key, value); 345 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 346 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty end"; 347 } 348 349 /** 350 * @tc.name: OH_ImageSourceNative_ModifyImageProperty 351 * @tc.desc: test OH_ImageSourceNative_ModifyImageProperty 352 * @tc.type: FUNC 353 */ 354 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_ModifyImageProperty, TestSize.Level3) 355 { 356 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty start"; 357 OH_ImageSourceNative *imageSource = nullptr; 358 Image_String* key = nullptr; 359 Image_String* value = nullptr; 360 Image_ErrorCode ret = OH_ImageSourceNative_ModifyImageProperty(imageSource, key, value); 361 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 362 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty end"; 363 } 364 365 /** 366 * @tc.name: OH_ImageSourceNative_GetFrameCount 367 * @tc.desc: test OH_ImageSourceNative_GetFrameCount 368 * @tc.type: FUNC 369 */ 370 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetFrameCount, TestSize.Level3) 371 { 372 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount start"; 373 OH_ImageSourceNative *imageSource = nullptr; 374 uint32_t* res = nullptr; 375 Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, res); 376 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 377 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount end"; 378 } 379 380 /** 381 * @tc.name: OH_ImageSourceNative_Release 382 * @tc.desc: test OH_ImageSourceNative_Release 383 * @tc.type: FUNC 384 */ 385 HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_Release, TestSize.Level3) 386 { 387 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release start"; 388 OH_ImageSourceNative *imageSource = nullptr; 389 Image_ErrorCode ret = OH_ImageSourceNative_Release(imageSource); 390 ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); 391 GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release end"; 392 } 393 394 } 395 } 396