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_POLICY_UNIT_TEST_H 17 #define AUDIO_POLICY_UNIT_TEST_H 18 19 #include "gtest/gtest.h" 20 #include "audio_info.h" 21 #include "audio_policy_manager.h" 22 #include "audio_policy_proxy.h" 23 #include "audio_stream_manager.h" 24 #include "audio_stream.h" 25 #include "audio_group_manager.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 class AudioManagerDeviceChangeCallbackTest : public AudioManagerDeviceChangeCallback { OnDeviceChange(const DeviceChangeAction & deviceChangeAction)30 virtual void OnDeviceChange(const DeviceChangeAction &deviceChangeAction) {} 31 }; 32 33 class AudioRendererStateChangeCallbackTest : public AudioRendererStateChangeCallback { OnRendererStateChange(const std::vector<std::unique_ptr<AudioRendererChangeInfo>> & audioRendererChangeInfos)34 virtual void OnRendererStateChange( 35 const std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) {} 36 }; 37 38 class AudioCapturerStateChangeCallbackTest : public AudioCapturerStateChangeCallback { OnCapturerStateChange(const std::vector<std::unique_ptr<AudioCapturerChangeInfo>> & audioCapturerChangeInfos)39 virtual void OnCapturerStateChange( 40 const std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) {} 41 }; 42 43 class AudioRingerModeCallbackTest : public AudioRingerModeCallback { 44 public: 45 virtual ~AudioRingerModeCallbackTest() = default; 46 /** 47 * Called when ringer mode is updated. 48 * 49 * @param ringerMode Indicates the updated ringer mode value. 50 * For details, refer RingerMode enum in audio_info.h 51 */ OnRingerModeUpdated(const AudioRingerMode & ringerMode)52 virtual void OnRingerModeUpdated(const AudioRingerMode &ringerMode) {}; 53 }; 54 55 class AudioManagerMicStateChangeCallbackTest : public AudioManagerMicStateChangeCallback { 56 public: 57 virtual ~AudioManagerMicStateChangeCallbackTest() = default; 58 /** 59 * Called when the microphone state changes 60 * 61 * @param micStateChangeEvent Microphone Status Information. 62 */ OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)63 virtual void OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) {}; 64 }; 65 66 class AudioClientTrackerTest : public AudioClientTracker { 67 public: 68 virtual ~AudioClientTrackerTest() = default; 69 /** 70 * Paused Stream was controlled by system application 71 * 72 * @param streamSetStateEventInternal Contains the set even information. 73 */ PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)74 virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {}; 75 /** 76 * Resumed Stream was controlled by system application 77 * 78 * @param streamSetStateEventInternal Contains the set even information. 79 */ ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)80 virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) {}; SetLowPowerVolumeImpl(float volume)81 virtual void SetLowPowerVolumeImpl(float volume) {}; GetLowPowerVolumeImpl(float & volume)82 virtual void GetLowPowerVolumeImpl(float &volume) {}; GetSingleStreamVolumeImpl(float & volume)83 virtual void GetSingleStreamVolumeImpl(float &volume) {}; 84 }; 85 86 class AudioPolicyUnitTest : public testing::Test { 87 public: 88 // SetUpTestCase: Called before all test cases 89 static void SetUpTestCase(void); 90 // TearDownTestCase: Called after all test case 91 static void TearDownTestCase(void); 92 // SetUp: Called before each test cases 93 void SetUp(void); 94 // TearDown: Called after each test cases 95 void TearDown(void); 96 static void InitAudioPolicyProxy(std::shared_ptr<AudioPolicyProxy> &audioPolicyProxy); 97 static void InitAudioStream(std::shared_ptr<AudioStream> &audioStream); 98 static uint32_t GetSessionId(std::shared_ptr<AudioStream> &audioStream); 99 static void GetIRemoteObject(sptr<IRemoteObject> &object); 100 }; 101 } // namespace AudioStandard 102 } // namespace OHOS 103 104 #endif // AUDIO_POLICY_UNIT_TEST_H 105