1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#ifndef ACTS_OH_AUDIO_NDK_TEST_H 17f6603c60Sopenharmony_ci#define ACTS_OH_AUDIO_NDK_TEST_H 18f6603c60Sopenharmony_ci 19f6603c60Sopenharmony_ci#include "gtest/gtest.h" 20f6603c60Sopenharmony_ci#include "native_audiostreambuilder.h" 21f6603c60Sopenharmony_ci#include "native_audiocapturer.h" 22f6603c60Sopenharmony_ci 23f6603c60Sopenharmony_ciconstexpr int32_t SAMPLE_RATE_48000 = 48000; 24f6603c60Sopenharmony_ciconstexpr int32_t CHANNEL_2 = 2; 25f6603c60Sopenharmony_ci 26f6603c60Sopenharmony_cinamespace OHOS { 27f6603c60Sopenharmony_cinamespace AudioStandard { 28f6603c60Sopenharmony_ciclass ActsOhAudioNdkTest : public testing::Test { 29f6603c60Sopenharmony_cipublic: 30f6603c60Sopenharmony_ci // SetUpTestCase: Called before all test cases 31f6603c60Sopenharmony_ci static void SetUpTestCase(void); 32f6603c60Sopenharmony_ci // TearDownTestCase: Called after all test case 33f6603c60Sopenharmony_ci static void TearDownTestCase(void); 34f6603c60Sopenharmony_ci // SetUp: Called before each test cases 35f6603c60Sopenharmony_ci void SetUp(void); 36f6603c60Sopenharmony_ci // TearDown: Called after each test cases 37f6603c60Sopenharmony_ci void TearDown(void); 38f6603c60Sopenharmony_ci // create a capturer type builder 39f6603c60Sopenharmony_ci static OH_AudioStreamBuilder* CreateCapturerBuilder(); 40f6603c60Sopenharmony_ci // create a renderer type builder 41f6603c60Sopenharmony_ci static OH_AudioStreamBuilder* CreateRenderBuilder(); 42f6603c60Sopenharmony_ci}; 43f6603c60Sopenharmony_ci 44f6603c60Sopenharmony_ciclass OHAudioCapturerReadCallbackMock { 45f6603c60Sopenharmony_cipublic: 46f6603c60Sopenharmony_ci void OnReadData(OH_AudioCapturer* capturer, void* userData, 47f6603c60Sopenharmony_ci void* buffer, 48f6603c60Sopenharmony_ci int32_t bufferLen) 49f6603c60Sopenharmony_ci { 50f6603c60Sopenharmony_ci exeCount_++; 51f6603c60Sopenharmony_ci if (executor_) { 52f6603c60Sopenharmony_ci executor_(capturer, userData, buffer, bufferLen); 53f6603c60Sopenharmony_ci } 54f6603c60Sopenharmony_ci } 55f6603c60Sopenharmony_ci 56f6603c60Sopenharmony_ci void Install(std::function<void(OH_AudioCapturer*, void*, void*, int32_t)> executor) 57f6603c60Sopenharmony_ci { 58f6603c60Sopenharmony_ci executor_ = executor; 59f6603c60Sopenharmony_ci } 60f6603c60Sopenharmony_ci 61f6603c60Sopenharmony_ci uint32_t GetExeCount() 62f6603c60Sopenharmony_ci { 63f6603c60Sopenharmony_ci return exeCount_; 64f6603c60Sopenharmony_ci } 65f6603c60Sopenharmony_ciprivate: 66f6603c60Sopenharmony_ci std::function<void(OH_AudioCapturer*, void*, void*, int32_t)> executor_; 67f6603c60Sopenharmony_ci std::atomic<uint32_t> exeCount_ = 0; 68f6603c60Sopenharmony_ci}; 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ciclass OHAudioRendererWriteCallbackMock { 71f6603c60Sopenharmony_cipublic: 72f6603c60Sopenharmony_ci void OnWriteData(OH_AudioRenderer* renderer, void* userData, 73f6603c60Sopenharmony_ci void* buffer, 74f6603c60Sopenharmony_ci int32_t bufferLen) 75f6603c60Sopenharmony_ci { 76f6603c60Sopenharmony_ci exeCount_++; 77f6603c60Sopenharmony_ci if (executor_) { 78f6603c60Sopenharmony_ci executor_(renderer, userData, buffer, bufferLen); 79f6603c60Sopenharmony_ci } 80f6603c60Sopenharmony_ci } 81f6603c60Sopenharmony_ci 82f6603c60Sopenharmony_ci void Install(std::function<void(OH_AudioRenderer*, void*, void*, int32_t)> executor) 83f6603c60Sopenharmony_ci { 84f6603c60Sopenharmony_ci executor_ = executor; 85f6603c60Sopenharmony_ci } 86f6603c60Sopenharmony_ci 87f6603c60Sopenharmony_ci uint32_t GetExeCount() 88f6603c60Sopenharmony_ci { 89f6603c60Sopenharmony_ci return exeCount_; 90f6603c60Sopenharmony_ci } 91f6603c60Sopenharmony_ciprivate: 92f6603c60Sopenharmony_ci std::function<void(OH_AudioRenderer*, void*, void*, int32_t)> executor_; 93f6603c60Sopenharmony_ci std::atomic<uint32_t> exeCount_ = 0; 94f6603c60Sopenharmony_ci}; 95f6603c60Sopenharmony_ci} // namespace AudioStandard 96f6603c60Sopenharmony_ci} // namespace OHOS 97f6603c60Sopenharmony_ci 98f6603c60Sopenharmony_ci#endif // ACTS_OH_AUDIO_NDK_TEST_H