• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #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     if (model_ == nullptr) {
59         GTEST_SKIP() << "model_ is nullptr" << std::endl;
60         return;
61     }
62 
63     int32_t ret = model_->CreateEffectController(model_, &info, &controller_, &contollerId_);
64     ASSERT_EQ(ret, HDF_SUCCESS);
65     ASSERT_NE(controller_, nullptr);
66 }
67 
TearDown()68 void EffectControlTest::TearDown()
69 {
70     // input testcase teardown step,teardown invoked after each testcases
71     if (libName_ != nullptr) {
72         free(libName_);
73         libName_ = nullptr;
74     }
75 
76     if (effectId_ != nullptr) {
77         free(effectId_);
78         effectId_ = nullptr;
79     }
80 
81     if (controller_ != nullptr && model_ != nullptr) {
82         int32_t ret = model_->DestroyEffectController(model_, &contollerId_);
83         EXPECT_EQ(ret, HDF_SUCCESS);
84     }
85 
86     if (model_ != nullptr) {
87         IEffectModelRelease(model_, IS_DIRECTLY_CALL);
88     }
89 }
90 
91 /**
92  * @tc.number: SUB_Driver_Audio_EffectControl_0100
93  * @tc.name: HdfAudioEffectProcess001
94  * @tc.desc: Verify the EffectControlEffectProcess function when the input parameter is invalid.
95  * @tc.type: FUNC
96  * @tc.require: I6I658
97  */
98 HWTEST_F(EffectControlTest, HdfAudioEffectProcess001, TestSize.Level1)
99 {
100     struct AudioEffectBuffer input = {0};
101     struct AudioEffectBuffer output = {0};
102 
103     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->EffectProcess(nullptr, &input, &output));
104     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectProcess(controller_, nullptr, &output));
105     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectProcess(controller_, &input, nullptr));
106 }
107 
108 /**
109  * @tc.number: SUB_Driver_Audio_EffectControl_0200
110  * @tc.name: HdfAudioEffectProcess002
111  * @tc.desc: Verify the EffectControlEffectProcess function.
112  * @tc.type: FUNC
113  * @tc.require: I6I658
114  */
115 HWTEST_F(EffectControlTest, HdfAudioEffectProcess002, TestSize.Level1)
116 {
117     struct AudioEffectBuffer input = {0};
118     struct AudioEffectBuffer output = {0};
119 
120     int32_t ret = controller_->EffectProcess(controller_, &input, &output);
121     EXPECT_EQ(ret, HDF_SUCCESS);
122 }
123 
124 /**
125  * @tc.number: SUB_Driver_Audio_EffectControl_0300
126  * @tc.name: HdfAudioEffectProcess003
127  * @tc.desc: Verify the value of EffectControlEffectProcess function's datatag.
128  * @tc.type: FUNC
129  * @tc.require: I6I658
130  */
131 HWTEST_F(EffectControlTest, HdfAudioEffectProcess003, TestSize.Level1)
132 {
133     struct AudioEffectBuffer input = {0};
134     struct AudioEffectBuffer output = {0};
135 
136     int32_t ret = controller_->EffectProcess(controller_, &input, &output);
137     EXPECT_EQ(ret, HDF_SUCCESS);
138 
139     int tag = output.datatag;
140     if (tag == 0 || tag == 1 || tag == 2 || tag == 4 || tag == 8)
141     {
142         EXPECT_TRUE(true);
143     } else {
144         EXPECT_TRUE(false);
145     }
146 }
147 
148 /**
149  * @tc.number: SUB_Driver_Audio_EffectControl_0400
150  * @tc.name: HdfAudioSendCommand001
151  * @tc.desc: Verify the EffectControlSendCommand function when the input parameter is invalid.
152  * @tc.type: FUNC
153  * @tc.require: I6I658
154  */
155 HWTEST_F(EffectControlTest, HdfAudioSendCommand001, TestSize.Level1)
156 {
157     int8_t input[SEND_COMMAND_LEN] = {0};
158     int8_t output[GET_BUFFER_LEN] = {0};
159     uint32_t replyLen = GET_BUFFER_LEN;
160 
161     int32_t ret = controller_->SendCommand(nullptr, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
162                                            input, SEND_COMMAND_LEN, output, &replyLen);
163     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, ret);
164 
165     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
166                                            nullptr, SEND_COMMAND_LEN, output, &replyLen);
167     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
168 
169     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
170                                            input, SEND_COMMAND_LEN, nullptr, &replyLen);
171     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
172 
173     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
174                                            input, SEND_COMMAND_LEN, output, nullptr);
175     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
176 
177     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INVALID_LARGE,
178                                            input, SEND_COMMAND_LEN, nullptr, &replyLen);
179     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
180 }
181 
182 /**
183  * @tc.number: SUB_Driver_Audio_EffectControl_0500
184  * @tc.name: HdfAudioSendCommandInit001
185  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_INIT_CONTOLLER.
186  * @tc.type: FUNC
187  * @tc.require: I6I658
188  */
189 HWTEST_F(EffectControlTest, HdfAudioSendCommandInit001, TestSize.Level1)
190 {
191     int8_t input[SEND_COMMAND_LEN] = {0};
192     int8_t output[GET_BUFFER_LEN] = {0};
193     uint32_t replyLen = GET_BUFFER_LEN;
194 
195     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
196                                            input, SEND_COMMAND_LEN, output, &replyLen);
197     EXPECT_EQ(ret, HDF_SUCCESS);
198 }
199 
200 /**
201  * @tc.number: SUB_Driver_Audio_EffectControl_0600
202  * @tc.name: HdfAudioSendCommandSetConf001
203  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_CONFIG.
204  * @tc.type: FUNC
205  * @tc.require: I6I658
206  */
207 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetConf001, TestSize.Level1)
208 {
209     int8_t input[SEND_COMMAND_LEN] = {0};
210     int8_t output[GET_BUFFER_LEN] = {0};
211     uint32_t replyLen = GET_BUFFER_LEN;
212 
213     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_CONFIG,
214                                            input, SEND_COMMAND_LEN, output, &replyLen);
215     EXPECT_EQ(ret, HDF_SUCCESS);
216 }
217 
218 /**
219  * @tc.number: SUB_Driver_Audio_EffectControl_0700
220  * @tc.name: HdfAudioSendCommandGetConf001
221  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_CONFIG.
222  * @tc.type: FUNC
223  * @tc.require: I6I658
224  */
225 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetConf001, TestSize.Level1)
226 {
227     int8_t input[SEND_COMMAND_LEN] = {0};
228     int8_t output[GET_BUFFER_LEN] = {0};
229     uint32_t replyLen = GET_BUFFER_LEN;
230 
231     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_CONFIG,
232                                            input, SEND_COMMAND_LEN, output, &replyLen);
233     EXPECT_EQ(ret, HDF_SUCCESS);
234 }
235 
236 /**
237  * @tc.number: SUB_Driver_Audio_EffectControl_0800
238  * @tc.name: HdfAudioSendCommandRest001
239  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_RESET.
240  * @tc.type: FUNC
241  * @tc.require: I6I658
242  */
243 HWTEST_F(EffectControlTest, HdfAudioSendCommandRest001, TestSize.Level1)
244 {
245     int8_t input[SEND_COMMAND_LEN] = {0};
246     int8_t output[GET_BUFFER_LEN] = {0};
247     uint32_t replyLen = GET_BUFFER_LEN;
248 
249     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_RESET,
250                                            input, SEND_COMMAND_LEN, output, &replyLen);
251     EXPECT_EQ(ret, HDF_SUCCESS);
252 }
253 
254 /**
255  * @tc.number: SUB_Driver_Audio_EffectControl_0900
256  * @tc.name: HdfAudioSendCommandEnable001
257  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_ENABLE.
258  * @tc.type: FUNC
259  * @tc.require: I6I658
260  */
261 HWTEST_F(EffectControlTest, HdfAudioSendCommandEnable001, 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_ENABLE,
268                                            input, SEND_COMMAND_LEN, output, &replyLen);
269     EXPECT_EQ(ret, HDF_SUCCESS);
270 }
271 
272 /**
273  * @tc.number: SUB_Driver_Audio_EffectControl_1000
274  * @tc.name: HdfAudioSendCommandDisable001
275  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_DISABLE.
276  * @tc.type: FUNC
277  * @tc.require: I6I658
278  */
279 HWTEST_F(EffectControlTest, HdfAudioSendCommandDisable001, TestSize.Level1)
280 {
281     int8_t input[SEND_COMMAND_LEN] = {0};
282     int8_t output[GET_BUFFER_LEN] = {0};
283     uint32_t replyLen = GET_BUFFER_LEN;
284     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_DISABLE,
285                                            input, SEND_COMMAND_LEN, output, &replyLen);
286     EXPECT_EQ(ret, HDF_SUCCESS);
287 }
288 
289 /**
290  * @tc.number: SUB_Driver_Audio_EffectControl_1100
291  * @tc.name: HdfAudioSendCommandSetParam001
292  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_PARAM.
293  * @tc.type: FUNC
294  * @tc.require: I6I658
295  */
296 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetParam001, TestSize.Level1)
297 {
298     int8_t input[SEND_COMMAND_LEN] = {0};
299     int8_t output[GET_BUFFER_LEN] = {0};
300     uint32_t replyLen = GET_BUFFER_LEN;
301 
302     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_PARAM,
303                                            input, SEND_COMMAND_LEN, output, &replyLen);
304     EXPECT_EQ(ret, HDF_SUCCESS);
305 }
306 
307 /**
308  * @tc.number: SUB_Driver_Audio_EffectControl_1700
309  * @tc.name: HdfAudioSendCommandSetParam002
310  * @tc.desc: Verify the EffectControlSendCommand function when distribute volume parameters.
311  * @tc.type: FUNC
312  * @tc.require: I6I658
313  */
314 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetParam002, TestSize.Level1)
315 {
316     int8_t input[SEND_COMMAND_LEN] = {7, 0};
317     int8_t output[GET_BUFFER_LEN] = {0};
318     uint32_t replyLen = GET_BUFFER_LEN;
319 
320     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_PARAM,
321                                            input, SEND_COMMAND_LEN, output, &replyLen);
322     EXPECT_EQ(ret, HDF_SUCCESS);
323 }
324 
325 /**
326  * @tc.number: SUB_Driver_Audio_EffectControl_1800
327  * @tc.name: HdfAudioSendCommandSetParam003
328  * @tc.desc: Verify the EffectControlSendCommand function when distribute rotating screen parameters.
329  * @tc.type: FUNC
330  * @tc.require: I6I658
331  */
332 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetParam003, TestSize.Level1)
333 {
334     int8_t input[SEND_COMMAND_LEN] = {8, 0};
335     int8_t output[GET_BUFFER_LEN] = {0};
336     uint32_t replyLen = GET_BUFFER_LEN;
337 
338     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_PARAM,
339                                            input, SEND_COMMAND_LEN, output, &replyLen);
340     EXPECT_EQ(ret, HDF_SUCCESS);
341 }
342 
343 /**
344  * @tc.number: SUB_Driver_Audio_EffectControl_1200
345  * @tc.name: HdfAudioSendCommandGetParam001
346  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_PARAM.
347  * @tc.type: FUNC
348  * @tc.require: I6I658
349  */
350 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetParam001, TestSize.Level1)
351 {
352     int8_t input[SEND_COMMAND_LEN] = {0};
353     int8_t output[GET_BUFFER_LEN] = {0};
354     uint32_t replyLen = GET_BUFFER_LEN;
355 
356     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_PARAM,
357                                            input, SEND_COMMAND_LEN, output, &replyLen);
358     EXPECT_EQ(ret, HDF_SUCCESS);
359 }
360 
361 /**
362  * @tc.number: SUB_Driver_Audio_EffectControl_1300
363  * @tc.name: HdfAudioGetDescriptor001
364  * @tc.desc: Verify the EffectGetOwnDescriptor function when the input parameter is invalid.
365  * @tc.type: FUNC
366  * @tc.require: I6I658
367  */
368 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor001, TestSize.Level1)
369 {
370     struct EffectControllerDescriptor desc;
371 
372     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->GetEffectDescriptor(nullptr, &desc));
373     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->GetEffectDescriptor(controller_, nullptr));
374 }
375 
376 /**
377  * @tc.number: SUB_Driver_Audio_EffectControl_1400
378  * @tc.name: HdfAudioGetDescriptor002
379  * @tc.desc: Verify the EffectGetOwnDescriptor function.
380  * @tc.type: FUNC
381  * @tc.require: I6I658
382  */
383 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor002, TestSize.Level1)
384 {
385     struct EffectControllerDescriptor desc;
386     int32_t ret = controller_->GetEffectDescriptor(controller_, &desc);
387     ASSERT_EQ(ret, HDF_SUCCESS);
388     EXPECT_STREQ(desc.effectId, effectId_);
389     EXPECT_STREQ(desc.effectName, "mock_effect");
390     EXPECT_STREQ(desc.libName, libName_);
391     EXPECT_STREQ(desc.supplier, "mock");
392     EffectControllerReleaseDesc(&desc);
393 }
394 
395 
396 /**
397  * @tc.number: SUB_Driver_Audio_EffectControl_1500
398  * @tc.name: HdfAudioEffectReverse001
399  * @tc.desc: Verify the EffectControlEffectReverse function when the input parameter is invalid.
400  * @tc.type: FUNC
401  * @tc.require: I7ASKC
402  */
403 HWTEST_F(EffectControlTest, HdfAudioEffectReverse001, TestSize.Level1)
404 {
405     struct AudioEffectBuffer input = {0};
406     struct AudioEffectBuffer output = {0};
407 
408     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->EffectReverse(nullptr, &input, &output));
409     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, nullptr, &output));
410     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, &input, nullptr));
411 }
412 
413 /**
414  * @tc.number: SUB_Driver_Audio_EffectControl_1600
415  * @tc.name: HdfAudioEffectReverse002
416  * @tc.desc: Verify the EffectControlEffectReverse function.
417  * @tc.type: FUNC
418  * @tc.require: I7ASKC
419  */
420 HWTEST_F(EffectControlTest, HdfAudioEffectReverse002, TestSize.Level1)
421 {
422     struct AudioEffectBuffer input = {0};
423     struct AudioEffectBuffer output = {0};
424 
425     int32_t ret = controller_->EffectReverse(controller_, &input, &output);
426     EXPECT_EQ(ret, HDF_SUCCESS);
427 }
428 } // end of namespace
429