• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 CLOUD_PREFERENCES_H
17 #define CLOUD_PREFERENCES_H
18 #include <gmock/gmock.h>
19 #include <string>
20 
21 namespace OHOS {
22 namespace NativePreferences {
23 class PreferencesInterface {
24 public:
25     virtual ~PreferencesInterface() = default;
26     virtual int GetInt(const std::string &key, const int &defValue = {}) = 0;
27     virtual std::string GetString(const std::string &key, const std::string &defValue = {}) = 0;
28     virtual bool GetBool(const std::string &key, const bool &defValue = {}) = 0;
29     virtual int64_t GetLong(const std::string &key, const int64_t &defValue = {}) = 0;
30     virtual int PutInt(const std::string &key, int value) = 0;
31     virtual int PutString(const std::string &key, const std::string &value) = 0;
32     virtual int PutBool(const std::string &key, bool value) = 0;
33     virtual int PutLong(const std::string &key, int64_t value) = 0;
34     virtual int Delete(const std::string &key) = 0;
35     virtual int Clear() = 0;
36     virtual int FlushSync() = 0;
37 };
38 
39 class Preferences : public PreferencesInterface {
40 public:
41     MOCK_METHOD2(GetInt, int(const std::string &key, const int &defValue));
42     MOCK_METHOD2(GetString, std::string(const std::string &key, const std::string &defValue));
43     MOCK_METHOD2(GetBool, bool(const std::string &key, const bool &defValue));
44     MOCK_METHOD2(GetLong, int64_t(const std::string &key, const int64_t &defValue));
45     MOCK_METHOD2(PutInt, int(const std::string &key, int value));
46     MOCK_METHOD2(PutString, int(const std::string &key, const std::string &value));
47     MOCK_METHOD2(PutBool, int(const std::string &key, bool value));
48     MOCK_METHOD2(PutLong, int(const std::string &key, int64_t value));
49     MOCK_METHOD1(Delete, int(const std::string &key));
50     MOCK_METHOD0(Clear, int());
51     MOCK_METHOD0(FlushSync, int());
52 };
53 } // namespace NativePreferences
54 } // namespace OHOS
55 #endif // CLOUD_PREFERENCES_H