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 <gtest/gtest.h>
17 #include "hdf_base.h"
18 #include "hdf_log.h"
19 #include "v1_0/effect_types.h"
20 #include "v1_0/ieffect_control.h"
21 #include "v1_0/ieffect_model.h"
22 #include "effect_common.h"
23 #include "osal_mem.h"
24
25 using namespace std;
26 using namespace testing::ext;
27 constexpr bool IS_DIRECTLY_CALL = false;
28 /* the input buffer len of the send command */
29 constexpr uint32_t SEND_COMMAND_LEN = 10;
30 /* the output buffer len of the command */
31 constexpr uint32_t GET_BUFFER_LEN = 10;
32 # define AUDIO_EFFECT_COMMAND_INVALID_LARGE 20
33
34 namespace {
35 class EffectControlTest : public testing::Test {
36 public:
37 struct IEffectControl *controller_ = nullptr;
38 struct IEffectModel *model_ = nullptr;
39 struct ControllerId contollerId_;
40 virtual void SetUp();
41 virtual void TearDown();
42 char *libName_ = nullptr;
43 char *effectId_ = nullptr;
44 };
45
SetUp()46 void EffectControlTest::SetUp()
47 {
48 // input testcase setup step,setup invoked before each testcases
49 libName_ = strdup("libmock_effect_lib");
50 ASSERT_NE(libName_, nullptr);
51 effectId_ = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966ff");
52 ASSERT_NE(effectId_, nullptr);
53 struct EffectInfo info = {
54 .libName = libName_,
55 .effectId = effectId_,
56 .ioDirection = 1,
57 };
58
59 model_ = IEffectModelGet(IS_DIRECTLY_CALL);
60 ASSERT_NE(model_, nullptr);
61
62 int32_t ret = model_->CreateEffectController(model_, &info, &controller_, &contollerId_);
63 ASSERT_EQ(ret, HDF_SUCCESS);
64 ASSERT_NE(controller_, nullptr);
65 }
66
TearDown()67 void EffectControlTest::TearDown()
68 {
69 // input testcase teardown step,teardown invoked after each testcases
70 if (libName_ != nullptr) {
71 free(libName_);
72 libName_ = nullptr;
73 }
74
75 if (effectId_ != nullptr) {
76 free(effectId_);
77 effectId_ = nullptr;
78 }
79
80 if (controller_ != nullptr && model_ != nullptr) {
81 int32_t ret = model_->DestroyEffectController(model_, &contollerId_);
82 EXPECT_EQ(ret, HDF_SUCCESS);
83 }
84
85 if (model_ != nullptr) {
86 IEffectModelRelease(model_, IS_DIRECTLY_CALL);
87 }
88 }
89
90 /**
91 * @tc.name: HdfAudioEffectProcess001
92 * @tc.desc: Verify the EffectControlEffectProcess function when the input parameter is invalid.
93 * @tc.type: FUNC
94 * @tc.require: I6I658
95 */
96 HWTEST_F(EffectControlTest, HdfAudioEffectProcess001, TestSize.Level1)
97 {
98 struct AudioEffectBuffer input = {0};
99 struct AudioEffectBuffer output = {0};
100
101 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->EffectProcess(nullptr, &input, &output));
102 EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectProcess(controller_, nullptr, &output));
103 EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectProcess(controller_, &input, nullptr));
104 }
105
106 /**
107 * @tc.name: HdfAudioEffectProcess002
108 * @tc.desc: Verify the EffectControlEffectProcess function.
109 * @tc.type: FUNC
110 * @tc.require: I6I658
111 */
112 HWTEST_F(EffectControlTest, HdfAudioEffectProcess002, TestSize.Level1)
113 {
114 struct AudioEffectBuffer input = {0};
115 struct AudioEffectBuffer output = {0};
116
117 int32_t ret = controller_->EffectProcess(controller_, &input, &output);
118 EXPECT_EQ(ret, HDF_SUCCESS);
119 }
120
121 /**
122 * @tc.name: HdfAudioSendCommand001
123 * @tc.desc: Verify the EffectControlSendCommand function when the input parameter is invalid.
124 * @tc.type: FUNC
125 * @tc.require: I6I658
126 */
127 HWTEST_F(EffectControlTest, HdfAudioSendCommand001, TestSize.Level1)
128 {
129 int8_t input[SEND_COMMAND_LEN] = {0};
130 int8_t output[GET_BUFFER_LEN] = {0};
131 uint32_t replyLen = GET_BUFFER_LEN;
132
133 int32_t ret = controller_->SendCommand(nullptr, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
134 input, SEND_COMMAND_LEN, output, &replyLen);
135 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, ret);
136
137 ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
138 nullptr, SEND_COMMAND_LEN, output, &replyLen);
139 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
140
141 ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
142 input, SEND_COMMAND_LEN, nullptr, &replyLen);
143 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
144
145 ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
146 input, SEND_COMMAND_LEN, output, nullptr);
147 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
148
149 ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INVALID_LARGE,
150 input, SEND_COMMAND_LEN, nullptr, &replyLen);
151 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
152 }
153
154 /**
155 * @tc.name: HdfAudioSendCommandInit001
156 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_INIT_CONTOLLER.
157 * @tc.type: FUNC
158 * @tc.require: I6I658
159 */
160 HWTEST_F(EffectControlTest, HdfAudioSendCommandInit001, TestSize.Level1)
161 {
162 int8_t input[SEND_COMMAND_LEN] = {0};
163 int8_t output[GET_BUFFER_LEN] = {0};
164 uint32_t replyLen = GET_BUFFER_LEN;
165
166 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
167 input, SEND_COMMAND_LEN, output, &replyLen);
168 EXPECT_EQ(ret, HDF_SUCCESS);
169 }
170
171 /**
172 * @tc.name: HdfAudioSendCommandSetConf001
173 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_CONFIG.
174 * @tc.type: FUNC
175 * @tc.require: I6I658
176 */
177 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetConf001, TestSize.Level1)
178 {
179 int8_t input[SEND_COMMAND_LEN] = {0};
180 int8_t output[GET_BUFFER_LEN] = {0};
181 uint32_t replyLen = GET_BUFFER_LEN;
182
183 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_CONFIG,
184 input, SEND_COMMAND_LEN, output, &replyLen);
185 EXPECT_EQ(ret, HDF_SUCCESS);
186 }
187
188 /**
189 * @tc.name: HdfAudioSendCommandGetConf001
190 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_CONFIG.
191 * @tc.type: FUNC
192 * @tc.require: I6I658
193 */
194 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetConf001, TestSize.Level1)
195 {
196 int8_t input[SEND_COMMAND_LEN] = {0};
197 int8_t output[GET_BUFFER_LEN] = {0};
198 uint32_t replyLen = GET_BUFFER_LEN;
199
200 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_CONFIG,
201 input, SEND_COMMAND_LEN, output, &replyLen);
202 EXPECT_EQ(ret, HDF_SUCCESS);
203 }
204
205 /**
206 * @tc.name: HdfAudioSendCommandRest001
207 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_RESET.
208 * @tc.type: FUNC
209 * @tc.require: I6I658
210 */
211 HWTEST_F(EffectControlTest, HdfAudioSendCommandRest001, TestSize.Level1)
212 {
213 int8_t input[SEND_COMMAND_LEN] = {0};
214 int8_t output[GET_BUFFER_LEN] = {0};
215 uint32_t replyLen = GET_BUFFER_LEN;
216
217 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_RESET,
218 input, SEND_COMMAND_LEN, output, &replyLen);
219 EXPECT_EQ(ret, HDF_SUCCESS);
220 }
221
222 /**
223 * @tc.name: HdfAudioSendCommandEnable001
224 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_ENABLE.
225 * @tc.type: FUNC
226 * @tc.require: I6I658
227 */
228 HWTEST_F(EffectControlTest, HdfAudioSendCommandEnable001, TestSize.Level1)
229 {
230 int8_t input[SEND_COMMAND_LEN] = {0};
231 int8_t output[GET_BUFFER_LEN] = {0};
232 uint32_t replyLen = GET_BUFFER_LEN;
233
234 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_ENABLE,
235 input, SEND_COMMAND_LEN, output, &replyLen);
236 EXPECT_EQ(ret, HDF_SUCCESS);
237 }
238
239 /**
240 * @tc.name: HdfAudioSendCommandDisable001
241 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_DISABLE.
242 * @tc.type: FUNC
243 * @tc.require: I6I658
244 */
245 HWTEST_F(EffectControlTest, HdfAudioSendCommandDisable001, TestSize.Level1)
246 {
247 int8_t input[SEND_COMMAND_LEN] = {0};
248 int8_t output[GET_BUFFER_LEN] = {0};
249 uint32_t replyLen = GET_BUFFER_LEN;
250 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_DISABLE,
251 input, SEND_COMMAND_LEN, output, &replyLen);
252 EXPECT_EQ(ret, HDF_SUCCESS);
253 }
254
255 /**
256 * @tc.name: HdfAudioSendCommandSetParam001
257 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_PARAM.
258 * @tc.type: FUNC
259 * @tc.require: I6I658
260 */
261 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetParam001, TestSize.Level1)
262 {
263 int8_t input[SEND_COMMAND_LEN] = {0};
264 int8_t output[GET_BUFFER_LEN] = {0};
265 uint32_t replyLen = GET_BUFFER_LEN;
266
267 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_PARAM,
268 input, SEND_COMMAND_LEN, output, &replyLen);
269 EXPECT_EQ(ret, HDF_SUCCESS);
270 }
271
272 /**
273 * @tc.name: HdfAudioSendCommandGetParam001
274 * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_PARAM.
275 * @tc.type: FUNC
276 * @tc.require: I6I658
277 */
278 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetParam001, TestSize.Level1)
279 {
280 int8_t input[SEND_COMMAND_LEN] = {0};
281 int8_t output[GET_BUFFER_LEN] = {0};
282 uint32_t replyLen = GET_BUFFER_LEN;
283
284 int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_PARAM,
285 input, SEND_COMMAND_LEN, output, &replyLen);
286 EXPECT_EQ(ret, HDF_SUCCESS);
287 }
288
289 /**
290 * @tc.name: HdfAudioGetDescriptor001
291 * @tc.desc: Verify the EffectGetOwnDescriptor function when the input parameter is invalid.
292 * @tc.type: FUNC
293 * @tc.require: I6I658
294 */
295 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor001, TestSize.Level1)
296 {
297 struct EffectControllerDescriptor desc;
298
299 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->GetEffectDescriptor(nullptr, &desc));
300 EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->GetEffectDescriptor(controller_, nullptr));
301 }
302
303 /**
304 * @tc.name: HdfAudioGetDescriptor002
305 * @tc.desc: Verify the EffectGetOwnDescriptor function.
306 * @tc.type: FUNC
307 * @tc.require: I6I658
308 */
309 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor002, TestSize.Level1)
310 {
311 struct EffectControllerDescriptor desc;
312 int32_t ret = controller_->GetEffectDescriptor(controller_, &desc);
313 ASSERT_EQ(ret, HDF_SUCCESS);
314 EXPECT_STREQ(desc.effectId, effectId_);
315 EXPECT_STREQ(desc.effectName, "mock_effect");
316 EXPECT_STREQ(desc.libName, libName_);
317 EXPECT_STREQ(desc.supplier, "mock");
318 OHOS::Audio::EffectControllerReleaseDesc(&desc);
319 }
320
321 /**
322 * @tc.name: HdfAudioEffectReverse001
323 * @tc.desc: Verify the EffectControlEffectReverse function when the input parameter is invalid.
324 * @tc.type: FUNC
325 * @tc.require: I7ASKC
326 */
327 HWTEST_F(EffectControlTest, HdfAudioEffectReverse001, TestSize.Level1)
328 {
329 struct AudioEffectBuffer input = {0};
330 struct AudioEffectBuffer output = {0};
331
332 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->EffectReverse(nullptr, &input, &output));
333 EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, nullptr, &output));
334 EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, &input, nullptr));
335 }
336
337 /**
338 * @tc.name: HdfAudioEffectReverse002
339 * @tc.desc: Verify the EffectControlEffectReverse function.
340 * @tc.type: FUNC
341 * @tc.require: I7ASKC
342 */
343 HWTEST_F(EffectControlTest, HdfAudioEffectReverse002, TestSize.Level1)
344 {
345 struct AudioEffectBuffer input = {0};
346 struct AudioEffectBuffer output = {0};
347
348 int32_t ret = controller_->EffectReverse(controller_, &input, &output);
349 EXPECT_EQ(ret, HDF_SUCCESS);
350 }
351 } // end of namespace
352