Xalan-C++ API Reference 1.12.0
XalanXMLFileReporter.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(HARNESS_HEADER_GUARD_1357924680)
19#define HARNESS_HEADER_GUARD_1357924680
20
21
22
24
25
26
27#include <cstdio>
28
29
30
32
33
34
38
39
40
42
43
44
45namespace XALAN_CPP_NAMESPACE {
46
47
48
49class XalanOutputTranscoder;
50
52{
53
54public:
55
57
58 typedef std::FILE FileHandleType;
59
60public:
61
62
63 // Construct and initialize this reporter with specified filename, if
64 // the filename is not empty.
65 XalanXMLFileReporter(MemoryManager& theManager, const XalanDOMString& fileName);
66
68
69 // Initialize this XalanXMLFileReporter. Must be called before attempting to log anything.
70 bool initialize(MemoryManager& theManager);
71
72 MemoryManager&
74 {
75 return m_fileName.getMemoryManager();
76 }
77
78 // Accessor for flushing; is set from properties.
80
81 // Accessor methods for our properties block.
83
84 // Accessor methods for our properties block.
85 void setFileName(const XalanDOMString& fileName);
86
87 // Accessor methods for our properties block.
88 void setFileName(const char* fileName, MemoryManager& theManager)
89 {
90 setFileName(XalanDOMString(fileName, theManager));
91 }
92
93 //
94 // Is this Reporter still running OK?
95 // @returns status - true if an error has occoured, false if it's still working fine
96 bool checkError();
97
98
99 //
100 // Is this Reporter ready to log results?
101 // @returns status - true if it's ready to report, false otherwise
102 bool isReady();
103
104 // Flush this reporter - ensure our File is flushed.
105 void flush();
106
107
108 // Close this reporter - ensure our File, etc. are closed.
109 void close();
110
111 //-----------------------------------------------------
112 //-------- Testfile / Testcase start and stop routines --------
113 //-----------------------------------------------------
114
115 /**
116 * Report that a testfile has started.
117 * @param msg message to log out
118 */
120
121 void logTestFileInit(const char* msg)
122 {
123 logTestFileInit(XalanDOMString(msg, getMemoryManager()));
124 }
125
126 /**
127 * Report that a testfile has finished, and report it's result.
128 * @param msg message to log out
129 * @param result result of testfile
130 */
131 void logTestFileClose(const XalanDOMString& msg, const XalanDOMString& result);
132
133 void logTestFileClose(const char* msg, const char* result)
134 {
135 logTestFileClose(XalanDOMString(msg, getMemoryManager()), XalanDOMString(result, getMemoryManager()));
136 }
137
139
140 void logTestCaseInit(const char* msg)
141 {
142 logTestCaseInit(XalanDOMString(msg, getMemoryManager()));
143 }
144
145 /**
146 * Report that a testcase has finished, and report it's result.
147 * @param msg message to log out
148 * @param result result of testfile
149 */
150 void logTestCaseClose(const XalanDOMString& msg, const XalanDOMString& result);
151
152 void logTestCaseClose(const char* msg, const char* result)
153 {
154 logTestCaseClose(XalanDOMString(msg , getMemoryManager()), XalanDOMString(result , getMemoryManager()));
155 }
156 //-----------------------------------------------------
157 //-------- Test results reporting and logging routines --------
158 //-----------------------------------------------------
159
160
161 /**
162 * Report a comment to result file with specified severity.
163 * <P>Record format: &lt;message level="##"&gt;msg&lt;/message&gt;</P>
164 * @param level severity or class of message.
165 * @param msg comment to log out.
166 */
167 void logMessage(int level, const XalanDOMString& msg);
168
169 /**
170 * Logs out statistics to result file with specified severity.
171 * <P>Record format: &lt;statistic level="##" desc="msg"&gt;&lt;longval&gt;1234&lt;/longval&gt;&lt;doubleval&gt;1.234&lt;/doubleval&gt;&lt;/statistic&gt;</P>
172 * @param level severity of message.
173 * @param lVal statistic in long format.
174 * @param dVal statistic in double format.
175 * @param msg comment to log out.
176 */
177 void logStatistic (int level, long lVal, double dVal, const XalanDOMString& msg);
178
179 void logStatistic (int level, long lVal, double dVal, const char* msg)
180 {
181 logStatistic(level, lVal, dVal, XalanDOMString(msg, getMemoryManager()));
182 }
183
184 // This routine will add an attribute to the attribute list.
185 void addMetricToAttrs(const char* desc, double theMetric, Hashtable& attrs);
186
187 /**
188 * Logs out a element to results with specified severity.
189 * Uses user-supplied element name and attribute list. Currently
190 * attribute values and msg are forced .toString(). Also,
191 * 'level' is forced to be the first attribute of the element.
192 * @param level severity of message.
193 * @param element name of enclosing element
194 * @param attrs hash of name=value attributes; note that the
195 * caller must ensure they're legal XML
196 * @param msg comment to log out.
197 */
198 void logElementWAttrs(int level, const XalanDOMString& element, Hashtable& attrs, const XalanDOMString& msg);
199
200 void logElementWAttrs(int level, const char* element, Hashtable& attrs, const char* msg)
201 {
202 logElementWAttrs(level, XalanDOMString(element, getMemoryManager()), attrs, XalanDOMString(msg, getMemoryManager()));
203 }
204
205 void logElement(int level, const XalanDOMString& element, const XalanDOMString& msg);
206
207 void logElement(const XalanDOMString& element, const XalanDOMString& msg);
208 /**
209 * Report an arbitrary XalanDOMString to result file with specified severity.
210 * <P>Appends and prepends \\n newline characters at the start and
211 * end of the message to separate it from the tags.</P>
212 * <P>Record format: &lt;arbitrary level="##"&gt;<BR/>
213 * msg<BR/>
214 * &lt;/arbitrary&gt;
215 * </P>
216 * @param level severity or class of message.
217 * @param msg arbitrary XalanDOMString to log out.
218 */
219 void logArbitraryMessage (int level, const XalanDOMString& msg);
220
221 /**
222 * Report a complete Hashtable to result file with specified severity.
223 * <P>Indents each hashitem within the table.</P>
224 * <P>Record format: &lt;hashtable level="##" desc="msg"/&gt;<BR/>
225 * &nbsp;&nbsp;&lt;hashitem key="key1"&gt;value1&lt;/hashitem&gt;<BR/>
226 * &nbsp;&nbsp;&lt;hashitem key="key2"&gt;value2&lt;/hashitem&gt;<BR/>
227 * &lt;/hashtable&gt;
228 * </P>
229 * @param level severity or class of message.
230 * @param hash Hashtable to log the contents of.
231 * @param msg decription of the Hashtable.
232 */
233 /*
234 void logHashtable (int level, Hashtable hash, const XalanDOMString& msg);
235 */
236
237 /**
238 * Writes out a Pass record with comment.
239 * <P>Record format: &lt;checkresult result="PASS" desc="comment"/&gt;</P>
240 * @param comment comment to log with the pass record.
241 */
242 void logCheckPass(const XalanDOMString& comment);
243
244 /**
245 * Writes out an ambiguous record with comment.
246 * <P>Record format: &lt;checkresult result="AMBG" desc="comment"/&gt;</P>
247 * @param comment comment to log with the ambg record.
248 */
249 void logCheckAmbiguous(const XalanDOMString& comment);
250
251 /**
252 * Writes out a Fail record with comment.
253 * <P>Record format: &lt;checkresult result="FAIL" desc="comment"/&gt;</P>
254 * @param comment comment to log with the fail record.
255 */
256 void logCheckFail(const XalanDOMString& comment);
257
258 void logCheckFail(const XalanDOMString& test, const Hashtable& faildata, const Hashtable& actexp);
259
260 void logCheckFail(const XalanDOMString& test, const Hashtable& actexp);
261
262 void logErrorResult(const XalanDOMString& test, const XalanDOMString& reason);
263
264 /**
265 * Writes out a Error record with comment.
266 * <P>Record format: &lt;checkresult result="ERRR" desc="comment"/&gt;</P>
267 * @param comment comment to log with the error record.
268 */
269 void logCheckErr(const XalanDOMString& comment);
270
271 /**
272 * Escapes a XalanDOMString to remove <, >, ', &, and " so it's valid XML.
273 * <P>Stolen mostly from Xalan applet sample.</P>
274 * @param s XalanDOMString to escape.
275 * @return XalanDOMString that has been escaped.
276 */
278
279
280private:
281 // not implemented
283 /**
284 * worker method to dump the xml header and open the resultsfile element.
285 */
286 bool startResultsFile();
287
288 /**
289 * worker method to close the resultsfile element.
290 */
291 bool closeResultsFile();
292
293 /**
294 * worker method to prints to the resultsfile.
295 */
296 bool printToFile(const XalanDOMString& output);
297
298 void
299 initStrings();
300
301 /**
302 * worker method to prints to the resultsfile.
303 */
305 getDateTimeString(XalanDOMString& result);
306
307 /** Key for Properties block that denotes our output filename. */
308 XalanDOMString OPT_FILENAME;
309
310 /** XML tagnames for results file structure. */
311 XalanDOMString ELEM_RESULTSFILE;
312 XalanDOMString ELEM_TESTFILE;
313 XalanDOMString ELEM_FILERESULT;
314 XalanDOMString ELEM_TESTCASE;
315 XalanDOMString ELEM_CASERESULT;
316 XalanDOMString ELEM_CHECKRESULT;
317 XalanDOMString ELEM_STATISTIC;
318 XalanDOMString ELEM_LONGVAL;
319 XalanDOMString ELEM_DOUBLEVAL;
320 XalanDOMString ELEM_MESSAGE;
321 XalanDOMString ELEM_ARBITRARY;
322 XalanDOMString ELEM_HASHTABLE;
323 XalanDOMString ELEM_HASHITEM;
324
325 /** XML attribute names for results file structure. */
326 XalanDOMString ATTR_LEVEL;
327 XalanDOMString ATTR_DESC;
328 XalanDOMString ATTR_TIME;
329 XalanDOMString ATTR_RESULT;
330 XalanDOMString ATTR_KEY;
331 XalanDOMString ATTR_FILENAME;
332 XalanDOMString LESS_THAN;
333 XalanDOMString GREATER_THAN;
334 XalanDOMString EQUALS_QUOTE;
335 XalanDOMString SPACE;
336 XalanDOMString QUOTE;
337 XalanDOMString QUOTE_SPACE;
338 XalanDOMString QUOTE_GREATER_THAN;
339 XalanDOMString QUOTE_SOLIDUS_GREATER_THAN;
340 XalanDOMString PASS;
341 XalanDOMString AMBG;
342 XalanDOMString ERRR;
343 XalanDOMString FAIL;
344 XalanDOMString LESS_THAN_SOLIDUS;
345 XalanDOMString XML_HEADER;
346 XalanDOMString REASON_EQUALS_QUOTE;
347
348 /**
349 * Optimization: for heavy use methods, form pre-defined constants to save on XalanDOMString concatenation.
350 * <P>Note the indent; must be updated if we ever switch to another indenting method.</P>
351 */
352 XalanDOMString TESTCASEINIT_HDR;
353 XalanDOMString TESTCASECLOSE_HDR;
354 XalanDOMString MESSAGE_HDR;
355 XalanDOMString STATISTIC_HDR;
356 XalanDOMString ARBITRARY_HDR;
357 XalanDOMString HASHTABLE_HDR;
358 XalanDOMString HASHITEM_HDR;
359 XalanDOMString CHECKPASS_HDR;
360 XalanDOMString CHECKAMBG_HDR;
361 XalanDOMString CHECKERRR_HDR;
362 XalanDOMString CHECKFAIL_HDR;
363 XalanDOMString CHECKFAIL_FTR;
364
365 /** If we have output anything yet. */
366 bool m_anyOutput;
367
368 /** Name of the file we're outputing to. */
369 XalanDOMString m_fileName;
370
371 /** File reference and other internal convenience variables. */
372 FileHandleType* m_fileHandle;
373
374 /** If we're ready to start outputting yet. */
375 bool m_ready;
376
377 /** If an error has occoured in this Reporter. */
378 bool m_error;
379
380 /** If we should flush after every logTestCaseClose. */
381 bool m_flushOnCaseClose;
382
383 const XalanAutoPtr<XalanOutputTranscoder> m_transcoder;
384
385 CharVectorType m_buffer;
386}; // end of class XalanXMLFileReporter
387
388
389
390}
391
392
393
394#endif
#define XALAN_HARNESS_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Xalan implementation of a hashtable.
Definition XalanMap.hpp:187
void logTestCaseClose(const char *msg, const char *result)
void logTestFileClose(const char *msg, const char *result)
void logErrorResult(const XalanDOMString &test, const XalanDOMString &reason)
void logCheckFail(const XalanDOMString &test, const Hashtable &faildata, const Hashtable &actexp)
void logTestFileClose(const XalanDOMString &msg, const XalanDOMString &result)
Report that a testfile has finished, and report it's result.
XalanXMLFileReporter(MemoryManager &theManager, const XalanDOMString &fileName)
void logStatistic(int level, long lVal, double dVal, const XalanDOMString &msg)
Logs out statistics to result file with specified severity.
void logElement(int level, const XalanDOMString &element, const XalanDOMString &msg)
void logCheckAmbiguous(const XalanDOMString &comment)
Writes out an ambiguous record with comment.
void logCheckPass(const XalanDOMString &comment)
Report a complete Hashtable to result file with specified severity.
void logTestFileInit(const XalanDOMString &msg)
Report that a testfile has started.
void logCheckErr(const XalanDOMString &comment)
Writes out a Error record with comment.
XalanDOMString & escapestring(const XalanDOMString &s, XalanDOMString &buffer)
Escapes a XalanDOMString to remove <, >, ', &, and " so it's valid XML.
void logArbitraryMessage(int level, const XalanDOMString &msg)
Report an arbitrary XalanDOMString to result file with specified severity.
void logTestCaseClose(const XalanDOMString &msg, const XalanDOMString &result)
Report that a testcase has finished, and report it's result.
XalanMap< XalanDOMString, XalanDOMString > Hashtable
void logMessage(int level, const XalanDOMString &msg)
Report a comment to result file with specified severity.
void logStatistic(int level, long lVal, double dVal, const char *msg)
void setFileName(const char *fileName, MemoryManager &theManager)
void addMetricToAttrs(const char *desc, double theMetric, Hashtable &attrs)
void logElement(const XalanDOMString &element, const XalanDOMString &msg)
void logCheckFail(const XalanDOMString &test, const Hashtable &actexp)
bool initialize(MemoryManager &theManager)
void logElementWAttrs(int level, const char *element, Hashtable &attrs, const char *msg)
void logCheckFail(const XalanDOMString &comment)
Writes out a Fail record with comment.
void logTestCaseInit(const XalanDOMString &msg)
void logElementWAttrs(int level, const XalanDOMString &element, Hashtable &attrs, const XalanDOMString &msg)
Logs out a element to results with specified severity.
const XalanDOMString & getFileName() const
void setFileName(const XalanDOMString &fileName)