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 const std::string RETURN_STRING = "test_string"; 32 const std::string ELEMENT_STRING = "com.example.myapplication/MainAbility"; 33 const std::string UPGRADE_VERSION = "version_1.0"; 34 constexpr int32_t UPGRADE_FAILED_CODE = -1; 35 const std::string UPGRADE_FAILED_MESSAGE = "upgrade failed"; 36 class EnterpriseDeviceMgrStubMock : public IRemoteStub<IEnterpriseDeviceMgr> { 37 public: 38 EnterpriseDeviceMgrStubMock() = default; 39 40 virtual ~EnterpriseDeviceMgrStubMock() = default; 41 42 MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); 43 InvokeSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)44 int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 45 { 46 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequest code :" << code; 47 code_ = code; 48 reply.WriteInt32(ERR_OK); 49 return 0; 50 } 51 52 int InvokeSendRequestGetEnterpriseInfo(uint32_t code, MessageParcel &data, MessageParcel &reply, 53 MessageOption &option); 54 55 int InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 56 57 int InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data, MessageParcel &reply, 58 MessageOption &option); 59 60 int InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 61 62 int InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 63 64 int InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 65 66 int InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data, MessageParcel &reply, 67 MessageOption &option); 68 69 int InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data, MessageParcel &reply, 70 MessageOption &option); 71 72 int InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 73 74 int InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code, MessageParcel &data, MessageParcel &reply, 75 MessageOption &option); 76 77 int InvokeSendRequestSetPolicyInstallFail(uint32_t code, MessageParcel &data, MessageParcel &reply, 78 MessageOption &option); 79 80 int InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 81 MessageOption &option); 82 83 int InvokeSendRequestGetErrPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 84 85 int InvokeSendRequestGetPolicyExceedsMax(uint32_t code, MessageParcel &data, MessageParcel &reply, 86 MessageOption &option); 87 88 int InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 89 MessageOption &option); 90 91 int InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 92 MessageOption &option); 93 94 int InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 95 96 int InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 97 MessageOption &option); 98 99 int InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data, MessageParcel &reply, 100 MessageOption &option); 101 102 int InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 103 MessageOption &option); 104 105 int InvokeDisallowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 106 MessageOption &option); 107 108 int InvokeSendRequestGetSuperAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 109 110 int InvokeSendRequestGetOTAUpdatePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 111 MessageOption &option); 112 113 int InvokeSendRequestGetUpgradeResult(uint32_t code, MessageParcel &data, MessageParcel &reply, 114 MessageOption &option); 115 116 int InvokeSendRequestGetPasswordPolicy(uint32_t code, MessageParcel &data, 117 MessageParcel &reply, MessageOption &option); 118 119 int InvokeSendRequestGetAdmins(uint32_t code, MessageParcel &data, 120 MessageParcel &reply, MessageOption &option); 121 122 int InvokeSendRequestCheckAndGetAdminProvisionInfo(uint32_t code, MessageParcel &data, 123 MessageParcel &reply, MessageOption &option); 124 125 int InvokeSendRequestGetManagedBrowserPolicy(uint32_t code, MessageParcel &data, 126 MessageParcel &reply, MessageOption &option); 127 InvokeSendRequestReplyFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)128 int InvokeSendRequestReplyFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 129 { 130 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestReplyFail code :" << code; 131 code_ = code; 132 reply.WriteInt32(ERR_PROXY_SENDREQUEST_FAIL); 133 return 0; 134 } 135 InvokeSendRequestFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)136 int InvokeSendRequestFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 137 { 138 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestFail code :" << code; 139 code_ = code; 140 return ERR_PROXY_SENDREQUEST_FAIL; 141 } 142 EnableAdmin(AppExecFwk::ElementName & admin,EntInfo & entInfo,AdminType type,int32_t userId)143 ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId) override 144 { 145 return 0; 146 } 147 DisableAdmin(AppExecFwk::ElementName & admin,int32_t userId)148 ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId) override { return 0; } 149 DisableSuperAdmin(const std::string & bundleName)150 ErrCode DisableSuperAdmin(const std::string &bundleName) override { return 0; } 151 HandleDevicePolicy(uint32_t code,AppExecFwk::ElementName & admin,MessageParcel & data,MessageParcel & reply,int32_t userId)152 ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data, MessageParcel &reply, 153 int32_t userId) override 154 { 155 return 0; 156 } 157 GetDevicePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,int32_t userId)158 ErrCode GetDevicePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, int32_t userId) override 159 { 160 return 0; 161 } 162 CheckAndGetAdminProvisionInfo(uint32_t code,MessageParcel & data,MessageParcel & reply,int32_t userId)163 ErrCode CheckAndGetAdminProvisionInfo(uint32_t code, MessageParcel &data, MessageParcel &reply, 164 int32_t userId) override 165 { 166 return 0; 167 } 168 GetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> & wants)169 ErrCode GetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> &wants) override 170 { 171 return 0; 172 } 173 GetEnabledAdmin(AdminType type,std::vector<std::string> & enabledAdminList)174 ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList) override { return 0; } 175 GetEnterpriseInfo(AppExecFwk::ElementName & admin,MessageParcel & reply)176 ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, MessageParcel &reply) override { return 0; } 177 SetEnterpriseInfo(AppExecFwk::ElementName & admin,EntInfo & entInfo)178 ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo) override { return 0; } 179 SubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)180 ErrCode SubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 181 { 182 return 0; 183 } 184 UnsubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)185 ErrCode UnsubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 186 { 187 return 0; 188 } 189 IsSuperAdmin(const std::string & bundleName)190 bool IsSuperAdmin(const std::string &bundleName) override { return false; } 191 IsAdminEnabled(AppExecFwk::ElementName & admin,int32_t userId)192 bool IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId) override { return false; } 193 AuthorizeAdmin(const AppExecFwk::ElementName & admin,const std::string & bundleName)194 ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName) override 195 { 196 return ERR_OK; 197 } 198 SetDelegatedPolicies(const std::string & parentAdminName,const std::string & bundleName,const std::vector<std::string> & policies)199 ErrCode SetDelegatedPolicies(const std::string &parentAdminName, const std::string &bundleName, 200 const std::vector<std::string> &policies) override 201 { 202 return ERR_OK; 203 } 204 GetDelegatedPolicies(const std::string & parentAdminName,const std::string & bundleName,std::vector<std::string> & policies)205 ErrCode GetDelegatedPolicies(const std::string &parentAdminName, const std::string &bundleName, 206 std::vector<std::string> &policies) override 207 { 208 return ERR_OK; 209 } 210 GetDelegatedBundleNames(const std::string & parentAdminName,const std::string & policyName,std::vector<std::string> & bundleNames)211 ErrCode GetDelegatedBundleNames(const std::string &parentAdminName, const std::string &policyName, 212 std::vector<std::string> &bundleNames) override 213 { 214 return ERR_OK; 215 } 216 GetSuperAdmin(MessageParcel & reply)217 ErrCode GetSuperAdmin(MessageParcel &reply) override 218 { 219 return ERR_OK; 220 } 221 222 uint32_t code_ = 0; 223 }; 224 } // namespace EDM 225 } // namespace OHOS 226 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H