1 /*
2 * Copyright (c) 2024 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 "clouddisk_notify_utils.h"
20 #include "clouddisk_rdb_utils.h"
21 #include "file_column.h"
22 #include "cloud_pref_impl.h"
23 #include "dfs_error.h"
24 #include "utils_log.h"
25
26 namespace OHOS {
27 namespace FileManagement::CloudDisk {
28 namespace Test {
29 using namespace testing::ext;
30 using namespace std;
31 const int32_t MOCKUSERID = 0;
32 const int32_t MOCK1 = 1;
33 const int32_t MOCK2 = 2;
34
MockFunc(CloudDiskFuseData* data, int64_t inode)35 std::shared_ptr<CloudDiskInode> MockFunc(CloudDiskFuseData* data, int64_t inode)
36 {
37 if (data->userId == MOCKUSERID) {
38 return nullptr;
39 }
40 std::shared_ptr<CloudDiskInode> inoPtr = make_shared<CloudDiskInode>();
41 if (data->userId == MOCK1) {
42 inoPtr->parent = FUSE_ROOT_ID;
43 }
44 if (data->userId == MOCK2) {
45 inoPtr->parent = 0;
46 inoPtr->fileName = "";
47 }
48 return inoPtr;
49 }
50
51 class CloudDiskNotifyUtilsTest : public testing::Test {
52 public:
53 static void SetUpTestCase(void);
54 static void TearDownTestCase(void);
55 void SetUp();
56 void TearDown();
57 };
58
SetUpTestCase(void)59 void CloudDiskNotifyUtilsTest::SetUpTestCase(void)
60 {
61 std::cout << "SetUpTestCase" << std::endl;
62 }
63
TearDownTestCase(void)64 void CloudDiskNotifyUtilsTest::TearDownTestCase(void)
65 {
66 std::cout << "TearDownTestCase" << std::endl;
67 }
68
SetUp(void)69 void CloudDiskNotifyUtilsTest::SetUp(void)
70 {
71 std::cout << "SetUp" << std::endl;
72 }
73
TearDown(void)74 void CloudDiskNotifyUtilsTest::TearDown(void)
75 {
76 std::cout << "TearDown" << std::endl;
77 }
78
79 /**
80 * @tc.name: GetNotifyDataTest001
81 * @tc.desc: Verify the GetNotifyData function.
82 * @tc.type: FUNC
83 * @tc.require: I6H5MH
84 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest001, TestSize.Level1)85 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest001, TestSize.Level1)
86 {
87 GTEST_LOG_(INFO) << "GetNotifyData Start";
88 CloudDiskNotifyUtils CloudDiskNotifyUtils;
89 CloudDiskFuseData* data = new CloudDiskFuseData();
90 FindCloudDiskInodeFunc func = MockFunc;
91 fuse_ino_t ino = FUSE_ROOT_ID;
92 NotifyData notifyData;
93 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, ino, notifyData);
94 EXPECT_EQ(ret, E_INVAL_ARG);
95 delete data;
96 GTEST_LOG_(INFO) << "GetNotifyData End";
97 }
98
99 /**
100 * @tc.name: GetNotifyDataTest002
101 * @tc.desc: Verify the GetNotifyData function.
102 * @tc.type: FUNC
103 * @tc.require: I6H5MH
104 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest002, TestSize.Level1)105 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest002, TestSize.Level1)
106 {
107 GTEST_LOG_(INFO) << "GetNotifyData Start";
108 CloudDiskNotifyUtils CloudDiskNotifyUtils;
109 CloudDiskFuseData* data = new CloudDiskFuseData();
110 data->userId = MOCKUSERID;
111 FindCloudDiskInodeFunc func = MockFunc;
112 fuse_ino_t ino = 0;
113 NotifyData notifyData;
114 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, ino, notifyData);
115 EXPECT_EQ(ret, E_INVAL_ARG);
116 delete data;
117 GTEST_LOG_(INFO) << "GetNotifyData End";
118 }
119
120 /**
121 * @tc.name: GetNotifyDataTest003
122 * @tc.desc: Verify the GetNotifyData function.
123 * @tc.type: FUNC
124 * @tc.require: I6H5MH
125 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest003, TestSize.Level1)126 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest003, TestSize.Level1)
127 {
128 GTEST_LOG_(INFO) << "GetNotifyData Start";
129 CloudDiskNotifyUtils CloudDiskNotifyUtils;
130 CloudDiskFuseData* data = new CloudDiskFuseData();
131 data->userId = MOCK1;
132 FindCloudDiskInodeFunc func = MockFunc;
133 fuse_ino_t ino = 0;
134 NotifyData notifyData;
135 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, ino, notifyData);
136 EXPECT_EQ(ret, E_OK);
137 delete data;
138 GTEST_LOG_(INFO) << "GetNotifyData End";
139 }
140
141 /**
142 * @tc.name: GetNotifyDataTest004
143 * @tc.desc: Verify the GetNotifyData function.
144 * @tc.type: FUNC
145 * @tc.require: I6H5MH
146 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest004, TestSize.Level1)147 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest004, TestSize.Level1)
148 {
149 GTEST_LOG_(INFO) << "GetNotifyData Start";
150 CloudDiskNotifyUtils CloudDiskNotifyUtils;
151 CloudDiskFuseData* data = new CloudDiskFuseData();
152 data->userId = MOCK2;
153 FindCloudDiskInodeFunc func = MockFunc;
154 fuse_ino_t ino = 0;
155 NotifyData notifyData;
156 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, ino, notifyData);
157 EXPECT_EQ(ret, E_OK);
158 delete data;
159 GTEST_LOG_(INFO) << "GetNotifyData End";
160 }
161
162 /**
163 * @tc.name: GetNotifyDataTest005
164 * @tc.desc: Verify the GetNotifyData function.
165 * @tc.type: FUNC
166 * @tc.require: I6H5MH
167 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest005, TestSize.Level1)168 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest005, TestSize.Level1)
169 {
170 GTEST_LOG_(INFO) << "GetNotifyData Start";
171 CloudDiskNotifyUtils CloudDiskNotifyUtils;
172 CloudDiskFuseData* data = new CloudDiskFuseData();
173 data->userId = MOCKUSERID;
174 FindCloudDiskInodeFunc func = MockFunc;
175 fuse_ino_t parent = 0;
176 string name = "test";
177 NotifyData notifyData;
178 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, parent, name, notifyData);
179 EXPECT_EQ(ret, E_INVAL_ARG);
180 delete data;
181 GTEST_LOG_(INFO) << "GetNotifyData End";
182 }
183
184 /**
185 * @tc.name: GetNotifyDataTest006
186 * @tc.desc: Verify the GetNotifyData function.
187 * @tc.type: FUNC
188 * @tc.require: I6H5MH
189 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest006, TestSize.Level1)190 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest006, TestSize.Level1)
191 {
192 GTEST_LOG_(INFO) << "GetNotifyData Start";
193 CloudDiskNotifyUtils CloudDiskNotifyUtils;
194 CloudDiskFuseData* data = new CloudDiskFuseData();
195 data->userId = MOCK2;
196 FindCloudDiskInodeFunc func = MockFunc;
197 fuse_ino_t parent = 0;
198 string name = "test";
199 NotifyData notifyData;
200 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, parent, name, notifyData);
201 EXPECT_EQ(ret, E_OK);
202 delete data;
203 GTEST_LOG_(INFO) << "GetNotifyData End";
204 }
205
206 /**
207 * @tc.name: GetNotifyDataTest007
208 * @tc.desc: Verify the GetNotifyData function.
209 * @tc.type: FUNC
210 * @tc.require: I6H5MH
211 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest007, TestSize.Level1)212 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest007, TestSize.Level1)
213 {
214 GTEST_LOG_(INFO) << "GetNotifyData Start";
215 CloudDiskNotifyUtils CloudDiskNotifyUtils;
216 CloudDiskFuseData* data = new CloudDiskFuseData();
217 FindCloudDiskInodeFunc func = MockFunc;
218 NotifyData notifyData;
219 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, nullptr, notifyData);
220 EXPECT_EQ(ret, E_INVAL_ARG);
221 delete data;
222 GTEST_LOG_(INFO) << "GetNotifyData End";
223 }
224
225 /**
226 * @tc.name: GetNotifyDataTest008
227 * @tc.desc: Verify the GetNotifyData function.
228 * @tc.type: FUNC
229 * @tc.require: I6H5MH
230 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest008, TestSize.Level1)231 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest008, TestSize.Level1)
232 {
233 GTEST_LOG_(INFO) << "GetNotifyData Start";
234 CloudDiskNotifyUtils CloudDiskNotifyUtils;
235 CloudDiskFuseData* data = new CloudDiskFuseData();
236 FindCloudDiskInodeFunc func = MockFunc;
237 shared_ptr<CloudDiskInode> inoPtr = make_shared<CloudDiskInode>();
238 NotifyData notifyData;
239 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, inoPtr, notifyData);
240 EXPECT_EQ(ret, E_OK);
241 delete data;
242 GTEST_LOG_(INFO) << "GetNotifyData End";
243 }
244
245 /**
246 * @tc.name: GetNotifyDataTest009
247 * @tc.desc: Verify the GetNotifyData function.
248 * @tc.type: FUNC
249 * @tc.require: I6H5MH
250 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest009, TestSize.Level1)251 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest009, TestSize.Level1)
252 {
253 GTEST_LOG_(INFO) << "GetNotifyData Start";
254 CloudDiskNotifyUtils CloudDiskNotifyUtils;
255 CloudDiskFuseData* data = new CloudDiskFuseData();
256 FindCloudDiskInodeFunc func = MockFunc;
257 string name = "test";
258 NotifyData notifyData;
259 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, nullptr, name, notifyData);
260 EXPECT_EQ(ret, E_INVAL_ARG);
261 delete data;
262 GTEST_LOG_(INFO) << "GetNotifyData End";
263 }
264
265 /**
266 * @tc.name: GetNotifyDataTest010
267 * @tc.desc: Verify the GetNotifyData function.
268 * @tc.type: FUNC
269 * @tc.require: I6H5MH
270 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest010, TestSize.Level1)271 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest010, TestSize.Level1)
272 {
273 GTEST_LOG_(INFO) << "GetNotifyData Start";
274 CloudDiskNotifyUtils CloudDiskNotifyUtils;
275 CloudDiskFuseData* data = new CloudDiskFuseData();
276 FindCloudDiskInodeFunc func = MockFunc;
277 shared_ptr<CloudDiskInode> pInoPtr = make_shared<CloudDiskInode>();
278 pInoPtr->fileName = "test";
279 string name = "test";
280 NotifyData notifyData;
281 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, pInoPtr, name, notifyData);
282 EXPECT_EQ(ret, E_OK);
283 delete data;
284 GTEST_LOG_(INFO) << "GetNotifyData End";
285 }
286
287 /**
288 * @tc.name: GetNotifyDataTest011
289 * @tc.desc: Verify the GetNotifyData function.
290 * @tc.type: FUNC
291 * @tc.require: I6H5MH
292 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest011, TestSize.Level1)293 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest011, TestSize.Level1)
294 {
295 GTEST_LOG_(INFO) << "GetNotifyData Start";
296 CloudDiskNotifyUtils CloudDiskNotifyUtils;
297 CloudDiskFuseData* data = new CloudDiskFuseData();
298 FindCloudDiskInodeFunc func = MockFunc;
299 shared_ptr<CloudDiskInode> pInoPtr = make_shared<CloudDiskInode>();
300 pInoPtr->fileName = "";
301 string name = "test";
302 NotifyData notifyData;
303 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, pInoPtr, name, notifyData);
304 EXPECT_EQ(ret, E_OK);
305 delete data;
306 GTEST_LOG_(INFO) << "GetNotifyData End";
307 }
308
309 /**
310 * @tc.name: GetCacheNodeTest001
311 * @tc.desc: Verify the GetCacheNode function.
312 * @tc.type: FUNC
313 * @tc.require: I6H5MH
314 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetCacheNodeTest001, TestSize.Level1)315 HWTEST_F(CloudDiskNotifyUtilsTest, GetCacheNodeTest001, TestSize.Level1)
316 {
317 GTEST_LOG_(INFO) << "GetCacheNode Start";
318 CloudDiskNotifyUtils CloudDiskNotifyUtils;
319 string cloudId = "100";
320 CacheNode cacheNode;
321 int ret = CloudDiskNotifyUtils.GetCacheNode(cloudId, cacheNode);
322 EXPECT_EQ(ret, E_INVAL_ARG);
323 GTEST_LOG_(INFO) << "GetCacheNode End";
324 }
325
326 /**
327 * @tc.name: PutCacheNodeTest001
328 * @tc.desc: Verify the PutCacheNode function.
329 * @tc.type: FUNC
330 * @tc.require: I6H5MH
331 */
HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest001, TestSize.Level1)332 HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest001, TestSize.Level1)
333 {
334 GTEST_LOG_(INFO) << "PutCacheNode Start";
335 CloudDiskNotifyUtils CloudDiskNotifyUtils;
336 string cloudId = "100";
337 CacheNode cacheNode;
338 cacheNode.isDir = "";
339 CloudDiskNotifyUtils.PutCacheNode(cloudId, cacheNode);
340 GTEST_LOG_(INFO) << "PutCacheNode End";
341 }
342
343 /**
344 * @tc.name: PutCacheNodeTest002
345 * @tc.desc: Verify the PutCacheNode function.
346 * @tc.type: FUNC
347 * @tc.require: I6H5MH
348 */
HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest002, TestSize.Level1)349 HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest002, TestSize.Level1)
350 {
351 GTEST_LOG_(INFO) << "PutCacheNode Start";
352 CloudDiskNotifyUtils CloudDiskNotifyUtils;
353 string cloudId = "100";
354 CacheNode cacheNode;
355 cacheNode.isDir = "directory";
356 CloudDiskNotifyUtils.PutCacheNode(cloudId, cacheNode);
357 GTEST_LOG_(INFO) << "PutCacheNode End";
358 }
359
360 /**
361 * @tc.name: GetUriFromCacheTest001
362 * @tc.desc: Verify the GetUriFromCache function.
363 * @tc.type: FUNC
364 * @tc.require: I6H5MH
365 */
HWTEST_F(CloudDiskNotifyUtilsTest, GetUriFromCacheTest001, TestSize.Level1)366 HWTEST_F(CloudDiskNotifyUtilsTest, GetUriFromCacheTest001, TestSize.Level1)
367 {
368 GTEST_LOG_(INFO) << "GetUriFromCache Start";
369 CloudDiskNotifyUtils CloudDiskNotifyUtils;
370 string bundleName = "com.ohos.photos";
371 string rootId = "rootId";
372 CacheNode cacheNode;
373 cacheNode.isDir = "";
374 cacheNode.cloudId = "";
375 string uri = "";
376 int ret = CloudDiskNotifyUtils.GetUriFromCache(bundleName, rootId, cacheNode, uri);
377 EXPECT_EQ(ret, E_INVAL_ARG);
378 GTEST_LOG_(INFO) << "GetUriFromCache End";
379 }
380 } // namespace Test
381 } // namespace FileManagement::CloudSync
382 } // namespace OHOS