1 /* 2 * Copyright (c) 2023 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 "hardware/jpeg_hw_decoder.h" 18 #include "mock_jpeg_hw_decode_flow.h" 19 #include "image_system_properties.h" 20 21 namespace OHOS::Media { 22 using namespace testing::ext; 23 using namespace OHOS::ImagePlugin; 24 using namespace OHOS::HDI::Codec::Image::V2_0; 25 26 class JpegHwDecoderTest : public testing::Test { 27 public: 28 static constexpr char JPEG_FORMAT[] = "image/jpeg"; 29 static constexpr char HEIF_FORMAT[] = "image/heif"; 30 static constexpr char TEST_JPEG_IMG[] = "/data/local/tmp/image/test_hw1.jpg"; 31 }; 32 33 HWTEST_F(JpegHwDecoderTest, unsupported_img_empty_format, TestSize.Level1) 34 { 35 JpegHardwareDecoder testObj; 36 Size srcImgSize = { 37 .width = 8192, 38 .height = 8192 39 }; 40 bool ret = testObj.IsHardwareDecodeSupported("", srcImgSize); 41 ASSERT_FALSE(ret); 42 } 43 44 HWTEST_F(JpegHwDecoderTest, unsupported_img_unknown_format, TestSize.Level1) 45 { 46 JpegHardwareDecoder testObj; 47 Size srcImgSize = { 48 .width = 512, 49 .height = 512 50 }; 51 bool ret = testObj.IsHardwareDecodeSupported(HEIF_FORMAT, srcImgSize); 52 ASSERT_FALSE(ret); 53 } 54 55 HWTEST_F(JpegHwDecoderTest, unsupported_img_size_too_small, TestSize.Level1) 56 { 57 JpegHardwareDecoder testObj; 58 Size srcImgSize = { 59 .width = 140, 60 .height = 512 61 }; 62 bool ret = testObj.IsHardwareDecodeSupported(JPEG_FORMAT, srcImgSize); 63 ASSERT_FALSE(ret); 64 } 65 66 HWTEST_F(JpegHwDecoderTest, unsupported_img_size_too_big, TestSize.Level1) 67 { 68 JpegHardwareDecoder testObj; 69 Size srcImgSize = { 70 .width = 8192, 71 .height = 8193 72 }; 73 bool ret = testObj.IsHardwareDecodeSupported(JPEG_FORMAT, srcImgSize); 74 ASSERT_FALSE(ret); 75 } 76 77 HWTEST_F(JpegHwDecoderTest, decode_ok, TestSize.Level1) 78 { 79 CommandOpt opt; 80 opt.width = 1280; 81 opt.height = 768; 82 opt.sampleSize = 1; 83 opt.inputFile = TEST_JPEG_IMG; 84 JpegHwDecoderFlow demo; 85 bool ret = true; 86 if (ImageSystemProperties::GetHardWareDecodeEnabled()) { 87 ret = demo.Run(opt, false); 88 } 89 ASSERT_TRUE(ret); 90 } 91 } // namespace OHOS::Media