1 /* 2 * Copyright (c) 2022 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 AUDIO_STREAM_UNIT_TEST_H 17 #define AUDIO_STREAM_UNIT_TEST_H 18 19 #include "gtest/gtest.h" 20 #include "audio_info.h" 21 #include "audio_stream.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 class RenderCallbackTest : public AudioRendererCallbacks { 26 public: OnSinkDeviceUpdatedCb()27 void OnSinkDeviceUpdatedCb() const 28 { 29 AUDIO_INFO_LOG("render callback OnSinkDeviceUpdatedCb"); 30 } OnStreamStateChangeCb()31 virtual void OnStreamStateChangeCb() const 32 { 33 AUDIO_INFO_LOG("render callback OnStreamStateChangeCb"); 34 } 35 OnStreamBufferUnderFlowCb()36 virtual void OnStreamBufferUnderFlowCb() const {} OnStreamBufferOverFlowCb()37 virtual void OnStreamBufferOverFlowCb() const {} OnErrorCb(AudioServiceErrorCodes error)38 virtual void OnErrorCb(AudioServiceErrorCodes error) const {} OnEventCb(AudioServiceEventTypes error)39 virtual void OnEventCb(AudioServiceEventTypes error) const {} 40 }; 41 42 class CapturterCallbackTest : public AudioCapturerCallbacks { 43 public: OnSourceDeviceUpdatedCb()44 void OnSourceDeviceUpdatedCb() const 45 { 46 AUDIO_INFO_LOG("captuer callback OnSourceDeviceUpdatedCb"); 47 } 48 // Need to check required state changes to update applications OnStreamStateChangeCb()49 virtual void OnStreamStateChangeCb() const 50 { 51 AUDIO_INFO_LOG("captuer callback OnStreamStateChangeCb"); 52 } 53 OnStreamBufferUnderFlowCb()54 virtual void OnStreamBufferUnderFlowCb() const {} OnStreamBufferOverFlowCb()55 virtual void OnStreamBufferOverFlowCb() const {} OnErrorCb(AudioServiceErrorCodes error)56 virtual void OnErrorCb(AudioServiceErrorCodes error) const {} OnEventCb(AudioServiceEventTypes error)57 virtual void OnEventCb(AudioServiceEventTypes error) const {} 58 }; 59 60 class AudioStreamCallbackTest : public AudioStreamCallback { 61 public: 62 virtual ~AudioStreamCallbackTest() = default; 63 64 virtual void OnStateChange(const State state, const StateChangeCmdType cmdType = CMD_FROM_CLIENT) {} 65 }; 66 67 class AudioCapturerReadCallbackTest : public AudioCapturerReadCallback { 68 public: 69 virtual ~AudioCapturerReadCallbackTest() = default; 70 71 /** 72 * Called when buffer to be enqueued. 73 * 74 * @param length Indicates requested buffer length. 75 */ OnReadData(size_t length)76 virtual void OnReadData(size_t length) {}; 77 }; 78 79 class CapturerPeriodPositionCallbackTest : public CapturerPeriodPositionCallback { 80 public: 81 virtual ~CapturerPeriodPositionCallbackTest() = default; 82 83 /** 84 * Called when the requested frame count is read. 85 * 86 * @param frameCount requested frame frame count for callback. 87 */ OnPeriodReached(const int64_t & frameNumber)88 virtual void OnPeriodReached(const int64_t &frameNumber) {}; 89 }; 90 91 class AudioStreamUnitTest : public testing::Test { 92 public: 93 // SetUpTestCase: Called before all test cases 94 static void SetUpTestCase(void); 95 // TearDownTestCase: Called after all test case 96 static void TearDownTestCase(void); 97 // SetUp: Called before each test cases 98 void SetUp(void); 99 // TearDown: Called after each test cases 100 void TearDown(void); 101 static void InitAudioStream(std::shared_ptr<AudioStream> &audioStream); 102 }; 103 } // namespace AudioStandard 104 } // namespace OHOS 105 106 #endif // AUDIO_STREAM_UNIT_TEST_H 107