1 /*
2 * Copyright (c) 2021-2025 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 <cstdio>
17 #include <gtest/gtest.h>
18 #include <sys/xattr.h>
19
20 #include "volume/volume_manager_service.h"
21 #include "disk/disk_manager_service.h"
22 #include "mock/file_utils_mock.h"
23 #include "volume_core.h"
24 #include "storage_service_errno.h"
25
26 int32_t g_cnt = 0;
27 const int32_t MTP_MAX_LEN = 512;
28 const int32_t CNT_ZERO = 0;
29 const int32_t CNT_ONE = 1;
30 const int32_t CNT_TWO = 2;
getxattr(const char * path,const char * name,void * value,size_t size)31 ssize_t getxattr(const char *path, const char *name, void *value, size_t size)
32 {
33 if (strcmp(name, "user.getfriendlyname") == 0 && g_cnt == CNT_ZERO) {
34 return -1;
35 }
36 if (strcmp(name, "user.getfriendlyname") == 0 && g_cnt == CNT_ONE) {
37 return 0;
38 }
39 if (strcmp(name, "user.getfriendlyname") == 0 && g_cnt == CNT_TWO) {
40 return MTP_MAX_LEN;
41 }
42 return 0;
43 }
44
45 namespace {
46 using namespace std;
47 using namespace OHOS;
48 using namespace StorageManager;
49 using namespace StorageDaemon;
50 class VolumeManagerServiceTest : public testing::Test {
51 public:
52 static void SetUpTestCase(void);
53 static void TearDownTestCase();
SetUp()54 void SetUp() {};
TearDown()55 void TearDown() {};
56 static inline std::shared_ptr<FileUtilMoc> fileUtilMoc_ = nullptr;
57 };
58
SetUpTestCase(void)59 void VolumeManagerServiceTest::SetUpTestCase(void)
60 {
61 GTEST_LOG_(INFO) << "SetUpTestCase Start";
62 fileUtilMoc_ = make_shared<FileUtilMoc>();
63 FileUtilMoc::fileUtilMoc = fileUtilMoc_;
64 }
65
TearDownTestCase()66 void VolumeManagerServiceTest::TearDownTestCase()
67 {
68 GTEST_LOG_(INFO) << "TearDownTestCase Start";
69 FileUtilMoc::fileUtilMoc = nullptr;
70 fileUtilMoc_ = nullptr;
71 }
72
73 /**
74 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0000
75 * @tc.name: Volume_manager_service_Mount_0000
76 * @tc.desc: Test function of Mount interface for SUCCESS.
77 * @tc.size: MEDIUM
78 * @tc.type: FUNC
79 * @tc.level Level 1
80 * @tc.require: SR000GGUPF
81 */
82 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0000, testing::ext::TestSize.Level1)
83 {
84 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0000";
85 auto &vmService = VolumeManagerService::GetInstance();
86 std::string volumeId = "vol-1-1";
87 int32_t fsType = 1;
88 std::string diskId = "disk-1-1";
89 VolumeCore vc(volumeId, fsType, diskId);
90 int32_t result;
91 vmService.OnVolumeCreated(vc);
92 result = vmService.Mount(volumeId);
93 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
94 EXPECT_EQ(result, E_NON_EXIST);
95 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0000";
96 }
97
98 /**
99 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0001
100 * @tc.name: Volume_manager_service_Mount_0001
101 * @tc.desc: Test function of Mount interface for SUCCESS.
102 * @tc.size: MEDIUM
103 * @tc.type: FUNC
104 * @tc.level Level 1
105 * @tc.require: SR000GGUPF
106 */
107 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0001, testing::ext::TestSize.Level1)
108 {
109 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0001";
110 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
111 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(false));
112 auto &vmService =VolumeManagerService::GetInstance();
113 std::string volumeId = "vol-1-2";
114 int32_t fsType = 1;
115 std::string diskId = "disk-1-2";
116 VolumeCore vc(volumeId, fsType, diskId);
117 int32_t result;
118 result = vmService.Mount(volumeId);
119 EXPECT_EQ(result, E_NON_EXIST);
120 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0001";
121 }
122
123 /**
124 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0002
125 * @tc.name: Volume_manager_service_Mount_0002
126 * @tc.desc: Test function of Mount interface for SUCCESS.
127 * @tc.size: MEDIUM
128 * @tc.type: FUNC
129 * @tc.level Level 1
130 * @tc.require: SR000GGUPF
131 */
132 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0002, testing::ext::TestSize.Level1)
133 {
134 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0002";
135 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
136 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(true));
137 auto &vmService =VolumeManagerService::GetInstance();
138 std::string volumeId = "vol-1-3";
139 std::string diskId = "disk-1-3";
140 VolumeCore vc(volumeId, FsType::MTP, diskId, VolumeState::UNMOUNTED);
141 int32_t result;
142 vmService.OnVolumeCreated(vc);
143 result = vmService.Mount(volumeId);
144 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
145 EXPECT_EQ(result, E_NON_EXIST);
146 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0002";
147 }
148
149 /**
150 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0003
151 * @tc.name: Volume_manager_service_Mount_0003
152 * @tc.desc: Test function of Mount interface for Isfuse =true,IsPathMounted=ture.
153 * @tc.size: MEDIUM
154 * @tc.type: FUNC
155 * @tc.level Level 1
156 * @tc.require: SR000GGUPF
157 */
158 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0003, testing::ext::TestSize.Level1)
159 {
160 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0003";
161 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(true));
162 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(true));
163 auto &vmService =VolumeManagerService::GetInstance();
164 std::string volumeId = "vol-1-3";
165 std::string diskId = "disk-1-3";
166 VolumeCore vc(volumeId, FsType::MTP, diskId, VolumeState::UNMOUNTED);
167 int32_t result;
168 vmService.OnVolumeCreated(vc);
169 std::shared_ptr<VolumeExternal> volumePtr = vmService.volumeMap_.ReadVal(volumeId);
170 ASSERT_NE(volumePtr, nullptr);
171 volumePtr->SetFsType(FsType::MTP);
172 result = vmService.Mount(volumeId);
173 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
174 EXPECT_EQ(result, E_NON_EXIST);
175 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0003";
176 }
177
178 /**
179 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0004
180 * @tc.name: Volume_manager_service_Mount_0004
181 * @tc.desc: Test function of Mount interface for Isfuse =true.
182 * @tc.size: MEDIUM
183 * @tc.type: FUNC
184 * @tc.level Level 1
185 * @tc.require: SR000GGUPF
186 */
187 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0004, testing::ext::TestSize.Level1)
188 {
189 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0004";
190 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(true));
191 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(false));
192 auto &vmService =VolumeManagerService::GetInstance();
193 std::string volumeId = "vol-1-3";
194 std::string diskId = "disk-1-3";
195 VolumeCore vc(volumeId, FsType::MTP, diskId, VolumeState::UNMOUNTED);
196 int32_t result;
197 vmService.OnVolumeCreated(vc);
198 std::shared_ptr<VolumeExternal> volumePtr = vmService.volumeMap_.ReadVal(volumeId);
199 ASSERT_NE(volumePtr, nullptr);
200 volumePtr->SetFsType(FsType::MTP);
201 result = vmService.Mount(volumeId);
202 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
203 EXPECT_EQ(result, E_NON_EXIST);
204 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0004";
205 }
206
207 /**
208 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0005
209 * @tc.name: Volume_manager_service_Mount_0005
210 * @tc.desc: Test function of Mount interface for SUCCESS.
211 * @tc.size: MEDIUM
212 * @tc.type: FUNC
213 * @tc.level Level 1
214 * @tc.require: SR000GGUPF
215 */
216 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0005, testing::ext::TestSize.Level1)
217 {
218 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0005";
219 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
220 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(true));
221 auto &vmService =VolumeManagerService::GetInstance();
222 std::string volumeId = "vol-1-3";
223 std::string diskId = "disk-1-3";
224 VolumeCore vc(volumeId, FsType::MTP, diskId, VolumeState::UNMOUNTED);
225 int32_t result;
226 vmService.OnVolumeCreated(vc);
227 std::shared_ptr<VolumeExternal> volumePtr = vmService.volumeMap_.ReadVal(volumeId);
228 ASSERT_NE(volumePtr, nullptr);
229 volumePtr->SetFsType(FsType::MTP);
230 result = vmService.Mount(volumeId);
231 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
232 EXPECT_EQ(result, E_NON_EXIST);
233 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0005";
234 }
235
236 /**
237 * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0006
238 * @tc.name: Volume_manager_service_Mount_0006
239 * @tc.desc: Test function of Mount interface for SUCCESS.
240 * @tc.size: MEDIUM
241 * @tc.type: FUNC
242 * @tc.level Level 1
243 * @tc.require: SR000GGUPF
244 */
245 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0006, testing::ext::TestSize.Level1)
246 {
247 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0006";
248 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
249 EXPECT_CALL(*fileUtilMoc_, IsPathMounted(testing::_)).WillOnce(testing::Return(false));
250 auto &vmService =VolumeManagerService::GetInstance();
251 std::string volumeId = "vol-1-3";
252 std::string diskId = "disk-1-3";
253 VolumeCore vc(volumeId, FsType::MTP, diskId, VolumeState::UNMOUNTED);
254 int32_t result;
255 vmService.OnVolumeCreated(vc);
256 std::shared_ptr<VolumeExternal> volumePtr = vmService.volumeMap_.ReadVal(volumeId);
257 ASSERT_NE(volumePtr, nullptr);
258 volumePtr->SetFsType(FsType::MTP);
259 result = vmService.Mount(volumeId);
260 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
261 EXPECT_EQ(result, E_NON_EXIST);
262 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0006";
263 }
264
265 /**
266 * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0000
267 * @tc.name: Volume_manager_service_Unmount_0000
268 * @tc.desc: Test function of Unmount interface for FAILED.
269 * @tc.size: MEDIUM
270 * @tc.type: FUNC
271 * @tc.level Level 1
272 * @tc.require: SR000GGUPF
273 */
274 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0000, testing::ext::TestSize.Level1)
275 {
276 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0000";
277 auto &vmService = VolumeManagerService::GetInstance();
278 std::string volumeId = "vol-1-3";
279 int32_t fsType = 1;
280 std::string diskId = "disk-1-3";
281 VolumeCore vc(volumeId, fsType, diskId);
282 int32_t result;
283 vc.SetState(VolumeState::MOUNTED);
284 result = vmService.Unmount(volumeId);
285 EXPECT_EQ(result, E_NON_EXIST);
286 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0000";
287 }
288
289 /**
290 * @tc.number: SUB_STORAGE_Volume_manager_service_TryToFix_0001
291 * @tc.name: Volume_manager_service_TryToFix_0001
292 * @tc.desc: Test function of TryToFix interface for SUCCESS.
293 * @tc.size: MEDIUM
294 * @tc.type: FUNC
295 * @tc.level Level 1
296 * @tc.require: SR000GGUPF
297 */
298 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_TryToFix_0001, testing::ext::TestSize.Level1)
299 {
300 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_TryToFix_0001";
301 auto &vmService = VolumeManagerService::GetInstance();
302 std::string volumeId = "vol-1-2";
303 int32_t fsType = 1;
304 std::string diskId = "disk-1-2";
305 VolumeCore vc(volumeId, fsType, diskId);
306 int32_t result;
307 result = vmService.TryToFix(volumeId);
308 EXPECT_EQ(result, E_NON_EXIST);
309 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_TryToFix_0001";
310 }
311
312 /**
313 * @tc.number: SUB_STORAGE_Volume_manager_service_TryToFix_0002
314 * @tc.name: Volume_manager_service_TryToFix_0002
315 * @tc.desc: Test function of TryToFix interface for SUCCESS.
316 * @tc.size: MEDIUM
317 * @tc.type: FUNC
318 * @tc.level Level 1
319 * @tc.require: SR000GGUPF
320 */
321 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_TryToFix_0002, testing::ext::TestSize.Level1)
322 {
323 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_TryToFix_0002";
324 auto &vmService = VolumeManagerService::GetInstance();
325 std::string volumeId = "vol-1-6";
326 int32_t fsType = 1;
327 std::string fsTypeStr = "ntfs";
328 std::string fsUuid = "uuid-1";
329 std::string path = "/";
330 std::string description = "description-1";
331 std::string diskId = "disk-1-6";
332 VolumeCore vc(volumeId, fsType, diskId);
333 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
334 int32_t result;
335 result = vmService.TryToFix(volumeId);
336 EXPECT_EQ(result, E_NON_EXIST);
337 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_TryToFix_0002";
338 }
339
340 /**
341 * @tc.number: SUB_STORAGE_Volume_manager_service_TryToFix_0003
342 * @tc.name: Volume_manager_service_TryToFix_0003
343 * @tc.desc: Test function of TryToFix interface for SUCCESS.
344 * @tc.size: MEDIUM
345 * @tc.type: FUNC
346 * @tc.level Level 1
347 * @tc.require: SR000GGUPF
348 */
349 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_TryToFix_0003, testing::ext::TestSize.Level1)
350 {
351 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_TryToFix_0003";
352 auto &vmService = VolumeManagerService::GetInstance();
353 std::string volumeId = "vol-1-8";
354 std::string diskId = "disk-1-8";
355 VolumeCore vc(volumeId, FsType::MTP, diskId);
356 int32_t result;
357 vmService.OnVolumeCreated(vc);
358 result = vmService.TryToFix(volumeId);
359 EXPECT_EQ(result, E_NON_EXIST);
360 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_TryToFix_0003";
361 }
362
363 /**
364 * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0001
365 * @tc.name: Volume_manager_service_Unmount_0001
366 * @tc.desc: Test function of Unmount interface for SUCCESS.
367 * @tc.size: MEDIUM
368 * @tc.type: FUNC
369 * @tc.level Level 1
370 * @tc.require: SR000GGUPF
371 */
372 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0001, testing::ext::TestSize.Level1)
373 {
374 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0001";
375 auto &vmService = VolumeManagerService::GetInstance();
376 std::string volumeId = "vol-1-4";
377 int32_t fsType = 1;
378 std::string diskId = "disk-1-4";
379 VolumeCore vc(volumeId, fsType, diskId);
380 int32_t result;
381 vc.SetState(VolumeState::MOUNTED);
382 vmService.OnVolumeCreated(vc);
383 result = vmService.Unmount(volumeId);
384 vmService.OnVolumeStateChanged(volumeId, VolumeState::REMOVED);
385 EXPECT_EQ(result, E_NON_EXIST);
386 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0001";
387 }
388
389 /**
390 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeCreated_0000
391 * @tc.name: Volume_manager_service_OnVolumeCreated_0000
392 * @tc.desc: Test function of OnVolumeCreated interface for SUCCESS.
393 * @tc.size: MEDIUM
394 * @tc.type: FUNC
395 * @tc.level Level 1
396 * @tc.require: SR000GGUPF
397 */
398 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeCreated_0000, testing::ext::TestSize.Level1)
399 {
400 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeCreated_0000";
401 auto &vmService = VolumeManagerService::GetInstance();
402 std::string volumeId = "vol-1-5";
403 int type = 1;
404 std::string diskId = "disk-1-5";
405 VolumeCore vc(volumeId, type, diskId);
406 vmService.OnVolumeCreated(vc);
407 VolumeExternal ve;
408 int32_t res = vmService.GetVolumeById(volumeId, ve);
409 EXPECT_EQ(res, E_OK);
410 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
411 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeCreated_0000";
412 }
413
414 /**
415 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeMounted_0000
416 * @tc.name: Volume_manager_service_OnVolumeMounted_0000
417 * @tc.desc: Test function of OnVolumeMounted interface for SUCCESS.
418 * @tc.size: MEDIUM
419 * @tc.type: FUNC
420 * @tc.level Level 1
421 * @tc.require: SR000GGUPF
422 */
423 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeMounted_0000, testing::ext::TestSize.Level1)
424 {
425 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeMounted_0000";
426 auto &vmService = VolumeManagerService::GetInstance();
427 std::string volumeId = "vol-1-5";
428 std::string fsTypeStr = "ntfs";
429 std::string fsUuid = "";
430 std::string path = "";
431 std::string description = "";
432 vmService.OnVolumeMounted(volumeId, fsTypeStr, fsUuid, path, description);
433 VolumeExternal ve;
434 int32_t res = vmService.GetVolumeById(volumeId, ve);
435 EXPECT_EQ(res, E_NON_EXIST);
436 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeMounted_0000";
437 }
438
439 /**
440 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDamaged_0000
441 * @tc.name: Volume_manager_service_OnVolumeDamaged_0000
442 * @tc.desc: Test function of OnVolumeDamaged interface for SUCCESS.
443 * @tc.size: MEDIUM
444 * @tc.type: FUNC
445 * @tc.level Level 1
446 * @tc.require: SR000GGUPF
447 */
448 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDamaged_0000, testing::ext::TestSize.Level1)
449 {
450 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDamaged_0000";
451 auto &vmService = VolumeManagerService::GetInstance();
452 std::string volumeId = "vol-1-5";
453 std::string fsTypeStr = "ntfs";
454 std::string fsUuid = "";
455 std::string path = "";
456 std::string description = "";
457 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
458 VolumeExternal ve;
459 int32_t res = vmService.GetVolumeById(volumeId, ve);
460 EXPECT_EQ(res, E_NON_EXIST);
461 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDamaged_0000";
462 }
463
464 /**
465 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDamaged_0001
466 * @tc.name: Volume_manager_service_OnVolumeDamaged_0001
467 * @tc.desc: Test function of OnVolumeDamaged interface for SUCCESS.
468 * @tc.size: MEDIUM
469 * @tc.type: FUNC
470 * @tc.level Level 1
471 * @tc.require: SR000GGUPF
472 */
473 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDamaged_0001, testing::ext::TestSize.Level1)
474 {
475 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDamaged_0001";
476 auto &vmService =VolumeManagerService::GetInstance();
477 DiskManagerService& dmService = DiskManagerService::GetInstance();
478 std::string volumeId = "vol-1-6";
479 int32_t fsType = 1;
480 std::string fsTypeStr = "ntfs";
481 std::string fsUuid = "uuid-1";
482 std::string path = "/";
483 std::string description = "description-1";
484 std::string diskId = "disk-1-6";
485
486 int64_t sizeBytes = 1024;
487 std::string vendor = "vendor-6";
488 int32_t flag = 1;
489 Disk disk(diskId, sizeBytes, path, vendor, flag);
490 VolumeCore vc(volumeId, fsType, diskId);
491
492 auto diskPtr = std::make_shared<Disk>(disk);
493 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
494 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
495
496 dmService.diskMap_.Insert(diskId, diskPtr);
497 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
498 VolumeExternal ve;
499 int32_t res = vmService.GetVolumeById(volumeId, ve);
500 EXPECT_EQ(res, E_OK);
501 vmService.volumeMap_.Clear();
502 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDamaged_0001";
503 }
504
505 /**
506 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDamaged_0002
507 * @tc.name: Volume_manager_service_OnVolumeDamaged_0002
508 * @tc.desc: Test function of OnVolumeDamaged interface for SUCCESS.
509 * @tc.size: MEDIUM
510 * @tc.type: FUNC
511 * @tc.level Level 1
512 * @tc.require: SR000GGUPF
513 */
514 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDamaged_0002, testing::ext::TestSize.Level1)
515 {
516 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDamaged_0002";
517 auto &vmService =VolumeManagerService::GetInstance();
518 DiskManagerService& dmService = DiskManagerService::GetInstance();
519 std::string volumeId = "vol-1-6";
520 int32_t fsType = 1;
521 std::string fsTypeStr = "ntfs";
522 std::string fsUuid = "uuid-1";
523 std::string path = "/";
524 std::string description = "description-1";
525 std::string diskId = "disk-1-6";
526
527 int64_t sizeBytes = 1024;
528 std::string vendor = "vendor-6";
529 int32_t flag = 2;
530 Disk disk(diskId, sizeBytes, path, vendor, flag);
531 VolumeCore vc(volumeId, fsType, diskId);
532
533 auto diskPtr = std::make_shared<Disk>(disk);
534 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
535 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
536
537 dmService.diskMap_.Insert(diskId, diskPtr);
538 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
539 VolumeExternal ve;
540 int32_t res = vmService.GetVolumeById(volumeId, ve);
541 EXPECT_EQ(res, E_OK);
542 vmService.volumeMap_.Clear();
543 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDamaged_0002";
544 }
545
546 /**
547 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDamaged_0003
548 * @tc.name: Volume_manager_service_OnVolumeDamaged_0003
549 * @tc.desc: Test function of OnVolumeDamaged interface for SUCCESS.
550 * @tc.size: MEDIUM
551 * @tc.type: FUNC
552 * @tc.level Level 1
553 * @tc.require: SR000GGUPF
554 */
555 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDamaged_0003, testing::ext::TestSize.Level1)
556 {
557 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDamaged_0003";
558 auto &vmService =VolumeManagerService::GetInstance();
559 DiskManagerService& dmService = DiskManagerService::GetInstance();
560 std::string volumeId = "vol-1-6";
561 int32_t fsType = 1;
562 std::string fsTypeStr = "ntfs";
563 std::string fsUuid = "uuid-1";
564 std::string path = "/";
565 std::string description = "description-1";
566 std::string diskId = "disk-1-6";
567
568 int64_t sizeBytes = 1024;
569 std::string vendor = "vendor-6";
570 int32_t flag = 3;
571 Disk disk(diskId, sizeBytes, path, vendor, flag);
572 VolumeCore vc(volumeId, fsType, diskId);
573
574 auto diskPtr = std::make_shared<Disk>(disk);
575 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
576 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
577
578 dmService.diskMap_.Insert(diskId, diskPtr);
579 vmService.OnVolumeDamaged(volumeId, fsTypeStr, fsUuid, path, description);
580 VolumeExternal ve;
581 int32_t res = vmService.GetVolumeById(volumeId, ve);
582 EXPECT_EQ(res, E_OK);
583 vmService.volumeMap_.Clear();
584 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDamaged_0003";
585 }
586
587 /**
588 * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDestroyed_0000
589 * @tc.name: Volume_manager_service_OnVolumeDestroyed_0000
590 * @tc.desc: Test function of OnVolumeDestroyed interface for SUCCESS.
591 * @tc.size: MEDIUM
592 * @tc.type: FUNC
593 * @tc.level Level 1
594 * @tc.require: SR000GGUPF
595 */
596 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDestroyed_0000, testing::ext::TestSize.Level1)
597 {
598 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDestroyed_0000";
599 auto &vmService = VolumeManagerService::GetInstance();
600 std::string volumeId = "vol-1-5";
601 vmService.OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
602 VolumeExternal ve;
603 int32_t res = vmService.GetVolumeById(volumeId, ve);
604 EXPECT_EQ(res, E_NON_EXIST);
605 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDestroyed_0000";
606 }
607
608 /**
609 * @tc.number: SUB_STORAGE_Volume_manager_service_GetAllVolumes_0000
610 * @tc.name: Volume_manager_service_GetAllVolumes_0000
611 * @tc.desc: Test function of GetAllVolumes interface for SUCCESS.
612 * @tc.size: MEDIUM
613 * @tc.type: FUNC
614 * @tc.level Level 1
615 * @tc.require: SR000GGUPF
616 */
617 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetAllVolumes_0000, testing::ext::TestSize.Level1)
618 {
619 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetAllVolumes_0000";
620 auto &vmService = VolumeManagerService::GetInstance();
621 std::vector<VolumeExternal> result = vmService.GetAllVolumes();
622 EXPECT_EQ(result.size(), 0);
623 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetAllVolumes_0000";
624 }
625
626 /**
627 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0000
628 * @tc.name: Volume_manager_service_GetVolumeByUuid_0000
629 * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
630 * @tc.size: MEDIUM
631 * @tc.type: FUNC
632 * @tc.level Level 1
633 * @tc.require: SR000GGUPF
634 */
635 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0000, testing::ext::TestSize.Level1)
636 {
637 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0000";
638 auto &vmService = VolumeManagerService::GetInstance();
639 std::string volumeId = "vol-1-6";
640 int32_t fsType = 1;
641 std::string fsTypeStr = "ntfs";
642 std::string fsUuid = "uuid-1";
643 std::string path = "/";
644 std::string description = "description-1";
645 std::string diskId = "disk-1-6";
646 VolumeCore vc(volumeId, fsType, diskId);
647 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
648 vmService.OnVolumeCreated(vc);
649 vmService.OnVolumeMounted(volumeId, fsTypeStr, fsUuid, path, description);
650 std::shared_ptr<VolumeExternal> result = vmService.GetVolumeByUuid(fsUuid);
651 EXPECT_NE(result, nullptr);
652 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0000";
653 }
654
655 /**
656 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0001
657 * @tc.name: Volume_manager_service_GetVolumeByUuid_0001
658 * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
659 * @tc.size: MEDIUM
660 * @tc.type: FUNC
661 * @tc.level Level 1
662 * @tc.require: SR000GGUPF
663 */
664 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0001, testing::ext::TestSize.Level1)
665 {
666 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0001";
667 auto &vmService = VolumeManagerService::GetInstance();
668 std::string volumeId = "vol-1-6";
669 int32_t fsType = 1;
670 std::string fsTypeStr = "ntfs";
671 std::string fsUuid = "uuid-1";
672 std::string path = "/";
673 std::string description = "description-1";
674 std::string diskId = "disk-1-6";
675 VolumeCore vc(volumeId, fsType, diskId);
676 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
677 vmService.OnVolumeCreated(vc);
678 vmService.OnVolumeMounted(volumeId, fsTypeStr, fsUuid, path, description);
679 VolumeExternal ve;
680 int32_t ret = vmService.GetVolumeByUuid(fsUuid, ve);
681 EXPECT_EQ(ret, E_OK);
682 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0001";
683 }
684
685 /**
686 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0002
687 * @tc.name: Volume_manager_service_GetVolumeByUuid_0002
688 * @tc.desc: Test function of GetVolumeByUuid interface for ERROR which volumeUuid not exist.
689 * @tc.size: MEDIUM
690 * @tc.type: FUNC
691 * @tc.level Level 1
692 * @tc.require: SR000GGUPF
693 */
694 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0002, testing::ext::TestSize.Level1)
695 {
696 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0002";
697 auto &vmService = VolumeManagerService::GetInstance();
698 std::string fsUuid = "uuid-2";
699 VolumeExternal ve;
700 int32_t ret = vmService.GetVolumeByUuid(fsUuid, ve);
701 EXPECT_EQ(ret, E_NON_EXIST);
702 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0002";
703 }
704
705 /**
706 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0003
707 * @tc.name: Volume_manager_service_GetVolumeByUuid_0003
708 * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
709 * @tc.size: MEDIUM
710 * @tc.type: FUNC
711 * @tc.level Level 1
712 * @tc.require: SR000GGUPF
713 */
714 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0003, testing::ext::TestSize.Level1)
715 {
716 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0003";
717 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
718 auto &vmService =VolumeManagerService::GetInstance();
719 std::string volumeId = "vol-1-8";
720 int32_t fsType = 5;
721 std::string fsUuid = "uuid-8";
722 std::string diskId = "disk-1-8";
723 VolumeCore vc(volumeId, fsType, diskId);
724 vmService.OnVolumeCreated(vc);
725 std::shared_ptr<VolumeExternal> result = vmService.GetVolumeByUuid("uuid-9");
726 EXPECT_EQ(result, nullptr);
727 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0003";
728 }
729
730 /**
731 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0000
732 * @tc.name: Volume_manager_service_GetVolumeById_0000
733 * @tc.desc: Test function of GetVolumeById interface for SUCCESS.
734 * @tc.size: MEDIUM
735 * @tc.type: FUNC
736 * @tc.level Level 1
737 * @tc.require: AR000H09L6
738 */
739 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0000, testing::ext::TestSize.Level1)
740 {
741 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0000";
742 auto &vmService = VolumeManagerService::GetInstance();
743 std::string volumeId = "vol-1-8";
744 int32_t fsType = 1;
745 std::string diskId = "disk-1-8";
746 VolumeCore vc(volumeId, fsType, diskId);
747 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
748 vmService.OnVolumeCreated(vc);
749 VolumeExternal ve;
750 int32_t result = vmService.GetVolumeById(volumeId, ve);
751 EXPECT_EQ(result, E_OK);
752 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0000";
753 }
754
755 /**
756 * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0001
757 * @tc.name: Volume_manager_service_GetVolumeById_0001
758 * @tc.desc: Test function of GetVolumeById interface for ERROR which volumeId not exist.
759 * @tc.size: MEDIUM
760 * @tc.type: FUNC
761 * @tc.level Level 1
762 * @tc.require: AR000H09L6
763 */
764 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0001, testing::ext::TestSize.Level1)
765 {
766 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0001";
767 auto &vmService = VolumeManagerService::GetInstance();
768 std::string volumeId = "vol-1-9";
769 VolumeExternal ve;
770 int32_t result = vmService.GetVolumeById(volumeId, ve);
771 EXPECT_NE(result, E_OK);
772 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0001";
773 }
774
775 /**
776 * @tc.number: SUB_STORAGE_Volume_manager_service_SetVolumeDescription_0000
777 * @tc.name: Volume_manager_service_SetVolumeDescription_0000
778 * @tc.desc: Test function of SetVolumeDescription interface for SUCCESS.
779 * @tc.size: MEDIUM
780 * @tc.type: FUNC
781 * @tc.level Level 1
782 * @tc.require: AR000H09L6
783 */
784 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_SetVolumeDescription_0000, testing::ext::TestSize.Level1)
785 {
786 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_SetVolumeDescription_0000";
787 auto &vmService = VolumeManagerService::GetInstance();
788 std::string volumeId = "vol-1-10";
789 int32_t fsType = 1;
790 std::string diskId = "disk-1-10";
791 VolumeCore vc(volumeId, fsType, diskId);
792 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
793 vmService.OnVolumeCreated(vc);
794 std::string fsUuid = "uuid-2";
795 std::string description = "description-1";
796 int32_t result = vmService.SetVolumeDescription(fsUuid, description);
797 EXPECT_EQ(result, E_NON_EXIST);
798 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_SetVolumeDescription_0000";
799 }
800
801 /**
802 * @tc.number: SUB_STORAGE_Volume_manager_service_SetVolumeDescription_0001
803 * @tc.name: Volume_manager_service_SetVolumeDescription_0001
804 * @tc.desc: Test function of SetVolumeDescription interface for SUCCESS.
805 * @tc.size: MEDIUM
806 * @tc.type: FUNC
807 * @tc.level Level 1
808 * @tc.require: AR000H09L6
809 */
810 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_SetVolumeDescription_0001, testing::ext::TestSize.Level1)
811 {
812 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_SetVolumeDescription_0001";
813 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
814 auto &vmService =VolumeManagerService::GetInstance();
815 std::string volumeId = "vol-1-11";
816 int32_t fsType = 1;
817 std::string diskId = "disk-1-11";
818 VolumeCore vc(volumeId, fsType, diskId, VolumeState::UNMOUNTED);
819 vmService.OnVolumeCreated(vc);
820 std::string fsUuid = "uuid-2";
821 std::string description = "description-2";
822 ASSERT_NE(vmService.volumeMap_.Contains(volumeId), false);
823 std::shared_ptr<VolumeExternal> volumePtr = vmService.volumeMap_.ReadVal(volumeId);
824 volumePtr->SetFsUuid(fsUuid);
825 int32_t result = vmService.SetVolumeDescription(fsUuid, description);
826 EXPECT_EQ(result, E_NON_EXIST);
827 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_SetVolumeDescription_0001";
828 }
829
830 /**
831 * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0000
832 * @tc.name: Volume_manager_service_Format_0000
833 * @tc.desc: Test function of Format interface for SUCCESS.
834 * @tc.size: MEDIUM
835 * @tc.type: FUNC
836 * @tc.level Level 1
837 * @tc.require: AR000H09L6
838 */
839 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0000, testing::ext::TestSize.Level1)
840 {
841 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0000";
842 auto &vmService = VolumeManagerService::GetInstance();
843 std::string volumeId = "vol-1-11";
844 int fsType = 1;
845 std::string diskId = "disk-1-11";
846 VolumeCore vc(volumeId, fsType, diskId);
847 vmService.OnVolumeCreated(vc);
848 string fsTypes = "fs-1";
849 int32_t result = vmService.Format(volumeId, fsTypes);
850 EXPECT_EQ(result, E_NON_EXIST);
851 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0000";
852 }
853
854 /**
855 * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0001
856 * @tc.name: Volume_manager_service_Format_0001
857 * @tc.desc: Test function of Format interface for SUCCESS.
858 * @tc.size: MEDIUM
859 * @tc.type: FUNC
860 * @tc.level Level 1
861 * @tc.require: AR000H09L6
862 */
863 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0001, testing::ext::TestSize.Level1)
864 {
865 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0001";
866 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(false));
867 auto &vmService =VolumeManagerService::GetInstance();
868 std::string volumeId = "vol-1-12";
869 int fsType = 1;
870 std::string fsUuid = "uuid-3";
871 std::string diskId = "disk-1-12";
872 VolumeCore vc(volumeId, fsType, diskId, VolumeState::MOUNTED);
873 vmService.OnVolumeCreated(vc);
874 VolumeExternal ve;
875 vmService.GetVolumeById(volumeId, ve);
876 string fsTypes = "fs-1";
877 int32_t result = vmService.Format(volumeId, fsTypes);
878 EXPECT_EQ(result, E_VOL_STATE);
879 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0001";
880 }
881
882 /**
883 * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0002
884 * @tc.name: Volume_manager_service_Format_0002
885 * @tc.desc: Test function of Format interface for SUCCESS.
886 * @tc.size: MEDIUM
887 * @tc.type: FUNC
888 * @tc.level Level 1
889 * @tc.require: AR000H09L6
890 */
891 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Format_0002, testing::ext::TestSize.Level1)
892 {
893 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Format_0002";
894 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).Times(2).WillOnce(testing::Return(true));
895 auto &vmService =VolumeManagerService::GetInstance();
896 std::string volumeId;
897 int fsType = 1;
898 std::string fsUuid = "uuid-3";
899 std::string diskId = "disk-1-12";
900 VolumeCore vc(volumeId, fsType, diskId, VolumeState::MOUNTED);
901 vmService.OnVolumeCreated(vc);
902 VolumeExternal ve;
903 vmService.GetVolumeById(volumeId, ve);
904 string fsTypes = "fs-1";
905 int32_t result = vmService.Format(volumeId, fsTypes);
906 EXPECT_EQ(result, E_VOL_STATE);
907 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Format_0002";
908 }
909 /**
910 * @tc.number: SUB_STORAGE_Volume_manager_service_NotifyMtpMounted_0001
911 * @tc.name: Volume_manager_service_NotifyMtpMounted_0001
912 * @tc.desc: Test function of NotifyMtpMounted interface for SUCCESS.
913 * @tc.size: MEDIUM
914 * @tc.type: FUNC
915 * @tc.level Level 1
916 * @tc.require: SR000GGUPF
917 */
918 HWTEST_F(VolumeManagerServiceTest, Storage_manager_NotifyMtpMounted_0001, testing::ext::TestSize.Level1)
919 {
920 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_NotifyMtpMounted_0001";
921 auto &vmService = VolumeManagerService::GetInstance();
922 std::string id = "vol-1-6";
923 std::string path = "/mnt/data/external/1";
924 std::string desc = "description-1";
925 std::string uuid = "uuid-1";
926 g_cnt = 0;
927 vmService.NotifyMtpMounted(id, path, desc, uuid);
928 g_cnt = 0;
929 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_NotifyMtpMounted_0001";
930 }
931
932 /**
933 * @tc.number: SUB_STORAGE_Volume_manager_service_NotifyMtpMounted_0002
934 * @tc.name: Volume_manager_service_NotifyMtpMounted_0002
935 * @tc.desc: Test function of NotifyMtpMounted interface for SUCCESS.
936 * @tc.size: MEDIUM
937 * @tc.type: FUNC
938 * @tc.level Level 1
939 * @tc.require: SR000GGUPF
940 */
941 HWTEST_F(VolumeManagerServiceTest, Storage_manager_NotifyMtpMounted_0002, testing::ext::TestSize.Level1)
942 {
943 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_NotifyMtpMounted_0002";
944 auto &vmService = VolumeManagerService::GetInstance();
945 std::string id = "vol-1-6";
946 std::string path = "/mnt/data/external/1";
947 std::string desc = "description-1";
948 std::string uuid = "uuid-1";
949 g_cnt = 1;
950 vmService.NotifyMtpMounted(id, path, desc, uuid);
951 g_cnt = 0;
952 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_NotifyMtpMounted_0002";
953 }
954
955 /**
956 * @tc.number: SUB_STORAGE_Volume_manager_service_NotifyMtpMounted_0003
957 * @tc.name: Volume_manager_service_NotifyMtpMounted_0003
958 * @tc.desc: Test function of NotifyMtpMounted interface for SUCCESS.
959 * @tc.size: MEDIUM
960 * @tc.type: FUNC
961 * @tc.level Level 1
962 * @tc.require: SR000GGUPF
963 */
964 HWTEST_F(VolumeManagerServiceTest, Storage_manager_NotifyMtpMounted_0003, testing::ext::TestSize.Level1)
965 {
966 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_NotifyMtpMounted_0003";
967 auto &vmService = VolumeManagerService::GetInstance();
968 std::string id = "vol-1-6";
969 std::string path = "/mnt/data/external/1";
970 std::string desc = "description-1";
971 std::string uuid = "uuid-1";
972 g_cnt = 2;
973 vmService.NotifyMtpMounted(id, path, desc, uuid);
974 g_cnt = 0;
975 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_NotifyMtpMounted_0003";
976 }
977
978 /**
979 * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0003
980 * @tc.name: Volume_manager_service_Format_0003
981 * @tc.desc: Test function of Format interface for E_NOT_SUPPORT.
982 * @tc.size: MEDIUM
983 * @tc.type: FUNC
984 * @tc.level Level 1
985 * @tc.require: AR000H09L6
986 */
987 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Format_0003, testing::ext::TestSize.Level1)
988 {
989 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Format_0003";
990 EXPECT_CALL(*fileUtilMoc_, IsUsbFuse()).WillOnce(testing::Return(true));
991 auto &vmService =VolumeManagerService::GetInstance();
992 std::string volumeId = "vol-1-11";
993 string fsTypes = "fs-1";
994 int32_t result = vmService.Format(volumeId, fsTypes);
995 EXPECT_EQ(result, E_NON_EXIST);
996 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Format_0003";
997 }
998
999 /**
1000 * @tc.number: SUB_STORAGE_Volume_manager_service_MountUsbFuse_0001
1001 * @tc.name: Volume_manager_service_MountUsbFuse_0001
1002 * @tc.desc: Test function of MountUsbFuse interface for volume state is not unmounted.
1003 * @tc.size: MEDIUM
1004 * @tc.type: FUNC
1005 * @tc.level Level 1
1006 * @tc.require: SR000GGUPF
1007 */
1008 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_MountUsbFuse_0001, testing::ext::TestSize.Level1)
1009 {
1010 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_MountUsbFuse_0001";
1011 auto &vmService =VolumeManagerService::GetInstance();
1012 std::string volumeId = "vol-fuse-3";
1013 int32_t fsType = 1;
1014 std::string diskId = "disk-fuse-3";
1015 VolumeCore vc(volumeId, fsType, diskId);
1016 vc.SetState(VolumeState::MOUNTED);
1017 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
1018 int32_t result = vmService.MountUsbFuse(volumeId);
1019 EXPECT_EQ(result, E_NON_EXIST);
1020 vmService.volumeMap_.Erase(volumeId);
1021 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_MountUsbFuse_0001";
1022 }
1023
1024 /**
1025 * @tc.number: SUB_STORAGE_Volume_manager_service_MountUsbFuse_0002
1026 * @tc.name: Volume_manager_service_MountUsbFuse_0002
1027 * @tc.desc: Test function of MountUsbFuse interface for Check method fails.
1028 * @tc.size: MEDIUM
1029 * @tc.type: FUNC
1030 * @tc.level Level 1
1031 * @tc.require: SR000GGUPF
1032 */
1033 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_MountUsbFuse_0002, testing::ext::TestSize.Level1)
1034 {
1035 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_MountUsbFuse_0002";
1036 auto &vmService =VolumeManagerService::GetInstance();
1037 std::string volumeId = "vol-fuse-4";
1038 int32_t fsType = 1;
1039 std::string diskId = "disk-fuse-4";
1040 VolumeCore vc(volumeId, fsType, diskId);
1041 vc.SetState(VolumeState::UNMOUNTED);
1042 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
1043 int32_t result = vmService.MountUsbFuse(volumeId);
1044 // Check method will fail because volume is not properly setup
1045 EXPECT_NE(result, E_OK);
1046 vmService.volumeMap_.Erase(volumeId);
1047 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_MountUsbFuse_0002";
1048 }
1049
1050 /**
1051 * @tc.number: SUB_STORAGE_Volume_manager_service_MountUsbFuse_0003
1052 * @tc.name: Volume_manager_service_MountUsbFuse_0003
1053 * @tc.desc: Test function of MountUsbFuse interface for MountUsbFuse communication fails.
1054 * @tc.size: MEDIUM
1055 * @tc.type: FUNC
1056 * @tc.level Level 1
1057 * @tc.require: SR000GGUPF
1058 */
1059 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_MountUsbFuse_0003, testing::ext::TestSize.Level1)
1060 {
1061 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_MountUsbFuse_0003";
1062 auto &vmService =VolumeManagerService::GetInstance();
1063 std::string volumeId = "vol-fuse-5";
1064 int32_t fsType = 1;
1065 std::string diskId = "disk-fuse-5";
1066 VolumeCore vc(volumeId, fsType, diskId);
1067 vc.SetState(VolumeState::UNMOUNTED);
1068 vmService.volumeMap_.Insert(volumeId, make_shared<VolumeExternal>(vc));
1069 int32_t result = vmService.MountUsbFuse(volumeId);
1070 // The communication will fail due to lack of proper setup
1071 EXPECT_NE(result, E_OK);
1072 vmService.volumeMap_.Erase(volumeId);
1073 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_MountUsbFuse_0003";
1074 }
1075 } // namespace
1076