00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TESTSOON_XML_REPORTER_HPP
00030 #define TESTSOON_XML_REPORTER_HPP
00031
00032 #include "../testsoon.hpp"
00033
00034 namespace testsoon {
00035
00036 class xml_reporter : public test_reporter {
00037 public:
00038 typedef stream_class stream;
00039 xml_reporter(stream &out) : out(out), indent(1) {}
00040
00041 void start() {
00042 out << "<?xml version=\"1.0\"?>\n";
00043 out << "<testsoon>\n";
00044 }
00045 void stop() {
00046 out << "</testsoon>\n";
00047 }
00048
00049 void begin_group(test_group const &group) {
00050 if (group.parent) {
00051 print_ind();
00052 ++indent;
00053 if (group.parent->parent)
00054 out << "<group";
00055 else
00056 out << "<file";
00057 out << " name=\"" << group.name << "\">\n";
00058 }
00059 }
00060
00061 void end_group(test_group const &group) {
00062 if (group.parent) {
00063 --indent;
00064 print_ind();
00065 if (group.parent->parent)
00066 out << "</group>\n";
00067 else
00068 out << "</file>\n";
00069 }
00070 }
00071
00072 void success(test_info const &i, string const &k) {
00073 print_ind() << "<success line=\"" << i.line << "\"";
00074 if (*i.name)
00075 out << " name=\"" << i.name << "\"";
00076 if (k.empty())
00077 out << " />\n";
00078 else {
00079 out << ">\n";
00080 ++indent;
00081 print_ind() << "<generator>" << k << "</generator>\n";
00082 --indent;
00083 print_ind() << "</success>\n";
00084 }
00085 }
00086
00087 void failure(test_info const &i, test_failure const &x, string const &k) {
00088 print_ind() << "<failure line=\"" << i.line << "\"";
00089 if (*i.name)
00090 out << " name=\"" << i.name << "\"";
00091 out << ">\n";
00092 ++indent;
00093
00094 print_ind() << "<problem>" << x.message << "</problem>\n";
00095 if (!x.data.empty()) {
00096 print_ind() << "<rawdata>\n";
00097 ++indent;
00098 for (string_vector::const_iterator it = x.data.begin();
00099 it != x.data.end();
00100 ++it) {
00101 print_ind() << "<item>" << *it << "</item>\n";
00102 }
00103 --indent;
00104 print_ind() << "</rawdata>\n";
00105 }
00106
00107 if (!k.empty()) {
00108 print_ind() << "<generator>" << k << "</generator>\n";
00109 }
00110
00111 --indent;
00112 print_ind() << "</failure>\n";
00113 }
00114
00115 private:
00116 stream_class &print_ind() {
00117 for (unsigned i = 0; i < indent; ++i)
00118 out << " ";
00119 return out;
00120 }
00121
00122 stream &out;
00123 unsigned indent;
00124 };
00125
00126 }
00127
00128 #endif