1 /* 2 * Copyright (C) 2025 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 INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H 17 #define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H 18 19 #include <gmock/gmock.h> 20 #include <sys/inotify.h> 21 22 namespace OHOS { 23 namespace FileManagement { 24 namespace ModuleFileIO { 25 namespace Test { 26 27 class IInotifyMock { 28 public: 29 virtual ~IInotifyMock() = default; 30 virtual int inotify_init() = 0; 31 virtual int inotify_add_watch(int, const char *, uint32_t) = 0; 32 virtual int inotify_rm_watch(int, int) = 0; 33 }; 34 35 class InotifyMock : public IInotifyMock { 36 public: 37 MOCK_METHOD(int, inotify_init, (), (override)); 38 MOCK_METHOD(int, inotify_add_watch, (int, const char *, uint32_t), (override)); 39 MOCK_METHOD(int, inotify_rm_watch, (int, int), (override)); 40 41 public: 42 static std::shared_ptr<InotifyMock> GetMock(); 43 static void EnableMock(); 44 static void DisableMock(); 45 static bool IsMockable(); 46 47 private: 48 static thread_local std::shared_ptr<InotifyMock> inotifyMock; 49 static thread_local bool mockable; 50 }; 51 52 } // namespace Test 53 } // namespace ModuleFileIO 54 } // namespace FileManagement 55 } // namespace OHOS 56 57 #endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H