blob: 4fe2d00895ecf08d97aa366a49d636d2847d4a70 [file] [log] [blame]
dacarver879c37a2009-04-26 23:41:32 +00001/*******************************************************************************
jmollerb0289532010-06-24 23:16:07 +00002 * Copyright (c) 2009-2010 Standards for Technology in Automotive Retail and others.
dacarver879c37a2009-04-26 23:41:32 +00003 * 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
dacarverf9402792009-08-22 01:14:10 +000033 * Jesper S Moller - bug 286061 correct handling of quoted string
jmollerb601eb02009-09-02 20:21:06 +000034 * Jesper S Moller - bug 280555 - Add pluggable collation support
jmolleraaedb5f2009-12-16 14:18:49 +000035 * Jesper S Moller - bug 297958 Fix fn:nilled for elements
mgandhi247cdd82009-12-25 09:50:00 +000036 * Mukul Gandhi - bug 298519 improvements to fn:number implementation, catering
37 * to node arguments.
mgandhi1fc77412010-02-02 15:07:05 +000038 * Mukul Gandhi - bug 301539 fix for "context undefined" bug in case of zero
mgandhi13d897f2010-04-18 09:46:00 +000039 * arity of fn:name function.
40 * Mukul Gandhi - bug 309585 implementation of xs:normalizedString data type
jmollerb0289532010-06-24 23:16:07 +000041 * Jesper S Moller - bug 311480 - fix problem with name matching on keywords
jmoller2c384ed2010-06-24 23:48:34 +000042 * Jesper S Moller - bug 312191 - instance of test fails with partial matches
mgandhi247b6e72010-07-07 11:50:37 +000043 * Mukul Gandhi - bug 318313 - improvements to computation of typed values of nodes,
44 * when validated by XML Schema primitive types
mgandhica745752010-09-27 12:42:00 +000045 * Mukul Gandhi - bug 323900 - improving computing the typed value of element &
46 * attribute nodes, where the schema type of nodes
47 * are simple, with varieties 'list' and 'union'.
48 * Mukul Gandhi - bug 325262 - providing ability to store an XPath2 sequence into
49 * an user-defined variable.
dacarver879c37a2009-04-26 23:41:32 +000050 *******************************************************************************/
51package org.eclipse.wst.xml.xpath2.processor.test;
52
mgandhica745752010-09-27 12:42:00 +000053import java.math.BigInteger;
dacarver879c37a2009-04-26 23:41:32 +000054import java.net.URL;
jmollerb601eb02009-09-02 20:21:06 +000055import java.util.Comparator;
dacarver879c37a2009-04-26 23:41:32 +000056
dacarver2b291392009-05-23 00:47:49 +000057import javax.xml.parsers.DocumentBuilder;
58import javax.xml.parsers.DocumentBuilderFactory;
59
dacarver879c37a2009-04-26 23:41:32 +000060import org.apache.xerces.xs.XSModel;
dacarver7d5e2922009-11-08 15:40:36 +000061import org.eclipse.core.runtime.Platform;
jmollerb601eb02009-09-02 20:21:06 +000062import org.eclipse.wst.xml.xpath2.processor.CollationProvider;
63import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
dacarver879c37a2009-04-26 23:41:32 +000064import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
65import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
mgandhi13d897f2010-04-18 09:46:00 +000066import org.eclipse.wst.xml.xpath2.processor.DynamicError;
dacarver879c37a2009-04-26 23:41:32 +000067import org.eclipse.wst.xml.xpath2.processor.Evaluator;
dacarver6018fcf2009-06-22 21:47:53 +000068import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
mgandhica745752010-09-27 12:42:00 +000069import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
dacarver6018fcf2009-06-22 21:47:53 +000070import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
mgandhica745752010-09-27 12:42:00 +000071import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
dacarver6018fcf2009-06-22 21:47:53 +000072import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
dacarver2915e2f2009-06-09 14:41:36 +000073import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal;
dacarvered2c87e2009-06-09 14:54:33 +000074import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble;
dacarverae395262009-07-02 04:30:16 +000075import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
dacarvered2c87e2009-06-09 14:54:33 +000076import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat;
mgandhica745752010-09-27 12:42:00 +000077import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger;
78import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
dacarver7d5e2922009-11-08 15:40:36 +000079import org.osgi.framework.Bundle;
jmolleref1b2b42010-08-12 10:33:28 +000080import org.xml.sax.InputSource;
dacarver879c37a2009-04-26 23:41:32 +000081
82public class TestBugs extends AbstractPsychoPathTest {
dacarver23c40122009-11-13 23:26:23 +000083
jmollerb601eb02009-09-02 20:21:06 +000084 private static final String URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR = "urn:x-eclipse:xpath20:funky-collator";
dacarver23c40122009-11-13 23:26:23 +000085
86 private Bundle bundle;
87
dacarver7d5e2922009-11-08 15:40:36 +000088 @Override
89 protected void setUp() throws Exception {
90 // TODO Auto-generated method stub
91 super.setUp();
92 bundle = Platform
dacarver23c40122009-11-13 23:26:23 +000093 .getBundle("org.eclipse.wst.xml.xpath2.processor.tests");
dacarver7d5e2922009-11-08 15:40:36 +000094
95 }
jmollerb601eb02009-09-02 20:21:06 +000096
jmollerb0289532010-06-24 23:16:07 +000097 public void testNamesWhichAreKeywords() throws Exception {
98 // Bug 273719
99 URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml");
100 loadDOMDocument(fileURL);
101
102 // Get XML Schema Information for the Document
103 XSModel schema = getGrammar();
104
105 DynamicContext dc = setupDynamicContext(schema);
106
107// String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)";
108 String xpath = "(/element/eq eq 'eq') or //child::xs:*";
109 XPath path = compileXPath(dc, xpath);
110
111 Evaluator eval = new DefaultEvaluator(dc, domDoc);
112 ResultSequence rs = eval.evaluate(path);
113
114 XSBoolean result = (XSBoolean) rs.first();
115
116 String actual = result.string_value();
117
118 assertEquals("true", actual);
119 }
120
dacarver879c37a2009-04-26 23:41:32 +0000121 public void testStringLengthWithElementArg() throws Exception {
122 // Bug 273719
123 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
124 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000125
dacarver879c37a2009-04-26 23:41:32 +0000126 // Get XML Schema Information for the Document
127 XSModel schema = getGrammar();
128
129 DynamicContext dc = setupDynamicContext(schema);
130
131 String xpath = "string-length(x) > 2";
132 XPath path = compileXPath(dc, xpath);
133
134 Evaluator eval = new DefaultEvaluator(dc, domDoc);
135 ResultSequence rs = eval.evaluate(path);
136
137 XSBoolean result = (XSBoolean) rs.first();
138
139 String actual = result.string_value();
140
141 assertEquals("true", actual);
dacarver84e43f52009-04-28 19:25:30 +0000142 }
dacarver6c9a7722009-05-24 01:16:07 +0000143
dacarver84e43f52009-04-28 19:25:30 +0000144 public void testBug273795Arity2() throws Exception {
145 // Bug 273795
146 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
147 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000148
dacarver84e43f52009-04-28 19:25:30 +0000149 // Get XML Schema Information for the Document
150 XSModel schema = getGrammar();
151
152 DynamicContext dc = setupDynamicContext(schema);
153
154 // test with arity 2
155 String xpath = "substring(x, 3) = 'happy'";
156 XPath path = compileXPath(dc, xpath);
157
158 Evaluator eval = new DefaultEvaluator(dc, domDoc);
159 ResultSequence rs = eval.evaluate(path);
160
161 XSBoolean result = (XSBoolean) rs.first();
162
163 String actual = result.string_value();
164
165 assertEquals("true", actual);
166 }
dacarver6c9a7722009-05-24 01:16:07 +0000167
dacarver84e43f52009-04-28 19:25:30 +0000168 public void testBug273795Arity3() throws Exception {
169 // Bug 273795
170 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
171 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000172
dacarver84e43f52009-04-28 19:25:30 +0000173 // Get XML Schema Information for the Document
174 XSModel schema = getGrammar();
175
176 DynamicContext dc = setupDynamicContext(schema);
177
178 // test with arity 3
179 String xpath = "substring(x, 3, 4) = 'happ'";
180 XPath path = compileXPath(dc, xpath);
181
182 Evaluator eval = new DefaultEvaluator(dc, domDoc);
183 ResultSequence rs = eval.evaluate(path);
184
185 XSBoolean result = (XSBoolean) rs.first();
186
187 String actual = result.string_value();
188
189 assertEquals("true", actual);
190 }
dacarver6c9a7722009-05-24 01:16:07 +0000191
dacarver2b291392009-05-23 00:47:49 +0000192 public void testStringFunctionBug274471() throws Exception {
193 // Bug 274471
194 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
195 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000196
dacarver2b291392009-05-23 00:47:49 +0000197 // Get XML Schema Information for the Document
198 XSModel schema = getGrammar();
199
200 DynamicContext dc = setupDynamicContext(schema);
201
202 String xpath = "x/string() = 'unhappy'";
203 XPath path = compileXPath(dc, xpath);
204
205 Evaluator eval = new DefaultEvaluator(dc, domDoc);
206 ResultSequence rs = eval.evaluate(path);
207
208 XSBoolean result = (XSBoolean) rs.first();
209
210 String actual = result.string_value();
211
212 assertEquals("true", actual);
213 }
dacarver6c9a7722009-05-24 01:16:07 +0000214
dacarver2b291392009-05-23 00:47:49 +0000215 public void testStringLengthFunctionBug274471() throws Exception {
216 // Bug 274471. string-length() with arity 0
217 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
218 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000219
dacarver2b291392009-05-23 00:47:49 +0000220 // Get XML Schema Information for the Document
221 XSModel schema = getGrammar();
222
223 DynamicContext dc = setupDynamicContext(schema);
224
225 String xpath = "x/string-length() = 7";
226 XPath path = compileXPath(dc, xpath);
227
228 Evaluator eval = new DefaultEvaluator(dc, domDoc);
229 ResultSequence rs = eval.evaluate(path);
230
231 XSBoolean result = (XSBoolean) rs.first();
232
233 String actual = result.string_value();
234
dacarver9bffb272009-09-03 01:28:58 +0000235 assertEquals("false", actual);
dacarver2b291392009-05-23 00:47:49 +0000236 }
dacarver6c9a7722009-05-24 01:16:07 +0000237
dacarver2b291392009-05-23 00:47:49 +0000238 public void testNormalizeSpaceFunctionBug274471() throws Exception {
239 // Bug 274471. normalize-space() with arity 0
240 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
241 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000242
dacarver2b291392009-05-23 00:47:49 +0000243 // Get XML Schema Information for the Document
244 XSModel schema = getGrammar();
245
246 DynamicContext dc = setupDynamicContext(schema);
247
248 String xpath = "x/normalize-space() = 'unhappy'";
249 XPath path = compileXPath(dc, xpath);
250
251 Evaluator eval = new DefaultEvaluator(dc, domDoc);
252 ResultSequence rs = eval.evaluate(path);
253
254 XSBoolean result = (XSBoolean) rs.first();
255
256 String actual = result.string_value();
257
258 assertEquals("true", actual);
259 }
dacarver6c9a7722009-05-24 01:16:07 +0000260
dacarver9cd5a342009-05-23 01:05:06 +0000261 public void testAnyUriEqualityBug() throws Exception {
262 // Bug 274719
263 // reusing the XML document from another bug
264 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
265 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000266
dacarver9cd5a342009-05-23 01:05:06 +0000267 // Get XML Schema Information for the Document
268 XSModel schema = getGrammar();
269
270 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000271
dacarver9cd5a342009-05-23 01:05:06 +0000272 String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')";
273 XPath path = compileXPath(dc, xpath);
274
275 Evaluator eval = new DefaultEvaluator(dc, domDoc);
276 ResultSequence rs = eval.evaluate(path);
277
278 XSBoolean result = (XSBoolean) rs.first();
279
280 String actual = result.string_value();
281
282 assertEquals("true", actual);
283 }
284
dacarverf585d0c2009-05-23 01:13:44 +0000285 public void testBaseUriBug() throws Exception {
dacarver2915e2f2009-06-09 14:41:36 +0000286 // Bug 274725
dacarver6c9a7722009-05-24 01:16:07 +0000287
dacarver23c40122009-11-13 23:26:23 +0000288 // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
289 // DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000290 loadDOMDocument(new URL("http://resolved-locally/xml/note.xml"));
dacarver6c9a7722009-05-24 01:16:07 +0000291
292 // for testing this bug, we read the XML document from the web.
dacarverf585d0c2009-05-23 01:13:44 +0000293 // this ensures, that base-uri property of DOM is not null.
jmolleref1b2b42010-08-12 10:33:28 +0000294 // domDoc = docBuilder.parse("http://resolved-locally/xml/note.xml");
dacarverf585d0c2009-05-23 01:13:44 +0000295
296 // we pass XSModel as null for this test case. Otherwise, we would
297 // get an exception.
298 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000299
jmolleref1b2b42010-08-12 10:33:28 +0000300 String xpath = "base-uri(note) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000301
302 // please note: The below XPath would also work, with base-uri using
303 // arity 0.
304 // String xpath =
jmolleref1b2b42010-08-12 10:33:28 +0000305 // "note/base-uri() eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000306
dacarverf585d0c2009-05-23 01:13:44 +0000307 XPath path = compileXPath(dc, xpath);
308
309 Evaluator eval = new DefaultEvaluator(dc, domDoc);
310 ResultSequence rs = eval.evaluate(path);
311
312 XSBoolean result = (XSBoolean) rs.first();
313
314 String actual = result.string_value();
315
dacarveracf5e122009-08-05 02:48:43 +0000316 assertEquals("true", actual);
dacarverf585d0c2009-05-23 01:13:44 +0000317 }
dacarverf79d73e2009-05-23 01:28:16 +0000318
319 public void testDocumentUriBug() throws Exception {
320 // Bug 274731
321 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
322 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000323
324 InputSource inputSource = getTestSource("http://resolved-locally/xml/note.xml");
325 domDoc = docBuilder.parse(inputSource);
dacarverf79d73e2009-05-23 01:28:16 +0000326
327 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000328
jmolleref1b2b42010-08-12 10:33:28 +0000329 String xpath = "document-uri(/) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000330
dacarverf79d73e2009-05-23 01:28:16 +0000331 XPath path = compileXPath(dc, xpath);
332
333 Evaluator eval = new DefaultEvaluator(dc, domDoc);
334 ResultSequence rs = eval.evaluate(path);
335
336 XSBoolean result = (XSBoolean) rs.first();
337
338 String actual = "false";
dacarver6c9a7722009-05-24 01:16:07 +0000339
dacarverf79d73e2009-05-23 01:28:16 +0000340 if (result != null) {
dacarver6c9a7722009-05-24 01:16:07 +0000341 actual = result.string_value();
dacarverf79d73e2009-05-23 01:28:16 +0000342 }
343
344 assertEquals("true", actual);
345 }
dacarver6c9a7722009-05-24 01:16:07 +0000346
dacarver2b291392009-05-23 00:47:49 +0000347 public void testBooleanTypeBug() throws Exception {
348 // Bug 274784
349 // reusing the XML document from another bug
350 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
351 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000352
dacarver2b291392009-05-23 00:47:49 +0000353 // Get XML Schema Information for the Document
354 XSModel schema = getGrammar();
355
356 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000357
dacarver2b291392009-05-23 00:47:49 +0000358 String xpath = "xs:boolean('1') eq xs:boolean('true')";
359 XPath path = compileXPath(dc, xpath);
360
361 Evaluator eval = new DefaultEvaluator(dc, domDoc);
362 ResultSequence rs = eval.evaluate(path);
363
364 XSBoolean result = (XSBoolean) rs.first();
365
366 String actual = result.string_value();
367
368 assertEquals("true", actual);
369 }
dacarver879c37a2009-04-26 23:41:32 +0000370
dacarver1d62b032009-05-23 01:39:15 +0000371 public void testDateConstructorBug() throws Exception {
372 // Bug 274792
373 URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml");
374 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000375
dacarver1d62b032009-05-23 01:39:15 +0000376 // Get XML Schema Information for the Document
377 XSModel schema = getGrammar();
378
379 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000380
dacarver1d62b032009-05-23 01:39:15 +0000381 String xpath = "xs:date(x) eq xs:date('2009-01-01')";
382 XPath path = compileXPath(dc, xpath);
383
384 Evaluator eval = new DefaultEvaluator(dc, domDoc);
385 ResultSequence rs = eval.evaluate(path);
386
387 XSBoolean result = (XSBoolean) rs.first();
388
389 String actual = result.string_value();
390
391 assertEquals("true", actual);
392 }
dacarver6c9a7722009-05-24 01:16:07 +0000393
dacarver41c7f742009-05-23 02:10:24 +0000394 public void testIntegerDataTypeBug() throws Exception {
395 // Bug 274805
396 URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml");
397 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000398
dacarver41c7f742009-05-23 02:10:24 +0000399 // Get XML Schema Information for the Document
400 XSModel schema = getGrammar();
401
402 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000403
dacarver41c7f742009-05-23 02:10:24 +0000404 String xpath = "xs:integer(x) gt 100";
405 XPath path = compileXPath(dc, xpath);
406
407 Evaluator eval = new DefaultEvaluator(dc, domDoc);
408 ResultSequence rs = eval.evaluate(path);
409
410 XSBoolean result = (XSBoolean) rs.first();
411
412 String actual = result.string_value();
413
414 assertEquals("true", actual);
dacarver6c9a7722009-05-24 01:16:07 +0000415 }
dacarver47328e82009-05-23 02:22:26 +0000416
417 public void testLongDataType() throws Exception {
418 // Bug 274952
dacarver23c40122009-11-13 23:26:23 +0000419 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver47328e82009-05-23 02:22:26 +0000420 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
421 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000422
dacarver47328e82009-05-23 02:22:26 +0000423 // Get XML Schema Information for the Document
424 XSModel schema = getGrammar();
425
426 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000427
dacarver47328e82009-05-23 02:22:26 +0000428 // long min value is -9223372036854775808
429 // and max value can be 9223372036854775807
430 String xpath = "xs:long('9223372036854775807') gt 0";
431 XPath path = compileXPath(dc, xpath);
432
433 Evaluator eval = new DefaultEvaluator(dc, domDoc);
434 ResultSequence rs = eval.evaluate(path);
435
436 XSBoolean result = (XSBoolean) rs.first();
437
438 String actual = result.string_value();
439
440 assertEquals("true", actual);
441 }
dacarver6c9a7722009-05-24 01:16:07 +0000442
dacarver10f28f12009-05-23 02:35:22 +0000443 public void testIntDataType() throws Exception {
444 // Bug 275105
dacarver23c40122009-11-13 23:26:23 +0000445 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver10f28f12009-05-23 02:35:22 +0000446 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
447 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000448
dacarver10f28f12009-05-23 02:35:22 +0000449 // Get XML Schema Information for the Document
450 XSModel schema = getGrammar();
451
452 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000453
dacarver10f28f12009-05-23 02:35:22 +0000454 // int min value is -2147483648
455 // and max value can be 2147483647
456 String xpath = "xs:int('2147483647') gt 0";
457 XPath path = compileXPath(dc, xpath);
458
459 Evaluator eval = new DefaultEvaluator(dc, domDoc);
460 ResultSequence rs = eval.evaluate(path);
461
462 XSBoolean result = (XSBoolean) rs.first();
463
464 String actual = result.string_value();
465
466 assertEquals("true", actual);
467 }
dacarver6c9a7722009-05-24 01:16:07 +0000468
469 public void testSchemaAwarenessForAttributes() throws Exception {
470 // Bug 276134
471 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
472 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
473
474 loadDOMDocument(fileURL, schemaURL);
475
476 // Get XSModel object for the Schema
477 XSModel schema = getGrammar(schemaURL);
478
479 DynamicContext dc = setupDynamicContext(schema);
480
481 String xpath = "person/@dob eq xs:date('2006-12-10')";
482 XPath path = compileXPath(dc, xpath);
483
484 Evaluator eval = new DefaultEvaluator(dc, domDoc);
485 ResultSequence rs = eval.evaluate(path);
486
487 XSBoolean result = (XSBoolean) rs.first();
488
489 String actual = result.string_value();
490
491 assertEquals("true", actual);
492
493 }
494
495 public void testSchemaAwarenessForElements() throws Exception {
496 // Bug 276134
497 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml");
498 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd");
499
500 loadDOMDocument(fileURL, schemaURL);
501
502 // Get XSModel object for the Schema
503 XSModel schema = getGrammar(schemaURL);
504
505 DynamicContext dc = setupDynamicContext(schema);
506
507 String xpath = "person/dob eq xs:date('2006-12-10')";
508 XPath path = compileXPath(dc, xpath);
509
510 Evaluator eval = new DefaultEvaluator(dc, domDoc);
511 ResultSequence rs = eval.evaluate(path);
512
513 XSBoolean result = (XSBoolean) rs.first();
514
515 String actual = result.string_value();
516
517 assertEquals("true", actual);
518 }
dacarver5f7e5d12009-06-09 14:30:40 +0000519
jmolleraaedb5f2009-12-16 14:18:49 +0000520 public void testNilled() throws Exception {
521 // This is a terrible shortcoming in the test suite, I'd say
522 URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml");
523 URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd");
524
525 loadDOMDocument(fileURL, schemaURL);
526
527 // Get XSModel object for the Schema
528 XSModel schema = getGrammar(schemaURL);
529
530 DynamicContext dc = setupDynamicContext(schema);
531
532 assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )"));
533 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )"));
534 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )"));
535
536 assertFalse(evaluateBoolean(dc, "nilled(/root/element1)"));
537 assertTrue(evaluateBoolean(dc, "nilled(/root/element2)"));
538 assertFalse(evaluateBoolean(dc, "nilled(/root/element3)"));
539 assertFalse(evaluateBoolean(dc, "nilled(/root/element4)"));
540 }
541
542 // I can't stand to see so much duplicated code!!!
543 private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception {
544 XPath path = compileXPath(dc, xpath);
545
546 Evaluator eval = new DefaultEvaluator(dc, domDoc);
547 ResultSequence rs = eval.evaluate(path);
548
549 XSBoolean result = (XSBoolean) rs.first();
550
551 return result.value();
552 }
553
dacarver9ebaa6f2009-05-25 03:16:50 +0000554 public void testXSNonPositiveInteger() throws Exception {
555 // Bug 277599
dacarver23c40122009-11-13 23:26:23 +0000556 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
557
dacarver9ebaa6f2009-05-25 03:16:50 +0000558 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
559 loadDOMDocument(fileURL);
560
561 // Get XML Schema Information for the Document
562 XSModel schema = getGrammar();
563
564 DynamicContext dc = setupDynamicContext(schema);
565
566 // min value of xs:nonPositiveInteger is -INF
567 // max value is 0
568 String xpath = "xs:nonPositiveInteger('0') eq 0";
569 XPath path = compileXPath(dc, xpath);
570
571 Evaluator eval = new DefaultEvaluator(dc, domDoc);
572 ResultSequence rs = eval.evaluate(path);
573
574 XSBoolean result = (XSBoolean) rs.first();
575
576 String actual = result.string_value();
577
578 assertEquals("true", actual);
579 }
dacarver5f7e5d12009-06-09 14:30:40 +0000580
dacarverca9bc132009-05-25 03:31:41 +0000581 public void testXSNegativeInteger() throws Exception {
582 // Bug 277602
dacarver23c40122009-11-13 23:26:23 +0000583 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
584
dacarverca9bc132009-05-25 03:31:41 +0000585 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
586 loadDOMDocument(fileURL);
587
588 // Get XML Schema Information for the Document
589 XSModel schema = getGrammar();
590
591 DynamicContext dc = setupDynamicContext(schema);
592
593 // min value of xs:negativeInteger is -INF
594 // max value is -1
595 String xpath = "xs:negativeInteger('-1') eq -1";
596 XPath path = compileXPath(dc, xpath);
597
598 Evaluator eval = new DefaultEvaluator(dc, domDoc);
599 ResultSequence rs = eval.evaluate(path);
600
601 XSBoolean result = (XSBoolean) rs.first();
602
603 String actual = result.string_value();
604
605 assertEquals("true", actual);
606 }
dacarver5f7e5d12009-06-09 14:30:40 +0000607
dacarver72e78ba2009-05-25 03:40:46 +0000608 public void testXSShort() throws Exception {
609 // Bug 277608
dacarver23c40122009-11-13 23:26:23 +0000610 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000611
dacarver72e78ba2009-05-25 03:40:46 +0000612 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
613 loadDOMDocument(fileURL);
614
615 // Get XML Schema Information for the Document
616 XSModel schema = getGrammar();
617
618 DynamicContext dc = setupDynamicContext(schema);
619
620 // min value of xs:short is -32768
621 // max value of xs:short is 32767
622 String xpath = "xs:short('-32768') eq -32768";
623 XPath path = compileXPath(dc, xpath);
624
625 Evaluator eval = new DefaultEvaluator(dc, domDoc);
626 ResultSequence rs = eval.evaluate(path);
627
628 XSBoolean result = (XSBoolean) rs.first();
629
630 String actual = result.string_value();
631
632 assertEquals("true", actual);
633 }
dacarver5f7e5d12009-06-09 14:30:40 +0000634
dacarver1bb092e2009-05-25 04:02:48 +0000635 public void testXSNonNegativeInteger() throws Exception {
636 // Bug 277609
dacarver23c40122009-11-13 23:26:23 +0000637 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000638
dacarver1bb092e2009-05-25 04:02:48 +0000639 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
640 loadDOMDocument(fileURL);
641
642 // Get XML Schema Information for the Document
643 XSModel schema = getGrammar();
644
645 DynamicContext dc = setupDynamicContext(schema);
646
647 // min value of xs:nonNegativeInteger is 0
648 // max value of xs:nonNegativeInteger is INF
649 String xpath = "xs:nonNegativeInteger('0') eq 0";
650 XPath path = compileXPath(dc, xpath);
651
652 Evaluator eval = new DefaultEvaluator(dc, domDoc);
653 ResultSequence rs = eval.evaluate(path);
654
655 XSBoolean result = (XSBoolean) rs.first();
656
657 String actual = result.string_value();
658
659 assertEquals("true", actual);
660 }
dacarver5f7e5d12009-06-09 14:30:40 +0000661
dacarverc9ccc722009-05-25 04:21:43 +0000662 public void testXSUnsignedLong() throws Exception {
663 // Bug 277629
dacarver23c40122009-11-13 23:26:23 +0000664 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000665
dacarverc9ccc722009-05-25 04:21:43 +0000666 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
667 loadDOMDocument(fileURL);
668
669 // Get XML Schema Information for the Document
670 XSModel schema = getGrammar();
671
672 DynamicContext dc = setupDynamicContext(schema);
673
674 // min value of xs:unsignedLong is 0
675 // max value of xs:unsignedLong is 18446744073709551615
676 String xpath = "xs:unsignedLong('0') eq 0";
677 XPath path = compileXPath(dc, xpath);
678
679 Evaluator eval = new DefaultEvaluator(dc, domDoc);
680 ResultSequence rs = eval.evaluate(path);
681
682 XSBoolean result = (XSBoolean) rs.first();
683
684 String actual = result.string_value();
685
686 assertEquals("true", actual);
687 }
dacarver5f7e5d12009-06-09 14:30:40 +0000688
dacarvercde26452009-05-25 22:48:28 +0000689 public void testXSPositiveInteger() throws Exception {
690 // Bug 277632
dacarver23c40122009-11-13 23:26:23 +0000691 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000692
dacarvercde26452009-05-25 22:48:28 +0000693 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
694 loadDOMDocument(fileURL);
695
696 // Get XML Schema Information for the Document
697 XSModel schema = getGrammar();
698
699 DynamicContext dc = setupDynamicContext(schema);
700
701 // min value of xs:positiveInteger is 1
702 // max value of xs:positiveInteger is INF
703 String xpath = "xs:positiveInteger('1') eq 1";
704 XPath path = compileXPath(dc, xpath);
705
706 Evaluator eval = new DefaultEvaluator(dc, domDoc);
707 ResultSequence rs = eval.evaluate(path);
708
709 XSBoolean result = (XSBoolean) rs.first();
710
711 String actual = result.string_value();
712
713 assertEquals("true", actual);
714 }
dacarver5f7e5d12009-06-09 14:30:40 +0000715
dacarver2673f012009-05-25 23:08:56 +0000716 public void testXSByte() throws Exception {
717 // Bug 277639
dacarver23c40122009-11-13 23:26:23 +0000718 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000719
dacarver2673f012009-05-25 23:08:56 +0000720 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
721 loadDOMDocument(fileURL);
722
723 // Get XML Schema Information for the Document
724 XSModel schema = getGrammar();
725
726 DynamicContext dc = setupDynamicContext(schema);
727
728 // min value of xs:byte is -128
729 // max value of xs:byte is 127
730 String xpath = "xs:byte('-128') eq -128";
731 XPath path = compileXPath(dc, xpath);
732
733 Evaluator eval = new DefaultEvaluator(dc, domDoc);
734 ResultSequence rs = eval.evaluate(path);
735
736 XSBoolean result = (XSBoolean) rs.first();
737
738 String actual = result.string_value();
739
740 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000741 }
742
dacarver28cff4b2009-05-25 23:19:36 +0000743 public void testXSUnsignedInt() throws Exception {
744 // Bug 277642
dacarver23c40122009-11-13 23:26:23 +0000745 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000746
dacarver28cff4b2009-05-25 23:19:36 +0000747 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
748 loadDOMDocument(fileURL);
749
750 // Get XML Schema Information for the Document
751 XSModel schema = getGrammar();
752
753 DynamicContext dc = setupDynamicContext(schema);
754
755 // min value of xs:unsignedInt is 0
756 // max value of xs:unsignedInt is 4294967295
757 String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')";
758 XPath path = compileXPath(dc, xpath);
759
760 Evaluator eval = new DefaultEvaluator(dc, domDoc);
761 ResultSequence rs = eval.evaluate(path);
762
763 XSBoolean result = (XSBoolean) rs.first();
764
765 String actual = result.string_value();
766
767 assertEquals("true", actual);
dacarver2673f012009-05-25 23:08:56 +0000768 }
dacarver5f7e5d12009-06-09 14:30:40 +0000769
dacarver3cc95782009-05-25 23:33:47 +0000770 public void testXSUnsignedShort() throws Exception {
771 // Bug 277645
dacarver23c40122009-11-13 23:26:23 +0000772 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver3cc95782009-05-25 23:33:47 +0000773 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
774 loadDOMDocument(fileURL);
775
776 // Get XML Schema Information for the Document
777 XSModel schema = getGrammar();
778
779 DynamicContext dc = setupDynamicContext(schema);
780
781 // min value of xs:unsignedShort is 0
782 // max value of xs:unsignedShort is 65535
783 String xpath = "xs:unsignedShort('65535') eq 65535";
784 XPath path = compileXPath(dc, xpath);
785
786 Evaluator eval = new DefaultEvaluator(dc, domDoc);
787 ResultSequence rs = eval.evaluate(path);
788
789 XSBoolean result = (XSBoolean) rs.first();
790
791 String actual = result.string_value();
792
793 assertEquals("true", actual);
794 }
dacarver23c40122009-11-13 23:26:23 +0000795
dacarvered2c87e2009-06-09 14:54:33 +0000796 public void testXSYearMonthDurationMultiply() throws Exception {
797 // Bug 279373
dacarver23c40122009-11-13 23:26:23 +0000798 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver68d6e6c2009-05-25 23:43:42 +0000799 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
800 loadDOMDocument(fileURL);
801
802 // Get XML Schema Information for the Document
803 XSModel schema = getGrammar();
804
805 DynamicContext dc = setupDynamicContext(schema);
806
dacarvered2c87e2009-06-09 14:54:33 +0000807 String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3";
dacarver68d6e6c2009-05-25 23:43:42 +0000808 XPath path = compileXPath(dc, xpath);
809
810 Evaluator eval = new DefaultEvaluator(dc, domDoc);
811 ResultSequence rs = eval.evaluate(path);
812
dacarverae395262009-07-02 04:30:16 +0000813 XSDuration result = (XSDuration) rs.first();
dacarver68d6e6c2009-05-25 23:43:42 +0000814
815 String actual = result.string_value();
816
dacarvered2c87e2009-06-09 14:54:33 +0000817 assertEquals("P6Y9M", actual);
dacarver68d6e6c2009-05-25 23:43:42 +0000818 }
dacarver23c40122009-11-13 23:26:23 +0000819
dacarvered2c87e2009-06-09 14:54:33 +0000820 public void testXSYearMonthDurationDivide1() throws Exception {
821 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000822 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000823 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
824 loadDOMDocument(fileURL);
825
826 // Get XML Schema Information for the Document
827 XSModel schema = getGrammar();
828
829 DynamicContext dc = setupDynamicContext(schema);
830
831 String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5";
832 XPath path = compileXPath(dc, xpath);
833
834 Evaluator eval = new DefaultEvaluator(dc, domDoc);
835 ResultSequence rs = eval.evaluate(path);
836
dacarverae395262009-07-02 04:30:16 +0000837 XSDuration result = (XSDuration) rs.first();
dacarvered2c87e2009-06-09 14:54:33 +0000838
839 String actual = result.string_value();
840
841 assertEquals("P1Y11M", actual);
842 }
dacarver23c40122009-11-13 23:26:23 +0000843
dacarvered2c87e2009-06-09 14:54:33 +0000844 public void testXSYearMonthDurationDivide2() throws Exception {
845 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000846 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000847 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
848 loadDOMDocument(fileURL);
849
850 // Get XML Schema Information for the Document
851 XSModel schema = getGrammar();
852
853 DynamicContext dc = setupDynamicContext(schema);
854
855 String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')";
856 XPath path = compileXPath(dc, xpath);
857
858 Evaluator eval = new DefaultEvaluator(dc, domDoc);
859 ResultSequence rs = eval.evaluate(path);
860
861 XSDecimal result = (XSDecimal) rs.first();
862
863 String actual = result.string_value();
864
865 assertEquals("-2.5", actual);
866 }
dacarver23c40122009-11-13 23:26:23 +0000867
dacarver2915e2f2009-06-09 14:41:36 +0000868 public void testXSDayTimeDurationMultiply() throws Exception {
869 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000870 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000871 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
872 loadDOMDocument(fileURL);
873
874 // Get XML Schema Information for the Document
875 XSModel schema = getGrammar();
876
877 DynamicContext dc = setupDynamicContext(schema);
878
879 String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1";
880 XPath path = compileXPath(dc, xpath);
881
882 Evaluator eval = new DefaultEvaluator(dc, domDoc);
883 ResultSequence rs = eval.evaluate(path);
884
dacarverae395262009-07-02 04:30:16 +0000885 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000886
887 String actual = result.string_value();
888
889 assertEquals("PT4H33M", actual);
890 }
dacarver23c40122009-11-13 23:26:23 +0000891
dacarver2915e2f2009-06-09 14:41:36 +0000892 public void testXSDayTimeDurationDivide() throws Exception {
893 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000894 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000895 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
896 loadDOMDocument(fileURL);
897
898 // Get XML Schema Information for the Document
899 XSModel schema = getGrammar();
900
901 DynamicContext dc = setupDynamicContext(schema);
902
903 String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5";
904 XPath path = compileXPath(dc, xpath);
905
906 Evaluator eval = new DefaultEvaluator(dc, domDoc);
907 ResultSequence rs = eval.evaluate(path);
908
dacarverae395262009-07-02 04:30:16 +0000909 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000910
911 String actual = result.string_value();
912
913 assertEquals("PT17H40M7S", actual);
914 }
dacarver23c40122009-11-13 23:26:23 +0000915
dacarvered2c87e2009-06-09 14:54:33 +0000916 public void testNegativeZeroDouble() throws Exception {
917 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000918 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver76b66582009-06-09 14:08:05 +0000919 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
920 loadDOMDocument(fileURL);
921
922 // Get XML Schema Information for the Document
923 XSModel schema = getGrammar();
924
925 DynamicContext dc = setupDynamicContext(schema);
926
dacarvered2c87e2009-06-09 14:54:33 +0000927 String xpath = "-(xs:double('0'))";
dacarver76b66582009-06-09 14:08:05 +0000928 XPath path = compileXPath(dc, xpath);
929
930 Evaluator eval = new DefaultEvaluator(dc, domDoc);
931 ResultSequence rs = eval.evaluate(path);
932
dacarvered2c87e2009-06-09 14:54:33 +0000933 XSDouble result = (XSDouble) rs.first();
dacarver76b66582009-06-09 14:08:05 +0000934
935 String actual = result.string_value();
936
dacarvered2c87e2009-06-09 14:54:33 +0000937 assertEquals("-0", actual);
dacarver76b66582009-06-09 14:08:05 +0000938 }
dacarver23c40122009-11-13 23:26:23 +0000939
dacarvered2c87e2009-06-09 14:54:33 +0000940 public void testNegativeZeroFloat() throws Exception {
941 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000942 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000943 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
944 loadDOMDocument(fileURL);
945
946 // Get XML Schema Information for the Document
947 XSModel schema = getGrammar();
948
949 DynamicContext dc = setupDynamicContext(schema);
950
dacarvered2c87e2009-06-09 14:54:33 +0000951 String xpath = "-(xs:float('0'))";
dacarver5f7e5d12009-06-09 14:30:40 +0000952 XPath path = compileXPath(dc, xpath);
953
954 Evaluator eval = new DefaultEvaluator(dc, domDoc);
955 ResultSequence rs = eval.evaluate(path);
dacarvered2c87e2009-06-09 14:54:33 +0000956
957 XSFloat result = (XSFloat) rs.first();
958
dacarver5f7e5d12009-06-09 14:30:40 +0000959 String actual = result.string_value();
960
dacarvered2c87e2009-06-09 14:54:33 +0000961 assertEquals("-0", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000962 }
963
dacarvered2c87e2009-06-09 14:54:33 +0000964 public void testXSUnsignedByte() throws Exception {
965 // Bug 277650
dacarver23c40122009-11-13 23:26:23 +0000966 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000967 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
968 loadDOMDocument(fileURL);
969
970 // Get XML Schema Information for the Document
dacarver5f7e5d12009-06-09 14:30:40 +0000971 XSModel schema = getGrammar();
dacarver5f7e5d12009-06-09 14:30:40 +0000972
dacarvered2c87e2009-06-09 14:54:33 +0000973 DynamicContext dc = setupDynamicContext(schema);
974
975 // min value of xs:unsignedByte is 0
976 // max value of xs:unsignedByte is 255
977 String xpath = "xs:unsignedByte('255') eq 255";
dacarver5f7e5d12009-06-09 14:30:40 +0000978 XPath path = compileXPath(dc, xpath);
dacarvered2c87e2009-06-09 14:54:33 +0000979
dacarver5f7e5d12009-06-09 14:30:40 +0000980 Evaluator eval = new DefaultEvaluator(dc, domDoc);
981 ResultSequence rs = eval.evaluate(path);
982
dacarvered2c87e2009-06-09 14:54:33 +0000983 XSBoolean result = (XSBoolean) rs.first();
dacarver5f7e5d12009-06-09 14:30:40 +0000984
985 String actual = result.string_value();
986
dacarvered2c87e2009-06-09 14:54:33 +0000987 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000988 }
dacarver23c40122009-11-13 23:26:23 +0000989
dacarver9cfaa8e2009-06-22 21:37:15 +0000990 public void testXSBase64Binary() throws Exception {
991 // Bug 281046
dacarver23c40122009-11-13 23:26:23 +0000992 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver9cfaa8e2009-06-22 21:37:15 +0000993 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
994 loadDOMDocument(fileURL);
995
996 // Get XML Schema Information for the Document
997 XSModel schema = getGrammar();
998
999 DynamicContext dc = setupDynamicContext(schema);
1000
1001 String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')";
1002 XPath path = compileXPath(dc, xpath);
1003
1004 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1005 ResultSequence rs = eval.evaluate(path);
1006
1007 XSBoolean result = (XSBoolean) rs.first();
1008
1009 String actual = result.string_value();
1010
1011 assertEquals("true", actual);
1012 }
dacarver23c40122009-11-13 23:26:23 +00001013
dacarver6018fcf2009-06-22 21:47:53 +00001014 public void testXSHexBinary() throws Exception {
1015 // Bug 281054
dacarver23c40122009-11-13 23:26:23 +00001016 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver6018fcf2009-06-22 21:47:53 +00001017 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1018 loadDOMDocument(fileURL);
1019
1020 // Get XML Schema Information for the Document
1021 XSModel schema = getGrammar();
1022
1023 DynamicContext dc = setupDynamicContext(schema);
1024
1025 String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')";
1026 XPath path = compileXPath(dc, xpath);
1027
1028 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1029 ResultSequence rs = eval.evaluate(path);
1030
1031 XSBoolean result = (XSBoolean) rs.first();
1032
1033 String actual = result.string_value();
1034
1035 assertEquals("true", actual);
1036 }
dacarver23c40122009-11-13 23:26:23 +00001037
mgandhiefe95742009-08-18 04:12:11 +00001038 public void testElementTypedValue() throws Exception {
1039 // test for fix in ElementType.java, involving incorrectly computing
1040 // typed value of element node, in case of validating element node,
1041 // with a user defined simple XSD type.
1042 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
dacarver23c40122009-11-13 23:26:23 +00001043 URL schemaURL = bundle
1044 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
mgandhiefe95742009-08-18 04:12:11 +00001045
1046 loadDOMDocument(fileURL, schemaURL);
1047
1048 // Get XSModel object for the Schema
1049 XSModel schema = getGrammar(schemaURL);
1050
1051 DynamicContext dc = setupDynamicContext(schema);
1052
1053 String xpath = "Example/Transportation/mode eq 'air'";
1054 XPath path = compileXPath(dc, xpath);
1055
1056 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1057 ResultSequence rs = eval.evaluate(path);
1058
1059 XSBoolean result = (XSBoolean) rs.first();
1060
1061 String actual = result.string_value();
1062
1063 assertEquals("true", actual);
1064
1065 }
dacarverf9402792009-08-22 01:14:10 +00001066
dacarver23c40122009-11-13 23:26:23 +00001067 public void testBug286061_quoted_string_literals_no_normalize()
1068 throws Exception {
dacarverf9402792009-08-22 01:14:10 +00001069
dacarver23c40122009-11-13 23:26:23 +00001070 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001071 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1072 loadDOMDocument(fileURL);
1073
1074 // Get XML Schema Information for the Document
1075 XSModel schema = getGrammar();
1076
1077 DynamicContext dc = setupDynamicContext(schema);
1078
dacarver23c40122009-11-13 23:26:23 +00001079 String xpath = "'\"\"'"; // the expression '""' contains no escapes
dacarverf9402792009-08-22 01:14:10 +00001080
1081 XPath path = compileXPath(dc, xpath);
1082
1083 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1084 ResultSequence rs = eval.evaluate(path);
1085
1086 String resultValue = rs.first().string_value();
1087
1088 assertEquals("\"\"", resultValue);
1089 }
dacarver23c40122009-11-13 23:26:23 +00001090
dacarverf9402792009-08-22 01:14:10 +00001091 public void testBug286061_quoted_string_literals() throws Exception {
1092
dacarver23c40122009-11-13 23:26:23 +00001093 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001094 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1095 loadDOMDocument(fileURL);
1096
1097 // Get XML Schema Information for the Document
1098 XSModel schema = getGrammar();
1099
1100 DynamicContext dc = setupDynamicContext(schema);
1101
1102 String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )";
1103
1104 XPath path = compileXPath(dc, xpath);
1105
1106 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1107 ResultSequence rs = eval.evaluate(path);
1108
1109 String resultValue = rs.first().string_value();
1110
1111 assertEquals("Don't try this at \"home\", she said", resultValue);
1112 }
1113
jmollerb601eb02009-09-02 20:21:06 +00001114 public void testBug280555_collations() throws Exception {
1115 // Setup context
1116 DefaultDynamicContext dc = setupDynamicContext(null);
1117 dc.set_collation_provider(createLengthCollatorProvider());
1118 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1119
1120 // Parse expression
1121 XPath path = compileXPath(dc, " 'abc' < 'de' ");
1122
1123 // Evaluate once
1124 XSBoolean bval = (XSBoolean) eval.evaluate(path).first();
1125 assertTrue("'abc' < 'def' for normal collations", bval.value());
dacarver23c40122009-11-13 23:26:23 +00001126
jmollerb601eb02009-09-02 20:21:06 +00001127 // Evaluate again with the funny collator
1128 dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR);
1129 XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first();
1130 assertFalse("'abc' < 'def' for normal collations", bval2.value());
dacarver23c40122009-11-13 23:26:23 +00001131 }
1132
mgandhiae92c592009-09-19 12:58:06 +00001133 public void testXPathDefaultNamespace() throws Exception {
1134 // Test for the fix, for xpathDefaultNamespace
dacarver23c40122009-11-13 23:26:23 +00001135 URL fileURL = bundle
1136 .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml");
mgandhiae92c592009-09-19 12:58:06 +00001137 loadDOMDocument(fileURL);
1138
1139 // Get XML Schema Information for the Document
1140 XSModel schema = getGrammar();
1141
dacarver23c40122009-11-13 23:26:23 +00001142 // set up XPath default namespace in Dynamic Context
mgandhiae92c592009-09-19 12:58:06 +00001143 DynamicContext dc = setupDynamicContext(schema);
1144 addXPathDefaultNamespace("http://xyz");
1145
1146 String xpath = "X/message = 'hello'";
1147 XPath path = compileXPath(dc, xpath);
1148
1149 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1150 ResultSequence rs = eval.evaluate(path);
1151
1152 XSBoolean result = (XSBoolean) rs.first();
1153
1154 String actual = result.string_value();
1155
1156 assertEquals("true", actual);
1157 }
dacarver07849652009-11-28 00:09:27 +00001158
mgandhi80a468d2009-12-25 04:57:38 +00001159 public void testXPathInstanceOf1() throws Exception {
1160 // Bug 298267
1161 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1162 URL schemaURL = bundle
1163 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1164
1165 loadDOMDocument(fileURL, schemaURL);
1166
1167 // Get XSModel object for the Schema
1168 XSModel schema = getGrammar(schemaURL);
1169
1170 DynamicContext dc = setupDynamicContext(schema);
1171
1172 String xpath = "Example/Transportation/mode instance of element()";
1173 XPath path = compileXPath(dc, xpath);
1174
1175 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1176 ResultSequence rs = eval.evaluate(path);
1177
1178 XSBoolean result = (XSBoolean) rs.first();
1179
1180 String actual = result.string_value();
1181
1182 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001183 }
1184
1185 public void testXPathInstanceOf2() throws Exception {
1186 // Bug 298267
1187 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1188 URL schemaURL = bundle
1189 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1190
1191 loadDOMDocument(fileURL, schemaURL);
1192
1193 // Get XSModel object for the Schema
1194 XSModel schema = getGrammar(schemaURL);
1195
1196 DynamicContext dc = setupDynamicContext(schema);
1197
1198 String xpath = "Example/Transportation/mode instance of element(mode)";
1199 XPath path = compileXPath(dc, xpath);
1200
1201 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1202 ResultSequence rs = eval.evaluate(path);
1203
1204 XSBoolean result = (XSBoolean) rs.first();
1205
1206 String actual = result.string_value();
1207
1208 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001209 }
1210
mgandhi663fbd02009-12-27 11:23:35 +00001211 public void testXPathInstanceOf3() throws Exception {
mgandhi80a468d2009-12-25 04:57:38 +00001212 // Bug 298267
1213 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1214 URL schemaURL = bundle
1215 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1216
1217 loadDOMDocument(fileURL, schemaURL);
1218
1219 // Get XSModel object for the Schema
1220 XSModel schema = getGrammar(schemaURL);
1221
1222 DynamicContext dc = setupDynamicContext(schema);
1223
mgandhi663fbd02009-12-27 11:23:35 +00001224 String xpath = "Example/Transportation/mode instance of element(mode, modeType)";
mgandhi80a468d2009-12-25 04:57:38 +00001225 XPath path = compileXPath(dc, xpath);
1226
1227 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1228 ResultSequence rs = eval.evaluate(path);
1229
1230 XSBoolean result = (XSBoolean) rs.first();
1231
1232 String actual = result.string_value();
1233
dacarver5a6bbea2009-12-27 17:14:05 +00001234 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001235 }
1236
1237 public void testXPathInstanceOf4() throws Exception {
1238 // Bug 298267
1239 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1240 URL schemaURL = bundle
1241 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1242
1243 loadDOMDocument(fileURL, schemaURL);
1244
1245 // Get XSModel object for the Schema
1246 XSModel schema = getGrammar(schemaURL);
1247
1248 DynamicContext dc = setupDynamicContext(schema);
1249
1250 String xpath = "Example/Transportation/mode instance of element(mode, abc)";
1251 XPath path = compileXPath(dc, xpath);
1252
1253 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1254 ResultSequence rs = eval.evaluate(path);
1255
1256 XSBoolean result = (XSBoolean) rs.first();
1257
1258 String actual = result.string_value();
1259
1260 assertEquals("false", actual);
mgandhi247cdd82009-12-25 09:50:00 +00001261 }
1262
mgandhi663fbd02009-12-27 11:23:35 +00001263 public void testXPathInstanceOf5() throws Exception {
1264 // Bug 298267
1265 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1266 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1267
1268 loadDOMDocument(fileURL, schemaURL);
1269
1270 // Get XSModel object for the Schema
1271 XSModel schema = getGrammar(schemaURL);
1272
1273 DynamicContext dc = setupDynamicContext(schema);
1274
1275 String xpath = "Example/x instance of element(x, x_Type)*";
1276 XPath path = compileXPath(dc, xpath);
1277
1278 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1279 ResultSequence rs = eval.evaluate(path);
1280
1281 XSBoolean result = (XSBoolean) rs.first();
1282
1283 String actual = result.string_value();
1284
1285 assertEquals("true", actual);
1286 }
jmoller2c384ed2010-06-24 23:48:34 +00001287
1288 public void testXPathInstanceOf5_2() throws Exception {
1289 // Bug 298267
1290 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1291 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1292
1293 loadDOMDocument(fileURL, schemaURL);
1294
1295 // Get XSModel object for the Schema
1296 XSModel schema = getGrammar(schemaURL);
1297
1298 DynamicContext dc = setupDynamicContext(schema);
1299
1300 String xpath = "(/Example/x, /Example) instance of element(x, x_Type)+";
1301 XPath path = compileXPath(dc, xpath);
1302
1303 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1304 ResultSequence rs = eval.evaluate(path);
1305
1306 XSBoolean result = (XSBoolean) rs.first();
1307
1308 assertEquals(false, result.value());
1309 }
1310
1311 public void testXPathInstanceOf5_3() throws Exception {
1312 // Bug 298267
1313 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1314 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1315
1316 loadDOMDocument(fileURL, schemaURL);
1317
1318 // Get XSModel object for the Schema
1319 XSModel schema = getGrammar(schemaURL);
1320
1321 DynamicContext dc = setupDynamicContext(schema);
1322
1323 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)";
1324 XPath path = compileXPath(dc, xpath);
1325
1326 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1327 ResultSequence rs = eval.evaluate(path);
1328
1329 XSBoolean result = (XSBoolean) rs.first();
1330
1331 assertFalse(result.value());
1332 }
1333
1334 public void testXPathInstanceOf5_4() throws Exception {
1335 // Bug 298267
1336 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1337 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1338
1339 loadDOMDocument(fileURL, schemaURL);
1340
1341 // Get XSModel object for the Schema
1342 XSModel schema = getGrammar(schemaURL);
1343
1344 DynamicContext dc = setupDynamicContext(schema);
1345
1346 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)+";
1347 XPath path = compileXPath(dc, xpath);
1348
1349 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1350 ResultSequence rs = eval.evaluate(path);
1351
1352 XSBoolean result = (XSBoolean) rs.first();
1353
1354 assertTrue(result.value());
1355 }
1356
1357 public void testXPathInstanceOf5_5() throws Exception {
1358 // Bug 298267
1359 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1360 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1361
1362 loadDOMDocument(fileURL, schemaURL);
1363
1364 // Get XSModel object for the Schema
1365 XSModel schema = getGrammar(schemaURL);
1366
1367 DynamicContext dc = setupDynamicContext(schema);
1368
1369 String xpath = "(/Example/x instance of x_Type+) and (/Example/x[2]/@mesg instance of mesg_Type)";
1370 XPath path = compileXPath(dc, xpath);
1371
1372 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1373 ResultSequence rs = eval.evaluate(path);
1374
1375 XSBoolean result = (XSBoolean) rs.first();
1376
1377 assertEquals(true, result.value());
1378 }
1379
mgandhi663fbd02009-12-27 11:23:35 +00001380 public void testXPathInstanceOf6() throws Exception {
1381 // Bug 298267
1382 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1383 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1384
1385 loadDOMDocument(fileURL, schemaURL);
1386
1387 // Get XSModel object for the Schema
1388 XSModel schema = getGrammar(schemaURL);
1389
1390 DynamicContext dc = setupDynamicContext(schema);
1391
1392 String xpath = "Example/x instance of element(*, x_Type)*";
1393 XPath path = compileXPath(dc, xpath);
1394
1395 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1396 ResultSequence rs = eval.evaluate(path);
1397
1398 XSBoolean result = (XSBoolean) rs.first();
1399
1400 String actual = result.string_value();
1401
1402 assertEquals("true", actual);
1403 }
1404
1405 public void testXPathInstanceOf7() throws Exception {
1406 // Bug 298267
1407 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1408 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1409
1410 loadDOMDocument(fileURL, schemaURL);
1411
1412 // Get XSModel object for the Schema
1413 XSModel schema = getGrammar(schemaURL);
1414
1415 DynamicContext dc = setupDynamicContext(schema);
1416
1417 String xpath = "Example/x instance of element(x, x_Type)+";
1418 XPath path = compileXPath(dc, xpath);
1419
1420 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1421 ResultSequence rs = eval.evaluate(path);
1422
1423 XSBoolean result = (XSBoolean) rs.first();
1424
1425 String actual = result.string_value();
1426
dacarver3da20eb2009-12-29 14:29:45 +00001427 assertEquals("true", actual);
mgandhi663fbd02009-12-27 11:23:35 +00001428 }
1429
1430 public void testXPathInstanceNonExistantElement() throws Exception {
1431 // Bug 298267
1432 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1433 URL schemaURL = bundle
1434 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1435
1436 loadDOMDocument(fileURL, schemaURL);
1437
1438 // Get XSModel object for the Schema
1439 XSModel schema = getGrammar(schemaURL);
1440
1441 DynamicContext dc = setupDynamicContext(schema);
1442
1443 String xpath = "Example/Transportation/mode instance of element(x)";
1444 XPath path = compileXPath(dc, xpath);
1445
1446 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1447 ResultSequence rs = eval.evaluate(path);
1448
1449 XSBoolean result = (XSBoolean) rs.first();
1450
1451 String actual = result.string_value();
1452
1453 assertEquals("false", actual);
1454 }
1455
mgandhi247cdd82009-12-25 09:50:00 +00001456 public void testFnNumber_Evaluation1() throws Exception {
1457 // Bug 298519
1458 URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml");
1459 URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd");
mgandhi80a468d2009-12-25 04:57:38 +00001460
mgandhi247cdd82009-12-25 09:50:00 +00001461 loadDOMDocument(fileURL, schemaURL);
1462
1463 // Get XSModel object for the Schema
1464 XSModel schema = getGrammar(schemaURL);
1465
1466 DynamicContext dc = setupDynamicContext(schema);
1467
1468 String xpath = "number(Example/x) ge 18";
1469 XPath path = compileXPath(dc, xpath);
1470
1471 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1472 ResultSequence rs = eval.evaluate(path);
1473
1474 XSBoolean result = (XSBoolean) rs.first();
1475
1476 String actual = result.string_value();
1477
1478 assertEquals("true", actual);
1479 }
1480
1481 public void testFnNumber_Evaluation2() throws Exception {
1482 // Bug 298519
1483 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1484 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1485 loadDOMDocument(fileURL);
1486
1487 // Get XML Schema Information for the Document
1488 XSModel schema = getGrammar();
1489
1490 DynamicContext dc = setupDynamicContext(schema);
1491
1492 String xpath = "number(xs:unsignedByte('20')) ge 18";
1493 XPath path = compileXPath(dc, xpath);
1494
1495 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1496 ResultSequence rs = eval.evaluate(path);
1497
1498 XSBoolean result = (XSBoolean) rs.first();
1499
1500 String actual = result.string_value();
1501
1502 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001503 }
mgandhie02bf582009-12-26 13:17:14 +00001504
1505 public void testAttrNode_Test1() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001506 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001507 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1508 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1509
1510 loadDOMDocument(fileURL, schemaURL);
1511
1512 // Get XSModel object for the Schema
1513 XSModel schema = getGrammar(schemaURL);
1514
1515 DynamicContext dc = setupDynamicContext(schema);
1516
1517 String xpath = "Example/x[1]/@mesg instance of attribute()";
1518 XPath path = compileXPath(dc, xpath);
1519
1520 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1521 ResultSequence rs = eval.evaluate(path);
1522
1523 XSBoolean result = (XSBoolean) rs.first();
1524
1525 String actual = result.string_value();
1526
1527 assertEquals("true", actual);
1528 }
1529
1530 public void testAttrNode_Test2() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001531 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001532 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1533 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1534
1535 loadDOMDocument(fileURL, schemaURL);
1536
1537 // Get XSModel object for the Schema
1538 XSModel schema = getGrammar(schemaURL);
1539
1540 DynamicContext dc = setupDynamicContext(schema);
1541
1542 String xpath = "Example/x[1]/@mesg instance of attribute(xx)";
1543 XPath path = compileXPath(dc, xpath);
1544
1545 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1546 ResultSequence rs = eval.evaluate(path);
1547
1548 XSBoolean result = (XSBoolean) rs.first();
1549
1550 String actual = result.string_value();
1551
1552 assertEquals("false", actual);
1553 }
1554
1555 public void testAttrNode_Test3() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001556 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001557 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1558 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1559
1560 loadDOMDocument(fileURL, schemaURL);
1561
1562 // Get XSModel object for the Schema
1563 XSModel schema = getGrammar(schemaURL);
1564
1565 DynamicContext dc = setupDynamicContext(schema);
1566
1567 String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)";
1568 XPath path = compileXPath(dc, xpath);
1569
1570 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1571 ResultSequence rs = eval.evaluate(path);
1572
1573 XSBoolean result = (XSBoolean) rs.first();
1574
1575 String actual = result.string_value();
1576
1577 assertEquals("true", actual);
1578 }
1579
1580 public void testAttrNode_Test4() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001581 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001582 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1583 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1584
1585 loadDOMDocument(fileURL, schemaURL);
1586
1587 // Get XSModel object for the Schema
1588 XSModel schema = getGrammar(schemaURL);
1589
1590 DynamicContext dc = setupDynamicContext(schema);
1591
1592 String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)";
1593 XPath path = compileXPath(dc, xpath);
1594
1595 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1596 ResultSequence rs = eval.evaluate(path);
1597
1598 XSBoolean result = (XSBoolean) rs.first();
1599
1600 String actual = result.string_value();
1601
1602 assertEquals("false", actual);
1603 }
1604
1605 public void testAttrNode_Test5() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001606 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001607 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1608 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1609
1610 loadDOMDocument(fileURL, schemaURL);
1611
1612 // Get XSModel object for the Schema
1613 XSModel schema = getGrammar(schemaURL);
1614
1615 DynamicContext dc = setupDynamicContext(schema);
1616
1617 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)";
1618 XPath path = compileXPath(dc, xpath);
1619
1620 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1621 ResultSequence rs = eval.evaluate(path);
1622
1623 XSBoolean result = (XSBoolean) rs.first();
1624
1625 String actual = result.string_value();
1626
1627 assertEquals("true", actual);
1628 }
1629
1630 public void testAttrNode_Test6() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001631 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001632 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1633 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1634
1635 loadDOMDocument(fileURL, schemaURL);
1636
1637 // Get XSModel object for the Schema
1638 XSModel schema = getGrammar(schemaURL);
1639
1640 DynamicContext dc = setupDynamicContext(schema);
1641
1642 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)";
1643 XPath path = compileXPath(dc, xpath);
1644
1645 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1646 ResultSequence rs = eval.evaluate(path);
1647
1648 XSBoolean result = (XSBoolean) rs.first();
1649
1650 String actual = result.string_value();
1651
1652 assertEquals("false", actual);
1653 }
1654
1655 public void testAttrNode_Test7() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001656 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001657 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1658 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1659
1660 loadDOMDocument(fileURL, schemaURL);
1661
1662 // Get XSModel object for the Schema
1663 XSModel schema = getGrammar(schemaURL);
1664
1665 DynamicContext dc = setupDynamicContext(schema);
1666
1667 String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*";
1668 XPath path = compileXPath(dc, xpath);
1669
1670 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1671 ResultSequence rs = eval.evaluate(path);
1672
1673 XSBoolean result = (XSBoolean) rs.first();
1674
1675 String actual = result.string_value();
1676
1677 assertEquals("true", actual);
1678 }
mgandhi1fc77412010-02-02 15:07:05 +00001679
1680 public void testFnNameContextUndefined() throws Exception {
1681 // Bug 301539
1682 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1683 loadDOMDocument(fileURL);
1684
1685 // Get XML Schema Information for the Document
1686 XSModel schema = getGrammar();
1687
1688 DynamicContext dc = setupDynamicContext(schema);
1689
1690 String xpath = "Example/*[1]/name() eq 'x'";
1691 XPath path = compileXPath(dc, xpath);
1692
1693 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1694 ResultSequence rs = eval.evaluate(path);
1695
1696 XSBoolean result = (XSBoolean) rs.first();
1697
1698 String actual = result.string_value();
1699
1700 assertEquals("true", actual);
1701 }
mgandhi13d897f2010-04-18 09:46:00 +00001702
1703 public void testXSNormalizedString() throws Exception {
1704 // Bug 309585
1705 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1706 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1707 loadDOMDocument(fileURL);
1708
1709 // Get XML Schema Information for the Document
1710 XSModel schema = getGrammar();
1711
1712 DynamicContext dc = setupDynamicContext(schema);
1713
1714 String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')";
1715 XPath path = compileXPath(dc, xpath);
1716
1717 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1718
1719 boolean testSuccess = false;
1720 try {
1721 ResultSequence rs = eval.evaluate(path);
1722 }
1723 catch(DynamicError ex) {
1724 // a 'DynamicError' exception indicates, that this test is a success
1725 testSuccess = true;
1726 }
1727
1728 assertTrue(testSuccess);
1729 }
jmollerb0289532010-06-24 23:16:07 +00001730
1731 public void testParseElementKeywordsAsNodes() throws Exception {
1732 // Bug 311480
1733 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1734 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1735 loadDOMDocument(fileURL);
1736
1737 // Get XML Schema Information for the Document
1738 XSModel schema = getGrammar();
1739
1740 DynamicContext dc = setupDynamicContext(schema);
1741
1742 String xpath = "/element/attribute";
1743 XPath path = compileXPath(dc, xpath);
1744 }
1745
mgandhi247b6e72010-07-07 11:50:37 +00001746 public void testTypedValueEnhancement_primitiveTypes() throws Exception {
1747 // Bug 318313
1748 URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml");
1749 URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd");
1750
1751 loadDOMDocument(fileURL, schemaURL);
1752
1753 // Get XSModel object for the Schema
1754 XSModel schema = getGrammar(schemaURL);
1755
1756 DynamicContext dc = setupDynamicContext(schema);
1757
1758 String xpath = "X gt 99";
1759 XPath path = compileXPath(dc, xpath);
1760
1761 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1762 ResultSequence rs = eval.evaluate(path);
1763
1764 XSBoolean result = (XSBoolean) rs.first();
1765
1766 String actual = result.string_value();
1767
1768 assertEquals("true", actual);
1769 }
1770
mgandhica745752010-09-27 12:42:00 +00001771 public void testTypedValueEnhancement_Bug323900_1() throws Exception {
1772 // Bug 323900
1773 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_1.xml");
1774 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_1.xsd");
1775
1776 loadDOMDocument(fileURL, schemaURL);
1777
1778 // Get XSModel object for the Schema
1779 XSModel schema = getGrammar(schemaURL);
1780
1781 DynamicContext dc = setupDynamicContext(schema);
1782
1783 String xpath = "data(X) instance of xs:integer+";
1784 XPath path = compileXPath(dc, xpath);
1785
1786 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1787 ResultSequence rs = eval.evaluate(path);
1788
1789 XSBoolean result = (XSBoolean) rs.first();
1790
1791 String actual = result.string_value();
1792
1793 assertEquals("true", actual);
1794 }
1795
1796 public void testTypedValueEnhancement_Bug323900_2() throws Exception {
1797 // Bug 323900
1798 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml");
1799 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd");
1800
1801 loadDOMDocument(fileURL, schemaURL);
1802
1803 // Get XSModel object for the Schema
1804 XSModel schema = getGrammar(schemaURL);
1805
1806 DynamicContext dc = setupDynamicContext(schema);
1807
1808 // 1st test
1809 String xpath = "data(X) instance of xs:integer+";
1810 XPath path = compileXPath(dc, xpath);
1811
1812 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1813 ResultSequence rs = eval.evaluate(path);
1814
1815 XSBoolean result = (XSBoolean) rs.first();
1816
1817 String actual = result.string_value();
1818
1819 assertEquals("false", actual);
1820 }
1821
1822 public void testTypedValueEnhancement_Bug323900_3() throws Exception {
1823 // Bug 323900
1824 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml");
1825 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd");
1826
1827 loadDOMDocument(fileURL, schemaURL);
1828
1829 // Get XSModel object for the Schema
1830 XSModel schema = getGrammar(schemaURL);
1831
1832 DynamicContext dc = setupDynamicContext(schema);
1833 String xpath = "data(X)";
1834 XPath path = compileXPath(dc, xpath);
1835 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1836 ResultSequence rs = eval.evaluate(path);
1837
1838 boolean result1 = ((XSInteger) rs.get(0)).eq(new XSInteger(BigInteger.
1839 valueOf(1)), dc);
1840 boolean result2 = ((XSInteger) rs.get(1)).eq(new XSInteger(BigInteger.
1841 valueOf(2)), dc);
1842 boolean result3 = ((XSString) rs.get(2)).eq(new XSString("3.3"), dc);
1843
1844 assertEquals(true, result1 && result2 && result3);
1845 }
1846
1847 public void testTypedValueEnhancement_Bug323900_4() throws Exception {
1848 // Bug 323900
1849 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_3.xml");
1850 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd");
1851
1852 loadDOMDocument(fileURL, schemaURL);
1853
1854 // Get XSModel object for the Schema
1855 XSModel schema = getGrammar(schemaURL);
1856
1857 DynamicContext dc = setupDynamicContext(schema);
1858 String xpath = "data(X)";
1859 XPath path = compileXPath(dc, xpath);
1860 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1861 ResultSequence rs = eval.evaluate(path);
1862
1863 XSString result = (XSString) rs.get(0);
1864 assertEquals("3.3", result.string_value());
1865 }
1866
1867 public void testTypedValueEnhancement_Bug323900_5() throws Exception {
1868 // Bug 323900
1869 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_4.xml");
1870 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd");
1871
1872 loadDOMDocument(fileURL, schemaURL);
1873
1874 // Get XSModel object for the Schema
1875 XSModel schema = getGrammar(schemaURL);
1876
1877 DynamicContext dc = setupDynamicContext(schema);
1878 String xpath = "data(X)";
1879 XPath path = compileXPath(dc, xpath);
1880 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1881 ResultSequence rs = eval.evaluate(path);
1882
1883 XSInteger result = (XSInteger) rs.get(0);
1884 assertEquals("10", result.string_value());
1885 }
1886
1887 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_1()
1888 throws Exception {
1889 // Bug 325262
1890 DynamicContext dc = setupDynamicContext(null);
1891
1892 ResultSequence rs = ResultSequenceFactory.create_new();
1893 dc.set_variable(new QName("value"), rs);
1894
1895 String xpath = "deep-equal($value,())";
1896 XPath path = compileXPath(dc, xpath);
1897 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1898 ResultSequence rsRes = eval.evaluate(path);
1899
1900 XSBoolean result = (XSBoolean) rsRes.get(0);
1901 assertEquals("true", result.string_value());
1902 }
1903
1904 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_2()
1905 throws Exception {
1906 // Bug 325262
1907 DynamicContext dc = setupDynamicContext(null);
1908
1909 ResultSequence rs = ResultSequenceFactory.create_new();
1910 rs.add(new XSInteger(BigInteger.valueOf(2)));
1911 rs.add(new XSInteger(BigInteger.valueOf(4)));
1912 rs.add(new XSInteger(BigInteger.valueOf(6)));
1913 dc.set_variable(new QName("value"), rs);
1914
1915 // test a
1916 String xpath = "$value instance of xs:integer+";
1917 XPath path = compileXPath(dc, xpath);
1918 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1919 ResultSequence rsRes = eval.evaluate(path);
1920 XSBoolean result = (XSBoolean) rsRes.get(0);
1921 assertEquals("true", result.string_value());
1922
1923 // test b
1924 xpath = "deep-equal($value, (2, 4, 6))";
1925 path = compileXPath(dc, xpath);
1926 eval = new DefaultEvaluator(dc, domDoc);
1927 rsRes = eval.evaluate(path);
1928 result = (XSBoolean) rsRes.get(0);
1929 assertEquals("true", result.string_value());
1930 }
1931
1932 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_3()
1933 throws Exception {
1934 // Bug 325262
1935 DynamicContext dc = setupDynamicContext(null);
1936
1937 ResultSequence rs = ResultSequenceFactory.create_new();
1938 rs.add(new XSInteger(BigInteger.valueOf(2)));
1939 rs.add(new XSInteger(BigInteger.valueOf(4)));
1940 rs.add(new XSInteger(BigInteger.valueOf(6)));
1941 dc.set_variable(new QName("value"), rs);
1942
1943 String xpath = "count(data($value)) = 3";
1944 XPath path = compileXPath(dc, xpath);
1945 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1946 ResultSequence rsRes = eval.evaluate(path);
1947 XSBoolean result = (XSBoolean) rsRes.get(0);
1948 assertEquals("true", result.string_value());
1949 }
1950
mgandhi247b6e72010-07-07 11:50:37 +00001951 private CollationProvider createLengthCollatorProvider() {
1952 return new CollationProvider() {
1953 @SuppressWarnings("unchecked")
1954 public Comparator get_collation(String name) {
1955 if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) {
1956 return new Comparator<String>() {
1957 public int compare(String o1, String o2) {
1958 return o1.length() - o2.length();
1959 }
1960 };
1961 }
1962 return null;
1963 }
1964 };
1965 }
1966
dacarver879c37a2009-04-26 23:41:32 +00001967}