File: xml_reporter.c

package info (click to toggle)
libdbi-drivers 0.9.0-13
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,160 kB
  • sloc: ansic: 19,030; sh: 10,963; xml: 2,759; makefile: 584
file content (66 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (6)
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
#include "xml_reporter.h"
#include <cgreen/reporter.h>
#include <cgreen/breadcrumb.h>
#include <stdio.h>
#include <stdarg.h>

static indent(TestReporter *reporter);
static void xml_reporter_start(TestReporter *reporter, const char *name);
static void xml_reporter_finish(TestReporter *reporter, const char *name);
static void xml_show_fail(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments);
static void xml_show_incomplete(TestReporter *reporter, const char *name);

TestReporter *create_xml_reporter() {
    TestReporter *reporter = create_reporter();
	reporter->start_suite = &xml_reporter_start;
	reporter->start_test = &xml_reporter_start;
	reporter->show_fail = &xml_show_fail;
	reporter->show_incomplete = &xml_show_incomplete;
	reporter->finish_test = &xml_reporter_finish;
	reporter->finish_suite = &xml_reporter_finish;
    return reporter;
}

static indent(TestReporter *reporter) {
    int depth = get_breadcrumb_depth((Breadcrumb *)reporter->breadcrumb);
    while (depth-- > 0) {
        printf("\t");
    }
}

static void xml_reporter_start(TestReporter *reporter, const char *name) {
    if (get_breadcrumb_depth((Breadcrumb *)reporter->breadcrumb) == 0) {
        printf("<?xml?>\n");
    }
	indent(reporter);
	printf("<test name=\"%s\">\n", name);
	reporter_start(reporter, name);
}

static void xml_reporter_finish(TestReporter *reporter, const char *name) {
	reporter_finish(reporter, name);
	indent(reporter);
	printf("</test>\n");
}

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><![CDATA[");
    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><![CDATA[Failed to complete]]></message>\n");
	indent(reporter);
    printf("</fail>\n");
}