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 #include <vector>
20
21 #include "edm_sys_manager_mock.h"
22 #include "enterprise_device_mgr_stub_mock.h"
23 #include "bluetooth_manager_proxy.h"
24 #include "utils.h"
25
26 using namespace testing::ext;
27 using namespace testing;
28
29 namespace OHOS {
30 namespace EDM {
31 namespace TEST {
32 const std::string ADMIN_PACKAGENAME = "com.edm.test.demo";
33 class BluetoothManagerProxyTest : public testing::Test {
34 protected:
35 void SetUp() override;
36
37 void TearDown() override;
38
39 static void TearDownTestSuite(void);
40 std::shared_ptr<BluetoothManagerProxy> proxy_ = nullptr;
41 std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
42 sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
43 };
44
SetUp()45 void BluetoothManagerProxyTest::SetUp()
46 {
47 proxy_ = BluetoothManagerProxy::GetBluetoothManagerProxy();
48 edmSysManager_ = std::make_shared<EdmSysManager>();
49 object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
50 edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
51 Utils::SetEdmServiceEnable();
52 }
53
TearDown()54 void BluetoothManagerProxyTest::TearDown()
55 {
56 proxy_.reset();
57 edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
58 object_ = nullptr;
59 Utils::SetEdmServiceDisable();
60 }
61
TearDownTestSuite()62 void BluetoothManagerProxyTest::TearDownTestSuite()
63 {
64 ASSERT_FALSE(Utils::GetEdmServiceState());
65 std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
66 }
67
68 /**
69 * @tc.name: TestGetBluetoothInfoSuc
70 * @tc.desc: Test GetBluetoothInfo success func.
71 * @tc.type: FUNC
72 */
73 HWTEST_F(BluetoothManagerProxyTest, TestGetBluetoothInfoSuc, TestSize.Level1)
74 {
75 MessageParcel data;
76 OHOS::AppExecFwk::ElementName admin;
77 admin.SetBundleName(ADMIN_PACKAGENAME);
78 data.WriteParcelable(&admin);
79 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
80 .Times(1)
81 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBluetoothProxySendRequestGetPolicy));
82
83 BluetoothInfo bluetoothInfo;
84 int32_t ret = proxy_->GetBluetoothInfo(data, bluetoothInfo);
85 ASSERT_TRUE(ret == ERR_OK);
86 ASSERT_TRUE(bluetoothInfo.name == RETURN_STRING);
87 ASSERT_TRUE(bluetoothInfo.state == 1);
88 ASSERT_TRUE(bluetoothInfo.connectionState == 1);
89 }
90
91 /**
92 * @tc.name: TestGetBluetoothInfoFail
93 * @tc.desc: Test GetBluetoothInfo without enable edm service func.
94 * @tc.type: FUNC
95 */
96 HWTEST_F(BluetoothManagerProxyTest, TestGetBluetoothInfoFail, TestSize.Level1)
97 {
98 Utils::SetEdmServiceDisable();
99 MessageParcel data;
100 OHOS::AppExecFwk::ElementName admin;
101 admin.SetBundleName(ADMIN_PACKAGENAME);
102 data.WriteParcelable(&admin);
103
104 BluetoothInfo bluetoothInfo;
105 int32_t ret = proxy_->GetBluetoothInfo(data, bluetoothInfo);
106 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
107 }
108
109 /**
110 * @tc.name: TestSetBluetoothDisabledSuc
111 * @tc.desc: Test SetBluetoothDisabled func.
112 * @tc.type: FUNC
113 */
114 HWTEST_F(BluetoothManagerProxyTest, TestSetBluetoothDisabledSuc, TestSize.Level1)
115 {
116 MessageParcel data;
117 AppExecFwk::ElementName admin;
118 admin.SetBundleName(ADMIN_PACKAGENAME);
119 data.WriteParcelable(&admin);
120 data.WriteBool(true);
121 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
122 .Times(1)
123 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
124
125 int32_t ret = proxy_->SetBluetoothDisabled(data);
126 ASSERT_TRUE(ret == ERR_OK);
127 }
128
129 /**
130 * @tc.name: TestSetBluetoothDisabledFail
131 * @tc.desc: Test SetBluetoothDisabled func without enable edm service.
132 * @tc.type: FUNC
133 */
134 HWTEST_F(BluetoothManagerProxyTest, TestSetBluetoothDisabledFail, TestSize.Level1)
135 {
136 Utils::SetEdmServiceDisable();
137 MessageParcel data;
138 AppExecFwk::ElementName admin;
139 admin.SetBundleName(ADMIN_PACKAGENAME);
140 data.WriteParcelable(&admin);
141 data.WriteBool(true);
142
143 int32_t ret = proxy_->SetBluetoothDisabled(data);
144 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
145 }
146
147 /**
148 * @tc.name: TestIsBluetoothDisabledSuc
149 * @tc.desc: Test IsBluetoothDisabled func.
150 * @tc.type: FUNC
151 */
152 HWTEST_F(BluetoothManagerProxyTest, TestIsBluetoothDisabledSuc, TestSize.Level1)
153 {
154 MessageParcel data;
155 AppExecFwk::ElementName admin;
156 admin.SetBundleName(ADMIN_PACKAGENAME);
157 data.WriteParcelable(&admin);
158 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
159 .Times(1)
160 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
161
162 bool isDisable = false;
163 int32_t ret = proxy_->IsBluetoothDisabled(data, isDisable);
164 ASSERT_TRUE(ret == ERR_OK);
165 ASSERT_TRUE(isDisable);
166 }
167
168 /**
169 * @tc.name: TestIsBluetoothDisabledFail
170 * @tc.desc: Test IsBluetoothDisabled func without enable edm service.
171 * @tc.type: FUNC
172 */
173 HWTEST_F(BluetoothManagerProxyTest, TestIsBluetoothDisabledFail, TestSize.Level1)
174 {
175 Utils::SetEdmServiceDisable();
176 MessageParcel data;
177 AppExecFwk::ElementName admin;
178 admin.SetBundleName(ADMIN_PACKAGENAME);
179 data.WriteParcelable(&admin);
180
181 bool isDisable = false;
182 int32_t ret = proxy_->IsBluetoothDisabled(data, isDisable);
183 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
184 ASSERT_FALSE(isDisable);
185 }
186
187 /**
188 * @tc.name: TestAddAllowedBluetoothDevicesSuc
189 * @tc.desc: Test AddAllowedBluetoothDevices func.
190 * @tc.type: FUNC
191 */
192 HWTEST_F(BluetoothManagerProxyTest, TestAddAllowedBluetoothDevicesSuc, TestSize.Level1)
193 {
194 MessageParcel data;
195 OHOS::AppExecFwk::ElementName admin;
196 admin.SetBundleName(ADMIN_PACKAGENAME);
197 data.WriteParcelable(&admin);
198 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
199 .Times(1)
200 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
201 std::vector<std::string> deviceIds = { "00:1A:2B:3C:4D:5E", "AA:BB:CC:DD:EE:FF" };
202 data.WriteStringVector(deviceIds);
203 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::SET,
204 EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
205 ASSERT_TRUE(ret == ERR_OK);
206 }
207
208 /**
209 * @tc.name: TestAddDisallowedBluetoothDevicesSuc
210 * @tc.desc: Test AddDisallowedBluetoothDevices func.
211 * @tc.type: FUNC
212 */
213 HWTEST_F(BluetoothManagerProxyTest, TestAddDisallowedBluetoothDevicesSuc, TestSize.Level1)
214 {
215 MessageParcel data;
216 OHOS::AppExecFwk::ElementName admin;
217 admin.SetBundleName(ADMIN_PACKAGENAME);
218 data.WriteParcelable(&admin);
219 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
220 .Times(1)
221 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
222 std::vector<std::string> deviceIds = { "00:1A:2B:3C:4D:5E", "AA:BB:CC:DD:EE:FF" };
223 data.WriteStringVector(deviceIds);
224 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::SET,
225 EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
226 ASSERT_TRUE(ret == ERR_OK);
227 }
228
229 /**
230 * @tc.name: TestAddAllowedBluetoothDevicesFail
231 * @tc.desc: Test AddAllowedBluetoothDevices func.
232 * @tc.type: FUNC
233 */
234 HWTEST_F(BluetoothManagerProxyTest, TestAddAllowedBluetoothDevicesFail, TestSize.Level1)
235 {
236 Utils::SetEdmServiceDisable();
237 OHOS::AppExecFwk::ElementName admin;
238 admin.SetBundleName(ADMIN_PACKAGENAME);
239 std::vector<std::string> deviceIds;
240 MessageParcel data;
241 data.WriteParcelable(&admin);
242 data.WriteStringVector(deviceIds);
243 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::SET,
244 EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
245 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
246 }
247
248 /**
249 * @tc.name: TestAddDisallowedBluetoothDevicesFail
250 * @tc.desc: Test AddDisallowedBluetoothDevices func.
251 * @tc.type: FUNC
252 */
253 HWTEST_F(BluetoothManagerProxyTest, TestAddDisallowedBluetoothDevicesFail, TestSize.Level1)
254 {
255 Utils::SetEdmServiceDisable();
256 OHOS::AppExecFwk::ElementName admin;
257 admin.SetBundleName(ADMIN_PACKAGENAME);
258 std::vector<std::string> deviceIds;
259 MessageParcel data;
260 data.WriteParcelable(&admin);
261 data.WriteStringVector(deviceIds);
262 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::SET,
263 EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
264 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
265 }
266
267 /**
268 * @tc.name: TestGetAllowedBluetoothDevicesSuc
269 * @tc.desc: Test GetAllowedBluetoothDevices func.
270 * @tc.type: FUNC
271 */
272 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesSuc, TestSize.Level1)
273 {
274 OHOS::AppExecFwk::ElementName admin;
275 admin.SetBundleName(ADMIN_PACKAGENAME);
276 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
277 .Times(1)
278 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
279 std::vector<std::string> deviceIds;
280 int32_t ret = proxy_->GetAllowedBluetoothDevices(&admin, deviceIds);
281 ASSERT_TRUE(ret == ERR_OK);
282 ASSERT_TRUE(deviceIds.size() == 1);
283 ASSERT_EQ(deviceIds[0], RETURN_STRING);
284 }
285
286 /**
287 * @tc.name: TestGetAllowedBluetoothDevicesFail
288 * @tc.desc: Test GetAllowedBluetoothDevices without enable edm service func.
289 * @tc.type: FUNC
290 */
291 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesFail, TestSize.Level1)
292 {
293 Utils::SetEdmServiceDisable();
294 OHOS::AppExecFwk::ElementName admin;
295 admin.SetBundleName(ADMIN_PACKAGENAME);
296 std::vector<std::string> deviceIds;
297 int32_t ret = proxy_->GetAllowedBluetoothDevices(&admin, deviceIds);
298 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
299 }
300
301 /**
302 * @tc.name: TestGetAllowedBluetoothDevicesWithoutAdminSuc
303 * @tc.desc: Test GetAllowedBluetoothDevices func.
304 * @tc.type: FUNC
305 */
306 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesWithoutAdminSuc, TestSize.Level1)
307 {
308 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
309 .Times(1)
310 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
311 std::vector<std::string> deviceIds;
312 int32_t ret = proxy_->GetAllowedBluetoothDevices(nullptr, deviceIds);
313 ASSERT_TRUE(ret == ERR_OK);
314 ASSERT_TRUE(deviceIds.size() == 1);
315 ASSERT_EQ(deviceIds[0], RETURN_STRING);
316 }
317
318 /**
319 * @tc.name: TestGetAllowedBluetoothDevicesSuc
320 * @tc.desc: Test GetAllowedBluetoothDevices func.
321 * @tc.type: FUNC
322 */
323 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesSuc001, TestSize.Level1)
324 {
325 MessageParcel data;
326 OHOS::AppExecFwk::ElementName admin;
327 admin.SetBundleName(ADMIN_PACKAGENAME);
328 data.WriteParcelable(&admin);
329 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
330 .Times(1)
331 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
332
333 std::vector<std::string> deviceIds;
334 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
335 ASSERT_TRUE(ret == ERR_OK);
336 ASSERT_TRUE(deviceIds.size() == 1);
337 ASSERT_EQ(deviceIds[0], RETURN_STRING);
338 }
339
340 /**
341 * @tc.name: TestGetDisallowedBluetoothDevicesSuc
342 * @tc.desc: Test GetDisallowedBluetoothDevices func.
343 * @tc.type: FUNC
344 */
345 HWTEST_F(BluetoothManagerProxyTest, TestGetDisallowedBluetoothDevicesSuc001, TestSize.Level1)
346 {
347 MessageParcel data;
348 OHOS::AppExecFwk::ElementName admin;
349 admin.SetBundleName(ADMIN_PACKAGENAME);
350 data.WriteParcelable(&admin);
351 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
352 .Times(1)
353 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
354
355 std::vector<std::string> deviceIds;
356 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
357 ASSERT_TRUE(ret == ERR_OK);
358 ASSERT_TRUE(deviceIds.size() == 1);
359 ASSERT_EQ(deviceIds[0], RETURN_STRING);
360 }
361
362 /**
363 * @tc.name: TestGetAllowedBluetoothDevicesWithoutAdminSuc
364 * @tc.desc: Test GetAllowedBluetoothDevices func.
365 * @tc.type: FUNC
366 */
367 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesWithoutAdminSuc001, TestSize.Level1)
368 {
369 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
370 .Times(1)
371 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
372 std::vector<std::string> deviceIds;
373 MessageParcel data;
374 data.WriteParcelable(nullptr);
375 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
376 ASSERT_TRUE(ret == ERR_OK);
377 ASSERT_TRUE(deviceIds.size() == 1);
378 ASSERT_EQ(deviceIds[0], RETURN_STRING);
379 }
380
381 /**
382 * @tc.name: TestGetDisallowedBluetoothDevicesWithoutAdminSuc
383 * @tc.desc: Test GetDisallowedBluetoothDevices func.
384 * @tc.type: FUNC
385 */
386 HWTEST_F(BluetoothManagerProxyTest, TestGetDisallowedBluetoothDevicesWithoutAdminSuc001, TestSize.Level1)
387 {
388 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
389 .Times(1)
390 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
391 std::vector<std::string> deviceIds;
392 MessageParcel data;
393 data.WriteParcelable(nullptr);
394 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
395 ASSERT_TRUE(ret == ERR_OK);
396 ASSERT_TRUE(deviceIds.size() == 1);
397 ASSERT_EQ(deviceIds[0], RETURN_STRING);
398 }
399
400 /**
401 * @tc.name: TestGetAllowedBluetoothDevicesFail
402 * @tc.desc: Test GetAllowedBluetoothDevices without enable edm service func.
403 * @tc.type: FUNC
404 */
405 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesFail001, TestSize.Level1)
406 {
407 Utils::SetEdmServiceDisable();
408 MessageParcel data;
409 OHOS::AppExecFwk::ElementName admin;
410 admin.SetBundleName(ADMIN_PACKAGENAME);
411 data.WriteParcelable(&admin);
412
413 std::vector<std::string> deviceIds;
414 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
415 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
416 }
417
418 /**
419 * @tc.name: TestGetDisallowedBluetoothDevicesFail
420 * @tc.desc: Test GetDisallowedBluetoothDevices without enable edm service func.
421 * @tc.type: FUNC
422 */
423 HWTEST_F(BluetoothManagerProxyTest, TestGetDisallowedBluetoothDevicesFail001, TestSize.Level1)
424 {
425 Utils::SetEdmServiceDisable();
426 MessageParcel data;
427 OHOS::AppExecFwk::ElementName admin;
428 admin.SetBundleName(ADMIN_PACKAGENAME);
429 data.WriteParcelable(&admin);
430
431 std::vector<std::string> deviceIds;
432 int32_t ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
433 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
434 }
435
436 /**
437 * @tc.name: TestGetAllowedBluetoothDevicesFail
438 * @tc.desc: Test GetAllowedBluetoothDevicesFail func if does not have Admin parameter without enable edm service.
439 * @tc.type: FUNC
440 */
441 HWTEST_F(BluetoothManagerProxyTest, TestGetAllowedBluetoothDevicesFail002, TestSize.Level1)
442 {
443 Utils::SetEdmServiceDisable();
444 MessageParcel data;
445 const std::u16string descriptor = u"ohos.edm.testdemo";
446 data.WriteInterfaceToken(descriptor);
447 data.WriteInt32(WITHOUT_USERID);
448 data.WriteString(WITHOUT_PERMISSION_TAG);
449 data.WriteInt32(WITHOUT_ADMIN);
450 std::vector<std::string> deviceIds;
451 ErrCode ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
452 ASSERT_TRUE(ret == ERR_OK);
453 }
454
455 /**
456 * @tc.name: TestGetDisallowedBluetoothDevicesFail
457 * @tc.desc: Test GetDisallowedBluetoothDevicesFail func if does not have Admin parameter without enable edm service.
458 * @tc.type: FUNC
459 */
460 HWTEST_F(BluetoothManagerProxyTest, TestGetDisallowedBluetoothDevicesFail002, TestSize.Level1)
461 {
462 Utils::SetEdmServiceDisable();
463 MessageParcel data;
464 const std::u16string descriptor = u"ohos.edm.testdemo";
465 data.WriteInterfaceToken(descriptor);
466 data.WriteInt32(WITHOUT_USERID);
467 data.WriteString(WITHOUT_PERMISSION_TAG);
468 data.WriteInt32(WITHOUT_ADMIN);
469 std::vector<std::string> deviceIds;
470 ErrCode ret = proxy_->GetBluetoothDevices(data, deviceIds, EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
471 ASSERT_TRUE(ret == ERR_OK);
472 }
473
474 /**
475 * @tc.name: TestRemoveAllowedBluetoothDevicesSuc
476 * @tc.desc: Test RemoveAllowedBluetoothDevices func.
477 * @tc.type: FUNC
478 */
479 HWTEST_F(BluetoothManagerProxyTest, TestRemoveAllowedBluetoothDevicesSuc, TestSize.Level1)
480 {
481 MessageParcel data;
482 OHOS::AppExecFwk::ElementName admin;
483 admin.SetBundleName(ADMIN_PACKAGENAME);
484 data.WriteParcelable(&admin);
485 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
486 .Times(1)
487 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
488 std::vector<std::string> deviceIds = { "00:1A:2B:3C:4D:5E", "AA:BB:CC:DD:EE:FF" };
489 data.WriteStringVector(deviceIds);
490
491 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::REMOVE,
492 EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
493 ASSERT_TRUE(ret == ERR_OK);
494 }
495
496 /**
497 * @tc.name: TestRemoveDisallowedBluetoothDevicesSuc
498 * @tc.desc: Test RemoveDisallowedBluetoothDevices func.
499 * @tc.type: FUNC
500 */
501 HWTEST_F(BluetoothManagerProxyTest, TestRemoveDisallowedBluetoothDevicesSuc, TestSize.Level1)
502 {
503 MessageParcel data;
504 OHOS::AppExecFwk::ElementName admin;
505 admin.SetBundleName(ADMIN_PACKAGENAME);
506 data.WriteParcelable(&admin);
507 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
508 .Times(1)
509 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
510 std::vector<std::string> deviceIds = { "00:1A:2B:3C:4D:5E", "AA:BB:CC:DD:EE:FF" };
511 data.WriteStringVector(deviceIds);
512
513 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::REMOVE,
514 EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
515 ASSERT_TRUE(ret == ERR_OK);
516 }
517
518 /**
519 * @tc.name: TestRemoveAllowedBluetoothDevicesFail
520 * @tc.desc: Test RemoveAllowedBluetoothDevices without enable edm service func.
521 * @tc.type: FUNC
522 */
523 HWTEST_F(BluetoothManagerProxyTest, TestRemoveAllowedBluetoothDevicesFail, TestSize.Level1)
524 {
525 Utils::SetEdmServiceDisable();
526 MessageParcel data;
527 OHOS::AppExecFwk::ElementName admin;
528 admin.SetBundleName(ADMIN_PACKAGENAME);
529 data.WriteParcelable(&admin);
530 std::vector<std::string> deviceIds;
531 data.WriteStringVector(deviceIds);
532
533 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::REMOVE,
534 EdmInterfaceCode::ALLOWED_BLUETOOTH_DEVICES);
535 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
536 }
537
538 /**
539 * @tc.name: TestRemoveDisallowedBluetoothDevicesFail
540 * @tc.desc: Test RemoveDisallowedBluetoothDevices without enable edm service func.
541 * @tc.type: FUNC
542 */
543 HWTEST_F(BluetoothManagerProxyTest, TestRemoveDisallowedBluetoothDevicesFail, TestSize.Level1)
544 {
545 Utils::SetEdmServiceDisable();
546 MessageParcel data;
547 OHOS::AppExecFwk::ElementName admin;
548 admin.SetBundleName(ADMIN_PACKAGENAME);
549 data.WriteParcelable(&admin);
550 std::vector<std::string> deviceIds;
551 data.WriteStringVector(deviceIds);
552
553 int32_t ret = proxy_->AddOrRemoveBluetoothDevices(data, FuncOperateType::REMOVE,
554 EdmInterfaceCode::DISALLOWED_BLUETOOTH_DEVICES);
555 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
556 }
557
558 /**
559 * @tc.name: TestTurnOnBluetoothSuc
560 * @tc.desc: Test TurnOnBluetoothSuc func.
561 * @tc.type: FUNC
562 */
563 HWTEST_F(BluetoothManagerProxyTest, TestTurnOnBluetoothSuc, TestSize.Level1)
564 {
565 MessageParcel data;
566 AppExecFwk::ElementName admin;
567 admin.SetBundleName(ADMIN_PACKAGENAME);
568 data.WriteParcelable(&admin);
569 data.WriteBool(true);
570 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
571 .Times(1)
572 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
573
574 int32_t ret = proxy_->TurnOnOrOffBluetooth(data);
575 ASSERT_TRUE(ret == ERR_OK);
576 }
577
578 /**
579 * @tc.name: TestTurnOnBluetoothFail
580 * @tc.desc: Test TurnOnBluetoothFail func without enable edm service.
581 * @tc.type: FUNC
582 */
583 HWTEST_F(BluetoothManagerProxyTest, TestTurnOnBluetoothFail, TestSize.Level1)
584 {
585 Utils::SetEdmServiceDisable();
586 MessageParcel data;
587 AppExecFwk::ElementName admin;
588 admin.SetBundleName(ADMIN_PACKAGENAME);
589 data.WriteParcelable(&admin);
590 data.WriteBool(true);
591
592 int32_t ret = proxy_->TurnOnOrOffBluetooth(data);
593 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
594 }
595
596 /**
597 * @tc.name: TestTurnOffBluetoothSuc
598 * @tc.desc: Test TurnOffBluetoothSuc func.
599 * @tc.type: FUNC
600 */
601 HWTEST_F(BluetoothManagerProxyTest, TestTurnOffBluetoothSuc, TestSize.Level1)
602 {
603 MessageParcel data;
604 AppExecFwk::ElementName admin;
605 admin.SetBundleName(ADMIN_PACKAGENAME);
606 data.WriteParcelable(&admin);
607 data.WriteBool(false);
608 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
609 .Times(1)
610 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
611
612 int32_t ret = proxy_->TurnOnOrOffBluetooth(data);
613 ASSERT_TRUE(ret == ERR_OK);
614 }
615
616 /**
617 * @tc.name: TestTurnOffBluetoothFail
618 * @tc.desc: Test TurnOffBluetoothFail func without enable edm service.
619 * @tc.type: FUNC
620 */
621 HWTEST_F(BluetoothManagerProxyTest, TestTurnOffBluetoothFail, TestSize.Level1)
622 {
623 Utils::SetEdmServiceDisable();
624 MessageParcel data;
625 AppExecFwk::ElementName admin;
626 admin.SetBundleName(ADMIN_PACKAGENAME);
627 data.WriteParcelable(&admin);
628 data.WriteBool(false);
629
630 int32_t ret = proxy_->TurnOnOrOffBluetooth(data);
631 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
632 }
633
634 /**
635 * @tc.name: TestAddOrRemoveDisallowedBluetoothProtocolsFail
636 * @tc.desc: Test AddOrRemoveDisallowedBluetoothProtocols without enable edm service func.
637 * @tc.type: FUNC
638 */
639 HWTEST_F(BluetoothManagerProxyTest, TestAddOrRemoveDisallowedBluetoothProtocolsFail, TestSize.Level1)
640 {
641 Utils::SetEdmServiceDisable();
642 MessageParcel data;
643 OHOS::AppExecFwk::ElementName admin;
644 std::vector<int32_t> protocols;
645 data.WriteParcelable(&admin);
646 data.WriteInt32Vector(protocols);
647
648 ErrCode ret = proxy_->AddOrRemoveDisallowedBluetoothProtocols(data, true);
649 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
650 }
651
652 /**
653 * @tc.name: TestAddOrRemoveDisallowedBluetoothProtocolsSuc
654 * @tc.desc: Test AddOrRemoveDisallowedBluetoothProtocols success func.
655 * @tc.type: FUNC
656 */
657 HWTEST_F(BluetoothManagerProxyTest, TestAddOrRemoveDisallowedBluetoothProtocolsSuc, TestSize.Level1)
658 {
659 MessageParcel data;
660 OHOS::AppExecFwk::ElementName admin;
661 std::vector<int32_t> protocols;
662 data.WriteParcelable(&admin);
663 data.WriteInt32Vector(protocols);
664
665 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
666 .Times(1)
667 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
668 ErrCode ret = proxy_->AddOrRemoveDisallowedBluetoothProtocols(data, true);
669 ASSERT_TRUE(ret == ERR_OK);
670 }
671
672 } // namespace TEST
673 } // namespace EDM
674 } // namespace OHOS
675