• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "file_sync_core.h"
17 
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include <sys/types.h>
21 #include <sys/xattr.h>
22 
23 #include "cloud_sync_manager.h"
24 #include "dfs_error.h"
25 #include "uri.h"
26 #include "utils_log.h"
27 
28 namespace OHOS::FileManagement::CloudDisk::Test {
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace std;
32 using namespace OHOS::FileManagement::CloudSync;
33 
34 class FileSyncCoreTest : public testing::Test {
35 public:
36     static void SetUpTestCase(void);
37     static void TearDownTestCase(void);
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase(void)42 void FileSyncCoreTest::SetUpTestCase(void)
43 {
44     GTEST_LOG_(INFO) << "SetUpTestCase";
45 }
46 
TearDownTestCase(void)47 void FileSyncCoreTest::TearDownTestCase(void)
48 {
49     GTEST_LOG_(INFO) << "TearDownTestCase";
50 }
51 
SetUp(void)52 void FileSyncCoreTest::SetUp(void)
53 {
54     GTEST_LOG_(INFO) << "SetUp";
55 }
56 
TearDown(void)57 void FileSyncCoreTest::TearDown(void)
58 {
59     GTEST_LOG_(INFO) << "TearDown";
60 }
61 
62 /**
63  * @tc.name: Constructor
64  * @tc.desc: Verify the FileSyncCore::Constructor function
65  * @tc.type: FUNC
66  * @tc.require: issueIC7I52
67  */
68 HWTEST_F(FileSyncCoreTest, ConstructorTest1, TestSize.Level1)
69 {
70     auto data = FileSyncCore::Constructor();
71     EXPECT_TRUE(data.IsSuccess());
72 }
73 
74 /**
75  * @tc.name: Constructor
76  * @tc.desc: Verify the FileSyncCore::Constructor function
77  * @tc.type: FUNC
78  * @tc.require: issueIC7I52
79  */
80 HWTEST_F(FileSyncCoreTest, ConstructorTest2, TestSize.Level1)
81 {
82     std::string bundleName = "com.example.test";
83     auto data = FileSyncCore::Constructor(bundleName);
84     EXPECT_TRUE(data.IsSuccess());
85 }
86 
87 /**
88  * @tc.name: Constructor
89  * @tc.desc: Verify the FileSyncCore::Constructor function
90  * @tc.type: FUNC
91  * @tc.require: issueIC7I52
92  */
93 HWTEST_F(FileSyncCoreTest, ConstructorTest3, TestSize.Level1)
94 {
95     std::string bundleName = "";
96     auto data = FileSyncCore::Constructor(bundleName);
97     EXPECT_FALSE(data.IsSuccess());
98 }
99 
100 /**
101  * @tc.name: GetBundleName
102  * @tc.desc: Verify the FileSyncCore::GetBundleName function
103  * @tc.type: FUNC
104  * @tc.require: issueIC7I52
105  */
106 HWTEST_F(FileSyncCoreTest, GetBundleNameTest1, TestSize.Level1)
107 {
108     const FileSyncCore *fileSync = FileSyncCore::Constructor().GetData().value();
109     string ret = fileSync->GetBundleName();
110     EXPECT_EQ(ret, "");
111 }
112 
113 /**
114  * @tc.name: GetBundleName
115  * @tc.desc: Verify the FileSyncCore::GetBundleName function
116  * @tc.type: FUNC
117  * @tc.require: issueIC7I52
118  */
119 HWTEST_F(FileSyncCoreTest, GetBundleNameTest2, TestSize.Level1)
120 {
121     std::string bundleName = "com.example.test";
122     const FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
123     string ret = fileSync->GetBundleName();
124     EXPECT_EQ(ret, bundleName);
125 }
126 
127 /**
128  * @tc.name: DoOn
129  * @tc.desc: Verify the FileSyncCore::DoOn function
130  * @tc.type: FUNC
131  * @tc.require: issueIC7I52
132  */
133 HWTEST_F(FileSyncCoreTest, DoOnTest1, TestSize.Level1)
134 {
135     std::string bundleName = "com.example.test";
136     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
137     auto callback = std::make_shared<CloudSyncCallbackAniImpl>(nullptr, nullptr);
138     std::string event = "";
139     auto ret = fileSync->DoOn(event, callback);
140     EXPECT_FALSE(ret.IsSuccess());
141     const auto &err = ret.GetError();
142     int errorCode = err.GetErrNo();
143     EXPECT_EQ(errorCode, E_PARAMS);
144 }
145 
146 /**
147  * @tc.name: DoOn
148  * @tc.desc: Verify the FileSyncCore::DoOn function
149  * @tc.type: FUNC
150  * @tc.require: issueIC7I52
151  */
152 HWTEST_F(FileSyncCoreTest, DoOnTest2, TestSize.Level1)
153 {
154     std::string bundleName = "com.example.test";
155     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
156     auto callback = std::make_shared<CloudSyncCallbackAniImpl>(nullptr, nullptr);
157     std::string event = "";
158     auto ret = fileSync->DoOn(event, callback);
159     EXPECT_FALSE(ret.IsSuccess());
160     const auto &err = ret.GetError();
161     int errorCode = err.GetErrNo();
162     EXPECT_EQ(errorCode, E_PARAMS);
163     ret = fileSync->DoOff(event);
164     EXPECT_FALSE(ret.IsSuccess());
165     const auto &error = ret.GetError();
166     errorCode = error.GetErrNo();
167     EXPECT_EQ(errorCode, E_PARAMS);
168 }
169 
170 /**
171  * @tc.name: DoOff
172  * @tc.desc: Verify the FileSyncCore::DoOff function
173  * @tc.type: FUNC
174  * @tc.require: issueIC7I52
175  */
176 HWTEST_F(FileSyncCoreTest, DoOffTest1, TestSize.Level1)
177 {
178     std::string bundleName = "com.example.test";
179     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
180     std::string event = "progress";
181     auto ret = fileSync->DoOff(event);
182     EXPECT_FALSE(ret.IsSuccess());
183     const auto &err = ret.GetError();
184     int errorCode = err.GetErrNo();
185     EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
186 }
187 
188 /**
189  * @tc.name: DoOff
190  * @tc.desc: Verify the FileSyncCore::DoOff function
191  * @tc.type: FUNC
192  * @tc.require: issueIC7I52
193  */
194 HWTEST_F(FileSyncCoreTest, DoOffTest2, TestSize.Level1)
195 {
196     std::string bundleName = "com.example.test";
197     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
198     std::string event = "";
199     auto ret = fileSync->DoOff(event);
200     EXPECT_FALSE(ret.IsSuccess());
201     const auto &err = ret.GetError();
202     int errorCode = err.GetErrNo();
203     EXPECT_EQ(errorCode, E_PARAMS);
204 }
205 
206 /**
207  * @tc.name: DoStart
208  * @tc.desc: Verify the FileSyncCore::DoStart function
209  * @tc.type: FUNC
210  * @tc.require: issueIC7I52
211  */
212 HWTEST_F(FileSyncCoreTest, DoStartTest1, TestSize.Level1)
213 {
214     std::string bundleName = "com.example.test";
215     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
216     auto ret = fileSync->DoStart();
217     EXPECT_FALSE(ret.IsSuccess());
218     const auto &err = ret.GetError();
219     int errorCode = err.GetErrNo();
220     EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
221 }
222 
223 /**
224  * @tc.name: DoStart
225  * @tc.desc: Verify the FileSyncCore::DoStart function
226  * @tc.type: FUNC
227  * @tc.require: issueIC7I52
228  */
229 HWTEST_F(FileSyncCoreTest, DoStartTest2, TestSize.Level1)
230 {
231     std::string bundleName = "com.example.test";
232     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
233     auto ret = fileSync->DoStart();
234     EXPECT_FALSE(ret.IsSuccess());
235     const auto &err = ret.GetError();
236     int errorCode = err.GetErrNo();
237     EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
238     ret = fileSync->DoStop();
239     EXPECT_FALSE(ret.IsSuccess());
240     const auto &error = ret.GetError();
241     errorCode = error.GetErrNo();
242     EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
243 }
244 
245 /**
246  * @tc.name: DoStop
247  * @tc.desc: Verify the FileSyncCore::DoStop function
248  * @tc.type: FUNC
249  * @tc.require: issueIC7I52
250  */
251 HWTEST_F(FileSyncCoreTest, DoStopTest1, TestSize.Level1)
252 {
253     std::string bundleName = "com.example.test";
254     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
255     auto ret = fileSync->DoStop();
256     EXPECT_FALSE(ret.IsSuccess());
257     const auto &err = ret.GetError();
258     int errorCode = err.GetErrNo();
259     EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
260 }
261 
262 /**
263  * @tc.name: DoGetLastSyncTime
264  * @tc.desc: Verify the FileSyncCore::DoGetLastSyncTime function
265  * @tc.type: FUNC
266  * @tc.require: issueIC7I52
267  */
268 HWTEST_F(FileSyncCoreTest, DoGetLastSyncTimeTest1, TestSize.Level1)
269 {
270     std::string bundleName = "com.example.test";
271     FileSyncCore *fileSync = FileSyncCore::Constructor(bundleName).GetData().value();
272     auto ret = fileSync->DoGetLastSyncTime();
273     EXPECT_FALSE(ret.IsSuccess());
274 }
275 } // namespace OHOS::FileManagement::CloudDisk::Test