From 81ba86b7f3dd7b1cd1566e52fe5e026d276c4ed1 Mon Sep 17 00:00:00 2001 From: wangzixuan123 Date: Wed, 8 Nov 2023 02:50:04 +0000 Subject: [PATCH] audio add deviceDescriptor UT Signed-off-by: wangzixuan123 --- services/audio_service/test/unittest/BUILD.gn | 24 ++++ .../audio_device_descriptor_unit_test.cpp | 105 ++++++++++++++++++ test/BUILD.gn | 1 + 3 files changed, 130 insertions(+) create mode 100644 services/audio_service/test/unittest/audio_device_descriptor_unit_test.cpp diff --git a/services/audio_service/test/unittest/BUILD.gn b/services/audio_service/test/unittest/BUILD.gn index 0553b71af2..335fadd566 100644 --- a/services/audio_service/test/unittest/BUILD.gn +++ b/services/audio_service/test/unittest/BUILD.gn @@ -63,3 +63,27 @@ ohos_unittest("audio_balance_unit_test") { "samgr:samgr_proxy", ] } + +ohos_unittest("audio_device_descriptor_unit_test") { + module_out_path = module_output_path + sources = [ "audio_device_descriptor_unit_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "$pulseaudio_build_path/src/pulse:pulse", + "../../../../frameworks/native/audioutils:audio_utils", + "../../../audio_service:audio_client", + "../../../audio_service:audio_common", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} diff --git a/services/audio_service/test/unittest/audio_device_descriptor_unit_test.cpp b/services/audio_service/test/unittest/audio_device_descriptor_unit_test.cpp new file mode 100644 index 0000000000..c85eb8f155 --- /dev/null +++ b/services/audio_service/test/unittest/audio_device_descriptor_unit_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "audio_errors.h" +#include "audio_manager_listener_stub.h" +#include "audio_manager_proxy.h" +#include "audio_log.h" +#include "audio_process_in_client.h" +#include "audio_process_proxy.h" +#include "audio_stream.h" +#include "audio_system_manager.h" +#include +#include "iservice_registry.h" +#include "system_ability_definition.h" + +using namespace testing::ext; +namespace OHOS { +namespace AudioStandard { + +class AudioDeviceDescriptorUnitTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +class AudioParameterCallbackTest : public AudioParameterCallback { + virtual void OnAudioParameterChange(const std::string networkId, const AudioParamKey key, + const std::string& condition, const std::string& value) {} +}; + +void AudioDeviceDescriptorUnitTest::SetUpTestCase(void) +{ + // input testsuit setup step,setup invoked before all testcases +} + +void AudioDeviceDescriptorUnitTest::TearDownTestCase(void) +{ + // input testsuit teardown step,teardown invoked after all testcases +} + +void AudioDeviceDescriptorUnitTest::SetUp(void) +{ + // input testcase setup step,setup invoked before each testcases +} + +void AudioDeviceDescriptorUnitTest::TearDown(void) +{ + // input testcase teardown step,teardown invoked after each testcases +} + +/** + * @tc.name : Test AudioDeviceDescriptor API + * @tc.type : FUNC + * @tc.number: AudioDeviceDescriptor_001 + * @tc.desc : Test AudioDeviceDescriptor interface. + */ +HWTEST(AudioDeviceDescriptorUnitTest, AudioDeviceDescriptor_001, TestSize.Level1) +{ + DeviceType type = DeviceType::DEVICE_TYPE_SPEAKER; + DeviceRole role = DeviceRole::OUTPUT_DEVICE; + int32_t interruptGroupId = 1; + int32_t volumeGroupId = 1; + std::string networkId = "LocalDevice"; + std::unique_ptr audioDeviceDescriptor = + std::make_unique(type, role, interruptGroupId, volumeGroupId, networkId); + EXPECT_NE(audioDeviceDescriptor, nullptr); + + AudioDeviceDescriptor deviceDescriptor; + deviceDescriptor.deviceType_ = type; + deviceDescriptor.deviceRole_ = role; + deviceDescriptor.channelIndexMasks_ = 1; + audioDeviceDescriptor = std::make_unique(deviceDescriptor); + EXPECT_NE(audioDeviceDescriptor, nullptr); + EXPECT_EQ(audioDeviceDescriptor->channelIndexMasks_, 1); + + std::string deviceName = ""; + std::string macAddress = ""; + audioDeviceDescriptor->SetDeviceInfo(deviceName, macAddress); + + AudioStreamInfo audioStreamInfo; + audioStreamInfo.channels = STEREO; + audioStreamInfo.encoding = ENCODING_PCM; + audioStreamInfo.format = SAMPLE_S16LE; + audioStreamInfo.samplingRate = SAMPLE_RATE_48000; + int32_t channelMask = 1; + int32_t channelIndexMasks = 2; + audioDeviceDescriptor->SetDeviceCapability(audioStreamInfo, channelMask, channelIndexMasks); + EXPECT_EQ(audioDeviceDescriptor->channelIndexMasks_, channelIndexMasks); +} +} // namespace AudioStandard +} // namespace OHOS \ No newline at end of file diff --git a/test/BUILD.gn b/test/BUILD.gn index a2e3a8dea3..a8ae6627d6 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -39,6 +39,7 @@ group("audio_unit_test") { "../frameworks/native/audioutils/test/unittest:audio_utils_unit_test", "../frameworks/native/toneplayer/test/unnittest:audio_toneplayer_unit_test", "../services/audio_service/test/unittest:audio_balance_unit_test", + "../services/audio_service/test/unittest:audio_device_descriptor_unit_test", ] if (audio_framework_feature_opensl_es) { -- Gitee