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 constexpr uint32_t MAX_DESCRIPTOR_NUM = 20;
29
30 namespace {
31 class EffectModelTest : public testing::Test {
32 public:
33 struct IEffectModel *model_ = nullptr;
34 struct ControllerId controllerId_;
35 char *libName_ = nullptr;
36 char *effectId_ = nullptr;
37 virtual void SetUp();
38 virtual void TearDown();
39 };
40
SetUp()41 void EffectModelTest::SetUp()
42 {
43 // input testcase setup step,setup invoked before each testcases
44 libName_ = strdup("libmock_effect_lib");
45 effectId_ = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966ff");
46 model_ = IEffectModelGet(IS_DIRECTLY_CALL);
47 if (model_ == nullptr) {
48 GTEST_SKIP() << "model_ is nullptr" << std::endl;
49 return;
50 }
51 }
52
TearDown()53 void EffectModelTest::TearDown()
54 {
55 // input testcase teardown step,teardown invoked after each testcases
56 if (libName_ != nullptr) {
57 free(libName_);
58 libName_ = nullptr;
59 }
60
61 if (effectId_ != nullptr) {
62 free(effectId_);
63 effectId_ = nullptr;
64 }
65
66 if (model_ != nullptr) {
67 IEffectModelRelease(model_, IS_DIRECTLY_CALL);
68 }
69 }
70
71 /**
72 * @tc.number: SUB_Driver_Audio_EffectModel_0100
73 * @tc.name: HdfAudioIsSupplyEffectLibs001
74 * @tc.desc: Verify the EffectModelIsSupplyEffectLibs function when the input parameter is invalid.
75 * @tc.type: FUNC
76 * @tc.require: I6I658
77 */
78 HWTEST_F(EffectModelTest, HdfAudioIsSupplyEffectLibs001, TestSize.Level1)
79 {
80 bool isSupport = false;
81 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, model_->IsSupplyEffectLibs(nullptr, &isSupport));
82 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->IsSupplyEffectLibs(model_, nullptr));
83 }
84
85 /**
86 * @tc.number: SUB_Driver_Audio_EffectModel_0200
87 * @tc.name: HdfAudioIsSupplyEffectLibs002
88 * @tc.desc: Verify the EffectModelIsSupplyEffectLibs function.
89 * @tc.type: FUNC
90 * @tc.require: I6I658
91 */
92 HWTEST_F(EffectModelTest, HdfAudioIsSupplyEffectLibs002, TestSize.Level1)
93 {
94 bool isSupport = false;
95 int32_t ret = model_->IsSupplyEffectLibs(model_, &isSupport);
96 EXPECT_EQ(ret, HDF_SUCCESS);
97 }
98
99 /**
100 * @tc.number: SUB_Driver_Audio_EffectModel_0300
101 * @tc.name: HdfAudioGetAllEffectDescriptors001
102 * @tc.desc: Verify the EffectModelGetAllEffectDescriptors function when the input parameter is invalid.
103 * @tc.type: FUNC
104 * @tc.require: I6I658
105 */
106 HWTEST_F(EffectModelTest, HdfAudioGetAllEffectDescriptors001, TestSize.Level1)
107 {
108 uint32_t descsLen = MAX_DESCRIPTOR_NUM;
109 struct EffectControllerDescriptor descs[MAX_DESCRIPTOR_NUM];
110
111 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, model_->GetAllEffectDescriptors(nullptr, descs, &descsLen));
112 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->GetAllEffectDescriptors(model_, nullptr, &descsLen));
113 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->GetAllEffectDescriptors(model_, descs, nullptr));
114 }
115
116 /**
117 * @tc.number: SUB_Driver_Audio_EffectModel_0400
118 * @tc.name: HdfAudioGetAllEffectDescriptors002
119 * @tc.desc: Verify the EffectModelGetAllEffectDescriptors function.
120 * @tc.type: FUNC
121 * @tc.require: I6I658
122 */
123 HWTEST_F(EffectModelTest, HdfAudioGetAllEffectDescriptors002, TestSize.Level1)
124 {
125 uint32_t descsLen = MAX_DESCRIPTOR_NUM;
126 struct EffectControllerDescriptor descs[MAX_DESCRIPTOR_NUM];
127
128 int32_t ret = model_->GetAllEffectDescriptors(model_, descs, &descsLen);
129 ASSERT_EQ(ret, HDF_SUCCESS);
130 EXPECT_GE(MAX_DESCRIPTOR_NUM, descsLen);
131 }
132
133 /**
134 * @tc.number: SUB_Driver_Audio_EffectModel_0500
135 * @tc.name: HdfAudioGetAllEffectDescriptors003
136 * @tc.desc: Verify the descs of EffectModelGetAllEffectDescriptors function.
137 * @tc.type: FUNC
138 * @tc.require: I6I658
139 */
140 HWTEST_F(EffectModelTest, HdfAudioGetAllEffectDescriptors003, TestSize.Level1)
141 {
142 uint32_t descsLen = MAX_DESCRIPTOR_NUM;
143 struct EffectControllerDescriptor descs[MAX_DESCRIPTOR_NUM];
144
145 int32_t ret = model_->GetAllEffectDescriptors(model_, descs, &descsLen);
146 ASSERT_EQ(ret, HDF_SUCCESS);
147 EXPECT_GE(MAX_DESCRIPTOR_NUM, descsLen);
148
149 for (uint32_t i = 0; i < descsLen; i++) {
150 EXPECT_NE(nullptr, descs[i].effectId);
151 }
152
153 EffectControllerReleaseDescs(descs, &descsLen);
154 }
155
156 /**
157 * @tc.number: SUB_Driver_Audio_EffectModel_0600
158 * @tc.name: HdfAudioCreateEffectController001
159 * @tc.desc: Verify the CreateEffectController function when the input parameter is invalid.
160 * @tc.type: FUNC
161 * @tc.require: I6I658
162 */
163 HWTEST_F(EffectModelTest, HdfAudioCreateEffectController001, TestSize.Level1)
164 {
165 struct EffectInfo info = {
166 .libName = libName_,
167 .effectId = effectId_,
168 .ioDirection = 1,
169 };
170
171 struct IEffectControl *controller = NULL;
172 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, model_->CreateEffectController(nullptr, &info, &controller, &controllerId_));
173 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->CreateEffectController(model_, nullptr, &controller, &controllerId_));
174 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->CreateEffectController(model_, &info, &controller, nullptr));
175 }
176
177 /**
178 * @tc.number: SUB_Driver_Audio_EffectModel_0700
179 * @tc.name: HdfAudioDestroyEffectController001
180 * @tc.desc: Verify the DestroyEffectController function when the input parameter is invalid.
181 * @tc.type: FUNC
182 * @tc.require: I6I658
183 */
184 HWTEST_F(EffectModelTest, HdfAudioDestroyEffectController001, TestSize.Level1)
185 {
186 struct EffectInfo info = {
187 .libName = libName_,
188 .effectId = effectId_,
189 .ioDirection = 1,
190 };
191
192 struct IEffectControl *controller = NULL;
193 ASSERT_EQ(HDF_SUCCESS, model_->CreateEffectController(model_, &info, &controller, &controllerId_));
194 ASSERT_NE(controller, nullptr);
195
196 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, model_->DestroyEffectController(nullptr, &controllerId_));
197 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->DestroyEffectController(model_, nullptr));
198 }
199
200 /**
201 * @tc.number: SUB_Driver_Audio_EffectModel_0800
202 * @tc.name: HdfAudioCreateDestroyController001
203 * @tc.desc: Verify the EffectModelCreateEffectController and EffectModelDestroyEffectController function.
204 * @tc.type: FUNC
205 * @tc.require: I6I658
206 */
207 HWTEST_F(EffectModelTest, HdfAudioCreateDestroyController001, TestSize.Level1)
208 {
209 struct EffectInfo info = {
210 .libName = libName_,
211 .effectId = effectId_,
212 .ioDirection = 1,
213 };
214
215 struct IEffectControl *controller = NULL;
216 int32_t ret = model_->CreateEffectController(model_, &info, &controller, &controllerId_);
217 if (ret == HDF_SUCCESS) {
218 ASSERT_NE(controller, nullptr);
219 }
220
221 if (controller != nullptr) {
222 ret = model_->DestroyEffectController(model_, &controllerId_);
223 }
224 }
225
226 /**
227 * @tc.number: SUB_Driver_Audio_EffectModel_0900
228 * @tc.name: HdfAudioGetEffectDescriptor001
229 * @tc.desc: Verify the EffectModelGetEffectDescriptor function when the input parameter is invalid.
230 * @tc.type: FUNC
231 * @tc.require: I6I658
232 */
233 HWTEST_F(EffectModelTest, HdfAudioGetEffectDescriptor001, TestSize.Level1)
234 {
235 struct EffectControllerDescriptor desc;
236
237 EXPECT_EQ(HDF_ERR_INVALID_OBJECT, model_->GetEffectDescriptor(nullptr, effectId_, &desc));
238 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->GetEffectDescriptor(model_, nullptr, &desc));
239 EXPECT_EQ(HDF_ERR_INVALID_PARAM, model_->GetEffectDescriptor(model_, effectId_, nullptr));
240 }
241
242 /**
243 * @tc.number: SUB_Driver_Audio_EffectModel_1000
244 * @tc.name: HdfAudioGetEffectDescriptor002
245 * @tc.desc: Verify the EffectModelGetEffectDescriptor function.
246 * @tc.type: FUNC
247 * @tc.require: I6I658
248 */
249 HWTEST_F(EffectModelTest, HdfAudioGetEffectDescriptor002, TestSize.Level1)
250 {
251 struct EffectControllerDescriptor desc;
252
253 int32_t ret = model_->GetEffectDescriptor(model_, effectId_, &desc);
254 ASSERT_EQ(ret, HDF_SUCCESS);
255 EXPECT_STREQ(desc.effectId, effectId_);
256 EXPECT_STREQ(desc.effectName, "mock_effect");
257 EXPECT_STREQ(desc.libName, libName_);
258 EXPECT_STREQ(desc.supplier, "mock");
259 EffectControllerReleaseDesc(&desc);
260 }
261 } // end of namespace
262