blob: 48e26411629154dcf36d2ccf051185b77f0750f3 [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
dacarver879c37a2009-04-26 23:41:32 +000045 *******************************************************************************/
46package org.eclipse.wst.xml.xpath2.processor.test;
47
48import java.net.URL;
jmollerb601eb02009-09-02 20:21:06 +000049import java.util.Comparator;
dacarver879c37a2009-04-26 23:41:32 +000050
dacarver2b291392009-05-23 00:47:49 +000051import javax.xml.parsers.DocumentBuilder;
52import javax.xml.parsers.DocumentBuilderFactory;
53
dacarver879c37a2009-04-26 23:41:32 +000054import org.apache.xerces.xs.XSModel;
dacarver7d5e2922009-11-08 15:40:36 +000055import org.eclipse.core.runtime.Platform;
jmollerb601eb02009-09-02 20:21:06 +000056import org.eclipse.wst.xml.xpath2.processor.CollationProvider;
57import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
dacarver879c37a2009-04-26 23:41:32 +000058import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
59import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
mgandhi13d897f2010-04-18 09:46:00 +000060import org.eclipse.wst.xml.xpath2.processor.DynamicError;
dacarver879c37a2009-04-26 23:41:32 +000061import org.eclipse.wst.xml.xpath2.processor.Evaluator;
dacarver6018fcf2009-06-22 21:47:53 +000062import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
63import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
64import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
dacarver2915e2f2009-06-09 14:41:36 +000065import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal;
dacarvered2c87e2009-06-09 14:54:33 +000066import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble;
dacarverae395262009-07-02 04:30:16 +000067import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
dacarvered2c87e2009-06-09 14:54:33 +000068import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat;
dacarver7d5e2922009-11-08 15:40:36 +000069import org.osgi.framework.Bundle;
jmolleref1b2b42010-08-12 10:33:28 +000070import org.xml.sax.InputSource;
dacarver879c37a2009-04-26 23:41:32 +000071
72public class TestBugs extends AbstractPsychoPathTest {
dacarver23c40122009-11-13 23:26:23 +000073
jmollerb601eb02009-09-02 20:21:06 +000074 private static final String URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR = "urn:x-eclipse:xpath20:funky-collator";
dacarver23c40122009-11-13 23:26:23 +000075
76 private Bundle bundle;
77
dacarver7d5e2922009-11-08 15:40:36 +000078 @Override
79 protected void setUp() throws Exception {
80 // TODO Auto-generated method stub
81 super.setUp();
82 bundle = Platform
dacarver23c40122009-11-13 23:26:23 +000083 .getBundle("org.eclipse.wst.xml.xpath2.processor.tests");
dacarver7d5e2922009-11-08 15:40:36 +000084
85 }
jmollerb601eb02009-09-02 20:21:06 +000086
jmollerb0289532010-06-24 23:16:07 +000087 public void testNamesWhichAreKeywords() throws Exception {
88 // Bug 273719
89 URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml");
90 loadDOMDocument(fileURL);
91
92 // Get XML Schema Information for the Document
93 XSModel schema = getGrammar();
94
95 DynamicContext dc = setupDynamicContext(schema);
96
97// String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)";
98 String xpath = "(/element/eq eq 'eq') or //child::xs:*";
99 XPath path = compileXPath(dc, xpath);
100
101 Evaluator eval = new DefaultEvaluator(dc, domDoc);
102 ResultSequence rs = eval.evaluate(path);
103
104 XSBoolean result = (XSBoolean) rs.first();
105
106 String actual = result.string_value();
107
108 assertEquals("true", actual);
109 }
110
dacarver879c37a2009-04-26 23:41:32 +0000111 public void testStringLengthWithElementArg() throws Exception {
112 // Bug 273719
113 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
114 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000115
dacarver879c37a2009-04-26 23:41:32 +0000116 // Get XML Schema Information for the Document
117 XSModel schema = getGrammar();
118
119 DynamicContext dc = setupDynamicContext(schema);
120
121 String xpath = "string-length(x) > 2";
122 XPath path = compileXPath(dc, xpath);
123
124 Evaluator eval = new DefaultEvaluator(dc, domDoc);
125 ResultSequence rs = eval.evaluate(path);
126
127 XSBoolean result = (XSBoolean) rs.first();
128
129 String actual = result.string_value();
130
131 assertEquals("true", actual);
dacarver84e43f52009-04-28 19:25:30 +0000132 }
dacarver6c9a7722009-05-24 01:16:07 +0000133
dacarver84e43f52009-04-28 19:25:30 +0000134 public void testBug273795Arity2() throws Exception {
135 // Bug 273795
136 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
137 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000138
dacarver84e43f52009-04-28 19:25:30 +0000139 // Get XML Schema Information for the Document
140 XSModel schema = getGrammar();
141
142 DynamicContext dc = setupDynamicContext(schema);
143
144 // test with arity 2
145 String xpath = "substring(x, 3) = 'happy'";
146 XPath path = compileXPath(dc, xpath);
147
148 Evaluator eval = new DefaultEvaluator(dc, domDoc);
149 ResultSequence rs = eval.evaluate(path);
150
151 XSBoolean result = (XSBoolean) rs.first();
152
153 String actual = result.string_value();
154
155 assertEquals("true", actual);
156 }
dacarver6c9a7722009-05-24 01:16:07 +0000157
dacarver84e43f52009-04-28 19:25:30 +0000158 public void testBug273795Arity3() throws Exception {
159 // Bug 273795
160 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
161 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000162
dacarver84e43f52009-04-28 19:25:30 +0000163 // Get XML Schema Information for the Document
164 XSModel schema = getGrammar();
165
166 DynamicContext dc = setupDynamicContext(schema);
167
168 // test with arity 3
169 String xpath = "substring(x, 3, 4) = 'happ'";
170 XPath path = compileXPath(dc, xpath);
171
172 Evaluator eval = new DefaultEvaluator(dc, domDoc);
173 ResultSequence rs = eval.evaluate(path);
174
175 XSBoolean result = (XSBoolean) rs.first();
176
177 String actual = result.string_value();
178
179 assertEquals("true", actual);
180 }
dacarver6c9a7722009-05-24 01:16:07 +0000181
dacarver2b291392009-05-23 00:47:49 +0000182 public void testStringFunctionBug274471() throws Exception {
183 // Bug 274471
184 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
185 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000186
dacarver2b291392009-05-23 00:47:49 +0000187 // Get XML Schema Information for the Document
188 XSModel schema = getGrammar();
189
190 DynamicContext dc = setupDynamicContext(schema);
191
192 String xpath = "x/string() = 'unhappy'";
193 XPath path = compileXPath(dc, xpath);
194
195 Evaluator eval = new DefaultEvaluator(dc, domDoc);
196 ResultSequence rs = eval.evaluate(path);
197
198 XSBoolean result = (XSBoolean) rs.first();
199
200 String actual = result.string_value();
201
202 assertEquals("true", actual);
203 }
dacarver6c9a7722009-05-24 01:16:07 +0000204
dacarver2b291392009-05-23 00:47:49 +0000205 public void testStringLengthFunctionBug274471() throws Exception {
206 // Bug 274471. string-length() with arity 0
207 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
208 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000209
dacarver2b291392009-05-23 00:47:49 +0000210 // Get XML Schema Information for the Document
211 XSModel schema = getGrammar();
212
213 DynamicContext dc = setupDynamicContext(schema);
214
215 String xpath = "x/string-length() = 7";
216 XPath path = compileXPath(dc, xpath);
217
218 Evaluator eval = new DefaultEvaluator(dc, domDoc);
219 ResultSequence rs = eval.evaluate(path);
220
221 XSBoolean result = (XSBoolean) rs.first();
222
223 String actual = result.string_value();
224
dacarver9bffb272009-09-03 01:28:58 +0000225 assertEquals("false", actual);
dacarver2b291392009-05-23 00:47:49 +0000226 }
dacarver6c9a7722009-05-24 01:16:07 +0000227
dacarver2b291392009-05-23 00:47:49 +0000228 public void testNormalizeSpaceFunctionBug274471() throws Exception {
229 // Bug 274471. normalize-space() with arity 0
230 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
231 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000232
dacarver2b291392009-05-23 00:47:49 +0000233 // Get XML Schema Information for the Document
234 XSModel schema = getGrammar();
235
236 DynamicContext dc = setupDynamicContext(schema);
237
238 String xpath = "x/normalize-space() = 'unhappy'";
239 XPath path = compileXPath(dc, xpath);
240
241 Evaluator eval = new DefaultEvaluator(dc, domDoc);
242 ResultSequence rs = eval.evaluate(path);
243
244 XSBoolean result = (XSBoolean) rs.first();
245
246 String actual = result.string_value();
247
248 assertEquals("true", actual);
249 }
dacarver6c9a7722009-05-24 01:16:07 +0000250
dacarver9cd5a342009-05-23 01:05:06 +0000251 public void testAnyUriEqualityBug() throws Exception {
252 // Bug 274719
253 // reusing the XML document from another bug
254 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
255 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000256
dacarver9cd5a342009-05-23 01:05:06 +0000257 // Get XML Schema Information for the Document
258 XSModel schema = getGrammar();
259
260 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000261
dacarver9cd5a342009-05-23 01:05:06 +0000262 String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')";
263 XPath path = compileXPath(dc, xpath);
264
265 Evaluator eval = new DefaultEvaluator(dc, domDoc);
266 ResultSequence rs = eval.evaluate(path);
267
268 XSBoolean result = (XSBoolean) rs.first();
269
270 String actual = result.string_value();
271
272 assertEquals("true", actual);
273 }
274
dacarverf585d0c2009-05-23 01:13:44 +0000275 public void testBaseUriBug() throws Exception {
dacarver2915e2f2009-06-09 14:41:36 +0000276 // Bug 274725
dacarver6c9a7722009-05-24 01:16:07 +0000277
dacarver23c40122009-11-13 23:26:23 +0000278 // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
279 // DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000280 loadDOMDocument(new URL("http://resolved-locally/xml/note.xml"));
dacarver6c9a7722009-05-24 01:16:07 +0000281
282 // for testing this bug, we read the XML document from the web.
dacarverf585d0c2009-05-23 01:13:44 +0000283 // this ensures, that base-uri property of DOM is not null.
jmolleref1b2b42010-08-12 10:33:28 +0000284 // domDoc = docBuilder.parse("http://resolved-locally/xml/note.xml");
dacarverf585d0c2009-05-23 01:13:44 +0000285
286 // we pass XSModel as null for this test case. Otherwise, we would
287 // get an exception.
288 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000289
jmolleref1b2b42010-08-12 10:33:28 +0000290 String xpath = "base-uri(note) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000291
292 // please note: The below XPath would also work, with base-uri using
293 // arity 0.
294 // String xpath =
jmolleref1b2b42010-08-12 10:33:28 +0000295 // "note/base-uri() eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000296
dacarverf585d0c2009-05-23 01:13:44 +0000297 XPath path = compileXPath(dc, xpath);
298
299 Evaluator eval = new DefaultEvaluator(dc, domDoc);
300 ResultSequence rs = eval.evaluate(path);
301
302 XSBoolean result = (XSBoolean) rs.first();
303
304 String actual = result.string_value();
305
dacarveracf5e122009-08-05 02:48:43 +0000306 assertEquals("true", actual);
dacarverf585d0c2009-05-23 01:13:44 +0000307 }
dacarverf79d73e2009-05-23 01:28:16 +0000308
309 public void testDocumentUriBug() throws Exception {
310 // Bug 274731
311 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
312 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000313
314 InputSource inputSource = getTestSource("http://resolved-locally/xml/note.xml");
315 domDoc = docBuilder.parse(inputSource);
dacarverf79d73e2009-05-23 01:28:16 +0000316
317 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000318
jmolleref1b2b42010-08-12 10:33:28 +0000319 String xpath = "document-uri(/) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000320
dacarverf79d73e2009-05-23 01:28:16 +0000321 XPath path = compileXPath(dc, xpath);
322
323 Evaluator eval = new DefaultEvaluator(dc, domDoc);
324 ResultSequence rs = eval.evaluate(path);
325
326 XSBoolean result = (XSBoolean) rs.first();
327
328 String actual = "false";
dacarver6c9a7722009-05-24 01:16:07 +0000329
dacarverf79d73e2009-05-23 01:28:16 +0000330 if (result != null) {
dacarver6c9a7722009-05-24 01:16:07 +0000331 actual = result.string_value();
dacarverf79d73e2009-05-23 01:28:16 +0000332 }
333
334 assertEquals("true", actual);
335 }
dacarver6c9a7722009-05-24 01:16:07 +0000336
dacarver2b291392009-05-23 00:47:49 +0000337 public void testBooleanTypeBug() throws Exception {
338 // Bug 274784
339 // reusing the XML document from another bug
340 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
341 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000342
dacarver2b291392009-05-23 00:47:49 +0000343 // Get XML Schema Information for the Document
344 XSModel schema = getGrammar();
345
346 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000347
dacarver2b291392009-05-23 00:47:49 +0000348 String xpath = "xs:boolean('1') eq xs:boolean('true')";
349 XPath path = compileXPath(dc, xpath);
350
351 Evaluator eval = new DefaultEvaluator(dc, domDoc);
352 ResultSequence rs = eval.evaluate(path);
353
354 XSBoolean result = (XSBoolean) rs.first();
355
356 String actual = result.string_value();
357
358 assertEquals("true", actual);
359 }
dacarver879c37a2009-04-26 23:41:32 +0000360
dacarver1d62b032009-05-23 01:39:15 +0000361 public void testDateConstructorBug() throws Exception {
362 // Bug 274792
363 URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml");
364 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000365
dacarver1d62b032009-05-23 01:39:15 +0000366 // Get XML Schema Information for the Document
367 XSModel schema = getGrammar();
368
369 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000370
dacarver1d62b032009-05-23 01:39:15 +0000371 String xpath = "xs:date(x) eq xs:date('2009-01-01')";
372 XPath path = compileXPath(dc, xpath);
373
374 Evaluator eval = new DefaultEvaluator(dc, domDoc);
375 ResultSequence rs = eval.evaluate(path);
376
377 XSBoolean result = (XSBoolean) rs.first();
378
379 String actual = result.string_value();
380
381 assertEquals("true", actual);
382 }
dacarver6c9a7722009-05-24 01:16:07 +0000383
dacarver41c7f742009-05-23 02:10:24 +0000384 public void testIntegerDataTypeBug() throws Exception {
385 // Bug 274805
386 URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml");
387 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000388
dacarver41c7f742009-05-23 02:10:24 +0000389 // Get XML Schema Information for the Document
390 XSModel schema = getGrammar();
391
392 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000393
dacarver41c7f742009-05-23 02:10:24 +0000394 String xpath = "xs:integer(x) gt 100";
395 XPath path = compileXPath(dc, xpath);
396
397 Evaluator eval = new DefaultEvaluator(dc, domDoc);
398 ResultSequence rs = eval.evaluate(path);
399
400 XSBoolean result = (XSBoolean) rs.first();
401
402 String actual = result.string_value();
403
404 assertEquals("true", actual);
dacarver6c9a7722009-05-24 01:16:07 +0000405 }
dacarver47328e82009-05-23 02:22:26 +0000406
407 public void testLongDataType() throws Exception {
408 // Bug 274952
dacarver23c40122009-11-13 23:26:23 +0000409 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver47328e82009-05-23 02:22:26 +0000410 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
411 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000412
dacarver47328e82009-05-23 02:22:26 +0000413 // Get XML Schema Information for the Document
414 XSModel schema = getGrammar();
415
416 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000417
dacarver47328e82009-05-23 02:22:26 +0000418 // long min value is -9223372036854775808
419 // and max value can be 9223372036854775807
420 String xpath = "xs:long('9223372036854775807') gt 0";
421 XPath path = compileXPath(dc, xpath);
422
423 Evaluator eval = new DefaultEvaluator(dc, domDoc);
424 ResultSequence rs = eval.evaluate(path);
425
426 XSBoolean result = (XSBoolean) rs.first();
427
428 String actual = result.string_value();
429
430 assertEquals("true", actual);
431 }
dacarver6c9a7722009-05-24 01:16:07 +0000432
dacarver10f28f12009-05-23 02:35:22 +0000433 public void testIntDataType() throws Exception {
434 // Bug 275105
dacarver23c40122009-11-13 23:26:23 +0000435 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver10f28f12009-05-23 02:35:22 +0000436 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
437 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000438
dacarver10f28f12009-05-23 02:35:22 +0000439 // Get XML Schema Information for the Document
440 XSModel schema = getGrammar();
441
442 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000443
dacarver10f28f12009-05-23 02:35:22 +0000444 // int min value is -2147483648
445 // and max value can be 2147483647
446 String xpath = "xs:int('2147483647') gt 0";
447 XPath path = compileXPath(dc, xpath);
448
449 Evaluator eval = new DefaultEvaluator(dc, domDoc);
450 ResultSequence rs = eval.evaluate(path);
451
452 XSBoolean result = (XSBoolean) rs.first();
453
454 String actual = result.string_value();
455
456 assertEquals("true", actual);
457 }
dacarver6c9a7722009-05-24 01:16:07 +0000458
459 public void testSchemaAwarenessForAttributes() throws Exception {
460 // Bug 276134
461 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
462 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
463
464 loadDOMDocument(fileURL, schemaURL);
465
466 // Get XSModel object for the Schema
467 XSModel schema = getGrammar(schemaURL);
468
469 DynamicContext dc = setupDynamicContext(schema);
470
471 String xpath = "person/@dob eq xs:date('2006-12-10')";
472 XPath path = compileXPath(dc, xpath);
473
474 Evaluator eval = new DefaultEvaluator(dc, domDoc);
475 ResultSequence rs = eval.evaluate(path);
476
477 XSBoolean result = (XSBoolean) rs.first();
478
479 String actual = result.string_value();
480
481 assertEquals("true", actual);
482
483 }
484
485 public void testSchemaAwarenessForElements() throws Exception {
486 // Bug 276134
487 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml");
488 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd");
489
490 loadDOMDocument(fileURL, schemaURL);
491
492 // Get XSModel object for the Schema
493 XSModel schema = getGrammar(schemaURL);
494
495 DynamicContext dc = setupDynamicContext(schema);
496
497 String xpath = "person/dob eq xs:date('2006-12-10')";
498 XPath path = compileXPath(dc, xpath);
499
500 Evaluator eval = new DefaultEvaluator(dc, domDoc);
501 ResultSequence rs = eval.evaluate(path);
502
503 XSBoolean result = (XSBoolean) rs.first();
504
505 String actual = result.string_value();
506
507 assertEquals("true", actual);
508 }
dacarver5f7e5d12009-06-09 14:30:40 +0000509
jmolleraaedb5f2009-12-16 14:18:49 +0000510 public void testNilled() throws Exception {
511 // This is a terrible shortcoming in the test suite, I'd say
512 URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml");
513 URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd");
514
515 loadDOMDocument(fileURL, schemaURL);
516
517 // Get XSModel object for the Schema
518 XSModel schema = getGrammar(schemaURL);
519
520 DynamicContext dc = setupDynamicContext(schema);
521
522 assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )"));
523 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )"));
524 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )"));
525
526 assertFalse(evaluateBoolean(dc, "nilled(/root/element1)"));
527 assertTrue(evaluateBoolean(dc, "nilled(/root/element2)"));
528 assertFalse(evaluateBoolean(dc, "nilled(/root/element3)"));
529 assertFalse(evaluateBoolean(dc, "nilled(/root/element4)"));
530 }
531
532 // I can't stand to see so much duplicated code!!!
533 private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception {
534 XPath path = compileXPath(dc, xpath);
535
536 Evaluator eval = new DefaultEvaluator(dc, domDoc);
537 ResultSequence rs = eval.evaluate(path);
538
539 XSBoolean result = (XSBoolean) rs.first();
540
541 return result.value();
542 }
543
dacarver9ebaa6f2009-05-25 03:16:50 +0000544 public void testXSNonPositiveInteger() throws Exception {
545 // Bug 277599
dacarver23c40122009-11-13 23:26:23 +0000546 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
547
dacarver9ebaa6f2009-05-25 03:16:50 +0000548 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
549 loadDOMDocument(fileURL);
550
551 // Get XML Schema Information for the Document
552 XSModel schema = getGrammar();
553
554 DynamicContext dc = setupDynamicContext(schema);
555
556 // min value of xs:nonPositiveInteger is -INF
557 // max value is 0
558 String xpath = "xs:nonPositiveInteger('0') eq 0";
559 XPath path = compileXPath(dc, xpath);
560
561 Evaluator eval = new DefaultEvaluator(dc, domDoc);
562 ResultSequence rs = eval.evaluate(path);
563
564 XSBoolean result = (XSBoolean) rs.first();
565
566 String actual = result.string_value();
567
568 assertEquals("true", actual);
569 }
dacarver5f7e5d12009-06-09 14:30:40 +0000570
dacarverca9bc132009-05-25 03:31:41 +0000571 public void testXSNegativeInteger() throws Exception {
572 // Bug 277602
dacarver23c40122009-11-13 23:26:23 +0000573 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
574
dacarverca9bc132009-05-25 03:31:41 +0000575 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
576 loadDOMDocument(fileURL);
577
578 // Get XML Schema Information for the Document
579 XSModel schema = getGrammar();
580
581 DynamicContext dc = setupDynamicContext(schema);
582
583 // min value of xs:negativeInteger is -INF
584 // max value is -1
585 String xpath = "xs:negativeInteger('-1') eq -1";
586 XPath path = compileXPath(dc, xpath);
587
588 Evaluator eval = new DefaultEvaluator(dc, domDoc);
589 ResultSequence rs = eval.evaluate(path);
590
591 XSBoolean result = (XSBoolean) rs.first();
592
593 String actual = result.string_value();
594
595 assertEquals("true", actual);
596 }
dacarver5f7e5d12009-06-09 14:30:40 +0000597
dacarver72e78ba2009-05-25 03:40:46 +0000598 public void testXSShort() throws Exception {
599 // Bug 277608
dacarver23c40122009-11-13 23:26:23 +0000600 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000601
dacarver72e78ba2009-05-25 03:40:46 +0000602 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
603 loadDOMDocument(fileURL);
604
605 // Get XML Schema Information for the Document
606 XSModel schema = getGrammar();
607
608 DynamicContext dc = setupDynamicContext(schema);
609
610 // min value of xs:short is -32768
611 // max value of xs:short is 32767
612 String xpath = "xs:short('-32768') eq -32768";
613 XPath path = compileXPath(dc, xpath);
614
615 Evaluator eval = new DefaultEvaluator(dc, domDoc);
616 ResultSequence rs = eval.evaluate(path);
617
618 XSBoolean result = (XSBoolean) rs.first();
619
620 String actual = result.string_value();
621
622 assertEquals("true", actual);
623 }
dacarver5f7e5d12009-06-09 14:30:40 +0000624
dacarver1bb092e2009-05-25 04:02:48 +0000625 public void testXSNonNegativeInteger() throws Exception {
626 // Bug 277609
dacarver23c40122009-11-13 23:26:23 +0000627 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000628
dacarver1bb092e2009-05-25 04:02:48 +0000629 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
630 loadDOMDocument(fileURL);
631
632 // Get XML Schema Information for the Document
633 XSModel schema = getGrammar();
634
635 DynamicContext dc = setupDynamicContext(schema);
636
637 // min value of xs:nonNegativeInteger is 0
638 // max value of xs:nonNegativeInteger is INF
639 String xpath = "xs:nonNegativeInteger('0') eq 0";
640 XPath path = compileXPath(dc, xpath);
641
642 Evaluator eval = new DefaultEvaluator(dc, domDoc);
643 ResultSequence rs = eval.evaluate(path);
644
645 XSBoolean result = (XSBoolean) rs.first();
646
647 String actual = result.string_value();
648
649 assertEquals("true", actual);
650 }
dacarver5f7e5d12009-06-09 14:30:40 +0000651
dacarverc9ccc722009-05-25 04:21:43 +0000652 public void testXSUnsignedLong() throws Exception {
653 // Bug 277629
dacarver23c40122009-11-13 23:26:23 +0000654 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000655
dacarverc9ccc722009-05-25 04:21:43 +0000656 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
657 loadDOMDocument(fileURL);
658
659 // Get XML Schema Information for the Document
660 XSModel schema = getGrammar();
661
662 DynamicContext dc = setupDynamicContext(schema);
663
664 // min value of xs:unsignedLong is 0
665 // max value of xs:unsignedLong is 18446744073709551615
666 String xpath = "xs:unsignedLong('0') eq 0";
667 XPath path = compileXPath(dc, xpath);
668
669 Evaluator eval = new DefaultEvaluator(dc, domDoc);
670 ResultSequence rs = eval.evaluate(path);
671
672 XSBoolean result = (XSBoolean) rs.first();
673
674 String actual = result.string_value();
675
676 assertEquals("true", actual);
677 }
dacarver5f7e5d12009-06-09 14:30:40 +0000678
dacarvercde26452009-05-25 22:48:28 +0000679 public void testXSPositiveInteger() throws Exception {
680 // Bug 277632
dacarver23c40122009-11-13 23:26:23 +0000681 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000682
dacarvercde26452009-05-25 22:48:28 +0000683 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
684 loadDOMDocument(fileURL);
685
686 // Get XML Schema Information for the Document
687 XSModel schema = getGrammar();
688
689 DynamicContext dc = setupDynamicContext(schema);
690
691 // min value of xs:positiveInteger is 1
692 // max value of xs:positiveInteger is INF
693 String xpath = "xs:positiveInteger('1') eq 1";
694 XPath path = compileXPath(dc, xpath);
695
696 Evaluator eval = new DefaultEvaluator(dc, domDoc);
697 ResultSequence rs = eval.evaluate(path);
698
699 XSBoolean result = (XSBoolean) rs.first();
700
701 String actual = result.string_value();
702
703 assertEquals("true", actual);
704 }
dacarver5f7e5d12009-06-09 14:30:40 +0000705
dacarver2673f012009-05-25 23:08:56 +0000706 public void testXSByte() throws Exception {
707 // Bug 277639
dacarver23c40122009-11-13 23:26:23 +0000708 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000709
dacarver2673f012009-05-25 23:08:56 +0000710 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
711 loadDOMDocument(fileURL);
712
713 // Get XML Schema Information for the Document
714 XSModel schema = getGrammar();
715
716 DynamicContext dc = setupDynamicContext(schema);
717
718 // min value of xs:byte is -128
719 // max value of xs:byte is 127
720 String xpath = "xs:byte('-128') eq -128";
721 XPath path = compileXPath(dc, xpath);
722
723 Evaluator eval = new DefaultEvaluator(dc, domDoc);
724 ResultSequence rs = eval.evaluate(path);
725
726 XSBoolean result = (XSBoolean) rs.first();
727
728 String actual = result.string_value();
729
730 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000731 }
732
dacarver28cff4b2009-05-25 23:19:36 +0000733 public void testXSUnsignedInt() throws Exception {
734 // Bug 277642
dacarver23c40122009-11-13 23:26:23 +0000735 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000736
dacarver28cff4b2009-05-25 23:19:36 +0000737 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
738 loadDOMDocument(fileURL);
739
740 // Get XML Schema Information for the Document
741 XSModel schema = getGrammar();
742
743 DynamicContext dc = setupDynamicContext(schema);
744
745 // min value of xs:unsignedInt is 0
746 // max value of xs:unsignedInt is 4294967295
747 String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')";
748 XPath path = compileXPath(dc, xpath);
749
750 Evaluator eval = new DefaultEvaluator(dc, domDoc);
751 ResultSequence rs = eval.evaluate(path);
752
753 XSBoolean result = (XSBoolean) rs.first();
754
755 String actual = result.string_value();
756
757 assertEquals("true", actual);
dacarver2673f012009-05-25 23:08:56 +0000758 }
dacarver5f7e5d12009-06-09 14:30:40 +0000759
dacarver3cc95782009-05-25 23:33:47 +0000760 public void testXSUnsignedShort() throws Exception {
761 // Bug 277645
dacarver23c40122009-11-13 23:26:23 +0000762 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver3cc95782009-05-25 23:33:47 +0000763 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
764 loadDOMDocument(fileURL);
765
766 // Get XML Schema Information for the Document
767 XSModel schema = getGrammar();
768
769 DynamicContext dc = setupDynamicContext(schema);
770
771 // min value of xs:unsignedShort is 0
772 // max value of xs:unsignedShort is 65535
773 String xpath = "xs:unsignedShort('65535') eq 65535";
774 XPath path = compileXPath(dc, xpath);
775
776 Evaluator eval = new DefaultEvaluator(dc, domDoc);
777 ResultSequence rs = eval.evaluate(path);
778
779 XSBoolean result = (XSBoolean) rs.first();
780
781 String actual = result.string_value();
782
783 assertEquals("true", actual);
784 }
dacarver23c40122009-11-13 23:26:23 +0000785
dacarvered2c87e2009-06-09 14:54:33 +0000786 public void testXSYearMonthDurationMultiply() throws Exception {
787 // Bug 279373
dacarver23c40122009-11-13 23:26:23 +0000788 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver68d6e6c2009-05-25 23:43:42 +0000789 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
790 loadDOMDocument(fileURL);
791
792 // Get XML Schema Information for the Document
793 XSModel schema = getGrammar();
794
795 DynamicContext dc = setupDynamicContext(schema);
796
dacarvered2c87e2009-06-09 14:54:33 +0000797 String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3";
dacarver68d6e6c2009-05-25 23:43:42 +0000798 XPath path = compileXPath(dc, xpath);
799
800 Evaluator eval = new DefaultEvaluator(dc, domDoc);
801 ResultSequence rs = eval.evaluate(path);
802
dacarverae395262009-07-02 04:30:16 +0000803 XSDuration result = (XSDuration) rs.first();
dacarver68d6e6c2009-05-25 23:43:42 +0000804
805 String actual = result.string_value();
806
dacarvered2c87e2009-06-09 14:54:33 +0000807 assertEquals("P6Y9M", actual);
dacarver68d6e6c2009-05-25 23:43:42 +0000808 }
dacarver23c40122009-11-13 23:26:23 +0000809
dacarvered2c87e2009-06-09 14:54:33 +0000810 public void testXSYearMonthDurationDivide1() throws Exception {
811 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000812 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000813 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
814 loadDOMDocument(fileURL);
815
816 // Get XML Schema Information for the Document
817 XSModel schema = getGrammar();
818
819 DynamicContext dc = setupDynamicContext(schema);
820
821 String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5";
822 XPath path = compileXPath(dc, xpath);
823
824 Evaluator eval = new DefaultEvaluator(dc, domDoc);
825 ResultSequence rs = eval.evaluate(path);
826
dacarverae395262009-07-02 04:30:16 +0000827 XSDuration result = (XSDuration) rs.first();
dacarvered2c87e2009-06-09 14:54:33 +0000828
829 String actual = result.string_value();
830
831 assertEquals("P1Y11M", actual);
832 }
dacarver23c40122009-11-13 23:26:23 +0000833
dacarvered2c87e2009-06-09 14:54:33 +0000834 public void testXSYearMonthDurationDivide2() throws Exception {
835 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000836 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000837 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
838 loadDOMDocument(fileURL);
839
840 // Get XML Schema Information for the Document
841 XSModel schema = getGrammar();
842
843 DynamicContext dc = setupDynamicContext(schema);
844
845 String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')";
846 XPath path = compileXPath(dc, xpath);
847
848 Evaluator eval = new DefaultEvaluator(dc, domDoc);
849 ResultSequence rs = eval.evaluate(path);
850
851 XSDecimal result = (XSDecimal) rs.first();
852
853 String actual = result.string_value();
854
855 assertEquals("-2.5", actual);
856 }
dacarver23c40122009-11-13 23:26:23 +0000857
dacarver2915e2f2009-06-09 14:41:36 +0000858 public void testXSDayTimeDurationMultiply() throws Exception {
859 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000860 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000861 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
862 loadDOMDocument(fileURL);
863
864 // Get XML Schema Information for the Document
865 XSModel schema = getGrammar();
866
867 DynamicContext dc = setupDynamicContext(schema);
868
869 String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1";
870 XPath path = compileXPath(dc, xpath);
871
872 Evaluator eval = new DefaultEvaluator(dc, domDoc);
873 ResultSequence rs = eval.evaluate(path);
874
dacarverae395262009-07-02 04:30:16 +0000875 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000876
877 String actual = result.string_value();
878
879 assertEquals("PT4H33M", actual);
880 }
dacarver23c40122009-11-13 23:26:23 +0000881
dacarver2915e2f2009-06-09 14:41:36 +0000882 public void testXSDayTimeDurationDivide() throws Exception {
883 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000884 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000885 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
886 loadDOMDocument(fileURL);
887
888 // Get XML Schema Information for the Document
889 XSModel schema = getGrammar();
890
891 DynamicContext dc = setupDynamicContext(schema);
892
893 String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5";
894 XPath path = compileXPath(dc, xpath);
895
896 Evaluator eval = new DefaultEvaluator(dc, domDoc);
897 ResultSequence rs = eval.evaluate(path);
898
dacarverae395262009-07-02 04:30:16 +0000899 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000900
901 String actual = result.string_value();
902
903 assertEquals("PT17H40M7S", actual);
904 }
dacarver23c40122009-11-13 23:26:23 +0000905
dacarvered2c87e2009-06-09 14:54:33 +0000906 public void testNegativeZeroDouble() throws Exception {
907 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000908 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver76b66582009-06-09 14:08:05 +0000909 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
910 loadDOMDocument(fileURL);
911
912 // Get XML Schema Information for the Document
913 XSModel schema = getGrammar();
914
915 DynamicContext dc = setupDynamicContext(schema);
916
dacarvered2c87e2009-06-09 14:54:33 +0000917 String xpath = "-(xs:double('0'))";
dacarver76b66582009-06-09 14:08:05 +0000918 XPath path = compileXPath(dc, xpath);
919
920 Evaluator eval = new DefaultEvaluator(dc, domDoc);
921 ResultSequence rs = eval.evaluate(path);
922
dacarvered2c87e2009-06-09 14:54:33 +0000923 XSDouble result = (XSDouble) rs.first();
dacarver76b66582009-06-09 14:08:05 +0000924
925 String actual = result.string_value();
926
dacarvered2c87e2009-06-09 14:54:33 +0000927 assertEquals("-0", actual);
dacarver76b66582009-06-09 14:08:05 +0000928 }
dacarver23c40122009-11-13 23:26:23 +0000929
dacarvered2c87e2009-06-09 14:54:33 +0000930 public void testNegativeZeroFloat() throws Exception {
931 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000932 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000933 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
934 loadDOMDocument(fileURL);
935
936 // Get XML Schema Information for the Document
937 XSModel schema = getGrammar();
938
939 DynamicContext dc = setupDynamicContext(schema);
940
dacarvered2c87e2009-06-09 14:54:33 +0000941 String xpath = "-(xs:float('0'))";
dacarver5f7e5d12009-06-09 14:30:40 +0000942 XPath path = compileXPath(dc, xpath);
943
944 Evaluator eval = new DefaultEvaluator(dc, domDoc);
945 ResultSequence rs = eval.evaluate(path);
dacarvered2c87e2009-06-09 14:54:33 +0000946
947 XSFloat result = (XSFloat) rs.first();
948
dacarver5f7e5d12009-06-09 14:30:40 +0000949 String actual = result.string_value();
950
dacarvered2c87e2009-06-09 14:54:33 +0000951 assertEquals("-0", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000952 }
953
dacarvered2c87e2009-06-09 14:54:33 +0000954 public void testXSUnsignedByte() throws Exception {
955 // Bug 277650
dacarver23c40122009-11-13 23:26:23 +0000956 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000957 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
958 loadDOMDocument(fileURL);
959
960 // Get XML Schema Information for the Document
dacarver5f7e5d12009-06-09 14:30:40 +0000961 XSModel schema = getGrammar();
dacarver5f7e5d12009-06-09 14:30:40 +0000962
dacarvered2c87e2009-06-09 14:54:33 +0000963 DynamicContext dc = setupDynamicContext(schema);
964
965 // min value of xs:unsignedByte is 0
966 // max value of xs:unsignedByte is 255
967 String xpath = "xs:unsignedByte('255') eq 255";
dacarver5f7e5d12009-06-09 14:30:40 +0000968 XPath path = compileXPath(dc, xpath);
dacarvered2c87e2009-06-09 14:54:33 +0000969
dacarver5f7e5d12009-06-09 14:30:40 +0000970 Evaluator eval = new DefaultEvaluator(dc, domDoc);
971 ResultSequence rs = eval.evaluate(path);
972
dacarvered2c87e2009-06-09 14:54:33 +0000973 XSBoolean result = (XSBoolean) rs.first();
dacarver5f7e5d12009-06-09 14:30:40 +0000974
975 String actual = result.string_value();
976
dacarvered2c87e2009-06-09 14:54:33 +0000977 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000978 }
dacarver23c40122009-11-13 23:26:23 +0000979
dacarver9cfaa8e2009-06-22 21:37:15 +0000980 public void testXSBase64Binary() throws Exception {
981 // Bug 281046
dacarver23c40122009-11-13 23:26:23 +0000982 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver9cfaa8e2009-06-22 21:37:15 +0000983 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
984 loadDOMDocument(fileURL);
985
986 // Get XML Schema Information for the Document
987 XSModel schema = getGrammar();
988
989 DynamicContext dc = setupDynamicContext(schema);
990
991 String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')";
992 XPath path = compileXPath(dc, xpath);
993
994 Evaluator eval = new DefaultEvaluator(dc, domDoc);
995 ResultSequence rs = eval.evaluate(path);
996
997 XSBoolean result = (XSBoolean) rs.first();
998
999 String actual = result.string_value();
1000
1001 assertEquals("true", actual);
1002 }
dacarver23c40122009-11-13 23:26:23 +00001003
dacarver6018fcf2009-06-22 21:47:53 +00001004 public void testXSHexBinary() throws Exception {
1005 // Bug 281054
dacarver23c40122009-11-13 23:26:23 +00001006 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver6018fcf2009-06-22 21:47:53 +00001007 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1008 loadDOMDocument(fileURL);
1009
1010 // Get XML Schema Information for the Document
1011 XSModel schema = getGrammar();
1012
1013 DynamicContext dc = setupDynamicContext(schema);
1014
1015 String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')";
1016 XPath path = compileXPath(dc, xpath);
1017
1018 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1019 ResultSequence rs = eval.evaluate(path);
1020
1021 XSBoolean result = (XSBoolean) rs.first();
1022
1023 String actual = result.string_value();
1024
1025 assertEquals("true", actual);
1026 }
dacarver23c40122009-11-13 23:26:23 +00001027
mgandhiefe95742009-08-18 04:12:11 +00001028 public void testElementTypedValue() throws Exception {
1029 // test for fix in ElementType.java, involving incorrectly computing
1030 // typed value of element node, in case of validating element node,
1031 // with a user defined simple XSD type.
1032 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
dacarver23c40122009-11-13 23:26:23 +00001033 URL schemaURL = bundle
1034 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
mgandhiefe95742009-08-18 04:12:11 +00001035
1036 loadDOMDocument(fileURL, schemaURL);
1037
1038 // Get XSModel object for the Schema
1039 XSModel schema = getGrammar(schemaURL);
1040
1041 DynamicContext dc = setupDynamicContext(schema);
1042
1043 String xpath = "Example/Transportation/mode eq 'air'";
1044 XPath path = compileXPath(dc, xpath);
1045
1046 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1047 ResultSequence rs = eval.evaluate(path);
1048
1049 XSBoolean result = (XSBoolean) rs.first();
1050
1051 String actual = result.string_value();
1052
1053 assertEquals("true", actual);
1054
1055 }
dacarverf9402792009-08-22 01:14:10 +00001056
dacarver23c40122009-11-13 23:26:23 +00001057 public void testBug286061_quoted_string_literals_no_normalize()
1058 throws Exception {
dacarverf9402792009-08-22 01:14:10 +00001059
dacarver23c40122009-11-13 23:26:23 +00001060 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001061 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1062 loadDOMDocument(fileURL);
1063
1064 // Get XML Schema Information for the Document
1065 XSModel schema = getGrammar();
1066
1067 DynamicContext dc = setupDynamicContext(schema);
1068
dacarver23c40122009-11-13 23:26:23 +00001069 String xpath = "'\"\"'"; // the expression '""' contains no escapes
dacarverf9402792009-08-22 01:14:10 +00001070
1071 XPath path = compileXPath(dc, xpath);
1072
1073 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1074 ResultSequence rs = eval.evaluate(path);
1075
1076 String resultValue = rs.first().string_value();
1077
1078 assertEquals("\"\"", resultValue);
1079 }
dacarver23c40122009-11-13 23:26:23 +00001080
dacarverf9402792009-08-22 01:14:10 +00001081 public void testBug286061_quoted_string_literals() throws Exception {
1082
dacarver23c40122009-11-13 23:26:23 +00001083 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001084 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1085 loadDOMDocument(fileURL);
1086
1087 // Get XML Schema Information for the Document
1088 XSModel schema = getGrammar();
1089
1090 DynamicContext dc = setupDynamicContext(schema);
1091
1092 String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )";
1093
1094 XPath path = compileXPath(dc, xpath);
1095
1096 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1097 ResultSequence rs = eval.evaluate(path);
1098
1099 String resultValue = rs.first().string_value();
1100
1101 assertEquals("Don't try this at \"home\", she said", resultValue);
1102 }
1103
jmollerb601eb02009-09-02 20:21:06 +00001104 public void testBug280555_collations() throws Exception {
1105 // Setup context
1106 DefaultDynamicContext dc = setupDynamicContext(null);
1107 dc.set_collation_provider(createLengthCollatorProvider());
1108 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1109
1110 // Parse expression
1111 XPath path = compileXPath(dc, " 'abc' < 'de' ");
1112
1113 // Evaluate once
1114 XSBoolean bval = (XSBoolean) eval.evaluate(path).first();
1115 assertTrue("'abc' < 'def' for normal collations", bval.value());
dacarver23c40122009-11-13 23:26:23 +00001116
jmollerb601eb02009-09-02 20:21:06 +00001117 // Evaluate again with the funny collator
1118 dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR);
1119 XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first();
1120 assertFalse("'abc' < 'def' for normal collations", bval2.value());
dacarver23c40122009-11-13 23:26:23 +00001121 }
1122
mgandhiae92c592009-09-19 12:58:06 +00001123 public void testXPathDefaultNamespace() throws Exception {
1124 // Test for the fix, for xpathDefaultNamespace
dacarver23c40122009-11-13 23:26:23 +00001125 URL fileURL = bundle
1126 .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml");
mgandhiae92c592009-09-19 12:58:06 +00001127 loadDOMDocument(fileURL);
1128
1129 // Get XML Schema Information for the Document
1130 XSModel schema = getGrammar();
1131
dacarver23c40122009-11-13 23:26:23 +00001132 // set up XPath default namespace in Dynamic Context
mgandhiae92c592009-09-19 12:58:06 +00001133 DynamicContext dc = setupDynamicContext(schema);
1134 addXPathDefaultNamespace("http://xyz");
1135
1136 String xpath = "X/message = 'hello'";
1137 XPath path = compileXPath(dc, xpath);
1138
1139 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1140 ResultSequence rs = eval.evaluate(path);
1141
1142 XSBoolean result = (XSBoolean) rs.first();
1143
1144 String actual = result.string_value();
1145
1146 assertEquals("true", actual);
1147 }
dacarver07849652009-11-28 00:09:27 +00001148
mgandhi80a468d2009-12-25 04:57:38 +00001149 public void testXPathInstanceOf1() throws Exception {
1150 // Bug 298267
1151 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1152 URL schemaURL = bundle
1153 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1154
1155 loadDOMDocument(fileURL, schemaURL);
1156
1157 // Get XSModel object for the Schema
1158 XSModel schema = getGrammar(schemaURL);
1159
1160 DynamicContext dc = setupDynamicContext(schema);
1161
1162 String xpath = "Example/Transportation/mode instance of element()";
1163 XPath path = compileXPath(dc, xpath);
1164
1165 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1166 ResultSequence rs = eval.evaluate(path);
1167
1168 XSBoolean result = (XSBoolean) rs.first();
1169
1170 String actual = result.string_value();
1171
1172 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001173 }
1174
1175 public void testXPathInstanceOf2() throws Exception {
1176 // Bug 298267
1177 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1178 URL schemaURL = bundle
1179 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1180
1181 loadDOMDocument(fileURL, schemaURL);
1182
1183 // Get XSModel object for the Schema
1184 XSModel schema = getGrammar(schemaURL);
1185
1186 DynamicContext dc = setupDynamicContext(schema);
1187
1188 String xpath = "Example/Transportation/mode instance of element(mode)";
1189 XPath path = compileXPath(dc, xpath);
1190
1191 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1192 ResultSequence rs = eval.evaluate(path);
1193
1194 XSBoolean result = (XSBoolean) rs.first();
1195
1196 String actual = result.string_value();
1197
1198 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001199 }
1200
mgandhi663fbd02009-12-27 11:23:35 +00001201 public void testXPathInstanceOf3() throws Exception {
mgandhi80a468d2009-12-25 04:57:38 +00001202 // Bug 298267
1203 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1204 URL schemaURL = bundle
1205 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1206
1207 loadDOMDocument(fileURL, schemaURL);
1208
1209 // Get XSModel object for the Schema
1210 XSModel schema = getGrammar(schemaURL);
1211
1212 DynamicContext dc = setupDynamicContext(schema);
1213
mgandhi663fbd02009-12-27 11:23:35 +00001214 String xpath = "Example/Transportation/mode instance of element(mode, modeType)";
mgandhi80a468d2009-12-25 04:57:38 +00001215 XPath path = compileXPath(dc, xpath);
1216
1217 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1218 ResultSequence rs = eval.evaluate(path);
1219
1220 XSBoolean result = (XSBoolean) rs.first();
1221
1222 String actual = result.string_value();
1223
dacarver5a6bbea2009-12-27 17:14:05 +00001224 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001225 }
1226
1227 public void testXPathInstanceOf4() throws Exception {
1228 // Bug 298267
1229 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1230 URL schemaURL = bundle
1231 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1232
1233 loadDOMDocument(fileURL, schemaURL);
1234
1235 // Get XSModel object for the Schema
1236 XSModel schema = getGrammar(schemaURL);
1237
1238 DynamicContext dc = setupDynamicContext(schema);
1239
1240 String xpath = "Example/Transportation/mode instance of element(mode, abc)";
1241 XPath path = compileXPath(dc, xpath);
1242
1243 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1244 ResultSequence rs = eval.evaluate(path);
1245
1246 XSBoolean result = (XSBoolean) rs.first();
1247
1248 String actual = result.string_value();
1249
1250 assertEquals("false", actual);
mgandhi247cdd82009-12-25 09:50:00 +00001251 }
1252
mgandhi663fbd02009-12-27 11:23:35 +00001253 public void testXPathInstanceOf5() throws Exception {
1254 // Bug 298267
1255 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1256 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1257
1258 loadDOMDocument(fileURL, schemaURL);
1259
1260 // Get XSModel object for the Schema
1261 XSModel schema = getGrammar(schemaURL);
1262
1263 DynamicContext dc = setupDynamicContext(schema);
1264
1265 String xpath = "Example/x instance of element(x, x_Type)*";
1266 XPath path = compileXPath(dc, xpath);
1267
1268 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1269 ResultSequence rs = eval.evaluate(path);
1270
1271 XSBoolean result = (XSBoolean) rs.first();
1272
1273 String actual = result.string_value();
1274
1275 assertEquals("true", actual);
1276 }
jmoller2c384ed2010-06-24 23:48:34 +00001277
1278 public void testXPathInstanceOf5_2() throws Exception {
1279 // Bug 298267
1280 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1281 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1282
1283 loadDOMDocument(fileURL, schemaURL);
1284
1285 // Get XSModel object for the Schema
1286 XSModel schema = getGrammar(schemaURL);
1287
1288 DynamicContext dc = setupDynamicContext(schema);
1289
1290 String xpath = "(/Example/x, /Example) instance of element(x, x_Type)+";
1291 XPath path = compileXPath(dc, xpath);
1292
1293 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1294 ResultSequence rs = eval.evaluate(path);
1295
1296 XSBoolean result = (XSBoolean) rs.first();
1297
1298 assertEquals(false, result.value());
1299 }
1300
1301 public void testXPathInstanceOf5_3() throws Exception {
1302 // Bug 298267
1303 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1304 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1305
1306 loadDOMDocument(fileURL, schemaURL);
1307
1308 // Get XSModel object for the Schema
1309 XSModel schema = getGrammar(schemaURL);
1310
1311 DynamicContext dc = setupDynamicContext(schema);
1312
1313 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)";
1314 XPath path = compileXPath(dc, xpath);
1315
1316 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1317 ResultSequence rs = eval.evaluate(path);
1318
1319 XSBoolean result = (XSBoolean) rs.first();
1320
1321 assertFalse(result.value());
1322 }
1323
1324 public void testXPathInstanceOf5_4() throws Exception {
1325 // Bug 298267
1326 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1327 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1328
1329 loadDOMDocument(fileURL, schemaURL);
1330
1331 // Get XSModel object for the Schema
1332 XSModel schema = getGrammar(schemaURL);
1333
1334 DynamicContext dc = setupDynamicContext(schema);
1335
1336 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)+";
1337 XPath path = compileXPath(dc, xpath);
1338
1339 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1340 ResultSequence rs = eval.evaluate(path);
1341
1342 XSBoolean result = (XSBoolean) rs.first();
1343
1344 assertTrue(result.value());
1345 }
1346
1347 public void testXPathInstanceOf5_5() throws Exception {
1348 // Bug 298267
1349 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1350 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1351
1352 loadDOMDocument(fileURL, schemaURL);
1353
1354 // Get XSModel object for the Schema
1355 XSModel schema = getGrammar(schemaURL);
1356
1357 DynamicContext dc = setupDynamicContext(schema);
1358
1359 String xpath = "(/Example/x instance of x_Type+) and (/Example/x[2]/@mesg instance of mesg_Type)";
1360 XPath path = compileXPath(dc, xpath);
1361
1362 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1363 ResultSequence rs = eval.evaluate(path);
1364
1365 XSBoolean result = (XSBoolean) rs.first();
1366
1367 assertEquals(true, result.value());
1368 }
1369
mgandhi663fbd02009-12-27 11:23:35 +00001370 public void testXPathInstanceOf6() throws Exception {
1371 // Bug 298267
1372 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1373 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1374
1375 loadDOMDocument(fileURL, schemaURL);
1376
1377 // Get XSModel object for the Schema
1378 XSModel schema = getGrammar(schemaURL);
1379
1380 DynamicContext dc = setupDynamicContext(schema);
1381
1382 String xpath = "Example/x instance of element(*, x_Type)*";
1383 XPath path = compileXPath(dc, xpath);
1384
1385 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1386 ResultSequence rs = eval.evaluate(path);
1387
1388 XSBoolean result = (XSBoolean) rs.first();
1389
1390 String actual = result.string_value();
1391
1392 assertEquals("true", actual);
1393 }
1394
1395 public void testXPathInstanceOf7() throws Exception {
1396 // Bug 298267
1397 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1398 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1399
1400 loadDOMDocument(fileURL, schemaURL);
1401
1402 // Get XSModel object for the Schema
1403 XSModel schema = getGrammar(schemaURL);
1404
1405 DynamicContext dc = setupDynamicContext(schema);
1406
1407 String xpath = "Example/x instance of element(x, x_Type)+";
1408 XPath path = compileXPath(dc, xpath);
1409
1410 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1411 ResultSequence rs = eval.evaluate(path);
1412
1413 XSBoolean result = (XSBoolean) rs.first();
1414
1415 String actual = result.string_value();
1416
dacarver3da20eb2009-12-29 14:29:45 +00001417 assertEquals("true", actual);
mgandhi663fbd02009-12-27 11:23:35 +00001418 }
1419
1420 public void testXPathInstanceNonExistantElement() throws Exception {
1421 // Bug 298267
1422 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1423 URL schemaURL = bundle
1424 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1425
1426 loadDOMDocument(fileURL, schemaURL);
1427
1428 // Get XSModel object for the Schema
1429 XSModel schema = getGrammar(schemaURL);
1430
1431 DynamicContext dc = setupDynamicContext(schema);
1432
1433 String xpath = "Example/Transportation/mode instance of element(x)";
1434 XPath path = compileXPath(dc, xpath);
1435
1436 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1437 ResultSequence rs = eval.evaluate(path);
1438
1439 XSBoolean result = (XSBoolean) rs.first();
1440
1441 String actual = result.string_value();
1442
1443 assertEquals("false", actual);
1444 }
1445
mgandhi247cdd82009-12-25 09:50:00 +00001446 public void testFnNumber_Evaluation1() throws Exception {
1447 // Bug 298519
1448 URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml");
1449 URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd");
mgandhi80a468d2009-12-25 04:57:38 +00001450
mgandhi247cdd82009-12-25 09:50:00 +00001451 loadDOMDocument(fileURL, schemaURL);
1452
1453 // Get XSModel object for the Schema
1454 XSModel schema = getGrammar(schemaURL);
1455
1456 DynamicContext dc = setupDynamicContext(schema);
1457
1458 String xpath = "number(Example/x) ge 18";
1459 XPath path = compileXPath(dc, xpath);
1460
1461 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1462 ResultSequence rs = eval.evaluate(path);
1463
1464 XSBoolean result = (XSBoolean) rs.first();
1465
1466 String actual = result.string_value();
1467
1468 assertEquals("true", actual);
1469 }
1470
1471 public void testFnNumber_Evaluation2() throws Exception {
1472 // Bug 298519
1473 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1474 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1475 loadDOMDocument(fileURL);
1476
1477 // Get XML Schema Information for the Document
1478 XSModel schema = getGrammar();
1479
1480 DynamicContext dc = setupDynamicContext(schema);
1481
1482 String xpath = "number(xs:unsignedByte('20')) ge 18";
1483 XPath path = compileXPath(dc, xpath);
1484
1485 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1486 ResultSequence rs = eval.evaluate(path);
1487
1488 XSBoolean result = (XSBoolean) rs.first();
1489
1490 String actual = result.string_value();
1491
1492 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001493 }
mgandhie02bf582009-12-26 13:17:14 +00001494
1495 public void testAttrNode_Test1() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001496 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001497 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1498 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1499
1500 loadDOMDocument(fileURL, schemaURL);
1501
1502 // Get XSModel object for the Schema
1503 XSModel schema = getGrammar(schemaURL);
1504
1505 DynamicContext dc = setupDynamicContext(schema);
1506
1507 String xpath = "Example/x[1]/@mesg instance of attribute()";
1508 XPath path = compileXPath(dc, xpath);
1509
1510 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1511 ResultSequence rs = eval.evaluate(path);
1512
1513 XSBoolean result = (XSBoolean) rs.first();
1514
1515 String actual = result.string_value();
1516
1517 assertEquals("true", actual);
1518 }
1519
1520 public void testAttrNode_Test2() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001521 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001522 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1523 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1524
1525 loadDOMDocument(fileURL, schemaURL);
1526
1527 // Get XSModel object for the Schema
1528 XSModel schema = getGrammar(schemaURL);
1529
1530 DynamicContext dc = setupDynamicContext(schema);
1531
1532 String xpath = "Example/x[1]/@mesg instance of attribute(xx)";
1533 XPath path = compileXPath(dc, xpath);
1534
1535 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1536 ResultSequence rs = eval.evaluate(path);
1537
1538 XSBoolean result = (XSBoolean) rs.first();
1539
1540 String actual = result.string_value();
1541
1542 assertEquals("false", actual);
1543 }
1544
1545 public void testAttrNode_Test3() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001546 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001547 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1548 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1549
1550 loadDOMDocument(fileURL, schemaURL);
1551
1552 // Get XSModel object for the Schema
1553 XSModel schema = getGrammar(schemaURL);
1554
1555 DynamicContext dc = setupDynamicContext(schema);
1556
1557 String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)";
1558 XPath path = compileXPath(dc, xpath);
1559
1560 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1561 ResultSequence rs = eval.evaluate(path);
1562
1563 XSBoolean result = (XSBoolean) rs.first();
1564
1565 String actual = result.string_value();
1566
1567 assertEquals("true", actual);
1568 }
1569
1570 public void testAttrNode_Test4() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001571 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001572 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1573 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1574
1575 loadDOMDocument(fileURL, schemaURL);
1576
1577 // Get XSModel object for the Schema
1578 XSModel schema = getGrammar(schemaURL);
1579
1580 DynamicContext dc = setupDynamicContext(schema);
1581
1582 String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)";
1583 XPath path = compileXPath(dc, xpath);
1584
1585 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1586 ResultSequence rs = eval.evaluate(path);
1587
1588 XSBoolean result = (XSBoolean) rs.first();
1589
1590 String actual = result.string_value();
1591
1592 assertEquals("false", actual);
1593 }
1594
1595 public void testAttrNode_Test5() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001596 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001597 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1598 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1599
1600 loadDOMDocument(fileURL, schemaURL);
1601
1602 // Get XSModel object for the Schema
1603 XSModel schema = getGrammar(schemaURL);
1604
1605 DynamicContext dc = setupDynamicContext(schema);
1606
1607 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)";
1608 XPath path = compileXPath(dc, xpath);
1609
1610 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1611 ResultSequence rs = eval.evaluate(path);
1612
1613 XSBoolean result = (XSBoolean) rs.first();
1614
1615 String actual = result.string_value();
1616
1617 assertEquals("true", actual);
1618 }
1619
1620 public void testAttrNode_Test6() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001621 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001622 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1623 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1624
1625 loadDOMDocument(fileURL, schemaURL);
1626
1627 // Get XSModel object for the Schema
1628 XSModel schema = getGrammar(schemaURL);
1629
1630 DynamicContext dc = setupDynamicContext(schema);
1631
1632 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)";
1633 XPath path = compileXPath(dc, xpath);
1634
1635 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1636 ResultSequence rs = eval.evaluate(path);
1637
1638 XSBoolean result = (XSBoolean) rs.first();
1639
1640 String actual = result.string_value();
1641
1642 assertEquals("false", actual);
1643 }
1644
1645 public void testAttrNode_Test7() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001646 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001647 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1648 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1649
1650 loadDOMDocument(fileURL, schemaURL);
1651
1652 // Get XSModel object for the Schema
1653 XSModel schema = getGrammar(schemaURL);
1654
1655 DynamicContext dc = setupDynamicContext(schema);
1656
1657 String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*";
1658 XPath path = compileXPath(dc, xpath);
1659
1660 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1661 ResultSequence rs = eval.evaluate(path);
1662
1663 XSBoolean result = (XSBoolean) rs.first();
1664
1665 String actual = result.string_value();
1666
1667 assertEquals("true", actual);
1668 }
mgandhi1fc77412010-02-02 15:07:05 +00001669
1670 public void testFnNameContextUndefined() throws Exception {
1671 // Bug 301539
1672 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1673 loadDOMDocument(fileURL);
1674
1675 // Get XML Schema Information for the Document
1676 XSModel schema = getGrammar();
1677
1678 DynamicContext dc = setupDynamicContext(schema);
1679
1680 String xpath = "Example/*[1]/name() eq 'x'";
1681 XPath path = compileXPath(dc, xpath);
1682
1683 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1684 ResultSequence rs = eval.evaluate(path);
1685
1686 XSBoolean result = (XSBoolean) rs.first();
1687
1688 String actual = result.string_value();
1689
1690 assertEquals("true", actual);
1691 }
mgandhi13d897f2010-04-18 09:46:00 +00001692
1693 public void testXSNormalizedString() throws Exception {
1694 // Bug 309585
1695 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1696 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1697 loadDOMDocument(fileURL);
1698
1699 // Get XML Schema Information for the Document
1700 XSModel schema = getGrammar();
1701
1702 DynamicContext dc = setupDynamicContext(schema);
1703
1704 String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')";
1705 XPath path = compileXPath(dc, xpath);
1706
1707 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1708
1709 boolean testSuccess = false;
1710 try {
1711 ResultSequence rs = eval.evaluate(path);
1712 }
1713 catch(DynamicError ex) {
1714 // a 'DynamicError' exception indicates, that this test is a success
1715 testSuccess = true;
1716 }
1717
1718 assertTrue(testSuccess);
1719 }
jmollerb0289532010-06-24 23:16:07 +00001720
1721 public void testParseElementKeywordsAsNodes() throws Exception {
1722 // Bug 311480
1723 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1724 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1725 loadDOMDocument(fileURL);
1726
1727 // Get XML Schema Information for the Document
1728 XSModel schema = getGrammar();
1729
1730 DynamicContext dc = setupDynamicContext(schema);
1731
1732 String xpath = "/element/attribute";
1733 XPath path = compileXPath(dc, xpath);
1734 }
1735
mgandhi247b6e72010-07-07 11:50:37 +00001736 public void testTypedValueEnhancement_primitiveTypes() throws Exception {
1737 // Bug 318313
1738 URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml");
1739 URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd");
1740
1741 loadDOMDocument(fileURL, schemaURL);
1742
1743 // Get XSModel object for the Schema
1744 XSModel schema = getGrammar(schemaURL);
1745
1746 DynamicContext dc = setupDynamicContext(schema);
1747
1748 String xpath = "X gt 99";
1749 XPath path = compileXPath(dc, xpath);
1750
1751 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1752 ResultSequence rs = eval.evaluate(path);
1753
1754 XSBoolean result = (XSBoolean) rs.first();
1755
1756 String actual = result.string_value();
1757
1758 assertEquals("true", actual);
1759 }
1760
1761 private CollationProvider createLengthCollatorProvider() {
1762 return new CollationProvider() {
1763 @SuppressWarnings("unchecked")
1764 public Comparator get_collation(String name) {
1765 if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) {
1766 return new Comparator<String>() {
1767 public int compare(String o1, String o2) {
1768 return o1.length() - o2.length();
1769 }
1770 };
1771 }
1772 return null;
1773 }
1774 };
1775 }
1776
dacarver879c37a2009-04-26 23:41:32 +00001777}