1 /*
2 * Copyright (c) 2023 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 #include "cloud_disk_data_handler.h"
19 #include "cloud_disk_data_syncer.h"
20 #include "clouddisk_rdbstore.h"
21 #include "dfs_error.h"
22 #include "rdb_store_mock.h"
23
24 namespace OHOS {
25 namespace FileManagement::CloudSync {
26 namespace Test {
27 using namespace testing::ext;
28 using namespace testing;
29 using namespace std;
30
31 enum {
32 BEGIN,
33 DOWNLOADFILE,
34 COMPLETEPULL,
35 UPLOADFILE,
36 COMPLETEPUSH,
37 END
38 };
39
40 class CloudDiskDataSyncerTest : public testing::Test {
41 public:
42 static void SetUpTestCase(void);
43 static void TearDownTestCase(void);
44 void SetUp();
45 void TearDown();
46 };
47
SetUpTestCase(void)48 void CloudDiskDataSyncerTest::SetUpTestCase(void)
49 {
50 GTEST_LOG_(INFO) << "SetUpTestCase";
51 }
52
TearDownTestCase(void)53 void CloudDiskDataSyncerTest::TearDownTestCase(void)
54 {
55 GTEST_LOG_(INFO) << "TearDownTestCase";
56 }
57
SetUp(void)58 void CloudDiskDataSyncerTest::SetUp(void)
59 {
60 GTEST_LOG_(INFO) << "SetUp";
61 }
62
TearDown(void)63 void CloudDiskDataSyncerTest::TearDown(void)
64 {
65 GTEST_LOG_(INFO) << "TearDown";
66 }
67
68 /**
69 * @tc.name: InitTest001
70 * @tc.desc: Verify the Init function.
71 * @tc.type: FUNC
72 * @tc.require: I6H5MH
73 */
74 HWTEST_F(CloudDiskDataSyncerTest, InitTest001, TestSize.Level1)
75 {
76 GTEST_LOG_(INFO) << "Init Start";
77 string bundleName = "com.ohos.test";
78 const int32_t userId = 100;
79 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
80 int result = cloudDiskDataSyncer.Init(bundleName, userId);
81 EXPECT_EQ(result, E_OK);
82 GTEST_LOG_(INFO) << "Init End";
83 }
84
85 /**
86 * @tc.name: CleanTest001
87 * @tc.desc: Verify the Clean function.
88 * @tc.type: FUNC
89 * @tc.require: I6H5MH
90 */
91 HWTEST_F(CloudDiskDataSyncerTest, CleanTest001, TestSize.Level1)
92 {
93 GTEST_LOG_(INFO) << "Clean Start";
94 const string bundleName = "bundleName";
95 const int32_t userId = 100;
96 const int action = 0;
97 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
98 int result = cloudDiskDataSyncer.Clean(action);
99 EXPECT_EQ(result, E_OK);
100 GTEST_LOG_(INFO) << "Clean End";
101 }
102
103 /**
104 * @tc.name: StartDownloadFileTest001
105 * @tc.desc: Verify the StartDownloadFile function.
106 * @tc.type: FUNC
107 * @tc.require: I6H5MH
108 */
109 HWTEST_F(CloudDiskDataSyncerTest, StartDownloadFileTest001, TestSize.Level1)
110 {
111 GTEST_LOG_(INFO) << "StartDownloadFile Start";
112 const string path = "";
113 const string bundleName = "bundleName";
114 const int32_t userId = 100;
115 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
116 int32_t result = cloudDiskDataSyncer.StartDownloadFile(path, userId);
117 EXPECT_EQ(result, E_OK);
118 GTEST_LOG_(INFO) << "StartDownloadFile End";
119 }
120
121 /**
122 * @tc.name: StopDownloadFileTest001
123 * @tc.desc: Verify the StopDownloadFile function.
124 * @tc.type: FUNC
125 * @tc.require: I6H5MH
126 */
127 HWTEST_F(CloudDiskDataSyncerTest, StopDownloadFileTest001, TestSize.Level1)
128 {
129 GTEST_LOG_(INFO) << "StopDownloadFile Start";
130 const string path = "";
131 const string bundleName = "bundleName";
132 const int32_t userId = 100;
133 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
134 int32_t result = cloudDiskDataSyncer.StopDownloadFile(path, userId);
135 EXPECT_EQ(result, E_OK);
136 GTEST_LOG_(INFO) << "StopDownloadFile End";
137 }
138
139 /**
140 * @tc.name: CleanCacheTest001
141 * @tc.desc: Verify the CleanCache function.
142 * @tc.type: FUNC
143 * @tc.require: I6H5MH
144 */
145 HWTEST_F(CloudDiskDataSyncerTest, CleanCacheTest001, TestSize.Level1)
146 {
147 GTEST_LOG_(INFO) << "CleanCache Start";
148 const int32_t userId = 100;
149 const string bundleName = "bundleName";
150 string uri = "sample_uri";
151 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
152 int32_t result = cloudDiskDataSyncer.Init(bundleName, userId);
153 EXPECT_EQ(result, E_OK);
154 result = cloudDiskDataSyncer.CleanCache(uri);
155 EXPECT_EQ(result, 2);
156 GTEST_LOG_(INFO) << "CleanCache End";
157 }
158
159 /**
160 * @tc.name: ScheduleTest001
161 * @tc.desc: Verify the Schedule function.
162 * @tc.size: MEDIUM
163 * @tc.type: FUNC
164 * @tc.level Level 1
165 */
166 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest001, TestSize.Level1)
167 {
168 GTEST_LOG_(INFO) << "Schedule Start";
169 string bundleName = "com.ohos.test";
170 const int32_t userId = 100;
171 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
172 cloudDiskDataSyncer.stage_ = BEGIN;
173 cloudDiskDataSyncer.Schedule();
174 EXPECT_EQ(cloudDiskDataSyncer.stage_, DOWNLOADFILE);
175 GTEST_LOG_(INFO) << "Schedule End";
176 }
177
178 /**
179 * @tc.name: ScheduleTest002
180 * @tc.desc: Verify the Schedule function.
181 * @tc.size: MEDIUM
182 * @tc.type: FUNC
183 * @tc.level Level 1
184 */
185 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest002, TestSize.Level1)
186 {
187 GTEST_LOG_(INFO) << "Schedule Start";
188 string bundleName = "com.ohos.test";
189 const int32_t userId = 100;
190 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
191 cloudDiskDataSyncer.stage_ = DOWNLOADFILE;
192 cloudDiskDataSyncer.Schedule();
193 EXPECT_EQ(cloudDiskDataSyncer.stage_, COMPLETEPULL);
194 GTEST_LOG_(INFO) << "Schedule End";
195 }
196
197 /**
198 * @tc.name: ScheduleTest003
199 * @tc.desc: Verify the Schedule function.
200 * @tc.size: MEDIUM
201 * @tc.type: FUNC
202 * @tc.level Level 1
203 */
204 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest003, TestSize.Level1)
205 {
206 GTEST_LOG_(INFO) << "Schedule Start";
207 string bundleName = "com.ohos.test";
208 const int32_t userId = 100;
209 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
210 cloudDiskDataSyncer.stage_ = COMPLETEPULL;
211 cloudDiskDataSyncer.Schedule();
212 EXPECT_EQ(cloudDiskDataSyncer.stage_, UPLOADFILE);
213 GTEST_LOG_(INFO) << "Schedule End";
214 }
215
216 /**
217 * @tc.name: ScheduleTest004
218 * @tc.desc: Verify the Schedule function.
219 * @tc.type: FUNC
220 * @tc.require: I6H5MH
221 */
222 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest004, TestSize.Level1)
223 {
224 GTEST_LOG_(INFO) << "Schedule Start";
225 string bundleName = "com.ohos.test";
226 const int32_t userId = 100;
227 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
228 cloudDiskDataSyncer.stage_ = UPLOADFILE;
229 cloudDiskDataSyncer.Schedule();
230 EXPECT_EQ(cloudDiskDataSyncer.stage_, COMPLETEPUSH);
231 GTEST_LOG_(INFO) << "Schedule End";
232 }
233
234 /**
235 * @tc.name: ScheduleTest005
236 * @tc.desc: Verify the Schedule function.
237 * @tc.type: FUNC
238 * @tc.require: I6H5MH
239 */
240 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest005, TestSize.Level1)
241 {
242 GTEST_LOG_(INFO) << "Schedule Start";
243 string bundleName = "com.ohos.test";
244 const int32_t userId = 100;
245 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
246 cloudDiskDataSyncer.stage_ = COMPLETEPUSH;
247 cloudDiskDataSyncer.Schedule();
248 EXPECT_EQ(cloudDiskDataSyncer.stage_, END);
249 GTEST_LOG_(INFO) << "Schedule End";
250 }
251
252 /**
253 * @tc.name: ScheduleTest006
254 * @tc.desc: Verify the Schedule function.
255 * @tc.type: FUNC
256 * @tc.require: I6H5MH
257 */
258 HWTEST_F(CloudDiskDataSyncerTest, ScheduleTest006, TestSize.Level1)
259 {
260 GTEST_LOG_(INFO) << "Schedule Start";
261 string bundleName = "com.ohos.test";
262 const int32_t userId = 100;
263 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
264 cloudDiskDataSyncer.stage_ = END;
265 std::shared_ptr<SdkHelper> sdkHelper = make_shared<SdkHelper>();
266 cloudDiskDataSyncer.SetSdkHelper(sdkHelper);
267 cloudDiskDataSyncer.Schedule();
268 EXPECT_EQ(cloudDiskDataSyncer.stage_, 6);
269 GTEST_LOG_(INFO) << "Schedule End";
270 }
271
272 /**
273 * @tc.name: ResetTest001
274 * @tc.desc: Verify the Reset function.
275 * @tc.size: MEDIUM
276 * @tc.type: FUNC
277 * @tc.level Level 1
278 */
279 HWTEST_F(CloudDiskDataSyncerTest, ResetTest001, TestSize.Level1)
280 {
281 GTEST_LOG_(INFO) << "Reset Start";
282 string bundleName = "com.ohos.test";
283 const int32_t userId = 100;
284 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
285 int result = cloudDiskDataSyncer.Init(bundleName, userId);
286 EXPECT_EQ(result, E_OK);
287 cloudDiskDataSyncer.Reset();
288 EXPECT_EQ(cloudDiskDataSyncer.stage_, BEGIN);
289 GTEST_LOG_(INFO) << "Reset End";
290 }
291
292 /**
293 * @tc.name: DownloadFileTest001
294 * @tc.desc: Verify the DownloadFile function.
295 * @tc.type: FUNC
296 * @tc.require: I6H5MH
297 */
298 HWTEST_F(CloudDiskDataSyncerTest, DownloadFileTest001, TestSize.Level1)
299 {
300 GTEST_LOG_(INFO) << "DownloadFile Start";
301 const string bundleName = "bundleName";
302 const int32_t userId = 100;
303 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
304 int result = cloudDiskDataSyncer.DownloadFile();
305 EXPECT_EQ(result, E_OK);
306 GTEST_LOG_(INFO) << "DownloadFile End";
307 }
308
309 /**
310 * @tc.name: UploadFileTest001
311 * @tc.desc: Verify the UploadFile function.
312 * @tc.type: FUNC
313 * @tc.require: I6H5MH
314 */
315 HWTEST_F(CloudDiskDataSyncerTest, UploadFileTest001, TestSize.Level1)
316 {
317 GTEST_LOG_(INFO) << "UploadFile Start";
318 const string bundleName = "bundleName";
319 const int32_t userId = 100;
320 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
321 int32_t result = cloudDiskDataSyncer.UploadFile();
322 EXPECT_EQ(result, E_OK);
323 GTEST_LOG_(INFO) << "UploadFile End";
324 }
325
326 /**
327 * @tc.name: CompleteTest001
328 * @tc.desc: Verify the Complete function.
329 * @tc.type: FUNC
330 * @tc.require: I6H5MH
331 */
332 HWTEST_F(CloudDiskDataSyncerTest, CompleteTest001, TestSize.Level1)
333 {
334 GTEST_LOG_(INFO) << "Complete Start";
335 const string bundleName = "bundleName";
336 const int32_t userId = 100;
337 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
338 std::shared_ptr<SdkHelper> sdkHelper = make_shared<SdkHelper>();
339 cloudDiskDataSyncer.SetSdkHelper(sdkHelper);
340 int32_t result = cloudDiskDataSyncer.Complete();
341 EXPECT_EQ(result, E_OK);
342 GTEST_LOG_(INFO) << "Complete End";
343 }
344
345 /**
346 * @tc.name: ChangesNotifyTest001
347 * @tc.desc: Verify the ChangesNotify function.
348 * @tc.type: FUNC
349 * @tc.require: I6H5MH
350 */
351 HWTEST_F(CloudDiskDataSyncerTest, ChangesNotifyTest001, TestSize.Level1)
352 {
353 GTEST_LOG_(INFO) << "ChangesNotify Start";
354 const string bundleName = "bundleName";
355 const int32_t userId = 100;
356 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
357 std::shared_ptr<SdkHelper> sdkHelper = make_shared<SdkHelper>();
358 cloudDiskDataSyncer.SetSdkHelper(sdkHelper);
359 cloudDiskDataSyncer.ChangesNotify();
360 EXPECT_TRUE(true);
361 GTEST_LOG_(INFO) << "ChangesNotify End";
362 }
363
364 /**
365 * @tc.name: ScheduleByTypeTest001
366 * @tc.desc: Verify the ScheduleByType function.
367 * @tc.type: FUNC
368 * @tc.require: I6H5MH
369 */
370 HWTEST_F(CloudDiskDataSyncerTest, ScheduleByTypeTest001, TestSize.Level1)
371 {
372 GTEST_LOG_(INFO) << "ScheduleByType Start";
373 const string bundleName = "bundleName";
374 const int32_t userId = 100;
375 CloudDiskDataSyncer cloudDiskDataSyncer(bundleName, userId);
376 cloudDiskDataSyncer.ScheduleByType(SyncTriggerType::APP_TRIGGER);
377 GTEST_LOG_(INFO) << "ScheduleByType End";
378 }
379
380 } // namespace Test
381 } // namespace FileManagement::CloudSync
382 } // namespace OHOS
383