Xalan-C++ API Reference  1.12.0
XalanFileUtility.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(XALAN_FILEUTILITY_HEADER_GUARD_1357924680)
19 #define XALAN_FILEUTILITY_HEADER_GUARD_1357924680
20 
21 
22 
24 
25 
27 
28 
29 #include <strstream>
30 
31 
32 
34 
35 
36 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
41 class FormatterListener;
42 class PrintWriter;
43 class StylesheetRoot;
44 class XalanCompiledStylesheet;
45 class XalanDocument;
46 class XalanNode;
47 class XalanSourceTreeDocument;
48 class XalanTransformer;
49 class XalanXMLFileReporter;
50 class XSLTInputSource;
51 
52 
53 using xercesc::MemoryManager;
54 
55 
56 
57 // This class is exported from the Harness.dll
59 {
60 public:
61 
62 // A vector to hold directory names and file names.
63 
66 
68  {
74  const char* msg;
78  int pass;
79  int fail;
80  int nogold;
81 
82  reportStruct(MemoryManager& theManager);
83 
84  void
85  reset();
86  private:
87  //Not implemented
88  reportStruct();
89  reportStruct(const reportStruct&);
90 
91  } data;
92 
94  {
95  private:
96 
97  typedef std::ostrstream StreamType;
98 
99  StreamType help;
100 
101  public:
102 
107  int source;
108  bool skip;
109  long iters;
110 
111 
112  cmdParams(MemoryManager& theManager);
113 
115  {
116  }
117 
118  const char*
119  getHelpMessage();
120 
121  StreamType&
123  {
124  return help;
125  }
126  private:
127  //Not implemented
128  cmdParams();
129  cmdParams(const cmdParams&);
130 
131  } args;
132 
133  /** Simple constructor, does not perform initialization. */
134  XalanFileUtility(MemoryManager& theManager);
135 
136  ~XalanFileUtility();
137 
138  bool
139  getVerbose() const
140  {
141  return m_verbose;
142  }
143 
144  void
145  setVerbose(bool flag)
146  {
147  m_verbose = flag;
148  }
149 
150  int
152  {
153  return data.fail;
154  }
155 
156  /**
157  * Utility method used to get test files from a specific directory.
158  * @returns a vector containing test files.
159  */
160 
162  getDrive(XalanDOMString& theResult);
163 
164  bool
165  getParams(
166  int argc,
167  char* argv[],
168  const char* outDir,
169  bool fsetGold = true);
170 
171 
172  FileNameVectorType&
173  getTestFileNames(
174  const XalanDOMString& baseDir,
175  const XalanDOMString& relDir,
176  bool useDirPrefix,
177  FileNameVectorType& theFiles);
178 
179  /**
180  * Utility method used to get subdirectories from a specific directory.
181  * @returns a vector containing directory files.
182  */
183  FileNameVectorType&
184  getDirectoryNames(const XalanDOMString& rootDirectory,
185  FileNameVectorType& theFiles);
186 
187  /**
188  * Utility method used to create default directories when neccessary
189  */
190  void
191  checkAndCreateDir(const XalanDOMString& directory);
192 
193  /**
194  * Utility method determines if directory exists.
195  */
196  bool
197  checkDir(const XalanDOMString& directory);
198 
199  /**
200  * Utility method used to get XSL file based on XML file.
201  * @returns a XalanDOMString.
202  */
204  getXSLFileName(const XalanDOMString& theXMLFileName,
205  XalanDOMString& theResult);
206 
207  /**
208  * Utility method used to get OUT file based on XML file.
209  * @returns a XalanDOMString.
210  */
212  generateFileName(
213  const XalanDOMString& theXMLFileName,
214  const char* suffix,
215  XalanDOMString& theResult,
216  bool* status = 0);
217 
218  /**
219  * Utility method used to generate UniqRunid.
220  * @returns a XalanDOMString.
221  */
223  generateUniqRunid(XalanDOMString& theResult);
224 
225  /**
226  * Utility methods used to get Xerces Version number.
227  * @returns a XalanDOMString.
228  */
230  getXercesVersion(XalanDOMString& theResult);
231 
232  void
233  checkResults(
234  const XalanDOMString& outputFile,
235  const XalanDOMString& goldFile,
236  XalanXMLFileReporter& logfile);
237 
238  void
239  checkAPIResults(
240  const XalanDOMString& actual,
241  const XalanDOMString& expected,
242  const char* msg,
243  XalanXMLFileReporter& logfile,
244  const XalanDOMString& outputFile,
245  const XalanDOMString& goldFile,
246  bool containsOnly = false);
247 
248  // This API is deprecated. Please use the following
249  // one.
250  void
252  const char* actual,
253  const char* expected,
254  const char* msg,
255  XalanXMLFileReporter& logfile,
256  const XalanDOMString& outputFile,
257  const XalanDOMString& goldFile,
258  MemoryManager& /* theManager */,
259  bool containsOnly = false)
260  {
261  checkAPIResults(
262  actual,
263  expected,
264  msg,
265  logfile,
266  outputFile,
267  goldFile,
268  containsOnly);
269  }
270 
271  void
273  const char* actual,
274  const char* expected,
275  const char* msg,
276  XalanXMLFileReporter& logfile,
277  const XalanDOMString& outputFile,
278  const XalanDOMString& goldFile,
279  bool containsOnly = false)
280  {
281  checkAPIResults(
282  XalanDOMString(actual, getMemoryManager()),
283  XalanDOMString(expected, getMemoryManager()),
284  msg,
285  logfile,
286  outputFile,
287  goldFile,
288  containsOnly);
289  }
290 
291  /**
292  * Utility method used to compare the results. It inturn
293  * call domCompare.
294  * @returns Void.
295  */
296  void
297  checkDOMResults(
298  const XalanDOMString& theOutputFile,
299  const XalanCompiledStylesheet* compiledSS,
300  const XalanSourceTreeDocument* dom,
301  const XSLTInputSource& goldInputSource,
302  XalanXMLFileReporter& logfile);
303 
304  bool
305  compareSerializedResults(
306  const XalanDOMString& transformResult,
307  const XalanDOMString& goldInputSource);
308 
309  /**
310  * Utility method used to create a FormatterToXML FormatterListener.
311  * This is required to DOM comparisions.
312  * @returns a pointer to a FormatterListener.
313  */
315  getXMLFormatter(
316  PrintWriter& resultWriter,
317  int indentAmount,
318  const XalanDOMString& mimeEncoding,
319  const StylesheetRoot* stylesheet);
320 
321 
322  bool
323  fileCompare(
324  const char* goldFile,
325  const char* outputFile);
326 
327  /**
328  * Utility methods used to perform a DOM Compare
329  * @returns boolean
330  */
331  bool
332  domCompare(const XalanNode& gold, const XalanNode& doc);
333 
334  /**
335  * Utility methods used to perform a DOM Compare
336  * @returns boolean
337  */
338  bool
339  domCompare(
340  const XalanDocument& gold,
341  const XalanDocument& doc);
342 
343  /**
344  * Utility methods used to diff two Element nodes.
345  * @returns boolean.
346  */
347  bool
348  diffElement(const XalanNode& gold, const XalanNode& doc);
349 
350  /**
351  * Utility methods used to diff two nodes.
352  * @returns true if the nodes are equal, and false if not.
353  */
354  bool
355  diffNode(
356  const XalanNode& gold,
357  const XalanNode& doc);
358 
359  /**
360  * Utility methods used to diff two nodes.
361  * @returns true if the nodes are equal, and false if not.
362  */
363  bool
364  diffNode(
365  const XalanNode* gold,
366  const XalanNode* doc);
367 
368  /**
369  * Utility methods used to diff two Element nodes.
370  * @returns boolean.
371  */
372  bool
373  diffElement2(
374  const XalanNode& gold,
375  const XalanNode& doc);
376 
377  /**
378  * Utility methods used to diff two attribute nodes.
379  * @returns boolean.
380  */
381  bool
382  diffAttr(const XalanNode* gAttr, const XalanNode* dAttr);
383 
384  /**
385  * Utility methods used to report Pass/Fail numbers.
386  * @returns void.
387  */
388  void
389  reportPassFail(XalanXMLFileReporter& logfile);
390 
391  void
392  reportPassFail(XalanXMLFileReporter& logfile, const XalanDOMString& runid);
393 
394  void
395  analyzeResults(XalanTransformer& xalan, const XalanDOMString& resultsFile);
396 
397  static const XalanDOMChar s_xmlSuffix[];
398 
399  static const XalanDOMChar s_pathSep[];
400 
401  const MemoryManager&
403  {
404  return m_buffer.getMemoryManager();
405  }
406 
407  MemoryManager&
409  {
410  return m_buffer.getMemoryManager();
411  }
412 
413 private:
414 
415  static const XalanDOMString s_emptyString;
416 
418  getProgramName(const char* fullName, XalanDOMString& theBuffer);
419 
420  /**
421  * Utility methods used to collect information about compare failures.
422  * @returns void.
423  */
424  void
425  collectData(
426  const char* errmsg,
427  const XalanDOMString& currentnode,
428  const XalanDOMString& actdata,
429  const XalanDOMString& expdata);
430 
431  /**
432  * Utility methods used to report DOM compare errors.
433  * @returns void.
434  */
435  void
436  reportError();
437 
438  void
439  debugNodeData(const XalanDOMString& /* value */);
440 
441  void
442  debugNodeData(
443  const XalanDOMString& /* node */,
444  const XalanDOMString& /* value */);
445 
446  void
447  debugAttributeData(const XalanDOMString& /* value */);
448 
449 private:
450 
451  CharVectorType m_buffer;
452 
453  bool m_verbose;
454 
455  //Not implemented
458 };
459 
460 
461 
462 }
463 
464 
465 
466 #endif // XALAN_FILEUTILITY_HEADER_GUARD_1357924680
xalanc::XalanFileUtility::getMemoryManager
MemoryManager & getMemoryManager()
Definition: XalanFileUtility.hpp:408
XALAN_HARNESS_EXPORT
#define XALAN_HARNESS_EXPORT
Definition: XalanHarnessDefinitions.hpp:27
xalanc::XalanFileUtility::checkAPIResults
void checkAPIResults(const char *actual, const char *expected, const char *msg, XalanXMLFileReporter &logfile, const XalanDOMString &outputFile, const XalanDOMString &goldFile, MemoryManager &, bool containsOnly=false)
Definition: XalanFileUtility.hpp:251
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanFileUtility::reportStruct::nogold
int nogold
Definition: XalanFileUtility.hpp:80
xalanc::XalanCompiledStylesheet
This is an abstraction of the StylesheetRoot class.
Definition: XalanCompiledStylesheet.hpp:40
xalanc::XalanNode
Definition: XalanNode.hpp:38
XalanDOMString.hpp
xalanc::XalanFileUtility::cmdParams::skip
bool skip
Definition: XalanFileUtility.hpp:108
xalanc::XalanFileUtility::cmdParams::getHelpStream
StreamType & getHelpStream()
Definition: XalanFileUtility.hpp:122
xalanc::XalanVector< XalanDOMString >
xalanc::XalanFileUtility::reportStruct::fail
int fail
Definition: XalanFileUtility.hpp:79
xalanc::XalanFileUtility::cmdParams::sub
XalanDOMString sub
Definition: XalanFileUtility.hpp:106
xalanc::XalanFileUtility::reportStruct::currentNode
XalanDOMString currentNode
Definition: XalanFileUtility.hpp:75
xalanc::XalanXMLFileReporter
Definition: XalanXMLFileReporter.hpp:51
xalanc::XalanFileUtility::reportStruct::theDrive
XalanDOMString theDrive
Definition: XalanFileUtility.hpp:69
xalanc::XalanDocument
Definition: XalanDocument.hpp:36
XalanVector.hpp
xalanc::XalanFileUtility::getMemoryManager
const MemoryManager & getMemoryManager() const
Definition: XalanFileUtility.hpp:402
xalanc::XalanFileUtility::reportStruct::xmlFileURL
XalanDOMString xmlFileURL
Definition: XalanFileUtility.hpp:71
xalanc::XalanFileUtility::cmdParams::~cmdParams
~cmdParams()
Definition: XalanFileUtility.hpp:114
xalanc::XalanFileUtility
Definition: XalanFileUtility.hpp:58
xalanc::XalanFileUtility::cmdParams::base
XalanDOMString base
Definition: XalanFileUtility.hpp:103
xalanc::XalanFileUtility::reportStruct::xmlFormat
XalanDOMString xmlFormat
Definition: XalanFileUtility.hpp:73
xalanc::XalanFileUtility::getFailureCount
int getFailureCount() const
Definition: XalanFileUtility.hpp:151
xalanc::XalanFileUtility::CharVectorType
XalanVector< char > CharVectorType
Definition: XalanFileUtility.hpp:65
XalanHarnessDefinitions.hpp
xalanc::XalanFileUtility::setVerbose
void setVerbose(bool flag)
Definition: XalanFileUtility.hpp:145
xalanc::XSLTInputSource
Definition: XSLTInputSource.hpp:62
xalanc::XalanFileUtility::reportStruct::xslFileURL
XalanDOMString xslFileURL
Definition: XalanFileUtility.hpp:72
xalanc::XalanFileUtility::reportStruct::expected
XalanDOMString expected
Definition: XalanFileUtility.hpp:77
xalanc::XalanFileUtility::getVerbose
bool getVerbose() const
Definition: XalanFileUtility.hpp:139
xalanc::XalanFileUtility::reportStruct::actual
XalanDOMString actual
Definition: XalanFileUtility.hpp:76
xalanc::PrintWriter
Definition: PrintWriter.hpp:37
xalanc::XalanFileUtility::cmdParams::output
XalanDOMString output
Definition: XalanFileUtility.hpp:104
xalanc::XalanFileUtility::cmdParams::gold
XalanDOMString gold
Definition: XalanFileUtility.hpp:105
xalanc::StylesheetRoot
This acts as the stylesheet root of the stylesheet tree, and holds values that are shared by all styl...
Definition: StylesheetRoot.hpp:63
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanFileUtility::cmdParams::iters
long iters
Definition: XalanFileUtility.hpp:109
xalanc::XalanFileUtility::reportStruct
Definition: XalanFileUtility.hpp:67
xalanc::XalanFileUtility::cmdParams::source
int source
Definition: XalanFileUtility.hpp:107
xalanc::XalanSourceTreeDocument
Definition: XalanSourceTreeDocument.hpp:78
xalanc::XalanTransformer
This is a simple C++ interface for some common usage patterns.
Definition: XalanTransformer.hpp:90
xalanc::XalanFileUtility::FileNameVectorType
XalanVector< XalanDOMString > FileNameVectorType
Definition: XalanFileUtility.hpp:64
xalanc::XalanFileUtility::checkAPIResults
void checkAPIResults(const char *actual, const char *expected, const char *msg, XalanXMLFileReporter &logfile, const XalanDOMString &outputFile, const XalanDOMString &goldFile, bool containsOnly=false)
Definition: XalanFileUtility.hpp:272
xalanc::XalanFileUtility::reportStruct::testOrFile
XalanDOMString testOrFile
Definition: XalanFileUtility.hpp:70
xalanc::XalanFileUtility::reportStruct::pass
int pass
Definition: XalanFileUtility.hpp:78
xalanc::XalanFileUtility::reportStruct::msg
const char * msg
Definition: XalanFileUtility.hpp:74
xalanc::XalanFileUtility::cmdParams
Definition: XalanFileUtility.hpp:93