~brianaker/libmemcached/gear-clean

« back to all changes in this revision

Viewing changes to libtest/formatter.cc

  • Committer: Continuous Integration
  • Date: 2014-02-01 14:30:50 UTC
  • mfrom: (1174.1.10 libmemcached-1.0)
  • Revision ID: ci@tangent.org-20140201143050-39jzc18bxcrd3gj6
Merge lp:~brianaker/libmemcached/1215783 Build: jenkins-Libmemcached-438

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
  
45
45
namespace libtest {
46
46
 
 
47
std::string& escape4XML(std::string const& arg, std::string& escaped_string)
 
48
{
 
49
  escaped_string.clear();
 
50
 
 
51
  escaped_string+= '"';
 
52
  for (std::string::const_iterator x= arg.begin(), end= arg.end(); x != end; ++x)
 
53
  {
 
54
    unsigned char c= *x;
 
55
    if (c == '&')
 
56
    {
 
57
      escaped_string+= "&";
 
58
    }
 
59
    else if (c == '>')
 
60
    {
 
61
      escaped_string+= ">";
 
62
    }
 
63
    else if (c == '<')
 
64
    {
 
65
      escaped_string+= "&lt;";
 
66
    }
 
67
    else if (c == '\'')
 
68
    {
 
69
      escaped_string+= "&apos;";  break;
 
70
    }
 
71
    else if (c == '"')
 
72
    {
 
73
      escaped_string+= "&quot;";
 
74
    }
 
75
    else if (c == ' ')
 
76
    {
 
77
      escaped_string+= ' ';
 
78
    }
 
79
    else if (isalnum(c))
 
80
    {
 
81
      escaped_string+= c;
 
82
    }
 
83
    else 
 
84
    {
 
85
      char const* const hexdig= "0123456789ABCDEF";
 
86
      escaped_string+= "&#x";
 
87
      escaped_string+= hexdig[c >> 4];
 
88
      escaped_string+= hexdig[c & 0xF];
 
89
      escaped_string+= ';';
 
90
    }
 
91
  }
 
92
  escaped_string+= '"';
 
93
 
 
94
  return escaped_string;
 
95
}
 
96
 
47
97
class TestCase {
48
98
public:
49
99
  TestCase(const std::string& arg):
110
160
void Formatter::skipped()
111
161
{
112
162
  current()->result(TEST_SKIPPED);
113
 
  Out << name() << "." << current()->name() <<  "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
 
163
  Out << name() << "." 
 
164
      << current()->name()
 
165
      <<  "\t\t\t\t\t" 
 
166
      << "[ " << test_strerror(current()->result()) << " ]";
114
167
 
115
168
  reset();
116
169
}
120
173
  assert(current());
121
174
  current()->result(TEST_FAILURE);
122
175
 
123
 
  Out << name() << "." << current()->name() <<  "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
 
176
  Out << name()
 
177
    << "." << current()->name() <<  "\t\t\t\t\t" 
 
178
    << "[ " << test_strerror(current()->result()) << " ]";
124
179
 
125
180
  reset();
126
181
}
129
184
{
130
185
  assert(current());
131
186
  current()->result(TEST_SUCCESS, timer_);
 
187
  std::string escaped_string;
132
188
 
133
189
  Out << name() << "."
134
190
    << current()->name()
141
197
 
142
198
void Formatter::xml(libtest::Framework& framework_, std::ofstream& output)
143
199
{
144
 
  output << "<testsuites name=\"" << framework_.name() << "\">" << std::endl;
 
200
  std::string escaped_string;
 
201
 
 
202
  output << "<testsuites name=" 
 
203
    << escape4XML(framework_.name(), escaped_string) << ">" << std::endl;
 
204
 
145
205
  for (Suites::iterator framework_iter= framework_.suites().begin();
146
206
       framework_iter != framework_.suites().end();
147
207
       ++framework_iter)
148
208
  {
149
 
    output << "\t<testsuite name=\"" << (*framework_iter)->name() << "\"  classname=\"\" package=\"\">" << std::endl;
 
209
    output << "\t<testsuite name=" 
 
210
      << escape4XML((*framework_iter)->name(), escaped_string)
 
211
#if 0
 
212
      << "  classname=\"\" package=\"\"" 
 
213
#endif
 
214
      << ">" << std::endl;
150
215
 
151
216
    for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin();
152
217
         case_iter != (*framework_iter)->formatter()->testcases().end();
153
218
         ++case_iter)
154
219
    {
155
 
      output << "\t\t<testcase name=\"" 
156
 
        << (*case_iter)->name() 
157
 
        << "\" time=\"" 
 
220
      output << "\t\t<testcase name=" 
 
221
        << escape4XML((*case_iter)->name(), escaped_string)
 
222
        << " time=\"" 
158
223
        << (*case_iter)->timer().elapsed_milliseconds() 
159
 
        << "\">" 
160
 
        << std::endl;
 
224
        << "\""; 
161
225
 
162
226
      switch ((*case_iter)->result())
163
227
      {
164
228
        case TEST_SKIPPED:
 
229
        output << ">" << std::endl;
165
230
        output << "\t\t <skipped/>" << std::endl;
 
231
        output << "\t\t</testcase>" << std::endl;
166
232
        break;
167
233
 
168
234
        case TEST_FAILURE:
 
235
        output << ">" << std::endl;
169
236
        output << "\t\t <failure message=\"\" type=\"\"/>"<< std::endl;
 
237
        output << "\t\t</testcase>" << std::endl;
170
238
        break;
171
239
 
172
240
        case TEST_SUCCESS:
 
241
        output << "/>" << std::endl;
173
242
        break;
174
243
      }
175
 
      output << "\t\t</testcase>" << std::endl;
176
244
    }
177
245
    output << "\t</testsuite>" << std::endl;
178
246
  }