1 /*
2 * Copyright (c) 2021 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_internal.h"
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 using namespace std;
21 using namespace testing::ext;
22 namespace {
23 class AudioCaptureTest : public testing::Test {
24 public:
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27 };
28
SetUpTestCase()29 void AudioCaptureTest::SetUpTestCase()
30 {
31 }
32
TearDownTestCase()33 void AudioCaptureTest::TearDownTestCase()
34 {
35 }
36
37 HWTEST_F(AudioCaptureTest, AudioCaptureStopWhenHandleIsNull, TestSize.Level0)
38 {
39 struct AudioHwCapture *hwCapture = nullptr;
40 AudioHandle handle = (AudioHandle)hwCapture;
41 int32_t ret = AudioCaptureStop(handle);
42 EXPECT_EQ(HDF_FAILURE, ret);
43 }
44
45 HWTEST_F(AudioCaptureTest, AudioCaptureStopWhenParamIsVaild, TestSize.Level0)
46 {
47 struct AudioHwCapture *hwCapture = new AudioHwCapture;
48 AudioHandle handle = (AudioHandle)hwCapture;
49 int32_t ret = AudioCaptureStop(handle);
50 EXPECT_EQ(HDF_SUCCESS, ret);
51 delete(hwCapture);
52 hwCapture = nullptr;
53 }
54
55 HWTEST_F(AudioCaptureTest, AudioCaptureResumeWhenHandleIsNull, TestSize.Level0)
56 {
57 struct AudioHwCapture *hwCapture = nullptr;
58 AudioHandle handle = (AudioHandle)hwCapture;
59 int32_t ret = AudioCaptureResume(handle);
60 EXPECT_EQ(HDF_FAILURE, ret);
61 }
62
63 HWTEST_F(AudioCaptureTest, AudioCaptureResumeWhenParamIsVaild, TestSize.Level0)
64 {
65 struct AudioHwCapture *hwCapture = new AudioHwCapture;
66 AudioHandle handle = (AudioHandle)hwCapture;
67 int32_t ret = AudioCaptureResume(handle);
68 EXPECT_EQ(HDF_SUCCESS, ret);
69 delete(hwCapture);
70 hwCapture = nullptr;
71 }
72
73 HWTEST_F(AudioCaptureTest, AudioCaptureSetSampleAttributesWhenHandleIsNull, TestSize.Level0)
74 {
75 struct AudioHwCapture *hwCapture = nullptr;
76 AudioHandle handle = (AudioHandle)hwCapture;
77 AudioSampleAttributes *attrs = new AudioSampleAttributes;
78 int32_t ret = AudioCaptureSetSampleAttributes(handle, attrs);
79 EXPECT_EQ(HDF_FAILURE, ret);
80 delete(attrs);
81 attrs = nullptr;
82 }
83
84 HWTEST_F(AudioCaptureTest, AudioCaptureSetSampleAttributesWhenAttrsIsNull, TestSize.Level0)
85 {
86 struct AudioHwCapture *hwCapture = new AudioHwCapture;
87 AudioHandle handle = (AudioHandle)hwCapture;
88 AudioSampleAttributes *attrs = nullptr;
89 int32_t ret = AudioCaptureSetSampleAttributes(handle, attrs);
90 EXPECT_EQ(HDF_FAILURE, ret);
91 delete(hwCapture);
92 hwCapture = nullptr;
93 }
94
95 HWTEST_F(AudioCaptureTest, AudioCaptureSetSampleAttributesWhenParamIsVaild, TestSize.Level0)
96 {
97 struct AudioHwCapture *hwCapture = new AudioHwCapture;
98 AudioHandle handle = (AudioHandle)hwCapture;
99 AudioSampleAttributes *attrs = new AudioSampleAttributes;
100 int32_t ret = AudioCaptureSetSampleAttributes(handle, attrs);
101 EXPECT_EQ(HDF_SUCCESS, ret);
102 delete(hwCapture);
103 hwCapture = nullptr;
104 delete(attrs);
105 attrs = nullptr;
106 }
107
108 HWTEST_F(AudioCaptureTest, AudioCaptureGetSampleAttributesWhenHandleIsNull, TestSize.Level0)
109 {
110 AudioSampleAttributes *attrs = new AudioSampleAttributes;
111 int32_t ret = AudioCaptureGetSampleAttributes(nullptr, attrs);
112 EXPECT_EQ(HDF_FAILURE, ret);
113 delete(attrs);
114 attrs = nullptr;
115 }
116
117 HWTEST_F(AudioCaptureTest, AudioCaptureGetSampleAttributesWhenAttrsIsNull, TestSize.Level0)
118 {
119 struct AudioHwCapture *hwCapture = new AudioHwCapture;
120 AudioHandle handle = (AudioHandle)hwCapture;
121 int32_t ret = AudioCaptureGetSampleAttributes(handle, nullptr);
122 EXPECT_EQ(HDF_FAILURE, ret);
123 delete(hwCapture);
124 hwCapture = nullptr;
125 }
126
127 HWTEST_F(AudioCaptureTest, AudioCaptureGetSampleAttributesWhenParamIsVaild, TestSize.Level0)
128 {
129 struct AudioHwCapture *hwCapture = new AudioHwCapture;
130 AudioHandle handle = (AudioHandle)hwCapture;
131 AudioSampleAttributes *attrs = new AudioSampleAttributes;
132 int32_t ret = AudioCaptureGetSampleAttributes(handle, attrs);
133 EXPECT_EQ(HDF_SUCCESS, ret);
134 delete(hwCapture);
135 hwCapture = nullptr;
136 delete(attrs);
137 attrs = nullptr;
138 }
139
140 HWTEST_F(AudioCaptureTest, AudioCaptureSetMuteWhenHandleIsNull, TestSize.Level0)
141 {
142 struct AudioHwCapture *hwCapture = nullptr;
143 AudioHandle handle = (AudioHandle)hwCapture;
144 bool mute = true;
145 int32_t ret = AudioCaptureSetMute(handle, mute);
146 EXPECT_EQ(HDF_FAILURE, ret);
147 }
148
149 HWTEST_F(AudioCaptureTest, AudioCaptureSetMuteParamIsVaild, TestSize.Level0)
150 {
151 struct AudioHwCapture *hwCapture = new AudioHwCapture;
152 AudioHandle handle = (AudioHandle)hwCapture;
153 bool mute = false;
154 int32_t ret = AudioCaptureSetMute(handle, mute);
155 EXPECT_EQ(HDF_SUCCESS, ret);
156 delete(hwCapture);
157 hwCapture = nullptr;
158 }
159 }
160