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 InvokeSendRequestReplyFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)119 int InvokeSendRequestReplyFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 120 { 121 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestReplyFail code :" << code; 122 code_ = code; 123 reply.WriteInt32(ERR_PROXY_SENDREQUEST_FAIL); 124 return 0; 125 } 126 InvokeSendRequestFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)127 int InvokeSendRequestFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 128 { 129 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestFail code :" << code; 130 code_ = code; 131 return ERR_PROXY_SENDREQUEST_FAIL; 132 } 133 EnableAdmin(AppExecFwk::ElementName & admin,EntInfo & entInfo,AdminType type,int32_t userId)134 ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId) override 135 { 136 return 0; 137 } 138 DisableAdmin(AppExecFwk::ElementName & admin,int32_t userId)139 ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId) override { return 0; } 140 DisableSuperAdmin(const std::string & bundleName)141 ErrCode DisableSuperAdmin(const std::string &bundleName) override { return 0; } 142 HandleDevicePolicy(uint32_t code,AppExecFwk::ElementName & admin,MessageParcel & data,MessageParcel & reply,int32_t userId)143 ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data, MessageParcel &reply, 144 int32_t userId) override 145 { 146 return 0; 147 } 148 GetDevicePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,int32_t userId)149 ErrCode GetDevicePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, int32_t userId) override 150 { 151 return 0; 152 } 153 GetEnabledAdmin(AdminType type,std::vector<std::string> & enabledAdminList)154 ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList) override { return 0; } 155 GetEnterpriseInfo(AppExecFwk::ElementName & admin,MessageParcel & reply)156 ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, MessageParcel &reply) override { return 0; } 157 SetEnterpriseInfo(AppExecFwk::ElementName & admin,EntInfo & entInfo)158 ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo) override { return 0; } 159 SubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)160 ErrCode SubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 161 { 162 return 0; 163 } 164 UnsubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)165 ErrCode UnsubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 166 { 167 return 0; 168 } 169 IsSuperAdmin(const std::string & bundleName)170 bool IsSuperAdmin(const std::string &bundleName) override { return false; } 171 IsAdminEnabled(AppExecFwk::ElementName & admin,int32_t userId)172 bool IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId) override { return false; } 173 AuthorizeAdmin(const AppExecFwk::ElementName & admin,const std::string & bundleName)174 ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName) override 175 { 176 return ERR_OK; 177 } 178 SetDelegatedPolicies(const std::string & parentAdminName,const std::string & bundleName,const std::vector<std::string> & policies)179 ErrCode SetDelegatedPolicies(const std::string &parentAdminName, const std::string &bundleName, 180 const std::vector<std::string> &policies) override 181 { 182 return ERR_OK; 183 } 184 GetDelegatedPolicies(const std::string & parentAdminName,const std::string & bundleName,std::vector<std::string> & policies)185 ErrCode GetDelegatedPolicies(const std::string &parentAdminName, const std::string &bundleName, 186 std::vector<std::string> &policies) override 187 { 188 return ERR_OK; 189 } 190 GetDelegatedBundleNames(const std::string & parentAdminName,const std::string & policyName,std::vector<std::string> & bundleNames)191 ErrCode GetDelegatedBundleNames(const std::string &parentAdminName, const std::string &policyName, 192 std::vector<std::string> &bundleNames) override 193 { 194 return ERR_OK; 195 } 196 GetSuperAdmin(MessageParcel & reply)197 ErrCode GetSuperAdmin(MessageParcel &reply) override 198 { 199 return ERR_OK; 200 } 201 202 uint32_t code_ = 0; 203 }; 204 } // namespace EDM 205 } // namespace OHOS 206 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H