• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
19 #include "volume/volume_manager_service.h"
20 #include "volume_core.h"
21 #include "storage_service_errno.h"
22 
23 namespace {
24 using namespace std;
25 using namespace OHOS;
26 using namespace StorageManager;
27 class VolumeManagerServiceTest : public testing::Test {
28 public:
SetUpTestCase(void)29     static void SetUpTestCase(void) {};
TearDownTestCase()30     static void TearDownTestCase() {};
SetUp()31     void SetUp() {};
TearDown()32     void TearDown() {};
33 };
34 
35 /**
36  * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0000
37  * @tc.name: Volume_manager_service_Mount_0000
38  * @tc.desc: Test function of Mount interface for SUCCESS.
39  * @tc.size: MEDIUM
40  * @tc.type: FUNC
41  * @tc.level Level 1
42  * @tc.require: SR000GGUPF
43  */
44 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0000, testing::ext::TestSize.Level1)
45 {
46     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0000";
47     std::shared_ptr<VolumeManagerService> vmService =
48         DelayedSingleton<VolumeManagerService>::GetInstance();
49     std::string volumeId = "vol-1-1";
50     int32_t fsType = 1;
51     std::string diskId = "disk-1-1";
52     VolumeCore vc(volumeId, fsType, diskId);
53     int32_t result;
54     if (vmService != nullptr) {
55         vmService->OnVolumeCreated(vc);
56         result = vmService->Mount(volumeId);
57         vmService->OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
58     }
59     EXPECT_EQ(result, E_NON_EXIST);
60     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0000";
61 }
62 
63 /**
64  * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0001
65  * @tc.name: Volume_manager_service_Mount_0001
66  * @tc.desc: Test function of Mount interface for SUCCESS.
67  * @tc.size: MEDIUM
68  * @tc.type: FUNC
69  * @tc.level Level 1
70  * @tc.require: SR000GGUPF
71  */
72 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0001, testing::ext::TestSize.Level1)
73 {
74     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0001";
75     std::shared_ptr<VolumeManagerService> vmService =
76         DelayedSingleton<VolumeManagerService>::GetInstance();
77     std::string volumeId = "vol-1-2";
78     int32_t fsType = 1;
79     std::string diskId = "disk-1-2";
80     VolumeCore vc(volumeId, fsType, diskId);
81     int32_t result;
82     if (vmService != nullptr) {
83         result = vmService->Mount(volumeId);
84     }
85     EXPECT_EQ(result, E_NON_EXIST);
86     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0001";
87 }
88 
89 /**
90  * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0000
91  * @tc.name: Volume_manager_service_Unmount_0000
92  * @tc.desc: Test function of Unmount interface for FAILED.
93  * @tc.size: MEDIUM
94  * @tc.type: FUNC
95  * @tc.level Level 1
96  * @tc.require: SR000GGUPF
97  */
98 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0000, testing::ext::TestSize.Level1)
99 {
100     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0000";
101     std::shared_ptr<VolumeManagerService> vmService =
102         DelayedSingleton<VolumeManagerService>::GetInstance();
103     std::string volumeId = "vol-1-3";
104     int32_t fsType = 1;
105     std::string diskId = "disk-1-3";
106     VolumeCore vc(volumeId, fsType, diskId);
107     int32_t result;
108     if (vmService != nullptr) {
109         vc.SetState(VolumeState::MOUNTED);
110         result = vmService->Unmount(volumeId);
111     }
112     EXPECT_EQ(result, E_NON_EXIST);
113     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0000";
114 }
115 
116 /**
117  * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0001
118  * @tc.name: Volume_manager_service_Unmount_0001
119  * @tc.desc: Test function of Unmount interface for SUCCESS.
120  * @tc.size: MEDIUM
121  * @tc.type: FUNC
122  * @tc.level Level 1
123  * @tc.require: SR000GGUPF
124  */
125 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0001, testing::ext::TestSize.Level1)
126 {
127     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0001";
128     std::shared_ptr<VolumeManagerService> vmService =
129         DelayedSingleton<VolumeManagerService>::GetInstance();
130     std::string volumeId = "vol-1-4";
131     int32_t fsType = 1;
132     std::string diskId = "disk-1-4";
133     VolumeCore vc(volumeId, fsType, diskId);
134     int32_t result;
135     if (vmService != nullptr) {
136         vc.SetState(VolumeState::MOUNTED);
137         vmService->OnVolumeCreated(vc);
138         result = vmService->Unmount(volumeId);
139         vmService->OnVolumeStateChanged(volumeId, VolumeState::REMOVED);
140     }
141     EXPECT_EQ(result, E_NON_EXIST);
142     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0001";
143 }
144 
145 /**
146  * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeCreated_0000
147  * @tc.name: Volume_manager_service_OnVolumeCreated_0000
148  * @tc.desc: Test function of OnVolumeCreated interface for SUCCESS.
149  * @tc.size: MEDIUM
150  * @tc.type: FUNC
151  * @tc.level Level 1
152  * @tc.require: SR000GGUPF
153  */
154 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeCreated_0000, testing::ext::TestSize.Level1)
155 {
156     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeCreated_0000";
157     std::shared_ptr<VolumeManagerService> vmService =
158         DelayedSingleton<VolumeManagerService>::GetInstance();
159     std::string volumeId = "vol-1-5";
160     int type = 1;
161     std::string diskId = "disk-1-5";
162     VolumeCore vc(volumeId, type, diskId);
163     if (vmService != nullptr) {
164         vmService->OnVolumeCreated(vc);
165         VolumeExternal ve;
166         int32_t res = vmService->GetVolumeById(volumeId, ve);
167         EXPECT_EQ(res, E_OK);
168         vmService->OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
169     }
170     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeCreated_0000";
171 }
172 
173 /**
174  * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeMounted_0000
175  * @tc.name: Volume_manager_service_OnVolumeMounted_0000
176  * @tc.desc: Test function of OnVolumeMounted interface for SUCCESS.
177  * @tc.size: MEDIUM
178  * @tc.type: FUNC
179  * @tc.level Level 1
180  * @tc.require: SR000GGUPF
181  */
182 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeMounted_0000, testing::ext::TestSize.Level1)
183 {
184     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeMounted_0000";
185     std::shared_ptr<VolumeManagerService> vmService =
186         DelayedSingleton<VolumeManagerService>::GetInstance();
187     std::string volumeId = "vol-1-5";
188     int32_t fsType = 1;
189     std::string fsUuid = "";
190     std::string path = "";
191     std::string description = "";
192     if (vmService != nullptr) {
193         vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
194         VolumeExternal ve;
195         int32_t res = vmService->GetVolumeById(volumeId, ve);
196         EXPECT_EQ(res, E_NON_EXIST);
197     }
198     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeMounted_0000";
199 }
200 
201 /**
202  * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDestroyed_0000
203  * @tc.name: Volume_manager_service_OnVolumeDestroyed_0000
204  * @tc.desc: Test function of OnVolumeDestroyed interface for SUCCESS.
205  * @tc.size: MEDIUM
206  * @tc.type: FUNC
207  * @tc.level Level 1
208  * @tc.require: SR000GGUPF
209  */
210 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDestroyed_0000, testing::ext::TestSize.Level1)
211 {
212     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDestroyed_0000";
213     std::shared_ptr<VolumeManagerService> vmService =
214         DelayedSingleton<VolumeManagerService>::GetInstance();
215     std::string volumeId = "vol-1-5";
216     if (vmService != nullptr) {
217         vmService->OnVolumeStateChanged(volumeId, VolumeState::BAD_REMOVAL);
218         VolumeExternal ve;
219         int32_t res = vmService->GetVolumeById(volumeId, ve);
220         EXPECT_EQ(res, E_NON_EXIST);
221     }
222     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDestroyed_0000";
223 }
224 
225 /**
226  * @tc.number: SUB_STORAGE_Volume_manager_service_GetAllVolumes_0000
227  * @tc.name: Volume_manager_service_GetAllVolumes_0000
228  * @tc.desc: Test function of GetAllVolumes interface for SUCCESS.
229  * @tc.size: MEDIUM
230  * @tc.type: FUNC
231  * @tc.level Level 1
232  * @tc.require: SR000GGUPF
233  */
234 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetAllVolumes_0000, testing::ext::TestSize.Level1)
235 {
236     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetAllVolumes_0000";
237     std::shared_ptr<VolumeManagerService> vmService =
238             DelayedSingleton<VolumeManagerService>::GetInstance();
239     std::vector<VolumeExternal> result = vmService->GetAllVolumes();
240     EXPECT_EQ(result.size(), 0);
241     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetAllVolumes_0000";
242 }
243 
244 /**
245  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0000
246  * @tc.name: Volume_manager_service_GetVolumeByUuid_0000
247  * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
248  * @tc.size: MEDIUM
249  * @tc.type: FUNC
250  * @tc.level Level 1
251  * @tc.require: SR000GGUPF
252  */
253 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0000, testing::ext::TestSize.Level1)
254 {
255     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0000";
256     std::shared_ptr<VolumeManagerService> vmService =
257             DelayedSingleton<VolumeManagerService>::GetInstance();
258     std::string volumeId = "vol-1-6";
259     int32_t fsType = 1;
260     std::string fsUuid = "uuid-1";
261     std::string path = "/";
262     std::string description = "description-1";
263     std::string diskId = "disk-1-6";
264     VolumeCore vc(volumeId, fsType, diskId);
265     vmService->OnVolumeCreated(vc);
266     vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
267     std::shared_ptr<VolumeExternal> result = vmService->GetVolumeByUuid(fsUuid);
268     EXPECT_NE(result, nullptr);
269     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0000";
270 }
271 
272 /**
273  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0001
274  * @tc.name: Volume_manager_service_GetVolumeByUuid_0001
275  * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
276  * @tc.size: MEDIUM
277  * @tc.type: FUNC
278  * @tc.level Level 1
279  * @tc.require: SR000GGUPF
280  */
281 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0001, testing::ext::TestSize.Level1)
282 {
283     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0001";
284     std::shared_ptr<VolumeManagerService> vmService =
285             DelayedSingleton<VolumeManagerService>::GetInstance();
286     std::string volumeId = "vol-1-6";
287     int32_t fsType = 1;
288     std::string fsUuid = "uuid-1";
289     std::string path = "/";
290     std::string description = "description-1";
291     std::string diskId = "disk-1-6";
292     VolumeCore vc(volumeId, fsType, diskId);
293     vmService->OnVolumeCreated(vc);
294     vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
295     VolumeExternal ve;
296     int32_t ret = vmService->GetVolumeByUuid(fsUuid, ve);
297     EXPECT_EQ(ret, E_OK);
298     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0001";
299 }
300 
301 /**
302  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0002
303  * @tc.name: Volume_manager_service_GetVolumeByUuid_0002
304  * @tc.desc: Test function of GetVolumeByUuid interface for ERROR which volumeUuid not exist.
305  * @tc.size: MEDIUM
306  * @tc.type: FUNC
307  * @tc.level Level 1
308  * @tc.require: SR000GGUPF
309  */
310 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0002, testing::ext::TestSize.Level1)
311 {
312     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0002";
313     std::shared_ptr<VolumeManagerService> vmService =
314             DelayedSingleton<VolumeManagerService>::GetInstance();
315     std::string fsUuid = "uuid-2";
316     VolumeExternal ve;
317     int32_t ret = vmService->GetVolumeByUuid(fsUuid, ve);
318     EXPECT_EQ(ret, E_NON_EXIST);
319     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0002";
320 }
321 
322 /**
323  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0000
324  * @tc.name: Volume_manager_service_GetVolumeById_0000
325  * @tc.desc: Test function of GetVolumeById interface for SUCCESS.
326  * @tc.size: MEDIUM
327  * @tc.type: FUNC
328  * @tc.level Level 1
329  * @tc.require: AR000H09L6
330  */
331 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0000, testing::ext::TestSize.Level1)
332 {
333     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0000";
334     std::shared_ptr<VolumeManagerService> vmService =
335             DelayedSingleton<VolumeManagerService>::GetInstance();
336     std::string volumeId = "vol-1-8";
337     int32_t fsType = 1;
338     std::string diskId = "disk-1-8";
339     VolumeCore vc(volumeId, fsType, diskId);
340     vmService->OnVolumeCreated(vc);
341     VolumeExternal ve;
342     int32_t result = vmService->GetVolumeById(volumeId, ve);
343     EXPECT_EQ(result, E_OK);
344     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0000";
345 }
346 
347 /**
348  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0001
349  * @tc.name: Volume_manager_service_GetVolumeById_0001
350  * @tc.desc: Test function of GetVolumeById interface for ERROR which volumeId not exist.
351  * @tc.size: MEDIUM
352  * @tc.type: FUNC
353  * @tc.level Level 1
354  * @tc.require: AR000H09L6
355  */
356 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0001, testing::ext::TestSize.Level1)
357 {
358     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0001";
359     std::shared_ptr<VolumeManagerService> vmService =
360             DelayedSingleton<VolumeManagerService>::GetInstance();
361     std::string volumeId = "vol-1-9";
362     VolumeExternal ve;
363     int32_t result = vmService->GetVolumeById(volumeId, ve);
364     EXPECT_NE(result, E_OK);
365     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0001";
366 }
367 
368 /**
369  * @tc.number: SUB_STORAGE_Volume_manager_service_SetVolumeDescription_0000
370  * @tc.name: Volume_manager_service_SetVolumeDescription_0000
371  * @tc.desc: Test function of SetVolumeDescription interface for SUCCESS.
372  * @tc.size: MEDIUM
373  * @tc.type: FUNC
374  * @tc.level Level 1
375  * @tc.require: AR000H09L6
376  */
377 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_SetVolumeDescription_0000, testing::ext::TestSize.Level1)
378 {
379     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_SetVolumeDescription_0000";
380     std::shared_ptr<VolumeManagerService> vmService =
381             DelayedSingleton<VolumeManagerService>::GetInstance();
382     std::string volumeId = "vol-1-10";
383     int32_t fsType = 1;
384     std::string diskId = "disk-1-10";
385     VolumeCore vc(volumeId, fsType, diskId);
386     vmService->OnVolumeCreated(vc);
387     std::string fsUuid = "uuid-2";
388     std::string description = "description-1";
389     int32_t result = vmService->SetVolumeDescription(fsUuid, description);
390     EXPECT_EQ(result, E_NON_EXIST);
391     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_SetVolumeDescription_0000";
392 }
393 
394 /**
395  * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0000
396  * @tc.name: Volume_manager_service_Format_0000
397  * @tc.desc: Test function of Format interface for SUCCESS.
398  * @tc.size: MEDIUM
399  * @tc.type: FUNC
400  * @tc.level Level 1
401  * @tc.require: AR000H09L6
402  */
403 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0000, testing::ext::TestSize.Level1)
404 {
405     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0000";
406     std::shared_ptr<VolumeManagerService> vmService =
407             DelayedSingleton<VolumeManagerService>::GetInstance();
408     std::string volumeId = "vol-1-11";
409     int fsType = 1;
410     std::string diskId = "disk-1-11";
411     VolumeCore vc(volumeId, fsType, diskId);
412     vmService->OnVolumeCreated(vc);
413     string fsTypes = "fs-1";
414     int32_t result = vmService->Format(volumeId, fsTypes);
415     EXPECT_EQ(result, E_NON_EXIST);
416     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0000";
417 }
418 
419 /**
420  * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0001
421  * @tc.name: Volume_manager_service_Format_0000
422  * @tc.desc: Test function of Format interface for SUCCESS.
423  * @tc.size: MEDIUM
424  * @tc.type: FUNC
425  * @tc.level Level 1
426  * @tc.require: AR000H09L6
427  */
428 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0001, testing::ext::TestSize.Level1)
429 {
430     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0001";
431     std::shared_ptr<VolumeManagerService> vmService =
432             DelayedSingleton<VolumeManagerService>::GetInstance();
433     std::string volumeId = "vol-1-12";
434     int fsType = 1;
435     std::string fsUuid = "uuid-3";
436     std::string diskId = "disk-1-12";
437     VolumeCore vc(volumeId, fsType, diskId, VolumeState::MOUNTED);
438     vmService->OnVolumeCreated(vc);
439     VolumeExternal ve;
440     vmService->GetVolumeById(volumeId, ve);
441     string fsTypes = "fs-1";
442     int32_t result = vmService->Format(volumeId, fsTypes);
443     EXPECT_EQ(result, E_VOL_STATE);
444     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0001";
445 }
446 } // namespace
447