1 /* 2 * Copyright (c) 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 #ifndef BASE_INTERFACE_LIB_MOCK_H 16 #define BASE_INTERFACE_LIB_MOCK_H 17 18 #include <fcntl.h> 19 #include <gmock/gmock.h> 20 #include "meta_file.h" 21 22 namespace OHOS { 23 namespace FileManagement { 24 using namespace testing; 25 using namespace testing::ext; 26 using namespace std; 27 28 class BaseInterfaceLib { 29 public: 30 virtual ~BaseInterfaceLib() = default; 31 virtual string GetDentryfileByPath(uint32_t userId, const string &path, bool caseSense) = 0; 32 virtual string GetDentryfileName(const std::string &path, bool caseSense) = 0; 33 virtual uint32_t GetOverallBucket(uint32_t level) = 0; 34 virtual uint32_t GetBucketaddr(uint32_t level, uint32_t buckoffset) = 0; 35 virtual uint32_t GetBucketByLevel(uint32_t level) = 0; 36 virtual uint32_t RoomForFilename(const uint8_t bitmap[], size_t slots, uint32_t maxSlots) = 0; 37 virtual uint32_t FindNextZeroBit(const uint8_t addr[], uint32_t maxSlots, uint32_t start) = 0; 38 virtual uint32_t FindNextBit(const uint8_t addr[], uint32_t maxSlots, uint32_t start) = 0; 39 virtual int32_t DoLookup(MetaBase &base) = 0; 40 virtual int32_t DoCreate(const MetaBase &base) = 0; 41 virtual int32_t DoLookupAndRemove(MetaBase &metaBase) = 0; 42 public: 43 static inline shared_ptr<BaseInterfaceLib> baseInterfaceLib_ = nullptr; 44 }; 45 46 class InterfaceLibMock : public BaseInterfaceLib { 47 public: 48 MOCK_METHOD3(GetDentryfileByPath, string(uint32_t userId, const string &path, bool caseSense)); 49 MOCK_METHOD2(GetDentryfileName, string(const string &path, bool caseSense)); 50 MOCK_METHOD1(GetOverallBucket, uint32_t(uint32_t level)); 51 MOCK_METHOD2(GetBucketaddr, uint32_t(uint32_t level, uint32_t buckoffset)); 52 MOCK_METHOD1(GetBucketByLevel, uint32_t(uint32_t level)); 53 MOCK_METHOD3(RoomForFilename, uint32_t(const uint8_t bitmap[], size_t slots, uint32_t maxSlot)); 54 MOCK_METHOD3(FindNextZeroBit, uint32_t(const uint8_t addr[], uint32_t maxSlots, uint32_t start)); 55 MOCK_METHOD3(FindNextBit, uint32_t(const uint8_t addr[], uint32_t maxSlots, uint32_t start)); 56 MOCK_METHOD1(DoLookup, int32_t(MetaBase &base)); 57 MOCK_METHOD1(DoCreate, int32_t(const MetaBase &base)); 58 MOCK_METHOD1(DoLookupAndRemove, int32_t(MetaBase &metaBase)); 59 }; 60 61 enum ErrStatus { 62 E_FAIL = -1, 63 E_SUCCESS = 0, 64 E_EINVAL = 22, 65 DENTRY_PER_GROUP = 60, 66 MAX_BUCKET_LEVEL = 63 67 }; 68 } // FileManagement 69 } // OHOS 70 #endif // BASE_INTERFACE_LIB_MOCK_H