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