blob: f2991659c717e1836fa12612b0131690011e0596 [file] [log] [blame]
dacarver879c37a2009-04-26 23:41:32 +00001/*******************************************************************************
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
dacarver2b291392009-05-23 00:47:49 +000010 * 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
dacarvercde26452009-05-25 22:48:28 +000013 * Mukul Gandhi - bug 274725 - improvements to fn:base-uri function
14 * Mukul Gandhi - bug 274731 - improvements to fn:document-uri function
dacarver2b291392009-05-23 00:47:49 +000015 * Mukul Gandhi - bug 274784 - improvements to xs:boolean data type
dacarver41c7f742009-05-23 02:10:24 +000016 * Mukul Gandhi - bug 274805 - improvements to xs:integer data type
dacarver47328e82009-05-23 02:22:26 +000017 * Mukul Gandhi - bug 274952 - implements xs:long data type
dacarver9ebaa6f2009-05-25 03:16:50 +000018 * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type
dacarverca9bc132009-05-25 03:31:41 +000019 * Mukul Gandhi - bug 277602 - implements xs:negativeInteger data type
20 * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type
dacarverc9ccc722009-05-25 04:21:43 +000021 * Mukul Gandhi - bug 277608 implements xs:short data type
22 * bug 277609 implements xs:nonNegativeInteger data type
dacarvercde26452009-05-25 22:48:28 +000023 * bug 277629 implements xs:unsignedLong data type
dacarver2673f012009-05-25 23:08:56 +000024 * bug 277632 implements xs:positiveInteger data type
dacarver28cff4b2009-05-25 23:19:36 +000025 * bug 277639 implements xs:byte data type
dacarver3cc95782009-05-25 23:33:47 +000026 * bug 277642 implements xs:unsignedInt data type
dacarver68d6e6c2009-05-25 23:43:42 +000027 * bug 277645 implements xs:unsignedShort data type
dacarver76b66582009-06-09 14:08:05 +000028 * bug 277650 implements xs:unsignedByte data type
29 * bug 279373 improvements to multiply operation on xs:yearMonthDuration
30 * data type.
dacarver9cfaa8e2009-06-22 21:37:15 +000031 * bug 279376 improvements to xs:yearMonthDuration division operation
32 * bug 281046 implementation of xs:base64Binary data type
dacarver879c37a2009-04-26 23:41:32 +000033 *******************************************************************************/
34package org.eclipse.wst.xml.xpath2.processor.test;
35
36import java.net.URL;
37
dacarver2b291392009-05-23 00:47:49 +000038import javax.xml.parsers.DocumentBuilder;
39import javax.xml.parsers.DocumentBuilderFactory;
40
dacarver879c37a2009-04-26 23:41:32 +000041import org.apache.xerces.xs.XSModel;
42import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
43import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
44import org.eclipse.wst.xml.xpath2.processor.Evaluator;
dacarver6018fcf2009-06-22 21:47:53 +000045import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
46import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
47import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
dacarver2915e2f2009-06-09 14:41:36 +000048import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal;
dacarvered2c87e2009-06-09 14:54:33 +000049import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble;
dacarverae395262009-07-02 04:30:16 +000050import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
dacarvered2c87e2009-06-09 14:54:33 +000051import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat;
dacarver879c37a2009-04-26 23:41:32 +000052
53public class TestBugs extends AbstractPsychoPathTest {
dacarver6c9a7722009-05-24 01:16:07 +000054
dacarver879c37a2009-04-26 23:41:32 +000055 public void testStringLengthWithElementArg() throws Exception {
56 // Bug 273719
57 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
58 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +000059
dacarver879c37a2009-04-26 23:41:32 +000060 // 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);
dacarver84e43f52009-04-28 19:25:30 +000076 }
dacarver6c9a7722009-05-24 01:16:07 +000077
dacarver84e43f52009-04-28 19:25:30 +000078 public void testBug273795Arity2() throws Exception {
79 // Bug 273795
80 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
81 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +000082
dacarver84e43f52009-04-28 19:25:30 +000083 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000101
dacarver84e43f52009-04-28 19:25:30 +0000102 public void testBug273795Arity3() throws Exception {
103 // Bug 273795
104 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
105 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000106
dacarver84e43f52009-04-28 19:25:30 +0000107 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000125
dacarver2b291392009-05-23 00:47:49 +0000126 public void testStringFunctionBug274471() throws Exception {
127 // Bug 274471
128 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
129 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000130
dacarver2b291392009-05-23 00:47:49 +0000131 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000148
dacarver2b291392009-05-23 00:47:49 +0000149 public void testStringLengthFunctionBug274471() throws Exception {
150 // Bug 274471. string-length() with arity 0
151 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
152 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000153
dacarver2b291392009-05-23 00:47:49 +0000154 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000171
dacarver2b291392009-05-23 00:47:49 +0000172 public void testNormalizeSpaceFunctionBug274471() throws Exception {
173 // Bug 274471. normalize-space() with arity 0
174 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
175 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000176
dacarver2b291392009-05-23 00:47:49 +0000177 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000194
dacarver9cd5a342009-05-23 01:05:06 +0000195 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);
dacarver6c9a7722009-05-24 01:16:07 +0000200
dacarver9cd5a342009-05-23 01:05:06 +0000201 // Get XML Schema Information for the Document
202 XSModel schema = getGrammar();
203
204 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000205
dacarver9cd5a342009-05-23 01:05:06 +0000206 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
dacarverf585d0c2009-05-23 01:13:44 +0000219 public void testBaseUriBug() throws Exception {
dacarver2915e2f2009-06-09 14:41:36 +0000220 // Bug 274725
dacarver6c9a7722009-05-24 01:16:07 +0000221
dacarverf585d0c2009-05-23 01:13:44 +0000222 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
223 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
dacarver6c9a7722009-05-24 01:16:07 +0000224
225 // for testing this bug, we read the XML document from the web.
dacarverf585d0c2009-05-23 01:13:44 +0000226 // 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);
dacarver6c9a7722009-05-24 01:16:07 +0000232
dacarverf585d0c2009-05-23 01:13:44 +0000233 String xpath = "base-uri(note) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000234
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
dacarverf585d0c2009-05-23 01:13:44 +0000240 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 }
dacarverf79d73e2009-05-23 01:28:16 +0000251
252 public void testDocumentUriBug() throws Exception {
253 // Bug 274731
254 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
255 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
dacarver6c9a7722009-05-24 01:16:07 +0000256
dacarverf79d73e2009-05-23 01:28:16 +0000257 domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml");
258
259 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000260
dacarverf79d73e2009-05-23 01:28:16 +0000261 String xpath = "document-uri(/) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000262
dacarverf79d73e2009-05-23 01:28:16 +0000263 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";
dacarver6c9a7722009-05-24 01:16:07 +0000271
dacarverf79d73e2009-05-23 01:28:16 +0000272 if (result != null) {
dacarver6c9a7722009-05-24 01:16:07 +0000273 actual = result.string_value();
dacarverf79d73e2009-05-23 01:28:16 +0000274 }
275
276 assertEquals("true", actual);
277 }
dacarver6c9a7722009-05-24 01:16:07 +0000278
dacarver2b291392009-05-23 00:47:49 +0000279 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);
dacarver6c9a7722009-05-24 01:16:07 +0000284
dacarver2b291392009-05-23 00:47:49 +0000285 // Get XML Schema Information for the Document
286 XSModel schema = getGrammar();
287
288 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000289
dacarver2b291392009-05-23 00:47:49 +0000290 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 }
dacarver879c37a2009-04-26 23:41:32 +0000302
dacarver1d62b032009-05-23 01:39:15 +0000303 public void testDateConstructorBug() throws Exception {
304 // Bug 274792
305 URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml");
306 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000307
dacarver1d62b032009-05-23 01:39:15 +0000308 // Get XML Schema Information for the Document
309 XSModel schema = getGrammar();
310
311 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000312
dacarver1d62b032009-05-23 01:39:15 +0000313 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000325
dacarver41c7f742009-05-23 02:10:24 +0000326 public void testIntegerDataTypeBug() throws Exception {
327 // Bug 274805
328 URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml");
329 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000330
dacarver41c7f742009-05-23 02:10:24 +0000331 // Get XML Schema Information for the Document
332 XSModel schema = getGrammar();
333
334 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000335
dacarver41c7f742009-05-23 02:10:24 +0000336 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);
dacarver6c9a7722009-05-24 01:16:07 +0000347 }
dacarver47328e82009-05-23 02:22:26 +0000348
349 public void testLongDataType() throws Exception {
350 // Bug 274952
351 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
352 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000353
dacarver47328e82009-05-23 02:22:26 +0000354 // Get XML Schema Information for the Document
355 XSModel schema = getGrammar();
356
357 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000358
dacarver47328e82009-05-23 02:22:26 +0000359 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000373
dacarver10f28f12009-05-23 02:35:22 +0000374 public void testIntDataType() throws Exception {
375 // Bug 275105
376 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
377 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000378
dacarver10f28f12009-05-23 02:35:22 +0000379 // Get XML Schema Information for the Document
380 XSModel schema = getGrammar();
381
382 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000383
dacarver10f28f12009-05-23 02:35:22 +0000384 // 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 }
dacarver6c9a7722009-05-24 01:16:07 +0000398
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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000449
dacarver9ebaa6f2009-05-25 03:16:50 +0000450 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000474
dacarverca9bc132009-05-25 03:31:41 +0000475 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000499
dacarver72e78ba2009-05-25 03:40:46 +0000500 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000524
dacarver1bb092e2009-05-25 04:02:48 +0000525 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000549
dacarverc9ccc722009-05-25 04:21:43 +0000550 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000574
dacarvercde26452009-05-25 22:48:28 +0000575 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 }
dacarver5f7e5d12009-06-09 14:30:40 +0000599
dacarver2673f012009-05-25 23:08:56 +0000600 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);
dacarver5f7e5d12009-06-09 14:30:40 +0000623 }
624
dacarver28cff4b2009-05-25 23:19:36 +0000625 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);
dacarver2673f012009-05-25 23:08:56 +0000648 }
dacarver5f7e5d12009-06-09 14:30:40 +0000649
dacarver3cc95782009-05-25 23:33:47 +0000650 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 }
dacarvered2c87e2009-06-09 14:54:33 +0000674
675 public void testXSYearMonthDurationMultiply() throws Exception {
676 // Bug 279373
dacarver68d6e6c2009-05-25 23:43:42 +0000677 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
dacarvered2c87e2009-06-09 14:54:33 +0000685 String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3";
dacarver68d6e6c2009-05-25 23:43:42 +0000686 XPath path = compileXPath(dc, xpath);
687
688 Evaluator eval = new DefaultEvaluator(dc, domDoc);
689 ResultSequence rs = eval.evaluate(path);
690
dacarverae395262009-07-02 04:30:16 +0000691 XSDuration result = (XSDuration) rs.first();
dacarver68d6e6c2009-05-25 23:43:42 +0000692
693 String actual = result.string_value();
694
dacarvered2c87e2009-06-09 14:54:33 +0000695 assertEquals("P6Y9M", actual);
dacarver68d6e6c2009-05-25 23:43:42 +0000696 }
dacarver2915e2f2009-06-09 14:41:36 +0000697
dacarvered2c87e2009-06-09 14:54:33 +0000698 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
dacarverae395262009-07-02 04:30:16 +0000714 XSDuration result = (XSDuration) rs.first();
dacarvered2c87e2009-06-09 14:54:33 +0000715
716 String actual = result.string_value();
717
718 assertEquals("P1Y11M", actual);
719 }
dacarver2915e2f2009-06-09 14:41:36 +0000720
dacarvered2c87e2009-06-09 14:54:33 +0000721 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 }
dacarver2915e2f2009-06-09 14:41:36 +0000743
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
dacarverae395262009-07-02 04:30:16 +0000760 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000761
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
dacarverae395262009-07-02 04:30:16 +0000783 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000784
785 String actual = result.string_value();
786
787 assertEquals("PT17H40M7S", actual);
788 }
789
dacarvered2c87e2009-06-09 14:54:33 +0000790 public void testNegativeZeroDouble() throws Exception {
791 // Bug 279406
dacarver76b66582009-06-09 14:08:05 +0000792 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
dacarvered2c87e2009-06-09 14:54:33 +0000800 String xpath = "-(xs:double('0'))";
dacarver76b66582009-06-09 14:08:05 +0000801 XPath path = compileXPath(dc, xpath);
802
803 Evaluator eval = new DefaultEvaluator(dc, domDoc);
804 ResultSequence rs = eval.evaluate(path);
805
dacarvered2c87e2009-06-09 14:54:33 +0000806 XSDouble result = (XSDouble) rs.first();
dacarver76b66582009-06-09 14:08:05 +0000807
808 String actual = result.string_value();
809
dacarvered2c87e2009-06-09 14:54:33 +0000810 assertEquals("-0", actual);
dacarver76b66582009-06-09 14:08:05 +0000811 }
dacarvered2c87e2009-06-09 14:54:33 +0000812
813 public void testNegativeZeroFloat() throws Exception {
814 // Bug 279406
dacarver5f7e5d12009-06-09 14:30:40 +0000815 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
dacarvered2c87e2009-06-09 14:54:33 +0000823 String xpath = "-(xs:float('0'))";
dacarver5f7e5d12009-06-09 14:30:40 +0000824 XPath path = compileXPath(dc, xpath);
825
826 Evaluator eval = new DefaultEvaluator(dc, domDoc);
827 ResultSequence rs = eval.evaluate(path);
dacarvered2c87e2009-06-09 14:54:33 +0000828
829 XSFloat result = (XSFloat) rs.first();
830
dacarver5f7e5d12009-06-09 14:30:40 +0000831 String actual = result.string_value();
832
dacarvered2c87e2009-06-09 14:54:33 +0000833 assertEquals("-0", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000834 }
dacarvered2c87e2009-06-09 14:54:33 +0000835
dacarver5f7e5d12009-06-09 14:30:40 +0000836
dacarvered2c87e2009-06-09 14:54:33 +0000837 public void testXSUnsignedByte() throws Exception {
838 // Bug 277650
dacarver5f7e5d12009-06-09 14:30:40 +0000839 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
840 loadDOMDocument(fileURL);
841
842 // Get XML Schema Information for the Document
dacarver5f7e5d12009-06-09 14:30:40 +0000843 XSModel schema = getGrammar();
dacarver5f7e5d12009-06-09 14:30:40 +0000844
dacarvered2c87e2009-06-09 14:54:33 +0000845 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";
dacarver5f7e5d12009-06-09 14:30:40 +0000850 XPath path = compileXPath(dc, xpath);
dacarvered2c87e2009-06-09 14:54:33 +0000851
dacarver5f7e5d12009-06-09 14:30:40 +0000852 Evaluator eval = new DefaultEvaluator(dc, domDoc);
853 ResultSequence rs = eval.evaluate(path);
854
dacarvered2c87e2009-06-09 14:54:33 +0000855 XSBoolean result = (XSBoolean) rs.first();
dacarver5f7e5d12009-06-09 14:30:40 +0000856
857 String actual = result.string_value();
858
dacarvered2c87e2009-06-09 14:54:33 +0000859 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000860 }
dacarver9cfaa8e2009-06-22 21:37:15 +0000861
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 }
dacarver6018fcf2009-06-22 21:47:53 +0000884
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 }
dacarver879c37a2009-04-26 23:41:32 +0000907}