1 /*
2 * Copyright (c) 2022 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 "audio_lib_common.h"
17 #include "audio_libcapture_test.h"
18
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::Audio;
22
23 namespace {
24 const string BIND_CONTROL = "control";
25 const string BIND_CAPTURE = "capture";
26 const string BIND_NAME_ERROR = "rendeo";
27
28 class AudioLibCaptureTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 void SetUp();
33 void TearDown();
34 static struct DevHandle *(*BindServiceCaptureSo)(const char *serverName);
35 static int32_t (*InterfaceLibOutputCapture)(struct DevHandle *handle, int cmdId,
36 struct AudioHwCaptureParam *handleData);
37 static int32_t (*InterfaceLibCtlCapture)(struct DevHandle *handle, int cmdId,
38 struct AudioHwCaptureParam *handleData);
39 static void (*CloseServiceCaptureSo)(struct DevHandle *handle);
40 static void *ptrHandle;
41 int32_t BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture, const std::string BindName,
42 const std::string adapterNameCase, struct DevHandle *&handle) const;
43 };
44
45 struct DevHandle *(*AudioLibCaptureTest::BindServiceCaptureSo)(const char *serverName) = nullptr;
46 int32_t (*AudioLibCaptureTest::InterfaceLibOutputCapture)(struct DevHandle *handle, int cmdId,
47 struct AudioHwCaptureParam *handleData) = nullptr;
48 int32_t (*AudioLibCaptureTest::InterfaceLibCtlCapture)(struct DevHandle *handle, int cmdId,
49 struct AudioHwCaptureParam *handleData) = nullptr;
50 void (*AudioLibCaptureTest::CloseServiceCaptureSo)(struct DevHandle *handle) = nullptr;
51 void *AudioLibCaptureTest::ptrHandle = nullptr;
52
SetUpTestCase(void)53 void AudioLibCaptureTest::SetUpTestCase(void)
54 {
55 char resolvedPath[] = HDF_LIBRARY_FULL_PATH("libaudio_capture_adapter");
56 ptrHandle = dlopen(resolvedPath, RTLD_LAZY);
57 if (ptrHandle == nullptr) {
58 return;
59 }
60 BindServiceCaptureSo = reinterpret_cast<struct DevHandle* (*)(const char *serverName)>(dlsym(ptrHandle,
61 "AudioBindServiceCapture"));
62 InterfaceLibOutputCapture = (int32_t (*)(struct DevHandle *handle, int cmdId,
63 struct AudioHwCaptureParam *handleData))dlsym(ptrHandle, "AudioInterfaceLibOutputCapture");
64 InterfaceLibCtlCapture = (int32_t (*)(struct DevHandle *handle, int cmdId,
65 struct AudioHwCaptureParam *handleData))dlsym(ptrHandle, "AudioInterfaceLibCtlCapture");
66 CloseServiceCaptureSo = reinterpret_cast<void (*)(struct DevHandle *handle)>(dlsym(ptrHandle,
67 "AudioCloseServiceCapture"));
68 if (BindServiceCaptureSo == nullptr || CloseServiceCaptureSo == nullptr ||
69 InterfaceLibCtlCapture == nullptr || InterfaceLibOutputCapture == nullptr) {
70 dlclose(ptrHandle);
71 return;
72 }
73 }
74
TearDownTestCase(void)75 void AudioLibCaptureTest::TearDownTestCase(void)
76 {
77 if (BindServiceCaptureSo != nullptr) {
78 BindServiceCaptureSo = nullptr;
79 }
80 if (CloseServiceCaptureSo != nullptr) {
81 CloseServiceCaptureSo = nullptr;
82 }
83 if (InterfaceLibCtlCapture != nullptr) {
84 InterfaceLibCtlCapture = nullptr;
85 }
86 if (InterfaceLibOutputCapture != nullptr) {
87 InterfaceLibOutputCapture = nullptr;
88 }
89 if (ptrHandle != nullptr) {
90 dlclose(ptrHandle);
91 ptrHandle = nullptr;
92 }
93 }
94
SetUp(void)95 void AudioLibCaptureTest::SetUp(void) {}
96
TearDown(void)97 void AudioLibCaptureTest::TearDown(void) {}
98
BindServiceAndHwCapture(struct AudioHwCapture * & hwCapture,const std::string BindName,const std::string adapterNameCase,struct DevHandle * & handle) const99 int32_t AudioLibCaptureTest::BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture,
100 const std::string BindName, const std::string adapterNameCase, struct DevHandle *&handle) const
101 {
102 if (BindServiceCaptureSo == nullptr) {
103 return HDF_FAILURE;
104 }
105 int32_t ret = HDF_FAILURE;
106 handle = BindServiceCaptureSo(BindName.c_str());
107 if (handle == nullptr) {
108 return HDF_FAILURE;
109 }
110 hwCapture = static_cast<struct AudioHwCapture *>(calloc(1, sizeof(*hwCapture)));
111 if (hwCapture == nullptr) {
112 CloseServiceCaptureSo(handle);
113 return HDF_FAILURE;
114 }
115 ret = InitHwCapture(hwCapture, adapterNameCase);
116 if (ret != HDF_SUCCESS) {
117 free(hwCapture);
118 hwCapture = nullptr;
119 CloseServiceCaptureSo(handle);
120 return HDF_FAILURE;
121 }
122 return HDF_SUCCESS;
123 }
124
125 /**
126 * @tc.name Audio_InterfaceLibBindServiceCapture_001
127 * @tc.desc Test AudioBindServiceCapture interface,return 0 is call successfully
128 * @tc.type: FUNC
129 */
130 HWTEST_F(AudioLibCaptureTest, Audio_InterfaceLibBindServiceCapture_001, TestSize.Level1)
131 {
132 struct DevHandle *handle = nullptr;
133 ASSERT_TRUE((BindServiceCaptureSo != nullptr && CloseServiceCaptureSo != nullptr));
134 handle = BindServiceCaptureSo(BIND_CONTROL.c_str());
135 EXPECT_NE(nullptr, handle);
136 CloseServiceCaptureSo(handle);
137 }
138 /**
139 * @tc.name Audio_InterfaceLibBindServiceCapture_002
140 * @tc.desc test Binding failed Service which invalid service Name is rendeo.
141 * @tc.type: FUNC
142 */
143 HWTEST_F(AudioLibCaptureTest, Audio_InterfaceLibBindServicecapture_002, TestSize.Level1)
144 {
145 struct DevHandle *handle = nullptr;
146 ASSERT_TRUE((BindServiceCaptureSo != nullptr && CloseServiceCaptureSo != nullptr));
147 handle = BindServiceCaptureSo(BIND_NAME_ERROR.c_str());
148 if (handle != nullptr) {
149 CloseServiceCaptureSo(handle);
150 ASSERT_EQ(nullptr, handle);
151 }
152 EXPECT_EQ(nullptr, handle);
153 }
154 /**
155 * @tc.name Audio_InterfaceLibBindServiceCapture_003
156 * @tc.desc test Binding failed Service, nullptr pointer passed in.
157 * @tc.type: FUNC
158 */
159 HWTEST_F(AudioLibCaptureTest, Audio_InterfaceLibBindServiceCapture_003, TestSize.Level1)
160 {
161 struct DevHandle *handle = {};
162 char *bindNameNull = nullptr;
163 ASSERT_TRUE((BindServiceCaptureSo != nullptr && CloseServiceCaptureSo != nullptr));
164 handle = BindServiceCaptureSo(bindNameNull);
165 if (handle != nullptr) {
166 CloseServiceCaptureSo(handle);
167 ASSERT_EQ(nullptr, handle);
168 }
169 EXPECT_EQ(nullptr, handle);
170 }
171 /**
172 * @tc.name Audio_InterfaceLibBindServiceCapture_004
173 * @tc.desc test Binding failed Service, Log printing 'service name not support!' and 'Failed to get service!'.
174 * @tc.type: FUNC
175 */
176 HWTEST_F(AudioLibCaptureTest, Audio_InterfaceLibBindServiceCapture_004, TestSize.Level1)
177 {
178 struct DevHandle *handle = nullptr;
179 ASSERT_TRUE((BindServiceCaptureSo != nullptr && CloseServiceCaptureSo != nullptr));
180 string bindNameOverLen = "capturecaptureededededede";
181 handle = BindServiceCaptureSo(bindNameOverLen.c_str());
182 if (handle != nullptr) {
183 CloseServiceCaptureSo(handle);
184 ASSERT_EQ(nullptr, handle);
185 }
186 EXPECT_EQ(nullptr, handle);
187 }
188 /**
189 * @tc.name Audio_InterfaceLibBindServiceCapture_005
190 * @tc.desc test Binding failed Service, Log printing 'Failed to snprintf_s'.
191 * @tc.type: FUNC
192 */
193 HWTEST_F(AudioLibCaptureTest, Audio_InterfaceLibBindServiceCapture_005, TestSize.Level1)
194 {
195 struct DevHandle *handle = nullptr;
196 string bindNameOverLen = "capturecaptureedededededer";
197 ASSERT_TRUE((BindServiceCaptureSo != nullptr && CloseServiceCaptureSo != nullptr));
198 handle = BindServiceCaptureSo(bindNameOverLen.c_str());
199 if (handle != nullptr) {
200 CloseServiceCaptureSo(handle);
201 ASSERT_EQ(nullptr, handle);
202 }
203 EXPECT_EQ(nullptr, handle);
204 }
205 /**
206 * @tc.name AudioInterfaceLibCtlCaptureMuteWriteRead_001
207 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE and
208 * AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE.
209 * @tc.type: FUNC
210 */
211 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibCtlCaptureMuteWriteRead_001, TestSize.Level1)
212 {
213 int32_t ret = HDF_FAILURE;
214 bool muteValue = 1;
215 bool wishValue = 0;
216 bool expectedValue = 1;
217 struct DevHandle *handle = nullptr;
218 struct AudioHwCapture *hwCapture = nullptr;
219
220 ASSERT_TRUE((InterfaceLibCtlCapture != nullptr && CloseServiceCaptureSo != nullptr));
221 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
222 ASSERT_EQ(HDF_SUCCESS, ret);
223
224 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
225 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
226 EXPECT_EQ(HDF_SUCCESS, ret);
227 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
228 EXPECT_EQ(HDF_SUCCESS, ret);
229 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
230 EXPECT_EQ(wishValue, muteValue);
231 hwCapture->captureParam.captureMode.ctlParam.mute = 1;
232 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
233 EXPECT_EQ(HDF_SUCCESS, ret);
234 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
235 EXPECT_EQ(HDF_SUCCESS, ret);
236 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
237 EXPECT_EQ(expectedValue, muteValue);
238 free(hwCapture);
239 hwCapture = nullptr;
240 CloseServiceCaptureSo(handle);
241 }
242 /**
243 * @tc.name AudioInterfaceLibCtlCaptureMuteWriteRead_002
244 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE and
245 * AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE.
246 * @tc.type: FUNC
247 */
248 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibCtlCaptureMuteWriteRead_002, TestSize.Level1)
249 {
250 int32_t ret = HDF_FAILURE;
251 bool muteValue = 0;
252 bool wishValue = 0;
253 bool expectedValue = 1;
254 struct DevHandle *handle = nullptr;
255 struct AudioHwCapture *hwCapture = nullptr;
256 ASSERT_TRUE((InterfaceLibCtlCapture != nullptr && CloseServiceCaptureSo != nullptr));
257 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
258 ASSERT_EQ(HDF_SUCCESS, ret);
259
260 hwCapture->captureParam.captureMode.ctlParam.mute = 2;
261 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
262 EXPECT_EQ(HDF_SUCCESS, ret);
263 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
264 EXPECT_EQ(HDF_SUCCESS, ret);
265 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
266 EXPECT_EQ(expectedValue, muteValue);
267 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
268 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
269 EXPECT_EQ(HDF_SUCCESS, ret);
270 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
271 EXPECT_EQ(HDF_SUCCESS, ret);
272 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
273 EXPECT_EQ(wishValue, muteValue);
274 free(hwCapture);
275 hwCapture = nullptr;
276 CloseServiceCaptureSo(handle);
277 }
278 /**
279 * @tc.name AudioInterfaceLibCtlCaptureAbnormal_001
280 * @tc.desc test InterfaceLibCtlCapture, cmdId is invalid eg 30,so return -1.
281 * @tc.type: FUNC
282 */
283 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibCtlCaptureAbnormal_001, TestSize.Level1)
284 {
285 int32_t ret = HDF_FAILURE;
286 struct DevHandle *handle = nullptr;
287 struct AudioHwCapture *hwCapture = nullptr;
288 ASSERT_TRUE((InterfaceLibCtlCapture != nullptr && CloseServiceCaptureSo != nullptr));
289 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
290 ASSERT_EQ(HDF_SUCCESS, ret);
291
292 ret = InterfaceLibCtlCapture(handle, 30, &hwCapture->captureParam);
293 if (ret == 0) {
294 CloseServiceCaptureSo(handle);
295 free(hwCapture);
296 hwCapture = nullptr;
297 ASSERT_EQ(HDF_FAILURE, ret);
298 }
299 EXPECT_EQ(HDF_FAILURE, ret);
300 CloseServiceCaptureSo(handle);
301 free(hwCapture);
302 hwCapture = nullptr;
303 }
304 /**
305 * @tc.name AudioInterfaceLibCtlCaptureAbnormal_002
306 * @tc.desc test InterfaceLibCtlCapture, handleData is invalid,so return -1.
307 * @tc.type: FUNC
308 */
309 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibCtlCaptureAbnormal_002, TestSize.Level1)
310 {
311 int32_t ret = HDF_FAILURE;
312 struct DevHandle *handle = nullptr;
313 struct AudioHwCaptureParam *handleData = nullptr;
314 ASSERT_TRUE((InterfaceLibCtlCapture != nullptr && CloseServiceCaptureSo != nullptr &&
315 CloseServiceCaptureSo != nullptr));
316 handle = BindServiceCaptureSo(BIND_CONTROL.c_str());
317 ASSERT_NE(nullptr, handle);
318 ret = InterfaceLibCtlCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, handleData);
319 EXPECT_EQ(HDF_FAILURE, ret);
320 CloseServiceCaptureSo(handle);
321 }
322 /**
323 * @tc.name AudioInterfaceLibOutputCaptureHwParams_001
324 * @tc.desc Test AudioOutputcapture interface,return 0 is call successfully.
325 * @tc.type: FUNC
326 */
327 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureHwParams_001, TestSize.Level1)
328 {
329 int32_t ret = HDF_FAILURE;
330 struct DevHandle *handle = nullptr;
331 struct AudioHwCapture *hwCapture = nullptr;
332 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
333 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
334 ASSERT_EQ(HDF_SUCCESS, ret);
335
336 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
337 EXPECT_EQ(HDF_SUCCESS, ret);
338 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
339 EXPECT_EQ(HDF_SUCCESS, ret);
340 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
341 EXPECT_EQ(HDF_SUCCESS, ret);
342 CloseServiceCaptureSo(handle);
343 free(hwCapture);
344 hwCapture = nullptr;
345 }
346 /**
347 * @tc.name AudioInterfaceLibOutputCapturePrepare_001
348 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE.
349 * @tc.type: FUNC
350 */
351 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCapturePrepare_001, TestSize.Level1)
352 {
353 int32_t ret = HDF_FAILURE;
354 struct AudioHwCapture *hwCapture = nullptr;
355 struct DevHandle *handle = nullptr;
356 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
357 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
358 ASSERT_EQ(HDF_SUCCESS, ret);
359
360 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
361 EXPECT_EQ(HDF_SUCCESS, ret);
362 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
363 EXPECT_EQ(HDF_SUCCESS, ret);
364 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
365 EXPECT_EQ(HDF_SUCCESS, ret);
366 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
367 EXPECT_EQ(HDF_SUCCESS, ret);
368 CloseServiceCaptureSo(handle);
369 free(hwCapture);
370 hwCapture = nullptr;
371 }
372 /**
373 * @tc.name AudioInterfaceLibOutputCaptureStart_001
374 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTRL_START_CAPTURE.
375 * @tc.type: FUNC
376 */
377 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureStart_001, TestSize.Level1)
378 {
379 struct DevHandle *handle = nullptr;
380 struct AudioHwCapture *hwCapture = nullptr;
381 int32_t ret = HDF_FAILURE;
382 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
383 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
384 ASSERT_EQ(HDF_SUCCESS, ret);
385
386 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
387 EXPECT_EQ(HDF_SUCCESS, ret);
388 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
389 EXPECT_EQ(HDF_SUCCESS, ret);
390 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
391 EXPECT_EQ(HDF_SUCCESS, ret);
392 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
393 EXPECT_EQ(HDF_SUCCESS, ret);
394 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
395 EXPECT_EQ(HDF_SUCCESS, ret);
396 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
397 EXPECT_EQ(HDF_SUCCESS, ret);
398 CloseServiceCaptureSo(handle);
399 free(hwCapture);
400 hwCapture = nullptr;
401 }
402 /**
403 * @tc.name AudioInterfaceLibOutputCaptureReadStop_001
404 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTL_READ and AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE.
405 * @tc.type: FUNC
406 */
407 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureReadStop_001, TestSize.Level1)
408 {
409 int32_t ret = HDF_FAILURE;
410 struct DevHandle *handle = nullptr;
411 struct AudioHwCapture *hwCapture = nullptr;
412 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
413 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
414 ASSERT_EQ(HDF_SUCCESS, ret);
415
416 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
417 EXPECT_EQ(HDF_SUCCESS, ret);
418 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
419 EXPECT_EQ(HDF_SUCCESS, ret);
420 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
421 EXPECT_EQ(HDF_SUCCESS, ret);
422 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
423 EXPECT_EQ(HDF_SUCCESS, ret);
424 hwCapture->captureParam.frameCaptureMode.buffer = static_cast<char *>(calloc(1, 16384));
425 if (hwCapture->captureParam.frameCaptureMode.buffer == nullptr) {
426 CloseServiceCaptureSo(handle);
427 free(hwCapture);
428 hwCapture = nullptr;
429 ASSERT_NE(nullptr, hwCapture);
430 }
431 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, &hwCapture->captureParam);
432 EXPECT_EQ(HDF_SUCCESS, ret);
433 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
434 EXPECT_EQ(HDF_SUCCESS, ret);
435 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
436 EXPECT_EQ(HDF_SUCCESS, ret);
437 CloseServiceCaptureSo(handle);
438 free(hwCapture->captureParam.frameCaptureMode.buffer);
439 hwCapture->captureParam.frameCaptureMode.buffer = nullptr;
440 free(hwCapture);
441 hwCapture = nullptr;
442 }
443 /**
444 * @tc.name AudioInterfaceLibOutputCapture_001
445 * @tc.desc test Audio lib Interface CtlCapture and OutputCapture,Data stream and control stream send successful.
446 * @tc.type: FUNC
447 */
448 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCapture_001, TestSize.Level1)
449 {
450 struct DevHandle *handle1 = nullptr;
451 struct AudioHwCapture *hwCapture = nullptr;
452 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && InterfaceLibCtlCapture != nullptr &&
453 CloseServiceCaptureSo != nullptr));
454 int32_t ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle1);
455 ASSERT_EQ(HDF_SUCCESS, ret);
456 struct DevHandle *handle2 = BindServiceCaptureSo(BIND_CAPTURE.c_str());
457 if (handle2 == nullptr) {
458 CloseServiceCaptureSo(handle1);
459 free(hwCapture);
460 ASSERT_NE(nullptr, handle2);
461 }
462 if (hwCapture != nullptr) {
463 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
464 ret = InterfaceLibCtlCapture(handle1, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
465 EXPECT_EQ(HDF_SUCCESS, ret);
466 ret = InterfaceLibCtlCapture(handle1, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
467 EXPECT_EQ(HDF_SUCCESS, ret);
468 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
469 EXPECT_EQ(HDF_SUCCESS, ret);
470 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
471 EXPECT_EQ(HDF_SUCCESS, ret);
472 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
473 EXPECT_EQ(HDF_SUCCESS, ret);
474 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
475 EXPECT_EQ(HDF_SUCCESS, ret);
476 hwCapture->captureParam.frameCaptureMode.buffer = static_cast<char *>(calloc(1, 16384));
477 if (hwCapture->captureParam.frameCaptureMode.buffer == nullptr) {
478 CloseServiceCaptureSo(handle1);
479 CloseServiceCaptureSo(handle2);
480 free(hwCapture);
481 hwCapture = nullptr;
482 ASSERT_NE(nullptr, hwCapture);
483 }
484 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_READ, &hwCapture->captureParam);
485 EXPECT_EQ(HDF_SUCCESS, ret);
486 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
487 EXPECT_EQ(HDF_SUCCESS, ret);
488 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
489 EXPECT_EQ(HDF_SUCCESS, ret);
490 if (hwCapture->captureParam.frameCaptureMode.buffer != nullptr) {
491 free(hwCapture->captureParam.frameCaptureMode.buffer);
492 }
493 free(hwCapture);
494 }
495 CloseServiceCaptureSo(handle1);
496 CloseServiceCaptureSo(handle2);
497 }
498 /**
499 * @tc.name AudioInterfaceLibOutputCapturePause_001
500 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIODRV_CTL_IOCTL_PAUSE_WRITE.
501 * @tc.type: FUNC
502 */
503 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCapturePause_001, TestSize.Level1)
504 {
505 int32_t ret = HDF_FAILURE;
506 struct DevHandle *handle = {};
507 struct AudioHwCapture *hwCapture = nullptr;
508 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
509 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
510 ASSERT_EQ(HDF_SUCCESS, ret);
511 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
512 EXPECT_EQ(HDF_SUCCESS, ret);
513 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
514 EXPECT_EQ(HDF_SUCCESS, ret);
515 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
516 EXPECT_EQ(HDF_SUCCESS, ret);
517 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
518 EXPECT_EQ(HDF_SUCCESS, ret);
519 hwCapture->captureParam.captureMode.ctlParam.pause = 1;
520 ret = InterfaceLibOutputCapture(handle, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE, &hwCapture->captureParam);
521 EXPECT_EQ(HDF_SUCCESS, ret);
522 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
523 EXPECT_EQ(HDF_SUCCESS, ret);
524 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
525 EXPECT_EQ(HDF_SUCCESS, ret);
526 CloseServiceCaptureSo(handle);
527 free(hwCapture);
528 hwCapture = nullptr;
529 }
530 /**
531 * @tc.name AudioInterfaceLibOutputCaptureResume_001
532 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIODRV_CTL_IOCTL_PAUSE_WRITE.
533 * @tc.type: FUNC
534 */
535 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureResume_001, TestSize.Level1)
536 {
537 int32_t ret = HDF_FAILURE;
538 struct AudioHwCapture *hwCapture = nullptr;
539 struct DevHandle *handle = {};
540 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
541 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
542 ASSERT_EQ(HDF_SUCCESS, ret);
543 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
544 EXPECT_EQ(HDF_SUCCESS, ret);
545 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
546 EXPECT_EQ(HDF_SUCCESS, ret);
547 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
548 EXPECT_EQ(HDF_SUCCESS, ret);
549 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
550 EXPECT_EQ(HDF_SUCCESS, ret);
551 hwCapture->captureParam.captureMode.ctlParam.pause = 0;
552 ret = InterfaceLibOutputCapture(handle, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE, &hwCapture->captureParam);
553 EXPECT_EQ(HDF_SUCCESS, ret);
554 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
555 EXPECT_EQ(HDF_SUCCESS, ret);
556 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
557 EXPECT_EQ(HDF_SUCCESS, ret);
558 CloseServiceCaptureSo(handle);
559 free(hwCapture);
560 hwCapture = nullptr;
561 }
562 /**
563 * @tc.name AudioInterfaceLibOutputCaptureAbnormal_001
564 * @tc.desc test OutputCapture interface, return -1 if the cmdId is invalid.
565 * @tc.type: FUNC
566 */
567 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureAbnormal_001, TestSize.Level1)
568 {
569 int32_t ret = HDF_FAILURE;
570 struct DevHandle *handle = nullptr;
571 struct AudioHwCapture *hwCapture = nullptr;
572 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
573 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
574 ASSERT_EQ(HDF_SUCCESS, ret);
575
576 ret = InterfaceLibOutputCapture(handle, 30, &hwCapture->captureParam);
577 EXPECT_EQ(HDF_FAILURE, ret);
578 CloseServiceCaptureSo(handle);
579 free(hwCapture);
580 hwCapture = nullptr;
581 }
582 /**
583 * @tc.name AudioInterfaceLibOutputCaptureAbnormal_002
584 * @tc.desc Test Outputcapture interface, return -1 if the incoming parameter handleData is empty.
585 * @tc.type: FUNC
586 */
587 HWTEST_F(AudioLibCaptureTest, AudioInterfaceLibOutputCaptureAbnormal_002, TestSize.Level1)
588 {
589 int32_t ret = HDF_FAILURE;
590 struct DevHandle *handle = nullptr;
591 struct AudioHwCaptureParam *handleData = nullptr;
592 struct AudioHwCapture *hwCapture = nullptr;
593 ASSERT_TRUE((InterfaceLibOutputCapture != nullptr && CloseServiceCaptureSo != nullptr));
594 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME, handle);
595 ASSERT_EQ(HDF_SUCCESS, ret);
596
597 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, handleData);
598 EXPECT_EQ(HDF_FAILURE, ret);
599 CloseServiceCaptureSo(handle);
600 free(hwCapture);
601 hwCapture = nullptr;
602 }
603 }
604