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