00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(HARNESS_HEADER_GUARD_1357924680) 00019 #define HARNESS_HEADER_GUARD_1357924680 00020 00021 00022 00023 #include "xalanc/Harness/XalanHarnessDefinitions.hpp" 00024 00025 00026 00027 #include <cstdio> 00028 00029 00030 00031 #include "xalanc/XalanDOM/XalanDOMString.hpp" 00032 00033 00034 00035 #include "xalanc/Include/XalanAutoPtr.hpp" 00036 #include "xalanc/Include/XalanMap.hpp" 00037 #include "xalanc/Include/XalanVector.hpp" 00038 00039 00040 00041 #include "xalanc/PlatformSupport/DOMStringHelper.hpp" 00042 00043 00044 00045 XALAN_CPP_NAMESPACE_BEGIN 00046 00047 00048 00049 class XalanOutputTranscoder; 00050 00051 class XALAN_HARNESS_EXPORT XalanXMLFileReporter 00052 { 00053 00054 public: 00055 00056 typedef XalanMap<XalanDOMString, XalanDOMString> Hashtable; 00057 00058 #if defined(XALAN_STRICT_ANSI_HEADERS) 00059 typedef std::FILE FileHandleType; 00060 #else 00061 typedef FILE FileHandleType; 00062 #endif 00063 00064 public: 00065 00066 00067 // Construct and initialize this reporter with specified filename, if 00068 // the filename is not empty. 00069 XalanXMLFileReporter(MemoryManager& theManager, const XalanDOMString& fileName); 00070 00071 ~XalanXMLFileReporter(); 00072 00073 // Initialize this XalanXMLFileReporter. Must be called before attempting to log anything. 00074 bool initialize(MemoryManager& theManager); 00075 00076 MemoryManager& 00077 getMemoryManager() 00078 { 00079 return m_fileName.getMemoryManager(); 00080 } 00081 00082 // Accessor for flushing; is set from properties. 00083 bool getFlushOnCaseClose(); 00084 00085 // Accessor methods for our properties block. 00086 const XalanDOMString& getFileName() const; 00087 00088 // Accessor methods for our properties block. 00089 void setFileName(const XalanDOMString& fileName); 00090 00091 // Accessor methods for our properties block. 00092 void setFileName(const char* fileName, MemoryManager& theManager) 00093 { 00094 setFileName(XalanDOMString(fileName, theManager)); 00095 } 00096 00097 // 00098 // Is this Reporter still running OK? 00099 // @returns status - true if an error has occoured, false if it's still working fine 00100 bool checkError(); 00101 00102 00103 // 00104 // Is this Reporter ready to log results? 00105 // @returns status - true if it's ready to report, false otherwise 00106 bool isReady(); 00107 00108 // Flush this reporter - ensure our File is flushed. 00109 void flush(); 00110 00111 00112 // Close this reporter - ensure our File, etc. are closed. 00113 void close(); 00114 00115 //----------------------------------------------------- 00116 //-------- Testfile / Testcase start and stop routines -------- 00117 //----------------------------------------------------- 00118 00119 /** 00120 * Report that a testfile has started. 00121 * @param msg message to log out 00122 */ 00123 void logTestFileInit(const XalanDOMString& msg); 00124 00125 void logTestFileInit(const char* msg) 00126 { 00127 logTestFileInit(XalanDOMString(msg, getMemoryManager())); 00128 } 00129 00130 /** 00131 * Report that a testfile has finished, and report it's result. 00132 * @param msg message to log out 00133 * @param result result of testfile 00134 */ 00135 void logTestFileClose(const XalanDOMString& msg, const XalanDOMString& result); 00136 00137 void logTestFileClose(const char* msg, const char* result) 00138 { 00139 logTestFileClose(XalanDOMString(msg, getMemoryManager()), XalanDOMString(result, getMemoryManager())); 00140 } 00141 00142 void logTestCaseInit(const XalanDOMString& msg); 00143 00144 void logTestCaseInit(const char* msg) 00145 { 00146 logTestCaseInit(XalanDOMString(msg, getMemoryManager())); 00147 } 00148 00149 /** 00150 * Report that a testcase has finished, and report it's result. 00151 * @param msg message to log out 00152 * @param result result of testfile 00153 */ 00154 void logTestCaseClose(const XalanDOMString& msg, const XalanDOMString& result); 00155 00156 void logTestCaseClose(const char* msg, const char* result) 00157 { 00158 logTestCaseClose(XalanDOMString(msg , getMemoryManager()), XalanDOMString(result , getMemoryManager())); 00159 } 00160 //----------------------------------------------------- 00161 //-------- Test results reporting and logging routines -------- 00162 //----------------------------------------------------- 00163 00164 00165 /** 00166 * Report a comment to result file with specified severity. 00167 * <P>Record format: <message level="##">msg</message></P> 00168 * @param level severity or class of message. 00169 * @param msg comment to log out. 00170 */ 00171 void logMessage(int level, const XalanDOMString& msg); 00172 00173 /** 00174 * Logs out statistics to result file with specified severity. 00175 * <P>Record format: <statistic level="##" desc="msg"><longval>1234</longval><doubleval>1.234</doubleval></statistic></P> 00176 * @param level severity of message. 00177 * @param lVal statistic in long format. 00178 * @param dVal statistic in double format. 00179 * @param msg comment to log out. 00180 */ 00181 void logStatistic (int level, long lVal, double dVal, const XalanDOMString& msg); 00182 00183 void logStatistic (int level, long lVal, double dVal, const char* msg) 00184 { 00185 logStatistic(level, lVal, dVal, XalanDOMString(msg, getMemoryManager())); 00186 } 00187 00188 // This routine will add an attribute to the attribute list. 00189 void addMetricToAttrs(const char* desc, double theMetric, Hashtable& attrs); 00190 00191 /** 00192 * Logs out a element to results with specified severity. 00193 * Uses user-supplied element name and attribute list. Currently 00194 * attribute values and msg are forced .toString(). Also, 00195 * 'level' is forced to be the first attribute of the element. 00196 * @param level severity of message. 00197 * @param element name of enclosing element 00198 * @param attrs hash of name=value attributes; note that the 00199 * caller must ensure they're legal XML 00200 * @param msg comment to log out. 00201 */ 00202 void logElementWAttrs(int level, const XalanDOMString& element, Hashtable& attrs, const XalanDOMString& msg); 00203 00204 void logElementWAttrs(int level, const char* element, Hashtable& attrs, const char* msg) 00205 { 00206 logElementWAttrs(level, XalanDOMString(element, getMemoryManager()), attrs, XalanDOMString(msg, getMemoryManager())); 00207 } 00208 00209 void logElement(int level, const XalanDOMString& element, const XalanDOMString& msg); 00210 00211 void logElement(const XalanDOMString& element, const XalanDOMString& msg); 00212 /** 00213 * Report an arbitrary XalanDOMString to result file with specified severity. 00214 * <P>Appends and prepends \\n newline characters at the start and 00215 * end of the message to separate it from the tags.</P> 00216 * <P>Record format: <arbitrary level="##"><BR/> 00217 * msg<BR/> 00218 * </arbitrary> 00219 * </P> 00220 * @param level severity or class of message. 00221 * @param msg arbitrary XalanDOMString to log out. 00222 */ 00223 void logArbitraryMessage (int level, const XalanDOMString& msg); 00224 00225 /** 00226 * Report a complete Hashtable to result file with specified severity. 00227 * <P>Indents each hashitem within the table.</P> 00228 * <P>Record format: <hashtable level="##" desc="msg"/><BR/> 00229 * <hashitem key="key1">value1</hashitem><BR/> 00230 * <hashitem key="key2">value2</hashitem><BR/> 00231 * </hashtable> 00232 * </P> 00233 * @param level severity or class of message. 00234 * @param hash Hashtable to log the contents of. 00235 * @param msg decription of the Hashtable. 00236 */ 00237 /* 00238 void logHashtable (int level, Hashtable hash, const XalanDOMString& msg); 00239 */ 00240 00241 /** 00242 * Writes out a Pass record with comment. 00243 * <P>Record format: <checkresult result="PASS" desc="comment"/></P> 00244 * @param comment comment to log with the pass record. 00245 */ 00246 void logCheckPass(const XalanDOMString& comment); 00247 00248 /** 00249 * Writes out an ambiguous record with comment. 00250 * <P>Record format: <checkresult result="AMBG" desc="comment"/></P> 00251 * @param comment comment to log with the ambg record. 00252 */ 00253 void logCheckAmbiguous(const XalanDOMString& comment); 00254 00255 /** 00256 * Writes out a Fail record with comment. 00257 * <P>Record format: <checkresult result="FAIL" desc="comment"/></P> 00258 * @param comment comment to log with the fail record. 00259 */ 00260 void logCheckFail(const XalanDOMString& comment); 00261 00262 void logCheckFail(const XalanDOMString& test, const Hashtable& faildata, const Hashtable& actexp); 00263 00264 void logCheckFail(const XalanDOMString& test, const Hashtable& actexp); 00265 00266 void logErrorResult(const XalanDOMString& test, const XalanDOMString& reason); 00267 00268 /** 00269 * Writes out a Error record with comment. 00270 * <P>Record format: <checkresult result="ERRR" desc="comment"/></P> 00271 * @param comment comment to log with the error record. 00272 */ 00273 void logCheckErr(const XalanDOMString& comment); 00274 00275 /** 00276 * Escapes a XalanDOMString to remove <, >, ', &, and " so it's valid XML. 00277 * <P>Stolen mostly from Xalan applet sample.</P> 00278 * @param s XalanDOMString to escape. 00279 * @return XalanDOMString that has been escaped. 00280 */ 00281 XalanDOMString& escapestring(const XalanDOMString& s, XalanDOMString& buffer); 00282 00283 00284 private: 00285 // not implemented 00286 XalanXMLFileReporter(const XalanXMLFileReporter&); 00287 /** 00288 * worker method to dump the xml header and open the resultsfile element. 00289 */ 00290 bool startResultsFile(); 00291 00292 /** 00293 * worker method to close the resultsfile element. 00294 */ 00295 bool closeResultsFile(); 00296 00297 /** 00298 * worker method to prints to the resultsfile. 00299 */ 00300 bool printToFile(const XalanDOMString& output); 00301 00302 void 00303 initStrings(); 00304 00305 /** 00306 * worker method to prints to the resultsfile. 00307 */ 00308 XalanDOMString& 00309 getDateTimeString(XalanDOMString& result); 00310 00311 /** Key for Properties block that denotes our output filename. */ 00312 XalanDOMString OPT_FILENAME; 00313 00314 /** XML tagnames for results file structure. */ 00315 XalanDOMString ELEM_RESULTSFILE; 00316 XalanDOMString ELEM_TESTFILE; 00317 XalanDOMString ELEM_FILERESULT; 00318 XalanDOMString ELEM_TESTCASE; 00319 XalanDOMString ELEM_CASERESULT; 00320 XalanDOMString ELEM_CHECKRESULT; 00321 XalanDOMString ELEM_STATISTIC; 00322 XalanDOMString ELEM_LONGVAL; 00323 XalanDOMString ELEM_DOUBLEVAL; 00324 XalanDOMString ELEM_MESSAGE; 00325 XalanDOMString ELEM_ARBITRARY; 00326 XalanDOMString ELEM_HASHTABLE; 00327 XalanDOMString ELEM_HASHITEM; 00328 00329 /** XML attribute names for results file structure. */ 00330 XalanDOMString ATTR_LEVEL; 00331 XalanDOMString ATTR_DESC; 00332 XalanDOMString ATTR_TIME; 00333 XalanDOMString ATTR_RESULT; 00334 XalanDOMString ATTR_KEY; 00335 XalanDOMString ATTR_FILENAME; 00336 XalanDOMString LESS_THAN; 00337 XalanDOMString GREATER_THAN; 00338 XalanDOMString EQUALS_QUOTE; 00339 XalanDOMString SPACE; 00340 XalanDOMString QUOTE; 00341 XalanDOMString QUOTE_SPACE; 00342 XalanDOMString QUOTE_GREATER_THAN; 00343 XalanDOMString QUOTE_SOLIDUS_GREATER_THAN; 00344 XalanDOMString PASS; 00345 XalanDOMString AMBG; 00346 XalanDOMString ERRR; 00347 XalanDOMString FAIL; 00348 XalanDOMString LESS_THAN_SOLIDUS; 00349 XalanDOMString XML_HEADER; 00350 XalanDOMString REASON_EQUALS_QUOTE; 00351 00352 /** 00353 * Optimization: for heavy use methods, form pre-defined constants to save on XalanDOMString concatenation. 00354 * <P>Note the indent; must be updated if we ever switch to another indenting method.</P> 00355 */ 00356 XalanDOMString TESTCASEINIT_HDR; 00357 XalanDOMString TESTCASECLOSE_HDR; 00358 XalanDOMString MESSAGE_HDR; 00359 XalanDOMString STATISTIC_HDR; 00360 XalanDOMString ARBITRARY_HDR; 00361 XalanDOMString HASHTABLE_HDR; 00362 XalanDOMString HASHITEM_HDR; 00363 XalanDOMString CHECKPASS_HDR; 00364 XalanDOMString CHECKAMBG_HDR; 00365 XalanDOMString CHECKERRR_HDR; 00366 XalanDOMString CHECKFAIL_HDR; 00367 XalanDOMString CHECKFAIL_FTR; 00368 00369 /** If we have output anything yet. */ 00370 bool m_anyOutput; 00371 00372 /** Name of the file we're outputing to. */ 00373 XalanDOMString m_fileName; 00374 00375 /** File reference and other internal convenience variables. */ 00376 FileHandleType* m_fileHandle; 00377 00378 /** If we're ready to start outputting yet. */ 00379 bool m_ready; 00380 00381 /** If an error has occoured in this Reporter. */ 00382 bool m_error; 00383 00384 /** If we should flush after every logTestCaseClose. */ 00385 bool m_flushOnCaseClose; 00386 00387 const XalanAutoPtr<XalanOutputTranscoder> m_transcoder; 00388 00389 CharVectorType m_buffer; 00390 }; // end of class XalanXMLFileReporter 00391 00392 00393 00394 XALAN_CPP_NAMESPACE_END 00395 00396 00397 00398 #endif
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|