• 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->OnVolumeDestroyed(volumeId);
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->OnVolumeDestroyed(volumeId);
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         vmService->OnVolumeDestroyed(volumeId);
166     }
167     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeCreated_0000";
168 }
169 
170 /**
171  * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeMounted_0000
172  * @tc.name: Volume_manager_service_OnVolumeMounted_0000
173  * @tc.desc: Test function of OnVolumeMounted interface for SUCCESS.
174  * @tc.size: MEDIUM
175  * @tc.type: FUNC
176  * @tc.level Level 1
177  * @tc.require: SR000GGUPF
178  */
179 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeMounted_0000, testing::ext::TestSize.Level1)
180 {
181     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeMounted_0000";
182     std::shared_ptr<VolumeManagerService> vmService =
183         DelayedSingleton<VolumeManagerService>::GetInstance();
184     std::string volumeId = "";
185     int32_t fsType = 1;
186     std::string fsUuid = "";
187     std::string path = "";
188     std::string description = "";
189     if (vmService != nullptr) {
190         vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
191     }
192     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeMounted_0000";
193 }
194 
195 /**
196  * @tc.number: SUB_STORAGE_Volume_manager_service_OnVolumeDestroyed_0000
197  * @tc.name: Volume_manager_service_OnVolumeDestroyed_0000
198  * @tc.desc: Test function of OnVolumeDestroyed interface for SUCCESS.
199  * @tc.size: MEDIUM
200  * @tc.type: FUNC
201  * @tc.level Level 1
202  * @tc.require: SR000GGUPF
203  */
204 HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeDestroyed_0000, testing::ext::TestSize.Level1)
205 {
206     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeDestroyed_0000";
207     std::shared_ptr<VolumeManagerService> vmService =
208         DelayedSingleton<VolumeManagerService>::GetInstance();
209     std::string volumeId = "";
210     if (vmService != nullptr) {
211         vmService->OnVolumeDestroyed(volumeId);
212     }
213     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeDestroyed_0000";
214 }
215 
216 /**
217  * @tc.number: SUB_STORAGE_Volume_manager_service_GetAllVolumes_0000
218  * @tc.name: Volume_manager_service_GetAllVolumes_0000
219  * @tc.desc: Test function of GetAllVolumes interface for SUCCESS.
220  * @tc.size: MEDIUM
221  * @tc.type: FUNC
222  * @tc.level Level 1
223  * @tc.require: SR000GGUPF
224  */
225 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetAllVolumes_0000, testing::ext::TestSize.Level1)
226 {
227     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetAllVolumes_0000";
228     std::shared_ptr<VolumeManagerService> vmService =
229             DelayedSingleton<VolumeManagerService>::GetInstance();
230     std::vector<VolumeExternal> result = vmService->GetAllVolumes();
231     EXPECT_EQ(result.size(), 0);
232     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetAllVolumes_0000";
233 }
234 
235 /**
236  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeByUuid_0000
237  * @tc.name: Volume_manager_service_GetVolumeByUuid_0000
238  * @tc.desc: Test function of GetVolumeByUuid interface for SUCCESS.
239  * @tc.size: MEDIUM
240  * @tc.type: FUNC
241  * @tc.level Level 1
242  * @tc.require: SR000GGUPF
243  */
244 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0000, testing::ext::TestSize.Level1)
245 {
246     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0000";
247     std::shared_ptr<VolumeManagerService> vmService =
248             DelayedSingleton<VolumeManagerService>::GetInstance();
249     std::string volumeId = "vol-1-6";
250     int32_t fsType = 1;
251     std::string fsUuid = "uuid-1";
252     std::string path = "/";
253     std::string description = "description-1";
254     std::string diskId = "disk-1-6";
255     VolumeCore vc(volumeId, fsType, diskId);
256     vmService->OnVolumeCreated(vc);
257     vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
258     std::shared_ptr<VolumeExternal> result = vmService->GetVolumeByUuid(fsUuid);
259     EXPECT_NE(result, nullptr);
260     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeByUuid_0000";
261 }
262 
263 /**
264  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0000
265  * @tc.name: Volume_manager_service_GetVolumeById_0000
266  * @tc.desc: Test function of GetVolumeById interface for SUCCESS.
267  * @tc.size: MEDIUM
268  * @tc.type: FUNC
269  * @tc.level Level 1
270  * @tc.require: AR000H09L6
271  */
272 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0000, testing::ext::TestSize.Level1)
273 {
274     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0000";
275     std::shared_ptr<VolumeManagerService> vmService =
276             DelayedSingleton<VolumeManagerService>::GetInstance();
277     std::string volumeId = "vol-1-8";
278     int32_t fsType = 1;
279     std::string diskId = "disk-1-8";
280     VolumeCore vc(volumeId, fsType, diskId);
281     vmService->OnVolumeCreated(vc);
282     VolumeExternal ve;
283     int32_t result = vmService->GetVolumeById(volumeId, ve);
284     EXPECT_EQ(result, E_OK);
285     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0000";
286 }
287 
288 /**
289  * @tc.number: SUB_STORAGE_Volume_manager_service_GetVolumeById_0001
290  * @tc.name: Volume_manager_service_GetVolumeById_0001
291  * @tc.desc: Test function of GetVolumeById interface for ERROR which volumeId not exist.
292  * @tc.size: MEDIUM
293  * @tc.type: FUNC
294  * @tc.level Level 1
295  * @tc.require: AR000H09L6
296  */
297 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0001, testing::ext::TestSize.Level1)
298 {
299     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0001";
300     std::shared_ptr<VolumeManagerService> vmService =
301             DelayedSingleton<VolumeManagerService>::GetInstance();
302     std::string volumeId = "vol-1-9";
303     VolumeExternal ve;
304     int32_t result = vmService->GetVolumeById(volumeId, ve);
305     EXPECT_NE(result, E_OK);
306     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetVolumeById_0001";
307 }
308 
309 /**
310  * @tc.number: SUB_STORAGE_Volume_manager_service_SetVolumeDescription_0000
311  * @tc.name: Volume_manager_service_SetVolumeDescription_0000
312  * @tc.desc: Test function of SetVolumeDescription interface for SUCCESS.
313  * @tc.size: MEDIUM
314  * @tc.type: FUNC
315  * @tc.level Level 1
316  * @tc.require: AR000H09L6
317  */
318 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_SetVolumeDescription_0000, testing::ext::TestSize.Level1)
319 {
320     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_SetVolumeDescription_0000";
321     std::shared_ptr<VolumeManagerService> vmService =
322             DelayedSingleton<VolumeManagerService>::GetInstance();
323     std::string volumeId = "vol-1-10";
324     int32_t fsType = 1;
325     std::string diskId = "disk-1-10";
326     VolumeCore vc(volumeId, fsType, diskId);
327     vmService->OnVolumeCreated(vc);
328     std::string fsUuid = "uuid-2";
329     std::string description = "description-1";
330     int32_t result = vmService->SetVolumeDescription(fsUuid, description);
331     EXPECT_EQ(result, E_NON_EXIST);
332     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_SetVolumeDescription_0000";
333 }
334 
335 /**
336  * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0000
337  * @tc.name: Volume_manager_service_Format_0000
338  * @tc.desc: Test function of Format interface for SUCCESS.
339  * @tc.size: MEDIUM
340  * @tc.type: FUNC
341  * @tc.level Level 1
342  * @tc.require: AR000H09L6
343  */
344 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0000, testing::ext::TestSize.Level1)
345 {
346     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0000";
347     std::shared_ptr<VolumeManagerService> vmService =
348             DelayedSingleton<VolumeManagerService>::GetInstance();
349     std::string volumeId = "vol-1-11";
350     int fsType = 1;
351     std::string diskId = "disk-1-11";
352     VolumeCore vc(volumeId, fsType, diskId);
353     vmService->OnVolumeCreated(vc);
354     string fsTypes = "fs-1";
355     int32_t result = vmService->Format(volumeId, fsTypes);
356     EXPECT_EQ(result, E_NON_EXIST);
357     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0000";
358 }
359 
360 /**
361  * @tc.number: SUB_STORAGE_Volume_manager_service_Format_0001
362  * @tc.name: Volume_manager_service_Format_0000
363  * @tc.desc: Test function of Format interface for SUCCESS.
364  * @tc.size: MEDIUM
365  * @tc.type: FUNC
366  * @tc.level Level 1
367  * @tc.require: AR000H09L6
368  */
369 HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0001, testing::ext::TestSize.Level1)
370 {
371     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0001";
372     std::shared_ptr<VolumeManagerService> vmService =
373             DelayedSingleton<VolumeManagerService>::GetInstance();
374     std::string volumeId = "vol-1-12";
375     int fsType = 1;
376     std::string fsUuid = "uuid-3";
377     std::string diskId = "disk-1-12";
378     VolumeCore vc(volumeId, fsType, diskId, VolumeState::MOUNTED);
379     vmService->OnVolumeCreated(vc);
380     VolumeExternal ve;
381     vmService->GetVolumeById(volumeId, ve);
382     string fsTypes = "fs-1";
383     int32_t result = vmService->Format(volumeId, fsTypes);
384     EXPECT_EQ(result, E_VOL_STATE);
385     GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_Format_0001";
386 }
387 } // namespace
388