From 7671c754f6c4a593e9cb94a6a358352cb837600e Mon Sep 17 00:00:00 2001 From: zhaona45 Date: Thu, 14 Aug 2025 11:02:56 +0800 Subject: [PATCH] fix tdd crash Signed-off-by: zhaona45 Change-Id: I908ec91f3cbb53c7d7148203e887c351b1c9fea4 --- .../test/unittest/jpeg_decoder_ex_test.cpp | 42 +++++------------ .../test/unittest/jpeg_decoder_test.cpp | 47 ++++++++++++------- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_ex_test.cpp b/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_ex_test.cpp index 513611704..ffad5235b 100644 --- a/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_ex_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_ex_test.cpp @@ -612,9 +612,11 @@ HWTEST_F(JpegDecoderTest, SetDecodeOptionsTest001, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest001 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); PixelDecodeOptions opts; PlImageInfo info; // goto : return ret @@ -657,9 +659,8 @@ HWTEST_F(JpegDecoderTest, SetDecodeOptionsTest003, TestSize.Level3) jpegDecoder->SetSource(*mock.get()); PixelDecodeOptions opts; PlImageInfo info; - uint32_t result = jpegDecoder->SetDecodeOptions(0, opts, info); - // goto DecoderHeader return ERR_IMAGE_SOURCE_DATA_INCOMPLETE - ASSERT_EQ(result, ERR_IMAGE_SOURCE_DATA_INCOMPLETE); + uint32_t result = jpegDecoder->SetDecodeOptions(1, opts, info); + ASSERT_EQ(result, ERR_IMAGE_INVALID_PARAMETER); GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest003 end"; } @@ -672,31 +673,12 @@ HWTEST_F(JpegDecoderTest, SetDecodeOptionsTest004, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest004 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); - PixelDecodeOptions opts; - PlImageInfo info; - uint32_t result = jpegDecoder->SetDecodeOptions(1, opts, info); - ASSERT_EQ(result, ERR_IMAGE_INVALID_PARAMETER); - GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest004 end"; -} - -/** - * @tc.name: SetDecodeOptionsTest005 - * @tc.desc: Test of SetDecodeOptions - * @tc.type: FUNC - */ -HWTEST_F(JpegDecoderTest, SetDecodeOptionsTest005, TestSize.Level3) -{ - GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest005 start"; - auto jpegDecoder = std::make_shared(); PixelDecodeOptions opts; PlImageInfo info; uint32_t result = jpegDecoder->SetDecodeOptions(0, opts, info); // goto DecoderHeader return ERR_IMAGE_SOURCE_DATA_INCOMPLETE ASSERT_EQ(result, ERR_MEDIA_INVALID_OPERATION); - GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest005 end"; + GTEST_LOG_(INFO) << "JpegDecoderTest: SetDecodeOptionsTest004 end"; } /** @@ -708,9 +690,11 @@ HWTEST_F(JpegDecoderTest, GetImageSizeTest001, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: GetImageSizeTest001 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); ImagePlugin::Size plSize; uint32_t result = jpegDecoder->GetImageSize(0, plSize); // goto DecodeHeader return ERR_IMAGE_SOURCE_DATA_INCOMPLETE diff --git a/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_test.cpp b/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_test.cpp index f152729b1..19ec29387 100644 --- a/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/jpeg_decoder_test.cpp @@ -94,9 +94,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest002, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest002 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); PixelDecodeOptions opts; PlImageInfo info; jpegDecoder->state_ = JpegDecodingState::IMAGE_DECODING; @@ -154,8 +156,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest005, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest005 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); ImagePlugin::Size plSize; uint32_t result = jpegDecoder->GetImageSize(0, plSize); ASSERT_EQ(result, ERR_IMAGE_SOURCE_DATA_INCOMPLETE); @@ -171,8 +176,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest006, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest006 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); ImagePlugin::Size plSize; uint32_t result = jpegDecoder->GetImageSize(0, plSize); ASSERT_EQ(result, ERR_IMAGE_SOURCE_DATA_INCOMPLETE); @@ -246,10 +254,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest0010, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest0010 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetStreamSize(1); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); ImagePlugin::Size plSize; uint32_t result = jpegDecoder->GetImageSize(0, plSize); ASSERT_EQ(result, ERR_IMAGE_SOURCE_DATA_INCOMPLETE); @@ -322,9 +331,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest0014, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest0014 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); DecodeContext context; jpegDecoder->state_ = JpegDecodingState::IMAGE_ERROR; uint32_t ret = jpegDecoder->Decode(0, context); @@ -378,9 +389,11 @@ HWTEST_F(JpegDecoderTest, JpegDecoderTest0017, TestSize.Level3) { GTEST_LOG_(INFO) << "JpegDecoderTest: JpegDecoderTest0017 start"; auto jpegDecoder = std::make_shared(); - auto mock = std::make_shared(); - mock->SetReturn(false); - jpegDecoder->SetSource(*mock.get()); + int size = 1; + std::unique_ptr data = std::make_unique(size); + auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size); + ASSERT_NE(streamPtr, nullptr); + jpegDecoder->SetSource(*streamPtr.release()); ProgDecodeContext context; uint32_t result = jpegDecoder->PromoteIncrementalDecode(0, context); ASSERT_EQ(result, ERR_MEDIA_INVALID_OPERATION); -- Gitee