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 InvokeSendRequestGetSuperAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 106 107 int InvokeSendRequestGetOTAUpdatePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 108 MessageOption &option); 109 110 int InvokeSendRequestGetUpgradeResult(uint32_t code, MessageParcel &data, MessageParcel &reply, 111 MessageOption &option); 112 113 int InvokeSendRequestGetPasswordPolicy(uint32_t code, MessageParcel &data, 114 MessageParcel &reply, MessageOption &option); 115 InvokeSendRequestReplyFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)116 int InvokeSendRequestReplyFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 117 { 118 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestReplyFail code :" << code; 119 code_ = code; 120 reply.WriteInt32(ERR_PROXY_SENDREQUEST_FAIL); 121 return 0; 122 } 123 InvokeSendRequestFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)124 int InvokeSendRequestFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 125 { 126 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestFail code :" << code; 127 code_ = code; 128 return ERR_PROXY_SENDREQUEST_FAIL; 129 } 130 EnableAdmin(AppExecFwk::ElementName & admin,EntInfo & entInfo,AdminType type,int32_t userId)131 ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId) override 132 { 133 return 0; 134 } 135 DisableAdmin(AppExecFwk::ElementName & admin,int32_t userId)136 ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId) override { return 0; } 137 DisableSuperAdmin(const std::string & bundleName)138 ErrCode DisableSuperAdmin(const std::string &bundleName) override { return 0; } 139 HandleDevicePolicy(uint32_t code,AppExecFwk::ElementName & admin,MessageParcel & data,MessageParcel & reply,int32_t userId)140 ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data, MessageParcel &reply, 141 int32_t userId) override 142 { 143 return 0; 144 } 145 GetDevicePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,int32_t userId)146 ErrCode GetDevicePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, int32_t userId) override 147 { 148 return 0; 149 } 150 GetEnabledAdmin(AdminType type,std::vector<std::string> & enabledAdminList)151 ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList) override { return 0; } 152 GetEnterpriseInfo(AppExecFwk::ElementName & admin,MessageParcel & reply)153 ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, MessageParcel &reply) override { return 0; } 154 SetEnterpriseInfo(AppExecFwk::ElementName & admin,EntInfo & entInfo)155 ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo) override { return 0; } 156 SubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)157 ErrCode SubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 158 { 159 return 0; 160 } 161 UnsubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)162 ErrCode UnsubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 163 { 164 return 0; 165 } 166 IsSuperAdmin(const std::string & bundleName)167 bool IsSuperAdmin(const std::string &bundleName) override { return false; } 168 IsAdminEnabled(AppExecFwk::ElementName & admin,int32_t userId)169 bool IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId) override { return false; } 170 AuthorizeAdmin(const AppExecFwk::ElementName & admin,const std::string & bundleName)171 ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName) override 172 { 173 return ERR_OK; 174 } 175 GetSuperAdmin(MessageParcel & reply)176 ErrCode GetSuperAdmin(MessageParcel &reply) override 177 { 178 return ERR_OK; 179 } 180 181 uint32_t code_ = 0; 182 }; 183 } // namespace EDM 184 } // namespace OHOS 185 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H