[298267]: [xpath2] problems with xpath2 "instance of" evaluation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298267
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllPsychoPathTests.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllPsychoPathTests.java
index f38b0b0..b31cff3 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllPsychoPathTests.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AllPsychoPathTests.java
@@ -34,6 +34,7 @@
suite.addTestSuite(XPathDecimalFormatTest.class);
suite.addTestSuite(LiteralUtilsTest.class);
suite.addTestSuite(TestWTPDOMXPath2.class);
+ suite.addTestSuite(KindTestSITest.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/KindTestSITest.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/KindTestSITest.java
new file mode 100644
index 0000000..5b99a83
--- /dev/null
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/KindTestSITest.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * 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 - initial api and implementation bug 262765
+ *******************************************************************************/
+
+package org.eclipse.wst.xml.xpath2.processor.test;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.apache.xerces.jaxp.validation.XMLSchemaFactory;
+import org.apache.xerces.xs.XSModel;
+import org.eclipse.wst.xml.xpath2.processor.*;
+import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
+import org.xml.sax.SAXException;
+
+public class KindTestSITest extends AbstractPsychoPathTest {
+
+ public void testElementTest1() throws Exception {
+ String inputFile = "/TestSources/SpecialTypes.xml";
+ String expectedResult = "true";
+ URL fileURL = bundle.getEntry(inputFile);
+ Schema jaxpSchema = loadSchema();
+ loadDOMDocument(fileURL, jaxpSchema);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://typedecl");
+ // addUserDefinedSimpleTypes(schema, dc);
+
+ String xpath = "/root/InterleaveType instance of element()";
+ 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:", expectedResult, actual);
+ }
+
+ public void testElementTest2() throws Exception {
+ String inputFile = "/TestSources/SpecialTypes.xml";
+ String expectedResult = "true";
+ URL fileURL = bundle.getEntry(inputFile);
+ Schema jaxpSchema = loadSchema();
+ loadDOMDocument(fileURL, jaxpSchema);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://typedecl");
+ // addUserDefinedSimpleTypes(schema, dc);
+
+ String xpath = "/root/InterleaveType instance of element(InterleaveType)";
+ 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:", expectedResult, actual);
+ }
+
+ public void testElementTest3() throws Exception {
+ String inputFile = "/TestSources/SpecialTypes.xml";
+ String expectedResult = "false";
+ URL fileURL = bundle.getEntry(inputFile);
+ Schema jaxpSchema = loadSchema();
+ loadDOMDocument(fileURL, jaxpSchema);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://typedecl");
+ // addUserDefinedSimpleTypes(schema, dc);
+
+ String xpath = "/root/InterleaveType instance of element(integer)";
+ 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:", expectedResult, actual);
+ }
+
+
+ public void testXPathInstanceOf4() throws Exception {
+ // Bug 298267
+ // This test should fail
+ String inputFile = "/TestSources/SpecialTypes.xml";
+ String expectedResult = "true";
+ URL fileURL = bundle.getEntry(inputFile);
+ Schema jaxpSchema = loadSchema();
+ loadDOMDocument(fileURL, jaxpSchema);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://typedecl");
+ // addUserDefinedSimpleTypes(schema, dc);
+
+ String xpath = "/root/InterleaveType instance of element(InterleaveType, InterleaveType)";
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ XSBoolean result = (XSBoolean) rs.first();
+
+ String actual = result.string_value();
+
+ assertEquals(expectedResult, actual);
+
+ }
+
+ public void testXPathInstanceOf5() throws Exception {
+ // Bug 298267
+ // This test should fail
+ String inputFile = "/TestSources/SpecialTypes.xml";
+ String expectedResult = "false";
+ URL fileURL = bundle.getEntry(inputFile);
+ Schema jaxpSchema = loadSchema();
+ loadDOMDocument(fileURL, jaxpSchema);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.add_namespace(null, "http://typedecl");
+ // addUserDefinedSimpleTypes(schema, dc);
+
+ String xpath = "/root/InterleaveType instance of element(InterleaveType, InterleaveType2)";
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, domDoc);
+ ResultSequence rs = eval.evaluate(path);
+
+ XSBoolean result = (XSBoolean) rs.first();
+
+ String actual = result.string_value();
+
+ assertEquals(expectedResult, actual);
+
+ }
+
+ private Schema loadSchema() throws SAXException {
+ String schemaFile = "/TestSources/SpecialTypes.xsd";
+ SchemaFactory schemaFactory = new XMLSchemaFactory();
+ URL schemaURL = bundle.getEntry(schemaFile);
+ Schema jaxpschema = schemaFactory.newSchema(schemaURL);
+ return jaxpschema;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/core/SeqExprInstanceOfTest.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/core/SeqExprInstanceOfTest.java
index 40c4fed..fac0e19 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/core/SeqExprInstanceOfTest.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/testsuite/core/SeqExprInstanceOfTest.java
@@ -6518,8 +6518,6 @@
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
-
-
}
}
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
index 7f78509..e7f87e4 100644
--- 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
@@ -421,8 +421,8 @@
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";
+ String xqFile = "Queries/XQuery/ResolveQNameConstructFunc/K-ResolveQNameConstructFunc-4.xq";
+ String expectedResult = "true";
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);