• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
19 
20 #include "data_sync/data_syncer.h"
21 
22 #include "data_sync_manager.h"
23 #include "gallery_data_syncer.h"
24 
25 #include "data_handler_method_mock.h"
26 #include "dfs_error.h"
27 #include "dk_error.h"
28 #include "gallery_data_syncer.h"
29 #include "gmock/gmock-actions.h"
30 #include "sync_rule/battery_status.h"
31 #include "sync_rule/cloud_status.h"
32 
33 namespace OHOS::FileManagement::CloudSync::Test {
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace std;
37 
38 class DataSyncerMock final : public DataSyncer {
39 public:
40     DataSyncerMock(const string bundleName, const int32_t userId);
41     MOCK_METHOD0(Schedule, void());
42     MOCK_METHOD0(Reset, void());
43     MOCK_METHOD1(ScheduleByType, void(SyncTriggerType syncTriggerType));
44     MOCK_METHOD1(Complete, int(bool));
45 };
46 
DataSyncerMock(const string bundleName,const int32_t userId)47 DataSyncerMock::DataSyncerMock(const string bundleName, const int32_t userId) : DataSyncer("com.ohos.test", 100) {}
48 
49 class DataSyncerTest : public testing::Test {
50 public:
51     static void SetUpTestCase(void);
52     static void TearDownTestCase(void);
53     void SetUp();
54     void TearDown();
55     static inline shared_ptr<DataSyncManager> dataSyncManager_;
56     static inline shared_ptr<DataSyncerMock> datasyncer_;
57     static inline shared_ptr<GalleryDataSyncer> galleryDataSyncer_;
58     static inline shared_ptr<FileDataHandler> handler_;
59     static inline shared_ptr<DataHandlerMethodMock> dataHandler_;
60 };
61 
SetUpTestCase(void)62 void DataSyncerTest::SetUpTestCase(void)
63 {
64     GTEST_LOG_(INFO) << "SetUpTestCase";
65     const int32_t userId = 100;
66     const string bundleName = "com.ohos.test";
67     datasyncer_ = make_shared<DataSyncerMock>(bundleName, userId);
68     EXPECT_CALL(*datasyncer_, Schedule()).Times(testing::AnyNumber());
69     EXPECT_CALL(*datasyncer_, Reset()).Times(testing::AnyNumber());
70     dataSyncManager_ = make_shared<DataSyncManager>();
71     auto sdkHelper = make_shared<SdkHelper>();
72     datasyncer_->SetSdkHelper(sdkHelper);
73     string test = "test";
74     dataHandler_ = make_shared<DataHandlerMethodMock>(userId, test, test);
75     EXPECT_CALL(*dataHandler_, GetFetchCondition(_)).Times(testing::AnyNumber());
76     EXPECT_CALL(*dataHandler_, FinishPull(_)).Times(testing::AnyNumber());
77     EXPECT_CALL(*dataHandler_, GetTempStartCursor(_)).Times(testing::AnyNumber());
78     EXPECT_CALL(*dataHandler_, GetNextCursor(_)).Times(testing::AnyNumber());
79     EXPECT_CALL(*dataHandler_, SetTempStartCursor(_)).Times(testing::AnyNumber());
80     EXPECT_CALL(*dataHandler_, SetTempNextCursor(_, _)).Times(testing::AnyNumber());
81 }
82 
TearDownTestCase(void)83 void DataSyncerTest::TearDownTestCase(void)
84 {
85     GTEST_LOG_(INFO) << "TearDownTestCase";
86     dataSyncManager_ = nullptr;
87     datasyncer_ = nullptr;
88     galleryDataSyncer_ = nullptr;
89     handler_ = nullptr;
90     dataHandler_ = nullptr;
91 }
92 
SetUp(void)93 void DataSyncerTest::SetUp(void) {}
94 
TearDown(void)95 void DataSyncerTest::TearDown(void) {}
96 
97 /**
98  * @tc.name: AsyncRunTest
99  * @tc.desc: Verify the AsyncRun function
100  * @tc.type: FUNC
101  * @tc.require: #I7UU3Z
102  */
103 HWTEST_F(DataSyncerTest, AsyncRunTest, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "AsyncRun Start";
106     shared_ptr<SdkHelper> sdkHelper;
107     try {
108         datasyncer_->AsyncRun({}, {});
109         EXPECT_TRUE(true);
110     } catch (...) {
111         EXPECT_TRUE(false);
112         GTEST_LOG_(INFO) << "AsyncRun FAILED";
113     }
114     GTEST_LOG_(INFO) << "AsyncRun end";
115 }
116 
117 /**
118  * @tc.name: StartSyncTest
119  * @tc.desc: Verify the StartSync function
120  * @tc.type: FUNC
121  * @tc.require: #I7UU3Z
122  */
123 HWTEST_F(DataSyncerTest, StartSyncTest, TestSize.Level1)
124 {
125     GTEST_LOG_(INFO) << "StartSync Start";
126     bool forceFlag = false;
127     int res = datasyncer_->StartSync(forceFlag, SyncTriggerType::PENDING_TRIGGER);
128     EXPECT_EQ(res, E_OK);
129     GTEST_LOG_(INFO) << "StartSync end";
130 }
131 
132 /**
133  * @tc.name: StartSyncErrTest
134  * @tc.desc: Verify the StartSync function
135  * @tc.type: FUNC
136  * @tc.require: #I7UU3Z
137  */
138 HWTEST_F(DataSyncerTest, StartSyncErrTest, TestSize.Level1)
139 {
140     GTEST_LOG_(INFO) << "StartSync Start";
141     try {
142         bool forceFlag = true;
143         int res = datasyncer_->StartSync(forceFlag, SyncTriggerType::PENDING_TRIGGER);
144         EXPECT_EQ(res, E_PENDING);
145     } catch (...) {
146         EXPECT_TRUE(false);
147         GTEST_LOG_(INFO) << "StartSync FAILED";
148     }
149     GTEST_LOG_(INFO) << "StartSync end";
150 }
151 
152 /**
153  * @tc.name: StopSyncTest
154  * @tc.desc: Verify the StopSync function
155  * @tc.type: FUNC
156  * @tc.require: #I7UU3Z
157  */
158 HWTEST_F(DataSyncerTest, StopSyncTest, TestSize.Level1)
159 {
160     GTEST_LOG_(INFO) << "StopSync Start";
161     int res = datasyncer_->StopSync(SyncTriggerType::PENDING_TRIGGER);
162     EXPECT_EQ(res, E_OK);
163     GTEST_LOG_(INFO) << "StopSync end";
164 }
165 
166 /**
167  * @tc.name: LockTest
168  * @tc.desc: Verify the Lock function
169  * @tc.type: FUNC
170  * @tc.require: #I7UU3Z
171  */
172 HWTEST_F(DataSyncerTest, LockTest, TestSize.Level1)
173 {
174     GTEST_LOG_(INFO) << "Lock Start";
175     datasyncer_->lock_.count = -100;
176     datasyncer_->lock_.lock.lockInterval = 100;
177     int res = datasyncer_->Lock();
178     EXPECT_EQ(res, E_OK);
179     GTEST_LOG_(INFO) << "Lock GetLock";
180     datasyncer_->lock_.count = 0;
181     datasyncer_->lock_.lock.lockInterval = 0;
182     res = datasyncer_->Lock();
183     EXPECT_EQ(res, E_OK);
184     res = datasyncer_->Lock();
185     EXPECT_EQ(res, E_OK);
186     GTEST_LOG_(INFO) << "Lock end";
187 }
188 
189 /**
190  * @tc.name: UnlockTest
191  * @tc.desc: Verify the Unlock function
192  * @tc.type: FUNC
193  * @tc.require: #I7UU3Z
194  */
195 HWTEST_F(DataSyncerTest, UnlockTest, TestSize.Level1)
196 {
197     GTEST_LOG_(INFO) << "Unlock Start";
198     try {
199         datasyncer_->Unlock();
200         datasyncer_->Unlock();
201         EXPECT_TRUE(true);
202     } catch (...) {
203         EXPECT_TRUE(false);
204         GTEST_LOG_(INFO) << "Unlock FAILED";
205     }
206     GTEST_LOG_(INFO) << "Unlock end";
207 }
208 
209 /**
210  * @tc.name: ForceUnlockTest
211  * @tc.desc: Verify the ForceUnlock function
212  * @tc.type: FUNC
213  * @tc.require: #I7UU3Z
214  */
215 HWTEST_F(DataSyncerTest, ForceUnlockTest, TestSize.Level1)
216 {
217     GTEST_LOG_(INFO) << "ForceUnlock Start";
218     try {
219         datasyncer_->lock_.count = 1;
220         datasyncer_->ForceUnlock();
221         datasyncer_->ForceUnlock();
222         EXPECT_TRUE(true);
223     } catch (...) {
224         EXPECT_TRUE(false);
225         GTEST_LOG_(INFO) << "ForceUnlock FAILED";
226     }
227     GTEST_LOG_(INFO) << "ForceUnlock end";
228 }
229 
230 /**
231  * @tc.name: StartDownloadFileTest
232  * @tc.desc: Verify the StartDownloadFileTask function
233  * @tc.type: FUNC
234  * @tc.require: #I7UU3Z
235  */
236 HWTEST_F(DataSyncerTest, StartDownloadFileTest, TestSize.Level1)
237 {
238     GTEST_LOG_(INFO) << "StartDownloadFile Start";
239     int res = datasyncer_->StartDownloadFile("/test", 100);
240     EXPECT_EQ(res, E_OK);
241     GTEST_LOG_(INFO) << "StartDownloadFile end";
242 }
243 
244 /**
245  * @tc.name: StopDownloadFileTest
246  * @tc.desc: Verify the StopDownloadFileTask function
247  * @tc.type: FUNC
248  * @tc.require: #I7UU3Z
249  */
250 HWTEST_F(DataSyncerTest, StopDownloadFileTest, TestSize.Level1)
251 {
252     GTEST_LOG_(INFO) << "StopDownloadFile Start";
253     int res = datasyncer_->StopDownloadFile("/test", 100);
254     EXPECT_EQ(res, E_OK);
255     GTEST_LOG_(INFO) << "StopDownloadFile end";
256 }
257 
258 /**
259  * @tc.name: RegisterDownloadFileCallbackTest
260  * @tc.desc: Verify the RegisterDownloadFileCallback function
261  * @tc.type: FUNC
262  * @tc.require: #I7UU3Z
263  */
264 HWTEST_F(DataSyncerTest, RegisterDownloadFileCallbackTest, TestSize.Level1)
265 {
266     GTEST_LOG_(INFO) << "RegisterDownloadFileCallback Start";
267     int res = datasyncer_->RegisterDownloadFileCallback(100, nullptr);
268     EXPECT_EQ(res, E_OK);
269     GTEST_LOG_(INFO) << "RegisterDownloadFileCallback end";
270 }
271 
272 /**
273  * @tc.name: UnregisterDownloadFileCallbackTest
274  * @tc.desc: Verify the UnregisterDownloadFileCallback function
275  * @tc.type: FUNC
276  * @tc.require: #I7UU3Z
277  */
278 HWTEST_F(DataSyncerTest, UnregisterDownloadFileCallbackTest, TestSize.Level1)
279 {
280     GTEST_LOG_(INFO) << "UnregisterDownloadFileCallback Start";
281     int res = datasyncer_->UnregisterDownloadFileCallback(100);
282     EXPECT_EQ(res, E_OK);
283     GTEST_LOG_(INFO) << "UnregisterDownloadFileCallback end";
284 }
285 
286 /**
287  * @tc.name: PullTest001
288  * @tc.desc: Verify the Pull function
289  * @tc.type: FUNC
290  * @tc.require: #I7UU3Z
291  */
292 HWTEST_F(DataSyncerTest, PullTest001, TestSize.Level1)
293 {
294     GTEST_LOG_(INFO) << "PullTest001 Start";
295     try {
296         EXPECT_CALL(*dataHandler_, GetRetryRecords(_)).Times(1).WillOnce(Return(E_OK));
297         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(1).WillOnce(Return(0));
298         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(true));
299         EXPECT_CALL(*dataHandler_, GetAssetsToDownload(_)).Times(1).WillOnce(Return(false));
300         int32_t result = datasyncer_->Pull(dataHandler_);
301         EXPECT_EQ(result, E_OK);
302     } catch (...) {
303         EXPECT_TRUE(false);
304         GTEST_LOG_(INFO) << "PullTest001 FAILED";
305     }
306     GTEST_LOG_(INFO) << "PullTest001 end";
307 }
308 
309 /**
310  * @tc.name: PullTest002
311  * @tc.desc: Verify the Pull function
312  * @tc.type: FUNC
313  * @tc.require: #I7UU3Z
314  */
315 HWTEST_F(DataSyncerTest, PullTest002, TestSize.Level1)
316 {
317     GTEST_LOG_(INFO) << "PullTest002 Start";
318     try {
319         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(1).WillOnce(Return(0));
320         EXPECT_CALL(*dataHandler_, GetRetryRecords(_)).Times(1).WillOnce(Return(1));
321         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(false));
322         EXPECT_CALL(*dataHandler_, GetAssetsToDownload(_)).Times(1).WillOnce(Return(false));
323         int32_t result = datasyncer_->Pull(dataHandler_);
324         EXPECT_EQ(result, E_OK);
325     } catch (...) {
326         EXPECT_TRUE(false);
327         GTEST_LOG_(INFO) << "PullTest002 FAILED";
328     }
329     GTEST_LOG_(INFO) << "PullTest002 end";
330 }
331 
332 /**
333  * @tc.name: PullRecordsTest
334  * @tc.desc: Verify the PullRecords function
335  * @tc.type: FUNC
336  * @tc.require: #I7UU3Z
337  */
338 HWTEST_F(DataSyncerTest, PullRecordsTest, TestSize.Level1)
339 {
340     GTEST_LOG_(INFO) << "PullRecords Start";
341     try {
342         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
343         EXPECT_CALL(*dataHandler_, GetCheckFlag()).Times(1).WillOnce(Return(true));
344         datasyncer_->PullRecords(context);
345         EXPECT_TRUE(true);
346     } catch (...) {
347         EXPECT_TRUE(false);
348         GTEST_LOG_(INFO) << "PullRecords FAILED";
349     }
350     GTEST_LOG_(INFO) << "PullRecords end";
351 }
352 
353 /**
354  * @tc.name: PullRecordsTest002
355  * @tc.desc: Verify the PullRecords function
356  * @tc.type: FUNC
357  * @tc.require: #I7UU3Z
358  */
359 HWTEST_F(DataSyncerTest, PullRecordsTest002, TestSize.Level1)
360 {
361     GTEST_LOG_(INFO) << "PullRecordsTest002 Start";
362     try {
363         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
364         datasyncer_->PullRecords(context);
365         EXPECT_TRUE(true);
366     } catch (...) {
367         EXPECT_TRUE(false);
368         GTEST_LOG_(INFO) << "PullRecordsTest002 FAILED";
369     }
370     GTEST_LOG_(INFO) << "PullRecordsTest002 end";
371 }
372 
373 /**
374  * @tc.name: PullRecordsTest003
375  * @tc.desc: Verify the PullRecords function
376  * @tc.type: FUNC
377  * @tc.require: #I7UU3Z
378  */
379 HWTEST_F(DataSyncerTest, PullRecordsTest003, TestSize.Level1)
380 {
381     GTEST_LOG_(INFO) << "PullRecordsTest003 Start";
382     try {
383         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
384         EXPECT_CALL(*dataHandler_, GetCheckFlag()).Times(1).WillOnce(Return(false));
385         char data[] = "123";
386         context->data_ = data;
387         datasyncer_->PullRecords(context);
388         EXPECT_TRUE(true);
389     } catch (...) {
390         EXPECT_TRUE(false);
391         GTEST_LOG_(INFO) << "PullRecordsTest003 FAILED";
392     }
393     GTEST_LOG_(INFO) << "PullRecordsTest003 end";
394 }
395 
396 /**
397  * @tc.name: PullDatabaseChangesTest
398  * @tc.desc: Verify the PullDatabaseChanges function
399  * @tc.type: FUNC
400  * @tc.require: #I7UU3Z
401  */
402 HWTEST_F(DataSyncerTest, PullDatabaseChangesTest, TestSize.Level1)
403 {
404     GTEST_LOG_(INFO) << "PullDatabaseChanges Start";
405     try {
406         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
407         datasyncer_->PullDatabaseChanges(context);
408         EXPECT_TRUE(true);
409     } catch (...) {
410         EXPECT_TRUE(false);
411         GTEST_LOG_(INFO) << "PullDatabaseChanges FAILED";
412     }
413     GTEST_LOG_(INFO) << "PullDatabaseChanges end";
414 }
415 
416 /**
417  * @tc.name: PullDatabaseChangesTest002
418  * @tc.desc: Verify the PullDatabaseChanges function
419  * @tc.type: FUNC
420  * @tc.require: #I7UU3Z
421  */
422 HWTEST_F(DataSyncerTest, PullDatabaseChangesTest002, TestSize.Level1)
423 {
424     GTEST_LOG_(INFO) << "PullDatabaseChangesTest002 Start";
425     try {
426         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
427         char data[] = "123";
428         context->data_ = data;
429         datasyncer_->PullDatabaseChanges(context);
430         EXPECT_TRUE(true);
431     } catch (...) {
432         EXPECT_TRUE(false);
433         GTEST_LOG_(INFO) << "PullDatabaseChangesTest002 FAILED";
434     }
435     GTEST_LOG_(INFO) << "PullDatabaseChangesTest002 end";
436 }
437 
438 /**
439  * @tc.name: PullDatabaseChangesTest003
440  * @tc.desc: Verify the PullDatabaseChanges function
441  * @tc.type: FUNC
442  * @tc.require: #I7UU3Z
443  */
444 HWTEST_F(DataSyncerTest, PullDatabaseChangesTest003, TestSize.Level1)
445 {
446     GTEST_LOG_(INFO) << "PullDatabaseChangesTest003 Start";
447     try {
448         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
449         datasyncer_->PullDatabaseChanges(context);
450         EXPECT_TRUE(true);
451     } catch (...) {
452         EXPECT_TRUE(false);
453         GTEST_LOG_(INFO) << "PullDatabaseChangesTest003 FAILED";
454     }
455     GTEST_LOG_(INFO) << "PullDatabaseChangesTest003 end";
456 }
457 
458 /**
459  * @tc.name: HandleOnFetchRecordsTest
460  * @tc.desc: Verify the HandleOnFetchRecords function
461  * @tc.type: FUNC
462  * @tc.require: #I7UU3Z
463  */
464 HWTEST_F(DataSyncerTest, HandleOnFetchRecordsTest, TestSize.Level1)
465 {
466     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest Start";
467     try {
468         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
469         auto res = datasyncer_->HandleOnFetchRecords(nullptr, nullptr, records, false);
470         EXPECT_EQ(res, E_OK);
471     } catch (...) {
472         EXPECT_TRUE(false);
473         GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest FAILED";
474     }
475     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest end";
476 }
477 
478 /**
479  * @tc.name: HandleOnFetchRecordsTest002
480  * @tc.desc: Verify the HandleOnFetchRecordsTest002 function
481  * @tc.type: FUNC
482  * @tc.require: #I7UU3Z
483  */
484 HWTEST_F(DataSyncerTest, HandleOnFetchRecordsTest002, TestSize.Level1)
485 {
486     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest002 Start";
487     try {
488         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 1);
489         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
490         records->push_back({});
491         auto res = datasyncer_->HandleOnFetchRecords(context, nullptr, records, false);
492         EXPECT_EQ(res, E_CONTEXT);
493     } catch (...) {
494         EXPECT_TRUE(false);
495         GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest002 FAILED";
496     }
497     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest002 end";
498 }
499 
500 /**
501  * @tc.name: HandleOnFetchRecordsTest003
502  * @tc.desc: Verify the HandleOnFetchRecordsTest002 function
503  * @tc.type: FUNC
504  * @tc.require: #I7UU3Z
505  */
506 HWTEST_F(DataSyncerTest, HandleOnFetchRecordsTest003, TestSize.Level1)
507 {
508     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest003 Start";
509     try {
510         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(true));
511         EXPECT_CALL(*dataHandler_, GetRecordSize()).Times(1).WillOnce(Return(1));
512         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(1));
513         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(dataHandler_, 0);
514         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
515         records->push_back({});
516         auto res = datasyncer_->HandleOnFetchRecords(context, nullptr, records, true);
517         EXPECT_NE(res, E_OK);
518     } catch (...) {
519         EXPECT_TRUE(false);
520         GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest003 FAILED";
521     }
522     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest003 end";
523 }
524 
525 /**
526  * @tc.name: HandleOnFetchRecordsTest004
527  * @tc.desc: Verify the HandleOnFetchRecordsTest004 function
528  * @tc.type: FUNC
529  * @tc.require: #I7UU3Z
530  */
531 HWTEST_F(DataSyncerTest, HandleOnFetchRecordsTest004, TestSize.Level1)
532 {
533     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest004 Start";
534     try {
535         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(false));
536         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(0));
537         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(dataHandler_, 0);
538         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
539         records->push_back({});
540         auto res = datasyncer_->HandleOnFetchRecords(context, nullptr, records, true);
541         EXPECT_EQ(res, E_OK);
542     } catch (...) {
543         EXPECT_TRUE(false);
544         GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest004 FAILED";
545     }
546     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest004 end";
547 }
548 
549 /**
550  * @tc.name: HandleOnFetchRecordsTest005
551  * @tc.desc: Verify the HandleOnFetchRecordsTest005 function
552  * @tc.type: FUNC
553  * @tc.require: #I7UU3Z
554  */
555 HWTEST_F(DataSyncerTest, HandleOnFetchRecordsTest005, TestSize.Level1)
556 {
557     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest005 Start";
558     try {
559         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(false));
560         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(0));
561         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(dataHandler_, 0);
562         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
563         records->push_back({});
564         auto res = datasyncer_->HandleOnFetchRecords(context, nullptr, records, false);
565         EXPECT_EQ(res, E_OK);
566     } catch (...) {
567         EXPECT_TRUE(false);
568         GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest005 FAILED";
569     }
570     GTEST_LOG_(INFO) << "HandleOnFetchRecordsTest005 end";
571 }
572 
573 /**
574  * @tc.name: OnFetchRecordsTest
575  * @tc.desc: Verify the OnFetchRecords function
576  * @tc.type: FUNC
577  * @tc.require: #I7UU3Z
578  */
579 HWTEST_F(DataSyncerTest, OnFetchRecordsTest, TestSize.Level1)
580 {
581     GTEST_LOG_(INFO) << "OnFetchRecordsTest Start";
582     try {
583         DriveKit::DKError err;
584         err.isLocalError = true;
585         err.serverErrorCode = static_cast<int>(DriveKit::DKServerErrorCode::NETWORK_ERROR);
586         datasyncer_->OnFetchRecords(nullptr, nullptr, nullptr, {}, err);
587         GTEST_LOG_(INFO) << "OnFetchRecordsTest else";
588         err.serverErrorCode = static_cast<int>(DriveKit::DKServerErrorCode::ACCESS_DENIED);
589         datasyncer_->OnFetchRecords(nullptr, nullptr, nullptr, {}, err);
590         EXPECT_TRUE(true);
591     } catch (...) {
592         EXPECT_TRUE(false);
593         GTEST_LOG_(INFO) << "OnFetchRecordsTest FAILED";
594     }
595     GTEST_LOG_(INFO) << "OnFetchRecordsTest end";
596 }
597 
598 /**
599  * @tc.name: OnFetchRecordsTest002
600  * @tc.desc: Verify the OnFetchRecords function
601  * @tc.type: FUNC
602  * @tc.require: #I7UU3Z
603  */
604 HWTEST_F(DataSyncerTest, OnFetchRecordsTest002, TestSize.Level1)
605 {
606     GTEST_LOG_(INFO) << "OnFetchRecordsTest002 Start";
607     try {
608         DriveKit::DKError err;
609         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
610         datasyncer_->OnFetchRecords(context, nullptr, nullptr, {}, err);
611         GTEST_LOG_(INFO) << "OnFetchRecordsTest002 other";
612         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(0));
613         EXPECT_CALL(*dataHandler_, SetRecordSize(_)).Times(1);
614         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(true));
615         shared_ptr<DownloadTaskContext> contextErr = make_shared<DownloadTaskContext>(dataHandler_, 0);
616         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
617         records->push_back({});
618         datasyncer_->OnFetchRecords(contextErr, nullptr, records, {}, err);
619         EXPECT_TRUE(true);
620     } catch (...) {
621         EXPECT_TRUE(false);
622         GTEST_LOG_(INFO) << "OnFetchRecordsTest002 FAILED";
623     }
624     GTEST_LOG_(INFO) << "OnFetchRecordsTest002 end";
625 }
626 
627 /**
628  * @tc.name: OnFetchRecordsTest003
629  * @tc.desc: Verify the OnFetchRecords function
630  * @tc.type: FUNC
631  * @tc.require: #I7UU3Z
632  */
633 HWTEST_F(DataSyncerTest, OnFetchRecordsTest003, TestSize.Level1)
634 {
635     GTEST_LOG_(INFO) << "OnFetchRecordsTest003 Start";
636     try {
637         DriveKit::DKError err;
638         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(1).WillOnce(Return(0));
639         shared_ptr<DownloadTaskContext> contextErr = make_shared<DownloadTaskContext>(dataHandler_, 1);
640         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
641         datasyncer_->OnFetchRecords(contextErr, nullptr, records, "", err);
642         GTEST_LOG_(INFO) << "OnFetchRecordsTest003 other";
643         records->push_back({});
644         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(1).WillOnce(Return(false));
645         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(1));
646         datasyncer_->OnFetchRecords(contextErr, nullptr, records, "test", err);
647         EXPECT_TRUE(true);
648     } catch (...) {
649         EXPECT_TRUE(false);
650         GTEST_LOG_(INFO) << "OnFetchRecordsTest003 FAILED";
651     }
652     GTEST_LOG_(INFO) << "OnFetchRecordsTest003 end";
653 }
654 
655 /**
656  * @tc.name: DownloadInnerTest
657  * @tc.desc: Verify the DownloadInner function
658  * @tc.type: FUNC
659  * @tc.require: #I7UU3Z
660  */
661 HWTEST_F(DataSyncerTest, DownloadInnerTest, TestSize.Level1)
662 {
663     GTEST_LOG_(INFO) << "DownloadInnerTest Start";
664     try {
665         int32_t userId = 100;
666         EXPECT_CALL(*dataHandler_, GetDownloadAsset(_, _)).Times(1).WillOnce(Return(1));
667         auto ret = datasyncer_->DownloadInner(dataHandler_, "test", userId);
668         EXPECT_NE(ret, E_OK);
669         EXPECT_CALL(*dataHandler_, GetDownloadAsset(_, _)).Times(1).WillOnce(Return(0));
670         auto res = datasyncer_->DownloadInner(dataHandler_, "test", userId);
671         EXPECT_EQ(res, E_OK);
672     } catch (...) {
673         EXPECT_TRUE(false);
674         GTEST_LOG_(INFO) << "DownloadInnerTest FAILED";
675     }
676     GTEST_LOG_(INFO) << "DownloadInnerTest end";
677 }
678 
679 /**
680  * @tc.name: OnFetchDatabaseChangesTest
681  * @tc.desc: Verify the OnFetchDatabaseChanges function
682  * @tc.type: FUNC
683  * @tc.require: #I7UU3Z
684  */
685 HWTEST_F(DataSyncerTest, OnFetchDatabaseChangesTest, TestSize.Level1)
686 {
687     GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest Start";
688     try {
689         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
690         DriveKit::DKError err;
691         datasyncer_->OnFetchDatabaseChanges(context, nullptr, nullptr, "", false, err);
692         GTEST_LOG_(INFO) << "OnFetchDatabaseChanges other 001";
693         err.isLocalError = true;
694         err.serverErrorCode = static_cast<int>(DriveKit::DKServerErrorCode::NETWORK_ERROR);
695         shared_ptr<DownloadTaskContext> contextTest = make_shared<DownloadTaskContext>(dataHandler_, 0);
696         datasyncer_->OnFetchDatabaseChanges(contextTest, nullptr, nullptr, "", false, err);
697         GTEST_LOG_(INFO) << "OnFetchDatabaseChanges other 002";
698         EXPECT_CALL(*dataHandler_, GetAssetsToDownload(_)).Times(2).WillRepeatedly(Return(0));
699         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(2).WillRepeatedly(Return(false));
700         EXPECT_CALL(*dataHandler_, GetRetryRecords(_)).Times(2).WillRepeatedly(Return(E_OK));
701         EXPECT_CALL(*dataHandler_, SetChecking()).Times(2);
702         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(2).WillRepeatedly(Return(0));
703         err.serverErrorCode = {};
704         DriveKit::DKErrorDetail detailErr{};
705         detailErr.detailCode = static_cast<int>(DriveKit::DKDetailErrorCode::PARAM_INVALID);
706         err.errorDetails.push_back(detailErr);
707         datasyncer_->OnFetchDatabaseChanges(contextTest, nullptr, nullptr, "", false, err);
708         GTEST_LOG_(INFO) << "OnFetchDatabaseChanges other 003";
709         err.errorDetails.clear();
710         detailErr.detailCode = static_cast<int>(DriveKit::DKDetailErrorCode::CURSOR_EXPIRED);
711         err.errorDetails.push_back(detailErr);
712         datasyncer_->OnFetchDatabaseChanges(contextTest, nullptr, nullptr, "", false, err);
713         GTEST_LOG_(INFO) << "OnFetchDatabaseChanges other 004";
714         err.errorDetails.clear();
715         detailErr.detailCode = static_cast<int>(DriveKit::DKDetailErrorCode::FLOW_ID_NOT_MATCH);
716         err.errorDetails.push_back(detailErr);
717         datasyncer_->OnFetchDatabaseChanges(contextTest, nullptr, nullptr, "", false, err);
718         GTEST_LOG_(INFO) << "OnFetchDatabaseChanges other 005";
719         err.errorDetails.clear();
720         datasyncer_->OnFetchDatabaseChanges(contextTest, nullptr, nullptr, "", false, err);
721         EXPECT_TRUE(true);
722     } catch (...) {
723         EXPECT_TRUE(false);
724         GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest FAILED";
725     }
726     GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest end";
727 }
728 
729 /**
730  * @tc.name: OnFetchDatabaseChangesTest002
731  * @tc.desc: Verify the OnFetchDatabaseChanges function
732  * @tc.type: FUNC
733  * @tc.require: #I7UU3Z
734  */
735 HWTEST_F(DataSyncerTest, OnFetchDatabaseChangesTest002, TestSize.Level1)
736 {
737     GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest002 Start";
738     try {
739         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(dataHandler_, 0);
740         DriveKit::DKError err;
741         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(1).WillRepeatedly(Return(0));
742         EXPECT_CALL(*dataHandler_, IsPullRecords()).Times(2).WillRepeatedly(Return(0));
743         shared_ptr<vector<DriveKit::DKRecord>> records = make_shared<vector<DriveKit::DKRecord>>();
744         datasyncer_->OnFetchDatabaseChanges(context, nullptr, records, "", false, err);
745         GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest002 other 002";
746         records->push_back({});
747         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(0));
748         datasyncer_->OnFetchDatabaseChanges(context, nullptr, records, "", false, err);
749         GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest002 other 003";
750 
751         EXPECT_CALL(*dataHandler_, OnFetchRecords(_, _)).Times(1).WillOnce(Return(0));
752         datasyncer_->OnFetchDatabaseChanges(context, nullptr, records, "", true, err);
753         EXPECT_TRUE(true);
754     } catch (...) {
755         EXPECT_TRUE(false);
756         GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest002 FAILED";
757     }
758     GTEST_LOG_(INFO) << "OnFetchDatabaseChangesTest002 end";
759 }
760 
761 /**
762  * @tc.name: OnFetchCheckRecordsTest
763  * @tc.desc: Verify the OnFetchCheckRecords function
764  * @tc.type: FUNC
765  * @tc.require: #I7UU3Z
766  */
767 HWTEST_F(DataSyncerTest, OnFetchCheckRecordsTest, TestSize.Level1)
768 {
769     GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest Start";
770     try {
771         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
772         DriveKit::DKError err;
773         err.isLocalError = true;
774         datasyncer_->OnFetchCheckRecords(context, nullptr, nullptr, "", err);
775         err.serverErrorCode = static_cast<int>(DriveKit::DKServerErrorCode::NETWORK_ERROR);
776         datasyncer_->OnFetchCheckRecords(context, nullptr, nullptr, "", err);
777         err.isLocalError = false;
778         datasyncer_->OnFetchCheckRecords(context, nullptr, nullptr, "", err);
779         EXPECT_TRUE(true);
780     } catch (...) {
781         EXPECT_TRUE(false);
782         GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest FAILED";
783     }
784     GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest end";
785 }
786 
787 /**
788  * @tc.name: OnFetchCheckRecordsTest002
789  * @tc.desc: Verify the OnFetchCheckRecords function
790  * @tc.type: FUNC
791  * @tc.require: #I7UU3Z
792  */
793 HWTEST_F(DataSyncerTest, OnFetchCheckRecordsTest002, TestSize.Level1)
794 {
795     GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest002 Start";
796     try {
797         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(dataHandler_, 0);
798         DriveKit::DKError err;
799         EXPECT_CALL(*dataHandler_, GetBatchNo()).Times(1).WillRepeatedly(Return(0));
800         EXPECT_CALL(*dataHandler_, GetCheckRecords(_, _)).Times(1).WillOnce(Return(1));
801         datasyncer_->OnFetchCheckRecords(context, nullptr, nullptr, "", err);
802         GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest002 other";
803         EXPECT_CALL(*dataHandler_, GetCheckRecords(_, _)).Times(1).WillOnce(Return(0));
804         datasyncer_->OnFetchCheckRecords(context, nullptr, nullptr, "test", err);
805         EXPECT_TRUE(true);
806     } catch (...) {
807         EXPECT_TRUE(false);
808         GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest002 FAILED";
809     }
810     GTEST_LOG_(INFO) << "OnFetchCheckRecordsTest002 end";
811 }
812 
813 /**
814  * @tc.name: PullRecordsWithIdTest
815  * @tc.desc: Verify the PullRecordsWithId function
816  * @tc.type: FUNC
817  * @tc.require: #I7UU3Z
818  */
819 HWTEST_F(DataSyncerTest, PullRecordsWithIdTest, TestSize.Level1)
820 {
821     GTEST_LOG_(INFO) << "PullRecordsWithIdTest Start";
822     try {
823         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
824         vector<DriveKit::DKRecordId> records;
825         datasyncer_->PullRecordsWithId(context, records, false);
826         GTEST_LOG_(INFO) << "PullRecordsWithIdTest other 001";
827         shared_ptr<DownloadTaskContext> contextOther = make_shared<DownloadTaskContext>(dataHandler_, 0);
828         datasyncer_->PullRecordsWithId(contextOther, records, false);
829         GTEST_LOG_(INFO) << "PullRecordsWithIdTest other 002";
830         records.push_back("test");
831         datasyncer_->PullRecordsWithId(contextOther, records, true);
832         EXPECT_TRUE(true);
833     } catch (...) {
834         EXPECT_TRUE(false);
835         GTEST_LOG_(INFO) << "PullRecordsWithIdTest FAILED";
836     }
837     GTEST_LOG_(INFO) << "PullRecordsWithIdTest end";
838 }
839 
840 /**
841  * @tc.name: OnFetchRecordWithIdTest
842  * @tc.desc: Verify the OnFetchRecordWithId function
843  * @tc.type: FUNC
844  * @tc.require: #I7UU3Z
845  */
846 HWTEST_F(DataSyncerTest, OnFetchRecordWithIdTest, TestSize.Level1)
847 {
848     GTEST_LOG_(INFO) << "OnFetchRecordWithIdTest Start";
849     try {
850         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
851         vector<DriveKit::DKRecordId> records;
852         DriveKit::DKError err;
853         DriveKit::DKRecord record;
854         datasyncer_->OnFetchRecordWithId(context, nullptr, "test", record, err);
855         GTEST_LOG_(INFO) << "OnFetchRecordWithIdTest other 001";
856         err.isLocalError = true;
857         datasyncer_->OnFetchRecordWithId(context, nullptr, "test", record, err);
858         EXPECT_TRUE(true);
859     } catch (...) {
860         EXPECT_TRUE(false);
861         GTEST_LOG_(INFO) << "OnFetchRecordWithIdTest FAILED";
862     }
863     GTEST_LOG_(INFO) << "OnFetchRecordWithIdTest end";
864 }
865 
866 /**
867  * @tc.name: RetryDownloadRecordsTest
868  * @tc.desc: Verify the RetryDownloadRecords function
869  * @tc.type: FUNC
870  * @tc.require: #I7UU3Z
871  */
872 HWTEST_F(DataSyncerTest, RetryDownloadRecordsTest, TestSize.Level1)
873 {
874     GTEST_LOG_(INFO) << "RetryDownloadRecordsTest Start";
875     try {
876         shared_ptr<DownloadTaskContext> context = make_shared<DownloadTaskContext>(nullptr, 0);
877         datasyncer_->RetryDownloadRecords(context);
878         shared_ptr<DownloadTaskContext> contextTest = make_shared<DownloadTaskContext>(dataHandler_, 0);
879         EXPECT_CALL(*dataHandler_, GetAssetsToDownload(_)).Times(1).WillOnce(Return(1));
880         datasyncer_->RetryDownloadRecords(contextTest);
881         EXPECT_CALL(*dataHandler_, GetAssetsToDownload(_)).Times(1).WillOnce(Return(0));
882         datasyncer_->RetryDownloadRecords(contextTest);
883         EXPECT_TRUE(true);
884     } catch (...) {
885         EXPECT_TRUE(false);
886         GTEST_LOG_(INFO) << "RetryDownloadRecordsTest FAILED";
887     }
888     GTEST_LOG_(INFO) << "RetryDownloadRecordsTest end";
889 }
890 
891 /**
892  * @tc.name: InitTest
893  * @tc.desc: Verify the Init function
894  * @tc.type: FUNC
895  * @tc.require: #I7UU3Z
896  */
897 HWTEST_F(DataSyncerTest, InitTest, TestSize.Level1)
898 {
899     GTEST_LOG_(INFO) << "InitTest Start";
900     try {
901         auto ret = datasyncer_->Init("test", 100);
902         EXPECT_EQ(ret, E_OK);
903     } catch (...) {
904         EXPECT_TRUE(false);
905         GTEST_LOG_(INFO) << "InitTest FAILED";
906     }
907     GTEST_LOG_(INFO) << "InitTest end";
908 }
909 
910 /**
911  * @tc.name: CleanTest
912  * @tc.desc: Verify the Clean function
913  * @tc.type: FUNC
914  * @tc.require: #I7UU3Z
915  */
916 HWTEST_F(DataSyncerTest, CleanTest, TestSize.Level1)
917 {
918     GTEST_LOG_(INFO) << "CleanTest Start";
919     try {
920         auto ret = datasyncer_->Clean(0);
921         EXPECT_EQ(ret, E_OK);
922     } catch (...) {
923         EXPECT_TRUE(false);
924         GTEST_LOG_(INFO) << "CleanTest FAILED";
925     }
926     GTEST_LOG_(INFO) << "CleanTest end";
927 }
928 
929 /**
930  * @tc.name: CleanInnerTest
931  * @tc.desc: Verify the CleanInner function
932  * @tc.type: FUNC
933  * @tc.require: #I7UU3Z
934  */
935 HWTEST_F(DataSyncerTest, CleanInnerTest, TestSize.Level1)
936 {
937     GTEST_LOG_(INFO) << "CleanInnerTest Start";
938     try {
939         EXPECT_CALL(*dataHandler_, ClearCursor()).Times(2);
940         EXPECT_CALL(*dataHandler_, Clean(_)).Times(1).WillOnce(Return(1));
941         auto ret = datasyncer_->CleanInner(dataHandler_, 0);
942         EXPECT_NE(ret, E_OK);
943         GTEST_LOG_(INFO) << "CleanInnerTest other";
944         EXPECT_CALL(*dataHandler_, Clean(_)).Times(1).WillOnce(Return(0));
945         ret = datasyncer_->CleanInner(dataHandler_, 0);
946         EXPECT_EQ(ret, E_OK);
947     } catch (...) {
948         EXPECT_TRUE(false);
949         GTEST_LOG_(INFO) << "CleanInnerTest FAILED";
950     }
951     GTEST_LOG_(INFO) << "CleanInnerTest end";
952 }
953 
954 /**
955  * @tc.name: CreateRecordsTest
956  * @tc.desc: Verify the CreateRecords function
957  * @tc.type: FUNC
958  * @tc.require: #I7UU3Z
959  */
960 HWTEST_F(DataSyncerTest, CreateRecordsTest, TestSize.Level1)
961 {
962     GTEST_LOG_(INFO) << "CreateRecords Start";
963     try {
964         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
965         datasyncer_->CreateRecords(context);
966         GTEST_LOG_(INFO) << "CreateRecords other 001";
967         EXPECT_CALL(*dataHandler_, GetCreatedRecords(_)).Times(1).WillOnce(Return(1));
968         shared_ptr<TaskContext> contextTest = make_shared<TaskContext>(dataHandler_);
969         datasyncer_->CreateRecords(contextTest);
970         GTEST_LOG_(INFO) << "CreateRecords other 002";
971         EXPECT_CALL(*dataHandler_, GetCreatedRecords(_)).Times(1).WillOnce(Return(0));
972         datasyncer_->CreateRecords(contextTest);
973         EXPECT_TRUE(true);
974     } catch (...) {
975         EXPECT_TRUE(false);
976         GTEST_LOG_(INFO) << "CreateRecords FAILED";
977     }
978     GTEST_LOG_(INFO) << "CreateRecords end";
979 }
980 
981 /**
982  * @tc.name: DeleteRecordsTest
983  * @tc.desc: Verify the DeleteRecords function
984  * @tc.type: FUNC
985  * @tc.require: #I7UU3Z
986  */
987 HWTEST_F(DataSyncerTest, DeleteRecordsTest, TestSize.Level1)
988 {
989     GTEST_LOG_(INFO) << "DeleteRecords Start";
990     try {
991         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
992         datasyncer_->DeleteRecords(context);
993         GTEST_LOG_(INFO) << "DeleteRecords other 001";
994         EXPECT_CALL(*dataHandler_, GetDeletedRecords(_)).Times(1).WillOnce(Return(1));
995         shared_ptr<TaskContext> contextTest = make_shared<TaskContext>(dataHandler_);
996         datasyncer_->DeleteRecords(contextTest);
997         GTEST_LOG_(INFO) << "DeleteRecords other 002";
998         EXPECT_CALL(*dataHandler_, GetDeletedRecords(_)).Times(1).WillOnce(Return(0));
999         datasyncer_->DeleteRecords(contextTest);
1000         EXPECT_TRUE(true);
1001     } catch (...) {
1002         EXPECT_TRUE(false);
1003         GTEST_LOG_(INFO) << "DeleteRecords FAILED";
1004     }
1005     GTEST_LOG_(INFO) << "DeleteRecords end";
1006 }
1007 
1008 /**
1009  * @tc.name: ModifyMdirtyRecordsTest
1010  * @tc.desc: Verify the ModifyMdirtyRecords function
1011  * @tc.type: FUNC
1012  * @tc.require: #I7UU3Z
1013  */
1014 HWTEST_F(DataSyncerTest, ModifyMdirtyRecordsTest, TestSize.Level1)
1015 {
1016     GTEST_LOG_(INFO) << "ModifyMdirtyRecordsTest Start";
1017     try {
1018         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
1019         datasyncer_->ModifyMdirtyRecords(context);
1020         GTEST_LOG_(INFO) << "ModifyMdirtyRecordsTest other 001";
1021         EXPECT_CALL(*dataHandler_, GetMetaModifiedRecords(_)).Times(1).WillOnce(Return(1));
1022         shared_ptr<TaskContext> contextTest = make_shared<TaskContext>(dataHandler_);
1023         datasyncer_->ModifyMdirtyRecords(contextTest);
1024         GTEST_LOG_(INFO) << "ModifyMdirtyRecordsTest other 002";
1025         EXPECT_CALL(*dataHandler_, GetMetaModifiedRecords(_)).Times(1).WillOnce(Return(0));
1026         datasyncer_->ModifyMdirtyRecords(contextTest);
1027         EXPECT_TRUE(true);
1028     } catch (...) {
1029         EXPECT_TRUE(false);
1030         GTEST_LOG_(INFO) << "ModifyMdirtyRecordsTest FAILED";
1031     }
1032     GTEST_LOG_(INFO) << "ModifyMdirtyRecordsTest end";
1033 }
1034 
1035 /**
1036  * @tc.name: ModifyFdirtyRecordsTest
1037  * @tc.desc: Verify the ModifyFdirtyRecords function
1038  * @tc.type: FUNC
1039  * @tc.require: #I7UU3Z
1040  */
1041 HWTEST_F(DataSyncerTest, ModifyFdirtyRecordsTest, TestSize.Level1)
1042 {
1043     GTEST_LOG_(INFO) << "ModifyFdirtyRecordsTest Start";
1044     try {
1045         shared_ptr<TaskContext> context = make_shared<TaskContext>(nullptr);
1046         datasyncer_->ModifyFdirtyRecords(context);
1047         GTEST_LOG_(INFO) << "ModifyFdirtyRecordsTest other 001";
1048         EXPECT_CALL(*dataHandler_, GetFileModifiedRecords(_)).Times(1).WillOnce(Return(1));
1049         shared_ptr<TaskContext> contextTest = make_shared<TaskContext>(dataHandler_);
1050         datasyncer_->ModifyFdirtyRecords(contextTest);
1051         GTEST_LOG_(INFO) << "ModifyFdirtyRecordsTest other 002";
1052         EXPECT_CALL(*dataHandler_, GetFileModifiedRecords(_)).Times(1).WillOnce(Return(0));
1053         datasyncer_->ModifyFdirtyRecords(contextTest);
1054         EXPECT_TRUE(true);
1055     } catch (...) {
1056         EXPECT_TRUE(false);
1057         GTEST_LOG_(INFO) << "ModifyFdirtyRecordsTest FAILED";
1058     }
1059     GTEST_LOG_(INFO) << "ModifyFdirtyRecordsTest end";
1060 }
1061 
1062 /**
1063  * @tc.name: OnCreateRecordsTest
1064  * @tc.desc: Verify the OnCreateRecords function
1065  * @tc.type: FUNC
1066  * @tc.require: #I7UU3Z
1067  */
1068 HWTEST_F(DataSyncerTest, OnCreateRecordsTest, TestSize.Level1)
1069 {
1070     GTEST_LOG_(INFO) << "OnCreateRecordsTest Start";
1071     try {
1072         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
1073         DriveKit::DKError err;
1074         shared_ptr<map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>> map =
1075             make_shared<std::map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>>();
1076 
1077         EXPECT_CALL(*dataHandler_, OnCreateRecords(_)).Times(1).WillOnce(Return(1));
1078         datasyncer_->OnCreateRecords(context, nullptr, map, err);
1079         GTEST_LOG_(INFO) << "OnCreateRecordsTest other 001";
1080         EXPECT_CALL(*dataHandler_, OnCreateRecords(_)).Times(1).WillOnce(Return(12));
1081         datasyncer_->OnCreateRecords(context, nullptr, map, err);
1082         GTEST_LOG_(INFO) << "OnCreateRecordsTest other 002";
1083         EXPECT_CALL(*dataHandler_, OnCreateRecords(_)).Times(1).WillOnce(Return(24));
1084         datasyncer_->OnCreateRecords(context, nullptr, map, err);
1085         GTEST_LOG_(INFO) << "OnCreateRecordsTest other 003";
1086         EXPECT_CALL(*dataHandler_, OnCreateRecords(_)).Times(1).WillOnce(Return(0));
1087         datasyncer_->OnCreateRecords(context, nullptr, map, err);
1088         EXPECT_TRUE(true);
1089     } catch (...) {
1090         EXPECT_TRUE(false);
1091         GTEST_LOG_(INFO) << "OnCreateRecordsTest FAILED";
1092     }
1093     GTEST_LOG_(INFO) << "OnCreateRecordsTest end";
1094 }
1095 
1096 /**
1097  * @tc.name: OnDeleteRecordsTest
1098  * @tc.desc: Verify the OnDeleteRecords function
1099  * @tc.type: FUNC
1100  * @tc.require: #I7UU3Z
1101  */
1102 HWTEST_F(DataSyncerTest, OnDeleteRecordsTest, TestSize.Level1)
1103 {
1104     GTEST_LOG_(INFO) << "OnDeleteRecordsTest Start";
1105     try {
1106         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
1107         DriveKit::DKError err;
1108         shared_ptr<map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>> map =
1109             make_shared<std::map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>>();
1110 
1111         EXPECT_CALL(*dataHandler_, OnDeleteRecords(_)).Times(1).WillOnce(Return(1));
1112         datasyncer_->OnDeleteRecords(context, nullptr, map, err);
1113         GTEST_LOG_(INFO) << "OnDeleteRecordsTest other 001";
1114         EXPECT_CALL(*dataHandler_, OnDeleteRecords(_)).Times(1).WillOnce(Return(12));
1115         datasyncer_->OnDeleteRecords(context, nullptr, map, err);
1116         GTEST_LOG_(INFO) << "OnDeleteRecordsTest other 002";
1117         EXPECT_CALL(*dataHandler_, OnDeleteRecords(_)).Times(1).WillOnce(Return(24));
1118         datasyncer_->OnDeleteRecords(context, nullptr, map, err);
1119         GTEST_LOG_(INFO) << "OnDeleteRecordsTest other 003";
1120         EXPECT_CALL(*dataHandler_, OnDeleteRecords(_)).Times(1).WillOnce(Return(0));
1121         datasyncer_->OnDeleteRecords(context, nullptr, map, err);
1122         EXPECT_TRUE(true);
1123     } catch (...) {
1124         EXPECT_TRUE(false);
1125         GTEST_LOG_(INFO) << "OnDeleteRecordsTest FAILED";
1126     }
1127     GTEST_LOG_(INFO) << "OnDeleteRecordsTest end";
1128 }
1129 
1130 /**
1131  * @tc.name: OnModifyMdirtyRecordsTest
1132  * @tc.desc: Verify the OnModifyMdirtyRecords function
1133  * @tc.type: FUNC
1134  * @tc.require: #I7UU3Z
1135  */
1136 HWTEST_F(DataSyncerTest, OnModifyMdirtyRecordsTest, TestSize.Level1)
1137 {
1138     GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest Start";
1139     try {
1140         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
1141         DriveKit::DKError err;
1142         shared_ptr<map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>> saveMap =
1143             make_shared<std::map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>>();
1144 
1145         EXPECT_CALL(*dataHandler_, OnModifyMdirtyRecords(_)).Times(1).WillOnce(Return(1));
1146         datasyncer_->OnModifyMdirtyRecords(context, nullptr, saveMap, nullptr, err);
1147         GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest other 001";
1148         EXPECT_CALL(*dataHandler_, OnModifyMdirtyRecords(_)).Times(1).WillOnce(Return(12));
1149         datasyncer_->OnModifyMdirtyRecords(context, nullptr, saveMap, nullptr, err);
1150         GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest other 002";
1151         EXPECT_CALL(*dataHandler_, OnModifyMdirtyRecords(_)).Times(1).WillOnce(Return(24));
1152         datasyncer_->OnModifyMdirtyRecords(context, nullptr, saveMap, nullptr, err);
1153         GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest other 003";
1154         EXPECT_CALL(*dataHandler_, OnModifyMdirtyRecords(_)).Times(1).WillOnce(Return(0));
1155         datasyncer_->OnModifyMdirtyRecords(context, nullptr, saveMap, nullptr, err);
1156         EXPECT_TRUE(true);
1157     } catch (...) {
1158         EXPECT_TRUE(false);
1159         GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest FAILED";
1160     }
1161     GTEST_LOG_(INFO) << "OnModifyMdirtyRecordsTest end";
1162 }
1163 
1164 /**
1165  * @tc.name: OnModifyFdirtyRecordsTest
1166  * @tc.desc: Verify the OnModifyFdirtyRecords function
1167  * @tc.type: FUNC
1168  * @tc.require: #I7UU3Z
1169  */
1170 HWTEST_F(DataSyncerTest, OnModifyFdirtyRecordsTest, TestSize.Level1)
1171 {
1172     GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest Start";
1173     try {
1174         shared_ptr<TaskContext> context = make_shared<TaskContext>(dataHandler_);
1175         DriveKit::DKError err;
1176         shared_ptr<map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>> saveMap =
1177             make_shared<std::map<DriveKit::DKRecordId, DriveKit::DKRecordOperResult>>();
1178 
1179         EXPECT_CALL(*dataHandler_, OnModifyFdirtyRecords(_)).Times(1).WillOnce(Return(1));
1180         datasyncer_->OnModifyFdirtyRecords(context, nullptr, saveMap, nullptr, err);
1181         GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest other 001";
1182         EXPECT_CALL(*dataHandler_, OnModifyFdirtyRecords(_)).Times(1).WillOnce(Return(12));
1183         datasyncer_->OnModifyFdirtyRecords(context, nullptr, saveMap, nullptr, err);
1184         GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest other 002";
1185         EXPECT_CALL(*dataHandler_, OnModifyFdirtyRecords(_)).Times(1).WillOnce(Return(24));
1186         datasyncer_->OnModifyFdirtyRecords(context, nullptr, saveMap, nullptr, err);
1187         GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest other 003";
1188         EXPECT_CALL(*dataHandler_, OnModifyFdirtyRecords(_)).Times(1).WillOnce(Return(0));
1189         datasyncer_->OnModifyFdirtyRecords(context, nullptr, saveMap, nullptr, err);
1190         EXPECT_TRUE(true);
1191     } catch (...) {
1192         EXPECT_TRUE(false);
1193         GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest FAILED";
1194     }
1195     GTEST_LOG_(INFO) << "OnModifyFdirtyRecordsTest end";
1196 }
1197 
1198 /**
1199  * @tc.name: BeginTransactionTest
1200  * @tc.desc: Verify the BeginTransaction function
1201  * @tc.type: FUNC
1202  * @tc.require: #I7UU3Z
1203  */
1204 HWTEST_F(DataSyncerTest, BeginTransactionTest, TestSize.Level1)
1205 {
1206     GTEST_LOG_(INFO) << "BeginTransaction Start";
1207     try {
1208         datasyncer_->BeginTransaction();
1209         EXPECT_TRUE(true);
1210     } catch (...) {
1211         EXPECT_TRUE(false);
1212         GTEST_LOG_(INFO) << "BeginTransaction FAILED";
1213     }
1214     GTEST_LOG_(INFO) << "BeginTransaction end";
1215 }
1216 
1217 /**
1218  * @tc.name: EndTransactionTest
1219  * @tc.desc: Verify the EndTransaction function
1220  * @tc.type: FUNC
1221  * @tc.require: #I7UU3Z
1222  */
1223 HWTEST_F(DataSyncerTest, EndTransactionTest, TestSize.Level1)
1224 {
1225     GTEST_LOG_(INFO) << "EndTransaction Start";
1226     try {
1227         datasyncer_->EndTransaction();
1228         EXPECT_TRUE(true);
1229     } catch (...) {
1230         EXPECT_TRUE(false);
1231         GTEST_LOG_(INFO) << "EndTransaction FAILED";
1232     }
1233     GTEST_LOG_(INFO) << "EndTransaction end";
1234 }
1235 
1236 /**
1237  * @tc.name: GetBundleNameTest
1238  * @tc.desc: Verify the GetBundleName function
1239  * @tc.type: FUNC
1240  * @tc.require: #I7UU3Z
1241  */
1242 HWTEST_F(DataSyncerTest, GetBundleNameTest, TestSize.Level1)
1243 {
1244     GTEST_LOG_(INFO) << "GetBundleName Start";
1245     string res = datasyncer_->GetBundleName();
1246     EXPECT_EQ(res, datasyncer_->bundleName_);
1247     GTEST_LOG_(INFO) << "GetBundleName end";
1248 }
1249 
1250 /**
1251  * @tc.name: GetUserIdTest
1252  * @tc.desc: Verify the GetUserId function
1253  * @tc.type: FUNC
1254  * @tc.require: #I7UU3Z
1255  */
1256 HWTEST_F(DataSyncerTest, GetUserIdTest, TestSize.Level1)
1257 {
1258     GTEST_LOG_(INFO) << "GetUserId Start";
1259     int res = datasyncer_->GetUserId();
1260     EXPECT_EQ(res, datasyncer_->userId_);
1261     GTEST_LOG_(INFO) << "GetUserId end";
1262 }
1263 
1264 /**
1265  * @tc.name: GetSyncStateTest
1266  * @tc.desc: Verify the GetSyncState function
1267  * @tc.type: FUNC
1268  * @tc.require: #I7UU3Z
1269  */
1270 HWTEST_F(DataSyncerTest, GetSyncStateTest, TestSize.Level1)
1271 {
1272     GTEST_LOG_(INFO) << "GetSyncState Start";
1273     try {
1274         datasyncer_->GetSyncState();
1275         EXPECT_TRUE(true);
1276     } catch (...) {
1277         EXPECT_TRUE(false);
1278         GTEST_LOG_(INFO) << "GetSyncState FAILED";
1279     }
1280     GTEST_LOG_(INFO) << "GetSyncState end";
1281 }
1282 
1283 /**
1284  * @tc.name: CompletePullTest
1285  * @tc.desc: Verify the CompletePull function
1286  * @tc.type: FUNC
1287  * @tc.require: #I7VDFI
1288  */
1289 HWTEST_F(DataSyncerTest, CompletePullTest, TestSize.Level1)
1290 {
1291     GTEST_LOG_(INFO) << "CompletePull Start";
1292     try {
1293         datasyncer_->CompletePull();
1294         datasyncer_->errorCode_ = 1;
1295         datasyncer_->CompletePull();
1296         EXPECT_TRUE(true);
1297     } catch (...) {
1298         EXPECT_TRUE(false);
1299         GTEST_LOG_(INFO) << "CompletePull FAILED";
1300     }
1301     GTEST_LOG_(INFO) << "CompletePull end";
1302 }
1303 
1304 /**
1305  * @tc.name: CompletePushTest
1306  * @tc.desc: Verify the CompletePush function
1307  * @tc.type: FUNC
1308  * @tc.require: #I7VDFI
1309  */
1310 HWTEST_F(DataSyncerTest, CompletePushTest, TestSize.Level1)
1311 {
1312     GTEST_LOG_(INFO) << "CompletePush Start";
1313     try {
1314         datasyncer_->CompletePush();
1315         datasyncer_->errorCode_ = 1;
1316         datasyncer_->CompletePush();
1317         EXPECT_TRUE(true);
1318     } catch (...) {
1319         EXPECT_TRUE(false);
1320         GTEST_LOG_(INFO) << "CompletePush FAILED";
1321     }
1322     GTEST_LOG_(INFO) << "CompletePush end";
1323 }
1324 
1325 /**
1326  * @tc.name: CompleteAllTest
1327  * @tc.desc: Verify the CompleteAll function
1328  * @tc.type: FUNC
1329  * @tc.require: #I7VDFI
1330  */
1331 HWTEST_F(DataSyncerTest, CompleteAllTest, TestSize.Level1)
1332 {
1333     GTEST_LOG_(INFO) << "CompleteAllTest Start";
1334     try {
1335         datasyncer_->lock_.count = 0;
1336         datasyncer_->errorCode_ = 0;
1337         datasyncer_->CompleteAll(true);
1338         datasyncer_->errorCode_ = 1;
1339         datasyncer_->CompleteAll(false);
1340         EXPECT_TRUE(true);
1341     } catch (...) {
1342         EXPECT_TRUE(false);
1343         GTEST_LOG_(INFO) << "CompleteAllTest FAILED";
1344     }
1345     GTEST_LOG_(INFO) << "CompleteAllTest end";
1346 }
1347 
1348 /**
1349  * @tc.name: SyncStateChangedNotifyTest
1350  * @tc.desc: Verify the SyncStateChangedNotify function
1351  * @tc.type: FUNC
1352  * @tc.require: #I7VDFI
1353  */
1354 HWTEST_F(DataSyncerTest, SyncStateChangedNotifyTest, TestSize.Level1)
1355 {
1356     GTEST_LOG_(INFO) << "SyncStateChangedNotify Start";
1357     try {
1358         datasyncer_->SyncStateChangedNotify(CloudSyncState::STOPPED, ErrorType::NO_ERROR);
1359         EXPECT_TRUE(true);
1360     } catch (...) {
1361         EXPECT_TRUE(false);
1362         GTEST_LOG_(INFO) << "SyncStateChangedNotify FAILED";
1363     }
1364     GTEST_LOG_(INFO) << "SyncStateChangedNotify end";
1365 }
1366 
1367 /**
1368  * @tc.name: NotifyCurrentSyncStateTest
1369  * @tc.desc: Verify the NotifyCurrentSyncState function
1370  * @tc.type: FUNC
1371  * @tc.require: #I7VDFI
1372  */
1373 HWTEST_F(DataSyncerTest, NotifyCurrentSyncStateTest, TestSize.Level1)
1374 {
1375     GTEST_LOG_(INFO) << "NotifyCurrentSyncStateTest Start";
1376     try {
1377         datasyncer_->NotifyCurrentSyncState();
1378         EXPECT_TRUE(true);
1379     } catch (...) {
1380         EXPECT_TRUE(false);
1381         GTEST_LOG_(INFO) << "NotifyCurrentSyncStateTest FAILED";
1382     }
1383     GTEST_LOG_(INFO) << "NotifyCurrentSyncStateTest end";
1384 }
1385 
1386 /**
1387  * @tc.name: SetErrorCodeMaskTest
1388  * @tc.desc: Verify the SetErrorCodeMask function
1389  * @tc.type: FUNC
1390  * @tc.require: #I7VDFI
1391  */
1392 HWTEST_F(DataSyncerTest, SetErrorCodeMaskTest, TestSize.Level1)
1393 {
1394     GTEST_LOG_(INFO) << "SetErrorCodeMaskTest Start";
1395     try {
1396         ErrorType errorType = NO_ERROR;
1397         datasyncer_->errorCode_ = 0;
1398         datasyncer_->SetErrorCodeMask(errorType);
1399         EXPECT_TRUE(true);
1400     } catch (...) {
1401         EXPECT_TRUE(false);
1402         GTEST_LOG_(INFO) << "SetErrorCodeMaskTest FAILED";
1403     }
1404     GTEST_LOG_(INFO) << "SetErrorCodeMaskTest end";
1405 }
1406 
1407 /**
1408  * @tc.name: GetErrorTypeTest
1409  * @tc.desc: Verify the GetErrorType function
1410  * @tc.type: FUNC
1411  * @tc.require: #I7VDFI
1412  */
1413 HWTEST_F(DataSyncerTest, GetErrorTypeTest, TestSize.Level1)
1414 {
1415     GTEST_LOG_(INFO) << "GetErrorType Start";
1416     datasyncer_->errorCode_ = E_OK;
1417     ErrorType result = datasyncer_->GetErrorType();
1418     EXPECT_EQ(ErrorType::NO_ERROR, result);
1419 
1420     datasyncer_->errorCode_ = 11;
1421     BatteryStatus::level_ = BatteryStatus::LEVEL_LOW;
1422     result = datasyncer_->GetErrorType();
1423     EXPECT_NE(ErrorType::NO_ERROR, result);
1424 
1425     datasyncer_->errorCode_ = 222;
1426     BatteryStatus::level_ = BatteryStatus::LEVEL_TOO_LOW;
1427     result = datasyncer_->GetErrorType();
1428     EXPECT_NE(ErrorType::NO_ERROR, result);
1429 
1430     BatteryStatus::level_ = BatteryStatus::LEVEL_NORMAL;
1431     result = datasyncer_->GetErrorType();
1432     EXPECT_NE(ErrorType::NO_ERROR, result);
1433     GTEST_LOG_(INFO) << "GetErrorType end";
1434 }
1435 
1436 /**
1437  * @tc.name: SaveSubscriptionTest
1438  * @tc.desc: Verify the SaveSubscription function
1439  * @tc.type: FUNC
1440  * @tc.require: #I7VDFI
1441  */
1442 HWTEST_F(DataSyncerTest, SaveSubscriptionTest, TestSize.Level1)
1443 {
1444     GTEST_LOG_(INFO) << "SaveSubscriptionTest Start";
1445     try {
1446         datasyncer_->SaveSubscription();
1447         EXPECT_TRUE(true);
1448     } catch (...) {
1449         EXPECT_TRUE(false);
1450         GTEST_LOG_(INFO) << "SaveSubscriptionTest FAILED";
1451     }
1452     GTEST_LOG_(INFO) << "SaveSubscriptionTest end";
1453 }
1454 
1455 /**
1456  * @tc.name: DeleteSubscriptionTest
1457  * @tc.desc: Verify the DeleteSubscription function
1458  * @tc.type: FUNC
1459  * @tc.require: #I7VDFI
1460  */
1461 HWTEST_F(DataSyncerTest, DeleteSubscriptionTest, TestSize.Level1)
1462 {
1463     GTEST_LOG_(INFO) << "DeleteSubscriptionTest Start";
1464     try {
1465         datasyncer_->DeleteSubscription();
1466         EXPECT_TRUE(true);
1467     } catch (...) {
1468         EXPECT_TRUE(false);
1469         GTEST_LOG_(INFO) << "DeleteSubscriptionTest FAILED";
1470     }
1471     GTEST_LOG_(INFO) << "DeleteSubscriptionTest end";
1472 }
1473 } // namespace OHOS::FileManagement::CloudSync::Test