1 /* 2 * Copyright (C) 2024 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 "image_source_impl.h" 18 19 namespace OHOS { 20 namespace Multimedia { 21 using namespace testing::ext; 22 using namespace OHOS::Media; 23 static const std::string IMAGE_JPEG_PATH = "/data/local/tmp/image/test_exif.jpg"; 24 25 class ImageSourceImplTest : public testing::Test { 26 public: ImageSourceImplTest()27 ImageSourceImplTest() {} ~ImageSourceImplTest()28 ~ImageSourceImplTest() {} 29 }; 30 31 /** 32 * @tc.name: ImageSourceImplTest001 33 * @tc.desc: test ImageSourceImpl 34 * @tc.type: FUNC 35 */ 36 HWTEST_F(ImageSourceImplTest, ImageSourceImplTest001, TestSize.Level3) 37 { 38 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest001 start"; 39 std::string uri = ""; 40 uint32_t errCode = 0; 41 std::unique_ptr<ImageSource> imageSource = ImageSourceImpl::CreateImageSource(uri, &errCode); 42 ASSERT_EQ(imageSource, nullptr); 43 SourceOptions opts; 44 imageSource = ImageSourceImpl::CreateImageSourceWithOption(uri, opts, &errCode); 45 ASSERT_EQ(imageSource, nullptr); 46 int fd = 0; 47 imageSource = ImageSourceImpl::CreateImageSource(fd, &errCode); 48 ASSERT_EQ(imageSource, nullptr); 49 imageSource = ImageSourceImpl::CreateImageSourceWithOption(fd, opts, &errCode); 50 ASSERT_EQ(imageSource, nullptr); 51 int32_t offset = 0; 52 int32_t length = 0; 53 imageSource = ImageSourceImpl::CreateImageSource(fd, offset, length, opts, errCode); 54 ASSERT_EQ(imageSource, nullptr); 55 const uint32_t size = 10; 56 uint8_t data[size] = {0}; 57 imageSource = ImageSourceImpl::CreateImageSource(&data[0], size, &errCode); 58 ASSERT_NE(imageSource, nullptr); 59 imageSource = ImageSourceImpl::CreateImageSourceWithOption(&data[0], size, opts, &errCode); 60 ASSERT_NE(imageSource, nullptr); 61 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest001 end"; 62 } 63 64 /** 65 * @tc.name: ImageSourceImplTest002 66 * @tc.desc: test ImageSourceImpl 67 * @tc.type: FUNC 68 */ 69 HWTEST_F(ImageSourceImplTest, ImageSourceImplTest002, TestSize.Level3) 70 { 71 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest002 start"; 72 SourceOptions opts; 73 uint32_t errorCode = 0; 74 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_JPEG_PATH, opts, errorCode); 75 ASSERT_EQ(errorCode, 0); 76 ImageSourceImpl imageSourceImpl(std::move(imageSource)); 77 ImageInfo imageInfo; 78 imageSourceImpl.GetImageInfo(0, imageInfo); 79 std::set<std::string> formats{}; 80 imageSourceImpl.GetSupportedFormats(formats); 81 std::string key = "key"; 82 std::string value = "value"; 83 imageSourceImpl.GetImageProperty(key, 0, value); 84 key = "BitsPerSample"; 85 imageSourceImpl.ModifyImageProperty(key, value); 86 key = "Orientation"; 87 imageSourceImpl.ModifyImageProperty(key, value); 88 key = "ImageLength"; 89 imageSourceImpl.ModifyImageProperty(key, value); 90 key = "ImageWidth"; 91 imageSourceImpl.ModifyImageProperty(key, value); 92 key = "GPSLatitude"; 93 imageSourceImpl.ModifyImageProperty(key, value); 94 key = "GPSLongitude"; 95 imageSourceImpl.ModifyImageProperty(key, value); 96 key = "GPSLatitudeRef"; 97 imageSourceImpl.ModifyImageProperty(key, value); 98 key = "GPSLongitudeRef"; 99 imageSourceImpl.ModifyImageProperty(key, value); 100 imageSourceImpl.SetPathName(IMAGE_JPEG_PATH); 101 imageSourceImpl.ModifyImageProperty(key, value); 102 imageSourceImpl.SetFd(0); 103 imageSourceImpl.ModifyImageProperty(key, value); 104 uint8_t data = 0; 105 imageSourceImpl.SetBuffer(&data, 1); 106 imageSourceImpl.ModifyImageProperty(key, value); 107 imageSourceImpl.GetFrameCount(errorCode); 108 imageSourceImpl.UpdateData(nullptr, 0, false); 109 DecodeOptions decodeOpts; 110 imageSourceImpl.CreatePixelMap(0, decodeOpts, errorCode); 111 imageSourceImpl.CreatePixelMapList(0, decodeOpts, &errorCode); 112 imageSourceImpl.GetDelayTime(&errorCode); 113 imageSourceImpl.Release(); 114 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest002 end"; 115 } 116 117 /** 118 * @tc.name: ImageSourceImplTest003 119 * @tc.desc: test ImageSourceImpl 120 * @tc.type: FUNC 121 */ 122 HWTEST_F(ImageSourceImplTest, ImageSourceImplTest003, TestSize.Level3) 123 { 124 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest003 start"; 125 ImageSourceImpl imageSourceImplNull(nullptr); 126 ImageInfo imageInfo; 127 imageSourceImplNull.GetImageInfo(0, imageInfo); 128 std::set<std::string> formats{}; 129 imageSourceImplNull.GetSupportedFormats(formats); 130 uint32_t errorCode = 0; 131 imageSourceImplNull.GetFrameCount(errorCode); 132 imageSourceImplNull.UpdateData(nullptr, 0, false); 133 DecodeOptions decodeOpts; 134 imageSourceImplNull.CreatePixelMap(0, decodeOpts, errorCode); 135 imageSourceImplNull.CreatePixelMapList(0, decodeOpts, &errorCode); 136 imageSourceImplNull.GetDelayTime(&errorCode); 137 imageSourceImplNull.SetPathName(""); 138 imageSourceImplNull.SetFd(0); 139 imageSourceImplNull.SetBuffer(nullptr, 0); 140 imageSourceImplNull.Release(); 141 GTEST_LOG_(INFO) << "ImageSourceImplTest: ImageSourceImplTest003 end"; 142 } 143 } 144 }