1/*
2 * Copyright (c) 2022-2023 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 MOCK_OHOS_BACKUP_PARCEL_H
17#define MOCK_OHOS_BACKUP_PARCEL_H
18
19#include <string>
20
21namespace OHOS::FileManagement::Backup {
22void MockWriteUint32(bool state);
23
24void MockWriteString(bool state, uint8_t count);
25
26void MockWriteParcelable(bool state);
27
28void MockReadParcelable(bool state);
29
30void ResetParcelState();
31
32bool GetMockReadParcelableState();
33
34class Parcelable;
35class Parcel {
36public:
37    Parcel() {}
38    virtual ~Parcel() = default;
39
40    bool WriteUint32(uint32_t);
41
42    bool WriteString(const std::string &);
43
44    bool WriteParcelable(const Parcelable *);
45
46    bool ReadString(std::string &value);
47
48    bool ReadUint32(uint32_t &value);
49
50    template <typename T>
51    T *ReadParcelable()
52    {
53        if (GetMockReadParcelableState()) {
54            return new T();
55        }
56        return nullptr;
57    }
58};
59
60class Parcelable {
61public:
62    Parcelable() = default;
63    virtual ~Parcelable() = default;
64    virtual bool Marshalling(Parcel &parcel) const = 0;
65};
66} // namespace OHOS::FileManagement::Backup
67#endif