• 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 
19 #include "gallery_data_syncer.h"
20 #include "dfs_error.h"
21 
22 
23 namespace OHOS::FileManagement::CloudSync::Test {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 
28 const int USER_ID = 100;
29 const std::string BUND_NAME = "com.ohos.photos";
30 class GalleryDataSyncerTest : public testing::Test {
31 public:
32     enum Action {
33         RETAIN_DATA = 0,
34         CLEAR_DATA
35     };
36     enum {
37         BEGIN,
38         DOWNLOADALBUM,
39         DOWNLOADFILE,
40         UPLOADALBUM,
41         UPLOADFILE,
42         END
43     };
44     static void SetUpTestCase(void);
45     static void TearDownTestCase(void);
46     void SetUp();
47     void TearDown();
48     shared_ptr<GalleryDataSyncer> galleryDataSyncer_;
49 };
SetUpTestCase(void)50 void GalleryDataSyncerTest::SetUpTestCase(void)
51 {
52     GTEST_LOG_(INFO) << "SetUpTestCase";
53 }
54 
TearDownTestCase(void)55 void GalleryDataSyncerTest::TearDownTestCase(void)
56 {
57     GTEST_LOG_(INFO) << "TearDownTestCase";
58 }
59 
SetUp(void)60 void GalleryDataSyncerTest::SetUp(void)
61 {
62     GTEST_LOG_(INFO) << "SetUp";
63     galleryDataSyncer_ = make_shared<GalleryDataSyncer>(BUND_NAME, USER_ID);
64 }
65 
TearDown(void)66 void GalleryDataSyncerTest::TearDown(void)
67 {
68     GTEST_LOG_(INFO) << "TearDown";
69 }
70 
71 /**
72  * @tc.name: CleanTest
73  * @tc.desc: Verify the Clean function
74  * @tc.type: FUNC
75  * @tc.require: I6JPKG
76  */
77 HWTEST_F(GalleryDataSyncerTest, CleanTest, TestSize.Level1)
78 {
79     int action = CLEAR_DATA;
80     int res = galleryDataSyncer_->Clean(action);
81     EXPECT_EQ(res, E_OK);
82 }
83 
84 /**
85  * @tc.name: StopDownloadFileTest
86  * @tc.desc: Verify the StopDownloadFile function
87  * @tc.type: FUNC
88  * @tc.require: I6JPKG
89  */
90 HWTEST_F(GalleryDataSyncerTest, StopDownloadFileTest, TestSize.Level1)
91 {
92     string path = "/data/service/el2/100/test";
93     int res = galleryDataSyncer_->StopDownloadFile(path, USER_ID);
94     EXPECT_EQ(res, E_OK);
95 }
96 
97 /**
98  * @tc.name: ResetTest
99  * @tc.desc: Verify the Reset function
100  * @tc.type: FUNC
101  * @tc.require: I6JPKG
102  */
103 HWTEST_F(GalleryDataSyncerTest, ResetTest, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "ResetTest Start";
106     try {
107         GalleryDataSyncer galleryDataSyncer(BUND_NAME, USER_ID);
108         galleryDataSyncer_->Reset();
109         EXPECT_TRUE(true);
110     } catch (...) {
111         EXPECT_TRUE(false);
112         GTEST_LOG_(INFO) << " ResetTest FAILED";
113     }
114     GTEST_LOG_(INFO) << "ResetTest End";
115 }
116 } // namespace OHOS::FileManagement::CloudSync::Test