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 <gmock/gmock.h>
17 #include "securec.h"
18 #include "wifi_hal_callback.h"
19 #include <log.h>
20
21 using ::testing::_;
22 using ::testing::AtLeast;
23 using ::testing::Eq;
24 using ::testing::ext::TestSize;
25
26 namespace OHOS {
27 namespace Wifi {
28 const int STATUS_MSG = 0;
29 const int NET_WORK = 5;
30 const int DISASSOC_STA_HAS_LEFT = 0;
31 static std::string g_errLog;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)32 void MyLogCallback(const LogType type, const LogLevel level,
33 const unsigned int domain, const char *tag,
34 const char *msg)
35 {
36 g_errLog = msg;
37 }
38
39 class WifiHalCallbackTest : public testing::Test {
40 public:
SetUpTestCase()41 static void SetUpTestCase() {}
TearDownTestCase()42 static void TearDownTestCase() {}
SetUp()43 virtual void SetUp()
44 {
45 LOG_SetCallback(MyLogCallback);
46 }
TearDown()47 virtual void TearDown() {}
48 };
49
50 HWTEST_F(WifiHalCallbackTest, RpcP2pSetWpsSecondaryDeviceTypeTest, TestSize.Level1)
51 {
52 int status = STATUS_MSG;
53 WifiHalCbNotifyScanEnd(status);
54 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
55 }
56
57 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyConnectChangedTest, TestSize.Level1)
58 {
59 int status = STATUS_MSG;
60 int networkId = NET_WORK;
61 char pos[] = "WIFI_REASON_LENGTH";
62 WifiHalCbNotifyConnectChanged(status, networkId, NULL);
63 WifiHalCbNotifyConnectChanged(status, networkId, pos);
64 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
65 }
66
67 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyDisConnectReasonTest, TestSize.Level1)
68 {
69 int status = DISASSOC_STA_HAS_LEFT;
70 char bssid[] = "02:42:ac:11:00:04";
71 WifiHalCbNotifyDisConnectReason(status, NULL);
72 WifiHalCbNotifyDisConnectReason(status, bssid);
73 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
74 }
75
76 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyBssidChangedTest, TestSize.Level1)
77 {
78 char reasonPos[] = "WIFI_REASON_LENGTH";
79 char bssidPos[] = "hello";
80 WifiHalCbNotifyBssidChanged(nullptr, bssidPos);
81 WifiHalCbNotifyBssidChanged(reasonPos, nullptr);
82 WifiHalCbNotifyBssidChanged(reasonPos, bssidPos);
83 char reason[] = "hello world";
84 WifiHalCbNotifyBssidChanged(reason, bssidPos);
85 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
86 }
87
88 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyWpaStateChangeTest, TestSize.Level1)
89 {
90 int status = STATUS_MSG;
91 WifiHalCbNotifyWpaStateChange(status);
92 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
93 }
94
95
96 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyWrongKeyTest, TestSize.Level1)
97 {
98 int status = STATUS_MSG;
99 WifiHalCbNotifyWrongKey(status);
100 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
101 }
102
103
104 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyConnectionFullTest, TestSize.Level1)
105 {
106 int status = STATUS_MSG;
107 WifiHalCbNotifyConnectionFull(status);
108 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
109 }
110
111 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyConnectionRejectTest, TestSize.Level1)
112 {
113 int status = STATUS_MSG;
114 WifiHalCbNotifyConnectionReject(status);
115 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
116 }
117
118 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyWpsOverlapTest, TestSize.Level1)
119 {
120 int event = STATUS_MSG;
121 WifiHalCbNotifyWpsOverlap(event);
122 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
123 }
124
125 HWTEST_F(WifiHalCallbackTest, WifiHalCbNotifyWpsTimeOutTest, TestSize.Level1)
126 {
127 int event = STATUS_MSG;
128 WifiHalCbNotifyWpsTimeOut(event);
129 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
130 }
131
132
133 HWTEST_F(WifiHalCallbackTest, WifiHalCbStaJoinTest, TestSize.Level1)
134 {
135 int id = NET_WORK;
136 char content[] = "AP-STA-CONNECTED";
137 char contents[] = "AP-STA-DISCONNECTED";
138 char contented[] = "WIFI_STA_LEAVE_EVENT";
139 WifiHalCbStaJoin(nullptr, id);
140 WifiHalCbStaJoin(content, id);
141 WifiHalCbStaJoin(contents, id);
142 WifiHalCbStaJoin(contented, id);
143 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
144 }
145
146 HWTEST_F(WifiHalCallbackTest, WifiHalCbApStateTest, TestSize.Level1)
147 {
148 int id = NET_WORK;
149 char content[] = "AP-ENABLED";
150 char contents[] = "AP-ENABLED";
151 char contentd[] = "CTRL-EVENT-TERMINATING";
152 char contented[] = "WIFI_STA_LEAVE_EVENT";
153 WifiHalCbApState(nullptr, id);
154 WifiHalCbApState(content, id);
155 WifiHalCbApState(contents, id);
156 WifiHalCbApState(contentd, id);
157 WifiHalCbApState(contented, id);
158 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
159 }
160
161 HWTEST_F(WifiHalCallbackTest, WifiP2pHalCbNotifyConnectSupplicantTest, TestSize.Level1)
162 {
163 int event = STATUS_MSG;
164 WifiP2pHalCbNotifyConnectSupplicant(event);
165 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
166 }
167
168 HWTEST_F(WifiHalCallbackTest, P2pHalCbDeviceFoundTest, TestSize.Level1)
169 {
170 P2pDeviceInfo device;
171 P2pHalCbDeviceFound(nullptr);
172 P2pHalCbDeviceFound(&device);
173 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
174 }
175
176 HWTEST_F(WifiHalCallbackTest, P2pHalCbDeviceLostTest, TestSize.Level1)
177 {
178 char p2pDeviceAddress[] = "00:00:00:00:00:00";
179 P2pHalCbDeviceLost(nullptr);
180 P2pHalCbDeviceLost(p2pDeviceAddress);
181 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
182 }
183
184 HWTEST_F(WifiHalCallbackTest, P2pHalCbGoNegotiationRequestTest, TestSize.Level1)
185 {
186 char srcAddress[] = "00:00:00:00:00:00";
187 short passwordId = NET_WORK;
188 P2pHalCbGoNegotiationRequest(nullptr, passwordId);
189 P2pHalCbGoNegotiationRequest(srcAddress, passwordId);
190 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
191 }
192
193 HWTEST_F(WifiHalCallbackTest, P2pHalCbGoNegotiationSuccessTest, TestSize.Level1)
194 {
195 P2pHalCbGoNegotiationSuccess();
196 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
197 }
198
199 HWTEST_F(WifiHalCallbackTest, P2pHalCbGoNegotiationFailureTest, TestSize.Level1)
200 {
201 int status = STATUS_MSG;
202 P2pHalCbGoNegotiationFailure(status);
203 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
204 }
205
206 HWTEST_F(WifiHalCallbackTest, P2pHalCbInvitationReceivedTest, TestSize.Level1)
207 {
208 P2pInvitationInfo info;
209 P2pHalCbInvitationReceived(NULL);
210 P2pHalCbInvitationReceived(&info);
211 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
212 }
213
214 HWTEST_F(WifiHalCallbackTest, P2pHalCbInvitationResultTest, TestSize.Level1)
215 {
216 int status = STATUS_MSG;
217 char bssid[] = "wifibssid";
218 P2pHalCbInvitationResult(NULL, status);
219 P2pHalCbInvitationResult(bssid, status);
220 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
221 }
222
223 HWTEST_F(WifiHalCallbackTest, P2pHalCbGroupFormationSuccessTest, TestSize.Level1)
224 {
225 P2pHalCbGroupFormationSuccess();
226 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
227 }
228
229 HWTEST_F(WifiHalCallbackTest, P2pHalCbGroupFormationFailureTest, TestSize.Level1)
230 {
231 char reason[] = "P2P_GROUP_FORMATION_FAILURE_EVENT";
232 P2pHalCbGroupFormationFailure(NULL);
233 P2pHalCbGroupFormationFailure(reason);
234 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
235 }
236
237 HWTEST_F(WifiHalCallbackTest, P2pHalCbGroupStartedTest, TestSize.Level1)
238 {
239 P2pGroupInfo info;
240 P2pHalCbGroupStarted(NULL);
241 P2pHalCbGroupStarted(&info);
242 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
243 }
244
245 HWTEST_F(WifiHalCallbackTest, P2pHalCbGroupRemovedTest, TestSize.Level1)
246 {
247 char groupIfName[] = "P2P_GROUP_REMOVED_EVENT";
248 int isGo = NET_WORK;
249 P2pHalCbGroupRemoved(NULL, isGo);
250 P2pHalCbGroupRemoved(groupIfName, isGo);
251 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
252 }
253
254 HWTEST_F(WifiHalCallbackTest, P2pHalCbProvisionDiscoveryPbcRequestTest, TestSize.Level1)
255 {
256 P2pHalCbProvisionDiscoveryPbcRequest(NULL);
257 P2pHalCbProvisionDiscoveryPbcRequest("P2P_PROV_DISC_PBC_REQ_EVENT");
258 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
259 }
260
261 HWTEST_F(WifiHalCallbackTest, P2pHalCbProvisionDiscoveryPbcResponseTest, TestSize.Level1)
262 {
263 P2pHalCbProvisionDiscoveryPbcResponse(NULL);
264 P2pHalCbProvisionDiscoveryPbcResponse("00:00:00:00:00:00");
265 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
266 }
267
268 HWTEST_F(WifiHalCallbackTest, P2pHalCbProvisionDiscoveryEnterPinTest, TestSize.Level1)
269 {
270 P2pHalCbProvisionDiscoveryEnterPin(NULL);
271 P2pHalCbProvisionDiscoveryEnterPin("00:00:00:00:00:00");
272 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
273 }
274
275 HWTEST_F(WifiHalCallbackTest, P2pHalCbProvisionDiscoveryShowPinTest, TestSize.Level1)
276 {
277 char address[] = "00:00:00:00:00:00";
278 char pin[] = "P2P_PROV_DISC_SHOW_PIN_EVEN";
279 P2pHalCbProvisionDiscoveryShowPin(NULL, pin);
280 P2pHalCbProvisionDiscoveryShowPin(address, NULL);
281 P2pHalCbProvisionDiscoveryShowPin(address, pin);
282 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
283 }
284
285 HWTEST_F(WifiHalCallbackTest, P2pHalCbProvisionDiscoveryFailureTest, TestSize.Level1)
286 {
287 P2pHalCbProvisionDiscoveryFailure();
288 P2pHalCbFindStopped();
289 P2pHalCbConnectSupplicantFailed();
290 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
291 }
292
293 HWTEST_F(WifiHalCallbackTest, P2pHalCbServiceDiscoveryResponseTest, TestSize.Level1)
294 {
295 P2pServDiscRespInfo info;
296 char buff[] = "\t1002callback";
297 info.tlvs = buff;
298 P2pHalCbServiceDiscoveryResponse(NULL);
299 P2pHalCbServiceDiscoveryResponse(&info);
300 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
301 }
302
303 HWTEST_F(WifiHalCallbackTest, P2pHalCbStaConnectStateTest, TestSize.Level1)
304 {
305 int state = STATUS_MSG;
306 char p2pDeviceAddress[] = "wifibssid";
307 char p2pGroupAddress[] = "wifiGroupAddr";
308 P2pHalCbStaConnectState(NULL, NULL, state);
309 P2pHalCbStaConnectState(p2pDeviceAddress, p2pGroupAddress, state);
310 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
311 }
312
313 HWTEST_F(WifiHalCallbackTest, P2pHalCbServDiscReqTest, TestSize.Level1)
314 {
315 P2pServDiscReqInfo info;
316 char buff[] = "\t1002request";
317 info.tlvs = buff;
318 P2pHalCbServDiscReq(NULL);
319 P2pHalCbServDiscReq(&info);
320 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
321 }
322
323 HWTEST_F(WifiHalCallbackTest, P2pHalCbP2pIfaceCreatedTest, TestSize.Level1)
324 {
325 int state = STATUS_MSG;
326 char ifName[] = "wifibssid";
327 P2pHalCbP2pIfaceCreated(NULL, state);
328 P2pHalCbP2pIfaceCreated(ifName, state);
329 EXPECT_FALSE(g_errLog.find("callback")!=std::string::npos);
330 }
331 } // namespace Wifi
332 } // namespace OHOS
333
334