1cb7eb8c9Sopenharmony_ci/*
2cb7eb8c9Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3cb7eb8c9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cb7eb8c9Sopenharmony_ci * you may not use this file except in compliance with the License.
5cb7eb8c9Sopenharmony_ci * You may obtain a copy of the License at
6cb7eb8c9Sopenharmony_ci *
7cb7eb8c9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cb7eb8c9Sopenharmony_ci *
9cb7eb8c9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cb7eb8c9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cb7eb8c9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb7eb8c9Sopenharmony_ci * See the License for the specific language governing permissions and
13cb7eb8c9Sopenharmony_ci * limitations under the License.
14cb7eb8c9Sopenharmony_ci */
15cb7eb8c9Sopenharmony_ci
16cb7eb8c9Sopenharmony_ci#ifndef TEST_UNITTESTS_CLOUD_DISK_ASSISTANT_H
17cb7eb8c9Sopenharmony_ci#define TEST_UNITTESTS_CLOUD_DISK_ASSISTANT_H
18cb7eb8c9Sopenharmony_ci
19cb7eb8c9Sopenharmony_ci#include <fuse_lowlevel.h>
20cb7eb8c9Sopenharmony_ci#include <memory>
21cb7eb8c9Sopenharmony_ci#include <gmock/gmock.h>
22cb7eb8c9Sopenharmony_ci
23cb7eb8c9Sopenharmony_cinamespace OHOS::FileManagement::CloudDisk {
24cb7eb8c9Sopenharmony_ciclass Assistant {
25cb7eb8c9Sopenharmony_cipublic:
26cb7eb8c9Sopenharmony_ci    static inline std::shared_ptr<Assistant> ins = nullptr;
27cb7eb8c9Sopenharmony_cipublic:
28cb7eb8c9Sopenharmony_ci    virtual ~Assistant() = default;
29cb7eb8c9Sopenharmony_ci    virtual void *fuse_req_userdata(fuse_req_t) = 0;
30cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_err(fuse_req_t, int) = 0;
31cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_open(fuse_req_t, const struct fuse_file_info *) = 0;
32cb7eb8c9Sopenharmony_ci    virtual void fuse_reply_none(fuse_req_t) = 0;
33cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_data(fuse_req_t, struct fuse_bufvec *, enum fuse_buf_copy_flags) = 0;
34cb7eb8c9Sopenharmony_ci    virtual size_t fuse_buf_size(const struct fuse_bufvec *) = 0;
35cb7eb8c9Sopenharmony_ci    virtual ssize_t fuse_buf_copy(struct fuse_bufvec *, struct fuse_bufvec *, enum fuse_buf_copy_flags) = 0;
36cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_write(fuse_req_t, size_t) = 0;
37cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_lseek(fuse_req_t, off_t) = 0;
38cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_buf(fuse_req_t, const char *, size_t) = 0;
39cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_xattr(fuse_req_t, size_t) = 0;
40cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_attr(fuse_req_t, const struct stat *, double) = 0;
41cb7eb8c9Sopenharmony_ci    virtual int fuse_reply_entry(fuse_req_t, const struct fuse_entry_param *) = 0;
42cb7eb8c9Sopenharmony_ci    static int access(const char *name, int type)
43cb7eb8c9Sopenharmony_ci    {
44cb7eb8c9Sopenharmony_ci        if (strcmp(name, "mock") == 0) {
45cb7eb8c9Sopenharmony_ci            return 0;
46cb7eb8c9Sopenharmony_ci        }
47cb7eb8c9Sopenharmony_ci        return 1;
48cb7eb8c9Sopenharmony_ci    }
49cb7eb8c9Sopenharmony_ci    static int open(const char *file, int oflag)
50cb7eb8c9Sopenharmony_ci    {
51cb7eb8c9Sopenharmony_ci        return 0;
52cb7eb8c9Sopenharmony_ci    }
53cb7eb8c9Sopenharmony_cipublic:
54cb7eb8c9Sopenharmony_ci    virtual off_t lseek(int, off_t, int) = 0;
55cb7eb8c9Sopenharmony_ci};
56cb7eb8c9Sopenharmony_ci
57cb7eb8c9Sopenharmony_ciclass AssistantMock : public Assistant {
58cb7eb8c9Sopenharmony_cipublic:
59cb7eb8c9Sopenharmony_ci    MOCK_METHOD1(fuse_req_userdata, void*(fuse_req_t));
60cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_err, int(fuse_req_t, int));
61cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_open, int(fuse_req_t, const struct fuse_file_info *));
62cb7eb8c9Sopenharmony_ci    MOCK_METHOD1(fuse_reply_none, void(fuse_req_t));
63cb7eb8c9Sopenharmony_ci    MOCK_METHOD3(fuse_reply_data, int(fuse_req_t, struct fuse_bufvec *, enum fuse_buf_copy_flags));
64cb7eb8c9Sopenharmony_ci    MOCK_METHOD1(fuse_buf_size, size_t(const struct fuse_bufvec *));
65cb7eb8c9Sopenharmony_ci    MOCK_METHOD3(fuse_buf_copy, ssize_t(struct fuse_bufvec *, struct fuse_bufvec *, enum fuse_buf_copy_flags));
66cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_write, int(fuse_req_t, size_t));
67cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_lseek, int(fuse_req_t, off_t));
68cb7eb8c9Sopenharmony_ci    MOCK_METHOD3(fuse_reply_buf, int(fuse_req_t, const char *, size_t));
69cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_xattr, int(fuse_req_t, size_t));
70cb7eb8c9Sopenharmony_ci    MOCK_METHOD3(fuse_reply_attr, int(fuse_req_t, const struct stat *, double));
71cb7eb8c9Sopenharmony_ci    MOCK_METHOD2(fuse_reply_entry, int(fuse_req_t, const struct fuse_entry_param *));
72cb7eb8c9Sopenharmony_ci
73cb7eb8c9Sopenharmony_cipublic:
74cb7eb8c9Sopenharmony_ci    MOCK_METHOD3(lseek, off_t(int, off_t, int));
75cb7eb8c9Sopenharmony_ci};
76cb7eb8c9Sopenharmony_ci} // namespace OHOS::FileManagement::CloudDisk
77cb7eb8c9Sopenharmony_ci#endif // TEST_UNITTESTS_CLOUD_DISK_ASSISTANT_H