• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "directory_ex.h"
20 #include "meta_file.h"
21 #include "base_interface_lib_mock.h"
22 
23 namespace OHOS::FileManagement::CloudSync::Test {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 constexpr uint32_t TEST_USER_ID = 201;
28 constexpr uint64_t TEST_ISIZE = 1024;
29 const string TEST_PATH = "/data/service/el2/100/hmdfs/cache/account_cache/dentry_cache/cloud/";
30 
31 class DentryMetaFileTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp();
36     void TearDown();
37 public:
38     static inline shared_ptr<InterfaceLibMock> interfaceLibMock_ = nullptr;
39 };
40 
SetUpTestCase(void)41 void DentryMetaFileTest::SetUpTestCase(void)
42 {
43     GTEST_LOG_(INFO) << "SetUpTestCase";
44     interfaceLibMock_ = make_shared<InterfaceLibMock>();
45     InterfaceLibMock::baseInterfaceLib_ = interfaceLibMock_;
46 }
47 
TearDownTestCase(void)48 void DentryMetaFileTest::TearDownTestCase(void)
49 {
50     GTEST_LOG_(INFO) << "TearDownTestCase";
51     InterfaceLibMock::baseInterfaceLib_ = nullptr;
52     interfaceLibMock_ = nullptr;
53 }
54 
SetUp(void)55 void DentryMetaFileTest::SetUp(void)
56 {
57     GTEST_LOG_(INFO) << "SetUp";
58 }
59 
TearDown(void)60 void DentryMetaFileTest::TearDown(void)
61 {
62     GTEST_LOG_(INFO) << "TearDown";
63 }
64 
65 /**
66  * @tc.name: MetaFileHandleFileByFd001
67  * @tc.desc: Verify the MetaFile::HandleFileByFd function
68  * @tc.type: FUNC
69  * @tc.require: SR000HRKKA
70  */
71 HWTEST_F(DentryMetaFileTest, MetaFileHandleFileByFd001, TestSize.Level1)
72 {
73     MetaFile mFile(TEST_USER_ID, "/");
74     unsigned long endBlock = 0;
75     uint32_t level = 0;
76     int ret = mFile.HandleFileByFd(endBlock, level);
77     EXPECT_EQ(ret, EINVAL);
78 }
79 
80 /**
81  * @tc.name: MetaFileHandleFileByFd002
82  * @tc.desc: Verify the MetaFile::HandleFileByFd function
83  * @tc.type: FUNC
84  * @tc.require: SR000HRKKA
85  */
86 HWTEST_F(DentryMetaFileTest, MetaFileHandleFileByFd002, TestSize.Level1)
87 {
88     uint32_t userId = 100;
89     MetaFile mFile(userId, "/");
90     unsigned long endBlock = 0;
91     uint32_t level = 64;
92     int ret = mFile.HandleFileByFd(endBlock, level);
93     EXPECT_EQ(ret, EINVAL);
94 }
95 
96 /**
97  * @tc.name: MetaFileHandleFileByFd003
98  * @tc.desc: Verify the MetaFile::HandleFileByFd function
99  * @tc.type: FUNC
100  * @tc.require: SR000HRKKA
101  */
102 HWTEST_F(DentryMetaFileTest, MetaFileHandleFileByFd003, TestSize.Level1)
103 {
104     uint32_t userId = 100;
105     MetaFile mFile(userId, "/");
106     unsigned long endBlock = 0;
107     uint32_t level = 0;
108     int ret = mFile.HandleFileByFd(endBlock, level);
109     EXPECT_EQ(ret, EINVAL);
110 }
111 
112 /**
113  * @tc.name: MetaFileCreate001
114  * @tc.desc: Verify the MetaFile::DoCreate function
115  * @tc.type: FUNC
116  * @tc.require: SR000HRKKA
117  */
118 HWTEST_F(DentryMetaFileTest, MetaFileCreate001, TestSize.Level1)
119 {
120     uint32_t userId = 100;
121     std::string cacheDir =
122         "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
123     ForceRemoveDirectory(cacheDir);
124 
125     MetaFile mFile(userId, "/");
126     MetaBase mBase1("file1", "id1");
127     mBase1.size = TEST_ISIZE;
128     int ret = mFile.DoCreate(mBase1);
129     EXPECT_EQ(ret, EINVAL);
130     MetaBase mBase2("file2", "id2");
131     mBase2.size = TEST_ISIZE;
132     ret = mFile.DoCreate(mBase2);
133     EXPECT_EQ(ret, EINVAL);
134     MetaFile mFile2(userId, "/a/b");
135     MetaBase mBase3("file3", "id3");
136     ret = mFile2.DoCreate(mBase3);
137 }
138 
139 /**
140  * @tc.name: MetaFileCreate002
141  * @tc.desc: Verify the MetaFile::DoCreate function
142  * @tc.type: FUNC
143  * @tc.require: SR000HRKKA
144  */
145 HWTEST_F(DentryMetaFileTest, MetaFileCreate002, TestSize.Level1)
146 {
147     MetaFile mFile(TEST_USER_ID, "/");
148     MetaBase mBase1("file1", "id1");
149     int ret = mFile.DoCreate(mBase1);
150     EXPECT_EQ(ret, EINVAL);
151 }
152 
153 /**
154  * @tc.name: MetaFileLookup001
155  * @tc.desc: Verify the MetaFile::DoLookup function
156  * @tc.type: FUNC
157  * @tc.require: SR000HRKKA
158  */
159 HWTEST_F(DentryMetaFileTest, MetaFileLookup001, TestSize.Level1)
160 {
161     MetaFile mFile(TEST_USER_ID, "/");
162     MetaBase mBase1("file1");
163     int ret = mFile.DoLookup(mBase1);
164     EXPECT_EQ(ret, EINVAL);
165 }
166 
167 /**
168  * @tc.name: MetaFileLookup002
169  * @tc.desc: Verify the MetaFile::DoLookup002 function
170  * @tc.type: FUNC
171  * @tc.require: SR000HRKKA
172  */
173 HWTEST_F(DentryMetaFileTest, MetaFileLookup, TestSize.Level1)
174 {
175     uint32_t userId = 100;
176     MetaFile mFile(userId, "/");
177     MetaBase mBase1("file1");
178     int ret = mFile.DoLookup(mBase1);
179     EXPECT_EQ(ret, EINVAL);
180     EXPECT_EQ(mBase1.size, 0);
181 }
182 
183 /**
184  * @tc.name: MetaFileUpdate001
185  * @tc.desc: Verify the MetaFile::DoUpdate function
186  * @tc.type: FUNC
187  * @tc.require: SR000HRKKC
188  */
189 HWTEST_F(DentryMetaFileTest, MetaFileUpdate001, TestSize.Level1)
190 {
191     MetaFile mFile(TEST_USER_ID, "/");
192     MetaBase mBase1("file1", "id11");
193     int ret = mFile.DoUpdate(mBase1);
194     EXPECT_EQ(ret, EINVAL);
195 }
196 
197 /**
198  * @tc.name: MetaFileUpdate
199  * @tc.desc: Verify the MetaFile::DoUpdate function
200  * @tc.type: FUNC
201  * @tc.require: SR000HRKKC
202  */
203 HWTEST_F(DentryMetaFileTest, MetaFileUpdate, TestSize.Level1)
204 {
205     uint32_t userId = 100;
206     MetaFile mFile(userId, "/");
207     MetaBase mBase1("file1", "id11");
208     mBase1.size = 0;
209     int ret = mFile.DoUpdate(mBase1);
210     EXPECT_EQ(ret, EINVAL);
211     MetaBase mBase2("file1");
212     ret = mFile.DoLookup(mBase2);
213     EXPECT_EQ(ret, EINVAL);
214     EXPECT_EQ(mBase2.size, 0);
215 }
216 
217 /**
218  * @tc.name: MetaFileRename
219  * @tc.desc: Verify the MetaFile::DoRename function
220  * @tc.type: FUNC
221  * @tc.require: SR000HRKKC
222  */
223 HWTEST_F(DentryMetaFileTest, MetaFileRename, TestSize.Level1)
224 {
225     uint32_t userId = 100;
226     MetaFile mFile(userId, "/");
227     MetaBase mBase1("file2");
228     int ret = mFile.DoRename(mBase1, "file4");
229     EXPECT_EQ(ret, EINVAL);
230     MetaBase mBase2("file4");
231     ret = mFile.DoLookup(mBase2);
232     EXPECT_EQ(ret, EINVAL);
233     EXPECT_EQ(mBase2.size, 0);
234 }
235 
236 /**
237  * @tc.name: MetaFileRemove001
238  * @tc.desc: Verify the MetaFile::DoRemove function
239  * @tc.type: FUNC
240  * @tc.require: SR000HRKJB
241  */
242 HWTEST_F(DentryMetaFileTest, MetaFileRemove001, TestSize.Level1)
243 {
244     MetaFile mFile(TEST_USER_ID, "/");
245     MetaBase mBase1("file1");
246     int ret = mFile.DoRemove(mBase1);
247     EXPECT_EQ(ret, EINVAL);
248 }
249 
250 /**
251  * @tc.name: MetaFileRemove002
252  * @tc.desc: Verify the MetaFile::DoRemove function
253  * @tc.type: FUNC
254  * @tc.require: SR000HRKJB
255  */
256 HWTEST_F(DentryMetaFileTest, MetaFileRemove002, TestSize.Level1)
257 {
258     uint32_t userId = 100;
259     MetaFile mFile(userId, "/");
260     MetaBase mBase1("file1");
261     int ret = mFile.DoRemove(mBase1);
262     EXPECT_EQ(ret, EINVAL);
263     MetaBase mBase2("file1");
264     ret = mFile.DoLookup(mBase2);
265     EXPECT_EQ(ret, EINVAL);
266 }
267 
268 /**
269  * @tc.name: LoadChildren001
270  * @tc.desc: Verify the LoadChildren
271  * @tc.type: FUNC
272  * @tc.require: issueI7SP3A
273  */
274 HWTEST_F(DentryMetaFileTest, LoadChildren001, TestSize.Level1)
275 {
276     GTEST_LOG_(INFO) << "LoadChildren001 Start";
277     try {
278         uint32_t userId = 100;
279         MetaFile mFile(userId, "/");
280         std::vector<MetaBase> bases;
281         int ret = mFile.LoadChildren(bases);
282         EXPECT_EQ(ret, EINVAL);
283     } catch (...) {
284         EXPECT_FALSE(false);
285         GTEST_LOG_(INFO) << "LoadChildren001 ERROR";
286     }
287     GTEST_LOG_(INFO) << "LoadChildren001 End";
288 }
289 
290 /**
291  * @tc.name: LoadChildren002
292  * @tc.desc: Verify the LoadChildren
293  * @tc.type: FUNC
294  * @tc.require: issueI7SP3A
295  */
296 HWTEST_F(DentryMetaFileTest, LoadChildren002, TestSize.Level1)
297 {
298     GTEST_LOG_(INFO) << "LoadChildren002 Start";
299     try {
300         MetaFile mFile(TEST_USER_ID, "/");
301         std::vector<MetaBase> bases;
302         int ret = mFile.LoadChildren(bases);
303         EXPECT_EQ(ret, EINVAL);
304     } catch (...) {
305         EXPECT_FALSE(false);
306         GTEST_LOG_(INFO) << "LoadChildren002 ERROR";
307     }
308     GTEST_LOG_(INFO) << "LoadChildren002 End";
309 }
310 
311 /**
312  * @tc.name: MetaFileMgr001
313  * @tc.desc: Verify the MetaFileMgr
314  * @tc.type: FUNC
315  * @tc.require: SR000HRKJB
316  */
317 HWTEST_F(DentryMetaFileTest, MetaFileMgr001, TestSize.Level1)
318 {
319     GTEST_LOG_(INFO) << "MetaFileMgr001 Start";
320     try {
321         uint32_t userId = 100;
322         auto m = MetaFileMgr::GetInstance().GetMetaFile(userId, "/o/p/q/r/s/t");
323         MetaBase mBase1("file1", "file1");
324         EXPECT_EQ(m->DoCreate(mBase1), EINVAL);
325         m = nullptr;
326         MetaFileMgr::GetInstance().ClearAll();
327     } catch (...) {
328         EXPECT_FALSE(false);
329         GTEST_LOG_(INFO) << " MetaFileMgr001 ERROR";
330     }
331     GTEST_LOG_(INFO) << "MetaFileMgr001 End";
332 }
333 
334 /**
335  * @tc.name: MetaFileMgr002
336  * @tc.desc: Verify the MetaFileMgr
337  * @tc.type: FUNC
338  * @tc.require: issueI7SP3A
339  */
340 HWTEST_F(DentryMetaFileTest, MetaFileMgr002, TestSize.Level1)
341 {
342     GTEST_LOG_(INFO) << "MetaFileMgr002 Start";
343     try {
344         uint32_t userId = 100;
345         auto m = MetaFileMgr::GetInstance().GetMetaFile(userId, "/o/p/q/r/s/t");
346         MetaBase mBase1("testLongLongfileName", "testLongLongfileName");
347         EXPECT_EQ(m->DoCreate(mBase1), EINVAL);
348         m = nullptr;
349         MetaFileMgr::GetInstance().ClearAll();
350     } catch (...) {
351         EXPECT_FALSE(false);
352         GTEST_LOG_(INFO) << " MetaFileMgr002 ERROR";
353     }
354     GTEST_LOG_(INFO) << "MetaFileMgr002 End";
355 }
356 
357 /**
358  * @tc.name:RecordIdToCloudId001
359  * @tc.desc: Verify the RecordIdToCloudId
360  * @tc.type: FUNC
361  * @tc.require: issueI7SP3A
362  */
363 HWTEST_F(DentryMetaFileTest, RecordIdToCloudId001, TestSize.Level1)
364 {
365     GTEST_LOG_(INFO) << "RecordIdToCloudId001 Start";
366     try {
367         std::string hexStr = "";
368         string ret = MetaFileMgr::GetInstance().RecordIdToCloudId(hexStr);
369         EXPECT_EQ(ret, "");
370         MetaFileMgr::GetInstance().ClearAll();
371     } catch (...) {
372         EXPECT_FALSE(false);
373         GTEST_LOG_(INFO) << "RecordIdToCloudId001 ERROR";
374     }
375     GTEST_LOG_(INFO) << "RecordIdToCloudId001 End";
376 }
377 
378 /**
379  * @tc.name:RecordIdToCloudId002
380  * @tc.desc: Verify the RecordIdToCloudId
381  * @tc.type: FUNC
382  * @tc.require: issueI7SP3A
383  */
384 HWTEST_F(DentryMetaFileTest, RecordIdToCloudId002, TestSize.Level1)
385 {
386     GTEST_LOG_(INFO) << "RecordIdToCloudId002 Start";
387     try {
388         std::string hexStr = "test";
389         string ret = MetaFileMgr::GetInstance().RecordIdToCloudId(hexStr);
390         EXPECT_EQ(ret, "");
391         MetaFileMgr::GetInstance().ClearAll();
392     } catch (...) {
393         EXPECT_FALSE(false);
394         GTEST_LOG_(INFO) << "RecordIdToCloudId002 ERROR";
395     }
396     GTEST_LOG_(INFO) << "RecordIdToCloudId002 End";
397 }
398 
399 /**
400  * @tc.name: GetParentDir001
401  * @tc.desc: Verify the GetParentDir
402  * @tc.type: FUNC
403  * @tc.require: issueI7SP3A
404  */
405 HWTEST_F(DentryMetaFileTest, GetParentDir001, TestSize.Level1)
406 {
407     GTEST_LOG_(INFO) << "GetParentDir001 Start";
408     try {
409         string str = MetaFile::GetParentDir("");
410         EXPECT_EQ(str, "");
411         str = MetaFile::GetParentDir("/");
412         EXPECT_EQ(str, "");
413         str = MetaFile::GetParentDir("abc");
414         EXPECT_EQ(str, "/");
415         str = MetaFile::GetParentDir("/abc");
416         EXPECT_EQ(str, "/");
417         str = MetaFile::GetParentDir("/abc/def");
418         EXPECT_EQ(str, "/abc");
419     } catch (...) {
420         EXPECT_FALSE(false);
421         GTEST_LOG_(INFO) << " GetParentDir001 ERROR";
422     }
423     GTEST_LOG_(INFO) << "GetParentDir001 End";
424 }
425 
426 /**
427  * @tc.name: GetFileName001
428  * @tc.desc: Verify the GetFileName
429  * @tc.type: FUNC
430  * @tc.require: issueI7SP3A
431  */
432 HWTEST_F(DentryMetaFileTest, GetFileName001, TestSize.Level1)
433 {
434     GTEST_LOG_(INFO) << "GetFileName001 Start";
435     try {
436         string str = MetaFile::GetFileName("");
437         EXPECT_EQ(str, "");
438         str = MetaFile::GetFileName("/");
439         EXPECT_EQ(str, "");
440         str = MetaFile::GetFileName("abc");
441         EXPECT_EQ(str, "");
442         str = MetaFile::GetFileName("/abc/def");
443         EXPECT_EQ(str, "def");
444     } catch (...) {
445         EXPECT_FALSE(false);
446         GTEST_LOG_(INFO) << " GetFileName001 ERROR";
447     }
448     GTEST_LOG_(INFO) << "GetFileName001 End";
449 }
450 
451 HWTEST_F(DentryMetaFileTest, HandleFileByFd_001, TestSize.Level1)
452 {
453     GTEST_LOG_(INFO) << "HandleFileByFd_001 Start";
454     try {
455         uint32_t userId = 100;
456         MetaFile mFile(userId, "/");
457         unsigned long endBlock = 0;
458         uint32_t level = MAX_BUCKET_LEVEL;
459         int ret = mFile.HandleFileByFd(endBlock, level);
460         EXPECT_EQ(ret, EINVAL);
461     } catch (...) {
462         EXPECT_FALSE(false);
463         GTEST_LOG_(INFO) << " HandleFileByFd_001 ERROR";
464     }
465     GTEST_LOG_(INFO) << "HandleFileByFd_001 End";
466 }
467 
468 HWTEST_F(DentryMetaFileTest, HandleFileByFd_002, TestSize.Level1)
469 {
470     GTEST_LOG_(INFO) << "HandleFileByFd_002 Start";
471     try {
472         uint32_t userId = 100;
473         MetaFile mFile(userId, "/");
474         unsigned long endBlock = DENTRY_PER_GROUP;
475         uint32_t level = MAX_BUCKET_LEVEL;
476         int ret = mFile.HandleFileByFd(endBlock, level);
477         EXPECT_EQ(ret, EINVAL);
478     } catch (...) {
479         EXPECT_FALSE(false);
480         GTEST_LOG_(INFO) << " HandleFileByFd_002 ERROR";
481     }
482     GTEST_LOG_(INFO) << "HandleFileByFd_002 End";
483 }
484 
485 HWTEST_F(DentryMetaFileTest, HandleFileByFd_003, TestSize.Level1)
486 {
487     GTEST_LOG_(INFO) << "HandleFileByFd_003 Start";
488     try {
489         uint32_t userId = 100;
490         MetaFile mFile(userId, "/");
491         unsigned long endBlock = -100;
492         uint32_t level = MAX_BUCKET_LEVEL;
493         int ret = mFile.HandleFileByFd(endBlock, level);
494         EXPECT_EQ(ret, EINVAL);
495     } catch (...) {
496         EXPECT_FALSE(false);
497         GTEST_LOG_(INFO) << " HandleFileByFd_003 ERROR";
498     }
499     GTEST_LOG_(INFO) << "HandleFileByFd_003 End";
500 }
501 
502 HWTEST_F(DentryMetaFileTest, GetDentryfileName_001, TestSize.Level1)
503 {
504     GTEST_LOG_(INFO) << "GetDentryfileName_001 Start";
505     try {
506         uint32_t userId = 100;
507         EXPECT_CALL(*interfaceLibMock_, GetDentryfileName(_, _)).WillOnce(Return("/"));
508         MetaFile mFile(userId, "/");
509 
510         string path = "/test/";
511         bool caseSense = true;
512         EXPECT_TRUE(true);
513         EXPECT_EQ(interfaceLibMock_->GetDentryfileName(path, caseSense), "/");
514     } catch (...) {
515         EXPECT_FALSE(false);
516         GTEST_LOG_(INFO) << " GetDentryfileName_001 ERROR";
517     }
518     GTEST_LOG_(INFO) << "GetDentryfileName_001 End";
519 }
520 
521 HWTEST_F(DentryMetaFileTest, GetOverallBucket_001, TestSize.Level1)
522 {
523     GTEST_LOG_(INFO) << "GetOverallBucket_001 Start";
524     try {
525         uint32_t userId = 100;
526         MetaFile mFile(userId, "/");
527         unsigned long endBlock = -100;
528         uint32_t level = MAX_BUCKET_LEVEL;
529 
530         EXPECT_CALL(*interfaceLibMock_, GetOverallBucket(_)).WillOnce(Return(E_SUCCESS));
531         int ret = mFile.HandleFileByFd(endBlock, level);
532         EXPECT_EQ(ret, EINVAL);
533         EXPECT_EQ(interfaceLibMock_->GetOverallBucket(MAX_BUCKET_LEVEL), E_SUCCESS);
534     } catch (...) {
535         EXPECT_FALSE(false);
536         GTEST_LOG_(INFO) << " GetOverallBucket_001 ERROR";
537     }
538     GTEST_LOG_(INFO) << "GetOverallBucket_001 End";
539 }
540 
541 HWTEST_F(DentryMetaFileTest, GetBucketaddr_001, TestSize.Level1)
542 {
543     GTEST_LOG_(INFO) << "GetBucketaddr_001 Start";
544     try {
545         EXPECT_CALL(*interfaceLibMock_, GetBucketaddr(_, _)).WillOnce(Return(E_SUCCESS));
546         uint32_t userId = 100;
547         std::string cacheDir =
548             "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
549         ForceRemoveDirectory(cacheDir);
550 
551         MetaFile mFile(userId, "/");
552         MetaBase mBase1("file1", "id1");
553         mBase1.size = TEST_ISIZE;
554         int ret = mFile.DoCreate(mBase1);
555         EXPECT_EQ(ret, EINVAL);
556         EXPECT_EQ(interfaceLibMock_->GetBucketaddr(MAX_BUCKET_LEVEL, MAX_BUCKET_LEVEL), E_SUCCESS);
557     } catch (...) {
558         EXPECT_FALSE(false);
559         GTEST_LOG_(INFO) << " GetBucketaddr_001 ERROR";
560     }
561     GTEST_LOG_(INFO) << "GetBucketaddr_001 End";
562 }
563 
564 HWTEST_F(DentryMetaFileTest, GetBucketaddr_002, TestSize.Level1)
565 {
566     GTEST_LOG_(INFO) << "GetBucketaddr_002 Start";
567     try {
568         EXPECT_CALL(*interfaceLibMock_, GetBucketaddr(Eq(E_SUCCESS), _)).WillOnce(Return(E_FAIL));
569         uint32_t userId = 100;
570         std::string cacheDir =
571             "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
572         ForceRemoveDirectory(cacheDir);
573 
574         MetaFile mFile(userId, "/");
575         MetaBase mBase1("file1", "id1");
576         mBase1.size = TEST_ISIZE;
577         int ret = mFile.DoCreate(mBase1);
578         EXPECT_EQ(ret, EINVAL);
579         EXPECT_EQ(interfaceLibMock_->GetBucketaddr(E_SUCCESS, MAX_BUCKET_LEVEL), E_FAIL);
580     } catch (...) {
581         EXPECT_FALSE(false);
582         GTEST_LOG_(INFO) << " GetBucketaddr_002 ERROR";
583     }
584     GTEST_LOG_(INFO) << "GetBucketaddr_002 End";
585 }
586 
587 HWTEST_F(DentryMetaFileTest, GetBucketByLevel_001, TestSize.Level1)
588 {
589     GTEST_LOG_(INFO) << "GetBucketByLevel_001 Start";
590     try {
591         EXPECT_CALL(*interfaceLibMock_, GetBucketByLevel(_)).WillOnce(Return(E_SUCCESS));
592         uint32_t userId = 100;
593         std::string cacheDir =
594             "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
595         ForceRemoveDirectory(cacheDir);
596 
597         MetaFile mFile(userId, "/");
598         MetaBase mBase1("file1", "id1");
599         mBase1.size = TEST_ISIZE;
600         int ret = mFile.DoCreate(mBase1);
601         EXPECT_EQ(ret, EINVAL);
602         EXPECT_EQ(interfaceLibMock_->GetBucketByLevel(E_SUCCESS), E_SUCCESS);
603     } catch (...) {
604         EXPECT_FALSE(false);
605         GTEST_LOG_(INFO) << " GetBucketByLevel_001 ERROR";
606     }
607     GTEST_LOG_(INFO) << "GetBucketByLevel_001 End";
608 }
609 
610 HWTEST_F(DentryMetaFileTest, RoomForFilename_001, TestSize.Level1)
611 {
612     GTEST_LOG_(INFO) << "RoomForFilename_001 Start";
613     try {
614         EXPECT_CALL(*interfaceLibMock_, FindNextZeroBit(_, _, _)).WillOnce(Return(DENTRY_PER_GROUP));
615         uint32_t userId = 100;
616         std::string cacheDir =
617             "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
618         ForceRemoveDirectory(cacheDir);
619 
620         MetaFile mFile(userId, "/");
621         MetaBase mBase1("file1", "id1");
622         mBase1.size = TEST_ISIZE;
623         int ret = mFile.DoCreate(mBase1);
624         uint8_t addr[] = {0};
625         uint32_t maxSlots = DENTRY_PER_GROUP;
626         uint32_t start = DENTRY_PER_GROUP;
627         EXPECT_EQ(interfaceLibMock_->FindNextZeroBit(addr, maxSlots, start), DENTRY_PER_GROUP);
628         EXPECT_EQ(ret, EINVAL);
629     } catch (...) {
630         EXPECT_FALSE(false);
631         GTEST_LOG_(INFO) << " RoomForFilename_001 ERROR";
632     }
633     GTEST_LOG_(INFO) << "RoomForFilename_001 End";
634 }
635 
636 HWTEST_F(DentryMetaFileTest, RoomForFilename_002, TestSize.Level1)
637 {
638     GTEST_LOG_(INFO) << "RoomForFilename_002 Start";
639     try {
640         EXPECT_CALL(*interfaceLibMock_, FindNextZeroBit(_, _, _)).WillOnce(Return(DENTRY_PER_GROUP));
641         EXPECT_CALL(*interfaceLibMock_, FindNextBit(_, _, _)).WillOnce(Return(MAX_BUCKET_LEVEL));
642         uint32_t userId = 100;
643         std::string cacheDir =
644             "/data/service/el2/" + std::to_string(userId) + "/hmdfs/cache/cloud_cache/dentry_cache/cloud/";
645         ForceRemoveDirectory(cacheDir);
646 
647         MetaFile mFile(userId, "/");
648         MetaBase mBase1("file1", "id1");
649         mBase1.size = TEST_ISIZE;
650         int ret = mFile.DoCreate(mBase1);
651         uint8_t addr[] = {0};
652         uint32_t maxSlots = DENTRY_PER_GROUP;
653         uint32_t start = DENTRY_PER_GROUP;
654         EXPECT_EQ(ret, EINVAL);
655         EXPECT_EQ(interfaceLibMock_->FindNextZeroBit(addr, maxSlots, start), DENTRY_PER_GROUP);
656         EXPECT_EQ(interfaceLibMock_->FindNextBit(addr, maxSlots, start), MAX_BUCKET_LEVEL);
657     } catch (...) {
658         EXPECT_FALSE(false);
659         GTEST_LOG_(INFO) << " RoomForFilename_002 ERROR";
660     }
661     GTEST_LOG_(INFO) << "RoomForFilename_002 End";
662 }
663 } // namespace OHOS::FileManagement::CloudSync::Test