Debian Codegraph @

src/mocks.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/mocks.c`/include <assert.h>
2 #include <cgreen/breadcrumb.h>cxx . . $ `<file>/include/cgreen/breadcrumb.h`/
3 #include <cgreen/mocks.h>cxx . . $ `<file>/include/cgreen/mocks.h`/
4 #include <cgreen/boxed_double.h>cxx . . $ `<file>/include/cgreen/boxed_double.h`/
5 #include <inttypes.h>
6 // TODO: report PC-Lint bug about undeserved 451
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include "cgreen_value_internal.h"cxx . . $ `<file>/src/cgreen_value_internal.h`/
13 #include "cgreen/cgreen_value.h"cxx . . $ `<file>/include/cgreen/cgreen_value.h`/
14 #include "parameters.h"cxx . . $ `<file>/src/parameters.h`/
15 #include "constraint_internal.h"cxx . . $ `<file>/src/constraint_internal.h`/
16 #include "utils.h"cxx . . $ `<file>/src/utils.h`/
17 #include "runner.h"cxx . . $ `<file>/src/runner.h`/
18
19
20 #ifdef __ANDROID__
21 #include "cgreen/internal/android_headers/androidcompat.h"
22 #endif // #ifdef __ANDROID__
23
24 typedef struct RecordedExpectation_cxx . . $ RecordedExpectation_# {
25 const char *functioncxx . . $ RecordedExpectation_#function.;
26 const char *test_filecxx . . $ RecordedExpectation_#test_file.;
27 int test_linecxx . . $ RecordedExpectation_#test_line.;
28 int time_to_livecxx . . $ RecordedExpectation_#time_to_live.;
29 CgreenVectorcxx . . $ CgreenVector# *constraintscxx . . $ RecordedExpectation_#constraints.;
30 int number_times_calledcxx . . $ RecordedExpectation_#number_times_called.;
31 /*
32 * Used to record the number of time this particular expectation was triggered.
33 * The main use at this point is to ensure that never_expect only adds itself
34 * as a successful test if it as never been called
35 */
36 int times_triggeredcxx . . $ RecordedExpectation_#times_triggered.;
37 } RecordedExpectationcxx . . $ RecordedExpectation#;
38
39 const int UNLIMITED_TIME_TO_LIVEcxx . . $ UNLIMITED_TIME_TO_LIVE. = 0x0f314159;
40
41 static CgreenMockModecxx . . $ CgreenMockMode# cgreen_mocks_are_cxx . . $ cgreen_mocks_are_. = strict_mockscxx . . $ strict_mocks.;
42 static CgreenVectorcxx . . $ CgreenVector# *learned_mock_callscxx . . $ learned_mock_calls. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
43 static CgreenVectorcxx . . $ CgreenVector# *successfully_mocked_callscxx . . $ successfully_mocked_calls. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
44 static CgreenVectorcxx . . $ CgreenVector# *global_expectation_queuecxx . . $ global_expectation_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
45
46 static CgreenVectorcxx . . $ CgreenVector# *create_vector_of_actualscxx . . $ create_vector_of_actuals(ea218f222332b186).(va_listcxx . . $ va_list# actuals, int count);
47 static CgreenVectorcxx . . $ CgreenVector# *create_equal_value_constraints_forcxx . . $ create_equal_value_constraints_for(1e5eb5e3f5cc84a3).(CgreenVectorcxx . . $ CgreenVector# *parameter_names,
48 CgreenVectorcxx . . $ CgreenVector# *actual_values);
49 static CgreenVectorcxx . . $ CgreenVector# *create_constraints_vectorcxx . . $ create_constraints_vector(14694a5d65bd8ff7).(void);
50 static RecordedExpectationcxx . . $ RecordedExpectation# *create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(const char *function, const char *test_file,
51 int test_line, CgreenVectorcxx . . $ CgreenVector# *constraints);
52 static CgreenVectorcxx . . $ CgreenVector# *constraints_vector_from_va_listcxx . . $ constraints_vector_from_va_list(171f9044bd7e1f2d).(va_listcxx . . $ va_list# constraints);
53 static void destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation);
54 static void ensure_expectation_queue_existscxx . . $ ensure_expectation_queue_exists(49f6e7a06ebc5aa8).(void);
55 static void ensure_learned_mock_calls_list_existscxx . . $ ensure_learned_mock_calls_list_exists(49f6e7a06ebc5aa8).(void);
56 static void ensure_successfully_mocked_calls_list_existscxx . . $ ensure_successfully_mocked_calls_list_exists(49f6e7a06ebc5aa8).(void);
57 static void remove_expectation_forcxx . . $ remove_expectation_for(85c52e162fed56f9).(const char *function);
58 static void trigger_unfulfilled_expectationscxx . . $ trigger_unfulfilled_expectations(fcc853f0047efea0).(CgreenVectorcxx . . $ CgreenVector# *expectation_queue, TestReportercxx . . $ TestReporter# *reporter);
59 static RecordedExpectationcxx . . $ RecordedExpectation# *find_expectationcxx . . $ find_expectation(7ab1b979b7dbe200).(const char *function);
60 static void apply_any_read_only_parameter_constraintscxx . . $ apply_any_read_only_parameter_constraints(13995eba0b1cdc6b).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
61 const char *parameter,
62 CgreenValuecxx . . $ CgreenValue# actual,
63 TestReportercxx . . $ TestReporter#* test_reporter);
64 static void apply_any_content_setting_parameter_constraintscxx . . $ apply_any_content_setting_parameter_constraints(13995eba0b1cdc6b).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
65 const char *parameter,
66 CgreenValuecxx . . $ CgreenValue# actual,
67 TestReportercxx . . $ TestReporter#* test_reporter);
68 static CgreenValuecxx . . $ CgreenValue# stored_result_or_default_forcxx . . $ stored_result_or_default_for(60202341d72e7bba).(CgreenVectorcxx . . $ CgreenVector#* constraints);
69 static int number_of_parameters_incxx . . $ number_of_parameters_in(5c4306d8553b3696).(const char *parameter_list);
70 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_always_callcxx . . $ is_always_call(182f0f58706ba67c).(RecordedExpectationcxx . . $ RecordedExpectation#* expectation);
71 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_always_expectation_forcxx . . $ have_always_expectation_for(c5f7da30cbc0f4e9).(const char* function);
72 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(RecordedExpectationcxx . . $ RecordedExpectation#* expectation);
73 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_never_call_expectation_forcxx . . $ have_never_call_expectation_for(c5f7da30cbc0f4e9).(const char* function);
74 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! remove_never_call_expectation_forcxx . . $ remove_never_call_expectation_for(c5f7da30cbc0f4e9).(const char* function);
75
76 static void report_violated_never_callcxx . . $ report_violated_never_call(f921f1a61d3cfbf6).(TestReportercxx . . $ TestReporter#*, RecordedExpectationcxx . . $ RecordedExpectation#*);
77 static void report_unexpected_callcxx . . $ report_unexpected_call(f921f1a61d3cfbf6).(TestReportercxx . . $ TestReporter#*, RecordedExpectationcxx . . $ RecordedExpectation#*);
78 static void report_mock_parameter_name_not_foundcxx . . $ report_mock_parameter_name_not_found(3eedbf4d6f65432d).(TestReportercxx . . $ TestReporter# *test_reporter,
79 RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
80 const char *parameter);
81 static void destroy_expectation_if_time_to_diecxx . . $ destroy_expectation_if_time_to_die(de9c512e3ac46f69).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation);
82
83 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_side_effect_constraintcxx . . $ is_side_effect_constraint(1ba69099f960dda3).(const Constraintcxx . . $ Constraint# *constraint);
84 static void apply_side_effectcxx . . $ apply_side_effect(48ef9482dbafcc0f).(TestReportercxx . . $ TestReporter# *test_reporter,
85 const RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
86 Constraintcxx . . $ Constraint# *constraint);
87
88 void cgreen_mocks_arecxx . . $ cgreen_mocks_are(366adfdc1bb4e579).(CgreenMockModecxx . . $ CgreenMockMode# mock_mode) {
89 cgreen_mocks_are_cxx . . $ cgreen_mocks_are_. = mock_mode;
90 }
91
92
93 static int number_of_parameters_incxx . . $ number_of_parameters_in(5c4306d8553b3696).(const char *parameter_list) {
94 int count = 1;
95 const char *current = parameter_list;
96
97 if (strlencxx . . $ strlen(751346f8406fd082).(parameter_list) == 0) return 0;
98
99 while (*current != '\0') {
100 if (*current == ',') count++;
101 current++;
102 }
103
104 return count;
105 }
106
107 /* Not used anywhere, but might become handy so make it non-static to avoid warnings */
108 int number_of_parameter_constraints_incxx . . $ number_of_parameter_constraints_in(d6a9fa4a29061fe2).(const CgreenVectorcxx . . $ CgreenVector#* constraints) {
109 int i, parameters = 0;
110
111 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(constraints); i++) {
112 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(constraints, i);
113
114 if (is_comparingcxx . . $ is_comparing(1ba69099f960dda3).(constraint)) {
115 parameters++;
116 }
117 }
118
119 return parameters;
120 }
121
122 static void learn_mock_call_forcxx . . $ learn_mock_call_for(20d05b6c306e1007).(const char *function, const char *mock_file, int mock_line,
123 CgreenVectorcxx . . $ CgreenVector# *parameter_names, CgreenVectorcxx . . $ CgreenVector# *actual_values) {
124 CgreenVectorcxx . . $ CgreenVector# *constraints = create_equal_value_constraints_forcxx . . $ create_equal_value_constraints_for(1e5eb5e3f5cc84a3).(parameter_names, actual_values);
125
126 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(function, mock_file, mock_line,
127 constraints);
128 ensure_learned_mock_calls_list_existscxx . . $ ensure_learned_mock_calls_list_exists(49f6e7a06ebc5aa8).();
129 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(learned_mock_callscxx . . $ learned_mock_calls., (void*)expectation);
130 }
131
132 static void handle_missing_expectation_forcxx . . $ handle_missing_expectation_for(9faa5f6abea0835b).(const char *function, const char *mock_file, int mock_line,
133 CgreenVectorcxx . . $ CgreenVector# *parameter_names, CgreenVectorcxx . . $ CgreenVector# *actual_values,
134 TestReportercxx . . $ TestReporter# *test_reporter) {
135 RecordedExpectationcxx . . $ RecordedExpectation# *expectation;
136 CgreenVectorcxx . . $ CgreenVector# *no_constraints;
137
138 switch (cgreen_mocks_are_cxx . . $ cgreen_mocks_are_.) {
139 case loose_mockscxx . . $ loose_mocks.:
140 break;
141
142 case learning_mockscxx . . $ learning_mocks.:
143 learn_mock_call_forcxx . . $ learn_mock_call_for(20d05b6c306e1007).(function, mock_file, mock_line, parameter_names, actual_values);
144 break;
145
146 case strict_mockscxx . . $ strict_mocks.:
147 no_constraints = create_constraints_vectorcxx . . $ create_constraints_vector(14694a5d65bd8ff7).();
148 expectation = create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(function, mock_file, mock_line, no_constraints);
149 report_unexpected_callcxx . . $ report_unexpected_call(f921f1a61d3cfbf6).(test_reporter, expectation);
150
151 destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(expectation);
152 break;
153 }
154 }
155
156
157 static CgreenValuecxx . . $ CgreenValue# convert_boxed_double_to_cgreen_valuecxx . . $ convert_boxed_double_to_cgreen_value(89307b92e16d10d5).(CgreenValuecxx . . $ CgreenValue# actual) {
158 actual.typecxx . . $ $anonymous_type_b16cac6eed758fe0_1#type. = CGREEN_DOUBLEcxx . . $ CGREEN_DOUBLE.;
159 actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..double_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#double_value. = unbox_doublecxx . . $ unbox_double(66f4a6ec74012662).(actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.);
160 return actual;
161 }
162
163 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! parameter_is_boxed_doublecxx . . $ parameter_is_boxed_double(3073f6616eeceb6a).(CgreenVectorcxx . . $ CgreenVector# *double_markers, int i) {
164 return *(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(double_markers, i) == truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
165 }
166
167
168 static void convert_boxed_doubles_to_cgreen_valuescxx . . $ convert_boxed_doubles_to_cgreen_values(11f4a7aef0a0e2da).(const char *parameters, CgreenVectorcxx . . $ CgreenVector# *actual_values) {
169 CgreenVectorcxx . . $ CgreenVector# *double_markers;
170 int i;
171 /* Since the caller must use 'box_double()' to pass doubles as
172 arguments to 'mock()' we can know which ones are such parameters
173 to be able to convert them to CgreenValues here */
174 double_markers = create_vector_of_double_markers_forcxx . . $ create_vector_of_double_markers_for(d5a3278d3d52ae11).(parameters);
175 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(double_markers); i++) {
176 if (parameter_is_boxed_doublecxx . . $ parameter_is_boxed_double(3073f6616eeceb6a).(double_markers, i)) {
177 CgreenValuecxx . . $ CgreenValue# *actual = cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(actual_values, i);
178 *actual = convert_boxed_double_to_cgreen_valuecxx . . $ convert_boxed_double_to_cgreen_value(89307b92e16d10d5).(*actual);
179 }
180 }
181 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(double_markers);
182 }
183
184
185 intptr_tcxx . . $ intptr_t# mock_cxx . . $ mock_(e53dfa95efbcf8ef).(TestReportercxx . . $ TestReporter#* test_reporter, const char *function, const char *mock_file, int mock_line, const char *parameters, ...) {
186 va_listcxx . . $ va_list# actuals;
187 CgreenVectorcxx . . $ CgreenVector# *actual_values;
188 CgreenVectorcxx . . $ CgreenVector# *parameter_names;
189 int failures_before_read_only_constraints_executed;
190 int failures_after_read_only_constraints_executed;
191 CgreenValuecxx . . $ CgreenValue# stored_result;
192 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = find_expectationcxx . . $ find_expectation(7ab1b979b7dbe200).(function);
193
194 parameter_names = create_vector_of_namescxx . . $ create_vector_of_names(d5a3278d3d52ae11).(parameters);
195
196 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(actuals, parameters);
197 actual_values = create_vector_of_actualscxx . . $ create_vector_of_actuals(ea218f222332b186).(actuals, number_of_parameters_incxx . . $ number_of_parameters_in(5c4306d8553b3696).(parameters));
198 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(actuals);
199
200 convert_boxed_doubles_to_cgreen_valuescxx . . $ convert_boxed_doubles_to_cgreen_values(11f4a7aef0a0e2da).(parameters, actual_values);
201
202 if (expectation == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
203 handle_missing_expectation_forcxx . . $ handle_missing_expectation_for(9faa5f6abea0835b).(function, mock_file, mock_line, parameter_names, actual_values, test_reporter);
204 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(actual_values);
205 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(parameter_names);
206 return 0;
207 }
208
209 if (is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(expectation)) {
210 expectation->times_triggeredcxx . . $ RecordedExpectation_#times_triggered.++;
211 report_violated_never_callcxx . . $ report_violated_never_call(f921f1a61d3cfbf6).(test_reporter, expectation);
212 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(actual_values);
213 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(parameter_names);
214 return 0;
215 }
216
217 ensure_successfully_mocked_calls_list_existscxx . . $ ensure_successfully_mocked_calls_list_exists(49f6e7a06ebc5aa8).();
218 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(successfully_mocked_callscxx . . $ successfully_mocked_calls., (void*)function);
219
220 stored_result = stored_result_or_default_forcxx . . $ stored_result_or_default_for(60202341d72e7bba).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.);
221 // FIXME: Should verify that return value is not a DOUBLE as `mock_()' can not
222 // return them. There should also be a 'mock_double_()' which does the same except
223 // returning a double.
224
225 // First check all actual constraints for validity...
226 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); i++) {
227 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., i);
228
229 if (constraint->typecxx . . $ Constraint_#type. == CGREEN_CALL_COUNTER_CONSTRAINTcxx . . $ CGREEN_CALL_COUNTER_CONSTRAINT.) {
230 expectation->number_times_calledcxx . . $ RecordedExpectation_#number_times_called.++;
231 continue;
232 }
233
234 if (!is_parametercxx . . $ is_parameter(1ba69099f960dda3).(constraint))
235 continue;
236
237 if (!constraint_is_for_parameter_incxx . . $ constraint_is_for_parameter_in(74f87f4455e42aa1).(constraint, parameters)) {
238 // if expectation parameter name isn't in parameter_names,
239 // fail test and skip applying constraints unlikely to match
240 report_mock_parameter_name_not_foundcxx . . $ report_mock_parameter_name_not_found(3eedbf4d6f65432d).(test_reporter, expectation, constraint->parameter_namecxx . . $ Constraint_#parameter_name.);
241 destroy_expectation_if_time_to_diecxx . . $ destroy_expectation_if_time_to_die(de9c512e3ac46f69).(expectation);
242 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(actual_values);
243 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(parameter_names);
244
245 return stored_result.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.;
246 }
247 }
248
249 // Now we can do the read-only constraints. If read-only
250 // constraints aren't matching, content-setting ones might corrupt
251 // memory so apply read-only ones first, and if they don't fail,
252 // then do the deeper constraints
253 failures_before_read_only_constraints_executed = test_reporter->failurescxx . . $ TestReporter_#failures.;
254
255 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(parameter_names); i++) {
256 const char* parameter_name = (const char*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(parameter_names, i);
257 CgreenValuecxx . . $ CgreenValue# actual = *(CgreenValuecxx . . $ CgreenValue#*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(actual_values, i);
258 apply_any_read_only_parameter_constraintscxx . . $ apply_any_read_only_parameter_constraints(13995eba0b1cdc6b).(expectation, parameter_name, actual, test_reporter);
259 }
260
261 failures_after_read_only_constraints_executed = test_reporter->failurescxx . . $ TestReporter_#failures.;
262
263 // And now we can do the content setting constraints...
264 // FIXME: this comparison doesn't work because only parent
265 // processes' pass/fail counts are updated, and even then
266 // only once they read from the pipe
267 if (failures_before_read_only_constraints_executed == failures_after_read_only_constraints_executed) {
268 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(parameter_names); i++) {
269 const char* parameter_name = (const char*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(parameter_names, i);
270 CgreenValuecxx . . $ CgreenValue# actual = *(CgreenValuecxx . . $ CgreenValue#*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(actual_values, i);
271 apply_any_content_setting_parameter_constraintscxx . . $ apply_any_content_setting_parameter_constraints(13995eba0b1cdc6b).(expectation, parameter_name, actual, test_reporter);
272 }
273 }
274
275 // And finally run all side effects
276 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); i++) {
277 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., i);
278
279 if (is_side_effect_constraintcxx . . $ is_side_effect_constraint(1ba69099f960dda3).(constraint)) {
280 apply_side_effectcxx . . $ apply_side_effect(48ef9482dbafcc0f).(test_reporter, expectation, constraint);
281 continue;
282 }
283 }
284
285
286
287 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(parameter_names);
288 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(actual_values);
289
290 expectation->times_triggeredcxx . . $ RecordedExpectation_#times_triggered.++;
291 destroy_expectation_if_time_to_diecxx . . $ destroy_expectation_if_time_to_die(de9c512e3ac46f69).(expectation);
292
293 if (stored_result.typecxx . . $ $anonymous_type_b16cac6eed758fe0_1#type. == CGREEN_DOUBLEcxx . . $ CGREEN_DOUBLE.) {
294 #ifdef FUTURE
295 /* TODO: for some future version we should ensure that the
296 user is not trying to return a double through 'mock()' when
297 there is a 'mock_double()' available, which there isn't
298 yet. So then
299
300 return unbox_double(mock(...));
301
302 should be replaced by
303
304 return mock_double(...);
305 */
306 test_reporter->assert_true(test_reporter,
307 mock_file,
308 mock_line,
309 false,
310 "Mocked function [%s] have a 'will_return_double()' expectation, "
311 "but 'mock()' cannot return doubles; Use 'mock_double()' instead",
312 function);
313 /* But we'll return it anyway, whatever it becomes is what he will get... */
314 return stored_result.value.double_value;
315 #else
316 /* ... but for now return a boxed double since the user is probably using
317
318 return unbox_double(mock(...));
319
320 as is the standard way in 1.x
321 */
322 return box_doublecxx . . $ box_double(a6e4a4c8b00c35a3).(stored_result.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..double_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#double_value.);
323 #endif
324 } else
325 return stored_result.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.;
326 }
327
328 static void apply_side_effectcxx . . $ apply_side_effect(48ef9482dbafcc0f).(TestReportercxx . . $ TestReporter# *test_reporter,
329 const RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
330 Constraintcxx . . $ Constraint# *constraint)
331 {
332 CgreenValuecxx . . $ CgreenValue# actual = {};
333 constraint->executecxx . . $ Constraint_#execute.(
334 constraint,
335 expectation->functioncxx . . $ RecordedExpectation_#function.,
336 actual,
337 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
338 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
339 test_reporter);
340 }
341
342 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_side_effect_constraintcxx . . $ is_side_effect_constraint(1ba69099f960dda3).(const Constraintcxx . . $ Constraint# *constraint) {
343 return constraint->typecxx . . $ Constraint_#type. == CGREEN_CALL_CONSTRAINTcxx . . $ CGREEN_CALL_CONSTRAINT.;
344 }
345
346 static CgreenVectorcxx . . $ CgreenVector# *create_vector_of_actualscxx . . $ create_vector_of_actuals(ea218f222332b186).(va_listcxx . . $ va_list# actuals, int count) {
347 int i;
348 CgreenVectorcxx . . $ CgreenVector# *actual_values = create_cgreen_vectorcxx . . $ create_cgreen_vector(940ca2d138a76a1b).(freecxx . . $ free(5d22bdacc48458e8).);
349 for (i = 0; i < count; i++) {
350 uintptr_tcxx . . $ uintptr_t# actual = va_argcxx . . $ `<external>/8293021631987149590/stdarg.h:54:9`!(actuals, uintptr_t);
351 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(actual_values, (void*)create_cgreen_valuecxx . . $ create_cgreen_value(f0aaa6389606dccb).(make_cgreen_integer_valuecxx . . $ make_cgreen_integer_value(1194b204c86a8e67).(actual)));
352 }
353 return actual_values;
354 }
355
356
357 static Constraintcxx . . $ Constraint# *create_appropriate_equal_constraint_forcxx . . $ create_appropriate_equal_constraint_for(399b2d1c11afccf1).(const char *parameter_name,
358 CgreenValuecxx . . $ CgreenValue# actual) {
359 Constraintcxx . . $ Constraint# *constraint;
360 if (actual.typecxx . . $ $anonymous_type_b16cac6eed758fe0_1#type. == CGREEN_DOUBLEcxx . . $ CGREEN_DOUBLE.)
361 constraint = create_equal_to_double_constraintcxx . . $ create_equal_to_double_constraint(fadb8cf50565de40).(actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..double_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#double_value.,
362 parameter_name);
363 else
364 constraint = create_equal_to_value_constraintcxx . . $ create_equal_to_value_constraint(f83092978cf2a14d).(actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.,
365 parameter_name);
366 return constraint;
367 }
368
369 static CgreenVectorcxx . . $ CgreenVector# *create_equal_value_constraints_forcxx . . $ create_equal_value_constraints_for(1e5eb5e3f5cc84a3).(CgreenVectorcxx . . $ CgreenVector# *parameter_names,
370 CgreenVectorcxx . . $ CgreenVector# *actual_values) {
371 int i;
372 CgreenVectorcxx . . $ CgreenVector# *constraints = create_constraints_vectorcxx . . $ create_constraints_vector(14694a5d65bd8ff7).();
373 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(parameter_names); i++) {
374 const char* parameter_name = (const char*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(parameter_names, i);
375 CgreenValuecxx . . $ CgreenValue# actual = *(CgreenValuecxx . . $ CgreenValue#*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(actual_values, i);
376 Constraintcxx . . $ Constraint# *constraint = create_appropriate_equal_constraint_forcxx . . $ create_appropriate_equal_constraint_for(399b2d1c11afccf1).(parameter_name, actual);
377 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(constraints, constraint);
378 }
379 return constraints;
380 }
381
382
383 Constraintcxx . . $ Constraint# *when_cxx . . $ when_(4f3350aa8fa022ad).(const char *parameter, Constraintcxx . . $ Constraint#* constraint) {
384 constraint->parameter_namecxx . . $ Constraint_#parameter_name. = parameter;
385 return constraint;
386 }
387
388
389
390 void test_times_calledcxx . . $ test_times_called(c0af3e8d8bd2e1e5).(Constraintcxx . . $ Constraint# *constraint, const char *function, CgreenValuecxx . . $ CgreenValue# actual,
391 const char *test_file, int test_line, TestReportercxx . . $ TestReporter# *reporter) {
392 char *message;
393 char parameter_name_actual_string[255];
394
395 snprintfcxx . . $ snprintf(ea502d73e74c754c).(parameter_name_actual_string, sizeof(parameter_name_actual_string) - 1, "%s", function);
396 message = constraint->failure_messagecxx . . $ Constraint_#failure_message.(constraint, parameter_name_actual_string, actual.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.);
397
398 (*reporter->assert_truecxx . . $ TestReporter_#assert_true.)(
399 reporter,
400 test_file,
401 test_line,
402 (*constraint->comparecxx . . $ Constraint_#compare.)(constraint, actual),
403 message);
404
405 freecxx . . $ free(5d22bdacc48458e8).(message);
406 }
407
408 Constraintcxx . . $ Constraint# *times_cxx . . $ times_(85a08db91913d9ec).(const int number_times_called) {
409 Constraintcxx . . $ Constraint# * time_constraint = create_constraintcxx . . $ create_constraint(ba55e2de72051eb6).();
410 time_constraint->expected_valuecxx . . $ Constraint_#expected_value. = make_cgreen_integer_valuecxx . . $ make_cgreen_integer_value(1194b204c86a8e67).(number_times_called);
411 time_constraint->expected_value_namecxx . . $ Constraint_#expected_value_name. = string_dupcxx . . $ string_dup(a8b8e32347182212).("times");
412 time_constraint->typecxx . . $ Constraint_#type. = CGREEN_CALL_COUNTER_CONSTRAINTcxx . . $ CGREEN_CALL_COUNTER_CONSTRAINT.;
413
414 time_constraint->comparecxx . . $ Constraint_#compare. = &compare_want_valuecxx . . $ compare_want_value(967c8d0e1b1425dd).;
415 time_constraint->executecxx . . $ Constraint_#execute. = &test_times_calledcxx . . $ test_times_called(c0af3e8d8bd2e1e5).;
416 time_constraint->namecxx . . $ Constraint_#name. = "be called";
417 time_constraint->size_of_expected_valuecxx . . $ Constraint_#size_of_expected_value. = sizeof(intptr_tcxx . . $ intptr_t#);
418 time_constraint->expected_value_messagecxx . . $ Constraint_#expected_value_message. = "\t\texpected to have been called:\t[%" PRIdPTRcxx . . $ `<external>/15933738808807975373/inttypes.h:165:10`! "] times";
419 return time_constraint;
420 }
421
422 static void destroy_expectation_if_time_to_diecxx . . $ destroy_expectation_if_time_to_die(de9c512e3ac46f69).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation) {
423
424 if (is_always_callcxx . . $ is_always_call(182f0f58706ba67c).(expectation)) {
425 return;
426 }
427
428 /* TODO: expectation->decrement_time_to_live_if_necessary(); if (expectation->time_to_die()) { ... } */
429 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live.--;
430
431 if (expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. <= 0) {
432 remove_expectation_forcxx . . $ remove_expectation_for(85c52e162fed56f9).(expectation->functioncxx . . $ RecordedExpectation_#function.);
433 destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(expectation);
434 }
435 }
436
437 void expect_cxx . . $ expect_(3e1046545893700d).(TestReportercxx . . $ TestReporter#* test_reporter, const char *function, const char *test_file, int test_line, ...) {
438 va_listcxx . . $ va_list# constraints;
439 RecordedExpectationcxx . . $ RecordedExpectation# *expectation;
440 CgreenVectorcxx . . $ CgreenVector# *constraints_vector;
441
442 if (have_always_expectation_forcxx . . $ have_always_expectation_for(c5f7da30cbc0f4e9).(function)) {
443 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
444 test_reporter,
445 test_file,
446 test_line,
447 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
448 "Mocked function [%s] already has an expectation that it will always be called a certain way; "
449 "any expectations declared after an always expectation are invalid", function);
450 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
451 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
452 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
453
454 return;
455 }
456
457 if (have_never_call_expectation_forcxx . . $ have_never_call_expectation_for(c5f7da30cbc0f4e9).(function)) {
458 remove_never_call_expectation_forcxx . . $ remove_never_call_expectation_for(c5f7da30cbc0f4e9).(function);
459
460 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
461 test_reporter,
462 test_file,
463 test_line,
464 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
465 "Mocked function [%s] already has an expectation that it will never be called; "
466 "any expectations declared after a never call expectation are invalid", function);
467 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
468 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
469 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
470
471 return;
472 }
473
474
475 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
476 constraints_vector = constraints_vector_from_va_listcxx . . $ constraints_vector_from_va_list(171f9044bd7e1f2d).(constraints);
477 expectation = create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(function, test_file, test_line, constraints_vector);
478 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
479
480 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. = 1;
481 for (int i = 0 ; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.) ; i++) {
482 Constraintcxx . . $ Constraint# * constraint = cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., i);
483 if (constraint && constraint->typecxx . . $ Constraint_#type. == CGREEN_CALL_COUNTER_CONSTRAINTcxx . . $ CGREEN_CALL_COUNTER_CONSTRAINT.) {
484 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. = (int)constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.;
485 break;
486 }
487 }
488 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(global_expectation_queuecxx . . $ global_expectation_queue., expectation);
489 }
490
491 void always_expect_cxx . . $ always_expect_(3e1046545893700d).(TestReportercxx . . $ TestReporter#* test_reporter, const char *function, const char *test_file, int test_line, ...) {
492 va_listcxx . . $ va_list# constraints;
493 RecordedExpectationcxx . . $ RecordedExpectation# *expectation;
494 CgreenVectorcxx . . $ CgreenVector# *constraints_vector;
495
496 if (have_always_expectation_forcxx . . $ have_always_expectation_for(c5f7da30cbc0f4e9).(function)) {
497 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
498 test_reporter,
499 test_file,
500 test_line,
501 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
502 "Mocked function [%s] already has an expectation and will always be called a certain way; "
503 "any expectations declared after an always expectation are discarded", function);
504 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
505 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
506 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
507
508 return;
509 }
510
511 if (have_never_call_expectation_forcxx . . $ have_never_call_expectation_for(c5f7da30cbc0f4e9).(function)) {
512 remove_never_call_expectation_forcxx . . $ remove_never_call_expectation_for(c5f7da30cbc0f4e9).(function);
513
514 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
515 test_reporter,
516 test_file,
517 test_line,
518 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
519 "Mocked function [%s] already has an expectation that it will never be called; "
520 "any expectations declared after a never call expectation are discarded", function);
521 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
522 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
523 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
524
525 return;
526 }
527
528 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
529 constraints_vector = constraints_vector_from_va_listcxx . . $ constraints_vector_from_va_list(171f9044bd7e1f2d).(constraints);
530 expectation = create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(function, test_file, test_line, constraints_vector);
531 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
532 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. = UNLIMITED_TIME_TO_LIVEcxx . . $ UNLIMITED_TIME_TO_LIVE.;
533 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(global_expectation_queuecxx . . $ global_expectation_queue., expectation);
534 }
535
536 void never_expect_cxx . . $ never_expect_(3e1046545893700d).(TestReportercxx . . $ TestReporter#* test_reporter, const char *function, const char *test_file, int test_line, ...) {
537 va_listcxx . . $ va_list# constraints;
538 RecordedExpectationcxx . . $ RecordedExpectation# *expectation;
539 CgreenVectorcxx . . $ CgreenVector# *constraints_vector;
540
541 if (have_always_expectation_forcxx . . $ have_always_expectation_for(c5f7da30cbc0f4e9).(function)) {
542 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
543 test_reporter,
544 test_file,
545 test_line,
546 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
547 "Mocked function [%s] already has an expectation and will always be called a certain way; "
548 "declaring an expectation after an always expectation is not allowed", function);
549 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
550 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
551 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
552
553 return;
554 }
555
556 if (have_never_call_expectation_forcxx . . $ have_never_call_expectation_for(c5f7da30cbc0f4e9).(function)) {
557 remove_never_call_expectation_forcxx . . $ remove_never_call_expectation_for(c5f7da30cbc0f4e9).(function);
558
559 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
560 test_reporter,
561 test_file,
562 test_line,
563 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
564 "Mocked function [%s] already has an expectation that it will never be called; "
565 "declaring an expectation for a function after a never call expectation is not allowed", function);
566 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
567 destroy_constraintscxx . . $ destroy_constraints(490612dd6b4b3be6).(constraints);
568 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(constraints);
569
570 return;
571 }
572
573 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(constraints, test_line);
574 constraints_vector = constraints_vector_from_va_listcxx . . $ constraints_vector_from_va_list(171f9044bd7e1f2d).(constraints);
575 expectation = create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(function, test_file, test_line, constraints_vector);
576 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. = -UNLIMITED_TIME_TO_LIVEcxx . . $ UNLIMITED_TIME_TO_LIVE.;
577 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(global_expectation_queuecxx . . $ global_expectation_queue., expectation);
578 }
579
580
581 static void report_violated_never_callcxx . . $ report_violated_never_call(f921f1a61d3cfbf6).(TestReportercxx . . $ TestReporter# *test_reporter, RecordedExpectationcxx . . $ RecordedExpectation#* expectation) {
582 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
583 test_reporter,
584 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
585 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
586 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
587 "Mocked function [%s] has an expectation that it will never be called, but it was",
588 expectation->functioncxx . . $ RecordedExpectation_#function.);
589 }
590
591
592 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! successfully_mocked_callcxx . . $ successfully_mocked_call(c5f7da30cbc0f4e9).(const char *function_name) {
593 int i;
594
595 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(successfully_mocked_callscxx . . $ successfully_mocked_calls.); i++) {
596 const char *successfully_mocked_function_name = (const char *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(successfully_mocked_callscxx . . $ successfully_mocked_calls., i);
597 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(successfully_mocked_function_name, function_name) == 0) {
598 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
599 }
600 }
601
602 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
603 }
604
605
606 static void report_unexpected_callcxx . . $ report_unexpected_call(f921f1a61d3cfbf6).(TestReportercxx . . $ TestReporter# *test_reporter, RecordedExpectationcxx . . $ RecordedExpectation#* expectation) {
607 const char *message;
608 if (successfully_mocked_callcxx . . $ successfully_mocked_call(c5f7da30cbc0f4e9).(expectation->functioncxx . . $ RecordedExpectation_#function.)) {
609 message = "Mocked function [%s] was called too many times";
610 } else {
611 message = "Mocked function [%s] did not have an expectation that it would be called";
612 }
613
614 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
615 test_reporter,
616 current_testcxx . . $ current_test.->filenamecxx . . $ $anonymous_type_2148a7db88bac269_1#filename.,
617 current_testcxx . . $ current_test.->linecxx . . $ $anonymous_type_2148a7db88bac269_1#line.,
618 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
619 message,
620 expectation->functioncxx . . $ RecordedExpectation_#function.);
621 }
622
623 void clear_mockscxx . . $ clear_mocks(49f6e7a06ebc5aa8).(void) {
624 if (global_expectation_queuecxx . . $ global_expectation_queue. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
625 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(global_expectation_queuecxx . . $ global_expectation_queue.);
626 global_expectation_queuecxx . . $ global_expectation_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
627 }
628
629 if (learned_mock_callscxx . . $ learned_mock_calls. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
630 int i;
631 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(learned_mock_callscxx . . $ learned_mock_calls.); i++) {
632 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = (RecordedExpectationcxx . . $ RecordedExpectation#*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(learned_mock_callscxx . . $ learned_mock_calls., i);
633 destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(expectation);
634 }
635
636 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(learned_mock_callscxx . . $ learned_mock_calls.);
637 learned_mock_callscxx . . $ learned_mock_calls. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
638 }
639 }
640
641 static void show_breadcrumbcxx . . $ show_breadcrumb(4611f29f2f861a56).(const char *name, void *memo) {
642 if (*(int *) memo > 1) {
643 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "-> ");
644 }
645 if (*(int *) memo > 0) {
646 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s ", name);
647 }
648 (*(int *) memo)++;
649 }
650
651
652 void print_learned_mockscxx . . $ print_learned_mocks(49f6e7a06ebc5aa8).(void) {
653 int e, c, i = 0;
654 CgreenBreadcrumbcxx . . $ CgreenBreadcrumb# *breadcrumb = get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->breadcrumbcxx . . $ TestReporter_#breadcrumb.;
655
656 walk_breadcrumbcxx . . $ walk_breadcrumb(e1235c45da9c923a).(breadcrumb, &show_breadcrumbcxx . . $ show_breadcrumb(4611f29f2f861a56)., (void *) &i);
657
658 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, ": Learned mocks are\n");
659
660 if (cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(learned_mock_callscxx . . $ learned_mock_calls.) == 0) {
661 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\t<none>\n");
662 return;
663 }
664
665 for (e = 0; e < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(learned_mock_callscxx . . $ learned_mock_calls.); e++) {
666 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = (RecordedExpectationcxx . . $ RecordedExpectation#*)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(learned_mock_callscxx . . $ learned_mock_calls., e);
667 const char *function_name = expectation->functioncxx . . $ RecordedExpectation_#function.;
668 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\texpect(%s", function_name);
669 for (c = 0; c < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); c++) {
670 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., c);
671 if (constraint->expected_valuecxx . . $ Constraint_#expected_value..typecxx . . $ $anonymous_type_b16cac6eed758fe0_1#type. == CGREEN_DOUBLEcxx . . $ CGREEN_DOUBLE.)
672 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, ", when(%s, is_equal_to_double(%f))", constraint->expected_value_namecxx . . $ Constraint_#expected_value_name.,
673 constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..double_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#double_value.);
674 else
675 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, ", when(%s, is_equal_to(%" PRIdPTRcxx . . $ `<external>/15933738808807975373/inttypes.h:165:10`! "))", constraint->expected_value_namecxx . . $ Constraint_#expected_value_name.,
676 constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..integer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#integer_value.);
677 }
678 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, ");\n");
679 }
680 }
681
682 void tally_mockscxx . . $ tally_mocks(1083e9dac9de8fd0).(TestReportercxx . . $ TestReporter# *reporter) {
683 if (cgreen_mocks_are_cxx . . $ cgreen_mocks_are_. == learning_mockscxx . . $ learning_mocks.) {
684 print_learned_mockscxx . . $ print_learned_mocks(49f6e7a06ebc5aa8).();
685 }
686
687 trigger_unfulfilled_expectationscxx . . $ trigger_unfulfilled_expectations(fcc853f0047efea0).(global_expectation_queuecxx . . $ global_expectation_queue., reporter);
688 clear_mockscxx . . $ clear_mocks(49f6e7a06ebc5aa8).();
689 }
690
691
692 static CgreenVectorcxx . . $ CgreenVector# *create_constraints_vectorcxx . . $ create_constraints_vector(14694a5d65bd8ff7).(void) {
693 return create_cgreen_vectorcxx . . $ create_cgreen_vector(940ca2d138a76a1b).((GenericDestructorcxx . . $ GenericDestructor#)&destroy_constraintcxx . . $ destroy_constraint(f159a969fe179808).);
694 }
695
696
697 static CgreenVectorcxx . . $ CgreenVector# *constraints_vector_from_va_listcxx . . $ constraints_vector_from_va_list(171f9044bd7e1f2d).(va_listcxx . . $ va_list# constraints) {
698 CgreenVectorcxx . . $ CgreenVector# *vector = create_constraints_vectorcxx . . $ create_constraints_vector(14694a5d65bd8ff7).();
699 Constraintcxx . . $ Constraint# *constraint;
700 while ((constraint = va_argcxx . . $ `<external>/8293021631987149590/stdarg.h:54:9`!(constraints, Constraint *)) != (Constraintcxx . . $ Constraint# *)0) {
701 cgreen_vector_addcxx . . $ cgreen_vector_add(77a2afb5bdbc2be1).(vector, constraint);
702 }
703 return vector;
704 }
705
706
707 static RecordedExpectationcxx . . $ RecordedExpectation# *create_recorded_expectationcxx . . $ create_recorded_expectation(3b85e6b9811012be).(const char *function, const char *test_file, int test_line, CgreenVectorcxx . . $ CgreenVector# *constraints) {
708 RecordedExpectationcxx . . $ RecordedExpectation# *expectation;
709
710 ensure_expectation_queue_existscxx . . $ ensure_expectation_queue_exists(49f6e7a06ebc5aa8).();
711 expectation = (RecordedExpectationcxx . . $ RecordedExpectation# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(RecordedExpectationcxx . . $ RecordedExpectation#));
712 expectation->functioncxx . . $ RecordedExpectation_#function. = function;
713 expectation->test_filecxx . . $ RecordedExpectation_#test_file. = test_file;
714 expectation->test_linecxx . . $ RecordedExpectation_#test_line. = test_line;
715 expectation->constraintscxx . . $ RecordedExpectation_#constraints. = constraints;
716 expectation->number_times_calledcxx . . $ RecordedExpectation_#number_times_called. = 0;
717 expectation->times_triggeredcxx . . $ RecordedExpectation_#times_triggered. = 0;
718
719 return expectation;
720 }
721
722 static void destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation) {
723 destroy_cgreen_vectorcxx . . $ destroy_cgreen_vector(fe9e7a16718af6c0).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.);
724 expectation->constraintscxx . . $ RecordedExpectation_#constraints. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
725 expectation->functioncxx . . $ RecordedExpectation_#function. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
726 expectation->test_filecxx . . $ RecordedExpectation_#test_file. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
727 expectation->test_linecxx . . $ RecordedExpectation_#test_line. = 0;
728 expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. = 0;
729 expectation->number_times_calledcxx . . $ RecordedExpectation_#number_times_called. = 0;
730 expectation->times_triggeredcxx . . $ RecordedExpectation_#times_triggered. = 0;
731
732 freecxx . . $ free(5d22bdacc48458e8).(expectation);
733 }
734
735 static void ensure_successfully_mocked_calls_list_existscxx . . $ ensure_successfully_mocked_calls_list_exists(49f6e7a06ebc5aa8).(void) {
736 if (successfully_mocked_callscxx . . $ successfully_mocked_calls. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
737 // successfully_mocked_calls are __func__, so there's nothing to destroy
738 successfully_mocked_callscxx . . $ successfully_mocked_calls. = create_cgreen_vectorcxx . . $ create_cgreen_vector(940ca2d138a76a1b).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
739 }
740 }
741
742 static void ensure_learned_mock_calls_list_existscxx . . $ ensure_learned_mock_calls_list_exists(49f6e7a06ebc5aa8).(void) {
743 if (learned_mock_callscxx . . $ learned_mock_calls. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
744 // learned_mock_calls are __func__, so there's nothing to destroy
745 learned_mock_callscxx . . $ learned_mock_calls. = create_cgreen_vectorcxx . . $ create_cgreen_vector(940ca2d138a76a1b).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
746 }
747 }
748
749 static void ensure_expectation_queue_existscxx . . $ ensure_expectation_queue_exists(49f6e7a06ebc5aa8).(void) {
750 if (global_expectation_queuecxx . . $ global_expectation_queue. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
751 global_expectation_queuecxx . . $ global_expectation_queue. = create_cgreen_vectorcxx . . $ create_cgreen_vector(940ca2d138a76a1b).((GenericDestructorcxx . . $ GenericDestructor#)&destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).);
752 }
753 }
754
755 static void remove_expectation_forcxx . . $ remove_expectation_for(85c52e162fed56f9).(const char *function) {
756 int i;
757 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(global_expectation_queuecxx . . $ global_expectation_queue.); i++) {
758 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(global_expectation_queuecxx . . $ global_expectation_queue., i);
759
760 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == expectation) {
761 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "*** CGREEN: NULL expectation found -- maybe a previous incorrect removal?");
762 continue;
763 }
764
765 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expectation->functioncxx . . $ RecordedExpectation_#function., function) == 0) {
766 cgreen_vector_removecxx . . $ cgreen_vector_remove(4c520eb064247ba8).(global_expectation_queuecxx . . $ global_expectation_queue., i);
767 return;
768 }
769 }
770 }
771
772 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_first_call_matchingcxx . . $ is_first_call_matching(182f0f58706ba67c).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation) {
773 return expectation->times_triggeredcxx . . $ RecordedExpectation_#times_triggered. == 0;
774 }
775
776
777 static void trigger_unfulfilled_expectationscxx . . $ trigger_unfulfilled_expectations(fcc853f0047efea0).(CgreenVectorcxx . . $ CgreenVector# *expectation_queue, TestReportercxx . . $ TestReporter# *reporter) {
778 for (int e = 0; e < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation_queue); e++) {
779 RecordedExpectationcxx . . $ RecordedExpectation# *expectation = (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation_queue, e);
780
781 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == expectation) {
782 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "*** NULL unfulfilled cgreen expectation found -- maybe a previous incorrect removal?");
783 continue;
784 }
785
786 if (is_always_callcxx . . $ is_always_call(182f0f58706ba67c).(expectation)) {
787 continue;
788 }
789
790 if (is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(expectation)) {
791 if (is_first_call_matchingcxx . . $ is_first_call_matching(182f0f58706ba67c).(expectation)) {
792 (*reporter->assert_truecxx . . $ TestReporter_#assert_true.)(reporter,
793 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
794 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
795 1,
796 "The mocked function [%s] was never called", expectation->functioncxx . . $ RecordedExpectation_#function.);
797 }
798 continue;
799 }
800
801 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! call_counter_present = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
802 for (int c = 0; c < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); c++) {
803 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *) cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., c);
804 if (constraint->typecxx . . $ Constraint_#type. == CGREEN_CALL_COUNTER_CONSTRAINTcxx . . $ CGREEN_CALL_COUNTER_CONSTRAINT.) {
805 constraint->executecxx . . $ Constraint_#execute.(
806 constraint,
807 expectation->functioncxx . . $ RecordedExpectation_#function.,
808 make_cgreen_integer_valuecxx . . $ make_cgreen_integer_value(1194b204c86a8e67).(expectation->number_times_calledcxx . . $ RecordedExpectation_#number_times_called.),
809 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
810 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
811 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).());
812 call_counter_present = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
813 }
814 }
815
816 if (!call_counter_present)
817 (*reporter->assert_truecxx . . $ TestReporter_#assert_true.)(
818 reporter,
819 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
820 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
821 0,
822 "Expected call was not made to mocked function [%s]", expectation->functioncxx . . $ RecordedExpectation_#function.);
823 }
824 }
825
826 static RecordedExpectationcxx . . $ RecordedExpectation# *find_expectationcxx . . $ find_expectation(7ab1b979b7dbe200).(const char *function) {
827 int i;
828 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(global_expectation_queuecxx . . $ global_expectation_queue.); i++) {
829 RecordedExpectationcxx . . $ RecordedExpectation# *expectation =
830 (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(global_expectation_queuecxx . . $ global_expectation_queue., i);
831
832 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expectation->functioncxx . . $ RecordedExpectation_#function., function) == 0) {
833 return expectation;
834 }
835 }
836 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
837 }
838
839 static void report_mock_parameter_name_not_foundcxx . . $ report_mock_parameter_name_not_found(3eedbf4d6f65432d).(TestReportercxx . . $ TestReporter# *test_reporter, RecordedExpectationcxx . . $ RecordedExpectation# *expectation, const char *constraint_parameter_name) {
840
841 test_reporter->assert_truecxx . . $ TestReporter_#assert_true.(
842 test_reporter,
843 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
844 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
845 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
846 "Mocked function [%s] did not define a parameter named [%s]. Did you misspell it in the expectation or forget it in the mock's argument list?",
847 expectation->functioncxx . . $ RecordedExpectation_#function.,
848 constraint_parameter_name);
849 }
850
851 static void apply_any_read_only_parameter_constraintscxx . . $ apply_any_read_only_parameter_constraints(13995eba0b1cdc6b).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
852 const char *parameter,
853 CgreenValuecxx . . $ CgreenValue# actual,
854 TestReportercxx . . $ TestReporter#* test_reporter) {
855 int i;
856
857 for (i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); i++) {
858 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., i);
859
860 if (is_content_settingcxx . . $ is_content_setting(1ba69099f960dda3).(constraint) || is_side_effect_constraintcxx . . $ is_side_effect_constraint(1ba69099f960dda3).(constraint)) {
861 continue;
862 }
863
864 /* TODO: we need to classify constraints better, now this
865 filters on COMPARING to not execute RETURN constraints
866 here...*/
867 if (constraint_is_not_for_parametercxx . . $ constraint_is_not_for_parameter(74f87f4455e42aa1).(constraint, parameter)) {
868 continue;
869 }
870
871 constraint->executecxx . . $ Constraint_#execute.(
872 constraint,
873 expectation->functioncxx . . $ RecordedExpectation_#function.,
874 actual,
875 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
876 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
877 test_reporter);
878 }
879 }
880
881 static void apply_any_content_setting_parameter_constraintscxx . . $ apply_any_content_setting_parameter_constraints(13995eba0b1cdc6b).(RecordedExpectationcxx . . $ RecordedExpectation# *expectation,
882 const char *parameter, CgreenValuecxx . . $ CgreenValue# actual,
883 TestReportercxx . . $ TestReporter#* test_reporter) {
884 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(expectation->constraintscxx . . $ RecordedExpectation_#constraints.); i++) {
885 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(expectation->constraintscxx . . $ RecordedExpectation_#constraints., i);
886
887 if (constraint_is_not_for_parametercxx . . $ constraint_is_not_for_parameter(74f87f4455e42aa1).(constraint, parameter)) {
888 continue;
889 }
890
891 if (constraint->typecxx . . $ Constraint_#type. != CGREEN_CONTENT_SETTER_CONSTRAINTcxx . . $ CGREEN_CONTENT_SETTER_CONSTRAINT.) {
892 continue;
893 }
894
895 constraint->executecxx . . $ Constraint_#execute.(
896 constraint,
897 expectation->functioncxx . . $ RecordedExpectation_#function.,
898 actual,
899 expectation->test_filecxx . . $ RecordedExpectation_#test_file.,
900 expectation->test_linecxx . . $ RecordedExpectation_#test_line.,
901 test_reporter);
902 }
903 }
904
905 static CgreenValuecxx . . $ CgreenValue# stored_result_or_default_forcxx . . $ stored_result_or_default_for(60202341d72e7bba).(CgreenVectorcxx . . $ CgreenVector#* constraints) {
906 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(constraints); i++) {
907 Constraintcxx . . $ Constraint# *constraint = (Constraintcxx . . $ Constraint# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(constraints, i);
908
909 switch (constraint->typecxx . . $ Constraint_#type.) {
910 case CGREEN_RETURN_VALUE_CONSTRAINTcxx . . $ CGREEN_RETURN_VALUE_CONSTRAINT.:
911 case CGREEN_RETURN_POINTER_CONSTRAINTcxx . . $ CGREEN_RETURN_POINTER_CONSTRAINT.:
912 return constraint->expected_valuecxx . . $ Constraint_#expected_value.;
913 case CGREEN_RETURN_BY_VALUE_CONSTRAINTcxx . . $ CGREEN_RETURN_BY_VALUE_CONSTRAINT.: {
914 /* When returning a struct by value we need to copy the struct
915 pointed out by the Cgreen pointer value so that it does
916 not get lost when the constraint is destroyed. The user
917 will be responsible for deallocating the copy of the struct. */
918 CgreenValuecxx . . $ CgreenValue# returnable = constraint->expected_valuecxx . . $ Constraint_#expected_value.;
919 void *the_struct = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(returnable.value_sizecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value_size.);
920 memcpycxx . . $ memcpy(cc817cb175f282d).(the_struct, returnable.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value., returnable.value_sizecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value_size.);
921 returnable.valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..pointer_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#pointer_value. = the_struct;
922 return returnable;
923 }
924 default:
925 break;
926 }
927 }
928 return (CgreenValuecxx . . $ CgreenValue#){CGREEN_INTEGERcxx . . $ CGREEN_INTEGER., {0}, 0};
929 }
930
931 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_always_callcxx . . $ is_always_call(182f0f58706ba67c).(RecordedExpectationcxx . . $ RecordedExpectation#* expectation) {
932 return expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. == UNLIMITED_TIME_TO_LIVEcxx . . $ UNLIMITED_TIME_TO_LIVE.;
933 }
934
935 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_always_expectation_forcxx . . $ have_always_expectation_for(c5f7da30cbc0f4e9).(const char* function) {
936 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(global_expectation_queuecxx . . $ global_expectation_queue.); i++) {
937 RecordedExpectationcxx . . $ RecordedExpectation# *expectation =
938 (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(global_expectation_queuecxx . . $ global_expectation_queue., i);
939 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expectation->functioncxx . . $ RecordedExpectation_#function., function) == 0) {
940 if (is_always_callcxx . . $ is_always_call(182f0f58706ba67c).(expectation)) {
941 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
942 }
943 }
944 }
945
946 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
947 }
948
949 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(RecordedExpectationcxx . . $ RecordedExpectation#* expectation) {
950 return expectation->time_to_livecxx . . $ RecordedExpectation_#time_to_live. == -UNLIMITED_TIME_TO_LIVEcxx . . $ UNLIMITED_TIME_TO_LIVE.;
951 }
952
953 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_never_call_expectation_forcxx . . $ have_never_call_expectation_for(c5f7da30cbc0f4e9).(const char* function) {
954 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(global_expectation_queuecxx . . $ global_expectation_queue.); i++) {
955 RecordedExpectationcxx . . $ RecordedExpectation# *expectation =
956 (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(global_expectation_queuecxx . . $ global_expectation_queue., i);
957 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expectation->functioncxx . . $ RecordedExpectation_#function., function) == 0) {
958 if (is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(expectation)) {
959 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
960 }
961 }
962 }
963
964 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
965 }
966
967 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! remove_never_call_expectation_forcxx . . $ remove_never_call_expectation_for(c5f7da30cbc0f4e9).(const char* function) {
968 for (int i = 0; i < cgreen_vector_sizecxx . . $ cgreen_vector_size(d6a9fa4a29061fe2).(global_expectation_queuecxx . . $ global_expectation_queue.); i++) {
969 RecordedExpectationcxx . . $ RecordedExpectation# *expectation =
970 (RecordedExpectationcxx . . $ RecordedExpectation# *)cgreen_vector_getcxx . . $ cgreen_vector_get(3d562d97df0b0b67).(global_expectation_queuecxx . . $ global_expectation_queue., i);
971 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expectation->functioncxx . . $ RecordedExpectation_#function., function) == 0) {
972 if (is_never_callcxx . . $ is_never_call(182f0f58706ba67c).(expectation)) {
973 cgreen_vector_removecxx . . $ cgreen_vector_remove(4c520eb064247ba8).(global_expectation_queuecxx . . $ global_expectation_queue., i);
974 destroy_expectationcxx . . $ destroy_expectation(de9c512e3ac46f69).(expectation);
975 }
976 }
977 }
978
979 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
980 }
981
982 /* vim: set ts=4 sw=4 et cindent: */