1 /*
2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef LOG_TAG
17 #define LOG_TAG "AudioDeviceAdapterImplUnitTest"
18 #endif
19
20 #include "audio_device_adapter_impl_unit_test.h"
21
22 #include <chrono>
23 #include <thread>
24
25 #include "audio_errors.h"
26 #include "audio_device_adapter_impl.h"
27 #include "i_audio_device_manager.h"
28
29 using namespace std;
30 using namespace std::chrono;
31 using namespace testing::ext;
32 using namespace testing;
33
34 namespace OHOS {
35 namespace AudioStandard {
36
37 namespace {
38 std::string adapterName = "adapterName";
39 sptr<IAudioAdapter> audioAdapter = nullptr;
40 std::shared_ptr<AudioDeviceAdapterImpl> audioDeviceAdapterImpl =
41 std::make_shared<AudioDeviceAdapterImpl>(adapterName, audioAdapter);
42 }
43
44 class IAudioAdapterFork : public IAudioAdapter {
45 public:
46 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.distributed_audio.audio.v1_0.IAudioAdapter");
47
IAudioAdapterFork()48 IAudioAdapterFork() {};
~IAudioAdapterFork()49 ~IAudioAdapterFork() {};
50
InitAllPorts()51 int32_t InitAllPorts() override
52 {
53 return SUCCESS;
54 };
55
CreateRender(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor & desc,const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs,sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender> & render,uint32_t & renderId)56 int32_t CreateRender(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor& desc,
57 const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs,
58 sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender>& render, uint32_t& renderId) override
59 {
60 return SUCCESS;
61 };
62
DestroyRender(uint32_t renderId)63 int32_t DestroyRender(uint32_t renderId) override
64 {
65 return SUCCESS;
66 };
67
CreateCapture(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor & desc,const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs,sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture> & capture,uint32_t & captureId)68 int32_t CreateCapture(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor& desc,
69 const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs,
70 sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture>& capture, uint32_t& captureId) override
71 {
72 return SUCCESS;
73 };
74
DestroyCapture(uint32_t captureId)75 int32_t DestroyCapture(uint32_t captureId) override
76 {
77 return SUCCESS;
78 };
79
GetPortCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort & port,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortCapability & capability)80 int32_t GetPortCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort& port,
81 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortCapability& capability) override
82 {
83 return SUCCESS;
84 };
85
SetPassthroughMode(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort & port,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPassthroughMode mode)86 int32_t SetPassthroughMode(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort& port,
87 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPassthroughMode mode) override
88 {
89 return SUCCESS;
90 };
91
GetPassthroughMode(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort & port,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPassthroughMode & mode)92 int32_t GetPassthroughMode(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort& port,
93 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPassthroughMode& mode) override
94 {
95 return SUCCESS;
96 };
97
GetDeviceStatus(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceStatus & status)98 int32_t GetDeviceStatus(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceStatus& status) override
99 {
100 return SUCCESS;
101 };
102
UpdateAudioRoute(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute & route,int32_t & routeHandle)103 int32_t UpdateAudioRoute(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute& route,
104 int32_t& routeHandle) override
105 {
106 return SUCCESS;
107 };
108
ReleaseAudioRoute(int32_t routeHandle)109 int32_t ReleaseAudioRoute(int32_t routeHandle) override
110 {
111 return SUCCESS;
112 };
113
SetMicMute(bool mute)114 int32_t SetMicMute(bool mute) override
115 {
116 return SUCCESS;
117 };
118
GetMicMute(bool & mute)119 int32_t GetMicMute(bool& mute) override
120 {
121 return SUCCESS;
122 };
123
SetVoiceVolume(float volume)124 int32_t SetVoiceVolume(float volume) override
125 {
126 return SUCCESS;
127 };
128
SetExtraParams(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey key,const std::string & condition,const std::string & value)129 int32_t SetExtraParams(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey key,
130 const std::string& condition, const std::string& value) override
131 {
132 return SUCCESS;
133 };
134
GetExtraParams(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey key,const std::string & condition,std::string & value)135 int32_t GetExtraParams(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey key,
136 const std::string& condition, std::string& value) override
137 {
138 return SUCCESS;
139 };
140
RegExtraParamObserver(const sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback> & audioCallback,int8_t cookie)141 int32_t RegExtraParamObserver(const sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback>& audioCallback,
142 int8_t cookie) override
143 {
144 return SUCCESS;
145 };
146
GetVersion(uint32_t & majorVer,uint32_t & minorVer)147 int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override
148 {
149 majorVer = 1;
150 minorVer = 0;
151 return HDF_SUCCESS;
152 }
153
IsProxy()154 bool IsProxy() override
155 {
156 return false;
157 }
158
GetDesc()159 const std::u16string GetDesc() override
160 {
161 return metaDescriptor_;
162 }
163 };
164
165 class IAudioRenderFork : public IAudioRender {
166 public:
167 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.distributed_audio.audio.v1_0.IAudioRender");
168
IAudioRenderFork()169 IAudioRenderFork() {};
~IAudioRenderFork()170 ~IAudioRenderFork() {};
171
GetLatency(uint32_t & ms)172 int32_t GetLatency(uint32_t& ms) override
173 {
174 return SUCCESS;
175 };
176
RenderFrame(const std::vector<int8_t> & frame,uint64_t & replyBytes)177 int32_t RenderFrame(const std::vector<int8_t>& frame, uint64_t& replyBytes) override
178 {
179 return SUCCESS;
180 };
181
GetRenderPosition(uint64_t & frames,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp & time)182 int32_t GetRenderPosition(uint64_t& frames,
183 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp& time) override
184 {
185 return SUCCESS;
186 };
187
SetRenderSpeed(float speed)188 int32_t SetRenderSpeed(float speed) override
189 {
190 return SUCCESS;
191 };
192
GetRenderSpeed(float & speed)193 int32_t GetRenderSpeed(float& speed) override
194 {
195 return SUCCESS;
196 };
197
SetChannelMode(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioChannelMode mode)198 int32_t SetChannelMode(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioChannelMode mode) override
199 {
200 return SUCCESS;
201 };
202
GetChannelMode(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioChannelMode & mode)203 int32_t GetChannelMode(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioChannelMode& mode) override
204 {
205 return SUCCESS;
206 };
207
RegCallback(const sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback> & audioCallback,int8_t cookie)208 int32_t RegCallback(const sptr<OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback>& audioCallback,
209 int8_t cookie) override
210 {
211 return SUCCESS;
212 };
213
DrainBuffer(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDrainNotifyType & type)214 int32_t DrainBuffer(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDrainNotifyType& type) override
215 {
216 return SUCCESS;
217 };
218
IsSupportsDrain(bool & support)219 int32_t IsSupportsDrain(bool& support) override
220 {
221 return SUCCESS;
222 };
223
CheckSceneCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor & scene,bool & supported)224 int32_t CheckSceneCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor& scene,
225 bool& supported) override
226 {
227 return SUCCESS;
228 };
229
SelectScene(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor & scene)230 int32_t SelectScene(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor& scene) override
231 {
232 return SUCCESS;
233 };
234
SetMute(bool mute)235 int32_t SetMute(bool mute) override
236 {
237 return SUCCESS;
238 };
239
GetMute(bool & mute)240 int32_t GetMute(bool& mute) override
241 {
242 return SUCCESS;
243 };
244
SetVolume(float volume)245 int32_t SetVolume(float volume) override
246 {
247 return SUCCESS;
248 };
249
GetVolume(float & volume)250 int32_t GetVolume(float& volume) override
251 {
252 return SUCCESS;
253 };
254
GetGainThreshold(float & min,float & max)255 int32_t GetGainThreshold(float& min, float& max) override
256 {
257 return SUCCESS;
258 };
259
GetGain(float & gain)260 int32_t GetGain(float& gain) override
261 {
262 return SUCCESS;
263 };
264
SetGain(float gain)265 int32_t SetGain(float gain) override
266 {
267 return SUCCESS;
268 };
269
GetFrameSize(uint64_t & size)270 int32_t GetFrameSize(uint64_t& size) override
271 {
272 return SUCCESS;
273 };
274
GetFrameCount(uint64_t & count)275 int32_t GetFrameCount(uint64_t& count) override
276 {
277 return SUCCESS;
278 };
279
SetSampleAttributes(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs)280 int32_t SetSampleAttributes(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs) override
281 {
282 return SUCCESS;
283 };
284
GetSampleAttributes(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs)285 int32_t GetSampleAttributes(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs) override
286 {
287 return SUCCESS;
288 };
289
GetCurrentChannelId(uint32_t & channelId)290 int32_t GetCurrentChannelId(uint32_t& channelId) override
291 {
292 return SUCCESS;
293 };
294
SetExtraParams(const std::string & keyValueList)295 int32_t SetExtraParams(const std::string& keyValueList) override
296 {
297 return SUCCESS;
298 };
299
GetExtraParams(std::string & keyValueList)300 int32_t GetExtraParams(std::string& keyValueList) override
301 {
302 return SUCCESS;
303 };
304
ReqMmapBuffer(int32_t reqSize,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioMmapBufferDescriptor & desc)305 int32_t ReqMmapBuffer(int32_t reqSize,
306 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioMmapBufferDescriptor& desc) override
307 {
308 return SUCCESS;
309 };
310
GetMmapPosition(uint64_t & frames,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp & time)311 int32_t GetMmapPosition(uint64_t& frames,
312 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp& time) override
313 {
314 return SUCCESS;
315 };
316
AddAudioEffect(uint64_t effectid)317 int32_t AddAudioEffect(uint64_t effectid) override
318 {
319 return SUCCESS;
320 };
321
RemoveAudioEffect(uint64_t effectid)322 int32_t RemoveAudioEffect(uint64_t effectid) override
323 {
324 return SUCCESS;
325 };
326
GetFrameBufferSize(uint64_t & bufferSize)327 int32_t GetFrameBufferSize(uint64_t& bufferSize) override
328 {
329 return SUCCESS;
330 };
331
Start()332 int32_t Start() override
333 {
334 return SUCCESS;
335 };
336
Stop()337 int32_t Stop() override
338 {
339 return SUCCESS;
340 };
341
Pause()342 int32_t Pause() override
343 {
344 return SUCCESS;
345 };
346
Resume()347 int32_t Resume() override
348 {
349 return SUCCESS;
350 };
351
Flush()352 int32_t Flush() override
353 {
354 return SUCCESS;
355 };
356
TurnStandbyMode()357 int32_t TurnStandbyMode() override
358 {
359 return SUCCESS;
360 };
361
AudioDevDump(int32_t range,int32_t fd)362 int32_t AudioDevDump(int32_t range, int32_t fd) override
363 {
364 return SUCCESS;
365 };
366
IsSupportsPauseAndResume(bool & supportPause,bool & supportResume)367 int32_t IsSupportsPauseAndResume(bool& supportPause, bool& supportResume) override
368 {
369 return SUCCESS;
370 };
371
GetVersion(uint32_t & majorVer,uint32_t & minorVer)372 int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override
373 {
374 majorVer = 1;
375 minorVer = 0;
376 return HDF_SUCCESS;
377 }
378
IsProxy()379 bool IsProxy() override
380 {
381 return false;
382 }
383
GetDesc()384 const std::u16string GetDesc() override
385 {
386 return metaDescriptor_;
387 }
388 };
389
390 class IAudioCaptureFork : public IAudioCapture {
391 public:
392 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.distributed_audio.audio.v1_0.IAudioCapture");
393
IAudioCaptureFork()394 IAudioCaptureFork() {};
~IAudioCaptureFork()395 ~IAudioCaptureFork() {};
396
CaptureFrame(std::vector<int8_t> & frame,uint64_t & replyBytes)397 int32_t CaptureFrame(std::vector<int8_t>& frame, uint64_t& replyBytes) override
398 {
399 return SUCCESS;
400 };
401
GetCapturePosition(uint64_t & frames,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp & time)402 int32_t GetCapturePosition(uint64_t& frames,
403 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp& time) override
404 {
405 return SUCCESS;
406 };
407
CheckSceneCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor & scene,bool & supported)408 int32_t CheckSceneCapability(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor& scene,
409 bool& supported) override
410 {
411 return SUCCESS;
412 };
413
SelectScene(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor & scene)414 int32_t SelectScene(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor& scene) override
415 {
416 return SUCCESS;
417 };
418
SetMute(bool mute)419 int32_t SetMute(bool mute) override
420 {
421 return SUCCESS;
422 };
423
GetMute(bool & mute)424 int32_t GetMute(bool& mute) override
425 {
426 return SUCCESS;
427 };
428
SetVolume(float volume)429 int32_t SetVolume(float volume) override
430 {
431 return SUCCESS;
432 };
433
GetVolume(float & volume)434 int32_t GetVolume(float& volume) override
435 {
436 return SUCCESS;
437 };
438
GetGainThreshold(float & min,float & max)439 int32_t GetGainThreshold(float& min, float& max) override
440 {
441 return SUCCESS;
442 };
443
GetGain(float & gain)444 int32_t GetGain(float& gain) override
445 {
446 return SUCCESS;
447 };
448
SetGain(float gain)449 int32_t SetGain(float gain) override
450 {
451 return SUCCESS;
452 };
453
GetFrameSize(uint64_t & size)454 int32_t GetFrameSize(uint64_t& size) override
455 {
456 return SUCCESS;
457 };
458
GetFrameCount(uint64_t & count)459 int32_t GetFrameCount(uint64_t& count) override
460 {
461 return SUCCESS;
462 };
463
SetSampleAttributes(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs)464 int32_t SetSampleAttributes(const OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs) override
465 {
466 return SUCCESS;
467 };
468
GetSampleAttributes(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes & attrs)469 int32_t GetSampleAttributes(OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes& attrs) override
470 {
471 return SUCCESS;
472 };
473
GetCurrentChannelId(uint32_t & channelId)474 int32_t GetCurrentChannelId(uint32_t& channelId) override
475 {
476 return SUCCESS;
477 };
478
SetExtraParams(const std::string & keyValueList)479 int32_t SetExtraParams(const std::string& keyValueList) override
480 {
481 return SUCCESS;
482 };
483
GetExtraParams(std::string & keyValueList)484 int32_t GetExtraParams(std::string& keyValueList) override
485 {
486 return SUCCESS;
487 };
488
ReqMmapBuffer(int32_t reqSize,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioMmapBufferDescriptor & desc)489 int32_t ReqMmapBuffer(int32_t reqSize,
490 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioMmapBufferDescriptor& desc) override
491 {
492 return SUCCESS;
493 };
494
GetMmapPosition(uint64_t & frames,OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp & time)495 int32_t GetMmapPosition(uint64_t& frames,
496 OHOS::HDI::DistributedAudio::Audio::V1_0::AudioTimeStamp& time) override
497 {
498 return SUCCESS;
499 };
500
AddAudioEffect(uint64_t effectid)501 int32_t AddAudioEffect(uint64_t effectid) override
502 {
503 return SUCCESS;
504 };
505
RemoveAudioEffect(uint64_t effectid)506 int32_t RemoveAudioEffect(uint64_t effectid) override
507 {
508 return SUCCESS;
509 };
510
GetFrameBufferSize(uint64_t & bufferSize)511 int32_t GetFrameBufferSize(uint64_t& bufferSize) override
512 {
513 return SUCCESS;
514 };
515
Start()516 int32_t Start() override
517 {
518 return SUCCESS;
519 };
520
Stop()521 int32_t Stop() override
522 {
523 return SUCCESS;
524 };
525
Pause()526 int32_t Pause() override
527 {
528 return SUCCESS;
529 };
530
Resume()531 int32_t Resume() override
532 {
533 return SUCCESS;
534 };
535
Flush()536 int32_t Flush() override
537 {
538 return SUCCESS;
539 };
540
TurnStandbyMode()541 int32_t TurnStandbyMode() override
542 {
543 return SUCCESS;
544 };
545
AudioDevDump(int32_t range,int32_t fd)546 int32_t AudioDevDump(int32_t range, int32_t fd) override
547 {
548 return SUCCESS;
549 };
550
IsSupportsPauseAndResume(bool & supportPause,bool & supportResume)551 int32_t IsSupportsPauseAndResume(bool& supportPause, bool& supportResume) override
552 {
553 return SUCCESS;
554 };
555
GetVersion(uint32_t & majorVer,uint32_t & minorVer)556 int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override
557 {
558 majorVer = 1;
559 minorVer = 0;
560 return HDF_SUCCESS;
561 }
562
IsProxy()563 bool IsProxy() override
564 {
565 return false;
566 }
567
GetDesc()568 const std::u16string GetDesc() override
569 {
570 return metaDescriptor_;
571 }
572 };
573
SetUpTestCase(void)574 void AudioDeviceAdapterImplUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)575 void AudioDeviceAdapterImplUnitTest::TearDownTestCase(void) {}
SetUp(void)576 void AudioDeviceAdapterImplUnitTest::SetUp(void) {}
TearDown(void)577 void AudioDeviceAdapterImplUnitTest::TearDown(void) {}
578
579 /**
580 * @tc.name : Test HandleRenderParamEvent API
581 * @tc.number : HandleRenderParamEvent_001
582 * @tc.desc : Test HandleRenderParamEvent interface.
583 */
584 HWTEST(AudioDeviceAdapterImplUnitTest, HandleRenderParamEvent_001, TestSize.Level1)
585 {
586 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
587 sptr<IAudioRender> render;
588 DevicePortInfo portInfo;
589 portInfo.devAdpCb = nullptr;
590 audioDeviceAdapterImpl->renderPorts_.emplace(render, portInfo);
591 const char *condition = "condition";
592 const char *value = "value";
593 int32_t result = audioDeviceAdapterImpl->HandleRenderParamEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
594 EXPECT_NE(SUCCESS, result);
595 }
596
597 /**
598 * @tc.name : Test HandleRenderParamEvent API
599 * @tc.number : HandleRenderParamEvent_002
600 * @tc.desc : Test HandleRenderParamEvent interface.
601 */
602 HWTEST(AudioDeviceAdapterImplUnitTest, HandleRenderParamEvent_002, TestSize.Level1)
603 {
604 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
605 const char *condition = "condition";
606 const char *value = "value";
607 int32_t result = audioDeviceAdapterImpl->HandleRenderParamEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
608 EXPECT_NE(SUCCESS, result);
609 }
610
611 /**
612 * @tc.name : Test HandleCaptureParamEvent API
613 * @tc.number : HandleCaptureParamEvent_001
614 * @tc.desc : Test HandleCaptureParamEvent interface.
615 */
616 HWTEST(AudioDeviceAdapterImplUnitTest, HandleCaptureParamEvent_001, TestSize.Level1)
617 {
618 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
619 sptr<IAudioCapture> capture;
620 DevicePortInfo portInfo;
621 portInfo.devAdpCb = nullptr;
622 audioDeviceAdapterImpl->capturePorts_.emplace(capture, portInfo);
623 const char *condition = "condition";
624 const char *value = "value";
625 int32_t result = audioDeviceAdapterImpl->HandleCaptureParamEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
626 EXPECT_NE(SUCCESS, result);
627 }
628
629 /**
630 * @tc.name : Test HandleCaptureParamEvent API
631 * @tc.number : HandleCaptureParamEvent_002
632 * @tc.desc : Test HandleCaptureParamEvent interface.
633 */
634 HWTEST(AudioDeviceAdapterImplUnitTest, HandleCaptureParamEvent_002, TestSize.Level1)
635 {
636 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
637 const char *condition = "condition";
638 const char *value = "value";
639 int32_t result = audioDeviceAdapterImpl->HandleCaptureParamEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
640 EXPECT_NE(SUCCESS, result);
641 }
642
643 /**
644 * @tc.name : Test HandleStateChangeEvent API
645 * @tc.number : HandleStateChangeEvent_001
646 * @tc.desc : Test HandleStateChangeEvent interface.
647 */
648 HWTEST(AudioDeviceAdapterImplUnitTest, HandleStateChangeEvent_001, TestSize.Level1)
649 {
650 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
651 const char *condition = "ERR_EVENT;DEVICE_TYPE=SPK";
652 const char *value = nullptr;
653 int32_t result = audioDeviceAdapterImpl->HandleStateChangeEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
654 EXPECT_NE(SUCCESS, result);
655 }
656
657 /**
658 * @tc.name : Test HandleStateChangeEvent API
659 * @tc.number : HandleStateChangeEvent_002
660 * @tc.desc : Test HandleStateChangeEvent interface.
661 */
662 HWTEST(AudioDeviceAdapterImplUnitTest, HandleStateChangeEvent_002, TestSize.Level1)
663 {
664 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
665 const char *condition = "ERR_EVENT;DEVICE_TYPE=1";
666 const char *value = nullptr;
667 int32_t result = audioDeviceAdapterImpl->HandleStateChangeEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
668 EXPECT_NE(SUCCESS, result);
669 }
670
671 /**
672 * @tc.name : Test HandleStateChangeEvent API
673 * @tc.number : HandleStateChangeEvent_003
674 * @tc.desc : Test HandleStateChangeEvent interface.
675 */
676 HWTEST(AudioDeviceAdapterImplUnitTest, HandleStateChangeEvent_003, TestSize.Level1)
677 {
678 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
679 const char *condition = "ERR_EVENT;DEVICE_TYPE=2";
680 const char *value = nullptr;
681 int32_t result = audioDeviceAdapterImpl->HandleStateChangeEvent(audioDeviceAdapterImpl, VOLUME, condition, value);
682 EXPECT_NE(SUCCESS, result);
683 }
684
685 /**
686 * @tc.name : Test ParamEventCallback API
687 * @tc.number : ParamEventCallback_001
688 * @tc.desc : Test ParamEventCallback interface.
689 */
690 HWTEST(AudioDeviceAdapterImplUnitTest, ParamEventCallback_001, TestSize.Level1)
691 {
692 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
693 AudioParamKey key = PARAM_KEY_STATE;
694 AudioExtParamKey extKey = AudioExtParamKey(key);
695 const char *condition = "condition";
696 const char *value = "value";
697 void *reserved = nullptr;
698 int32_t result = audioDeviceAdapterImpl->
699 ParamEventCallback(extKey, condition, value, reserved, audioDeviceAdapterImpl);
700 EXPECT_NE(SUCCESS, result);
701 }
702
703 /**
704 * @tc.name : Test ParamEventCallback API
705 * @tc.number : ParamEventCallback_002
706 * @tc.desc : Test ParamEventCallback interface.
707 */
708 HWTEST(AudioDeviceAdapterImplUnitTest, ParamEventCallback_002, TestSize.Level1)
709 {
710 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
711 AudioParamKey key = VOLUME;
712 AudioExtParamKey extKey = AudioExtParamKey(key);
713 const char *condition = "condition";
714 const char *value = "value";
715 void *reserved = nullptr;
716 int32_t result = audioDeviceAdapterImpl->
717 ParamEventCallback(extKey, condition, value, reserved, audioDeviceAdapterImpl);
718 EXPECT_EQ(SUCCESS, result);
719 }
720
721 /**
722 * @tc.name : Test ParamEventCallback API
723 * @tc.number : ParamEventCallback_003
724 * @tc.desc : Test ParamEventCallback interface.
725 */
726 HWTEST(AudioDeviceAdapterImplUnitTest, ParamEventCallback_003, TestSize.Level1)
727 {
728 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
729 AudioParamKey key = INTERRUPT;
730 AudioExtParamKey extKey = AudioExtParamKey(key);
731 const char *condition = "condition";
732 const char *value = "value";
733 void *reserved = nullptr;
734 int32_t result = audioDeviceAdapterImpl->
735 ParamEventCallback(extKey, condition, value, reserved, audioDeviceAdapterImpl);
736 EXPECT_EQ(SUCCESS, result);
737 }
738
739 /**
740 * @tc.name : Test ParamEventCallback API
741 * @tc.number : ParamEventCallback_004
742 * @tc.desc : Test ParamEventCallback interface.
743 */
744 HWTEST(AudioDeviceAdapterImplUnitTest, ParamEventCallback_004, TestSize.Level1)
745 {
746 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
747 AudioParamKey key = NONE;
748 AudioExtParamKey extKey = AudioExtParamKey(key);
749 const char *condition = "condition";
750 const char *value = "value";
751 void *reserved = nullptr;
752 int32_t result = audioDeviceAdapterImpl->
753 ParamEventCallback(extKey, condition, value, reserved, audioDeviceAdapterImpl);
754 EXPECT_NE(SUCCESS, result);
755 }
756
757 #ifdef FEATURE_DISTRIBUTE_AUDIO
758 /**
759 * @tc.name : Test RegExtraParamObserver API
760 * @tc.number : RegExtraParamObserver_001
761 * @tc.desc : Test RegExtraParamObserver interface.
762 */
763 HWTEST(AudioDeviceAdapterImplUnitTest, RegExtraParamObserver_001, TestSize.Level1)
764 {
765 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
766 audioDeviceAdapterImpl->isParamCbReg_ = true;
767 int32_t result = audioDeviceAdapterImpl->RegExtraParamObserver();
768 EXPECT_EQ(SUCCESS, result);
769 }
770 #endif
771
772 /**
773 * @tc.name : Test RegExtraParamObserver API
774 * @tc.number : RegExtraParamObserver_002
775 * @tc.desc : Test RegExtraParamObserver interface.
776 */
777 HWTEST(AudioDeviceAdapterImplUnitTest, RegExtraParamObserver_002, TestSize.Level1)
778 {
779 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
780 audioDeviceAdapterImpl->isParamCbReg_ = false;
781 int32_t result = audioDeviceAdapterImpl->RegExtraParamObserver();
782 EXPECT_NE(SUCCESS, result);
783 }
784
785 /**
786 * @tc.name : Test CreateRender API
787 * @tc.number : CreateRender_001
788 * @tc.desc : Test CreateRender interface.
789 */
790 HWTEST(AudioDeviceAdapterImplUnitTest, CreateRender_001, TestSize.Level1)
791 {
792 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
793 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
794 AudioDeviceDescriptor devDesc;
795 AudioSampleAttributes attr;
796 sptr<IAudioRender> audioRender = new IAudioRenderFork();
797 IAudioDeviceAdapterCallback *renderCb = nullptr;
798 uint32_t renderId = 0;
799 int32_t result = audioDeviceAdapterImpl->CreateRender(devDesc, attr, audioRender, renderCb, renderId);
800 EXPECT_EQ(SUCCESS, result);
801 }
802
803 /**
804 * @tc.name : Test CreateRender API
805 * @tc.number : CreateRender_002
806 * @tc.desc : Test CreateRender interface.
807 */
808 HWTEST(AudioDeviceAdapterImplUnitTest, CreateRender_002, TestSize.Level1)
809 {
810 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
811 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
812 DevicePortInfo portInfo;
813 AudioDeviceDescriptor devDesc;
814 AudioSampleAttributes attr;
815 sptr<IAudioRender> audioRender = new IAudioRenderFork();
816 IAudioDeviceAdapterCallback *renderCb = nullptr;
817 uint32_t renderId = 0;
818 audioDeviceAdapterImpl->renderPorts_.emplace(audioRender, portInfo);
819 int32_t result = audioDeviceAdapterImpl->CreateRender(devDesc, attr, audioRender, renderCb, renderId);
820 EXPECT_EQ(SUCCESS, result);
821 }
822
823 /**
824 * @tc.name : Test DestroyRender API
825 * @tc.number : DestroyRender_001
826 * @tc.desc : Test DestroyRender interface.
827 */
828 HWTEST(AudioDeviceAdapterImplUnitTest, DestroyRender_001, TestSize.Level1)
829 {
830 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
831 sptr<IAudioRender> audioRender = new IAudioRenderFork();
832 uint32_t renderId = 0;
833 audioDeviceAdapterImpl->DestroyRender(audioRender, renderId);
834 EXPECT_NE(audioDeviceAdapterImpl, nullptr);
835 }
836
837 /**
838 * @tc.name : Test DestroyRender API
839 * @tc.number : DestroyRender_002
840 * @tc.desc : Test DestroyRender interface.
841 */
842 HWTEST(AudioDeviceAdapterImplUnitTest, DestroyRender_002, TestSize.Level1)
843 {
844 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
845 DevicePortInfo portInfo;
846 sptr<IAudioRender> audioRender = new IAudioRenderFork();
847 uint32_t renderId = 0;
848 audioDeviceAdapterImpl->renderPorts_.emplace(audioRender, portInfo);
849 audioDeviceAdapterImpl->DestroyRender(audioRender, renderId);
850 EXPECT_NE(audioDeviceAdapterImpl, nullptr);
851 }
852
853 /**
854 * @tc.name : Test CreateCapture API
855 * @tc.number : CreateCapture_001
856 * @tc.desc : Test CreateCapture interface.
857 */
858 HWTEST(AudioDeviceAdapterImplUnitTest, CreateCapture_001, TestSize.Level1)
859 {
860 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
861 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
862 DevicePortInfo portInfo;
863 AudioDeviceDescriptor devDesc;
864 AudioSampleAttributes attr;
865 sptr<IAudioCapture> audioCapture = new IAudioCaptureFork();
866 IAudioDeviceAdapterCallback *captureCb = nullptr;
867 uint32_t captureId = 0;
868 audioDeviceAdapterImpl->capturePorts_.emplace(audioCapture, portInfo);
869 int32_t result = audioDeviceAdapterImpl->CreateCapture(devDesc, attr, audioCapture, captureCb, captureId);
870 EXPECT_EQ(SUCCESS, result);
871 }
872
873 /**
874 * @tc.name : Test CreateCapture API
875 * @tc.number : CreateCapture_002
876 * @tc.desc : Test CreateCapture interface.
877 */
878 HWTEST(AudioDeviceAdapterImplUnitTest, CreateCapture_002, TestSize.Level1)
879 {
880 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
881 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
882 AudioDeviceDescriptor devDesc;
883 AudioSampleAttributes attr;
884 sptr<IAudioCapture> audioCapture = new IAudioCaptureFork();
885 IAudioDeviceAdapterCallback *captureCb = nullptr;
886 uint32_t captureId = 0;
887 int32_t result = audioDeviceAdapterImpl->CreateCapture(devDesc, attr, audioCapture, captureCb, captureId);
888 EXPECT_EQ(SUCCESS, result);
889 }
890
891 /**
892 * @tc.name : Test DestroyCapture API
893 * @tc.number : DestroyCapture_001
894 * @tc.desc : Test DestroyCapture interface.
895 */
896 HWTEST(AudioDeviceAdapterImplUnitTest, DestroyCapture_001, TestSize.Level1)
897 {
898 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
899 sptr<IAudioCapture> audioCapture = new IAudioCaptureFork();
900 uint32_t captureId = 0;
901 audioDeviceAdapterImpl->DestroyCapture(audioCapture, captureId);
902 EXPECT_NE(audioDeviceAdapterImpl, nullptr);
903 }
904
905 /**
906 * @tc.name : Test DestroyCapture API
907 * @tc.number : DestroyCapture_002
908 * @tc.desc : Test DestroyCapture interface.
909 */
910 HWTEST(AudioDeviceAdapterImplUnitTest, DestroyCapture_002, TestSize.Level1)
911 {
912 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
913 sptr<IAudioCapture> audioCapture = new IAudioCaptureFork();
914 DevicePortInfo portInfo;
915 uint32_t captureId = 0;
916 audioDeviceAdapterImpl->capturePorts_.emplace(audioCapture, portInfo);
917 audioDeviceAdapterImpl->DestroyCapture(audioCapture, captureId);
918 EXPECT_NE(audioDeviceAdapterImpl, nullptr);
919 }
920
921 /**
922 * @tc.name : Test Release API
923 * @tc.number : Release_001
924 * @tc.desc : Test Release interface.
925 */
926 HWTEST(AudioDeviceAdapterImplUnitTest, Release_001, TestSize.Level1)
927 {
928 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
929 audioDeviceAdapterImpl->audioAdapter_ = nullptr;
930 int32_t result = audioDeviceAdapterImpl->Release();
931 EXPECT_EQ(SUCCESS, result);
932 }
933
934 /**
935 * @tc.name : Test Release API
936 * @tc.number : Release_002
937 * @tc.desc : Test Release interface.
938 */
939 HWTEST(AudioDeviceAdapterImplUnitTest, Release_002, TestSize.Level1)
940 {
941 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
942 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
943 int32_t result = audioDeviceAdapterImpl->Release();
944 EXPECT_NE(SUCCESS, result);
945 }
946
947 /**
948 * @tc.name : Test Release API
949 * @tc.number : Release_003
950 * @tc.desc : Test Release interface.
951 */
952 HWTEST(AudioDeviceAdapterImplUnitTest, Release_003, TestSize.Level1)
953 {
954 ASSERT_TRUE(audioDeviceAdapterImpl != nullptr);
955 audioDeviceAdapterImpl->audioAdapter_ = new IAudioAdapterFork();
956 audioDeviceAdapterImpl->routeHandle_ = 0;
957 int32_t result = audioDeviceAdapterImpl->Release();
958 EXPECT_NE(SUCCESS, result);
959 }
960 } // namespace AudioStandard
961 } // namespace OHOS