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