2020-02-17 21:05:20 +00:00
|
|
|
/*
|
2020-02-17 21:13:50 +00:00
|
|
|
* Copyright (c) 2001-2008
|
2020-02-17 21:05:20 +00:00
|
|
|
* DecisionSoft Limited. All rights reserved.
|
2020-02-17 21:13:50 +00:00
|
|
|
* Copyright (c) 2004-2008
|
2020-02-17 21:05:20 +00:00
|
|
|
* Oracle. All rights reserved.
|
|
|
|
*
|
2020-02-17 21:12:51 +00:00
|
|
|
* Licensed 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
|
2020-02-17 21:05:20 +00:00
|
|
|
*
|
2020-02-17 21:12:51 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2020-02-17 21:17:06 +00:00
|
|
|
* $Id: runner.cpp 687 2008-11-26 14:25:40Z jpcs $
|
2020-02-17 21:05:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable: 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <xqilla/xqts/TestSuiteParser.hpp>
|
|
|
|
#include <xqilla/xqts/TestSuiteResultListener.hpp>
|
|
|
|
#include <xqilla/xqts/TestSuiteRunner.hpp>
|
|
|
|
|
2020-02-17 21:11:31 +00:00
|
|
|
#include <set>
|
2020-02-17 21:05:20 +00:00
|
|
|
#include <iostream>
|
2020-02-17 21:11:31 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <stdio.h>
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
#include <xercesc/framework/URLInputSource.hpp>
|
|
|
|
#include <xercesc/util/XMLEntityResolver.hpp>
|
|
|
|
#include <xercesc/framework/MemBufFormatTarget.hpp>
|
|
|
|
#include <xercesc/dom/DOMException.hpp>
|
|
|
|
|
|
|
|
#include <xqilla/xqilla-simple.hpp>
|
|
|
|
#include <xqilla/context/VariableStore.hpp>
|
|
|
|
#include <xqilla/functions/FunctionConstructor.hpp>
|
|
|
|
#include <xqilla/utils/XQillaPlatformUtils.hpp>
|
2020-02-17 21:11:31 +00:00
|
|
|
#include <xqilla/events/ContentSequenceFilter.hpp>
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
#if defined(XERCES_HAS_CPP_NAMESPACE)
|
|
|
|
XERCES_CPP_NAMESPACE_USE
|
|
|
|
#endif
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class XQillaTestSuiteRunner : public TestSuiteRunner, private XMLEntityResolver, private ModuleResolver, private URIResolver
|
|
|
|
{
|
|
|
|
public:
|
2020-02-17 21:11:31 +00:00
|
|
|
XQillaTestSuiteRunner(const string &singleTest, TestSuiteResultListener *results, XQillaConfiguration *conf, XQilla::Language lang);
|
|
|
|
virtual ~XQillaTestSuiteRunner();
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
virtual void addSource(const string &id, const string &filename, const string &schema);
|
|
|
|
virtual void addSchema(const string &id, const string &filename, const string &uri);
|
|
|
|
virtual void addModule(const string &id, const string &filename);
|
2020-02-17 21:12:51 +00:00
|
|
|
virtual void addCollectionDoc(const string &id, const string &filename);
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
virtual void startTestGroup(const string &name);
|
|
|
|
virtual void endTestGroup();
|
|
|
|
|
|
|
|
virtual void runTestCase(const TestCase &testCase);
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
|
|
|
|
virtual bool resolveModuleLocation(VectorOfStrings* result, const XMLCh* nsUri, const StaticContext* context);
|
2020-02-17 21:12:51 +00:00
|
|
|
virtual bool resolveDocument(Sequence &result, const XMLCh* uri, DynamicContext* context, const QueryPathNode *projection);
|
|
|
|
virtual bool resolveCollection(Sequence &result, const XMLCh* uri, DynamicContext* context, const QueryPathNode *projection);
|
|
|
|
virtual bool resolveDefaultCollection(Sequence &result, DynamicContext* context, const QueryPathNode *projection);
|
2020-02-17 21:17:06 +00:00
|
|
|
virtual bool putDocument(const Node::Ptr &document, const XMLCh *uri, DynamicContext *context) { return true; }
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-17 21:11:31 +00:00
|
|
|
XQillaConfiguration *m_conf;
|
|
|
|
XQilla::Language m_lang;
|
2020-02-17 21:05:20 +00:00
|
|
|
string m_szSingleTest;
|
|
|
|
string m_szFullTestName;
|
|
|
|
const TestCase* m_pCurTestCase;
|
|
|
|
|
|
|
|
// id -> filename
|
|
|
|
map<string, string> m_inputFiles;
|
|
|
|
// schemaURL -> filename
|
|
|
|
map<string, string> m_schemaFiles;
|
|
|
|
// id -> filename
|
|
|
|
map<string, string> m_moduleFiles;
|
|
|
|
// id -> list of inputFiles ID
|
|
|
|
map<string, list<string> > m_collections;
|
2020-02-17 21:11:31 +00:00
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
AutoDelete<XQQuery> m_docQuery;
|
|
|
|
map<string, Sequence> m_inputDocs;
|
2020-02-17 21:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void usage(const char *progname)
|
|
|
|
{
|
|
|
|
const char *name = progname;
|
|
|
|
while(*progname != 0) {
|
|
|
|
if(*progname == '/' || *progname == '\\') {
|
|
|
|
++progname;
|
|
|
|
name = progname;
|
|
|
|
} else {
|
|
|
|
++progname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Usage: " << name << " [options] <location of the XQTS suite> (<test group or case name>)?" << endl << endl;
|
|
|
|
cout << "-e <file> : Use the given file as a known error file" << endl;
|
|
|
|
cout << "-E <file> : Output an error file" << endl;
|
|
|
|
cout << "-h : Show this display" << endl;
|
2020-02-17 21:11:31 +00:00
|
|
|
cout << "-r : Output results as XML" << endl;
|
|
|
|
cout << "-u : Parse XQuery Update (also uses Xerces-C data model)" << endl;
|
2020-02-17 21:17:06 +00:00
|
|
|
cout << "-s : Parse XSLT 2.0" << endl;
|
2020-02-17 21:11:31 +00:00
|
|
|
cout << "-x : Use the Xerces-C data model (default is FastXDM)" << endl;
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
string testSuitePath;
|
|
|
|
string singleTest;
|
|
|
|
string errorFile;
|
|
|
|
string outputErrorFile;
|
|
|
|
bool xmlResults = false;
|
2020-02-17 21:11:31 +00:00
|
|
|
bool update = false;
|
2020-02-17 21:17:06 +00:00
|
|
|
bool xslt = false;
|
2020-02-17 21:11:31 +00:00
|
|
|
|
|
|
|
XercesConfiguration xercesConf;
|
|
|
|
FastXDMConfiguration fastConf;
|
|
|
|
XQillaConfiguration *conf = &fastConf;
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
for(int i = 1; i < argc; ++i) {
|
|
|
|
if(*argv[i] == '-' && argv[i][2] == '\0' ){
|
|
|
|
|
|
|
|
switch(argv[i][1]) {
|
|
|
|
case 'h': {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case 'e': {
|
|
|
|
i++;
|
|
|
|
if(i == argc) {
|
|
|
|
cout << "Missing argument to option 'e'" << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
errorFile = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'E': {
|
|
|
|
i++;
|
|
|
|
if(i == argc) {
|
|
|
|
cout << "Missing argument to option 'E'" << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
outputErrorFile = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
2020-02-17 21:11:31 +00:00
|
|
|
case 'r': {
|
2020-02-17 21:05:20 +00:00
|
|
|
xmlResults = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-17 21:11:31 +00:00
|
|
|
case 'u': {
|
|
|
|
update = true;
|
|
|
|
conf = &xercesConf;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-17 21:17:06 +00:00
|
|
|
case 's': {
|
|
|
|
xslt = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-17 21:11:31 +00:00
|
|
|
case 'x': {
|
|
|
|
conf = &xercesConf;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-17 21:05:20 +00:00
|
|
|
default: {
|
|
|
|
cout << "Unknown option: " << argv[i] << endl;
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(testSuitePath == "") {
|
|
|
|
testSuitePath = argv[i];
|
|
|
|
}
|
|
|
|
else if(singleTest == "") {
|
|
|
|
singleTest = argv[i];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(testSuitePath == "") {
|
|
|
|
cout << "Test suite path not specified!" << endl;
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XQillaPlatformUtils::enableExtendedPrecision(false);
|
|
|
|
XQilla xqilla;
|
|
|
|
|
|
|
|
Janitor<TestSuiteResultListener> results(0);
|
|
|
|
if(xmlResults) {
|
|
|
|
results.reset(new XMLReportResultListener());
|
|
|
|
XMLReportResultListener *xmlreport = (XMLReportResultListener*)results.get();
|
2020-02-17 21:13:50 +00:00
|
|
|
xmlreport->setImplementation("XQilla", "2.0");
|
2020-02-17 21:05:20 +00:00
|
|
|
xmlreport->setOrganization("XQilla", "http://xqilla.sourceforge.net");
|
|
|
|
|
2020-02-17 21:13:50 +00:00
|
|
|
if(!update) {
|
|
|
|
xmlreport->addImplementationDefinedItem("expressionUnicode", "UTF-16");
|
|
|
|
xmlreport->addImplementationDefinedItem("implicitTimezone", "Defined by the system clock");
|
|
|
|
xmlreport->addImplementationDefinedItem("XMLVersion", "1.1");
|
|
|
|
xmlreport->addImplementationDefinedItem("axes", "Full axis support");
|
|
|
|
xmlreport->addImplementationDefinedItem("defaultOrderEmpty", "empty least");
|
|
|
|
xmlreport->addImplementationDefinedItem("normalizationForms", "NFC, NFD, NFKC, NFKD");
|
|
|
|
xmlreport->addImplementationDefinedItem("docProcessing", "schema validation");
|
|
|
|
}
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
xmlreport->addFeature("Minimal Conformance", true);
|
2020-02-17 21:13:50 +00:00
|
|
|
if(!update) {
|
|
|
|
xmlreport->addFeature("Schema Import", true);
|
|
|
|
xmlreport->addFeature("Schema Validation", true);
|
|
|
|
xmlreport->addFeature("Static Typing", false);
|
|
|
|
xmlreport->addFeature("Static Typing Extensions", false);
|
|
|
|
xmlreport->addFeature("Full Axis", true);
|
|
|
|
xmlreport->addFeature("Module", true);
|
|
|
|
xmlreport->addFeature("Serialization", false);
|
|
|
|
xmlreport->addFeature("Trivial XML Embedding", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlreport->setSubmittor("John Snelson", "john.snelson@oracle.com");
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
results.reset(new ConsoleResultListener());
|
|
|
|
}
|
|
|
|
|
|
|
|
KnownErrorChecker knownErrors(results.get());
|
|
|
|
if(errorFile != "" && !knownErrors.loadErrors(errorFile)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
XQilla::Language lang = XQilla::XQUERY;
|
|
|
|
if(update) lang = XQilla::XQUERY_UPDATE;
|
|
|
|
else if(xslt) lang = XQilla::XSLT2;
|
|
|
|
|
|
|
|
XQillaTestSuiteRunner runner(singleTest, &knownErrors, conf, lang);
|
2020-02-17 21:05:20 +00:00
|
|
|
TestSuiteParser parser(testSuitePath, &runner);
|
|
|
|
|
|
|
|
parser.run();
|
|
|
|
|
|
|
|
bool passed = true;
|
|
|
|
if(xmlResults) {
|
|
|
|
((XMLReportResultListener*)results.get())->printReport();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
passed = ((ConsoleResultListener*)results.get())->printReport();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(errorFile != "") {
|
|
|
|
passed = knownErrors.printReport();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(outputErrorFile != "" && !knownErrors.saveErrors(outputErrorFile)) {
|
|
|
|
cout << "Unable to open error file: " << outputErrorFile << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return passed ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-02-17 21:11:31 +00:00
|
|
|
XQillaTestSuiteRunner::XQillaTestSuiteRunner(const string &singleTest, TestSuiteResultListener *results, XQillaConfiguration *conf, XQilla::Language lang)
|
2020-02-17 21:05:20 +00:00
|
|
|
: TestSuiteRunner(results),
|
2020-02-17 21:11:31 +00:00
|
|
|
m_conf(conf),
|
|
|
|
m_lang(lang),
|
2020-02-17 21:05:20 +00:00
|
|
|
m_szSingleTest(singleTest),
|
2020-02-17 21:17:06 +00:00
|
|
|
m_pCurTestCase(NULL),
|
|
|
|
m_docQuery(0)
|
2020-02-17 21:05:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:11:31 +00:00
|
|
|
XQillaTestSuiteRunner::~XQillaTestSuiteRunner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:05:20 +00:00
|
|
|
void XQillaTestSuiteRunner::startTestGroup(const string &name)
|
|
|
|
{
|
|
|
|
if(m_szFullTestName != "")
|
|
|
|
m_szFullTestName += ":";
|
|
|
|
m_szFullTestName += name;
|
|
|
|
|
|
|
|
m_results->startTestGroup(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQillaTestSuiteRunner::endTestGroup()
|
|
|
|
{
|
2020-02-17 21:12:51 +00:00
|
|
|
string::size_type nColonPos = m_szFullTestName.find_last_of(":");
|
|
|
|
if(nColonPos != string::npos)
|
2020-02-17 21:05:20 +00:00
|
|
|
m_szFullTestName = string(m_szFullTestName.c_str(), nColonPos);
|
|
|
|
else
|
|
|
|
m_szFullTestName = "";
|
|
|
|
|
|
|
|
m_results->endTestGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQillaTestSuiteRunner::addSource(const string &id, const string &filename, const string &schema)
|
|
|
|
{
|
|
|
|
m_inputFiles[id] = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQillaTestSuiteRunner::addSchema(const string &id, const string &filename, const string &uri)
|
|
|
|
{
|
|
|
|
m_schemaFiles[uri] = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQillaTestSuiteRunner::addModule(const string &id, const string &filename)
|
|
|
|
{
|
|
|
|
m_moduleFiles[id] = filename;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:12:51 +00:00
|
|
|
void XQillaTestSuiteRunner::addCollectionDoc(const string &id, const string &filename)
|
2020-02-17 21:05:20 +00:00
|
|
|
{
|
|
|
|
m_collections[id].push_back(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XQillaTestSuiteRunner::runTestCase(const TestCase &testCase)
|
|
|
|
{
|
|
|
|
if(m_szSingleTest != "" &&
|
|
|
|
testCase.name.find(m_szSingleTest) == string::npos &&
|
|
|
|
m_szFullTestName.find(m_szSingleTest) == string::npos) {
|
|
|
|
m_results->reportSkip(testCase, "Not run");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
if(m_szFullTestName.substr(0,21)=="Optional:StaticTyping" && !testCase.updateTest) {
|
2020-02-17 21:05:20 +00:00
|
|
|
m_results->reportSkip(testCase, "Static typing not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_szFullTestName.substr(0,26)=="Optional:TrivialEmbedding") {
|
|
|
|
m_results->reportSkip(testCase, "TrivialEmbedding not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XQilla xqilla;
|
|
|
|
|
|
|
|
m_pCurTestCase=&testCase;
|
2020-02-17 21:17:06 +00:00
|
|
|
|
|
|
|
DynamicContext *context = xqilla.createContext(m_lang, m_conf);
|
|
|
|
AutoDelete<DynamicContext> contextGuard(context);
|
|
|
|
|
2020-02-17 21:05:20 +00:00
|
|
|
try {
|
|
|
|
context->setImplicitTimezone(context->getItemFactory()->
|
2020-02-17 21:17:06 +00:00
|
|
|
createDayTimeDuration(X("PT0S"), context));
|
2020-02-17 21:05:20 +00:00
|
|
|
context->setXMLEntityResolver(this);
|
|
|
|
context->setModuleResolver(this);
|
2020-02-17 21:11:31 +00:00
|
|
|
context->registerURIResolver(this, /*adopt*/false);
|
2020-02-17 21:17:06 +00:00
|
|
|
if(testCase.xsltTest || testCase.updateTest)
|
|
|
|
context->setBaseURI(X(testCase.queryURL.c_str()));
|
2020-02-17 21:11:31 +00:00
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
if(testCase.updateTest) {
|
|
|
|
if(testCase.stateTime == 0) {
|
|
|
|
m_inputDocs.clear();
|
|
|
|
m_docQuery.set(0);
|
|
|
|
}
|
|
|
|
else if(m_docQuery.get() == 0) {
|
|
|
|
m_results->reportSkip(testCase, "State 0 failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XQQuery *parsedQuery = xqilla.parseFromURI(X(testCase.queryURL.c_str()), contextGuard.adopt());
|
|
|
|
AutoDelete<XQQuery> parsedQueryGuard(parsedQuery);
|
2020-02-17 21:05:20 +00:00
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
if(testCase.updateTest && testCase.stateTime == 0) {
|
|
|
|
m_docQuery.set(parsedQuery);
|
|
|
|
parsedQueryGuard.adopt();
|
|
|
|
}
|
2020-02-17 21:05:20 +00:00
|
|
|
|
|
|
|
map<string, string>::const_iterator v;
|
|
|
|
for(v=testCase.extraVars.begin();v!=testCase.extraVars.end();v++) {
|
2020-02-17 21:17:06 +00:00
|
|
|
AutoDelete<XQQuery> pInnerQuery(xqilla.parseFromURI(X(v->second.c_str()), context, XQilla::NO_ADOPT_CONTEXT));
|
|
|
|
Sequence doc=pInnerQuery->execute(context)->toSequence(context);
|
2020-02-17 21:11:31 +00:00
|
|
|
context->setExternalVariable(X(v->first.c_str()), doc);
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
for(v=testCase.inputVars.begin();v!=testCase.inputVars.end();v++) {
|
2020-02-17 21:11:31 +00:00
|
|
|
string filename = v->second;
|
2020-02-17 21:17:06 +00:00
|
|
|
Sequence doc;
|
2020-02-17 21:11:31 +00:00
|
|
|
|
|
|
|
if(testCase.updateTest) {
|
2020-02-17 21:17:06 +00:00
|
|
|
if(m_inputDocs.find(v->first) != m_inputDocs.end()) {
|
|
|
|
doc = m_inputDocs[v->first];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
doc = const_cast<DynamicContext*>(m_docQuery->getStaticContext())->
|
|
|
|
resolveDocument(X(filename.c_str()), 0);
|
|
|
|
m_inputDocs[v->first] = doc;
|
2020-02-17 21:11:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-17 21:17:06 +00:00
|
|
|
else {
|
|
|
|
doc = context->resolveDocument(X(filename.c_str()), 0);
|
|
|
|
}
|
2020-02-17 21:11:31 +00:00
|
|
|
|
|
|
|
context->setExternalVariable(X(v->first.c_str()), doc);
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
for(v=testCase.inputURIVars.begin();v!=testCase.inputURIVars.end();v++) {
|
2020-02-17 21:17:06 +00:00
|
|
|
Item::Ptr uri = context->getItemFactory()->createString(X(v->second.c_str()),context);
|
2020-02-17 21:11:31 +00:00
|
|
|
context->setExternalVariable(X(v->first.c_str()), uri);
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
2020-02-17 21:17:06 +00:00
|
|
|
for(v=testCase.inputParams.begin();v!=testCase.inputParams.end();v++) {
|
|
|
|
Item::Ptr value = context->getItemFactory()->createUntypedAtomic(X(v->second.c_str()),context);
|
|
|
|
context->setExternalVariable(X(v->first.c_str()), value);
|
|
|
|
}
|
|
|
|
if(testCase.templateName != "") {
|
|
|
|
Item::Ptr value = context->getItemFactory()->createUntypedAtomic(X(testCase.templateName.c_str()),context);
|
|
|
|
context->setExternalVariable(X("http://xqilla.sourceforge.net/Functions"), X("name"), value);
|
|
|
|
}
|
2020-02-17 21:05:20 +00:00
|
|
|
if(!testCase.contextItem.empty())
|
|
|
|
{
|
|
|
|
Sequence doc=context->resolveDocument(X(testCase.contextItem.c_str()), 0);
|
|
|
|
context->setContextItem(doc.first());
|
|
|
|
}
|
|
|
|
context->setContextPosition(1);
|
|
|
|
context->setContextSize(1);
|
|
|
|
time_t curTime;
|
|
|
|
context->setCurrentTime(time(&curTime));
|
|
|
|
|
2020-02-17 21:11:31 +00:00
|
|
|
// Emulate the XQuery serialization spec
|
|
|
|
MemBufFormatTarget target;
|
|
|
|
EventSerializer writer("UTF-8", "1.1", &target, context->getMemoryManager());
|
|
|
|
NSFixupFilter nsfilter(&writer, context->getMemoryManager());
|
|
|
|
ContentSequenceFilter csfilter(&nsfilter);
|
2020-02-17 21:05:20 +00:00
|
|
|
|
2020-02-17 21:17:06 +00:00
|
|
|
parsedQuery->execute(&csfilter, context);
|
2020-02-17 21:11:31 +00:00
|
|
|
testResults(testCase, (char*)target.getRawBuffer());
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
catch(XQException& e) {
|
|
|
|
ostringstream oss;
|
|
|
|
// if(e.getXQueryLine() == 0) {
|
|
|
|
// oss << "No line number:" << std::endl << UTF8(e.getError()) << std::endl;
|
|
|
|
// oss << "at " << UTF8(e.getXQueryFile()) << ":" << e.getXQueryLine() << ":" << e.getXQueryColumn() << std::endl;
|
|
|
|
// oss << "at " << e.getCppFile() << ":" << e.getCppLine() << std::endl;
|
|
|
|
// m_results->reportFailUnexpectedError(testCase, oss.str(), "XXX");
|
|
|
|
// }
|
|
|
|
// else if(e.getXQueryColumn() == 0) {
|
|
|
|
// oss << "No column number:" << std::endl << UTF8(e.getError()) << std::endl;
|
|
|
|
// oss << "at " << UTF8(e.getXQueryFile()) << ":" << e.getXQueryLine() << ":" << e.getXQueryColumn() << std::endl;
|
|
|
|
// oss << "at " << e.getCppFile() << ":" << e.getCppLine() << std::endl;
|
|
|
|
// m_results->reportFailUnexpectedError(testCase, oss.str(), "XXX");
|
|
|
|
// }
|
|
|
|
// else if(e.getXQueryFile() == 0) {
|
|
|
|
// oss << "No file name:" << std::endl << UTF8(e.getError()) << std::endl;
|
|
|
|
// oss << "at " << UTF8(e.getXQueryFile()) << ":" << e.getXQueryLine() << ":" << e.getXQueryColumn() << std::endl;
|
|
|
|
// oss << "at " << e.getCppFile() << ":" << e.getCppLine() << std::endl;
|
|
|
|
// m_results->reportFailUnexpectedError(testCase, oss.str(), "XXX");
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
oss << UTF8(e.getError()) << std::endl;
|
|
|
|
oss << "at " << UTF8(e.getXQueryFile()) << ":" << e.getXQueryLine() << ":" << e.getXQueryColumn() << std::endl;
|
|
|
|
oss << "at " << e.getCppFile() << ":" << e.getCppLine() << std::endl;
|
|
|
|
testErrors(testCase, oss.str());
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
catch(DOMException &de) {
|
|
|
|
testErrors(testCase, string("DOMException: ") + UTF8(de.getMessage()));
|
|
|
|
}
|
|
|
|
catch(...) {
|
|
|
|
testErrors(testCase, "[Unknown exception]");
|
|
|
|
}
|
|
|
|
m_pCurTestCase=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputSource* XQillaTestSuiteRunner::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
|
|
|
|
{
|
|
|
|
const XMLCh* systemId=resourceIdentifier->getSystemId();
|
|
|
|
if((systemId==NULL || *systemId==0) &&
|
|
|
|
resourceIdentifier->getResourceIdentifierType()==XMLResourceIdentifier::SchemaGrammar) {
|
|
|
|
|
|
|
|
map<string, string>::const_iterator i =
|
|
|
|
m_schemaFiles.find(UTF8(resourceIdentifier->getNameSpace()));
|
|
|
|
if(i != m_schemaFiles.end()) {
|
|
|
|
return new URLInputSource(X(i->second.c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(resourceIdentifier->getResourceIdentifierType()==XMLResourceIdentifier::UnKnown) {
|
|
|
|
list<std::pair<string, string> >::const_iterator i;
|
|
|
|
for(i=m_pCurTestCase->moduleFiles.begin(); i!=m_pCurTestCase->moduleFiles.end(); i++)
|
|
|
|
{
|
|
|
|
if(i->first == UTF8(resourceIdentifier->getNameSpace()) &&
|
|
|
|
i->second == UTF8(resourceIdentifier->getSystemId()))
|
|
|
|
{
|
|
|
|
map<string, string>::const_iterator i2 = m_moduleFiles.find(i->second);
|
|
|
|
if(i2 != m_moduleFiles.end()) {
|
|
|
|
string file=i2->second+".xq";
|
|
|
|
return new URLInputSource(X(file.c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XQillaTestSuiteRunner::resolveModuleLocation(VectorOfStrings* result, const XMLCh* nsUri, const StaticContext* context)
|
|
|
|
{
|
|
|
|
bool bFound=false;
|
|
|
|
list<std::pair<string, string> >::const_iterator i;
|
|
|
|
for(i=m_pCurTestCase->moduleFiles.begin(); i!=m_pCurTestCase->moduleFiles.end(); i++)
|
|
|
|
{
|
|
|
|
if(i->first == UTF8(nsUri))
|
|
|
|
{
|
|
|
|
result->push_back(context->getMemoryManager()->getPooledString(i->second.c_str()));
|
|
|
|
bFound=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:12:51 +00:00
|
|
|
bool XQillaTestSuiteRunner::resolveDocument(Sequence &result, const XMLCh* uri, DynamicContext* context, const QueryPathNode *projection)
|
2020-02-17 21:05:20 +00:00
|
|
|
{
|
|
|
|
std::map<std::string, std::string>::iterator it=m_inputFiles.find(UTF8(uri));
|
|
|
|
if(it!=m_inputFiles.end())
|
|
|
|
{
|
2020-02-17 21:12:51 +00:00
|
|
|
result=context->resolveDocument(X(it->second.c_str()), 0, projection);
|
2020-02-17 21:05:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:12:51 +00:00
|
|
|
bool XQillaTestSuiteRunner::resolveCollection(Sequence &result, const XMLCh* uri, DynamicContext* context, const QueryPathNode *projection)
|
2020-02-17 21:05:20 +00:00
|
|
|
{
|
|
|
|
std::map<std::string, std::list<std::string> >::iterator it=m_collections.find(UTF8(uri));
|
|
|
|
if(it!=m_collections.end())
|
|
|
|
{
|
|
|
|
for(std::list<std::string>::iterator s=it->second.begin();s!=it->second.end();s++)
|
|
|
|
{
|
2020-02-17 21:12:51 +00:00
|
|
|
result.joinSequence(context->resolveDocument(X(s->c_str()), 0, projection));
|
2020-02-17 21:05:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:12:51 +00:00
|
|
|
bool XQillaTestSuiteRunner::resolveDefaultCollection(Sequence &result, DynamicContext* context, const QueryPathNode *projection)
|
2020-02-17 21:05:20 +00:00
|
|
|
{
|
|
|
|
if(!m_pCurTestCase->defaultCollection.empty())
|
2020-02-17 21:12:51 +00:00
|
|
|
return resolveCollection(result, X(m_pCurTestCase->defaultCollection.c_str()), context, projection);
|
2020-02-17 21:05:20 +00:00
|
|
|
return false;
|
|
|
|
}
|