dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2009-2010 Standards for Technology in Automotive Retail and others. |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * David Carver (STAR) - initial API and implementation |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 10 | * Mukul Gandhi - bug 273719 - improvements to fn:string-length function |
| 11 | * Mukul Gandhi - bug 273795 - improvements to fn:substring function |
| 12 | * Mukul Gandhi - bug 274471 - improvements to fn:string function |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 13 | * Mukul Gandhi - bug 274725 - improvements to fn:base-uri function |
| 14 | * Mukul Gandhi - bug 274731 - improvements to fn:document-uri function |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 15 | * Mukul Gandhi - bug 274784 - improvements to xs:boolean data type |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 16 | * Mukul Gandhi - bug 274805 - improvements to xs:integer data type |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 17 | * Mukul Gandhi - bug 274952 - implements xs:long data type |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 18 | * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 19 | * Mukul Gandhi - bug 277602 - implements xs:negativeInteger data type |
| 20 | * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 21 | * Mukul Gandhi - bug 277608 implements xs:short data type |
| 22 | * bug 277609 implements xs:nonNegativeInteger data type |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 23 | * bug 277629 implements xs:unsignedLong data type |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 24 | * bug 277632 implements xs:positiveInteger data type |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 25 | * bug 277639 implements xs:byte data type |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 26 | * bug 277642 implements xs:unsignedInt data type |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 27 | * bug 277645 implements xs:unsignedShort data type |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 28 | * bug 277650 implements xs:unsignedByte data type |
| 29 | * bug 279373 improvements to multiply operation on xs:yearMonthDuration |
| 30 | * data type. |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 31 | * bug 279376 improvements to xs:yearMonthDuration division operation |
| 32 | * bug 281046 implementation of xs:base64Binary data type |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 33 | * Jesper S Moller - bug 286061 correct handling of quoted string |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 34 | * Jesper S Moller - bug 280555 - Add pluggable collation support |
jmoller | aaedb5f | 2009-12-16 14:18:49 +0000 | [diff] [blame] | 35 | * Jesper S Moller - bug 297958 Fix fn:nilled for elements |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 36 | * Mukul Gandhi - bug 298519 improvements to fn:number implementation, catering |
| 37 | * to node arguments. |
mgandhi | 1fc7741 | 2010-02-02 15:07:05 +0000 | [diff] [blame] | 38 | * Mukul Gandhi - bug 301539 fix for "context undefined" bug in case of zero |
mgandhi | 13d897f | 2010-04-18 09:46:00 +0000 | [diff] [blame] | 39 | * arity of fn:name function. |
| 40 | * Mukul Gandhi - bug 309585 implementation of xs:normalizedString data type |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 41 | * Jesper S Moller - bug 311480 - fix problem with name matching on keywords |
jmoller | 2c384ed | 2010-06-24 23:48:34 +0000 | [diff] [blame] | 42 | * Jesper S Moller - bug 312191 - instance of test fails with partial matches |
mgandhi | 247b6e7 | 2010-07-07 11:50:37 +0000 | [diff] [blame] | 43 | * Mukul Gandhi - bug 318313 - improvements to computation of typed values of nodes, |
| 44 | * when validated by XML Schema primitive types |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 45 | * Mukul Gandhi - bug 323900 - improving computing the typed value of element & |
| 46 | * attribute nodes, where the schema type of nodes |
| 47 | * are simple, with varieties 'list' and 'union'. |
| 48 | * Mukul Gandhi - bug 325262 - providing ability to store an XPath2 sequence into |
mgandhi | d2cb89c | 2011-01-16 11:59:19 +0000 | [diff] [blame] | 49 | * an user-defined variable. |
mgandhi | 8ac9e1c | 2011-01-20 04:15:58 +0000 | [diff] [blame] | 50 | * Mukul Gandhi - bug 334478 implementation of xs:token data type |
| 51 | * Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, |
mgandhi | 3727fd6 | 2011-03-01 00:59:09 +0000 | [diff] [blame] | 52 | * ID, IDREF and NMTOKEN. |
mgandhi | b3af5cf | 2011-03-05 08:58:57 +0000 | [diff] [blame] | 53 | * Mukul Gandhi - bug 338494 - prohibiting xpath expressions starting with / or // to be parsed. |
mgandhi | 43d0fcf | 2011-03-06 01:46:48 +0000 | [diff] [blame] | 54 | * Mukul Gandhi - bug 338999 - improving compliance of function 'fn:subsequence'. implementing full arity support. |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 55 | * Mukul Gandhi - bug 339025 - fixes to fn:distinct-values function. ability to find distinct values on node items. |
| 56 | * Mukul Gandhi - bug 341862 - improvements to computation of typed value of xs:boolean nodes. |
| 57 | * Mukul Gandhi - bug 343224 - allow user defined simpleType definitions to be available in in-scope schema types |
| 58 | * Mukul Gandhi - bug 353373 - "preceding" & "following" axes behavior is erroneous |
mgandhi | 6418399 | 2014-05-16 12:07:25 +0530 | [diff] [blame] | 59 | * Mukul Gandhi - bug 360306 - improvements to "resolve-QName" function and xs:QName type implementation |
| 60 | * Mukul Gandhi added a test case for improvements to "eq" function for anyURI |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 61 | *******************************************************************************/ |
| 62 | package org.eclipse.wst.xml.xpath2.processor.test; |
| 63 | |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 64 | import java.math.BigInteger; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 65 | import java.net.URL; |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 66 | import java.util.Comparator; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 67 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 68 | import javax.xml.parsers.DocumentBuilder; |
| 69 | import javax.xml.parsers.DocumentBuilderFactory; |
| 70 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 71 | import org.apache.xerces.xs.XSModel; |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 72 | import org.eclipse.core.runtime.Platform; |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 73 | import org.eclipse.wst.xml.xpath2.processor.CollationProvider; |
| 74 | import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 75 | import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; |
| 76 | import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
mgandhi | 13d897f | 2010-04-18 09:46:00 +0000 | [diff] [blame] | 77 | import org.eclipse.wst.xml.xpath2.processor.DynamicError; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 78 | import org.eclipse.wst.xml.xpath2.processor.Evaluator; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 79 | import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 80 | import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; |
mgandhi | 3727fd6 | 2011-03-01 00:59:09 +0000 | [diff] [blame] | 81 | import org.eclipse.wst.xml.xpath2.processor.XPathParserException; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 82 | import org.eclipse.wst.xml.xpath2.processor.ast.XPath; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 83 | import org.eclipse.wst.xml.xpath2.processor.internal.types.QName; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 84 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean; |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 85 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 86 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble; |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 87 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 88 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 89 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger; |
| 90 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString; |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 91 | import org.osgi.framework.Bundle; |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 92 | import org.w3c.dom.Document; |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 93 | import org.xml.sax.InputSource; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 94 | |
| 95 | public class TestBugs extends AbstractPsychoPathTest { |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 96 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 97 | private static final String URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR = "urn:x-eclipse:xpath20:funky-collator"; |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 98 | |
| 99 | private Bundle bundle; |
| 100 | |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 101 | @Override |
| 102 | protected void setUp() throws Exception { |
| 103 | // TODO Auto-generated method stub |
| 104 | super.setUp(); |
| 105 | bundle = Platform |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 106 | .getBundle("org.eclipse.wst.xml.xpath2.processor.tests"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 107 | |
| 108 | } |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 109 | |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 110 | public void testNamesWhichAreKeywords() throws Exception { |
| 111 | // Bug 273719 |
| 112 | URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml"); |
| 113 | loadDOMDocument(fileURL); |
| 114 | |
| 115 | // Get XML Schema Information for the Document |
| 116 | XSModel schema = getGrammar(); |
| 117 | |
| 118 | DynamicContext dc = setupDynamicContext(schema); |
| 119 | |
mgandhi | 1e589ea | 2012-06-16 19:42:57 +0000 | [diff] [blame] | 120 | // String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)"; |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 121 | String xpath = "(/element/eq eq 'eq') or //child::xs:*"; |
| 122 | XPath path = compileXPath(dc, xpath); |
| 123 | |
| 124 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 125 | ResultSequence rs = eval.evaluate(path); |
| 126 | |
| 127 | XSBoolean result = (XSBoolean) rs.first(); |
| 128 | |
| 129 | String actual = result.string_value(); |
| 130 | |
| 131 | assertEquals("true", actual); |
| 132 | } |
| 133 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 134 | public void testStringLengthWithElementArg() throws Exception { |
| 135 | // Bug 273719 |
| 136 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 137 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 138 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 139 | // Get XML Schema Information for the Document |
| 140 | XSModel schema = getGrammar(); |
| 141 | |
| 142 | DynamicContext dc = setupDynamicContext(schema); |
| 143 | |
| 144 | String xpath = "string-length(x) > 2"; |
| 145 | XPath path = compileXPath(dc, xpath); |
| 146 | |
| 147 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 148 | ResultSequence rs = eval.evaluate(path); |
| 149 | |
| 150 | XSBoolean result = (XSBoolean) rs.first(); |
| 151 | |
| 152 | String actual = result.string_value(); |
| 153 | |
| 154 | assertEquals("true", actual); |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 155 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 156 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 157 | public void testBug273795Arity2() throws Exception { |
| 158 | // Bug 273795 |
| 159 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 160 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 161 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 162 | // Get XML Schema Information for the Document |
| 163 | XSModel schema = getGrammar(); |
| 164 | |
| 165 | DynamicContext dc = setupDynamicContext(schema); |
| 166 | |
| 167 | // test with arity 2 |
| 168 | String xpath = "substring(x, 3) = 'happy'"; |
| 169 | XPath path = compileXPath(dc, xpath); |
| 170 | |
| 171 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 172 | ResultSequence rs = eval.evaluate(path); |
| 173 | |
| 174 | XSBoolean result = (XSBoolean) rs.first(); |
| 175 | |
| 176 | String actual = result.string_value(); |
| 177 | |
| 178 | assertEquals("true", actual); |
| 179 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 180 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 181 | public void testBug273795Arity3() throws Exception { |
| 182 | // Bug 273795 |
| 183 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 184 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 185 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 186 | // Get XML Schema Information for the Document |
| 187 | XSModel schema = getGrammar(); |
| 188 | |
| 189 | DynamicContext dc = setupDynamicContext(schema); |
| 190 | |
| 191 | // test with arity 3 |
| 192 | String xpath = "substring(x, 3, 4) = 'happ'"; |
| 193 | XPath path = compileXPath(dc, xpath); |
| 194 | |
| 195 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 196 | ResultSequence rs = eval.evaluate(path); |
| 197 | |
| 198 | XSBoolean result = (XSBoolean) rs.first(); |
| 199 | |
| 200 | String actual = result.string_value(); |
| 201 | |
| 202 | assertEquals("true", actual); |
| 203 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 204 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 205 | public void testStringFunctionBug274471() throws Exception { |
| 206 | // Bug 274471 |
| 207 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 208 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 209 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 210 | // Get XML Schema Information for the Document |
| 211 | XSModel schema = getGrammar(); |
| 212 | |
| 213 | DynamicContext dc = setupDynamicContext(schema); |
| 214 | |
| 215 | String xpath = "x/string() = 'unhappy'"; |
| 216 | XPath path = compileXPath(dc, xpath); |
| 217 | |
| 218 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 219 | ResultSequence rs = eval.evaluate(path); |
| 220 | |
| 221 | XSBoolean result = (XSBoolean) rs.first(); |
| 222 | |
| 223 | String actual = result.string_value(); |
| 224 | |
| 225 | assertEquals("true", actual); |
| 226 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 227 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 228 | public void testStringLengthFunctionBug274471() throws Exception { |
| 229 | // Bug 274471. string-length() with arity 0 |
| 230 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 231 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 232 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 233 | // Get XML Schema Information for the Document |
| 234 | XSModel schema = getGrammar(); |
| 235 | |
| 236 | DynamicContext dc = setupDynamicContext(schema); |
| 237 | |
| 238 | String xpath = "x/string-length() = 7"; |
| 239 | XPath path = compileXPath(dc, xpath); |
| 240 | |
| 241 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 242 | ResultSequence rs = eval.evaluate(path); |
| 243 | |
| 244 | XSBoolean result = (XSBoolean) rs.first(); |
| 245 | |
| 246 | String actual = result.string_value(); |
| 247 | |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 248 | assertEquals("true", actual); |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 249 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 250 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 251 | public void testNormalizeSpaceFunctionBug274471() throws Exception { |
| 252 | // Bug 274471. normalize-space() with arity 0 |
| 253 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 254 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 255 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 256 | // Get XML Schema Information for the Document |
| 257 | XSModel schema = getGrammar(); |
| 258 | |
| 259 | DynamicContext dc = setupDynamicContext(schema); |
| 260 | |
| 261 | String xpath = "x/normalize-space() = 'unhappy'"; |
| 262 | XPath path = compileXPath(dc, xpath); |
| 263 | |
| 264 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 265 | ResultSequence rs = eval.evaluate(path); |
| 266 | |
| 267 | XSBoolean result = (XSBoolean) rs.first(); |
| 268 | |
| 269 | String actual = result.string_value(); |
| 270 | |
| 271 | assertEquals("true", actual); |
| 272 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 273 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 274 | public void testAnyUriEqualityBug() throws Exception { |
| 275 | // Bug 274719 |
| 276 | // reusing the XML document from another bug |
| 277 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 278 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 279 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 280 | // Get XML Schema Information for the Document |
| 281 | XSModel schema = getGrammar(); |
| 282 | |
| 283 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 284 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 285 | String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')"; |
| 286 | XPath path = compileXPath(dc, xpath); |
| 287 | |
| 288 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 289 | ResultSequence rs = eval.evaluate(path); |
| 290 | |
| 291 | XSBoolean result = (XSBoolean) rs.first(); |
| 292 | |
| 293 | String actual = result.string_value(); |
| 294 | |
| 295 | assertEquals("true", actual); |
| 296 | } |
| 297 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 298 | public void testBaseUriBug() throws Exception { |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 299 | // Bug 274725 |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 300 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 301 | // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 302 | // DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 303 | loadDOMDocument(new URL("http://resolved-locally/xml/note.xml")); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 304 | |
| 305 | // for testing this bug, we read the XML document from the web. |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 306 | // this ensures, that base-uri property of DOM is not null. |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 307 | // domDoc = docBuilder.parse("http://resolved-locally/xml/note.xml"); |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 308 | |
| 309 | // we pass XSModel as null for this test case. Otherwise, we would |
| 310 | // get an exception. |
| 311 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 312 | |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 313 | String xpath = "base-uri(note) eq xs:anyURI('http://resolved-locally/xml/note.xml')"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 314 | |
| 315 | // please note: The below XPath would also work, with base-uri using |
| 316 | // arity 0. |
| 317 | // String xpath = |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 318 | // "note/base-uri() eq xs:anyURI('http://resolved-locally/xml/note.xml')"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 319 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 320 | XPath path = compileXPath(dc, xpath); |
| 321 | |
| 322 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 323 | ResultSequence rs = eval.evaluate(path); |
| 324 | |
| 325 | XSBoolean result = (XSBoolean) rs.first(); |
| 326 | |
| 327 | String actual = result.string_value(); |
| 328 | |
dacarver | acf5e12 | 2009-08-05 02:48:43 +0000 | [diff] [blame] | 329 | assertEquals("true", actual); |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 330 | } |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 331 | |
| 332 | public void testDocumentUriBug() throws Exception { |
| 333 | // Bug 274731 |
| 334 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 335 | DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 336 | |
| 337 | InputSource inputSource = getTestSource("http://resolved-locally/xml/note.xml"); |
| 338 | domDoc = docBuilder.parse(inputSource); |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 339 | |
| 340 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 341 | |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 342 | String xpath = "document-uri(/) eq xs:anyURI('http://resolved-locally/xml/note.xml')"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 343 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 344 | XPath path = compileXPath(dc, xpath); |
| 345 | |
| 346 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 347 | ResultSequence rs = eval.evaluate(path); |
| 348 | |
| 349 | XSBoolean result = (XSBoolean) rs.first(); |
| 350 | |
| 351 | String actual = "false"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 352 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 353 | if (result != null) { |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 354 | actual = result.string_value(); |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | assertEquals("true", actual); |
| 358 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 359 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 360 | public void testBooleanTypeBug() throws Exception { |
| 361 | // Bug 274784 |
| 362 | // reusing the XML document from another bug |
| 363 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 364 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 365 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 366 | // Get XML Schema Information for the Document |
| 367 | XSModel schema = getGrammar(); |
| 368 | |
| 369 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 370 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 371 | String xpath = "xs:boolean('1') eq xs:boolean('true')"; |
| 372 | XPath path = compileXPath(dc, xpath); |
| 373 | |
| 374 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 375 | ResultSequence rs = eval.evaluate(path); |
| 376 | |
| 377 | XSBoolean result = (XSBoolean) rs.first(); |
| 378 | |
| 379 | String actual = result.string_value(); |
| 380 | |
| 381 | assertEquals("true", actual); |
| 382 | } |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 383 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 384 | public void testDateConstructorBug() throws Exception { |
| 385 | // Bug 274792 |
| 386 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml"); |
| 387 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 388 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 389 | // Get XML Schema Information for the Document |
| 390 | XSModel schema = getGrammar(); |
| 391 | |
| 392 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 393 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 394 | String xpath = "xs:date(x) eq xs:date('2009-01-01')"; |
| 395 | XPath path = compileXPath(dc, xpath); |
| 396 | |
| 397 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 398 | ResultSequence rs = eval.evaluate(path); |
| 399 | |
| 400 | XSBoolean result = (XSBoolean) rs.first(); |
| 401 | |
| 402 | String actual = result.string_value(); |
| 403 | |
| 404 | assertEquals("true", actual); |
| 405 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 406 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 407 | public void testIntegerDataTypeBug() throws Exception { |
| 408 | // Bug 274805 |
| 409 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml"); |
| 410 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 411 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 412 | // Get XML Schema Information for the Document |
| 413 | XSModel schema = getGrammar(); |
| 414 | |
| 415 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 416 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 417 | String xpath = "xs:integer(x) gt 100"; |
| 418 | XPath path = compileXPath(dc, xpath); |
| 419 | |
| 420 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 421 | ResultSequence rs = eval.evaluate(path); |
| 422 | |
| 423 | XSBoolean result = (XSBoolean) rs.first(); |
| 424 | |
| 425 | String actual = result.string_value(); |
| 426 | |
| 427 | assertEquals("true", actual); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 428 | } |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 429 | |
| 430 | public void testLongDataType() throws Exception { |
| 431 | // Bug 274952 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 432 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 433 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 434 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 435 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 436 | // Get XML Schema Information for the Document |
| 437 | XSModel schema = getGrammar(); |
| 438 | |
| 439 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 440 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 441 | // long min value is -9223372036854775808 |
| 442 | // and max value can be 9223372036854775807 |
| 443 | String xpath = "xs:long('9223372036854775807') gt 0"; |
| 444 | XPath path = compileXPath(dc, xpath); |
| 445 | |
| 446 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 447 | ResultSequence rs = eval.evaluate(path); |
| 448 | |
| 449 | XSBoolean result = (XSBoolean) rs.first(); |
| 450 | |
| 451 | String actual = result.string_value(); |
| 452 | |
| 453 | assertEquals("true", actual); |
| 454 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 455 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 456 | public void testIntDataType() throws Exception { |
| 457 | // Bug 275105 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 458 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 459 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 460 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 461 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 462 | // Get XML Schema Information for the Document |
| 463 | XSModel schema = getGrammar(); |
| 464 | |
| 465 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 466 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 467 | // int min value is -2147483648 |
| 468 | // and max value can be 2147483647 |
| 469 | String xpath = "xs:int('2147483647') gt 0"; |
| 470 | XPath path = compileXPath(dc, xpath); |
| 471 | |
| 472 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 473 | ResultSequence rs = eval.evaluate(path); |
| 474 | |
| 475 | XSBoolean result = (XSBoolean) rs.first(); |
| 476 | |
| 477 | String actual = result.string_value(); |
| 478 | |
| 479 | assertEquals("true", actual); |
| 480 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 481 | |
| 482 | public void testSchemaAwarenessForAttributes() throws Exception { |
| 483 | // Bug 276134 |
| 484 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 485 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 486 | |
| 487 | loadDOMDocument(fileURL, schemaURL); |
| 488 | |
| 489 | // Get XSModel object for the Schema |
| 490 | XSModel schema = getGrammar(schemaURL); |
| 491 | |
| 492 | DynamicContext dc = setupDynamicContext(schema); |
| 493 | |
| 494 | String xpath = "person/@dob eq xs:date('2006-12-10')"; |
| 495 | XPath path = compileXPath(dc, xpath); |
| 496 | |
| 497 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 498 | ResultSequence rs = eval.evaluate(path); |
| 499 | |
| 500 | XSBoolean result = (XSBoolean) rs.first(); |
| 501 | |
| 502 | String actual = result.string_value(); |
| 503 | |
| 504 | assertEquals("true", actual); |
| 505 | |
| 506 | } |
| 507 | |
| 508 | public void testSchemaAwarenessForElements() throws Exception { |
| 509 | // Bug 276134 |
| 510 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml"); |
| 511 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd"); |
| 512 | |
| 513 | loadDOMDocument(fileURL, schemaURL); |
| 514 | |
| 515 | // Get XSModel object for the Schema |
| 516 | XSModel schema = getGrammar(schemaURL); |
| 517 | |
| 518 | DynamicContext dc = setupDynamicContext(schema); |
| 519 | |
| 520 | String xpath = "person/dob eq xs:date('2006-12-10')"; |
| 521 | XPath path = compileXPath(dc, xpath); |
| 522 | |
| 523 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 524 | ResultSequence rs = eval.evaluate(path); |
| 525 | |
| 526 | XSBoolean result = (XSBoolean) rs.first(); |
| 527 | |
| 528 | String actual = result.string_value(); |
| 529 | |
| 530 | assertEquals("true", actual); |
| 531 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 532 | |
jmoller | aaedb5f | 2009-12-16 14:18:49 +0000 | [diff] [blame] | 533 | public void testNilled() throws Exception { |
| 534 | // This is a terrible shortcoming in the test suite, I'd say |
| 535 | URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml"); |
| 536 | URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd"); |
| 537 | |
| 538 | loadDOMDocument(fileURL, schemaURL); |
| 539 | |
| 540 | // Get XSModel object for the Schema |
| 541 | XSModel schema = getGrammar(schemaURL); |
| 542 | |
| 543 | DynamicContext dc = setupDynamicContext(schema); |
| 544 | |
| 545 | assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )")); |
| 546 | assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )")); |
| 547 | assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )")); |
| 548 | |
| 549 | assertFalse(evaluateBoolean(dc, "nilled(/root/element1)")); |
| 550 | assertTrue(evaluateBoolean(dc, "nilled(/root/element2)")); |
| 551 | assertFalse(evaluateBoolean(dc, "nilled(/root/element3)")); |
| 552 | assertFalse(evaluateBoolean(dc, "nilled(/root/element4)")); |
| 553 | } |
| 554 | |
| 555 | // I can't stand to see so much duplicated code!!! |
| 556 | private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception { |
| 557 | XPath path = compileXPath(dc, xpath); |
| 558 | |
| 559 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 560 | ResultSequence rs = eval.evaluate(path); |
| 561 | |
| 562 | XSBoolean result = (XSBoolean) rs.first(); |
| 563 | |
| 564 | return result.value(); |
| 565 | } |
| 566 | |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 567 | public void testXSNonPositiveInteger() throws Exception { |
| 568 | // Bug 277599 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 569 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 570 | |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 571 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 572 | loadDOMDocument(fileURL); |
| 573 | |
| 574 | // Get XML Schema Information for the Document |
| 575 | XSModel schema = getGrammar(); |
| 576 | |
| 577 | DynamicContext dc = setupDynamicContext(schema); |
| 578 | |
| 579 | // min value of xs:nonPositiveInteger is -INF |
| 580 | // max value is 0 |
| 581 | String xpath = "xs:nonPositiveInteger('0') eq 0"; |
| 582 | XPath path = compileXPath(dc, xpath); |
| 583 | |
| 584 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 585 | ResultSequence rs = eval.evaluate(path); |
| 586 | |
| 587 | XSBoolean result = (XSBoolean) rs.first(); |
| 588 | |
| 589 | String actual = result.string_value(); |
| 590 | |
| 591 | assertEquals("true", actual); |
| 592 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 593 | |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 594 | public void testXSNegativeInteger() throws Exception { |
| 595 | // Bug 277602 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 596 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 597 | |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 598 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 599 | loadDOMDocument(fileURL); |
| 600 | |
| 601 | // Get XML Schema Information for the Document |
| 602 | XSModel schema = getGrammar(); |
| 603 | |
| 604 | DynamicContext dc = setupDynamicContext(schema); |
| 605 | |
| 606 | // min value of xs:negativeInteger is -INF |
| 607 | // max value is -1 |
| 608 | String xpath = "xs:negativeInteger('-1') eq -1"; |
| 609 | XPath path = compileXPath(dc, xpath); |
| 610 | |
| 611 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 612 | ResultSequence rs = eval.evaluate(path); |
| 613 | |
| 614 | XSBoolean result = (XSBoolean) rs.first(); |
| 615 | |
| 616 | String actual = result.string_value(); |
| 617 | |
| 618 | assertEquals("true", actual); |
| 619 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 620 | |
dacarver | 72e78ba | 2009-05-25 03:40:46 +0000 | [diff] [blame] | 621 | public void testXSShort() throws Exception { |
| 622 | // Bug 277608 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 623 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 624 | |
dacarver | 72e78ba | 2009-05-25 03:40:46 +0000 | [diff] [blame] | 625 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 626 | loadDOMDocument(fileURL); |
| 627 | |
| 628 | // Get XML Schema Information for the Document |
| 629 | XSModel schema = getGrammar(); |
| 630 | |
| 631 | DynamicContext dc = setupDynamicContext(schema); |
| 632 | |
| 633 | // min value of xs:short is -32768 |
| 634 | // max value of xs:short is 32767 |
| 635 | String xpath = "xs:short('-32768') eq -32768"; |
| 636 | XPath path = compileXPath(dc, xpath); |
| 637 | |
| 638 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 639 | ResultSequence rs = eval.evaluate(path); |
| 640 | |
| 641 | XSBoolean result = (XSBoolean) rs.first(); |
| 642 | |
| 643 | String actual = result.string_value(); |
| 644 | |
| 645 | assertEquals("true", actual); |
| 646 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 647 | |
dacarver | 1bb092e | 2009-05-25 04:02:48 +0000 | [diff] [blame] | 648 | public void testXSNonNegativeInteger() throws Exception { |
| 649 | // Bug 277609 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 650 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 651 | |
dacarver | 1bb092e | 2009-05-25 04:02:48 +0000 | [diff] [blame] | 652 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 653 | loadDOMDocument(fileURL); |
| 654 | |
| 655 | // Get XML Schema Information for the Document |
| 656 | XSModel schema = getGrammar(); |
| 657 | |
| 658 | DynamicContext dc = setupDynamicContext(schema); |
| 659 | |
| 660 | // min value of xs:nonNegativeInteger is 0 |
| 661 | // max value of xs:nonNegativeInteger is INF |
| 662 | String xpath = "xs:nonNegativeInteger('0') eq 0"; |
| 663 | XPath path = compileXPath(dc, xpath); |
| 664 | |
| 665 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 666 | ResultSequence rs = eval.evaluate(path); |
| 667 | |
| 668 | XSBoolean result = (XSBoolean) rs.first(); |
| 669 | |
| 670 | String actual = result.string_value(); |
| 671 | |
| 672 | assertEquals("true", actual); |
| 673 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 674 | |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 675 | public void testXSUnsignedLong() throws Exception { |
| 676 | // Bug 277629 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 677 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 678 | |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 679 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 680 | loadDOMDocument(fileURL); |
| 681 | |
| 682 | // Get XML Schema Information for the Document |
| 683 | XSModel schema = getGrammar(); |
| 684 | |
| 685 | DynamicContext dc = setupDynamicContext(schema); |
| 686 | |
| 687 | // min value of xs:unsignedLong is 0 |
| 688 | // max value of xs:unsignedLong is 18446744073709551615 |
| 689 | String xpath = "xs:unsignedLong('0') eq 0"; |
| 690 | XPath path = compileXPath(dc, xpath); |
| 691 | |
| 692 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 693 | ResultSequence rs = eval.evaluate(path); |
| 694 | |
| 695 | XSBoolean result = (XSBoolean) rs.first(); |
| 696 | |
| 697 | String actual = result.string_value(); |
| 698 | |
| 699 | assertEquals("true", actual); |
| 700 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 701 | |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 702 | public void testXSPositiveInteger() throws Exception { |
| 703 | // Bug 277632 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 704 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 705 | |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 706 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 707 | loadDOMDocument(fileURL); |
| 708 | |
| 709 | // Get XML Schema Information for the Document |
| 710 | XSModel schema = getGrammar(); |
| 711 | |
| 712 | DynamicContext dc = setupDynamicContext(schema); |
| 713 | |
| 714 | // min value of xs:positiveInteger is 1 |
| 715 | // max value of xs:positiveInteger is INF |
| 716 | String xpath = "xs:positiveInteger('1') eq 1"; |
| 717 | XPath path = compileXPath(dc, xpath); |
| 718 | |
| 719 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 720 | ResultSequence rs = eval.evaluate(path); |
| 721 | |
| 722 | XSBoolean result = (XSBoolean) rs.first(); |
| 723 | |
| 724 | String actual = result.string_value(); |
| 725 | |
| 726 | assertEquals("true", actual); |
| 727 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 728 | |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 729 | public void testXSByte() throws Exception { |
| 730 | // Bug 277639 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 731 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 732 | |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 733 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 734 | loadDOMDocument(fileURL); |
| 735 | |
| 736 | // Get XML Schema Information for the Document |
| 737 | XSModel schema = getGrammar(); |
| 738 | |
| 739 | DynamicContext dc = setupDynamicContext(schema); |
| 740 | |
| 741 | // min value of xs:byte is -128 |
| 742 | // max value of xs:byte is 127 |
| 743 | String xpath = "xs:byte('-128') eq -128"; |
| 744 | XPath path = compileXPath(dc, xpath); |
| 745 | |
| 746 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 747 | ResultSequence rs = eval.evaluate(path); |
| 748 | |
| 749 | XSBoolean result = (XSBoolean) rs.first(); |
| 750 | |
| 751 | String actual = result.string_value(); |
| 752 | |
| 753 | assertEquals("true", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 754 | } |
| 755 | |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 756 | public void testXSUnsignedInt() throws Exception { |
| 757 | // Bug 277642 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 758 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 759 | |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 760 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 761 | loadDOMDocument(fileURL); |
| 762 | |
| 763 | // Get XML Schema Information for the Document |
| 764 | XSModel schema = getGrammar(); |
| 765 | |
| 766 | DynamicContext dc = setupDynamicContext(schema); |
| 767 | |
| 768 | // min value of xs:unsignedInt is 0 |
| 769 | // max value of xs:unsignedInt is 4294967295 |
| 770 | String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')"; |
| 771 | XPath path = compileXPath(dc, xpath); |
| 772 | |
| 773 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 774 | ResultSequence rs = eval.evaluate(path); |
| 775 | |
| 776 | XSBoolean result = (XSBoolean) rs.first(); |
| 777 | |
| 778 | String actual = result.string_value(); |
| 779 | |
| 780 | assertEquals("true", actual); |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 781 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 782 | |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 783 | public void testXSUnsignedShort() throws Exception { |
| 784 | // Bug 277645 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 785 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 786 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 787 | loadDOMDocument(fileURL); |
| 788 | |
| 789 | // Get XML Schema Information for the Document |
| 790 | XSModel schema = getGrammar(); |
| 791 | |
| 792 | DynamicContext dc = setupDynamicContext(schema); |
| 793 | |
| 794 | // min value of xs:unsignedShort is 0 |
| 795 | // max value of xs:unsignedShort is 65535 |
| 796 | String xpath = "xs:unsignedShort('65535') eq 65535"; |
| 797 | XPath path = compileXPath(dc, xpath); |
| 798 | |
| 799 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 800 | ResultSequence rs = eval.evaluate(path); |
| 801 | |
| 802 | XSBoolean result = (XSBoolean) rs.first(); |
| 803 | |
| 804 | String actual = result.string_value(); |
| 805 | |
| 806 | assertEquals("true", actual); |
| 807 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 808 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 809 | public void testXSYearMonthDurationMultiply() throws Exception { |
| 810 | // Bug 279373 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 811 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 812 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 813 | loadDOMDocument(fileURL); |
| 814 | |
| 815 | // Get XML Schema Information for the Document |
| 816 | XSModel schema = getGrammar(); |
| 817 | |
| 818 | DynamicContext dc = setupDynamicContext(schema); |
| 819 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 820 | String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3"; |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 821 | XPath path = compileXPath(dc, xpath); |
| 822 | |
| 823 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 824 | ResultSequence rs = eval.evaluate(path); |
| 825 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 826 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 827 | |
| 828 | String actual = result.string_value(); |
| 829 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 830 | assertEquals("P6Y9M", actual); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 831 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 832 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 833 | public void testXSYearMonthDurationDivide1() throws Exception { |
| 834 | // Bug 279376 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 835 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 836 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 837 | loadDOMDocument(fileURL); |
| 838 | |
| 839 | // Get XML Schema Information for the Document |
| 840 | XSModel schema = getGrammar(); |
| 841 | |
| 842 | DynamicContext dc = setupDynamicContext(schema); |
| 843 | |
| 844 | String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5"; |
| 845 | XPath path = compileXPath(dc, xpath); |
| 846 | |
| 847 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 848 | ResultSequence rs = eval.evaluate(path); |
| 849 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 850 | XSDuration result = (XSDuration) rs.first(); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 851 | |
| 852 | String actual = result.string_value(); |
| 853 | |
| 854 | assertEquals("P1Y11M", actual); |
| 855 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 856 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 857 | public void testXSYearMonthDurationDivide2() throws Exception { |
| 858 | // Bug 279376 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 859 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 860 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 861 | loadDOMDocument(fileURL); |
| 862 | |
| 863 | // Get XML Schema Information for the Document |
| 864 | XSModel schema = getGrammar(); |
| 865 | |
| 866 | DynamicContext dc = setupDynamicContext(schema); |
| 867 | |
| 868 | String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')"; |
| 869 | XPath path = compileXPath(dc, xpath); |
| 870 | |
| 871 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 872 | ResultSequence rs = eval.evaluate(path); |
| 873 | |
| 874 | XSDecimal result = (XSDecimal) rs.first(); |
| 875 | |
| 876 | String actual = result.string_value(); |
| 877 | |
| 878 | assertEquals("-2.5", actual); |
| 879 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 880 | |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 881 | public void testXSDayTimeDurationMultiply() throws Exception { |
| 882 | // Bug 279377 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 883 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 884 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 885 | loadDOMDocument(fileURL); |
| 886 | |
| 887 | // Get XML Schema Information for the Document |
| 888 | XSModel schema = getGrammar(); |
| 889 | |
| 890 | DynamicContext dc = setupDynamicContext(schema); |
| 891 | |
| 892 | String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1"; |
| 893 | XPath path = compileXPath(dc, xpath); |
| 894 | |
| 895 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 896 | ResultSequence rs = eval.evaluate(path); |
| 897 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 898 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 899 | |
| 900 | String actual = result.string_value(); |
| 901 | |
| 902 | assertEquals("PT4H33M", actual); |
| 903 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 904 | |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 905 | public void testXSDayTimeDurationDivide() throws Exception { |
| 906 | // Bug 279377 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 907 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 908 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 909 | loadDOMDocument(fileURL); |
| 910 | |
| 911 | // Get XML Schema Information for the Document |
| 912 | XSModel schema = getGrammar(); |
| 913 | |
| 914 | DynamicContext dc = setupDynamicContext(schema); |
| 915 | |
| 916 | String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5"; |
| 917 | XPath path = compileXPath(dc, xpath); |
| 918 | |
| 919 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 920 | ResultSequence rs = eval.evaluate(path); |
| 921 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 922 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 923 | |
| 924 | String actual = result.string_value(); |
| 925 | |
| 926 | assertEquals("PT17H40M7S", actual); |
| 927 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 928 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 929 | public void testNegativeZeroDouble() throws Exception { |
| 930 | // Bug 279406 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 931 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 932 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 933 | loadDOMDocument(fileURL); |
| 934 | |
| 935 | // Get XML Schema Information for the Document |
| 936 | XSModel schema = getGrammar(); |
| 937 | |
| 938 | DynamicContext dc = setupDynamicContext(schema); |
| 939 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 940 | String xpath = "-(xs:double('0'))"; |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 941 | XPath path = compileXPath(dc, xpath); |
| 942 | |
| 943 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 944 | ResultSequence rs = eval.evaluate(path); |
| 945 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 946 | XSDouble result = (XSDouble) rs.first(); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 947 | |
| 948 | String actual = result.string_value(); |
| 949 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 950 | assertEquals("-0", actual); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 951 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 952 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 953 | public void testNegativeZeroFloat() throws Exception { |
| 954 | // Bug 279406 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 955 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 956 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 957 | loadDOMDocument(fileURL); |
| 958 | |
| 959 | // Get XML Schema Information for the Document |
| 960 | XSModel schema = getGrammar(); |
| 961 | |
| 962 | DynamicContext dc = setupDynamicContext(schema); |
| 963 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 964 | String xpath = "-(xs:float('0'))"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 965 | XPath path = compileXPath(dc, xpath); |
| 966 | |
| 967 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 968 | ResultSequence rs = eval.evaluate(path); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 969 | |
| 970 | XSFloat result = (XSFloat) rs.first(); |
| 971 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 972 | String actual = result.string_value(); |
| 973 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 974 | assertEquals("-0", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 975 | } |
| 976 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 977 | public void testXSUnsignedByte() throws Exception { |
| 978 | // Bug 277650 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 979 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 980 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 981 | loadDOMDocument(fileURL); |
| 982 | |
| 983 | // Get XML Schema Information for the Document |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 984 | XSModel schema = getGrammar(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 985 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 986 | DynamicContext dc = setupDynamicContext(schema); |
| 987 | |
| 988 | // min value of xs:unsignedByte is 0 |
| 989 | // max value of xs:unsignedByte is 255 |
| 990 | String xpath = "xs:unsignedByte('255') eq 255"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 991 | XPath path = compileXPath(dc, xpath); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 992 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 993 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 994 | ResultSequence rs = eval.evaluate(path); |
| 995 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 996 | XSBoolean result = (XSBoolean) rs.first(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 997 | |
| 998 | String actual = result.string_value(); |
| 999 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 1000 | assertEquals("true", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 1001 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1002 | |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 1003 | public void testXSBase64Binary() throws Exception { |
| 1004 | // Bug 281046 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1005 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 1006 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1007 | loadDOMDocument(fileURL); |
| 1008 | |
| 1009 | // Get XML Schema Information for the Document |
| 1010 | XSModel schema = getGrammar(); |
| 1011 | |
| 1012 | DynamicContext dc = setupDynamicContext(schema); |
| 1013 | |
| 1014 | String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')"; |
| 1015 | XPath path = compileXPath(dc, xpath); |
| 1016 | |
| 1017 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1018 | ResultSequence rs = eval.evaluate(path); |
| 1019 | |
| 1020 | XSBoolean result = (XSBoolean) rs.first(); |
| 1021 | |
| 1022 | String actual = result.string_value(); |
| 1023 | |
| 1024 | assertEquals("true", actual); |
| 1025 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1026 | |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 1027 | public void testXSHexBinary() throws Exception { |
| 1028 | // Bug 281054 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1029 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 1030 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1031 | loadDOMDocument(fileURL); |
| 1032 | |
| 1033 | // Get XML Schema Information for the Document |
| 1034 | XSModel schema = getGrammar(); |
| 1035 | |
| 1036 | DynamicContext dc = setupDynamicContext(schema); |
| 1037 | |
| 1038 | String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')"; |
| 1039 | XPath path = compileXPath(dc, xpath); |
| 1040 | |
| 1041 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1042 | ResultSequence rs = eval.evaluate(path); |
| 1043 | |
| 1044 | XSBoolean result = (XSBoolean) rs.first(); |
| 1045 | |
| 1046 | String actual = result.string_value(); |
| 1047 | |
| 1048 | assertEquals("true", actual); |
| 1049 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1050 | |
mgandhi | efe9574 | 2009-08-18 04:12:11 +0000 | [diff] [blame] | 1051 | public void testElementTypedValue() throws Exception { |
| 1052 | // test for fix in ElementType.java, involving incorrectly computing |
| 1053 | // typed value of element node, in case of validating element node, |
| 1054 | // with a user defined simple XSD type. |
| 1055 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1056 | URL schemaURL = bundle |
| 1057 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
mgandhi | efe9574 | 2009-08-18 04:12:11 +0000 | [diff] [blame] | 1058 | |
| 1059 | loadDOMDocument(fileURL, schemaURL); |
| 1060 | |
| 1061 | // Get XSModel object for the Schema |
| 1062 | XSModel schema = getGrammar(schemaURL); |
| 1063 | |
| 1064 | DynamicContext dc = setupDynamicContext(schema); |
| 1065 | |
| 1066 | String xpath = "Example/Transportation/mode eq 'air'"; |
| 1067 | XPath path = compileXPath(dc, xpath); |
| 1068 | |
| 1069 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1070 | ResultSequence rs = eval.evaluate(path); |
| 1071 | |
| 1072 | XSBoolean result = (XSBoolean) rs.first(); |
| 1073 | |
| 1074 | String actual = result.string_value(); |
| 1075 | |
| 1076 | assertEquals("true", actual); |
| 1077 | |
| 1078 | } |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1079 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1080 | public void testBug286061_quoted_string_literals_no_normalize() |
| 1081 | throws Exception { |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1082 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1083 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1084 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1085 | loadDOMDocument(fileURL); |
| 1086 | |
| 1087 | // Get XML Schema Information for the Document |
| 1088 | XSModel schema = getGrammar(); |
| 1089 | |
| 1090 | DynamicContext dc = setupDynamicContext(schema); |
| 1091 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1092 | String xpath = "'\"\"'"; // the expression '""' contains no escapes |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1093 | |
| 1094 | XPath path = compileXPath(dc, xpath); |
| 1095 | |
| 1096 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1097 | ResultSequence rs = eval.evaluate(path); |
| 1098 | |
| 1099 | String resultValue = rs.first().string_value(); |
| 1100 | |
| 1101 | assertEquals("\"\"", resultValue); |
| 1102 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1103 | |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1104 | public void testBug286061_quoted_string_literals() throws Exception { |
| 1105 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1106 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1107 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1108 | loadDOMDocument(fileURL); |
| 1109 | |
| 1110 | // Get XML Schema Information for the Document |
| 1111 | XSModel schema = getGrammar(); |
| 1112 | |
| 1113 | DynamicContext dc = setupDynamicContext(schema); |
| 1114 | |
| 1115 | String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )"; |
| 1116 | |
| 1117 | XPath path = compileXPath(dc, xpath); |
| 1118 | |
| 1119 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1120 | ResultSequence rs = eval.evaluate(path); |
| 1121 | |
| 1122 | String resultValue = rs.first().string_value(); |
| 1123 | |
| 1124 | assertEquals("Don't try this at \"home\", she said", resultValue); |
| 1125 | } |
| 1126 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 1127 | public void testBug280555_collations() throws Exception { |
| 1128 | // Setup context |
| 1129 | DefaultDynamicContext dc = setupDynamicContext(null); |
| 1130 | dc.set_collation_provider(createLengthCollatorProvider()); |
| 1131 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1132 | |
| 1133 | // Parse expression |
| 1134 | XPath path = compileXPath(dc, " 'abc' < 'de' "); |
| 1135 | |
| 1136 | // Evaluate once |
| 1137 | XSBoolean bval = (XSBoolean) eval.evaluate(path).first(); |
| 1138 | assertTrue("'abc' < 'def' for normal collations", bval.value()); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1139 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 1140 | // Evaluate again with the funny collator |
| 1141 | dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR); |
| 1142 | XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first(); |
| 1143 | assertFalse("'abc' < 'def' for normal collations", bval2.value()); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1146 | public void testXPathDefaultNamespace() throws Exception { |
| 1147 | // Test for the fix, for xpathDefaultNamespace |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1148 | URL fileURL = bundle |
| 1149 | .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml"); |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1150 | loadDOMDocument(fileURL); |
| 1151 | |
| 1152 | // Get XML Schema Information for the Document |
| 1153 | XSModel schema = getGrammar(); |
| 1154 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1155 | // set up XPath default namespace in Dynamic Context |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1156 | DynamicContext dc = setupDynamicContext(schema); |
| 1157 | addXPathDefaultNamespace("http://xyz"); |
| 1158 | |
| 1159 | String xpath = "X/message = 'hello'"; |
| 1160 | XPath path = compileXPath(dc, xpath); |
| 1161 | |
| 1162 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1163 | ResultSequence rs = eval.evaluate(path); |
| 1164 | |
| 1165 | XSBoolean result = (XSBoolean) rs.first(); |
| 1166 | |
| 1167 | String actual = result.string_value(); |
| 1168 | |
| 1169 | assertEquals("true", actual); |
| 1170 | } |
dacarver | 0784965 | 2009-11-28 00:09:27 +0000 | [diff] [blame] | 1171 | |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1172 | public void testXPathInstanceOf1() throws Exception { |
| 1173 | // Bug 298267 |
| 1174 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1175 | URL schemaURL = bundle |
| 1176 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1177 | |
| 1178 | loadDOMDocument(fileURL, schemaURL); |
| 1179 | |
| 1180 | // Get XSModel object for the Schema |
| 1181 | XSModel schema = getGrammar(schemaURL); |
| 1182 | |
| 1183 | DynamicContext dc = setupDynamicContext(schema); |
| 1184 | |
| 1185 | String xpath = "Example/Transportation/mode instance of element()"; |
| 1186 | XPath path = compileXPath(dc, xpath); |
| 1187 | |
| 1188 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1189 | ResultSequence rs = eval.evaluate(path); |
| 1190 | |
| 1191 | XSBoolean result = (XSBoolean) rs.first(); |
| 1192 | |
| 1193 | String actual = result.string_value(); |
| 1194 | |
| 1195 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | public void testXPathInstanceOf2() throws Exception { |
| 1199 | // Bug 298267 |
| 1200 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1201 | URL schemaURL = bundle |
| 1202 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1203 | |
| 1204 | loadDOMDocument(fileURL, schemaURL); |
| 1205 | |
| 1206 | // Get XSModel object for the Schema |
| 1207 | XSModel schema = getGrammar(schemaURL); |
| 1208 | |
| 1209 | DynamicContext dc = setupDynamicContext(schema); |
| 1210 | |
| 1211 | String xpath = "Example/Transportation/mode instance of element(mode)"; |
| 1212 | XPath path = compileXPath(dc, xpath); |
| 1213 | |
| 1214 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1215 | ResultSequence rs = eval.evaluate(path); |
| 1216 | |
| 1217 | XSBoolean result = (XSBoolean) rs.first(); |
| 1218 | |
| 1219 | String actual = result.string_value(); |
| 1220 | |
| 1221 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1224 | public void testXPathInstanceOf3() throws Exception { |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1225 | // Bug 298267 |
| 1226 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1227 | URL schemaURL = bundle |
| 1228 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1229 | |
| 1230 | loadDOMDocument(fileURL, schemaURL); |
| 1231 | |
| 1232 | // Get XSModel object for the Schema |
| 1233 | XSModel schema = getGrammar(schemaURL); |
| 1234 | |
| 1235 | DynamicContext dc = setupDynamicContext(schema); |
| 1236 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1237 | String xpath = "Example/Transportation/mode instance of element(mode, modeType)"; |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1238 | XPath path = compileXPath(dc, xpath); |
| 1239 | |
| 1240 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1241 | ResultSequence rs = eval.evaluate(path); |
| 1242 | |
| 1243 | XSBoolean result = (XSBoolean) rs.first(); |
| 1244 | |
| 1245 | String actual = result.string_value(); |
| 1246 | |
dacarver | 5a6bbea | 2009-12-27 17:14:05 +0000 | [diff] [blame] | 1247 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | public void testXPathInstanceOf4() throws Exception { |
| 1251 | // Bug 298267 |
| 1252 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1253 | URL schemaURL = bundle |
| 1254 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1255 | |
| 1256 | loadDOMDocument(fileURL, schemaURL); |
| 1257 | |
| 1258 | // Get XSModel object for the Schema |
| 1259 | XSModel schema = getGrammar(schemaURL); |
| 1260 | |
| 1261 | DynamicContext dc = setupDynamicContext(schema); |
| 1262 | |
| 1263 | String xpath = "Example/Transportation/mode instance of element(mode, abc)"; |
| 1264 | XPath path = compileXPath(dc, xpath); |
| 1265 | |
| 1266 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1267 | ResultSequence rs = eval.evaluate(path); |
| 1268 | |
| 1269 | XSBoolean result = (XSBoolean) rs.first(); |
| 1270 | |
| 1271 | String actual = result.string_value(); |
| 1272 | |
| 1273 | assertEquals("false", actual); |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1276 | public void testXPathInstanceOf5() throws Exception { |
| 1277 | // Bug 298267 |
| 1278 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1279 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1280 | |
| 1281 | loadDOMDocument(fileURL, schemaURL); |
| 1282 | |
| 1283 | // Get XSModel object for the Schema |
| 1284 | XSModel schema = getGrammar(schemaURL); |
| 1285 | |
| 1286 | DynamicContext dc = setupDynamicContext(schema); |
| 1287 | |
| 1288 | String xpath = "Example/x instance of element(x, x_Type)*"; |
| 1289 | XPath path = compileXPath(dc, xpath); |
| 1290 | |
| 1291 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1292 | ResultSequence rs = eval.evaluate(path); |
| 1293 | |
| 1294 | XSBoolean result = (XSBoolean) rs.first(); |
| 1295 | |
| 1296 | String actual = result.string_value(); |
| 1297 | |
| 1298 | assertEquals("true", actual); |
| 1299 | } |
jmoller | 2c384ed | 2010-06-24 23:48:34 +0000 | [diff] [blame] | 1300 | |
| 1301 | public void testXPathInstanceOf5_2() throws Exception { |
| 1302 | // Bug 298267 |
| 1303 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1304 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1305 | |
| 1306 | loadDOMDocument(fileURL, schemaURL); |
| 1307 | |
| 1308 | // Get XSModel object for the Schema |
| 1309 | XSModel schema = getGrammar(schemaURL); |
| 1310 | |
| 1311 | DynamicContext dc = setupDynamicContext(schema); |
| 1312 | |
| 1313 | String xpath = "(/Example/x, /Example) instance of element(x, x_Type)+"; |
| 1314 | XPath path = compileXPath(dc, xpath); |
| 1315 | |
| 1316 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1317 | ResultSequence rs = eval.evaluate(path); |
| 1318 | |
| 1319 | XSBoolean result = (XSBoolean) rs.first(); |
| 1320 | |
| 1321 | assertEquals(false, result.value()); |
| 1322 | } |
| 1323 | |
| 1324 | public void testXPathInstanceOf5_3() throws Exception { |
| 1325 | // Bug 298267 |
| 1326 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1327 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1328 | |
| 1329 | loadDOMDocument(fileURL, schemaURL); |
| 1330 | |
| 1331 | // Get XSModel object for the Schema |
| 1332 | XSModel schema = getGrammar(schemaURL); |
| 1333 | |
| 1334 | DynamicContext dc = setupDynamicContext(schema); |
| 1335 | |
| 1336 | String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)"; |
| 1337 | XPath path = compileXPath(dc, xpath); |
| 1338 | |
| 1339 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1340 | ResultSequence rs = eval.evaluate(path); |
| 1341 | |
| 1342 | XSBoolean result = (XSBoolean) rs.first(); |
| 1343 | |
| 1344 | assertFalse(result.value()); |
| 1345 | } |
| 1346 | |
| 1347 | public void testXPathInstanceOf5_4() throws Exception { |
| 1348 | // Bug 298267 |
| 1349 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1350 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1351 | |
| 1352 | loadDOMDocument(fileURL, schemaURL); |
| 1353 | |
| 1354 | // Get XSModel object for the Schema |
| 1355 | XSModel schema = getGrammar(schemaURL); |
| 1356 | |
| 1357 | DynamicContext dc = setupDynamicContext(schema); |
| 1358 | |
| 1359 | String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)+"; |
| 1360 | XPath path = compileXPath(dc, xpath); |
| 1361 | |
| 1362 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1363 | ResultSequence rs = eval.evaluate(path); |
| 1364 | |
| 1365 | XSBoolean result = (XSBoolean) rs.first(); |
| 1366 | |
| 1367 | assertTrue(result.value()); |
| 1368 | } |
| 1369 | |
| 1370 | public void testXPathInstanceOf5_5() throws Exception { |
| 1371 | // Bug 298267 |
| 1372 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1373 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1374 | |
| 1375 | loadDOMDocument(fileURL, schemaURL); |
| 1376 | |
| 1377 | // Get XSModel object for the Schema |
| 1378 | XSModel schema = getGrammar(schemaURL); |
| 1379 | |
| 1380 | DynamicContext dc = setupDynamicContext(schema); |
| 1381 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 1382 | assertXPathFalse("/Example/x instance of x_Type+", dc, domDoc); |
| 1383 | assertXPathTrue("/Example/x instance of element(*, x_Type)+", dc, domDoc); |
jmoller | ccaf191 | 2011-03-04 02:12:18 +0000 | [diff] [blame] | 1384 | assertXPathTrue("/Example/x instance of element(x, x_Type)+", dc, domDoc); |
| 1385 | assertXPathTrue("not (/Example/x instance of element(z, x_Type)+)", dc, domDoc); |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 1386 | assertXPathFalse("/Example/x[2]/@mesg instance of mesg_Type", dc, domDoc); |
jmoller | ccaf191 | 2011-03-04 02:12:18 +0000 | [diff] [blame] | 1387 | assertXPathTrue("/Example/x[2]/@mesg instance of attribute(mesg, mesg_Type)", dc, domDoc); |
| 1388 | assertXPathTrue("not (/Example/x[2]/@mesg instance of attribute(cesc, mesg_Type))", dc, domDoc); |
jmoller | 2c384ed | 2010-06-24 23:48:34 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1391 | public void testXPathInstanceOf6() throws Exception { |
| 1392 | // Bug 298267 |
| 1393 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1394 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1395 | |
| 1396 | loadDOMDocument(fileURL, schemaURL); |
| 1397 | |
| 1398 | // Get XSModel object for the Schema |
| 1399 | XSModel schema = getGrammar(schemaURL); |
| 1400 | |
| 1401 | DynamicContext dc = setupDynamicContext(schema); |
| 1402 | |
| 1403 | String xpath = "Example/x instance of element(*, x_Type)*"; |
| 1404 | XPath path = compileXPath(dc, xpath); |
| 1405 | |
| 1406 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1407 | ResultSequence rs = eval.evaluate(path); |
| 1408 | |
| 1409 | XSBoolean result = (XSBoolean) rs.first(); |
| 1410 | |
| 1411 | String actual = result.string_value(); |
| 1412 | |
| 1413 | assertEquals("true", actual); |
| 1414 | } |
| 1415 | |
| 1416 | public void testXPathInstanceOf7() throws Exception { |
| 1417 | // Bug 298267 |
| 1418 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1419 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1420 | |
| 1421 | loadDOMDocument(fileURL, schemaURL); |
| 1422 | |
| 1423 | // Get XSModel object for the Schema |
| 1424 | XSModel schema = getGrammar(schemaURL); |
| 1425 | |
| 1426 | DynamicContext dc = setupDynamicContext(schema); |
| 1427 | |
| 1428 | String xpath = "Example/x instance of element(x, x_Type)+"; |
| 1429 | XPath path = compileXPath(dc, xpath); |
| 1430 | |
| 1431 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1432 | ResultSequence rs = eval.evaluate(path); |
| 1433 | |
| 1434 | XSBoolean result = (XSBoolean) rs.first(); |
| 1435 | |
| 1436 | String actual = result.string_value(); |
| 1437 | |
dacarver | 3da20eb | 2009-12-29 14:29:45 +0000 | [diff] [blame] | 1438 | assertEquals("true", actual); |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
jmoller | ccaf191 | 2011-03-04 02:12:18 +0000 | [diff] [blame] | 1441 | public void testXPathNotInstanceOf() throws Exception { |
| 1442 | // Bug 298267 |
| 1443 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1444 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1445 | |
| 1446 | loadDOMDocument(fileURL, schemaURL); |
| 1447 | |
| 1448 | // Get XSModel object for the Schema |
| 1449 | XSModel schema = getGrammar(schemaURL); |
| 1450 | |
| 1451 | DynamicContext dc = setupDynamicContext(schema); |
| 1452 | |
| 1453 | String xpath = "/Example/x[1] instance of element(*, x_Type) and not (/Example/x[1] instance of element(*, y_Type))"; |
| 1454 | XPath path = compileXPath(dc, xpath); |
| 1455 | |
| 1456 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1457 | ResultSequence rs = eval.evaluate(path); |
| 1458 | |
| 1459 | XSBoolean result = (XSBoolean) rs.first(); |
| 1460 | |
| 1461 | String actual = result.string_value(); |
| 1462 | |
| 1463 | assertEquals("true", actual); |
| 1464 | } |
| 1465 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1466 | public void testXPathInstanceNonExistantElement() throws Exception { |
| 1467 | // Bug 298267 |
| 1468 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1469 | URL schemaURL = bundle |
| 1470 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1471 | |
| 1472 | loadDOMDocument(fileURL, schemaURL); |
| 1473 | |
| 1474 | // Get XSModel object for the Schema |
| 1475 | XSModel schema = getGrammar(schemaURL); |
| 1476 | |
| 1477 | DynamicContext dc = setupDynamicContext(schema); |
| 1478 | |
| 1479 | String xpath = "Example/Transportation/mode instance of element(x)"; |
| 1480 | XPath path = compileXPath(dc, xpath); |
| 1481 | |
| 1482 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1483 | ResultSequence rs = eval.evaluate(path); |
| 1484 | |
| 1485 | XSBoolean result = (XSBoolean) rs.first(); |
| 1486 | |
| 1487 | String actual = result.string_value(); |
| 1488 | |
| 1489 | assertEquals("false", actual); |
| 1490 | } |
| 1491 | |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1492 | public void testFnNumber_Evaluation1() throws Exception { |
| 1493 | // Bug 298519 |
| 1494 | URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml"); |
| 1495 | URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd"); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1496 | |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1497 | loadDOMDocument(fileURL, schemaURL); |
| 1498 | |
| 1499 | // Get XSModel object for the Schema |
| 1500 | XSModel schema = getGrammar(schemaURL); |
| 1501 | |
| 1502 | DynamicContext dc = setupDynamicContext(schema); |
| 1503 | |
| 1504 | String xpath = "number(Example/x) ge 18"; |
| 1505 | XPath path = compileXPath(dc, xpath); |
| 1506 | |
| 1507 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1508 | ResultSequence rs = eval.evaluate(path); |
| 1509 | |
| 1510 | XSBoolean result = (XSBoolean) rs.first(); |
| 1511 | |
| 1512 | String actual = result.string_value(); |
| 1513 | |
| 1514 | assertEquals("true", actual); |
| 1515 | } |
| 1516 | |
| 1517 | public void testFnNumber_Evaluation2() throws Exception { |
| 1518 | // Bug 298519 |
| 1519 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1520 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1521 | loadDOMDocument(fileURL); |
| 1522 | |
| 1523 | // Get XML Schema Information for the Document |
| 1524 | XSModel schema = getGrammar(); |
| 1525 | |
| 1526 | DynamicContext dc = setupDynamicContext(schema); |
| 1527 | |
| 1528 | String xpath = "number(xs:unsignedByte('20')) ge 18"; |
| 1529 | XPath path = compileXPath(dc, xpath); |
| 1530 | |
| 1531 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1532 | ResultSequence rs = eval.evaluate(path); |
| 1533 | |
| 1534 | XSBoolean result = (XSBoolean) rs.first(); |
| 1535 | |
| 1536 | String actual = result.string_value(); |
| 1537 | |
| 1538 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1539 | } |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1540 | |
| 1541 | public void testAttrNode_Test1() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1542 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1543 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1544 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1545 | |
| 1546 | loadDOMDocument(fileURL, schemaURL); |
| 1547 | |
| 1548 | // Get XSModel object for the Schema |
| 1549 | XSModel schema = getGrammar(schemaURL); |
| 1550 | |
| 1551 | DynamicContext dc = setupDynamicContext(schema); |
| 1552 | |
| 1553 | String xpath = "Example/x[1]/@mesg instance of attribute()"; |
| 1554 | XPath path = compileXPath(dc, xpath); |
| 1555 | |
| 1556 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1557 | ResultSequence rs = eval.evaluate(path); |
| 1558 | |
| 1559 | XSBoolean result = (XSBoolean) rs.first(); |
| 1560 | |
| 1561 | String actual = result.string_value(); |
| 1562 | |
| 1563 | assertEquals("true", actual); |
| 1564 | } |
| 1565 | |
| 1566 | public void testAttrNode_Test2() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1567 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1568 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1569 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1570 | |
| 1571 | loadDOMDocument(fileURL, schemaURL); |
| 1572 | |
| 1573 | // Get XSModel object for the Schema |
| 1574 | XSModel schema = getGrammar(schemaURL); |
| 1575 | |
| 1576 | DynamicContext dc = setupDynamicContext(schema); |
| 1577 | |
| 1578 | String xpath = "Example/x[1]/@mesg instance of attribute(xx)"; |
| 1579 | XPath path = compileXPath(dc, xpath); |
| 1580 | |
| 1581 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1582 | ResultSequence rs = eval.evaluate(path); |
| 1583 | |
| 1584 | XSBoolean result = (XSBoolean) rs.first(); |
| 1585 | |
| 1586 | String actual = result.string_value(); |
| 1587 | |
| 1588 | assertEquals("false", actual); |
| 1589 | } |
| 1590 | |
| 1591 | public void testAttrNode_Test3() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1592 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1593 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1594 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1595 | |
| 1596 | loadDOMDocument(fileURL, schemaURL); |
| 1597 | |
| 1598 | // Get XSModel object for the Schema |
| 1599 | XSModel schema = getGrammar(schemaURL); |
| 1600 | |
| 1601 | DynamicContext dc = setupDynamicContext(schema); |
| 1602 | |
| 1603 | String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)"; |
| 1604 | XPath path = compileXPath(dc, xpath); |
| 1605 | |
| 1606 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1607 | ResultSequence rs = eval.evaluate(path); |
| 1608 | |
| 1609 | XSBoolean result = (XSBoolean) rs.first(); |
| 1610 | |
| 1611 | String actual = result.string_value(); |
| 1612 | |
| 1613 | assertEquals("true", actual); |
| 1614 | } |
| 1615 | |
| 1616 | public void testAttrNode_Test4() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1617 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1618 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1619 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1620 | |
| 1621 | loadDOMDocument(fileURL, schemaURL); |
| 1622 | |
| 1623 | // Get XSModel object for the Schema |
| 1624 | XSModel schema = getGrammar(schemaURL); |
| 1625 | |
| 1626 | DynamicContext dc = setupDynamicContext(schema); |
| 1627 | |
| 1628 | String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)"; |
| 1629 | XPath path = compileXPath(dc, xpath); |
| 1630 | |
| 1631 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1632 | ResultSequence rs = eval.evaluate(path); |
| 1633 | |
| 1634 | XSBoolean result = (XSBoolean) rs.first(); |
| 1635 | |
| 1636 | String actual = result.string_value(); |
| 1637 | |
| 1638 | assertEquals("false", actual); |
| 1639 | } |
| 1640 | |
| 1641 | public void testAttrNode_Test5() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1642 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1643 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1644 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1645 | |
| 1646 | loadDOMDocument(fileURL, schemaURL); |
| 1647 | |
| 1648 | // Get XSModel object for the Schema |
| 1649 | XSModel schema = getGrammar(schemaURL); |
| 1650 | |
| 1651 | DynamicContext dc = setupDynamicContext(schema); |
| 1652 | |
| 1653 | String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)"; |
| 1654 | XPath path = compileXPath(dc, xpath); |
| 1655 | |
| 1656 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1657 | ResultSequence rs = eval.evaluate(path); |
| 1658 | |
| 1659 | XSBoolean result = (XSBoolean) rs.first(); |
| 1660 | |
| 1661 | String actual = result.string_value(); |
| 1662 | |
| 1663 | assertEquals("true", actual); |
| 1664 | } |
| 1665 | |
| 1666 | public void testAttrNode_Test6() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1667 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1668 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1669 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1670 | |
| 1671 | loadDOMDocument(fileURL, schemaURL); |
| 1672 | |
| 1673 | // Get XSModel object for the Schema |
| 1674 | XSModel schema = getGrammar(schemaURL); |
| 1675 | |
| 1676 | DynamicContext dc = setupDynamicContext(schema); |
| 1677 | |
| 1678 | String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)"; |
| 1679 | XPath path = compileXPath(dc, xpath); |
| 1680 | |
| 1681 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1682 | ResultSequence rs = eval.evaluate(path); |
| 1683 | |
| 1684 | XSBoolean result = (XSBoolean) rs.first(); |
| 1685 | |
| 1686 | String actual = result.string_value(); |
| 1687 | |
| 1688 | assertEquals("false", actual); |
| 1689 | } |
| 1690 | |
| 1691 | public void testAttrNode_Test7() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1692 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1693 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1694 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1695 | |
| 1696 | loadDOMDocument(fileURL, schemaURL); |
| 1697 | |
| 1698 | // Get XSModel object for the Schema |
| 1699 | XSModel schema = getGrammar(schemaURL); |
| 1700 | |
| 1701 | DynamicContext dc = setupDynamicContext(schema); |
| 1702 | |
| 1703 | String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*"; |
| 1704 | XPath path = compileXPath(dc, xpath); |
| 1705 | |
| 1706 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1707 | ResultSequence rs = eval.evaluate(path); |
| 1708 | |
| 1709 | XSBoolean result = (XSBoolean) rs.first(); |
| 1710 | |
| 1711 | String actual = result.string_value(); |
| 1712 | |
| 1713 | assertEquals("true", actual); |
| 1714 | } |
mgandhi | 1fc7741 | 2010-02-02 15:07:05 +0000 | [diff] [blame] | 1715 | |
| 1716 | public void testFnNameContextUndefined() throws Exception { |
| 1717 | // Bug 301539 |
| 1718 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1719 | loadDOMDocument(fileURL); |
| 1720 | |
| 1721 | // Get XML Schema Information for the Document |
| 1722 | XSModel schema = getGrammar(); |
| 1723 | |
| 1724 | DynamicContext dc = setupDynamicContext(schema); |
| 1725 | |
| 1726 | String xpath = "Example/*[1]/name() eq 'x'"; |
| 1727 | XPath path = compileXPath(dc, xpath); |
| 1728 | |
| 1729 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1730 | ResultSequence rs = eval.evaluate(path); |
| 1731 | |
| 1732 | XSBoolean result = (XSBoolean) rs.first(); |
| 1733 | |
| 1734 | String actual = result.string_value(); |
| 1735 | |
| 1736 | assertEquals("true", actual); |
| 1737 | } |
mgandhi | 13d897f | 2010-04-18 09:46:00 +0000 | [diff] [blame] | 1738 | |
| 1739 | public void testXSNormalizedString() throws Exception { |
| 1740 | // Bug 309585 |
| 1741 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1742 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1743 | loadDOMDocument(fileURL); |
| 1744 | |
| 1745 | // Get XML Schema Information for the Document |
| 1746 | XSModel schema = getGrammar(); |
| 1747 | |
| 1748 | DynamicContext dc = setupDynamicContext(schema); |
| 1749 | |
| 1750 | String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')"; |
| 1751 | XPath path = compileXPath(dc, xpath); |
| 1752 | |
| 1753 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1754 | |
| 1755 | boolean testSuccess = false; |
| 1756 | try { |
| 1757 | ResultSequence rs = eval.evaluate(path); |
| 1758 | } |
| 1759 | catch(DynamicError ex) { |
| 1760 | // a 'DynamicError' exception indicates, that this test is a success |
| 1761 | testSuccess = true; |
| 1762 | } |
| 1763 | |
| 1764 | assertTrue(testSuccess); |
| 1765 | } |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 1766 | |
| 1767 | public void testParseElementKeywordsAsNodes() throws Exception { |
| 1768 | // Bug 311480 |
| 1769 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1770 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1771 | loadDOMDocument(fileURL); |
| 1772 | |
| 1773 | // Get XML Schema Information for the Document |
| 1774 | XSModel schema = getGrammar(); |
| 1775 | |
| 1776 | DynamicContext dc = setupDynamicContext(schema); |
| 1777 | |
| 1778 | String xpath = "/element/attribute"; |
| 1779 | XPath path = compileXPath(dc, xpath); |
| 1780 | } |
| 1781 | |
mgandhi | 247b6e7 | 2010-07-07 11:50:37 +0000 | [diff] [blame] | 1782 | public void testTypedValueEnhancement_primitiveTypes() throws Exception { |
| 1783 | // Bug 318313 |
| 1784 | URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml"); |
| 1785 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd"); |
| 1786 | |
| 1787 | loadDOMDocument(fileURL, schemaURL); |
| 1788 | |
| 1789 | // Get XSModel object for the Schema |
| 1790 | XSModel schema = getGrammar(schemaURL); |
| 1791 | |
| 1792 | DynamicContext dc = setupDynamicContext(schema); |
| 1793 | |
| 1794 | String xpath = "X gt 99"; |
| 1795 | XPath path = compileXPath(dc, xpath); |
| 1796 | |
| 1797 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1798 | ResultSequence rs = eval.evaluate(path); |
| 1799 | |
| 1800 | XSBoolean result = (XSBoolean) rs.first(); |
| 1801 | |
| 1802 | String actual = result.string_value(); |
| 1803 | |
| 1804 | assertEquals("true", actual); |
| 1805 | } |
| 1806 | |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 1807 | public void testTypedValueEnhancement_Bug323900_1() throws Exception { |
| 1808 | // Bug 323900 |
| 1809 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_1.xml"); |
| 1810 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_1.xsd"); |
| 1811 | |
| 1812 | loadDOMDocument(fileURL, schemaURL); |
| 1813 | |
| 1814 | // Get XSModel object for the Schema |
| 1815 | XSModel schema = getGrammar(schemaURL); |
| 1816 | |
| 1817 | DynamicContext dc = setupDynamicContext(schema); |
| 1818 | |
| 1819 | String xpath = "data(X) instance of xs:integer+"; |
| 1820 | XPath path = compileXPath(dc, xpath); |
| 1821 | |
| 1822 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1823 | ResultSequence rs = eval.evaluate(path); |
| 1824 | |
| 1825 | XSBoolean result = (XSBoolean) rs.first(); |
| 1826 | |
| 1827 | String actual = result.string_value(); |
| 1828 | |
| 1829 | assertEquals("true", actual); |
| 1830 | } |
| 1831 | |
| 1832 | public void testTypedValueEnhancement_Bug323900_2() throws Exception { |
| 1833 | // Bug 323900 |
| 1834 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml"); |
| 1835 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd"); |
| 1836 | |
| 1837 | loadDOMDocument(fileURL, schemaURL); |
| 1838 | |
| 1839 | // Get XSModel object for the Schema |
| 1840 | XSModel schema = getGrammar(schemaURL); |
| 1841 | |
| 1842 | DynamicContext dc = setupDynamicContext(schema); |
| 1843 | |
| 1844 | // 1st test |
| 1845 | String xpath = "data(X) instance of xs:integer+"; |
| 1846 | XPath path = compileXPath(dc, xpath); |
| 1847 | |
| 1848 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1849 | ResultSequence rs = eval.evaluate(path); |
| 1850 | |
| 1851 | XSBoolean result = (XSBoolean) rs.first(); |
| 1852 | |
| 1853 | String actual = result.string_value(); |
| 1854 | |
| 1855 | assertEquals("false", actual); |
| 1856 | } |
| 1857 | |
| 1858 | public void testTypedValueEnhancement_Bug323900_3() throws Exception { |
| 1859 | // Bug 323900 |
| 1860 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml"); |
| 1861 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd"); |
| 1862 | |
| 1863 | loadDOMDocument(fileURL, schemaURL); |
| 1864 | |
| 1865 | // Get XSModel object for the Schema |
| 1866 | XSModel schema = getGrammar(schemaURL); |
| 1867 | |
| 1868 | DynamicContext dc = setupDynamicContext(schema); |
| 1869 | String xpath = "data(X)"; |
| 1870 | XPath path = compileXPath(dc, xpath); |
| 1871 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1872 | ResultSequence rs = eval.evaluate(path); |
| 1873 | |
| 1874 | boolean result1 = ((XSInteger) rs.get(0)).eq(new XSInteger(BigInteger. |
| 1875 | valueOf(1)), dc); |
| 1876 | boolean result2 = ((XSInteger) rs.get(1)).eq(new XSInteger(BigInteger. |
| 1877 | valueOf(2)), dc); |
| 1878 | boolean result3 = ((XSString) rs.get(2)).eq(new XSString("3.3"), dc); |
| 1879 | |
| 1880 | assertEquals(true, result1 && result2 && result3); |
| 1881 | } |
| 1882 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 1883 | public void testTypedValueEnhancement_Bug323900_4() throws Exception { |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 1884 | // Bug 323900 |
| 1885 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_3.xml"); |
| 1886 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd"); |
| 1887 | |
| 1888 | loadDOMDocument(fileURL, schemaURL); |
| 1889 | |
| 1890 | // Get XSModel object for the Schema |
| 1891 | XSModel schema = getGrammar(schemaURL); |
| 1892 | |
| 1893 | DynamicContext dc = setupDynamicContext(schema); |
| 1894 | String xpath = "data(X)"; |
| 1895 | XPath path = compileXPath(dc, xpath); |
| 1896 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1897 | ResultSequence rs = eval.evaluate(path); |
| 1898 | |
| 1899 | XSString result = (XSString) rs.get(0); |
| 1900 | assertEquals("3.3", result.string_value()); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 1901 | } |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 1902 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 1903 | public void testTypedValueEnhancement_Bug323900_5() throws Exception { |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 1904 | // Bug 323900 |
| 1905 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_4.xml"); |
| 1906 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd"); |
| 1907 | |
| 1908 | loadDOMDocument(fileURL, schemaURL); |
| 1909 | |
| 1910 | // Get XSModel object for the Schema |
| 1911 | XSModel schema = getGrammar(schemaURL); |
| 1912 | |
| 1913 | DynamicContext dc = setupDynamicContext(schema); |
| 1914 | String xpath = "data(X)"; |
| 1915 | XPath path = compileXPath(dc, xpath); |
| 1916 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1917 | ResultSequence rs = eval.evaluate(path); |
| 1918 | |
| 1919 | XSInteger result = (XSInteger) rs.get(0); |
| 1920 | assertEquals("10", result.string_value()); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 1921 | } |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame] | 1922 | |
| 1923 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_1() |
| 1924 | throws Exception { |
| 1925 | // Bug 325262 |
| 1926 | DynamicContext dc = setupDynamicContext(null); |
| 1927 | |
| 1928 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1929 | dc.set_variable(new QName("value"), rs); |
| 1930 | |
| 1931 | String xpath = "deep-equal($value,())"; |
| 1932 | XPath path = compileXPath(dc, xpath); |
| 1933 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1934 | ResultSequence rsRes = eval.evaluate(path); |
| 1935 | |
| 1936 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1937 | assertEquals("true", result.string_value()); |
| 1938 | } |
| 1939 | |
| 1940 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_2() |
| 1941 | throws Exception { |
| 1942 | // Bug 325262 |
| 1943 | DynamicContext dc = setupDynamicContext(null); |
| 1944 | |
| 1945 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1946 | rs.add(new XSInteger(BigInteger.valueOf(2))); |
| 1947 | rs.add(new XSInteger(BigInteger.valueOf(4))); |
| 1948 | rs.add(new XSInteger(BigInteger.valueOf(6))); |
| 1949 | dc.set_variable(new QName("value"), rs); |
| 1950 | |
| 1951 | // test a |
| 1952 | String xpath = "$value instance of xs:integer+"; |
| 1953 | XPath path = compileXPath(dc, xpath); |
| 1954 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1955 | ResultSequence rsRes = eval.evaluate(path); |
| 1956 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1957 | assertEquals("true", result.string_value()); |
| 1958 | |
| 1959 | // test b |
| 1960 | xpath = "deep-equal($value, (2, 4, 6))"; |
| 1961 | path = compileXPath(dc, xpath); |
| 1962 | eval = new DefaultEvaluator(dc, domDoc); |
| 1963 | rsRes = eval.evaluate(path); |
| 1964 | result = (XSBoolean) rsRes.get(0); |
| 1965 | assertEquals("true", result.string_value()); |
| 1966 | } |
| 1967 | |
| 1968 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_3() |
| 1969 | throws Exception { |
| 1970 | // Bug 325262 |
| 1971 | DynamicContext dc = setupDynamicContext(null); |
| 1972 | |
| 1973 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1974 | rs.add(new XSInteger(BigInteger.valueOf(2))); |
| 1975 | rs.add(new XSInteger(BigInteger.valueOf(4))); |
| 1976 | rs.add(new XSInteger(BigInteger.valueOf(6))); |
| 1977 | dc.set_variable(new QName("value"), rs); |
| 1978 | |
| 1979 | String xpath = "count(data($value)) = 3"; |
| 1980 | XPath path = compileXPath(dc, xpath); |
| 1981 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1982 | ResultSequence rsRes = eval.evaluate(path); |
| 1983 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1984 | assertEquals("true", result.string_value()); |
| 1985 | } |
| 1986 | |
mgandhi | d2cb89c | 2011-01-16 11:59:19 +0000 | [diff] [blame] | 1987 | public void testXSToken() throws Exception { |
| 1988 | // Bug 334478 |
| 1989 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1990 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1991 | loadDOMDocument(fileURL); |
| 1992 | |
| 1993 | // Get XML Schema Information for the Document |
| 1994 | XSModel schema = getGrammar(); |
| 1995 | |
| 1996 | DynamicContext dc = setupDynamicContext(schema); |
| 1997 | |
| 1998 | // the strings in below are not valid tokens (they contain 2 consecutive spaces) |
| 1999 | String xpath = "xs:token('abcs abcde') eq xs:token('abcs abcde')"; |
| 2000 | XPath path = compileXPath(dc, xpath); |
| 2001 | |
| 2002 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2003 | |
| 2004 | boolean testSuccess = false; |
| 2005 | try { |
| 2006 | ResultSequence rs = eval.evaluate(path); |
| 2007 | } |
| 2008 | catch(DynamicError ex) { |
| 2009 | // a 'DynamicError' exception indicates, that this test is a success |
| 2010 | testSuccess = true; |
| 2011 | } |
| 2012 | |
| 2013 | assertTrue(testSuccess); |
| 2014 | } |
| 2015 | |
mgandhi | 8ac9e1c | 2011-01-20 04:15:58 +0000 | [diff] [blame] | 2016 | public void testBug334842() throws Exception { |
| 2017 | // Bug 334842 |
| 2018 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2019 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2020 | loadDOMDocument(fileURL); |
| 2021 | |
| 2022 | // Get XML Schema Information for the Document |
| 2023 | XSModel schema = getGrammar(); |
| 2024 | |
| 2025 | DynamicContext dc = setupDynamicContext(schema); |
| 2026 | |
| 2027 | // test a) |
| 2028 | String xpath = "xs:Name('x:abc') eq xs:Name('x:abc')"; |
| 2029 | XPath path = compileXPath(dc, xpath); |
| 2030 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2031 | ResultSequence rsRes = eval.evaluate(path); |
| 2032 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 2033 | assertEquals("true", result.string_value()); |
| 2034 | |
| 2035 | // test b) |
| 2036 | xpath = "xs:NCName('x:abc') eq xs:NCName('x:abc')"; |
| 2037 | path = compileXPath(dc, xpath); |
| 2038 | try { |
| 2039 | rsRes = eval.evaluate(path); |
| 2040 | assertTrue(false); |
| 2041 | } |
| 2042 | catch(DynamicError ex) { |
| 2043 | // a 'DynamicError' exception indicates, that this test is a success |
| 2044 | assertTrue(true); |
| 2045 | } |
| 2046 | |
| 2047 | // test c) |
| 2048 | xpath = "xs:NCName('abc') eq xs:NCName('abc')"; |
| 2049 | path = compileXPath(dc, xpath); |
| 2050 | rsRes = eval.evaluate(path); |
| 2051 | result = (XSBoolean) rsRes.get(0); |
| 2052 | assertEquals("true", result.string_value()); |
| 2053 | |
| 2054 | // test d) |
| 2055 | xpath = "xs:ID('x:abc') eq xs:ID('x:abc')"; |
| 2056 | path = compileXPath(dc, xpath); |
| 2057 | try { |
| 2058 | rsRes = eval.evaluate(path); |
| 2059 | assertTrue(false); |
| 2060 | } |
| 2061 | catch(DynamicError ex) { |
| 2062 | // a 'DynamicError' exception indicates, that this test is a success |
| 2063 | assertTrue(true); |
| 2064 | } |
| 2065 | |
| 2066 | // test e) |
| 2067 | xpath = "xs:ID('abc') eq xs:ID('abc')"; |
| 2068 | path = compileXPath(dc, xpath); |
| 2069 | rsRes = eval.evaluate(path); |
| 2070 | result = (XSBoolean) rsRes.get(0); |
| 2071 | assertEquals("true", result.string_value()); |
| 2072 | } |
| 2073 | |
mgandhi | b3af5cf | 2011-03-05 08:58:57 +0000 | [diff] [blame] | 2074 | public void testDefNamespaceOnbuiltInTypes() throws Exception { |
mgandhi | 3727fd6 | 2011-03-01 00:59:09 +0000 | [diff] [blame] | 2075 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2076 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2077 | loadDOMDocument(fileURL); |
| 2078 | |
| 2079 | // Get XML Schema Information for the Document |
| 2080 | XSModel schema = getGrammar(); |
| 2081 | |
| 2082 | // set up XPath default namespace in Dynamic Context |
| 2083 | DynamicContext dc = setupDynamicContext(schema); |
| 2084 | dc.set_variable(new QName("value"), new XSString("2.5")); |
| 2085 | addXPathDefaultNamespace("http://www.w3.org/2001/XMLSchema"); |
| 2086 | |
| 2087 | String xpath = "$value castable as double"; |
| 2088 | XPath path = compileXPath(dc, xpath); |
| 2089 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2090 | Evaluator eval = new DefaultEvaluator(dc, (Document)null); |
mgandhi | 3727fd6 | 2011-03-01 00:59:09 +0000 | [diff] [blame] | 2091 | ResultSequence rs = eval.evaluate(path); |
| 2092 | |
| 2093 | XSBoolean result = (XSBoolean) rs.first(); |
| 2094 | |
| 2095 | String actual = result.string_value(); |
| 2096 | |
| 2097 | assertEquals("true", actual); |
| 2098 | } |
| 2099 | |
mgandhi | b3af5cf | 2011-03-05 08:58:57 +0000 | [diff] [blame] | 2100 | public void testExprParsingBeginnigWithRootNode_bug338494() throws Exception { |
| 2101 | // Bug 338494 |
mgandhi | 3727fd6 | 2011-03-01 00:59:09 +0000 | [diff] [blame] | 2102 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2103 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2104 | loadDOMDocument(fileURL); |
| 2105 | |
| 2106 | // Get XML Schema Information for the Document |
| 2107 | XSModel schema = getGrammar(); |
| 2108 | |
| 2109 | DynamicContext dc = setupDynamicContext(schema); |
| 2110 | |
| 2111 | // test a) |
| 2112 | String xpath = "/x"; |
| 2113 | XPath path = null; |
| 2114 | try { |
| 2115 | path = compileXPath(dc, xpath, true); |
| 2116 | // test fails |
| 2117 | assertTrue(false); |
| 2118 | } |
| 2119 | catch(XPathParserException ex) { |
| 2120 | if ("Expression starts with / or //".equals(ex.getMessage())) { |
| 2121 | // test passes |
| 2122 | assertTrue(true); |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | // test b) |
| 2127 | xpath = "//x"; |
| 2128 | try { |
| 2129 | path = compileXPath(dc, xpath, true); |
| 2130 | // test fails |
| 2131 | assertTrue(false); |
| 2132 | } |
| 2133 | catch(XPathParserException ex) { |
| 2134 | if ("Expression starts with / or //".equals(ex.getMessage())) { |
| 2135 | // test passes |
| 2136 | assertTrue(true); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | // test c) |
| 2141 | xpath = "/"; |
| 2142 | try { |
| 2143 | path = compileXPath(dc, xpath, true); |
| 2144 | // test fails |
| 2145 | assertTrue(false); |
| 2146 | } |
| 2147 | catch(XPathParserException ex) { |
| 2148 | if ("Expression starts with / or //".equals(ex.getMessage())) { |
| 2149 | // test passes |
| 2150 | assertTrue(true); |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | // test d) |
| 2155 | xpath = "x/y[/a]"; |
| 2156 | try { |
| 2157 | path = compileXPath(dc, xpath, true); |
| 2158 | // test fails |
| 2159 | assertTrue(false); |
| 2160 | } |
| 2161 | catch(XPathParserException ex) { |
| 2162 | if ("Expression starts with / or //".equals(ex.getMessage())) { |
| 2163 | // test passes |
| 2164 | assertTrue(true); |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 | // test e) |
| 2169 | xpath = ".//x"; |
| 2170 | try { |
| 2171 | path = compileXPath(dc, xpath, true); |
| 2172 | // test passes |
| 2173 | assertTrue(true); |
| 2174 | } |
| 2175 | catch(XPathParserException ex) { |
| 2176 | // test fails |
| 2177 | assertTrue(false); |
| 2178 | } |
| 2179 | } |
| 2180 | |
mgandhi | b3af5cf | 2011-03-05 08:58:57 +0000 | [diff] [blame] | 2181 | public void testBug338999_Fnsubsequence() throws Exception { |
| 2182 | // bug 338999 |
| 2183 | URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml"); |
| 2184 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd"); |
| 2185 | |
| 2186 | loadDOMDocument(fileURL, schemaURL); |
| 2187 | |
| 2188 | // Get XSModel object for the Schema |
| 2189 | XSModel schema = getGrammar(schemaURL); |
| 2190 | |
| 2191 | DynamicContext dc = setupDynamicContext(schema); |
| 2192 | |
| 2193 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2194 | |
| 2195 | // test a) |
| 2196 | String xpath = "count(subsequence(X/*, 2)) eq 2"; |
| 2197 | XPath path = compileXPath(dc, xpath); |
| 2198 | ResultSequence rs = eval.evaluate(path); |
| 2199 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2200 | assertEquals("true", actual); |
| 2201 | |
| 2202 | // test b) |
| 2203 | xpath = "subsequence(X/*, 2) instance of element(*, xs:integer)+"; |
| 2204 | path = compileXPath(dc, xpath); |
| 2205 | rs = eval.evaluate(path); |
| 2206 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2207 | assertEquals("true", actual); |
| 2208 | |
| 2209 | // test c) |
| 2210 | xpath = "deep-equal(subsequence((1,2,3,4), 2), (2,3,4))"; |
| 2211 | path = compileXPath(dc, xpath); |
| 2212 | rs = eval.evaluate(path); |
| 2213 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2214 | assertEquals("true", actual); |
| 2215 | |
| 2216 | // test d) |
| 2217 | // hetrogeneous sequence as input. arity 3 mode. |
| 2218 | xpath = "deep-equal(subsequence(('a', 1, 1.5), 2, 2), (1, 1.5))"; |
| 2219 | path = compileXPath(dc, xpath); |
| 2220 | rs = eval.evaluate(path); |
| 2221 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2222 | assertEquals("true", actual); |
| 2223 | |
| 2224 | // test e) |
| 2225 | // hetrogeneous sequence as input. arity 3 mode (startingLoc is < 0). |
| 2226 | xpath = "deep-equal(subsequence(('a', 1, 1.5, 'b'), -2, 3), ())"; |
| 2227 | path = compileXPath(dc, xpath); |
| 2228 | rs = eval.evaluate(path); |
| 2229 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2230 | assertEquals("true", actual); |
| 2231 | } |
| 2232 | |
mgandhi | 43d0fcf | 2011-03-06 01:46:48 +0000 | [diff] [blame] | 2233 | public void testBug339025_distinctValuesOnNodeSequence() throws Exception { |
| 2234 | // bug 339025 |
| 2235 | URL fileURL = bundle.getEntry("/bugTestFiles/bug339025.xml"); |
| 2236 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug339025.xsd"); |
| 2237 | |
| 2238 | loadDOMDocument(fileURL, schemaURL); |
| 2239 | |
| 2240 | // Get XSModel object for the Schema |
| 2241 | XSModel schema = getGrammar(schemaURL); |
| 2242 | |
| 2243 | DynamicContext dc = setupDynamicContext(schema);; |
| 2244 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2245 | |
| 2246 | // test a) |
| 2247 | String xpath = "count(//a) = count(distinct-values(//a))"; |
| 2248 | XPath path = compileXPath(dc, xpath); |
| 2249 | ResultSequence rs = eval.evaluate(path); |
| 2250 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2251 | assertEquals("true", actual); |
| 2252 | |
| 2253 | // test b) |
| 2254 | xpath = "count(X/a) = count(distinct-values(X/a))"; |
| 2255 | path = compileXPath(dc, xpath); |
| 2256 | rs = eval.evaluate(path); |
| 2257 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2258 | assertEquals("true", actual); |
| 2259 | |
| 2260 | // test c) |
| 2261 | xpath = "count(//b) = count(distinct-values(//b))"; |
| 2262 | path = compileXPath(dc, xpath); |
| 2263 | rs = eval.evaluate(path); |
| 2264 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2265 | assertEquals("false", actual); |
| 2266 | } |
| 2267 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2268 | public void testBug341862_TypedBooleanNode() throws Exception { |
| 2269 | // bug 341862 |
| 2270 | URL fileURL = bundle.getEntry("/bugTestFiles/bug341862.xml"); |
| 2271 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug341862.xsd"); |
| 2272 | |
| 2273 | loadDOMDocument(fileURL, schemaURL); |
| 2274 | |
| 2275 | // Get XSModel object for the Schema |
| 2276 | XSModel schema = getGrammar(schemaURL); |
| 2277 | |
| 2278 | DynamicContext dc = setupDynamicContext(schema);; |
| 2279 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2280 | |
| 2281 | // test a) |
| 2282 | String xpath = "/X/a[1] = true()"; |
| 2283 | XPath path = compileXPath(dc, xpath); |
| 2284 | ResultSequence rs = eval.evaluate(path); |
| 2285 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2286 | assertEquals("true", actual); |
| 2287 | |
| 2288 | // test b) |
| 2289 | xpath = "/X/a[1]/@att = true()"; |
| 2290 | path = compileXPath(dc, xpath); |
| 2291 | rs = eval.evaluate(path); |
| 2292 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2293 | assertEquals("true", actual); |
| 2294 | |
| 2295 | // test c) |
| 2296 | xpath = "/X/a[2] = true()"; |
| 2297 | path = compileXPath(dc, xpath); |
| 2298 | rs = eval.evaluate(path); |
| 2299 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2300 | assertEquals("true", actual); |
| 2301 | |
| 2302 | // test d) |
| 2303 | xpath = "/X/a[2]/@att = true()"; |
| 2304 | path = compileXPath(dc, xpath); |
| 2305 | rs = eval.evaluate(path); |
| 2306 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2307 | assertEquals("true", actual); |
| 2308 | |
| 2309 | // test e) |
| 2310 | xpath = "/X/a[3] = false()"; |
| 2311 | path = compileXPath(dc, xpath); |
| 2312 | rs = eval.evaluate(path); |
| 2313 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2314 | assertEquals("true", actual); |
| 2315 | |
| 2316 | // test f) |
| 2317 | xpath = "/X/a[3]/@att = false()"; |
| 2318 | path = compileXPath(dc, xpath); |
| 2319 | rs = eval.evaluate(path); |
| 2320 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2321 | assertEquals("true", actual); |
| 2322 | |
| 2323 | // test g) |
| 2324 | xpath = "/X/a[4] = false()"; |
| 2325 | path = compileXPath(dc, xpath); |
| 2326 | rs = eval.evaluate(path); |
| 2327 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2328 | assertEquals("true", actual); |
| 2329 | |
| 2330 | // test h) |
| 2331 | xpath = "/X/a[4]/@att = false()"; |
| 2332 | path = compileXPath(dc, xpath); |
| 2333 | rs = eval.evaluate(path); |
| 2334 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2335 | assertEquals("true", actual); |
| 2336 | } |
| 2337 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2338 | public void testBug_343224() throws Exception { |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2339 | // bug 343224 |
| 2340 | URL fileURL = bundle.getEntry("/bugTestFiles/bug343224.xml"); |
| 2341 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug343224.xsd"); |
| 2342 | |
| 2343 | loadDOMDocument(fileURL, schemaURL); |
| 2344 | |
| 2345 | // Get XSModel object for the Schema |
| 2346 | XSModel schema = getGrammar(schemaURL); |
| 2347 | |
| 2348 | DynamicContext dc = setupDynamicContext(schema); |
| 2349 | |
| 2350 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2351 | |
| 2352 | // test a) |
| 2353 | String xpath = "X/a[1] castable as STATUS"; |
| 2354 | XPath path = compileXPath(dc, xpath); |
| 2355 | ResultSequence rs = eval.evaluate(path); |
| 2356 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2357 | assertEquals("true", actual); |
| 2358 | |
| 2359 | // test b) |
| 2360 | xpath = "X/a[2] castable as STATUS"; |
| 2361 | path = compileXPath(dc, xpath); |
| 2362 | rs = eval.evaluate(path); |
| 2363 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2364 | assertEquals("true", actual); |
| 2365 | |
| 2366 | // test c) |
| 2367 | xpath = "X/a[3] castable as STATUS"; |
| 2368 | path = compileXPath(dc, xpath); |
| 2369 | rs = eval.evaluate(path); |
| 2370 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2371 | assertEquals("false", actual); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2372 | } |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2373 | |
| 2374 | public void testReverse_axes() throws Exception { |
| 2375 | // Bug 353373 |
| 2376 | URL fileURL = bundle.getEntry("/bugTestFiles/bug353373_1.xml"); |
| 2377 | loadDOMDocument(fileURL); |
| 2378 | |
| 2379 | // Get XML Schema Information for the Document |
| 2380 | XSModel schema = getGrammar(); |
| 2381 | |
| 2382 | DynamicContext dc = setupDynamicContext(schema); |
| 2383 | |
| 2384 | // test (a) |
| 2385 | String xpath = "count(x/q/preceding-sibling::*) = 2"; |
| 2386 | XPath path = compileXPath(dc, xpath); |
| 2387 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2388 | ResultSequence rs = eval.evaluate(path); |
| 2389 | XSBoolean result = (XSBoolean) rs.first(); |
| 2390 | String actual = result.string_value(); |
| 2391 | assertEquals("true", actual); |
| 2392 | |
| 2393 | // test (b) |
| 2394 | xpath = "deep-equal((x/q/preceding-sibling::*[1]/name(),x/q/preceding-sibling::*[2]/name()),('p','uu'))"; |
| 2395 | path = compileXPath(dc, xpath); |
| 2396 | eval = new DefaultEvaluator(dc, domDoc); |
| 2397 | rs = eval.evaluate(path); |
| 2398 | result = (XSBoolean) rs.first(); |
| 2399 | actual = result.string_value(); |
| 2400 | assertEquals("true", actual); |
| 2401 | |
| 2402 | // test (c) |
| 2403 | xpath = "count(//u/preceding::*) = 7"; |
| 2404 | path = compileXPath(dc, xpath); |
| 2405 | eval = new DefaultEvaluator(dc, domDoc); |
| 2406 | rs = eval.evaluate(path); |
| 2407 | result = (XSBoolean) rs.first(); |
| 2408 | actual = result.string_value(); |
| 2409 | assertEquals("true", actual); |
| 2410 | |
| 2411 | // test (d) |
| 2412 | xpath = "deep-equal((//u/preceding::*[1]/name(),//u/preceding::*[2]/name(),//u/preceding::*[3]/name(),//u/preceding::*[4]/name(),//u/preceding::*[5]/name(),//u/preceding::*[6]/name(),//u/preceding::*[7]/name()), " + |
| 2413 | "('m2','m1','z','c','q','p','uu'))"; |
| 2414 | path = compileXPath(dc, xpath); |
| 2415 | eval = new DefaultEvaluator(dc, domDoc); |
| 2416 | rs = eval.evaluate(path); |
| 2417 | result = (XSBoolean) rs.first(); |
| 2418 | actual = result.string_value(); |
| 2419 | assertEquals("true", actual); |
| 2420 | |
| 2421 | // test (e) |
| 2422 | xpath = "count(//u/ancestor::*) = 2"; |
| 2423 | path = compileXPath(dc, xpath); |
| 2424 | eval = new DefaultEvaluator(dc, domDoc); |
| 2425 | rs = eval.evaluate(path); |
| 2426 | result = (XSBoolean) rs.first(); |
| 2427 | actual = result.string_value(); |
| 2428 | assertEquals("true", actual); |
| 2429 | |
| 2430 | // test (f) |
| 2431 | xpath = "deep-equal((//u/ancestor::*[1]/name(),//u/ancestor::*[2]/name()),('y','x'))"; |
| 2432 | path = compileXPath(dc, xpath); |
| 2433 | eval = new DefaultEvaluator(dc, domDoc); |
| 2434 | rs = eval.evaluate(path); |
| 2435 | result = (XSBoolean) rs.first(); |
| 2436 | actual = result.string_value(); |
| 2437 | assertEquals("true", actual); |
| 2438 | |
| 2439 | // test (g) |
| 2440 | xpath = "count(//u/ancestor-or-self::*) = 3"; |
| 2441 | path = compileXPath(dc, xpath); |
| 2442 | eval = new DefaultEvaluator(dc, domDoc); |
| 2443 | rs = eval.evaluate(path); |
| 2444 | result = (XSBoolean) rs.first(); |
| 2445 | actual = result.string_value(); |
| 2446 | assertEquals("true", actual); |
| 2447 | |
| 2448 | // test (h) |
| 2449 | xpath = "deep-equal((//u/ancestor-or-self::*[1]/name(),//u/ancestor-or-self::*[2]/name(),//u/ancestor-or-self::*[3]/name()),('u','y','x'))"; |
| 2450 | path = compileXPath(dc, xpath); |
| 2451 | eval = new DefaultEvaluator(dc, domDoc); |
| 2452 | rs = eval.evaluate(path); |
| 2453 | result = (XSBoolean) rs.first(); |
| 2454 | actual = result.string_value(); |
| 2455 | assertEquals("true", actual); |
| 2456 | } |
| 2457 | |
| 2458 | public void testForward_axes() throws Exception { |
| 2459 | // Bug 353373 |
| 2460 | URL fileURL = bundle.getEntry("/bugTestFiles/bug353373_2.xml"); |
| 2461 | loadDOMDocument(fileURL); |
| 2462 | |
| 2463 | // Get XML Schema Information for the Document |
| 2464 | XSModel schema = getGrammar(); |
| 2465 | |
| 2466 | DynamicContext dc = setupDynamicContext(schema); |
| 2467 | |
| 2468 | // test (a) |
| 2469 | String xpath = "count(x/q/following-sibling::*) = 2"; |
| 2470 | XPath path = compileXPath(dc, xpath); |
| 2471 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2472 | ResultSequence rs = eval.evaluate(path); |
| 2473 | XSBoolean result = (XSBoolean) rs.first(); |
| 2474 | String actual = result.string_value(); |
| 2475 | assertEquals("true", actual); |
| 2476 | |
| 2477 | // test (b) |
| 2478 | xpath = "deep-equal((x/q/following-sibling::*[1]/name(),x/q/following-sibling::*[2]/name()),('c','y'))"; |
| 2479 | path = compileXPath(dc, xpath); |
| 2480 | eval = new DefaultEvaluator(dc, domDoc); |
| 2481 | rs = eval.evaluate(path); |
| 2482 | result = (XSBoolean) rs.first(); |
| 2483 | actual = result.string_value(); |
| 2484 | assertEquals("true", actual); |
| 2485 | |
| 2486 | // test (c) |
| 2487 | xpath = "count(//a5/following::*) = 8"; |
| 2488 | path = compileXPath(dc, xpath); |
| 2489 | eval = new DefaultEvaluator(dc, domDoc); |
| 2490 | rs = eval.evaluate(path); |
| 2491 | result = (XSBoolean) rs.first(); |
| 2492 | actual = result.string_value(); |
| 2493 | assertEquals("true", actual); |
| 2494 | |
| 2495 | // test (d) |
| 2496 | xpath = "deep-equal((//n1/following::*[1]/name(),//n1/following::*[2]/name(),//n1/following::*[3]/name(),//n1/following::*[4]/name(),//n1/following::*[5]/name(),//n1/following::*[6]/name(),//n1/following::*[7]/name(),//n1/following::*[8]/name())," + |
| 2497 | "('p','q','c','y','z','m1','m2','u'))"; |
| 2498 | path = compileXPath(dc, xpath); |
| 2499 | eval = new DefaultEvaluator(dc, domDoc); |
| 2500 | rs = eval.evaluate(path); |
| 2501 | result = (XSBoolean) rs.first(); |
| 2502 | actual = result.string_value(); |
| 2503 | assertEquals("true", actual); |
| 2504 | } |
| 2505 | |
| 2506 | public void testInstanceOf_1() throws Exception { |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2507 | // improvements to "instance of" checks |
| 2508 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2509 | // reusing files from another bug |
| 2510 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 2511 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 2512 | |
| 2513 | loadDOMDocument(fileURL, schemaURL); |
| 2514 | |
| 2515 | // Get XSModel object for the Schema |
| 2516 | XSModel schema = getGrammar(schemaURL); |
| 2517 | |
| 2518 | DynamicContext dc = setupDynamicContext(schema); |
| 2519 | |
| 2520 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2521 | |
| 2522 | // test a) |
| 2523 | String xpath = "/person/@id instance of attribute(*, xs:integer)"; |
| 2524 | XPath path = compileXPath(dc, xpath); |
| 2525 | ResultSequence rs = eval.evaluate(path); |
| 2526 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2527 | assertEquals("true", actual); |
| 2528 | |
| 2529 | // test b) |
| 2530 | xpath = "/person/@id instance of xs:integer"; |
| 2531 | path = compileXPath(dc, xpath); |
| 2532 | rs = eval.evaluate(path); |
| 2533 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2534 | assertEquals("false", actual); |
| 2535 | } |
| 2536 | |
| 2537 | public void testInstanceOf_2() throws Exception { |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2538 | // improvements to "instance of" checks |
| 2539 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2540 | // reusing files from another bug |
| 2541 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 2542 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 2543 | |
| 2544 | loadDOMDocument(fileURL, schemaURL); |
| 2545 | |
| 2546 | // Get XSModel object for the Schema |
| 2547 | XSModel schema = getGrammar(schemaURL); |
| 2548 | |
| 2549 | DynamicContext dc = setupDynamicContext(schema); |
| 2550 | |
| 2551 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2552 | |
| 2553 | // test a) |
| 2554 | String xpath = "/person/fname instance of element(*, xs:string)"; |
| 2555 | XPath path = compileXPath(dc, xpath); |
| 2556 | ResultSequence rs = eval.evaluate(path); |
| 2557 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2558 | assertEquals("true", actual); |
| 2559 | |
| 2560 | // test b) |
| 2561 | xpath = "/person/fname instance of xs:string"; |
| 2562 | path = compileXPath(dc, xpath); |
| 2563 | rs = eval.evaluate(path); |
| 2564 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2565 | assertEquals("false", actual); |
| 2566 | } |
| 2567 | |
| 2568 | public void testResolveQName_1() throws Exception { |
| 2569 | // Bug 360306 |
| 2570 | URL fileURL = bundle.getEntry("/bugTestFiles/resQName.xml"); |
| 2571 | loadDOMDocument(fileURL); |
| 2572 | |
| 2573 | // Get XML Schema Information for the Document |
| 2574 | XSModel schema = getGrammar(); |
| 2575 | |
| 2576 | DynamicContext dc = setupDynamicContext(schema); |
| 2577 | |
| 2578 | // test (a) |
| 2579 | String xpath = "resolve-QName(/messages/message[1]/@kind, /messages) = xs:QName('xs:int')"; |
| 2580 | XPath path = compileXPath(dc, xpath); |
| 2581 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2582 | ResultSequence rs = eval.evaluate(path); |
| 2583 | XSBoolean result = (XSBoolean) rs.first(); |
| 2584 | String actual = result.string_value(); |
| 2585 | assertEquals("true", actual); |
| 2586 | } |
| 2587 | |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2588 | public void testBug_namespaceUriFromQName_1() throws Exception { |
| 2589 | // improving implementation of fn:namespace-uri-from-QName |
| 2590 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2591 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2592 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2593 | loadDOMDocument(fileURL); |
| 2594 | |
| 2595 | // Get XML Schema Information for the Document |
| 2596 | XSModel schema = getGrammar(); |
| 2597 | |
| 2598 | DynamicContext dc = setupDynamicContext(schema); |
| 2599 | dc.add_namespace("p", "http://cta023.com/p"); |
| 2600 | |
| 2601 | // test (a) |
| 2602 | String xpath = "namespace-uri-from-QName(xs:QName('p:ppp')) = 'http://cta023.com/p'"; |
| 2603 | XPath path = compileXPath(dc, xpath); |
| 2604 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2605 | ResultSequence rs = eval.evaluate(path); |
| 2606 | XSBoolean result = (XSBoolean) rs.first(); |
| 2607 | String actual = result.string_value(); |
| 2608 | assertEquals("true", actual); |
| 2609 | } |
| 2610 | |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2611 | public void testBug_namespaceUriFromQName_2() throws Exception { |
| 2612 | // improving implementation of fn:namespace-uri-from-QName |
| 2613 | |
| 2614 | URL fileURL = bundle.getEntry("/bugTestFiles/namespaceUriFromQName_bug.xml"); |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2615 | loadDOMDocument(fileURL); |
| 2616 | |
| 2617 | // Get XML Schema Information for the Document |
| 2618 | XSModel schema = getGrammar(); |
| 2619 | |
| 2620 | DynamicContext dc = setupDynamicContext(schema); |
| 2621 | dc.add_namespace("a", "http://x.y"); |
| 2622 | |
| 2623 | String xpath = "namespace-uri-from-QName(node-name(a:X)) = 'http://x.y'"; |
| 2624 | XPath path = compileXPath(dc, xpath); |
| 2625 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2626 | ResultSequence rs = eval.evaluate(path); |
| 2627 | XSBoolean result = (XSBoolean) rs.first(); |
| 2628 | String actual = result.string_value(); |
| 2629 | assertEquals("true", actual); |
| 2630 | } |
| 2631 | |
| 2632 | public void testNonDocumentNodeAsRoot() throws Exception { |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2633 | // a non-document node as root node of the XDM tree. introducing a new argument to DefaultEvaluator. |
| 2634 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2635 | // reusing files from another bug |
| 2636 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 2637 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 2638 | |
| 2639 | loadDOMDocument(fileURL, schemaURL); |
| 2640 | |
| 2641 | // Get XSModel object for the Schema |
| 2642 | XSModel schema = getGrammar(schemaURL); |
| 2643 | |
| 2644 | DynamicContext dc = setupDynamicContext(schema); |
| 2645 | |
| 2646 | Evaluator eval = new DefaultEvaluator(dc, domDoc, domDoc.getDocumentElement()); |
| 2647 | |
| 2648 | // test a) |
| 2649 | String xpath = ". is root()"; |
| 2650 | XPath path = compileXPath(dc, xpath); |
| 2651 | ResultSequence rs = eval.evaluate(path); |
| 2652 | String actual = ((XSBoolean) rs.first()).string_value(); |
| 2653 | assertEquals("true", actual); |
| 2654 | |
| 2655 | // test b) |
| 2656 | xpath = "empty(..)"; |
| 2657 | path = compileXPath(dc, xpath); |
| 2658 | rs = eval.evaluate(path); |
| 2659 | actual = ((XSBoolean) rs.first()).string_value(); |
| 2660 | assertEquals("true", actual); |
| 2661 | } |
| 2662 | |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2663 | public void testFnIndexOf_onQName1() throws Exception { |
| 2664 | // fn:index-of finding QName values |
| 2665 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2666 | URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml"); |
| 2667 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd"); |
| 2668 | |
| 2669 | loadDOMDocument(fileURL, schemaURL); |
| 2670 | |
| 2671 | // Get XSModel object for the Schema |
| 2672 | XSModel schema = getGrammar(schemaURL); |
| 2673 | |
| 2674 | DynamicContext dc = setupDynamicContext(schema); |
| 2675 | |
| 2676 | String xpath = "index-of(for $e in X/* return node-name($e), node-name(X/b))"; |
| 2677 | XPath path = compileXPath(dc, xpath); |
| 2678 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2679 | ResultSequence rs = eval.evaluate(path); |
| 2680 | assertTrue(rs.size() > 0); |
| 2681 | String actual = ((XSInteger) rs.first()).string_value(); |
| 2682 | assertEquals("2", actual); |
| 2683 | } |
| 2684 | |
| 2685 | public void testFnIndexOf_onQName2() throws Exception { |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2686 | // fn:index-of finding QName values |
| 2687 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2688 | URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml"); |
| 2689 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd"); |
| 2690 | |
| 2691 | loadDOMDocument(fileURL, schemaURL); |
| 2692 | |
| 2693 | // Get XSModel object for the Schema |
| 2694 | XSModel schema = getGrammar(schemaURL); |
| 2695 | |
| 2696 | DynamicContext dc = setupDynamicContext(schema); |
| 2697 | |
| 2698 | String xpath = "index-of(for $e in X/* return node-name($e), xs:QName('b'))"; |
| 2699 | XPath path = compileXPath(dc, xpath); |
| 2700 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2701 | ResultSequence rs = eval.evaluate(path); |
| 2702 | assertTrue(rs.size() > 0); |
| 2703 | String actual = ((XSInteger) rs.first()).string_value(); |
| 2704 | assertEquals("2", actual); |
| 2705 | } |
| 2706 | |
| 2707 | public void testFnIndexOf_onQName3() throws Exception { |
mgandhi | 1794102 | 2011-11-26 15:45:14 +0000 | [diff] [blame] | 2708 | // fn:index-of finding QName values |
| 2709 | |
mgandhi | 13e689c | 2011-11-26 15:03:37 +0000 | [diff] [blame] | 2710 | URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml"); |
| 2711 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd"); |
| 2712 | |
| 2713 | loadDOMDocument(fileURL, schemaURL); |
| 2714 | |
| 2715 | // Get XSModel object for the Schema |
| 2716 | XSModel schema = getGrammar(schemaURL); |
| 2717 | |
| 2718 | DynamicContext dc = setupDynamicContext(schema); |
| 2719 | |
| 2720 | String xpath = "index-of(for $e in X/* return node-name($e), fn:QName('', 'b'))"; |
| 2721 | XPath path = compileXPath(dc, xpath); |
| 2722 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2723 | ResultSequence rs = eval.evaluate(path); |
| 2724 | assertTrue(rs.size() > 0); |
| 2725 | String actual = ((XSInteger) rs.first()).string_value(); |
| 2726 | assertEquals("2", actual); |
| 2727 | } |
| 2728 | |
mgandhi | 1e589ea | 2012-06-16 19:42:57 +0000 | [diff] [blame] | 2729 | public void testXSDateTimeCast() throws Exception { |
| 2730 | // test explicit casts on xs:dateTime node references |
| 2731 | |
| 2732 | URL fileURL = bundle.getEntry("/bugTestFiles/dateTime1.xml"); |
| 2733 | URL schemaURL = bundle.getEntry("/bugTestFiles/dateTime1.xsd"); |
| 2734 | |
| 2735 | loadDOMDocument(fileURL, schemaURL); |
| 2736 | |
| 2737 | // Get XSModel object for the Schema |
| 2738 | XSModel schema = getGrammar(schemaURL); |
| 2739 | |
| 2740 | DynamicContext dc = setupDynamicContext(schema); |
| 2741 | |
| 2742 | // test a) |
| 2743 | String xpath = "exists(xs:dateTime(/test/@t1))"; |
| 2744 | XPath path = compileXPath(dc, xpath); |
| 2745 | |
| 2746 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2747 | ResultSequence rs = eval.evaluate(path); |
| 2748 | |
| 2749 | XSBoolean result = (XSBoolean) rs.first(); |
| 2750 | String actual = result.string_value(); |
| 2751 | assertEquals("true", actual); |
| 2752 | |
| 2753 | // test b) |
| 2754 | xpath = "/test/@t1 instance of attribute(t1, xs:dateTime)"; |
| 2755 | path = compileXPath(dc, xpath); |
| 2756 | |
| 2757 | eval = new DefaultEvaluator(dc, domDoc); |
| 2758 | rs = eval.evaluate(path); |
| 2759 | |
| 2760 | result = (XSBoolean) rs.first(); |
| 2761 | actual = result.string_value(); |
| 2762 | assertEquals("true", actual); |
| 2763 | |
| 2764 | // test c) |
| 2765 | xpath = "(xs:dateTime(/test/@t1) + xs:dayTimeDuration('P1D')) eq xs:dateTime('2010-10-06T10:05:05')"; |
| 2766 | path = compileXPath(dc, xpath); |
| 2767 | |
| 2768 | eval = new DefaultEvaluator(dc, domDoc); |
| 2769 | rs = eval.evaluate(path); |
| 2770 | |
| 2771 | result = (XSBoolean) rs.first(); |
| 2772 | actual = result.string_value(); |
| 2773 | assertEquals("true", actual); |
| 2774 | } |
| 2775 | |
mgandhi | c4152f7 | 2012-09-29 09:15:53 +0530 | [diff] [blame] | 2776 | public void testBug_362026() throws Exception { |
| 2777 | // "instance of" must not atomize the LHS before the comparison check |
| 2778 | |
| 2779 | URL fileURL = bundle.getEntry("/bugTestFiles/bug362026.xml"); |
| 2780 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug362026.xsd"); |
| 2781 | |
| 2782 | loadDOMDocument(fileURL, schemaURL); |
| 2783 | |
| 2784 | // Get XSModel object for the Schema |
| 2785 | XSModel schema = getGrammar(schemaURL); |
| 2786 | |
| 2787 | DynamicContext dc = setupDynamicContext(schema); |
| 2788 | |
| 2789 | // test a) |
| 2790 | String xpath = "/X/Y instance of xs:integer"; |
| 2791 | XPath path = compileXPath(dc, xpath); |
| 2792 | |
| 2793 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2794 | ResultSequence rs = eval.evaluate(path); |
| 2795 | |
| 2796 | XSBoolean result = (XSBoolean) rs.first(); |
| 2797 | String actual = result.string_value(); |
| 2798 | assertEquals("false", actual); |
| 2799 | |
| 2800 | // test b) |
| 2801 | xpath = "/X/@att1 instance of xs:string"; |
| 2802 | path = compileXPath(dc, xpath); |
| 2803 | |
| 2804 | eval = new DefaultEvaluator(dc, domDoc); |
| 2805 | rs = eval.evaluate(path); |
| 2806 | |
| 2807 | result = (XSBoolean) rs.first(); |
| 2808 | actual = result.string_value(); |
| 2809 | assertEquals("false", actual); |
| 2810 | |
| 2811 | // test c) |
| 2812 | xpath = "/X/Y instance of element(*, xs:integer)"; |
| 2813 | path = compileXPath(dc, xpath); |
| 2814 | |
| 2815 | eval = new DefaultEvaluator(dc, domDoc); |
| 2816 | rs = eval.evaluate(path); |
| 2817 | |
| 2818 | result = (XSBoolean) rs.first(); |
| 2819 | actual = result.string_value(); |
| 2820 | assertEquals("true", actual); |
| 2821 | |
| 2822 | // test d) |
| 2823 | xpath = "/X/@att1 instance of attribute(*, xs:string)"; |
| 2824 | path = compileXPath(dc, xpath); |
| 2825 | |
| 2826 | eval = new DefaultEvaluator(dc, domDoc); |
| 2827 | rs = eval.evaluate(path); |
| 2828 | |
| 2829 | result = (XSBoolean) rs.first(); |
| 2830 | actual = result.string_value(); |
| 2831 | assertEquals("true", actual); |
| 2832 | } |
| 2833 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2834 | public void testBugNonAsciiCharsHandling() throws Exception { |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2835 | |
| 2836 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2837 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2838 | loadDOMDocument(fileURL); |
| 2839 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2840 | // Get XML Schema Information for the Document |
| 2841 | XSModel schema = getGrammar(); |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2842 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2843 | DynamicContext dc = setupDynamicContext(schema); |
| 2844 | |
| 2845 | |
| 2846 | String xpath = "count(Einführung) le 1"; |
| 2847 | try { |
| 2848 | XPath path = compileXPath(dc, xpath, true); |
| 2849 | } |
| 2850 | catch(Exception ex) { |
| 2851 | assertTrue(false); |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | public void testBugEQ() throws Exception { |
| 2856 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2857 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2858 | loadDOMDocument(fileURL); |
| 2859 | |
| 2860 | // Get XML Schema Information for the Document |
| 2861 | XSModel schema = getGrammar(); |
| 2862 | |
| 2863 | DynamicContext dc = setupDynamicContext(schema); |
| 2864 | |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2865 | String xpath = "1 eq '1'"; |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2866 | XPath path = compileXPath(dc, xpath); |
| 2867 | boolean successStatus = true; |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2868 | try { |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2869 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2870 | ResultSequence rs = eval.evaluate(path); |
| 2871 | assertEquals(false, successStatus); |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2872 | } |
| 2873 | catch (DynamicError err) { |
| 2874 | if ("XPTY0004".equals(err.code())) { |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2875 | successStatus = false; |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2876 | } |
| 2877 | } |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2878 | } |
| 2879 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2880 | public void testBugFnIndexOf() throws Exception { |
mgandhi | b936d57 | 2012-11-14 21:09:08 +0530 | [diff] [blame] | 2881 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2882 | URL fileURL = bundle.getEntry("/bugTestFiles/indexOf1.xml"); |
| 2883 | URL schemaURL = bundle.getEntry("/bugTestFiles/indexOf1.xsd"); |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2884 | |
| 2885 | loadDOMDocument(fileURL, schemaURL); |
| 2886 | |
| 2887 | // Get XSModel object for the Schema |
| 2888 | XSModel schema = getGrammar(schemaURL); |
| 2889 | |
| 2890 | DynamicContext dc = setupDynamicContext(schema); |
| 2891 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2892 | String xpath = "deep-equal(index-of(X/a, 2), (1,4))"; |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2893 | XPath path = compileXPath(dc, xpath); |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2894 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2895 | ResultSequence rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2896 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2897 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2898 | xpath = "deep-equal(index-of(X/b, 1), (1,3))"; |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2899 | path = compileXPath(dc, xpath); |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2900 | rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2901 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
| 2902 | |
| 2903 | xpath = "deep-equal(index-of(X/@attr, 5), (3,4,5))"; |
| 2904 | path = compileXPath(dc, xpath); |
| 2905 | rs = eval.evaluate(path); |
| 2906 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | efde5e1 | 2012-11-24 08:09:38 +0530 | [diff] [blame] | 2907 | } |
| 2908 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2909 | public void testBugTypedValue() throws Exception { |
mgandhi | 3d86c1b | 2012-11-26 22:02:50 +0530 | [diff] [blame] | 2910 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2911 | URL fileURL = bundle.getEntry("/bugTestFiles/bugTypedValue1.xml"); |
| 2912 | URL schemaURL = bundle.getEntry("/bugTestFiles/bugTypedValue1.xsd"); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2913 | |
| 2914 | loadDOMDocument(fileURL, schemaURL); |
| 2915 | |
| 2916 | // Get XSModel object for the Schema |
| 2917 | XSModel schema = getGrammar(schemaURL); |
| 2918 | |
| 2919 | DynamicContext dc = setupDynamicContext(schema); |
| 2920 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2921 | String xpath = "data(Z/X[1]/@val) instance of xs:date+"; |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2922 | XPath path = compileXPath(dc, xpath); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2923 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2924 | ResultSequence rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2925 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2926 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2927 | xpath = "count(data(Z/X[1]/@val)) eq 3"; |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2928 | path = compileXPath(dc, xpath); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2929 | rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2930 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2931 | } |
| 2932 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2933 | public void testBugFnSumOnDurationTypes() throws Exception { |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2934 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2935 | // use XSD 1.1 validation, for this test |
| 2936 | |
| 2937 | URL fileURL = bundle.getEntry("/bugTestFiles/FnSum1.xml"); |
| 2938 | URL schemaURL = bundle.getEntry("/bugTestFiles/FnSum1.xsd"); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2939 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2940 | loadDOMDocumentXS11(fileURL, schemaURL); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2941 | |
| 2942 | // Get XSModel object for the Schema |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2943 | XSModel schema = getGrammarXS11(schemaURL); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2944 | |
| 2945 | DynamicContext dc = setupDynamicContext(schema); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2946 | dc.add_namespace("tst", "http://www.rackspace.com/test/duration"); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2947 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2948 | String xpath = "xsd:dayTimeDuration('PT24H') = sum(tst:test/tst:d)"; |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2949 | XPath path = compileXPath(dc, xpath); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2950 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2951 | ResultSequence rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2952 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2953 | |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2954 | xpath = "xsd:dayTimeDuration('PT24H') = sum(for $d in tst:test/tst:d return $d)"; |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2955 | path = compileXPath(dc, xpath); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2956 | rs = eval.evaluate(path); |
mgandhi | ed6ab1e | 2014-04-15 14:06:40 +0530 | [diff] [blame] | 2957 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
mgandhi | 47f6a16 | 2012-12-12 19:15:08 +0530 | [diff] [blame] | 2958 | } |
| 2959 | |
mgandhi | 1e589ea | 2012-06-16 19:42:57 +0000 | [diff] [blame] | 2960 | |
IBM_ADMIN | 93f0343 | 2014-05-15 17:57:14 +0530 | [diff] [blame] | 2961 | public void testXSAnyURI_bug() throws Exception { |
| 2962 | |
| 2963 | URL fileURL = bundle.getEntry("/bugTestFiles/dashboard.xml"); |
| 2964 | loadDOMDocument(fileURL); |
| 2965 | |
| 2966 | // Get XML Schema Information for the Document |
| 2967 | XSModel schema = getGrammar(); |
| 2968 | |
| 2969 | DynamicContext dc = setupDynamicContext(schema); |
| 2970 | |
| 2971 | String xpath = "count(/dashboard/widget/*[namespace-uri() eq 'http://jaspersoft.com/highcharts']) eq 1"; |
| 2972 | XPath path = compileXPath(dc, xpath); |
| 2973 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2974 | ResultSequence rs = eval.evaluate(path); |
| 2975 | XSBoolean result = (XSBoolean) rs.first(); |
| 2976 | String actual = result.string_value(); |
| 2977 | assertEquals("true", actual); |
| 2978 | } |
| 2979 | |
Mukul Gandhi | a2692d1 | 2014-08-07 20:44:39 +0530 | [diff] [blame] | 2980 | public void testfnMatches() throws Exception { |
| 2981 | |
| 2982 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 2983 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 2984 | loadDOMDocument(fileURL); |
| 2985 | |
| 2986 | // Get XML Schema Information for the Document |
| 2987 | XSModel schema = getGrammar(); |
| 2988 | |
| 2989 | DynamicContext dc = setupDynamicContext(schema); |
| 2990 | |
| 2991 | String xpath = "matches('111-111-1111', '[0-9]{3}-[0-9]{3}-[0-9]{4}')"; |
| 2992 | XPath path = compileXPath(dc, xpath); |
| 2993 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 2994 | ResultSequence rs = eval.evaluate(path); |
| 2995 | assertEquals(true, ((XSBoolean) rs.first()).value()); |
| 2996 | } |
IBM_ADMIN | 93f0343 | 2014-05-15 17:57:14 +0530 | [diff] [blame] | 2997 | |
mgandhi | 247b6e7 | 2010-07-07 11:50:37 +0000 | [diff] [blame] | 2998 | private CollationProvider createLengthCollatorProvider() { |
| 2999 | return new CollationProvider() { |
| 3000 | @SuppressWarnings("unchecked") |
| 3001 | public Comparator get_collation(String name) { |
| 3002 | if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) { |
| 3003 | return new Comparator<String>() { |
| 3004 | public int compare(String o1, String o2) { |
| 3005 | return o1.length() - o2.length(); |
| 3006 | } |
| 3007 | }; |
| 3008 | } |
| 3009 | return null; |
| 3010 | } |
| 3011 | }; |
| 3012 | } |
| 3013 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 3014 | } |