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 
16 #ifndef FILEMANAGEMENT_DFS_SERVICE_LIBRARY_FUNC_MOCK_H
17 #define FILEMANAGEMENT_DFS_SERVICE_LIBRARY_FUNC_MOCK_H
18 
19 #include <cstdlib>
20 #include <dlfcn.h>
21 #include <memory>
22 
23 #include "gmock/gmock.h"
24 
25 namespace OHOS {
26 namespace Storage {
27 namespace DistributedFile {
28 class LibraryFunc {
29 public:
30     virtual ~LibraryFunc() = default;
31 
32     virtual void *dlopen(const char *file, int mode) = 0;
33     virtual int dlclose(void *handle) = 0;
34     virtual void *dlsym(void *__restrict handle, const char *__restrict name) = 0;
35     virtual char *realpath(const char *__restrict path, char *__restrict resolved_path) = 0;
36 
37 public:
38     static inline std::shared_ptr<LibraryFunc> libraryFunc_ = nullptr;
39 };
40 
41 class LibraryFuncMock : public LibraryFunc {
42 public:
43     MOCK_METHOD2(dlopen, void *(const char *file, int mode));
44     MOCK_METHOD1(dlclose, int(void *handle));
45     MOCK_METHOD2(dlsym, void *(void *__restrict handle, const char *__restrict name));
46     MOCK_METHOD2(realpath, char *(const char *__restrict path, char *__restrict resolved_path));
47 };
48 } // namespace DistributedFile
49 } // namespace Storage
50 } // namespace OHOS
51 
52 #endif // FILEMANAGEMENT_DFS_SERVICE_LIBRARY_FUNC_MOCK_H
53