1 /* 2 * Copyright (C) 2025 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 #ifndef MEDIA_SOURCE_MOCK_H 17 #define MEDIA_SOURCE_MOCK_H 18 19 #include "gtest/gtest.h" 20 #include "source.h" 21 22 namespace OHOS { 23 namespace Media { 24 class MockMediaSource : public Plugins::MediaSource { 25 public: MockMediaSource(std::string uri)26 MockMediaSource(std::string uri) 27 : Plugins::MediaSource(uri), 28 uri_(std::move(uri)), 29 type_(SourceType::SOURCE_TYPE_URI) {} 30 31 #ifndef OHOS_LITE MockMediaSource(std::shared_ptr<IMediaDataSource> dataSrc)32 MockMediaSource(std::shared_ptr<IMediaDataSource> dataSrc) 33 : Plugins::MediaSource(dataSrc), 34 type_(SourceType::SOURCE_TYPE_STREAM), 35 dataSrc_(std::move(dataSrc)) {} 36 #endif MockMediaSource(std::string uri,std::map<std::string,std::string> header)37 MockMediaSource(std::string uri, std::map<std::string, std::string> header) 38 : Plugins::MediaSource(uri, header), 39 uri_(std::move(uri)), 40 header_(std::move(header)) {} 41 GetSourceType()42 SourceType GetSourceType() const 43 { 44 return type_; 45 } 46 GetSourceUri()47 const std::string &GetSourceUri() const 48 { 49 return uri_; 50 } 51 GetSourceHeader()52 const std::map<std::string, std::string> &GetSourceHeader() const 53 { 54 return header_; 55 } AddMediaStream(const std::shared_ptr<PlayMediaStream> & playMediaStream)56 void AddMediaStream(const std::shared_ptr<PlayMediaStream>& playMediaStream) 57 { 58 playMediaStreamVec_.push_back(playMediaStream); 59 } GetMediaStreamList()60 MediaStreamList GetMediaStreamList() const 61 { 62 return playMediaStreamVec_; 63 } 64 SetPlayStrategy(const std::shared_ptr<PlayStrategy> & playStrategy)65 void SetPlayStrategy(const std::shared_ptr<PlayStrategy>& playStrategy) 66 { 67 playStrategy_ = playStrategy; 68 } 69 GetPlayStrategy()70 std::shared_ptr<PlayStrategy> GetPlayStrategy() const 71 { 72 return playStrategy_; 73 } 74 SetMimeType(const std::string & mimeType)75 void SetMimeType(const std::string& mimeType) 76 { 77 mimeType_ = mimeType; 78 } 79 GetMimeType()80 std::string GetMimeType() const 81 { 82 return mimeType_; 83 } 84 SetAppUid(int32_t appUid)85 void SetAppUid(int32_t appUid) 86 { 87 appUid_ = appUid; 88 } 89 GetAppUid()90 int32_t GetAppUid() 91 { 92 return appUid_; 93 } 94 SetSourceLoader(std::shared_ptr<IMediaSourceLoader> mediaSourceLoader)95 void SetSourceLoader(std::shared_ptr<IMediaSourceLoader> mediaSourceLoader) 96 { 97 sourceLoader_ = std::move(mediaSourceLoader); 98 } 99 GetSourceLoader()100 std::shared_ptr<IMediaSourceLoader> GetSourceLoader() const 101 { 102 return sourceLoader_; 103 } 104 105 #ifndef OHOS_LITE GetDataSrc()106 std::shared_ptr<IMediaDataSource> GetDataSrc() const 107 { 108 return dataSrc_; 109 } 110 #endif 111 private: 112 std::string uri_ {}; 113 std::string mimeType_ {}; 114 SourceType type_ {}; 115 std::map<std::string, std::string> header_ {}; 116 std::shared_ptr<PlayStrategy> playStrategy_ {}; 117 int32_t appUid_ {-1}; 118 #ifndef OHOS_LITE 119 std::shared_ptr<IMediaDataSource> dataSrc_ {}; 120 #endif 121 std::shared_ptr<IMediaSourceLoader> sourceLoader_ {}; 122 MediaStreamList playMediaStreamVec_; 123 }; 124 } // namespace Media 125 } // namespace OHOS 126 #endif // MEDIA_SOURCE_MOCK_H