1 /*
2 * Copyright (c) 2022-2024 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
18 #include <string>
19 #include <vector>
20
21 #include "edm_sys_manager_mock.h"
22 #include "enterprise_device_mgr_proxy.h"
23 #include "enterprise_device_mgr_stub_mock.h"
24 #include "func_code.h"
25 #include "system_ability_definition.h"
26 #include "utils.h"
27
28 using namespace testing::ext;
29 using ::testing::_;
30 using ::testing::Invoke;
31 using ::testing::Mock;
32 using namespace testing;
33
34 namespace OHOS {
35 namespace EDM {
36 namespace TEST {
37 namespace {
38 constexpr int32_t DEFAULT_USERID = 100;
39 constexpr int32_t FUNC_CODE_ERR = -222;
40 }
41 class EnterpriseDeviceMgrProxyTest : public testing::Test {
42 protected:
43 void SetUp() override;
44
45 void TearDown() override;
46
47 static void TearDownTestSuite(void);
48 std::shared_ptr<EnterpriseDeviceMgrProxy> enterpriseDeviceMgrProxyTest = nullptr;
49 std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
50 sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
51 };
52
SetUp()53 void EnterpriseDeviceMgrProxyTest::SetUp()
54 {
55 enterpriseDeviceMgrProxyTest = EnterpriseDeviceMgrProxy::GetInstance();
56 edmSysManager_ = std::make_shared<EdmSysManager>();
57 object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
58 edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
59 Utils::SetEdmServiceEnable();
60 }
61
TearDown()62 void EnterpriseDeviceMgrProxyTest::TearDown()
63 {
64 EnterpriseDeviceMgrProxy::DestroyInstance();
65 edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
66 object_ = nullptr;
67 Utils::SetEdmServiceDisable();
68 }
69
TearDownTestSuite()70 void EnterpriseDeviceMgrProxyTest::TearDownTestSuite()
71 {
72 ASSERT_FALSE(Utils::GetEdmServiceState());
73 std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
74 }
75
76 /**
77 * @tc.name: TestEnableAdminSuc
78 * @tc.desc: Test EnableAdmin func.
79 * @tc.type: FUNC
80 */
81 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestEnableAdminSuc, TestSize.Level1)
82 {
83 AppExecFwk::ElementName admin;
84 admin.SetBundleName("com.edm.test.demo");
85 admin.SetAbilityName("com.edm.test.demo.Ability");
86 EntInfo entInfo("test", "this is test");
87 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
88 .Times(1)
89 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
90 ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::NORMAL, DEFAULT_USERID);
91 EXPECT_TRUE(errVal == ERR_OK);
92 }
93
94 /**
95 * @tc.name: TestEnableAdminFail
96 * @tc.desc: Test EnableAdmin func.
97 * @tc.type: FUNC
98 */
99 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestEnableAdminFail, TestSize.Level1)
100 {
101 AppExecFwk::ElementName admin;
102 admin.SetBundleName("com.edm.test.demo");
103 admin.SetAbilityName("com.edm.test.demo.Ability");
104 EntInfo entInfo("test", "this is test");
105 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
106 .Times(1)
107 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
108 ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::NORMAL, DEFAULT_USERID);
109 EXPECT_TRUE(errVal != ERR_OK);
110 }
111
112 /**
113 * @tc.name: TestSetEnterpriseInfoSuc
114 * @tc.desc: Test SetEnterpriseInfo func.
115 * @tc.type: FUNC
116 */
117 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetEnterpriseInfoSuc, TestSize.Level1)
118 {
119 AppExecFwk::ElementName admin;
120 admin.SetBundleName("com.edm.test.demo");
121 admin.SetAbilityName("com.edm.test.demo.Ability");
122 EntInfo entInfo("test", "this is test");
123 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
124 .Times(1)
125 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
126 ErrCode errVal = enterpriseDeviceMgrProxyTest->SetEnterpriseInfo(admin, entInfo);
127 EXPECT_TRUE(errVal == ERR_OK);
128 }
129
130 /**
131 * @tc.name: TestSetEnterpriseInfoFail
132 * @tc.desc: Test SetEnterpriseInfo func.
133 * @tc.type: FUNC
134 */
135 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetEnterpriseInfoFail, TestSize.Level1)
136 {
137 AppExecFwk::ElementName admin;
138 admin.SetBundleName("com.edm.test.demo");
139 admin.SetAbilityName("com.edm.test.demo.Ability");
140 EntInfo entInfo("test", "this is test");
141 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
142 .Times(1)
143 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
144 ErrCode errVal = enterpriseDeviceMgrProxyTest->SetEnterpriseInfo(admin, entInfo);
145 EXPECT_TRUE(errVal != ERR_OK);
146 }
147
148 /**
149 * @tc.name: TestGetEnterpriseInfoEntInfo
150 * @tc.desc: Test GetEnterpriseInfo func.
151 * @tc.type: FUNC
152 */
153 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnterpriseInfoEntInfo, TestSize.Level1)
154 {
155 AppExecFwk::ElementName admin;
156 admin.SetBundleName("com.edm.test.demo");
157 admin.SetAbilityName("com.edm.test.demo.Ability");
158 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
159 .Times(1)
160 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetEnterpriseInfo));
161 EntInfo entInfo1;
162 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetEnterpriseInfo(admin, entInfo1);
163 EXPECT_TRUE(errVal == ERR_OK);
164 }
165
166 /**
167 * @tc.name: TestGetEnterpriseInfoFail
168 * @tc.desc: Test GetEnterpriseInfo func.
169 * @tc.type: FUNC
170 */
171 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnterpriseInfoFail, TestSize.Level1)
172 {
173 AppExecFwk::ElementName admin;
174 admin.SetBundleName("com.edm.test.demo");
175 admin.SetAbilityName("com.edm.test.demo.Ability");
176 EntInfo entInfo1;
177 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
178 .Times(1)
179 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
180 enterpriseDeviceMgrProxyTest->GetEnterpriseInfo(admin, entInfo1);
181 EXPECT_TRUE(entInfo1.enterpriseName.size() == 0);
182 EXPECT_TRUE(entInfo1.description.size() == 0);
183 }
184
185 /**
186 * @tc.name: TestIsAdminEnabledFail
187 * @tc.desc: Test IsAdminEnabled func.
188 * @tc.type: FUNC
189 */
190 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsAdminEnabledFail, TestSize.Level1)
191 {
192 AppExecFwk::ElementName admin;
193 admin.SetBundleName("com.edm.test.demo");
194 admin.SetAbilityName("com.edm.test.demo.Ability");
195 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
196 .Times(1)
197 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
198 bool ret = false;
199 enterpriseDeviceMgrProxyTest->IsAdminEnabled(admin, DEFAULT_USERID, ret);
200 EXPECT_FALSE(ret);
201 }
202
203 /**
204 * @tc.name: TestGetEnabledAdminReplyFail
205 * @tc.desc: Test GetEnabledAdmin func.
206 * @tc.type: FUNC
207 */
208 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledAdminReplyFail, TestSize.Level1)
209 {
210 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
211 .Times(1)
212 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail));
213 std::vector<std::string> enabledAdminList1;
214 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1);
215 EXPECT_TRUE(errVal != ERR_OK);
216 }
217
218 /**
219 * @tc.name: TestGetEnabledAdminFail
220 * @tc.desc: Test GetEnabledAdmin func.
221 * @tc.type: FUNC
222 */
223 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledAdminFail, TestSize.Level1)
224 {
225 std::vector<std::string> enabledAdminList1;
226 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
227 .Times(1)
228 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
229 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1);
230 EXPECT_TRUE(errVal != ERR_OK);
231 }
232
233 /**
234 * @tc.name: TestIsPolicyDisabledSuc
235 * @tc.desc: Test IsPolicyDisabled func.
236 * @tc.type: FUNC
237 */
238 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledSuc, TestSize.Level1)
239 {
240 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
241 .Times(1)
242 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
243 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
244 bool isDisabled = false;
245 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, funcCode, isDisabled);
246 EXPECT_TRUE(!isDisabled);
247 }
248
249 /**
250 * @tc.name: TestIsPolicyDisabledFail
251 * @tc.desc: Test IsPolicyDisabled func.
252 * @tc.type: FUNC
253 */
254 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledFail, TestSize.Level1)
255 {
256 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
257 bool isDisabled = false;
258 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
259 .Times(1)
260 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
261 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, funcCode, isDisabled);
262 EXPECT_TRUE(!isDisabled);
263 }
264
265 /**
266 * @tc.name: TestIsPolicyDisabledFuncCodeFail
267 * @tc.desc: Test IsPolicyDisabled func.
268 * @tc.type: FUNC
269 */
270 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledFuncCodeFail, TestSize.Level1)
271 {
272 bool isDisabled = false;
273 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, FUNC_CODE_ERR, isDisabled);
274 EXPECT_TRUE(!isDisabled);
275 }
276
277 /**
278 * @tc.name: TestIsPolicyDisabledWithTagSuc
279 * @tc.desc: Test IsPolicyDisabled func.
280 * @tc.type: FUNC
281 */
282 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledWithTagSuc, TestSize.Level1)
283 {
284 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
285 .Times(1)
286 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
287 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
288 bool isDisabled = false;
289 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, funcCode, isDisabled, "version_11");
290 EXPECT_TRUE(!isDisabled);
291 }
292
293 /**
294 * @tc.name: TestIsPolicyDisabledWithTagFail
295 * @tc.desc: Test IsPolicyDisabled func.
296 * @tc.type: FUNC
297 */
298 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledWithTagFail, TestSize.Level1)
299 {
300 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
301 bool isDisabled = false;
302 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
303 .Times(1)
304 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
305 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, funcCode, isDisabled, "version_11");
306 EXPECT_TRUE(!isDisabled);
307 }
308
309 /**
310 * @tc.name: TestIsPolicyDisabledWithTagFuncCodeFail
311 * @tc.desc: Test IsPolicyDisabled func.
312 * @tc.type: FUNC
313 */
314 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsPolicyDisabledWithTagFuncCodeFail, TestSize.Level1)
315 {
316 bool isDisabled = false;
317 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, FUNC_CODE_ERR, isDisabled, "version_11");
318 EXPECT_TRUE(!isDisabled);
319 }
320
321 /**
322 * @tc.name: TestSetPolicyDisabledSuc
323 * @tc.desc: Test SetPolicyDisabled func.
324 * @tc.type: FUNC
325 */
326 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledSuc, TestSize.Level1)
327 {
328 AppExecFwk::ElementName admin;
329 admin.SetBundleName("com.edm.test.demo");
330 admin.SetAbilityName("com.edm.test.demo.Ability");
331 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
332 .Times(1)
333 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
334 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLED_PRINTER);
335 bool isDisabled = true;
336 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, funcCode, isDisabled);
337 EXPECT_TRUE(ret == ERR_OK);
338 }
339
340 /**
341 * @tc.name: TestSetPolicyDisabledFail
342 * @tc.desc: Test SetPolicyDisabled func.
343 * @tc.type: FUNC
344 */
345 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledFail, TestSize.Level1)
346 {
347 AppExecFwk::ElementName admin;
348 admin.SetBundleName("com.edm.test.demo");
349 admin.SetAbilityName("com.edm.test.demo.Ability");
350 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLED_PRINTER);
351 bool isDisabled = true;
352 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
353 .Times(1)
354 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
355 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, funcCode, isDisabled);
356 EXPECT_TRUE(ret != ERR_OK);
357 }
358
359 /**
360 * @tc.name: TestSetPolicyDisabledFuncCodeFail
361 * @tc.desc: Test SetPolicyDisabled func.
362 * @tc.type: FUNC
363 */
364 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledFuncCodeFail, TestSize.Level1)
365 {
366 AppExecFwk::ElementName admin;
367 admin.SetBundleName("com.edm.test.demo");
368 admin.SetAbilityName("com.edm.test.demo.Ability");
369 bool isDisabled = true;
370 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, FUNC_CODE_ERR, isDisabled);
371 EXPECT_TRUE(ret != ERR_OK);
372 }
373
374 /**
375 * @tc.name: TestSetPolicyDisabledWithTagSuc
376 * @tc.desc: Test SetPolicyDisabled func.
377 * @tc.type: FUNC
378 */
379 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledWithTagSuc, TestSize.Level1)
380 {
381 AppExecFwk::ElementName admin;
382 admin.SetBundleName("com.edm.test.demo");
383 admin.SetAbilityName("com.edm.test.demo.Ability");
384 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
385 .Times(1)
386 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
387 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLED_PRINTER);
388 bool isDisabled = true;
389 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, funcCode, isDisabled, "version_11");
390 EXPECT_TRUE(ret == ERR_OK);
391 }
392
393 /**
394 * @tc.name: TestSetPolicyDisabledWithTagFail
395 * @tc.desc: Test SetPolicyDisabled func.
396 * @tc.type: FUNC
397 */
398 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledWithTagFail, TestSize.Level1)
399 {
400 AppExecFwk::ElementName admin;
401 admin.SetBundleName("com.edm.test.demo");
402 admin.SetAbilityName("com.edm.test.demo.Ability");
403 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLED_PRINTER);
404 bool isDisabled = true;
405 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
406 .Times(1)
407 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
408 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, funcCode, isDisabled, "version_11");
409 EXPECT_TRUE(ret != ERR_OK);
410 }
411
412 /**
413 * @tc.name: TestSetPolicyDisabledWithTagFuncCodeFail
414 * @tc.desc: Test SetPolicyDisabled func.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetPolicyDisabledWithTagFuncCodeFail, TestSize.Level1)
418 {
419 AppExecFwk::ElementName admin;
420 admin.SetBundleName("com.edm.test.demo");
421 admin.SetAbilityName("com.edm.test.demo.Ability");
422 bool isDisabled = true;
423 int32_t ret = enterpriseDeviceMgrProxyTest->SetPolicyDisabled(admin, FUNC_CODE_ERR, isDisabled, "version_11");
424 EXPECT_TRUE(ret != ERR_OK);
425 }
426
427 /**
428 * @tc.name: TestGetPolicyValueSuc
429 * @tc.desc: Test GetPolicyValue func.
430 * @tc.type: FUNC
431 */
432 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyValueSuc, TestSize.Level1)
433 {
434 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
435 .Times(1)
436 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
437 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
438 std::string policyData;
439 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyValue(nullptr, funcCode, policyData);
440 EXPECT_TRUE(ret);
441 }
442
443 /**
444 * @tc.name: TestGetPolicyValueReplyFail
445 * @tc.desc: Test GetPolicyValue func.
446 * @tc.type: FUNC
447 */
448 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyValueReplyFail, TestSize.Level1)
449 {
450 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
451 std::string policyData;
452 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
453 .Times(1)
454 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail));
455 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyValue(nullptr, funcCode, policyData);
456 EXPECT_TRUE(!ret);
457 }
458
459 /**
460 * @tc.name: TestHandleDevicePolicyFuncCodeFail
461 * @tc.desc: Test HandleDevicePolicy func.
462 * @tc.type: FUNC
463 */
464 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestHandleDevicePolicyFuncCodeFail, TestSize.Level1)
465 {
466 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
467 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
468 .Times(1)
469 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
470 MessageParcel data;
471 ErrCode errVal = enterpriseDeviceMgrProxyTest->HandleDevicePolicy(funcCode, data);
472 EXPECT_TRUE(errVal != ERR_OK);
473 }
474
475 /**
476 * @tc.name: TestDisableAdminSuc
477 * @tc.desc: Test DisableAdmin func.
478 * @tc.type: FUNC
479 */
480 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableAdminSuc, TestSize.Level1)
481 {
482 AppExecFwk::ElementName admin;
483 admin.SetBundleName("com.edm.test.demo");
484 admin.SetAbilityName("com.edm.test.demo.Ability");
485 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
486 .Times(1)
487 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
488 ErrCode errVal = enterpriseDeviceMgrProxyTest->DisableAdmin(admin, DEFAULT_USERID);
489 EXPECT_TRUE(errVal == ERR_OK);
490 }
491
492 /**
493 * @tc.name: TestDisableAdminFail
494 * @tc.desc: Test DisableAdmin func.
495 * @tc.type: FUNC
496 */
497 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableAdminFail, TestSize.Level1)
498 {
499 AppExecFwk::ElementName admin;
500 admin.SetBundleName("com.edm.test.demo");
501 admin.SetAbilityName("com.edm.test.demo.Ability");
502 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
503 .Times(1)
504 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
505 ErrCode errVal = enterpriseDeviceMgrProxyTest->DisableAdmin(admin, DEFAULT_USERID);
506 EXPECT_TRUE(errVal != ERR_OK);
507 }
508
509 /**
510 * @tc.name: TestGetPolicyArrayEnableAdmin
511 * @tc.desc: Test GetPolicyArray func.
512 * @tc.type: FUNC
513 */
514 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyArrayEnableAdmin, TestSize.Level1)
515 {
516 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
517 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
518 .Times(1)
519 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin));
520 std::vector<std::string> policyArrayData;
521 enterpriseDeviceMgrProxyTest->GetPolicyArray(nullptr, funcCode, policyArrayData);
522 EXPECT_TRUE(policyArrayData.size() == 1);
523 }
524
525 /**
526 * @tc.name: TestGetPolicyArrayFail
527 * @tc.desc: Test GetPolicyArray func.
528 * @tc.type: FUNC
529 */
530 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyArrayFail, TestSize.Level1)
531 {
532 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
533 std::vector<std::string> policyArrayData;
534 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
535 .Times(1)
536 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
537 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyArray(nullptr, funcCode, policyArrayData);
538 EXPECT_TRUE(!ret);
539 }
540
541 /**
542 * @tc.name: TestGetPolicyArraySuc
543 * @tc.desc: Test GetPolicyArray func.
544 * @tc.type: FUNC
545 */
546 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyArraySuc, TestSize.Level1)
547 {
548 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
549 std::vector<std::string> policyArrayData;
550 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
551 .Times(1)
552 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
553 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyArray(nullptr, funcCode, policyArrayData);
554 EXPECT_TRUE(ret);
555 }
556
557 /**
558 * @tc.name: TestGetPolicyMapSuc
559 * @tc.desc: Test GetPolicyMap func.
560 * @tc.type: FUNC
561 */
562 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyMapSuc, TestSize.Level1)
563 {
564 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
565 std::map<std::string, std::string> policyMapData;
566 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
567 .Times(1)
568 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
569 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyMap(nullptr, funcCode, policyMapData);
570 EXPECT_TRUE(ret);
571 }
572
573 /**
574 * @tc.name: TestGetPolicyMapReplyFail
575 * @tc.desc: Test GetPolicyMap func.
576 * @tc.type: FUNC
577 */
578 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyMapReplyFail, TestSize.Level1)
579 {
580 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
581 std::map<std::string, std::string> policyMapData;
582 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
583 .Times(1)
584 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail));
585 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyMap(nullptr, funcCode, policyMapData);
586 EXPECT_FALSE(ret);
587 }
588
589 /**
590 * @tc.name: TestGetPolicyMapEnableAdminNotEqual
591 * @tc.desc: Test GetPolicyMap func.
592 * @tc.type: FUNC
593 */
594 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyMapEnableAdminNotEqual, TestSize.Level1)
595 {
596 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
597 std::map<std::string, std::string> policyMapData;
598 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
599 .Times(1)
600 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin));
601 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyMap(nullptr, funcCode, policyMapData);
602 EXPECT_FALSE(ret);
603 }
604
605 /**
606 * @tc.name: TestGetPolicyMapEnableAdminSizeEqual
607 * @tc.desc: Test GetPolicyMap func.
608 * @tc.type: FUNC
609 */
610 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetPolicyMapEnableAdminSizeEqual, TestSize.Level1)
611 {
612 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
613 std::map<std::string, std::string> policyMapData;
614 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
615 .Times(1)
616 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestMapEnableAdminTwoSuc));
617 bool ret = enterpriseDeviceMgrProxyTest->GetPolicyMap(nullptr, funcCode, policyMapData);
618 EXPECT_TRUE(ret);
619 }
620
621 /**
622 * @tc.name: TestIsSuperAdminReturnFail
623 * @tc.desc: Test IsSuperAdmin func.
624 * @tc.type: FUNC
625 */
626 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestIsSuperAdminReturnFail, TestSize.Level1)
627 {
628 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
629 .Times(1)
630 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
631 bool ret = false;
632 enterpriseDeviceMgrProxyTest->IsSuperAdmin("com.edm.test.demo", ret);
633 EXPECT_FALSE(ret);
634 }
635
636 /**
637 * @tc.name: TestGetEnabledSuperAdminReturnFail
638 * @tc.desc: Test GetEnabledSuperAdmin func.
639 * @tc.type: FUNC
640 */
641 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledSuperAdminReturnFail, TestSize.Level1)
642 {
643 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
644 .Times(1)
645 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
646 std::string enabledAdmin;
647 enterpriseDeviceMgrProxyTest->GetEnabledSuperAdmin(enabledAdmin);
648 EXPECT_TRUE(enabledAdmin.size() == 0);
649 }
650
651 /**
652 * @tc.name: TestGetEnabledSuperAdminReturnReplyFail
653 * @tc.desc: Test GetEnabledSuperAdmin func.
654 * @tc.type: FUNC
655 */
656 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledSuperAdminReturnReplyFail, TestSize.Level1)
657 {
658 std::string enabledAdmin;
659 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
660 .Times(1)
661 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail));
662 enterpriseDeviceMgrProxyTest->GetEnabledSuperAdmin(enabledAdmin);
663 EXPECT_TRUE(enabledAdmin.size() == 0);
664 }
665
666 /**
667 * @tc.name: TestGetEnabledSuperAdminReturnEnableAdmin
668 * @tc.desc: Test GetEnabledSuperAdmin func.
669 * @tc.type: FUNC
670 */
671 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledSuperAdminReturnEnableAdmin, TestSize.Level1)
672 {
673 std::string enabledAdmin;
674 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
675 .Times(1)
676 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin));
677 enterpriseDeviceMgrProxyTest->GetEnabledSuperAdmin(enabledAdmin);
678 GTEST_LOG_(INFO) << "mock enabledAdmin enabledAdmin item :" << enabledAdmin;
679 EXPECT_TRUE(enabledAdmin.size() > 0);
680 }
681
682 /**
683 * @tc.name: TestDisableSuperAdminReturnSuc
684 * @tc.desc: Test DisableSuperAdmin func.
685 * @tc.type: FUNC
686 */
687 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableSuperAdminReturnSuc, TestSize.Level1)
688 {
689 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
690 .Times(1)
691 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
692 ErrCode errVal = enterpriseDeviceMgrProxyTest->DisableSuperAdmin("com.edm.test.demo");
693 EXPECT_TRUE(errVal == ERR_OK);
694 }
695
696 /**
697 * @tc.name: TestDisableSuperAdminReturnFail
698 * @tc.desc: Test DisableSuperAdmin func.
699 * @tc.type: FUNC
700 */
701 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableSuperAdminReturnFail, TestSize.Level1)
702 {
703 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
704 .Times(1)
705 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
706 ErrCode errVal = enterpriseDeviceMgrProxyTest->DisableSuperAdmin("com.edm.test.demo");
707 EXPECT_TRUE(errVal != ERR_OK);
708 }
709
710 /**
711 * @tc.name: TestHandleManagedEventReturnFail
712 * @tc.desc: Test HandleManagedEvent func.
713 * @tc.type: FUNC
714 */
715 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestHandleManagedEventReturnFail, TestSize.Level1)
716 {
717 AppExecFwk::ElementName admin;
718 admin.SetBundleName("com.edm.test.demo");
719 admin.SetAbilityName("com.edm.test.demo.Ability");
720 const std::vector<uint32_t> events;
721 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
722 .Times(1)
723 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
724 ErrCode errVal = enterpriseDeviceMgrProxyTest->HandleManagedEvent(admin, events, false);
725 EXPECT_TRUE(errVal != ERR_OK);
726 }
727
728 /**
729 * @tc.name: TestHandleManagedEventSuc
730 * @tc.desc: Test HandleManagedEvent func.
731 * @tc.type: FUNC
732 */
733 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestHandleManagedEventSuc, TestSize.Level1)
734 {
735 AppExecFwk::ElementName admin;
736 admin.SetBundleName("com.edm.test.demo");
737 admin.SetAbilityName("com.edm.test.demo.Ability");
738 const std::vector<uint32_t> events;
739 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
740 .Times(1)
741 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
742 ErrCode errVal = enterpriseDeviceMgrProxyTest->HandleManagedEvent(admin, events, true);
743 EXPECT_TRUE(errVal == ERR_OK);
744 }
745
746 /**
747 * @tc.name: TestAuthorizeAdminEdmDisable
748 * @tc.desc: Test AuthorizeAdmin without enable edm service func.
749 * @tc.type: FUNC
750 */
751 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestAuthorizeAdminEdmDisable, TestSize.Level1)
752 {
753 Utils::SetEdmServiceDisable();
754 OHOS::AppExecFwk::ElementName admin;
755 ErrCode ret = enterpriseDeviceMgrProxyTest->AuthorizeAdmin(admin, "com.edm.test.demo");
756 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
757 }
758
759 /**
760 * @tc.name: TestAuthorizeAdminIpcFail
761 * @tc.desc: Test AuthorizeAdmin func with ipc failed.
762 * @tc.type: FUNC
763 */
764 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestAuthorizeAdminIpcFail, TestSize.Level1)
765 {
766 OHOS::AppExecFwk::ElementName admin;
767 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
768 .Times(1)
769 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
770 ErrCode errVal = enterpriseDeviceMgrProxyTest->AuthorizeAdmin(admin, "com.edm.test.demo");
771 EXPECT_TRUE(errVal == EdmReturnErrCode::SYSTEM_ABNORMALLY);
772 }
773
774 /**
775 * @tc.name: TestAuthorizeAdminReplyFail
776 * @tc.desc: Test AuthorizeAdmin func with reply failed.
777 * @tc.type: FUNC
778 */
779 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestAuthorizeAdminReplyFail, TestSize.Level1)
780 {
781 OHOS::AppExecFwk::ElementName admin;
782 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
783 .Times(1)
784 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail));
785 ErrCode errVal = enterpriseDeviceMgrProxyTest->AuthorizeAdmin(admin, "com.edm.test.demo");
786 EXPECT_TRUE(errVal == ERR_PROXY_SENDREQUEST_FAIL);
787 }
788
789 /**
790 * @tc.name: TestAuthorizeAdminSuccess
791 * @tc.desc: Test AuthorizeAdmin func success.
792 * @tc.type: FUNC
793 */
794 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestAuthorizeAdminSuccess, TestSize.Level1)
795 {
796 OHOS::AppExecFwk::ElementName admin;
797 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
798 .Times(1)
799 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
800 ErrCode errVal = enterpriseDeviceMgrProxyTest->AuthorizeAdmin(admin, "com.edm.test.demo");
801 EXPECT_TRUE(errVal == ERR_OK);
802 }
803
804 /**
805 * @tc.name: TestDisableAdmin
806 * @tc.desc: Test DisableAdmin func.
807 * @tc.type: FUNC
808 */
809 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableAdmin, TestSize.Level1)
810 {
811 AppExecFwk::ElementName admin;
812 admin.SetBundleName("com.edm.test.demo");
813 admin.SetAbilityName("com.edm.test.demo.Ability");
814
815 EntInfo entInfo("test", "this is test");
816
817 ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::NORMAL, DEFAULT_USERID);
818 EXPECT_TRUE(errVal != ERR_OK);
819
820 errVal = enterpriseDeviceMgrProxyTest->SetEnterpriseInfo(admin, entInfo);
821 EXPECT_TRUE(errVal != ERR_OK);
822
823 EntInfo entInfo1;
824 enterpriseDeviceMgrProxyTest->GetEnterpriseInfo(admin, entInfo1);
825 EXPECT_TRUE(entInfo1.enterpriseName.size() == 0);
826 EXPECT_TRUE(entInfo1.description.size() == 0);
827
828 bool ret = false;
829 enterpriseDeviceMgrProxyTest->IsAdminEnabled(admin, DEFAULT_USERID, ret);
830 EXPECT_FALSE(ret);
831
832
833 std::vector<std::string> enabledAdminList;
834 enterpriseDeviceMgrProxyTest->GetEnabledAdmins(enabledAdminList);
835 EXPECT_TRUE(enabledAdminList.empty());
836
837 std::vector<std::string> enabledAdminList1;
838 enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1);
839 EXPECT_TRUE(enabledAdminList1.empty());
840
841 int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
842 bool isDisabled;
843 enterpriseDeviceMgrProxyTest->IsPolicyDisabled(nullptr, funcCode, isDisabled);
844 EXPECT_FALSE(isDisabled);
845
846
847 errVal = enterpriseDeviceMgrProxyTest->DisableAdmin(admin, DEFAULT_USERID);
848 EXPECT_TRUE(errVal != ERR_OK);
849 }
850
851 /**
852 * @tc.name: TestDisableSuperAdmin
853 * @tc.desc: Test DisableSuperAdmin func.
854 * @tc.type: FUNC
855 */
856 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableSuperAdmin, TestSize.Level1)
857 {
858 AppExecFwk::ElementName admin;
859 admin.SetBundleName("com.edm.test.demo");
860 admin.SetAbilityName("com.edm.test.demo.Ability");
861
862 EntInfo entInfo("test", "this is test");
863
864 ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::ENT, DEFAULT_USERID);
865 EXPECT_TRUE(errVal != ERR_OK);
866
867 bool ret = false;
868 enterpriseDeviceMgrProxyTest->IsSuperAdmin("com.edm.test.demo", ret);
869 EXPECT_FALSE(ret);
870
871 std::string enabledAdmin;
872 enterpriseDeviceMgrProxyTest->GetEnabledSuperAdmin(enabledAdmin);
873 EXPECT_TRUE(enabledAdmin.size() == 0);
874
875 ret = enterpriseDeviceMgrProxyTest->IsSuperAdminExist();
876 EXPECT_FALSE(ret);
877
878 errVal = enterpriseDeviceMgrProxyTest->DisableSuperAdmin("com.edm.test.demo");
879 EXPECT_TRUE(errVal != ERR_OK);
880 }
881
882 /**
883 * @tc.name: TestGetSuperAdminSuccess
884 * @tc.desc: Test GetSuperAdmin func.
885 * @tc.type: FUNC
886 */
887 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetSuperAdminSuccess, TestSize.Level1)
888 {
889 std::string bundleName;
890 std::string abilityName;
891 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
892 .Times(1)
893 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetSuperAdmin));
894 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetSuperAdmin(bundleName, abilityName);
895 EXPECT_TRUE(errVal == ERR_OK);
896 EXPECT_TRUE(bundleName == RETURN_STRING);
897 EXPECT_TRUE(abilityName == RETURN_STRING);
898 }
899
900 /**
901 * @tc.name: TestGetSuperAdminFail
902 * @tc.desc: Test GetSuperAdmin func.
903 * @tc.type: FUNC
904 */
905 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetSuperAdminFail, TestSize.Level1)
906 {
907 std::string bundleName;
908 std::string abilityName;
909 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
910 .Times(1)
911 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
912 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetSuperAdmin(bundleName, abilityName);
913 EXPECT_TRUE(errVal != ERR_OK);
914 EXPECT_TRUE(bundleName.empty());
915 EXPECT_TRUE(abilityName.empty());
916 }
917
918 /**
919 * @tc.name: TestSetDelegatedPoliciesWithEdmDisable
920 * @tc.desc: Test SetDelegatedPolicies without enable edm service func.
921 * @tc.type: FUNC
922 */
923 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetDelegatedPoliciesWithEdmDisable, TestSize.Level1)
924 {
925 Utils::SetEdmServiceDisable();
926 OHOS::AppExecFwk::ElementName admin;
927 ErrCode ret = enterpriseDeviceMgrProxyTest->SetDelegatedPolicies(admin, "com.edm.test.demo", {});
928 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
929 }
930
931 /**
932 * @tc.name: TestSetDelegatedPoliciesIpcFail
933 * @tc.desc: Test SetDelegatedPolicies func with ipc failed.
934 * @tc.type: FUNC
935 */
936 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetDelegatedPoliciesIpcFail, TestSize.Level1)
937 {
938 OHOS::AppExecFwk::ElementName admin;
939 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
940 .Times(1)
941 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
942 ErrCode errVal = enterpriseDeviceMgrProxyTest->SetDelegatedPolicies(admin, "com.edm.test.demo", {});
943 EXPECT_TRUE(errVal == ERR_PROXY_SENDREQUEST_FAIL);
944 }
945
946 /**
947 * @tc.name: TestSetDelegatedPoliciesSuccess
948 * @tc.desc: Test SetDelegatedPolicies func success.
949 * @tc.type: FUNC
950 */
951 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestSetDelegatedPoliciesSuccess, TestSize.Level1)
952 {
953 OHOS::AppExecFwk::ElementName admin;
954 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
955 .Times(1)
956 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
957 ErrCode errVal = enterpriseDeviceMgrProxyTest->SetDelegatedPolicies(admin, "com.edm.test.demo", {});
958 EXPECT_TRUE(errVal == ERR_OK);
959 }
960
961 /**
962 * @tc.name: TestGetDelegatedPoliciesWithEdmDisable
963 * @tc.desc: Test GetDelegatedPolicies without enable edm service func.
964 * @tc.type: FUNC
965 */
966 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetDelegatedPoliciesWithEdmDisable, TestSize.Level1)
967 {
968 Utils::SetEdmServiceDisable();
969 OHOS::AppExecFwk::ElementName admin;
970 std::vector<std::string> result;
971 ErrCode ret = enterpriseDeviceMgrProxyTest->GetDelegatedPolicies(admin, "com.edm.test.demo",
972 EdmInterfaceCode::GET_DELEGATED_POLICIES, result);
973 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
974 }
975
976 /**
977 * @tc.name: TestGetDelegatedPoliciesIpcFail
978 * @tc.desc: Test GetDelegatedPolicies func with ipc failed.
979 * @tc.type: FUNC
980 */
981 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetDelegatedPoliciesIpcFail, TestSize.Level1)
982 {
983 OHOS::AppExecFwk::ElementName admin;
984 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
985 .Times(1)
986 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail));
987 std::vector<std::string> result;
988 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetDelegatedPolicies(admin, "com.edm.test.demo",
989 EdmInterfaceCode::GET_DELEGATED_POLICIES, result);
990 EXPECT_TRUE(errVal == ERR_PROXY_SENDREQUEST_FAIL);
991 }
992
993 /**
994 * @tc.name: TestGetDelegatedPoliciesSuccess
995 * @tc.desc: Test GetDelegatedPolicies func success.
996 * @tc.type: FUNC
997 */
998 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetDelegatedPoliciesSuccess, TestSize.Level1)
999 {
1000 OHOS::AppExecFwk::ElementName admin;
1001 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
1002 .Times(1)
1003 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequest));
1004 std::vector<std::string> result;
1005 ErrCode errVal = enterpriseDeviceMgrProxyTest->GetDelegatedPolicies(admin, "com.edm.test.demo",
1006 EdmInterfaceCode::GET_DELEGATED_POLICIES, result);
1007 EXPECT_TRUE(errVal == ERR_OK);
1008 }
1009 } // namespace TEST
1010 } // namespace EDM
1011 } // namespace OHOS
1012