1 /*
2  * Copyright (c) 2021-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 <fcntl.h>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 #include <iostream>
20 #include <mntent.h>
21 #include <unordered_map>
22 
23 #include "crypto/app_clone_key_manager.h"
24 #include "ipc/istorage_daemon.h"
25 #include "ipc/storage_daemon.h"
26 #include "storage_service_errno.h"
27 #include "storage_service_log.h"
28 #include "test/common/help_utils.h"
29 #include "user/user_manager.h"
30 #include "utils/file_utils.h"
31 
32 namespace OHOS {
33 namespace StorageDaemon {
34 using namespace testing::ext;
35 class StorageDaemonTest : public testing::Test {
36 public:
37     static void SetUpTestCase(void);
TearDownTestCase(void)38     static void TearDownTestCase(void) {};
39     void SetUp();
40     void TearDown();
41 
42     StorageDaemon* storageDaemon_;
43 };
44 
SetUpTestCase(void)45 void StorageDaemonTest::SetUpTestCase(void)
46 {
47     std::vector<std::string> paths = {
48         "/data/app",
49         "/data/app/el1",
50         "/data/app/el2",
51 
52         "/data/service",
53         "/data/service/el1",
54         "/data/service/el2",
55 
56         "/data/chipset",
57         "/data/chipset/el1",
58         "/data/chipset/el2",
59 
60         "/storage",
61         "/storage/media"
62     };
63 
64     mode_t mode = 0711;
65     for (auto path : paths) {
66         if (!StorageTest::StorageTestUtils::CheckDir(path)) {
67             StorageTest::StorageTestUtils::MkDir(path, mode);
68         }
69     }
70 }
71 
SetUp()72 void StorageDaemonTest::SetUp()
73 {
74     storageDaemon_ = new StorageDaemon();
75     StorageTest::StorageTestUtils::ClearTestResource();
76 }
77 
TearDown(void)78 void StorageDaemonTest::TearDown(void)
79 {
80     StorageTest::StorageTestUtils::ClearTestResource();
81     if (storageDaemon_ != nullptr) {
82         delete storageDaemon_;
83         storageDaemon_ = nullptr;
84     }
85 }
86 
87 /**
88  * @tc.name: Storage_Manager_StorageDaemonTest_PrepareUserDirs_001
89  * @tc.desc: check PrepareUserDirs when the el1 path exists but is not dir.
90  * @tc.type: FUNC
91  * @tc.require: AR000GK4HB
92  */
93 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_PrepareUserDirs_001, TestSize.Level1)
94 {
95     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_001 start";
96 
97     ASSERT_TRUE(storageDaemon_ != nullptr);
98 
99     std::string filePath(StorageTest::StorageTestUtils::gRootDirs[0].path);
100     filePath.replace(filePath.find("%s"), 2, "el1");
101     filePath.replace(filePath.find("%d"), 2, std::to_string(StorageTest::USER_ID1));
102     auto bRet = StorageTest::StorageTestUtils::CreateFile(filePath);
103     EXPECT_TRUE(bRet) << "check the file create";
104 
105     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
106     int32_t ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID1, flags);
107     EXPECT_TRUE(ret == E_PREPARE_DIR) << "the path is not dir";
108 
109     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_001 end";
110 }
111 
112 /**
113  * @tc.name: Storage_Manager_StorageDaemonTest_PrepareUserDirs_002
114  * @tc.desc: check PrepareUserDirs when the flags is incorrect.
115  * @tc.type: FUNC
116  * @tc.require: AR000GK4HB
117  */
118 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_PrepareUserDirs_002, TestSize.Level1)
119 {
120     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_002 start";
121 
122     ASSERT_TRUE(storageDaemon_ != nullptr);
123 
124     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1;
125     auto ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID2, flags);
126     EXPECT_TRUE(ret == E_OK) << "the flags is incorrect";
127 
128     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_002 end";
129 }
130 
131 /**
132  * @tc.name: Storage_Manager_StorageDaemonTest_PrepareUserDirs_003
133  * @tc.desc: Verify the PrepareUserDirs function when args are normal.
134  * @tc.type: FUNC
135  * @tc.require: AR000GK4HB
136  */
137 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_PrepareUserDirs_003, TestSize.Level1)
138 {
139     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_003 start";
140 
141     ASSERT_TRUE(storageDaemon_ != nullptr);
142 
143     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
144     auto ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID3, flags);
145     EXPECT_TRUE(ret == E_OK);
146 
147     storageDaemon_->DestroyUserDirs(StorageTest::USER_ID3, flags);
148     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_PrepareUserDirs_003 end";
149 }
150 
151 /**
152  * @tc.name: Storage_Manager_StorageDaemonTest_StartUser_001
153  * @tc.desc: check StartUser when user's dirs are not prepare.
154  * @tc.type: FUNC
155  * @tc.require: AR000GK4HB
156  */
157 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StartUser_001, TestSize.Level1)
158 {
159     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StartUser_001 start";
160 
161     ASSERT_TRUE(storageDaemon_ != nullptr);
162 
163     int32_t ret = storageDaemon_->StartUser(StorageTest::USER_ID1);
164     EXPECT_TRUE(ret == E_MOUNT) << "user's dirs are not prepare";
165 
166     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StartUser_001 end";
167 }
168 
169 /**
170  * @tc.name: Storage_Manager_StorageDaemonTest_StartUser_002
171  * @tc.desc: check the StartUser function when args are normal
172  * @tc.type: FUNC
173  * @tc.require: AR000GK4HB
174  */
175 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StartUser_002, TestSize.Level1)
176 {
177     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StartUser_002 start";
178 
179     ASSERT_TRUE(storageDaemon_ != nullptr);
180 
181     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
182     auto ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID5, flags);
183     EXPECT_TRUE(ret == E_OK) << "create user dirs error";
184 
185     ret = storageDaemon_->StartUser(StorageTest::USER_ID5);
186     EXPECT_TRUE(ret == E_OK) << "check StartUser";
187 
188     storageDaemon_->StopUser(StorageTest::USER_ID5);
189     storageDaemon_->DestroyUserDirs(StorageTest::USER_ID5, flags);
190     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StartUser_002 end";
191 }
192 
193 /**
194  * @tc.name: Storage_Manager_StorageDaemonTest_DestroyUserDirs_001
195  * @tc.desc: Verify the DestroyUserDirs function.
196  * @tc.type: FUNC
197  * @tc.require: AR000GK4HB
198  */
199 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_DestroyUserDirs_001, TestSize.Level1)
200 {
201     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_DestroyUserDirs_001 start";
202 
203     ASSERT_TRUE(storageDaemon_ != nullptr);
204 
205     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
206     auto ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID3, flags);
207     EXPECT_TRUE(ret == E_OK);
208 
209     ret = storageDaemon_->DestroyUserDirs(StorageTest::USER_ID3, flags);
210     EXPECT_TRUE(ret == E_OK);
211 
212     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_DestroyUserDirs_001 end";
213 }
214 
215 /**
216  * @tc.name: Storage_Manager_StorageDaemonTest_StopUser_001
217  * @tc.desc: check the StopUser function when dir does not exist.
218  * @tc.type: FUNC
219  * @tc.require: AR000GK4HB
220  */
221 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StopUser_001, TestSize.Level1)
222 {
223     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_001 start";
224 
225     ASSERT_TRUE(storageDaemon_ != nullptr);
226 
227     auto ret = storageDaemon_->StopUser(StorageTest::USER_ID1);
228     EXPECT_TRUE(ret == E_OK) << "dir is not mount";
229 
230     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_001 end";
231 }
232 
233 /**
234  * @tc.name: Storage_Manager_StorageDaemonTest_StopUser_002
235  * @tc.desc: check the StopUser function when dir is not mount.
236  * @tc.type: FUNC
237  * @tc.require: AR000GK4HB
238  */
239 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StopUser_002, TestSize.Level1)
240 {
241     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_002 start";
242 
243     ASSERT_TRUE(storageDaemon_ != nullptr);
244 
245     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
246     storageDaemon_->PrepareUserDirs(StorageTest::USER_ID4, flags);
247 
248     auto ret = storageDaemon_->StopUser(StorageTest::USER_ID4);
249     EXPECT_TRUE(ret == E_OK) << "stop user error";
250 
251     storageDaemon_->DestroyUserDirs(StorageTest::USER_ID4, flags);
252     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_002 end";
253 }
254 
255 /**
256  * @tc.name: Storage_Manager_StorageDaemonTest_StopUser_003
257  * @tc.desc: check the StopUser function normal
258  * @tc.type: FUNC
259  * @tc.require: AR000GK4HB
260  */
261 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StopUser_003, TestSize.Level1)
262 {
263     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_003 start";
264 
265     ASSERT_TRUE(storageDaemon_ != nullptr);
266 
267     int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL1 | IStorageDaemon::CRYPTO_FLAG_EL2;
268     auto ret = storageDaemon_->PrepareUserDirs(StorageTest::USER_ID3, flags);
269     EXPECT_TRUE(ret == E_OK) << "PrepareUserDirs error";
270     ret = storageDaemon_->StartUser(StorageTest::USER_ID3);
271     EXPECT_TRUE(ret == E_OK) << "StartUser error";
272 
273     ret = storageDaemon_->StopUser(StorageTest::USER_ID3);
274     EXPECT_TRUE(ret == E_OK) << "check StopUser error";
275 
276     storageDaemon_->DestroyUserDirs(StorageTest::USER_ID3, flags);
277     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_003 end";
278 }
279 
280 /**
281  * @tc.name: Storage_Manager_StorageDaemonTest_Shutdown_001
282  * @tc.desc: check the StopUser function normal
283  * @tc.type: FUNC
284  * @tc.require: AR000GK4HB
285  */
286 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Shutdown_001, TestSize.Level1)
287 {
288     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Shutdown_001 start";
289 
290     ASSERT_TRUE(storageDaemon_ != nullptr);
291 
292     auto ret = storageDaemon_->Shutdown();
293     EXPECT_TRUE(ret == E_OK);
294     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Shutdown_001 end";
295 }
296 
297 /**
298  * @tc.name: Storage_Manager_StorageDaemonTest_MountDfsDocs_001
299  * @tc.desc: check the StopUser function normal
300  * @tc.type: FUNC
301  * @tc.require: issueI9G5A0
302  */
303 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_MountDfsDocs_001, TestSize.Level1)
304 {
305     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_MountDfsDocs_001 start";
306 
307     ASSERT_TRUE(storageDaemon_ != nullptr);
308 
309     int32_t userId = 105;
310     std::string relativePath = "account";
311     std::string networkId = "testnetworkid";
312     std::string deviceId = "testdevid";
313     auto ret = storageDaemon_->MountDfsDocs(userId, relativePath, networkId, deviceId);
314     EXPECT_EQ(ret, E_PREPARE_DIR);
315     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_MountDfsDocs_001 end";
316 }
317 
318 /**
319  * @tc.name: Storage_Manager_StorageDaemonTest_UMountDfsDocs_001
320  * @tc.desc: check the StopUser function normal
321  * @tc.type: FUNC
322  * @tc.require: issueI9G5A0
323  */
324 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_UMountDfsDocs_001, TestSize.Level1)
325 {
326     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMountDfsDocs_001 start";
327 
328     ASSERT_TRUE(storageDaemon_ != nullptr);
329 
330     int32_t userId = 105;
331     std::string relativePath = "account";
332     std::string networkId = "testnetworkid";
333     std::string deviceId = "testdevid";
334     auto ret = storageDaemon_->UMountDfsDocs(userId, relativePath, networkId, deviceId);
335     EXPECT_EQ(ret, E_UMOUNT);
336     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMountDfsDocs_001 end";
337 }
338 
339 #ifdef EXTERNAL_STORAGE_MANAGER
340 /**
341  * @tc.name: Storage_Manager_StorageDaemonTest_Mount_001
342  * @tc.desc: check the Mount function when volume not exist
343  * @tc.type: FUNC
344  * @tc.require: AR000GK4HB
345  */
346 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Mount_001, TestSize.Level1)
347 {
348     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Mount_001 start";
349 
350     ASSERT_TRUE(storageDaemon_ != nullptr);
351 
352     std::string volId = "vol-1-1";
353     uint32_t flag = 0;
354     auto ret = storageDaemon_->Mount(volId, flag);
355     EXPECT_TRUE(ret == E_NON_EXIST);
356     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Mount_001 end";
357 }
358 
359 /**
360  * @tc.name: Storage_Manager_StorageDaemonTest_UMount_001
361  * @tc.desc: check the UMount function when volume not exist
362  * @tc.type: FUNC
363  * @tc.require: AR000GK4HB
364  */
365 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_UMount_001, TestSize.Level1)
366 {
367     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMount_001 start";
368 
369     ASSERT_TRUE(storageDaemon_ != nullptr);
370 
371     std::string volId = "vol-1-2";
372     auto ret = storageDaemon_->UMount(volId);
373     EXPECT_TRUE(ret == E_NON_EXIST);
374     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMount_001 end";
375 }
376 
377 /**
378  * @tc.name: Storage_Manager_StorageDaemonTest_Check_001
379  * @tc.desc: check the Check function when volume not exist
380  * @tc.type: FUNC
381  * @tc.require: AR000GK4HB
382  */
383 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Check_001, TestSize.Level1)
384 {
385     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Check_001 start";
386 
387     ASSERT_TRUE(storageDaemon_ != nullptr);
388 
389     std::string volId = "vol-1-3";
390     auto ret = storageDaemon_->Check(volId);
391     EXPECT_TRUE(ret == E_NON_EXIST);
392     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Check_001 end";
393 }
394 
395 /**
396  * @tc.name: Storage_Manager_StorageDaemonTest_Format_001
397  * @tc.desc: check the Format function when volume not exist
398  * @tc.type: FUNC
399  * @tc.require: AR000GK4HB
400  */
401 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Format_001, TestSize.Level1)
402 {
403     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Format_001 start";
404 
405     ASSERT_TRUE(storageDaemon_ != nullptr);
406 
407     std::string volId = "vol-1-4";
408     std::string fsType = "exfat";
409     auto ret = storageDaemon_->Format(volId, fsType);
410     EXPECT_TRUE(ret == E_NON_EXIST);
411     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Format_001 end";
412 }
413 
414 /**
415  * @tc.name: Storage_Manager_StorageDaemonTest_Partition_001
416  * @tc.desc: check the Partition function when disk not exist
417  * @tc.type: FUNC
418  * @tc.require: AR000GK4HB
419  */
420 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Partition_001, TestSize.Level1)
421 {
422     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Partition_001 start";
423 
424     ASSERT_TRUE(storageDaemon_ != nullptr);
425 
426     std::string diskId = "disk-1-0";
427     int32_t type = 0;
428     auto ret = storageDaemon_->Partition(diskId, type);
429     EXPECT_TRUE(ret == E_NON_EXIST);
430     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Partition_001 end";
431 }
432 
433 /**
434  * @tc.name: Storage_Manager_StorageDaemonTest_SetVolumeDescription_001
435  * @tc.desc: check the SetVolumeDescription function when volume not exist
436  * @tc.type: FUNC
437  * @tc.require: AR000GK4HB
438  */
439 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_SetVolumeDescription_001, TestSize.Level1)
440 {
441     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetVolumeDescription_001 start";
442 
443     ASSERT_TRUE(storageDaemon_ != nullptr);
444 
445     std::string volId = "vol-1-5";
446     std::string des = "des";
447     auto ret = storageDaemon_->SetVolumeDescription(volId, des);
448     EXPECT_TRUE(ret == E_NON_EXIST);
449     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetVolumeDescription_001 end";
450 }
451 #endif
452 
453 /**
454  * @tc.name: Storage_Manager_StorageDaemonTest_SetBundleQuota_001
455  * @tc.desc: check the SetBundleQuota function
456  * @tc.type: FUNC
457  * @tc.require: AR000HSKSO
458  */
459 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_SetBundleQuota_001, TestSize.Level1)
460 {
461     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetBundleQuota_001 start";
462 
463     ASSERT_TRUE(storageDaemon_ != nullptr);
464 
465     std::string bundleName = "com.ohos.bundleName-0-1";
466     std::string bundleDataDirPath = "/data/app/el2/100/base/" + bundleName;
467     int32_t uid = 20000000;
468     int32_t limitSizeMb = 1000;
469     auto ret = storageDaemon_->SetBundleQuota(bundleName, uid, bundleDataDirPath, limitSizeMb);
470     EXPECT_TRUE(ret == E_SYS_CALL);
471     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetBundleQuota_001 end";
472 }
473 
474 /**
475  * @tc.name: Storage_Manager_StorageDaemonTest_GetBundleStatsForIncrease_001
476  * @tc.desc: check the GetBundleStatsForIncrease function
477  * @tc.type: FUNC
478  * @tc.require: AR000IGCR7
479  */
480 HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_GetBundleStatsForIncrease_001, TestSize.Level1)
481 {
482     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_GetBundleStatsForIncrease_001 start";
483 
484     ASSERT_TRUE(storageDaemon_ != nullptr);
485     // create parameter
486     uint32_t userId = 100;
487     std::vector<std::string> bundleNames;
488     std::string bundleName = "com.ohos.UserFile.ExternalFileManager";
489     bundleNames.emplace_back(bundleName);
490     std::vector<int64_t> incrementalBackTimes;
491     int64_t lastIncrementalTime = 0;
492     incrementalBackTimes.emplace_back(lastIncrementalTime);
493     std::vector<int64_t> pkgFileSizes;
494     std::vector<int64_t> incPkgFileSizes;
495     // prepare config file
496     mode_t mode = 0771;
497     // backup_sa bundle path
498     std::string backupSaBundleDir = BACKUP_PATH_PREFIX + std::to_string(userId) + BACKUP_PATH_SURFFIX + bundleName +
499         FILE_SEPARATOR_CHAR;
500     if (!StorageTest::StorageTestUtils::CheckDir(backupSaBundleDir)) {
501         StorageTest::StorageTestUtils::MkDir(backupSaBundleDir, mode);
502     }
503     // backup_sa include/exclude
504     std::string incExFilePath = backupSaBundleDir + BACKUP_INCEXC_SYMBOL + std::to_string(lastIncrementalTime);
505     std::ofstream incExcFile;
506     incExcFile.open(incExFilePath.data(), std::ios::out | std::ios::trunc);
507     if (!incExcFile.is_open()) {
508         EXPECT_TRUE(false) << "Failed to create file for include-exclude config";
509     }
510     incExcFile << BACKUP_INCLUDE << std::endl;
511     std::string include = "/storage/Users/currentUser/";
512     incExcFile << include << std::endl;
513 
514     incExcFile << BACKUP_EXCLUDE << std::endl;
515     std::string exclude = "/storage/Users/currentUser/.Trash/";
516     incExcFile << exclude << std::endl;
517     incExcFile.close();
518 
519     // backup_sa stat
520     std::string statFilePath = backupSaBundleDir + BACKUP_STAT_SYMBOL + std::to_string(lastIncrementalTime);
521     std::ofstream statFile;
522     statFile.open(statFilePath.data(), std::ios::out | std::ios::trunc);
523     if (!statFile.is_open()) {
524         EXPECT_TRUE(false) << "Failed to create file for bundle stat";
525     }
526     statFile.close();
527     // invoke GetBundleStatsForIncrease
528     auto ret = storageDaemon_->GetBundleStatsForIncrease(userId, bundleNames, incrementalBackTimes, pkgFileSizes,
529         incPkgFileSizes);
530     EXPECT_TRUE(ret == E_OK);
531     EXPECT_GE(pkgFileSizes[0], 0);
532     EXPECT_GE(incPkgFileSizes[0], 0);
533 
534     if (StorageTest::StorageTestUtils::CheckDir(backupSaBundleDir)) {
535         StorageTest::StorageTestUtils::RmDirRecurse(backupSaBundleDir);
536     }
537 
538     GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_GetBundleStatsForIncrease_001 end";
539 }
540 } // STORAGE_DAEMON
541 } // OHOS
542