• 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 <gtest/gtest.h>
17 #include <memory>
18 
19 #include "cloud_sync_common.h"
20 #include "dfs_error.h"
21 #include "iservice_registry.h"
22 
23 namespace OHOS {
24 namespace FileManagement::CloudSync {
25 namespace Test {
26 using namespace testing::ext;
27 using namespace testing;
28 using namespace std;
29 
30 class CloudSyncCommonTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase(void)38 void CloudSyncCommonTest::SetUpTestCase(void)
39 {
40     std::cout << "SetUpTestCase" << std::endl;
41 }
42 
TearDownTestCase(void)43 void CloudSyncCommonTest::TearDownTestCase(void)
44 {
45     std::cout << "TearDownTestCase" << std::endl;
46 }
47 
SetUp(void)48 void CloudSyncCommonTest::SetUp(void)
49 {
50     std::cout << "SetUp" << std::endl;
51 }
52 
TearDown(void)53 void CloudSyncCommonTest::TearDown(void)
54 {
55     std::cout << "TearDown" << std::endl;
56 }
57 
58 /*
59  * @tc.name: Marshalling
60  * @tc.desc: Verify the Marshalling function.
61  * @tc.type: FUNC
62  * @tc.require: I6H5MH
63  */
64 HWTEST_F(CloudSyncCommonTest, Marshalling, TestSize.Level1)
65 {
66     GTEST_LOG_(INFO) << "Marshalling Start";
67     try {
68         SwitchDataObj switchDataObj;
69         Parcel parcel;
70         string strSwitchData = "continue";
71         bool boolSwitchData = false;
72         switchDataObj.switchData.insert({strSwitchData, boolSwitchData});
73         auto res = switchDataObj.Marshalling(parcel);
74         EXPECT_TRUE(!res);
75     } catch (...) {
76         EXPECT_TRUE(false);
77         GTEST_LOG_(INFO) << " Marshalling FAILED";
78     }
79     GTEST_LOG_(INFO) << "Marshalling End";
80 }
81 
82 /*
83  * @tc.name: Marshalling001
84  * @tc.desc: Verify the Marshalling001 function.
85  * @tc.type: FUNC
86  * @tc.require: I6H5MH
87  */
88 HWTEST_F(CloudSyncCommonTest, Marshalling001, TestSize.Level1)
89 {
90     GTEST_LOG_(INFO) << "Marshalling001 Start";
91     try {
92         SwitchDataObj switchDataObj;
93         Parcel parcel;
94 
95         auto res = switchDataObj.Marshalling(parcel);
96         EXPECT_TRUE(!res);
97 
98         string strSwitchData = "continue";
99         bool boolSwitchData = true;
100         switchDataObj.switchData.insert({strSwitchData, boolSwitchData});
101         res = switchDataObj.Marshalling(parcel);
102         EXPECT_TRUE(res);
103     } catch (...) {
104         EXPECT_TRUE(false);
105         GTEST_LOG_(INFO) << " Marshalling001 FAILED";
106     }
107     GTEST_LOG_(INFO) << "Marshalling001 End";
108 }
109 
110 /*
111  * @tc.name: Marshalling002
112  * @tc.desc: Verify the Marshalling002 function.
113  * @tc.type: FUNC
114  * @tc.require: I6H5MH
115  */
116 HWTEST_F(CloudSyncCommonTest, Marshalling002, TestSize.Level1)
117 {
118     GTEST_LOG_(INFO) << "Marshalling002 Start";
119     try {
120         SwitchDataObj switchDataObj;
121         Parcel parcel;
122 
123         string strSwitchData = "strSwitchData";
124         bool boolSwitchData = false;
125         switchDataObj.switchData.insert({strSwitchData, boolSwitchData});
126         auto res = switchDataObj.Marshalling(parcel);
127         EXPECT_TRUE(!res);
128     } catch (...) {
129         EXPECT_TRUE(false);
130         GTEST_LOG_(INFO) << " Marshalling002 FAILED";
131     }
132     GTEST_LOG_(INFO) << "Marshalling002 End";
133 }
134 
135 /*
136  * @tc.name: Marshalling003
137  * @tc.desc: Verify the Marshalling003 function.
138  * @tc.type: FUNC
139  * @tc.require: I6H5MH
140  */
141 HWTEST_F(CloudSyncCommonTest, Marshalling003, TestSize.Level1)
142 {
143     GTEST_LOG_(INFO) << "Marshalling003 Start";
144     try {
145         DownloadProgressObj downloadProgressObj;
146         Parcel parcel;
147         downloadProgressObj.path = "continue";
148         downloadProgressObj.state = downloadProgressObj.RUNNING;
149         downloadProgressObj.downloadedSize = 1;
150         downloadProgressObj.totalSize = 1;
151         auto res = downloadProgressObj.Marshalling(parcel);
152         EXPECT_TRUE(!res);
153 
154         downloadProgressObj.path = "continue";
155         downloadProgressObj.state = downloadProgressObj.RUNNING;
156         downloadProgressObj.downloadedSize = 1;
157         downloadProgressObj.totalSize = 0;
158         res = downloadProgressObj.Marshalling(parcel);
159         EXPECT_TRUE(!res);
160 
161         downloadProgressObj.path = "continue";
162         downloadProgressObj.state = downloadProgressObj.RUNNING;
163         downloadProgressObj.downloadedSize = 0;
164         downloadProgressObj.totalSize = 0;
165         res = downloadProgressObj.Marshalling(parcel);
166         EXPECT_TRUE(!res);
167 
168         downloadProgressObj.path = "continue";
169         downloadProgressObj.state = downloadProgressObj.STOPPED;
170         downloadProgressObj.downloadedSize = 0;
171         downloadProgressObj.totalSize = 0;
172         res = downloadProgressObj.Marshalling(parcel);
173         EXPECT_TRUE(!res);
174 
175         downloadProgressObj.path = "path";
176         downloadProgressObj.state = downloadProgressObj.STOPPED;
177         downloadProgressObj.downloadedSize = 0;
178         downloadProgressObj.totalSize = 0;
179         res = downloadProgressObj.Marshalling(parcel);
180         EXPECT_TRUE(!res);
181     } catch (...) {
182         EXPECT_TRUE(false);
183         GTEST_LOG_(INFO) << " Marshalling003 FAILED";
184     }
185     GTEST_LOG_(INFO) << "Marshalling003 End";
186 }
187 
188 /*
189  * @tc.name: Marshalling004
190  * @tc.desc: Verify the Marshalling004 function.
191  * @tc.type: FUNC
192  * @tc.require: I6H5MH
193  */
194 HWTEST_F(CloudSyncCommonTest, Marshalling004, TestSize.Level1)
195 {
196     GTEST_LOG_(INFO) << "Marshalling004 Start";
197     try {
198         CleanOptions cleanOptions;
199         Parcel parcel;
200 
201         auto res = cleanOptions.Marshalling(parcel);
202         EXPECT_TRUE(!res);
203 
204         string strActionsData = "continue";
205         int32_t intActionsData = 1;
206         cleanOptions.appActionsData.insert({strActionsData, intActionsData});
207         res = cleanOptions.Marshalling(parcel);
208         EXPECT_TRUE(res);
209     } catch (...) {
210         EXPECT_TRUE(false);
211         GTEST_LOG_(INFO) << " Marshalling004 FAILED";
212     }
213     GTEST_LOG_(INFO) << "Marshalling004 End";
214 }
215 
216 /*
217  * @tc.name: Marshalling005
218  * @tc.desc: Verify the Marshalling005 function.
219  * @tc.type: FUNC
220  * @tc.require: I6H5MH
221  */
222 HWTEST_F(CloudSyncCommonTest, Marshalling005, TestSize.Level1)
223 {
224     GTEST_LOG_(INFO) << "Marshalling005 Start";
225     try {
226         CleanOptions cleanOptions;
227         Parcel parcel;
228         string strActionsData = "strActionsData";
229         int32_t intActionsData = 0;
230         cleanOptions.appActionsData.insert({strActionsData, intActionsData});
231         auto res = cleanOptions.Marshalling(parcel);
232         EXPECT_TRUE(!res);
233     } catch (...) {
234         EXPECT_TRUE(false);
235         GTEST_LOG_(INFO) << " Marshalling005 FAILED";
236     }
237     GTEST_LOG_(INFO) << "Marshalling005 End";
238 }
239 
240 /*
241  * @tc.name: Marshalling006
242  * @tc.desc: Verify the Marshalling006 function.
243  * @tc.type: FUNC
244  * @tc.require: I6H5MH
245  */
246 HWTEST_F(CloudSyncCommonTest, Marshalling006, TestSize.Level1)
247 {
248     GTEST_LOG_(INFO) << "Marshalling006 Start";
249     try {
250         CleanOptions cleanOptions;
251         Parcel parcel;
252 
253         auto res = cleanOptions.Marshalling(parcel);
254         EXPECT_TRUE(!res);
255 
256         string strActionsData = "continue";
257         int32_t intActionsData = 0;
258         cleanOptions.appActionsData.insert({strActionsData, intActionsData});
259         res = cleanOptions.Marshalling(parcel);
260         EXPECT_TRUE(!res);
261     } catch (...) {
262         EXPECT_TRUE(false);
263         GTEST_LOG_(INFO) << " Marshalling006 FAILED";
264     }
265     GTEST_LOG_(INFO) << "Marshalling006 End";
266 }
267 
268 /*
269  * @tc.name: Unmarshalling001
270  * @tc.desc: Verify the Unmarshalling001 function.
271  * @tc.type: FUNC
272  * @tc.require: I6H5MH
273  */
274 HWTEST_F(CloudSyncCommonTest, Unmarshalling001, TestSize.Level1)
275 {
276     GTEST_LOG_(INFO) << "Unmarshalling001 Start";
277     try {
278         auto switchDataObj = make_shared<SwitchDataObj>();
279         Parcel parcel;
280         auto res = switchDataObj->Unmarshalling(parcel);
281         EXPECT_TRUE(res == nullptr);
282     } catch (...) {
283         EXPECT_TRUE(false);
284         GTEST_LOG_(INFO) << " Unmarshalling001 FAILED";
285     }
286     GTEST_LOG_(INFO) << "Unmarshalling001 End";
287 }
288 
289 /*
290  * @tc.name: Unmarshalling002
291  * @tc.desc: Verify the Unmarshalling002 function.
292  * @tc.type: FUNC
293  * @tc.require: I6H5MH
294  */
295 HWTEST_F(CloudSyncCommonTest, Unmarshalling002, TestSize.Level1)
296 {
297     GTEST_LOG_(INFO) << "Unmarshalling002 Start";
298     try {
299         auto downloadProgressObj = make_shared<DownloadProgressObj>();
300         Parcel parcel;
301         auto res = downloadProgressObj->Unmarshalling(parcel);
302         EXPECT_TRUE(res == nullptr);
303     } catch (...) {
304         EXPECT_TRUE(false);
305         GTEST_LOG_(INFO) << " Unmarshalling002 FAILED";
306     }
307     GTEST_LOG_(INFO) << "Unmarshalling002 End";
308 }
309 
310 /*
311  * @tc.name: Unmarshalling003
312  * @tc.desc: Verify the Unmarshalling003 function.
313  * @tc.type: FUNC
314  * @tc.require: I6H5MH
315  */
316 HWTEST_F(CloudSyncCommonTest, Unmarshalling003, TestSize.Level1)
317 {
318     GTEST_LOG_(INFO) << "Unmarshalling003 Start";
319     try {
320         auto cleanOptions = make_shared<CleanOptions>();
321         Parcel parcel;
322         auto res = cleanOptions->Unmarshalling(parcel);
323         EXPECT_TRUE(res == nullptr);
324     } catch (...) {
325         EXPECT_TRUE(false);
326         GTEST_LOG_(INFO) << " Unmarshalling003 FAILED";
327     }
328     GTEST_LOG_(INFO) << "Unmarshalling003 End";
329 }
330 
331 /*
332  * @tc.name: ReadFromParcel001
333  * @tc.desc: Verify the ReadFromParcel001 function.
334  * @tc.type: FUNC
335  * @tc.require: I6H5MH
336  */
337 HWTEST_F(CloudSyncCommonTest, ReadFromParcel001, TestSize.Level1)
338 {
339     GTEST_LOG_(INFO) << "ReadFromParcel001 Start";
340     try {
341         SwitchDataObj switchDataObj;
342         Parcel parcel;
343         parcel.dataSize_ = 0;
344         auto res = switchDataObj.ReadFromParcel(parcel);
345         EXPECT_TRUE(!res);
346     } catch (...) {
347         EXPECT_TRUE(false);
348         GTEST_LOG_(INFO) << " ReadFromParcel001 FAILED";
349     }
350     GTEST_LOG_(INFO) << "ReadFromParcel001 End";
351 }
352 
353 /*
354  * @tc.name: ReadFromParcel002
355  * @tc.desc: Verify the ReadFromParcel002 function.
356  * @tc.type: FUNC
357  * @tc.require: I6H5MH
358  */
359 HWTEST_F(CloudSyncCommonTest, ReadFromParcel002, TestSize.Level1)
360 {
361     GTEST_LOG_(INFO) << "ReadFromParcel002 Start";
362     try {
363         SwitchDataObj switchDataObj;
364         Parcel parcel;
365         parcel.dataSize_ = 1025;
366         auto res = switchDataObj.ReadFromParcel(parcel);
367         EXPECT_TRUE(!res);
368     } catch (...) {
369         EXPECT_TRUE(false);
370         GTEST_LOG_(INFO) << " ReadFromParcel002 FAILED";
371     }
372     GTEST_LOG_(INFO) << "ReadFromParcel002 End";
373 }
374 
375 /*
376  * @tc.name: ReadFromParcel003
377  * @tc.desc: Verify the ReadFromParcel003 function.
378  * @tc.type: FUNC
379  * @tc.require: I6H5MH
380  */
381 HWTEST_F(CloudSyncCommonTest, ReadFromParcel003, TestSize.Level1)
382 {
383     GTEST_LOG_(INFO) << "ReadFromParcel003 Start";
384     try {
385         SwitchDataObj switchDataObj;
386         Parcel parcel;
387         parcel.dataSize_ = 3;
388         auto res = switchDataObj.ReadFromParcel(parcel);
389         EXPECT_TRUE(!res);
390 
391         parcel.data_ = new uint8_t();
392         parcel.writable_ = 0;
393         res = switchDataObj.ReadFromParcel(parcel);
394         EXPECT_TRUE(!res);
395 
396         parcel.writable_ = 1;
397         res = switchDataObj.ReadFromParcel(parcel);
398         EXPECT_TRUE(res);
399     } catch (...) {
400         EXPECT_TRUE(false);
401         GTEST_LOG_(INFO) << " ReadFromParcel003 FAILED";
402     }
403     GTEST_LOG_(INFO) << "ReadFromParcel003 End";
404 }
405 
406 /*
407  * @tc.name: ReadFromParcel004
408  * @tc.desc: Verify the ReadFromParcel004 function.
409  * @tc.type: FUNC
410  * @tc.require: I6H5MH
411  */
412 HWTEST_F(CloudSyncCommonTest, ReadFromParcel004, TestSize.Level1)
413 {
414     GTEST_LOG_(INFO) << "ReadFromParcel004 Start";
415     try {
416         CleanOptions cleanOptions;
417         Parcel parcel;
418         parcel.dataSize_ = 0;
419         auto res = cleanOptions.ReadFromParcel(parcel);
420         EXPECT_TRUE(!res);
421     } catch (...) {
422         EXPECT_TRUE(false);
423         GTEST_LOG_(INFO) << " ReadFromParcel004 FAILED";
424     }
425     GTEST_LOG_(INFO) << "ReadFromParcel004 End";
426 }
427 
428 /*
429  * @tc.name: ReadFromParcel005
430  * @tc.desc: Verify the ReadFromParcel005 function.
431  * @tc.type: FUNC
432  * @tc.require: I6H5MH
433  */
434 HWTEST_F(CloudSyncCommonTest, ReadFromParcel005, TestSize.Level1)
435 {
436     GTEST_LOG_(INFO) << "ReadFromParcel005 Start";
437     try {
438         CleanOptions cleanOptions;
439         Parcel parcel;
440         parcel.dataSize_ = 1025;
441         auto res = cleanOptions.ReadFromParcel(parcel);
442         EXPECT_TRUE(!res);
443     } catch (...) {
444         EXPECT_TRUE(false);
445         GTEST_LOG_(INFO) << " ReadFromParcel005 FAILED";
446     }
447     GTEST_LOG_(INFO) << "ReadFromParcel005 End";
448 }
449 
450 /*
451  * @tc.name: ReadFromParcel006
452  * @tc.desc: Verify the ReadFromParcel006 function.
453  * @tc.type: FUNC
454  * @tc.require: I6H5MH
455  */
456 HWTEST_F(CloudSyncCommonTest, ReadFromParcel006, TestSize.Level1)
457 {
458     GTEST_LOG_(INFO) << "ReadFromParcel006 Start";
459     try {
460         CleanOptions cleanOptions;
461         Parcel parcel;
462         parcel.dataSize_ = 3;
463         auto res = cleanOptions.ReadFromParcel(parcel);
464         EXPECT_TRUE(!res);
465 
466         parcel.data_ = new uint8_t();
467         parcel.readCursor_ = 0;
468         res = cleanOptions.ReadFromParcel(parcel);
469         EXPECT_TRUE(!res);
470 
471         parcel.readCursor_ = 1;
472         res = cleanOptions.ReadFromParcel(parcel);
473         EXPECT_TRUE(res);
474     } catch (...) {
475         EXPECT_TRUE(false);
476         GTEST_LOG_(INFO) << " ReadFromParcel006 FAILED";
477     }
478     GTEST_LOG_(INFO) << "ReadFromParcel006 End";
479 }
480 
481 /*
482  * @tc.name: ReadFromParcel007
483  * @tc.desc: Verify the ReadFromParcel007 function.
484  * @tc.type: FUNC
485  * @tc.require: I6H5MH
486  */
487 HWTEST_F(CloudSyncCommonTest, ReadFromParcel007, TestSize.Level1)
488 {
489     GTEST_LOG_(INFO) << "ReadFromParcel007 Start";
490     try {
491         DownloadProgressObj downloadProgressObj;
492         Parcel parcel;
493         auto res = downloadProgressObj.ReadFromParcel(parcel);
494         EXPECT_TRUE(!res);
495 
496         parcel.data_ = new uint8_t();
497         parcel.readCursor_ = 0;
498         res = downloadProgressObj.ReadFromParcel(parcel);
499         EXPECT_TRUE(!res);
500 
501         parcel.readCursor_ = 1;
502         res = downloadProgressObj.ReadFromParcel(parcel);
503         EXPECT_TRUE(!res);
504 
505         downloadProgressObj.downloadedSize = 0;
506         res = downloadProgressObj.ReadFromParcel(parcel);
507         EXPECT_TRUE(!res);
508 
509         downloadProgressObj.downloadedSize = 1;
510         downloadProgressObj.totalSize = 0;
511         res = downloadProgressObj.ReadFromParcel(parcel);
512         EXPECT_TRUE(!res);
513 
514         downloadProgressObj.totalSize = 1;
515         res = downloadProgressObj.ReadFromParcel(parcel);
516         EXPECT_TRUE(res);
517     } catch (...) {
518         EXPECT_TRUE(false);
519         GTEST_LOG_(INFO) << " ReadFromParcel007 FAILED";
520     }
521     GTEST_LOG_(INFO) << "ReadFromParcel007 End";
522 }
523 
524 /*
525  * @tc.name: to_string
526  * @tc.desc: Verify the to_string function.
527  * @tc.type: FUNC
528  * @tc.require: I6H5MH
529  */
530 HWTEST_F(CloudSyncCommonTest, to_string, TestSize.Level1)
531 {
532     GTEST_LOG_(INFO) << "to_string Start";
533     try {
534         DownloadProgressObj downloadProgressObj;
535         auto res = downloadProgressObj.to_string();
536         std::string expectStr = "DownloadProgressObj [path:  state: 0 downloaded: 0 total: 0]";
537         EXPECT_EQ(res, expectStr);
538     } catch (...) {
539         EXPECT_TRUE(false);
540         GTEST_LOG_(INFO) << " to_string FAILED";
541     }
542     GTEST_LOG_(INFO) << "to_string End";
543 }
544 /*
545  * @tc.name: ReadFromParcel00
546  * @tc.desc: Verify the ReadFromParcel00 function.
547  * @tc.type: FUNC
548  * @tc.require: I6H5MH
549  */
550 HWTEST_F(CloudSyncCommonTest, ReadFromParcel00, TestSize.Level1)
551 {
552     GTEST_LOG_(INFO) << "ReadFromParcel00 Start";
553     try {
554         AssetInfoObj assetInfo;
555         Parcel parcel;
556         auto res = assetInfo.ReadFromParcel(parcel);
557         EXPECT_TRUE(res);
558     } catch (...) {
559         EXPECT_TRUE(false);
560         GTEST_LOG_(INFO) << " ReadFromParcel00 FAILED";
561     }
562     GTEST_LOG_(INFO) << "ReadFromParcel00 End";
563 }
564 
565 /*
566  * @tc.name: Marshalling007
567  * @tc.desc: Verify the Marshalling007 function.
568  * @tc.type: FUNC
569  * @tc.require: I6H5MH
570  */
571 HWTEST_F(CloudSyncCommonTest, Marshalling007, TestSize.Level1)
572 {
573     GTEST_LOG_(INFO) << "Marshalling007 Start";
574     try {
575         AssetInfoObj assetInfo;
576         Parcel parcel;
577         auto res = assetInfo.Marshalling(parcel);
578         EXPECT_TRUE(res);
579     } catch (...) {
580         EXPECT_TRUE(false);
581         GTEST_LOG_(INFO) << " Marshalling007 FAILED";
582     }
583     GTEST_LOG_(INFO) << "Marshalling007 End";
584 }
585 
586 /*
587  * @tc.name: Unmarshalling
588  * @tc.desc: Verify the Unmarshalling function.
589  * @tc.type: FUNC
590  * @tc.require: I6H5MH
591  */
592 HWTEST_F(CloudSyncCommonTest, Unmarshalling, TestSize.Level1)
593 {
594     GTEST_LOG_(INFO) << "Unmarshalling Start";
595     try {
596         auto assetInfo = make_shared<AssetInfoObj>();
597         Parcel parcel;
598         auto res = assetInfo->Unmarshalling(parcel);
599         EXPECT_TRUE(res != nullptr);
600     } catch (...) {
601         EXPECT_TRUE(false);
602         GTEST_LOG_(INFO) << " Unmarshalling FAILED";
603     }
604     GTEST_LOG_(INFO) << "Unmarshalling End";
605 }
606 } // namespace Test
607 } // namespace FileManagement::CloudSync
608 } // namespace OHOS
609