diff --git a/hdf/BUILD.gn b/hdf/BUILD.gn index 5c4d4ee8b2e14b6569349971de2c2c4a349bfeb6..f8dcb4d9399e326f3da6af6a853bd6ad65fd9538 100755 --- a/hdf/BUILD.gn +++ b/hdf/BUILD.gn @@ -15,6 +15,7 @@ group("hdfacttest") { testonly = true if (is_standard_system) { deps = [ + "audio:hdf_xtstest_audio", "input:hdf_xtstest_input", "sensor:hdf_xtstest_sensor", "wlan/wifi:hdf_xtstest_wifi", diff --git a/hdf/audio/BUILD.gn b/hdf/audio/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7fd7161411c90bdf07724075fc38910c29144e21 --- /dev/null +++ b/hdf/audio/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2021 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. + +import("//build/ohos_var.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//test/xts/tools/build/suite.gni") + +#################################group######################################### +group("hdf_xtstest_audio") { + if (!defined(ohos_lite)) { + testonly = true + } + deps = [] + + deps += [ "hdi:hdi" ] +} +############################################################################### diff --git a/hdf/audio/Test.json b/hdf/audio/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..e59f60e2ef8050628b978d79bb7cc88953e047e1 --- /dev/null +++ b/hdf/audio/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "hdf_xtstest_audio->/data/local/tmp/hdf_xtstest_audio" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hdf_xtstest_audio", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hdf_xtstest_audio Tests" +} \ No newline at end of file diff --git a/hdf/audio/common/hdi_common/include/audio_hdi_common.h b/hdf/audio/common/hdi_common/include/audio_hdi_common.h new file mode 100755 index 0000000000000000000000000000000000000000..0cbe15f87c9b149d5a5abba70b4094b5cac0b4bb --- /dev/null +++ b/hdf/audio/common/hdi_common/include/audio_hdi_common.h @@ -0,0 +1,298 @@ +/** + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_adapter.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_HDI_COMMON_H +#define AUDIO_HDI_COMMON_H + +#include +#include "audio_adapter.h" +#include "audio_internal.h" +#include "audio_types.h" +#include "hdf_io_service_if.h" +#include "hdf_sbuf.h" +#include "audio_proxy_manager.h" + +namespace HMOS { +namespace Audio { +#ifdef AUDIO_ADM_SO + const std::string FUNCTION_NAME = "GetAudioManagerFuncs"; + const std::string RESOLVED_PATH = "//system/lib/libhdi_audio.z.so"; + using TestAudioManager = struct AudioManager; + const int IS_ADM = true; +#endif +#ifdef AUDIO_MPI_SO + const std::string FUNCTION_NAME = "GetAudioManagerFuncs"; + const std::string RESOLVED_PATH = "//system/lib/libhdi_audio.z.so"; + using TestAudioManager = struct AudioManager; + const int IS_ADM = false; +#endif +#ifdef AUDIO_ADM_SERVICE + const std::string FUNCTION_NAME = "GetAudioProxyManagerFuncs"; + const std::string RESOLVED_PATH = "//system/lib/libaudio_hdi_proxy_server.z.so"; + using TestAudioManager = struct AudioProxyManager; + const int IS_ADM = true; +#endif +#ifdef AUDIO_MPI_SERVICE + const std::string FUNCTION_NAME = "GetAudioProxyManagerFuncs"; + const std::string RESOLVED_PATH = "//system/lib/libaudio_hdi_proxy_server.z.so"; + using TestAudioManager = struct AudioProxyManager; + const int IS_ADM = false; +#endif +#ifdef __LITEOS__ + const std::string FUNCTION_NAME = "GetAudioManagerFuncs"; + const std::string RESOLVED_PATH = "/usr/lib/libhdi_audio.so"; + using TestAudioManager = struct AudioManager; + const int IS_ADM = true; + const std::string AUDIO_FILE = "/userdata/audiorendertest.wav"; + const std::string LOW_LATENCY_AUDIO_FILE = "/userdata/lowlatencyrendertest.wav"; + const std::string AUDIO_CAPTURE_FILE = "/userdata/audiocapture.wav"; + const std::string AUDIO_LOW_LATENCY_CAPTURE_FILE = "/userdata/lowlatencycapturetest.wav"; +#else + const std::string AUDIO_FILE = "//bin/audiorendertest.wav"; + const std::string LOW_LATENCY_AUDIO_FILE = "//bin/lowlatencyrendertest.wav"; + const std::string AUDIO_CAPTURE_FILE = "//bin/audiocapture.wav"; + const std::string AUDIO_LOW_LATENCY_CAPTURE_FILE = "//bin/lowlatencycapturetest.wav"; +#endif + +const std::string AUDIO_RIFF = "RIFF"; +const std::string AUDIO_WAVE = "WAVE"; +const std::string AUDIO_DATA = "data"; +const uint32_t INT_32_MAX = 0x7fffffff; +const uint32_t INDEX_END = 555; +const uint32_t MOVE_RIGHT_NUM = 3; +const int MOVE_LEFT_NUM = 8; +const int CHANNELCOUNT = 2; +const int SAMPLERATE = 48000; +const int DEEP_BUFFER_RENDER_PERIOD_SIZE = 4096; +const float GAIN_MIN = 0; +const float GAIN_MAX = 15; +const uint64_t INITIAL_VALUE = 0; +const int BUFFER_LENTH = 1024 * 16; +const int FILE_CAPTURE_SIZE = 1024 * 1024 * 1; +const uint64_t MEGABYTE = 1024; +const int FRAME_SIZE = 1024; +const int FRAME_COUNT = 4; +const int ADAPTER_COUNT = 32; +const int TRY_NUM_FRAME = 20; +const int AUDIO_ADAPTER_MAX_NUM = 3; +const int64_t SECTONSEC = 1000000000; +const int MICROSECOND = 1000000; +const std::string HDF_CONTROL_SERVICE = "hdf_audio_control"; +const std::string HDF_RENDER_SERVICE = "hdf_audio_render"; +const std::string HDF_CAPTURE_SERVICE = "hdf_audio_capture"; + +const int AUDIODRV_CTL_ELEM_IFACE_DAC = 0; /* virtual dac device */ +const int AUDIODRV_CTL_ELEM_IFACE_ADC = 1; /* virtual adc device */ +const int AUDIODRV_CTL_ELEM_IFACE_GAIN = 2; /* virtual adc device */ +const int AUDIODRV_CTL_ELEM_IFACE_MIXER = 3; /* virtual mixer device */ +const int AUDIODRV_CTL_ELEM_IFACE_ACODEC = 4; /* Acodec device */ +const int AUDIODRV_CTL_ELEM_IFACE_PGA = 5; /* PGA device */ +const int AUDIODRV_CTL_ELEM_IFACE_AIAO = 6; /* AIAO device */ + +enum ControlDispMethodCmd { + AUDIODRV_CTRL_IOCTRL_ELEM_INFO, + AUDIODRV_CTRL_IOCTRL_ELEM_READ, + AUDIODRV_CTRL_IOCTRL_ELEM_WRITE, + AUDIODRV_CTRL_IOCTRL_ELEM_BUTT, +}; + +enum AudioPCMBit { + PCM_8_BIT = 8, + PCM_16_BIT = 16, + PCM_24_BIT = 24, + PCM_32_BIT = 32, +}; + +struct AudioCtlElemId { + const char *cardServiceName; + int32_t iface; + const char *itemName; /* ASCII name of item */ +}; + +struct AudioCtlElemValue { + struct AudioCtlElemId id; + int32_t value[2]; +}; + +struct AudioHeadInfo { + uint32_t testFileRiffId; + uint32_t testFileRiffSize; + uint32_t testFileFmt; + uint32_t audioFileFmtId; + uint32_t audioFileFmtSize; + uint16_t audioFileFormat; + uint16_t audioChannelNum; + uint32_t audioSampleRate; + uint32_t audioByteRate; + uint16_t audioBlockAlign; + uint16_t audioBitsPerSample; + uint32_t dataId; + uint32_t dataSize; +}; + +struct AudioCharacteristic { + bool setmute; + bool getmute; + float setvolume; + float getvolume; + float setgain; + float getgain; + float gainthresholdmin; + float gainthresholdmax; + uint64_t getframes; + uint64_t getframesize; + uint64_t getframecount; + uint32_t getcurrentchannelId; + enum AudioChannelMode setmode; + enum AudioChannelMode getmode; + bool supported; + uint32_t latencyTime; +}; + +struct PrepareAudioPara { + TestAudioManager *manager; + enum AudioPortDirection portType; + const char *adapterName; + struct AudioAdapter *adapter; + struct AudioPort *audioPort; + void *self; + void *result; + pthread_t tids; + enum AudioPortPin pins; + const char *path; + struct AudioRender *render; + struct AudioCapture *capture; + struct AudioHeadInfo headInfo; + struct AudioAdapterDescriptor *desc; + struct AudioAdapterDescriptor *descs; + char *frame; + uint64_t requestBytes; + uint64_t replyBytes; + uint64_t fileSize; + struct AudioSampleAttributes attrs; + struct AudioCharacteristic character; + struct AudioSampleAttributes attrsValue; + struct AudioSceneDescriptor scenes; + struct AudioPortCapability capability; + enum AudioPortPassthroughMode mode; + struct AudioTimeStamp time; + struct timeval start; + struct timeval end; + long delayTime; + long totalTime; + float averageDelayTime; + struct AudioDeviceDescriptor devDesc; +}; + +int32_t InitAttrs(struct AudioSampleAttributes &attrs); + +int32_t InitDevDesc(struct AudioDeviceDescriptor &devDesc, const uint32_t portId, enum AudioPortPin pins); + +int32_t SwitchAdapter(struct AudioAdapterDescriptor *descs, const std::string &adapterNameCase, + enum AudioPortDirection portFlag, struct AudioPort *&audioPort, int size); + +uint32_t PcmFormatToBits(enum AudioFormat format); + +uint32_t PcmFramesToBytes(const struct AudioSampleAttributes attrs); + +int32_t WavHeadAnalysis(struct AudioHeadInfo &wavHeadInfo, FILE *file, struct AudioSampleAttributes &attrs); + +int32_t GetAdapters(TestAudioManager *manager, struct AudioAdapterDescriptor **descs, int &size); + +int32_t GetLoadAdapter(TestAudioManager *manager, enum AudioPortDirection portType, + const std::string &adapterName, struct AudioAdapter **adapter, struct AudioPort *&audioPort); + +int32_t AudioCreateRender(TestAudioManager *manager, enum AudioPortPin pins, const std::string &adapterName, + struct AudioAdapter **adapter, struct AudioRender **render); + +int32_t AudioCreateCapture(TestAudioManager *manager, enum AudioPortPin pins, const std::string &adapterName, + struct AudioAdapter **adapter, struct AudioCapture **capture); + +int32_t FrameStart(struct AudioHeadInfo wavHeadInfo, struct AudioRender *render, FILE *file, + struct AudioSampleAttributes attrs); + +int32_t FrameStartCapture(struct AudioCapture *capture, FILE *file, const struct AudioSampleAttributes attrs); + +int32_t RenderFramePrepare(const std::string &path, char *&frame, uint64_t &numRead); + +void FrameStatus(int status); + +int32_t StartRecord(struct AudioCapture *capture, FILE *file, uint64_t filesize); + +int32_t WriteIdToBuf(struct HdfSBuf *sBuf, struct AudioCtlElemId id); + +int32_t WriteEleValueToBuf(struct HdfSBuf *sBuf, struct AudioCtlElemValue elemvalue); + +int32_t PowerOff(struct AudioCtlElemValue firstElemValue, struct AudioCtlElemValue secondElemValue); + +int32_t CheckRegisterStatus(const struct AudioCtlElemId firstId, const struct AudioCtlElemId secondId, + const int firstStatus, const int secondStatus); + +int32_t AudioCreateStartRender(TestAudioManager *manager, struct AudioRender **render, struct AudioAdapter **adapter, + const std::string &adapterName); + +int32_t AudioRenderStartAndOneFrame(struct AudioRender *render); + +int32_t StopAudio(struct PrepareAudioPara &audiopara); + +int32_t ThreadRelease(struct PrepareAudioPara &audiopara); + +int32_t AudioCreateStartCapture(TestAudioManager *manager, struct AudioCapture **capture, + struct AudioAdapter **adapter, const std::string &adapterName); + +int32_t AudioCaptureStartAndOneFrame(struct AudioCapture *capture); + +int32_t PlayAudioFile(struct PrepareAudioPara &audiopara); + +int32_t RecordAudio(struct PrepareAudioPara &audiopara); + +int32_t InitAttrsUpdate(struct AudioSampleAttributes &attrs, enum AudioFormat format, uint32_t channelCount, + uint32_t sampleRate); + +int32_t AudioRenderSetGetSampleAttributes(struct AudioSampleAttributes attrs, struct AudioSampleAttributes &attrsValue, + struct AudioRender *render); + +int32_t AudioCaptureSetGetSampleAttributes(struct AudioSampleAttributes attrs, struct AudioSampleAttributes &attrsValue, + struct AudioCapture *capture); + +int32_t InitMmapDesc(FILE *fp, struct AudioMmapBufferDescripter &desc, int32_t &reqSize, bool flag); + +int32_t PlayMapAudioFile(struct PrepareAudioPara &audiopara); + +int32_t RecordMapAudio(struct PrepareAudioPara &audiopara); +} +} +#endif // AUDIO_HDI_COMMON_H + diff --git a/hdf/audio/common/hdi_common/src/audio_hdi_common.cpp b/hdf/audio/common/hdi_common/src/audio_hdi_common.cpp new file mode 100755 index 0000000000000000000000000000000000000000..90eff07abbeaea0223f9237a8ef8b9e426e6e1d5 --- /dev/null +++ b/hdf/audio/common/hdi_common/src/audio_hdi_common.cpp @@ -0,0 +1,1000 @@ +/** + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_adapter.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" + +using namespace std; + +static int g_frameStatus = 1; +namespace HMOS { +namespace Audio { +int32_t InitAttrs(struct AudioSampleAttributes &attrs) +{ + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + attrs.channelCount = CHANNELCOUNT; + attrs.sampleRate = SAMPLERATE; + attrs.interleaved = 0; + attrs.type = AUDIO_IN_MEDIA; + attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE; + attrs.frameSize = PCM_16_BIT * CHANNELCOUNT / MOVE_LEFT_NUM; + attrs.isBigEndian = false; + attrs.isSignedData = true; + attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (PCM_16_BIT * attrs.channelCount / MOVE_LEFT_NUM); + attrs.stopThreshold = INT_32_MAX; + attrs.silenceThreshold = BUFFER_LENTH; + return HDF_SUCCESS; +} +int32_t InitAttrsUpdate(struct AudioSampleAttributes &attrs, enum AudioFormat format, uint32_t channelCount, + uint32_t sampleRate) +{ + InitAttrs(attrs); + attrs.format = format; + attrs.sampleRate = sampleRate; + attrs.channelCount = channelCount; + return HDF_SUCCESS; +} +int32_t AudioRenderSetGetSampleAttributes(struct AudioSampleAttributes attrs, struct AudioSampleAttributes &attrsValue, + struct AudioRender *render) +{ + int32_t ret = -1; + if (render == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = render->attr.SetSampleAttributes(render, &attrs); + if (ret < 0) { + return ret; + } + ret = render->attr.GetSampleAttributes(render, &attrsValue); + if (ret < 0) { + return ret; + } + return AUDIO_HAL_SUCCESS; +} +int32_t AudioCaptureSetGetSampleAttributes(struct AudioSampleAttributes attrs, struct AudioSampleAttributes &attrsValue, + struct AudioCapture *capture) +{ + int32_t ret = -1; + if (capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = capture->attr.SetSampleAttributes(capture, &attrs); + if (ret < 0) { + return ret; + } + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + if (ret < 0) { + return ret; + } + return AUDIO_HAL_SUCCESS; +} +uint32_t StringToInt(std::string flag) +{ + uint32_t temp = flag[0]; + for (int i = flag.size() - 1; i >= 0; i--) { + temp <<= MOVE_LEFT_NUM; + temp += flag[i]; + } + return temp; +} + +int32_t InitDevDesc(struct AudioDeviceDescriptor &devDesc, const uint32_t portId, enum AudioPortPin pins) +{ + devDesc.portId = portId; + devDesc.pins = pins; + devDesc.desc = nullptr; + return HDF_SUCCESS; +} + +int32_t SwitchAdapter(struct AudioAdapterDescriptor *descs, const std::string &adapterNameCase, + enum AudioPortDirection portFlag, struct AudioPort *&audioPort, int size) +{ + if (descs == nullptr || size > ADAPTER_COUNT) { + return HDF_FAILURE; + } + + for (int index = 0; index < size; index++) { + struct AudioAdapterDescriptor *desc = &descs[index]; + if (desc == nullptr || desc->adapterName == nullptr) { + continue; + } + if (strcmp(desc->adapterName, adapterNameCase.c_str())) { + continue; + } + for (uint32_t port = 0; port < desc->portNum; port++) { + if (desc->ports[port].dir == portFlag) { + audioPort = &desc->ports[port]; + return index; + } + } + } + return HDF_FAILURE; +} + +uint32_t PcmFormatToBits(enum AudioFormat format) +{ + switch (format) { + case AUDIO_FORMAT_PCM_8_BIT: + return PCM_8_BIT; + case AUDIO_FORMAT_PCM_16_BIT: + return PCM_16_BIT; + case AUDIO_FORMAT_PCM_24_BIT: + return PCM_24_BIT; + case AUDIO_FORMAT_PCM_32_BIT: + return PCM_32_BIT; + default: + return PCM_16_BIT; + }; +} + +uint32_t PcmFramesToBytes(const struct AudioSampleAttributes attrs) +{ + if (attrs.channelCount < 1 || attrs.channelCount > 2) { + return 0; + } + uint32_t formatBits = PcmFormatToBits(attrs.format); + if (formatBits < PCM_8_BIT || formatBits > PCM_32_BIT) { + return 0; + } + uint32_t ret = FRAME_SIZE * (attrs.channelCount) * (formatBits >> MOVE_RIGHT_NUM); + return ret; +} + +int32_t WavHeadAnalysis(struct AudioHeadInfo &wavHeadInfo, FILE *file, struct AudioSampleAttributes &attrs) +{ + size_t ret = 0; + if (file == nullptr) { + return HDF_FAILURE; + } + ret = fread(&wavHeadInfo, sizeof(wavHeadInfo), 1, file); + if (ret != 1) { + return HDF_FAILURE; + } + uint32_t audioRiffId = StringToInt(AUDIO_RIFF); + uint32_t audioFileFmt = StringToInt(AUDIO_WAVE); + uint32_t audioDataId = StringToInt(AUDIO_DATA); + if (wavHeadInfo.testFileRiffId != audioRiffId || wavHeadInfo.testFileFmt != audioFileFmt || + wavHeadInfo.dataId != audioDataId) { + return HDF_FAILURE; + } + attrs.channelCount = wavHeadInfo.audioChannelNum; + attrs.sampleRate = wavHeadInfo.audioSampleRate; + switch (wavHeadInfo.audioBitsPerSample) { + case PCM_8_BIT: { + attrs.format = AUDIO_FORMAT_PCM_8_BIT; + break; + } + case PCM_16_BIT: { + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + break; + } + case PCM_24_BIT: { + attrs.format = AUDIO_FORMAT_PCM_24_BIT; + break; + } + case PCM_32_BIT: { + attrs.format = AUDIO_FORMAT_PCM_32_BIT; + break; + } + default: + return HDF_FAILURE; + } + return HDF_SUCCESS; +} +int32_t GetAdapters(TestAudioManager *manager, struct AudioAdapterDescriptor **descs, int &size) +{ + int32_t ret = -1; + if (descs == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = manager->GetAllAdapters(manager, descs, &size); + if (ret < 0) { + return ret; + } + if (*descs == nullptr || size != AUDIO_ADAPTER_MAX_NUM) { + return AUDIO_HAL_ERR_INTERNAL; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t GetLoadAdapter(TestAudioManager *manager, enum AudioPortDirection portType, + const std::string &adapterName, struct AudioAdapter **adapter, struct AudioPort *&audioPort) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *desc = nullptr; + struct AudioAdapterDescriptor *descs = nullptr; + if (adapter == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = GetAdapters(manager, &descs, size); + if (ret < 0) { + return ret; + } + if (descs == nullptr) { + return AUDIO_HAL_ERR_INTERNAL; + } + + int index = SwitchAdapter(descs, adapterName, portType, audioPort, size); + if (index < 0) { + return AUDIO_HAL_ERR_INTERNAL; + } + desc = &descs[index]; + if (desc == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = manager->LoadAdapter(manager, desc, adapter); + if (ret < 0) { + return ret; + } + if (*adapter == nullptr) { + return AUDIO_HAL_ERR_INTERNAL; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioCreateRender(TestAudioManager *manager, enum AudioPortPin pins, const std::string &adapterName, + struct AudioAdapter **adapter, struct AudioRender **render) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioPort *renderPort = nullptr; + if (adapter == nullptr || render == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = GetLoadAdapter(manager, PORT_OUT, adapterName, adapter, renderPort); + if (ret < 0) { + return ret; + } + if (*adapter == nullptr || (*adapter)->CreateRender == nullptr) { + return AUDIO_HAL_ERR_INTERNAL; + } + InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, pins); + ret = (*adapter)->CreateRender(*adapter, &devDesc, &attrs, render); + if (ret < 0) { + manager->UnloadAdapter(manager, *adapter); + return ret; + } + if (*render == nullptr) { + manager->UnloadAdapter(manager, *adapter); + return AUDIO_HAL_ERR_INTERNAL; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioCreateStartRender(TestAudioManager *manager, struct AudioRender **render, struct AudioAdapter **adapter, + const std::string &adapterName) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + + if (adapter == nullptr || render == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = AudioCreateRender(manager, pins, adapterName, adapter, render); + if (ret < 0) { + return ret; + } + if (*render == nullptr || *adapter == nullptr) { + return AUDIO_HAL_ERR_INTERNAL; + } + ret = AudioRenderStartAndOneFrame(*render); + if (ret < 0) { + (*adapter)->DestroyRender(*adapter, *render); + manager->UnloadAdapter(manager, *adapter); + return ret; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioRenderStartAndOneFrame(struct AudioRender *render) +{ + int32_t ret = -1; + char *frame = nullptr; + uint64_t numRead = 0; + uint64_t replyBytes = 0; + if (render == nullptr || render->control.Start == nullptr || render->RenderFrame == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = render->control.Start((AudioHandle)render); + if (ret) { + return ret; + } + ret = RenderFramePrepare(AUDIO_FILE, frame, numRead); + if (ret < 0) { + if (frame != nullptr) { + free(frame); + frame = nullptr; + } + return HDF_FAILURE; + } + ret = render->RenderFrame(render, frame, numRead, &replyBytes); + if (ret < 0) { + if (frame != nullptr) { + free(frame); + frame = nullptr; + } + return ret; + } + free(frame); + frame = nullptr; + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioCreateCapture(TestAudioManager *manager, enum AudioPortPin pins, const std::string &adapterName, + struct AudioAdapter **adapter, struct AudioCapture **capture) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioPort *capturePort = nullptr; + if (adapter == nullptr || capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = GetLoadAdapter(manager, PORT_IN, adapterName, adapter, capturePort); + if (ret < 0) { + return ret; + } + if (*adapter == nullptr || (*adapter)->CreateCapture == nullptr) { + return AUDIO_HAL_ERR_INTERNAL; + } + InitAttrs(attrs); + InitDevDesc(devDesc, capturePort->portId, pins); + ret = (*adapter)->CreateCapture(*adapter, &devDesc, &attrs, capture); + if (ret < 0) { + manager->UnloadAdapter(manager, *adapter); + return ret; + } + if (*capture == nullptr) { + manager->UnloadAdapter(manager, *adapter); + return AUDIO_HAL_ERR_INTERNAL; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioCreateStartCapture(TestAudioManager *manager, struct AudioCapture **capture, + struct AudioAdapter **adapter, const std::string &adapterName) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + enum AudioPortPin pins = PIN_IN_MIC; + if (adapter == nullptr || capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = AudioCreateCapture(manager, pins, adapterName, adapter, capture); + if (ret < 0) { + manager->UnloadAdapter(manager, *adapter); + return ret; + } + if (*capture == nullptr || *adapter == nullptr) { + manager->UnloadAdapter(manager, *adapter); + return AUDIO_HAL_ERR_INTERNAL; + } + FILE *file = fopen(AUDIO_CAPTURE_FILE.c_str(), "wb+"); + if (file == nullptr) { + (*adapter)->DestroyCapture(*adapter, *capture); + manager->UnloadAdapter(manager, *adapter); + return HDF_FAILURE; + } + InitAttrs(attrs); + ret = FrameStartCapture((*capture), file, attrs); + if (ret < 0) { + (*adapter)->DestroyCapture(*adapter, *capture); + manager->UnloadAdapter(manager, *adapter); + (void)fclose(file); + return ret; + } + (void)fclose(file); + return AUDIO_HAL_SUCCESS; +} + +int32_t AudioCaptureStartAndOneFrame(struct AudioCapture *capture) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + InitAttrs(attrs); + FILE *file = fopen(AUDIO_CAPTURE_FILE.c_str(), "wb+"); + if (file == nullptr) { + return HDF_FAILURE; + } + ret = FrameStartCapture(capture, file, attrs); + if (ret < 0) { + (void)fclose(file); + return ret; + } + (void)fclose(file); + return AUDIO_HAL_SUCCESS; +} + +int32_t FrameStart(struct AudioHeadInfo wavHeadInfo, struct AudioRender *render, FILE *file, + struct AudioSampleAttributes attrs) +{ + uint32_t readSize = 0; + size_t numRead = 0; + uint64_t replyBytes = 0; + int32_t tryNumFrame = 0; + if (render == nullptr || render->control.Start == nullptr || render->RenderFrame == nullptr || file == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + int32_t ret = render->control.Start((AudioHandle)render); + if (ret) { + return ret; + } + uint32_t remainingDataSize = wavHeadInfo.dataSize; + uint32_t bufferSize = PcmFramesToBytes(attrs); + if (bufferSize <= 0) { + return HDF_FAILURE; + } + char *frame = nullptr; + frame = (char *)calloc(1, bufferSize); + if (frame == nullptr) { + return HDF_ERR_MALLOC_FAIL; + } + do { + if (g_frameStatus) { + readSize = (remainingDataSize) > (bufferSize) ? (bufferSize) : (remainingDataSize); + numRead = fread(frame, readSize, 1, file); + if (numRead > 0) { + ret = render->RenderFrame(render, frame, readSize, &replyBytes); + if (ret < 0) { + if (ret == -1) { + if (tryNumFrame > TRY_NUM_FRAME) { + free(frame); + return ret; + } + tryNumFrame++; + continue; + } + free(frame); + return ret; + } + tryNumFrame = 0; + } + remainingDataSize -= readSize; + } + } while (readSize > 0 && remainingDataSize > 0); + free(frame); + return AUDIO_HAL_SUCCESS; +} + +int32_t FrameStartCapture(struct AudioCapture *capture, FILE *file, const struct AudioSampleAttributes attrs) +{ + int32_t ret = 0; + uint32_t bufferSize = 0; + uint64_t replyBytes = 0; + uint64_t requestBytes = 0; + if (capture == nullptr || capture->control.Start == nullptr || capture->CaptureFrame == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = capture->control.Start((AudioHandle)capture); + if (ret < 0) { + return ret; + } + uint32_t pcmBytes = PcmFramesToBytes(attrs); + if (pcmBytes < 1024 || pcmBytes > 8192) { + return HDF_FAILURE; + } + bufferSize = FRAME_COUNT * pcmBytes; + if (bufferSize <= 0) { + return HDF_FAILURE; + } + char *frame = nullptr; + frame = (char *)calloc(1, bufferSize); + if (frame == nullptr) { + return HDF_ERR_MALLOC_FAIL; + } + requestBytes = bufferSize; + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + if (ret < 0) { + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + if (ret < 0) { + free(frame); + return ret; + } + } + uint32_t requestByte = static_cast(replyBytes); + (void)fwrite(frame, requestByte, 1, file); + free(frame); + return AUDIO_HAL_SUCCESS; +} + +int32_t RenderFramePrepare(const std::string &path, char *&frame, uint64_t &readSize) +{ + int32_t ret = -1; + size_t numRead = 0; + uint32_t bufferSize = 4096; + uint32_t remainingDataSize = 0; + struct AudioSampleAttributes attrs = {}; + struct AudioHeadInfo headInfo = {}; + InitAttrs(attrs); + char absPath[PATH_MAX] = {0}; + if (realpath(path.c_str(), absPath) == nullptr) { + return HDF_FAILURE; + } + FILE *file = fopen(absPath, "rb"); + if (file == nullptr) { + return HDF_FAILURE; + } + ret = WavHeadAnalysis(headInfo, file, attrs); + if (ret < 0) { + (void)fclose(file); + return HDF_FAILURE; + } + frame = (char *)calloc(1, bufferSize); + if (frame == nullptr) { + (void)fclose(file); + return HDF_ERR_MALLOC_FAIL; + } + remainingDataSize = headInfo.dataSize; + readSize = (remainingDataSize) > (bufferSize) ? (bufferSize) : (remainingDataSize); + size_t readSizes = static_cast(readSize); + numRead = fread(frame, readSizes, 1, file); + if (numRead < 1) { + free(frame); + frame = nullptr; + (void)fclose(file); + return HDF_FAILURE; + } + (void)fclose(file); + return HDF_SUCCESS; +} + +void FrameStatus(int status) +{ + g_frameStatus = status; + return; +} + +int32_t StartRecord(struct AudioCapture *capture, FILE *file, uint64_t filesize) +{ + uint64_t replyBytes = 0; + uint64_t requestBytes = BUFFER_LENTH; + uint64_t totalSize = 0; + int32_t tryNumFrame = 0; + if (capture == nullptr || capture->control.Start == nullptr || + capture->CaptureFrame == nullptr || file == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + int32_t ret = capture->control.Start((AudioHandle)capture); + if (ret < 0) { + return ret; + } + char *frame = (char *)calloc(1, BUFFER_LENTH); + if (frame == nullptr) { + return HDF_ERR_MALLOC_FAIL; + } + do { + if (g_frameStatus) { + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + if (ret < 0) { + if (ret == -1) { + if (tryNumFrame++ > TRY_NUM_FRAME) { + free(frame); + frame = nullptr; + return ret; + } + continue; + } + free(frame); + frame = nullptr; + return ret; + } + tryNumFrame = 0; + uint32_t replyByte = static_cast(replyBytes); + size_t writeRet = fwrite(frame, replyByte, 1, file); + if (writeRet < 0) { + free(frame); + frame = nullptr; + return HDF_FAILURE; + } + totalSize += replyBytes; + } else { + totalSize += 0; + } + } while (totalSize <= filesize * MEGABYTE); + free(frame); + frame = nullptr; + return AUDIO_HAL_SUCCESS; +} + +int32_t WriteIdToBuf(struct HdfSBuf *sBuf, struct AudioCtlElemId id) +{ + if (!HdfSbufWriteInt32(sBuf, id.iface)) { + return HDF_FAILURE; + } + if (!HdfSbufWriteString(sBuf, id.cardServiceName)) { + return HDF_FAILURE; + } + if (!HdfSbufWriteString(sBuf, id.itemName)) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t WriteEleValueToBuf(struct HdfSBuf *sBuf, struct AudioCtlElemValue elemvalue) +{ + int32_t ret = -1; + if (sBuf == nullptr) { + return HDF_FAILURE; + } + if (!HdfSbufWriteInt32(sBuf, elemvalue.value[0])) { + return HDF_FAILURE; + } + ret = WriteIdToBuf(sBuf, elemvalue.id); + if (ret != HDF_SUCCESS) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t ChangeRegisterStatus(struct AudioCtlElemValue elemValue) +{ + int32_t ret = -1; + struct HdfIoService *service = nullptr; + struct HdfSBuf *reply = nullptr; + struct HdfSBuf *sBuf = nullptr; + service = HdfIoServiceBind(HDF_CONTROL_SERVICE.c_str()); + if (service == nullptr || service->dispatcher == nullptr) { + return HDF_FAILURE; + } + sBuf = HdfSBufObtainDefaultSize(); + if (sBuf == nullptr) { + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + ret = WriteEleValueToBuf(sBuf, elemValue); + if (ret < 0) { + HdfSBufRecycle(sBuf); + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + ret = service->dispatcher->Dispatch(&service->object, AUDIODRV_CTRL_IOCTRL_ELEM_WRITE, sBuf, reply); + if (ret < 0) { + HdfSBufRecycle(sBuf); + HdfIoServiceRecycle(service); + return ret; + } + HdfSBufRecycle(sBuf); + HdfIoServiceRecycle(service); + return HDF_SUCCESS; +} + +int32_t QueryRegisterStatus(struct AudioCtlElemId id, struct AudioCtlElemValue &elemValue) +{ + struct HdfIoService *service = nullptr; + struct HdfSBuf *sBuf = nullptr; + struct HdfSBuf *reply = nullptr; + int32_t ret = -1; + service = HdfIoServiceBind(HDF_CONTROL_SERVICE.c_str()); + if (service == nullptr || service->dispatcher == nullptr) { + return HDF_FAILURE; + } + sBuf = HdfSBufObtainDefaultSize(); + if (sBuf == nullptr) { + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + ret = WriteIdToBuf(sBuf, id); + if (ret < 0) { + HdfSBufRecycle(sBuf); + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + reply = HdfSBufObtainDefaultSize(); + if (reply == nullptr) { + HdfSBufRecycle(sBuf); + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + ret = service->dispatcher->Dispatch(&service->object, AUDIODRV_CTRL_IOCTRL_ELEM_READ, sBuf, reply); + if (ret < 0) { + HdfSBufRecycle(sBuf); + HdfSBufRecycle(reply); + HdfIoServiceRecycle(service); + return ret; + } + if (!HdfSbufReadInt32(reply, &elemValue.value[0])) { + HdfSBufRecycle(sBuf); + HdfSBufRecycle(reply); + HdfIoServiceRecycle(service); + return HDF_FAILURE; + } + HdfSBufRecycle(sBuf); + HdfSBufRecycle(reply); + HdfIoServiceRecycle(service); + return HDF_SUCCESS; +} + +int32_t PowerOff(struct AudioCtlElemValue firstElemValue, struct AudioCtlElemValue secondElemValue) +{ + int32_t ret = -1; + ret = ChangeRegisterStatus(firstElemValue); + if (ret < 0) { + return ret; + } + ret = ChangeRegisterStatus(secondElemValue); + if (ret < 0) { + return ret; + } + return HDF_SUCCESS; +} + +int32_t CheckRegisterStatus(const struct AudioCtlElemId firstId, const struct AudioCtlElemId secondId, + const int firstStatus, const int secondStatus) +{ + int32_t ret = -1; + struct AudioCtlElemValue elemValue[2] = {{}, {}}; + ret = QueryRegisterStatus(firstId, elemValue[0]); + if (ret < 0) { + return ret; + } + if (firstStatus != elemValue[0].value[0]) { + return HDF_FAILURE; + } + ret = QueryRegisterStatus(secondId, elemValue[1]); + if (ret < 0) { + return ret; + } + if (secondStatus != elemValue[1].value[0]) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t StopAudio(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + if (audiopara.capture != nullptr) { + ret = audiopara.capture->control.Stop((AudioHandle)(audiopara.capture)); + if (ret < 0) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + audiopara.capture = nullptr; + audiopara.adapter = nullptr; + return ret; + } + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.capture = nullptr; + } + if (audiopara.render != nullptr) { + ret = audiopara.render->control.Stop((AudioHandle)(audiopara.render)); + if (ret < 0) { + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + audiopara.render = nullptr; + audiopara.adapter = nullptr; + return ret; + } + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.render = nullptr; + } + if (audiopara.manager != nullptr && audiopara.adapter != nullptr) { + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + audiopara.adapter = nullptr; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t ThreadRelease(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + pthread_join(audiopara.tids, &audiopara.result); + ret = (intptr_t)audiopara.result; + if (ret < 0) { + StopAudio(audiopara); + return ret; + } + ret = StopAudio(audiopara); + if (ret < 0) { + return ret; + } + return AUDIO_HAL_SUCCESS; +} +int32_t PlayAudioFile(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + char absPath[PATH_MAX] = {0}; + if (realpath(audiopara.path, absPath) == nullptr) { + return HDF_FAILURE; + } + if (audiopara.manager == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + FILE *file = fopen(absPath, "rb"); + if (file == nullptr) { + return HDF_FAILURE; + } + if (WavHeadAnalysis(audiopara.headInfo, file, audiopara.attrs) < 0) { + (void)fclose(file); + return HDF_FAILURE; + } + ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0) { + (void)fclose(file); + return ret; + } + if (audiopara.render == nullptr) { + (void)fclose(file); + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = FrameStart(audiopara.headInfo, audiopara.render, file, audiopara.attrs); + if (ret == AUDIO_HAL_SUCCESS) { + (void)fclose(file); + } else { + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + audiopara.render = nullptr; + audiopara.adapter = nullptr; + (void)fclose(file); + return ret; + } + return AUDIO_HAL_SUCCESS; +} + +int32_t RecordAudio(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + if (audiopara.manager == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0) { + return ret; + } + if (audiopara.capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + + bool isMute = false; + ret = audiopara.capture->volume.SetMute(audiopara.capture, isMute); + if (ret < 0) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + return ret; + } + + FILE *file = fopen(audiopara.path, "wb+"); + if (file == nullptr) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + return AUDIO_HAL_ERR_INTERNAL; + } + ret = StartRecord(audiopara.capture, file, audiopara.fileSize); + if (ret < 0) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + audiopara.capture = nullptr; + audiopara.adapter = nullptr; + (void)fclose(file); + return ret; + } + (void)fclose(file); + return AUDIO_HAL_SUCCESS; +} +int32_t InitMmapDesc(FILE *fp, struct AudioMmapBufferDescripter &desc, int32_t &reqSize, bool flag) +{ + if (fp == NULL) { + return HDF_FAILURE; + } + int fd = fileno(fp); + if (fd == -1) { + return HDF_FAILURE; + } + if (flag) { + struct AudioHeadInfo wavHeadInfo = {}; + fseek(fp, 0, SEEK_END); + reqSize = ftell(fp); + desc.offset = sizeof(wavHeadInfo); + } else { + reqSize = FILE_CAPTURE_SIZE; + ftruncate(fd, FILE_CAPTURE_SIZE); + desc.offset = 0; + } + desc.memoryFd = fd; + desc.isShareable = 1; + desc.transferFrameSize = DEEP_BUFFER_RENDER_PERIOD_SIZE / FRAME_COUNT; + return HDF_SUCCESS; +} + +int32_t PlayMapAudioFile(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + int32_t reqSize = 0; + bool isRender = true; + FrameStatus(1); + struct AudioMmapBufferDescripter desc = {}; + if (audiopara.render == nullptr) { + return HDF_FAILURE; + } + char absPath[PATH_MAX] = {0}; + if (realpath(audiopara.path, absPath) == nullptr) { + return HDF_FAILURE; + } + FILE *fp = fopen(absPath, "rb+"); + if (fp == nullptr) { + return HDF_FAILURE; + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + if (ret < 0) { + (void)fclose(fp); + return HDF_FAILURE; + } + ret = audiopara.render->control.Start((AudioHandle)(audiopara.render)); + if (ret < 0) { + (void)fclose(fp); + return ret; + } + ret = audiopara.render->attr.ReqMmapBuffer((AudioHandle)(audiopara.render), reqSize, &desc); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + (void)fclose(fp); + return ret; +} +int32_t RecordMapAudio(struct PrepareAudioPara &audiopara) +{ + int32_t ret = -1; + int32_t reqSize = 0; + bool isRender = false; + struct AudioMmapBufferDescripter desc = {}; + if (audiopara.capture == nullptr) { + return HDF_FAILURE; + } + FILE *fp = fopen(audiopara.path, "wb+"); + if (fp == NULL) { + return HDF_FAILURE; + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + if (ret < 0) { + (void)fclose(fp); + return HDF_FAILURE; + } + ret = audiopara.capture->control.Start((AudioHandle)(audiopara.capture)); + if (ret < 0) { + (void)fclose(fp); + return ret; + } + ret = audiopara.capture->attr.ReqMmapBuffer((AudioHandle)(audiopara.capture), reqSize, &desc); + (void)fclose(fp); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + return ret; +} +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/BUILD.gn b/hdf/audio/hdi/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d3db851aea2b529816f48a19161053e24dd026fa --- /dev/null +++ b/hdf/audio/hdi/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2021 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. + +import("//build/ohos_var.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/peripheral/audio/audio.gni") +import("//test/xts/tools/build/suite.gni") + +###########################end########################### +group("hdi") { + if (!defined(ohos_lite)) { + testonly = true + } + deps = [ + "adapter:hdf_audio_hdi_adapter_test", + "capture:hdf_audio_hdi_capture_test", + "render:hdf_audio_hdi_render_test", + ] +} diff --git a/hdf/audio/hdi/adapter/BUILD.gn b/hdf/audio/hdi/adapter/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2625783157a2eb4d9320ddced2ca008bcfa201a5 --- /dev/null +++ b/hdf/audio/hdi/adapter/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 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. + +import("//build/ohos_var.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/peripheral/audio/audio.gni") +import("//test/xts/tools/build/suite.gni") + +###########################NOT LITEOS############################## +module_output_path = "hdf/audio" + +###########################hdf_audio_hdi_adapter_test##################### +ohos_moduletest_suite("hdf_audio_hdi_adapter_test") { + module_out_path = module_output_path + sources = [ + "../../common/hdi_common/src/audio_hdi_common.cpp", + "src/audio_hdiadapter_test.cpp", + ] + + include_dirs = [ + "//drivers/peripheral/audio/hal/hdi_passthrough/include", + "//drivers/peripheral/audio/interfaces/include", + "//drivers/peripheral/audio/hal/hdi_binder/proxy/include", + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/adapter/uhdf2/shared/include", + "//drivers/adapter/uhdf2/osal/include", + "//drivers/framework/include/core", + "//drivers/framework/include/utils", + "//drivers/framework/include/osal", + "//drivers/framework/include", + "//drivers/framework/utils/include", + "//third_party/bounds_checking_function/include", + "//drivers/peripheral/audio/test/systemtest/common/hdi_common/include", + "//third_party/googletest/googletest/include/gtest", + "//drivers/peripheral/audio/test/systemtest/hdi/adapter/include", + ] + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + defines = [] + if (enable_audio_adm_so) { + defines += [ "AUDIO_ADM_SO" ] + } + if (enable_audio_mpi_so) { + defines += [ "AUDIO_MPI_SO" ] + } + if (enable_audio_adm_service) { + defines += [ "AUDIO_ADM_SERVICE" ] + } + if (enable_audio_mpi_service) { + defines += [ "AUDIO_MPI_SERVICE" ] + } +} +###########################end########################### diff --git a/hdf/audio/hdi/adapter/Test.json b/hdf/audio/hdi/adapter/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..a2767967d54be9a2ac64b3ba434fae100a1a3754 --- /dev/null +++ b/hdf/audio/hdi/adapter/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "hdf_audio_hdi_adapter_test->/data/local/tmp/hdf_audio_hdi_adapter_test" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hdf_audio_hdi_adapter_test", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hdf_audio_hdi_adapter_test Tests" +} \ No newline at end of file diff --git a/hdf/audio/hdi/adapter/include/audio_hdiadapter_test.h b/hdf/audio/hdi/adapter/include/audio_hdiadapter_test.h new file mode 100755 index 0000000000000000000000000000000000000000..a43a4cff1e2e79c1beead725f3116963dedacf13 --- /dev/null +++ b/hdf/audio/hdi/adapter/include/audio_hdiadapter_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIADAPTER_TEST_H +#define AUDIO_HDIADAPTER_TEST_H + +#endif diff --git a/hdf/audio/hdi/adapter/src/audio_hdiadapter_test.cpp b/hdf/audio/hdi/adapter/src/audio_hdiadapter_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..59ae28a6657e0c7f0bb634dd9da39039d4abb44d --- /dev/null +++ b/hdf/audio/hdi/adapter/src/audio_hdiadapter_test.cpp @@ -0,0 +1,828 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Test audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdiadapter_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + + +class AudioHdiAdapterTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +TestAudioManager *(*AudioHdiAdapterTest::GetAudioManager)() = nullptr; +void *AudioHdiAdapterTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiAdapterTest::SdkInit)() = nullptr; + void (*AudioHdiAdapterTest::SdkExit)() = nullptr; + void *AudioHdiAdapterTest::sdkSo = nullptr; +#endif + +void AudioHdiAdapterTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiAdapterTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiAdapterTest::SetUp(void) {} + +void AudioHdiAdapterTest::TearDown(void) {} + +/** +* @tc.name Test GetAllAdapters API via legal input +* @tc.number SUB_Audio_HDI_GetAllAdapters_0001 +* @tc.desc test GetAllAdapters interface,Returns 0 if the list is obtained successfully +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_GetAllAdapters_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->GetAllAdapters(manager, &descs, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_ADAPTER_MAX_NUM, size); +} + +/** +* @tc.name Test GetAllAdapters API via setting the incoming parameter manager is nullptr +* @tc.number SUB_Audio_HDI_GetAllAdapters_0002 +* @tc.desc test GetAllAdapters interface,Returns -1 if the incoming parameter manager is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_GetAllAdapters_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + TestAudioManager *manager1 = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->GetAllAdapters(manager1, &descs, &size); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); +} + +/** +* @tc.name Test GetAllAdapters API via setting the incoming parameter descs is nullptr +* @tc.number SUB_Audio_HDI_GetAllAdapters_0003 +* @tc.desc test GetAllAdapters interface,Returns -1 if the incoming parameter descs is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_GetAllAdapters_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor **descs = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->GetAllAdapters(manager, descs, &size); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); +} + +/** +* @tc.name Test GetAllAdapters API via setting the incoming parameter size is nullptr +* @tc.number SUB_Audio_HDI_GetAllAdapters_0004 +* @tc.desc test GetAllAdapters interface,Returns -1 if the incoming parameter size is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_GetAllAdapters_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int *size = nullptr; + struct AudioAdapterDescriptor *descs = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->GetAllAdapters(manager, &descs, size); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); +} + +/** +* @tc.name Test LoadAdapter API via legal input +* @tc.number SUB_Audio_HDI_LoadAdapter_0001 +* @tc.desc test LoadAdapter interface,Returns 0 if the driver is loaded successfully +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetAdapters(manager, &descs, size); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + struct AudioAdapterDescriptor *desc = &descs[0]; + ASSERT_TRUE(desc != nullptr); + struct AudioAdapter *adapter = nullptr; + ret = manager->LoadAdapter(manager, desc, &adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = -1; + if (adapter != nullptr) { + if (adapter->InitAllPorts != nullptr && adapter->CreateRender != nullptr && + adapter->DestroyRender != nullptr && adapter->CreateCapture != nullptr && + adapter->DestroyCapture != nullptr && adapter->GetPortCapability != nullptr && + adapter->SetPassthroughMode != nullptr && adapter->GetPassthroughMode != nullptr) { + ret = 0; + } + } + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test LoadAdapter API via changing the adapterName of incoming parameter desc +* @tc.number SUB_Audio_HDI_LoadAdapter_0002 +* @tc.desc test LoadAdapter interface,Returns -1 if the adapterName of incoming parameter desc is not support +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetAdapters(manager, &descs, size); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + struct AudioAdapterDescriptor *desc = &descs[0]; + desc->adapterName = "illegal"; + ASSERT_TRUE(desc != nullptr); + struct AudioAdapter *adapter = nullptr; + + ret = manager->LoadAdapter(manager, desc, &adapter); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + desc->adapterName = "internal"; + ret = manager->LoadAdapter(manager, desc, &adapter); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test LoadAdapter API via setting the adapterName of incoming parameter desc is illegal +* @tc.number SUB_Audio_HDI_LoadAdapter_0003 +* @tc.desc test LoadAdapter interface,Returns -1 if the adapterName of incoming parameter desc is illegal +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapterDescriptor desc = { + .adapterName = "illegal", + .portNum = 2, + .ports = nullptr, + }; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->LoadAdapter(manager, &desc, &adapter); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test LoadAdapter API via setting the adapterName of incoming parameter manager is nullptr +* @tc.number SUB_Audio_HDI_LoadAdapter_0004 +* @tc.desc test LoadAdapter interface,Returns -1 if the incoming parameter manager is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + TestAudioManager *managerNull = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetAdapters(manager, &descs, size); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + struct AudioAdapterDescriptor *desc = &descs[0]; + ASSERT_TRUE(desc != nullptr); + struct AudioAdapter *adapter = nullptr; + + ret = manager->LoadAdapter(managerNull, desc, &adapter); + ASSERT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test LoadAdapter API via setting the adapterName of incoming parameter desc is nullptr +* @tc.number SUB_Audio_HDI_LoadAdapter_0005 +* @tc.desc test LoadAdapter interface,Returns -1 if the incoming parameter desc is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapterDescriptor *desc = nullptr; + struct AudioAdapter *adapter = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + ASSERT_NE(nullptr, manager); + ret = manager->LoadAdapter(manager, desc, &adapter); + ASSERT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test LoadAdapter API via setting the adapterName of incoming parameter adapter is nullptr +* @tc.number SUB_Audio_HDI_LoadAdapter_0006 +* @tc.desc test LoadAdapter interface,Returns -1 if the incoming parameter adapter is nullptr +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_LoadAdapter_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int size = 0; + struct AudioAdapterDescriptor *descs = nullptr; + struct AudioAdapter **adapter = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetAdapters(manager, &descs, size); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + struct AudioAdapterDescriptor *desc = &descs[0]; + ASSERT_TRUE(desc != nullptr); + + ret = manager->LoadAdapter(manager, desc, adapter); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); +} + +/** +* @tc.name Test AudioAdapterInitAllPorts API via legal input. +* @tc.number SUB_Audio_HDI_AdapterInitAllPorts_0001 +* @tc.desc Test AudioAdapterInitAllPorts interface, return 0 if the ports is initialize successfully. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterInitAllPorts_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioPort* renderPort = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterInitAllPorts API when loads two adapters. +* @tc.number SUB_Audio_HDI_AdapterInitAllPorts_0002 +* @tc.desc Test AudioAdapterInitAllPorts interface, return 0 if loads two adapters successfully. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterInitAllPorts_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int32_t ret2 = -1; + struct AudioPort* renderPort = nullptr; + struct AudioPort* renderPortUsb = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapter1 = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_INTERNAL, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret2 = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter1, renderPortUsb); + if (ret2 < 0 || adapter1 == nullptr) { + manager->UnloadAdapter(manager, adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret2); + } + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = adapter->InitAllPorts(adapter1); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret2); + + manager->UnloadAdapter(manager, adapter); + manager->UnloadAdapter(manager, adapter1); +} + +/** +* @tc.name Test AudioAdapterInitAllPorts API when the parameter adapter is empty. +* @tc.number SUB_Audio_HDI_AdapterInitAllPorts_0003 +* @tc.desc Test AudioAdapterInitAllPorts API, return -1 if the parameter adapter is empty. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterInitAllPorts_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapterNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API when the PortType is PORT_OUT. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0001 +* @tc.desc Test AudioAdapterGetPortCapability,return 0 if PortType is PORT_OUT. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPortCapability capability = {}; + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPortCapability(adapter, audioPort, &capability); + if (ret < 0 || capability.formats == nullptr || capability.subPorts == nullptr) { + manager->UnloadAdapter(manager, adapter); + ASSERT_NE(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, capability.formats); + ASSERT_NE(nullptr, capability.subPorts); + } + if (capability.subPorts->desc == nullptr) { + manager->UnloadAdapter(manager, adapter); + ASSERT_NE(nullptr, capability.subPorts->desc); + } + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API when the PortType is PORT_IN. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0002 +* @tc.desc Test AudioAdapterGetPortCapability,return 0 if PortType is PORT_IN. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPortCapability capability = {}; + + ret = GetLoadAdapter(manager, PORT_IN, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPortCapability(adapter, audioPort, &capability); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API when the PortType is PORT_OUT_IN. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0003 +* @tc.desc Test AudioAdapterGetPortCapability,return 0 if PortType is PORT_OUT_IN. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPortCapability capability = {}; + + ret = GetLoadAdapter(manager, PORT_OUT_IN, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPortCapability(adapter, audioPort, &capability); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API, when the parameter adapter is empty. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0004 +* @tc.desc Test AudioAdapterGetPortCapability, return -1 if the parameter adapter is empty. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + struct AudioPortCapability capability = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_INTERNAL, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + ret = adapter->GetPortCapability(adapterNull, audioPort, &capability); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API when the audioPort is nullptr or not supported. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0005 +* @tc.desc Test AudioAdapterGetPortCapability, return -1 if the audioPort is nullptr or not supported. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort *audioPortNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioPortCapability capability = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPort* audioPort = nullptr; + struct AudioPort audioPortError = { .dir = PORT_OUT, .portId = 9, .portName = "AIP" }; + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_INTERNAL, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPortCapability(adapter, audioPortNull, &capability); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = adapter->GetPortCapability(adapter, &audioPortError, &capability); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioAdapterGetPortCapability API when the capability is nullptr. +* @tc.number SUB_Audio_HDI_AdapterGetPortCapability_0006 +* @tc.desc Test AudioAdapterGetPortCapability, return -1 if capability is nullptr. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPortCapability_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioPortCapability *capabilityNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_INTERNAL, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPortCapability(adapter, audioPort, capabilityNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterSetPassthroughMode API when the PortType is PORT_OUT. +* @tc.number SUB_Audio_HDI_AdapterSetPassthroughMode_0001 +* @tc.desc test AdapterSetPassthroughMode interface, return 0 if PortType is PORT_OUT. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterSetPassthroughMode_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + enum AudioPortPassthroughMode modeLpcm = PORT_PASSTHROUGH_AUTO; + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->SetPassthroughMode(adapter, audioPort, PORT_PASSTHROUGH_LPCM); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPassthroughMode(adapter, audioPort, &modeLpcm); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(PORT_PASSTHROUGH_LPCM, modeLpcm); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterSetPassthroughMode API when the PortType is PORT_IN. +* @tc.number SUB_Audio_HDI_AdapterSetPassthroughMode_0002 +* @tc.desc test AdapterSetPassthroughMode interface, return -1 if PortType is PORT_IN. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterSetPassthroughMode_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioPort* audioPort = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_IN, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->SetPassthroughMode(adapter, audioPort, PORT_PASSTHROUGH_LPCM); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterSetPassthroughMode API when the parameter adapter is nullptr. +* @tc.number SUB_Audio_HDI_AdapterSetPassthroughMode_0003 +* @tc.desc test AdapterSetPassthroughMode interface, return -1 the parameter adapter is empty. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterSetPassthroughMode_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_INTERNAL, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->SetPassthroughMode(adapterNull, audioPort, PORT_PASSTHROUGH_LPCM); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterSetPassthroughMode API when the parameter audioPort is nullptr or not supported. +* @tc.number SUB_Audio_HDI_AdapterSetPassthroughMode_0004 +* @tc.desc test AdapterSetPassthroughMode interface, return -1 if the audioPort is nullptr or not supported. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterSetPassthroughMode_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioPort *audioPortNull = nullptr; + enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPort audioPortError = { .dir = PORT_OUT, .portId = 8, .portName = "AIP1" }; + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->SetPassthroughMode(adapter, audioPortNull, mode); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = adapter->SetPassthroughMode(adapter, &audioPortError, mode); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterSetPassthroughMode API when the not supported mode. +* @tc.number SUB_Audio_HDI_AdapterSetPassthroughMode_0005 +* @tc.desc test AdapterSetPassthroughMode interface, return -1 if the not supported mode. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterSetPassthroughMode_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->SetPassthroughMode(adapter, audioPort, PORT_PASSTHROUGH_RAW); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterGetPassthroughMode API via legal input +* @tc.number SUB_Audio_HDI_AdapterGetPassthroughMode_0001 +* @tc.desc test AdapterGetPassthroughMode interface, return 0 if is get successfully. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPassthroughMode_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_AUTO; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = adapter->SetPassthroughMode(adapter, audioPort, PORT_PASSTHROUGH_LPCM); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = adapter->GetPassthroughMode(adapter, audioPort, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(PORT_PASSTHROUGH_LPCM, mode); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterGetPassthroughMode API when the parameter adapter is nullptr. +* @tc.number SUB_Audio_HDI_AdapterGetPassthroughMode_0002 +* @tc.desc test AdapterGetPassthroughMode interface, return -1 if the parameter adapter is empty.. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPassthroughMode_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPassthroughMode(adapterNull, audioPort, &mode); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterGetPassthroughMode API when the parameter audioPort is nullptr or not supported. +* @tc.number SUB_Audio_HDI_AdapterGetPassthroughMode_0003 +* @tc.desc test AdapterGetPassthroughMode interface, return -1 if the audioPort is nullptr or not supported. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPassthroughMode_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + struct AudioPort *audioPortNull = nullptr; + enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + struct AudioPort audioPortError = { .dir = PORT_OUT, .portId = 8, .portName = "AIP" }; + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPassthroughMode(adapter, audioPortNull, &mode); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = adapter->GetPassthroughMode(adapter, &audioPortError, &mode); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AdapterGetPassthroughMode API when the parameter mode is nullptr. +* @tc.number SUB_Audio_HDI_AdapterGetPassthroughMode_0004 +* @tc.desc test AdapterGetPassthroughMode interface, return -1 if the parameter mode is empty. +*/ +HWTEST_F(AudioHdiAdapterTest, SUB_Audio_HDI_AdapterGetPassthroughMode_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* audioPort = nullptr; + enum AudioPortPassthroughMode *modeNull = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_NE(nullptr, adapter); + ret = adapter->InitAllPorts(adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->GetPassthroughMode(adapter, audioPort, modeNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/BUILD.gn b/hdf/audio/hdi/capture/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..67a39cb8872701d4ddf7a00b3936d76b190db059 --- /dev/null +++ b/hdf/audio/hdi/capture/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2021 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. + +import("//build/ohos_var.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/peripheral/audio/audio.gni") +import("//test/xts/tools/build/suite.gni") + +###########################systemtest############################## +module_output_path = "hdf/audio" + +###########################hdf_audio_hdi_capture_test##################### +ohos_moduletest_suite("hdf_audio_hdi_capture_test") { + module_out_path = module_output_path + sources = [ + "../../common/hdi_common/src/audio_hdi_common.cpp", + "src/audio_hdicapture_attr_test.cpp", + "src/audio_hdicapture_control_test.cpp", + "src/audio_hdicapture_scene_test.cpp", + "src/audio_hdicapture_test.cpp", + "src/audio_hdicapture_volume_test.cpp", + ] + + include_dirs = [ + "//drivers/peripheral/audio/hal/hdi_passthrough/include", + "//drivers/peripheral/audio/interfaces/include", + "//drivers/peripheral/audio/hal/hdi_binder/proxy/include", + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/adapter/uhdf2/shared/include", + "//drivers/framework/include/core", + "//drivers/framework/include/utils", + "//drivers/framework/include/osal", + "//drivers/framework/include", + "//third_party/bounds_checking_function/include", + "//drivers/framework/utils/include", + "//drivers/adapter/uhdf2/osal/include", + "//drivers/peripheral/audio/test/systemtest/common/hdi_common/include", + "//third_party/googletest/googletest/include/gtest", + "//drivers/peripheral/audio/test/systemtest/hdi/capture/include", + ] + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + defines = [] + if (enable_audio_adm_so) { + defines += [ "AUDIO_ADM_SO" ] + } + if (enable_audio_mpi_so) { + defines += [ "AUDIO_MPI_SO" ] + } + if (enable_audio_adm_service) { + defines += [ "AUDIO_ADM_SERVICE" ] + } + if (enable_audio_mpi_service) { + defines += [ "AUDIO_MPI_SERVICE" ] + } +} diff --git a/hdf/audio/hdi/capture/Test.json b/hdf/audio/hdi/capture/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1c5d6a741970ce956c52b705ee2f812e5d1d49a4 --- /dev/null +++ b/hdf/audio/hdi/capture/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "hdf_audio_hdi_capture_test->/data/local/tmp/hdf_audio_hdi_capture_test" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hdf_audio_hdi_capture_test", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hdf_audio_hdi_capture_test Tests" +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/include/audio_hdicapture_attr_test.h b/hdf/audio/hdi/capture/include/audio_hdicapture_attr_test.h new file mode 100755 index 0000000000000000000000000000000000000000..e08c8b5289ac8ce0705d5717bf6f8978965e9555 --- /dev/null +++ b/hdf/audio/hdi/capture/include/audio_hdicapture_attr_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDICAPTURE_ATTR_TEST_H +#define AUDIO_HDICAPTURE_ATTR_TEST_H + +#endif diff --git a/hdf/audio/hdi/capture/include/audio_hdicapture_control_test.h b/hdf/audio/hdi/capture/include/audio_hdicapture_control_test.h new file mode 100755 index 0000000000000000000000000000000000000000..a2de06e2e2fd93a8ea47bd3c194a2282bcefbd64 --- /dev/null +++ b/hdf/audio/hdi/capture/include/audio_hdicapture_control_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDICAPTURE_CONTROL_TEST_H +#define AUDIO_HDICAPTURE_CONTROL_TEST_H + +#endif diff --git a/hdf/audio/hdi/capture/include/audio_hdicapture_scene_test.h b/hdf/audio/hdi/capture/include/audio_hdicapture_scene_test.h new file mode 100755 index 0000000000000000000000000000000000000000..e80537f6edfebcc36bdf94c67e0f10e6f4d33b18 --- /dev/null +++ b/hdf/audio/hdi/capture/include/audio_hdicapture_scene_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDICAPTURE_SCENE_TEST_H +#define AUDIO_HDICAPTURE_SCENE_TEST_H + +#endif diff --git a/hdf/audio/hdi/capture/include/audio_hdicapture_test.h b/hdf/audio/hdi/capture/include/audio_hdicapture_test.h new file mode 100755 index 0000000000000000000000000000000000000000..b2a3dc872054065c88052430be0f0ed725f6f010 --- /dev/null +++ b/hdf/audio/hdi/capture/include/audio_hdicapture_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDICAPTURE_TEST_H +#define AUDIO_HDICAPTURE_TEST_H + +#endif diff --git a/hdf/audio/hdi/capture/include/audio_hdicapture_volume_test.h b/hdf/audio/hdi/capture/include/audio_hdicapture_volume_test.h new file mode 100755 index 0000000000000000000000000000000000000000..f51f3953cef2206a614e98bf3b6ce944ba9f5712 --- /dev/null +++ b/hdf/audio/hdi/capture/include/audio_hdicapture_volume_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDICAPTURE_VOLUME_TEST_H +#define AUDIO_HDICAPTURE_VOLUME_TEST_H + +#endif diff --git a/hdf/audio/hdi/capture/src/audio_hdicapture_attr_test.cpp b/hdf/audio/hdi/capture/src/audio_hdicapture_attr_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f796425a949385bd8c6292689571c6039ee5a579 --- /dev/null +++ b/hdf/audio/hdi/capture/src/audio_hdicapture_attr_test.cpp @@ -0,0 +1,1748 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for capture drivers function. + * accessing a driver adapter, and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the capturing audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdicapture_attr_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_HDMI = "hdmi"; +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiCaptureAttrTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif + int32_t AudioCaptureStart(const string path, struct AudioCapture *capture) const; +}; + +using THREAD_FUNC = void *(*)(void *); + +TestAudioManager *(*AudioHdiCaptureAttrTest::GetAudioManager)() = nullptr; +void *AudioHdiCaptureAttrTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiCaptureAttrTest::SdkInit)() = nullptr; + void (*AudioHdiCaptureAttrTest::SdkExit)() = nullptr; + void *AudioHdiCaptureAttrTest::sdkSo = nullptr; +#endif + +void AudioHdiCaptureAttrTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiCaptureAttrTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiCaptureAttrTest::SetUp(void) {} +void AudioHdiCaptureAttrTest::TearDown(void) {} + +int32_t AudioHdiCaptureAttrTest::AudioCaptureStart(const string path, struct AudioCapture *capture) const +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + if (capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = InitAttrs(attrs); + if (ret < 0) { + return ret; + } + FILE *file = fopen(path.c_str(), "wb+"); + if (file == nullptr) { + return HDF_FAILURE; + } + ret = FrameStartCapture(capture, file, attrs); + (void)fclose(file); + return ret; +} + +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0001 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 8000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 8000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 8000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0002 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 11025; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 11025; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 11025); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0003 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 22050; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 22050; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 22050); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0004 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 32000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 32000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 32000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0005 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 44100; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 44100; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 44100); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0006 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_COMMUNICATION; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 48000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 48000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via setting the capture is empty . +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0007 +* @tc.desc Test AudioCaptureSetSampleAttributes interface, return -1 if the capture is empty. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 8000); + + ret = capture->attr.SetSampleAttributes(captureNull, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = capture->attr.SetSampleAttributes(capture, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0008 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 12000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 12000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 12000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0009 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 16000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 16000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 16000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0010 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 24000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0010, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 24000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 24000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0011 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 64000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0011, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 64000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 64000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0012 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 96000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0012, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 96000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 96000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0013 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16; +* attrs.sampleRate = 0xFFFFFFFFu; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0013, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 0xFFFFFFFFu); + + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0014 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_8/32_BIT/AAC_MAIN; +* attrs.sampleRate = 8000/11025/22050; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0014, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + struct AudioSampleAttributes attrs3 = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs1, AUDIO_FORMAT_PCM_8_BIT, 1, 8000); + ret = capture->attr.SetSampleAttributes(capture, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_PCM_32_BIT, 2, 11025); + ret = capture->attr.SetSampleAttributes(capture, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs3, AUDIO_FORMAT_AAC_MAIN, 1, 22050); + ret = capture->attr.SetSampleAttributes(capture, &attrs3); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0015 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_AAC_LC/LD/ELD; +* attrs.sampleRate = 32000/44100/48000; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0015, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + struct AudioSampleAttributes attrs3 = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs1, AUDIO_FORMAT_AAC_LC, 2, 32000); + ret = capture->attr.SetSampleAttributes(capture, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_AAC_LD, 1, 44100); + ret = capture->attr.SetSampleAttributes(capture, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs3, AUDIO_FORMAT_AAC_ELD, 2, 48000); + ret = capture->attr.SetSampleAttributes(capture, &attrs3); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0016 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_AAC_HE_V1/V2 +* attrs.sampleRate = 8000/44100; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0016, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs1, AUDIO_FORMAT_AAC_HE_V1, 1, 8000); + ret = capture->attr.SetSampleAttributes(capture, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_AAC_HE_V2, 2, 44100); + ret = capture->attr.SetSampleAttributes(capture, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0017 +* @tc.desc Test AudioCaptureSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT +* attrs.sampleRate = 8000; +* attrs.channelCount = 5; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureSetSampleAttributes_0017, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 5, 8000); + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureGetSampleAttributes_0001 +* @tc.desc Test AudioCaptureGetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 8000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureGetSampleAttributes_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 32000; + uint32_t ret2 = 1; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 32000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetSampleAttributes API via setting the capture is empty . +* @tc.number SUB_Audio_HDI_AudioCaptureGetSampleAttributes_0002 +* @tc.desc Test AudioCaptureGetSampleAttributes interface, return -1 if the capture is empty. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_AudioCaptureGetSampleAttributes_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 48000); + + ret = capture->attr.GetSampleAttributes(captureNull, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = capture->attr.GetSampleAttributes(capture, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameSize API via legal input +* @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0001 +* @tc.desc test AudioCaptureGetFrameSize interface, return 0 is call successfully. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetFrameSize(capture, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameSize API via setting the parameter handle is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0002 +* @tc.desc test AudioCaptureGetFrameSize interface, return -1 if the parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameSize(captureNull, &size); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameSize API via setting the parameter size is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0003 +* @tc.desc test AudioCaptureGetFrameSize interface, return -1 if the parameter size is nullptr. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *sizeNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameSize(capture, sizeNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameSize API via define format to different values + * @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0004 + * @tc.desc Test CaptureGetFrameSize interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 48000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = capture->attr.GetFrameSize(capture, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameSize API via define sampleRate to different values + * @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0005 + * @tc.desc Test CaptureGetFrameSize interface,return 0 if get framesize define sampleRate as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 48000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = capture->attr.GetFrameSize(capture, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameSize API via define channelCount to different values + * @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0006 + * @tc.desc Test CaptureGetFrameSize interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 44100; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 44100); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = capture->attr.GetFrameSize(capture, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameSize API via define sampleRate to different value + * @tc.number SUB_Audio_hdi_CaptureGetFrameSize_0007 + * @tc.desc Test CaptureGetFrameSize interface,return 0 if get framesize define sampleRate as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameSize_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 48000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = capture->attr.GetFrameSize(capture, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameCount API via legal input +* @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0001 +* @tc.desc test AudioCaptureGetFrameCount interface, return 0 if the FrameCount is called after creating the object. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(count, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameCount API via legal input in the difference scene +* @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0001 +* @tc.desc test AudioCaptureGetFrameCount interface, return 0 if the GetFrameCount is called after started. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameCount API via setting the parameter handle is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0003 +* @tc.desc test AudioCaptureGetFrameCount interface, return -1 if the parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameCount(captureNull, &count); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCaptureGetFrameCount API via setting the parameter handle is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0004 +* @tc.desc test AudioCaptureGetFrameCount interface, return -1 if the parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *countNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetFrameCount(capture, countNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameCount API via define channelCount to different value + * @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0005 + * @tc.desc Test CaptureGetFrameCount interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 8000; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 8000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameCount API via define format to different value + * @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0006 + * @tc.desc Test CaptureGetFrameCount interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 8000; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 8000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameCount API via define channelCount to different value + * @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0007 + * @tc.desc Test CaptureGetFrameCount interface,return 0 if get framesize define channelCount to different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 44100; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 44100); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetFrameCount API via define format to different value + * @tc.number SUB_Audio_hdi_CaptureGetFrameCount_0008 + * @tc.desc Test CaptureGetFrameCount interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_hdi_CaptureGetFrameCount_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 32000; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 32000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetCurrentChannelId API via legal input + * @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0001 + * @tc.desc Test GetCurrentChannelId, return 0 if the default CurrentChannelId is obtained successfully +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetCurrentChannelId_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdValue = CHANNELCOUNT; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetCurrentChannelId(capture, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdValue, channelId); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test GetCurrentChannelId API via getting channelId to 1 and set channelCount to 1 + * @tc.number SUB_Audio_HDI_CaptureGetCurrentChannelId_0002 + * @tc.desc Test GetCurrentChannelId interface,return 0 if get channelId to 1 and set channelCount to 1 +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetCurrentChannelId_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdExp = 1; + uint32_t channelCountExp = 1; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 48000); + + ret = AudioCaptureSetGetSampleAttributes(attrs, attrsValue, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = capture->attr.GetCurrentChannelId(capture, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdExp, channelId); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test GetCurrentChannelId API via CurrentChannelId is obtained after started + * @tc.number SUB_Audio_HDI_CaptureGetCurrentChannelId_0003 + * @tc.desc Test GetCurrentChannelId interface, return 0 if CurrentChannelId is obtained after started +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetCurrentChannelId_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdExp = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetCurrentChannelId(capture, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdExp, channelId); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test GetCurrentChannelId API via setting the parameter capture is nullptr + * @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0004 + * @tc.desc Test GetCurrentChannelId interface,return -1 if set the parameter capture is nullptr +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetCurrentChannelId_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetCurrentChannelId(captureNull, &channelId); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetCurrentChannelId API via setting the parameter channelId is nullptr + * @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0005 + * @tc.desc Test CaptureGetCurrentChannelId interface, return -1 if setting the parameter channelId is nullptr +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetCurrentChannelId_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t *channelIdNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.GetCurrentChannelId(capture, channelIdNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +#if defined (AUDIO_ADM_SERVICE) || defined (AUDIO_ADM_SO) || defined (__LITEOS__) +/** + * @tc.name Test CaptureSetExtraParams API via setting ExtraParams during playback + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0001 + * @tc.desc Test CaptureSetExtraParams interface,return 0 if the ExtraParams is set during playback +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000"; + char keyValueListExp[] = "attr-route=1;attr-format=32;attr-channels=2;attr-sampling-rate=48000"; + size_t index = 1; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + uint64_t FILESIZE = 1024; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_IN_MIC, + .path = AUDIO_CAPTURE_FILE.c_str(), .fileSize = FILESIZE + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)RecordAudio, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.capture != nullptr) { + ret = audiopara.capture->attr.SetExtraParams((AudioHandle)audiopara.capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.capture->attr.GetExtraParams((AudioHandle)audiopara.capture, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + string strGetValue = keyValueListValue; + size_t indexAttr = strGetValue.find("attr-frame-count"); + size_t indexFlag = strGetValue.rfind(";"); + if (indexAttr != string::npos && indexFlag != string::npos) { + strGetValue.replace(indexAttr, indexFlag - indexAttr + index, ""); + } + EXPECT_STREQ(keyValueListExp, strGetValue.c_str()); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting some parameters after playing + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0002 + * @tc.desc Test CaptureSetExtraParams interface,return 0 if some parameters is set after playing +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueListOne[] = "attr-frame-count=4096;"; + char keyValueListOneExp[] = "attr-route=0;attr-format=16;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListTwo[] = "attr-route=1;attr-frame-count=1024;"; + char keyValueListTwoExp[] = "attr-route=1;attr-format=16;attr-channels=2;attr-frame-count=1024;\ +attr-sampling-rate=48000"; + char keyValueListThr[] = "attr-route=0;attr-channels=1;attr-frame-count=4096;"; + char keyValueListThrExp[] = "attr-route=0;attr-format=16;attr-channels=1;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListFour[] = "attr-format=32;attr-channels=2;attr-frame-count=4096;attr-sampling-rate=48000"; + char keyValueListFourExp[] = "attr-route=0;attr-format=32;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListValueOne[256] = {}; + char keyValueListValueTwo[256] = {}; + char keyValueListValueThr[256] = {}; + char keyValueListValueFour[256] = {}; + int32_t listLenth = 256; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueListOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValueOne, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListOneExp, keyValueListValueOne); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueListTwo); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValueTwo, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListTwoExp, keyValueListValueTwo); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueListThr); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValueThr, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListThrExp, keyValueListValueThr); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueListFour); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValueFour, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListFourExp, keyValueListValueFour); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting keyvaluelist to a value outside the range + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0003 + * @tc.desc Test CaptureSetExtraParams interface,return -1 if the Keyvaluelist is a value out of range +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueList[] = "attr-para=abc;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via adding parameters to keyvaluelist + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0004 + * @tc.desc Test CaptureSetExtraParams interface,return -1 if adding parameters to keyvaluelist +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000;\ +attr-para=abc"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting ExtraParams When the key is the same and the value is + different + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0005 + * @tc.desc Test CaptureSetExtraParams interface,return 0 if set ExtraParams When the key is the same and the value + is different +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-frame-count=4096;"; + char keyValueListExp[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListExp, keyValueListValue); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting the parameter in keyvaluelist as an abnormal value + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0006 + * @tc.desc Test CaptureSetExtraParams interface,return -1 if set the parameter in keyvaluelist as an abnormal value +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char attrSamplingRateError[] = "attr-sampling-rate=1234567;"; + char attrChannelsError[] = "attr-channels=3;"; + char attrFrameCountError[] = "attr-frame-count=111111111111111111111;"; + char attrRouteError[] = "attr-route=5;"; + char attrFormateError[] = "attr-formate=12;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, attrSamplingRateError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, attrChannelsError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, attrFrameCountError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, attrRouteError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, attrFormateError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting the parameter render is nullptr + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0007 + * @tc.desc Test CaptureSetExtraParams interface,return -1 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + char keyValueList[] = "attr-format=2;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)captureNull, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureSetExtraParams API via setting the format of ExtraParams is nullptr + * @tc.number SUB_Audio_HDI_CaptureSetExtraParams_0008 + * @tc.desc Test CaptureSetExtraParams interface,return -1 if set the format of ExtraParams is nullptr +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureSetExtraParams_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueListNull[] = "attr-format=;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueListNull); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetExtraParams API via legal input + * @tc.number SUB_Audio_HDI_CaptureGetExtraParams_0001 + * @tc.desc Test CaptureGetExtraParams interface,return 0 if the RenderGetExtraParams was obtained successfully +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetExtraParams_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrsValue = {}; + char keyValueList[] = "attr-format=24;attr-frame-count=4096;"; + char keyValueListExp[] = "attr-route=0;attr-format=24;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + int32_t formatExp = 3; + uint32_t sampleRateExp = 48000; + uint32_t channelCountExp = 2; + uint32_t frameCountExp = 4096; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListExp, keyValueListValue); + + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(formatExp, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = capture->attr.GetFrameCount(capture, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(count, frameCountExp); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetExtraParams API via setting the parameter render is nullptr + * @tc.number SUB_Audio_HDI_CaptureGetExtraParams_0002 + * @tc.desc Test CaptureGetExtraParams interface,return 0 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetExtraParams_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + char keyValueList[] = "attr-format=32;"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)captureNull, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetExtraParams API via setting listlength to be less than the actual length + * @tc.number SUB_Audio_HDI_CaptureGetExtraParams_0003 + * @tc.desc Test CaptureGetExtraParams interface,return 0 if set listlength to be less than the actual length +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetExtraParams_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000;"; + char keyValueListValue[256] = {}; + int32_t listLenth = 8; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** + * @tc.name Test CaptureGetExtraParams API via setting listlenth equal to the actual length + * @tc.number SUB_Audio_HDI_CaptureGetExtraParams_0004 + * @tc.desc Test CaptureGetExtraParams interface,return 0 if set listlenth equal to the actual length +*/ +HWTEST_F(AudioHdiCaptureAttrTest, SUB_Audio_HDI_CaptureGetExtraParams_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=11111111111111111111;\ +attr-sampling-rate=48000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 107; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.SetExtraParams((AudioHandle)capture, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetExtraParams((AudioHandle)capture, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueList, keyValueListValue); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +#endif +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/src/audio_hdicapture_control_test.cpp b/hdf/audio/hdi/capture/src/audio_hdicapture_control_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..17a9cc7a60262579f59afc729f6fb5a20a2aa235 --- /dev/null +++ b/hdf/audio/hdi/capture/src/audio_hdicapture_control_test.cpp @@ -0,0 +1,1019 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for capture drivers function. + * accessing a driver adapter, and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the capturing audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdicapture_control_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_HDMI = "hdmi"; +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiCaptureControlTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +TestAudioManager *(*AudioHdiCaptureControlTest::GetAudioManager)() = nullptr; +void *AudioHdiCaptureControlTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiCaptureControlTest::SdkInit)() = nullptr; + void (*AudioHdiCaptureControlTest::SdkExit)() = nullptr; + void *AudioHdiCaptureControlTest::sdkSo = nullptr; +#endif + +void AudioHdiCaptureControlTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiCaptureControlTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiCaptureControlTest::SetUp(void) {} + +void AudioHdiCaptureControlTest::TearDown(void) {} + +/** +* @tc.name Test AudioCreateCapture API via legal input +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0001 +* @tc.desc Test AudioCreateCapture interface,Returns 0 if the AudioCapture object is created successfully +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via creating a capture object when a render object was created +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0002 +* @tc.desc test AudioCreateCapture interface: + (1)service mode:Returns 0,if the AudioCapture object can be created successfully which was created + (2)passthrough mode: Returns -1,if the AudioCapture object can't be created which was created +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortDirection portType = PORT_OUT_IN; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *firstCapture = nullptr; + struct AudioCapture *secondCapture = nullptr; + struct AudioPort* audioPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor DevDesc = {}; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + InitDevDesc(DevDesc, audioPort->portId, PIN_IN_MIC); + ret = adapter->CreateCapture(adapter, &DevDesc, &attrs, &firstCapture); + if (ret < 0) { + manager->UnloadAdapter(manager, adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + ret = adapter->CreateCapture(adapter, &DevDesc, &attrs, &secondCapture); +#if defined (AUDIO_ADM_SERVICE) || defined (AUDIO_MPI_SERVICE) + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, secondCapture); +#endif +#if defined (AUDIO_ADM_SO) || defined (AUDIO_MPI_SO) || defined (__LITEOS__) + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + adapter->DestroyCapture(adapter, firstCapture); +#endif + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via creating a capture object when a render object was created +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0003 +* @tc.desc test AudioCreateCapture interface,Returns 0 if the AudioCapture object can be created successfully + when AudioRender was created +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortDirection portType = PORT_OUT_IN; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioPort* audioPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor renderDevDesc = {}; + struct AudioDeviceDescriptor captureDevDesc = {}; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, audioPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + InitDevDesc(renderDevDesc, audioPort->portId, PIN_OUT_SPEAKER); + InitDevDesc(captureDevDesc, audioPort->portId, PIN_IN_MIC); + ret = adapter->CreateRender(adapter, &renderDevDesc, &attrs, &render); + if (ret < 0) { + manager->UnloadAdapter(manager, adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + ret = adapter->CreateCapture(adapter, &captureDevDesc, &attrs, &capture); + if (ret < 0) { + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + adapter->DestroyRender(adapter, render); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via creating two capture objects +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0004 +* @tc.desc Test AudioCreateCapture interface,return 0 if the the two audiocapture objects are created successfully +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapterFirst = nullptr; + struct AudioAdapter *adapterSecond = nullptr; + struct AudioCapture *captureFirst = nullptr; + struct AudioCapture *captureSecond = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapterFirst, &captureFirst); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_INTERNAL, &adapterSecond, &captureSecond); + if (ret < 0) { + adapterFirst->DestroyCapture(adapterFirst, captureFirst); + manager->UnloadAdapter(manager, adapterFirst); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + adapterFirst->DestroyCapture(adapterFirst, captureFirst); + adapterSecond->DestroyCapture(adapterSecond, captureSecond); + manager->UnloadAdapter(manager, adapterFirst); + manager->UnloadAdapter(manager, adapterSecond); +} +/** +* @tc.name Test AudioCreateCapture API via setting the incoming parameter adapter is nullptr +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0005 +* @tc.desc Test AudioCreateCapture interface,Returns -1 if the incoming parameter adapter is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioSampleAttributes attrs = {}; + enum AudioPortDirection portType = PORT_IN; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + struct AudioCapture *capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitAttrs(attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitDevDesc(devDesc, capturePort->portId, pins); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->CreateCapture(adapterNull, &devDesc, &attrs, &capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via setting the incoming parameter desc is nullptr +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0006 +* @tc.desc Test AudioCreateCapture interface,Returns -1 if the incoming parameter desc is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + struct AudioSampleAttributes attrs = {}; + enum AudioPortDirection portType = PORT_IN; + struct AudioDeviceDescriptor *devDesc = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitAttrs(attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->CreateCapture(adapter, devDesc, &attrs, &capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via setting the incoming parameter attrs is nullptr +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0007 +* @tc.desc Test AudioCreateCapture interface,Returns -1 if the incoming parameter attrs is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + struct AudioDeviceDescriptor devDesc = {}; + enum AudioPortDirection portType = PORT_IN; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioSampleAttributes *attrs = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitDevDesc(devDesc, capturePort->portId, pins); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->CreateCapture(adapter, &devDesc, attrs, &capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via setting the incoming parameter capture is nullptr +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0008 +* @tc.desc Test AudioCreateCapture interface,Returns -1 if the incoming parameter capture is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioSampleAttributes attrs = {}; + enum AudioPortDirection portType = PORT_IN; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture **capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitAttrs(attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitDevDesc(devDesc, capturePort->portId, pins); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->CreateCapture(adapter, &devDesc, &attrs, capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateCapture API via setting the incoming parameter adapter which port type is PORT_OUT +* @tc.number SUB_Audio_HDI_AudioCreateCapture_0008 +* @tc.desc Test AudioCreateCapture interface,Returns -1 if the incoming parameter adapter which port type is PORT_OUT +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioCreateCapture_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioSampleAttributes attrs = {}; + enum AudioPortDirection portType = PORT_OUT; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_HDMI, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitAttrs(attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitDevDesc(devDesc, capturePort->portId, pins); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->CreateCapture(adapter, &devDesc, &attrs, &capture); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioDestroyCapture API via legal input +* @tc.number SUB_Audio_HDI_AudioDestroyCapture_0001 +* @tc.desc Test AudioDestroyCapture interface,Returns 0 if the AudioCapture object is destroyed +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioDestroyCapture_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->DestroyCapture(adapter, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioDestroyCapture API via setting the incoming parameter adapter is nullptr +* @tc.number SUB_Audio_HDI_AudioDestroyCapture_0002 +* @tc.desc Test AudioDestroyCapture interface,Returns -1 if the incoming parameter adapter is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioDestroyCapture_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapterNull = nullptr; + struct AudioCapture *capture = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->DestroyCapture(adapterNull, capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = adapter->DestroyCapture(adapter, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioDestroyCapture API via setting the incoming parameter capture is nullptr +* @tc.number SUB_Audio_HDI_AudioDestroyCapture_0003 +* @tc.desc Test AudioDestroyCapture interface,Returns -1 if the incoming parameter capture is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_AudioDestroyCapture_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* capturePort = nullptr; + enum AudioPortDirection portType = PORT_IN; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, portType, ADAPTER_NAME_USB, &adapter, capturePort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = adapter->DestroyCapture(adapter, capture); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStart API via legal input +* @tc.number SUB_Audio_HDI_StartCapture_0001 +* @tc.desc Test AudioCaptureStart interface,return 0 if the audiocapture object is started successfully +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStart_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureStart API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_CaptureStart_0002 +* @tc.desc Test CaptureStart interface,return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStart_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)captureNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStart API via start two capture object continuously +* @tc.number SUB_Audio_HDI_CaptureStart_0003 +* @tc.desc Test AudioCaptureStart interface,return 0 if the Audiocapturestart was successfully called twice +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStart_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_AI_BUSY, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStop API via legal input +* @tc.number SUB_Audio_HDI_CaptureStop_0001 +* @tc.desc Test AudioCaptureStop interface,return 0 if the audiocapture object is stopped successfully +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStop_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStop API via stop two capture object continuously +* @tc.number SUB_Audio_HDI_CaptureStop_0002 +* @tc.desc Test AudioCaptureStop interface,return -4 if Audiocapturestop was successfully called twice +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStop_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStop API via start an audio capture after stopping +* @tc.number SUB_Audio_HDI_CaptureStop_0003 +* @tc.desc Test AudioCaptureStop interface,return 0 if stop and start an audio capture successfully +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStop_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureStop API via the capture does not start and stop only +* @tc.number SUB_Audio_HDI_CaptureStop_0004 +* @tc.desc Test AudioCaptureStop interface,return -4 if the capture does not start and stop only +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStop_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureStop API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_CaptureStop_0005 +* @tc.desc Test CaptureStop interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureStop_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)captureNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CapturePause API via legal input +* @tc.number SUB_Audio_HDI_CapturePause_0001 +* @tc.desc test HDI CapturePause interface,return 0 if the capture is paused after start +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CapturePause_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CapturePause API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_CapturePause_0002 +* @tc.desc Test CapturePause interface, return -1 the second time if CapturePause is called twice +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CapturePause_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CapturePause API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_CapturePause_0003 +* @tc.desc Test CapturePause interface,return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CapturePause_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)captureNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CapturePause API via the capture is not Started and paused only. +* @tc.number SUB_Audio_HDI_CapturePause_0004 +* @tc.desc Test AudioRenderPause interface,return -1 if the capture is not Started and paused only. +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CapturePause_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CapturePause API via the capture is paused after stoped. +* @tc.number SUB_Audio_HDI_CapturePause_0005 +* @tc.desc Test CapturePause interface, return -1 the capture is paused after stoped. +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CapturePause_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureResume API via legal input +* @tc.number SUB_Audio_HDI_CaptureResume_0001 +* @tc.desc Test CaptureResume interface,return 0 if the capture is resumed after paused +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureResume API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_CaptureResume_0002 +* @tc.desc Test CaptureResume interface,return -1 the second time if the CaptureResume is called twice +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test CaptureResume API via the capture is resumed after started +* @tc.number SUB_Audio_HDI_CaptureResume_0003 +* @tc.desc test HDI CaptureResume interface,return -1 if the capture is resumed after started +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureResume API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_CaptureResume_0004 +* @tc.desc Test CaptureResume interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)captureNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureResume API via the capture is resumed after stopped +* @tc.number SUB_Audio_HDI_CaptureResume_0005 +* @tc.desc test HDI CaptureResume interface,return -1 if the capture is resumed after stopped +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureResume API via the capture Continue to start after resume +* @tc.number SUB_Audio_HDI_CaptureResume_0006 +* @tc.desc test HDI CaptureResume interface,return -1 if the capture Continue to start after resume +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Pause((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Resume((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_ERR_AI_BUSY, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via the different capture objects is started、paused、resumed and stopped. +* @tc.number SUB_Audio_HDI_CaptureResume_0007 +* @tc.desc test HDI CaptureResume interface,return 0 if the different objects is started、paused、resumed and stopped. +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureResume_0007, Function | MediumTest | Level1) +{ + int32_t ret1 = -1; + int32_t ret2 = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapterOne = nullptr; + struct AudioAdapter *adapterSec = nullptr; + struct AudioCapture *captureOne = nullptr; + struct AudioCapture *captureSec = nullptr; + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret1 = AudioCreateStartCapture(manager, &captureOne, &adapterOne, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret1); + ret1 = captureOne->control.Pause((AudioHandle)captureOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret1); + ret1 = captureOne->control.Resume((AudioHandle)captureOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret1); + ret1 = captureOne->control.Stop((AudioHandle)captureOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret1); + adapterOne->DestroyCapture(adapterOne, captureOne); + manager->UnloadAdapter(manager, adapterOne); + ret2 = AudioCreateStartCapture(manager, &captureSec, &adapterSec, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret2); + ret2 = captureSec->control.Pause((AudioHandle)captureSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret2); + ret2 = captureSec->control.Resume((AudioHandle)captureSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret2); + ret2 = captureSec->control.Stop((AudioHandle)captureSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret2); + adapterSec->DestroyCapture(adapterSec, captureSec); + manager->UnloadAdapter(manager, adapterSec); +} +/** + * @tc.name Test CaptureFlush API via legal input Verify that the data in the buffer is flushed after stop + * @tc.number SUB_Audio_HDI_CaptureFlush_0001 + * @tc.desc Test CaptureFlush interface,return -2 if the data in the buffer is flushed successfully after stop +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureFlush_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Flush((AudioHandle)capture); + EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test CaptureFlush that the data in the buffer is flushed when handle is nullptr +* @tc.number SUB_Audio_HDI_CaptureFlush_0002 +* @tc.desc Test CaptureFlush, return -1 if the data in the buffer is flushed when handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureControlTest, SUB_Audio_HDI_CaptureFlush_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Flush((AudioHandle)captureNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/src/audio_hdicapture_scene_test.cpp b/hdf/audio/hdi/capture/src/audio_hdicapture_scene_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f0eec59283138251cf99c492eff9c39be1ca3b27 --- /dev/null +++ b/hdf/audio/hdi/capture/src/audio_hdicapture_scene_test.cpp @@ -0,0 +1,398 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for capture drivers function. + * accessing a driver adapter, and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the capturing audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdicapture_scene_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_HDMI = "hdmi"; +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiCaptureSceneTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif + int32_t AudioCaptureStart(const string path, struct AudioCapture *capture) const; +}; + +TestAudioManager *(*AudioHdiCaptureSceneTest::GetAudioManager)() = nullptr; +void *AudioHdiCaptureSceneTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiCaptureSceneTest::SdkInit)() = nullptr; + void (*AudioHdiCaptureSceneTest::SdkExit)() = nullptr; + void *AudioHdiCaptureSceneTest::sdkSo = nullptr; +#endif + +void AudioHdiCaptureSceneTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiCaptureSceneTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} +int32_t AudioHdiCaptureSceneTest::AudioCaptureStart(const string path, struct AudioCapture *capture) const +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + + ret = InitAttrs(attrs); + if (ret < 0) { + return ret; + } + FILE *file = fopen(path.c_str(), "wb+"); + if (file == nullptr) { + return HDF_FAILURE; + } + ret = FrameStartCapture(capture, file, attrs); + (void)fclose(file); + return ret; +} +void AudioHdiCaptureSceneTest::SetUp(void) {} +void AudioHdiCaptureSceneTest::TearDown(void) {} + +/** +* @tc.name Test AudioCaptureCheckSceneCapability API and check scene's capability +* @tc.number SUB_Audio_HDI_CaptureCheckSceneCapability_0001 +* @tc.desc Test AudioCaptureCheckSceneCapability interface,return 0 if check scene's capability successful. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_CaptureCheckSceneCapability_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = false; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.CheckSceneCapability(capture, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_TRUE(supported); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the scene is not configured in the json. +* @tc.number SUB_Audio_HDI_CaptureCheckSceneCapability_0002 +* @tc.desc Test AudioCreateCapture interface,return -1 if the scene is not configured in the json. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_CaptureCheckSceneCapability_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + scenes.scene.id = 5; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.CheckSceneCapability(capture, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the capture is empty +* @tc.number SUB_Audio_HDI_CaptureCheckSceneCapability_0003 +* @tc.desc Test AudioCreateCapture interface,return -1 if the capture is empty. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_CaptureCheckSceneCapability_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.CheckSceneCapability(captureNull, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the scene is empty +* @tc.number SUB_Audio_HDI_CaptureCheckSceneCapability_0004 +* @tc.desc Test AudioCreateCapture interface,return -1 if the scene is empty. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_CaptureCheckSceneCapability_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor *scenes = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->scene.CheckSceneCapability(capture, scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the parameter supported is empty. +* @tc.number SUB_Audio_HDI_CaptureCheckSceneCapability_0005 +* @tc.desc Test AudioCreateCapture interface,return -1 if the parameter supported is empty. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_CaptureCheckSceneCapability_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.CheckSceneCapability(capture, &scenes, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSelectScene API via legal input +* @tc.number SUB_Audio_HDI_AudioCaptureSelectScene_0001 +* @tc.desc Test AudioCaptureSelectScene interface,return 0 if select capture's scene successful. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_AudioCaptureSelectScene_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.SelectScene(capture, &scenes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSelectScene API after capture start. +* @tc.number SUB_Audio_HDI_AudioCaptureSelectScene_0002 +* @tc.desc Test AudioCaptureSelectScene, return 0 if select capture's scene successful after capture start. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_AudioCaptureSelectScene_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.SelectScene(capture, &scenes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSelectScene API where the parameter handle is empty. +* @tc.number SUB_Audio_HDI_AudioCaptureSelectScene_0003 +* @tc.desc Test AudioCaptureSelectScene, return -1 if the parameter handle is empty. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_AudioCaptureSelectScene_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = capture->scene.SelectScene(captureNull, &scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSelectScene API where the parameter scene is empty. +* @tc.number SUB_Audio_HDI_AudioCaptureSelectScene_0004 +* @tc.desc Test AudioCaptureSelectScene, return -1 if the parameter scene is empty. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_AudioCaptureSelectScene_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor *scenes = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->scene.SelectScene(capture, scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSelectScene API where the scene is not configured in the json. +* @tc.number SUB_Audio_HDI_AudioCaptureSelectScene_0005 +* @tc.desc Test AudioCaptureSelectScene, return -1 if the scene is not configured in the json. +*/ +HWTEST_F(AudioHdiCaptureSceneTest, SUB_Audio_HDI_AudioCaptureSelectScene_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 5; + scenes.desc.pins = PIN_OUT_HDMI; + ret = capture->scene.SelectScene(capture, &scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/src/audio_hdicapture_test.cpp b/hdf/audio/hdi/capture/src/audio_hdicapture_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6ea039bc3157cab02cf1c59ec92da0900b2f6214 --- /dev/null +++ b/hdf/audio/hdi/capture/src/audio_hdicapture_test.cpp @@ -0,0 +1,1232 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for capture drivers function. + * accessing a driver adapter, and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the capturing audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdicapture_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_HDMI = "hdmi"; +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; +const int BUFFER_SIZE = 16384; +const int BUFFER_SIZE_LITTLE = 0; +const uint64_t FILESIZE = 1024; + +class AudioHdiCaptureTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif + + static int32_t GetLoadAdapterAudioPara(struct PrepareAudioPara& audiopara); +}; + +using THREAD_FUNC = void *(*)(void *); + +TestAudioManager *(*AudioHdiCaptureTest::GetAudioManager)() = nullptr; +void *AudioHdiCaptureTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiCaptureTest::SdkInit)() = nullptr; + void (*AudioHdiCaptureTest::SdkExit)() = nullptr; + void *AudioHdiCaptureTest::sdkSo = nullptr; +#endif + +void AudioHdiCaptureTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiCaptureTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + + +void AudioHdiCaptureTest::SetUp(void) {} + +void AudioHdiCaptureTest::TearDown(void) {} + + +int32_t AudioHdiCaptureTest::GetLoadAdapterAudioPara(struct PrepareAudioPara& audiopara) +{ + int32_t ret = -1; + int size = 0; + auto *inst = (AudioHdiCaptureTest *)audiopara.self; + if (inst != nullptr && inst->GetAudioManager != nullptr) { + audiopara.manager = inst->GetAudioManager(); + } + if (audiopara.manager == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + ret = audiopara.manager->GetAllAdapters(audiopara.manager, &audiopara.descs, &size); + if (ret < 0) { + return ret; + } + if (audiopara.descs == nullptr || size == 0) { + return AUDIO_HAL_ERR_INTERNAL; + } + int index = SwitchAdapter(audiopara.descs, audiopara.adapterName, + audiopara.portType, audiopara.audioPort, size); + if (index < 0) { + return AUDIO_HAL_ERR_INTERNAL; + } else { + audiopara.desc = &audiopara.descs[index]; + } + if (audiopara.desc == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } else { + ret = audiopara.manager->LoadAdapter(audiopara.manager, audiopara.desc, &audiopara.adapter); + } + if (ret < 0) { + return ret; + } + if (audiopara.adapter == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + + +/** +* @tc.name Test AudioCaptureCaptureFrame API via legal input +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0001 +* @tc.desc test AudioCaptureCaptureFrame interface,Returns 0 if the input data is read successfully +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t replyBytes = 0; + uint64_t requestBytes = BUFFER_SIZE; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + char *frame = (char *)calloc(1, BUFFER_SIZE); + EXPECT_NE(nullptr, frame); + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioCaptureCaptureFrame API via setting the incoming parameter frame is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0002 +* @tc.desc test AudioCaptureCaptureFrame interface,Returns -1 if the incoming parameter frame is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t replyBytes = 0; + uint64_t requestBytes = BUFFER_SIZE; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + char *frame = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureCaptureFrame API via setting the incoming parameter replyBytes is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0003 +* @tc.desc test AudioCaptureCaptureFrame interface,Returns -1 if the incoming parameter replyBytes is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = BUFFER_SIZE; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + uint64_t *replyBytes = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + char *frame = (char *)calloc(1, BUFFER_SIZE); + EXPECT_NE(nullptr, frame); + ret = capture->CaptureFrame(capture, frame, requestBytes, replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioCaptureCaptureFrame API via setting the incoming parameter capture is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0004 +* @tc.desc test AudioCaptureCaptureFrame interface,Returns -1 if the incoming parameter capture is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = BUFFER_SIZE; + uint64_t replyBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + char *frame = (char *)calloc(1, BUFFER_SIZE); + EXPECT_NE(nullptr, frame); + ret = capture->CaptureFrame(captureNull, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioCaptureFrame API without calling interface capturestart +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0005 +* @tc.desc Test AudioCaptureFrame interface,Returns -1 if without calling interface capturestart +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = BUFFER_SIZE; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + uint64_t replyBytes = 0; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + char *frame = (char *)calloc(1, BUFFER_SIZE); + EXPECT_NE(nullptr, frame); + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioCaptureCaptureFrame API via setting the incoming parameter requestBytes +less than interface requirements +* @tc.number SUB_Audio_HDI_AudioCaptureFrame_0006 +* @tc.desc test AudioCaptureCaptureFrame interface,Returns -1 if the incoming parameter +requestBytes less than interface requirements +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureFrame_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = BUFFER_SIZE_LITTLE; + uint64_t replyBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + char *frame = (char *)calloc(1, BUFFER_SIZE); + EXPECT_NE(nullptr, frame); + ret = capture->CaptureFrame(capture, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioCaptureGetCapturePosition API via legal input +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0001 +* @tc.desc Test AudioCaptureGetCapturePosition interface,Returns 0 if get CapturePosition during playing. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_IN_MIC, + .path = AUDIO_CAPTURE_FILE.c_str(), .fileSize = FILESIZE + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)RecordAudio, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.capture != nullptr) { + ret = audiopara.capture->GetCapturePosition(audiopara.capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test GetCapturePosition API via get CapturePosition after the audiois Paused and resumed +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0002 +* @tc.desc Test GetCapturePosition interface,Returns 0 if get Position after Pause and resume during playing +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int64_t timeExp = 0; + uint64_t frames = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_IN_MIC, + .path = AUDIO_CAPTURE_FILE.c_str(), .fileSize = FILESIZE + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)RecordAudio, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.capture != nullptr) { + ret = audiopara.capture->control.Pause((AudioHandle)(audiopara.capture)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.capture->GetCapturePosition(audiopara.capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + ret = audiopara.capture->control.Resume((AudioHandle)(audiopara.capture)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.capture->GetCapturePosition(audiopara.capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test GetCapturePosition API via get CapturePosition after the audio file is stopped +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0003 +* @tc.desc Test GetCapturePosition interface,Returns 0 if get CapturePosition after stop during playing +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + uint64_t frames = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + int64_t timeExp = 0; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via get CapturePosition after the object is created +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0004 +* @tc.desc Test GetCapturePosition interface, return 0 if get CapturePosition after the object is created +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_IN_MIC; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + uint64_t frames = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + int64_t timeExp = 0; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, pins, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via setting the parameter Capture is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0005 +* @tc.desc Test GetCapturePosition interface, return -1 if setting the parameter Capture is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + uint64_t frames = 0; + struct AudioTimeStamp time = {}; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(captureNull, &frames, &time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via setting the parameter frames is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0006 +* @tc.desc Test GetCapturePosition interface, return -1 if setting the parameter frames is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + uint64_t *framesNull = nullptr; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, framesNull, &time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via setting the parameter time is nullptr +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0007 +* @tc.desc Test GetCapturePosition interface, return -1 if setting the parameter time is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + uint64_t frames = 0; + struct AudioTimeStamp *timeNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, timeNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via get CapturePosition continuously +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0008 +* @tc.desc Test GetCapturePosition interface, return 0 if the GetCapturePosition was called twice +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = {}; + struct AudioCapture *capture = nullptr; + uint64_t frames = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + struct AudioTimeStamp timeSec = {.tvSec = 0, .tvNSec = 0}; + int64_t timeExp = 0; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartCapture(manager, &capture, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + ret = capture->GetCapturePosition(capture, &frames, &timeSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via define format to AUDIO_FORMAT_PCM_16_BIT +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0009 +* @tc.desc Test GetCapturePosition interface,return 0 if get framesize define format to AUDIO_FORMAT_PCM_16_BIT +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 2; + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via define format to AUDIO_FORMAT_PCM_24_BIT +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0010 +* @tc.desc Test GetCapturePosition interface,return 0 if get framesize define format to AUDIO_FORMAT_PCM_24_BIT +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0010, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_24_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 2; + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via define sampleRate and channelCount to different value +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0011 +* @tc.desc Test GetCapturePosition interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0011, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 1; + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCapturePosition API via define sampleRate and channelCount to 1 +* @tc.number SUB_Audio_HDI_AudioCaptureGetCapturePosition_0012 +* @tc.desc Test GetCapturePosition interface,return 0 if get framesize define channelCount to 1 +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_AudioCaptureGetCapturePosition_0012, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_24_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 1; + ret = capture->attr.SetSampleAttributes(capture, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.GetSampleAttributes(capture, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + + ret = AudioCaptureStartAndOneFrame(capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->GetCapturePosition(capture, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via legal input +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0001 +* @tc.desc Test ReqMmapBuffer interface,return 0 if call ReqMmapBuffer interface successfully +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + (void)fclose(fp); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is bigger than + the size of actual audio file +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0002 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsuccessful when setting the + incoming parameter reqSize is bigger than the size of actual audio file +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = reqSize + BUFFER_LENTH; + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + (void)fclose(fp); + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is smaller than + the size of actual audio file +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0003 +* @tc.desc Test ReqMmapBuffer interface,return 0 if call ReqMmapBuffer interface successfully when setting the + incoming parameter reqSize is smaller than the size of actual audio file +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = reqSize / 2; + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + (void)fclose(fp); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is zero +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0004 +* @tc.desc Test ReqMmapBuffer interface,return -1 if call ReqMmapBuffer interface unsuccessful when setting the + incoming parameter reqSize is zero +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = 0; + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + (void)fclose(fp); + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter memoryFd of desc is illegal +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0005 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsuccessful when setting the + incoming parameter memoryFd of desc is illegal +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + desc.memoryFd = 1; + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + (void)fclose(fp); + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0006 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsuccessful when setting the + incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = false; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + FILE *fp = fopen(AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str(), "wb+"); + ASSERT_NE(nullptr, fp); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + (void)fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)captureNull, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + (void)fclose(fp); + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via the incoming parameter desc is nullptr +* @tc.number SUB_Audio_HDI_CaptureReqMmapBuffer_0007 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsuccessful when setting the + incoming parameter desc is nullptr +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureReqMmapBuffer_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t reqSize = 0; + struct AudioMmapBufferDescripter *descNull = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_USB, &adapter, &capture); + if (ret < 0 || capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, capture); + } + reqSize = FILE_CAPTURE_SIZE; + ret = capture->control.Start((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->attr.ReqMmapBuffer((AudioHandle)capture, reqSize, descNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test GetMmapPosition API via Getting position is normal in Before recording , recording and after recording +* @tc.number SUB_Audio_HDI_CaptureGetMmapPosition_0001 +* @tc.desc Test GetMmapPosition interface,return 0 if Getting position successfully. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureGetMmapPosition_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + uint64_t framesCapturing = 0; + uint64_t framesExpCapture = 0; + int64_t timeExp = 0; + int64_t timeExpCaptureing = 0; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .pins = PIN_IN_MIC, + .path = AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0 || audiopara.capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.capture); + } + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_EQ(frames, INITIAL_VALUE); + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)RecordMapAudio, &audiopara); + if (ret != 0) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + sleep(1); + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, &framesCapturing, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_GT(framesCapturing, INITIAL_VALUE); + timeExpCaptureing = (audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec); + void *result = nullptr; + pthread_join(audiopara.tids, &result); + EXPECT_EQ(AUDIO_HAL_SUCCESS, (intptr_t)result); + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, &framesExpCapture, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExpCaptureing); + EXPECT_GT(framesExpCapture, framesCapturing); + + audiopara.capture->control.Stop((AudioHandle)audiopara.capture); + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test GetMmapPosition API via SetSampleAttributes and Getting position is normal. +* @tc.number SUB_Audio_HDI_CaptureGetMmapPosition_0002 +* @tc.desc Test GetMmapPosition interface,return 0 if Getting position successfully. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureGetMmapPosition_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .pins = PIN_IN_MIC, + .path = AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0 || audiopara.capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.capture); + } + InitAttrs(audiopara.attrs); + audiopara.attrs.format = AUDIO_FORMAT_PCM_24_BIT; + audiopara.attrs.channelCount = 1; + ret = audiopara.capture->attr.SetSampleAttributes(audiopara.capture, &(audiopara.attrs)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)RecordMapAudio, &audiopara); + if (ret != 0) { + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + + void *result = nullptr; + pthread_join(audiopara.tids, &result); + EXPECT_EQ(AUDIO_HAL_SUCCESS, (intptr_t)result); + + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + audiopara.capture->control.Stop((AudioHandle)audiopara.capture); + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint frames is nullptr. +* @tc.number SUB_Audio_HDI_CaptureGetMmapPosition_0003 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureGetMmapPosition_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *frames = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .pins = PIN_IN_MIC, + .path = AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0 || audiopara.capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.capture); + } + + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint time is nullptr. +* @tc.number SUB_Audio_HDI_CaptureGetMmapPosition_0004 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureGetMmapPosition_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + struct AudioTimeStamp *time = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .pins = PIN_IN_MIC, + .path = AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0 || audiopara.capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.capture); + } + + ret = audiopara.capture->attr.GetMmapPosition(audiopara.capture, &frames, time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint capture is nullptr. +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0005 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiCaptureTest, SUB_Audio_HDI_CaptureGetMmapPosition_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + struct AudioCapture *captureNull = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_IN, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_IN_MIC, + .path = AUDIO_LOW_LATENCY_CAPTURE_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + ret = AudioCreateCapture(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.capture); + if (ret < 0 || audiopara.capture == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.capture); + } + + ret = audiopara.capture->attr.GetMmapPosition(captureNull, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyCapture(audiopara.adapter, audiopara.capture); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/capture/src/audio_hdicapture_volume_test.cpp b/hdf/audio/hdi/capture/src/audio_hdicapture_volume_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5c2e0f0bb7da10fc915892ef253c2b5d7e8c0f49 --- /dev/null +++ b/hdf/audio/hdi/capture/src/audio_hdicapture_volume_test.cpp @@ -0,0 +1,779 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for capture drivers funtion. + * accessing a driver adapter, and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the capturing audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdicapture_volume_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_HDMI = "hdmi"; +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiCaptureVolumeTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif + int32_t AudioCaptureStart(const string path, struct AudioCapture *capture) const; +}; + +TestAudioManager *(*AudioHdiCaptureVolumeTest::GetAudioManager)() = nullptr; +void *AudioHdiCaptureVolumeTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiCaptureVolumeTest::SdkInit)() = nullptr; + void (*AudioHdiCaptureVolumeTest::SdkExit)() = nullptr; + void *AudioHdiCaptureVolumeTest::sdkSo = nullptr; +#endif + +void AudioHdiCaptureVolumeTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiCaptureVolumeTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiCaptureVolumeTest::SetUp(void) {} +void AudioHdiCaptureVolumeTest::TearDown(void) {} + +int32_t AudioHdiCaptureVolumeTest::AudioCaptureStart(const string path, struct AudioCapture *capture) const +{ + int32_t ret = -1; + struct AudioSampleAttributes attrs = {}; + if (capture == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + InitAttrs(attrs); + FILE *file = fopen(path.c_str(), "wb+"); + if (file == nullptr) { + return HDF_FAILURE; + } + ret = FrameStartCapture(capture, file, attrs); + (void)fclose(file); + return ret; +} + +/** +* @tc.name Test AudioCaptureSetMute API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetMute_0001 +* @tc.desc Test AudioCaptureSetMute interface , return 0 if the audiocapture object sets mute successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetMute_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteTrue = true; + bool muteFalse = false; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetMute(capture, muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetMute(capture, &muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_TRUE(muteTrue); + + ret = capture->volume.SetMute(capture, muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetMute(capture, &muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_FALSE(muteFalse); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetMute API via setting the capture is empty . +* @tc.number SUB_Audio_HDI_AudioCaptureSetMute_0002 +* @tc.desc Test AudioCaptureSetMute interface, return -1 if the capture is empty. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetMute_0002, Function | MediumTest | Level1) +{ + bool muteTrue = true; + bool muteFalse = false; + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.SetMute(captureNull, muteTrue); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->volume.SetMute(captureNull, muteFalse); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetMute API,when the parameter mutevalue equals 2. +* @tc.number SUB_Audio_HDI_AudioCaptureSetMute_0003 +* @tc.desc Test AudioCaptureSetMute interface and set the parameter mutevalue with 2. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetMute_0003, Function | MediumTest | Level1) +{ + bool muteValue = 2; + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetMute(capture, muteValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetMute(capture, &muteValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_TRUE(muteValue); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetMute API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureGetMute_0001 +* @tc.desc Test AudioCaptureGetMute interface , return 0 if the audiocapture gets mute successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureGetMute_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteTrue = true; + bool muteFalse = false; + bool defaultmute = true; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetMute(capture, &muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(muteTrue, defaultmute); + + ret = capture->volume.SetMute(capture, muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetMute(capture, &muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_FALSE(muteFalse); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test interface AudioCaptureGetMute when capture is empty. +* @tc.number SUB_Audio_HDI_AudioCaptureGetMute_0002 +* @tc.desc Test AudioCreateCapture interface, return -1 if the capture is empty. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureGetMute_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteTrue = true; + bool muteFalse = false; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetMute(captureNull, &muteTrue); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->volume.GetMute(captureNull, &muteFalse); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->volume.GetMute(capture, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetVolume API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureSetVolume_0001 +* @tc.desc Test AudioCaptureSetVolume interface , return 0 if the audiocapture sets volume successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetVolume_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volumeInit = 0.30; + float volumeInitExpc = 0.30; + float volumeLow = 0.10; + float volumeLowExpc = 0.10; + float volumeMid = 0.40; + float volumeMidExpc = 0.40; + float volumeHigh = 0.70; + float volumeHighExpc = 0.70; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.SetVolume(capture, volumeInit); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeInit); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeInitExpc, volumeInit); + ret = capture->volume.SetVolume(capture, volumeLow); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeLow); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeLowExpc, volumeLow); + ret = capture->volume.SetVolume(capture, volumeMid); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeMid); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMidExpc, volumeMid); + ret = capture->volume.SetVolume(capture, volumeHigh); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeHigh); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeHighExpc, volumeHigh); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetVolume,when volume is set maximum value or minimum value. +* @tc.number SUB_Audio_HDI_AudioCaptureSetVolume_0002 +* @tc.desc Test AudioCaptureSetVolume,return 0 if volume is set maximum value or minimum value. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetVolume_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volumeMin = 0; + float volumeMinExpc = 0; + float volumeMax = 1.0; + float volumeMaxExpc = 1.0; + float volumeMinBoundary = -1; + float volumeMaxBoundary = 1.1; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetVolume(capture, volumeMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMinExpc, volumeMin); + + ret = capture->volume.SetVolume(capture, volumeMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volumeMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMaxExpc, volumeMax); + + ret = capture->volume.SetVolume(capture, volumeMinBoundary); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = capture->volume.SetVolume(capture, volumeMaxBoundary); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetVolume,when capture is empty. +* @tc.number SUB_Audio_HDI_AudioCaptureSetVolume_0003 +* @tc.desc Test AudioCaptureSetVolume,return -1 when capture is empty. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureSetVolume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetVolume(captureNull, volume); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetVolume API via legal input. +* @tc.number SUB_Audio_HDI_AudioCaptureGetVolume_001 +* @tc.desc Test AudioCaptureGetVolume interface , return 0 if the audiocapture is get successful. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureGetVolume_001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.60; + float defaultVolume = 0.60; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetVolume(capture, volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(defaultVolume, volume); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetVolume when when capturing is in progress. +* @tc.number SUB_Audio_HDI_AudioCaptureGetVolume_002. +* @tc.desc Test AudioCaptureGetVolume,return 0 when when capturing is in progress. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureGetVolume_002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.60; + float defaultVolume = 0.60; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = AudioCaptureStart(AUDIO_CAPTURE_FILE, capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetVolume(capture, volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetVolume(capture, &volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(defaultVolume, volume); + + ret = capture->control.Stop((AudioHandle)capture); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetVolume,when capture is empty. +* @tc.number SUB_Audio_HDI_AudioCaptureGetVolume_0003 +* @tc.desc Test AudioCaptureGetVolume,return -1 when capture is empty. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_HDI_AudioCaptureGetVolume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.30; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetVolume(captureNull, &volume); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGainThreshold API via legal input +* @tc.number SUB_Audio_hdi_CaptureGetGainThreshold_0001 +* @tc.desc test AudioCaptureGetGainThreshold interface, return 0 is call successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGainThreshold_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGainThreshold((AudioHandle)capture, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(min, GAIN_MIN); + EXPECT_EQ(max, GAIN_MAX); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGainThreshold API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetGainThreshold_0002 +* @tc.desc test AudioCaptureGetGainThreshold interface, return -1 if the incoming parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGainThreshold_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGainThreshold((AudioHandle)captureNull, &min, &max); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGainThreshold API via setting the incoming parameter min is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetGainThreshold_0003 +* @tc.desc test AudioCaptureGetGainThreshold interface, return -1 if the incoming parameter min is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGainThreshold_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float max = 0; + float* minNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGainThreshold((AudioHandle)capture, minNull, &max); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGainThreshold API via setting the incoming parameter max is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetGainThreshold_0004 +* @tc.desc test AudioCaptureGetGainThreshold interface, return -1 if the incoming parameter max is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGainThreshold_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float* maxNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGainThreshold((AudioHandle)capture, &min, maxNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetGain API via legal input +* @tc.number SUB_Audio_hdi_CaptureSetGain_0001 +* @tc.desc test AudioCaptureSetGain interface, return 0 is call successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureSetGain_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGainThreshold((AudioHandle)capture, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + float gain = max - 1; + float gainMax = max; + float gainMin = min; + float gainExpc = max - 1; + float gainMaxExpc = max; + float gainMinExpc = min; + ret = capture->volume.SetGain((AudioHandle)capture, gainMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)capture, &gainMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainMaxExpc, gainMax); + + ret = capture->volume.SetGain((AudioHandle)capture, gainMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)capture, &gainMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainMinExpc, gainMin); + + ret = capture->volume.SetGain((AudioHandle)capture, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)capture, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainExpc, gain); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetGain API via setting gain greater than the maximum and less than the minimum +* @tc.number SUB_Audio_hdi_CaptureSetGain_0002 +* @tc.desc test AudioCaptureSetGain interface, return -1 if gain greater than the maximum and less than the minimum +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureSetGain_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGainThreshold((AudioHandle)capture, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + float gainOne = max+1; + float gainSec = min-1; + ret = capture->volume.SetGain((AudioHandle)capture, gainOne); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + ret = capture->volume.SetGain((AudioHandle)capture, gainSec); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureSetGain API via setting the incoming parameter handle is nullptr. +* @tc.number SUB_Audio_hdi_CaptureSetGain_0006 +* @tc.desc test AudioCaptureSetGain interface, return -1 if the incoming parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureSetGain_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gain = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetGain((AudioHandle)captureNull, gain); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGain API via legal input +* @tc.number SUB_Audio_hdi_CaptureGetGain_0001 +* @tc.desc test AudioCaptureGetGain interface, return 0 if CaptureGetGain is call successfully. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGain_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGainThreshold((AudioHandle)capture, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + float gain = min+1; + float gainValue = min+1; + ret = capture->volume.SetGain((AudioHandle)capture, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)capture, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainValue, gain); + + capture->control.Stop((AudioHandle)capture); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGain API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetGain_0002 +* @tc.desc test AudioCaptureGetGain interface, return -1 if the incoming parameter handle is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGain_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gainValue = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + struct AudioCapture *captureNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)captureNull, &gainValue); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGain API via legal input in difference scenes +* @tc.number SUB_Audio_hdi_CaptureGetGain_0003 +* @tc.desc test AudioCaptureGetGain interface, return 0 if get gain after creating the capture object. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGain_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gain = GAIN_MAX-1; + float gainOne = GAIN_MAX-1; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.SetGain((AudioHandle)capture, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = capture->volume.GetGain((AudioHandle)capture, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainOne, gain); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetGain API via setting the parameter gain is nullptr +* @tc.number SUB_Audio_hdi_CaptureGetGain_0004 +* @tc.desc test AudioCaptureGetGain interface, return -1 if the parameter gain is nullptr. +*/ +HWTEST_F(AudioHdiCaptureVolumeTest, SUB_Audio_hdi_CaptureGetGain_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioCapture *capture = nullptr; + float *gainNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateCapture(manager, PIN_IN_MIC, ADAPTER_NAME_INTERNAL, &adapter, &capture); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = capture->volume.GetGain((AudioHandle)capture, gainNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyCapture(adapter, capture); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/BUILD.gn b/hdf/audio/hdi/render/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b0317cf8207e0577b20d1fe3ce63556489bdef99 --- /dev/null +++ b/hdf/audio/hdi/render/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2021 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. + +import("//build/ohos_var.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/peripheral/audio/audio.gni") +import("//test/xts/tools/build/suite.gni") + +###########################systemtest############################## +module_output_path = "hdf/audio" + +###########################hdf_audio_hdi_render_test###################### +ohos_moduletest_suite("hdf_audio_hdi_render_test") { + module_out_path = module_output_path + sources = [ + "../../common/hdi_common/src/audio_hdi_common.cpp", + "src/audio_hdirender_attr_test.cpp", + "src/audio_hdirender_control_test.cpp", + "src/audio_hdirender_scene_test.cpp", + "src/audio_hdirender_test.cpp", + "src/audio_hdirender_volume_test.cpp", + ] + + include_dirs = [ + "//drivers/peripheral/audio/hal/hdi_passthrough/include", + "//drivers/peripheral/audio/interfaces/include", + "//drivers/peripheral/audio/hal/hdi_binder/proxy/include", + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/adapter/uhdf2/shared/include", + "//drivers/framework/include/core", + "//drivers/framework/include/utils", + "//drivers/framework/include/osal", + "//drivers/framework/include", + "//third_party/bounds_checking_function/include", + "//drivers/framework/utils/include", + "//drivers/adapter/uhdf2/osal/include", + "//drivers/peripheral/audio/test/systemtest/common/hdi_common/include", + "//third_party/googletest/googletest/include/gtest", + "//drivers/peripheral/audio/test/systemtest/hdi/render/include", + ] + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + defines = [] + if (enable_audio_adm_so) { + defines += [ "AUDIO_ADM_SO" ] + } + if (enable_audio_mpi_so) { + defines += [ "AUDIO_MPI_SO" ] + } + if (enable_audio_adm_service) { + defines += [ "AUDIO_ADM_SERVICE" ] + } + if (enable_audio_mpi_service) { + defines += [ "AUDIO_MPI_SERVICE" ] + } +} diff --git a/hdf/audio/hdi/render/Test.json b/hdf/audio/hdi/render/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..c16f91e7557b813c421d5ab0363da85c9f9cef49 --- /dev/null +++ b/hdf/audio/hdi/render/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "hdf_audio_hdi_render_test->/data/local/tmp/hdf_audio_hdi_render_test" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hdf_audio_hdi_render_test", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hdf_audio_hdi_render_test Tests" +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/include/audio_hdirender_attr_test.h b/hdf/audio/hdi/render/include/audio_hdirender_attr_test.h new file mode 100755 index 0000000000000000000000000000000000000000..2b45c4275b4ea15aa7fb6c7e9c23efcefc4705ae --- /dev/null +++ b/hdf/audio/hdi/render/include/audio_hdirender_attr_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIRENDER_ATTR_TEST +#define AUDIO_HDIRENDER_ATTR_TEST + +#endif diff --git a/hdf/audio/hdi/render/include/audio_hdirender_control_test.h b/hdf/audio/hdi/render/include/audio_hdirender_control_test.h new file mode 100755 index 0000000000000000000000000000000000000000..a302965274195b221787e596da9ba24026744cae --- /dev/null +++ b/hdf/audio/hdi/render/include/audio_hdirender_control_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIRENDER_CONTROL_TEST_H +#define AUDIO_HDIRENDER_CONTROL_TEST_H + +#endif diff --git a/hdf/audio/hdi/render/include/audio_hdirender_scene_test.h b/hdf/audio/hdi/render/include/audio_hdirender_scene_test.h new file mode 100755 index 0000000000000000000000000000000000000000..0e6a208d1c3a8780da476351221827baac8aba7d --- /dev/null +++ b/hdf/audio/hdi/render/include/audio_hdirender_scene_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIRENDER_SCENE_TEST_H +#define AUDIO_HDIRENDER_SCENE_TEST_H + +#endif diff --git a/hdf/audio/hdi/render/include/audio_hdirender_test.h b/hdf/audio/hdi/render/include/audio_hdirender_test.h new file mode 100755 index 0000000000000000000000000000000000000000..b83148e1d6cddc861d29cf274f7c63cb13aa403b --- /dev/null +++ b/hdf/audio/hdi/render/include/audio_hdirender_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIRENDER_TEST_H +#define AUDIO_HDIRENDER_TEST_H + +#endif diff --git a/hdf/audio/hdi/render/include/audio_hdirender_volume_test.h b/hdf/audio/hdi/render/include/audio_hdirender_volume_test.h new file mode 100755 index 0000000000000000000000000000000000000000..fee4409264d91822ade596bbb194324c8d7d0f5e --- /dev/null +++ b/hdf/audio/hdi/render/include/audio_hdirender_volume_test.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef AUDIO_HDIRENDER_VOLUME_TEST_H +#define AUDIO_HDIRENDER_VOLUME_TEST_H + +#endif diff --git a/hdf/audio/hdi/render/src/audio_hdirender_attr_test.cpp b/hdf/audio/hdi/render/src/audio_hdirender_attr_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3012565a2a54725dd24f2707977a102c7ab1b910 --- /dev/null +++ b/hdf/audio/hdi/render/src/audio_hdirender_attr_test.cpp @@ -0,0 +1,1704 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio render adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdirender_attr_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiRenderAttrTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +using THREAD_FUNC = void *(*)(void *); + +TestAudioManager *(*AudioHdiRenderAttrTest::GetAudioManager)() = nullptr; +void *AudioHdiRenderAttrTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiRenderAttrTest::SdkInit)() = nullptr; + void (*AudioHdiRenderAttrTest::SdkExit)() = nullptr; + void *AudioHdiRenderAttrTest::sdkSo = nullptr; +#endif + +void AudioHdiRenderAttrTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiRenderAttrTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} +void AudioHdiRenderAttrTest::SetUp(void) {} +void AudioHdiRenderAttrTest::TearDown(void) {} + +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0001 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = AUDIO_SAMPLE_RATE_MASK_8000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 8000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 8000); + + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0002 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 11025; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 11025; + uint32_t ret2 = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 11025); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0003 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 22050; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 22050; + uint32_t ret2 = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 22050); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0004 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 32000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 32000; + uint32_t ret2 = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 32000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0005 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 44100; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 44100; + uint32_t ret2 = 1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 44100); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_COMMUNICATION; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 48000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 48000; + uint32_t ret2 = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 48000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via setting the render is empty . +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0007 +* @tc.desc Test AudioRenderSetSampleAttributes interface, return -1 if the render is empty. +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + struct AudioSampleAttributes attrs = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 8000); + + ret = render->attr.SetSampleAttributes(renderNull, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = render->attr.SetSampleAttributes(render, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0008 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 12000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 12000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 12000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0009 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 16000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 16000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 16000); + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0010 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 24000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0010, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 24000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 24000); + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0011 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 64000; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0011, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 2; + uint32_t ret2 = 64000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 64000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0012 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_24_BIT; +* attrs.sampleRate = 96000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0012, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 1; + uint32_t ret2 = 96000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 96000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret2, attrsValue.sampleRate); + EXPECT_EQ(ret1, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0013 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 0xFFFFFFFFu; +* attrs.channelCount = 2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0013, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 0xFFFFFFFFu); + + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0014 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_8/32_BIT/AAC_MAIN; +* attrs.sampleRate = 8000/11025/22050; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0014, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + struct AudioSampleAttributes attrs3 = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs1, AUDIO_FORMAT_PCM_8_BIT, 1, 8000); + ret = render->attr.SetSampleAttributes(render, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_PCM_32_BIT, 2, 11025); + ret = render->attr.SetSampleAttributes(render, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs3, AUDIO_FORMAT_AAC_MAIN, 1, 22050); + ret = render->attr.SetSampleAttributes(render, &attrs3); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0015 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_AAC_LC/LD/ELD; +* attrs.sampleRate = 32000/44100/48000; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0015, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + struct AudioSampleAttributes attrs3 = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs1, AUDIO_FORMAT_AAC_LC, 2, 32000); + ret = render->attr.SetSampleAttributes(render, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_AAC_LD, 1, 44100); + ret = render->attr.SetSampleAttributes(render, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs3, AUDIO_FORMAT_AAC_ELD, 2, 48000); + ret = render->attr.SetSampleAttributes(render, &attrs3); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0016 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_AAC_HE_V1/V2 +* attrs.sampleRate = 8000/44100; +* attrs.channelCount = 1/2; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0016, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs1 = {}; + struct AudioSampleAttributes attrs2 = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs1, AUDIO_FORMAT_AAC_HE_V1, 1, 8000); + ret = render->attr.SetSampleAttributes(render, &attrs1); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + InitAttrsUpdate(attrs2, AUDIO_FORMAT_AAC_HE_V2, 2, 44100); + ret = render->attr.SetSampleAttributes(render, &attrs2); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetSampleAttributes API via illegal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetSampleAttributes_0017 +* @tc.desc Test AudioRenderSetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT +* attrs.sampleRate = 8000; +* attrs.channelCount = 5; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderSetSampleAttributes_0017, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 5, 8000); + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetSampleAttributes API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderGetSampleAttributes_0001 +* @tc.desc Test AudioRenderGetSampleAttributes ,the setting parameters are as follows. +* attrs.type = AUDIO_IN_MEDIA; +* attrs.format = AUDIO_FORMAT_PCM_16_BIT; +* attrs.sampleRate = 8000; +* attrs.channelCount = 1; +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderGetSampleAttributes_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t ret1 = 8000; + uint32_t ret2 = 1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 8000); + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + EXPECT_EQ(AUDIO_IN_MEDIA, attrsValue.type); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(ret1, attrsValue.sampleRate); + EXPECT_EQ(ret2, attrsValue.channelCount); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRendereGetSampleAttributes API via setting the render is empty . +* @tc.number SUB_Audio_HDI_AudioRenderGetSampleAttributes_0002 +* @tc.desc Test AudioRendereGetSampleAttributes interface, return -1 if the render is empty. +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_AudioRenderGetSampleAttributes_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes *attrsValue = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 44100); + + ret = render->attr.GetSampleAttributes(renderNull, &attrs); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = render->attr.GetSampleAttributes(render, attrsValue); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API via legal input +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0001 +* @tc.desc Test RenderGetFrameSize interface,return 0 if the FrameSize was obtained successfully +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t zero = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameSize(render, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, zero); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCaptureGetFrameSize API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0002 +* @tc.desc Test RenderGetFrameSize interface,return -1 if failed to get the FrameSize when handle is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameSize(renderNull, &size); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API setting the incoming parameter FrameSize is nullptr +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0003 +* @tc.desc Test RenderGetFrameSize interface,return -1 if failed to get the FrameSize when size is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *sizeNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameSize(render, sizeNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API via define format to different values +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0004 +* @tc.desc Test RenderGetFrameSize interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 48000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = render->attr.GetFrameSize(render, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API via define sampleRate to different values +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0005 +* @tc.desc Test RenderGetFrameSize interface,return 0 if get framesize define sampleRate as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 48000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = render->attr.GetFrameSize(render, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API via define channelCount to different values +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0006 +* @tc.desc Test RenderGetFrameSize interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 44100; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 44100); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = render->attr.GetFrameSize(render, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameSize API via define sampleRate to different value +* @tc.number SUB_Audio_HDI_RenderGetFrameSize_0007 +* @tc.desc Test RenderGetFrameSize interface,return 0 if get framesize define sampleRate as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameSize_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t size = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 48000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = render->attr.GetFrameSize(render, &size); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(size, INITIAL_VALUE); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via legal +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0001 +* @tc.desc Test RenderGetFrameCount interface, return 0 if the FrameSize was obtained successfully +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t zero = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, zero); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0002 +* @tc.desc Test RenderGetFrameCount interface,return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameCount(renderNull, &count); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API setting the incoming parameter count is nullptr +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0003 +* @tc.desc Test RenderGetFrameCount interface,return -1 if the incoming parameter count is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *countNull = nullptr; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetFrameCount(render, countNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via define channelCount to different value +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0004 +* @tc.desc Test RenderGetFrameCount interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 8000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 2, 8000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via define format to different value +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0005 +* @tc.desc Test RenderGetFrameCount interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 8000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 2, 8000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via define channelCount to different value +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0006 +* @tc.desc Test RenderGetFrameCount interface,return 0 if get framesize define channelCount to different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 44100; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 44100); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetFrameCount API via define format to different value +* @tc.number SUB_Audio_HDI_RenderGetFrameCount_0007 +* @tc.desc Test RenderGetFrameCount interface,return 0 if get framesize define format as different values +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetFrameCount_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 32000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_16_BIT, 1, 32000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT(count, INITIAL_VALUE); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetCurrentChannelId API via legal input +* @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0001 +* @tc.desc Test RenderGetCurrentChannelId, return 0 if the default CurrentChannelId is obtained successfully +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetCurrentChannelId_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdValue = CHANNELCOUNT; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetCurrentChannelId(render, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdValue, channelId); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCurrentChannelId API via get channelId to 1 and set channelCount to 1 +* @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0003 +* @tc.desc Test GetCurrentChannelId interface,return 0 if get channelId to 1 and set channelCount to 1 +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetCurrentChannelId_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdExp = 1; + uint32_t channelCountExp = 1; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrsUpdate(attrs, AUDIO_FORMAT_PCM_24_BIT, 1, 32000); + + ret = AudioRenderSetGetSampleAttributes(attrs, attrsValue, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelCountExp, attrs.channelCount); + + ret = render->attr.GetCurrentChannelId(render, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdExp, channelId); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetCurrentChannelId API via CurrentChannelId is obtained after created +* @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0003 +* @tc.desc Test RenderGetCurrentChannelId interface, return 0 if CurrentChannelId is obtained after created +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetCurrentChannelId_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + uint32_t channelIdExp = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetCurrentChannelId(render, &channelId); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(channelIdExp, channelId); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetCurrentChannelId API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0004 +* @tc.desc Test GetCurrentChannelId interface,return -1 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetCurrentChannelId_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t channelId = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetCurrentChannelId(renderNull, &channelId); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetCurrentChannelId API via setting the parameter channelId is nullptr +* @tc.number SUB_Audio_HDI_RenderGetCurrentChannelId_0005 +* @tc.desc Test RenderGetCurrentChannelId interface, return -1 if setting the parameter channelId is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetCurrentChannelId_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t *channelIdNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->attr.GetCurrentChannelId(render, channelIdNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +#if defined (AUDIO_ADM_SERVICE) || defined (AUDIO_ADM_SO) || defined (__LITEOS__) +/** +* @tc.name Test RenderSetExtraParams API via setting ExtraParams during playback +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0001 +* @tc.desc Test RenderSetExtraParams interface,return 0 if the ExtraParams is set during playback +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000"; + char keyValueListExp[] = "attr-route=1;attr-format=32;attr-channels=2;attr-sampling-rate=48000"; + size_t index = 1; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = AUDIO_FILE.c_str() + }; + ASSERT_NE(nullptr, GetAudioManager); + audiopara.manager = GetAudioManager(); + ASSERT_NE(nullptr, audiopara.manager); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)PlayAudioFile, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.render != nullptr) { + ret = audiopara.render->attr.SetExtraParams((AudioHandle)audiopara.render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.render->attr.GetExtraParams((AudioHandle)audiopara.render, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + string strGetValue = keyValueListValue; + size_t indexAttr = strGetValue.find("attr-frame-count"); + size_t indexFlag = strGetValue.rfind(";"); + if (indexAttr != string::npos && indexFlag != string::npos) { + strGetValue.replace(indexAttr, indexFlag - indexAttr + index, ""); + } + EXPECT_STREQ(keyValueListExp, strGetValue.c_str()); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test RenderSetExtraParams API via setting some parameters after playing +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0002 +* @tc.desc Test RenderSetExtraParams interface,return 0 if some parameters is set after playing +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueListOne[] = "attr-frame-count=1024;"; + char keyValueListOneExp[] = "attr-route=0;attr-format=16;attr-channels=2;attr-frame-count=1024;\ +attr-sampling-rate=48000"; + char keyValueListTwo[] = "attr-format=16;attr-frame-count=1024;"; + char keyValueListTwoExp[] = "attr-route=0;attr-format=16;attr-channels=2;attr-frame-count=1024;\ +attr-sampling-rate=48000"; + char keyValueListThr[] = "attr-route=1;attr-channels=1;attr-frame-count=1024;"; + char keyValueListThrExp[] = "attr-route=1;attr-format=16;attr-channels=1;attr-frame-count=1024;\ +attr-sampling-rate=48000"; + char keyValueListFour[] = "attr-format=32;attr-channels=2;attr-frame-count=4096;attr-sampling-rate=48000"; + char keyValueListFourExp[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListValueOne[256] = {}; + char keyValueListValueTwo[256] = {}; + char keyValueListValueThr[256] = {}; + char keyValueListValueFour[256] = {}; + int32_t listLenth = 256; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueListOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValueOne, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListOneExp, keyValueListValueOne); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueListTwo); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValueTwo, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListTwoExp, keyValueListValueTwo); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueListThr); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValueThr, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListThrExp, keyValueListValueThr); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueListFour); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValueFour, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListFourExp, keyValueListValueFour); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via setting keyvaluelist to a value outside the range +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0003 +* @tc.desc Test RenderSetExtraParams interface,return -1 if the Keyvaluelist is a value out of range +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueList[] = "attr-para=abc;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via adding parameters to keyvaluelist +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0004 +* @tc.desc Test RenderSetExtraParams interface,return -1 if adding parameters to keyvaluelist +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000;\ +attr-para=123"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via setting ExtraParams When the key is the same and the value is + different +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0005 +* @tc.desc Test RenderSetExtraParams interface,return 0 if set ExtraParams When the key is the same and the value + is different +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + char keyValueList[] = "attr-sampling-rate=48000;attr-sampling-rate=96000;attr-frame-count=4096;"; + char keyValueListExp[] = "attr-route=0;attr-format=16;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=96000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListExp, keyValueListValue); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via setting the parameter in keyvaluelist as an abnormal value +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0006 +* @tc.desc Test RenderSetExtraParams interface,return -1 if Set the parameter in keyvaluelist as an abnormal value +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char attrSamplingRateError[] = "attr-sampling-rate=1234567;"; + char attrChannelsError[] = "attr-channels=3;"; + char attrFrameCountError[] = "attr-frame-count=111111111111111111111;"; + char attrRouteError[] = "attr-route=5;"; + char attrFormateError[] = "attr-formate=12;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, attrSamplingRateError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, attrChannelsError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, attrFrameCountError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, attrRouteError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, attrFormateError); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0007 +* @tc.desc Test RenderSetExtraParams interface,return -1 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + char keyValueList[] = "attr-format=2;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)renderNull, keyValueList); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetExtraParams API via setting the format of ExtraParams is nullptr +* @tc.number SUB_Audio_HDI_RenderSetExtraParams_0008 +* @tc.desc Test RenderSetExtraParams interface,return -1 if set the format of ExtraParams is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderSetExtraParams_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueListNull[] = "attr-format=;"; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueListNull); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetExtraParams API via legal input +* @tc.number SUB_Audio_HDI_RenderGetExtraParams_0001 +* @tc.desc Test RenderGetExtraParams interface,return 0 if the RenderGetExtraParams was obtained successfully +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetExtraParams_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t count = 0; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrsValue = {}; + char keyValueList[] = "attr-format=24;attr-frame-count=4096;"; + char keyValueListExp[] = "attr-route=0;attr-format=24;attr-channels=2;attr-frame-count=4096;\ +attr-sampling-rate=48000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + int32_t formatExp = 3; + uint32_t sampleRateExp = 48000; + uint32_t channelCountExp = 2; + uint32_t frameCountExp = 4096; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueListExp, keyValueListValue); + + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(formatExp, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = render->attr.GetFrameCount(render, &count); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(count, frameCountExp); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetExtraParams API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_RenderGetExtraParams_0002 +* @tc.desc Test RenderGetExtraParams interface,return -1 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetExtraParams_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + char keyValueList[] = "attr-format=32;"; + char keyValueListValue[256] = {}; + int32_t listLenth = 256; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)renderNull, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetExtraParams API via setting listlength to be less than the actual length +* @tc.number SUB_Audio_HDI_RenderGetExtraParams_0003 +* @tc.desc Test RenderGetExtraParams interface,return -1 if set listlength to be less than the actual length +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetExtraParams_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000;"; + char keyValueListValue[256] = {}; + int32_t listLenth = 8; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetExtraParams API via setting listlenth equal to the actual length +* @tc.number SUB_Audio_HDI_RenderGetExtraParams_0004 +* @tc.desc Test RenderGetExtraParams interface,return 0 if set listlenth equal to the actual length +*/ +HWTEST_F(AudioHdiRenderAttrTest, SUB_Audio_HDI_RenderGetExtraParams_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = {}; + struct AudioRender *render = nullptr; + char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=11111111111111111111;\ +attr-sampling-rate=48000"; + char keyValueListValue[256] = {}; + int32_t listLenth = 107; + + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.SetExtraParams((AudioHandle)render, keyValueList); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetExtraParams((AudioHandle)render, keyValueListValue, listLenth); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_STREQ(keyValueList, keyValueListValue); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +#endif +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/src/audio_hdirender_control_test.cpp b/hdf/audio/hdi/render/src/audio_hdirender_control_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d272f70005cd7a7548891cdeb1deae05c8ed4d41 --- /dev/null +++ b/hdf/audio/hdi/render/src/audio_hdirender_control_test.cpp @@ -0,0 +1,945 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio render adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdirender_control_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiRenderControlTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +TestAudioManager *(*AudioHdiRenderControlTest::GetAudioManager)() = nullptr; +void *AudioHdiRenderControlTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiRenderControlTest::SdkInit)() = nullptr; + void (*AudioHdiRenderControlTest::SdkExit)() = nullptr; + void *AudioHdiRenderControlTest::sdkSo = nullptr; +#endif + +void AudioHdiRenderControlTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiRenderControlTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiRenderControlTest::SetUp(void) {} + +void AudioHdiRenderControlTest::TearDown(void) {} + +/** +* @tc.name Test AudioRenderStart API via legal input +* @tc.number SUB_Audio_HDI_RenderStart_0001 +* @tc.desc Test AudioRenderStart interface,return 0 if the audiorender object is created successfully. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStart_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderStart API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderStart_0002 +* @tc.desc Test AudioRenderStart interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStart_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderStart API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_RenderStart_0003 +* @tc.desc Test AudioRenderStart interface,return -1 the second time if the RenderStart is called twice +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStart_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioRender *render = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_AO_BUSY, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderStop API via legal input +* @tc.number SUB_Audio_HDI_RenderStop_0001 +* @tc.desc test AudioRenderStop interface. return 0 if the rendering is successfully stopped. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStop_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioRender *render = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderStop API via the render does not start and stop only +* @tc.number SUB_Audio_HDI_RenderStop_0002 +* @tc.desc test AudioRenderStop interface. return -4 if the render does not start and stop only +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStop_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderStop API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_RenderStop_0003 +* @tc.desc Test RenderStop interface,return -4 the second time if the RenderStop is called twice +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStop_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderStop API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderStop_0004 +* @tc.desc Test RenderStop interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderStop_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderPause API via legal input +* @tc.number SUB_Audio_HDI_RenderPause_001 +* @tc.desc test HDI RenderPause interface,return 0 if the render is paused after start +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderPause API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_RenderPause_0002 +* @tc.desc Test AudioRenderPause interface, return -1 the second time if RenderPause is called twice +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + TestAudioManager* manager = {}; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderPause API via the render is paused after created. +* @tc.number SUB_Audio_HDI_RenderPause_0003 +* @tc.desc Test AudioRenderPause interface,return -1 if the render is paused after created. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderPause API via the render is paused after resumed. +* @tc.number SUB_Audio_HDI_RenderPause_0004 +* @tc.desc Test AudioRenderPause interface,return 0 if the render is paused after resumed. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderPause API via the render is paused after stoped. +* @tc.number SUB_Audio_HDI_RenderPause_0005 +* @tc.desc Test AudioRenderPause interface, return -1 the render is paused after stoped. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + TestAudioManager* manager = {}; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderPause API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderPause_0006 +* @tc.desc Test RenderPause interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderPause_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + TestAudioManager* manager = {}; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via the render is resumed after started +* @tc.number SUB_Audio_HDI_RenderResume_0001 +* @tc.desc test HDI RenderResume interface,return -1 if the render is resumed after started +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via the render is resumed after stopped +* @tc.number SUB_Audio_HDI_RenderResume_0002 +* @tc.desc test HDI RenderResume interface,return -1 if the render is resumed after stopped +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via legal input +* @tc.number SUB_Audio_HDI_RenderResume_0003 +* @tc.desc Test AudioRenderResume interface,return 0 if the render is resumed after paused +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via the interface is called twice in a row +* @tc.number SUB_Audio_HDI_RenderResume_0004 +* @tc.desc Test RenderResume interface,return -1 the second time if the RenderResume is called twice +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via the render Continue to start after resume +* @tc.number SUB_Audio_HDI_RenderResume_0005 +* @tc.desc test HDI RenderResume interface,return -1 if the render Continue to start after resume +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_AO_BUSY, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderResume API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderResume_0007 +* @tc.desc Test RenderResume interface, return -1 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderResume_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Resume((AudioHandle)renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateRender API via legal input. +* @tc.number SUB_Audio_HDI_CreateRender_0001 +* @tc.desc test AudioCreateRender interface,return 0 if render is created successful. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateRender API when two renders is created successful. +* @tc.number SUB_Audio_HDI_AudioCreateRender_0002 +* @tc.desc Test AudioCreateRender interface,return 0 when two renders is created successful. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_AudioCreateRender_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioAdapter *adapter = nullptr; + struct AudioAdapter *adapter2 = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *render2 = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter2, &render2); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter2->DestroyRender(adapter2, render2); + manager->UnloadAdapter(manager, adapter2); +} +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter pins is PIN_IN_MIC. +* @tc.number SUB_Audio_HDI_CreateRender_0003 +* @tc.desc test AudioCreateRender interface,return -1 if the incoming parameter pins is PIN_IN_MIC. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioPort* renderPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, PIN_IN_MIC); + + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter attr is error. +* @tc.number SUB_Audio_HDI_CreateRender_0004 +* @tc.desc test AudioCreateRender interface,return -1 if the incoming parameter attr is error. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioPort* renderPort = nullptr; + uint32_t channelCountErr = 5; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, PIN_OUT_SPEAKER); + attrs.format = AUDIO_FORMAT_AAC_MAIN; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + attrs.channelCount = channelCountErr; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + attrs.type = AUDIO_IN_COMMUNICATION; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter adapter is nullptr +* @tc.number SUB_Audio_HDI_CreateRender_0005 +* @tc.desc test AudioCreateRender interface,Returns -1 if the incoming parameter adapter is nullptr. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapterNull = nullptr; + struct AudioPort* renderPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, PIN_OUT_SPEAKER); + + ret = adapter->CreateRender(adapterNull, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter devDesc is nullptr +* @tc.number SUB_Audio_HDI_CreateRender_0006 +* @tc.desc test AudioCreateRender interface,Returns -1 if the incoming parameter devDesc is nullptr. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioPort* renderPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor *devDescNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrs(attrs); + + ret = adapter->CreateRender(adapter, devDescNull, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter attrs is nullptr +* @tc.number SUB_Audio_HDI_CreateRender_0007 +* @tc.desc test AudioCreateRender interface,Returns -1 if the incoming parameter attrs is nullptr. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioPort* renderPort = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes *attrsNull = nullptr; + struct AudioDeviceDescriptor devDesc = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitDevDesc(devDesc, renderPort->portId, PIN_OUT_SPEAKER); + + ret = adapter->CreateRender(adapter, &devDesc, attrsNull, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter render is nullptr +* @tc.number SUB_Audio_HDI_CreateRender_0008 +* @tc.desc test AudioCreateRender interface,Returns -1 if the incoming parameter render is nullptr. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender **renderNull = nullptr; + struct AudioPort* renderPort = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, PIN_OUT_SPEAKER); + + ret = adapter->CreateRender(adapter, &devDesc, &attrs, renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test AudioCreateRender API via setting the incoming parameter devDesc is error +* @tc.number SUB_Audio_HDI_CreateRender_0009 +* @tc.desc test AudioCreateRender interface,Returns -1 if the incoming parameter devDesc is error. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_CreateRender_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioDeviceDescriptor devDesc = {}; + struct AudioPort* renderPort = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = GetLoadAdapter(manager, PORT_OUT, ADAPTER_NAME_USB, &adapter, renderPort); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = InitAttrs(attrs); + InitDevDesc(devDesc, renderPort->portId, PIN_OUT_SPEAKER); + + devDesc.portId = -5; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + devDesc.pins = PIN_NONE; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + devDesc.desc = "devtestname"; + ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioDestroyRender API via legal input. +* @tc.number SUB_Audio_HDI_DestroyRender_0001 +* @tc.desc Test AudioDestroyRender interface, return 0 if render is destroyed successful. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_DestroyRender_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = adapter->DestroyRender(adapter, render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioDestroyRender API,where the parameter render is empty. +* @tc.number SUB_Audio_HDI_DestroyRender_0002 +* @tc.desc Test AudioDestroyRender interface, return -1 if the parameter render is empty. +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_DestroyRender_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = adapter->DestroyRender(adapter, renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + manager->UnloadAdapter(manager, adapter); +} + +/** +* @tc.name Test RenderFlush API via legal input Verify that the data in the buffer is flushed after stop +* @tc.number SUB_Audio_HDI_RenderFlush_0001 +* @tc.desc Test RenderFlush interface,return -2 if the data in the buffer is flushed successfully after stop +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderFlush_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Flush((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderFlush that the data in the buffer is flushed when handle is nullptr after paused +* @tc.number SUB_Audio_HDI_RenderFlush_0002 +* @tc.desc Test RenderFlush, return -1 if the data in the buffer is flushed when handle is nullptr after paused +*/ +HWTEST_F(AudioHdiRenderControlTest, SUB_Audio_HDI_RenderFlush_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + + manager = GetAudioManager(); + ASSERT_NE(nullptr, GetAudioManager); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Pause((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Flush((AudioHandle)renderNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/src/audio_hdirender_scene_test.cpp b/hdf/audio/hdi/render/src/audio_hdirender_scene_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4f7ddd482cbd22170d5254f40ce86b3030cf210b --- /dev/null +++ b/hdf/audio/hdi/render/src/audio_hdirender_scene_test.cpp @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio render adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdirender_scene_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiRenderSceneTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +using THREAD_FUNC = void *(*)(void *); + +TestAudioManager *(*AudioHdiRenderSceneTest::GetAudioManager)() = nullptr; +void *AudioHdiRenderSceneTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiRenderSceneTest::SdkInit)() = nullptr; + void (*AudioHdiRenderSceneTest::SdkExit)() = nullptr; + void *AudioHdiRenderSceneTest::sdkSo = nullptr; +#endif + +void AudioHdiRenderSceneTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiRenderSceneTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiRenderSceneTest::SetUp(void) {} + +void AudioHdiRenderSceneTest::TearDown(void) {} + +/** +* @tc.name Test AudioRenderCheckSceneCapability API and check scene's capability +* @tc.number SUB_Audio_HDI_RenderCheckSceneCapability_0001 +* @tc.desc Test AudioRenderCheckSceneCapability interface,return 0 if check scene's capability successful. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_RenderCheckSceneCapability_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = false; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_OUT_SPEAKER; + ret = render->scene.CheckSceneCapability(render, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_TRUE(supported); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the scene is not configed in the josn. +* @tc.number SUB_Audio_HDI_RenderCheckSceneCapability_0002 +* @tc.desc Test RenderCheckSceneCapability interface,return -1 if the scene is not configed in the josn. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_RenderCheckSceneCapability_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 5; + scenes.desc.pins = PIN_OUT_SPEAKER; + ret = render->scene.CheckSceneCapability(render, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test checking scene's capability where the render is empty +* @tc.number SUB_Audio_HDI_RenderCheckSceneCapability_0003 +* @tc.desc Test AudioRenderCheckSceneCapability,return -1 if the render is empty. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_RenderCheckSceneCapability_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_OUT_SPEAKER; + ret = render->scene.CheckSceneCapability(renderNull, &scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderCheckSceneCapability API and check scene's capability +* @tc.number SUB_Audio_HDI_RenderCheckSceneCapability_0004 +* @tc.desc Test AudioRenderCheckSceneCapability interface,return -1 if the scene is empty. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_RenderCheckSceneCapability_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool supported = true; + struct AudioSceneDescriptor *scenes = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->scene.CheckSceneCapability(render, scenes, &supported); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderCheckSceneCapability API and check scene's capability +* @tc.number SUB_Audio_HDI_RenderCheckSceneCapability_0005 +* @tc.desc Test AudioRenderCheckSceneCapability interface,return -1 if the supported is empty. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_RenderCheckSceneCapability_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_OUT_SPEAKER; + ret = render->scene.CheckSceneCapability(render, &scenes, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSelectScene API via legal input +* @tc.number SUB_Audio_HDI_AudioRenderSelectScene_0001 +* @tc.desc Test AudioRenderSelectScene interface,return 0 if select Render's scene successful. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_AudioRenderSelectScene_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + scenes.scene.id = 0; + scenes.desc.pins = PIN_OUT_SPEAKER; + + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->scene.SelectScene(render, &scenes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSelectScene API after Render start. +* @tc.number SUB_Audio_HDI_AudioRenderSelectScene_0002 +* @tc.desc Test AudioRenderSelectScene, return 0 if select Render's scene successful after Render start. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_AudioRenderSelectScene_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_OUT_SPEAKER; + ret = render->scene.SelectScene(render, &scenes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSelectScene API where the parameter handle is empty. +* @tc.number SUB_Audio_HDI_AudioRenderSelectScene_0003 +* @tc.desc Test AudioRenderSelectScene, return -1 if the parameter handle is empty. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_AudioRenderSelectScene_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 0; + scenes.desc.pins = PIN_IN_MIC; + ret = render->scene.SelectScene(renderNull, &scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSelectScene API where the parameter scene is empty. +* @tc.number SUB_Audio_HDI_AudioRenderSelectScene_0004 +* @tc.desc Test AudioRenderSelectScene, return -1 if the parameter scene is empty. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_AudioRenderSelectScene_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor *scenes = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->scene.SelectScene(render, scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSelectScene API where the scene is not configed in the josn. +* @tc.number SUB_Audio_HDI_AudioRenderSelectScene_0005 +* @tc.desc Test AudioRenderSelectScene, return -1 if the scene is not configed in the josn. +*/ +HWTEST_F(AudioHdiRenderSceneTest, SUB_Audio_HDI_AudioRenderSelectScene_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioSceneDescriptor scenes = {}; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + scenes.scene.id = 5; + scenes.desc.pins = PIN_OUT_HDMI; + ret = render->scene.SelectScene(render, &scenes); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/src/audio_hdirender_test.cpp b/hdf/audio/hdi/render/src/audio_hdirender_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..0ce772ea6ddd5968b1e0ce2b58d0f18c3e3d5591 --- /dev/null +++ b/hdf/audio/hdi/render/src/audio_hdirender_test.cpp @@ -0,0 +1,1608 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio render adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdirender_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiRenderTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif + static int32_t GetLoadAdapterAudioPara(struct PrepareAudioPara& audiopara); +}; + +using THREAD_FUNC = void *(*)(void *); + +TestAudioManager *(*AudioHdiRenderTest::GetAudioManager)() = nullptr; +void *AudioHdiRenderTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiRenderTest::SdkInit)() = nullptr; + void (*AudioHdiRenderTest::SdkExit)() = nullptr; + void *AudioHdiRenderTest::sdkSo = nullptr; +#endif +void AudioHdiRenderTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiRenderTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiRenderTest::SetUp(void) {} + +void AudioHdiRenderTest::TearDown(void) {} + +int32_t AudioHdiRenderTest::GetLoadAdapterAudioPara(struct PrepareAudioPara& audiopara) +{ + int32_t ret = -1; + int size = 0; + auto *inst = (AudioHdiRenderTest *)audiopara.self; + if (inst != nullptr && inst->GetAudioManager != nullptr) { + audiopara.manager = inst->GetAudioManager(); + } + if (audiopara.manager == nullptr) { + return HDF_FAILURE; + } + ret = audiopara.manager->GetAllAdapters(audiopara.manager, &audiopara.descs, &size); + if (ret < 0) { + return ret; + } + if (audiopara.descs == nullptr || size == 0) { + return AUDIO_HAL_ERR_INTERNAL; + } + int index = SwitchAdapter(audiopara.descs, audiopara.adapterName, + audiopara.portType, audiopara.audioPort, size); + if (index < 0) { + return AUDIO_HAL_ERR_INTERNAL; + } else { + audiopara.desc = &audiopara.descs[index]; + } + if (audiopara.desc == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } else { + ret = audiopara.manager->LoadAdapter(audiopara.manager, audiopara.desc, &audiopara.adapter); + } + if (ret < 0) { + return ret; + } + if (audiopara.adapter == nullptr) { + return AUDIO_HAL_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + +/** +* @tc.name Test RenderGetLatency API via legal +* @tc.number SUB_Audio_HDI_RenderGetLatency_0001 +* @tc.desc test RenderGetLatency interface, return 0 if GetLatency successful +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetLatency_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t latencyTime = 0; + uint32_t expectLatency = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetLatency(render, &latencyTime); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_LT(expectLatency, latencyTime); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetLatency API via Setting parameters render is empty +* @tc.number SUB_Audio_HDI_AudioRenderGetLatency_0002 +* @tc.desc test RenderGetLatency interface, return -1 if Setting parameters render is empty +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetLatency_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t latencyTime = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetLatency(renderNull, &latencyTime); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetLatency API via Setting parameters ms is empty +* @tc.number SUB_Audio_HDI_AudioRenderGetLatency_0003 +* @tc.desc test RenderGetLatency interface,return -1 if Setting parameters ms is empty +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetLatency_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint32_t *latencyTime = nullptr; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetLatency(render, latencyTime); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test SetRenderSpeed API via legal +* @tc.number SUB_Audio_HDI_AudioRenderSetRenderSpeed_0001 +* @tc.desc Test SetRenderSpeed interface,return -2 if setting RenderSpeed +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetRenderSpeed_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float speed = 100; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->SetRenderSpeed(render, speed); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test SetRenderSpeed API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderSetRenderSpeed_0002 +* @tc.desc Test SetRenderSpeed interface,return -2 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetRenderSpeed_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float speed = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->SetRenderSpeed(renderNull, speed); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderSpeed API via legal +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderSpeed_0001 +* @tc.desc Test GetRenderSpeed interface,return -2 if getting RenderSpeed +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderSpeed_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float speed = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderSpeed(render, &speed); + EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderSpeed API via setting the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderSpeed_0002 +* @tc.desc Test GetRenderSpeed interface,return -2 if the incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderSpeed_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + float speed = 0; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetRenderSpeed(renderNull, &speed); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderSpeed API via setting the incoming parameter speed is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderSpeed_0002 +* @tc.desc Test GetRenderSpeed interface,return -2 if the incoming parameter speed is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderSpeed_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + float *speedNull = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetRenderSpeed(render, speedNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderFrame API via legal input +* @tc.number SUB_Audio_HDI_AudioRenderFrame_0001 +* @tc.desc test AudioRenderFrame interface,Returns 0 if the data is written successfully +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderFrame_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = 0; + uint64_t replyBytes = 0; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + char *frame = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = RenderFramePrepare(AUDIO_FILE, frame, requestBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->RenderFrame(render, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioRenderFrame API via setting the incoming parameter render is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderFrame_0002 +* @tc.desc Test AudioRenderFrame interface,Returns -1 if the incoming parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderFrame_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = 0; + uint64_t replyBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + char *frame = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = RenderFramePrepare(AUDIO_FILE, frame, requestBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->RenderFrame(renderNull, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioRenderFrame API via setting the incoming parameter frame is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderFrame_0003 +* @tc.desc Test AudioRenderFrame interface,Returns -1 if the incoming parameter frame is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderFrame_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = 0; + uint64_t replyBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + char *frame = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->RenderFrame(render, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderFrame API via setting the incoming parameter replyBytes is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderFrame_0004 +* @tc.desc Test AudioRenderFrame interface,Returns -1 if the incoming parameter replyBytes is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderFrame_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t requestBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + char *frame = nullptr; + uint64_t *replyBytes = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = RenderFramePrepare(AUDIO_FILE, frame, requestBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->RenderFrame(render, frame, requestBytes, replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test AudioRenderFrame API without calling interface renderstart +* @tc.number SUB_Audio_HDI_AudioRenderFrame_0005 +* @tc.desc Test AudioRenderFrame interface,Returns -1 if without calling interface renderstart +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderFrame_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t replyBytes = 0; + uint64_t requestBytes = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + char *frame = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = RenderFramePrepare(AUDIO_FILE, frame, requestBytes); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->RenderFrame(render, frame, requestBytes, &replyBytes); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); + if (frame != nullptr) { + free(frame); + frame = nullptr; + } +} +/** +* @tc.name Test SetChannelMode API via setting channel mode to different enumeration values +* @tc.number SUB_Audio_HDI_AudioRenderSetChannelMode_0001 +* @tc.desc Test SetChannelMode interface,return 0 if set channel mode to different enumeration values +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetChannelMode_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + enum AudioChannelMode modeOne = AUDIO_CHANNEL_BOTH_LEFT; + enum AudioChannelMode modeSec = AUDIO_CHANNEL_BOTH_RIGHT; + enum AudioChannelMode modeTrd = AUDIO_CHANNEL_EXCHANGE; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->SetChannelMode(render, mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode); + ret = render->SetChannelMode(render, modeOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_BOTH_LEFT, modeOne); + ret = render->SetChannelMode(render, modeSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_BOTH_RIGHT, modeSec); + ret = render->SetChannelMode(render, modeTrd); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeTrd); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_EXCHANGE, modeTrd); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test SetChannelMode API via setting channel mode to different values +* @tc.number SUB_Audio_HDI_AudioRenderSetChannelMode_0002 +* @tc.desc Test SetChannelMode interface,return 0 if set channel mode to different values +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetChannelMode_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_MIX; + enum AudioChannelMode modeOne = AUDIO_CHANNEL_LEFT_MUTE; + enum AudioChannelMode modeSec = AUDIO_CHANNEL_RIGHT_MUTE; + enum AudioChannelMode modeTrd = AUDIO_CHANNEL_BOTH_MUTE; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->SetChannelMode(render, mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_MIX, mode); + ret = render->SetChannelMode(render, modeOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeOne); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_LEFT_MUTE, modeOne); + ret = render->SetChannelMode(render, modeSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeSec); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_RIGHT_MUTE, modeSec); + ret = render->SetChannelMode(render, modeTrd); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &modeTrd); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_BOTH_MUTE, modeTrd); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test SetChannelMode API via setting channel mode after render object is created +* @tc.number SUB_Audio_HDI_AudioRenderSetChannelMode_0003 +* @tc.desc Test SetChannelMode interface,return 0 if set channel mode after render object is created +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetChannelMode_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->SetChannelMode(render, mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test SetChannelMode API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderSetChannelMode_0004 +* @tc.desc Test SetChannelMode interface,return -1 if set the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderSetChannelMode_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *renderNull = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->SetChannelMode(renderNull, mode); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetChannelMode API via getting the channel mode after setting +* @tc.number SUB_Audio_HDI_AudioRenderGetChannelMode_0001 +* @tc.desc Test GetChannelMode interface,return 0 if getting the channel mode after setting +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetChannelMode_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->SetChannelMode(render, mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetChannelMode API via getting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetChannelMode_0002 +* @tc.desc Test GetChannelMode interface,return -1 if getting the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetChannelMode_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *renderNull = nullptr; + struct AudioRender *render = nullptr; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetChannelMode(renderNull, &mode); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetChannelMode API via getting the channel mode after the render object is created +* @tc.number SUB_Audio_HDI_AudioRenderGetChannelMode_0003 +* @tc.desc Test GetChannelMode interface,return 0 if getting the channel mode after the object is created +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetChannelMode_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + TestAudioManager* manager = {}; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetChannelMode(render, &mode); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderPosition API via legal input +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0001 +* @tc.desc Test GetRenderPosition interface,Returns 0 if get RenderPosition during playing. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)PlayAudioFile, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.render != nullptr) { + ret = audiopara.render->GetRenderPosition(audiopara.render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via get RenderPosition after the audio file is Paused and resumed +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0002 +* @tc.desc Test GetRenderPosition interface,Returns 0 if get RenderPosition after Pause and resume during playing +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int64_t timeExp = 0; + uint64_t frames = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)PlayAudioFile, &audiopara); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + sleep(1); + if (audiopara.render != nullptr) { + FrameStatus(0); + usleep(1000); + ret = audiopara.render->control.Pause((AudioHandle)(audiopara.render)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.render->GetRenderPosition(audiopara.render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + usleep(1000); + ret = audiopara.render->control.Resume((AudioHandle)(audiopara.render)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + FrameStatus(1); + ret = audiopara.render->GetRenderPosition(audiopara.render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + } + + ret = ThreadRelease(audiopara); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); +} +/** +* @tc.name Test GetRenderPosition API via get RenderPosition after the audio file is stopped +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0003 +* @tc.desc Test GetRenderPosition interface,Returns 0 if get RenderPosition after stop +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int64_t timeExp = 0; + uint64_t frames = 0; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0004 +* @tc.desc Test AudioRenderGetRenderPosition interface, return -1 if setting the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter =nullptr; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via setting the parameter render is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0005 +* @tc.desc Test AudioRenderGetRenderPosition interface, return -1 if setting the parameter render is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + struct AudioTimeStamp time = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(renderNull, &frames, &time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via setting the parameter frames is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0006 +* @tc.desc Test AudioRenderGetRenderPosition interface, return -1 if setting the parameter frames is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *framesNull = nullptr; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, framesNull, &time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via setting the parameter time is nullptr +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0007 +* @tc.desc Test AudioRenderGetRenderPosition interface, return -1 if setting the parameter time is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioTimeStamp *timeNull = nullptr; + + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetRenderPosition(render, &frames, timeNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetRenderPosition API via get RenderPosition continuously +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0008 +* @tc.desc Test AudioRenderGetRenderPosition interface, return 0 if the GetRenderPosition was called twice +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0008, Function | MediumTest | Level1) +{ + int32_t ret = -1; + int64_t timeExp = 0; + uint64_t frames = 0; + TestAudioManager* manager = {}; + struct AudioAdapter *adapter =nullptr; + struct AudioRender *render = nullptr; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + ASSERT_NE(GetAudioManager, nullptr); + manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderPosition API via define format to AUDIO_FORMAT_PCM_16_BIT +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0009 +* @tc.desc Test GetRenderPosition interface,return 0 if get framesize define format to AUDIO_FORMAT_PCM_16_BIT +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0009, Function | MediumTest | Level1) +{ + int32_t ret = -1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + enum AudioPortPin pins = PIN_OUT_SPEAKER; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + TestAudioManager* manager = GetAudioManager(); + ASSERT_NE(GetAudioManager, nullptr); + ret = AudioCreateRender(manager, pins, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 2; + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderPosition API via define format to AUDIO_FORMAT_PCM_24_BIT +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0010 +* @tc.desc Test GetRenderPosition interface,return 0 if get framesize define format to AUDIO_FORMAT_PCM_24_BIT +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0010, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + uint64_t channelCountExp = 2; + uint32_t sampleRateExp = 48000; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_24_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 2; + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderPosition API via define sampleRate and channelCount to different value +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0011 +* @tc.desc Test GetRenderPosition interface,return 0 if get framesize define channelCount as different values +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0011, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + uint32_t sampleRateExp = 48000; + uint64_t channelCountExp = 1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_16_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 1; + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(AUDIO_FORMAT_PCM_16_BIT, attrsValue.format); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetRenderPosition API via define sampleRate and channelCount to 1 +* @tc.number SUB_Audio_HDI_AudioRenderGetRenderPosition_0012 +* @tc.desc Test GetRenderPosition interface,return 0 if get framesize define channelCount to 1 +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_AudioRenderGetRenderPosition_0012, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioSampleAttributes attrs = {}; + struct AudioSampleAttributes attrsValue = {}; + struct AudioTimeStamp time = {.tvSec = 0, .tvNSec = 0}; + uint64_t channelCountExp = 1; + uint32_t sampleRateExp = 48000; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + InitAttrs(attrs); + attrs.type = AUDIO_IN_MEDIA; + attrs.interleaved = false; + attrs.format = AUDIO_FORMAT_PCM_24_BIT; + attrs.sampleRate = 48000; + attrs.channelCount = 1; + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.GetSampleAttributes(render, &attrsValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(AUDIO_FORMAT_PCM_24_BIT, attrsValue.format); + EXPECT_EQ(sampleRateExp, attrsValue.sampleRate); + EXPECT_EQ(channelCountExp, attrsValue.channelCount); + ret = AudioRenderStartAndOneFrame(render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->GetRenderPosition(render, &frames, &time); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((time.tvSec) * SECTONSEC + (time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via legal input +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0001 +* @tc.desc Test ReqMmapBuffer interface,return 0 if call ReqMmapBuffer interface sucessfully +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioSampleAttributes attrs = {}; + ASSERT_NE(GetAudioManager, nullptr); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + InitAttrs(attrs); + attrs.startThreshold = 0; + ret = render->attr.SetSampleAttributes(render, &attrs); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + fclose(fp); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is bigger than + the size of actual audio file +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0002 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsucessfully when setting the + incoming parameter reqSize is bigger than the size of actual audio file +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = reqSize + BUFFER_LENTH; + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + fclose(fp); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is smaller than + the size of actual audio file +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0003 +* @tc.desc Test ReqMmapBuffer interface,return 0 if call ReqMmapBuffer interface sucessfully when setting the + incoming parameter reqSize is smaller than the size of actual audio file +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = reqSize / 2; + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + fclose(fp); + if (ret == 0) { + munmap(desc.memoryAddress, reqSize); + } + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter reqSize is zero +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0003 +* @tc.desc Test ReqMmapBuffer interface,return -1 if call ReqMmapBuffer interface unsucessfully when setting the + incoming parameter reqSize is zero +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager *manager = GetAudioManager(); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + reqSize = 0; + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + fclose(fp); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via setting the incoming parameter memoryFd of desc is illegal +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0003 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsucessfully when setting the + incoming parameter memoryFd of desc is illegal +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + TestAudioManager *manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + desc.memoryFd = 1; + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + fclose(fp); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via the incoming parameter handle is nullptr +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0005 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsucessfully when setting the + incoming parameter handle is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0006, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)renderNull, reqSize, &desc); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + fclose(fp); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via the incoming parameter desc is nullptr +* @tc.number SUB_Audio_HDI_RenderReqMmapBuffer_0006 +* @tc.desc Test ReqMmapBuffer interface,return -3 if call ReqMmapBuffer interface unsucessfully when setting the + incoming parameter desc is nullptr +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderReqMmapBuffer_0007, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool isRender = true; + int32_t reqSize = 0; + struct AudioMmapBufferDescripter desc = {}; + struct AudioMmapBufferDescripter *descNull = nullptr; + struct AudioRender *render = nullptr; + struct AudioAdapter *adapter = nullptr; + ASSERT_NE(GetAudioManager, nullptr); + TestAudioManager* manager = GetAudioManager(); + FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+"); + ASSERT_NE(fp, nullptr); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + if (ret < 0 || render == nullptr) { + fclose(fp); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, render); + } + ret = InitMmapDesc(fp, desc, reqSize, isRender); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->control.Start((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, descNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + fclose(fp); + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test GetMmapPosition API via Getting position is normal in Before playing and Playing. +* @tc.number SUB_Audio_HDI_RenderGetMmapPosition_0001 +* @tc.desc Test GetMmapPosition interface,return 0 if Getting position successfully. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderGetMmapPosition_0001, Function | MediumTest | Level1) +{ + uint64_t frames = 0; + uint64_t framesRendering = 0; + uint64_t framesexpRender = 0; + int64_t timeExp = 0; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .pins = PIN_OUT_SPEAKER, + .path = LOW_LATENCY_AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + int32_t ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0 || audiopara.render == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.render); + } + InitAttrs(audiopara.attrs); + audiopara.attrs.startThreshold = 0; + ret = audiopara.render->attr.SetSampleAttributes(audiopara.render, &(audiopara.attrs)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_EQ(frames, INITIAL_VALUE); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)PlayMapAudioFile, &audiopara); + if (ret != 0) { + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + sleep(1); + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &framesRendering, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_GT(framesRendering, INITIAL_VALUE); + int64_t timeExprendering = (audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec); + void *result = nullptr; + pthread_join(audiopara.tids, &result); + EXPECT_EQ(AUDIO_HAL_SUCCESS, (intptr_t)result); + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &framesexpRender, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GE((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExprendering); + EXPECT_GE(framesexpRender, framesRendering); + audiopara.render->control.Stop((AudioHandle)audiopara.render); + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test GetMmapPosition API via SetSampleAttributes and Getting position is normal. +* @tc.number SUB_Audio_HDI_RenderGetMmapPosition_0002 +* @tc.desc Test GetMmapPosition interface,return 0 if Getting position successfully. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderGetMmapPosition_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + int64_t timeExp = 0; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = LOW_LATENCY_AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0 || audiopara.render == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.render); + } + InitAttrs(audiopara.attrs); + audiopara.attrs.format = AUDIO_FORMAT_PCM_24_BIT; + audiopara.attrs.channelCount = 1; + ret = audiopara.render->attr.SetSampleAttributes(audiopara.render, &(audiopara.attrs)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = pthread_create(&audiopara.tids, NULL, (THREAD_FUNC)PlayMapAudioFile, &audiopara); + if (ret != 0) { + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + } + + void *result = nullptr; + pthread_join(audiopara.tids, &result); + EXPECT_EQ(AUDIO_HAL_SUCCESS, (intptr_t)result); + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_GT((audiopara.time.tvSec) * SECTONSEC + (audiopara.time.tvNSec), timeExp); + EXPECT_GT(frames, INITIAL_VALUE); + audiopara.render->control.Stop((AudioHandle)audiopara.render); + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint frame is nullptr. +* @tc.number SUB_Audio_HDI_RenderGetMmapPosition_0003 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderGetMmapPosition_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t *frames = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = LOW_LATENCY_AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0 || audiopara.render == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.render); + } + + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint time is nullptr. +* @tc.number SUB_Audio_HDI_RenderGetMmapPosition_0004 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderGetMmapPosition_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + struct AudioTimeStamp *time = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = LOW_LATENCY_AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0 || audiopara.render == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.render); + } + + ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &frames, time); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +/** +* @tc.name Test ReqMmapBuffer API via inputtint render is nullptr. +* @tc.number SUB_Audio_HDI_RenderGetMmapPosition_0005 +* @tc.desc Test GetMmapPosition interface,return -3 if Error in incoming parameter. +*/ +HWTEST_F(AudioHdiRenderTest, SUB_Audio_HDI_RenderGetMmapPosition_0005, Function | MediumTest | Level1) +{ + int32_t ret = -1; + uint64_t frames = 0; + struct AudioRender *renderNull = nullptr; + struct PrepareAudioPara audiopara = { + .portType = PORT_OUT, .adapterName = ADAPTER_NAME_USB.c_str(), .self = this, .pins = PIN_OUT_SPEAKER, + .path = LOW_LATENCY_AUDIO_FILE.c_str() + }; + ASSERT_NE(GetAudioManager, nullptr); + audiopara.manager = GetAudioManager(); + ASSERT_NE(audiopara.manager, nullptr); + ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter, + &audiopara.render); + if (ret < 0 || audiopara.render == nullptr) { + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ASSERT_EQ(nullptr, audiopara.render); + } + + ret = audiopara.render->attr.GetMmapPosition(renderNull, &frames, &(audiopara.time)); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render); + audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter); +} +} \ No newline at end of file diff --git a/hdf/audio/hdi/render/src/audio_hdirender_volume_test.cpp b/hdf/audio/hdi/render/src/audio_hdirender_volume_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..927bf95404c93234b18d71faf4f4c0da2b59c863 --- /dev/null +++ b/hdf/audio/hdi/render/src/audio_hdirender_volume_test.cpp @@ -0,0 +1,769 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_hdi_common.h + * + * @brief Declares APIs for operations related to the audio render adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#include "audio_hdi_common.h" +#include "audio_hdirender_volume_test.h" + +using namespace std; +using namespace testing::ext; +using namespace HMOS::Audio; + +namespace { +const string ADAPTER_NAME_USB = "usb"; +const string ADAPTER_NAME_INTERNAL = "internal"; + +class AudioHdiRenderVolumeTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static TestAudioManager *(*GetAudioManager)(); + static void *handleSo; +#ifdef AUDIO_MPI_SO + static int32_t (*SdkInit)(); + static void (*SdkExit)(); + static void *sdkSo; +#endif +}; + +TestAudioManager *(*AudioHdiRenderVolumeTest::GetAudioManager)() = nullptr; +void *AudioHdiRenderVolumeTest::handleSo = nullptr; +#ifdef AUDIO_MPI_SO + int32_t (*AudioHdiRenderVolumeTest::SdkInit)() = nullptr; + void (*AudioHdiRenderVolumeTest::SdkExit)() = nullptr; + void *AudioHdiRenderVolumeTest::sdkSo = nullptr; +#endif + +void AudioHdiRenderVolumeTest::SetUpTestCase(void) +{ +#ifdef AUDIO_MPI_SO + char sdkResolvedPath[] = "//system/lib/libhdi_audio_interface_lib_render.z.so"; + sdkSo = dlopen(sdkResolvedPath, RTLD_LAZY); + if (sdkSo == nullptr) { + return; + } + SdkInit = (int32_t (*)())(dlsym(sdkSo, "MpiSdkInit")); + if (SdkInit == nullptr) { + return; + } + SdkExit = (void (*)())(dlsym(sdkSo, "MpiSdkExit")); + if (SdkExit == nullptr) { + return; + } + SdkInit(); +#endif + char absPath[PATH_MAX] = {0}; + if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) { + return; + } + handleSo = dlopen(absPath, RTLD_LAZY); + if (handleSo == nullptr) { + return; + } + GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str())); + if (GetAudioManager == nullptr) { + return; + } +} + +void AudioHdiRenderVolumeTest::TearDownTestCase(void) +{ +#ifdef AUDIO_MPI_SO + SdkExit(); + if (sdkSo != nullptr) { + dlclose(sdkSo); + sdkSo = nullptr; + } + if (SdkInit != nullptr) { + SdkInit = nullptr; + } + if (SdkExit != nullptr) { + SdkExit = nullptr; + } +#endif + if (handleSo != nullptr) { + dlclose(handleSo); + handleSo = nullptr; + } + if (GetAudioManager != nullptr) { + GetAudioManager = nullptr; + } +} + +void AudioHdiRenderVolumeTest::SetUp(void) {} +void AudioHdiRenderVolumeTest::TearDown(void) {} + +/** +* @tc.name Test RenderGetGainThreshold API via legal input +* @tc.number SUB_Audio_HDI_RenderGetGainThreshold_0001 +* @tc.desc Test RenderGetGainThreshold interface,return 0 if the GetGainThreshold is obtained successfully +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGainThreshold_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetGainThreshold((AudioHandle)render, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(min, GAIN_MIN); + EXPECT_EQ(max, GAIN_MAX); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGainThreshold API via set the parameter render to nullptr +* @tc.number SUB_Audio_HDI_RenderGetGainThreshold_0002 +* @tc.desc Test RenderGetGainThreshold interface, return -1 if set render to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGainThreshold_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetGainThreshold((AudioHandle)renderNull, &min, &max); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGainThreshold API via set the parameter min to nullptr +* @tc.number SUB_Audio_HDI_RenderGetGainThreshold_0003 +* @tc.desc Test RenderGetGainThreshold interface, return -1 if set min to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGainThreshold_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float max = 0; + float *minNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetGainThreshold((AudioHandle)render, minNull, &max); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGainThreshold API via set the parameter max to nullptr +* @tc.number SUB_Audio_HDI_RenderGetGainThreshold_0004 +* @tc.desc Test RenderGetGainThreshold interface, return -1 if set max to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGainThreshold_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float *maxNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGainThreshold(render, &min, maxNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetGain API via legal input +* @tc.number SUB_Audio_HDI_RenderSetGain_0001 +* @tc.desc Test RenderSetGain interface,return 0 if Set gain to normal value, maximum or minimum and get success +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderSetGain_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGainThreshold((AudioHandle)render, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + float gain = 10.8; + float gainMax = max; + float gainMin = min; + float gainExpc = 10; + float gainMaxExpc = max; + float gainMinExpc = min; + ret = render->volume.SetGain(render, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain(render, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainExpc, gain); + + ret = render->volume.SetGain(render, gainMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain(render, &gainMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainMaxExpc, gainMax); + + ret = render->volume.SetGain(render, gainMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain(render, &gainMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainMinExpc, gainMin); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetGain API via set gain to the boundary value +* @tc.number SUB_Audio_HDI_RenderSetGain_0002 +* @tc.desc Test RenderSetGain interface,return -1 if Set gain to exceed the boundary value +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderSetGain_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGainThreshold((AudioHandle)render, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + float gainOne = max+1; + float gainSec = min-1; + ret = render->volume.SetGain(render, gainOne); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + ret = render->volume.SetGain(render, gainSec); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetGain API via set gain to exception type +* @tc.number SUB_Audio_HDI_RenderSetGain_0003 +* @tc.desc Test RenderSetGain interface,return -1 if set gain to exception type +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderSetGain_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + char gain = 'a'; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetGain(render, gain); + EXPECT_EQ(AUDIO_HAL_ERR_INTERNAL, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderSetGain API via set the parameter render to nullptr +* @tc.number SUB_Audio_HDI_RenderSetGain_0004 +* @tc.desc Test RenderSetGain interface, return -1 if set render to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderSetGain_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gain = 1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetGain((AudioHandle)renderNull, gain); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGain API via legal input +* @tc.number SUB_Audio_HDI_RenderGetGain_0001 +* @tc.desc Test RenderGetGain interface,return 0 if the RenderGetGain was obtained successfully +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGain_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float min = 0; + float max = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGainThreshold((AudioHandle)render, &min, &max); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + float gain = min+1; + float gainValue = min+1; + ret = render->volume.SetGain(render, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain(render, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gainValue, gain); + + render->control.Stop((AudioHandle)render); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGain API via set the parameter render to nullptr +* @tc.number SUB_Audio_HDI_RenderGetGain_0002 +* @tc.desc Test RenderGetGain interface, return -1 if get gain set render to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGain_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gain = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetGain((AudioHandle)renderNull, &gain); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGain API via legal input in difference scenes +* @tc.number SUB_Audio_HDI_RenderGetGain_0003 +* @tc.desc Test RenderGetGainThreshold interface, return 0 if get gain before start successfully +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGain_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float gain = GAIN_MAX-1; + float gainOne = GAIN_MAX-1; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetGain(render, gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain(render, &gain); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(gain, gainOne); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test RenderGetGain API via set the parameter gain to nullptr +* @tc.number SUB_Audio_HDI_RenderGetGain_0004 +* @tc.desc Test RenderGetGain interface, return -1 if get gain set gain to nullptr +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_RenderGetGain_0004, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float *gainNull = nullptr; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetGain((AudioHandle)render, gainNull); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetMute API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetMute_0001 +* @tc.desc Test AudioRenderSetMute interface , return 0 if the audiorender object sets mute successfully. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetMute_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteFalse = false; + bool muteTrue = true; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetMute(render, muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetMute(render, &muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(false, muteFalse); + + ret = render->volume.SetMute(render, muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetMute(render, &muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(true, muteTrue); + + muteTrue = false; + ret = render->volume.SetMute(render, muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_FALSE(muteTrue); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetMute API via setting the incoming parameter render is empty . +* @tc.number SUB_Audio_HDI_AudioRenderSetMute_0002 +* @tc.desc Test AudioRenderSetMute interface, return -1 if the incoming parameter render is empty. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetMute_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool mute = true; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.SetMute(renderNull, mute); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetMute API,when the parameter mutevalue equals 2. +* @tc.number SUB_Audio_HDI_AudioRenderSetMute_0003 +* @tc.desc Test AudioRenderSetMute interface and set the parameter mutevalue with 2. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetMute_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteValue = 2; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetMute(render, muteValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetMute(render, &muteValue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(true, muteValue); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetMute API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderGetMute_0001 +* @tc.desc Test AudioRenderGetMute interface , return 0 if the audiocapture gets mute successfully. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderGetMute_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteTrue = true; + bool muteFalse = false; + bool defaultmute = true; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetMute(render, &muteTrue); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(muteTrue, defaultmute); + + ret = render->volume.SetMute(render, muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.GetMute(render, &muteFalse); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_FALSE(muteFalse); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test interface AudioRenderGetMute when incoming parameter render is empty. +* @tc.number SUB_Audio_HDI_AudioRenderGetMute_0002 +* @tc.desc Test AudioRenderGetMute interface, return -1 if the incoming parameter render is empty. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderGetMute_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + bool muteTrue = true; + bool muteFalse = false; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetMute(renderNull, &muteTrue); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->volume.GetMute(renderNull, &muteFalse); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->volume.GetMute(render, nullptr); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetVolume API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderSetVolume_0001 +* @tc.desc Test AudioRenderSetVolume interface , return 0 if the audiocapture sets volume successfully. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetVolume_0001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volumeInit = 0.20; + float volumeInitExpc = 0.20; + float volumeLow = 0.10; + float volumeLowExpc = 0.10; + float volumeMid = 0.50; + float volumeMidExpc = 0.50; + float volumeHigh = 0.80; + float volumeHighExpc = 0.80; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetVolume(render, volumeInit); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeInit); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeInitExpc, volumeInit); + ret = render->volume.SetVolume(render, volumeLow); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeLow); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeLowExpc, volumeLow); + ret = render->volume.SetVolume(render, volumeMid); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeMid); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMidExpc, volumeMid); + ret = render->volume.SetVolume(render, volumeHigh); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeHigh); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeHighExpc, volumeHigh); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetVolume,when volume is set maximum value or minimum value. +* @tc.number SUB_Audio_HDI_AudioRenderSetVolume_0002 +* @tc.desc Test AudioRenderSetVolume,return 0 if volume is set maximum value or minimum value. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetVolume_0002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volumeMin = 0; + float volumeMinExpc = 0; + float volumeMax = 1.0; + float volumeMaxExpc = 1.0; + float volumeMinBoundary = -1; + float volumeMaxBoundary = 1.01; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.SetVolume(render, volumeMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeMin); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMinExpc, volumeMin); + + ret = render->volume.SetVolume(render, volumeMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volumeMax); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeMaxExpc, volumeMax); + + ret = render->volume.SetVolume(render, volumeMinBoundary); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + ret = render->volume.SetVolume(render, volumeMaxBoundary); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderSetVolume,when incoming parameter render is empty. +* @tc.number SUB_Audio_HDI_AudioRenderSetVolume_0003 +* @tc.desc Test AudioRenderSetVolume,return -1 when incoming parameter render is empty. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderSetVolume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.SetVolume(renderNull, volume); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetVolume API via legal input. +* @tc.number SUB_Audio_HDI_AudioRenderGetVolume_001 +* @tc.desc Test AudioRenderGetVolume interface , return 0 if the audiocapture is get successful. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderGetVolume_001, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.30; + float volumeDefault = 0.30; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetVolume(render, volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(volumeDefault, volume); + + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetVolume when when capturing is in progress. +* @tc.number SUB_Audio_HDI_AudioRenderGetVolume_002. +* @tc.desc Test AudioRenderGetVolume,return 0 when when capturing is in progress. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderGetVolume_002, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.30; + float defaultVolume = 0.30; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateStartRender(manager, &render, &adapter, ADAPTER_NAME_USB); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + + ret = render->volume.SetVolume(render, volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(render, &volume); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + EXPECT_EQ(defaultVolume, volume); + + ret = render->control.Stop((AudioHandle)render); + EXPECT_EQ(AUDIO_HAL_SUCCESS, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +/** +* @tc.name Test AudioRenderGetVolume,when incoming parameter render is empty. +* @tc.number SUB_Audio_HDI_AudioRenderGetVolume_0003 +* @tc.desc Test AudioRenderGetVolume,return -1 when incoming parameter render is empty. +*/ +HWTEST_F(AudioHdiRenderVolumeTest, SUB_Audio_HDI_AudioRenderGetVolume_0003, Function | MediumTest | Level1) +{ + int32_t ret = -1; + float volume = 0.3; + struct AudioAdapter *adapter = nullptr; + struct AudioRender *render = nullptr; + struct AudioRender *renderNull = nullptr; + ASSERT_NE(nullptr, GetAudioManager); + TestAudioManager* manager = GetAudioManager(); + ret = AudioCreateRender(manager, PIN_OUT_SPEAKER, ADAPTER_NAME_USB, &adapter, &render); + ASSERT_EQ(AUDIO_HAL_SUCCESS, ret); + ret = render->volume.GetVolume(renderNull, &volume); + EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret); + adapter->DestroyRender(adapter, render); + manager->UnloadAdapter(manager, adapter); +} +} \ No newline at end of file