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 HdiApTest {
28 const char *g_hdiServiceNameHostapd = "hostapd_interface_service";
29
30 class HdfHostapdHostCTest : 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 HdfHostapdHostCTest::SetUpTestCase()
41 {
42 g_hostapdObj = IHostapdInterfaceGetInstance(g_hdiServiceNameHostapd, false);
43 g_hostapdCallbackObj = HostapdCallbackServiceGet();
44 ASSERT_TRUE(g_hostapdObj != nullptr);
45 ASSERT_TRUE(g_hostapdCallbackObj != nullptr);
46 int32_t rc = g_hostapdObj->StartApWithCmd(g_hostapdObj, IFNAME, 1);
47 ASSERT_EQ(rc, HDF_SUCCESS);
48 printf("hostapd_interface_service start successful.");
49 }
50
TearDownTestCase()51 void HdfHostapdHostCTest::TearDownTestCase()
52 {
53 int32_t rc = g_hostapdObj->StopAp(g_hostapdObj);
54 ASSERT_EQ(rc, HDF_SUCCESS);
55 IHostapdInterfaceReleaseInstance(g_hdiServiceNameHostapd, g_hostapdObj, false);
56 HostapdCallbackServiceRelease(g_hostapdCallbackObj);
57 printf("hostapd_interface_service stop successful.");
58 }
59
SetUp()60 void HdfHostapdHostCTest::SetUp()
61 {
62 }
63
TearDown()64 void HdfHostapdHostCTest::TearDown()
65 {
66 }
67
68 /**
69 * @tc.name: EnableApTest_001
70 * @tc.desc: Wifi hdi Add Hostapd Iface function test
71 * @tc.type: FUNC
72 * @tc.require:
73 */
74 HWTEST_F(HdfHostapdHostCTest, EnableApTest_001, TestSize.Level1)
75 {
76 printf("Ready enter to DisableAp.");
77 int32_t rc = g_hostapdObj->DisableAp(g_hostapdObj, IFNAME, 1);
78 if (rc == HDF_SUCCESS) {
79 printf("Ready enter to EnableAp.");
80 rc = g_hostapdObj->EnableAp(g_hostapdObj, IFNAME, 1);
81 ASSERT_EQ(rc, HDF_SUCCESS);
82 }
83 printf("ifName EnableAP succ.");
84 }
85
86 /**
87 * @tc.name: SetApPasswdTest_002
88 * @tc.desc: Wifi hdi set ap passwd function test
89 * @tc.type: FUNC
90 * @tc.require:
91 */
92 HWTEST_F(HdfHostapdHostCTest, SetApPasswdTest_002, TestSize.Level1)
93 {
94 int32_t rc = g_hostapdObj->SetApPasswd(g_hostapdObj, IFNAME, "123456789", 1);
95 ASSERT_EQ(rc, HDF_SUCCESS);
96 printf("ready to enter DisableAp in HdfHostapdHostCTest.");
97 printf("DisableAp done in HdfHostapdHostCTest.");
98 }
99
100 /**
101 * @tc.name: SetApNameTest_003
102 * @tc.desc: Wifi hdi set ap name function test
103 * @tc.type: FUNC
104 * @tc.require:
105 */
106 HWTEST_F(HdfHostapdHostCTest, SetApNameTest_003, TestSize.Level1)
107 {
108 printf("ready to enter EnableAp in HdfHostapdHostCTest.");
109 printf("ready to enter SetApName in HdfHostapdHostCTest.");
110 int32_t rc = g_hostapdObj->SetApName(g_hostapdObj, IFNAME, "SFG001", 1);
111 ASSERT_EQ(rc, HDF_SUCCESS);
112 printf("ready to enter DisableAp in HdfHostapdHostCTest.");
113 }
114
115 /**
116 * @tc.name: SetApWpaValueTest_004
117 * @tc.desc: Wifi hdi set ap WpaValue function test
118 * @tc.type: FUNC
119 * @tc.require:
120 */
121 HWTEST_F(HdfHostapdHostCTest, SetApWpaValueTest_004, TestSize.Level1)
122 {
123 int32_t rc = g_hostapdObj->SetApWpaValue(g_hostapdObj, IFNAME, 2, 1);
124 ASSERT_EQ(rc, HDF_SUCCESS);
125 }
126
127 /**
128 * @tc.name: SetApBandTest_005
129 * @tc.desc: Wifi hdi set ap band function test
130 * @tc.type: FUNC
131 * @tc.require:
132 */
133 HWTEST_F(HdfHostapdHostCTest, SetApBandTest_005, TestSize.Level1)
134 {
135 int32_t rc = g_hostapdObj->SetApBand(g_hostapdObj, IFNAME, 1, 1);
136 ASSERT_EQ(rc, HDF_SUCCESS);
137 }
138
139 /**
140 * @tc.name: SetAp80211nTest_006
141 * @tc.desc: Wifi hdi set ap 80211n function test
142 * @tc.type: FUNC
143 * @tc.require:
144 */
145 HWTEST_F(HdfHostapdHostCTest, SetAp80211nTest_006, TestSize.Level1)
146 {
147 int32_t rc = g_hostapdObj->SetAp80211n(g_hostapdObj, IFNAME, 1, 1);
148 ASSERT_EQ(rc, HDF_SUCCESS);
149 }
150
151 /**
152 * @tc.name: SetApWmmTest_007
153 * @tc.desc: Wifi hdi set ap Wmm function test
154 * @tc.type: FUNC
155 * @tc.require:
156 */
157 HWTEST_F(HdfHostapdHostCTest, SetApWmmTest_007, TestSize.Level1)
158 {
159 int32_t rc = g_hostapdObj->SetApWmm(g_hostapdObj, IFNAME, 1, 1);
160 ASSERT_EQ(rc, HDF_SUCCESS);
161 }
162
163 /**
164 * @tc.name: SetApChannelTest_008
165 * @tc.desc: Wifi hdi set ap channel function test
166 * @tc.type: FUNC
167 * @tc.require:
168 */
169 HWTEST_F(HdfHostapdHostCTest, SetApChannelTest_008, TestSize.Level1)
170 {
171 int32_t rc = g_hostapdObj->SetApChannel(g_hostapdObj, IFNAME, 6, 1);
172 ASSERT_EQ(rc, HDF_SUCCESS);
173 }
174
175 /**
176 * @tc.name: SetApMaxConnTest_009
177 * @tc.desc: Wifi hdi set ap MaxConn function test
178 * @tc.type: FUNC
179 * @tc.require:
180 */
181 HWTEST_F(HdfHostapdHostCTest, SetApMaxConnTest_009, TestSize.Level1)
182 {
183 int32_t rc = g_hostapdObj->SetApMaxConn(g_hostapdObj, IFNAME, 3, 1);
184 ASSERT_EQ(rc, HDF_SUCCESS);
185 }
186
187 /**
188 * @tc.name: SetMacFilterTest_010
189 * @tc.desc: Wifi hdi set mac filter function test
190 * @tc.type: FUNC
191 * @tc.require:
192 */
193 HWTEST_F(HdfHostapdHostCTest, SetMacFilterTest_010, TestSize.Level1)
194 {
195 int32_t rc = g_hostapdObj->SetMacFilter(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
196 ASSERT_EQ(rc, HDF_SUCCESS);
197 }
198
199 /**
200 * @tc.name: DelMacFilterTest_011
201 * @tc.desc: Wifi hdi del mac filter function test
202 * @tc.type: FUNC
203 * @tc.require:
204 */
205 HWTEST_F(HdfHostapdHostCTest, DelMacFilterTest_011, TestSize.Level1)
206 {
207 int32_t rc = g_hostapdObj->DelMacFilter(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
208 ASSERT_EQ(rc, HDF_SUCCESS);
209 }
210
211 /**
212 * @tc.name: GetStaInfosTest_012
213 * @tc.desc: Wifi hdi get sta infos function test
214 * @tc.type: FUNC
215 * @tc.require:
216 */
217 HWTEST_F(HdfHostapdHostCTest, GetStaInfosTest_012, TestSize.Level1)
218 {
219 char *buf = (char *)calloc(4096 * 10, sizeof(char));
220 uint32_t bufLen = 4096 * 10;
221 int32_t size = 1024;
222 int32_t rc = g_hostapdObj->GetStaInfos(g_hostapdObj, IFNAME, buf, bufLen, size, 1);
223 ASSERT_EQ(rc, HDF_SUCCESS);
224 free(buf);
225 }
226
227 /**
228 * @tc.name: DisassociateStaTest_013
229 * @tc.desc: Wifi hdi disassociate sta function test
230 * @tc.type: FUNC
231 * @tc.require:
232 */
233 HWTEST_F(HdfHostapdHostCTest, DisassociateStaTest_013, TestSize.Level1)
234 {
235 int32_t rc = g_hostapdObj->DisassociateSta(g_hostapdObj, IFNAME, "34:3a:20:32:fb:31", 1);
236 ASSERT_EQ(rc, HDF_SUCCESS);
237 }
238
239 /**
240 * @tc.name: HostApdShellCmdTest_015
241 * @tc.desc: Wifi hdi HostApdShellCmd function test
242 * @tc.type: FUNC
243 * @tc.require:
244 */
245 HWTEST_F(HdfHostapdHostCTest, HostApdShellCmdTest_015, TestSize.Level1)
246 {
247 int32_t rc = g_hostapdObj->HostApdShellCmd(g_hostapdObj, IFNAME, "");
248 ASSERT_EQ(rc, HDF_SUCCESS);
249 }
250
251 /**
252 * @tc.name: ReloadApConfigInfo_016
253 * @tc.desc: Wifi hdi ReloadApConfigInfo function test
254 * @tc.type: FUNC
255 * @tc.require:
256 */
257 HWTEST_F(HdfHostapdHostCTest, ReloadApConfigInfo_016, TestSize.Level1)
258 {
259 int32_t rc = g_hostapdObj->ReloadApConfigInfo(g_hostapdObj, IFNAME, 1);
260 ASSERT_EQ(rc, HDF_SUCCESS);
261 }
262
263 };
264