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_FILEMGMT_BACKUP_MESSAGE_PARCEL_MOCK_H 16 #define OHOS_FILEMGMT_BACKUP_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 #include "b_file_info.h" 25 #include "b_incremental_data.h" 26 27 namespace OHOS::FileManagement::Backup { 28 class BackupIfaceCast { 29 public: 30 virtual ~BackupIfaceCast() = default; 31 virtual sptr<IRemoteBroker> iface_cast(const sptr<IRemoteObject> &) = 0; 32 public: 33 static inline std::shared_ptr<BackupIfaceCast> cast = nullptr; 34 }; 35 36 class IfaceCastMock : public BackupIfaceCast { 37 public: 38 MOCK_METHOD1(iface_cast, sptr<IRemoteBroker>(const sptr<IRemoteObject> &)); 39 }; 40 41 class BackupMessageParcel { 42 public: 43 virtual ~BackupMessageParcel() = default; 44 public: 45 virtual bool WriteInterfaceToken(std::u16string name) = 0; 46 virtual std::u16string ReadInterfaceToken() = 0; 47 virtual bool WriteParcelable(const Parcelable *object) = 0; 48 virtual bool WriteInt32(int32_t value) = 0; 49 virtual int32_t ReadInt32() = 0; 50 virtual bool ReadInt32(int32_t &value) = 0; 51 virtual bool WriteRemoteObject(const Parcelable *object) = 0; 52 virtual bool WriteRemoteObject(const sptr<IRemoteObject> &object) = 0; 53 virtual sptr<IRemoteObject> ReadRemoteObject() = 0; 54 virtual bool ReadBool(); 55 virtual bool ReadBool(bool &value) = 0; 56 virtual bool WriteBool(bool value) = 0; 57 virtual bool WriteString(const std::string &value) = 0; 58 virtual bool WriteFileDescriptor(int fd) = 0; 59 virtual bool ReadString(std::string &value) = 0; 60 virtual int ReadFileDescriptor() = 0; 61 virtual bool ReadStringVector(std::vector<std::string> *value) = 0; 62 virtual bool ReadUint32(uint32_t &value) = 0; 63 public: 64 static inline std::shared_ptr<BackupMessageParcel> messageParcel = nullptr; 65 }; 66 67 class MessageParcelMock : public BackupMessageParcel { 68 public: 69 MOCK_METHOD1(WriteInterfaceToken, bool(std::u16string name)); 70 MOCK_METHOD0(ReadInterfaceToken, std::u16string()); 71 MOCK_METHOD1(WriteParcelable, bool(const Parcelable *object)); 72 MOCK_METHOD1(WriteInt32, bool(int32_t value)); 73 MOCK_METHOD0(ReadInt32, int32_t()); 74 MOCK_METHOD1(ReadInt32, bool(int32_t &value)); 75 MOCK_METHOD1(WriteRemoteObject, bool(const Parcelable *object)); 76 MOCK_METHOD1(WriteRemoteObject, bool(const sptr<IRemoteObject> &object)); 77 MOCK_METHOD0(ReadRemoteObject, sptr<IRemoteObject>()); 78 MOCK_METHOD0(ReadBool, bool()); 79 MOCK_METHOD1(ReadBool, bool(bool &value)); 80 MOCK_METHOD1(WriteBool, bool(bool value)); 81 MOCK_METHOD1(WriteString, bool(const std::string &value)); 82 MOCK_METHOD1(WriteFileDescriptor, bool(int fd)); 83 MOCK_METHOD1(ReadString, bool(std::string &value)); 84 MOCK_METHOD0(ReadFileDescriptor, int()); 85 MOCK_METHOD1(ReadStringVector, bool(std::vector<std::string> *value)); 86 MOCK_METHOD1(ReadUint32, bool(uint32_t &value)); 87 }; 88 } // namespace OHOS::FileManagement::Backup 89 #endif // OHOS_FILEMGMT_BACKUP_MESSAGE_PARCEL_MOCK_H