Debian Codegraph @

tests/cute_reporter_tests.c

raw symbols SCIP
1
2 #include <cgreen/breadcrumb.h>cxx . . $ `<file>/include/cgreen/breadcrumb.h`/
3 #include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/
4 #include <cgreen/messaging.h>cxx . . $ `<file>/include/cgreen/messaging.h`/
5
6 #include <stdio.h>
7 #include <string.h>
8
9 #include <cgreen/cute_reporter.h>cxx . . $ `<file>/include/cgreen/cute_reporter.h`/
10 #include "cute_reporter_internal.h"cxx . . $ `<file>/src/cute_reporter_internal.h`/
11
12
13 #ifdef __cpluspluscxx . . $ `<built-in>:440:9`!
14 using namespace cgreen;
15 #endif
16
17 static const int linecxx . . $ line.=666;
18 static char *outputcxx . . $ output. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
19
20 static void clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).(void)
21 {
22 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`! != outputcxx . . $ output.) {
23 freecxx . . $ free(5d22bdacc48458e8).(outputcxx . . $ output.);
24 }
25
26 outputcxx . . $ output. = (char*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(1);
27 *outputcxx . . $ output. = '\0';
28 }
29
30 static char *concatcxx . . $ concat(5bd1a890f71b1efd).(char *output, char *buffer) {
31 output = (char *) realloccxx . . $ realloc(417ab160f6baadc6).(output, strlencxx . . $ strlen(751346f8406fd082).(output)+strlencxx . . $ strlen(751346f8406fd082).(buffer)+1);
32 strcatcxx . . $ strcat(b7b3a83273496486).(output, buffer);
33 return output;
34 }
35
36 static int mocked_vprintfcxx . . $ mocked_vprintf(5c80dbd47e6ebfbb).(const char *format, va_listcxx . . $ va_list# arguments) {
37 char buffer[10000];
38
39 vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(buffer, sizeof(buffer), format, arguments);
40
41 outputcxx . . $ output. = concatcxx . . $ concat(5bd1a890f71b1efd).(outputcxx . . $ output., buffer);
42 return strlencxx . . $ strlen(751346f8406fd082).(outputcxx . . $ output.);
43 }
44
45 static int mocked_printfcxx . . $ mocked_printf(581fddd72a8db8fc).(const char *format, ...) {
46 int result = 0;
47
48 va_listcxx . . $ va_list# ap;
49 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(ap, format);
50 result = mocked_vprintfcxx . . $ mocked_vprintf(5c80dbd47e6ebfbb).(format, ap);
51 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(ap);
52
53 return result;
54 }
55
56 static TestReportercxx . . $ TestReporter# *reportercxx . . $ reporter.;
57
58 static void setup_cute_reporter_testscxx . . $ setup_cute_reporter_tests(49f6e7a06ebc5aa8).(void) {
59 reportercxx . . $ reporter. = create_cute_reportercxx . . $ create_cute_reporter(a6a8ef953e197a65).();
60
61 // We can not use setup_reporting() since we are running
62 // inside a test suite which needs the real reporting
63 // So we'll have to set up the messaging explicitly
64 reportercxx . . $ reporter.->ipccxx . . $ TestReporter_#ipc. = start_cgreen_messagingcxx . . $ start_cgreen_messaging(7864480464b09eea).(666);
65
66 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
67 set_cute_reporter_printercxx . . $ set_cute_reporter_printer(ecb5d6da6d3395c).(reportercxx . . $ reporter., mocked_printfcxx . . $ mocked_printf(581fddd72a8db8fc).);
68 set_cute_reporter_vprintercxx . . $ set_cute_reporter_vprinter(6046060cadba98d3).(reportercxx . . $ reporter., mocked_vprintfcxx . . $ mocked_vprintf(5c80dbd47e6ebfbb).);
69 }
70
71 static void teardown_cute_reporter_testscxx . . $ teardown_cute_reporter_tests(49f6e7a06ebc5aa8).(void) {
72 //bad mojo when running tests in same process, as destroy_reporter also sets
73 //context.reporter = NULL, thus breaking the next test to run
74 destroy_reportercxx . . $ destroy_reporter(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
75 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != outputcxx . . $ output.) {
76 freecxx . . $ free(5d22bdacc48458e8).(outputcxx . . $ output.);
77 //need to set output to NULL to avoid second free in subsequent call to setup_cute_reporter_tests->clear_output
78 //when running tests in same process
79 outputcxx . . $ output. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
80 }
81 }
82
83 static void assert_no_outputcxx . . $ assert_no_output(49f6e7a06ebc5aa8).(void) {
84 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(strlen(output), is_equal_tocxx . . $ `include/cgreen/constraint_syntax_helpers.h:26:9`!(0));
85 }
86
87 Describecxx . . $ AfterEach_For_CuteReporter.(CuteReporter);
88 BeforeEachcxx . . $ BeforeEach_For_CuteReporter.(CuteReporter) {
89 setup_cute_reporter_testscxx . . $ setup_cute_reporter_tests(49f6e7a06ebc5aa8).();
90 }
91 AfterEachcxx . . $ AfterEach_For_CuteReporter.(CuteReporter) {
92 teardown_cute_reporter_testscxx . . $ teardown_cute_reporter_tests(49f6e7a06ebc5aa8).();
93 }
94
95 Ensurecxx . . $ CgreenTest#(CuteReporter, will_report_beginning_of_suite) {
96 reportercxx . . $ reporter.->start_suitecxx . . $ TestReporter_#start_suite.(reportercxx . . $ reporter., "suite_name", 2);
97 assert_thatcxx . . $ intptr_t#(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#beginning"));
98 assert_thatcxx . . $ cgreen/(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("suite_name"));
99 }
100
101 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(CuteReporter, will_report_beginning_and_successful_finishing_of_test) {
102 va_listcxx . . $ va_list# arguments;
103
104 reportercxx . . $ reporter.->start_testcxx . . $ TestReporter_#start_test.(reportercxx . . $ reporter., "test_name");
105 assert_thatcxx . . $ output.(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#starting"));
106 assert_thatcxx . . $ intptr_t#(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("test_name"));
107
108 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
109
110 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&arguments, 0, sizeof(va_listcxx . . $ va_list#));
111 reportercxx . . $ reporter.->show_passcxx . . $ TestReporter_#show_pass.(reportercxx . . $ reporter., "file", 2, "test_name", arguments);
112 assert_no_outputcxx . . $ assert_no_output(49f6e7a06ebc5aa8).();
113
114 // Must indicate test case completion before calling finish_test()
115 send_reporter_completion_notificationcxx . . $ send_reporter_completion_notification(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
116 reportercxx . . $ reporter.->finish_testcxx . . $ TestReporter_#finish_test.(reportercxx . . $ reporter., "filename", linecxx . . $ line., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!);
117 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#success"));
118 assert_thatcxx . . $ output.(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("test_name"));
119 }
120
121 Ensurecxx . . $ CuteReporter__will_report_failing_of_test_only_once(49f6e7a06ebc5aa8).(CuteReporter, will_report_failing_of_test_only_once) {
122 va_listcxx . . $ va_list# arguments;
123
124 reportercxx . . $ reporter.->start_testcxx . . $ TestReporter_#start_test.(reportercxx . . $ reporter., "test_name");
125
126 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
127 reportercxx . . $ reporter.->failurescxx . . $ TestReporter_#failures.++; // Simulating a failed assert
128 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&arguments, 0, sizeof(va_listcxx . . $ va_list#));
129 reportercxx . . $ reporter.->show_failcxx . . $ TestReporter_#show_fail.(reportercxx . . $ reporter., "file", 2, "test_name", arguments);
130 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#failure"));
131 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("test_name"));
132
133 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
134 reportercxx . . $ reporter.->failurescxx . . $ TestReporter_#failures.++; // Simulating another failed assert
135 reportercxx . . $ reporter.->show_failcxx . . $ TestReporter_#show_fail.(reportercxx . . $ reporter., "file", 2, "test_name", arguments);
136 assert_no_outputcxx . . $ assert_no_output(49f6e7a06ebc5aa8).();
137
138 // Must indicate test case completion before calling finish_test()
139 send_reporter_completion_notificationcxx . . $ send_reporter_completion_notification(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
140 reportercxx . . $ reporter.->finish_testcxx . . $ TestReporter_#finish_test.(reportercxx . . $ reporter., "filename", linecxx . . $ line., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!);
141 assert_no_outputcxx . . $ assert_no_output(49f6e7a06ebc5aa8).();
142 }
143
144 static void wrapped_show_failcxx . . $ wrapped_show_fail(f41b995409722d28).(TestReportercxx . . $ TestReporter# *reporter, const char *file, int line,
145 const char *message, ...) {
146 va_listcxx . . $ va_list# arguments;
147 va_startcxx . . $ `<external>/8293021631987149590/stdarg.h:51:9`!(arguments, message);
148 reporter->show_failcxx . . $ TestReporter_#show_fail.(reporter, file, line, message, arguments);
149 va_endcxx . . $ `<external>/8293021631987149590/stdarg.h:53:9`!(arguments);
150 }
151
152 Ensurecxx . . $ CgreenSpec__CuteReporter__will_use_arguments_for_show_fail__.(CuteReporter, will_use_arguments_for_show_fail) {
153 reportercxx . . $ reporter.->start_testcxx . . $ TestReporter_#start_test.(reportercxx . . $ reporter., "test_name");
154
155 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
156 reportercxx . . $ reporter.->failurescxx . . $ TestReporter_#failures.++; // Simulating a failed assert
157 wrapped_show_failcxx . . $ wrapped_show_fail(f41b995409722d28).(reportercxx . . $ reporter., "file", 2, "test_case %i provides %s", 42, "the answer");
158 assert_thatcxx . . $ output.(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#failure"));
159 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("test_case 42 provides the answer"));
160
161 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
162
163 // Must indicate test case completion before calling finish_test()
164 send_reporter_completion_notificationcxx . . $ send_reporter_completion_notification(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
165 reportercxx . . $ reporter.->finish_testcxx . . $ TestReporter_#finish_test.(reportercxx . . $ reporter., "filename", linecxx . . $ line., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
166 assert_no_outputcxx . . $ assert_no_output(49f6e7a06ebc5aa8).();
167 }
168
169 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(CuteReporter, will_report_finishing_of_suite) {
170 // Must indicate test suite completion before calling finish_suite()
171 reportercxx . . $ reporter.->start_suitecxx . . $ TestReporter_#start_suite.(reportercxx . . $ reporter., "suite_name", 1);
172
173 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
174
175 send_reporter_completion_notificationcxx . . $ send_reporter_completion_notification(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
176 reportercxx . . $ reporter.->finish_suitecxx . . $ TestReporter_#finish_suite.(reportercxx . . $ reporter., "filename", linecxx . . $ line.);
177
178 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#ending"));
179 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("suite_name"));
180 }
181
182 Ensurecxx . . $ contextForCuteReporter.(CuteReporter, will_report_non_finishing_test) {
183 const int line = 666;
184 reportercxx . . $ reporter.->start_suitecxx . . $ TestReporter_#start_suite.(reportercxx . . $ reporter., "suite_name", 1);
185 clear_outputcxx . . $ clear_output(49f6e7a06ebc5aa8).();
186
187 send_reporter_exception_notificationcxx . . $ send_reporter_exception_notification(1083e9dac9de8fd0).(reportercxx . . $ reporter.);
188 reportercxx . . $ reporter.->finish_suitecxx . . $ TestReporter_#finish_suite.(reportercxx . . $ reporter., "filename", line);
189
190 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(output, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("#error"));
191 assert_thatcxx . . $ cgreen/assert_that_(b064aa216885589).(output, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("failed to complete"));
192 }
193
194 TestSuitecxx . . $ TestSuite# *cute_reporter_testscxx . . $ cute_reporter_tests(564401a81ded3a53).(void) {
195 TestSuitecxx . . $ TestSuite# *suite = create_test_suitecxx . . $ `include/cgreen/suite.h:20:9`!();
196 set_setupcxx . . $ set_setup(375347ed146b1459).(suite, setup_cute_reporter_testscxx . . $ setup_cute_reporter_tests(49f6e7a06ebc5aa8).);
197
198 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, CuteReporter, will_report_beginning_of_suite);
199 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, CuteReporter, will_report_beginning_and_successful_finishing_of_test);
200 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, CuteReporter, will_report_failing_of_test_only_once);
201 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, CuteReporter, will_report_finishing_of_suite);
202 add_test_with_contextcxx . . $ `include/cgreen/suite.h:23:9`!(suite, CuteReporter, will_report_non_finishing_test);
203
204 set_teardowncxx . . $ set_teardown(375347ed146b1459).(suite, teardown_cute_reporter_testscxx . . $ teardown_cute_reporter_tests(49f6e7a06ebc5aa8).);
205 return suite;
206 }