[298535] [xpath2] adding test cases for the bug, https://bugs.eclipse.org/bugs/show_bug.cgi?id=298535
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xml b/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xml new file mode 100644 index 0000000..ce0511a --- /dev/null +++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xml
@@ -0,0 +1,5 @@ +<Example> + <x mesg="hello" /> + <x mesg="world" /> + <x mesg="test" /> +</Example> \ No newline at end of file
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xsd b/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xsd new file mode 100644 index 0000000..42e0da7 --- /dev/null +++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/bugTestFiles/attrNodeTest.xsd
@@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:element name="Example"> + <xs:complexType> + <xs:sequence> + <xs:element name="x" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="mesg" type="mesg_Type" /> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:simpleType name="mesg_Type"> + <xs:restriction base="xs:string"> + <xs:enumeration value="hello" /> + <xs:enumeration value="world" /> + <xs:enumeration value="test" /> + </xs:restriction> + </xs:simpleType> + +</xs:schema>
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java index 3cac23b..d3fe0a9 100644 --- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java +++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java
@@ -1264,6 +1264,181 @@ assertEquals("true", actual); } + + public void testAttrNode_Test1() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute()"; + 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("true", actual); + } + + public void testAttrNode_Test2() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute(xx)"; + 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("false", actual); + } + + public void testAttrNode_Test3() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)"; + 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("true", actual); + } + + public void testAttrNode_Test4() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)"; + 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("false", actual); + } + + public void testAttrNode_Test5() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)"; + 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("true", actual); + } + + public void testAttrNode_Test6() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)"; + 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("false", actual); + } + + public void testAttrNode_Test7() throws Exception { + // Bug ?? + URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); + URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); + + loadDOMDocument(fileURL, schemaURL); + + // Get XSModel object for the Schema + XSModel schema = getGrammar(schemaURL); + + DynamicContext dc = setupDynamicContext(schema); + + String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*"; + 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("true", actual); + } private CollationProvider createLengthCollatorProvider() { return new CollationProvider() {