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
17 #include <cstdint>
18 #include <functional>
19 #include <map>
20 #include <string>
21
22 // Mock include file to share data between tests and mock
23 #include "test/common/mock_functions.h"
24 #include "test/mock/mock_device_iot_config.h"
25
26 namespace test {
27 namespace mock {
28 namespace device_iot_config {
29
30 struct device_iot_config_get_int device_iot_config_get_int;
31 struct device_iot_config_set_int device_iot_config_set_int;
32 struct device_iot_config_int_add_one device_iot_config_int_add_one;
33 struct device_iot_config_get_hex device_iot_config_get_hex;
34 struct device_iot_config_set_hex device_iot_config_set_hex;
35 struct device_iot_config_set_hex_if_greater device_iot_config_set_hex_if_greater;
36 struct device_iot_config_get_str device_iot_config_get_str;
37 struct device_iot_config_set_str device_iot_config_set_str;
38 struct device_iot_config_get_bin device_iot_config_get_bin;
39 struct device_iot_config_set_bin device_iot_config_set_bin;
40 struct device_iot_config_get_bin_length device_iot_config_get_bin_length;
41 struct device_iot_config_has_section device_iot_config_has_section;
42 struct device_iot_config_exist device_iot_config_exist;
43 struct device_iot_config_remove device_iot_config_remove;
44 struct device_iot_config_clear device_iot_config_clear;
45 struct device_iot_config_flush device_iot_config_flush;
46 struct device_debug_iot_config_dump device_debug_iot_config_dump;
47
48 } // namespace device_iot_config
49 } // namespace mock
50 } // namespace test
51
52 // Mocked functions, if any
device_iot_config_get_int(const std::string & section,const std::string & key,int & value)53 bool device_iot_config_get_int(const std::string& section, const std::string& key,
54 int& value) {
55 inc_func_call_count(__func__);
56 return test::mock::device_iot_config::device_iot_config_get_int(section, key, value);
57 }
58
device_iot_config_set_int(const std::string & section,const std::string & key,int value)59 bool device_iot_config_set_int(const std::string& section,
60 const std::string& key, int value) {
61 inc_func_call_count(__func__);
62 return test::mock::device_iot_config::device_iot_config_set_int(section, key, value);
63 }
64
device_iot_config_int_add_one(const std::string & section,const std::string & key)65 bool device_iot_config_int_add_one(const std::string& section,
66 const std::string& key) {
67 inc_func_call_count(__func__);
68 return test::mock::device_iot_config::device_iot_config_int_add_one(section, key);
69 }
70
device_iot_config_get_hex(const std::string & section,const std::string & key,int & value)71 bool device_iot_config_get_hex(const std::string& section,
72 const std::string& key, int& value) {
73 inc_func_call_count(__func__);
74 return test::mock::device_iot_config::device_iot_config_get_hex(section, key, value);
75 }
76
device_iot_config_set_hex(const std::string & section,const std::string & key,int value,int byte_num)77 bool device_iot_config_set_hex(const std::string& section,
78 const std::string& key, int value, int byte_num) {
79 inc_func_call_count(__func__);
80 return test::mock::device_iot_config::device_iot_config_set_hex(section, key, value, byte_num);
81 }
82
device_iot_config_set_hex_if_greater(const std::string & section,const std::string & key,int value,int byte_num)83 bool device_iot_config_set_hex_if_greater(const std::string& section,
84 const std::string& key, int value, int byte_num) {
85 inc_func_call_count(__func__);
86 return test::mock::device_iot_config::device_iot_config_set_hex_if_greater(section, key, value, byte_num);
87 }
88
device_iot_config_get_str(const std::string & section,const std::string & key,char * value,int * size_bytes)89 bool device_iot_config_get_str(const std::string& section,
90 const std::string& key, char* value,
91 int* size_bytes) {
92 inc_func_call_count(__func__);
93 return test::mock::device_iot_config::device_iot_config_get_str(section, key, value, size_bytes);
94 }
95
device_iot_config_set_str(const std::string & section,const std::string & key,const std::string & value)96 bool device_iot_config_set_str(const std::string& section,
97 const std::string& key,
98 const std::string& value) {
99 inc_func_call_count(__func__);
100 return test::mock::device_iot_config::device_iot_config_set_str(section, key, value);
101 }
102
device_iot_config_get_bin(const std::string & section,const std::string & key,uint8_t * value,size_t * length)103 bool device_iot_config_get_bin(const std::string& section,
104 const std::string& key, uint8_t* value,
105 size_t* length) {
106 inc_func_call_count(__func__);
107 return test::mock::device_iot_config::device_iot_config_get_bin(section, key, value, length);
108 }
109
device_iot_config_set_bin(const std::string & section,const std::string & key,const uint8_t * value,size_t length)110 bool device_iot_config_set_bin(const std::string& section,
111 const std::string& key, const uint8_t* value,
112 size_t length) {
113 inc_func_call_count(__func__);
114 return test::mock::device_iot_config::device_iot_config_set_bin(section, key, value, length);
115 }
116
device_iot_config_get_bin_length(const std::string & section,const std::string & key)117 size_t device_iot_config_get_bin_length(const std::string& section,
118 const std::string& key) {
119 inc_func_call_count(__func__);
120 return test::mock::device_iot_config::device_iot_config_get_bin_length(section, key);
121 }
122
device_iot_config_has_section(const std::string & section)123 bool device_iot_config_has_section(const std::string& section) {
124 inc_func_call_count(__func__);
125 return test::mock::device_iot_config::device_iot_config_has_section(section);
126 }
127
device_iot_config_exist(const std::string & section,const std::string & key)128 bool device_iot_config_exist(const std::string& section,
129 const std::string& key) {
130 inc_func_call_count(__func__);
131 return test::mock::device_iot_config::device_iot_config_exist(section, key);
132 }
133
device_iot_config_remove(const std::string & section,const std::string & key)134 bool device_iot_config_remove(const std::string& section,
135 const std::string& key) {
136 inc_func_call_count(__func__);
137 return test::mock::device_iot_config::device_iot_config_remove(section, key);
138 }
139
device_iot_config_flush(void)140 void device_iot_config_flush(void) {
141 inc_func_call_count(__func__);
142 test::mock::device_iot_config::device_iot_config_flush();
143 }
144
device_iot_config_clear(void)145 bool device_iot_config_clear(void) {
146 inc_func_call_count(__func__);
147 return test::mock::device_iot_config::device_iot_config_clear();
148 }
149
device_debug_iot_config_dump(int fd)150 void device_debug_iot_config_dump(int fd) {
151 inc_func_call_count(__func__);
152 test::mock::device_iot_config::device_debug_iot_config_dump(fd);
153 }
154