• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: HdfAudioSendCommand001
121  * @tc.desc: Verify the EffectControlSendCommand function when the input parameter is invalid.
122  * @tc.type: FUNC
123  * @tc.require: I6I658
124  */
125 HWTEST_F(EffectControlTest, HdfAudioSendCommand001, TestSize.Level1)
126 {
127     int8_t input[SEND_COMMAND_LEN] = {0};
128     int8_t output[GET_BUFFER_LEN] = {0};
129     uint32_t replyLen = GET_BUFFER_LEN;
130 
131     int32_t ret = controller_->SendCommand(nullptr, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
132                                            input, SEND_COMMAND_LEN, output, &replyLen);
133     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, ret);
134 
135     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
136                                            nullptr, SEND_COMMAND_LEN, output, &replyLen);
137     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
138 
139     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
140                                            input, SEND_COMMAND_LEN, nullptr, &replyLen);
141     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
142 
143     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
144                                            input, SEND_COMMAND_LEN, output, nullptr);
145     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
146 
147     ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INVALID_LARGE,
148                                            input, SEND_COMMAND_LEN, nullptr, &replyLen);
149     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
150 }
151 
152 /**
153  * @tc.name: HdfAudioSendCommandInit001
154  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_INIT_CONTOLLER.
155  * @tc.type: FUNC
156  * @tc.require: I6I658
157  */
158 HWTEST_F(EffectControlTest, HdfAudioSendCommandInit001, TestSize.Level1)
159 {
160     int8_t input[SEND_COMMAND_LEN] = {0};
161     int8_t output[GET_BUFFER_LEN] = {0};
162     uint32_t replyLen = GET_BUFFER_LEN;
163 
164     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
165                                            input, SEND_COMMAND_LEN, output, &replyLen);
166     EXPECT_EQ(ret, HDF_SUCCESS);
167 }
168 
169 /**
170  * @tc.name: HdfAudioSendCommandSetConf001
171  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_CONFIG.
172  * @tc.type: FUNC
173  * @tc.require: I6I658
174  */
175 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetConf001, TestSize.Level1)
176 {
177     int8_t input[SEND_COMMAND_LEN] = {0};
178     int8_t output[GET_BUFFER_LEN] = {0};
179     uint32_t replyLen = GET_BUFFER_LEN;
180 
181     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_CONFIG,
182                                            input, SEND_COMMAND_LEN, output, &replyLen);
183     EXPECT_EQ(ret, HDF_SUCCESS);
184 }
185 
186 /**
187  * @tc.name: HdfAudioSendCommandGetConf001
188  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_CONFIG.
189  * @tc.type: FUNC
190  * @tc.require: I6I658
191  */
192 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetConf001, TestSize.Level1)
193 {
194     int8_t input[SEND_COMMAND_LEN] = {0};
195     int8_t output[GET_BUFFER_LEN] = {0};
196     uint32_t replyLen = GET_BUFFER_LEN;
197 
198     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_CONFIG,
199                                            input, SEND_COMMAND_LEN, output, &replyLen);
200     EXPECT_EQ(ret, HDF_SUCCESS);
201 }
202 
203 /**
204  * @tc.name: HdfAudioSendCommandRest001
205  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_RESET.
206  * @tc.type: FUNC
207  * @tc.require: I6I658
208  */
209 HWTEST_F(EffectControlTest, HdfAudioSendCommandRest001, TestSize.Level1)
210 {
211     int8_t input[SEND_COMMAND_LEN] = {0};
212     int8_t output[GET_BUFFER_LEN] = {0};
213     uint32_t replyLen = GET_BUFFER_LEN;
214 
215     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_RESET,
216                                            input, SEND_COMMAND_LEN, output, &replyLen);
217     EXPECT_EQ(ret, HDF_SUCCESS);
218 }
219 
220 /**
221  * @tc.name: HdfAudioSendCommandEnable001
222  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_ENABLE.
223  * @tc.type: FUNC
224  * @tc.require: I6I658
225  */
226 HWTEST_F(EffectControlTest, HdfAudioSendCommandEnable001, TestSize.Level1)
227 {
228     int8_t input[SEND_COMMAND_LEN] = {0};
229     int8_t output[GET_BUFFER_LEN] = {0};
230     uint32_t replyLen = GET_BUFFER_LEN;
231 
232     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_ENABLE,
233                                            input, SEND_COMMAND_LEN, output, &replyLen);
234     EXPECT_EQ(ret, HDF_SUCCESS);
235 }
236 
237 /**
238  * @tc.name: HdfAudioSendCommandDisable001
239  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_DISABLE.
240  * @tc.type: FUNC
241  * @tc.require: I6I658
242  */
243 HWTEST_F(EffectControlTest, HdfAudioSendCommandDisable001, 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     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_DISABLE,
249                                            input, SEND_COMMAND_LEN, output, &replyLen);
250     EXPECT_EQ(ret, HDF_SUCCESS);
251 }
252 
253 /**
254  * @tc.name: HdfAudioSendCommandSetParam001
255  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_SET_PARAM.
256  * @tc.type: FUNC
257  * @tc.require: I6I658
258  */
259 HWTEST_F(EffectControlTest, HdfAudioSendCommandSetParam001, TestSize.Level1)
260 {
261     int8_t input[SEND_COMMAND_LEN] = {0};
262     int8_t output[GET_BUFFER_LEN] = {0};
263     uint32_t replyLen = GET_BUFFER_LEN;
264 
265     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_SET_PARAM,
266                                            input, SEND_COMMAND_LEN, output, &replyLen);
267     EXPECT_EQ(ret, HDF_SUCCESS);
268 }
269 
270 /**
271  * @tc.name: HdfAudioSendCommandGetParam001
272  * @tc.desc: Verify the EffectControlSendCommand function when cmdId is AUDIO_EFFECT_COMMAND_GET_PARAM.
273  * @tc.type: FUNC
274  * @tc.require: I6I658
275  */
276 HWTEST_F(EffectControlTest, HdfAudioSendCommandGetParam001, TestSize.Level1)
277 {
278     int8_t input[SEND_COMMAND_LEN] = {0};
279     int8_t output[GET_BUFFER_LEN] = {0};
280     uint32_t replyLen = GET_BUFFER_LEN;
281 
282     int32_t ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_GET_PARAM,
283                                            input, SEND_COMMAND_LEN, output, &replyLen);
284     EXPECT_EQ(ret, HDF_SUCCESS);
285 }
286 
287 /**
288  * @tc.name: HdfAudioGetDescriptor001
289  * @tc.desc: Verify the EffectGetOwnDescriptor function when the input parameter is invalid.
290  * @tc.type: FUNC
291  * @tc.require: I6I658
292  */
293 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor001, TestSize.Level1)
294 {
295     struct EffectControllerDescriptor desc;
296 
297     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->GetEffectDescriptor(nullptr, &desc));
298     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->GetEffectDescriptor(controller_, nullptr));
299 }
300 
301 /**
302  * @tc.name: HdfAudioGetDescriptor002
303  * @tc.desc: Verify the EffectGetOwnDescriptor function.
304  * @tc.type: FUNC
305  * @tc.require: I6I658
306  */
307 HWTEST_F(EffectControlTest, HdfAudioGetDescriptor002, TestSize.Level1)
308 {
309     struct EffectControllerDescriptor desc;
310     int32_t ret = controller_->GetEffectDescriptor(controller_, &desc);
311     ASSERT_EQ(ret, HDF_SUCCESS);
312     EXPECT_STREQ(desc.effectId, effectId_);
313     EXPECT_STREQ(desc.effectName, "mock_effect");
314     EXPECT_STREQ(desc.libName, libName_);
315     EXPECT_STREQ(desc.supplier, "mock");
316     EffectControllerReleaseDesc(&desc);
317 }
318 
319 /**
320  * @tc.name: HdfAudioEffectReverse001
321  * @tc.desc: Verify the EffectControlEffectReverse function when the input parameter is invalid.
322  * @tc.type: FUNC
323  * @tc.require: I7ASKC
324  */
325 HWTEST_F(EffectControlTest, HdfAudioEffectReverse001, TestSize.Level1)
326 {
327     struct AudioEffectBuffer input = {0};
328     struct AudioEffectBuffer output = {0};
329 
330     EXPECT_EQ(HDF_ERR_INVALID_OBJECT, controller_->EffectReverse(nullptr, &input, &output));
331     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, nullptr, &output));
332     EXPECT_EQ(HDF_ERR_INVALID_PARAM, controller_->EffectReverse(controller_, &input, nullptr));
333 }
334 
335 /**
336  * @tc.name: HdfAudioEffectReverse002
337  * @tc.desc: Verify the EffectControlEffectReverse function.
338  * @tc.type: FUNC
339  * @tc.require: I7ASKC
340  */
341 HWTEST_F(EffectControlTest, HdfAudioEffectReverse002, TestSize.Level1)
342 {
343     struct AudioEffectBuffer input = {0};
344     struct AudioEffectBuffer output = {0};
345 
346     int32_t ret = controller_->EffectReverse(controller_, &input, &output);
347     EXPECT_EQ(ret, HDF_SUCCESS);
348 }
349 } // end of namespace
350