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_MOCK_IPC_IREMOTE_INVOKER_H 17 #define OHOS_MOCK_IPC_IREMOTE_INVOKER_H 18 19 #include <unistd.h> 20 #include <sys/types.h> 21 22 #include <gtest/gtest.h> 23 #include <gmock/gmock.h> 24 25 #include "binder_connector.h" 26 #include "iremote_invoker.h" 27 #include "invoker_factory.h" 28 29 namespace OHOS { 30 #ifdef CONFIG_IPC_SINGLE 31 namespace IPC_SINGLE { 32 #endif 33 34 class MockIRemoteInvoker : public IRemoteInvoker { 35 public: 36 MockIRemoteInvoker() = default; 37 38 MOCK_METHOD1(AcquireHandle, bool(int32_t handle)); 39 MOCK_METHOD1(ReleaseHandle, bool(int32_t handle)); 40 MOCK_METHOD1(PingService, bool(int32_t handle)); 41 MOCK_METHOD3(SendReply, int(MessageParcel &reply, uint32_t flags, int32_t result)); 42 MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, 43 MessageParcel &reply, MessageOption &option)); 44 MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); 45 MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); 46 MOCK_METHOD1(SetMaxWorkThread, bool(int maxThreadNum)); 47 MOCK_METHOD1(JoinThread, void(bool initiative)); 48 MOCK_METHOD1(JoinProcessThread, void(bool initiative)); 49 MOCK_METHOD1(FreeBuffer, void(void *data)); 50 MOCK_METHOD1(SetRegistryObject, bool(sptr<IRemoteObject> &object)); 51 MOCK_METHOD0(StopWorkThread, void()); 52 MOCK_CONST_METHOD0(GetCallerSid, std::string()); 53 MOCK_CONST_METHOD0(GetCallerPid, pid_t()); 54 MOCK_CONST_METHOD0(GetCallerRealPid, pid_t()); 55 MOCK_CONST_METHOD0(GetCallerUid, uid_t()); 56 MOCK_CONST_METHOD0(GetCallerTokenID, uint64_t()); 57 MOCK_CONST_METHOD0(GetFirstCallerTokenID, uint64_t()); 58 MOCK_CONST_METHOD0(GetSelfTokenID, uint64_t()); 59 MOCK_CONST_METHOD0(GetSelfFirstCallerTokenID, uint64_t()); 60 MOCK_METHOD0(GetStatus, uint32_t()); 61 MOCK_METHOD0(IsLocalCalling, bool()); 62 MOCK_METHOD0(GetLocalDeviceID, std::string()); 63 MOCK_CONST_METHOD0(GetCallerDeviceID, std::string()); 64 MOCK_CONST_METHOD2(FlattenObject, bool(Parcel &parcel, const IRemoteObject *object)); 65 MOCK_METHOD1(UnflattenObject, sptr<IRemoteObject>(Parcel &parcel)); 66 MOCK_METHOD1(ReadFileDescriptor, int(Parcel &parcel)); 67 MOCK_METHOD3(WriteFileDescriptor, bool(Parcel &parcel, int fd, bool takeOwnership)); 68 MOCK_METHOD1(FlushCommands, int(IRemoteObject *object)); 69 MOCK_METHOD0(ResetCallingIdentity, std::string()); 70 MOCK_METHOD2(SetCallingIdentity, bool(std::string &identity, bool flag)); 71 72 #ifndef CONFIG_IPC_SINGLE 73 MOCK_METHOD0(GetSAMgrObject, sptr<IRemoteObject>()); 74 MOCK_METHOD2(TranslateIRemoteObject, int(int32_t cmd, const sptr<IRemoteObject> &obj)); 75 #endif 76 }; 77 #ifdef CONFIG_IPC_SINGLE 78 } // namespace IPC_SINGLE 79 #endif 80 } // namespace OHOS 81 #endif // OHOS_MOCK_IPC_IREMOTE_INVOKER_H 82