1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <cstdio>
#include <iostream>
// This is here for memory leak testing.
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif
// XERCES HEADERS...
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
// XALAN HEADERS...
#include <xalanc/XPath/XPathExecutionContextDefault.hpp>
#include <xalanc/XPath/XObjectFactoryDefault.hpp>
#include <xalanc/XPath/XPathFactoryDefault.hpp>
#include <xalanc/XSLT/StylesheetConstructionContextDefault.hpp>
#include <xalanc/XSLT/StylesheetExecutionContextDefault.hpp>
#include <xalanc/XSLT/XSLTProcessorEnvSupportDefault.hpp>
#include <xalanc/XSLT/XSLTEngineImpl.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
#include <xalanc/Harness/XalanXMLFileReporter.hpp>
#include <xalanc/Harness/XalanFileUtility.hpp>
using std::cerr;
using std::cout;
using std::endl;
// Just hoist everything...
using namespace xalanc;
void
setHelp(XalanFileUtility& h)
{
h.args.getHelpStream() << endl
<< "inputsource dirname [-out]"
<< endl
<< endl
<< "dirname (base directory for testcases)"
<< endl
<< "-out dirname (base directory for output)"
<< endl;
}
// TestCase1 will use the following method of XSLTInputSource
// - XSLTInputSource(const XMLCh* systemId)
// - XSLTInputSource(const XMLCh* systemId,
// const XMLCh* publicId)
void
testCase1(
XalanTransformer& xalan,
XalanXMLFileReporter& logFile,
const XalanDOMString& xml,
const XalanDOMString& xsl,
const XalanDOMString& outBase,
const XalanDOMString& theGoldFile,
XalanFileUtility& h)
{
const XalanDOMString publicID("public-smublic");
const XalanDOMString theOutputFile = outBase + XalanDOMString("\\InputSource-TestCase1.out");
const XSLTResultTarget theResultTarget(theOutputFile);
h.data.testOrFile = "InputSource-TestCase1";
// This code exercised the stated methods of XSLTInputSource
const XSLTInputSource xmlInputSource(xml);
const XSLTInputSource xslInputSource(xsl, publicID);
// Do the transform and report the results.
xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
h.checkResults(theOutputFile, theGoldFile, logFile);
}
// TestCase2 will use the following methods of XSLTInputSource
// - XSLTInputSource(const char* systemId)
// - XSLTInputSource(const char* systemId,
// const char* publicId)
void
testCase2(
XalanTransformer& xalan,
XalanXMLFileReporter& logFile,
const XalanDOMString& outBase,
const XalanDOMString& theGoldFile,
XalanFileUtility& h)
{
const XalanDOMString theOutputFile = outBase + XalanDOMString("\\InputSource-TestCase2.out");
const XSLTResultTarget theResultTarget2(theOutputFile);
h.data.testOrFile = "InputSource-TestCase2";
// This code excersized the stated methods of XSLTInputSource
const XSLTInputSource xslStringSource("\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xsl","public-smublic");
const XSLTInputSource xmlStringSource("\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xml");
// Do the transform and report the results.
xalan.transform(xmlStringSource, xslStringSource, theResultTarget2);
h.checkResults(theOutputFile, theGoldFile, logFile);
}
// TestCase3 will use the following methods of XSLTInputSource
// - XSLTInputSource()
// - XSLTInputSource(XalanNode* node)
// - XSLTInputSource::setNode(XalanNode* node)
// - XSLTInputSource::getNode()
// - NOTE: We can't use the XalanTransformer Class with this test. So we create the processor directly.
void testCase3(
XalanXMLFileReporter& logFile,
const XalanDOMString& outBase,
const XalanDOMString& theGoldFile,
XalanFileUtility& h)
{
XalanDOMString name, value;
const XalanDOMString theOutputFile = outBase + XalanDOMString("\\InputSource-TestCase3.out");
XSLTResultTarget theResultTarget3(theOutputFile);
h.data.testOrFile = "InputSource-TestCase3a";
// Create necessary Infrastructure to perform transform without the XalanTransformer Class.
// Can't use it because it doesn't take a DOM.
XalanSourceTreeDOMSupport domSupport;
XalanSourceTreeParserLiaison parserLiaison(domSupport);
domSupport.setParserLiaison(&parserLiaison);
XSLTProcessorEnvSupportDefault envSupport;
XObjectFactoryDefault xObjectFactory;
XPathFactoryDefault xPathFactory;
// Create a processor and connect to ProcessorEnvSupport object
XSLTEngineImpl theProcessor(parserLiaison,
envSupport,
domSupport,
xObjectFactory,
xPathFactory);
// Hook up the processor the the support object.
envSupport.setProcessor(&theProcessor);
// Create separate factory support object, so the stylesheet's
// factory-created XPath instance are independent from processor's.
XPathFactoryDefault ssXPathFactory;
// Create a stylesheet construction context, using the
// stylesheet's factory support objects.
StylesheetConstructionContextDefault constContext( theProcessor,
ssXPathFactory);
StylesheetExecutionContextDefault execuContext(
theProcessor,
envSupport,
domSupport,
xObjectFactory);
// Create the XSL Input Source
const XSLTInputSource xslStringSource("\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xsl");
XalanDocument* const domXSL = parserLiaison.parseXMLStream(xslStringSource);
// Here is one of the tests. It will be verified when we do the transform.
XSLTInputSource xslXalanNode(domXSL);
// Set the system ID, so relative URIs are resolved properly...
xslXalanNode.setSystemId(xslStringSource.getSystemId());
XalanNode *theNode, *firstChild;
// Here is another test
theNode = xslXalanNode.getNode();
firstChild = theNode->getFirstChild();
value = firstChild->getNodeValue();
h.checkAPIResults(value, XalanDOMString(" This is THE Smoke Test "), "XSLTInputSource.getNode()", logFile,
theOutputFile, theGoldFile);
// Create the XML Input Source
const XSLTInputSource xmlStringSource("\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xml");
XalanDocument* const domXML = parserLiaison.parseXMLStream(xmlStringSource);
// Here is the final test. It too will be verified when we do the transform.
XSLTInputSource xmlXalanNode;
xmlXalanNode.setNode(domXML);
// Do the transform and report the results.
theProcessor.process(xmlXalanNode, //inputSource,
xslXalanNode, //stylesheetSource,
theResultTarget3, //outputTarget,
constContext,
execuContext);
// Reset testcase name
h.data.testOrFile = "InputSource-TestCase3b";
h.checkResults(theOutputFile,
theGoldFile,
logFile);
}
// TestCase4 will use the following API. Default constructor of XSLTInputSource will take a string.
// - XSLTInputSource(const char*)
// - XSLTInputSource(const char*)
void testCase4(
XalanTransformer& xalan,
XalanXMLFileReporter& logFile,
const XalanDOMString& outBase,
const XalanDOMString& theGoldFile,
XalanFileUtility& h)
{
const XalanDOMString theOutputFile = outBase + XalanDOMString("\\InputSource-TestCase4.out");
const XSLTResultTarget theResultTarget(theOutputFile);
h.data.testOrFile = "InputSource-TestCase4";
// This code exercises the stated methods of XSLTInputSource
// Do the transform and report the results.
xalan.transform("\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xml",
"\\xml-xalan\\test\\tests\\capi\\smoke\\smoke01.xsl",
theResultTarget);
h.checkResults(theOutputFile, theGoldFile, logFile);
}
// TestCase5 uses XercesDOMWrapperParsedSource class to wrap a xerces generated dom.
//
void
testCase5(
XalanTransformer& xalan,
XalanXMLFileReporter& logFile,
const XalanDOMString& xml,
const XalanDOMString& xsl,
const XalanDOMString& outBase,
const XalanDOMString& theGoldFile,
XalanFileUtility& h)
{
using xercesc::XercesDOMParser;
using xercesc::DOMDocument;
h.data.testOrFile = "InputSource-TestCase5";
const XSLTInputSource xmlInputSource(xml);
XercesDOMParser theParser;
theParser.parse(xmlInputSource);
const DOMDocument* const theDOM = theParser.getDocument();
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
// This is the wrapper class for Xerces DOM.
const XercesDOMWrapperParsedSource xmlDocWrapper(theDOM,
theParserLiaison,
theDOMSupport,
xml);
const XalanDOMString theOutputFile(outBase + XalanDOMString("\\InputSource-TestCase5.out"));
const XSLTInputSource xslInputSource(xsl);
const XSLTResultTarget theResultTarget(theOutputFile);
// Do the transform and report the results.
xalan.transform(xmlDocWrapper, xslInputSource, theResultTarget);
h.checkResults(theOutputFile, theGoldFile, logFile);
}
int
runTests(
int argc,
char* argv[])
{
int theResult = 0;
XalanFileUtility h;
// Set the program help string, then get the command line parameters.
//
setHelp(h);
if (h.getParams(argc, argv, "INPUTSOURCE-RESULTS") == true)
{
// Generate and Initialize Unique result logfile, and get drive designation
//
const XalanDOMString UniqRunid = h.generateUniqRunid();
const XalanDOMString drive(h.getDrive());
const XalanDOMString resultFilePrefix("isource");
const XalanDOMString resultsFile(drive + h.args.output + resultFilePrefix + UniqRunid + XalanFileUtility::s_xmlSuffix);
XalanXMLFileReporter logFile(resultsFile);
logFile.logTestFileInit("XSLTInputSource Testing: Give various types of allowable Inputs. ");
try
{
XalanTransformer xalan;
XalanDOMString fileName;
// Get testfiles from the capi\smoke directory, create output directory, .
//
const XalanDOMString currentDir("smoke");
const XalanDOMString theOutputDir = h.args.output + currentDir;
h.checkAndCreateDir(theOutputDir);
typedef XalanFileUtility::FileNameVectorType FileNameVectorType;
// Get the single file found in the "smoke" directory, and run tests.
//
const FileNameVectorType files = h.getTestFileNames(h.args.base, currentDir, true);
logFile.logTestCaseInit(currentDir);
for(FileNameVectorType::size_type i = 0; i < files.size(); ++i)
{
fileName = files[i];
h.data.testOrFile = fileName;
// Set up the input/output files.
const XalanDOMString theXSLFile= h.args.base + currentDir + XalanFileUtility::s_pathSep + fileName;
const XalanDOMString theXMLFile = h.generateFileName(theXSLFile,"xml");
h.data.xmlFileURL = theXMLFile;
h.data.xslFileURL = theXSLFile;
// Set the gold file.
XalanDOMString theGoldFile = h.args.gold + currentDir + XalanFileUtility::s_pathSep + fileName;
theGoldFile = h.generateFileName(theGoldFile, "out");
// Execute the test cases.
//
testCase1(xalan, logFile, theXMLFile, theXSLFile, theOutputDir, theGoldFile, h);
testCase2(xalan, logFile, theOutputDir, theGoldFile, h);
testCase3(logFile, theOutputDir, theGoldFile, h);
testCase4(xalan, logFile, theOutputDir, theGoldFile, h);
testCase5(xalan, logFile, theXMLFile, theXSLFile, theOutputDir, theGoldFile, h);
}
logFile.logTestCaseClose("Done", "Pass");
h.reportPassFail(logFile, UniqRunid);
logFile.logTestFileClose("ISource Testing: ", "Done");
logFile.close();
h.analyzeResults(xalan, resultsFile);
}
catch(...)
{
cerr << "Exception caught!!!" << endl << endl;
theResult = -1;
}
}
return theResult;
}
int
main(
int argc,
char* argv[])
{
#if !defined(NDEBUG) && defined(_MSC_VER)
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
int theResult = 0;
try
{
using xercesc::XMLPlatformUtils;
// Call the static initializers for xerces and xalan, and create a transformer
//
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
theResult = runTests(argc, argv);
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
XalanTransformer::ICUCleanUp();
}
catch(...)
{
cerr << "Initialization failed!" << endl << endl;
theResult = -1;
}
return theResult;
}
|