1 /* 2 * Copyright (c) 2021-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 #ifndef APP_DOMAIN_VERIFY_MOCK_PREFERENCES_H 17 #define APP_DOMAIN_VERIFY_MOCK_PREFERENCES_H 18 #include <gmock/gmock.h> 19 #include "preferences.h" 20 #include <string> 21 namespace OHOS { 22 namespace NativePreferences { 23 void MockPreferences(std::shared_ptr<Preferences> pre, int errCode = 0); 24 void MockPreferencesRet(int ret); 25 class MocPreferences : public Preferences { 26 public: 27 MocPreferences() = default; 28 ~MocPreferences() override = default; 29 MOCK_METHOD(std::string, GetString, (const std::string& key, const std::string& defValue), (override)); 30 MOCK_METHOD(int, PutString, (const std::string& key, const std::string& value), (override)); 31 MOCK_METHOD(int, RegisterObserver, (std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode), 32 (override)); 33 MOCK_METHOD(int, UnRegisterObserver, (std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode), 34 (override)); 35 Get(const std::string & key,const PreferencesValue & defValue)36 PreferencesValue Get(const std::string& key, const PreferencesValue& defValue) override 37 { 38 return PreferencesValue(); 39 } Put(const std::string & key,const PreferencesValue & value)40 int Put(const std::string& key, const PreferencesValue& value) override 41 { 42 return 0; 43 } 44 int GetInt(const std::string& key, const int& defValue = {}) override 45 { 46 return 0; 47 } 48 49 bool GetBool(const std::string& key, const bool& defValue = {}) override 50 { 51 return 0; 52 } 53 float GetFloat(const std::string& key, const float& defValue = {}) override 54 { 55 return 0; 56 } 57 double GetDouble(const std::string& key, const double& defValue = {}) override 58 { 59 return 0; 60 } 61 int64_t GetLong(const std::string& key, const int64_t& defValue = {}) override 62 { 63 return 0; 64 } GetAll()65 std::map<std::string, PreferencesValue> GetAll() override 66 { 67 return std::map<std::string, PreferencesValue>(); 68 } HasKey(const std::string & key)69 bool HasKey(const std::string& key) override 70 { 71 return 0; 72 } PutInt(const std::string & key,int value)73 int PutInt(const std::string& key, int value) override 74 { 75 return 0; 76 } 77 PutBool(const std::string & key,bool value)78 int PutBool(const std::string& key, bool value) override 79 { 80 return 0; 81 } PutLong(const std::string & key,int64_t value)82 int PutLong(const std::string& key, int64_t value) override 83 { 84 return 0; 85 } PutFloat(const std::string & key,float value)86 int PutFloat(const std::string& key, float value) override 87 { 88 return 0; 89 } PutDouble(const std::string & key,double value)90 int PutDouble(const std::string& key, double value) override 91 { 92 return 0; 93 } Delete(const std::string & key)94 int Delete(const std::string& key) override 95 { 96 return 0; 97 } Clear()98 int Clear() override 99 { 100 return 0; 101 } Flush()102 void Flush() override 103 { 104 } FlushSync()105 int FlushSync() override 106 { 107 return 0; 108 } 109 }; 110 } 111 } 112 #endif // APP_DOMAIN_VERIFY_MOCK_PREFERENCES_H 113