1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <climits>
17 #include <cstring>
18 #include <gtest/gtest.h>
19 #include "hdf_dlist.h"
20 #include "osal_mem.h"
21 #include "i_audio_types.h"
22 #include "v1_0/iaudio_adapter.h"
23 #include "v1_0/iaudio_manager.h"
24
25 using namespace std;
26 using namespace testing::ext;
27
28 #define AUDIO_CHANNELCOUNT 2
29 #define AUDIO_SAMPLE_RATE_48K 48000
30 #define DEEP_BUFFER_RENDER_PERIOD_SIZE 4096
31 #define INT_32_MAX 0x7fffffff
32 #define PCM_16_BIT 16
33 #define PCM_8_BIT 8
34
35 namespace {
36 static const uint32_t g_audioAdapterNumMax = 5;
37 const int32_t AUDIO_ADAPTER_BUF_TEST = 1024;
38
39 class HdfAudioUtAdapterTest : public testing::Test {
40 public:
41 struct IAudioManager *manager_ = nullptr;
42 struct IAudioAdapter *adapter_ = nullptr;
43 struct AudioAdapterDescriptor *adapterDescs_ = nullptr;
44 uint32_t renderId_ = 0;
45 uint32_t captureId_ = 0;
46 virtual void SetUp();
47 virtual void TearDown();
48 void InitAttrs(struct AudioSampleAttributes &attrs);
49 void InitDevDesc(struct AudioDeviceDescriptor &devDesc);
50 void AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
51 void ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
52 };
53
AudioAdapterDescriptorFree(struct AudioAdapterDescriptor * dataBlock,bool freeSelf)54 void HdfAudioUtAdapterTest::AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
55 {
56 if (dataBlock == nullptr) {
57 return;
58 }
59
60 if (dataBlock->adapterName != nullptr) {
61 OsalMemFree(dataBlock->adapterName);
62 dataBlock->adapterName = nullptr;
63 }
64
65 if (dataBlock->ports != nullptr) {
66 OsalMemFree(dataBlock->ports);
67 }
68
69 if (freeSelf) {
70 OsalMemFree(dataBlock);
71 }
72 }
73
ReleaseAdapterDescs(struct AudioAdapterDescriptor ** descs,uint32_t descsLen)74 void HdfAudioUtAdapterTest::ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
75 {
76 if ((descsLen > 0) && (descs != nullptr) && ((*descs) != nullptr)) {
77 for (uint32_t i = 0; i < descsLen; i++) {
78 AudioAdapterDescriptorFree(&(*descs)[i], false);
79 }
80 OsalMemFree(*descs);
81 *descs = nullptr;
82 }
83 }
84
InitAttrs(struct AudioSampleAttributes & attrs)85 void HdfAudioUtAdapterTest::InitAttrs(struct AudioSampleAttributes &attrs)
86 {
87 attrs.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
88 attrs.channelCount = AUDIO_CHANNELCOUNT;
89 attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
90 attrs.interleaved = 1;
91 attrs.type = AUDIO_IN_MEDIA;
92 attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE;
93 attrs.frameSize = PCM_16_BIT * attrs.channelCount / PCM_8_BIT;
94 attrs.isBigEndian = false;
95 attrs.isSignedData = true;
96 attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.frameSize);
97 attrs.stopThreshold = INT_32_MAX;
98 }
99
InitDevDesc(struct AudioDeviceDescriptor & devDesc)100 void HdfAudioUtAdapterTest::InitDevDesc(struct AudioDeviceDescriptor &devDesc)
101 {
102 ASSERT_NE(adapterDescs_, nullptr);
103 ASSERT_NE(adapterDescs_->ports, nullptr);
104 for (uint32_t index = 0; index < adapterDescs_->portsLen; index++) {
105 if (adapterDescs_->ports[index].dir == PORT_OUT) {
106 devDesc.portId = adapterDescs_->ports[index].portId;
107 return;
108 }
109 }
110 }
111
SetUp()112 void HdfAudioUtAdapterTest::SetUp()
113 {
114 uint32_t size = g_audioAdapterNumMax;
115 manager_ = IAudioManagerGet(false);
116 ASSERT_NE(manager_, nullptr);
117
118 adapterDescs_ = (struct AudioAdapterDescriptor *)OsalMemCalloc(
119 sizeof(struct AudioAdapterDescriptor) * (g_audioAdapterNumMax));
120 ASSERT_NE(adapterDescs_, nullptr);
121
122 ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
123 if (size > g_audioAdapterNumMax) {
124 ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
125 ASSERT_LT(size, g_audioAdapterNumMax);
126 }
127
128 if (manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_) != HDF_SUCCESS) {
129 ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
130 ASSERT_TRUE(false);
131 }
132 if (adapter_ == nullptr) {
133 ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
134 ASSERT_TRUE(false);
135 }
136 }
137
TearDown()138 void HdfAudioUtAdapterTest::TearDown()
139 {
140 ASSERT_NE(manager_, nullptr);
141 ASSERT_NE(adapter_, nullptr);
142
143 manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
144 ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
145 adapter_ = nullptr;
146 IAudioManagerRelease(manager_, false);
147 manager_ = nullptr;
148 }
149
150 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterInitAllPortsNull001, TestSize.Level1)
151 {
152 EXPECT_NE(HDF_SUCCESS, adapter_->InitAllPorts(nullptr));
153 }
154
155 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterInitAllPortsParaIsvalid001, TestSize.Level1)
156 {
157 EXPECT_EQ(HDF_SUCCESS, adapter_->InitAllPorts(adapter_));
158 }
159
160 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderNull001, TestSize.Level1)
161 {
162 EXPECT_NE(HDF_SUCCESS, adapter_->CreateRender(nullptr, nullptr, nullptr, nullptr, &renderId_));
163 }
164
165 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderNull002, TestSize.Level1)
166 {
167 struct IAudioRender *render = nullptr;
168 struct AudioDeviceDescriptor devicedesc = {};
169 struct AudioSampleAttributes attrs = {};
170 EXPECT_NE(HDF_SUCCESS, adapter_->CreateRender(nullptr, &devicedesc, &attrs, &render, &renderId_));
171 }
172
173 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderInvalid001, TestSize.Level1)
174 {
175 struct IAudioRender *render = nullptr;
176 struct AudioSampleAttributes attrs = {};
177 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateRender(adapter_, nullptr, &attrs, &render, &renderId_));
178 }
179
180 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderInvalid002, TestSize.Level1)
181 {
182 struct IAudioRender *render = nullptr;
183 struct AudioDeviceDescriptor devicedesc = {};
184 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateRender(adapter_, &devicedesc, nullptr, &render, &renderId_));
185 }
186
187 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateRenderIsvalid001, TestSize.Level1)
188 {
189 struct IAudioRender *render = nullptr;
190 struct AudioDeviceDescriptor devicedesc = {};
191 struct AudioSampleAttributes attrs = {};
192 InitDevDesc(devicedesc);
193 devicedesc.desc = const_cast<char*>("primary");
194 devicedesc.pins = PIN_OUT_SPEAKER;
195 InitAttrs(attrs);
196 attrs.silenceThreshold = 0;
197 attrs.streamId = 0;
198 int32_t ret = adapter_->CreateRender(adapter_, &devicedesc, &attrs, &render, &renderId_);
199 if (ret != HDF_SUCCESS) {
200 attrs.format = AUDIO_FORMAT_TYPE_PCM_32_BIT;
201 ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devicedesc, &attrs, &render, &renderId_));
202 }
203 EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyRender(adapter_, renderId_));
204 }
205
206 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyRenderNull001, TestSize.Level1)
207 {
208 EXPECT_NE(HDF_SUCCESS, adapter_->DestroyRender(nullptr, renderId_));
209 }
210
211 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyRenderNull002, TestSize.Level1)
212 {
213 uint32_t renderId = AUDIO_HW_STREAM_NUM_MAX - 1;
214 int32_t ret = adapter_->DestroyRender(adapter_, renderId);
215 ASSERT_TRUE(ret == HDF_FAILURE || ret == HDF_ERR_INVALID_PARAM);
216 }
217
218 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyRenderInvalid001, TestSize.Level1)
219 {
220 uint32_t renderId = AUDIO_HW_STREAM_NUM_MAX;
221 int32_t ret = adapter_->DestroyRender(adapter_, renderId);
222 ASSERT_TRUE(ret == HDF_FAILURE || ret == HDF_ERR_INVALID_PARAM);
223 }
224
225 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureNull001, TestSize.Level1)
226 {
227 EXPECT_NE(HDF_SUCCESS, adapter_->CreateCapture(nullptr, nullptr, nullptr, nullptr, &captureId_));
228 }
229
230 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureNull002, TestSize.Level1)
231 {
232 struct IAudioCapture *capture = nullptr;
233 struct AudioDeviceDescriptor devicedesc = {};
234 struct AudioSampleAttributes attrs = {};
235 EXPECT_NE(HDF_SUCCESS, adapter_->CreateCapture(nullptr, &devicedesc, &attrs, &capture, &captureId_));
236 }
237
238 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureInvalid001, TestSize.Level1)
239 {
240 struct IAudioCapture *capture = nullptr;
241 struct AudioSampleAttributes attrs = {};
242 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateCapture(adapter_, nullptr, &attrs, &capture, &captureId_));
243 }
244
245 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureInvalid002, TestSize.Level1)
246 {
247 struct IAudioCapture *capture = nullptr;
248 struct AudioDeviceDescriptor devicedesc = {};
249 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->CreateCapture(adapter_, &devicedesc, nullptr, &capture, &captureId_));
250 }
251
252 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterCreateCaptureIsvalid001, TestSize.Level1)
253 {
254 struct IAudioCapture *capture = nullptr;
255 struct AudioDeviceDescriptor devicedesc = {};
256 struct AudioSampleAttributes attrs = {};
257 InitDevDesc(devicedesc);
258 devicedesc.desc = const_cast<char*>("primary");
259 devicedesc.pins = PIN_IN_MIC;
260 InitAttrs(attrs);
261 attrs.silenceThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE;
262 EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devicedesc, &attrs, &capture, &captureId_));
263 EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
264 }
265
266 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyCaptureNull001, TestSize.Level1)
267 {
268 EXPECT_NE(HDF_SUCCESS, adapter_->DestroyCapture(nullptr, captureId_));
269 }
270
271 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterDestroyCaptureInvalid001, TestSize.Level1)
272 {
273 uint32_t captureId = AUDIO_HW_STREAM_NUM_MAX;
274 int32_t ret = adapter_->DestroyCapture(adapter_, captureId);
275 ASSERT_TRUE(ret == HDF_FAILURE || ret == HDF_ERR_INVALID_PARAM);
276 }
277
278 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityNull001, TestSize.Level1)
279 {
280 EXPECT_NE(HDF_SUCCESS, adapter_->GetPortCapability(nullptr, nullptr, nullptr));
281 }
282
283 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityNull002, TestSize.Level1)
284 {
285 struct AudioPort port = {};
286 struct AudioPortCapability capability = {};
287 EXPECT_NE(HDF_SUCCESS, adapter_->GetPortCapability(nullptr, &port, &capability));
288 }
289
290 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityInvalid001, TestSize.Level1)
291 {
292 struct AudioPortCapability capability = {};
293 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPortCapability(adapter_, nullptr, &capability));
294 }
295
296 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityInvalid002, TestSize.Level1)
297 {
298 struct AudioPort port = {};
299 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPortCapability(adapter_, &port, nullptr));
300 }
301
302 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityInvalid003, TestSize.Level1)
303 {
304 struct AudioPort port = {};
305 struct AudioPortCapability capability = {};
306 port.dir = PORT_OUT;
307 port.portId = 0;
308 port.portName = const_cast<char*>("primary");
309 int32_t ret = adapter_->GetPortCapability(adapter_, &port, &capability);
310 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
311 }
312
313 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPortCapabilityIsvalid001, TestSize.Level1)
314 {
315 struct AudioPort port = adapterDescs_[0].ports[0];
316 struct AudioPortCapability capability = {};
317 int32_t ret = adapter_->GetPortCapability(adapter_, &port, &capability);
318 ASSERT_TRUE(ret == HDF_SUCCESS);
319 }
320
321 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeNull001, TestSize.Level1)
322 {
323 enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
324 EXPECT_NE(HDF_SUCCESS, adapter_->SetPassthroughMode(nullptr, nullptr, mode));
325 }
326
327 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeNull002, TestSize.Level1)
328 {
329 struct AudioPort port = {};
330 enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
331 EXPECT_NE(HDF_SUCCESS, adapter_->SetPassthroughMode(nullptr, &port, mode));
332 }
333
334 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeInvalid001, TestSize.Level1)
335 {
336 enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
337 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->SetPassthroughMode(adapter_, nullptr, mode));
338 }
339
340 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetPassthroughModeIsvalid001, TestSize.Level1)
341 {
342 struct AudioPort port = {};
343 port.dir = PORT_OUT;
344 port.portId = 0;
345 port.portName = const_cast<char*>("primary");
346 enum AudioPortPassthroughMode mode = PORT_PASSTHROUGH_LPCM;
347 int32_t ret = adapter_->SetPassthroughMode(adapter_, &port, mode);
348 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
349 }
350
351 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeNull001, TestSize.Level1)
352 {
353 EXPECT_NE(HDF_SUCCESS, adapter_->GetPassthroughMode(nullptr, nullptr, nullptr));
354 }
355
356 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeNull002, TestSize.Level1)
357 {
358 struct AudioPort port = {};
359 enum AudioPortPassthroughMode mode;
360 EXPECT_NE(HDF_SUCCESS, adapter_->GetPassthroughMode(nullptr, &port, &mode));
361 }
362
363 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeInvalid001, TestSize.Level1)
364 {
365 enum AudioPortPassthroughMode mode;
366 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetPassthroughMode(adapter_, nullptr, &mode));
367 }
368
369 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetPassthroughModeIsvalid001, TestSize.Level1)
370 {
371 struct AudioPort port = {};
372 port.dir = PORT_OUT;
373 port.portId = 0;
374 port.portName = const_cast<char*>("primary");
375 enum AudioPortPassthroughMode mode;
376 int32_t ret = adapter_->GetPassthroughMode(adapter_, &port, &mode);
377 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
378 }
379
380 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusNull001, TestSize.Level1)
381 {
382 EXPECT_NE(HDF_SUCCESS, adapter_->GetDeviceStatus(nullptr, nullptr));
383 }
384
385 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusNull002, TestSize.Level1)
386 {
387 struct AudioDeviceStatus status = {};
388 EXPECT_NE(HDF_SUCCESS, adapter_->GetDeviceStatus(nullptr, &status));
389 }
390
391 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusInvalid001, TestSize.Level1)
392 {
393 EXPECT_EQ(HDF_ERR_INVALID_PARAM, adapter_->GetDeviceStatus(adapter_, nullptr));
394 }
395
396 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetDeviceStatusIsvalid001, TestSize.Level1)
397 {
398 struct AudioDeviceStatus status = {};
399 EXPECT_EQ(HDF_SUCCESS, adapter_->GetDeviceStatus(adapter_, &status));
400 }
401
402 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetMicMuteNull001, TestSize.Level1)
403 {
404 bool mute = false;
405 EXPECT_NE(HDF_SUCCESS, adapter_->SetMicMute(nullptr, mute));
406 }
407
408 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetMicMuteIsvalid001, TestSize.Level1)
409 {
410 bool mute = false;
411 int32_t ret = adapter_->SetMicMute(adapter_, mute);
412 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
413 }
414
415 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteNull001, TestSize.Level1)
416 {
417 EXPECT_NE(HDF_SUCCESS, adapter_->GetMicMute(nullptr, nullptr));
418 }
419
420 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteNull002, TestSize.Level1)
421 {
422 bool mute = false;
423 EXPECT_NE(HDF_SUCCESS, adapter_->GetMicMute(nullptr, &mute));
424 }
425
426 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetMicMuteIsvalid001, TestSize.Level1)
427 {
428 bool mute = false;
429 int32_t ret = adapter_->GetMicMute(adapter_, &mute);
430 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
431 }
432
433 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetVoiceVolumeNull001, TestSize.Level1)
434 {
435 float volume = 0;
436 EXPECT_NE(HDF_SUCCESS, adapter_->SetVoiceVolume(nullptr, volume));
437 }
438
439 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetVoiceVolumeIsvalid001, TestSize.Level1)
440 {
441 float volume = 0;
442 int32_t ret = adapter_->SetVoiceVolume(adapter_, volume);
443 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
444 }
445
446 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsNull001, TestSize.Level1)
447 {
448 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
449 EXPECT_NE(HDF_SUCCESS, adapter_->SetExtraParams(nullptr, key, nullptr, nullptr));
450 }
451
452 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsNull002, TestSize.Level1)
453 {
454 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
455 char condition[AUDIO_ADAPTER_BUF_TEST];
456 char value[AUDIO_ADAPTER_BUF_TEST];
457 EXPECT_NE(HDF_SUCCESS, adapter_->SetExtraParams(nullptr, key, condition, value));
458 }
459
460 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterSetExtraParamsIsvalid001, TestSize.Level1)
461 {
462 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_LOWPOWER;
463 char condition[AUDIO_ADAPTER_BUF_TEST];
464 const char *value = "sup_sampling_rates=4800;sup_channels=1;sup_formats=2;";
465 int32_t ret = adapter_->SetExtraParams(adapter_, key, condition, value);
466 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
467 }
468
469 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetExtraParamsNull001, TestSize.Level1)
470 {
471 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
472 uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
473 EXPECT_NE(HDF_SUCCESS, adapter_->GetExtraParams(nullptr, key, nullptr, nullptr, valueLen));
474 }
475
476 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetExtraParamsNull002, TestSize.Level1)
477 {
478 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
479 char condition[AUDIO_ADAPTER_BUF_TEST];
480 char value[AUDIO_ADAPTER_BUF_TEST];
481 uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
482 EXPECT_NE(HDF_SUCCESS, adapter_->GetExtraParams(nullptr, key, condition, value, valueLen));
483 }
484
485 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetExtraParamsIsvalid001, TestSize.Level1)
486 {
487 enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
488 char condition[AUDIO_ADAPTER_BUF_TEST];
489 char value[AUDIO_ADAPTER_BUF_TEST] = "sup_sampling_rates=4800;sup_channels=1;sup_formats=2;";
490 uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
491
492 int32_t ret = adapter_->GetExtraParams(adapter_, key, condition, value, valueLen);
493 ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_FAILURE);
494 }
495
496 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterUpdateAudioRouteNull001, TestSize.Level1)
497 {
498 struct AudioRoute route = {};
499 int32_t routeHandle = 0;
500 EXPECT_NE(HDF_SUCCESS, adapter_->UpdateAudioRoute(nullptr, &route, &routeHandle));
501 }
502
503 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterUpdateAudioRouteIsvalid001, TestSize.Level1)
504 {
505 struct AudioRoute route = {};
506 int32_t routeHandle = 0;
507 int32_t ret = adapter_->UpdateAudioRoute(adapter_, &route, &routeHandle);
508 ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_FAILURE);
509 }
510
511 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterReleaseAudioRouteNull001, TestSize.Level1)
512 {
513 int32_t routeHandle = 0;
514 EXPECT_NE(HDF_SUCCESS, adapter_->ReleaseAudioRoute(nullptr, routeHandle));
515 }
516
517 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterReleaseAudioRouteIsvalid001, TestSize.Level1)
518 {
519 int32_t routeHandle = 0;
520 int32_t ret = adapter_->ReleaseAudioRoute(adapter_, routeHandle);
521 ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_FAILURE);
522 }
523
524 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetVersionNull001, TestSize.Level1)
525 {
526 uint32_t majorVer = 0;
527 uint32_t minorVer = 0;
528 EXPECT_NE(HDF_SUCCESS, adapter_->GetVersion(nullptr, &majorVer, &minorVer));
529 }
530
531 HWTEST_F(HdfAudioUtAdapterTest, HdfAudioAdapterGetVersionIsvalid001, TestSize.Level1)
532 {
533 uint32_t majorVer = 0;
534 uint32_t minorVer = 0;
535 int32_t ret = adapter_->GetVersion(adapter_, &majorVer, &minorVer);
536 ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_SUCCESS);
537 }
538 }
539