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 <string>
18 #include <system_ability_definition.h>
19
20 #include "edm_sys_manager_mock.h"
21 #include "enterprise_device_mgr_stub_mock.h"
22 #include "message_parcel_utils.h"
23 #include "utils.h"
24 #include "wifi_id.h"
25 #include "wifi_manager_proxy.h"
26
27 using namespace testing::ext;
28 using namespace testing;
29
30 namespace OHOS {
31 namespace EDM {
32 namespace TEST {
33 const std::string ADMIN_PACKAGENAME = "com.edm.test.demo";
34 class WifiManagerProxyTest : public testing::Test {
35 protected:
36 void SetUp() override;
37
38 void TearDown() override;
39
40 static void TearDownTestSuite(void);
41 std::shared_ptr<WifiManagerProxy> wifiManagerProxy = nullptr;
42 std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
43 sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
44 };
45
SetUp()46 void WifiManagerProxyTest::SetUp()
47 {
48 wifiManagerProxy = WifiManagerProxy::GetWifiManagerProxy();
49 edmSysManager_ = std::make_shared<EdmSysManager>();
50 object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
51 edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
52 Utils::SetEdmServiceEnable();
53 }
54
TearDown()55 void WifiManagerProxyTest::TearDown()
56 {
57 wifiManagerProxy.reset();
58 edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
59 object_ = nullptr;
60 Utils::SetEdmServiceDisable();
61 }
62
TearDownTestSuite()63 void WifiManagerProxyTest::TearDownTestSuite()
64 {
65 ASSERT_FALSE(Utils::GetEdmServiceState());
66 std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
67 }
68
69 /**
70 * @tc.name: TestIsWifiActiveSuc
71 * @tc.desc: Test IsWifiActive func.
72 * @tc.type: FUNC
73 */
74 HWTEST_F(WifiManagerProxyTest, TestIsWifiActiveSuc, TestSize.Level1)
75 {
76 MessageParcel data;
77 OHOS::AppExecFwk::ElementName admin;
78 admin.SetBundleName(ADMIN_PACKAGENAME);
79 data.WriteParcelable(&admin);
80 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
81 .Times(1)
82 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
83 bool isActive = false;
84 int32_t ret = wifiManagerProxy->IsWifiActive(data, isActive);
85 ASSERT_TRUE(ret == ERR_OK);
86 ASSERT_TRUE(isActive);
87 }
88
89 /**
90 * @tc.name: TestIsWifiActiveFail
91 * @tc.desc: Test IsWifiActive func without enable edm service.
92 * @tc.type: FUNC
93 */
94 HWTEST_F(WifiManagerProxyTest, TestIsWifiActiveFail, TestSize.Level1)
95 {
96 Utils::SetEdmServiceDisable();
97 MessageParcel data;
98 OHOS::AppExecFwk::ElementName admin;
99 admin.SetBundleName(ADMIN_PACKAGENAME);
100 data.WriteParcelable(&admin);
101 bool isActive = false;
102 int32_t ret = wifiManagerProxy->IsWifiActive(data, isActive);
103 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
104 ASSERT_FALSE(isActive);
105 }
106
107 /**
108 * @tc.name: TestSetWifiProfileSuc
109 * @tc.desc: Test SetWifiProfile success func.
110 * @tc.type: FUNC
111 */
112 HWTEST_F(WifiManagerProxyTest, TestSetWifiProfileSuc, TestSize.Level1)
113 {
114 MessageParcel data;
115 OHOS::AppExecFwk::ElementName admin;
116 admin.SetBundleName(ADMIN_PACKAGENAME);
117 data.WriteParcelable(&admin);
118 Wifi::WifiDeviceConfig config;
119 config.wifiIpConfig.staticIpAddress.ipAddress.address.addressIpv6 = { 0x01 };
120 WifiPassword pwd;
121 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
122 .Times(1)
123 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
124 MessageParcelUtils::WriteWifiDeviceConfig(config, data, pwd);
125
126 int32_t ret = wifiManagerProxy->SetWifiProfile(data);
127 ASSERT_TRUE(ret == ERR_OK);
128 }
129
130 /**
131 * @tc.name: TestSetWifiProfileFail
132 * @tc.desc: Test SetWifiProfile func without enable edm service.
133 * @tc.type: FUNC
134 */
135 HWTEST_F(WifiManagerProxyTest, TestSetWifiProfileFail, TestSize.Level1)
136 {
137 Utils::SetEdmServiceDisable();
138 MessageParcel data;
139 OHOS::AppExecFwk::ElementName admin;
140 admin.SetBundleName(ADMIN_PACKAGENAME);
141 data.WriteParcelable(&admin);
142 Wifi::WifiDeviceConfig config;
143 config.wifiIpConfig.staticIpAddress.ipAddress.address.addressIpv6 = { 0x01 };
144 WifiPassword pwd;
145 MessageParcelUtils::WriteWifiDeviceConfig(config, data, pwd);
146
147 int32_t ret = wifiManagerProxy->SetWifiProfile(data);
148 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
149 }
150
151 /**
152 * @tc.name: TestSetWifiDisabledSuc
153 * @tc.desc: Test SetWifiDisabled func.
154 * @tc.type: FUNC
155 */
156 HWTEST_F(WifiManagerProxyTest, TestSetWifiDisabledSuc, TestSize.Level1)
157 {
158 MessageParcel data;
159 OHOS::AppExecFwk::ElementName admin;
160 admin.SetBundleName(ADMIN_PACKAGENAME);
161 data.WriteParcelable(&admin);
162 data.WriteBool(true);
163 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
164 .Times(1)
165 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
166
167 int32_t ret = wifiManagerProxy->SetWifiDisabled(data);
168 ASSERT_TRUE(ret == ERR_OK);
169 }
170
171 /**
172 * @tc.name: TestSetWifiDisabledFail
173 * @tc.desc: Test SetWifiDisabled func without enable edm service.
174 * @tc.type: FUNC
175 */
176 HWTEST_F(WifiManagerProxyTest, TestSetWifiDisabledFail, TestSize.Level1)
177 {
178 Utils::SetEdmServiceDisable();
179 MessageParcel data;
180 OHOS::AppExecFwk::ElementName admin;
181 admin.SetBundleName(ADMIN_PACKAGENAME);
182 data.WriteParcelable(&admin);
183 data.WriteBool(true);
184
185 int32_t ret = wifiManagerProxy->SetWifiDisabled(data);
186 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
187 }
188
189 /**
190 * @tc.name: TestIsWifiDisabledSuc
191 * @tc.desc: Test IsWifiDisabled func.
192 * @tc.type: FUNC
193 */
194 HWTEST_F(WifiManagerProxyTest, TestIsWifiDisabledSuc, TestSize.Level1)
195 {
196 MessageParcel data;
197 OHOS::AppExecFwk::ElementName admin;
198 admin.SetBundleName(ADMIN_PACKAGENAME);
199 data.WriteParcelable(&admin);
200 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
201 .Times(1)
202 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
203 bool isDisable = false;
204 int32_t ret = wifiManagerProxy->IsWifiDisabled(data, isDisable);
205 ASSERT_TRUE(ret == ERR_OK);
206 ASSERT_TRUE(isDisable);
207 }
208
209 /**
210 * @tc.name: TestIsWifiDisabledFail
211 * @tc.desc: Test IsWifiDisabled func without enable edm service.
212 * @tc.type: FUNC
213 */
214 HWTEST_F(WifiManagerProxyTest, TestIsWifiDisabledFail, TestSize.Level1)
215 {
216 Utils::SetEdmServiceDisable();
217 MessageParcel data;
218 OHOS::AppExecFwk::ElementName admin;
219 admin.SetBundleName(ADMIN_PACKAGENAME);
220 data.WriteParcelable(&admin);
221 bool isDisable = false;
222 int32_t ret = wifiManagerProxy->IsWifiDisabled(data, isDisable);
223 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
224 ASSERT_FALSE(isDisable);
225 }
226
227 /**
228 * @tc.name: TestAddAllowedWifiListSuc
229 * @tc.desc: Test AddAllowedWifiList success func.
230 * @tc.type: FUNC
231 */
232 HWTEST_F(WifiManagerProxyTest, TestAddAllowedWifiListSuc, TestSize.Level1)
233 {
234 MessageParcel data;
235 OHOS::AppExecFwk::ElementName admin;
236 admin.SetBundleName(ADMIN_PACKAGENAME);
237 data.WriteParcelable(&admin);
238 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
239 .Times(1)
240 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
241 WifiId id1;
242 id1.SetSsid("wifi_name");
243 id1.SetBssid("68:77:24:77:A6:D6");
244 data.WriteUint32(1);
245 id1.Marshalling(data);
246
247 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::SET,
248 EdmInterfaceCode::ALLOWED_WIFI_LIST);
249 ASSERT_TRUE(ret == ERR_OK);
250 }
251
252 /**
253 * @tc.name: TestAddAllowedWifiListFail
254 * @tc.desc: Test AddAllowedWifiList without enable edm service func.
255 * @tc.type: FUNC
256 */
257 HWTEST_F(WifiManagerProxyTest, TestAddAllowedWifiListFail, TestSize.Level1)
258 {
259 Utils::SetEdmServiceDisable();
260 MessageParcel data;
261 OHOS::AppExecFwk::ElementName admin;
262 admin.SetBundleName(ADMIN_PACKAGENAME);
263 data.WriteParcelable(&admin);
264 WifiId id1;
265 id1.SetSsid("wifi_name");
266 id1.SetBssid("68:77:24:77:A6:D6");
267 data.WriteUint32(1);
268 id1.Marshalling(data);
269
270 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::SET,
271 EdmInterfaceCode::ALLOWED_WIFI_LIST);
272 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
273 }
274
275 /**
276 * @tc.name: TestRemoveAllowedWifiListSuc
277 * @tc.desc: Test RemoveAllowedWifiList success func.
278 * @tc.type: FUNC
279 */
280 HWTEST_F(WifiManagerProxyTest, TestRemoveAllowedWifiListSuc, TestSize.Level1)
281 {
282 MessageParcel data;
283 OHOS::AppExecFwk::ElementName admin;
284 admin.SetBundleName(ADMIN_PACKAGENAME);
285 data.WriteParcelable(&admin);
286 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
287 .Times(1)
288 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
289 WifiId id1;
290 id1.SetSsid("wifi_name");
291 id1.SetBssid("68:77:24:77:A6:D6");
292 data.WriteUint32(1);
293 id1.Marshalling(data);
294
295 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::REMOVE,
296 EdmInterfaceCode::ALLOWED_WIFI_LIST);
297 ASSERT_TRUE(ret == ERR_OK);
298 }
299
300 /**
301 * @tc.name: TestRemoveAllowedWifiListFail
302 * @tc.desc: Test RemoveAllowedWifiList without enable edm service func.
303 * @tc.type: FUNC
304 */
305 HWTEST_F(WifiManagerProxyTest, TestRemoveAllowedWifiListFail, TestSize.Level1)
306 {
307 Utils::SetEdmServiceDisable();
308 MessageParcel data;
309 OHOS::AppExecFwk::ElementName admin;
310 admin.SetBundleName(ADMIN_PACKAGENAME);
311 data.WriteParcelable(&admin);
312 WifiId id1;
313 id1.SetSsid("wifi_name");
314 id1.SetBssid("68:77:24:77:A6:D6");
315 data.WriteUint32(1);
316 id1.Marshalling(data);
317
318 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::REMOVE,
319 EdmInterfaceCode::ALLOWED_WIFI_LIST);
320 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
321 }
322
323 /**
324 * @tc.name: TestGetAllowedWifiListSuc
325 * @tc.desc: Test GetAllowedWifiList func.
326 * @tc.type: FUNC
327 */
328 HWTEST_F(WifiManagerProxyTest, TestGetAllowedWifiListSuc, TestSize.Level1)
329 {
330 MessageParcel data;
331 OHOS::AppExecFwk::ElementName admin;
332 admin.SetBundleName(ADMIN_PACKAGENAME);
333 data.WriteParcelable(&admin);
334 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
335 .Times(1)
336 .WillOnce(Invoke(object_.GetRefPtr(),
337 &EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy));
338
339 std::vector<WifiId> wifiIds;
340 int32_t ret = wifiManagerProxy->GetWifiList(data, wifiIds, EdmInterfaceCode::ALLOWED_WIFI_LIST);
341 ASSERT_TRUE(ret == ERR_OK);
342 ASSERT_TRUE(wifiIds.size() == 1);
343 }
344
345 /**
346 * @tc.name: TestGetAllowedWifiListFail
347 * @tc.desc: Test GetAllowedWifiList func without enable edm service.
348 * @tc.type: FUNC
349 */
350 HWTEST_F(WifiManagerProxyTest, TestGetAllowedWifiListFail, TestSize.Level1)
351 {
352 Utils::SetEdmServiceDisable();
353 MessageParcel data;
354 OHOS::AppExecFwk::ElementName admin;
355 admin.SetBundleName(ADMIN_PACKAGENAME);
356 data.WriteParcelable(&admin);
357
358 std::vector<WifiId> wifiIds;
359 int32_t ret = wifiManagerProxy->GetWifiList(data, wifiIds, EdmInterfaceCode::ALLOWED_WIFI_LIST);
360 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
361 ASSERT_TRUE(wifiIds.empty());
362 }
363
364 /**
365 * @tc.name: TestAddDisallowedWifiListSuc
366 * @tc.desc: Test AddDisallowedWifiList success func.
367 * @tc.type: FUNC
368 */
369 HWTEST_F(WifiManagerProxyTest, TestAddDisallowedWifiListSuc, TestSize.Level1)
370 {
371 MessageParcel data;
372 OHOS::AppExecFwk::ElementName admin;
373 admin.SetBundleName(ADMIN_PACKAGENAME);
374 data.WriteParcelable(&admin);
375 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
376 .Times(1)
377 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
378 WifiId id1;
379 id1.SetSsid("wifi_name");
380 id1.SetBssid("68:77:24:77:A6:D6");
381 data.WriteUint32(1);
382 id1.Marshalling(data);
383
384 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::SET,
385 EdmInterfaceCode::DISALLOWED_WIFI_LIST);
386 ASSERT_TRUE(ret == ERR_OK);
387 }
388
389 /**
390 * @tc.name: TestAddDisallowedWifiListFail
391 * @tc.desc: Test AddDisallowedWifiList without enable edm service func.
392 * @tc.type: FUNC
393 */
394 HWTEST_F(WifiManagerProxyTest, TestAddDisallowedWifiListFail, TestSize.Level1)
395 {
396 Utils::SetEdmServiceDisable();
397 MessageParcel data;
398 OHOS::AppExecFwk::ElementName admin;
399 admin.SetBundleName(ADMIN_PACKAGENAME);
400 data.WriteParcelable(&admin);
401 WifiId id1;
402 id1.SetSsid("wifi_name");
403 id1.SetBssid("68:77:24:77:A6:D6");
404 data.WriteUint32(1);
405 id1.Marshalling(data);
406
407 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::SET,
408 EdmInterfaceCode::DISALLOWED_WIFI_LIST);
409 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
410 }
411
412 /**
413 * @tc.name: TestRemoveDisallowedWifiListSuc
414 * @tc.desc: Test RemoveDisallowedWifiList success func.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(WifiManagerProxyTest, TestRemoveDisallowedWifiListSuc, TestSize.Level1)
418 {
419 MessageParcel data;
420 OHOS::AppExecFwk::ElementName admin;
421 admin.SetBundleName(ADMIN_PACKAGENAME);
422 data.WriteParcelable(&admin);
423 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
424 .Times(1)
425 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
426 WifiId id1;
427 id1.SetSsid("wifi_name");
428 id1.SetBssid("68:77:24:77:A6:D6");
429 data.WriteUint32(1);
430 id1.Marshalling(data);
431
432 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::REMOVE,
433 EdmInterfaceCode::DISALLOWED_WIFI_LIST);
434 ASSERT_TRUE(ret == ERR_OK);
435 }
436
437 /**
438 * @tc.name: TestRemoveDisallowedWifiListFail
439 * @tc.desc: Test RemoveDisallowedWifiList without enable edm service func.
440 * @tc.type: FUNC
441 */
442 HWTEST_F(WifiManagerProxyTest, TestRemoveDisallowedWifiListFail, TestSize.Level1)
443 {
444 Utils::SetEdmServiceDisable();
445 MessageParcel data;
446 OHOS::AppExecFwk::ElementName admin;
447 admin.SetBundleName(ADMIN_PACKAGENAME);
448 data.WriteParcelable(&admin);
449 WifiId id1;
450 id1.SetSsid("wifi_name");
451 id1.SetBssid("68:77:24:77:A6:D6");
452 data.WriteUint32(1);
453 id1.Marshalling(data);
454
455 int32_t ret = wifiManagerProxy->AddOrRemoveWifiList(data, FuncOperateType::REMOVE,
456 EdmInterfaceCode::DISALLOWED_WIFI_LIST);
457 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
458 }
459
460 /**
461 * @tc.name: TestGetDisallowedWifiListSuc
462 * @tc.desc: Test GetDisallowedWifiList func.
463 * @tc.type: FUNC
464 */
465 HWTEST_F(WifiManagerProxyTest, TestGetDisallowedWifiListSuc, TestSize.Level1)
466 {
467 MessageParcel data;
468 OHOS::AppExecFwk::ElementName admin;
469 admin.SetBundleName(ADMIN_PACKAGENAME);
470 data.WriteParcelable(&admin);
471 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
472 .Times(1)
473 .WillOnce(Invoke(object_.GetRefPtr(),
474 &EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy));
475
476 std::vector<WifiId> wifiIds;
477 int32_t ret = wifiManagerProxy->GetWifiList(data, wifiIds, EdmInterfaceCode::DISALLOWED_WIFI_LIST);
478 ASSERT_TRUE(ret == ERR_OK);
479 ASSERT_TRUE(wifiIds.size() == 1);
480 }
481
482 /**
483 * @tc.name: TestGetDisallowedWifiListFail
484 * @tc.desc: Test GetDisallowedWifiList func without enable edm service.
485 * @tc.type: FUNC
486 */
487 HWTEST_F(WifiManagerProxyTest, TestGetDisallowedWifiListFail, TestSize.Level1)
488 {
489 Utils::SetEdmServiceDisable();
490 MessageParcel data;
491 OHOS::AppExecFwk::ElementName admin;
492 admin.SetBundleName(ADMIN_PACKAGENAME);
493 data.WriteParcelable(&admin);
494
495 std::vector<WifiId> wifiIds;
496 int32_t ret = wifiManagerProxy->GetWifiList(data, wifiIds, EdmInterfaceCode::DISALLOWED_WIFI_LIST);
497 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
498 ASSERT_TRUE(wifiIds.empty());
499 }
500
501 /**
502 * @tc.name: TestForceTurnOnWifiSuc
503 * @tc.desc: Test TurnOnWifi func.
504 * @tc.type: FUNC
505 */
506 HWTEST_F(WifiManagerProxyTest, TestForceTurnOnWifiSuc, TestSize.Level1)
507 {
508 MessageParcel data;
509 OHOS::AppExecFwk::ElementName admin;
510 admin.SetBundleName(ADMIN_PACKAGENAME);
511 data.WriteParcelable(&admin);
512 data.WriteBool(true);
513 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
514 .Times(1)
515 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy));
516
517 int32_t ret = wifiManagerProxy->TurnOnWifi(data);
518 ASSERT_TRUE(ret == ERR_OK);
519 }
520
521 /**
522 * @tc.name: TestForceTurnOnWifiFail
523 * @tc.desc: Test TurnOnWifi func without enable edm service.
524 * @tc.type: FUNC
525 */
526 HWTEST_F(WifiManagerProxyTest, TestForceTurnOnWifiFail, TestSize.Level1)
527 {
528 Utils::SetEdmServiceDisable();
529 MessageParcel data;
530 OHOS::AppExecFwk::ElementName admin;
531 admin.SetBundleName(ADMIN_PACKAGENAME);
532 data.WriteParcelable(&admin);
533 data.WriteBool(true);
534 int32_t ret = wifiManagerProxy->TurnOnWifi(data);
535 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
536 }
537
538 /**
539 * @tc.name: TestTurnOnWifiSuc
540 * @tc.desc: Test TurnOnWifi func.
541 * @tc.type: FUNC
542 */
543 HWTEST_F(WifiManagerProxyTest, TestTurnOnWifiSuc, TestSize.Level1)
544 {
545 MessageParcel data;
546 OHOS::AppExecFwk::ElementName admin;
547 admin.SetBundleName(ADMIN_PACKAGENAME);
548 data.WriteParcelable(&admin);
549 data.WriteBool(false);
550 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
551 .Times(1)
552 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy));
553
554 int32_t ret = wifiManagerProxy->TurnOnWifi(data);
555 ASSERT_TRUE(ret == ERR_OK);
556 }
557
558 /**
559 * @tc.name: TestTurnOnWifiFail
560 * @tc.desc: Test TurnOnWifi func without enable edm service.
561 * @tc.type: FUNC
562 */
563 HWTEST_F(WifiManagerProxyTest, TestTurnOnWifiFail, TestSize.Level1)
564 {
565 Utils::SetEdmServiceDisable();
566 MessageParcel data;
567 OHOS::AppExecFwk::ElementName admin;
568 admin.SetBundleName(ADMIN_PACKAGENAME);
569 data.WriteParcelable(&admin);
570 data.WriteBool(false);
571 int32_t ret = wifiManagerProxy->TurnOnWifi(data);
572 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
573 }
574
575 /**
576 * @tc.name: TestTurnOffWifiSuc
577 * @tc.desc: Test TurnOffWifi func.
578 * @tc.type: FUNC
579 */
580 HWTEST_F(WifiManagerProxyTest, TestTurnOffWifiSuc, TestSize.Level1)
581 {
582 MessageParcel data;
583 OHOS::AppExecFwk::ElementName admin;
584 admin.SetBundleName(ADMIN_PACKAGENAME);
585 data.WriteParcelable(&admin);
586 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
587 .Times(1)
588 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy));
589
590 int32_t ret = wifiManagerProxy->TurnOffWifi(data);
591 ASSERT_TRUE(ret == ERR_OK);
592 }
593
594 /**
595 * @tc.name: TestTurnOffWifiFail
596 * @tc.desc: Test TurnOffWifi func without enable edm service.
597 * @tc.type: FUNC
598 */
599 HWTEST_F(WifiManagerProxyTest, TestTurnOffWifiFail, TestSize.Level1)
600 {
601 Utils::SetEdmServiceDisable();
602 MessageParcel data;
603 OHOS::AppExecFwk::ElementName admin;
604 admin.SetBundleName(ADMIN_PACKAGENAME);
605 data.WriteParcelable(&admin);
606 int32_t ret = wifiManagerProxy->TurnOffWifi(data);
607 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
608 }
609
610 } // namespace TEST
611 } // namespace EDM
612 } // namespace OHOS
613