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