1 /* 2 * Copyright (c) 2022 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 MOCK_PREFERENCES_H 17 #define MOCK_PREFERENCES_H 18 19 #include "preferences.h" 20 21 namespace OHOS { 22 namespace NativePreferences { 23 class MockPreferences : public Preferences { 24 public: 25 explicit MockPreferences(); 26 ~MockPreferences() override; 27 28 PreferencesValue Get(const std::string &key, const PreferencesValue &defValue) override; 29 30 int Put(const std::string &key, const PreferencesValue &value) override; 31 32 int GetInt(const std::string &key, const int &defValue = {}) override; 33 34 std::string GetString(const std::string &key, const std::string &defValue = {}) override; 35 36 bool GetBool(const std::string &key, const bool &defValue = {}) override; 37 38 float GetFloat(const std::string &key, const float &defValue = {}) override; 39 40 double GetDouble(const std::string &key, const double &defValue = {}) override; 41 42 int64_t GetLong(const std::string &key, const int64_t &defValue = {}) override; 43 44 std::map<std::string, PreferencesValue> GetAll() override; 45 46 bool HasKey(const std::string &key) override; 47 48 int PutInt(const std::string &key, int value) override; 49 50 int PutString(const std::string &key, const std::string &value) override; 51 52 int PutBool(const std::string &key, bool value) override; 53 54 int PutLong(const std::string &key, int64_t value) override; 55 56 int PutFloat(const std::string &key, float value) override; 57 58 int PutDouble(const std::string &key, double value) override; 59 60 int Delete(const std::string &key) override; 61 62 int Clear() override; 63 64 void Flush() override; 65 66 int FlushSync() override; 67 68 int RegisterObserver(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode) override; 69 70 int UnRegisterObserver(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode) override; 71 }; 72 } // End of namespace NativePreferences 73 } // End of namespace OHOS 74 #endif // End of #ifndef PREFERENCES_H 75