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 
29 namespace OHOS {
30 namespace EDM {
31 namespace TEST {
32 class EnterpriseDeviceMgrAbilityTest : public testing::Test {
33 public:
34     void SetUp() override;
35     void TearDown() override;
36     void PrepareBeforeHandleDevicePolicy();
37     void GetPolicySuccess(int32_t userId, const std::string& adminName, const std::string& policyName);
38     void GetPolicyFailed(int32_t userId, const std::string& adminName, const std::string& policyName);
39     void SetPolicy(const std::string& adminName, const std::string& policyName);
40     void EnableAdminSuc(AppExecFwk::ElementName& admin, AdminType adminType, int userId, bool isDebug = false);
41     void AuthorizeAdminSuc(const AppExecFwk::ElementName& admin, const std::string& subSuperAdminBundleName);
42     void DisableAdminSuc(AppExecFwk::ElementName &admin, int32_t userId);
43     void DisableSuperAdminSuc(const std::string &bundleName);
44 
45     void GetBundleInfoMock(bool ret, const std::string& permission);
46     void QueryExtensionAbilityInfosMock(bool ret, const std::string& bundleName, bool isExtensionInfoEmpty = false);
47     int HandleDevicePolicyFuncTest001(void);
48     int HandleDevicePolicyFuncTest002(void);
49     int HandleDevicePolicyFuncTest003(void);
50     int HandleDevicePolicyFuncTest004(void);
51     int HandleDevicePolicyFuncTest005(void);
52     int HandleDevicePolicyFuncTest006(void);
53     int HandleDevicePolicyFuncTest007(void);
54     int HandleDevicePolicyFuncTest008(void);
55     int GetDevicePolicyFuncTest001(void);
56     int GetDevicePolicyFuncTest002(void);
57     int GetDevicePolicyFuncTest003(void);
58     int GetDevicePolicyFuncTest004(void);
59     int GetDevicePolicyFuncTest005(void);
60     int GetDevicePolicyFuncTest006(void);
61     int GetAndSwitchPolicyManagerByUserIdTest001(void);
62     int GetAndSwitchPolicyManagerByUserIdTest002(void);
63 protected:
64     int32_t TestDump();
65     sptr<EnterpriseDeviceMgrAbilityMock> edmMgr_ = nullptr;
66     std::shared_ptr<EdmAppManagerImplMock> appMgrMock_ = nullptr;
67     std::shared_ptr<EdmBundleManagerImplMock> bundleMgrMock_ = nullptr;
68     std::shared_ptr<EdmOsAccountManagerImplMock> osAccountMgrMock_ = nullptr;
69     std::shared_ptr<EdmAccessTokenManagerImplMock> accessTokenMgrMock_ = nullptr;
70     std::shared_ptr<ExternalManagerFactoryMock> factoryMock_ = nullptr;
71     std::shared_ptr<IPlugin> plugin_ = nullptr;
72 };
73 } // namespace TEST
74 } // namespace EDM
75 } // namespace OHOS
76 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_ABILITY_TEST_H