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