From a20a4d06bf915a797dc6c39481f476446ded73d1 Mon Sep 17 00:00:00 2001 From: baosiyuan Date: Thu, 12 Jun 2025 10:50:16 +0800 Subject: [PATCH] add unittest Signed-off-by: baosiyuan Change-Id: I3a031adb02050830f568838b9197b35d7cff6313 --- .../unittest/jpeg_hw_decoder_test.cpp | 22 ++++++++ .../test/unittest/picture_ext_test.cpp | 28 +++++++++++ .../unittest/plugin_test/ext_decoder_test.cpp | 50 +++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/frameworks/innerkitsimpl/test/unittest/jpeg_hw_decode/unittest/jpeg_hw_decoder_test.cpp b/frameworks/innerkitsimpl/test/unittest/jpeg_hw_decode/unittest/jpeg_hw_decoder_test.cpp index db28fb461..f29052c4a 100644 --- a/frameworks/innerkitsimpl/test/unittest/jpeg_hw_decode/unittest/jpeg_hw_decoder_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/jpeg_hw_decode/unittest/jpeg_hw_decoder_test.cpp @@ -126,6 +126,26 @@ HWTEST_F(JpegHwDecoderTest, IsHardwareDecodeSupportedTest002, TestSize.Level3) GTEST_LOG_(INFO) << "JpegHwDecoderTest: IsHardwareDecodeSupportedTest002 end"; } +/** + * @tc.name: IsHardwareDecodeSupportedTest003 + * @tc.desc: Verify that IsHardwareDecodeSupported returns false when input is invalid, + * including empty file path and zero size, and when hardware decoder is unavailable (nullptr). + * @tc.type: FUNC + */ +HWTEST_F(JpegHwDecoderTest, IsHardwareDecodeSupportedTest003, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "JpegHwDecoderTest: IsHardwareDecodeSupportedTest003 start"; + JpegHardwareDecoder jpegHardwareDecoder; + ASSERT_NE(jpegHardwareDecoder.hwDecoder_, nullptr); + Media::Size size = {0, 0}; + bool ret = jpegHardwareDecoder.IsHardwareDecodeSupported("", size); + EXPECT_FALSE(ret); + jpegHardwareDecoder.hwDecoder_ = nullptr; + ret = jpegHardwareDecoder.IsHardwareDecodeSupported("", size); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "JpegHwDecoderTest: IsHardwareDecodeSupportedTest003 end"; +} + /** * @tc.name: CheckInputColorFmtTest001 * @tc.desc: test the CheckInputColorFmt @@ -235,4 +255,6 @@ HWTEST_F(JpegHwDecoderTest, PrepareInputDataTest001, TestSize.Level3) ASSERT_EQ(ret, false); GTEST_LOG_(INFO) << "JpegHwDecoderTest: PrepareInputDataTest001 end"; } + + } // namespace OHOS::Media \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/unittest/picture_ext_test.cpp b/frameworks/innerkitsimpl/test/unittest/picture_ext_test.cpp index 24936e0a2..c7f59cf8e 100644 --- a/frameworks/innerkitsimpl/test/unittest/picture_ext_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/picture_ext_test.cpp @@ -720,6 +720,34 @@ HWTEST_F(PictureExtTest, getHDRComposedPixelmapTest001, TestSize.Level1) EXPECT_EQ(format, PixelFormat::RGBA_1010102); } +/** + * @tc.name: getHDRComposedPixelmapTest002 + * @tc.desc: Verifies that HDR composed PixelMap is correctly created with expected properties from a JPEG image source. + * @tc.type: FUNC + */ +HWTEST_F(PictureExtTest, getHDRComposedPixelmapTest001, TestSize.Level1) +{ + uint32_t errorCode = 0; + SourceOptions sourceOpts; + std::unique_ptr imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_HEIFHDR_PATH.c_str(), + sourceOpts, errorCode); + ASSERT_NE(imageSource, nullptr); + DecodingOptionsForPicture opts; + opts.desiredPixelFormat = PixelFormat::YCBCR_P010; + std::unique_ptr picture = imageSource->CreatePicture(opts, errorCode); + ASSERT_EQ(errorCode, OHOS::Media::SUCCESS); + ASSERT_NE(picture, nullptr); + auto ret = picture->GetHdrComposedPixelMap(); + EXPECT_NE(ret, nullptr); + + opts.desiredPixelFormat = Media::PixelFormat::YCRCB_P010; + picture = imageSource->CreatePicture(opts, errorCode); + ASSERT_EQ(errorCode, OHOS::Media::SUCCESS); + ASSERT_NE(picture, nullptr); + ret = picture->GetHdrComposedPixelMap(); + EXPECT_NE(ret, nullptr); +} + /** * @tc.name: getHDRComposedPixelmapTest002 * @tc.desc: Verifies that HDR composed PixelMap is null when the picture is created with a fragment map diff --git a/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp b/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp index c59d567ec..cd40b641e 100644 --- a/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp @@ -60,6 +60,7 @@ const static string SUPPORT_SCALE_KEY = "SupportScale"; const static string SUPPORT_CROP_KEY = "SupportCrop"; const static string EXT_SHAREMEM_NAME = "EXT RawData"; const static string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test_hw1.jpg"; +static const std::string IMAGE_DEST = "/data/local/tmp/image/test_encode_out.dat"; class ExtDecoderTest : public testing::Test { public: ExtDecoderTest() {} @@ -841,6 +842,24 @@ HWTEST_F(ExtDecoderTest, FinalizeEncodeTest001, TestSize.Level3) GTEST_LOG_(INFO) << "ExtDecoderTest: FinalizeEncodeTest001 end"; } +/** + * @tc.name: FinalizeEncodeTest002 + * @tc.desc: Verify that FinalizePacking returns ERR_IMAGE_INVALID_PARAMETER when packing + * is initialized with invalid parameters (e.g., empty destination path). + * @tc.type: FUNC + */ +HWTEST_F(ExtEncoderTest, FinalizeEncodeTest002, TestSize.Level3) +{ + uint32_t errorCode = -1; + ImagePacker pack; + PackOption option; + option.format = "image/jpeg"; + uint32_t ret = pack.StartPacking(IMAGE_DEST, option); + ASSERT_EQ(ret, OHOS::Media::SUCCESS); + ret = pack.FinalizePacking(); + EXPECT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER); +} + /** * @tc.name: readTest001 * @tc.desc: Test of read @@ -1064,6 +1083,21 @@ HWTEST_F(ExtDecoderTest, IsHardwareEncodeSupportedTest001, TestSize.Level3) GTEST_LOG_(INFO) << "ExtDecoderTest: IsHardwareEncodeSupportedTest001 end"; } +/** + * @tc.name: GetJpegYuvOutFmtTest002 + * @tc.desc: Verify that IsHardwareEncodeSupported returns false when input pixelMap is nullptr, + * indicating hardware encoding is not supported for invalid input. + * @tc.type: FUNC + */ +HWTEST_F(ExtEncoderTest, IsHardwareEncodeSupportedTest002, TestSize.Level3) +{ + ExtEncoder encoder; + PlEncodeOptions opts; + Media::PixelMap *pixelMap = nullptr; + bool res = encoder.IsHardwareEncodeSupported(opts, pixelMap); + EXPECT_FALSE(res); +} + /** @tc.name: DoHardWareEncodeTest001 @tc.desc: Test of DoHardWareEncode @@ -1830,6 +1864,22 @@ HWTEST_F(ExtDecoderTest, EncodeHeifByPixelmapTest001, TestSize.Level3) GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeHeifByPixelmapTest001 end"; } +/** + * @tc.name: EncodeHeifByPixelmapTest002 + * @tc.desc: Verify that EncodeHeifByPixelmap returns ERR_IMAGE_INVALID_PARAMETER + * when both input pixelMap and encoder output are nullptr, which are invalid parameters for HEIF encoding. + * @tc.type: FUNC + */ +HWTEST_F(ExtEncoderTest, EncodeHeifByPixelmapTest002, TestSize.Level3) +{ + ExtEncoder encoder; + PlEncodeOptions opts; + Media::PixelMap *pixelMap = nullptr; + encoder.output_ = nullptr; + bool res = encoder->EncodeHeifByPixelmap(pixelMap, opts); + EXPECT_EQ(res, ERR_IMAGE_INVALID_PARAMETER); +} + /** * @tc.name: TryHardwareEncodePictureTest001 * @tc.desc: test the function of TryHardwareEncodePicture -- Gitee