1 /* 2 * Copyright (c) 2024 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 ACTS_OH_AUDIO_NDK_TEST_H 17 #define ACTS_OH_AUDIO_NDK_TEST_H 18 19 #include "gtest/gtest.h" 20 #include "native_audiostreambuilder.h" 21 #include "native_audiocapturer.h" 22 23 constexpr int32_t SAMPLE_RATE_48000 = 48000; 24 constexpr int32_t CHANNEL_2 = 2; 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class ActsOhAudioNdkTest : public testing::Test { 29 public: 30 // SetUpTestCase: Called before all test cases 31 static void SetUpTestCase(void); 32 // TearDownTestCase: Called after all test case 33 static void TearDownTestCase(void); 34 // SetUp: Called before each test cases 35 void SetUp(void); 36 // TearDown: Called after each test cases 37 void TearDown(void); 38 // create a capturer type builder 39 static OH_AudioStreamBuilder* CreateCapturerBuilder(); 40 // create a renderer type builder 41 static OH_AudioStreamBuilder* CreateRenderBuilder(); 42 }; 43 44 class OHAudioCapturerReadCallbackMock { 45 public: OnReadData(OH_AudioCapturer* capturer, void* userData, void* buffer, int32_t bufferLen)46 void OnReadData(OH_AudioCapturer* capturer, void* userData, 47 void* buffer, 48 int32_t bufferLen) 49 { 50 exeCount_++; 51 if (executor_) { 52 executor_(capturer, userData, buffer, bufferLen); 53 } 54 } 55 Install(std::function<void(OH_AudioCapturer*, void*, void*, int32_t)> executor)56 void Install(std::function<void(OH_AudioCapturer*, void*, void*, int32_t)> executor) 57 { 58 executor_ = executor; 59 } 60 GetExeCount()61 uint32_t GetExeCount() 62 { 63 return exeCount_; 64 } 65 private: 66 std::function<void(OH_AudioCapturer*, void*, void*, int32_t)> executor_; 67 std::atomic<uint32_t> exeCount_ = 0; 68 }; 69 70 class OHAudioRendererWriteCallbackMock { 71 public: OnWriteData(OH_AudioRenderer* renderer, void* userData, void* buffer, int32_t bufferLen)72 void OnWriteData(OH_AudioRenderer* renderer, void* userData, 73 void* buffer, 74 int32_t bufferLen) 75 { 76 exeCount_++; 77 if (executor_) { 78 executor_(renderer, userData, buffer, bufferLen); 79 } 80 } 81 Install(std::function<void(OH_AudioRenderer*, void*, void*, int32_t)> executor)82 void Install(std::function<void(OH_AudioRenderer*, void*, void*, int32_t)> executor) 83 { 84 executor_ = executor; 85 } 86 GetExeCount()87 uint32_t GetExeCount() 88 { 89 return exeCount_; 90 } 91 private: 92 std::function<void(OH_AudioRenderer*, void*, void*, int32_t)> executor_; 93 std::atomic<uint32_t> exeCount_ = 0; 94 }; 95 } // namespace AudioStandard 96 } // namespace OHOS 97 98 #endif // ACTS_OH_AUDIO_NDK_TEST_H