Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo