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 #include <gtest/gtest.h>
16 #include <servmgr_hdi.h>
17 #include <osal_mem.h>
18 #include "v1_0/ihostapd_interface.h"
19 #include "hostapd_callback_impl.h"
20 #include <securec.h>
21
22 #define IFNAME "wlan0"
23
24 #define HDF_LOG_TAG service_manager_test
25 using namespace testing::ext;
26
27 namespace HdiHostapdDirectTest {
28 const char *g_hdiServiceNameHostapd = "hostapd_interface_service";
29
30 class HdfHostapdHostDirectTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp();
35 void TearDown();
36 };
37
38 static struct IHostapdInterface *g_hostapdObj = nullptr;
39 struct IHostapdCallback *g_hostapdCallbackObj = nullptr;
SetUpTestCase()40 void HdfHostapdHostDirectTest::SetUpTestCase()
41 {
42 g_hostapdObj = IHostapdInterfaceGetInstance(g_hdiServiceNameHostapd, true);
43 g_hostapdCallbackObj = HostapdCallbackServiceGet();
44 ASSERT_TRUE(g_hostapdObj != nullptr);
45 ASSERT_TRUE(g_hostapdCallbackObj != nullptr);
46 printf("hostapd_interface_service start successful.");
47 }
48
TearDownTestCase()49 void HdfHostapdHostDirectTest::TearDownTestCase()
50 {
51 IHostapdInterfaceReleaseInstance(g_hdiServiceNameHostapd, g_hostapdObj, true);
52 HostapdCallbackServiceRelease(g_hostapdCallbackObj);
53 printf("hostapd_interface_service stop successful.");
54 }
55
SetUp()56 void HdfHostapdHostDirectTest::SetUp()
57 {
58 }
59
TearDown()60 void HdfHostapdHostDirectTest::TearDown()
61 {
62 }
63
64 /**
65 * @tc.name: EnableApTest_001
66 * @tc.desc: Hostapd enable ap feature function test
67 * @tc.type: FUNC
68 * @tc.require:
69 */
70 HWTEST_F(HdfHostapdHostDirectTest, EnableApTest_001, TestSize.Level1)
71 {
72 int32_t rc = g_hostapdObj->EnableAp(g_hostapdObj, IFNAME, 1);
73 ASSERT_EQ(rc, HDF_FAILURE);
74 rc = g_hostapdObj->EnableAp(g_hostapdObj, nullptr, 1);
75 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
76 }
77
78 /**
79 * @tc.name: DisableApTest_002
80 * @tc.desc: Hostapd disable ap feature function test
81 * @tc.type: FUNC
82 * @tc.require:
83 */
84 HWTEST_F(HdfHostapdHostDirectTest, DisableApTest_002, TestSize.Level1)
85 {
86 int32_t rc = g_hostapdObj->DisableAp(g_hostapdObj, IFNAME, 1);
87 ASSERT_EQ(rc, HDF_FAILURE);
88 rc = g_hostapdObj->DisableAp(g_hostapdObj, nullptr, 1);
89 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
90 }
91
92 /**
93 * @tc.name: SetApPasswdTest_003
94 * @tc.desc: Hostapd hdi set ap passwd feature function test
95 * @tc.type: FUNC
96 * @tc.require:
97 */
98 HWTEST_F(HdfHostapdHostDirectTest, SetApPasswdTest_003, TestSize.Level1)
99 {
100 int32_t rc = g_hostapdObj->SetApPasswd(g_hostapdObj, IFNAME, "123123123", 1);
101 ASSERT_EQ(rc, HDF_FAILURE);
102 rc = g_hostapdObj->SetApPasswd(g_hostapdObj, nullptr, "123123123", 1);
103 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
104 rc = g_hostapdObj->SetApPasswd(g_hostapdObj, IFNAME, nullptr, 1);
105 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
106 }
107
108 /**
109 * @tc.name: SetApNameTest_004
110 * @tc.desc: Hostapd hdi set ap name feature function test
111 * @tc.type: FUNC
112 * @tc.require:
113 */
114 HWTEST_F(HdfHostapdHostDirectTest, SetApNameTest_004, TestSize.Level1)
115 {
116 int32_t rc = g_hostapdObj->SetApName(g_hostapdObj, IFNAME, "SFG001", 1);
117 ASSERT_EQ(rc, HDF_FAILURE);
118 rc = g_hostapdObj->SetApName(g_hostapdObj, nullptr, "SFG001", 1);
119 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
120 rc = g_hostapdObj->SetApName(g_hostapdObj, IFNAME, nullptr, 1);
121 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
122 }
123
124 /**
125 * @tc.name: SetApBandTest_006
126 * @tc.desc: Hostapd hdi set ap band feature function test
127 * @tc.type: FUNC
128 * @tc.require:
129 */
130 HWTEST_F(HdfHostapdHostDirectTest, SetApBandTest_006, TestSize.Level1)
131 {
132 int32_t rc = g_hostapdObj->SetApBand(g_hostapdObj, IFNAME, 6, 1);
133 ASSERT_EQ(rc, HDF_FAILURE);
134 rc = g_hostapdObj->SetApBand(g_hostapdObj, nullptr, 1, 1);
135 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
136 }
137
138 /**
139 * @tc.name: SetAp80211nTest_007
140 * @tc.desc: Hostapd hdi set ap 80211n feature function test
141 * @tc.type: FUNC
142 * @tc.require:
143 */
144 HWTEST_F(HdfHostapdHostDirectTest, SetAp80211nTest_007, TestSize.Level1)
145 {
146 int32_t rc = g_hostapdObj->SetAp80211n(g_hostapdObj, IFNAME, 1, 1);
147 ASSERT_EQ(rc, HDF_FAILURE);
148 rc = g_hostapdObj->SetAp80211n(g_hostapdObj, nullptr, 1, 1);
149 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
150 }
151
152 /**
153 * @tc.name: SetApWmmTest_008
154 * @tc.desc: Hostapd hdi set ap Wmm feature function test
155 * @tc.type: FUNC
156 * @tc.require:
157 */
158 HWTEST_F(HdfHostapdHostDirectTest, SetApWmmTest_008, TestSize.Level1)
159 {
160 int32_t rc = g_hostapdObj->SetApWmm(g_hostapdObj, IFNAME, 1, 1);
161 ASSERT_EQ(rc, HDF_FAILURE);
162 rc = g_hostapdObj->SetApWmm(g_hostapdObj, nullptr, 1, 1);
163 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
164 }
165
166 /**
167 * @tc.name: SetApChannelTest_009
168 * @tc.desc: Hostapd hdi set ap channel feature function test
169 * @tc.type: FUNC
170 * @tc.require:
171 */
172 HWTEST_F(HdfHostapdHostDirectTest, SetApChannelTest_009, TestSize.Level1)
173 {
174 int32_t rc = g_hostapdObj->SetApChannel(g_hostapdObj, IFNAME, 6, 1);
175 ASSERT_EQ(rc, HDF_FAILURE);
176 rc = g_hostapdObj->SetApChannel(g_hostapdObj, nullptr, 6, 1);
177 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
178 }
179
180 /**
181 * @tc.name: SetApMaxConnTest_010
182 * @tc.desc: Hostapd hdi set ap MaxConn feature function test
183 * @tc.type: FUNC
184 * @tc.require:
185 */
186 HWTEST_F(HdfHostapdHostDirectTest, SetApMaxConnTest_010, TestSize.Level1)
187 {
188 int32_t rc = g_hostapdObj->SetApMaxConn(g_hostapdObj, IFNAME, 3, 1);
189 ASSERT_EQ(rc, HDF_FAILURE);
190 rc = g_hostapdObj->SetApMaxConn(g_hostapdObj, nullptr, 3, 1);
191 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
192 }
193
194 /**
195 * @tc.name: SetMacFilterTest_011
196 * @tc.desc: Hostapd hdi set mac filter feature function test
197 * @tc.type: FUNC
198 * @tc.require:
199 */
200 HWTEST_F(HdfHostapdHostDirectTest, SetMacFilterTest_011, TestSize.Level1)
201 {
202 int32_t rc = g_hostapdObj->SetMacFilter(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
203 ASSERT_EQ(rc, HDF_FAILURE);
204 rc = g_hostapdObj->SetMacFilter(g_hostapdObj, nullptr, "34:3a:20:32:fb:31", 2);
205 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
206 rc = g_hostapdObj->SetMacFilter(g_hostapdObj, IFNAME, nullptr, 1);
207 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
208 }
209
210 /**
211 * @tc.name: DelMacFilterTest_012
212 * @tc.desc: Hostapd hdi del mac filter feature function test
213 * @tc.type: FUNC
214 * @tc.require:
215 */
216 HWTEST_F(HdfHostapdHostDirectTest, DelMacFilterTest_012, TestSize.Level1)
217 {
218 int32_t rc = g_hostapdObj->DelMacFilter(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
219 ASSERT_EQ(rc, HDF_FAILURE);
220 rc = g_hostapdObj->DelMacFilter(g_hostapdObj, nullptr, "34:3a:20:32:fb:31", 1);
221 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
222 rc = g_hostapdObj->DelMacFilter(g_hostapdObj, IFNAME, nullptr, 1);
223 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
224 }
225
226 /**
227 * @tc.name: GetStaInfosTest_013
228 * @tc.desc: Hostapd hdi get sta infos feature function test
229 * @tc.type: FUNC
230 * @tc.require:
231 */
232 HWTEST_F(HdfHostapdHostDirectTest, GetStaInfosTest_013, TestSize.Level1)
233 {
234 char *buf = (char *)calloc(4096 * 10, sizeof(char));
235 const uint32_t bufLen = 4096*10;
236 const int32_t size = 1024;
237 int32_t rc = g_hostapdObj->GetStaInfos(g_hostapdObj, IFNAME, buf, bufLen, size, 1);
238 ASSERT_EQ(rc, HDF_FAILURE);
239 rc = g_hostapdObj->GetStaInfos(g_hostapdObj, nullptr, buf, bufLen, size, 1);
240 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
241 rc = g_hostapdObj->GetStaInfos(g_hostapdObj, IFNAME, nullptr, bufLen, size, 1);
242 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
243 }
244
245 /**
246 * @tc.name: DisassociateStaTest_014
247 * @tc.desc: Hostapd hdi disassociate sta feature function test
248 * @tc.type: FUNC
249 * @tc.require:
250 */
251 HWTEST_F(HdfHostapdHostDirectTest, DisassociateStaTest_014, TestSize.Level1)
252 {
253 int32_t rc = g_hostapdObj->DisassociateSta(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
254 ASSERT_EQ(rc, HDF_FAILURE);
255 rc = g_hostapdObj->DisassociateSta(g_hostapdObj, nullptr, "34:3a:20:32:fb:31", 1);
256 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
257 rc = g_hostapdObj->DisassociateSta(g_hostapdObj, IFNAME, nullptr, 1);
258 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
259 }
260
261 /**
262 * @tc.name: HostApdShellCmdTest_015
263 * @tc.desc: Wifi hdi HostApdShellCmd function test
264 * @tc.type: FUNC
265 * @tc.require:
266 */
267 HWTEST_F(HdfHostapdHostDirectTest, HostApdShellCmdTest_015, TestSize.Level1)
268 {
269 int32_t rc = g_hostapdObj->HostApdShellCmd(g_hostapdObj, IFNAME, "");
270 ASSERT_EQ(rc, HDF_FAILURE);
271 rc = g_hostapdObj->HostApdShellCmd(g_hostapdObj, nullptr, "");
272 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
273 rc = g_hostapdObj->HostApdShellCmd(g_hostapdObj, IFNAME, nullptr);
274 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
275 }
276
277 /**
278 * @tc.name: StartApTest_016
279 * @tc.desc: Wifi hdi StartAp function test
280 * @tc.type: FUNC
281 * @tc.require:
282 */
283 HWTEST_F(HdfHostapdHostDirectTest, StartApTest_016, TestSize.Level1)
284 {
285 int32_t rc = g_hostapdObj->StartAp(g_hostapdObj);
286 ASSERT_EQ(rc, HDF_FAILURE);
287 }
288
289 /**
290 * @tc.name: StartApWithCmdTest_017
291 * @tc.desc: Wifi hdi StartApWithCmd function test
292 * @tc.type: FUNC
293 * @tc.require:
294 */
295 HWTEST_F(HdfHostapdHostDirectTest, StartApWithCmdTest_017, TestSize.Level1)
296 {
297 int32_t rc = g_hostapdObj->StartApWithCmd(g_hostapdObj, IFNAME, 1);
298 ASSERT_EQ(rc, HDF_FAILURE);
299 rc = g_hostapdObj->StartApWithCmd(g_hostapdObj, nullptr, 1);
300 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
301 }
302
303 /**
304 * @tc.name: StopApTest_018
305 * @tc.desc: Wifi hdi StopAp function test
306 * @tc.type: FUNC
307 * @tc.require:
308 */
309 HWTEST_F(HdfHostapdHostDirectTest, StopApTest_018, TestSize.Level1)
310 {
311 int32_t rc = g_hostapdObj->StopAp(g_hostapdObj);
312 ASSERT_EQ(rc, HDF_FAILURE);
313 }
314
315 /**
316 * @tc.name: ReloadApConfigInfoTest_019
317 * @tc.desc: Wifi hdi ReloadApConfigInfo function test
318 * @tc.type: FUNC
319 * @tc.require:
320 */
321 HWTEST_F(HdfHostapdHostDirectTest, ReloadApConfigInfoTest_019, TestSize.Level1)
322 {
323 int32_t rc = g_hostapdObj->ReloadApConfigInfo(g_hostapdObj, IFNAME, 1);
324 ASSERT_EQ(rc, HDF_FAILURE);
325 rc = g_hostapdObj->ReloadApConfigInfo(g_hostapdObj, nullptr, 1);
326 ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
327 }
328 };
329