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 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "file_operations_base.h"
20 #include "cloud_disk_inode.h"
21 #include "file_operations_helper.h"
22 #include "dfs_error.h"
23 #include "assistant.h"
24 
25 namespace OHOS::FileManagement::CloudDisk::Test {
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 
30 class FileOperationBaseTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36     static inline FileOperationsBase* fileoperationBase_ = new FileOperationsBase();
37     static inline shared_ptr<AssistantMock> insMock = nullptr;
38 };
39 
SetUpTestCase(void)40 void FileOperationBaseTest::SetUpTestCase(void)
41 {
42     GTEST_LOG_(INFO) << "SetUpTestCase";
43     insMock = make_shared<AssistantMock>();
44     Assistant::ins = insMock;
45 }
46 
TearDownTestCase(void)47 void FileOperationBaseTest::TearDownTestCase(void)
48 {
49     GTEST_LOG_(INFO) << "TearDownTestCase";
50     fileoperationBase_ = nullptr;
51     Assistant::ins = nullptr;
52     insMock = nullptr;
53 }
54 
SetUp(void)55 void FileOperationBaseTest::SetUp(void)
56 {
57     GTEST_LOG_(INFO) << "SetUp";
58 }
59 
TearDown(void)60 void FileOperationBaseTest::TearDown(void)
61 {
62     GTEST_LOG_(INFO) << "TearDown";
63 }
64 
65 /**
66  * @tc.name: ForgetTest001
67  * @tc.desc: Verify the Forget function
68  * @tc.type: FUNC
69  * @tc.require: issuesI92WQP
70  */
71 HWTEST_F(FileOperationBaseTest, ForgetTest001, TestSize.Level1)
72 {
73     GTEST_LOG_(INFO) << "ForgetTest001 Start";
74     try {
75         CloudDiskFuseData data;
76         EXPECT_CALL(*insMock, fuse_req_userdata(_)).WillOnce(Return(reinterpret_cast<void*>(&data)));
77         fuse_req_t req = nullptr;
78         uint64_t nLookup = 0;
79 
80         fileoperationBase_->Forget(req, FUSE_ROOT_ID, nLookup);
81         EXPECT_TRUE(true);
82     } catch (...) {
83         EXPECT_TRUE(false);
84         GTEST_LOG_(INFO) << "ForgetTest001  ERROR";
85     }
86     GTEST_LOG_(INFO) << "ForgetTest001 End";
87 }
88 
89 /**
90  * @tc.name: ForgetTest002
91  * @tc.desc: Verify the Forget function
92  * @tc.type: FUNC
93  * @tc.require: issuesI92WQP
94  */
95 HWTEST_F(FileOperationBaseTest, ForgetTest002, TestSize.Level1)
96 {
97     GTEST_LOG_(INFO) << "ForgetTest002 Start";
98     try {
99         CloudDiskFuseData data;
100         EXPECT_CALL(*insMock, fuse_req_userdata(_)).WillOnce(Return(reinterpret_cast<void*>(&data)));
101         fuse_req_t req = nullptr;
102         uint64_t nLookup = 0;
103 
104         fileoperationBase_->Forget(req, 0, nLookup);
105         EXPECT_TRUE(true);
106     } catch (...) {
107         EXPECT_TRUE(false);
108         GTEST_LOG_(INFO) << "ForgetTest002  ERROR";
109     }
110     GTEST_LOG_(INFO) << "ForgetTest002 End";
111 }
112 
113 /**
114  * @tc.name: ForgetMultiTest001
115  * @tc.desc: Verify the ForgetMulti function
116  * @tc.type: FUNC
117  * @tc.require: issuesI92WQP
118  */
119 HWTEST_F(FileOperationBaseTest, ForgetMultiTest001, TestSize.Level1)
120 {
121     GTEST_LOG_(INFO) << "ForgetMultiTest001 Start";
122     try {
123         CloudDiskFuseData data;
124         EXPECT_CALL(*insMock, fuse_req_userdata(_)).WillOnce(Return(reinterpret_cast<void*>(&data)));
125         fuse_req_t req = nullptr;
126         fuse_forget_data* forgets = nullptr;
127 
128         fileoperationBase_->ForgetMulti(req, 0, forgets);
129         EXPECT_TRUE(true);
130     } catch (...) {
131         EXPECT_TRUE(false);
132         GTEST_LOG_(INFO) << "ForgetMultiTest001  ERROR";
133     }
134     GTEST_LOG_(INFO) << "ForgetMultiTest001 End";
135 }
136 } // namespace OHOS::FileManagement::CloudDisk::Test