Debian Codegraph @

src/assertions.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/assertions.c`/include <cgreen/assertions.h>cxx . . $ `<file>/include/cgreen/assertions.h`/
2 #include <cgreen/boxed_double.h>cxx . . $ `<file>/include/cgreen/boxed_double.h`/
3 #include <cgreen/constraint_syntax_helpers.h>cxx . . $ `<file>/include/cgreen/constraint_syntax_helpers.h`/
4 #include <cgreen/message_formatting.h>cxx . . $ `<file>/include/cgreen/message_formatting.h`/
5 #include <cgreen/reporter.h>cxx . . $ `<file>/include/cgreen/reporter.h`/
6 #include <cgreen/string_comparison.h>cxx . . $ `<file>/include/cgreen/string_comparison.h`/
7
8 #include <stdint.h>
9 #include <inttypes.h>
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <float.h>
15
16
17 #include "cgreen_value_internal.h"cxx . . $ `<file>/src/cgreen_value_internal.h`/
18 #include "constraint_internal.h"cxx . . $ `<file>/src/constraint_internal.h`/
19
20
21 const char *show_null_as_the_string_nullcxx . . $ show_null_as_the_string_null(fb58d2e09a2a1ce6).(const char *string);
22
23
24 void assert_core_cxx . . $ assert_core_(7e860a4f442fe6d4).(const char *file, int line, const char *actual_string, intptr_tcxx . . $ intptr_t# actual,
25 Constraintcxx . . $ Constraint#* constraint) {
26
27 char *failure_message;
28
29 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != constraint && is_not_comparingcxx . . $ is_not_comparing(1ba69099f960dda3).(constraint)) {
30 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
31 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
32 file,
33 line,
34 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
35 "Got constraint of type [%s],\n"
36 "\t\tbut they are not allowed for assertions, only in mock expectations.",
37 constraint->namecxx . . $ Constraint_#name.);
38
39 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
40
41 return;
42 }
43
44 if (constraint->typecxx . . $ Constraint_#type. == CGREEN_DOUBLE_COMPARER_CONSTRAINTcxx . . $ CGREEN_DOUBLE_COMPARER_CONSTRAINT.) {
45 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
46 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
47 file,
48 line,
49 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
50 "Constraints of double type, such as [%s],\n"
51 "\t\tshould only be used with 'assert_that_double()' to ensure proper comparison.",
52 constraint->namecxx . . $ Constraint_#name.);
53 }
54
55 if (parameters_are_not_valid_forcxx . . $ parameters_are_not_valid_for(908815a3afc9f0a1).(constraint, actual)) {
56 char *validation_message = validation_failure_message_forcxx . . $ validation_failure_message_for(61ddab92ee18b24e).(constraint, actual);
57
58 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
59 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
60 file,
61 line,
62 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
63 validation_message);
64
65 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
66 freecxx . . $ free(5d22bdacc48458e8).(validation_message);
67 return;
68 }
69
70 failure_message = constraint->failure_messagecxx . . $ Constraint_#failure_message.(constraint, actual_string, actual);
71
72 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
73 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
74 file,
75 line,
76 (*constraint->comparecxx . . $ Constraint_#compare.)(constraint, make_cgreen_integer_valuecxx . . $ make_cgreen_integer_value(1194b204c86a8e67).(actual)),
77 failure_message
78 );
79
80 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
81 freecxx . . $ free(5d22bdacc48458e8).(failure_message);
82 }
83
84 void assert_that_double_cxx . . $ assert_that_double_(12bd53f56e56b98f).(const char *file, int line, const char *expression, double actual, Constraintcxx . . $ Constraint#* constraint) {
85 BoxedDoublecxx . . $ BoxedDouble#* boxed_actual;
86
87 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != constraint && is_not_comparingcxx . . $ is_not_comparing(1ba69099f960dda3).(constraint)) {
88 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
89 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
90 file,
91 line,
92 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
93 "Got constraint of type [%s],\n"
94 "\t\tbut they are not allowed for assertions, only in mock expectations.",
95 constraint->namecxx . . $ Constraint_#name.);
96
97 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
98
99 return;
100 }
101
102 if (constraint->typecxx . . $ Constraint_#type. != CGREEN_DOUBLE_COMPARER_CONSTRAINTcxx . . $ CGREEN_DOUBLE_COMPARER_CONSTRAINT.) {
103 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
104 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
105 file,
106 line,
107 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
108 "Only constraints of double type should be used with 'assert_that_double()'.\n"
109 "\t\tOther types of constraints, such as [%s], will probably fail comparison.",
110 constraint->namecxx . . $ Constraint_#name.);
111 }
112
113 boxed_actual = (BoxedDoublecxx . . $ BoxedDouble#*)box_doublecxx . . $ box_double(a6e4a4c8b00c35a3).(actual);
114
115 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(), file, line,
116 (*constraint->comparecxx . . $ Constraint_#compare.)(constraint, make_cgreen_double_valuecxx . . $ make_cgreen_double_value(4e2bf7528ffbaa1f).(actual)),
117 "Expected [%s] to [%s] [%s] within [%d] significant figures\n"
118 "\t\tactual value:\t\t\t[%08f]\n"
119 "\t\texpected value:\t\t\t[%08f]",
120 expression,
121 constraint->namecxx . . $ Constraint_#name.,
122 constraint->expected_value_namecxx . . $ Constraint_#expected_value_name.,
123 get_significant_figurescxx . . $ get_significant_figures(b126dc7c1de90089).(),
124 actual,
125 constraint->expected_valuecxx . . $ Constraint_#expected_value..valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#value..double_valuecxx . . $ $anonymous_type_b16cac6eed758fe0_1#$anonymous_type_2#double_value.);
126
127 freecxx . . $ free(5d22bdacc48458e8).(boxed_actual);
128 constraint->destroycxx . . $ Constraint_#destroy.(constraint);
129 }
130
131 void assert_equal_cxx . . $ assert_equal_(cfdabd75ecfd189b).(const char *file, int line, const char *expression, intptr_tcxx . . $ intptr_t# tried, intptr_tcxx . . $ intptr_t# expected) {
132 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
133 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
134 file,
135 line,
136 (tried == expected),
137 "[%s] should be [%" PRIdPTRcxx . . $ `<external>/15933738808807975373/inttypes.h:165:10`! "] but was [%" PRIdPTRcxx . . $ `<external>/15933738808807975373/inttypes.h:165:10`! "]\n", expression, expected, tried);
138 }
139
140 void assert_not_equal_cxx . . $ assert_not_equal_(cfdabd75ecfd189b).(const char *file, int line, const char *expression, intptr_tcxx . . $ intptr_t# tried, intptr_tcxx . . $ intptr_t# expected) {
141 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
142 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
143 file,
144 line,
145 (tried != expected),
146 "[%s] should not be [%" PRIdPTRcxx . . $ `<external>/15933738808807975373/inttypes.h:165:10`! "] but was\n", expression, expected);
147 }
148
149 void assert_double_equal_cxx . . $ assert_double_equal_(f258a07107a41aca).(const char *file, int line, const char *expression, double tried, double expected) {
150 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
151 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
152 file,
153 line,
154 doubles_are_equalcxx . . $ doubles_are_equal(828b76dce88fac).(tried, expected),
155 "[%s] should be [%f] within %d significant figures but was [%f]\n", expression, expected, get_significant_figurescxx . . $ get_significant_figures(b126dc7c1de90089).(), tried);
156 }
157
158 void assert_double_not_equal_cxx . . $ assert_double_not_equal_(f258a07107a41aca).(const char *file, int line, const char *expression, double tried, double expected) {
159 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
160 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
161 file,
162 line,
163 ! doubles_are_equalcxx . . $ doubles_are_equal(828b76dce88fac).(tried, expected),
164 "[%s] should not be [%f] within %d significant figures but was [%f]\n", expression, expected, get_significant_figurescxx . . $ get_significant_figures(b126dc7c1de90089).(), tried);
165 }
166
167 void assert_string_equal_cxx . . $ assert_string_equal_(35ecd74ea3711e56).(const char *file, int line, const char *expression, const char *tried, const char *expected) {
168 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
169 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
170 file,
171 line,
172 strings_are_equalcxx . . $ strings_are_equal(b7a7aa4a824b7595).(tried, expected),
173 "[%s] should be [%s] but was [%s]\n", expression, show_null_as_the_string_nullcxx . . $ show_null_as_the_string_null(fb58d2e09a2a1ce6).(expected), show_null_as_the_string_nullcxx . . $ show_null_as_the_string_null(fb58d2e09a2a1ce6).(tried));
174 }
175
176 void assert_string_not_equal_cxx . . $ assert_string_not_equal_(35ecd74ea3711e56).(const char *file, int line, const char *expression, const char *tried, const char *expected) {
177 (*get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).()->assert_truecxx . . $ TestReporter_#assert_true.)(
178 get_test_reportercxx . . $ get_test_reporter(a6a8ef953e197a65).(),
179 file,
180 line,
181 ! strings_are_equalcxx . . $ strings_are_equal(b7a7aa4a824b7595).(tried, expected),
182 "[%s] should not be [%s] but was\n", expression, show_null_as_the_string_nullcxx . . $ show_null_as_the_string_null(fb58d2e09a2a1ce6).(expected));
183 }
184
185 const char *show_null_as_the_string_nullcxx . . $ show_null_as_the_string_null(fb58d2e09a2a1ce6).(const char *string) {
186 return (string == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! ? "NULL" : string);
187 }
188
189
190 /* vim: set ts=4 sw=4 et cindent: */