1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <cstdint> 17 #include <functional> 18 #include <string> 19 20 namespace test { 21 namespace mock { 22 namespace device_iot_config { 23 24 // Shared state between mocked functions and tests 25 // Name: device_iot_config_get_int 26 // Params: const std::string& section, const std::string& key, int& value 27 // Return: bool 28 struct device_iot_config_get_int { 29 bool return_value{false}; 30 std::function<bool(const std::string& section, const std::string& key, 31 int& value)> 32 body{[this](const std::string& /* section */, 33 const std::string& /* key */, 34 int& /* value */) { return return_value; }}; operatordevice_iot_config_get_int35 bool operator()(const std::string& section, const std::string& key, 36 int& value) { 37 return body(section, key, value); 38 }; 39 }; 40 extern struct device_iot_config_get_int device_iot_config_get_int; 41 42 // Name: device_iot_config_set_int 43 // Params: const std::string& section, const std::string& key, int& value 44 // Return: bool 45 struct device_iot_config_set_int { 46 bool return_value{false}; 47 std::function<bool(const std::string& section, const std::string& key, 48 int value)> 49 body{[this](const std::string& /* section */, 50 const std::string& /* key */, 51 int /* value */) { return return_value; }}; operatordevice_iot_config_set_int52 bool operator()(const std::string& section, const std::string& key, 53 int value) { 54 return body(section, key, value); 55 }; 56 }; 57 extern struct device_iot_config_set_int device_iot_config_set_int; 58 59 // Name: device_iot_config_int_add_one 60 // Params: const std::string& section, const std::string& key 61 // Return: bool 62 struct device_iot_config_int_add_one { 63 bool return_value{false}; 64 std::function<bool(const std::string& section, const std::string& key)> body{ 65 [this](const std::string& /* section */, const std::string& /* key */) { 66 return return_value; 67 }}; operatordevice_iot_config_int_add_one68 bool operator()(const std::string& section, const std::string& key) { 69 return body(section, key); 70 }; 71 }; 72 extern struct device_iot_config_int_add_one device_iot_config_int_add_one; 73 74 // Name: device_iot_config_get_hex 75 // Params: const std::string& section, const std::string& key, int& value 76 // Return: bool 77 struct device_iot_config_get_hex { 78 bool return_value{false}; 79 std::function<bool(const std::string& section, const std::string& key, 80 int& value)> 81 body{[this](const std::string& /* section */, 82 const std::string& /* key */, 83 int& /* value */) { return return_value; }}; operatordevice_iot_config_get_hex84 bool operator()(const std::string& section, const std::string& key, 85 int& value) { 86 return body(section, key, value); 87 }; 88 }; 89 extern struct device_iot_config_get_hex device_iot_config_get_hex; 90 91 // Name: device_iot_config_set_hex 92 // Params: const std::string& section, const std::string& key, int value, int 93 // byte_num 94 // Return: bool 95 struct device_iot_config_set_hex { 96 bool return_value{false}; 97 std::function<bool(const std::string& section, const std::string& key, 98 int value, int byte_num)> 99 body{[this](const std::string& /* section */, 100 const std::string& /* key */, int /* value */, 101 int /* byte_num */) { return return_value; }}; operatordevice_iot_config_set_hex102 bool operator()(const std::string& section, const std::string& key, int value, 103 int byte_num) { 104 return body(section, key, value, byte_num); 105 }; 106 }; 107 extern struct device_iot_config_set_hex device_iot_config_set_hex; 108 109 // Name: device_iot_config_set_hex_if_greater 110 // Params: const std::string& section, const std::string& key, int value, int 111 // byte_num 112 // Return: bool 113 struct device_iot_config_set_hex_if_greater { 114 bool return_value{false}; 115 std::function<bool(const std::string& section, const std::string& key, 116 int value, int byte_num)> 117 body{[this](const std::string& /* section */, 118 const std::string& /* key */, int /* value */, 119 int /* byte_num */) { return return_value; }}; operatordevice_iot_config_set_hex_if_greater120 bool operator()(const std::string& section, const std::string& key, int value, 121 int byte_num) { 122 return body(section, key, value, byte_num); 123 }; 124 }; 125 extern struct device_iot_config_set_hex_if_greater 126 device_iot_config_set_hex_if_greater; 127 128 // Name: device_iot_config_get_str 129 // Params: const std::string& section, const std::string& key, char* value, int* 130 // size_bytes 131 // Return: bool 132 struct device_iot_config_get_str { 133 bool return_value{false}; 134 std::function<bool(const std::string& section, const std::string& key, 135 char* value, int* size_bytes)> 136 body{[this](const std::string& /* section */, 137 const std::string& /* key */, char* /* value */, 138 int* /* size_bytes */) { return return_value; }}; operatordevice_iot_config_get_str139 bool operator()(const std::string& section, const std::string& key, 140 char* value, int* size_bytes) { 141 return body(section, key, value, size_bytes); 142 }; 143 }; 144 extern struct device_iot_config_get_str device_iot_config_get_str; 145 146 // Name: device_iot_config_set_str 147 // Params: const std::string& section, const std::string& key, const 148 // std::string& value 149 // Return: bool 150 struct device_iot_config_set_str { 151 bool return_value{false}; 152 std::function<bool(const std::string& section, const std::string& key, 153 const std::string& value)> 154 body{[this](const std::string& /* section */, 155 const std::string& /* key */, 156 const std::string& /* value */) { return return_value; }}; operatordevice_iot_config_set_str157 bool operator()(const std::string& section, const std::string& key, 158 const std::string& value) { 159 return body(section, key, value); 160 }; 161 }; 162 extern struct device_iot_config_set_str device_iot_config_set_str; 163 164 // Name: device_iot_config_get_bin 165 // Params: const std::string& section, const std::string& key, uint8_t* value, 166 // size_t* length 167 // Return: bool 168 struct device_iot_config_get_bin { 169 bool return_value{false}; 170 std::function<bool(const std::string& section, const std::string& key, 171 uint8_t* value, size_t* length)> 172 body{[this](const std::string& /* section */, 173 const std::string& /* key */, uint8_t* /* value */, 174 size_t* /* length */) { return return_value; }}; operatordevice_iot_config_get_bin175 bool operator()(const std::string& section, const std::string& key, 176 uint8_t* value, size_t* length) { 177 return body(section, key, value, length); 178 }; 179 }; 180 extern struct device_iot_config_get_bin device_iot_config_get_bin; 181 182 // Name: device_iot_config_set_bin 183 // Params: const std::string& section, const std::string& key, const uint8_t* 184 // value, size_t length 185 // Return: bool 186 struct device_iot_config_set_bin { 187 bool return_value{false}; 188 std::function<bool(const std::string& section, const std::string& key, 189 const uint8_t* value, size_t length)> 190 body{[this](const std::string& /* section */, 191 const std::string& /* key */, const uint8_t* /* value */, 192 size_t /* length */) { return return_value; }}; operatordevice_iot_config_set_bin193 bool operator()(const std::string& section, const std::string& key, 194 const uint8_t* value, size_t length) { 195 return body(section, key, value, length); 196 }; 197 }; 198 extern struct device_iot_config_set_bin device_iot_config_set_bin; 199 200 // Name: device_iot_config_get_bin_length 201 // Params: const std::string& section, const std::string& key 202 // Return: size_t 203 struct device_iot_config_get_bin_length { 204 size_t return_value{0}; 205 std::function<size_t(const std::string& section, const std::string& key)> 206 body{[this](const std::string& /* section */, 207 const std::string& /* key */) { return return_value; }}; operatordevice_iot_config_get_bin_length208 size_t operator()(const std::string& section, const std::string& key) { 209 return body(section, key); 210 }; 211 }; 212 extern struct device_iot_config_get_bin_length device_iot_config_get_bin_length; 213 214 // Name: device_iot_config_has_section 215 // Params: const std::string& section 216 // Return: bool 217 struct device_iot_config_has_section { 218 bool return_value{false}; 219 std::function<bool(const std::string& section)> body{ 220 [this](const std::string& /* section */) { return return_value; }}; operatordevice_iot_config_has_section221 bool operator()(const std::string& section) { return body(section); }; 222 }; 223 extern struct device_iot_config_has_section device_iot_config_has_section; 224 225 // Name: device_iot_config_exist 226 // Params: const std::string& section, const std::string& key 227 // Return: bool 228 struct device_iot_config_exist { 229 bool return_value{false}; 230 std::function<bool(const std::string& section, const std::string& key)> body{ 231 [this](const std::string& /* section */, const std::string& /* key */) { 232 return return_value; 233 }}; operatordevice_iot_config_exist234 bool operator()(const std::string& section, const std::string& key) { 235 return body(section, key); 236 }; 237 }; 238 extern struct device_iot_config_exist device_iot_config_exist; 239 240 // Name: device_iot_config_remove 241 // Params: const std::string& section, const std::string& key 242 // Return: bool 243 struct device_iot_config_remove { 244 bool return_value{false}; 245 std::function<bool(const std::string& section, const std::string& key)> body{ 246 [this](const std::string& /* section */, const std::string& /* key */) { 247 return return_value; 248 }}; operatordevice_iot_config_remove249 bool operator()(const std::string& section, const std::string& key) { 250 return body(section, key); 251 }; 252 }; 253 extern struct device_iot_config_remove device_iot_config_remove; 254 255 // Name: device_iot_config_clear 256 // Params: void 257 // Return: bool 258 struct device_iot_config_clear { 259 bool return_value{false}; 260 std::function<bool(void)> body{[this]() { return return_value; }}; operatordevice_iot_config_clear261 bool operator()(void) { return body(); }; 262 }; 263 extern struct device_iot_config_clear device_iot_config_clear; 264 265 // Name: device_iot_config_flush 266 // Params: void 267 // Return: void 268 struct device_iot_config_flush { 269 std::function<void(void)> body{[]() {}}; operatordevice_iot_config_flush270 void operator()(void){ body(); }; 271 }; 272 extern struct device_iot_config_flush device_iot_config_flush; 273 274 // Name: device_debug_iot_config_dump 275 // Params: int fd 276 // Return: void 277 struct device_debug_iot_config_dump { 278 std::function<void(int fd)> body{[](int /* fd */) {}}; operatordevice_debug_iot_config_dump279 void operator()(int fd) { body(fd); }; 280 }; 281 extern struct device_debug_iot_config_dump device_debug_iot_config_dump; 282 283 } // namespace device_iot_config 284 } // namespace mock 285 } // namespace test 286