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 #define private public
17 #define protected public
18 #include "image_source.h"
19 #undef private
20 #undef protected
21 #include "mock_image_related_class.h"
22
23 namespace {
24 bool g_mockImageSourceCreateImageSourceRet = true;
25 uint32_t g_mockImageSourceCreateImageSourceErrorCode = 0;
26 bool g_mockImageSourceCreatePixelMapRet = true;
27 uint32_t g_mockImageSourceCreatePixelMapErrorCode = 0;
28 uint32_t g_mockImageSourceGetSupportedFormatsRet = 0;
29 }
30
MockImageSourceCreateImageSource(bool mockRet,uint32_t errorCode)31 void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode)
32 {
33 g_mockImageSourceCreateImageSourceRet = mockRet;
34 g_mockImageSourceCreateImageSourceErrorCode = errorCode;
35 }
36
MockImageSourceCreatePixelMap(bool mockRet,uint32_t errorCode)37 void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode)
38 {
39 g_mockImageSourceCreatePixelMapRet = mockRet;
40 g_mockImageSourceCreatePixelMapErrorCode = errorCode;
41 }
42
MockImageSourceGetSupportedFormats(uint32_t mockRet)43 void MockImageSourceGetSupportedFormats(uint32_t mockRet)
44 {
45 g_mockImageSourceGetSupportedFormatsRet = mockRet;
46 }
47
MockResetImageSourceState()48 void MockResetImageSourceState()
49 {
50 g_mockImageSourceCreateImageSourceRet = true;
51 g_mockImageSourceCreateImageSourceErrorCode = 0;
52 g_mockImageSourceCreatePixelMapRet = true;
53 g_mockImageSourceCreatePixelMapErrorCode = 0;
54 }
55
56 namespace OHOS {
57 namespace Media {
58 using namespace ImagePlugin;
59
GetSupportedFormats(std::set<std::string> & formats)60 uint32_t ImageSource::GetSupportedFormats(std::set<std::string> &formats)
61 {
62 return g_mockImageSourceGetSupportedFormatsRet;
63 }
64
CreateImageSource(std::unique_ptr<std::istream> is,const SourceOptions & opts,uint32_t & errorCode)65 std::unique_ptr<ImageSource> ImageSource::CreateImageSource(std::unique_ptr<std::istream> is,
66 const SourceOptions &opts, uint32_t &errorCode)
67 {
68 return nullptr;
69 }
70
CreateImageSource(const uint8_t * data,uint32_t size,const SourceOptions & opts,uint32_t & errorCode)71 std::unique_ptr<ImageSource> ImageSource::CreateImageSource(const uint8_t *data, uint32_t size,
72 const SourceOptions &opts, uint32_t &errorCode)
73 {
74 errorCode = g_mockImageSourceCreateImageSourceErrorCode;
75 if (g_mockImageSourceCreateImageSourceRet) {
76 std::unique_ptr<OHOS::Media::SourceStream> stream = nullptr;
77 OHOS::Media::SourceOptions opts;
78 ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts);
79 return std::unique_ptr<ImageSource>(sourcePtr);
80 }
81 return nullptr;
82 }
83
CreateImageSource(const std::string & pathName,const SourceOptions & opts,uint32_t & errorCode)84 std::unique_ptr<ImageSource> ImageSource::CreateImageSource(const std::string &pathName, const SourceOptions &opts,
85 uint32_t &errorCode)
86 {
87 errorCode = g_mockImageSourceCreateImageSourceErrorCode;
88 if (g_mockImageSourceCreateImageSourceRet) {
89 std::unique_ptr<OHOS::Media::SourceStream> stream = nullptr;
90 OHOS::Media::SourceOptions opts;
91 ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts);
92 return std::unique_ptr<ImageSource>(sourcePtr);
93 }
94 return nullptr;
95 }
96
CreateImageSource(const int fd,const SourceOptions & opts,uint32_t & errorCode)97 std::unique_ptr<ImageSource> ImageSource::CreateImageSource(const int fd, const SourceOptions &opts,
98 uint32_t &errorCode)
99 {
100 return nullptr;
101 }
102
CreateIncrementalImageSource(const IncrementalSourceOptions & opts,uint32_t & errorCode)103 std::unique_ptr<ImageSource> ImageSource::CreateIncrementalImageSource(const IncrementalSourceOptions &opts,
104 uint32_t &errorCode)
105 {
106 return nullptr;
107 }
108
Reset()109 void ImageSource::Reset()
110 {}
111
CreatePixelMapEx(uint32_t index,const DecodeOptions & opts,uint32_t & errorCode)112 std::unique_ptr<PixelMap> ImageSource::CreatePixelMapEx(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode)
113 {
114 errorCode = g_mockImageSourceCreatePixelMapErrorCode;
115 if (g_mockImageSourceCreatePixelMapRet) {
116 PixelMap *pixelMap = new (std::nothrow) PixelMap();
117 return std::unique_ptr<PixelMap>(pixelMap);
118 }
119 return nullptr;
120 }
121
CreatePixelMap(uint32_t index,const DecodeOptions & opts,uint32_t & errorCode)122 std::unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode)
123 {
124 return nullptr;
125 }
126
CreateIncrementalPixelMap(uint32_t index,const DecodeOptions & opts,uint32_t & errorCode)127 std::unique_ptr<IncrementalPixelMap> ImageSource::CreateIncrementalPixelMap(uint32_t index, const DecodeOptions &opts,
128 uint32_t &errorCode)
129 {
130 return nullptr;
131 }
132
PromoteDecoding(uint32_t index,const DecodeOptions & opts,PixelMap & pixelMap,ImageDecodingState & state,uint8_t & decodeProgress)133 uint32_t ImageSource::PromoteDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap,
134 ImageDecodingState &state, uint8_t &decodeProgress)
135 {
136 return 0;
137 }
138
DetachIncrementalDecoding(PixelMap & pixelMap)139 void ImageSource::DetachIncrementalDecoding(PixelMap &pixelMap)
140 {}
141
UpdateData(const uint8_t * data,uint32_t size,bool isCompleted)142 uint32_t ImageSource::UpdateData(const uint8_t *data, uint32_t size, bool isCompleted)
143 {
144 return 0;
145 }
146
GetDecodeEvent()147 DecodeEvent ImageSource::GetDecodeEvent()
148 {
149 return decodeEvent_;
150 }
151
GetImageInfo(uint32_t index,ImageInfo & imageInfo)152 uint32_t ImageSource::GetImageInfo(uint32_t index, ImageInfo &imageInfo)
153 {
154 return 0;
155 }
156
ModifyImageProperty(uint32_t index,const std::string & key,const std::string & value,const std::string & path)157 uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key,
158 const std::string &value, const std::string &path)
159 {
160 return 0;
161 }
162
ModifyImageProperty(uint32_t index,const std::string & key,const std::string & value,const int fd)163 uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key,
164 const std::string &value, const int fd)
165 {
166 return 0;
167 }
168
ModifyImageProperty(uint32_t index,const std::string & key,const std::string & value,uint8_t * data,uint32_t size)169 uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key,
170 const std::string &value, uint8_t *data, uint32_t size)
171 {
172 return 0;
173 }
174
GetImagePropertyInt(uint32_t index,const std::string & key,int32_t & value)175 uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value)
176 {
177 return 0;
178 }
179
GetImagePropertyString(uint32_t index,const std::string & key,std::string & value)180 uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value)
181 {
182 return 0;
183 }
184
GetSourceInfo(uint32_t & errorCode)185 const SourceInfo &ImageSource::GetSourceInfo(uint32_t &errorCode)
186 {
187 return sourceInfo_;
188 }
189
RegisterListener(PeerListener * listener)190 void ImageSource::RegisterListener(PeerListener *listener)
191 {}
192
UnRegisterListener(PeerListener * listener)193 void ImageSource::UnRegisterListener(PeerListener *listener)
194 {}
195
AddDecodeListener(DecodeListener * listener)196 void ImageSource::AddDecodeListener(DecodeListener *listener)
197 {}
198
RemoveDecodeListener(DecodeListener * listener)199 void ImageSource::RemoveDecodeListener(DecodeListener *listener)
200 {}
201
~ImageSource()202 ImageSource::~ImageSource()
203 {}
204
IsStreamCompleted()205 bool ImageSource::IsStreamCompleted()
206 {
207 return true;
208 }
209
ImageSource(std::unique_ptr<SourceStream> && stream,const SourceOptions & opts)210 ImageSource::ImageSource(std::unique_ptr<SourceStream> &&stream, const SourceOptions &opts)
211 {}
212
InitClass()213 ImageSource::FormatAgentMap ImageSource::InitClass()
214 {
215 FormatAgentMap tempAgentMap;
216 return tempAgentMap;
217 }
218
CheckEncodedFormat(AbsImageFormatAgent & agent)219 uint32_t ImageSource::CheckEncodedFormat(AbsImageFormatAgent &agent)
220 {
221 return 0;
222 }
223
CheckFormatHint(const std::string & formatHint,FormatAgentMap::iterator & formatIter)224 uint32_t ImageSource::CheckFormatHint(const std::string &formatHint, FormatAgentMap::iterator &formatIter)
225 {
226 return 0;
227 }
228
GetEncodedFormat(const std::string & formatHint,std::string & format)229 uint32_t ImageSource::GetEncodedFormat(const std::string &formatHint, std::string &format)
230 {
231 return 0;
232 }
233
OnSourceRecognized(bool isAcquiredImageNum)234 uint32_t ImageSource::OnSourceRecognized(bool isAcquiredImageNum)
235 {
236 return 0;
237 }
238
OnSourceUnresolved()239 uint32_t ImageSource::OnSourceUnresolved()
240 {
241 return 0;
242 }
243
DecodeSourceInfo(bool isAcquiredImageNum)244 uint32_t ImageSource::DecodeSourceInfo(bool isAcquiredImageNum)
245 {
246 return 0;
247 }
248
DecodeImageInfo(uint32_t index,ImageStatusMap::iterator & iter)249 uint32_t ImageSource::DecodeImageInfo(uint32_t index, ImageStatusMap::iterator &iter)
250 {
251 return 0;
252 }
253
InitMainDecoder()254 uint32_t ImageSource::InitMainDecoder()
255 {
256 return 0;
257 }
258
CreateDecoder(uint32_t & errorCode)259 AbsImageDecoder *ImageSource::CreateDecoder(uint32_t &errorCode)
260 {
261 return nullptr;
262 }
263
SetDecodeOptions(std::unique_ptr<AbsImageDecoder> & decoder,uint32_t index,const DecodeOptions & opts,ImagePlugin::PlImageInfo & plInfo)264 uint32_t ImageSource::SetDecodeOptions(std::unique_ptr<AbsImageDecoder> &decoder, uint32_t index,
265 const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo)
266 {
267 return 0;
268 }
269
UpdatePixelMapInfo(const DecodeOptions & opts,ImagePlugin::PlImageInfo & plInfo,PixelMap & pixelMap)270 uint32_t ImageSource::UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo,
271 PixelMap &pixelMap)
272 {
273 return 0;
274 }
275
CopyOptionsToPlugin(const DecodeOptions & opts,PixelDecodeOptions & plOpts)276 void ImageSource::CopyOptionsToPlugin(const DecodeOptions &opts, PixelDecodeOptions &plOpts)
277 {}
278
CopyOptionsToProcOpts(const DecodeOptions & opts,DecodeOptions & procOpts,PixelMap & pixelMap)279 void ImageSource::CopyOptionsToProcOpts(const DecodeOptions &opts, DecodeOptions &procOpts, PixelMap &pixelMap)
280 {}
281
GetValidImageStatus(uint32_t index,uint32_t & errorCode)282 ImageSource::ImageStatusMap::iterator ImageSource::GetValidImageStatus(uint32_t index, uint32_t &errorCode)
283 {
284 return imageStatusMap_.find(index);
285 }
286
AddIncrementalContext(PixelMap & pixelMap,IncrementalRecordMap::iterator & iterator)287 uint32_t ImageSource::AddIncrementalContext(PixelMap &pixelMap, IncrementalRecordMap::iterator &iterator)
288 {
289 return 0;
290 }
291
DoIncrementalDecoding(uint32_t index,const DecodeOptions & opts,PixelMap & pixelMap,IncrementalDecodingContext & recordContext)292 uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap,
293 IncrementalDecodingContext &recordContext)
294 {
295 return 0;
296 }
297
GetNinePatchInfo() const298 const NinePatchInfo &ImageSource::GetNinePatchInfo() const
299 {
300 return ninePatchInfo_;
301 }
302
SetMemoryUsagePreference(const MemoryUsagePreference preference)303 void ImageSource::SetMemoryUsagePreference(const MemoryUsagePreference preference)
304 {}
305
GetMemoryUsagePreference()306 MemoryUsagePreference ImageSource::GetMemoryUsagePreference()
307 {
308 return preference_;
309 }
310
GetFilterArea(const int & redactionType,std::vector<std::pair<uint32_t,uint32_t>> & ranges)311 uint32_t ImageSource::GetFilterArea(const int &redactionType,
312 std::vector<std::pair<uint32_t, uint32_t>> &ranges)
313 {
314 return 0;
315 }
316
SetIncrementalSource(const bool isIncrementalSource)317 void ImageSource::SetIncrementalSource(const bool isIncrementalSource)
318 {
319 isIncrementalSource_ = isIncrementalSource;
320 }
321
IsIncrementalSource()322 bool ImageSource::IsIncrementalSource()
323 {
324 return isIncrementalSource_;
325 }
326
GetFinalOutputStep(const DecodeOptions & opts,PixelMap & pixelMap,bool hasNinePatch)327 FinalOutputStep ImageSource::GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch)
328 {
329 return FinalOutputStep::NO_CHANGE;
330 }
331
HasDensityChange(const DecodeOptions & opts,ImageInfo & srcImageInfo,bool hasNinePatch)332 bool ImageSource::HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch)
333 {
334 return true;
335 }
336
ImageSizeChange(int32_t width,int32_t height,int32_t desiredWidth,int32_t desiredHeight)337 bool ImageSource::ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight)
338 {
339 return false;
340 }
341
ImageConverChange(const Rect & cropRect,ImageInfo & dstImageInfo,ImageInfo & srcImageInfo)342 bool ImageSource::ImageConverChange(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo)
343 {
344 return true;
345 }
346
DecodeBase64(const uint8_t * data,uint32_t size)347 std::unique_ptr<SourceStream> ImageSource::DecodeBase64(const uint8_t *data, uint32_t size)
348 {
349 return DecodeBase64("");
350 }
351
DecodeBase64(const std::string & data)352 std::unique_ptr<SourceStream> ImageSource::DecodeBase64(const std::string &data)
353 {
354 return nullptr;
355 }
356
IsSpecialYUV()357 bool ImageSource::IsSpecialYUV()
358 {
359 return true;
360 }
361
ConvertYUV420ToRGBA(uint8_t * data,uint32_t size,bool isSupportOdd,bool isAddUV,uint32_t & errorCode)362 bool ImageSource::ConvertYUV420ToRGBA(uint8_t *data, uint32_t size,
363 bool isSupportOdd, bool isAddUV, uint32_t &errorCode)
364 {
365 return true;
366 }
367
CreatePixelMapForYUV(uint32_t & errorCode)368 std::unique_ptr<PixelMap> ImageSource::CreatePixelMapForYUV(uint32_t &errorCode)
369 {
370 return nullptr;
371 }
372 } // namespace Media
373 } // namespace OHOS
374