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 TEST_UNITTESTS_CLOUD_FILE_FUSEASSISTANT_H 17 #define TEST_UNITTESTS_CLOUD_FILE_FUSEASSISTANT_H 18 #ifndef FUSE_USE_VERSION 19 #define FUSE_USE_VERSION 30 20 #endif 21 22 #include <fuse_lowlevel.h> 23 #include <fuse_opt.h> 24 #include <gmock/gmock.h> 25 #include <memory> 26 27 namespace OHOS::FileManagement::CloudFile { 28 class FuseAssistant { 29 public: 30 virtual ~FuseAssistant() = default; 31 virtual int fuse_opt_add_arg(struct fuse_args *args, const char *arg) = 0; 32 virtual struct fuse_session* fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, 33 size_t opSize, void *userData) = 0; 34 virtual void fuse_session_destroy(struct fuse_session *se) = 0; 35 virtual int mkdir(const char* path, mode_t mode) = 0; 36 virtual int chown(const char *path, uid_t owner, gid_t group) = 0; 37 virtual int chmod(const char *path, mode_t mode) = 0; 38 virtual void HandleStartMove(int32_t userId) = 0; 39 static inline std::shared_ptr<FuseAssistant> ins = nullptr; 40 static inline bool mockable = false; 41 }; 42 43 class FuseAssistantMock : public FuseAssistant { 44 public: 45 MOCK_METHOD2(fuse_opt_add_arg, int(struct fuse_args *args, const char *arg)); 46 MOCK_METHOD4(fuse_session_new, struct fuse_session*(struct fuse_args *args, const struct fuse_lowlevel_ops *op, 47 size_t opSize, void *userData)); 48 MOCK_METHOD1(fuse_session_destroy, void(struct fuse_session *se)); 49 MOCK_METHOD2(mkdir, int(const char* path, mode_t mode)); 50 MOCK_METHOD3(chown, int(const char * path, uid_t owner, gid_t group)); 51 MOCK_METHOD2(chmod, int(const char * path, mode_t mode)); 52 MOCK_METHOD1(HandleStartMove, void(int32_t userId)); 53 54 public: 55 static void EnableMock(); 56 static void DisableMock(); 57 static bool IsMockable(); 58 }; 59 } // namespace OHOS::FileManagement::CloudDisk 60 #endif // TEST_UNITTESTS_CLOUD_FILE_FUSEASSISTANT_H