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 #ifndef MULTIPLE_AUDIO_CAPTURER_UNIT_TEST_H 17 #define MULTIPLE_AUDIO_CAPTURER_UNIT_TEST_H 18 19 #include "gtest/gtest.h" 20 #include "audio_capturer.h" 21 #include "audio_capturer_log.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 enum FOCUS_RULING { 26 START_NORMAL, // start normal 27 START_FAIL, // start fail 28 STOP_CAP1, // current start ok, capture1 stop. 29 STOP_CAP2, // current start ok, capture2 stop. 30 }; 31 32 class MultipleAudioCapturerCallbackTest : public AudioCapturerCallback { 33 public: OnInterrupt(const InterruptEvent & interruptEvent)34 void OnInterrupt(const InterruptEvent &interruptEvent) override 35 { 36 AUDIO_DEBUG_LOG("MultipleAudioCapturerCallbackTest: OnInterrupt Hint: %{public}d eventType: %{public}d,\ 37 forceType: %{public}d", interruptEvent.hintType, interruptEvent.eventType, interruptEvent.forceType); 38 currInterruptEvent = interruptEvent; 39 } OnStateChange(const CapturerState state)40 void OnStateChange(const CapturerState state) override {} GetInterruptEvent()41 InterruptEvent GetInterruptEvent() const 42 { 43 return currInterruptEvent; 44 } 45 46 private: 47 InterruptEvent currInterruptEvent; 48 }; 49 50 class MultipleAudioCapturerUnitTest : public testing::Test { 51 public: 52 // SetUpTestCase: Called before all test cases 53 static void SetUpTestCase(void); 54 // TearDownTestCase: Called after all test case 55 static void TearDownTestCase(void); 56 // SetUp: Called before each test cases 57 void SetUp(void); 58 // TearDown: Called after each test cases 59 void TearDown(void); 60 61 static void AudioCapUnitTestFunc(std::unique_ptr<AudioCapturer> &audioCapturer, 62 std::shared_ptr<MultipleAudioCapturerCallbackTest> &cb, SourceType sourceType, bool isStarted = true); 63 static void TestUnitFunc(SourceType s1, SourceType s2, FOCUS_RULING exp1, SourceType s3, FOCUS_RULING exp2); 64 }; 65 } // namespace AudioStandard 66 } // namespace OHOS 67 68 #endif // MULTIPLE_AUDIO_CAPTURER_UNIT_TEST_H 69