• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cachebuffer_mock.h"
17 
18 using namespace std;
19 using namespace OHOS;
20 using namespace OHOS::Media;
21 using namespace testing::ext;
22 
CreateCacheBuffer(const Format & trackFormat,const int32_t & soundID,const int32_t & streamID,std::shared_ptr<ThreadPool> cacheBufferStopThreadPool)23 bool CacheBufferMock::CreateCacheBuffer(const Format &trackFormat, const int32_t &soundID,
24     const int32_t &streamID, std::shared_ptr<ThreadPool> cacheBufferStopThreadPool)
25 {
26     if (cacheBuffer_ != nullptr) {
27         cacheBuffer_.reset();
28     }
29     cacheBuffer_ = std::make_shared<CacheBuffer>(trackFormat, soundID, streamID, cacheBufferStopThreadPool);
30     return cacheBuffer_ == nullptr;
31 }
32 
IsAudioRendererCanMix(const AudioStandard::AudioRendererInfo & audioRendererInfo)33 bool CacheBufferMock::IsAudioRendererCanMix(const AudioStandard::AudioRendererInfo &audioRendererInfo)
34 {
35     UNITTEST_CHECK_AND_RETURN_RET_LOG(cacheBuffer_ != nullptr, MSERR_INVALID_OPERATION, "cacheBuffer_ == nullptr");
36     return cacheBuffer_->IsAudioRendererCanMix(audioRendererInfo);
37 }
38 
CreateAudioRenderer(const int32_t streamID,const AudioStandard::AudioRendererInfo audioRendererInfo,const PlayParams playParams)39 int32_t CacheBufferMock::CreateAudioRenderer(const int32_t streamID,
40     const AudioStandard::AudioRendererInfo audioRendererInfo, const PlayParams playParams)
41 {
42     UNITTEST_CHECK_AND_RETURN_RET_LOG(cacheBuffer_ != nullptr, MSERR_INVALID_OPERATION, "cacheBuffer_ == nullptr");
43     return cacheBuffer_->CreateAudioRenderer(audioRendererInfo, playParams) == nullptr;
44 }
45 
GetFileSize(const std::string & fileName)46 size_t CacheBufferMock::GetFileSize(const std::string& fileName)
47 {
48     size_t fileSize = 0;
49     if (!fileName.empty()) {
50         struct stat fileStatus {};
51         if (stat(fileName.c_str(), &fileStatus) == 0) {
52             fileSize = static_cast<size_t>(fileStatus.st_size);
53         }
54     }
55     return fileSize;
56 }