File expectedDir = new File(rootDir,
XQueryUtil.xquery(catalog, ns + "ns:test-suite/@ResultOffsetPath").get(0).getValue());
File queryDir = new File(rootDir,
XQueryUtil.xquery(catalog, ns + "ns:test-suite/@XQueryQueryOffsetPath").get(0).getValue());
File testSourcesDir = new File(rootDir, "TestSources");
Nodes testCases = XQueryUtil.xquery(catalog, ns + "//ns:test-case");
for (int i=0; i < testCases.size(); i++) {
Node testCase = testCases.get(i);
// String groupTitle = XQueryUtil.xquery(testCase, ns + "../ns:GroupInfo/ns:title").get(0).getValue();
String path = XQueryUtil.xquery(testCase, "@FilePath").get(0).getValue();
File query = new File(new File(queryDir, path),
XQueryUtil.xquery(testCase, ns + "ns:query/@name").get(0).getValue() + ".xq");
String squery = readQuery(query);
System.out.println(i + ": " + query + " ...");
if (XQueryUtil.xquery(testCase, ns + "ns:spec-citation[@section-pointer='id-validate']").size() > 0) {
System.out.println(" ************* IGNORED SCHEMA AWARE FUNCTIONALITY *****");
continue; // ignore validate() function (nux is not schema aware)
}
if (squery == null) {
System.out.println(" ************* IGNORED *****");
continue;
}
Nodes inputs = XQueryUtil.xquery(testCase, ns + "ns:input-file");
Map vars = new HashMap();
for (int j=0; j < inputs.size(); j++) {
File input = new File(testSourcesDir, inputs.get(j).getValue() + ".xml");
String varName = ((Element) inputs.get(j)).getAttributeValue("variable");
Document inputDoc = buildDocument(input);
// System.out.println(inputDoc.getBaseURI());
if (true) XOMUtil.Normalizer.STRIP.normalize(inputDoc);
vars.put(varName, inputDoc);
}
Nodes expectedErrors = XQueryUtil.xquery(testCase, ns + "ns:expected-error");
Nodes expectedOutputs = XQueryUtil.xquery(testCase, ns + "ns:output-file");
boolean inspect = false;
for (int k=0; !inspect && k < expectedOutputs.size(); k++) {
String compare = ((Element)expectedOutputs.get(k)).getAttributeValue("compare");
if ("Inspect".equals(compare)) inspect = true;
}
Nodes results = null;
try { // here's where the query is actually executed
XQuery xquery = new XQuery(squery, testSourcesDir.toURI());
// XQuery xquery = new XQuery(squery, query.toURI());
// XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery(squery, query.toURI());
results = xquery.execute(null, null, vars).toNodes();