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 #include "watcher_entity.h"
17
18 #include <gtest/gtest.h>
19 #include <thread>
20
21 namespace OHOS::FileManagement::ModuleFileIO::Test {
22
23 class WatcherEntityTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 void SetUp();
28 void TearDown();
29 };
30
SetUpTestCase(void)31 void WatcherEntityTest::SetUpTestCase(void)
32 {
33 GTEST_LOG_(INFO) << "SetUpTestCase";
34 }
35
TearDownTestCase(void)36 void WatcherEntityTest::TearDownTestCase(void)
37 {
38 GTEST_LOG_(INFO) << "TearDownTestCase";
39 }
40
SetUp(void)41 void WatcherEntityTest::SetUp(void)
42 {
43 GTEST_LOG_(INFO) << "SetUp";
44 }
45
TearDown(void)46 void WatcherEntityTest::TearDown(void)
47 {
48 GTEST_LOG_(INFO) << "TearDown";
49 }
50
51 /**
52 * @tc.name: WatcherEntityTest_CloseNotifyFd_001
53 * @tc.desc: Test function of WatcherEntityTest::CloseNotifyFd interface for SUCCESS without close.
54 * @tc.size: MEDIUM
55 * @tc.type: FUNC
56 * @tc.level Level 1
57 */
58 HWTEST_F(WatcherEntityTest, WatcherEntityTest_CloseNotifyFd_001, testing::ext::TestSize.Level1)
59 {
60 GTEST_LOG_(INFO) << "WatcherEntityTest-begin WatcherEntityTest_CloseNotifyFd_001";
61
62 auto &watcher = FileWatcher::GetInstance();
63 watcher.run_ = false;
64 auto ret = watcher.CloseNotifyFd();
65 EXPECT_EQ(ret, 0);
66
67 GTEST_LOG_(INFO) << "WatcherEntityTest-end WatcherEntityTest_CloseNotifyFd_001";
68 }
69
70 /**
71 * @tc.name: WatcherEntityTest_CloseNotifyFd_002
72 * @tc.desc: Test function of WatcherEntityTest::CloseNotifyFd interface for SUCCESS.
73 * @tc.size: MEDIUM
74 * @tc.type: FUNC
75 * @tc.level Level 1
76 */
77 HWTEST_F(WatcherEntityTest, WatcherEntityTest_CloseNotifyFd_002, testing::ext::TestSize.Level1)
78 {
79 GTEST_LOG_(INFO) << "WatcherEntityTest-begin WatcherEntityTest_CloseNotifyFd_002";
80
81 auto &watcher = FileWatcher::GetInstance();
82 watcher.run_ = true;
83 watcher.InitNotify();
84 auto ret = watcher.CloseNotifyFd();
85 EXPECT_EQ(ret, 0);
86
87 GTEST_LOG_(INFO) << "WatcherEntityTest-end WatcherEntityTest_CloseNotifyFd_002";
88 }
89
90 /**
91 * @tc.name: WatcherEntityTest_CloseNotifyFd_003
92 * @tc.desc: Test function of WatcherEntityTest::CloseNotifyFd interface for FAILURE.
93 * @tc.size: MEDIUM
94 * @tc.type: FUNC
95 * @tc.level Level 1
96 */
97 HWTEST_F(WatcherEntityTest, WatcherEntityTest_CloseNotifyFd_003, testing::ext::TestSize.Level1)
98 {
99 GTEST_LOG_(INFO) << "WatcherEntityTest-begin WatcherEntityTest_CloseNotifyFd_003";
100
101 auto &watcher = FileWatcher::GetInstance();
102 watcher.run_ = true;
103 auto ret = watcher.CloseNotifyFd();
104 EXPECT_NE(ret, 0);
105
106 GTEST_LOG_(INFO) << "WatcherEntityTest-end WatcherEntityTest_CloseNotifyFd_003";
107 }
108
109 } // namespace OHOS::FileManagement::ModuleFileIO::Test