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 #include <gtest/gtest.h> 17 #include "preferences_value.h" 18 19 namespace OHOS { 20 namespace NativePreferences { PreferencesValue(PreferencesValue && preferencesValue)21PreferencesValue::PreferencesValue(PreferencesValue &&preferencesValue) noexcept 22 { 23 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 24 if (this == &preferencesValue) { 25 return; 26 } 27 value_ = std::move(preferencesValue.value_); 28 } 29 PreferencesValue(const PreferencesValue & preferencesValue)30PreferencesValue::PreferencesValue(const PreferencesValue &preferencesValue) 31 { 32 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 33 if (this == &preferencesValue) { 34 return; 35 } 36 value_ = preferencesValue.value_; 37 } 38 PreferencesValue(int64_t value)39PreferencesValue::PreferencesValue(int64_t value) 40 { 41 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 42 value_ = value; 43 } 44 PreferencesValue(int value)45PreferencesValue::PreferencesValue(int value) 46 { 47 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 48 value_ = value; 49 } 50 PreferencesValue(double value)51PreferencesValue::PreferencesValue(double value) 52 { 53 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 54 value_ = value; 55 } 56 PreferencesValue(float value)57PreferencesValue::PreferencesValue(float value) 58 { 59 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 60 value_ = value; 61 } 62 PreferencesValue(const char * value)63PreferencesValue::PreferencesValue(const char *value) 64 { 65 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 66 PreferencesValue((std::string)value); 67 } 68 PreferencesValue(bool value)69PreferencesValue::PreferencesValue(bool value) 70 { 71 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 72 value_ = value; 73 } 74 PreferencesValue(std::vector<double> value)75PreferencesValue::PreferencesValue(std::vector<double> value) 76 { 77 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 78 value_ = value; 79 } 80 PreferencesValue(std::string value)81PreferencesValue::PreferencesValue(std::string value) 82 { 83 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 84 value_ = value; 85 } 86 PreferencesValue(std::vector<bool> value)87PreferencesValue::PreferencesValue(std::vector<bool> value) 88 { 89 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 90 value_ = value; 91 } 92 93 PreferencesValue(std::vector<std::string> value)94PreferencesValue::PreferencesValue(std::vector<std::string> value) 95 { 96 GTEST_LOG_(INFO) << "MOCK PreferencesValue PreferencesValue"; 97 value_ = value; 98 } 99 operator =(const PreferencesValue & preferencesValue)100PreferencesValue &PreferencesValue::operator=(const PreferencesValue &preferencesValue) 101 { 102 GTEST_LOG_(INFO) << "MOCK PreferencesValue operator="; 103 if (this == &preferencesValue) { 104 return *this; 105 } 106 value_ = preferencesValue.value_; 107 return *this; 108 } 109 operator =(PreferencesValue && preferencesValue)110PreferencesValue &PreferencesValue::operator=(PreferencesValue &&preferencesValue) noexcept 111 { 112 GTEST_LOG_(INFO) << "MOCK PreferencesValue operator="; 113 if (this == &preferencesValue) { 114 return *this; 115 } 116 value_ = std::move(preferencesValue.value_); 117 return *this; 118 } 119 IsInt() const120bool PreferencesValue::IsInt() const 121 { 122 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsInt"; 123 return std::holds_alternative<int>(value_); 124 } 125 IsLong() const126bool PreferencesValue::IsLong() const 127 { 128 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsLong"; 129 return std::holds_alternative<int64_t>(value_); 130 } 131 IsDouble() const132bool PreferencesValue::IsDouble() const 133 { 134 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsDouble"; 135 return std::holds_alternative<double>(value_); 136 } 137 IsFloat() const138bool PreferencesValue::IsFloat() const 139 { 140 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsFloat"; 141 return std::holds_alternative<float>(value_); 142 } 143 IsString() const144bool PreferencesValue::IsString() const 145 { 146 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsString"; 147 return std::holds_alternative<std::string>(value_); 148 } 149 IsBool() const150bool PreferencesValue::IsBool() const 151 { 152 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsBool"; 153 return std::holds_alternative<bool>(value_); 154 } 155 IsDoubleArray() const156bool PreferencesValue::IsDoubleArray() const 157 { 158 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsDoubleArray"; 159 return std::holds_alternative<std::vector<double>>(value_); 160 } 161 IsBoolArray() const162bool PreferencesValue::IsBoolArray() const 163 { 164 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsBoolArray"; 165 return std::holds_alternative<std::vector<bool>>(value_); 166 } 167 IsStringArray() const168bool PreferencesValue::IsStringArray() const 169 { 170 GTEST_LOG_(INFO) << "MOCK PreferencesValue IsStringArray"; 171 return std::holds_alternative<std::vector<std::string>>(value_); 172 } 173 operator int() const174PreferencesValue::operator int() const 175 { 176 GTEST_LOG_(INFO) << "MOCK PreferencesValue int"; 177 return std::get<int>(value_); 178 } 179 operator int64_t() const180PreferencesValue::operator int64_t() const 181 { 182 GTEST_LOG_(INFO) << "MOCK PreferencesValue int64_t"; 183 return std::get<int64_t>(value_); 184 } 185 operator double() const186PreferencesValue::operator double() const 187 { 188 GTEST_LOG_(INFO) << "MOCK PreferencesValue double"; 189 return std::get<double>(value_); 190 } 191 operator float() const192PreferencesValue::operator float() const 193 { 194 GTEST_LOG_(INFO) << "MOCK PreferencesValue float"; 195 return std::get<float>(value_); 196 } 197 operator std::string() const198PreferencesValue::operator std::string() const 199 { 200 GTEST_LOG_(INFO) << "MOCK PreferencesValue string"; 201 return std::get<std::string>(value_); 202 } 203 operator bool() const204PreferencesValue::operator bool() const 205 { 206 GTEST_LOG_(INFO) << "MOCK PreferencesValue bool"; 207 return std::get<bool>(value_); 208 } 209 operator std::vector<double>() const210PreferencesValue::operator std::vector<double>() const 211 { 212 GTEST_LOG_(INFO) << "MOCK PreferencesValue std::vector<double>"; 213 return std::get<std::vector<double>>(value_); 214 } 215 operator std::vector<std::string>() const216PreferencesValue::operator std::vector<std::string>() const 217 { 218 GTEST_LOG_(INFO) << "MOCK PreferencesValue std::vector<std::string>"; 219 return std::get<std::vector<std::string>>(value_); 220 } 221 operator std::vector<bool>() const222PreferencesValue::operator std::vector<bool>() const 223 { 224 GTEST_LOG_(INFO) << "MOCK PreferencesValue std::vector<bool>"; 225 return std::get<std::vector<bool>>(value_); 226 } 227 operator ==(const PreferencesValue & value)228bool PreferencesValue::operator==(const PreferencesValue &value) 229 { 230 GTEST_LOG_(INFO) << "MOCK PreferencesValue operator=="; 231 return (this->value_ == value.value_); 232 } 233 } // End of namespace NativePreferences 234 } // End of namespace OHOS 235