[288886]: [xpath2] fn:resolve-qname has not tests
https://bugs.eclipse.org/bugs/show_bug.cgi?id=288886
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllW3CFunctionTests.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllW3CFunctionTests.java
index 6fa00b1..27bcd56 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllW3CFunctionTests.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllW3CFunctionTests.java
@@ -116,6 +116,7 @@
suite.addTestSuite(SeqIDFuncTest.class);
suite.addTestSuite(DaysFromDurationFuncTest.class);
suite.addTestSuite(DocumentURIFuncTest.class);
+ suite.addTestSuite(ResolveQNameFuncTest.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/AllW3CFunctionTests.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/AllW3CFunctionTests.java
index 6603ab3..54914b1 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/AllW3CFunctionTests.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/AllW3CFunctionTests.java
@@ -114,6 +114,7 @@
suite.addTestSuite(SeqIDFuncTest.class);
suite.addTestSuite(DaysFromDurationFuncTest.class);
suite.addTestSuite(DocumentURIFuncTest.class);
+ suite.addTestSuite(ResolveQNameFuncTest.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/ResolveQNameFuncTest.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/ResolveQNameFuncTest.java
new file mode 100644
index 0000000..7f78509
--- /dev/null
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/functions/ResolveQNameFuncTest.java
@@ -0,0 +1,456 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Standards for Technology in Automotive Retail and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Carver (STAR) - bug 288886 - add unit tests and fix fn:resolve-qname function
+ *******************************************************************************/
+package org.eclipse.wst.xml.xpath2.processor.testsuite.functions;
+
+import java.net.URL;
+
+import org.apache.xerces.xs.XSModel;
+import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
+import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
+import org.eclipse.wst.xml.xpath2.processor.DynamicError;
+import org.eclipse.wst.xml.xpath2.processor.Evaluator;
+import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
+import org.eclipse.wst.xml.xpath2.processor.StaticError;
+import org.eclipse.wst.xml.xpath2.processor.XPathParserException;
+import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
+import org.eclipse.wst.xml.xpath2.processor.test.AbstractPsychoPathTest;
+
+public class ResolveQNameFuncTest extends AbstractPsychoPathTest {
+
+ public void test_fn_resolve_qname_1() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "FOCA0002";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName(\"aName::\", /doc)";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_2() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "FONS0004";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName(\"p1:doc\", /doc)";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_3() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName((), /doc)";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_4() throws Exception {
+ String inputFile = "/TestSources/MixNS.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "c";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace("cm", "http://www.example.com");
+ dc.add_namespace("ed", "http://www.example.edu");
+
+ String xpath = "fn:string(fn:local-name-from-QName(fn:resolve-QName(\"cm:c\", /a/b/cm:c)))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_5() throws Exception {
+ String inputFile = "/TestSources/MixNS.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "http://www.example.com";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace("cm", "http://www.example.com");
+ dc.add_namespace("ed", "http://www.example.edu");
+
+ String xpath = "fn:string(fn:namespace-uri-from-QName(fn:resolve-QName(\"cm:c\", /a/b/cm:c)))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_6() throws Exception {
+ String inputFile = "/TestSources/MixNS.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "c";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace("cm", "http://www.example.com");
+ dc.add_namespace("ed", "http://www.example.edu");
+
+ String xpath = "fn:string(fn:local-name-from-QName(fn:resolve-QName(\"ed:c\", /a/b/ed:c)))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_8() throws Exception {
+ String inputFile = "/TestSources/MixNS.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "c";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace("cm", "http://www.example.com");
+ dc.add_namespace("ed", "http://www.example.edu");
+
+ String xpath = "fn:string(fn:local-name-from-QName(fn:resolve-QName(\"c\", /a/b/cm:c)))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_fn_resolve_qname_9() throws Exception {
+ String inputFile = "/TestSources/examples.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "http://www.w3.org/XQueryTest/someExamples";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://www.w3.org/XQueryTest/someExamples");
+
+ String xpath = "fn:string(fn:namespace-uri-from-QName(fn:resolve-QName(\"E6-Root\", /E6-Root)))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_K_ResolveQnameConstructFunc_1() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "XPST0017";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName()";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_K_ResolveQnameConstructFunc_2() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "XPST0017";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName(\"wrongparam\")";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_K_ResolveQnameConstructFunc_3() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "XPST0017";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:resolve-QName(\"wrongparam\", \"takes a node\", \"wrong\")";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+
+ public void test_K_ResolveQnameConstructFunc_4() throws Exception {
+ String inputFile = "/TestSources/emptydoc.xml";
+ String xqFile = "/Queries/XQuery/Functions/URIFunc/ResolveURIFunc/fn-resolve-uri-1.xq";
+ String expectedResult = "XPTY0004";
+ URL fileURL = bundle.getEntry(inputFile);
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ String xpath = "fn:empty(fn:resolve-QName((), \"a string\"))";
+
+ String actual = null;
+ try {
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ actual = buildResultString(rs);
+
+ } catch (XPathParserException ex) {
+ actual = ex.code();
+ } catch (StaticError ex) {
+ actual = ex.code();
+ } catch (DynamicError ex) {
+ actual = ex.code();
+ }
+
+ assertEquals("XPath Result Error " + xqFile + ":", expectedResult,
+ actual);
+ }
+}
\ No newline at end of file