1cb7eb8c9Sopenharmony_ci/* 2cb7eb8c9Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3cb7eb8c9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb7eb8c9Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb7eb8c9Sopenharmony_ci * You may obtain a copy of the License at 6cb7eb8c9Sopenharmony_ci * 7cb7eb8c9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb7eb8c9Sopenharmony_ci * 9cb7eb8c9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb7eb8c9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb7eb8c9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb7eb8c9Sopenharmony_ci * See the License for the specific language governing permissions and 13cb7eb8c9Sopenharmony_ci * limitations under the License. 14cb7eb8c9Sopenharmony_ci */ 15cb7eb8c9Sopenharmony_ci 16cb7eb8c9Sopenharmony_ci#include <gmock/gmock.h> 17cb7eb8c9Sopenharmony_ci#include <gtest/gtest.h> 18cb7eb8c9Sopenharmony_ci#include "preferences_helper.h" 19cb7eb8c9Sopenharmony_ci 20cb7eb8c9Sopenharmony_cinamespace OHOS { 21cb7eb8c9Sopenharmony_cinamespace NativePreferences { 22cb7eb8c9Sopenharmony_ci#define TEST_PATH "/data/service/el2/123/hmdfs/cloudfile_manager/test_key/" 23cb7eb8c9Sopenharmony_ciclass PreferencesHelperMock : public Preferences { 24cb7eb8c9Sopenharmony_cipublic: 25cb7eb8c9Sopenharmony_ci MOCK_METHOD2(Get, PreferencesValue(const std::string &key, const PreferencesValue &defValue)); 26cb7eb8c9Sopenharmony_ci MOCK_METHOD2(Put, int(const std::string &key, const PreferencesValue &value)); 27cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetInt, int(const std::string &key, const int &defValue)); 28cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetString, std::string(const std::string &key, const std::string &defValue)); 29cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetBool, bool(const std::string &key, const bool &defValue)); 30cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetFloat, float(const std::string &key, const float &defValue)); 31cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetDouble, double(const std::string &key, const double &defValue)); 32cb7eb8c9Sopenharmony_ci MOCK_METHOD2(GetLong, int64_t(const std::string &key, const int64_t &defValue)); 33cb7eb8c9Sopenharmony_ci MOCK_METHOD0(GetAll, std::map<std::string, PreferencesValue>()); 34cb7eb8c9Sopenharmony_ci MOCK_METHOD1(HasKey, bool(const std::string &key)); 35cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutInt, int(const std::string &key, int value)); 36cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutString, int(const std::string &key, const std::string &value)); 37cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutBool, int(const std::string &key, bool value)); 38cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutLong, int(const std::string &key, int64_t value)); 39cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutFloat, int(const std::string &key, float value)); 40cb7eb8c9Sopenharmony_ci MOCK_METHOD2(PutDouble, int(const std::string &key, double value)); 41cb7eb8c9Sopenharmony_ci MOCK_METHOD1(Delete, int(const std::string &key)); 42cb7eb8c9Sopenharmony_ci MOCK_METHOD0(Clear, int()); 43cb7eb8c9Sopenharmony_ci MOCK_METHOD0(Flush, void()); 44cb7eb8c9Sopenharmony_ci MOCK_METHOD0(FlushSync, int()); 45cb7eb8c9Sopenharmony_ci MOCK_METHOD2(RegisterObserver, int(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode)); 46cb7eb8c9Sopenharmony_ci MOCK_METHOD2(UnRegisterObserver, int(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode)); 47cb7eb8c9Sopenharmony_ci}; 48cb7eb8c9Sopenharmony_ci 49cb7eb8c9Sopenharmony_cistd::string PreferencesHelper::GetRealPath(const std::string &path, int &errorCode) 50cb7eb8c9Sopenharmony_ci{ 51cb7eb8c9Sopenharmony_ci return ""; 52cb7eb8c9Sopenharmony_ci} 53cb7eb8c9Sopenharmony_ci 54cb7eb8c9Sopenharmony_cistd::shared_ptr<Preferences> PreferencesHelper::GetPreferences(const Options &options, int &errCode) 55cb7eb8c9Sopenharmony_ci{ 56cb7eb8c9Sopenharmony_ci if (options.filePath == "") { 57cb7eb8c9Sopenharmony_ci return nullptr; 58cb7eb8c9Sopenharmony_ci } 59cb7eb8c9Sopenharmony_ci 60cb7eb8c9Sopenharmony_ci if (options.filePath == TEST_PATH) { 61cb7eb8c9Sopenharmony_ci return nullptr; 62cb7eb8c9Sopenharmony_ci } 63cb7eb8c9Sopenharmony_ci 64cb7eb8c9Sopenharmony_ci std::shared_ptr<PreferencesHelperMock> pref = std::make_shared<PreferencesHelperMock>(); 65cb7eb8c9Sopenharmony_ci return pref; 66cb7eb8c9Sopenharmony_ci} 67cb7eb8c9Sopenharmony_ci 68cb7eb8c9Sopenharmony_ciint PreferencesHelper::DeletePreferences(const std::string &path) 69cb7eb8c9Sopenharmony_ci{ 70cb7eb8c9Sopenharmony_ci return 0; 71cb7eb8c9Sopenharmony_ci} 72cb7eb8c9Sopenharmony_ci 73cb7eb8c9Sopenharmony_ciint PreferencesHelper::RemovePreferencesFromCache(const std::string &path) 74cb7eb8c9Sopenharmony_ci{ 75cb7eb8c9Sopenharmony_ci return 0; 76cb7eb8c9Sopenharmony_ci} 77cb7eb8c9Sopenharmony_ci} // End of namespace NativePreferences 78cb7eb8c9Sopenharmony_ci} // End of namespace OHOS