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 16 #ifndef OHOS_DISTRIBUTED_DATA_STORE_UTIL_MOCK_H 17 #define OHOS_DISTRIBUTED_DATA_STORE_UTIL_MOCK_H 18 19 #include <gmock/gmock.h> 20 21 #include "store_types.h" 22 #include "store_util.h" 23 24 namespace OHOS::DistributedKv { 25 class BStoreUtil { 26 public: 27 virtual bool IsFileExist(const std::string &) = 0; 28 virtual bool Remove(const std::string &) = 0; 29 virtual Status ConvertStatus(StoreUtil::DBStatus) = 0; 30 virtual bool InitPath(const std::string) = 0; 31 virtual StoreUtil::DBSecurity GetDBSecurity(int32_t) = 0; 32 virtual StoreUtil::DBIndexType GetDBIndexType(IndexType) = 0; 33 virtual std::vector<std::string> GetSubPath(const std::string &) = 0; 34 virtual std::vector<StoreUtil::FileInfo> GetFiles(const std::string &) = 0; 35 virtual bool Rename(const std::string &, const std::string &) = 0; 36 virtual uint32_t Anonymous(const void *) = 0; 37 virtual bool RemoveRWXForOthers(const std::string &) = 0; 38 virtual std::string Anonymous(const std::string &) = 0; 39 virtual bool CreateFile(const std::string &) = 0; 40 BStoreUtil() = default; 41 virtual ~BStoreUtil() = default; 42 43 public: 44 static inline std::shared_ptr<BStoreUtil> storeUtil = nullptr; 45 }; 46 47 class StoreUtilMock : public BStoreUtil { 48 public: 49 MOCK_METHOD(bool, IsFileExist, (const std::string &)); 50 MOCK_METHOD(bool, Remove, (const std::string &)); 51 MOCK_METHOD(Status, ConvertStatus, (StoreUtil::DBStatus)); 52 MOCK_METHOD(StoreUtil::DBSecurity, GetDBSecurity, (int32_t)); 53 MOCK_METHOD(bool, InitPath, (const std::string)); 54 MOCK_METHOD(StoreUtil::DBIndexType, GetDBIndexType, (IndexType)); 55 MOCK_METHOD(std::vector<std::string>, GetSubPath, (const std::string &)); 56 MOCK_METHOD(std::vector<StoreUtil::FileInfo>, GetFiles, (const std::string &)); 57 MOCK_METHOD(bool, Rename, (const std::string &, const std::string &)); 58 MOCK_METHOD(uint32_t, Anonymous, (const void *)); 59 MOCK_METHOD(std::string, Anonymous, (const std::string &)); 60 MOCK_METHOD(bool, RemoveRWXForOthers, (const std::string &)); 61 MOCK_METHOD(bool, CreateFile, (const std::string &)); 62 }; 63 } // namespace OHOS::DistributedKv 64 #endif // OHOS_DISTRIBUTED_DATA_STORE_UTIL_MOCK_H