1 /* 2 * Copyright (C) 2025 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 OHOS_DISTRIBUTED_MESSAGE_PARCEL_MOCK_H 16 #define OHOS_DISTRIBUTED_MESSAGE_PARCEL_MOCK_H 17 18 #include <memory> 19 #include <string> 20 #include <gmock/gmock.h> 21 22 #include "message_parcel.h" 23 #include "iremote_broker.h" 24 25 namespace OHOS::DistributedSchedule { 26 class DmsMessageParcel { 27 public: 28 virtual ~DmsMessageParcel() = default; 29 public: 30 virtual bool WriteInterfaceToken(std::u16string name) = 0; 31 virtual std::u16string ReadInterfaceToken() = 0; 32 virtual bool WriteParcelable(const Parcelable *object) = 0; 33 virtual bool WriteInt32(int32_t value) = 0; 34 virtual int32_t ReadInt32() = 0; 35 virtual bool ReadInt32(int32_t &value) = 0; 36 virtual bool WriteRemoteObject(const Parcelable *object) = 0; 37 virtual bool WriteRemoteObject(const sptr<IRemoteObject> &object) = 0; 38 virtual sptr<IRemoteObject> ReadRemoteObject() = 0; 39 virtual bool ReadBool(); 40 virtual bool ReadBool(bool &value) = 0; 41 virtual bool WriteBool(bool value) = 0; 42 virtual bool WriteString(const std::string &value) = 0; 43 virtual bool WriteFileDescriptor(int fd) = 0; 44 virtual bool ReadString(std::string &value) = 0; 45 virtual int ReadFileDescriptor() = 0; 46 virtual bool ReadStringVector(std::vector<std::string> *value) = 0; 47 virtual bool ReadUint32(uint32_t &value) = 0; 48 public: 49 static inline std::shared_ptr<DmsMessageParcel> messageParcel = nullptr; 50 }; 51 52 class MessageParcelMock : public DmsMessageParcel { 53 public: 54 MOCK_METHOD1(WriteInterfaceToken, bool(std::u16string name)); 55 MOCK_METHOD0(ReadInterfaceToken, std::u16string()); 56 MOCK_METHOD1(WriteParcelable, bool(const Parcelable *object)); 57 MOCK_METHOD1(WriteInt32, bool(int32_t value)); 58 MOCK_METHOD0(ReadInt32, int32_t()); 59 MOCK_METHOD1(ReadInt32, bool(int32_t &value)); 60 MOCK_METHOD1(WriteRemoteObject, bool(const Parcelable *object)); 61 MOCK_METHOD1(WriteRemoteObject, bool(const sptr<IRemoteObject> &object)); 62 MOCK_METHOD0(ReadRemoteObject, sptr<IRemoteObject>()); 63 MOCK_METHOD0(ReadBool, bool()); 64 MOCK_METHOD1(ReadBool, bool(bool &value)); 65 MOCK_METHOD1(WriteBool, bool(bool value)); 66 MOCK_METHOD1(WriteString, bool(const std::string &value)); 67 MOCK_METHOD1(WriteFileDescriptor, bool(int fd)); 68 MOCK_METHOD1(ReadString, bool(std::string &value)); 69 MOCK_METHOD0(ReadFileDescriptor, int()); 70 MOCK_METHOD1(ReadStringVector, bool(std::vector<std::string> *value)); 71 MOCK_METHOD1(ReadUint32, bool(uint32_t &value)); 72 }; 73 } // namespace OHOS::DistributedSchedule 74 #endif // OHOS_DISTRIBUTED_MESSAGE_PARCEL_MOCK_H