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 |
| 49 | * an user-defined variable. |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 50 | *******************************************************************************/ |
| 51 | package org.eclipse.wst.xml.xpath2.processor.test; |
| 52 | |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame^] | 53 | import java.math.BigInteger; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 54 | import java.net.URL; |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 55 | import java.util.Comparator; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 56 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 57 | import javax.xml.parsers.DocumentBuilder; |
| 58 | import javax.xml.parsers.DocumentBuilderFactory; |
| 59 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 60 | import org.apache.xerces.xs.XSModel; |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 61 | import org.eclipse.core.runtime.Platform; |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 62 | import org.eclipse.wst.xml.xpath2.processor.CollationProvider; |
| 63 | import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 64 | import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; |
| 65 | import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
mgandhi | 13d897f | 2010-04-18 09:46:00 +0000 | [diff] [blame] | 66 | import org.eclipse.wst.xml.xpath2.processor.DynamicError; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 67 | import org.eclipse.wst.xml.xpath2.processor.Evaluator; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 68 | import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame^] | 69 | import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 70 | import org.eclipse.wst.xml.xpath2.processor.ast.XPath; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame^] | 71 | import org.eclipse.wst.xml.xpath2.processor.internal.types.QName; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 72 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean; |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 73 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 74 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble; |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 75 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 76 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat; |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame^] | 77 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger; |
| 78 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString; |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 79 | import org.osgi.framework.Bundle; |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 80 | import org.xml.sax.InputSource; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 81 | |
| 82 | public class TestBugs extends AbstractPsychoPathTest { |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 83 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 84 | 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] | 85 | |
| 86 | private Bundle bundle; |
| 87 | |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 88 | @Override |
| 89 | protected void setUp() throws Exception { |
| 90 | // TODO Auto-generated method stub |
| 91 | super.setUp(); |
| 92 | bundle = Platform |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 93 | .getBundle("org.eclipse.wst.xml.xpath2.processor.tests"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 94 | |
| 95 | } |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 96 | |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 97 | public void testNamesWhichAreKeywords() throws Exception { |
| 98 | // Bug 273719 |
| 99 | URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml"); |
| 100 | loadDOMDocument(fileURL); |
| 101 | |
| 102 | // Get XML Schema Information for the Document |
| 103 | XSModel schema = getGrammar(); |
| 104 | |
| 105 | DynamicContext dc = setupDynamicContext(schema); |
| 106 | |
| 107 | // String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)"; |
| 108 | String xpath = "(/element/eq eq 'eq') or //child::xs:*"; |
| 109 | XPath path = compileXPath(dc, xpath); |
| 110 | |
| 111 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 112 | ResultSequence rs = eval.evaluate(path); |
| 113 | |
| 114 | XSBoolean result = (XSBoolean) rs.first(); |
| 115 | |
| 116 | String actual = result.string_value(); |
| 117 | |
| 118 | assertEquals("true", actual); |
| 119 | } |
| 120 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 121 | public void testStringLengthWithElementArg() throws Exception { |
| 122 | // Bug 273719 |
| 123 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 124 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 125 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 126 | // Get XML Schema Information for the Document |
| 127 | XSModel schema = getGrammar(); |
| 128 | |
| 129 | DynamicContext dc = setupDynamicContext(schema); |
| 130 | |
| 131 | String xpath = "string-length(x) > 2"; |
| 132 | XPath path = compileXPath(dc, xpath); |
| 133 | |
| 134 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 135 | ResultSequence rs = eval.evaluate(path); |
| 136 | |
| 137 | XSBoolean result = (XSBoolean) rs.first(); |
| 138 | |
| 139 | String actual = result.string_value(); |
| 140 | |
| 141 | assertEquals("true", actual); |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 142 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 143 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 144 | public void testBug273795Arity2() throws Exception { |
| 145 | // Bug 273795 |
| 146 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 147 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 148 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 149 | // Get XML Schema Information for the Document |
| 150 | XSModel schema = getGrammar(); |
| 151 | |
| 152 | DynamicContext dc = setupDynamicContext(schema); |
| 153 | |
| 154 | // test with arity 2 |
| 155 | String xpath = "substring(x, 3) = 'happy'"; |
| 156 | XPath path = compileXPath(dc, xpath); |
| 157 | |
| 158 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 159 | ResultSequence rs = eval.evaluate(path); |
| 160 | |
| 161 | XSBoolean result = (XSBoolean) rs.first(); |
| 162 | |
| 163 | String actual = result.string_value(); |
| 164 | |
| 165 | assertEquals("true", actual); |
| 166 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 167 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 168 | public void testBug273795Arity3() throws Exception { |
| 169 | // Bug 273795 |
| 170 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 171 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 172 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 173 | // Get XML Schema Information for the Document |
| 174 | XSModel schema = getGrammar(); |
| 175 | |
| 176 | DynamicContext dc = setupDynamicContext(schema); |
| 177 | |
| 178 | // test with arity 3 |
| 179 | String xpath = "substring(x, 3, 4) = 'happ'"; |
| 180 | XPath path = compileXPath(dc, xpath); |
| 181 | |
| 182 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 183 | ResultSequence rs = eval.evaluate(path); |
| 184 | |
| 185 | XSBoolean result = (XSBoolean) rs.first(); |
| 186 | |
| 187 | String actual = result.string_value(); |
| 188 | |
| 189 | assertEquals("true", actual); |
| 190 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 191 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 192 | public void testStringFunctionBug274471() throws Exception { |
| 193 | // Bug 274471 |
| 194 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 195 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 196 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 197 | // Get XML Schema Information for the Document |
| 198 | XSModel schema = getGrammar(); |
| 199 | |
| 200 | DynamicContext dc = setupDynamicContext(schema); |
| 201 | |
| 202 | String xpath = "x/string() = 'unhappy'"; |
| 203 | XPath path = compileXPath(dc, xpath); |
| 204 | |
| 205 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 206 | ResultSequence rs = eval.evaluate(path); |
| 207 | |
| 208 | XSBoolean result = (XSBoolean) rs.first(); |
| 209 | |
| 210 | String actual = result.string_value(); |
| 211 | |
| 212 | assertEquals("true", actual); |
| 213 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 214 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 215 | public void testStringLengthFunctionBug274471() throws Exception { |
| 216 | // Bug 274471. string-length() with arity 0 |
| 217 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 218 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 219 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 220 | // Get XML Schema Information for the Document |
| 221 | XSModel schema = getGrammar(); |
| 222 | |
| 223 | DynamicContext dc = setupDynamicContext(schema); |
| 224 | |
| 225 | String xpath = "x/string-length() = 7"; |
| 226 | XPath path = compileXPath(dc, xpath); |
| 227 | |
| 228 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 229 | ResultSequence rs = eval.evaluate(path); |
| 230 | |
| 231 | XSBoolean result = (XSBoolean) rs.first(); |
| 232 | |
| 233 | String actual = result.string_value(); |
| 234 | |
dacarver | 9bffb27 | 2009-09-03 01:28:58 +0000 | [diff] [blame] | 235 | assertEquals("false", actual); |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 236 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 237 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 238 | public void testNormalizeSpaceFunctionBug274471() throws Exception { |
| 239 | // Bug 274471. normalize-space() with arity 0 |
| 240 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 241 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 242 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 243 | // Get XML Schema Information for the Document |
| 244 | XSModel schema = getGrammar(); |
| 245 | |
| 246 | DynamicContext dc = setupDynamicContext(schema); |
| 247 | |
| 248 | String xpath = "x/normalize-space() = 'unhappy'"; |
| 249 | XPath path = compileXPath(dc, xpath); |
| 250 | |
| 251 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 252 | ResultSequence rs = eval.evaluate(path); |
| 253 | |
| 254 | XSBoolean result = (XSBoolean) rs.first(); |
| 255 | |
| 256 | String actual = result.string_value(); |
| 257 | |
| 258 | assertEquals("true", actual); |
| 259 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 260 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 261 | public void testAnyUriEqualityBug() throws Exception { |
| 262 | // Bug 274719 |
| 263 | // reusing the XML document from another bug |
| 264 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 265 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 266 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 267 | // Get XML Schema Information for the Document |
| 268 | XSModel schema = getGrammar(); |
| 269 | |
| 270 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 271 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 272 | String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')"; |
| 273 | XPath path = compileXPath(dc, xpath); |
| 274 | |
| 275 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 276 | ResultSequence rs = eval.evaluate(path); |
| 277 | |
| 278 | XSBoolean result = (XSBoolean) rs.first(); |
| 279 | |
| 280 | String actual = result.string_value(); |
| 281 | |
| 282 | assertEquals("true", actual); |
| 283 | } |
| 284 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 285 | public void testBaseUriBug() throws Exception { |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 286 | // Bug 274725 |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 287 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 288 | // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 289 | // DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 290 | loadDOMDocument(new URL("http://resolved-locally/xml/note.xml")); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 291 | |
| 292 | // for testing this bug, we read the XML document from the web. |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 293 | // this ensures, that base-uri property of DOM is not null. |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 294 | // domDoc = docBuilder.parse("http://resolved-locally/xml/note.xml"); |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 295 | |
| 296 | // we pass XSModel as null for this test case. Otherwise, we would |
| 297 | // get an exception. |
| 298 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 299 | |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 300 | 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] | 301 | |
| 302 | // please note: The below XPath would also work, with base-uri using |
| 303 | // arity 0. |
| 304 | // String xpath = |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 305 | // "note/base-uri() eq xs:anyURI('http://resolved-locally/xml/note.xml')"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 306 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 307 | XPath path = compileXPath(dc, xpath); |
| 308 | |
| 309 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 310 | ResultSequence rs = eval.evaluate(path); |
| 311 | |
| 312 | XSBoolean result = (XSBoolean) rs.first(); |
| 313 | |
| 314 | String actual = result.string_value(); |
| 315 | |
dacarver | acf5e12 | 2009-08-05 02:48:43 +0000 | [diff] [blame] | 316 | assertEquals("true", actual); |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 317 | } |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 318 | |
| 319 | public void testDocumentUriBug() throws Exception { |
| 320 | // Bug 274731 |
| 321 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 322 | DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 323 | |
| 324 | InputSource inputSource = getTestSource("http://resolved-locally/xml/note.xml"); |
| 325 | domDoc = docBuilder.parse(inputSource); |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 326 | |
| 327 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 328 | |
jmoller | ef1b2b4 | 2010-08-12 10:33:28 +0000 | [diff] [blame] | 329 | String xpath = "document-uri(/) eq xs:anyURI('http://resolved-locally/xml/note.xml')"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 330 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 331 | XPath path = compileXPath(dc, xpath); |
| 332 | |
| 333 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 334 | ResultSequence rs = eval.evaluate(path); |
| 335 | |
| 336 | XSBoolean result = (XSBoolean) rs.first(); |
| 337 | |
| 338 | String actual = "false"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 339 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 340 | if (result != null) { |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 341 | actual = result.string_value(); |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | assertEquals("true", actual); |
| 345 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 346 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 347 | public void testBooleanTypeBug() throws Exception { |
| 348 | // Bug 274784 |
| 349 | // reusing the XML document from another bug |
| 350 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 351 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 352 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 353 | // Get XML Schema Information for the Document |
| 354 | XSModel schema = getGrammar(); |
| 355 | |
| 356 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 357 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 358 | String xpath = "xs:boolean('1') eq xs:boolean('true')"; |
| 359 | XPath path = compileXPath(dc, xpath); |
| 360 | |
| 361 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 362 | ResultSequence rs = eval.evaluate(path); |
| 363 | |
| 364 | XSBoolean result = (XSBoolean) rs.first(); |
| 365 | |
| 366 | String actual = result.string_value(); |
| 367 | |
| 368 | assertEquals("true", actual); |
| 369 | } |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 370 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 371 | public void testDateConstructorBug() throws Exception { |
| 372 | // Bug 274792 |
| 373 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml"); |
| 374 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 375 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 376 | // Get XML Schema Information for the Document |
| 377 | XSModel schema = getGrammar(); |
| 378 | |
| 379 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 380 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 381 | String xpath = "xs:date(x) eq xs:date('2009-01-01')"; |
| 382 | XPath path = compileXPath(dc, xpath); |
| 383 | |
| 384 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 385 | ResultSequence rs = eval.evaluate(path); |
| 386 | |
| 387 | XSBoolean result = (XSBoolean) rs.first(); |
| 388 | |
| 389 | String actual = result.string_value(); |
| 390 | |
| 391 | assertEquals("true", actual); |
| 392 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 393 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 394 | public void testIntegerDataTypeBug() throws Exception { |
| 395 | // Bug 274805 |
| 396 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml"); |
| 397 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 398 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 399 | // Get XML Schema Information for the Document |
| 400 | XSModel schema = getGrammar(); |
| 401 | |
| 402 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 403 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 404 | String xpath = "xs:integer(x) gt 100"; |
| 405 | XPath path = compileXPath(dc, xpath); |
| 406 | |
| 407 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 408 | ResultSequence rs = eval.evaluate(path); |
| 409 | |
| 410 | XSBoolean result = (XSBoolean) rs.first(); |
| 411 | |
| 412 | String actual = result.string_value(); |
| 413 | |
| 414 | assertEquals("true", actual); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 415 | } |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 416 | |
| 417 | public void testLongDataType() throws Exception { |
| 418 | // Bug 274952 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 419 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 420 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 421 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 422 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 423 | // Get XML Schema Information for the Document |
| 424 | XSModel schema = getGrammar(); |
| 425 | |
| 426 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 427 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 428 | // long min value is -9223372036854775808 |
| 429 | // and max value can be 9223372036854775807 |
| 430 | String xpath = "xs:long('9223372036854775807') gt 0"; |
| 431 | XPath path = compileXPath(dc, xpath); |
| 432 | |
| 433 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 434 | ResultSequence rs = eval.evaluate(path); |
| 435 | |
| 436 | XSBoolean result = (XSBoolean) rs.first(); |
| 437 | |
| 438 | String actual = result.string_value(); |
| 439 | |
| 440 | assertEquals("true", actual); |
| 441 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 442 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 443 | public void testIntDataType() throws Exception { |
| 444 | // Bug 275105 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 445 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 446 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 447 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 448 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 449 | // Get XML Schema Information for the Document |
| 450 | XSModel schema = getGrammar(); |
| 451 | |
| 452 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 453 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 454 | // int min value is -2147483648 |
| 455 | // and max value can be 2147483647 |
| 456 | String xpath = "xs:int('2147483647') gt 0"; |
| 457 | XPath path = compileXPath(dc, xpath); |
| 458 | |
| 459 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 460 | ResultSequence rs = eval.evaluate(path); |
| 461 | |
| 462 | XSBoolean result = (XSBoolean) rs.first(); |
| 463 | |
| 464 | String actual = result.string_value(); |
| 465 | |
| 466 | assertEquals("true", actual); |
| 467 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 468 | |
| 469 | public void testSchemaAwarenessForAttributes() throws Exception { |
| 470 | // Bug 276134 |
| 471 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 472 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 473 | |
| 474 | loadDOMDocument(fileURL, schemaURL); |
| 475 | |
| 476 | // Get XSModel object for the Schema |
| 477 | XSModel schema = getGrammar(schemaURL); |
| 478 | |
| 479 | DynamicContext dc = setupDynamicContext(schema); |
| 480 | |
| 481 | String xpath = "person/@dob eq xs:date('2006-12-10')"; |
| 482 | XPath path = compileXPath(dc, xpath); |
| 483 | |
| 484 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 485 | ResultSequence rs = eval.evaluate(path); |
| 486 | |
| 487 | XSBoolean result = (XSBoolean) rs.first(); |
| 488 | |
| 489 | String actual = result.string_value(); |
| 490 | |
| 491 | assertEquals("true", actual); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | public void testSchemaAwarenessForElements() throws Exception { |
| 496 | // Bug 276134 |
| 497 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml"); |
| 498 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd"); |
| 499 | |
| 500 | loadDOMDocument(fileURL, schemaURL); |
| 501 | |
| 502 | // Get XSModel object for the Schema |
| 503 | XSModel schema = getGrammar(schemaURL); |
| 504 | |
| 505 | DynamicContext dc = setupDynamicContext(schema); |
| 506 | |
| 507 | String xpath = "person/dob eq xs:date('2006-12-10')"; |
| 508 | XPath path = compileXPath(dc, xpath); |
| 509 | |
| 510 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 511 | ResultSequence rs = eval.evaluate(path); |
| 512 | |
| 513 | XSBoolean result = (XSBoolean) rs.first(); |
| 514 | |
| 515 | String actual = result.string_value(); |
| 516 | |
| 517 | assertEquals("true", actual); |
| 518 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 519 | |
jmoller | aaedb5f | 2009-12-16 14:18:49 +0000 | [diff] [blame] | 520 | public void testNilled() throws Exception { |
| 521 | // This is a terrible shortcoming in the test suite, I'd say |
| 522 | URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml"); |
| 523 | URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd"); |
| 524 | |
| 525 | loadDOMDocument(fileURL, schemaURL); |
| 526 | |
| 527 | // Get XSModel object for the Schema |
| 528 | XSModel schema = getGrammar(schemaURL); |
| 529 | |
| 530 | DynamicContext dc = setupDynamicContext(schema); |
| 531 | |
| 532 | assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )")); |
| 533 | assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )")); |
| 534 | assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )")); |
| 535 | |
| 536 | assertFalse(evaluateBoolean(dc, "nilled(/root/element1)")); |
| 537 | assertTrue(evaluateBoolean(dc, "nilled(/root/element2)")); |
| 538 | assertFalse(evaluateBoolean(dc, "nilled(/root/element3)")); |
| 539 | assertFalse(evaluateBoolean(dc, "nilled(/root/element4)")); |
| 540 | } |
| 541 | |
| 542 | // I can't stand to see so much duplicated code!!! |
| 543 | private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception { |
| 544 | XPath path = compileXPath(dc, xpath); |
| 545 | |
| 546 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 547 | ResultSequence rs = eval.evaluate(path); |
| 548 | |
| 549 | XSBoolean result = (XSBoolean) rs.first(); |
| 550 | |
| 551 | return result.value(); |
| 552 | } |
| 553 | |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 554 | public void testXSNonPositiveInteger() throws Exception { |
| 555 | // Bug 277599 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 556 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 557 | |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 558 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 559 | loadDOMDocument(fileURL); |
| 560 | |
| 561 | // Get XML Schema Information for the Document |
| 562 | XSModel schema = getGrammar(); |
| 563 | |
| 564 | DynamicContext dc = setupDynamicContext(schema); |
| 565 | |
| 566 | // min value of xs:nonPositiveInteger is -INF |
| 567 | // max value is 0 |
| 568 | String xpath = "xs:nonPositiveInteger('0') eq 0"; |
| 569 | XPath path = compileXPath(dc, xpath); |
| 570 | |
| 571 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 572 | ResultSequence rs = eval.evaluate(path); |
| 573 | |
| 574 | XSBoolean result = (XSBoolean) rs.first(); |
| 575 | |
| 576 | String actual = result.string_value(); |
| 577 | |
| 578 | assertEquals("true", actual); |
| 579 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 580 | |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 581 | public void testXSNegativeInteger() throws Exception { |
| 582 | // Bug 277602 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 583 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 584 | |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 585 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 586 | loadDOMDocument(fileURL); |
| 587 | |
| 588 | // Get XML Schema Information for the Document |
| 589 | XSModel schema = getGrammar(); |
| 590 | |
| 591 | DynamicContext dc = setupDynamicContext(schema); |
| 592 | |
| 593 | // min value of xs:negativeInteger is -INF |
| 594 | // max value is -1 |
| 595 | String xpath = "xs:negativeInteger('-1') eq -1"; |
| 596 | XPath path = compileXPath(dc, xpath); |
| 597 | |
| 598 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 599 | ResultSequence rs = eval.evaluate(path); |
| 600 | |
| 601 | XSBoolean result = (XSBoolean) rs.first(); |
| 602 | |
| 603 | String actual = result.string_value(); |
| 604 | |
| 605 | assertEquals("true", actual); |
| 606 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 607 | |
dacarver | 72e78ba | 2009-05-25 03:40:46 +0000 | [diff] [blame] | 608 | public void testXSShort() throws Exception { |
| 609 | // Bug 277608 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 610 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 611 | |
dacarver | 72e78ba | 2009-05-25 03:40:46 +0000 | [diff] [blame] | 612 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 613 | loadDOMDocument(fileURL); |
| 614 | |
| 615 | // Get XML Schema Information for the Document |
| 616 | XSModel schema = getGrammar(); |
| 617 | |
| 618 | DynamicContext dc = setupDynamicContext(schema); |
| 619 | |
| 620 | // min value of xs:short is -32768 |
| 621 | // max value of xs:short is 32767 |
| 622 | String xpath = "xs:short('-32768') eq -32768"; |
| 623 | XPath path = compileXPath(dc, xpath); |
| 624 | |
| 625 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 626 | ResultSequence rs = eval.evaluate(path); |
| 627 | |
| 628 | XSBoolean result = (XSBoolean) rs.first(); |
| 629 | |
| 630 | String actual = result.string_value(); |
| 631 | |
| 632 | assertEquals("true", actual); |
| 633 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 634 | |
dacarver | 1bb092e | 2009-05-25 04:02:48 +0000 | [diff] [blame] | 635 | public void testXSNonNegativeInteger() throws Exception { |
| 636 | // Bug 277609 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 637 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 638 | |
dacarver | 1bb092e | 2009-05-25 04:02:48 +0000 | [diff] [blame] | 639 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 640 | loadDOMDocument(fileURL); |
| 641 | |
| 642 | // Get XML Schema Information for the Document |
| 643 | XSModel schema = getGrammar(); |
| 644 | |
| 645 | DynamicContext dc = setupDynamicContext(schema); |
| 646 | |
| 647 | // min value of xs:nonNegativeInteger is 0 |
| 648 | // max value of xs:nonNegativeInteger is INF |
| 649 | String xpath = "xs:nonNegativeInteger('0') eq 0"; |
| 650 | XPath path = compileXPath(dc, xpath); |
| 651 | |
| 652 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 653 | ResultSequence rs = eval.evaluate(path); |
| 654 | |
| 655 | XSBoolean result = (XSBoolean) rs.first(); |
| 656 | |
| 657 | String actual = result.string_value(); |
| 658 | |
| 659 | assertEquals("true", actual); |
| 660 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 661 | |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 662 | public void testXSUnsignedLong() throws Exception { |
| 663 | // Bug 277629 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 664 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 665 | |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 666 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 667 | loadDOMDocument(fileURL); |
| 668 | |
| 669 | // Get XML Schema Information for the Document |
| 670 | XSModel schema = getGrammar(); |
| 671 | |
| 672 | DynamicContext dc = setupDynamicContext(schema); |
| 673 | |
| 674 | // min value of xs:unsignedLong is 0 |
| 675 | // max value of xs:unsignedLong is 18446744073709551615 |
| 676 | String xpath = "xs:unsignedLong('0') eq 0"; |
| 677 | XPath path = compileXPath(dc, xpath); |
| 678 | |
| 679 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 680 | ResultSequence rs = eval.evaluate(path); |
| 681 | |
| 682 | XSBoolean result = (XSBoolean) rs.first(); |
| 683 | |
| 684 | String actual = result.string_value(); |
| 685 | |
| 686 | assertEquals("true", actual); |
| 687 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 688 | |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 689 | public void testXSPositiveInteger() throws Exception { |
| 690 | // Bug 277632 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 691 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 692 | |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 693 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 694 | loadDOMDocument(fileURL); |
| 695 | |
| 696 | // Get XML Schema Information for the Document |
| 697 | XSModel schema = getGrammar(); |
| 698 | |
| 699 | DynamicContext dc = setupDynamicContext(schema); |
| 700 | |
| 701 | // min value of xs:positiveInteger is 1 |
| 702 | // max value of xs:positiveInteger is INF |
| 703 | String xpath = "xs:positiveInteger('1') eq 1"; |
| 704 | XPath path = compileXPath(dc, xpath); |
| 705 | |
| 706 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 707 | ResultSequence rs = eval.evaluate(path); |
| 708 | |
| 709 | XSBoolean result = (XSBoolean) rs.first(); |
| 710 | |
| 711 | String actual = result.string_value(); |
| 712 | |
| 713 | assertEquals("true", actual); |
| 714 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 715 | |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 716 | public void testXSByte() throws Exception { |
| 717 | // Bug 277639 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 718 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 719 | |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 720 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 721 | loadDOMDocument(fileURL); |
| 722 | |
| 723 | // Get XML Schema Information for the Document |
| 724 | XSModel schema = getGrammar(); |
| 725 | |
| 726 | DynamicContext dc = setupDynamicContext(schema); |
| 727 | |
| 728 | // min value of xs:byte is -128 |
| 729 | // max value of xs:byte is 127 |
| 730 | String xpath = "xs:byte('-128') eq -128"; |
| 731 | XPath path = compileXPath(dc, xpath); |
| 732 | |
| 733 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 734 | ResultSequence rs = eval.evaluate(path); |
| 735 | |
| 736 | XSBoolean result = (XSBoolean) rs.first(); |
| 737 | |
| 738 | String actual = result.string_value(); |
| 739 | |
| 740 | assertEquals("true", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 741 | } |
| 742 | |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 743 | public void testXSUnsignedInt() throws Exception { |
| 744 | // Bug 277642 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 745 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 7d5e292 | 2009-11-08 15:40:36 +0000 | [diff] [blame] | 746 | |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 747 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 748 | loadDOMDocument(fileURL); |
| 749 | |
| 750 | // Get XML Schema Information for the Document |
| 751 | XSModel schema = getGrammar(); |
| 752 | |
| 753 | DynamicContext dc = setupDynamicContext(schema); |
| 754 | |
| 755 | // min value of xs:unsignedInt is 0 |
| 756 | // max value of xs:unsignedInt is 4294967295 |
| 757 | String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')"; |
| 758 | XPath path = compileXPath(dc, xpath); |
| 759 | |
| 760 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 761 | ResultSequence rs = eval.evaluate(path); |
| 762 | |
| 763 | XSBoolean result = (XSBoolean) rs.first(); |
| 764 | |
| 765 | String actual = result.string_value(); |
| 766 | |
| 767 | assertEquals("true", actual); |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 768 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 769 | |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 770 | public void testXSUnsignedShort() throws Exception { |
| 771 | // Bug 277645 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 772 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 773 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 774 | loadDOMDocument(fileURL); |
| 775 | |
| 776 | // Get XML Schema Information for the Document |
| 777 | XSModel schema = getGrammar(); |
| 778 | |
| 779 | DynamicContext dc = setupDynamicContext(schema); |
| 780 | |
| 781 | // min value of xs:unsignedShort is 0 |
| 782 | // max value of xs:unsignedShort is 65535 |
| 783 | String xpath = "xs:unsignedShort('65535') eq 65535"; |
| 784 | XPath path = compileXPath(dc, xpath); |
| 785 | |
| 786 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 787 | ResultSequence rs = eval.evaluate(path); |
| 788 | |
| 789 | XSBoolean result = (XSBoolean) rs.first(); |
| 790 | |
| 791 | String actual = result.string_value(); |
| 792 | |
| 793 | assertEquals("true", actual); |
| 794 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 795 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 796 | public void testXSYearMonthDurationMultiply() throws Exception { |
| 797 | // Bug 279373 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 798 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 799 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 800 | loadDOMDocument(fileURL); |
| 801 | |
| 802 | // Get XML Schema Information for the Document |
| 803 | XSModel schema = getGrammar(); |
| 804 | |
| 805 | DynamicContext dc = setupDynamicContext(schema); |
| 806 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 807 | String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3"; |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 808 | XPath path = compileXPath(dc, xpath); |
| 809 | |
| 810 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 811 | ResultSequence rs = eval.evaluate(path); |
| 812 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 813 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 814 | |
| 815 | String actual = result.string_value(); |
| 816 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 817 | assertEquals("P6Y9M", actual); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 818 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 819 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 820 | public void testXSYearMonthDurationDivide1() throws Exception { |
| 821 | // Bug 279376 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 822 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 823 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 824 | loadDOMDocument(fileURL); |
| 825 | |
| 826 | // Get XML Schema Information for the Document |
| 827 | XSModel schema = getGrammar(); |
| 828 | |
| 829 | DynamicContext dc = setupDynamicContext(schema); |
| 830 | |
| 831 | String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5"; |
| 832 | XPath path = compileXPath(dc, xpath); |
| 833 | |
| 834 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 835 | ResultSequence rs = eval.evaluate(path); |
| 836 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 837 | XSDuration result = (XSDuration) rs.first(); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 838 | |
| 839 | String actual = result.string_value(); |
| 840 | |
| 841 | assertEquals("P1Y11M", actual); |
| 842 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 843 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 844 | public void testXSYearMonthDurationDivide2() throws Exception { |
| 845 | // Bug 279376 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 846 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 847 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 848 | loadDOMDocument(fileURL); |
| 849 | |
| 850 | // Get XML Schema Information for the Document |
| 851 | XSModel schema = getGrammar(); |
| 852 | |
| 853 | DynamicContext dc = setupDynamicContext(schema); |
| 854 | |
| 855 | String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')"; |
| 856 | XPath path = compileXPath(dc, xpath); |
| 857 | |
| 858 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 859 | ResultSequence rs = eval.evaluate(path); |
| 860 | |
| 861 | XSDecimal result = (XSDecimal) rs.first(); |
| 862 | |
| 863 | String actual = result.string_value(); |
| 864 | |
| 865 | assertEquals("-2.5", actual); |
| 866 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 867 | |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 868 | public void testXSDayTimeDurationMultiply() throws Exception { |
| 869 | // Bug 279377 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 870 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 871 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 872 | loadDOMDocument(fileURL); |
| 873 | |
| 874 | // Get XML Schema Information for the Document |
| 875 | XSModel schema = getGrammar(); |
| 876 | |
| 877 | DynamicContext dc = setupDynamicContext(schema); |
| 878 | |
| 879 | String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1"; |
| 880 | XPath path = compileXPath(dc, xpath); |
| 881 | |
| 882 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 883 | ResultSequence rs = eval.evaluate(path); |
| 884 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 885 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 886 | |
| 887 | String actual = result.string_value(); |
| 888 | |
| 889 | assertEquals("PT4H33M", actual); |
| 890 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 891 | |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 892 | public void testXSDayTimeDurationDivide() throws Exception { |
| 893 | // Bug 279377 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 894 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 895 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 896 | loadDOMDocument(fileURL); |
| 897 | |
| 898 | // Get XML Schema Information for the Document |
| 899 | XSModel schema = getGrammar(); |
| 900 | |
| 901 | DynamicContext dc = setupDynamicContext(schema); |
| 902 | |
| 903 | String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5"; |
| 904 | XPath path = compileXPath(dc, xpath); |
| 905 | |
| 906 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 907 | ResultSequence rs = eval.evaluate(path); |
| 908 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame] | 909 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 910 | |
| 911 | String actual = result.string_value(); |
| 912 | |
| 913 | assertEquals("PT17H40M7S", actual); |
| 914 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 915 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 916 | public void testNegativeZeroDouble() throws Exception { |
| 917 | // Bug 279406 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 918 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 919 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 920 | loadDOMDocument(fileURL); |
| 921 | |
| 922 | // Get XML Schema Information for the Document |
| 923 | XSModel schema = getGrammar(); |
| 924 | |
| 925 | DynamicContext dc = setupDynamicContext(schema); |
| 926 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 927 | String xpath = "-(xs:double('0'))"; |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 928 | XPath path = compileXPath(dc, xpath); |
| 929 | |
| 930 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 931 | ResultSequence rs = eval.evaluate(path); |
| 932 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 933 | XSDouble result = (XSDouble) rs.first(); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 934 | |
| 935 | String actual = result.string_value(); |
| 936 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 937 | assertEquals("-0", actual); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 938 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 939 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 940 | public void testNegativeZeroFloat() throws Exception { |
| 941 | // Bug 279406 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 942 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 943 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 944 | loadDOMDocument(fileURL); |
| 945 | |
| 946 | // Get XML Schema Information for the Document |
| 947 | XSModel schema = getGrammar(); |
| 948 | |
| 949 | DynamicContext dc = setupDynamicContext(schema); |
| 950 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 951 | String xpath = "-(xs:float('0'))"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 952 | XPath path = compileXPath(dc, xpath); |
| 953 | |
| 954 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 955 | ResultSequence rs = eval.evaluate(path); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 956 | |
| 957 | XSFloat result = (XSFloat) rs.first(); |
| 958 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 959 | String actual = result.string_value(); |
| 960 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 961 | assertEquals("-0", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 962 | } |
| 963 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 964 | public void testXSUnsignedByte() throws Exception { |
| 965 | // Bug 277650 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 966 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 967 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 968 | loadDOMDocument(fileURL); |
| 969 | |
| 970 | // Get XML Schema Information for the Document |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 971 | XSModel schema = getGrammar(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 972 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 973 | DynamicContext dc = setupDynamicContext(schema); |
| 974 | |
| 975 | // min value of xs:unsignedByte is 0 |
| 976 | // max value of xs:unsignedByte is 255 |
| 977 | String xpath = "xs:unsignedByte('255') eq 255"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 978 | XPath path = compileXPath(dc, xpath); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 979 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 980 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 981 | ResultSequence rs = eval.evaluate(path); |
| 982 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 983 | XSBoolean result = (XSBoolean) rs.first(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 984 | |
| 985 | String actual = result.string_value(); |
| 986 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 987 | assertEquals("true", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 988 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 989 | |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 990 | public void testXSBase64Binary() throws Exception { |
| 991 | // Bug 281046 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 992 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 993 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 994 | loadDOMDocument(fileURL); |
| 995 | |
| 996 | // Get XML Schema Information for the Document |
| 997 | XSModel schema = getGrammar(); |
| 998 | |
| 999 | DynamicContext dc = setupDynamicContext(schema); |
| 1000 | |
| 1001 | String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')"; |
| 1002 | XPath path = compileXPath(dc, xpath); |
| 1003 | |
| 1004 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1005 | ResultSequence rs = eval.evaluate(path); |
| 1006 | |
| 1007 | XSBoolean result = (XSBoolean) rs.first(); |
| 1008 | |
| 1009 | String actual = result.string_value(); |
| 1010 | |
| 1011 | assertEquals("true", actual); |
| 1012 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1013 | |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 1014 | public void testXSHexBinary() throws Exception { |
| 1015 | // Bug 281054 |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1016 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 1017 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1018 | loadDOMDocument(fileURL); |
| 1019 | |
| 1020 | // Get XML Schema Information for the Document |
| 1021 | XSModel schema = getGrammar(); |
| 1022 | |
| 1023 | DynamicContext dc = setupDynamicContext(schema); |
| 1024 | |
| 1025 | String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')"; |
| 1026 | XPath path = compileXPath(dc, xpath); |
| 1027 | |
| 1028 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1029 | ResultSequence rs = eval.evaluate(path); |
| 1030 | |
| 1031 | XSBoolean result = (XSBoolean) rs.first(); |
| 1032 | |
| 1033 | String actual = result.string_value(); |
| 1034 | |
| 1035 | assertEquals("true", actual); |
| 1036 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1037 | |
mgandhi | efe9574 | 2009-08-18 04:12:11 +0000 | [diff] [blame] | 1038 | public void testElementTypedValue() throws Exception { |
| 1039 | // test for fix in ElementType.java, involving incorrectly computing |
| 1040 | // typed value of element node, in case of validating element node, |
| 1041 | // with a user defined simple XSD type. |
| 1042 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1043 | URL schemaURL = bundle |
| 1044 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
mgandhi | efe9574 | 2009-08-18 04:12:11 +0000 | [diff] [blame] | 1045 | |
| 1046 | loadDOMDocument(fileURL, schemaURL); |
| 1047 | |
| 1048 | // Get XSModel object for the Schema |
| 1049 | XSModel schema = getGrammar(schemaURL); |
| 1050 | |
| 1051 | DynamicContext dc = setupDynamicContext(schema); |
| 1052 | |
| 1053 | String xpath = "Example/Transportation/mode eq 'air'"; |
| 1054 | XPath path = compileXPath(dc, xpath); |
| 1055 | |
| 1056 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1057 | ResultSequence rs = eval.evaluate(path); |
| 1058 | |
| 1059 | XSBoolean result = (XSBoolean) rs.first(); |
| 1060 | |
| 1061 | String actual = result.string_value(); |
| 1062 | |
| 1063 | assertEquals("true", actual); |
| 1064 | |
| 1065 | } |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1066 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1067 | public void testBug286061_quoted_string_literals_no_normalize() |
| 1068 | throws Exception { |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1069 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1070 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1071 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1072 | loadDOMDocument(fileURL); |
| 1073 | |
| 1074 | // Get XML Schema Information for the Document |
| 1075 | XSModel schema = getGrammar(); |
| 1076 | |
| 1077 | DynamicContext dc = setupDynamicContext(schema); |
| 1078 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1079 | String xpath = "'\"\"'"; // the expression '""' contains no escapes |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1080 | |
| 1081 | XPath path = compileXPath(dc, xpath); |
| 1082 | |
| 1083 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1084 | ResultSequence rs = eval.evaluate(path); |
| 1085 | |
| 1086 | String resultValue = rs.first().string_value(); |
| 1087 | |
| 1088 | assertEquals("\"\"", resultValue); |
| 1089 | } |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1090 | |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1091 | public void testBug286061_quoted_string_literals() throws Exception { |
| 1092 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1093 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
dacarver | f940279 | 2009-08-22 01:14:10 +0000 | [diff] [blame] | 1094 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1095 | loadDOMDocument(fileURL); |
| 1096 | |
| 1097 | // Get XML Schema Information for the Document |
| 1098 | XSModel schema = getGrammar(); |
| 1099 | |
| 1100 | DynamicContext dc = setupDynamicContext(schema); |
| 1101 | |
| 1102 | String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )"; |
| 1103 | |
| 1104 | XPath path = compileXPath(dc, xpath); |
| 1105 | |
| 1106 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1107 | ResultSequence rs = eval.evaluate(path); |
| 1108 | |
| 1109 | String resultValue = rs.first().string_value(); |
| 1110 | |
| 1111 | assertEquals("Don't try this at \"home\", she said", resultValue); |
| 1112 | } |
| 1113 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 1114 | public void testBug280555_collations() throws Exception { |
| 1115 | // Setup context |
| 1116 | DefaultDynamicContext dc = setupDynamicContext(null); |
| 1117 | dc.set_collation_provider(createLengthCollatorProvider()); |
| 1118 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1119 | |
| 1120 | // Parse expression |
| 1121 | XPath path = compileXPath(dc, " 'abc' < 'de' "); |
| 1122 | |
| 1123 | // Evaluate once |
| 1124 | XSBoolean bval = (XSBoolean) eval.evaluate(path).first(); |
| 1125 | assertTrue("'abc' < 'def' for normal collations", bval.value()); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1126 | |
jmoller | b601eb0 | 2009-09-02 20:21:06 +0000 | [diff] [blame] | 1127 | // Evaluate again with the funny collator |
| 1128 | dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR); |
| 1129 | XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first(); |
| 1130 | assertFalse("'abc' < 'def' for normal collations", bval2.value()); |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1133 | public void testXPathDefaultNamespace() throws Exception { |
| 1134 | // Test for the fix, for xpathDefaultNamespace |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1135 | URL fileURL = bundle |
| 1136 | .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml"); |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1137 | loadDOMDocument(fileURL); |
| 1138 | |
| 1139 | // Get XML Schema Information for the Document |
| 1140 | XSModel schema = getGrammar(); |
| 1141 | |
dacarver | 23c4012 | 2009-11-13 23:26:23 +0000 | [diff] [blame] | 1142 | // set up XPath default namespace in Dynamic Context |
mgandhi | ae92c59 | 2009-09-19 12:58:06 +0000 | [diff] [blame] | 1143 | DynamicContext dc = setupDynamicContext(schema); |
| 1144 | addXPathDefaultNamespace("http://xyz"); |
| 1145 | |
| 1146 | String xpath = "X/message = 'hello'"; |
| 1147 | XPath path = compileXPath(dc, xpath); |
| 1148 | |
| 1149 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1150 | ResultSequence rs = eval.evaluate(path); |
| 1151 | |
| 1152 | XSBoolean result = (XSBoolean) rs.first(); |
| 1153 | |
| 1154 | String actual = result.string_value(); |
| 1155 | |
| 1156 | assertEquals("true", actual); |
| 1157 | } |
dacarver | 0784965 | 2009-11-28 00:09:27 +0000 | [diff] [blame] | 1158 | |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1159 | public void testXPathInstanceOf1() throws Exception { |
| 1160 | // Bug 298267 |
| 1161 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1162 | URL schemaURL = bundle |
| 1163 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1164 | |
| 1165 | loadDOMDocument(fileURL, schemaURL); |
| 1166 | |
| 1167 | // Get XSModel object for the Schema |
| 1168 | XSModel schema = getGrammar(schemaURL); |
| 1169 | |
| 1170 | DynamicContext dc = setupDynamicContext(schema); |
| 1171 | |
| 1172 | String xpath = "Example/Transportation/mode instance of element()"; |
| 1173 | XPath path = compileXPath(dc, xpath); |
| 1174 | |
| 1175 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1176 | ResultSequence rs = eval.evaluate(path); |
| 1177 | |
| 1178 | XSBoolean result = (XSBoolean) rs.first(); |
| 1179 | |
| 1180 | String actual = result.string_value(); |
| 1181 | |
| 1182 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | public void testXPathInstanceOf2() throws Exception { |
| 1186 | // Bug 298267 |
| 1187 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1188 | URL schemaURL = bundle |
| 1189 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1190 | |
| 1191 | loadDOMDocument(fileURL, schemaURL); |
| 1192 | |
| 1193 | // Get XSModel object for the Schema |
| 1194 | XSModel schema = getGrammar(schemaURL); |
| 1195 | |
| 1196 | DynamicContext dc = setupDynamicContext(schema); |
| 1197 | |
| 1198 | String xpath = "Example/Transportation/mode instance of element(mode)"; |
| 1199 | XPath path = compileXPath(dc, xpath); |
| 1200 | |
| 1201 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1202 | ResultSequence rs = eval.evaluate(path); |
| 1203 | |
| 1204 | XSBoolean result = (XSBoolean) rs.first(); |
| 1205 | |
| 1206 | String actual = result.string_value(); |
| 1207 | |
| 1208 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1211 | public void testXPathInstanceOf3() throws Exception { |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1212 | // Bug 298267 |
| 1213 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1214 | URL schemaURL = bundle |
| 1215 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1216 | |
| 1217 | loadDOMDocument(fileURL, schemaURL); |
| 1218 | |
| 1219 | // Get XSModel object for the Schema |
| 1220 | XSModel schema = getGrammar(schemaURL); |
| 1221 | |
| 1222 | DynamicContext dc = setupDynamicContext(schema); |
| 1223 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1224 | String xpath = "Example/Transportation/mode instance of element(mode, modeType)"; |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1225 | XPath path = compileXPath(dc, xpath); |
| 1226 | |
| 1227 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1228 | ResultSequence rs = eval.evaluate(path); |
| 1229 | |
| 1230 | XSBoolean result = (XSBoolean) rs.first(); |
| 1231 | |
| 1232 | String actual = result.string_value(); |
| 1233 | |
dacarver | 5a6bbea | 2009-12-27 17:14:05 +0000 | [diff] [blame] | 1234 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | public void testXPathInstanceOf4() throws Exception { |
| 1238 | // Bug 298267 |
| 1239 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1240 | URL schemaURL = bundle |
| 1241 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1242 | |
| 1243 | loadDOMDocument(fileURL, schemaURL); |
| 1244 | |
| 1245 | // Get XSModel object for the Schema |
| 1246 | XSModel schema = getGrammar(schemaURL); |
| 1247 | |
| 1248 | DynamicContext dc = setupDynamicContext(schema); |
| 1249 | |
| 1250 | String xpath = "Example/Transportation/mode instance of element(mode, abc)"; |
| 1251 | XPath path = compileXPath(dc, xpath); |
| 1252 | |
| 1253 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1254 | ResultSequence rs = eval.evaluate(path); |
| 1255 | |
| 1256 | XSBoolean result = (XSBoolean) rs.first(); |
| 1257 | |
| 1258 | String actual = result.string_value(); |
| 1259 | |
| 1260 | assertEquals("false", actual); |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1263 | public void testXPathInstanceOf5() throws Exception { |
| 1264 | // Bug 298267 |
| 1265 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1266 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1267 | |
| 1268 | loadDOMDocument(fileURL, schemaURL); |
| 1269 | |
| 1270 | // Get XSModel object for the Schema |
| 1271 | XSModel schema = getGrammar(schemaURL); |
| 1272 | |
| 1273 | DynamicContext dc = setupDynamicContext(schema); |
| 1274 | |
| 1275 | String xpath = "Example/x instance of element(x, x_Type)*"; |
| 1276 | XPath path = compileXPath(dc, xpath); |
| 1277 | |
| 1278 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1279 | ResultSequence rs = eval.evaluate(path); |
| 1280 | |
| 1281 | XSBoolean result = (XSBoolean) rs.first(); |
| 1282 | |
| 1283 | String actual = result.string_value(); |
| 1284 | |
| 1285 | assertEquals("true", actual); |
| 1286 | } |
jmoller | 2c384ed | 2010-06-24 23:48:34 +0000 | [diff] [blame] | 1287 | |
| 1288 | public void testXPathInstanceOf5_2() throws Exception { |
| 1289 | // Bug 298267 |
| 1290 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1291 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1292 | |
| 1293 | loadDOMDocument(fileURL, schemaURL); |
| 1294 | |
| 1295 | // Get XSModel object for the Schema |
| 1296 | XSModel schema = getGrammar(schemaURL); |
| 1297 | |
| 1298 | DynamicContext dc = setupDynamicContext(schema); |
| 1299 | |
| 1300 | String xpath = "(/Example/x, /Example) instance of element(x, x_Type)+"; |
| 1301 | XPath path = compileXPath(dc, xpath); |
| 1302 | |
| 1303 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1304 | ResultSequence rs = eval.evaluate(path); |
| 1305 | |
| 1306 | XSBoolean result = (XSBoolean) rs.first(); |
| 1307 | |
| 1308 | assertEquals(false, result.value()); |
| 1309 | } |
| 1310 | |
| 1311 | public void testXPathInstanceOf5_3() throws Exception { |
| 1312 | // Bug 298267 |
| 1313 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1314 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1315 | |
| 1316 | loadDOMDocument(fileURL, schemaURL); |
| 1317 | |
| 1318 | // Get XSModel object for the Schema |
| 1319 | XSModel schema = getGrammar(schemaURL); |
| 1320 | |
| 1321 | DynamicContext dc = setupDynamicContext(schema); |
| 1322 | |
| 1323 | String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)"; |
| 1324 | XPath path = compileXPath(dc, xpath); |
| 1325 | |
| 1326 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1327 | ResultSequence rs = eval.evaluate(path); |
| 1328 | |
| 1329 | XSBoolean result = (XSBoolean) rs.first(); |
| 1330 | |
| 1331 | assertFalse(result.value()); |
| 1332 | } |
| 1333 | |
| 1334 | public void testXPathInstanceOf5_4() throws Exception { |
| 1335 | // Bug 298267 |
| 1336 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1337 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1338 | |
| 1339 | loadDOMDocument(fileURL, schemaURL); |
| 1340 | |
| 1341 | // Get XSModel object for the Schema |
| 1342 | XSModel schema = getGrammar(schemaURL); |
| 1343 | |
| 1344 | DynamicContext dc = setupDynamicContext(schema); |
| 1345 | |
| 1346 | String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)+"; |
| 1347 | XPath path = compileXPath(dc, xpath); |
| 1348 | |
| 1349 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1350 | ResultSequence rs = eval.evaluate(path); |
| 1351 | |
| 1352 | XSBoolean result = (XSBoolean) rs.first(); |
| 1353 | |
| 1354 | assertTrue(result.value()); |
| 1355 | } |
| 1356 | |
| 1357 | public void testXPathInstanceOf5_5() throws Exception { |
| 1358 | // Bug 298267 |
| 1359 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1360 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1361 | |
| 1362 | loadDOMDocument(fileURL, schemaURL); |
| 1363 | |
| 1364 | // Get XSModel object for the Schema |
| 1365 | XSModel schema = getGrammar(schemaURL); |
| 1366 | |
| 1367 | DynamicContext dc = setupDynamicContext(schema); |
| 1368 | |
| 1369 | String xpath = "(/Example/x instance of x_Type+) and (/Example/x[2]/@mesg instance of mesg_Type)"; |
| 1370 | XPath path = compileXPath(dc, xpath); |
| 1371 | |
| 1372 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1373 | ResultSequence rs = eval.evaluate(path); |
| 1374 | |
| 1375 | XSBoolean result = (XSBoolean) rs.first(); |
| 1376 | |
| 1377 | assertEquals(true, result.value()); |
| 1378 | } |
| 1379 | |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1380 | public void testXPathInstanceOf6() throws Exception { |
| 1381 | // Bug 298267 |
| 1382 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1383 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1384 | |
| 1385 | loadDOMDocument(fileURL, schemaURL); |
| 1386 | |
| 1387 | // Get XSModel object for the Schema |
| 1388 | XSModel schema = getGrammar(schemaURL); |
| 1389 | |
| 1390 | DynamicContext dc = setupDynamicContext(schema); |
| 1391 | |
| 1392 | String xpath = "Example/x instance of element(*, x_Type)*"; |
| 1393 | XPath path = compileXPath(dc, xpath); |
| 1394 | |
| 1395 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1396 | ResultSequence rs = eval.evaluate(path); |
| 1397 | |
| 1398 | XSBoolean result = (XSBoolean) rs.first(); |
| 1399 | |
| 1400 | String actual = result.string_value(); |
| 1401 | |
| 1402 | assertEquals("true", actual); |
| 1403 | } |
| 1404 | |
| 1405 | public void testXPathInstanceOf7() throws Exception { |
| 1406 | // Bug 298267 |
| 1407 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1408 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1409 | |
| 1410 | loadDOMDocument(fileURL, schemaURL); |
| 1411 | |
| 1412 | // Get XSModel object for the Schema |
| 1413 | XSModel schema = getGrammar(schemaURL); |
| 1414 | |
| 1415 | DynamicContext dc = setupDynamicContext(schema); |
| 1416 | |
| 1417 | String xpath = "Example/x instance of element(x, x_Type)+"; |
| 1418 | XPath path = compileXPath(dc, xpath); |
| 1419 | |
| 1420 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1421 | ResultSequence rs = eval.evaluate(path); |
| 1422 | |
| 1423 | XSBoolean result = (XSBoolean) rs.first(); |
| 1424 | |
| 1425 | String actual = result.string_value(); |
| 1426 | |
dacarver | 3da20eb | 2009-12-29 14:29:45 +0000 | [diff] [blame] | 1427 | assertEquals("true", actual); |
mgandhi | 663fbd0 | 2009-12-27 11:23:35 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | public void testXPathInstanceNonExistantElement() throws Exception { |
| 1431 | // Bug 298267 |
| 1432 | URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml"); |
| 1433 | URL schemaURL = bundle |
| 1434 | .getEntry("/bugTestFiles/elementTypedValueBug.xsd"); |
| 1435 | |
| 1436 | loadDOMDocument(fileURL, schemaURL); |
| 1437 | |
| 1438 | // Get XSModel object for the Schema |
| 1439 | XSModel schema = getGrammar(schemaURL); |
| 1440 | |
| 1441 | DynamicContext dc = setupDynamicContext(schema); |
| 1442 | |
| 1443 | String xpath = "Example/Transportation/mode instance of element(x)"; |
| 1444 | XPath path = compileXPath(dc, xpath); |
| 1445 | |
| 1446 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1447 | ResultSequence rs = eval.evaluate(path); |
| 1448 | |
| 1449 | XSBoolean result = (XSBoolean) rs.first(); |
| 1450 | |
| 1451 | String actual = result.string_value(); |
| 1452 | |
| 1453 | assertEquals("false", actual); |
| 1454 | } |
| 1455 | |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1456 | public void testFnNumber_Evaluation1() throws Exception { |
| 1457 | // Bug 298519 |
| 1458 | URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml"); |
| 1459 | URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd"); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1460 | |
mgandhi | 247cdd8 | 2009-12-25 09:50:00 +0000 | [diff] [blame] | 1461 | loadDOMDocument(fileURL, schemaURL); |
| 1462 | |
| 1463 | // Get XSModel object for the Schema |
| 1464 | XSModel schema = getGrammar(schemaURL); |
| 1465 | |
| 1466 | DynamicContext dc = setupDynamicContext(schema); |
| 1467 | |
| 1468 | String xpath = "number(Example/x) ge 18"; |
| 1469 | XPath path = compileXPath(dc, xpath); |
| 1470 | |
| 1471 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1472 | ResultSequence rs = eval.evaluate(path); |
| 1473 | |
| 1474 | XSBoolean result = (XSBoolean) rs.first(); |
| 1475 | |
| 1476 | String actual = result.string_value(); |
| 1477 | |
| 1478 | assertEquals("true", actual); |
| 1479 | } |
| 1480 | |
| 1481 | public void testFnNumber_Evaluation2() throws Exception { |
| 1482 | // Bug 298519 |
| 1483 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1484 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1485 | loadDOMDocument(fileURL); |
| 1486 | |
| 1487 | // Get XML Schema Information for the Document |
| 1488 | XSModel schema = getGrammar(); |
| 1489 | |
| 1490 | DynamicContext dc = setupDynamicContext(schema); |
| 1491 | |
| 1492 | String xpath = "number(xs:unsignedByte('20')) ge 18"; |
| 1493 | XPath path = compileXPath(dc, xpath); |
| 1494 | |
| 1495 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1496 | ResultSequence rs = eval.evaluate(path); |
| 1497 | |
| 1498 | XSBoolean result = (XSBoolean) rs.first(); |
| 1499 | |
| 1500 | String actual = result.string_value(); |
| 1501 | |
| 1502 | assertEquals("true", actual); |
mgandhi | 80a468d | 2009-12-25 04:57:38 +0000 | [diff] [blame] | 1503 | } |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1504 | |
| 1505 | public void testAttrNode_Test1() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1506 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1507 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1508 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1509 | |
| 1510 | loadDOMDocument(fileURL, schemaURL); |
| 1511 | |
| 1512 | // Get XSModel object for the Schema |
| 1513 | XSModel schema = getGrammar(schemaURL); |
| 1514 | |
| 1515 | DynamicContext dc = setupDynamicContext(schema); |
| 1516 | |
| 1517 | String xpath = "Example/x[1]/@mesg instance of attribute()"; |
| 1518 | XPath path = compileXPath(dc, xpath); |
| 1519 | |
| 1520 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1521 | ResultSequence rs = eval.evaluate(path); |
| 1522 | |
| 1523 | XSBoolean result = (XSBoolean) rs.first(); |
| 1524 | |
| 1525 | String actual = result.string_value(); |
| 1526 | |
| 1527 | assertEquals("true", actual); |
| 1528 | } |
| 1529 | |
| 1530 | public void testAttrNode_Test2() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1531 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1532 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1533 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1534 | |
| 1535 | loadDOMDocument(fileURL, schemaURL); |
| 1536 | |
| 1537 | // Get XSModel object for the Schema |
| 1538 | XSModel schema = getGrammar(schemaURL); |
| 1539 | |
| 1540 | DynamicContext dc = setupDynamicContext(schema); |
| 1541 | |
| 1542 | String xpath = "Example/x[1]/@mesg instance of attribute(xx)"; |
| 1543 | XPath path = compileXPath(dc, xpath); |
| 1544 | |
| 1545 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1546 | ResultSequence rs = eval.evaluate(path); |
| 1547 | |
| 1548 | XSBoolean result = (XSBoolean) rs.first(); |
| 1549 | |
| 1550 | String actual = result.string_value(); |
| 1551 | |
| 1552 | assertEquals("false", actual); |
| 1553 | } |
| 1554 | |
| 1555 | public void testAttrNode_Test3() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1556 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1557 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1558 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1559 | |
| 1560 | loadDOMDocument(fileURL, schemaURL); |
| 1561 | |
| 1562 | // Get XSModel object for the Schema |
| 1563 | XSModel schema = getGrammar(schemaURL); |
| 1564 | |
| 1565 | DynamicContext dc = setupDynamicContext(schema); |
| 1566 | |
| 1567 | String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)"; |
| 1568 | XPath path = compileXPath(dc, xpath); |
| 1569 | |
| 1570 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1571 | ResultSequence rs = eval.evaluate(path); |
| 1572 | |
| 1573 | XSBoolean result = (XSBoolean) rs.first(); |
| 1574 | |
| 1575 | String actual = result.string_value(); |
| 1576 | |
| 1577 | assertEquals("true", actual); |
| 1578 | } |
| 1579 | |
| 1580 | public void testAttrNode_Test4() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1581 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1582 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1583 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1584 | |
| 1585 | loadDOMDocument(fileURL, schemaURL); |
| 1586 | |
| 1587 | // Get XSModel object for the Schema |
| 1588 | XSModel schema = getGrammar(schemaURL); |
| 1589 | |
| 1590 | DynamicContext dc = setupDynamicContext(schema); |
| 1591 | |
| 1592 | String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)"; |
| 1593 | XPath path = compileXPath(dc, xpath); |
| 1594 | |
| 1595 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1596 | ResultSequence rs = eval.evaluate(path); |
| 1597 | |
| 1598 | XSBoolean result = (XSBoolean) rs.first(); |
| 1599 | |
| 1600 | String actual = result.string_value(); |
| 1601 | |
| 1602 | assertEquals("false", actual); |
| 1603 | } |
| 1604 | |
| 1605 | public void testAttrNode_Test5() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1606 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1607 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1608 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1609 | |
| 1610 | loadDOMDocument(fileURL, schemaURL); |
| 1611 | |
| 1612 | // Get XSModel object for the Schema |
| 1613 | XSModel schema = getGrammar(schemaURL); |
| 1614 | |
| 1615 | DynamicContext dc = setupDynamicContext(schema); |
| 1616 | |
| 1617 | String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)"; |
| 1618 | XPath path = compileXPath(dc, xpath); |
| 1619 | |
| 1620 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1621 | ResultSequence rs = eval.evaluate(path); |
| 1622 | |
| 1623 | XSBoolean result = (XSBoolean) rs.first(); |
| 1624 | |
| 1625 | String actual = result.string_value(); |
| 1626 | |
| 1627 | assertEquals("true", actual); |
| 1628 | } |
| 1629 | |
| 1630 | public void testAttrNode_Test6() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1631 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1632 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1633 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1634 | |
| 1635 | loadDOMDocument(fileURL, schemaURL); |
| 1636 | |
| 1637 | // Get XSModel object for the Schema |
| 1638 | XSModel schema = getGrammar(schemaURL); |
| 1639 | |
| 1640 | DynamicContext dc = setupDynamicContext(schema); |
| 1641 | |
| 1642 | String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)"; |
| 1643 | XPath path = compileXPath(dc, xpath); |
| 1644 | |
| 1645 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1646 | ResultSequence rs = eval.evaluate(path); |
| 1647 | |
| 1648 | XSBoolean result = (XSBoolean) rs.first(); |
| 1649 | |
| 1650 | String actual = result.string_value(); |
| 1651 | |
| 1652 | assertEquals("false", actual); |
| 1653 | } |
| 1654 | |
| 1655 | public void testAttrNode_Test7() throws Exception { |
mgandhi | d52c9a3 | 2009-12-26 13:19:26 +0000 | [diff] [blame] | 1656 | // Bug 298535 |
mgandhi | e02bf58 | 2009-12-26 13:17:14 +0000 | [diff] [blame] | 1657 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1658 | URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd"); |
| 1659 | |
| 1660 | loadDOMDocument(fileURL, schemaURL); |
| 1661 | |
| 1662 | // Get XSModel object for the Schema |
| 1663 | XSModel schema = getGrammar(schemaURL); |
| 1664 | |
| 1665 | DynamicContext dc = setupDynamicContext(schema); |
| 1666 | |
| 1667 | String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*"; |
| 1668 | XPath path = compileXPath(dc, xpath); |
| 1669 | |
| 1670 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1671 | ResultSequence rs = eval.evaluate(path); |
| 1672 | |
| 1673 | XSBoolean result = (XSBoolean) rs.first(); |
| 1674 | |
| 1675 | String actual = result.string_value(); |
| 1676 | |
| 1677 | assertEquals("true", actual); |
| 1678 | } |
mgandhi | 1fc7741 | 2010-02-02 15:07:05 +0000 | [diff] [blame] | 1679 | |
| 1680 | public void testFnNameContextUndefined() throws Exception { |
| 1681 | // Bug 301539 |
| 1682 | URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml"); |
| 1683 | loadDOMDocument(fileURL); |
| 1684 | |
| 1685 | // Get XML Schema Information for the Document |
| 1686 | XSModel schema = getGrammar(); |
| 1687 | |
| 1688 | DynamicContext dc = setupDynamicContext(schema); |
| 1689 | |
| 1690 | String xpath = "Example/*[1]/name() eq 'x'"; |
| 1691 | XPath path = compileXPath(dc, xpath); |
| 1692 | |
| 1693 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1694 | ResultSequence rs = eval.evaluate(path); |
| 1695 | |
| 1696 | XSBoolean result = (XSBoolean) rs.first(); |
| 1697 | |
| 1698 | String actual = result.string_value(); |
| 1699 | |
| 1700 | assertEquals("true", actual); |
| 1701 | } |
mgandhi | 13d897f | 2010-04-18 09:46:00 +0000 | [diff] [blame] | 1702 | |
| 1703 | public void testXSNormalizedString() throws Exception { |
| 1704 | // Bug 309585 |
| 1705 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1706 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1707 | loadDOMDocument(fileURL); |
| 1708 | |
| 1709 | // Get XML Schema Information for the Document |
| 1710 | XSModel schema = getGrammar(); |
| 1711 | |
| 1712 | DynamicContext dc = setupDynamicContext(schema); |
| 1713 | |
| 1714 | String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')"; |
| 1715 | XPath path = compileXPath(dc, xpath); |
| 1716 | |
| 1717 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1718 | |
| 1719 | boolean testSuccess = false; |
| 1720 | try { |
| 1721 | ResultSequence rs = eval.evaluate(path); |
| 1722 | } |
| 1723 | catch(DynamicError ex) { |
| 1724 | // a 'DynamicError' exception indicates, that this test is a success |
| 1725 | testSuccess = true; |
| 1726 | } |
| 1727 | |
| 1728 | assertTrue(testSuccess); |
| 1729 | } |
jmoller | b028953 | 2010-06-24 23:16:07 +0000 | [diff] [blame] | 1730 | |
| 1731 | public void testParseElementKeywordsAsNodes() throws Exception { |
| 1732 | // Bug 311480 |
| 1733 | bundle = Platform.getBundle("org.w3c.xqts.testsuite"); |
| 1734 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 1735 | loadDOMDocument(fileURL); |
| 1736 | |
| 1737 | // Get XML Schema Information for the Document |
| 1738 | XSModel schema = getGrammar(); |
| 1739 | |
| 1740 | DynamicContext dc = setupDynamicContext(schema); |
| 1741 | |
| 1742 | String xpath = "/element/attribute"; |
| 1743 | XPath path = compileXPath(dc, xpath); |
| 1744 | } |
| 1745 | |
mgandhi | 247b6e7 | 2010-07-07 11:50:37 +0000 | [diff] [blame] | 1746 | public void testTypedValueEnhancement_primitiveTypes() throws Exception { |
| 1747 | // Bug 318313 |
| 1748 | URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml"); |
| 1749 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd"); |
| 1750 | |
| 1751 | loadDOMDocument(fileURL, schemaURL); |
| 1752 | |
| 1753 | // Get XSModel object for the Schema |
| 1754 | XSModel schema = getGrammar(schemaURL); |
| 1755 | |
| 1756 | DynamicContext dc = setupDynamicContext(schema); |
| 1757 | |
| 1758 | String xpath = "X gt 99"; |
| 1759 | XPath path = compileXPath(dc, xpath); |
| 1760 | |
| 1761 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1762 | ResultSequence rs = eval.evaluate(path); |
| 1763 | |
| 1764 | XSBoolean result = (XSBoolean) rs.first(); |
| 1765 | |
| 1766 | String actual = result.string_value(); |
| 1767 | |
| 1768 | assertEquals("true", actual); |
| 1769 | } |
| 1770 | |
mgandhi | ca74575 | 2010-09-27 12:42:00 +0000 | [diff] [blame^] | 1771 | public void testTypedValueEnhancement_Bug323900_1() throws Exception { |
| 1772 | // Bug 323900 |
| 1773 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_1.xml"); |
| 1774 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_1.xsd"); |
| 1775 | |
| 1776 | loadDOMDocument(fileURL, schemaURL); |
| 1777 | |
| 1778 | // Get XSModel object for the Schema |
| 1779 | XSModel schema = getGrammar(schemaURL); |
| 1780 | |
| 1781 | DynamicContext dc = setupDynamicContext(schema); |
| 1782 | |
| 1783 | String xpath = "data(X) instance of xs:integer+"; |
| 1784 | XPath path = compileXPath(dc, xpath); |
| 1785 | |
| 1786 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1787 | ResultSequence rs = eval.evaluate(path); |
| 1788 | |
| 1789 | XSBoolean result = (XSBoolean) rs.first(); |
| 1790 | |
| 1791 | String actual = result.string_value(); |
| 1792 | |
| 1793 | assertEquals("true", actual); |
| 1794 | } |
| 1795 | |
| 1796 | public void testTypedValueEnhancement_Bug323900_2() throws Exception { |
| 1797 | // Bug 323900 |
| 1798 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml"); |
| 1799 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd"); |
| 1800 | |
| 1801 | loadDOMDocument(fileURL, schemaURL); |
| 1802 | |
| 1803 | // Get XSModel object for the Schema |
| 1804 | XSModel schema = getGrammar(schemaURL); |
| 1805 | |
| 1806 | DynamicContext dc = setupDynamicContext(schema); |
| 1807 | |
| 1808 | // 1st test |
| 1809 | String xpath = "data(X) instance of xs:integer+"; |
| 1810 | XPath path = compileXPath(dc, xpath); |
| 1811 | |
| 1812 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1813 | ResultSequence rs = eval.evaluate(path); |
| 1814 | |
| 1815 | XSBoolean result = (XSBoolean) rs.first(); |
| 1816 | |
| 1817 | String actual = result.string_value(); |
| 1818 | |
| 1819 | assertEquals("false", actual); |
| 1820 | } |
| 1821 | |
| 1822 | public void testTypedValueEnhancement_Bug323900_3() throws Exception { |
| 1823 | // Bug 323900 |
| 1824 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml"); |
| 1825 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd"); |
| 1826 | |
| 1827 | loadDOMDocument(fileURL, schemaURL); |
| 1828 | |
| 1829 | // Get XSModel object for the Schema |
| 1830 | XSModel schema = getGrammar(schemaURL); |
| 1831 | |
| 1832 | DynamicContext dc = setupDynamicContext(schema); |
| 1833 | String xpath = "data(X)"; |
| 1834 | XPath path = compileXPath(dc, xpath); |
| 1835 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1836 | ResultSequence rs = eval.evaluate(path); |
| 1837 | |
| 1838 | boolean result1 = ((XSInteger) rs.get(0)).eq(new XSInteger(BigInteger. |
| 1839 | valueOf(1)), dc); |
| 1840 | boolean result2 = ((XSInteger) rs.get(1)).eq(new XSInteger(BigInteger. |
| 1841 | valueOf(2)), dc); |
| 1842 | boolean result3 = ((XSString) rs.get(2)).eq(new XSString("3.3"), dc); |
| 1843 | |
| 1844 | assertEquals(true, result1 && result2 && result3); |
| 1845 | } |
| 1846 | |
| 1847 | public void testTypedValueEnhancement_Bug323900_4() throws Exception { |
| 1848 | // Bug 323900 |
| 1849 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_3.xml"); |
| 1850 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd"); |
| 1851 | |
| 1852 | loadDOMDocument(fileURL, schemaURL); |
| 1853 | |
| 1854 | // Get XSModel object for the Schema |
| 1855 | XSModel schema = getGrammar(schemaURL); |
| 1856 | |
| 1857 | DynamicContext dc = setupDynamicContext(schema); |
| 1858 | String xpath = "data(X)"; |
| 1859 | XPath path = compileXPath(dc, xpath); |
| 1860 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1861 | ResultSequence rs = eval.evaluate(path); |
| 1862 | |
| 1863 | XSString result = (XSString) rs.get(0); |
| 1864 | assertEquals("3.3", result.string_value()); |
| 1865 | } |
| 1866 | |
| 1867 | public void testTypedValueEnhancement_Bug323900_5() throws Exception { |
| 1868 | // Bug 323900 |
| 1869 | URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_4.xml"); |
| 1870 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd"); |
| 1871 | |
| 1872 | loadDOMDocument(fileURL, schemaURL); |
| 1873 | |
| 1874 | // Get XSModel object for the Schema |
| 1875 | XSModel schema = getGrammar(schemaURL); |
| 1876 | |
| 1877 | DynamicContext dc = setupDynamicContext(schema); |
| 1878 | String xpath = "data(X)"; |
| 1879 | XPath path = compileXPath(dc, xpath); |
| 1880 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1881 | ResultSequence rs = eval.evaluate(path); |
| 1882 | |
| 1883 | XSInteger result = (XSInteger) rs.get(0); |
| 1884 | assertEquals("10", result.string_value()); |
| 1885 | } |
| 1886 | |
| 1887 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_1() |
| 1888 | throws Exception { |
| 1889 | // Bug 325262 |
| 1890 | DynamicContext dc = setupDynamicContext(null); |
| 1891 | |
| 1892 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1893 | dc.set_variable(new QName("value"), rs); |
| 1894 | |
| 1895 | String xpath = "deep-equal($value,())"; |
| 1896 | XPath path = compileXPath(dc, xpath); |
| 1897 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1898 | ResultSequence rsRes = eval.evaluate(path); |
| 1899 | |
| 1900 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1901 | assertEquals("true", result.string_value()); |
| 1902 | } |
| 1903 | |
| 1904 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_2() |
| 1905 | throws Exception { |
| 1906 | // Bug 325262 |
| 1907 | DynamicContext dc = setupDynamicContext(null); |
| 1908 | |
| 1909 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1910 | rs.add(new XSInteger(BigInteger.valueOf(2))); |
| 1911 | rs.add(new XSInteger(BigInteger.valueOf(4))); |
| 1912 | rs.add(new XSInteger(BigInteger.valueOf(6))); |
| 1913 | dc.set_variable(new QName("value"), rs); |
| 1914 | |
| 1915 | // test a |
| 1916 | String xpath = "$value instance of xs:integer+"; |
| 1917 | XPath path = compileXPath(dc, xpath); |
| 1918 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1919 | ResultSequence rsRes = eval.evaluate(path); |
| 1920 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1921 | assertEquals("true", result.string_value()); |
| 1922 | |
| 1923 | // test b |
| 1924 | xpath = "deep-equal($value, (2, 4, 6))"; |
| 1925 | path = compileXPath(dc, xpath); |
| 1926 | eval = new DefaultEvaluator(dc, domDoc); |
| 1927 | rsRes = eval.evaluate(path); |
| 1928 | result = (XSBoolean) rsRes.get(0); |
| 1929 | assertEquals("true", result.string_value()); |
| 1930 | } |
| 1931 | |
| 1932 | public void testTypedValueEnhancement_BugUsingSeqIntoVariable_3() |
| 1933 | throws Exception { |
| 1934 | // Bug 325262 |
| 1935 | DynamicContext dc = setupDynamicContext(null); |
| 1936 | |
| 1937 | ResultSequence rs = ResultSequenceFactory.create_new(); |
| 1938 | rs.add(new XSInteger(BigInteger.valueOf(2))); |
| 1939 | rs.add(new XSInteger(BigInteger.valueOf(4))); |
| 1940 | rs.add(new XSInteger(BigInteger.valueOf(6))); |
| 1941 | dc.set_variable(new QName("value"), rs); |
| 1942 | |
| 1943 | String xpath = "count(data($value)) = 3"; |
| 1944 | XPath path = compileXPath(dc, xpath); |
| 1945 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 1946 | ResultSequence rsRes = eval.evaluate(path); |
| 1947 | XSBoolean result = (XSBoolean) rsRes.get(0); |
| 1948 | assertEquals("true", result.string_value()); |
| 1949 | } |
| 1950 | |
mgandhi | 247b6e7 | 2010-07-07 11:50:37 +0000 | [diff] [blame] | 1951 | private CollationProvider createLengthCollatorProvider() { |
| 1952 | return new CollationProvider() { |
| 1953 | @SuppressWarnings("unchecked") |
| 1954 | public Comparator get_collation(String name) { |
| 1955 | if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) { |
| 1956 | return new Comparator<String>() { |
| 1957 | public int compare(String o1, String o2) { |
| 1958 | return o1.length() - o2.length(); |
| 1959 | } |
| 1960 | }; |
| 1961 | } |
| 1962 | return null; |
| 1963 | } |
| 1964 | }; |
| 1965 | } |
| 1966 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 1967 | } |