| 1 | #include <cgreen/reporter.h> |
| 2 | #include <cgreen/breadcrumb.h> |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include "xml_reporter.h" |
| 6 | |
| 7 | |
| 8 | static void xml_reporter_start_suite(TestReporter *reporter, const char *name, int count) { |
| 9 | printf("<suite name=\"%s\">\n", name); |
| 10 | reporter_start_suite(reporter, name, count); |
| 11 | } |
| 12 | |
| 13 | static void xml_reporter_start_test(TestReporter *reporter, const char *name) { |
| 14 | printf("<test name=\"%s\">\n", name); |
| 15 | reporter_start_test(reporter, name); |
| 16 | } |
| 17 | |
| 18 | static void xml_show_fail(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) { |
| 19 | printf("<fail>\n"); |
| 20 | printf("\t<message>"); |
| 21 | vprintf(message, arguments); |
| 22 | printf("</message>\n"); |
| 23 | printf("\t<location file=\"%s\" line=\"%d\"/>\n", file, line); |
| 24 | printf("</fail>\n"); |
| 25 | } |
| 26 | |
| 27 | static void xml_show_incomplete(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) { |
| 28 | printf("<fail>\n"); |
| 29 | printf("\t<message>Failed to complete</message>\n"); |
| 30 | printf("</fail>\n"); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | static void xml_reporter_finish_test(TestReporter *reporter, const char *filename, int line, const char *message) { |
| 35 | reporter_finish_test(reporter, filename, line, message); |
| 36 | printf("</test>\n"); |
| 37 | } |
| 38 | |
| 39 | static void xml_reporter_finish_suite(TestReporter *reporter, const char *filename, int line) { |
| 40 | reporter_finish_suite(reporter, filename, line); |
| 41 | printf("</suite>\n"); |
| 42 | } |
| 43 | |
| 44 | TestReporter *create_xml_reporter() { |
| 45 | TestReporter *reporter = create_reporter(); |
| 46 | reporter->start_suite = &xml_reporter_start_suite; |
| 47 | reporter->start_test = &xml_reporter_start_test; |
| 48 | reporter->show_fail = &xml_show_fail; |
| 49 | reporter->show_incomplete = &xml_show_incomplete; |
| 50 | reporter->finish_test = &xml_reporter_finish_test; |
| 51 | reporter->finish_suite = &xml_reporter_finish_suite; |
| 52 | return reporter; |
| 53 | } |