Debian Codegraph @

doc/tutorial_src/xml_reporter4.c

raw symbols SCIP
1 #include <cgreen/reporter.h>
2 #include <cgreen/breadcrumb.h>
3
4 #include <stdio.h>
5 #include "xml_reporter.h"
6
7 static void indent(TestReporter *reporter) {
8 int depth = get_breadcrumb_depth((CgreenBreadcrumb *)reporter->breadcrumb);
9 while (depth-- > 0) {
10 printf("\t");
11 }
12 }
13
14 static void xml_reporter_start_suite(TestReporter *reporter, const char *name, int count) {
15 if (get_breadcrumb_depth((CgreenBreadcrumb *)reporter->breadcrumb) == 0) {
16 printf("<?xml?>\n");
17 }
18 indent(reporter);
19 printf("<suite name=\"%s\">\n", name);
20 reporter_start_suite(reporter, name, count);
21 }
22
23 static void xml_reporter_start_test(TestReporter *reporter, const char *name) {
24 indent(reporter);
25 printf("<test name=\"%s\">\n", name);
26 reporter_start_test(reporter, name);
27 }
28
29 static void xml_show_fail(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
30 indent(reporter);
31 printf("<fail>\n");
32 indent(reporter);
33 printf("\t<message>");
34 vprintf(message, arguments);
35 printf("</message>\n");
36 indent(reporter);
37 printf("\t<location file=\"%s\" line=\"%d\"/>\n", file, line);
38 indent(reporter);
39 printf("</fail>\n");
40 }
41
42 static void xml_show_incomplete(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
43 indent(reporter);
44 printf("<fail>\n");
45 indent(reporter);
46 printf("\t<message>Failed to complete</message>\n");
47 indent(reporter);
48 printf("</fail>\n");
49 }
50
51
52 static void xml_reporter_finish_test(TestReporter *reporter, const char *filename, int line, const char *message) {
53 reporter_finish_test(reporter, filename, line, message);
54 indent(reporter);
55 printf("</test>\n");
56 }
57
58 static void xml_reporter_finish_suite(TestReporter *reporter, const char *filename, int line) {
59 reporter_finish_suite(reporter, filename, line);
60 indent(reporter);
61 printf("</suite>\n");
62 }
63
64 TestReporter *create_xml_reporter() {
65 TestReporter *reporter = create_reporter();
66 reporter->start_suite = &xml_reporter_start_suite;
67 reporter->start_test = &xml_reporter_start_test;
68 reporter->show_fail = &xml_show_fail;
69 reporter->show_incomplete = &xml_show_incomplete;
70 reporter->finish_test = &xml_reporter_finish_test;
71 reporter->finish_suite = &xml_reporter_finish_suite;
72 return reporter;
73 }