1 /* 2 * Copyright (C) 2021 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 <fstream> 18 #include <fcntl.h> 19 #include "directory_ex.h" 20 #include "image_packer.h" 21 #include "image_source.h" 22 #include "image_type.h" 23 #include "image_utils.h" 24 #include "incremental_pixel_map.h" 25 #include "media_errors.h" 26 #include "pixel_map.h" 27 #include "pixel_map_manager.h" 28 #include "image_receiver.h" 29 #include "image_source_util.h" 30 #include "graphic_common.h" 31 #include "image_receiver_manager.h" 32 33 using namespace testing::ext; 34 using namespace OHOS::Media; 35 namespace OHOS { 36 namespace Multimedia { 37 static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg"; 38 static const std::string OPTION_FORMAT_TEST = "image/jpeg"; 39 static const std::int32_t OPTION_QUALITY_TEST = 100; 40 static const std::int32_t OPTION_NUMBERHINT_TEST = 1; 41 42 class InterfaceTest : public testing::Test { 43 public: InterfaceTest()44 InterfaceTest() {} ~InterfaceTest()45 ~InterfaceTest() {} 46 }; 47 48 /** 49 * @tc.name: InterfaceTest001 50 * @tc.desc: PromoteDecoding 51 * @tc.type: FUNC 52 */ 53 HWTEST_F(InterfaceTest, InterfaceTest001, TestSize.Level3) 54 { 55 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest001 start"; 56 uint32_t errorCode = 0; 57 IncrementalSourceOptions incOpts; 58 incOpts.incrementalMode = IncrementalMode::INCREMENTAL_DATA; 59 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateIncrementalImageSource(incOpts, errorCode); 60 DecodeOptions decodeOpts; 61 std::unique_ptr<IncrementalPixelMap> incPixelMap = imageSource->CreateIncrementalPixelMap(0, decodeOpts, 62 errorCode); 63 uint8_t decodeProgress = 0; 64 incPixelMap->PromoteDecoding(decodeProgress); 65 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest001 end"; 66 } 67 68 /** 69 * @tc.name: InterfaceTest002 70 * @tc.desc: DetachFromDecoding 71 * @tc.type: FUNC 72 */ 73 HWTEST_F(InterfaceTest, InterfaceTest002, TestSize.Level3) 74 { 75 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest002 start"; 76 uint32_t errorCode = 0; 77 IncrementalSourceOptions incOpts; 78 incOpts.incrementalMode = IncrementalMode::INCREMENTAL_DATA; 79 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateIncrementalImageSource(incOpts, errorCode); 80 DecodeOptions decodeOpts; 81 std::unique_ptr<IncrementalPixelMap> incPixelMap = imageSource->CreateIncrementalPixelMap(0, decodeOpts, 82 errorCode); 83 incPixelMap->DetachFromDecoding(); 84 ASSERT_NE(incPixelMap, nullptr); 85 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest002 end"; 86 } 87 88 /** 89 * @tc.name: InterfaceTest003 90 * @tc.desc: GetDecodingStatus 91 * @tc.type: FUNC 92 */ 93 HWTEST_F(InterfaceTest, InterfaceTest003, TestSize.Level3) 94 { 95 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest003 start"; 96 uint32_t errorCode = 0; 97 IncrementalSourceOptions incOpts; 98 incOpts.incrementalMode = IncrementalMode::INCREMENTAL_DATA; 99 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateIncrementalImageSource(incOpts, errorCode); 100 DecodeOptions decodeOpts; 101 std::unique_ptr<IncrementalPixelMap> incPixelMap = imageSource->CreateIncrementalPixelMap(0, decodeOpts, 102 errorCode); 103 incPixelMap->DetachFromDecoding(); 104 IncrementalDecodingStatus status = incPixelMap->GetDecodingStatus(); 105 ASSERT_EQ(status.decodingProgress, 0); 106 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest003 end"; 107 } 108 109 /** 110 * @tc.name: InterfaceTest004 111 * @tc.desc: FreePixels 112 * @tc.type: FUNC 113 */ 114 HWTEST_F(InterfaceTest, InterfaceTest004, TestSize.Level3) 115 { 116 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest004 start"; 117 PixelMap *pixelMap = nullptr; 118 PixelMapManager pixelMapManager(pixelMap); 119 pixelMapManager.FreePixels(); 120 ASSERT_EQ(&pixelMapManager.GetPixelMap(), nullptr); 121 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest004 end"; 122 } 123 124 /** 125 * @tc.name: InterfaceTest005 126 * @tc.desc: Invalid 127 * @tc.type: FUNC 128 */ 129 HWTEST_F(InterfaceTest, InterfaceTest005, TestSize.Level3) 130 { 131 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest005 start"; 132 PixelMap *pixelMap = nullptr; 133 PixelMapManager pixelMapManager(pixelMap); 134 bool flag = pixelMapManager.Invalid(); 135 ASSERT_EQ(flag, true); 136 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest005 end"; 137 } 138 139 /** 140 * @tc.name: InterfaceTest006 141 * @tc.desc: GetPixelMap 142 * @tc.type: FUNC 143 */ 144 HWTEST_F(InterfaceTest, InterfaceTest006, TestSize.Level3) 145 { 146 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest006 start"; 147 PixelMap *pixelMap = nullptr; 148 PixelMapManager pixelMapManager(pixelMap); 149 ASSERT_EQ(&pixelMapManager.GetPixelMap(), nullptr); 150 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest006 end"; 151 } 152 153 /** 154 * @tc.name: InterfaceTest007 155 * @tc.desc: GetByteCount 156 * @tc.type: FUNC 157 */ 158 HWTEST_F(InterfaceTest, InterfaceTest007, TestSize.Level3) 159 { 160 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest007 start"; 161 PixelMap *pixelMap = nullptr; 162 PixelMapManager pixelMapManager(pixelMap); 163 int32_t count = pixelMapManager.GetByteCount(); 164 ASSERT_EQ(count, 0); 165 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest007 end"; 166 } 167 168 /** 169 * @tc.name: InterfaceTest008 170 * @tc.desc: Ref 171 * @tc.type: FUNC 172 */ 173 HWTEST_F(InterfaceTest, InterfaceTest008, TestSize.Level3) 174 { 175 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest008 start"; 176 PixelMap *pixelMap = nullptr; 177 PixelMapManager pixelMapManager(pixelMap); 178 pixelMapManager.Ref(); 179 ASSERT_EQ(pixelMap, nullptr); 180 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest008 end"; 181 } 182 183 /** 184 * @tc.name: InterfaceTest009 185 * @tc.desc: UnRef 186 * @tc.type: FUNC 187 */ 188 HWTEST_F(InterfaceTest, InterfaceTest009, TestSize.Level3) 189 { 190 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest009 start"; 191 PixelMap *pixelMap = nullptr; 192 PixelMapManager pixelMapManager(pixelMap); 193 pixelMapManager.UnRef(); 194 ASSERT_EQ(pixelMap, nullptr); 195 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest009 end"; 196 } 197 198 /** 199 * @tc.name: InterfaceTest0010 200 * @tc.desc: ImagePacker StartPacking 201 * @tc.type: FUNC 202 */ 203 HWTEST_F(InterfaceTest, InterfaceTest0010, TestSize.Level3) 204 { 205 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0010 start"; 206 ImagePacker imagePacker; 207 PackOption option; 208 option.format = OPTION_FORMAT_TEST; 209 option.quality = OPTION_QUALITY_TEST; 210 option.numberHint = OPTION_NUMBERHINT_TEST; 211 size_t bufferSize = 0; 212 bool ret = ImageUtils::GetFileSize(IMAGE_INPUT_JPEG_PATH, bufferSize); 213 ASSERT_EQ(ret, true); 214 uint8_t *buffer = reinterpret_cast<uint8_t *>(malloc(bufferSize)); 215 imagePacker.StartPacking(buffer, bufferSize, option); 216 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0010 end"; 217 } 218 219 /** 220 * @tc.name: InterfaceTest0011 221 * @tc.desc: ImagePacker StartPacking 222 * @tc.type: FUNC 223 */ 224 HWTEST_F(InterfaceTest, InterfaceTest0011, TestSize.Level3) 225 { 226 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0011 start"; 227 ImagePacker imagePacker; 228 PackOption option; 229 option.format = OPTION_FORMAT_TEST; 230 option.quality = OPTION_QUALITY_TEST; 231 option.numberHint = OPTION_NUMBERHINT_TEST; 232 size_t bufferSize = 0; 233 bool ret = ImageUtils::GetFileSize(IMAGE_INPUT_JPEG_PATH, bufferSize); 234 ASSERT_EQ(ret, true); 235 uint8_t *buffer = nullptr; 236 imagePacker.StartPacking(buffer, bufferSize, option); 237 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0011 end"; 238 } 239 240 /** 241 * @tc.name: InterfaceTest0012 242 * @tc.desc: ImagePacker StartPacking 243 * @tc.type: FUNC 244 */ 245 HWTEST_F(InterfaceTest, InterfaceTest0012, TestSize.Level3) 246 { 247 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0012 start"; 248 ImagePacker imagePacker; 249 PackOption option; 250 option.format = OPTION_FORMAT_TEST; 251 option.quality = OPTION_QUALITY_TEST; 252 option.numberHint = OPTION_NUMBERHINT_TEST; 253 size_t bufferSize = 0; 254 uint8_t *buffer = reinterpret_cast<uint8_t *>(malloc(bufferSize)); 255 ASSERT_NE(buffer, nullptr); 256 uint32_t tmp = imagePacker.StartPacking(buffer, bufferSize, option); 257 ASSERT_EQ(tmp, SUCCESS); 258 GTEST_LOG_(INFO) << "InterfaceTest: InterfaceTest0012 end"; 259 } 260 } 261 }