• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_ABILITY_TEST_H
17 #define EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_ABILITY_TEST_H
18 
19 #include <gtest/gtest.h>
20 #include <memory>
21 
22 #include "edm_access_token_manager_impl_mock.h"
23 #include "edm_app_manager_impl_mock.h"
24 #include "edm_bundle_manager_impl_mock.h"
25 #include "edm_os_account_manager_impl_mock.h"
26 #include "enterprise_device_mgr_ability_mock.h"
27 #include "external_manager_factory_mock.h"
28 #include "permission_checker_mock.h"
29 
30 namespace OHOS {
31 namespace EDM {
32 namespace TEST {
33 class EnterpriseDeviceMgrAbilityTest : public testing::Test {
34 public:
35     void SetUp() override;
36     void TearDown() override;
37     static void SetUpTestSuite();
38     static void TearDownTestSuite();
39     void PrepareBeforeHandleDevicePolicy();
40     void GetPolicySuccess(int32_t userId, const std::string& adminName, const std::string& policyName);
41     void GetPolicyFailed(int32_t userId, const std::string& adminName, const std::string& policyName);
42     void SetPolicy(const std::string& adminName, const std::string& policyName);
43     void EnableAdminSuc(AppExecFwk::ElementName& admin, AdminType adminType, int userId, bool isDebug = false);
44     void AuthorizeAdminSuc(const AppExecFwk::ElementName& admin, const std::string& subSuperAdminBundleName);
45     void DisableAdminSuc(AppExecFwk::ElementName &admin, int32_t userId);
46     void DisableSuperAdminSuc(const std::string &bundleName);
47 
48     void GetBundleInfoMock(bool ret, const std::string& permission);
49     void QueryExtensionAbilityInfosMock(bool ret, const std::string& bundleName, bool isExtensionInfoEmpty = false);
50     int HandleDevicePolicyFuncTest001(void);
51     int HandleDevicePolicyFuncTest002(void);
52     int HandleDevicePolicyFuncTest003(void);
53     int HandleDevicePolicyFuncTest004(void);
54     int HandleDevicePolicyFuncTest005(void);
55     int HandleDevicePolicyFuncTest006(void);
56     int HandleDevicePolicyFuncTest007(void);
57     int HandleDevicePolicyFuncTest008(void);
58     int GetDevicePolicyFuncTest001(void);
59     int GetDevicePolicyFuncTest002(void);
60     int GetDevicePolicyFuncTest003(void);
61     int GetDevicePolicyFuncTest004(void);
62     int GetDevicePolicyFuncTest005(void);
63     int GetDevicePolicyFuncTest006(void);
64     int GetAndSwitchPolicyManagerByUserIdTest001(void);
65     int GetAndSwitchPolicyManagerByUserIdTest002(void);
66 protected:
67     int32_t TestDump();
68     void initPolicies();
69     sptr<EnterpriseDeviceMgrAbilityMock> edmMgr_ = nullptr;
70     std::shared_ptr<EdmAppManagerImplMock> appMgrMock_ = nullptr;
71     std::shared_ptr<EdmBundleManagerImplMock> bundleMgrMock_ = nullptr;
72     std::shared_ptr<EdmOsAccountManagerImplMock> osAccountMgrMock_ = nullptr;
73     std::shared_ptr<EdmAccessTokenManagerImplMock> accessTokenMgrMock_ = nullptr;
74     std::shared_ptr<ExternalManagerFactoryMock> factoryMock_ = nullptr;
75     std::shared_ptr<PermissionCheckerMock> permissionCheckerMock_ = nullptr;
76     std::shared_ptr<IPlugin> plugin_ = nullptr;
77 };
78 } // namespace TEST
79 } // namespace EDM
80 } // namespace OHOS
81 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_ABILITY_TEST_H