• 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_STUB_MOCK_H
17 #define EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include <iremote_stub.h>
21 
22 #include <map>
23 #include <vector>
24 
25 #include "ienterprise_device_mgr.h"
26 #include "string_ex.h"
27 
28 namespace OHOS {
29 namespace EDM {
30 constexpr int ERR_PROXY_SENDREQUEST_FAIL = 111;
31 constexpr int EDM_MAXREQUESTSIZE = 99999;
32 const std::string RETURN_STRING = "test_string";
33 const std::string ELEMENT_STRING = "com.example.myapplication/MainAbility";
34 const std::string UPGRADE_VERSION = "version_1.0";
35 constexpr int32_t UPGRADE_FAILED_CODE = -1;
36 const std::string UPGRADE_FAILED_MESSAGE = "upgrade failed";
37 const std::string AUTH_DATA = "auth data";
38 class EnterpriseDeviceMgrStubMock : public IRemoteStub<IEnterpriseDeviceMgrIdl> {
39 public:
40     EnterpriseDeviceMgrStubMock() = default;
41 
42     virtual ~EnterpriseDeviceMgrStubMock() = default;
43 
44     MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &));
45     MOCK_METHOD(int, EnableAdmin, (const AppExecFwk::ElementName &, const EntInfo &, AdminType, int32_t), (override));
46     MOCK_METHOD(int, DisableAdmin, (const AppExecFwk::ElementName &, int32_t), (override));
47     MOCK_METHOD(int, DisableSuperAdmin, (const std::string &), (override));
48     MOCK_METHOD(int, GetEnabledAdmin, (AdminType, (std::vector<std::string> &)), (override));
49     MOCK_METHOD(int, GetEnterpriseInfo, (const AppExecFwk::ElementName &, EntInfo &), (override));
50     MOCK_METHOD(int, SetEnterpriseInfo, (const AppExecFwk::ElementName &, const EntInfo &), (override));
51     MOCK_METHOD(int, IsSuperAdmin, (const std::string &, bool &), (override));
52     MOCK_METHOD(int, IsByodAdmin, (const AppExecFwk::ElementName &, bool &), (override));
53     MOCK_METHOD(int, IsAdminEnabled, (const AppExecFwk::ElementName &, int32_t, bool &), (override));
54     MOCK_METHOD(int, SubscribeManagedEvent, (const AppExecFwk::ElementName &, (const std::vector<uint32_t> &)),
55         (override));
56     MOCK_METHOD(int, UnsubscribeManagedEvent, (const AppExecFwk::ElementName &, (const std::vector<uint32_t> &)),
57         (override));
58     MOCK_METHOD(int, AuthorizeAdmin, (const AppExecFwk::ElementName &, const std::string &), (override));
59     MOCK_METHOD(int, GetSuperAdmin, (std::string &, std::string &), (override));
60     MOCK_METHOD(int, SetDelegatedPolicies,
61         (const AppExecFwk::ElementName &, const std::string &, (const std::vector<std::string> &)), (override));
62     MOCK_METHOD(int, GetDelegatedPolicies,
63         (const AppExecFwk::ElementName &, const std::string &, (std::vector<std::string> &)), (override));
64     MOCK_METHOD(int, GetDelegatedBundleNames,
65         (const AppExecFwk::ElementName &, const std::string &, (std::vector<std::string> &)), (override));
66     MOCK_METHOD(int, ReplaceSuperAdmin, (const AppExecFwk::ElementName &, const AppExecFwk::ElementName &, bool),
67         (override));
68     MOCK_METHOD(int, GetAdmins, ((std::vector<std::shared_ptr<AAFwk::Want>> &)), (override));
69     MOCK_METHOD(int, SetAdminRunningMode, (const AppExecFwk::ElementName &, uint32_t), (override));
70     MOCK_METHOD(int, SetDelegatedPolicies, (const std::string &, (const std::vector<std::string> &), int32_t),
71         (override));
72     MOCK_METHOD(int, SetBundleInstallPolicies, ((const std::vector<std::string> &), int32_t, int32_t),
73         (override));
74 
InvokeSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)75     int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
76     {
77         GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequest code :" << code;
78         code_ = code;
79         reply.WriteInt32(ERR_OK);
80         return 0;
81     }
82 
83     int InvokeGetEnterpriseInfo(const AppExecFwk::ElementName &admin, EntInfo &entInfo);
84     int InvokeGetEnterpriseInfoFail(const AppExecFwk::ElementName &admin, EntInfo &entInfo);
85     int InvokeIsAdminEnabledFail(const AppExecFwk::ElementName &admin, int32_t userId, bool &isEnabled);
86     int InvokeIsSuperAdminFail(const std::string &bundleName, bool &isSuper);
87     int InvokeIsByodAdminFail(const AppExecFwk::ElementName &admin, bool &isByod);
88     int InvokeGetSuperAdmin(std::string &bundleName, std::string &abilityName);
89     int InvokeGetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> &wants);
90     int InvokeGetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList);
91 
92     int InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
93 
94     int InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data, MessageParcel &reply,
95         MessageOption &option);
96 
97     int InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
98 
99     int InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
100 
101     int InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
102 
103     int InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data, MessageParcel &reply,
104         MessageOption &option);
105 
106     int InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data, MessageParcel &reply,
107         MessageOption &option);
108 
109     int InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
110 
111     int InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code, MessageParcel &data, MessageParcel &reply,
112         MessageOption &option);
113 
114     int InvokeSendRequestSetPolicyInstallFail(uint32_t code, MessageParcel &data, MessageParcel &reply,
115         MessageOption &option);
116 
117     int InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
118         MessageOption &option);
119 
120     int InvokeSendRequestGetErrPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
121 
122     int InvokeSendRequestGetPolicyExceedsMax(uint32_t code, MessageParcel &data, MessageParcel &reply,
123         MessageOption &option);
124 
125     int InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
126         MessageOption &option);
127 
128     int InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
129         MessageOption &option);
130 
131     int InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
132 
133     int InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
134         MessageOption &option);
135 
136     int InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data, MessageParcel &reply,
137         MessageOption &option);
138 
139     int InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
140         MessageOption &option);
141 
142     int InvokeWifiListSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
143         MessageOption &option);
144 
145     int InvokeArrayIntSendRequestGetPolicy(uint32_t code, MessageParcel &data,
146         MessageParcel &reply, MessageOption &option);
147 
148     int InvokeDisallowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
149         MessageOption &option);
150 
151     int InvokeSendRequestGetSuperAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
152 
153     int InvokeSendRequestGetOTAUpdatePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
154         MessageOption &option);
155 
156     int InvokeSendRequestGetUpgradeResult(uint32_t code, MessageParcel &data, MessageParcel &reply,
157         MessageOption &option);
158 
159     int InvokeSendRequestGetUpdateAuthData(uint32_t code, MessageParcel &data, MessageParcel &reply,
160         MessageOption &option);
161 
162     int InvokeSendRequestGetPasswordPolicy(uint32_t code, MessageParcel &data,
163         MessageParcel &reply, MessageOption &option);
164 
165     int InvokeSendRequestGetManagedBrowserPolicy(uint32_t code, MessageParcel &data,
166         MessageParcel &reply, MessageOption &option);
167 
168     int InvokeSendRequestGetAdmins(uint32_t code, MessageParcel &data,
169         MessageParcel &reply, MessageOption &option);
170 
171     int InvokeSendRequestCheckAndGetAdminProvisionInfo(uint32_t code, MessageParcel &data,
172         MessageParcel &reply, MessageOption &option);
173 
174     int InvokeSendRequestGetInstalledBundleList(uint32_t code, MessageParcel &data,
175         MessageParcel &reply, MessageOption &option);
176 
InvokeSendRequestReplyFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)177     int InvokeSendRequestReplyFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
178     {
179         GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestReplyFail code :" << code;
180         code_ = code;
181         reply.WriteInt32(ERR_PROXY_SENDREQUEST_FAIL);
182         return 0;
183     }
184 
InvokeSendRequestFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)185     int InvokeSendRequestFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
186     {
187         GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestFail code :" << code;
188         code_ = code;
189         return ERR_PROXY_SENDREQUEST_FAIL;
190     }
191 
192     int InvokeSendRequestSizeError(uint32_t code, MessageParcel &data, MessageParcel &reply,
193         MessageOption &option);
194     uint32_t code_ = 0;
195 };
196 } // namespace EDM
197 } // namespace OHOS
198 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H