1 /* 2 * Copyright (C) 2024 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_DFS_SERVICE_MESSAGE_PARCEL_MOCK_H 16 #define OHOS_DFS_SERVICE_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::Storage::DistributedFile { 26 class DfsMessageParcel { 27 public: 28 virtual ~DfsMessageParcel() = 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 WriteCString(const char *value) = 0; 44 virtual bool WriteFileDescriptor(int fd) = 0; 45 virtual bool ReadString(std::string &value) = 0; 46 virtual int ReadFileDescriptor() = 0; 47 virtual bool ReadStringVector(std::vector<std::string> *value) = 0; 48 virtual bool ReadUint32(uint32_t &value) = 0; 49 virtual bool WriteUint64(uint64_t value) = 0; 50 virtual bool WriteUint16(uint16_t value) = 0; 51 virtual bool WriteUint32(uint32_t value) = 0; 52 virtual bool ReadUint64(uint64_t &value) = 0; 53 virtual bool WriteStringVector(const std::vector<std::string> &val) = 0; 54 public: 55 static inline std::shared_ptr<DfsMessageParcel> messageParcel = nullptr; 56 }; 57 58 class MessageParcelMock : public DfsMessageParcel { 59 public: 60 MOCK_METHOD1(WriteInterfaceToken, bool(std::u16string name)); 61 MOCK_METHOD0(ReadInterfaceToken, std::u16string()); 62 MOCK_METHOD1(WriteParcelable, bool(const Parcelable *object)); 63 MOCK_METHOD1(WriteInt32, bool(int32_t value)); 64 MOCK_METHOD0(ReadInt32, int32_t()); 65 MOCK_METHOD1(ReadInt32, bool(int32_t &value)); 66 MOCK_METHOD1(WriteRemoteObject, bool(const Parcelable *object)); 67 MOCK_METHOD1(WriteRemoteObject, bool(const sptr<IRemoteObject> &object)); 68 MOCK_METHOD0(ReadRemoteObject, sptr<IRemoteObject>()); 69 MOCK_METHOD0(ReadBool, bool()); 70 MOCK_METHOD1(ReadBool, bool(bool &value)); 71 MOCK_METHOD1(WriteBool, bool(bool value)); 72 MOCK_METHOD1(WriteString, bool(const std::string &value)); 73 MOCK_METHOD1(WriteCString, bool(const char *value)); 74 MOCK_METHOD1(WriteFileDescriptor, bool(int fd)); 75 MOCK_METHOD1(ReadString, bool(std::string &value)); 76 MOCK_METHOD0(ReadFileDescriptor, int()); 77 MOCK_METHOD1(ReadStringVector, bool(std::vector<std::string> *value)); 78 MOCK_METHOD1(ReadUint32, bool(uint32_t &value)); 79 MOCK_METHOD1(WriteUint64, bool(uint64_t value)); 80 MOCK_METHOD1(WriteUint16, bool(uint16_t value)); 81 MOCK_METHOD1(WriteUint32, bool(uint32_t value)); 82 MOCK_METHOD1(ReadUint64, bool(uint64_t &value)); 83 MOCK_METHOD1(WriteStringVector, bool(const std::vector<std::string> &val)); 84 }; 85 } 86 #endif