Debian Codegraph @

doc/tutorial_src/xml_reporter.c

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