• 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 <gmock/gmock.h>
18 
19 #include "cloud_download_uri_manager.h"
20 #include "dfs_error.h"
21 
22 namespace OHOS {
23 namespace FileManagement::CloudSync {
24 namespace Test {
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace std;
28 
29 class CloudDownloadUriManagerTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32     static void TearDownTestCase(void);
33     void SetUp();
34     void TearDown();
35 };
36 
SetUpTestCase(void)37 void CloudDownloadUriManagerTest::SetUpTestCase(void)
38 {
39     std::cout << "SetUpTestCase" << std::endl;
40 }
41 
TearDownTestCase(void)42 void CloudDownloadUriManagerTest::TearDownTestCase(void)
43 {
44     std::cout << "TearDownTestCase" << std::endl;
45 }
46 
SetUp(void)47 void CloudDownloadUriManagerTest::SetUp(void)
48 {
49     std::cout << "SetUp" << std::endl;
50 }
51 
TearDown(void)52 void CloudDownloadUriManagerTest::TearDown(void)
53 {
54     std::cout << "TearDown" << std::endl;
55 }
56 
57 /**
58  * @tc.name: GetInstanceTest
59  * @tc.desc: Verify the GetInstance function.
60  * @tc.type: FUNC
61  * @tc.require: I6H5MH
62  */
63 HWTEST_F(CloudDownloadUriManagerTest, GetInstanceTest, TestSize.Level1)
64 {
65     try {
66         CloudDownloadUriManager::GetInstance();
67     } catch (...) {
68         EXPECT_TRUE(false);
69     }
70 }
71 
72 /**
73  * @tc.name: AddPathToUriTest001
74  * @tc.desc: Verify the AddPathToUri function.
75  * @tc.type: FUNC
76  * @tc.require: I6H5MH
77  */
78 HWTEST_F(CloudDownloadUriManagerTest, AddPathToUriTest001, TestSize.Level1)
79 {
80     const std::string path = "file://data/file";
81     const std::string uri = "file://data/file/test";
82     CloudDownloadUriManager mUriMgr;
83     mUriMgr.AddPathToUri(path, uri);
84     EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
85 }
86 
87 /**
88  * @tc.name: AddPathToUriTest002
89  * @tc.desc: Verify the AddPathToUri function.
90  * @tc.type: FUNC
91  * @tc.require: issueI7UYAL
92  */
93 HWTEST_F(CloudDownloadUriManagerTest, AddPathToUriTest002, TestSize.Level1)
94 {
95     const std::string path = "file://data/file";
96     const std::string uri = "file://data/file/test";
97     CloudDownloadUriManager mUriMgr;
98     mUriMgr.pathUriMap_[path] = uri;
99     auto ret = mUriMgr.AddPathToUri(path, uri);
100     EXPECT_EQ(ret, E_STOP);
101 }
102 
103 /**
104  * @tc.name: RemoveUriTest001
105  * @tc.desc: Verify the RemoveUri function.
106  * @tc.type: FUNC
107  * @tc.require: I6H5MH
108  */
109 HWTEST_F(CloudDownloadUriManagerTest, RemoveUriTest001, TestSize.Level1)
110 {
111     const std::string path = "file://data/file";
112     const std::string uri = "file://data/file/test1";
113     CloudDownloadUriManager mUriMgr;
114     mUriMgr.AddPathToUri(path, uri);
115     EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
116     mUriMgr.RemoveUri(path);
117     auto ret = mUriMgr.pathUriMap_.find(path);
118     EXPECT_EQ(ret, mUriMgr.pathUriMap_.end());
119 }
120 
121 /**
122  * @tc.name: RemoveUriTest002
123  * @tc.desc: Verify the RemoveUri function.
124  * @tc.type: FUNC
125  * @tc.require: issueI7UYAL
126  */
127 HWTEST_F(CloudDownloadUriManagerTest, RemoveUriTest002, TestSize.Level1)
128 {
129     const std::string path = "file://data/file";
130     CloudDownloadUriManager mUriMgr;
131     mUriMgr.RemoveUri(path);
132     auto ret = mUriMgr.pathUriMap_.find(path);
133     EXPECT_EQ(ret, mUriMgr.pathUriMap_.end());
134 }
135 
136 /**
137  * @tc.name: RemoveUriTest003
138  * @tc.desc: Verify the RemoveUri function.
139  * @tc.type: FUNC
140  * @tc.require: issueI7UYAL
141  */
142 HWTEST_F(CloudDownloadUriManagerTest, RemoveUriTest003, TestSize.Level1)
143 {
144     int64_t downloadId = 3;
145     const std::string path = "file://data/file";
146     CloudDownloadUriManager mUriMgr;
147     (mUriMgr.downloadIdPathMap_)[3].push_back(path);
148     (mUriMgr.pathUriMap_)[path] = "test2";
149     mUriMgr.RemoveUri(downloadId);
150     auto ret1 = mUriMgr.pathUriMap_.find(path);
151     EXPECT_EQ(ret1, mUriMgr.pathUriMap_.end());
152     auto ret2 = mUriMgr.downloadIdPathMap_.find(downloadId);
153     EXPECT_EQ(ret2, mUriMgr.downloadIdPathMap_.end());
154 }
155 
156 /**
157  * @tc.name: GetUriTest001
158  * @tc.desc: Verify the GetUri function.
159  * @tc.type: FUNC
160  * @tc.require: I6H5MH
161  */
162 HWTEST_F(CloudDownloadUriManagerTest, GetUriTest001, TestSize.Level1)
163 {
164     const std::string path = "";
165     const std::string uri = "";
166     CloudDownloadUriManager mUriMgr;
167     string uriStr = mUriMgr.GetUri(path);
168     EXPECT_EQ(uriStr, uri);
169 }
170 
171 /**
172  * @tc.name: GetUriTest002
173  * @tc.desc: Verify the GetUri function.
174  * @tc.type: FUNC
175  * @tc.require: I6H5MH
176  */
177 HWTEST_F(CloudDownloadUriManagerTest, GetUriTest002, TestSize.Level1)
178 {
179     const std::string path = "file://data/file";
180     const std::string uri = "file://data/file/test2";
181     CloudDownloadUriManager mUriMgr;
182     mUriMgr.AddPathToUri(path, uri);
183     EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
184     string uriStr = mUriMgr.GetUri(path);
185     EXPECT_EQ(uriStr, uri);
186 }
187 
188 /**
189  * @tc.name: CheckDownloadIdPathMap001
190  * @tc.desc: Verify the CheckDownloadIdPathMap function.
191  * @tc.type: FUNC
192  * @tc.require: I6H5MH
193  */
194 HWTEST_F(CloudDownloadUriManagerTest, CheckDownloadIdPathMap001, TestSize.Level1)
195 {
196     int64_t downloadId = 1;
197     const std::string path = "file://data/file";
198     CloudDownloadUriManager mUriMgr;
199     (mUriMgr.downloadIdPathMap_)[1].push_back(path);
200     mUriMgr.CheckDownloadIdPathMap(downloadId);
201     auto ret = mUriMgr.downloadIdPathMap_.find(downloadId);
202     EXPECT_EQ(ret, mUriMgr.downloadIdPathMap_.end());
203 }
204 
205 /**
206  * @tc.name: CheckDownloadIdPathMap002
207  * @tc.desc: Verify the CheckDownloadIdPathMap function.
208  * @tc.type: FUNC
209  * @tc.require: I6H5MH
210  */
211 HWTEST_F(CloudDownloadUriManagerTest, CheckDownloadIdPathMap002, TestSize.Level1)
212 {
213     int64_t downloadId = 1;
214     const std::string path = "fild://data/file";
215     CloudDownloadUriManager mUriMgr;
216     (mUriMgr.downloadIdPathMap_)[1].push_back(path);
217     (mUriMgr.pathUriMap_)[path] = "test2";
218     mUriMgr.CheckDownloadIdPathMap(downloadId);
219     auto ret1 = mUriMgr.downloadIdPathMap_.find(downloadId);
220     EXPECT_NE(ret1, mUriMgr.downloadIdPathMap_.end());
221     auto ret2 = mUriMgr.pathUriMap_.find(path);
222     EXPECT_NE(ret2, mUriMgr.pathUriMap_.end());
223 }
224 
225 /**
226  * @tc.name: AddDownloadIdToPathTest
227  * @tc.desc: Verify the AddDownloadIdToPath function.
228  * @tc.type: FUNC
229  * @tc.require: I6H5MH
230  */
231 HWTEST_F(CloudDownloadUriManagerTest, AddDownloadIdToPathTest, TestSize.Level1)
232 {
233     std::vector<std::string> pathVec = {"file://data/file"};
234     int64_t downloadId = 0;
235     CloudDownloadUriManager mUriMgr;
236     auto ret = mUriMgr.AddDownloadIdToPath(downloadId, pathVec);
237     EXPECT_EQ(ret, E_OK);
238 }
239 } // namespace Test
240 } // namespace FileManagement::CloudSync {
241 } // namespace OHOS
242