1 /* 2 * Copyright (c) 2022-2023 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 class EnterpriseDeviceMgrStubMock : public IRemoteStub<IEnterpriseDeviceMgr> { 34 public: 35 EnterpriseDeviceMgrStubMock() = default; 36 37 virtual ~EnterpriseDeviceMgrStubMock() = default; 38 39 MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); 40 InvokeSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 42 { 43 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequest code :" << code; 44 code_ = code; 45 reply.WriteInt32(ERR_OK); 46 return 0; 47 } 48 49 int InvokeSendRequestGetEnterpriseInfo(uint32_t code, MessageParcel &data, MessageParcel &reply, 50 MessageOption &option); 51 52 int InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 53 54 int InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data, MessageParcel &reply, 55 MessageOption &option); 56 57 int InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 58 59 int InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 60 61 int InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 62 63 int InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data, MessageParcel &reply, 64 MessageOption &option); 65 66 int InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data, MessageParcel &reply, 67 MessageOption &option); 68 69 int InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 70 71 int InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 72 MessageOption &option); 73 74 int InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 75 MessageOption &option); 76 77 int InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 78 MessageOption &option); 79 80 int InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 81 82 int InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 83 MessageOption &option); 84 85 int InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data, MessageParcel &reply, 86 MessageOption &option); 87 88 int InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, 89 MessageOption &option); 90 InvokeSendRequestReplyFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)91 int InvokeSendRequestReplyFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 92 { 93 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestReplyFail code :" << code; 94 code_ = code; 95 reply.WriteInt32(ERR_PROXY_SENDREQUEST_FAIL); 96 return 0; 97 } 98 InvokeSendRequestFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)99 int InvokeSendRequestFail(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 100 { 101 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestFail code :" << code; 102 code_ = code; 103 return ERR_PROXY_SENDREQUEST_FAIL; 104 } 105 EnableAdmin(AppExecFwk::ElementName & admin,EntInfo & entInfo,AdminType type,int32_t userId)106 ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId) override 107 { 108 return 0; 109 } 110 DisableAdmin(AppExecFwk::ElementName & admin,int32_t userId)111 ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId) override { return 0; } 112 DisableSuperAdmin(const std::string & bundleName)113 ErrCode DisableSuperAdmin(const std::string &bundleName) override { return 0; } 114 HandleDevicePolicy(uint32_t code,AppExecFwk::ElementName & admin,MessageParcel & data,MessageParcel & reply,int32_t userId)115 ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data, MessageParcel &reply, 116 int32_t userId) override 117 { 118 return 0; 119 } 120 GetDevicePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,int32_t userId)121 ErrCode GetDevicePolicy(uint32_t code, MessageParcel &data, MessageParcel &reply, int32_t userId) override 122 { 123 return 0; 124 } 125 GetEnabledAdmin(AdminType type,std::vector<std::string> & enabledAdminList)126 ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList) override { return 0; } 127 GetEnterpriseInfo(AppExecFwk::ElementName & admin,MessageParcel & reply)128 ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, MessageParcel &reply) override { return 0; } 129 SetEnterpriseInfo(AppExecFwk::ElementName & admin,EntInfo & entInfo)130 ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo) override { return 0; } 131 SubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)132 ErrCode SubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 133 { 134 return 0; 135 } 136 UnsubscribeManagedEvent(const AppExecFwk::ElementName & admin,const std::vector<uint32_t> & events)137 ErrCode UnsubscribeManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events) override 138 { 139 return 0; 140 } 141 IsSuperAdmin(const std::string & bundleName)142 bool IsSuperAdmin(const std::string &bundleName) override { return false; } 143 IsAdminEnabled(AppExecFwk::ElementName & admin,int32_t userId)144 bool IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId) override { return false; } 145 AuthorizeAdmin(const AppExecFwk::ElementName & admin,const std::string & bundleName)146 ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName) override 147 { 148 return ERR_OK; 149 } 150 151 uint32_t code_ = 0; 152 }; 153 } // namespace EDM 154 } // namespace OHOS 155 #endif // EDM_UNIT_TEST_ENTERPRISE_DEVICE_MGR_STUB_MOCK_H