1 /* 2 * Copyright (c) 2022 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 OHOS_ROSEN_TEST_COMMON_MOCK_IREMOTE_OBJECT_MOCKER 17 #define OHOS_ROSEN_TEST_COMMON_MOCK_IREMOTE_OBJECT_MOCKER 18 19 #include <iremote_object.h> 20 #include <gmock/gmock.h> 21 22 namespace OHOS { 23 namespace Rosen { 24 class IRemoteObjectMocker : public IRemoteObject { 25 public: IRemoteObjectMocker()26 IRemoteObjectMocker() : IRemoteObject {u"IRemoteObjectMocker"} 27 { 28 } 29 ~IRemoteObjectMocker()30 ~IRemoteObjectMocker() 31 { 32 } 33 GetObjectRefCount()34 int32_t GetObjectRefCount() 35 { 36 return 0; 37 } 38 SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) 40 { 41 return 0; 42 } 43 IsProxyObject()44 bool IsProxyObject() const 45 { 46 return true; 47 } 48 CheckObjectLegality()49 bool CheckObjectLegality() const 50 { 51 return true; 52 } 53 AddDeathRecipient(const sptr<DeathRecipient> & recipient)54 bool AddDeathRecipient(const sptr<DeathRecipient>& recipient) 55 { 56 return true; 57 } 58 RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)59 bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient) 60 { 61 return true; 62 } 63 AsInterface()64 sptr<IRemoteBroker> AsInterface() 65 { 66 return nullptr; 67 } 68 Dump(int fd,const std::vector<std::u16string> & args)69 int Dump(int fd, const std::vector<std::u16string>& args) 70 { 71 return 0; 72 } 73 }; 74 class MockIRemoteObject : public IRemoteObject { 75 public: MockIRemoteObject()76 MockIRemoteObject() : IRemoteObject {u"MockIRemoteObject"} 77 { 78 } 79 ~MockIRemoteObject()80 ~MockIRemoteObject() 81 { 82 } 83 GetObjectRefCount()84 int32_t GetObjectRefCount() 85 { 86 return 0; 87 } 88 SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)89 int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) 90 { 91 return sendRequestResult_; 92 } 93 IsProxyObject()94 bool IsProxyObject() const 95 { 96 return true; 97 } 98 CheckObjectLegality()99 bool CheckObjectLegality() const 100 { 101 return true; 102 } 103 AddDeathRecipient(const sptr<DeathRecipient> & recipient)104 bool AddDeathRecipient(const sptr<DeathRecipient>& recipient) 105 { 106 return true; 107 } 108 RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)109 bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient) 110 { 111 return true; 112 } 113 AsInterface()114 sptr<IRemoteBroker> AsInterface() 115 { 116 return nullptr; 117 } 118 Dump(int fd,const std::vector<std::u16string> & args)119 int Dump(int fd, const std::vector<std::u16string>& args) 120 { 121 return 0; 122 } 123 SetRequestResult(int result)124 void SetRequestResult(int result) 125 { 126 sendRequestResult_ = result; 127 } 128 129 int sendRequestResult_ = 0; 130 int count_ = 0; 131 }; 132 133 class RemoteObjectMocker : public IRemoteObject { 134 public: RemoteObjectMocker()135 RemoteObjectMocker() : IRemoteObject{u"RemoteObjectMocker"} {} ~RemoteObjectMocker()136 ~RemoteObjectMocker() {} 137 138 MOCK_METHOD(int32_t, GetObjectRefCount, (), (override)); 139 MOCK_METHOD(int, SendRequest, (uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option), 140 (override)); 141 MOCK_METHOD(bool, IsProxyObject, (), (const, override)); 142 MOCK_METHOD(bool, IsObjectDead, (), (const, override)); 143 MOCK_METHOD(std::u16string, GetInterfaceDescriptor, (), (override)); 144 MOCK_METHOD(bool, CheckObjectLegality, (), (const, override)); 145 MOCK_METHOD(bool, AddDeathRecipient, (const sptr<DeathRecipient>& recipient), (override)); 146 MOCK_METHOD(bool, RemoveDeathRecipient, (const sptr<DeathRecipient>& recipient), (override)); 147 MOCK_METHOD(bool, Marshalling, (Parcel& parcel), (const, override)); 148 MOCK_METHOD(sptr<IRemoteBroker>, AsInterface, (), (override)); 149 MOCK_METHOD(int, Dump, (int fd, const std::vector<std::u16string>& args), (override)); 150 }; 151 } 152 } 153 154 #endif