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