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 #ifndef REMOTE_OBJECT_MOCK_H 16 #define REMOTE_OBJECT_MOCK_H 17 18 #include "gmock/gmock.h" 19 #include "iremote_object.h" 20 #include "softbus_common.h" 21 22 namespace OHOS { 23 class RemoteObjectMock : public IRemoteObject { 24 public: 25 static sptr<RemoteObjectMock> Get(); 26 27 RemoteObjectMock(); 28 ~RemoteObjectMock() override; 29 GetObjectRefCount()30 int32_t GetObjectRefCount() override 31 { 32 return 0; 33 } 34 AddDeathRecipient(const sptr<DeathRecipient> & recipient)35 bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override 36 { 37 return true; 38 } 39 RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)40 bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override 41 { 42 return true; 43 } 44 Dump(int fd,const std::vector<std::u16string> & args)45 int Dump(int fd, const std::vector<std::u16string> &args) override 46 { 47 return 0; 48 } 49 50 static void SetSelf(const sptr<RemoteObjectMock>& self); 51 static void Destroy(); 52 static void SetupStub(const sptr<RemoteObjectMock>& self); 53 54 MOCK_METHOD(int, SendRequest, (uint32_t, MessageParcel&, MessageParcel&, MessageOption &), (override)); 55 56 bool GetResult(uint32_t code, const DeviceInfo *deviceInfo = nullptr, int publishId = 0, int subscribeId = 0, 57 int reason = 0); 58 59 static int ActionOfSendRequestForOnDeviceFound(uint32_t code, MessageParcel &data, MessageParcel &reply, 60 MessageOption &option); 61 static int ActionOfSendRequestForOnDiscoveryFailed(uint32_t code, MessageParcel &data, MessageParcel &reply, 62 MessageOption &option); 63 static int ActionOfSendRequestForOnDiscoverySuccess(uint32_t code, MessageParcel &data, MessageParcel &reply, 64 MessageOption &option); 65 static int ActionOfSendRequestForOnPublishSuccess(uint32_t code, MessageParcel &data, MessageParcel &reply, 66 MessageOption &option); 67 static int ActionOfSendRequestForOnPublishFail(uint32_t code, MessageParcel &data, MessageParcel &reply, 68 MessageOption &option); 69 70 private: 71 std::u16string descriptor_; 72 uint32_t code_ {}; 73 DeviceInfo deviceInfo_ {}; 74 int publishId_ {}; 75 int subscribeId_ {}; 76 int reason_ {}; 77 78 static inline sptr<RemoteObjectMock> instance_; 79 }; 80 } 81 #endif