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