dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 Standards for Technology in Automotive Retail and others. |
| 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 | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 33 | *******************************************************************************/ |
| 34 | package org.eclipse.wst.xml.xpath2.processor.test; |
| 35 | |
| 36 | import java.net.URL; |
| 37 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 38 | import javax.xml.parsers.DocumentBuilder; |
| 39 | import javax.xml.parsers.DocumentBuilderFactory; |
| 40 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 41 | import org.apache.xerces.xs.XSModel; |
| 42 | import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; |
| 43 | import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
| 44 | import org.eclipse.wst.xml.xpath2.processor.Evaluator; |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 45 | import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
| 46 | import org.eclipse.wst.xml.xpath2.processor.ast.XPath; |
| 47 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean; |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 48 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 49 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble; |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame^] | 50 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration; |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 51 | import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat; |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 52 | |
| 53 | public class TestBugs extends AbstractPsychoPathTest { |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 54 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 55 | public void testStringLengthWithElementArg() throws Exception { |
| 56 | // Bug 273719 |
| 57 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 58 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 59 | |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 60 | // Get XML Schema Information for the Document |
| 61 | XSModel schema = getGrammar(); |
| 62 | |
| 63 | DynamicContext dc = setupDynamicContext(schema); |
| 64 | |
| 65 | String xpath = "string-length(x) > 2"; |
| 66 | XPath path = compileXPath(dc, xpath); |
| 67 | |
| 68 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 69 | ResultSequence rs = eval.evaluate(path); |
| 70 | |
| 71 | XSBoolean result = (XSBoolean) rs.first(); |
| 72 | |
| 73 | String actual = result.string_value(); |
| 74 | |
| 75 | assertEquals("true", actual); |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 76 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 77 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 78 | public void testBug273795Arity2() throws Exception { |
| 79 | // Bug 273795 |
| 80 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 81 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 82 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 83 | // Get XML Schema Information for the Document |
| 84 | XSModel schema = getGrammar(); |
| 85 | |
| 86 | DynamicContext dc = setupDynamicContext(schema); |
| 87 | |
| 88 | // test with arity 2 |
| 89 | String xpath = "substring(x, 3) = 'happy'"; |
| 90 | XPath path = compileXPath(dc, xpath); |
| 91 | |
| 92 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 93 | ResultSequence rs = eval.evaluate(path); |
| 94 | |
| 95 | XSBoolean result = (XSBoolean) rs.first(); |
| 96 | |
| 97 | String actual = result.string_value(); |
| 98 | |
| 99 | assertEquals("true", actual); |
| 100 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 101 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 102 | public void testBug273795Arity3() throws Exception { |
| 103 | // Bug 273795 |
| 104 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml"); |
| 105 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 106 | |
dacarver | 84e43f5 | 2009-04-28 19:25:30 +0000 | [diff] [blame] | 107 | // Get XML Schema Information for the Document |
| 108 | XSModel schema = getGrammar(); |
| 109 | |
| 110 | DynamicContext dc = setupDynamicContext(schema); |
| 111 | |
| 112 | // test with arity 3 |
| 113 | String xpath = "substring(x, 3, 4) = 'happ'"; |
| 114 | XPath path = compileXPath(dc, xpath); |
| 115 | |
| 116 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 117 | ResultSequence rs = eval.evaluate(path); |
| 118 | |
| 119 | XSBoolean result = (XSBoolean) rs.first(); |
| 120 | |
| 121 | String actual = result.string_value(); |
| 122 | |
| 123 | assertEquals("true", actual); |
| 124 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 125 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 126 | public void testStringFunctionBug274471() throws Exception { |
| 127 | // Bug 274471 |
| 128 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 129 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 130 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 131 | // Get XML Schema Information for the Document |
| 132 | XSModel schema = getGrammar(); |
| 133 | |
| 134 | DynamicContext dc = setupDynamicContext(schema); |
| 135 | |
| 136 | String xpath = "x/string() = 'unhappy'"; |
| 137 | XPath path = compileXPath(dc, xpath); |
| 138 | |
| 139 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 140 | ResultSequence rs = eval.evaluate(path); |
| 141 | |
| 142 | XSBoolean result = (XSBoolean) rs.first(); |
| 143 | |
| 144 | String actual = result.string_value(); |
| 145 | |
| 146 | assertEquals("true", actual); |
| 147 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 148 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 149 | public void testStringLengthFunctionBug274471() throws Exception { |
| 150 | // Bug 274471. string-length() with arity 0 |
| 151 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 152 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 153 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 154 | // Get XML Schema Information for the Document |
| 155 | XSModel schema = getGrammar(); |
| 156 | |
| 157 | DynamicContext dc = setupDynamicContext(schema); |
| 158 | |
| 159 | String xpath = "x/string-length() = 7"; |
| 160 | XPath path = compileXPath(dc, xpath); |
| 161 | |
| 162 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 163 | ResultSequence rs = eval.evaluate(path); |
| 164 | |
| 165 | XSBoolean result = (XSBoolean) rs.first(); |
| 166 | |
| 167 | String actual = result.string_value(); |
| 168 | |
| 169 | assertEquals("true", actual); |
| 170 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 171 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 172 | public void testNormalizeSpaceFunctionBug274471() throws Exception { |
| 173 | // Bug 274471. normalize-space() with arity 0 |
| 174 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 175 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 176 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 177 | // Get XML Schema Information for the Document |
| 178 | XSModel schema = getGrammar(); |
| 179 | |
| 180 | DynamicContext dc = setupDynamicContext(schema); |
| 181 | |
| 182 | String xpath = "x/normalize-space() = 'unhappy'"; |
| 183 | XPath path = compileXPath(dc, xpath); |
| 184 | |
| 185 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 186 | ResultSequence rs = eval.evaluate(path); |
| 187 | |
| 188 | XSBoolean result = (XSBoolean) rs.first(); |
| 189 | |
| 190 | String actual = result.string_value(); |
| 191 | |
| 192 | assertEquals("true", actual); |
| 193 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 194 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 195 | public void testAnyUriEqualityBug() throws Exception { |
| 196 | // Bug 274719 |
| 197 | // reusing the XML document from another bug |
| 198 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml"); |
| 199 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 200 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 201 | // Get XML Schema Information for the Document |
| 202 | XSModel schema = getGrammar(); |
| 203 | |
| 204 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 205 | |
dacarver | 9cd5a34 | 2009-05-23 01:05:06 +0000 | [diff] [blame] | 206 | String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')"; |
| 207 | XPath path = compileXPath(dc, xpath); |
| 208 | |
| 209 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 210 | ResultSequence rs = eval.evaluate(path); |
| 211 | |
| 212 | XSBoolean result = (XSBoolean) rs.first(); |
| 213 | |
| 214 | String actual = result.string_value(); |
| 215 | |
| 216 | assertEquals("true", actual); |
| 217 | } |
| 218 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 219 | public void testBaseUriBug() throws Exception { |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 220 | // Bug 274725 |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 221 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 222 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 223 | DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 224 | |
| 225 | // for testing this bug, we read the XML document from the web. |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 226 | // this ensures, that base-uri property of DOM is not null. |
| 227 | domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml"); |
| 228 | |
| 229 | // we pass XSModel as null for this test case. Otherwise, we would |
| 230 | // get an exception. |
| 231 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 232 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 233 | 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] | 234 | |
| 235 | // please note: The below XPath would also work, with base-uri using |
| 236 | // arity 0. |
| 237 | // String xpath = |
| 238 | // "note/base-uri() eq xs:anyURI('http://www.w3schools.com/xml/note.xml')"; |
| 239 | |
dacarver | f585d0c | 2009-05-23 01:13:44 +0000 | [diff] [blame] | 240 | XPath path = compileXPath(dc, xpath); |
| 241 | |
| 242 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 243 | ResultSequence rs = eval.evaluate(path); |
| 244 | |
| 245 | XSBoolean result = (XSBoolean) rs.first(); |
| 246 | |
| 247 | String actual = result.string_value(); |
| 248 | |
| 249 | assertEquals("true", actual); |
| 250 | } |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 251 | |
| 252 | public void testDocumentUriBug() throws Exception { |
| 253 | // Bug 274731 |
| 254 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 255 | DocumentBuilder docBuilder = dbf.newDocumentBuilder(); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 256 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 257 | domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml"); |
| 258 | |
| 259 | DynamicContext dc = setupDynamicContext(null); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 260 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 261 | 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] | 262 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 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 = "false"; |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 271 | |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 272 | if (result != null) { |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 273 | actual = result.string_value(); |
dacarver | f79d73e | 2009-05-23 01:28:16 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | assertEquals("true", actual); |
| 277 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 278 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 279 | public void testBooleanTypeBug() throws Exception { |
| 280 | // Bug 274784 |
| 281 | // reusing the XML document from another bug |
| 282 | URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml"); |
| 283 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 284 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 285 | // Get XML Schema Information for the Document |
| 286 | XSModel schema = getGrammar(); |
| 287 | |
| 288 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 289 | |
dacarver | 2b29139 | 2009-05-23 00:47:49 +0000 | [diff] [blame] | 290 | String xpath = "xs:boolean('1') eq xs:boolean('true')"; |
| 291 | XPath path = compileXPath(dc, xpath); |
| 292 | |
| 293 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 294 | ResultSequence rs = eval.evaluate(path); |
| 295 | |
| 296 | XSBoolean result = (XSBoolean) rs.first(); |
| 297 | |
| 298 | String actual = result.string_value(); |
| 299 | |
| 300 | assertEquals("true", actual); |
| 301 | } |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 302 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 303 | public void testDateConstructorBug() throws Exception { |
| 304 | // Bug 274792 |
| 305 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml"); |
| 306 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 307 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 308 | // Get XML Schema Information for the Document |
| 309 | XSModel schema = getGrammar(); |
| 310 | |
| 311 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 312 | |
dacarver | 1d62b03 | 2009-05-23 01:39:15 +0000 | [diff] [blame] | 313 | String xpath = "xs:date(x) eq xs:date('2009-01-01')"; |
| 314 | XPath path = compileXPath(dc, xpath); |
| 315 | |
| 316 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 317 | ResultSequence rs = eval.evaluate(path); |
| 318 | |
| 319 | XSBoolean result = (XSBoolean) rs.first(); |
| 320 | |
| 321 | String actual = result.string_value(); |
| 322 | |
| 323 | assertEquals("true", actual); |
| 324 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 325 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 326 | public void testIntegerDataTypeBug() throws Exception { |
| 327 | // Bug 274805 |
| 328 | URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml"); |
| 329 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 330 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 331 | // Get XML Schema Information for the Document |
| 332 | XSModel schema = getGrammar(); |
| 333 | |
| 334 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 335 | |
dacarver | 41c7f74 | 2009-05-23 02:10:24 +0000 | [diff] [blame] | 336 | String xpath = "xs:integer(x) gt 100"; |
| 337 | XPath path = compileXPath(dc, xpath); |
| 338 | |
| 339 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 340 | ResultSequence rs = eval.evaluate(path); |
| 341 | |
| 342 | XSBoolean result = (XSBoolean) rs.first(); |
| 343 | |
| 344 | String actual = result.string_value(); |
| 345 | |
| 346 | assertEquals("true", actual); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 347 | } |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 348 | |
| 349 | public void testLongDataType() throws Exception { |
| 350 | // Bug 274952 |
| 351 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 352 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 353 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 354 | // Get XML Schema Information for the Document |
| 355 | XSModel schema = getGrammar(); |
| 356 | |
| 357 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 358 | |
dacarver | 47328e8 | 2009-05-23 02:22:26 +0000 | [diff] [blame] | 359 | // long min value is -9223372036854775808 |
| 360 | // and max value can be 9223372036854775807 |
| 361 | String xpath = "xs:long('9223372036854775807') gt 0"; |
| 362 | XPath path = compileXPath(dc, xpath); |
| 363 | |
| 364 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 365 | ResultSequence rs = eval.evaluate(path); |
| 366 | |
| 367 | XSBoolean result = (XSBoolean) rs.first(); |
| 368 | |
| 369 | String actual = result.string_value(); |
| 370 | |
| 371 | assertEquals("true", actual); |
| 372 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 373 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 374 | public void testIntDataType() throws Exception { |
| 375 | // Bug 275105 |
| 376 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 377 | loadDOMDocument(fileURL); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 378 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 379 | // Get XML Schema Information for the Document |
| 380 | XSModel schema = getGrammar(); |
| 381 | |
| 382 | DynamicContext dc = setupDynamicContext(schema); |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 383 | |
dacarver | 10f28f1 | 2009-05-23 02:35:22 +0000 | [diff] [blame] | 384 | // int min value is -2147483648 |
| 385 | // and max value can be 2147483647 |
| 386 | String xpath = "xs:int('2147483647') gt 0"; |
| 387 | XPath path = compileXPath(dc, xpath); |
| 388 | |
| 389 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 390 | ResultSequence rs = eval.evaluate(path); |
| 391 | |
| 392 | XSBoolean result = (XSBoolean) rs.first(); |
| 393 | |
| 394 | String actual = result.string_value(); |
| 395 | |
| 396 | assertEquals("true", actual); |
| 397 | } |
dacarver | 6c9a772 | 2009-05-24 01:16:07 +0000 | [diff] [blame] | 398 | |
| 399 | public void testSchemaAwarenessForAttributes() throws Exception { |
| 400 | // Bug 276134 |
| 401 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml"); |
| 402 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd"); |
| 403 | |
| 404 | loadDOMDocument(fileURL, schemaURL); |
| 405 | |
| 406 | // Get XSModel object for the Schema |
| 407 | XSModel schema = getGrammar(schemaURL); |
| 408 | |
| 409 | DynamicContext dc = setupDynamicContext(schema); |
| 410 | |
| 411 | String xpath = "person/@dob eq xs:date('2006-12-10')"; |
| 412 | XPath path = compileXPath(dc, xpath); |
| 413 | |
| 414 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 415 | ResultSequence rs = eval.evaluate(path); |
| 416 | |
| 417 | XSBoolean result = (XSBoolean) rs.first(); |
| 418 | |
| 419 | String actual = result.string_value(); |
| 420 | |
| 421 | assertEquals("true", actual); |
| 422 | |
| 423 | } |
| 424 | |
| 425 | public void testSchemaAwarenessForElements() throws Exception { |
| 426 | // Bug 276134 |
| 427 | URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml"); |
| 428 | URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd"); |
| 429 | |
| 430 | loadDOMDocument(fileURL, schemaURL); |
| 431 | |
| 432 | // Get XSModel object for the Schema |
| 433 | XSModel schema = getGrammar(schemaURL); |
| 434 | |
| 435 | DynamicContext dc = setupDynamicContext(schema); |
| 436 | |
| 437 | String xpath = "person/dob eq xs:date('2006-12-10')"; |
| 438 | XPath path = compileXPath(dc, xpath); |
| 439 | |
| 440 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 441 | ResultSequence rs = eval.evaluate(path); |
| 442 | |
| 443 | XSBoolean result = (XSBoolean) rs.first(); |
| 444 | |
| 445 | String actual = result.string_value(); |
| 446 | |
| 447 | assertEquals("true", actual); |
| 448 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 449 | |
dacarver | 9ebaa6f | 2009-05-25 03:16:50 +0000 | [diff] [blame] | 450 | public void testXSNonPositiveInteger() throws Exception { |
| 451 | // Bug 277599 |
| 452 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 453 | loadDOMDocument(fileURL); |
| 454 | |
| 455 | // Get XML Schema Information for the Document |
| 456 | XSModel schema = getGrammar(); |
| 457 | |
| 458 | DynamicContext dc = setupDynamicContext(schema); |
| 459 | |
| 460 | // min value of xs:nonPositiveInteger is -INF |
| 461 | // max value is 0 |
| 462 | String xpath = "xs:nonPositiveInteger('0') eq 0"; |
| 463 | XPath path = compileXPath(dc, xpath); |
| 464 | |
| 465 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 466 | ResultSequence rs = eval.evaluate(path); |
| 467 | |
| 468 | XSBoolean result = (XSBoolean) rs.first(); |
| 469 | |
| 470 | String actual = result.string_value(); |
| 471 | |
| 472 | assertEquals("true", actual); |
| 473 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 474 | |
dacarver | ca9bc13 | 2009-05-25 03:31:41 +0000 | [diff] [blame] | 475 | public void testXSNegativeInteger() throws Exception { |
| 476 | // Bug 277602 |
| 477 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 478 | loadDOMDocument(fileURL); |
| 479 | |
| 480 | // Get XML Schema Information for the Document |
| 481 | XSModel schema = getGrammar(); |
| 482 | |
| 483 | DynamicContext dc = setupDynamicContext(schema); |
| 484 | |
| 485 | // min value of xs:negativeInteger is -INF |
| 486 | // max value is -1 |
| 487 | String xpath = "xs:negativeInteger('-1') eq -1"; |
| 488 | XPath path = compileXPath(dc, xpath); |
| 489 | |
| 490 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 491 | ResultSequence rs = eval.evaluate(path); |
| 492 | |
| 493 | XSBoolean result = (XSBoolean) rs.first(); |
| 494 | |
| 495 | String actual = result.string_value(); |
| 496 | |
| 497 | assertEquals("true", actual); |
| 498 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 499 | |
dacarver | 72e78ba | 2009-05-25 03:40:46 +0000 | [diff] [blame] | 500 | public void testXSShort() throws Exception { |
| 501 | // Bug 277608 |
| 502 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 503 | loadDOMDocument(fileURL); |
| 504 | |
| 505 | // Get XML Schema Information for the Document |
| 506 | XSModel schema = getGrammar(); |
| 507 | |
| 508 | DynamicContext dc = setupDynamicContext(schema); |
| 509 | |
| 510 | // min value of xs:short is -32768 |
| 511 | // max value of xs:short is 32767 |
| 512 | String xpath = "xs:short('-32768') eq -32768"; |
| 513 | XPath path = compileXPath(dc, xpath); |
| 514 | |
| 515 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 516 | ResultSequence rs = eval.evaluate(path); |
| 517 | |
| 518 | XSBoolean result = (XSBoolean) rs.first(); |
| 519 | |
| 520 | String actual = result.string_value(); |
| 521 | |
| 522 | assertEquals("true", actual); |
| 523 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 524 | |
dacarver | 1bb092e | 2009-05-25 04:02:48 +0000 | [diff] [blame] | 525 | public void testXSNonNegativeInteger() throws Exception { |
| 526 | // Bug 277609 |
| 527 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 528 | loadDOMDocument(fileURL); |
| 529 | |
| 530 | // Get XML Schema Information for the Document |
| 531 | XSModel schema = getGrammar(); |
| 532 | |
| 533 | DynamicContext dc = setupDynamicContext(schema); |
| 534 | |
| 535 | // min value of xs:nonNegativeInteger is 0 |
| 536 | // max value of xs:nonNegativeInteger is INF |
| 537 | String xpath = "xs:nonNegativeInteger('0') eq 0"; |
| 538 | XPath path = compileXPath(dc, xpath); |
| 539 | |
| 540 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 541 | ResultSequence rs = eval.evaluate(path); |
| 542 | |
| 543 | XSBoolean result = (XSBoolean) rs.first(); |
| 544 | |
| 545 | String actual = result.string_value(); |
| 546 | |
| 547 | assertEquals("true", actual); |
| 548 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 549 | |
dacarver | c9ccc72 | 2009-05-25 04:21:43 +0000 | [diff] [blame] | 550 | public void testXSUnsignedLong() throws Exception { |
| 551 | // Bug 277629 |
| 552 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 553 | loadDOMDocument(fileURL); |
| 554 | |
| 555 | // Get XML Schema Information for the Document |
| 556 | XSModel schema = getGrammar(); |
| 557 | |
| 558 | DynamicContext dc = setupDynamicContext(schema); |
| 559 | |
| 560 | // min value of xs:unsignedLong is 0 |
| 561 | // max value of xs:unsignedLong is 18446744073709551615 |
| 562 | String xpath = "xs:unsignedLong('0') eq 0"; |
| 563 | XPath path = compileXPath(dc, xpath); |
| 564 | |
| 565 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 566 | ResultSequence rs = eval.evaluate(path); |
| 567 | |
| 568 | XSBoolean result = (XSBoolean) rs.first(); |
| 569 | |
| 570 | String actual = result.string_value(); |
| 571 | |
| 572 | assertEquals("true", actual); |
| 573 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 574 | |
dacarver | cde2645 | 2009-05-25 22:48:28 +0000 | [diff] [blame] | 575 | public void testXSPositiveInteger() throws Exception { |
| 576 | // Bug 277632 |
| 577 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 578 | loadDOMDocument(fileURL); |
| 579 | |
| 580 | // Get XML Schema Information for the Document |
| 581 | XSModel schema = getGrammar(); |
| 582 | |
| 583 | DynamicContext dc = setupDynamicContext(schema); |
| 584 | |
| 585 | // min value of xs:positiveInteger is 1 |
| 586 | // max value of xs:positiveInteger is INF |
| 587 | String xpath = "xs:positiveInteger('1') eq 1"; |
| 588 | XPath path = compileXPath(dc, xpath); |
| 589 | |
| 590 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 591 | ResultSequence rs = eval.evaluate(path); |
| 592 | |
| 593 | XSBoolean result = (XSBoolean) rs.first(); |
| 594 | |
| 595 | String actual = result.string_value(); |
| 596 | |
| 597 | assertEquals("true", actual); |
| 598 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 599 | |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 600 | public void testXSByte() throws Exception { |
| 601 | // Bug 277639 |
| 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:byte is -128 |
| 611 | // max value of xs:byte is 127 |
| 612 | String xpath = "xs:byte('-128') eq -128"; |
| 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); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 623 | } |
| 624 | |
dacarver | 28cff4b | 2009-05-25 23:19:36 +0000 | [diff] [blame] | 625 | public void testXSUnsignedInt() throws Exception { |
| 626 | // Bug 277642 |
| 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:unsignedInt is 0 |
| 636 | // max value of xs:unsignedInt is 4294967295 |
| 637 | String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')"; |
| 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); |
dacarver | 2673f01 | 2009-05-25 23:08:56 +0000 | [diff] [blame] | 648 | } |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 649 | |
dacarver | 3cc9578 | 2009-05-25 23:33:47 +0000 | [diff] [blame] | 650 | public void testXSUnsignedShort() throws Exception { |
| 651 | // Bug 277645 |
| 652 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 653 | loadDOMDocument(fileURL); |
| 654 | |
| 655 | // Get XML Schema Information for the Document |
| 656 | XSModel schema = getGrammar(); |
| 657 | |
| 658 | DynamicContext dc = setupDynamicContext(schema); |
| 659 | |
| 660 | // min value of xs:unsignedShort is 0 |
| 661 | // max value of xs:unsignedShort is 65535 |
| 662 | String xpath = "xs:unsignedShort('65535') eq 65535"; |
| 663 | XPath path = compileXPath(dc, xpath); |
| 664 | |
| 665 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 666 | ResultSequence rs = eval.evaluate(path); |
| 667 | |
| 668 | XSBoolean result = (XSBoolean) rs.first(); |
| 669 | |
| 670 | String actual = result.string_value(); |
| 671 | |
| 672 | assertEquals("true", actual); |
| 673 | } |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 674 | |
| 675 | public void testXSYearMonthDurationMultiply() throws Exception { |
| 676 | // Bug 279373 |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 677 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 678 | loadDOMDocument(fileURL); |
| 679 | |
| 680 | // Get XML Schema Information for the Document |
| 681 | XSModel schema = getGrammar(); |
| 682 | |
| 683 | DynamicContext dc = setupDynamicContext(schema); |
| 684 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 685 | String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3"; |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 686 | XPath path = compileXPath(dc, xpath); |
| 687 | |
| 688 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 689 | ResultSequence rs = eval.evaluate(path); |
| 690 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame^] | 691 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 692 | |
| 693 | String actual = result.string_value(); |
| 694 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 695 | assertEquals("P6Y9M", actual); |
dacarver | 68d6e6c | 2009-05-25 23:43:42 +0000 | [diff] [blame] | 696 | } |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 697 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 698 | public void testXSYearMonthDurationDivide1() throws Exception { |
| 699 | // Bug 279376 |
| 700 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 701 | loadDOMDocument(fileURL); |
| 702 | |
| 703 | // Get XML Schema Information for the Document |
| 704 | XSModel schema = getGrammar(); |
| 705 | |
| 706 | DynamicContext dc = setupDynamicContext(schema); |
| 707 | |
| 708 | String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5"; |
| 709 | XPath path = compileXPath(dc, xpath); |
| 710 | |
| 711 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 712 | ResultSequence rs = eval.evaluate(path); |
| 713 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame^] | 714 | XSDuration result = (XSDuration) rs.first(); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 715 | |
| 716 | String actual = result.string_value(); |
| 717 | |
| 718 | assertEquals("P1Y11M", actual); |
| 719 | } |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 720 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 721 | public void testXSYearMonthDurationDivide2() throws Exception { |
| 722 | // Bug 279376 |
| 723 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 724 | loadDOMDocument(fileURL); |
| 725 | |
| 726 | // Get XML Schema Information for the Document |
| 727 | XSModel schema = getGrammar(); |
| 728 | |
| 729 | DynamicContext dc = setupDynamicContext(schema); |
| 730 | |
| 731 | String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')"; |
| 732 | XPath path = compileXPath(dc, xpath); |
| 733 | |
| 734 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 735 | ResultSequence rs = eval.evaluate(path); |
| 736 | |
| 737 | XSDecimal result = (XSDecimal) rs.first(); |
| 738 | |
| 739 | String actual = result.string_value(); |
| 740 | |
| 741 | assertEquals("-2.5", actual); |
| 742 | } |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 743 | |
| 744 | public void testXSDayTimeDurationMultiply() throws Exception { |
| 745 | // Bug 279377 |
| 746 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 747 | loadDOMDocument(fileURL); |
| 748 | |
| 749 | // Get XML Schema Information for the Document |
| 750 | XSModel schema = getGrammar(); |
| 751 | |
| 752 | DynamicContext dc = setupDynamicContext(schema); |
| 753 | |
| 754 | String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1"; |
| 755 | XPath path = compileXPath(dc, xpath); |
| 756 | |
| 757 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 758 | ResultSequence rs = eval.evaluate(path); |
| 759 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame^] | 760 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 761 | |
| 762 | String actual = result.string_value(); |
| 763 | |
| 764 | assertEquals("PT4H33M", actual); |
| 765 | } |
| 766 | |
| 767 | public void testXSDayTimeDurationDivide() throws Exception { |
| 768 | // Bug 279377 |
| 769 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 770 | loadDOMDocument(fileURL); |
| 771 | |
| 772 | // Get XML Schema Information for the Document |
| 773 | XSModel schema = getGrammar(); |
| 774 | |
| 775 | DynamicContext dc = setupDynamicContext(schema); |
| 776 | |
| 777 | String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5"; |
| 778 | XPath path = compileXPath(dc, xpath); |
| 779 | |
| 780 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 781 | ResultSequence rs = eval.evaluate(path); |
| 782 | |
dacarver | ae39526 | 2009-07-02 04:30:16 +0000 | [diff] [blame^] | 783 | XSDuration result = (XSDuration) rs.first(); |
dacarver | 2915e2f | 2009-06-09 14:41:36 +0000 | [diff] [blame] | 784 | |
| 785 | String actual = result.string_value(); |
| 786 | |
| 787 | assertEquals("PT17H40M7S", actual); |
| 788 | } |
| 789 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 790 | public void testNegativeZeroDouble() throws Exception { |
| 791 | // Bug 279406 |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 792 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 793 | loadDOMDocument(fileURL); |
| 794 | |
| 795 | // Get XML Schema Information for the Document |
| 796 | XSModel schema = getGrammar(); |
| 797 | |
| 798 | DynamicContext dc = setupDynamicContext(schema); |
| 799 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 800 | String xpath = "-(xs:double('0'))"; |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 801 | XPath path = compileXPath(dc, xpath); |
| 802 | |
| 803 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 804 | ResultSequence rs = eval.evaluate(path); |
| 805 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 806 | XSDouble result = (XSDouble) rs.first(); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 807 | |
| 808 | String actual = result.string_value(); |
| 809 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 810 | assertEquals("-0", actual); |
dacarver | 76b6658 | 2009-06-09 14:08:05 +0000 | [diff] [blame] | 811 | } |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 812 | |
| 813 | public void testNegativeZeroFloat() throws Exception { |
| 814 | // Bug 279406 |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 815 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 816 | loadDOMDocument(fileURL); |
| 817 | |
| 818 | // Get XML Schema Information for the Document |
| 819 | XSModel schema = getGrammar(); |
| 820 | |
| 821 | DynamicContext dc = setupDynamicContext(schema); |
| 822 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 823 | String xpath = "-(xs:float('0'))"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 824 | XPath path = compileXPath(dc, xpath); |
| 825 | |
| 826 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 827 | ResultSequence rs = eval.evaluate(path); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 828 | |
| 829 | XSFloat result = (XSFloat) rs.first(); |
| 830 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 831 | String actual = result.string_value(); |
| 832 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 833 | assertEquals("-0", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 834 | } |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 835 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 836 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 837 | public void testXSUnsignedByte() throws Exception { |
| 838 | // Bug 277650 |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 839 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 840 | loadDOMDocument(fileURL); |
| 841 | |
| 842 | // Get XML Schema Information for the Document |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 843 | XSModel schema = getGrammar(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 844 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 845 | DynamicContext dc = setupDynamicContext(schema); |
| 846 | |
| 847 | // min value of xs:unsignedByte is 0 |
| 848 | // max value of xs:unsignedByte is 255 |
| 849 | String xpath = "xs:unsignedByte('255') eq 255"; |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 850 | XPath path = compileXPath(dc, xpath); |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 851 | |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 852 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 853 | ResultSequence rs = eval.evaluate(path); |
| 854 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 855 | XSBoolean result = (XSBoolean) rs.first(); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 856 | |
| 857 | String actual = result.string_value(); |
| 858 | |
dacarver | ed2c87e | 2009-06-09 14:54:33 +0000 | [diff] [blame] | 859 | assertEquals("true", actual); |
dacarver | 5f7e5d1 | 2009-06-09 14:30:40 +0000 | [diff] [blame] | 860 | } |
dacarver | 9cfaa8e | 2009-06-22 21:37:15 +0000 | [diff] [blame] | 861 | |
| 862 | public void testXSBase64Binary() throws Exception { |
| 863 | // Bug 281046 |
| 864 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 865 | loadDOMDocument(fileURL); |
| 866 | |
| 867 | // Get XML Schema Information for the Document |
| 868 | XSModel schema = getGrammar(); |
| 869 | |
| 870 | DynamicContext dc = setupDynamicContext(schema); |
| 871 | |
| 872 | String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')"; |
| 873 | XPath path = compileXPath(dc, xpath); |
| 874 | |
| 875 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 876 | ResultSequence rs = eval.evaluate(path); |
| 877 | |
| 878 | XSBoolean result = (XSBoolean) rs.first(); |
| 879 | |
| 880 | String actual = result.string_value(); |
| 881 | |
| 882 | assertEquals("true", actual); |
| 883 | } |
dacarver | 6018fcf | 2009-06-22 21:47:53 +0000 | [diff] [blame] | 884 | |
| 885 | public void testXSHexBinary() throws Exception { |
| 886 | // Bug 281054 |
| 887 | URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml"); |
| 888 | loadDOMDocument(fileURL); |
| 889 | |
| 890 | // Get XML Schema Information for the Document |
| 891 | XSModel schema = getGrammar(); |
| 892 | |
| 893 | DynamicContext dc = setupDynamicContext(schema); |
| 894 | |
| 895 | String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')"; |
| 896 | XPath path = compileXPath(dc, xpath); |
| 897 | |
| 898 | Evaluator eval = new DefaultEvaluator(dc, domDoc); |
| 899 | ResultSequence rs = eval.evaluate(path); |
| 900 | |
| 901 | XSBoolean result = (XSBoolean) rs.first(); |
| 902 | |
| 903 | String actual = result.string_value(); |
| 904 | |
| 905 | assertEquals("true", actual); |
| 906 | } |
dacarver | 879c37a | 2009-04-26 23:41:32 +0000 | [diff] [blame] | 907 | } |