1 /* 2 * Copyright (C) 2025 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 #define private public 17 #define protected public 18 #include <gtest/gtest.h> 19 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace ImagePlugin { 23 class HeifDecodeImplTest : public testing::Test { 24 public: HeifDecodeImplTest()25 HeifDecodeImplTest() {} ~HeifDecodeImplTest()26 ~HeifDecodeImplTest() {} 27 }; 28 29 /** 30 * @tc.name: HeifDecoderImpl_initTest001 31 * @tc.desc: Verify that HeifDecoderImpl call init when stream is nullptr. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_initTest001, TestSize.Level3) 35 { 36 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_initTest001 start"; 37 #ifdef HEIF_HW_DECODE_ENABLE 38 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 39 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 40 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 41 ASSERT_NE(streamPtr, nullptr); 42 extDecoder->SetSource(*streamPtr); 43 ASSERT_NE(extDecoder->stream_, nullptr); 44 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 45 bool ret = extDecoder->CheckCodec(); 46 ASSERT_NE(extDecoder->codec_, nullptr); 47 ASSERT_EQ(ret, true); 48 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 49 ASSERT_NE(mockDecoderImpl, nullptr); 50 ret = mockDecoderImpl->init(nullptr, nullptr); 51 ASSERT_EQ(ret, false); 52 #endif 53 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_initTest001 end"; 54 } 55 56 /** 57 * @tc.name: HeifDecoderImpl_initTest002 58 * @tc.desc: Verify that HeifDecoderImpl call init when err is heif_error_ok. 59 * @tc.type: FUNC 60 */ 61 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_initTest002, TestSize.Level3) 62 { 63 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_initTest002 start"; 64 #ifdef HEIF_HW_DECODE_ENABLE 65 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 66 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 67 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 68 ASSERT_NE(streamPtr, nullptr); 69 extDecoder->SetSource(*streamPtr); 70 ASSERT_NE(extDecoder->stream_, nullptr); 71 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 72 bool ret = extDecoder->CheckCodec(); 73 ASSERT_NE(extDecoder->codec_, nullptr); 74 ASSERT_EQ(ret, true); 75 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 76 ASSERT_NE(mockDecoderImpl, nullptr); 77 ret = mockDecoderImpl->init(new MockHeifStream(), nullptr); 78 ASSERT_EQ(ret, false); 79 auto copyData = mockDecoderImpl->srcMemory_; 80 mockDecoderImpl->srcMemory_ = nullptr; 81 ret = mockDecoderImpl->init(new MockHeifStream(), nullptr); 82 ASSERT_EQ(ret, false); 83 mockDecoderImpl->srcMemory_ = copyData; 84 #endif 85 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_initTest002 end"; 86 } 87 88 /** 89 * @tc.name: HeifDecoderImpl_initTest003 90 * @tc.desc: Verify HEIF decoder initialization fails with null stream and frameInfo. 91 * @tc.type: FUNC 92 */ 93 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_initTest003, TestSize.Level3) 94 { 95 #ifdef HEIF_HW_DECODE_ENABLE 96 HeifDecoderImpl decoder; 97 HeifStream *stream = nullptr; 98 HeifFrameInfo *frameInfo = nullptr; 99 bool ret = decoder.init(stream, frameInfo); 100 EXPECT_FALSE(ret); 101 #endif 102 } 103 104 /** 105 * @tc.name: HeifDecoderImpl_CheckAuxiliaryMapTest001 106 * @tc.desc: Verify that CheckAuxiliaryMap call init when parser_ is nullptr. 107 * @tc.type: FUNC 108 */ 109 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_CheckAuxiliaryMapTest001, TestSize.Level3) 110 { 111 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_CheckAuxiliaryMapTest001 start"; 112 #ifdef HEIF_HW_DECODE_ENABLE 113 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 114 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 115 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 116 ASSERT_NE(streamPtr, nullptr); 117 extDecoder->SetSource(*streamPtr); 118 ASSERT_NE(extDecoder->stream_, nullptr); 119 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 120 bool ret = extDecoder->CheckCodec(); 121 ASSERT_NE(extDecoder->codec_, nullptr); 122 ASSERT_EQ(ret, true); 123 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 124 ASSERT_NE(mockDecoderImpl, nullptr); 125 auto copyParser = mockDecoderImpl->parser_; 126 mockDecoderImpl->parser_ = nullptr; 127 ret = mockDecoderImpl->CheckAuxiliaryMap(AuxiliaryPictureType::GAINMAP); 128 ASSERT_EQ(ret, false); 129 mockDecoderImpl->parser_ = copyParser; 130 #endif 131 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_CheckAuxiliaryMapTest001 end"; 132 } 133 134 /** 135 * @tc.name: HeifDecoderImpl_CheckAuxiliaryMapTest002 136 * @tc.desc: Verify that CheckAuxiliaryMap call init when AuxiliaryPictureType is NONE. 137 * @tc.type: FUNC 138 */ 139 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_CheckAuxiliaryMapTest002, TestSize.Level3) 140 { 141 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_CheckAuxiliaryMapTest002 start"; 142 #ifdef HEIF_HW_DECODE_ENABLE 143 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 144 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 145 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 146 ASSERT_NE(streamPtr, nullptr); 147 extDecoder->SetSource(*streamPtr); 148 ASSERT_NE(extDecoder->stream_, nullptr); 149 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 150 bool ret = extDecoder->CheckCodec(); 151 ASSERT_NE(extDecoder->codec_, nullptr); 152 ASSERT_EQ(ret, true); 153 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 154 ASSERT_NE(mockDecoderImpl, nullptr); 155 ASSERT_NE(mockDecoderImpl->parser_, nullptr); 156 ret = mockDecoderImpl->CheckAuxiliaryMap(AuxiliaryPictureType::NONE); 157 ASSERT_EQ(ret, false); 158 #endif 159 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_CheckAuxiliaryMapTest002 end"; 160 } 161 162 /** 163 * @tc.name: HeifDecoderImpl_CheckAuxiliaryMapTest003 164 * @tc.desc: Verify CheckAuxiliaryMap returns false when parser is null. 165 * @tc.type: FUNC 166 */ 167 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_CheckAuxiliaryMapTest003, TestSize.Level3) 168 { 169 #ifdef HEIF_HW_DECODE_ENABLE 170 HeifDecoderImpl decoder; 171 decoder.parser_ = nullptr; 172 AuxiliaryPictureType type = AuxiliaryPictureType::GAINMAP; 173 bool ret = decoder.CheckAuxiliaryMap(type); 174 EXPECT_FALSE(ret); 175 #endif 176 } 177 178 /** 179 * @tc.name: HeifDecoderImpl_ReinitTest001 180 * @tc.desc: Verify that Reinit call init when primaryImage_ is nullptr. 181 * @tc.type: FUNC 182 */ 183 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_ReinitTest001, TestSize.Level3) 184 { 185 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_ReinitTest001 start"; 186 #ifdef HEIF_HW_DECODE_ENABLE 187 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 188 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 189 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 190 ASSERT_NE(streamPtr, nullptr); 191 extDecoder->SetSource(*streamPtr); 192 ASSERT_NE(extDecoder->stream_, nullptr); 193 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 194 bool ret = extDecoder->CheckCodec(); 195 ASSERT_NE(extDecoder->codec_, nullptr); 196 ASSERT_EQ(ret, true); 197 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 198 ASSERT_NE(mockDecoderImpl, nullptr); 199 mockDecoderImpl->primaryImage_.reset(); 200 mockDecoderImpl->GetTileSize(mockDecoderImpl->primaryImage_, mockDecoderImpl->gridInfo_); 201 ret = mockDecoderImpl->Reinit(nullptr); 202 ASSERT_EQ(ret, true); 203 #endif 204 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_ReinitTest001 end"; 205 } 206 207 /** 208 * @tc.name: HeifDecoderImpl_HwDecodeImageTest001 209 * @tc.desc: Verify that HwDecodeImage call init when outPixelFormat_ is UNKNOWN. 210 * @tc.type: FUNC 211 */ 212 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_HwDecodeImageTest001, TestSize.Level3) 213 { 214 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeImageTest001 start"; 215 #ifdef HEIF_HW_DECODE_ENABLE 216 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 217 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 218 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 219 ASSERT_NE(streamPtr, nullptr); 220 extDecoder->SetSource(*streamPtr); 221 ASSERT_NE(extDecoder->stream_, nullptr); 222 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 223 bool ret = extDecoder->CheckCodec(); 224 ASSERT_NE(extDecoder->codec_, nullptr); 225 ASSERT_EQ(ret, true); 226 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 227 ASSERT_NE(mockDecoderImpl, nullptr); 228 mockDecoderImpl->outPixelFormat_ = PixelFormat::UNKNOWN; 229 ret = mockDecoderImpl->HwDecodeImage(mockDecoderImpl->primaryImage_, 230 mockDecoderImpl->gridInfo_, nullptr, false); 231 ASSERT_EQ(ret, false); 232 #endif 233 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeImageTest001 end"; 234 } 235 236 /** 237 * @tc.name: HeifDecoderImpl_HwDecodeImageTest002 238 * @tc.desc: Verify that HwDecodeImage call init when outBuffer is nullptr. 239 * @tc.type: FUNC 240 */ 241 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_HwDecodeImageTest002, TestSize.Level3) 242 { 243 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeImageTest002 start"; 244 #ifdef HEIF_HW_DECODE_ENABLE 245 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 246 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 247 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 248 ASSERT_NE(streamPtr, nullptr); 249 extDecoder->SetSource(*streamPtr); 250 ASSERT_NE(extDecoder->stream_, nullptr); 251 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 252 bool ret = extDecoder->CheckCodec(); 253 ASSERT_NE(extDecoder->codec_, nullptr); 254 ASSERT_EQ(ret, true); 255 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 256 ASSERT_NE(mockDecoderImpl, nullptr); 257 mockDecoderImpl->outPixelFormat_ = PixelFormat::ARGB_8888; 258 ret = mockDecoderImpl->HwDecodeImage(mockDecoderImpl->primaryImage_, 259 mockDecoderImpl->gridInfo_, nullptr, false); 260 ASSERT_EQ(ret, false); 261 #endif 262 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeImageTest002 end"; 263 } 264 265 /** 266 * @tc.name: HeifDecoderImpl_HwDecodeGridsTest001 267 * @tc.desc: Verify that HwDecodeGrids call init when the conditions before decoding are not met. 268 * @tc.type: FUNC 269 */ 270 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_HwDecodeGridsTest001, TestSize.Level3) 271 { 272 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeGridsTest001 start"; 273 #ifdef HEIF_HW_DECODE_ENABLE 274 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 275 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 276 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 277 ASSERT_NE(streamPtr, nullptr); 278 extDecoder->SetSource(*streamPtr); 279 ASSERT_NE(extDecoder->stream_, nullptr); 280 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 281 bool ret = extDecoder->CheckCodec(); 282 ASSERT_NE(extDecoder->codec_, nullptr); 283 ASSERT_EQ(ret, true); 284 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 285 ASSERT_NE(mockDecoderImpl, nullptr); 286 sptr<SurfaceBuffer> mockHwBuffer; 287 ret = mockDecoderImpl->HwDecodeGrids(mockDecoderImpl->primaryImage_, 288 mockDecoderImpl->gridInfo_, mockHwBuffer); 289 ASSERT_EQ(ret, false); 290 ASSERT_NE(mockDecoderImpl->primaryImage_, nullptr); 291 ASSERT_NE(mockDecoderImpl->parser_, nullptr); 292 decltype(mockDecoderImpl->parser_->infeBoxes_) copyMockParserMap; 293 std::swap(mockDecoderImpl->parser_->infeBoxes_, copyMockParserMap); 294 ret = mockDecoderImpl->HwDecodeGrids(mockDecoderImpl->primaryImage_, 295 mockDecoderImpl->gridInfo_, mockHwBuffer); 296 ASSERT_EQ(ret, false); 297 std::swap(mockDecoderImpl->parser_->infeBoxes_, copyMockParserMap); 298 GridInfo mockGridInfo; 299 ret = mockDecoderImpl->HwDecodeGrids(mockDecoderImpl->primaryImage_, 300 mockGridInfo, mockHwBuffer); 301 ASSERT_EQ(ret, false); 302 #endif 303 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeGridsTest001 end"; 304 } 305 306 /** 307 * @tc.name: HeifDecoderImpl_HwDecodeSingleImageTest001 308 * @tc.desc: Verify that HwDecodeSingleImage call init when the conditions before decoding are not met. 309 * @tc.type: FUNC 310 */ 311 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_HwDecodeSingleImageTest001, TestSize.Level3) 312 { 313 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeSingleImageTest001 start"; 314 #ifdef HEIF_HW_DECODE_ENABLE 315 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 316 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 317 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 318 ASSERT_NE(streamPtr, nullptr); 319 extDecoder->SetSource(*streamPtr); 320 ASSERT_NE(extDecoder->stream_, nullptr); 321 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 322 bool ret = extDecoder->CheckCodec(); 323 ASSERT_NE(extDecoder->codec_, nullptr); 324 ASSERT_EQ(ret, true); 325 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 326 ASSERT_NE(mockDecoderImpl, nullptr); 327 sptr<SurfaceBuffer> mockHwBuffer; 328 ret = mockDecoderImpl->HwDecodeSingleImage(mockDecoderImpl->primaryImage_, 329 mockDecoderImpl->gridInfo_, mockHwBuffer); 330 ASSERT_EQ(ret, false); 331 #endif 332 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeSingleImageTest001 end"; 333 } 334 335 /** 336 * @tc.name: HeifDecoderImpl_HwDecodeMimeImageTest001 337 * @tc.desc: Verify that call HwDecodeMimeImage when the conditions before decoding are not met. 338 * @tc.type: FUNC 339 */ 340 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_HwDecodeMimeImageTest001, TestSize.Level3) 341 { 342 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeMimeImageTest001 start"; 343 #ifdef HEIF_HW_DECODE_ENABLE 344 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 345 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 346 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 347 ASSERT_NE(streamPtr, nullptr); 348 extDecoder->SetSource(*streamPtr); 349 ASSERT_NE(extDecoder->stream_, nullptr); 350 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 351 bool ret = extDecoder->CheckCodec(); 352 ASSERT_NE(extDecoder->codec_, nullptr); 353 ASSERT_EQ(ret, true); 354 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 355 ASSERT_NE(mockDecoderImpl, nullptr); 356 std::shared_ptr<HeifImage> mockHeifImage; 357 ret = mockDecoderImpl->HwDecodeMimeImage(mockHeifImage); 358 ASSERT_EQ(ret, false); 359 auto copyAuxiDstMem = mockDecoderImpl->auxiliaryDstMemory_; 360 mockDecoderImpl->auxiliaryDstMemory_ = nullptr; 361 ret = mockDecoderImpl->HwDecodeMimeImage(mockDecoderImpl->primaryImage_); 362 ASSERT_EQ(ret, false); 363 mockDecoderImpl->auxiliaryDstMemory_ = copyAuxiDstMem; 364 #endif 365 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_HwDecodeMimeImageTest001 end"; 366 } 367 368 /** 369 * @tc.name: HeifDecoderImpl_SwDecodeImageTest001 370 * @tc.desc: Verify that call SwDecodeImage when the conditions before decoding are not met. 371 * @tc.type: FUNC 372 */ 373 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_SwDecodeImageTest001, TestSize.Level3) 374 { 375 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_SwDecodeImageTest001 start"; 376 #ifdef HEIF_HW_DECODE_ENABLE 377 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 378 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 379 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 380 ASSERT_NE(streamPtr, nullptr); 381 extDecoder->SetSource(*streamPtr); 382 ASSERT_NE(extDecoder->stream_, nullptr); 383 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 384 bool ret = extDecoder->CheckCodec(); 385 ASSERT_NE(extDecoder->codec_, nullptr); 386 ASSERT_EQ(ret, true); 387 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 388 ASSERT_NE(mockDecoderImpl, nullptr); 389 mockDecoderImpl->outPixelFormat_ = PixelFormat::UNKNOWN; 390 HevcSoftDecodeParam mockParam; 391 std::shared_ptr<HeifImage> mockHeifImage; 392 ret = mockDecoderImpl->SwDecodeImage(mockHeifImage, mockParam, mockDecoderImpl->gridInfo_, false); 393 ASSERT_EQ(ret, false); 394 mockDecoderImpl->outPixelFormat_ = PixelFormat::RGBA_8888; 395 ret = mockDecoderImpl->SwDecodeImage(mockHeifImage, mockParam, mockDecoderImpl->gridInfo_, false); 396 ASSERT_EQ(ret, false); 397 #endif 398 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_SwDecodeImageTest001 end"; 399 } 400 401 /** 402 * @tc.name: HeifDecoderImpl_ProcessChunkHeadTest001 403 * @tc.desc: Verify that call ProcessChunkHead when len less than CHUNK_HEAD_SIZE. 404 * @tc.type: FUNC 405 */ 406 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_ProcessChunkHeadTest001, TestSize.Level3) 407 { 408 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_ProcessChunkHeadTest001 start"; 409 #ifdef HEIF_HW_DECODE_ENABLE 410 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 411 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 412 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 413 ASSERT_NE(streamPtr, nullptr); 414 extDecoder->SetSource(*streamPtr); 415 ASSERT_NE(extDecoder->stream_, nullptr); 416 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 417 bool ret = extDecoder->CheckCodec(); 418 ASSERT_NE(extDecoder->codec_, nullptr); 419 ASSERT_EQ(ret, true); 420 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 421 ASSERT_NE(mockDecoderImpl, nullptr); 422 ret = mockDecoderImpl->ProcessChunkHead(nullptr, SIZE_ZERO); 423 ASSERT_EQ(ret, false); 424 #endif 425 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_ProcessChunkHeadTest001 end"; 426 } 427 428 /** 429 * @tc.name: HeifDecoderImpl_getTmapInfoTest001 430 * @tc.desc: Verify that call getTmapInfo when frameInfo is nullptr. 431 * @tc.type: FUNC 432 */ 433 HWTEST_F(HeifDecodeImplTest, HeifDecoderImpl_getTmapInfoTest001, TestSize.Level3) 434 { 435 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_getTmapInfoTest001 start"; 436 #ifdef HEIF_HW_DECODE_ENABLE 437 std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>(); 438 const int fd = open("/data/local/tmp/image/test_heif.heic", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 439 std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd); 440 ASSERT_NE(streamPtr, nullptr); 441 extDecoder->SetSource(*streamPtr); 442 ASSERT_NE(extDecoder->stream_, nullptr); 443 extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_)); 444 bool ret = extDecoder->CheckCodec(); 445 ASSERT_NE(extDecoder->codec_, nullptr); 446 ASSERT_EQ(ret, true); 447 auto mockDecoderImpl = reinterpret_cast<HeifDecoderImpl*>(extDecoder->codec_->getHeifContext()); 448 ASSERT_NE(mockDecoderImpl, nullptr); 449 ret = mockDecoderImpl->getTmapInfo(nullptr); 450 ASSERT_EQ(ret, true); 451 HeifFrameInfo mockFrameInfo; 452 ret = mockDecoderImpl->getTmapInfo(&mockFrameInfo); 453 ASSERT_EQ(ret, true); 454 #endif 455 GTEST_LOG_(INFO) << "HeifDecodeImplTest: HeifDecoderImpl_getTmapInfoTest001 end"; 456 } 457 } // namespace ImagePlugin 458 } // namespace OHOS