HelenOS sources
This source file includes following definitions.
- xml_init
- xml_suite_start
- xml_suite_done
- xml_test_start
- print_by_lines
- xml_test_done
- xml_done
#include "../internal.h"
#include "report.h"
#ifndef __helenos__
#pragma warning(push, 0)
#include <string.h>
#pragma warning(pop)
#endif
#pragma warning(push, 0)
#include <stdio.h>
#pragma warning(pop)
static int test_counter;
static int tests_in_suite;
static int failed_tests_in_suite;
static void xml_init(pcut_item_t *all_items) {
int tests_total = pcut_count_tests(all_items);
test_counter = 0;
printf("<?xml version=\"1.0\"?>\n");
printf("<report tests-total=\"%d\">\n", tests_total);
}
static void xml_suite_start(pcut_item_t *suite) {
tests_in_suite = 0;
failed_tests_in_suite = 0;
printf("\t<suite name=\"%s\">\n", suite->name);
}
static void xml_suite_done(pcut_item_t *suite) {
printf("\t</suite><!-- %s: %d / %d -->\n", suite->name,
failed_tests_in_suite, tests_in_suite);
}
static void xml_test_start(pcut_item_t *test) {
PCUT_UNUSED(test);
tests_in_suite++;
test_counter++;
}
static void print_by_lines(const char *message, const char *element_name) {
char *next_line_start;
if ((message == NULL) || (message[0] == 0)) {
return;
}
printf("\t\t\t<%s><![CDATA[", element_name);
next_line_start = pcut_str_find_char(message, '\n');
while (next_line_start != NULL) {
next_line_start[0] = 0;
printf("%s\n", message);
message = next_line_start + 1;
next_line_start = pcut_str_find_char(message, '\n');
}
if (message[0] != 0) {
printf("%s\n", message);
}
printf("]]></%s>\n", element_name);
}
static void xml_test_done(pcut_item_t *test, int outcome,
const char *error_message, const char *teardown_error_message,
const char *extra_output) {
const char *test_name = test->name;
const char *status_str = NULL;
if (outcome != PCUT_OUTCOME_PASS) {
failed_tests_in_suite++;
}
switch (outcome) {
case PCUT_OUTCOME_PASS:
status_str = "pass";
break;
case PCUT_OUTCOME_FAIL:
status_str = "fail";
break;
default:
status_str = "error";
break;
}
printf("\t\t<testcase name=\"%s\" status=\"%s\">\n", test_name,
status_str);
print_by_lines(error_message, "error-message");
print_by_lines(teardown_error_message, "error-message");
print_by_lines(extra_output, "standard-output");
printf("\t\t</testcase><!-- %s -->\n", test_name);
}
static void xml_done(void) {
printf("</report>\n");
}
pcut_report_ops_t pcut_report_xml = {
xml_init, xml_done,
xml_suite_start, xml_suite_done,
xml_test_start, xml_test_done
};
HelenOS homepage, sources at GitHub