!610 【master】增加audio idl用例

Merge pull request !610 from 王倩56/0410
This commit is contained in:
openharmony_ci 2023-04-11 02:11:55 +00:00 committed by Gitee
commit f7dd66f772
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 2442 additions and 4 deletions

View File

@ -23,11 +23,10 @@ group("HatsHdfAudioTest") {
}
if (is_standard_system) {
if (xts_hats_rich == false) {
deps = [ "hdi:audio_hdi" ]
deps = [ "idl:hdi_base_common" ]
} else {
deps = [ "idl:hdi_base_common" ]
}
# else {
# deps = [ "client_advance:HdiClientAdvance" ]
# }
}
}
###############################################################################

29
hdf/audio/idl/BUILD.gn Normal file
View File

@ -0,0 +1,29 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//test/xts/tools/build/suite.gni")
group("hdi_base_common") {
if (!defined(ohos_lite)) {
testonly = true
}
deps = [
"common/adapter:HatsHdfAudioIdlAdapterTest",
"common/capture:HatsHdfAudioIdlCaptureTest",
"common/manager:HatsHdfAudioIdlManagerTest",
"common/render:HatsHdfAudioIdlRenderTest",
]
}

View File

@ -0,0 +1,39 @@
# Copyright (c) 2021-2022 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/hdf_core/adapter/uhdf2/uhdf.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/audio"
ohos_moduletest_suite("HatsHdfAudioIdlAdapterTest") {
module_out_path = module_output_path
sources = [ "src/audio_adapter_common_test.cpp" ]
configs = [ ":audio_idl_adapter" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
external_deps = [
"c_utils:utils",
"drivers_interface_audio:audio_idl_headers",
"drivers_interface_audio:libaudio_proxy_1.0",
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "hdf"
part_name = "drivers_peripheral_audio"
}
config("audio_idl_adapter") {
include_dirs = []
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfAudioIdlAdapterTest->/data/local/tmp/HatsHdfAudioIdlAdapterTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfAudioIdlAdapterTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfAudioIdlAdapterTest Tests"
}

View File

@ -0,0 +1,454 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <climits>
#include <cstring>
#include <gtest/gtest.h>
#include "hdf_dlist.h"
#include "osal_mem.h"
#include "v1_0/iaudio_adapter.h"
#include "v1_0/iaudio_manager.h"
using namespace std;
using namespace testing::ext;
#define AUDIO_CHANNELCOUNT 2
#define AUDIO_SAMPLE_RATE_48K 48000
#define DEEP_BUFFER_RENDER_PERIOD_SIZE 4096
#define INT_32_MAX 0x7fffffff
#define PCM_16_BIT 16
#define PCM_8_BIT 8
namespace {
static const uint32_t g_audioAdapterNumMax = 5;
const int32_t AUDIO_ADAPTER_BUF_TEST = 1024;
class HdfAudioUtAdapterTest : public testing::Test {
public:
struct IAudioManager *manager_ = nullptr;
struct IAudioAdapter *adapter_ = nullptr;
struct AudioAdapterDescriptor *adapterDescs_ = nullptr;
uint32_t renderId_ = 0;
uint32_t captureId_ = 0;
virtual void SetUp();
virtual void TearDown();
void InitAttrs(struct AudioSampleAttributes &attrs);
void InitDevDesc(struct AudioDeviceDescriptor &devDesc);
void AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
};
void HdfAudioUtAdapterTest::AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
{
if (dataBlock == nullptr) {
return;
}
if (dataBlock->adapterName != nullptr) {
OsalMemFree(dataBlock->adapterName);
dataBlock->adapterName = nullptr;
}
if (dataBlock->ports != nullptr) {
OsalMemFree(dataBlock->ports);
}
if (freeSelf) {
OsalMemFree(dataBlock);
}
}
void HdfAudioUtAdapterTest::ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
{
if ((descsLen > 0) && (descs != nullptr) && ((*descs) != nullptr)) {
for (uint32_t i = 0; i < descsLen; i++) {
AudioAdapterDescriptorFree(&(*descs)[i], false);
}
OsalMemFree(*descs);
*descs = nullptr;
}
}
void HdfAudioUtAdapterTest::InitAttrs(struct AudioSampleAttributes &attrs)
{
attrs.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
attrs.channelCount = AUDIO_CHANNELCOUNT;
attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
attrs.interleaved = 1;
attrs.type = AUDIO_IN_MEDIA;
attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE;
attrs.frameSize = PCM_16_BIT * attrs.channelCount / PCM_8_BIT;
attrs.isBigEndian = false;
attrs.isSignedData = true;
attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.frameSize);
attrs.stopThreshold = INT_32_MAX;
}
void HdfAudioUtAdapterTest::InitDevDesc(struct AudioDeviceDescriptor &devDesc)
{
ASSERT_NE(adapterDescs_, nullptr);
ASSERT_NE(adapterDescs_->ports, nullptr);
for (uint32_t index = 0; index < adapterDescs_->portsLen; index++) {
if (adapterDescs_->ports[index].dir == PORT_OUT) {
devDesc.portId = adapterDescs_->ports[index].portId;
return;
}
}
}
void HdfAudioUtAdapterTest::SetUp()
{
uint32_t size = g_audioAdapterNumMax;
manager_ = IAudioManagerGet(false);
ASSERT_NE(manager_, nullptr);
adapterDescs_ = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
ASSERT_NE(adapterDescs_, nullptr);
ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
if (size > g_audioAdapterNumMax) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ASSERT_LT(size, g_audioAdapterNumMax);
}
if (manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_) != HDF_SUCCESS) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ASSERT_TRUE(false);
}
if (adapter_ == nullptr) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ASSERT_TRUE(false);
}
}
void HdfAudioUtAdapterTest::TearDown()
{
ASSERT_NE(manager_, nullptr);
ASSERT_NE(adapter_, nullptr);
manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
adapter_ = nullptr;
IAudioManagerRelease(manager_, false);
manager_ = nullptr;
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterInitAllPortsNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->InitAllPorts(nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterInitAllPortsParaIsvalid001, TestSize.Level1)
{
EXPECT_EQ(HDF_SUCCESS, adapter_->InitAllPorts(adapter_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->CreateRender(nullptr, nullptr, nullptr, nullptr, &renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderNull002, TestSize.Level1)
{
struct IAudioRender *render = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
struct AudioSampleAttributes attrs = {};
EXPECT_NE(HDF_SUCCESS, adapter_->CreateRender(nullptr, &devicedesc, &attrs, &render, &renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderInvalid001, TestSize.Level1)
{
struct IAudioRender *render = nullptr;
struct AudioSampleAttributes attrs = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateRender(adapter_, nullptr, &attrs, &render, &renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderInvalid002, TestSize.Level1)
{
struct IAudioRender *render = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateRender(adapter_, &devicedesc, nullptr, &render, &renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderIsvalid001, TestSize.Level1)
{
struct IAudioRender *render = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
struct AudioSampleAttributes attrs = {};
InitDevDesc(devicedesc);
devicedesc.desc = const_cast<char*>("primary");
devicedesc.pins = PIN_OUT_SPEAKER;
InitAttrs(attrs);
attrs.silenceThreshold = 0;
attrs.streamId = 0;
int32_t ret = adapter_->CreateRender(adapter_, &devicedesc, &attrs, &render, &renderId_);
if (ret != HDF_SUCCESS) {
attrs.format = AUDIO_FORMAT_TYPE_PCM_32_BIT;
ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devicedesc, &attrs, &render, &renderId_));
}
EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyRender(adapter_, renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyRenderNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->DestroyRender(nullptr, renderId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->CreateCapture(nullptr, nullptr, nullptr, nullptr, &captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureNull002, TestSize.Level1)
{
struct IAudioCapture *capture = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
struct AudioSampleAttributes attrs = {};
EXPECT_NE(HDF_SUCCESS, adapter_->CreateCapture(nullptr, &devicedesc, &attrs, &capture, &captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureInvalid001, TestSize.Level1)
{
struct IAudioCapture *capture = nullptr;
struct AudioSampleAttributes attrs = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateCapture(adapter_, nullptr, &attrs, &capture, &captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureInvalid002, TestSize.Level1)
{
struct IAudioCapture *capture = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateCapture(adapter_, &devicedesc, nullptr, &capture, &captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureIsvalid001, TestSize.Level1)
{
struct IAudioCapture *capture = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
struct AudioSampleAttributes attrs = {};
InitDevDesc(devicedesc);
devicedesc.desc = const_cast<char*>("primary");
devicedesc.pins = PIN_IN_MIC;
InitAttrs(attrs);
attrs.silenceThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE;
EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devicedesc, &attrs, &capture, &captureId_));
EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyCaptureNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->DestroyCapture(nullptr, captureId_));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->GetPortCapability(nullptr, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityNull002, TestSize.Level1)
{
struct AudioPort port = {};
struct AudioPortCapability capability = {};
EXPECT_NE(HDF_SUCCESS, adapter_->GetPortCapability(nullptr, &port, &capability));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityInvalid001, TestSize.Level1)
{
struct AudioPortCapability capability = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPortCapability(adapter_, nullptr, &capability));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityInvalid002, TestSize.Level1)
{
struct AudioPort port = {};
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPortCapability(adapter_, &port, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityIsvalid001, TestSize.Level1)
{
struct AudioPort port = {};
struct AudioPortCapability capability = {};
port.dir = PORT_OUT;
port.portId = 0;
port.portName = const_cast<char*>("primary");
int32_t ret = adapter_->GetPortCapability(adapter_, &port, &capability);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeNull001, TestSize.Level1)
{
enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
EXPECT_NE(HDF_SUCCESS, adapter_->SetPassthroughMode(nullptr, nullptr, mode));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeNull002, TestSize.Level1)
{
struct AudioPort port = {};
enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
EXPECT_NE(HDF_SUCCESS, adapter_->SetPassthroughMode(nullptr, &port, mode));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeInvalid001, TestSize.Level1)
{
enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->SetPassthroughMode(adapter_, nullptr, mode));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeIsvalid001, TestSize.Level1)
{
struct AudioPort port = {};
port.dir = PORT_OUT;
port.portId = 0;
port.portName = const_cast<char*>("primary");
enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
int32_t ret = adapter_->SetPassthroughMode(adapter_, &port, mode);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->GetPassthroughMode(nullptr, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeNull002, TestSize.Level1)
{
struct AudioPort port = {};
enum AudioPortPassthroughMode mode;
EXPECT_NE(HDF_SUCCESS, adapter_->GetPassthroughMode(nullptr, &port, &mode));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeInvalid001, TestSize.Level1)
{
enum AudioPortPassthroughMode mode;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPassthroughMode(adapter_, nullptr, &mode));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeIsvalid001, TestSize.Level1)
{
struct AudioPort port = {};
port.dir = PORT_OUT;
port.portId = 0;
port.portName = const_cast<char*>("primary");
enum AudioPortPassthroughMode mode;
int32_t ret = adapter_->GetPassthroughMode(adapter_, &port, &mode);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->GetDeviceStatus(nullptr, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusNull002, TestSize.Level1)
{
struct AudioDeviceStatus status = {};
EXPECT_NE(HDF_SUCCESS, adapter_->GetDeviceStatus(nullptr, &status));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusInvalid001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetDeviceStatus(adapter_, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusIsvalid001, TestSize.Level1)
{
struct AudioDeviceStatus status = {};
EXPECT_EQ(HDF_SUCCESS, adapter_->GetDeviceStatus(adapter_, &status));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetMicMuteNull001, TestSize.Level1)
{
bool mute = false;
EXPECT_NE(HDF_SUCCESS, adapter_->SetMicMute(nullptr, mute));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetMicMuteIsvalid001, TestSize.Level1)
{
bool mute = false;
int32_t ret = adapter_->SetMicMute(adapter_, mute);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteNull001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, adapter_->GetMicMute(nullptr, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteNull002, TestSize.Level1)
{
bool mute = false;
EXPECT_NE(HDF_SUCCESS, adapter_->GetMicMute(nullptr, &mute));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteIsvalid001, TestSize.Level1)
{
bool mute = false;
int32_t ret = adapter_->GetMicMute(adapter_, &mute);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetVoiceVolumeNull001, TestSize.Level1)
{
float volume = 0;
EXPECT_NE(HDF_SUCCESS, adapter_->SetVoiceVolume(nullptr, volume));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetVoiceVolumeIsvalid001, TestSize.Level1)
{
float volume = 0;
int32_t ret = adapter_->SetVoiceVolume(adapter_, volume);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsNull001, TestSize.Level1)
{
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
EXPECT_NE(HDF_SUCCESS, adapter_->SetExtraParams(nullptr, key, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsNull002, TestSize.Level1)
{
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
char condition[AUDIO_ADAPTER_BUF_TEST];
char value[AUDIO_ADAPTER_BUF_TEST];
EXPECT_NE(HDF_SUCCESS, adapter_->SetExtraParams(nullptr, key, condition, value));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsIsvalid001, TestSize.Level1)
{
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_LOWPOWER;
char condition[AUDIO_ADAPTER_BUF_TEST];
const char *value = "sup_sampling_rates=4800;sup_channels=1;sup_formats=2;";
int32_t ret = adapter_->SetExtraParams(adapter_, key, condition, value);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetExtraParamsNull001, TestSize.Level1)
{
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
EXPECT_NE(HDF_SUCCESS, adapter_->GetExtraParams(nullptr, key, nullptr, nullptr, valueLen));
}
HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetExtraParamsNull002, TestSize.Level1)
{
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
char condition[AUDIO_ADAPTER_BUF_TEST];
char value[AUDIO_ADAPTER_BUF_TEST];
uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
EXPECT_NE(HDF_SUCCESS, adapter_->GetExtraParams(nullptr, key, condition, value, valueLen));
}
}

View File

@ -0,0 +1,39 @@
# Copyright (c) 2021-2022 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/hdf_core/adapter/uhdf2/uhdf.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/audio"
ohos_moduletest_suite("HatsHdfAudioIdlCaptureTest") {
module_out_path = module_output_path
sources = [ "src/audio_capture_common_test.cpp" ]
configs = [ ":audio_idl_capture" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
external_deps = [
"c_utils:utils",
"drivers_interface_audio:audio_idl_headers",
"drivers_interface_audio:libaudio_proxy_1.0",
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "hdf"
part_name = "drivers_peripheral_audio"
}
config("audio_idl_capture") {
include_dirs = []
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfAudioIdlCaptureTest->/data/local/tmp/HatsHdfAudioIdlCaptureTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfAudioIdlCaptureTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfAudioIdlCaptureTest Tests"
}

View File

@ -0,0 +1,783 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <climits>
#include "osal_mem.h"
#include "v1_0/iaudio_capture.h"
#include "v1_0/iaudio_manager.h"
using namespace std;
using namespace testing::ext;
namespace {
static const uint32_t MAX_AUDIO_ADAPTER_NUM = 5;
const int BUFFER_LENTH = 1024 * 16;
const int DEEP_BUFFER_CAPTURE_PERIOD_SIZE = 4 * 1024;
const int DEFAULT_BUFFER_SIZE = 16384;
const float HALF_OF_MAX_VOLUME = 0.5;
const int MOVE_LEFT_NUM = 8;
const int TEST_SAMPLE_RATE_MASK_48000 = 48000;
const int TEST_CHANNEL_COUNT = 2;
class AudioUtCaptureTest : public testing::Test {
public:
struct IAudioManager *manager_ = nullptr;;
struct IAudioAdapter *adapter_ = nullptr;
struct IAudioCapture *capture_ = nullptr;
uint32_t captureId_ = 0;
char *devDescriptorName_ = nullptr;
struct AudioAdapterDescriptor *adapterDescs_ = nullptr;
virtual void SetUp();
virtual void TearDown();
uint64_t GetCaptureBufferSize();
void InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc);
void InitCaptureAttrs(struct AudioSampleAttributes &attrs);
void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
};
/* common method for capture ceate */
uint64_t AudioUtCaptureTest::GetCaptureBufferSize()
{
int32_t ret = HDF_SUCCESS;
uint64_t frameSize = 0;
uint64_t frameCount = 0;
uint64_t bufferSize = 0;
if (capture_ == nullptr) {
return DEFAULT_BUFFER_SIZE;
}
ret = capture_->GetFrameSize(capture_, &frameSize);
if (ret != HDF_SUCCESS) {
return DEFAULT_BUFFER_SIZE;
}
ret = capture_->GetFrameCount(capture_, &frameCount);
if (ret != HDF_SUCCESS) {
return DEFAULT_BUFFER_SIZE;
}
bufferSize = frameCount * frameSize;
if (bufferSize == 0) {
bufferSize = DEFAULT_BUFFER_SIZE;
}
return bufferSize;
}
void AudioUtCaptureTest::InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc)
{
devDesc.pins = (enum AudioPortPin)PIN_IN_MIC;
devDescriptorName_ = strdup("cardname");
devDesc.desc = devDescriptorName_;
ASSERT_NE(adapterDescs_, nullptr);
ASSERT_NE(adapterDescs_->ports, nullptr);
for (uint32_t index = 0; index < adapterDescs_->portsLen; index++) {
if (adapterDescs_->ports[index].dir == PORT_IN) {
devDesc.portId = adapterDescs_->ports[index].portId;
return;
}
}
}
void AudioUtCaptureTest::InitCaptureAttrs(struct AudioSampleAttributes &attrs)
{
attrs.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
attrs.channelCount = TEST_CHANNEL_COUNT;
attrs.sampleRate = TEST_SAMPLE_RATE_MASK_48000;
attrs.interleaved = 0;
attrs.type = AUDIO_IN_MEDIA;
attrs.period = DEEP_BUFFER_CAPTURE_PERIOD_SIZE;
attrs.frameSize = AUDIO_FORMAT_TYPE_PCM_16_BIT * TEST_CHANNEL_COUNT / MOVE_LEFT_NUM;
attrs.isBigEndian = false;
attrs.isSignedData = true;
attrs.startThreshold = DEEP_BUFFER_CAPTURE_PERIOD_SIZE / (attrs.format * attrs.channelCount / MOVE_LEFT_NUM);
attrs.stopThreshold = INT_MAX;
attrs.silenceThreshold = BUFFER_LENTH;
}
void AudioUtCaptureTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
{
if (dataBlock == nullptr) {
return;
}
if (dataBlock->adapterName != nullptr) {
OsalMemFree(dataBlock->adapterName);
dataBlock->adapterName = nullptr;
}
if (dataBlock->ports != nullptr) {
OsalMemFree(dataBlock->ports);
}
if (freeSelf) {
OsalMemFree(dataBlock);
}
}
void AudioUtCaptureTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
{
if ((descsLen > 0) && (descs != nullptr) && ((*descs) != nullptr)) {
for (uint32_t i = 0; i < descsLen; i++) {
FreeAdapterElements(&(*descs)[i], false);
}
OsalMemFree(*descs);
*descs = nullptr;
}
}
void AudioUtCaptureTest::SetUp()
{
uint32_t size = MAX_AUDIO_ADAPTER_NUM;
struct AudioDeviceDescriptor devDesc = {};
struct AudioSampleAttributes attrs = {};
manager_ = IAudioManagerGet(false);
ASSERT_NE(manager_, nullptr);
adapterDescs_ = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (MAX_AUDIO_ADAPTER_NUM));
ASSERT_NE(adapterDescs_, nullptr);
EXPECT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
if (size > MAX_AUDIO_ADAPTER_NUM) {
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ASSERT_LT(size, MAX_AUDIO_ADAPTER_NUM);
}
EXPECT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_));
if (adapter_ == nullptr) {
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
EXPECT_NE(adapter_, nullptr);
}
InitCaptureDevDesc(devDesc);
InitCaptureAttrs(attrs);
EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devDesc, &attrs, &capture_, &captureId_));
if (capture_ == nullptr) {
(void)manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
}
ASSERT_NE(capture_, nullptr);
}
void AudioUtCaptureTest::TearDown()
{
ASSERT_NE(devDescriptorName_, nullptr);
free(devDescriptorName_);
ASSERT_NE(capture_, nullptr);
EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
ASSERT_NE(manager_, nullptr);
EXPECT_EQ(HDF_SUCCESS, manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName));
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
IAudioManagerRelease(manager_, false);
}
/* capture frame cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureFrame001, TestSize.Level1)
{
uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
uint64_t requestBytes = frameLen;
ASSERT_NE(capture_->CaptureFrame, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
int8_t *frame = (int8_t *)calloc(1, frameLen);
EXPECT_NE(nullptr, frame);
ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
EXPECT_EQ(ret, HDF_SUCCESS);
capture_->Stop(capture_);
if (frame != nullptr) {
free(frame);
frame = nullptr;
}
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureFrameExceptions001, TestSize.Level1)
{
uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
uint64_t requestBytes = frameLen;
ASSERT_NE(capture_->CaptureFrame, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
int8_t *frame = (int8_t *)calloc(1, frameLen);
EXPECT_NE(nullptr, frame);
EXPECT_NE(HDF_SUCCESS, capture_->CaptureFrame(nullptr, nullptr, nullptr, nullptr));
EXPECT_NE(HDF_SUCCESS, capture_->CaptureFrame(capture_, frame, nullptr, nullptr));
EXPECT_NE(HDF_SUCCESS, capture_->CaptureFrame(capture_, frame, &frameLen, nullptr));
EXPECT_NE(HDF_SUCCESS, capture_->CaptureFrame(nullptr, frame, &frameLen, &requestBytes));
if (frame != nullptr) {
free(frame);
frame = nullptr;
}
}
/* capture getposition cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioGetCapturePosition001, TestSize.Level1)
{
uint64_t frames;
struct AudioTimeStamp time;
uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
uint64_t requestBytes = frameLen;
ASSERT_NE(capture_->CaptureFrame, nullptr);
ASSERT_NE(capture_->GetCapturePosition, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
int8_t *frame = (int8_t *)calloc(1, frameLen);
EXPECT_NE(nullptr, frame);
ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->GetCapturePosition(capture_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
capture_->Stop(capture_);
if (frame != nullptr) {
free(frame);
frame = nullptr;
}
}
HWTEST_F(AudioUtCaptureTest, HdfAudioGetCapturePositionExceptions001, TestSize.Level1)
{
int32_t ret;
uint64_t frames;
struct AudioTimeStamp time;
ASSERT_NE(capture_->GetCapturePosition, nullptr);
ret = capture_->GetCapturePosition(capture_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->GetCapturePosition(capture_, nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetCapturePosition(capture_, &frames, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/**
* @brief from here starts the control tests
*/
/* capture start cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureStart001, TestSize.Level1)
{
ASSERT_NE(capture_->Start, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureException001, TestSize.Level1)
{
ASSERT_NE(capture_->Start, nullptr);
int32_t ret = capture_->Start(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture stop cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureStop001, TestSize.Level1)
{
ASSERT_NE(capture_->Start, nullptr);
ASSERT_NE(capture_->Stop, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->Stop(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureStopException001, TestSize.Level1)
{
ASSERT_NE(capture_->Stop, nullptr);
int32_t ret = capture_->Stop(capture_);
EXPECT_NE(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureStopException002, TestSize.Level1)
{
ASSERT_NE(capture_->Stop, nullptr);
int32_t ret = capture_->Stop(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture pause cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCapturePause001, TestSize.Level1)
{
ASSERT_NE(capture_->Pause, nullptr);
ASSERT_NE(capture_->Start, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->Pause(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCapturePauseException001, TestSize.Level1)
{
ASSERT_NE(capture_->Pause, nullptr);
int32_t ret = capture_->Pause(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCapturePauseException002, TestSize.Level1)
{
ASSERT_NE(capture_->Pause, nullptr);
ASSERT_NE(capture_->Start, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->Pause(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->Pause(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
/* capture resume cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureResume001, TestSize.Level1)
{
ASSERT_NE(capture_->Pause, nullptr);
ASSERT_NE(capture_->Resume, nullptr);
ASSERT_NE(capture_->Start, nullptr);
ASSERT_NE(capture_->Stop, nullptr);
int32_t ret = capture_->Start(capture_);
ASSERT_EQ(ret, HDF_SUCCESS);
ret = capture_->Pause(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->Resume(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->Stop(capture_);
ASSERT_EQ(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureResumeException001, TestSize.Level1)
{
ASSERT_NE(capture_->Resume, nullptr);
int32_t ret = capture_->Resume(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureResumeException002, TestSize.Level1)
{
ASSERT_NE(capture_->Resume, nullptr);
int32_t ret = capture_->Resume(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture flush cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureFlush001, TestSize.Level1)
{
ASSERT_NE(capture_->Flush, nullptr);
int32_t ret = capture_->Flush(capture_);
EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureFlushException001, TestSize.Level1)
{
ASSERT_NE(capture_->Flush, nullptr);
int32_t ret = capture_->Flush(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture TurnStandbyMode cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureTurnStandbyMode001, TestSize.Level1)
{
ASSERT_NE(capture_->TurnStandbyMode, nullptr);
ASSERT_NE(capture_->Start, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->TurnStandbyMode(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureTurnStandbyModeException001, TestSize.Level1)
{
ASSERT_NE(capture_->TurnStandbyMode, nullptr);
int32_t ret = capture_->TurnStandbyMode(nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture AudioDevDump cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureAudioDevDump001, TestSize.Level1)
{
ASSERT_NE(capture_->AudioDevDump, nullptr);
int32_t range = 4;
char pathBuf[] = "/data/CaptureDump.log";
FILE *file = fopen(pathBuf, "wb+");
ASSERT_NE(nullptr, file);
int fd = fileno(file);
if (fd == -1) {
fclose(file);
ASSERT_NE(fd, -1);
}
int32_t ret = capture_->AudioDevDump(capture_, range, fd);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
fclose(file);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureAudioDevDumpExption001, TestSize.Level1)
{
ASSERT_NE(capture_->AudioDevDump, nullptr);
int32_t range = 4;
int32_t ret = capture_->AudioDevDump(nullptr, range, -1);
EXPECT_NE(ret, HDF_SUCCESS);
}
/**
* @brief here starts the volume test cases
*/
/* capture SetMute cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetMute001, TestSize.Level1)
{
bool isSupport = false;
ASSERT_NE(capture_->SetMute, nullptr);
ASSERT_NE(capture_->GetMute, nullptr);
int32_t ret = capture_->SetMute(capture_, isSupport);
if (ret == HDF_SUCCESS) {
ret = capture_->GetMute(capture_, &isSupport);
ASSERT_EQ(isSupport, false);
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
isSupport = true;
ret = capture_->SetMute(capture_, isSupport);
if (ret == HDF_SUCCESS) {
ret = capture_->GetMute(capture_, &isSupport);
ASSERT_EQ(isSupport, true);
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
}
// set twice
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetMuteException001, TestSize.Level1)
{
bool isSupport = true;
ASSERT_NE(capture_->SetMute, nullptr);
ASSERT_NE(capture_->GetMute, nullptr);
int32_t ret = capture_->SetMute(capture_, isSupport);
if (ret == HDF_SUCCESS) {
ret = capture_->GetMute(capture_, &isSupport);
ASSERT_EQ(isSupport, true);
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
ret = capture_->SetMute(capture_, isSupport);
if (ret == HDF_SUCCESS) {
ret = capture_->GetMute(capture_, &isSupport);
ASSERT_EQ(isSupport, true);
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetMuteException002, TestSize.Level1)
{
EXPECT_NE(capture_->SetMute, nullptr);
int32_t ret = capture_->SetMute(nullptr, true);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture GetMute cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetMute001, TestSize.Level1)
{
bool isSupport = true;
EXPECT_NE(capture_->GetMute, nullptr);
int32_t ret = capture_->GetMute(capture_, &isSupport);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetMuteException001, TestSize.Level1)
{
EXPECT_NE(capture_->GetMute, nullptr);
int32_t ret = capture_->GetMute(nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetMute(capture_, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture SetVolume cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetVolume001, TestSize.Level1)
{
float volume = 0.0;
EXPECT_NE(capture_->SetVolume, nullptr);
EXPECT_NE(capture_->GetVolume, nullptr);
int32_t ret = capture_->SetVolume(capture_, HALF_OF_MAX_VOLUME);
if (ret == HDF_SUCCESS) {
ret = capture_->GetVolume(capture_, &volume);
ASSERT_EQ(volume, HALF_OF_MAX_VOLUME);
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetVolumeException001, TestSize.Level1)
{
float exceptionVolume = 2.0;
EXPECT_NE(capture_->SetVolume, nullptr);
int32_t ret = capture_->SetVolume(capture_, exceptionVolume);
EXPECT_NE(ret, HDF_SUCCESS);
exceptionVolume = -3.0;
ret = capture_->SetVolume(capture_, exceptionVolume);
EXPECT_NE(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetVolumeException002, TestSize.Level1)
{
EXPECT_NE(capture_->SetVolume, nullptr);
int32_t ret = capture_->SetVolume(nullptr, HALF_OF_MAX_VOLUME);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture GetVolume cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetVolume001, TestSize.Level1)
{
float volume = 0.0;
EXPECT_NE(capture_->GetVolume, nullptr);
int32_t ret = capture_->GetVolume(capture_, &volume);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetVolumeException001, TestSize.Level1)
{
float volume = 0.0;
EXPECT_NE(capture_->GetVolume, nullptr);
int32_t ret = capture_->GetVolume(nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetVolume(capture_, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetVolume(nullptr, &volume);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture GetGainThreshold cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetGainThreshold001, TestSize.Level1)
{
float bottom = 0;
float top = 0;
EXPECT_NE(capture_->GetGainThreshold, nullptr);
int32_t ret = capture_->GetGainThreshold(capture_, &bottom, &top);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetGainThresholdException002, TestSize.Level1)
{
float bottom = 0;
float top = 0;
EXPECT_NE(capture_->GetGainThreshold, nullptr);
int32_t ret = capture_->GetGainThreshold(nullptr, &bottom, &top);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetGainThreshold(nullptr, nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetGainThreshold(capture_, nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/**
* @brief here starts the attributes cases
*/
/* capture GetSampleAttributes cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetSampleAttributes001, TestSize.Level1)
{
struct AudioSampleAttributes attrs = {};
EXPECT_NE(capture_->GetSampleAttributes, nullptr);
int32_t ret = capture_->GetSampleAttributes(capture_, &attrs);
EXPECT_EQ(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetSampleAttributesException001, TestSize.Level1)
{
struct AudioSampleAttributes attrs = {};
EXPECT_NE(capture_->GetSampleAttributes, nullptr);
int32_t ret = capture_->GetSampleAttributes(nullptr, &attrs);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetSampleAttributes(capture_, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetSampleAttributesException001, TestSize.Level1)
{
struct AudioSampleAttributes attrs = {
.format = AUDIO_FORMAT_TYPE_PCM_16_BIT,
.sampleRate = TEST_SAMPLE_RATE_MASK_48000,
.channelCount = TEST_CHANNEL_COUNT,
};
EXPECT_NE(capture_->SetSampleAttributes, nullptr);
int32_t ret = capture_->SetSampleAttributes(capture_, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->SetSampleAttributes(nullptr, &attrs);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture GetCurrentChannelId cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetCurrentChannelId001, TestSize.Level1)
{
int32_t ret = HDF_SUCCESS;
uint32_t channelId = 0;
EXPECT_NE(capture_->GetCurrentChannelId, nullptr);
ret = capture_->GetCurrentChannelId(capture_, &channelId);
EXPECT_EQ(ret, HDF_SUCCESS);
EXPECT_EQ(TEST_CHANNEL_COUNT, channelId);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetCurrentChannelIdException001, TestSize.Level1)
{
int32_t ret = HDF_SUCCESS;
uint32_t channelId = 0;
EXPECT_NE(capture_->GetCurrentChannelId, nullptr);
ret = capture_->GetCurrentChannelId(capture_, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetCurrentChannelId(nullptr, &channelId);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture SetExtraParams cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetExtraParams001, TestSize.Level1)
{
EXPECT_NE(capture_->SetExtraParams, nullptr);
EXPECT_NE(capture_->GetExtraParams, nullptr);
char kvList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
char keyValueListReply[256] = {};
uint32_t listLenth = 256;
size_t index = 1;
int32_t ret = capture_->SetExtraParams(capture_, kvList);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
// the vendor can not supply this methodone it not supply returns HDF_ERR_INVALID_PARAM
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
std::string strGetValue = keyValueListReply;
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, "");
}
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureSetExtraParamsException001, TestSize.Level1)
{
ASSERT_NE(capture_->SetExtraParams, nullptr);
int32_t ret = capture_->SetExtraParams(nullptr, nullptr);
EXPECT_NE(ret, HDF_SUCCESS);
}
/* capture GetExtraParams cases */
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetExtraParams001, TestSize.Level1)
{
ASSERT_NE(capture_->GetExtraParams, nullptr);
char keyValueListReply[256] = {};
uint32_t listLenth = 256;
int32_t ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
// the vendor can not supply this methodone it not supply returns HDF_ERR_INVALID_PARAM
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
}
HWTEST_F(AudioUtCaptureTest, HdfAudioCaptureGetExtraParamsException001, TestSize.Level1)
{
ASSERT_NE(capture_->GetExtraParams, nullptr);
char keyValueListReply[256] = {};
uint32_t listLenth = 256;
int32_t ret = capture_->GetExtraParams(nullptr, keyValueListReply, listLenth);
EXPECT_NE(ret, HDF_SUCCESS);
ret = capture_->GetExtraParams(capture_, nullptr, listLenth);
EXPECT_NE(ret, HDF_SUCCESS);
}
} // end of name space

View File

@ -0,0 +1,39 @@
# Copyright (c) 2021-2022 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/hdf_core/adapter/uhdf2/uhdf.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/audio"
ohos_moduletest_suite("HatsHdfAudioIdlManagerTest") {
module_out_path = module_output_path
sources = [ "src/audio_manager_common_test.cpp" ]
configs = [ ":audio_idl_manager" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
external_deps = [
"c_utils:utils",
"drivers_interface_audio:audio_idl_headers",
"drivers_interface_audio:libaudio_proxy_1.0",
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "hdf"
part_name = "drivers_peripheral_audio"
}
config("audio_idl_manager") {
include_dirs = []
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfAudioIdlManagerTest->/data/local/tmp/HatsHdfAudioIdlManagerTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfAudioIdlManagerTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfAudioIdlManagerTest Tests"
}

View File

@ -0,0 +1,255 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <climits>
#include <gtest/gtest.h>
#include "hdf_dlist.h"
#include "osal_mem.h"
#include "v1_0/iaudio_manager.h"
using namespace std;
using namespace testing::ext;
namespace {
static const uint32_t g_audioAdapterNumMax = 5;
struct IAudioManager *g_manager = nullptr;
class HdfAudioUtManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
};
void HdfAudioUtManagerTest::AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
{
if (dataBlock == nullptr) {
return;
}
if (dataBlock->adapterName != nullptr) {
OsalMemFree(dataBlock->adapterName);
dataBlock->adapterName = nullptr;
}
if (dataBlock->ports != nullptr) {
OsalMemFree(dataBlock->ports);
}
if (freeSelf) {
OsalMemFree(dataBlock);
}
}
void HdfAudioUtManagerTest::ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
{
if ((descsLen > 0) && (descs != nullptr) && ((*descs) != nullptr)) {
for (uint32_t i = 0; i < descsLen; i++) {
AudioAdapterDescriptorFree(&(*descs)[i], false);
}
OsalMemFree(*descs);
*descs = nullptr;
}
}
void HdfAudioUtManagerTest::SetUp()
{
}
void HdfAudioUtManagerTest::TearDown()
{
}
void HdfAudioUtManagerTest::SetUpTestCase()
{
g_manager = IAudioManagerGet(false);
ASSERT_NE(g_manager, nullptr);
}
void HdfAudioUtManagerTest::TearDownTestCase()
{
IAudioManagerRelease(g_manager, false);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetVersionNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->GetVersion(nullptr, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetVersionNull002, TestSize.Level1)
{
uint32_t version;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->GetVersion(nullptr, &version, &version));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetVersionNull003, TestSize.Level1)
{
uint32_t version;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->GetVersion(g_manager, nullptr, &version));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetVersionNull004, TestSize.Level1)
{
uint32_t version;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->GetVersion(g_manager, &version, nullptr));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetVersionIsValid001, TestSize.Level1)
{
uint32_t majorVer;
uint32_t minorVer;
ASSERT_EQ(HDF_SUCCESS, g_manager->GetVersion(g_manager, &majorVer, &minorVer));
EXPECT_EQ(IAUDIO_MANAGER_MAJOR_VERSION, majorVer);
EXPECT_EQ(IAUDIO_MANAGER_MINOR_VERSION, minorVer);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->GetAllAdapters(nullptr, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersNull002, TestSize.Level1)
{
uint32_t size = 0;
struct AudioAdapterDescriptor descs;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->GetAllAdapters(nullptr, &descs, &size));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersNull003, TestSize.Level1)
{
uint32_t size = 0;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->GetAllAdapters(g_manager, nullptr, &size));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersParaInvalid001, TestSize.Level1)
{
uint32_t size = 0;
struct AudioAdapterDescriptor descs;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->GetAllAdapters(g_manager, &descs, &size));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersParaInvalid002, TestSize.Level1)
{
uint32_t size = UINT_MAX;
struct AudioAdapterDescriptor descs;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->GetAllAdapters(g_manager, &descs, &size));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersSizeIsValid_001, TestSize.Level1)
{
uint32_t size = g_audioAdapterNumMax;
struct AudioAdapterDescriptor *descs = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
ASSERT_NE(nullptr, descs);
ASSERT_EQ(HDF_SUCCESS, g_manager->GetAllAdapters(g_manager, descs, &size));
EXPECT_GE(g_audioAdapterNumMax, size);
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerGetAllAdaptersDescsIsValid_001, TestSize.Level1)
{
uint32_t size = g_audioAdapterNumMax;
struct AudioAdapterDescriptor *descs = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
ASSERT_NE(nullptr, descs);
ASSERT_EQ(HDF_SUCCESS, g_manager->GetAllAdapters(g_manager, descs, &size));
EXPECT_GE(g_audioAdapterNumMax, size);
for (uint32_t i = 0; i < size; i++) {
EXPECT_NE(nullptr, descs[i].adapterName);
}
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterNull_001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->LoadAdapter(nullptr, nullptr, nullptr));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterNull_002, TestSize.Level1)
{
struct AudioAdapterDescriptor descs;
struct IAudioAdapter *adapter = nullptr;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->LoadAdapter(nullptr, &descs, &adapter));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterNull_003, TestSize.Level1)
{
struct IAudioAdapter *adapter = nullptr;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->LoadAdapter(g_manager, nullptr, &adapter));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterNull_004, TestSize.Level1)
{
struct AudioAdapterDescriptor descs;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, g_manager->LoadAdapter(g_manager, &descs, nullptr));
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterSuccess_001, TestSize.Level1)
{
uint32_t size = g_audioAdapterNumMax;
struct IAudioAdapter *adapter = nullptr;
struct AudioAdapterDescriptor *descs = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
ASSERT_NE(nullptr, descs);
ASSERT_EQ(HDF_SUCCESS, g_manager->GetAllAdapters(g_manager, descs, &size));
if (size > g_audioAdapterNumMax) {
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
ASSERT_GE(g_audioAdapterNumMax, size);
}
ASSERT_EQ(HDF_SUCCESS, g_manager->LoadAdapter(g_manager, &descs[0], &adapter));
EXPECT_TRUE(adapter != nullptr);
EXPECT_EQ(HDF_SUCCESS, g_manager->UnloadAdapter(g_manager, descs[0].adapterName));
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerLoadAdapterSuccess_002, TestSize.Level1)
{
uint32_t size = g_audioAdapterNumMax;
struct IAudioAdapter *firstAdapter = nullptr;
struct IAudioAdapter *secondAdapter = nullptr;
struct AudioAdapterDescriptor *descs = (struct AudioAdapterDescriptor *)OsalMemCalloc(
sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
ASSERT_NE(nullptr, descs);
EXPECT_EQ(HDF_SUCCESS, g_manager->GetAllAdapters(g_manager, descs, &size));
if (size > g_audioAdapterNumMax) {
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
ASSERT_GE(g_audioAdapterNumMax, size);
}
EXPECT_EQ(HDF_SUCCESS, g_manager->LoadAdapter(g_manager, &descs[0], &firstAdapter));
EXPECT_TRUE(firstAdapter != nullptr);
EXPECT_EQ(HDF_SUCCESS, g_manager->LoadAdapter(g_manager, &descs[0], &secondAdapter));
EXPECT_TRUE(secondAdapter != nullptr);
EXPECT_EQ(HDF_SUCCESS, g_manager->UnloadAdapter(g_manager, descs[0].adapterName));
EXPECT_EQ(HDF_SUCCESS, g_manager->UnloadAdapter(g_manager, descs[0].adapterName));
ReleaseAdapterDescs(&descs, g_audioAdapterNumMax);
}
HWTEST_F(HdfAudioUtManagerTest, HdfAudioManagerReleaseAudioManagerObjectNull_001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, g_manager->ReleaseAudioManagerObject(nullptr));
}
}

View File

@ -0,0 +1,39 @@
# Copyright (c) 2021-2022 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/hdf_core/adapter/uhdf2/uhdf.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/audio"
ohos_moduletest_suite("HatsHdfAudioIdlRenderTest") {
module_out_path = module_output_path
sources = [ "src/audio_render_common_test.cpp" ]
configs = [ ":audio_idl_render" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
external_deps = [
"c_utils:utils",
"drivers_interface_audio:audio_idl_headers",
"drivers_interface_audio:libaudio_proxy_1.0",
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "hdf"
part_name = "drivers_peripheral_audio"
}
config("audio_idl_render") {
include_dirs = []
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfAudioIdlRenderTest->/data/local/tmp/HatsHdfAudioIdlRenderTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfAudioIdlRenderTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfAudioIdlRenderTest Tests"
}

View File

@ -0,0 +1,690 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "osal_mem.h"
#include "v1_0/audio_types.h"
#include "v1_0/iaudio_manager.h"
#include "v1_0/iaudio_render.h"
using namespace std;
using namespace testing::ext;
namespace {
const int32_t AUDIO_RENDER_CHANNELCOUNT = 2;
const int32_t AUDIO_SAMPLE_RATE_48K = 48000;
const uint64_t DEFAULT_BUFFER_SIZE = 16384;
const int32_t MAX_AUDIO_ADAPTER_DESC = 5;
const int32_t AUDIO_RENDER_BUF_TEST = 1024;
const float MAX_GAINTHRESHOLD = 15.0;
const float MIN_GAINTHRESHOLD = 0.0;
class AudioUtRenderTest : public testing::Test {
public:
struct IAudioManager *manager_ = nullptr;
struct AudioAdapterDescriptor descs_[MAX_AUDIO_ADAPTER_DESC];
struct AudioAdapterDescriptor *desc_;
struct IAudioAdapter *adapter_ = nullptr;
struct IAudioRender *render_ = nullptr;
struct AudioDeviceDescriptor devDescRender_ = {};
struct AudioSampleAttributes attrsRender_ = {};
uint32_t renderId_ = 0;
uint32_t size_ = MAX_AUDIO_ADAPTER_DESC;
virtual void SetUp();
virtual void TearDown();
uint64_t GetRenderBufferSize();
void InitRenderAttrs(struct AudioSampleAttributes &attrs);
void InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc);
void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
};
uint64_t AudioUtRenderTest::GetRenderBufferSize()
{
int32_t ret = HDF_SUCCESS;
uint64_t frameSize = 0;
uint64_t frameCount = 0;
uint64_t bufferSize = 0;
if (render_ == nullptr) {
return DEFAULT_BUFFER_SIZE;
}
ret = render_->GetFrameSize(render_, &frameSize);
if (ret != HDF_SUCCESS) {
return DEFAULT_BUFFER_SIZE;
}
ret = render_->GetFrameCount(render_, &frameCount);
if (ret != HDF_SUCCESS) {
return DEFAULT_BUFFER_SIZE;
}
bufferSize = frameCount * frameSize;
if (bufferSize == 0) {
bufferSize = DEFAULT_BUFFER_SIZE;
}
return bufferSize;
}
void AudioUtRenderTest::InitRenderAttrs(struct AudioSampleAttributes &attrs)
{
attrs.channelCount = AUDIO_RENDER_CHANNELCOUNT;
attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
attrs.interleaved = 0;
attrs.type = AUDIO_IN_MEDIA;
attrs.period = 4 * 1024;
attrs.frameSize = 16 * 2 / 8;
attrs.isBigEndian = false;
attrs.isSignedData = true;
attrs.startThreshold = 4 * 1024 / (attrs.format * attrs.channelCount / 8);
attrs.stopThreshold = INT_MAX;
attrs.silenceThreshold = 1024 * 16;
}
void AudioUtRenderTest::InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc)
{
devDesc.pins = PIN_OUT_SPEAKER;
devDesc.desc = strdup("cardname");
ASSERT_NE(desc_, nullptr);
ASSERT_NE(desc_->ports, nullptr);
for (uint32_t index = 0; index < desc_->portsLen; index++) {
if (desc_->ports[index].dir == PORT_OUT) {
devDesc.portId = desc_->ports[index].portId;
return;
}
}
free(devDesc.desc);
}
void AudioUtRenderTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
{
if (dataBlock == nullptr) {
return;
}
OsalMemFree(dataBlock->adapterName);
OsalMemFree(dataBlock->ports);
if (freeSelf) {
OsalMemFree(dataBlock);
}
}
void AudioUtRenderTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
{
if (descs == nullptr || descsLen == 0) {
return;
}
for (uint32_t i = 0; i < descsLen; i++) {
FreeAdapterElements(&descs[i], false);
}
}
void AudioUtRenderTest::SetUp()
{
manager_ = IAudioManagerGet(false);
ASSERT_NE(manager_, nullptr);
ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, descs_, &size_));
ASSERT_NE(descs_, nullptr);
EXPECT_GE(MAX_AUDIO_ADAPTER_DESC, size_);
desc_ = &descs_[0];
ASSERT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, desc_, &adapter_));
ASSERT_NE(adapter_, nullptr);
InitRenderDevDesc(devDescRender_);
InitRenderAttrs(attrsRender_);
attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
int32_t ret = adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_);
if (ret != HDF_SUCCESS) {
attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_32_BIT;
ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_));
}
ASSERT_NE(render_, nullptr);
}
void AudioUtRenderTest::TearDown()
{
if (adapter_ != nullptr) {
adapter_->DestroyRender(adapter_, renderId_);
render_ = nullptr;
}
if (manager_ != nullptr) {
manager_->UnloadAdapter(manager_, desc_->adapterName);
adapter_ = nullptr;
ReleaseAllAdapterDescs(descs_, size_);
IAudioManagerRelease(manager_, false);
}
}
HWTEST_F(AudioUtRenderTest, RenderStartNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->Start(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderStartNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
EXPECT_NE(HDF_SUCCESS, render_->Start(render_));
EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
}
HWTEST_F(AudioUtRenderTest, RenderStartStopIsValid001, TestSize.Level1)
{
EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
}
HWTEST_F(AudioUtRenderTest, RenderFlushNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->Flush(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderFlushIsValid001, TestSize.Level1)
{
EXPECT_NE(HDF_SUCCESS, render_->Flush(render_));
}
HWTEST_F(AudioUtRenderTest, RenderStopNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->Stop(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameSizeNull001, TestSize.Level1)
{
uint64_t frameSize = 0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetFrameSize(nullptr, &frameSize));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameSizeNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetFrameSize(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameSizeIsValid001, TestSize.Level1)
{
uint64_t frameSize = 0;
EXPECT_EQ(HDF_SUCCESS, render_->GetFrameSize(render_, &frameSize));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameCountNull001, TestSize.Level1)
{
uint64_t frameCount = 0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetFrameCount(nullptr, &frameCount));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameCountNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetFrameCount(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetFrameCountIsValid001, TestSize.Level1)
{
uint64_t frameCount = 0;
EXPECT_EQ(HDF_SUCCESS, render_->GetFrameCount(render_, &frameCount));
}
HWTEST_F(AudioUtRenderTest, RenderSetSampleAttributesNull001, TestSize.Level1)
{
struct AudioSampleAttributes attrs;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetSampleAttributes(nullptr, &attrs));
}
HWTEST_F(AudioUtRenderTest, RenderSetSampleAttributesNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->SetSampleAttributes(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderSetSampleAttributesIsValid001, TestSize.Level1)
{
struct AudioSampleAttributes attrs = attrsRender_;
EXPECT_EQ(HDF_SUCCESS, render_->SetSampleAttributes(render_, &attrs));
}
HWTEST_F(AudioUtRenderTest, RenderGetSampleAttributesNull001, TestSize.Level1)
{
struct AudioSampleAttributes attrs;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetSampleAttributes(nullptr, &attrs));
}
HWTEST_F(AudioUtRenderTest, RenderGetSampleAttributesNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetSampleAttributes(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetSampleAttributesIsValid001, TestSize.Level1)
{
struct AudioSampleAttributes attrs;
EXPECT_EQ(HDF_SUCCESS, render_->GetSampleAttributes(render_, &attrs));
}
HWTEST_F(AudioUtRenderTest, RenderGetCurrentChannelIdNull001, TestSize.Level1)
{
uint32_t channelId;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetCurrentChannelId(nullptr, &channelId));
}
HWTEST_F(AudioUtRenderTest, RenderGetCurrentChannelIdNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetCurrentChannelId(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetCurrentChannelIdIsValid001, TestSize.Level1)
{
uint32_t channelId;
EXPECT_EQ(HDF_SUCCESS, render_->GetCurrentChannelId(render_, &channelId));
}
HWTEST_F(AudioUtRenderTest, RenderCheckSceneCapabilityNull001, TestSize.Level1)
{
struct AudioSceneDescriptor scene;
bool supported = false;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->CheckSceneCapability(nullptr, &scene, &supported));
}
HWTEST_F(AudioUtRenderTest, RenderCheckSceneCapabilityNull002, TestSize.Level1)
{
bool supported = false;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->CheckSceneCapability(render_, nullptr, &supported));
}
HWTEST_F(AudioUtRenderTest, RenderCheckSceneCapabilityNull003, TestSize.Level1)
{
struct AudioSceneDescriptor scene;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->CheckSceneCapability(render_, &scene, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderSelectSceneNull001, TestSize.Level1)
{
struct AudioSceneDescriptor scene;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SelectScene(nullptr, &scene));
}
HWTEST_F(AudioUtRenderTest, RenderSelectSceneNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->SelectScene(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderSelectSceneIsValid001, TestSize.Level1)
{
struct AudioSceneDescriptor scene;
scene.scene.id = AUDIO_IN_MEDIA;
scene.desc.pins = PIN_OUT_HEADSET;
scene.desc.desc = strdup("mic");
EXPECT_EQ(HDF_SUCCESS, render_->SelectScene(render_, &scene));
scene.desc.pins = PIN_OUT_SPEAKER;
EXPECT_EQ(HDF_SUCCESS, render_->SelectScene(render_, &scene));
free(scene.desc.desc);
}
HWTEST_F(AudioUtRenderTest, RenderGetLatencyNull001, TestSize.Level1)
{
uint32_t ms = 0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetLatency(nullptr, &ms));
}
HWTEST_F(AudioUtRenderTest, RenderGetLatencyNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetLatency(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetLatencyIsValid001, TestSize.Level1)
{
uint32_t ms = 0;
EXPECT_EQ(HDF_SUCCESS, render_->GetLatency(render_, &ms));
}
HWTEST_F(AudioUtRenderTest, RenderGetRenderPositionNull001, TestSize.Level1)
{
uint64_t frames = 0;
struct AudioTimeStamp time;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetRenderPosition(nullptr, &frames, &time));
}
HWTEST_F(AudioUtRenderTest, RenderGetRenderPositionNull002, TestSize.Level1)
{
struct AudioTimeStamp time;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetRenderPosition(render_, nullptr, &time));
}
HWTEST_F(AudioUtRenderTest, RenderGetRenderPositionNull003, TestSize.Level1)
{
uint64_t frames = 0;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetRenderPosition(render_, &frames, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderGetRenderPositionIsValid001, TestSize.Level1)
{
uint64_t frames = 0;
struct AudioTimeStamp time;
int32_t ret = render_->GetRenderPosition(render_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
}
HWTEST_F(AudioUtRenderTest, RenderSetExtraParamsNull001, TestSize.Level1)
{
char keyValueList[AUDIO_RENDER_BUF_TEST];
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetExtraParams(nullptr, keyValueList));
}
HWTEST_F(AudioUtRenderTest, RenderSetExtraParamsNull002, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->SetExtraParams(render_, nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderSetExtraParamsIsValid001, TestSize.Level1)
{
char keyValueList[AUDIO_RENDER_BUF_TEST] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
EXPECT_EQ(HDF_SUCCESS, render_->SetExtraParams(render_, keyValueList));
}
HWTEST_F(AudioUtRenderTest, RenderGetExtraParamsNull001, TestSize.Level1)
{
char keyValueList[AUDIO_RENDER_BUF_TEST];
uint32_t keyValueListLen = 0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetExtraParams(nullptr, keyValueList, keyValueListLen));
}
HWTEST_F(AudioUtRenderTest, RenderGetExtraParamsNull002, TestSize.Level1)
{
uint32_t keyValueListLen = 0;
EXPECT_EQ(HDF_ERR_INVALID_PARAM, render_->GetExtraParams(render_, nullptr, keyValueListLen));
}
HWTEST_F(AudioUtRenderTest, RenderGetExtraParamsIsValid001, TestSize.Level1)
{
char keyValueList[AUDIO_RENDER_BUF_TEST] = {};
uint32_t keyValueListLen = 0;
EXPECT_NE(HDF_SUCCESS, render_->GetExtraParams(render_, keyValueList, keyValueListLen));
}
HWTEST_F(AudioUtRenderTest, RenderTurnStandbyModeNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->TurnStandbyMode(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderTurnStandbyModeIsValid001, TestSize.Level1)
{
EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
EXPECT_EQ(HDF_SUCCESS, render_->TurnStandbyMode(render_));
}
HWTEST_F(AudioUtRenderTest, RenderAudioDevDumpNull001, TestSize.Level1)
{
int32_t range = 4;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->AudioDevDump(nullptr, range, -1));
}
HWTEST_F(AudioUtRenderTest, RenderAudioDevDumpIsValid001, TestSize.Level1)
{
int32_t range = 4;
char pathBuf[] = "./DevDump.log";
FILE *file = fopen(pathBuf, "wb+");
ASSERT_NE(nullptr, file);
int fd = fileno(file);
if (fd == -1) {
fclose(file);
ASSERT_NE(fd, -1);
}
int32_t ret = render_->AudioDevDump(render_, range, fd);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
fclose(file);
}
HWTEST_F(AudioUtRenderTest, RenderGetGainNull001, TestSize.Level1)
{
float gain;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetGain(nullptr, &gain));
}
HWTEST_F(AudioUtRenderTest, RenderGetGainIsValid001, TestSize.Level1)
{
float gain;
int32_t ret = render_->GetGain(render_, &gain);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderGetGainThresholdNull001, TestSize.Level1)
{
float min = 0.0;
float max = 1.0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetGainThreshold(nullptr, &min, &max));
}
HWTEST_F(AudioUtRenderTest, RenderGetGainThresholdIsValid001, TestSize.Level1)
{
float min = 0.0;
float max = 1.0;
int32_t ret = render_->GetGainThreshold(render_, &min, &max);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
EXPECT_GE(min, MIN_GAINTHRESHOLD);
EXPECT_LE(max, MAX_GAINTHRESHOLD);
}
HWTEST_F(AudioUtRenderTest, RenderGetMmapPositionNull001, TestSize.Level1)
{
uint64_t frames = 0;
struct AudioTimeStamp time;
time.tvNSec = 0;
time.tvSec = 0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetMmapPosition(nullptr, &frames, &time));
}
HWTEST_F(AudioUtRenderTest, RenderGetMmapPositionIsValid001, TestSize.Level1)
{
uint64_t frames = 0;
struct AudioTimeStamp time;
time.tvNSec = 0;
time.tvSec = 0;
int32_t ret = render_->GetMmapPosition(render_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderGetMuteNull001, TestSize.Level1)
{
bool isMute = false;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetMute(nullptr, &isMute));
}
HWTEST_F(AudioUtRenderTest, RenderGetMuteIsValid001, TestSize.Level1)
{
bool isMute = false;
int32_t ret = render_->GetMute(render_, &isMute);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderGetVersionNull001, TestSize.Level1)
{
uint32_t majorVer;
uint32_t minorVer;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetVersion(nullptr, &majorVer, &minorVer));
}
HWTEST_F(AudioUtRenderTest, RenderGetVersionIsValid001, TestSize.Level1)
{
uint32_t majorVer;
uint32_t minorVer;
ASSERT_EQ(HDF_SUCCESS, render_->GetVersion(render_, &majorVer, &minorVer));
EXPECT_EQ(IAUDIO_MANAGER_MAJOR_VERSION, majorVer);
EXPECT_EQ(IAUDIO_MANAGER_MINOR_VERSION, minorVer);
}
HWTEST_F(AudioUtRenderTest, RenderGetVolumeNull001, TestSize.Level1)
{
float val = 0.0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->GetVolume(nullptr, &val));
}
HWTEST_F(AudioUtRenderTest, RenderGetVolumeIsValid001, TestSize.Level1)
{
float val = 0.0;
int32_t ret = render_->GetVolume(render_, &val);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderPauseNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->Pause(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderResumeNull001, TestSize.Level1)
{
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->Resume(nullptr));
}
HWTEST_F(AudioUtRenderTest, RenderPauseResumeIsValid001, TestSize.Level1)
{
EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
int32_t ret = render_->Pause(render_);
if (ret == HDF_SUCCESS) {
EXPECT_EQ(HDF_SUCCESS, render_->Resume(render_));
} else if (ret == HDF_ERR_NOT_SUPPORT) {
ASSERT_TRUE(true);
} else {
ASSERT_TRUE(false);
}
EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
}
HWTEST_F(AudioUtRenderTest, RenderRenderFrameNull001, TestSize.Level1)
{
uint32_t frameLen = DEFAULT_BUFFER_SIZE;
uint64_t requestBytes = frameLen;
int8_t *frame = (int8_t *)calloc(1, frameLen);
ASSERT_NE(nullptr, frame);
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->RenderFrame(nullptr, frame, frameLen, &requestBytes));
if (frame != nullptr) {
free(frame);
frame = nullptr;
}
}
HWTEST_F(AudioUtRenderTest, RenderRenderFrameIsValid001, TestSize.Level1)
{
uint32_t frameLen = (uint64_t)GetRenderBufferSize();
uint64_t requestBytes = frameLen;
EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
int8_t *frame = (int8_t *)calloc(1, frameLen);
ASSERT_NE(nullptr, frame);
EXPECT_EQ(HDF_SUCCESS, render_->RenderFrame(render_, frame, frameLen, &requestBytes));
EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
if (frame != nullptr) {
free(frame);
frame = nullptr;
}
}
HWTEST_F(AudioUtRenderTest, RenderSetChannelModeNull001, TestSize.Level1)
{
AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetChannelMode(nullptr, mode));
}
HWTEST_F(AudioUtRenderTest, RenderSetChannelModeIsValid001, TestSize.Level1)
{
AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
int32_t ret = render_->SetChannelMode(render_, mode);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderSetGainNull001, TestSize.Level1)
{
float gain = 1.0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetGain(nullptr, gain));
}
HWTEST_F(AudioUtRenderTest, RenderSetGainIsValid001, TestSize.Level1)
{
float gain = 1.0;
int32_t ret = render_->SetGain(render_, gain);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderSetMuteNull001, TestSize.Level1)
{
bool mute = false;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetMute(nullptr, mute));
}
HWTEST_F(AudioUtRenderTest, RenderSetMuteIsValid001, TestSize.Level1)
{
bool mute = false;
int32_t ret = render_->SetMute(render_, mute);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
HWTEST_F(AudioUtRenderTest, RenderSetRenderSpeedNull001, TestSize.Level1)
{
float speed = 2.0;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetRenderSpeed(nullptr, speed));
}
HWTEST_F(AudioUtRenderTest, RenderSetRenderSpeedIsValid001, TestSize.Level1)
{
float speed = 2.0;
EXPECT_NE(HDF_SUCCESS, render_->SetRenderSpeed(render_, speed));
}
HWTEST_F(AudioUtRenderTest, RenderSetVolumeNull001, TestSize.Level1)
{
float volume = 0.2;
EXPECT_EQ(HDF_ERR_INVALID_OBJECT, render_->SetVolume(nullptr, volume));
}
HWTEST_F(AudioUtRenderTest, RenderSetVolumeIsInValid001, TestSize.Level1)
{
float volume = -1.0;
EXPECT_NE(HDF_SUCCESS, render_->SetVolume(render_, volume));
}
HWTEST_F(AudioUtRenderTest, RenderSetVolumeIsInValid002, TestSize.Level1)
{
float volume = 2.0;
EXPECT_NE(HDF_SUCCESS, render_->SetVolume(render_, volume));
}
HWTEST_F(AudioUtRenderTest, RenderSetVolumeIsValid001, TestSize.Level1)
{
float volume = 0.2;
int32_t ret = render_->SetVolume(render_, volume);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
} // end of namespace