Debian Codegraph @

tests/constraint_messages_tests.c

raw symbols SCIP
1 /* Note: the whole point of these tests is that they should fail!
2 This makes it hard to think straight and to give the variables good
3 names ;-) */
4
5 #include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/
6 #include <cgreen/mocks.h>cxx . . $ `<file>/include/cgreen/mocks.h`/
7 #include <signal.h>
8 #include <float.h>
9 #ifdef HAVE_SYS_RESOURCE_Hcxx . . $ `<built-in>:410:9`!
10 #include <sys/resource.h>
11 #endif
12
13
14 #ifdef __cplusplus
15 using namespace cgreen;
16 #endif
17
18
19 Describecxx . . $ `include/cgreen/unit.h:12:9`!(ConstraintMessage);
20 BeforeEachcxx . . $ `include/cgreen/unit.h:15:9`!(ConstraintMessage) {}
21 AfterEachcxx . . $ `include/cgreen/unit.h:18:9`!(ConstraintMessage) {}
22
23 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage,for_is_null) {
24 int i;
25 int *pointer = &i;
26 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(pointer, is_nullcxx . . $ `include/cgreen/constraint_syntax_helpers.h:31:9`!);
27 }
28
29 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage,for_is_non_null) {
30 int *pointer = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
31 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(pointer, is_non_nullcxx . . $ `include/cgreen/constraint_syntax_helpers.h:29:9`!);
32 }
33
34 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage,for_is_equal_to) {
35 int forty_five = 45, thirty_three = 33;
36 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(forty_five, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(thirty_three));
37 }
38
39 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_equal_to_hex) {
40 unsigned char bytes[4];
41 memsetcxx . . $ memset(d1de1e4fb215f1c6).(bytes, 0xaa, sizeof(bytes));
42 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!((unsigned char) bytes[0], is_equal_to_hexcxx . . $ `include/cgreen/constraint_syntax_helpers.h:27:9`!(0xbb));
43 }
44
45 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_not_equal_to) {
46 int should_not_be_forty_five = 45, forty_five = 45;
47 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(should_not_be_forty_five, is_not_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:28:9`!(forty_five));
48 }
49
50 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_greater_than) {
51 int forty_five = 45, thirty_three = 33;
52 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(thirty_three, is_greater_thancxx . . $ `include/cgreen/constraint_syntax_helpers.h:35:9`!(forty_five));
53 }
54
55 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_less_than) {
56 int forty_five = 45, thirty_three = 33;
57 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(forty_five, is_less_thancxx . . $ `include/cgreen/constraint_syntax_helpers.h:36:9`!(thirty_three));
58 }
59
60
61 // Contents of struct/memory
62 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_equal_to_contents_of) {
63 char forty_five[45] = {45, 44, 43}, thirty_three[33] = {45, 44, 33};
64 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(thirty_three, is_equal_to_contents_ofcxx . . $ `include/cgreen/constraint_syntax_helpers.h:38:9`!(forty_five, 45));
65 }
66
67 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_not_equal_to_contents_of) {
68 int forty_five_and_up[3] = {45, 46, 47}, another_forty_five_and_up[3] = {45, 46, 47};
69 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(forty_five_and_up, is_not_equal_to_contents_ofcxx . . $ `include/cgreen/constraint_syntax_helpers.h:39:9`!(another_forty_five_and_up, 3));
70 }
71
72
73 // Strings
74 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_equal_to_string) {
75 const char *forty_five = "this string is fortyfive", *thirty_three = "this string is thirtythree";
76 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(thirty_three, is_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:41:9`!(forty_five));
77 }
78
79 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_not_equal_to_string) {
80 const char *forty_five = "this string is fortyfive", *another_forty_five = "this string is fortyfive";
81 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(another_forty_five, is_not_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:42:9`!(forty_five));
82 }
83
84 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_contains_string) {
85 const char *forty_five = "fortyfive", *not_containing_forty_five = "this text is thirtythree";
86 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(not_containing_forty_five, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!(forty_five));
87 }
88
89 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_does_not_contain_string) {
90 const char *contains_forty_five = "this string is fortyfive", *forty_five = "fortyfive";
91 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(contains_forty_five, does_not_contain_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:44:9`!(forty_five));
92 }
93
94 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_begins_with_string) {
95 const char *does_not_begin_with_forty_five = "this string does not begin with fortyfive", *forty_five = "fortyfive";
96 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(does_not_begin_with_forty_five, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!(forty_five));
97 }
98
99 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_does_not_begin_with_string) {
100 const char *begins_with_forty_five = "fortyfive is the start of this", *forty_five = "fortyfive";
101 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(begins_with_forty_five, does_not_begin_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:46:9`!(forty_five));
102 }
103
104 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_ends_with_string) {
105 const char *does_not_end_with_forty_five = "fortyfive is not the end of this string", *forty_five = "fortyfive";
106 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(does_not_end_with_forty_five, ends_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:47:9`!(forty_five));
107 }
108
109 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_does_not_end_with_string) {
110 const char *ends_with_forty_five = "this string ends with fortyfive", *forty_five = "fortyfive";
111 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(ends_with_forty_five, does_not_end_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:48:9`!(forty_five));
112 }
113
114
115 // Double
116
117 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_equal_to_double) {
118 double four_point_five = 4.5f, three_point_three = 3.3f;
119 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(four_point_five, is_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:50:9`!(three_point_three));
120 }
121
122 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_not_equal_to_double) {
123 significant_figures_for_assert_double_arecxx . . $ significant_figures_for_assert_double_are(d4f767463ce0a6b3).(4);
124 double epsilon = 1.0e-4;
125 double four_point_five = 4.5, almost_four_point_five = 4.5 - epsilon;
126 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(four_point_five, is_not_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:51:9`!(almost_four_point_five));
127 }
128
129 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_greater_than_double) {
130 double four_point_five = 4.5f, three_point_three = 3.3f;
131 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(three_point_three, is_greater_than_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:54:9`!(four_point_five));
132 }
133
134 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_less_than_double) {
135 double four_point_five = 4.5f, three_point_three = 3.3f;
136 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(four_point_five, is_less_than_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:53:9`!(three_point_three));
137 }
138
139 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_equal_to_double) {
140 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(0, is_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:50:9`!(1));
141 }
142
143 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_equal_to_double_negative) {
144 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(-1, is_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:50:9`!(-2));
145 }
146
147 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_not_equal_to_double) {
148 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(0, is_not_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:51:9`!(0));
149 }
150
151 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_not_equal_to_double_negative) {
152 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(-1, is_not_equal_to_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:51:9`!(-1));
153 }
154
155 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_less_than_double_with_accuracy) {
156 significant_figures_for_assert_double_arecxx . . $ significant_figures_for_assert_double_are(d4f767463ce0a6b3).(4);
157 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(1.0, is_less_than_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:53:9`!(1.0 - 1.0e-3 - DBL_EPSILONcxx . . $ `<external>/8223903785965736313/float.h:114:9`!));
158 }
159
160 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_is_greater_than_double_with_accuracy) {
161 significant_figures_for_assert_double_arecxx . . $ significant_figures_for_assert_double_are(d4f767463ce0a6b3).(4);
162 assert_that_doublecxx . . $ `include/cgreen/assertions.h:31:9`!(1.0, is_greater_than_doublecxx . . $ `include/cgreen/constraint_syntax_helpers.h:54:9`!(1.0 + 1.0e-3 + DBL_EPSILONcxx . . $ `<external>/8223903785965736313/float.h:114:9`!));
163 }
164
165
166 // Basic core assert_that()
167
168 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_assert_that) {
169 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(0 == 1);
170 }
171
172
173 // Mocks
174
175 void some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(int parameter) {
176 mockcxx . . $ `include/cgreen/mocks.h:34:9`!(parameter);
177 }
178
179 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_mock_called_without_expectation) {
180 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(0);
181 }
182
183 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_mock_called_more_times_than_expected) {
184 expectcxx . . $ `include/cgreen/mocks.h:21:9`!(some_mock);
185 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(0);
186 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(0);
187 }
188
189 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_mock_called_with_unexpected_parameter_value) {
190 expectcxx . . $ `include/cgreen/mocks.h:21:9`!(some_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(parameter, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(1)));
191 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(0);
192 }
193
194 /* Tests that will fail with "illegal" type of messages */
195 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_always_followed_by_expectation) {
196 always_expectcxx . . $ `include/cgreen/mocks.h:23:9`!(some_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(parameter, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(1)));
197 expectcxx . . $ `include/cgreen/mocks.h:21:9`!(some_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(parameter, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(0)));
198 }
199
200 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_violated_never_expect) {
201 never_expectcxx . . $ `include/cgreen/mocks.h:25:9`!(some_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(parameter, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(1)));
202 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(1);
203 }
204
205 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_mock_parameter_name_not_matching_constraint_parameter_name) {
206 expectcxx . . $ `include/cgreen/mocks.h:21:9`!(some_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(PARAMETER, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(0)));
207 some_mockcxx . . $ some_mock(d4f767463ce0a6b3).(0);
208 }
209
210 void forgot_to_pass_parameters_mockcxx . . $ forgot_to_pass_parameters_mock(d4f767463ce0a6b3).(int x) {
211 (void)x; // to silence compiler warning
212 mockcxx . . $ `include/cgreen/mocks.h:34:9`!();
213 }
214
215 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, for_no_mock_parameters_with_parameter_constraint) {
216 expectcxx . . $ `include/cgreen/mocks.h:21:9`!(forgot_to_pass_parameters_mock, whencxx . . $ `include/cgreen/mocks.h:38:9`!(x, is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(0)));
217 forgot_to_pass_parameters_mockcxx . . $ forgot_to_pass_parameters_mock(d4f767463ce0a6b3).(0);
218 }
219
220 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, increments_exception_count_when_terminating_via_SIGQUIT) {
221 #ifdef HAVE_SYS_RESOURCE_Hcxx . . $ `<built-in>:410:9`!
222 struct rlimitcxx . . $ rlimit# core_limit;
223 core_limit.rlim_curcxx . . $ rlimit#rlim_cur. = 1U;
224 core_limit.rlim_maxcxx . . $ rlimit#rlim_max. = 1U;
225 setrlimitcxx . . $ setrlimit(dd6e4620e125bc7d).(RLIMIT_COREcxx . . $ `<external>/1890803886155400780/resource.h:51:9`!, &core_limit);
226 #endif
227 raisecxx . . $ raise(7864480464b09eea).(SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!);
228 }
229
230 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(ConstraintMessage, increments_exception_count_when_terminating_via_SIGTERM) {
231 raisecxx . . $ raise(7864480464b09eea).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!);
232 }
233
234 #ifdef __cplusplus
235 Ensure(ConstraintMessage, for_incorrect_assert_throws) {
236 assert_throws(std::string, throw "something else");
237 }
238
239 Ensure(ConstraintMessage, for_exception_was_expected_but_nothing_thrown) {
240 assert_throws(std::string, (void)5);
241 }
242 #endif