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
32 class CloudDiskNotifyUtilsTest : public testing::Test {
33 public:
34 static void SetUpTestCase(void);
35 static void TearDownTestCase(void);
36 void SetUp();
37 void TearDown();
38 };
39
SetUpTestCase(void)40 void CloudDiskNotifyUtilsTest::SetUpTestCase(void)
41 {
42 std::cout << "SetUpTestCase" << std::endl;
43 }
44
TearDownTestCase(void)45 void CloudDiskNotifyUtilsTest::TearDownTestCase(void)
46 {
47 std::cout << "TearDownTestCase" << std::endl;
48 }
49
SetUp(void)50 void CloudDiskNotifyUtilsTest::SetUp(void)
51 {
52 std::cout << "SetUp" << std::endl;
53 }
54
TearDown(void)55 void CloudDiskNotifyUtilsTest::TearDown(void)
56 {
57 std::cout << "TearDown" << std::endl;
58 }
59
60 /**
61 * @tc.name: GetNotifyDataTest001
62 * @tc.desc: Verify the GetNotifyData function.
63 * @tc.type: FUNC
64 * @tc.require: I6H5MH
65 */
66 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest001, TestSize.Level1)
67 {
68 GTEST_LOG_(INFO) << "GetNotifyData Start";
69 CloudDiskNotifyUtils CloudDiskNotifyUtils;
70 CloudDiskFuseData* data = nullptr;
71 FindCloudDiskInodeFunc func;
72 fuse_ino_t ino = 1;
73 NotifyData notifyData;
74 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, ino, notifyData);
75 EXPECT_EQ(ret, E_INVAL_ARG);
76 GTEST_LOG_(INFO) << "GetNotifyData End";
77 }
78
79 /**
80 * @tc.name: GetNotifyDataTest002
81 * @tc.desc: Verify the GetNotifyData function.
82 * @tc.type: FUNC
83 * @tc.require: I6H5MH
84 */
85 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest002, TestSize.Level1)
86 {
87 GTEST_LOG_(INFO) << "GetNotifyData Start";
88 CloudDiskNotifyUtils CloudDiskNotifyUtils;
89 CloudDiskFuseData* data = nullptr;
90 FindCloudDiskInodeFunc func;
91 shared_ptr<CloudDiskInode> inoPtr = nullptr;
92 NotifyData notifyData;
93 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, inoPtr, notifyData);
94 EXPECT_EQ(ret, E_INVAL_ARG);
95 GTEST_LOG_(INFO) << "GetNotifyData End";
96 }
97
98 /**
99 * @tc.name: GetNotifyDataTest003
100 * @tc.desc: Verify the GetNotifyData function.
101 * @tc.type: FUNC
102 * @tc.require: I6H5MH
103 */
104 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest003, TestSize.Level1)
105 {
106 GTEST_LOG_(INFO) << "GetNotifyData Start";
107 CloudDiskNotifyUtils CloudDiskNotifyUtils;
108 CloudDiskFuseData* data = nullptr;
109 FindCloudDiskInodeFunc func;
110 shared_ptr<CloudDiskInode> inoPtr = make_shared<CloudDiskInode>();
111 inoPtr->parent = 1;
112 NotifyData notifyData;
113 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, inoPtr, notifyData);
114 EXPECT_EQ(ret, E_OK);
115 GTEST_LOG_(INFO) << "GetNotifyData End";
116 }
117
118 /**
119 * @tc.name: GetNotifyDataTest004
120 * @tc.desc: Verify the GetNotifyData function.
121 * @tc.type: FUNC
122 * @tc.require: I6H5MH
123 */
124 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest004, TestSize.Level1)
125 {
126 GTEST_LOG_(INFO) << "GetNotifyData Start";
127 CloudDiskNotifyUtils CloudDiskNotifyUtils;
128 CloudDiskFuseData* data = nullptr;
129 FindCloudDiskInodeFunc func;
130 shared_ptr<CloudDiskInode> inoPtr = nullptr;
131 NotifyData notifyData;
132 string name = "test";
133 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, inoPtr, name, notifyData);
134 EXPECT_EQ(ret, E_INVAL_ARG);
135 GTEST_LOG_(INFO) << "GetNotifyData End";
136 }
137
138 /**
139 * @tc.name: GetNotifyDataTest005
140 * @tc.desc: Verify the GetNotifyData function.
141 * @tc.type: FUNC
142 * @tc.require: I6H5MH
143 */
144 HWTEST_F(CloudDiskNotifyUtilsTest, GetNotifyDataTest005, TestSize.Level1)
145 {
146 GTEST_LOG_(INFO) << "GetNotifyData Start";
147 CloudDiskNotifyUtils CloudDiskNotifyUtils;
148 CloudDiskFuseData* data = nullptr;
149 FindCloudDiskInodeFunc func;
150 shared_ptr<CloudDiskInode> inoPtr = make_shared<CloudDiskInode>();
151 inoPtr->parent = 1;
152 inoPtr->fileName = "test";
153 NotifyData notifyData;
154 string name = "test";
155 int ret = CloudDiskNotifyUtils.GetNotifyData(data, func, inoPtr, name, notifyData);
156 EXPECT_EQ(ret, E_OK);
157 GTEST_LOG_(INFO) << "GetNotifyData End";
158 }
159
160 /**
161 * @tc.name: GetCacheNodeTest001
162 * @tc.desc: Verify the GetCacheNode function.
163 * @tc.type: FUNC
164 * @tc.require: I6H5MH
165 */
166 HWTEST_F(CloudDiskNotifyUtilsTest, GetCacheNodeTest001, TestSize.Level1)
167 {
168 GTEST_LOG_(INFO) << "GetCacheNode Start";
169 CloudDiskNotifyUtils CloudDiskNotifyUtils;
170 string cloudId = "100";
171 CacheNode cacheNode;
172 int ret = CloudDiskNotifyUtils.GetCacheNode(cloudId, cacheNode);
173 EXPECT_EQ(ret, E_INVAL_ARG);
174 GTEST_LOG_(INFO) << "GetCacheNode End";
175 }
176
177 /**
178 * @tc.name: PutCacheNodeTest001
179 * @tc.desc: Verify the PutCacheNode function.
180 * @tc.type: FUNC
181 * @tc.require: I6H5MH
182 */
183 HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest001, TestSize.Level1)
184 {
185 GTEST_LOG_(INFO) << "PutCacheNode Start";
186 CloudDiskNotifyUtils CloudDiskNotifyUtils;
187 string cloudId = "100";
188 CacheNode cacheNode;
189 cacheNode.isDir = "";
190 CloudDiskNotifyUtils.PutCacheNode(cloudId, cacheNode);
191 GTEST_LOG_(INFO) << "PutCacheNode End";
192 }
193
194 /**
195 * @tc.name: PutCacheNodeTest002
196 * @tc.desc: Verify the PutCacheNode function.
197 * @tc.type: FUNC
198 * @tc.require: I6H5MH
199 */
200 HWTEST_F(CloudDiskNotifyUtilsTest, PutCacheNodeTest002, TestSize.Level1)
201 {
202 GTEST_LOG_(INFO) << "PutCacheNode Start";
203 CloudDiskNotifyUtils CloudDiskNotifyUtils;
204 string cloudId = "100";
205 CacheNode cacheNode;
206 cacheNode.isDir = "directory";
207 CloudDiskNotifyUtils.PutCacheNode(cloudId, cacheNode);
208 GTEST_LOG_(INFO) << "PutCacheNode End";
209 }
210
211 /**
212 * @tc.name: GetUriFromCacheTest001
213 * @tc.desc: Verify the GetUriFromCache function.
214 * @tc.type: FUNC
215 * @tc.require: I6H5MH
216 */
217 HWTEST_F(CloudDiskNotifyUtilsTest, GetUriFromCacheTest001, TestSize.Level1)
218 {
219 GTEST_LOG_(INFO) << "GetUriFromCache Start";
220 CloudDiskNotifyUtils CloudDiskNotifyUtils;
221 string bundleName = "com.ohos.photos";
222 string rootId = "rootId";
223 CacheNode cacheNode;
224 cacheNode.isDir = "";
225 cacheNode.cloudId = "";
226 string uri = "";
227 int ret = CloudDiskNotifyUtils.GetUriFromCache(bundleName, rootId, cacheNode, uri);
228 EXPECT_EQ(ret, E_INVAL_ARG);
229 GTEST_LOG_(INFO) << "GetUriFromCache End";
230 }
231 } // namespace Test
232 } // namespace FileManagement::CloudSync
233 } // namespace OHOS