blob: 122f5a837f846b07a3033ba295bc1e2fa8d5aa84 [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
mgandhid2cb89c2011-01-16 11:59:19 +000049 * an user-defined variable.
mgandhi8ac9e1c2011-01-20 04:15:58 +000050 * Mukul Gandhi - bug 334478 implementation of xs:token data type
51 * Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY,
mgandhi3727fd62011-03-01 00:59:09 +000052 * ID, IDREF and NMTOKEN.
mgandhib3af5cf2011-03-05 08:58:57 +000053 * Mukul Gandhi - bug 338494 - prohibiting xpath expressions starting with / or // to be parsed.
mgandhi43d0fcf2011-03-06 01:46:48 +000054 * Mukul Gandhi - bug 338999 - improving compliance of function 'fn:subsequence'. implementing full arity support.
mgandhi13e689c2011-11-26 15:03:37 +000055 * Mukul Gandhi - bug 339025 - fixes to fn:distinct-values function. ability to find distinct values on node items.
56 * Mukul Gandhi - bug 341862 - improvements to computation of typed value of xs:boolean nodes.
57 * Mukul Gandhi - bug 343224 - allow user defined simpleType definitions to be available in in-scope schema types
58 * Mukul Gandhi - bug 353373 - "preceding" & "following" axes behavior is erroneous
mgandhi64183992014-05-16 12:07:25 +053059 * Mukul Gandhi - bug 360306 - improvements to "resolve-QName" function and xs:QName type implementation
60 * Mukul Gandhi added a test case for improvements to "eq" function for anyURI
dacarver879c37a2009-04-26 23:41:32 +000061 *******************************************************************************/
62package org.eclipse.wst.xml.xpath2.processor.test;
63
mgandhica745752010-09-27 12:42:00 +000064import java.math.BigInteger;
dacarver879c37a2009-04-26 23:41:32 +000065import java.net.URL;
jmollerb601eb02009-09-02 20:21:06 +000066import java.util.Comparator;
dacarver879c37a2009-04-26 23:41:32 +000067
dacarver2b291392009-05-23 00:47:49 +000068import javax.xml.parsers.DocumentBuilder;
69import javax.xml.parsers.DocumentBuilderFactory;
70
dacarver879c37a2009-04-26 23:41:32 +000071import org.apache.xerces.xs.XSModel;
dacarver7d5e2922009-11-08 15:40:36 +000072import org.eclipse.core.runtime.Platform;
jmollerb601eb02009-09-02 20:21:06 +000073import org.eclipse.wst.xml.xpath2.processor.CollationProvider;
74import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
dacarver879c37a2009-04-26 23:41:32 +000075import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
76import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
mgandhi13d897f2010-04-18 09:46:00 +000077import org.eclipse.wst.xml.xpath2.processor.DynamicError;
dacarver879c37a2009-04-26 23:41:32 +000078import org.eclipse.wst.xml.xpath2.processor.Evaluator;
dacarver6018fcf2009-06-22 21:47:53 +000079import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
mgandhica745752010-09-27 12:42:00 +000080import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
mgandhi3727fd62011-03-01 00:59:09 +000081import org.eclipse.wst.xml.xpath2.processor.XPathParserException;
dacarver6018fcf2009-06-22 21:47:53 +000082import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
mgandhica745752010-09-27 12:42:00 +000083import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
dacarver6018fcf2009-06-22 21:47:53 +000084import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
dacarver2915e2f2009-06-09 14:41:36 +000085import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal;
dacarvered2c87e2009-06-09 14:54:33 +000086import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble;
dacarverae395262009-07-02 04:30:16 +000087import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
dacarvered2c87e2009-06-09 14:54:33 +000088import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat;
mgandhica745752010-09-27 12:42:00 +000089import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger;
90import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
dacarver7d5e2922009-11-08 15:40:36 +000091import org.osgi.framework.Bundle;
mgandhi13e689c2011-11-26 15:03:37 +000092import org.w3c.dom.Document;
jmolleref1b2b42010-08-12 10:33:28 +000093import org.xml.sax.InputSource;
dacarver879c37a2009-04-26 23:41:32 +000094
95public class TestBugs extends AbstractPsychoPathTest {
dacarver23c40122009-11-13 23:26:23 +000096
jmollerb601eb02009-09-02 20:21:06 +000097 private static final String URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR = "urn:x-eclipse:xpath20:funky-collator";
dacarver23c40122009-11-13 23:26:23 +000098
99 private Bundle bundle;
100
dacarver7d5e2922009-11-08 15:40:36 +0000101 @Override
102 protected void setUp() throws Exception {
103 // TODO Auto-generated method stub
104 super.setUp();
105 bundle = Platform
dacarver23c40122009-11-13 23:26:23 +0000106 .getBundle("org.eclipse.wst.xml.xpath2.processor.tests");
dacarver7d5e2922009-11-08 15:40:36 +0000107
108 }
jmollerb601eb02009-09-02 20:21:06 +0000109
jmollerb0289532010-06-24 23:16:07 +0000110 public void testNamesWhichAreKeywords() throws Exception {
111 // Bug 273719
112 URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml");
113 loadDOMDocument(fileURL);
114
115 // Get XML Schema Information for the Document
116 XSModel schema = getGrammar();
117
118 DynamicContext dc = setupDynamicContext(schema);
119
mgandhi1e589ea2012-06-16 19:42:57 +0000120 // String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)";
jmollerb0289532010-06-24 23:16:07 +0000121 String xpath = "(/element/eq eq 'eq') or //child::xs:*";
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);
132 }
133
dacarver879c37a2009-04-26 23:41:32 +0000134 public void testStringLengthWithElementArg() throws Exception {
135 // Bug 273719
136 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
137 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000138
dacarver879c37a2009-04-26 23:41:32 +0000139 // Get XML Schema Information for the Document
140 XSModel schema = getGrammar();
141
142 DynamicContext dc = setupDynamicContext(schema);
143
144 String xpath = "string-length(x) > 2";
145 XPath path = compileXPath(dc, xpath);
146
147 Evaluator eval = new DefaultEvaluator(dc, domDoc);
148 ResultSequence rs = eval.evaluate(path);
149
150 XSBoolean result = (XSBoolean) rs.first();
151
152 String actual = result.string_value();
153
154 assertEquals("true", actual);
dacarver84e43f52009-04-28 19:25:30 +0000155 }
dacarver6c9a7722009-05-24 01:16:07 +0000156
dacarver84e43f52009-04-28 19:25:30 +0000157 public void testBug273795Arity2() throws Exception {
158 // Bug 273795
159 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
160 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000161
dacarver84e43f52009-04-28 19:25:30 +0000162 // Get XML Schema Information for the Document
163 XSModel schema = getGrammar();
164
165 DynamicContext dc = setupDynamicContext(schema);
166
167 // test with arity 2
168 String xpath = "substring(x, 3) = 'happy'";
169 XPath path = compileXPath(dc, xpath);
170
171 Evaluator eval = new DefaultEvaluator(dc, domDoc);
172 ResultSequence rs = eval.evaluate(path);
173
174 XSBoolean result = (XSBoolean) rs.first();
175
176 String actual = result.string_value();
177
178 assertEquals("true", actual);
179 }
dacarver6c9a7722009-05-24 01:16:07 +0000180
dacarver84e43f52009-04-28 19:25:30 +0000181 public void testBug273795Arity3() throws Exception {
182 // Bug 273795
183 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
184 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000185
dacarver84e43f52009-04-28 19:25:30 +0000186 // Get XML Schema Information for the Document
187 XSModel schema = getGrammar();
188
189 DynamicContext dc = setupDynamicContext(schema);
190
191 // test with arity 3
192 String xpath = "substring(x, 3, 4) = 'happ'";
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 testStringFunctionBug274471() throws Exception {
206 // Bug 274471
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() = 'unhappy'";
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
225 assertEquals("true", actual);
226 }
dacarver6c9a7722009-05-24 01:16:07 +0000227
dacarver2b291392009-05-23 00:47:49 +0000228 public void testStringLengthFunctionBug274471() throws Exception {
229 // Bug 274471. string-length() 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/string-length() = 7";
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
mgandhib936d572012-11-14 21:09:08 +0530248 assertEquals("true", actual);
dacarver2b291392009-05-23 00:47:49 +0000249 }
dacarver6c9a7722009-05-24 01:16:07 +0000250
dacarver2b291392009-05-23 00:47:49 +0000251 public void testNormalizeSpaceFunctionBug274471() throws Exception {
252 // Bug 274471. normalize-space() with arity 0
253 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
254 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000255
dacarver2b291392009-05-23 00:47:49 +0000256 // Get XML Schema Information for the Document
257 XSModel schema = getGrammar();
258
259 DynamicContext dc = setupDynamicContext(schema);
260
261 String xpath = "x/normalize-space() = 'unhappy'";
262 XPath path = compileXPath(dc, xpath);
263
264 Evaluator eval = new DefaultEvaluator(dc, domDoc);
265 ResultSequence rs = eval.evaluate(path);
266
267 XSBoolean result = (XSBoolean) rs.first();
268
269 String actual = result.string_value();
270
271 assertEquals("true", actual);
272 }
dacarver6c9a7722009-05-24 01:16:07 +0000273
dacarver9cd5a342009-05-23 01:05:06 +0000274 public void testAnyUriEqualityBug() throws Exception {
275 // Bug 274719
276 // reusing the XML document from another bug
277 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
278 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000279
dacarver9cd5a342009-05-23 01:05:06 +0000280 // Get XML Schema Information for the Document
281 XSModel schema = getGrammar();
282
283 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000284
dacarver9cd5a342009-05-23 01:05:06 +0000285 String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')";
286 XPath path = compileXPath(dc, xpath);
287
288 Evaluator eval = new DefaultEvaluator(dc, domDoc);
289 ResultSequence rs = eval.evaluate(path);
290
291 XSBoolean result = (XSBoolean) rs.first();
292
293 String actual = result.string_value();
294
295 assertEquals("true", actual);
296 }
297
dacarverf585d0c2009-05-23 01:13:44 +0000298 public void testBaseUriBug() throws Exception {
dacarver2915e2f2009-06-09 14:41:36 +0000299 // Bug 274725
dacarver6c9a7722009-05-24 01:16:07 +0000300
dacarver23c40122009-11-13 23:26:23 +0000301 // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
302 // DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000303 loadDOMDocument(new URL("http://resolved-locally/xml/note.xml"));
dacarver6c9a7722009-05-24 01:16:07 +0000304
305 // for testing this bug, we read the XML document from the web.
dacarverf585d0c2009-05-23 01:13:44 +0000306 // this ensures, that base-uri property of DOM is not null.
jmolleref1b2b42010-08-12 10:33:28 +0000307 // domDoc = docBuilder.parse("http://resolved-locally/xml/note.xml");
dacarverf585d0c2009-05-23 01:13:44 +0000308
309 // we pass XSModel as null for this test case. Otherwise, we would
310 // get an exception.
311 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000312
jmolleref1b2b42010-08-12 10:33:28 +0000313 String xpath = "base-uri(note) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000314
315 // please note: The below XPath would also work, with base-uri using
316 // arity 0.
317 // String xpath =
jmolleref1b2b42010-08-12 10:33:28 +0000318 // "note/base-uri() eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000319
dacarverf585d0c2009-05-23 01:13:44 +0000320 XPath path = compileXPath(dc, xpath);
321
322 Evaluator eval = new DefaultEvaluator(dc, domDoc);
323 ResultSequence rs = eval.evaluate(path);
324
325 XSBoolean result = (XSBoolean) rs.first();
326
327 String actual = result.string_value();
328
dacarveracf5e122009-08-05 02:48:43 +0000329 assertEquals("true", actual);
dacarverf585d0c2009-05-23 01:13:44 +0000330 }
dacarverf79d73e2009-05-23 01:28:16 +0000331
332 public void testDocumentUriBug() throws Exception {
333 // Bug 274731
334 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
335 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
jmolleref1b2b42010-08-12 10:33:28 +0000336
337 InputSource inputSource = getTestSource("http://resolved-locally/xml/note.xml");
338 domDoc = docBuilder.parse(inputSource);
dacarverf79d73e2009-05-23 01:28:16 +0000339
340 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000341
jmolleref1b2b42010-08-12 10:33:28 +0000342 String xpath = "document-uri(/) eq xs:anyURI('http://resolved-locally/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000343
dacarverf79d73e2009-05-23 01:28:16 +0000344 XPath path = compileXPath(dc, xpath);
345
346 Evaluator eval = new DefaultEvaluator(dc, domDoc);
347 ResultSequence rs = eval.evaluate(path);
348
349 XSBoolean result = (XSBoolean) rs.first();
350
351 String actual = "false";
dacarver6c9a7722009-05-24 01:16:07 +0000352
dacarverf79d73e2009-05-23 01:28:16 +0000353 if (result != null) {
dacarver6c9a7722009-05-24 01:16:07 +0000354 actual = result.string_value();
dacarverf79d73e2009-05-23 01:28:16 +0000355 }
356
357 assertEquals("true", actual);
358 }
dacarver6c9a7722009-05-24 01:16:07 +0000359
dacarver2b291392009-05-23 00:47:49 +0000360 public void testBooleanTypeBug() throws Exception {
361 // Bug 274784
362 // reusing the XML document from another bug
363 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
364 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000365
dacarver2b291392009-05-23 00:47:49 +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
dacarver2b291392009-05-23 00:47:49 +0000371 String xpath = "xs:boolean('1') eq xs:boolean('true')";
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 }
dacarver879c37a2009-04-26 23:41:32 +0000383
dacarver1d62b032009-05-23 01:39:15 +0000384 public void testDateConstructorBug() throws Exception {
385 // Bug 274792
386 URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml");
387 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000388
dacarver1d62b032009-05-23 01:39:15 +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
dacarver1d62b032009-05-23 01:39:15 +0000394 String xpath = "xs:date(x) eq xs:date('2009-01-01')";
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);
405 }
dacarver6c9a7722009-05-24 01:16:07 +0000406
dacarver41c7f742009-05-23 02:10:24 +0000407 public void testIntegerDataTypeBug() throws Exception {
408 // Bug 274805
409 URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml");
410 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000411
dacarver41c7f742009-05-23 02:10:24 +0000412 // Get XML Schema Information for the Document
413 XSModel schema = getGrammar();
414
415 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000416
dacarver41c7f742009-05-23 02:10:24 +0000417 String xpath = "xs:integer(x) gt 100";
418 XPath path = compileXPath(dc, xpath);
419
420 Evaluator eval = new DefaultEvaluator(dc, domDoc);
421 ResultSequence rs = eval.evaluate(path);
422
423 XSBoolean result = (XSBoolean) rs.first();
424
425 String actual = result.string_value();
426
427 assertEquals("true", actual);
dacarver6c9a7722009-05-24 01:16:07 +0000428 }
dacarver47328e82009-05-23 02:22:26 +0000429
430 public void testLongDataType() throws Exception {
431 // Bug 274952
dacarver23c40122009-11-13 23:26:23 +0000432 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver47328e82009-05-23 02:22:26 +0000433 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
434 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000435
dacarver47328e82009-05-23 02:22:26 +0000436 // Get XML Schema Information for the Document
437 XSModel schema = getGrammar();
438
439 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000440
dacarver47328e82009-05-23 02:22:26 +0000441 // long min value is -9223372036854775808
442 // and max value can be 9223372036854775807
443 String xpath = "xs:long('9223372036854775807') gt 0";
444 XPath path = compileXPath(dc, xpath);
445
446 Evaluator eval = new DefaultEvaluator(dc, domDoc);
447 ResultSequence rs = eval.evaluate(path);
448
449 XSBoolean result = (XSBoolean) rs.first();
450
451 String actual = result.string_value();
452
453 assertEquals("true", actual);
454 }
dacarver6c9a7722009-05-24 01:16:07 +0000455
dacarver10f28f12009-05-23 02:35:22 +0000456 public void testIntDataType() throws Exception {
457 // Bug 275105
dacarver23c40122009-11-13 23:26:23 +0000458 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver10f28f12009-05-23 02:35:22 +0000459 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
460 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000461
dacarver10f28f12009-05-23 02:35:22 +0000462 // Get XML Schema Information for the Document
463 XSModel schema = getGrammar();
464
465 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000466
dacarver10f28f12009-05-23 02:35:22 +0000467 // int min value is -2147483648
468 // and max value can be 2147483647
469 String xpath = "xs:int('2147483647') gt 0";
470 XPath path = compileXPath(dc, xpath);
471
472 Evaluator eval = new DefaultEvaluator(dc, domDoc);
473 ResultSequence rs = eval.evaluate(path);
474
475 XSBoolean result = (XSBoolean) rs.first();
476
477 String actual = result.string_value();
478
479 assertEquals("true", actual);
480 }
dacarver6c9a7722009-05-24 01:16:07 +0000481
482 public void testSchemaAwarenessForAttributes() throws Exception {
483 // Bug 276134
484 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
485 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
486
487 loadDOMDocument(fileURL, schemaURL);
488
489 // Get XSModel object for the Schema
490 XSModel schema = getGrammar(schemaURL);
491
492 DynamicContext dc = setupDynamicContext(schema);
493
494 String xpath = "person/@dob eq xs:date('2006-12-10')";
495 XPath path = compileXPath(dc, xpath);
496
497 Evaluator eval = new DefaultEvaluator(dc, domDoc);
498 ResultSequence rs = eval.evaluate(path);
499
500 XSBoolean result = (XSBoolean) rs.first();
501
502 String actual = result.string_value();
503
504 assertEquals("true", actual);
505
506 }
507
508 public void testSchemaAwarenessForElements() throws Exception {
509 // Bug 276134
510 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml");
511 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd");
512
513 loadDOMDocument(fileURL, schemaURL);
514
515 // Get XSModel object for the Schema
516 XSModel schema = getGrammar(schemaURL);
517
518 DynamicContext dc = setupDynamicContext(schema);
519
520 String xpath = "person/dob eq xs:date('2006-12-10')";
521 XPath path = compileXPath(dc, xpath);
522
523 Evaluator eval = new DefaultEvaluator(dc, domDoc);
524 ResultSequence rs = eval.evaluate(path);
525
526 XSBoolean result = (XSBoolean) rs.first();
527
528 String actual = result.string_value();
529
530 assertEquals("true", actual);
531 }
dacarver5f7e5d12009-06-09 14:30:40 +0000532
jmolleraaedb5f2009-12-16 14:18:49 +0000533 public void testNilled() throws Exception {
534 // This is a terrible shortcoming in the test suite, I'd say
535 URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml");
536 URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd");
537
538 loadDOMDocument(fileURL, schemaURL);
539
540 // Get XSModel object for the Schema
541 XSModel schema = getGrammar(schemaURL);
542
543 DynamicContext dc = setupDynamicContext(schema);
544
545 assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )"));
546 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )"));
547 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )"));
548
549 assertFalse(evaluateBoolean(dc, "nilled(/root/element1)"));
550 assertTrue(evaluateBoolean(dc, "nilled(/root/element2)"));
551 assertFalse(evaluateBoolean(dc, "nilled(/root/element3)"));
552 assertFalse(evaluateBoolean(dc, "nilled(/root/element4)"));
553 }
554
555 // I can't stand to see so much duplicated code!!!
556 private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception {
557 XPath path = compileXPath(dc, xpath);
558
559 Evaluator eval = new DefaultEvaluator(dc, domDoc);
560 ResultSequence rs = eval.evaluate(path);
561
562 XSBoolean result = (XSBoolean) rs.first();
563
564 return result.value();
565 }
566
dacarver9ebaa6f2009-05-25 03:16:50 +0000567 public void testXSNonPositiveInteger() throws Exception {
568 // Bug 277599
dacarver23c40122009-11-13 23:26:23 +0000569 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
570
dacarver9ebaa6f2009-05-25 03:16:50 +0000571 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
572 loadDOMDocument(fileURL);
573
574 // Get XML Schema Information for the Document
575 XSModel schema = getGrammar();
576
577 DynamicContext dc = setupDynamicContext(schema);
578
579 // min value of xs:nonPositiveInteger is -INF
580 // max value is 0
581 String xpath = "xs:nonPositiveInteger('0') eq 0";
582 XPath path = compileXPath(dc, xpath);
583
584 Evaluator eval = new DefaultEvaluator(dc, domDoc);
585 ResultSequence rs = eval.evaluate(path);
586
587 XSBoolean result = (XSBoolean) rs.first();
588
589 String actual = result.string_value();
590
591 assertEquals("true", actual);
592 }
dacarver5f7e5d12009-06-09 14:30:40 +0000593
dacarverca9bc132009-05-25 03:31:41 +0000594 public void testXSNegativeInteger() throws Exception {
595 // Bug 277602
dacarver23c40122009-11-13 23:26:23 +0000596 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
597
dacarverca9bc132009-05-25 03:31:41 +0000598 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
599 loadDOMDocument(fileURL);
600
601 // Get XML Schema Information for the Document
602 XSModel schema = getGrammar();
603
604 DynamicContext dc = setupDynamicContext(schema);
605
606 // min value of xs:negativeInteger is -INF
607 // max value is -1
608 String xpath = "xs:negativeInteger('-1') eq -1";
609 XPath path = compileXPath(dc, xpath);
610
611 Evaluator eval = new DefaultEvaluator(dc, domDoc);
612 ResultSequence rs = eval.evaluate(path);
613
614 XSBoolean result = (XSBoolean) rs.first();
615
616 String actual = result.string_value();
617
618 assertEquals("true", actual);
619 }
dacarver5f7e5d12009-06-09 14:30:40 +0000620
dacarver72e78ba2009-05-25 03:40:46 +0000621 public void testXSShort() throws Exception {
622 // Bug 277608
dacarver23c40122009-11-13 23:26:23 +0000623 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000624
dacarver72e78ba2009-05-25 03:40:46 +0000625 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
626 loadDOMDocument(fileURL);
627
628 // Get XML Schema Information for the Document
629 XSModel schema = getGrammar();
630
631 DynamicContext dc = setupDynamicContext(schema);
632
633 // min value of xs:short is -32768
634 // max value of xs:short is 32767
635 String xpath = "xs:short('-32768') eq -32768";
636 XPath path = compileXPath(dc, xpath);
637
638 Evaluator eval = new DefaultEvaluator(dc, domDoc);
639 ResultSequence rs = eval.evaluate(path);
640
641 XSBoolean result = (XSBoolean) rs.first();
642
643 String actual = result.string_value();
644
645 assertEquals("true", actual);
646 }
dacarver5f7e5d12009-06-09 14:30:40 +0000647
dacarver1bb092e2009-05-25 04:02:48 +0000648 public void testXSNonNegativeInteger() throws Exception {
649 // Bug 277609
dacarver23c40122009-11-13 23:26:23 +0000650 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000651
dacarver1bb092e2009-05-25 04:02:48 +0000652 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
653 loadDOMDocument(fileURL);
654
655 // Get XML Schema Information for the Document
656 XSModel schema = getGrammar();
657
658 DynamicContext dc = setupDynamicContext(schema);
659
660 // min value of xs:nonNegativeInteger is 0
661 // max value of xs:nonNegativeInteger is INF
662 String xpath = "xs:nonNegativeInteger('0') eq 0";
663 XPath path = compileXPath(dc, xpath);
664
665 Evaluator eval = new DefaultEvaluator(dc, domDoc);
666 ResultSequence rs = eval.evaluate(path);
667
668 XSBoolean result = (XSBoolean) rs.first();
669
670 String actual = result.string_value();
671
672 assertEquals("true", actual);
673 }
dacarver5f7e5d12009-06-09 14:30:40 +0000674
dacarverc9ccc722009-05-25 04:21:43 +0000675 public void testXSUnsignedLong() throws Exception {
676 // Bug 277629
dacarver23c40122009-11-13 23:26:23 +0000677 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000678
dacarverc9ccc722009-05-25 04:21:43 +0000679 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
680 loadDOMDocument(fileURL);
681
682 // Get XML Schema Information for the Document
683 XSModel schema = getGrammar();
684
685 DynamicContext dc = setupDynamicContext(schema);
686
687 // min value of xs:unsignedLong is 0
688 // max value of xs:unsignedLong is 18446744073709551615
689 String xpath = "xs:unsignedLong('0') eq 0";
690 XPath path = compileXPath(dc, xpath);
691
692 Evaluator eval = new DefaultEvaluator(dc, domDoc);
693 ResultSequence rs = eval.evaluate(path);
694
695 XSBoolean result = (XSBoolean) rs.first();
696
697 String actual = result.string_value();
698
699 assertEquals("true", actual);
700 }
dacarver5f7e5d12009-06-09 14:30:40 +0000701
dacarvercde26452009-05-25 22:48:28 +0000702 public void testXSPositiveInteger() throws Exception {
703 // Bug 277632
dacarver23c40122009-11-13 23:26:23 +0000704 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000705
dacarvercde26452009-05-25 22:48:28 +0000706 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
707 loadDOMDocument(fileURL);
708
709 // Get XML Schema Information for the Document
710 XSModel schema = getGrammar();
711
712 DynamicContext dc = setupDynamicContext(schema);
713
714 // min value of xs:positiveInteger is 1
715 // max value of xs:positiveInteger is INF
716 String xpath = "xs:positiveInteger('1') eq 1";
717 XPath path = compileXPath(dc, xpath);
718
719 Evaluator eval = new DefaultEvaluator(dc, domDoc);
720 ResultSequence rs = eval.evaluate(path);
721
722 XSBoolean result = (XSBoolean) rs.first();
723
724 String actual = result.string_value();
725
726 assertEquals("true", actual);
727 }
dacarver5f7e5d12009-06-09 14:30:40 +0000728
dacarver2673f012009-05-25 23:08:56 +0000729 public void testXSByte() throws Exception {
730 // Bug 277639
dacarver23c40122009-11-13 23:26:23 +0000731 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000732
dacarver2673f012009-05-25 23:08:56 +0000733 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
734 loadDOMDocument(fileURL);
735
736 // Get XML Schema Information for the Document
737 XSModel schema = getGrammar();
738
739 DynamicContext dc = setupDynamicContext(schema);
740
741 // min value of xs:byte is -128
742 // max value of xs:byte is 127
743 String xpath = "xs:byte('-128') eq -128";
744 XPath path = compileXPath(dc, xpath);
745
746 Evaluator eval = new DefaultEvaluator(dc, domDoc);
747 ResultSequence rs = eval.evaluate(path);
748
749 XSBoolean result = (XSBoolean) rs.first();
750
751 String actual = result.string_value();
752
753 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000754 }
755
dacarver28cff4b2009-05-25 23:19:36 +0000756 public void testXSUnsignedInt() throws Exception {
757 // Bug 277642
dacarver23c40122009-11-13 23:26:23 +0000758 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000759
dacarver28cff4b2009-05-25 23:19:36 +0000760 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
761 loadDOMDocument(fileURL);
762
763 // Get XML Schema Information for the Document
764 XSModel schema = getGrammar();
765
766 DynamicContext dc = setupDynamicContext(schema);
767
768 // min value of xs:unsignedInt is 0
769 // max value of xs:unsignedInt is 4294967295
770 String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')";
771 XPath path = compileXPath(dc, xpath);
772
773 Evaluator eval = new DefaultEvaluator(dc, domDoc);
774 ResultSequence rs = eval.evaluate(path);
775
776 XSBoolean result = (XSBoolean) rs.first();
777
778 String actual = result.string_value();
779
780 assertEquals("true", actual);
dacarver2673f012009-05-25 23:08:56 +0000781 }
dacarver5f7e5d12009-06-09 14:30:40 +0000782
dacarver3cc95782009-05-25 23:33:47 +0000783 public void testXSUnsignedShort() throws Exception {
784 // Bug 277645
dacarver23c40122009-11-13 23:26:23 +0000785 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver3cc95782009-05-25 23:33:47 +0000786 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
787 loadDOMDocument(fileURL);
788
789 // Get XML Schema Information for the Document
790 XSModel schema = getGrammar();
791
792 DynamicContext dc = setupDynamicContext(schema);
793
794 // min value of xs:unsignedShort is 0
795 // max value of xs:unsignedShort is 65535
796 String xpath = "xs:unsignedShort('65535') eq 65535";
797 XPath path = compileXPath(dc, xpath);
798
799 Evaluator eval = new DefaultEvaluator(dc, domDoc);
800 ResultSequence rs = eval.evaluate(path);
801
802 XSBoolean result = (XSBoolean) rs.first();
803
804 String actual = result.string_value();
805
806 assertEquals("true", actual);
807 }
dacarver23c40122009-11-13 23:26:23 +0000808
dacarvered2c87e2009-06-09 14:54:33 +0000809 public void testXSYearMonthDurationMultiply() throws Exception {
810 // Bug 279373
dacarver23c40122009-11-13 23:26:23 +0000811 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver68d6e6c2009-05-25 23:43:42 +0000812 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
813 loadDOMDocument(fileURL);
814
815 // Get XML Schema Information for the Document
816 XSModel schema = getGrammar();
817
818 DynamicContext dc = setupDynamicContext(schema);
819
dacarvered2c87e2009-06-09 14:54:33 +0000820 String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3";
dacarver68d6e6c2009-05-25 23:43:42 +0000821 XPath path = compileXPath(dc, xpath);
822
823 Evaluator eval = new DefaultEvaluator(dc, domDoc);
824 ResultSequence rs = eval.evaluate(path);
825
dacarverae395262009-07-02 04:30:16 +0000826 XSDuration result = (XSDuration) rs.first();
dacarver68d6e6c2009-05-25 23:43:42 +0000827
828 String actual = result.string_value();
829
dacarvered2c87e2009-06-09 14:54:33 +0000830 assertEquals("P6Y9M", actual);
dacarver68d6e6c2009-05-25 23:43:42 +0000831 }
dacarver23c40122009-11-13 23:26:23 +0000832
dacarvered2c87e2009-06-09 14:54:33 +0000833 public void testXSYearMonthDurationDivide1() throws Exception {
834 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000835 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000836 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
837 loadDOMDocument(fileURL);
838
839 // Get XML Schema Information for the Document
840 XSModel schema = getGrammar();
841
842 DynamicContext dc = setupDynamicContext(schema);
843
844 String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5";
845 XPath path = compileXPath(dc, xpath);
846
847 Evaluator eval = new DefaultEvaluator(dc, domDoc);
848 ResultSequence rs = eval.evaluate(path);
849
dacarverae395262009-07-02 04:30:16 +0000850 XSDuration result = (XSDuration) rs.first();
dacarvered2c87e2009-06-09 14:54:33 +0000851
852 String actual = result.string_value();
853
854 assertEquals("P1Y11M", actual);
855 }
dacarver23c40122009-11-13 23:26:23 +0000856
dacarvered2c87e2009-06-09 14:54:33 +0000857 public void testXSYearMonthDurationDivide2() throws Exception {
858 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000859 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000860 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
861 loadDOMDocument(fileURL);
862
863 // Get XML Schema Information for the Document
864 XSModel schema = getGrammar();
865
866 DynamicContext dc = setupDynamicContext(schema);
867
868 String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')";
869 XPath path = compileXPath(dc, xpath);
870
871 Evaluator eval = new DefaultEvaluator(dc, domDoc);
872 ResultSequence rs = eval.evaluate(path);
873
874 XSDecimal result = (XSDecimal) rs.first();
875
876 String actual = result.string_value();
877
878 assertEquals("-2.5", actual);
879 }
dacarver23c40122009-11-13 23:26:23 +0000880
dacarver2915e2f2009-06-09 14:41:36 +0000881 public void testXSDayTimeDurationMultiply() throws Exception {
882 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000883 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000884 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
885 loadDOMDocument(fileURL);
886
887 // Get XML Schema Information for the Document
888 XSModel schema = getGrammar();
889
890 DynamicContext dc = setupDynamicContext(schema);
891
892 String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1";
893 XPath path = compileXPath(dc, xpath);
894
895 Evaluator eval = new DefaultEvaluator(dc, domDoc);
896 ResultSequence rs = eval.evaluate(path);
897
dacarverae395262009-07-02 04:30:16 +0000898 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000899
900 String actual = result.string_value();
901
902 assertEquals("PT4H33M", actual);
903 }
dacarver23c40122009-11-13 23:26:23 +0000904
dacarver2915e2f2009-06-09 14:41:36 +0000905 public void testXSDayTimeDurationDivide() throws Exception {
906 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000907 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000908 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
909 loadDOMDocument(fileURL);
910
911 // Get XML Schema Information for the Document
912 XSModel schema = getGrammar();
913
914 DynamicContext dc = setupDynamicContext(schema);
915
916 String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5";
917 XPath path = compileXPath(dc, xpath);
918
919 Evaluator eval = new DefaultEvaluator(dc, domDoc);
920 ResultSequence rs = eval.evaluate(path);
921
dacarverae395262009-07-02 04:30:16 +0000922 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000923
924 String actual = result.string_value();
925
926 assertEquals("PT17H40M7S", actual);
927 }
dacarver23c40122009-11-13 23:26:23 +0000928
dacarvered2c87e2009-06-09 14:54:33 +0000929 public void testNegativeZeroDouble() throws Exception {
930 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000931 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver76b66582009-06-09 14:08:05 +0000932 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
933 loadDOMDocument(fileURL);
934
935 // Get XML Schema Information for the Document
936 XSModel schema = getGrammar();
937
938 DynamicContext dc = setupDynamicContext(schema);
939
dacarvered2c87e2009-06-09 14:54:33 +0000940 String xpath = "-(xs:double('0'))";
dacarver76b66582009-06-09 14:08:05 +0000941 XPath path = compileXPath(dc, xpath);
942
943 Evaluator eval = new DefaultEvaluator(dc, domDoc);
944 ResultSequence rs = eval.evaluate(path);
945
dacarvered2c87e2009-06-09 14:54:33 +0000946 XSDouble result = (XSDouble) rs.first();
dacarver76b66582009-06-09 14:08:05 +0000947
948 String actual = result.string_value();
949
dacarvered2c87e2009-06-09 14:54:33 +0000950 assertEquals("-0", actual);
dacarver76b66582009-06-09 14:08:05 +0000951 }
dacarver23c40122009-11-13 23:26:23 +0000952
dacarvered2c87e2009-06-09 14:54:33 +0000953 public void testNegativeZeroFloat() throws Exception {
954 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000955 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000956 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
957 loadDOMDocument(fileURL);
958
959 // Get XML Schema Information for the Document
960 XSModel schema = getGrammar();
961
962 DynamicContext dc = setupDynamicContext(schema);
963
dacarvered2c87e2009-06-09 14:54:33 +0000964 String xpath = "-(xs:float('0'))";
dacarver5f7e5d12009-06-09 14:30:40 +0000965 XPath path = compileXPath(dc, xpath);
966
967 Evaluator eval = new DefaultEvaluator(dc, domDoc);
968 ResultSequence rs = eval.evaluate(path);
dacarvered2c87e2009-06-09 14:54:33 +0000969
970 XSFloat result = (XSFloat) rs.first();
971
dacarver5f7e5d12009-06-09 14:30:40 +0000972 String actual = result.string_value();
973
dacarvered2c87e2009-06-09 14:54:33 +0000974 assertEquals("-0", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000975 }
976
dacarvered2c87e2009-06-09 14:54:33 +0000977 public void testXSUnsignedByte() throws Exception {
978 // Bug 277650
dacarver23c40122009-11-13 23:26:23 +0000979 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000980 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
981 loadDOMDocument(fileURL);
982
983 // Get XML Schema Information for the Document
dacarver5f7e5d12009-06-09 14:30:40 +0000984 XSModel schema = getGrammar();
dacarver5f7e5d12009-06-09 14:30:40 +0000985
dacarvered2c87e2009-06-09 14:54:33 +0000986 DynamicContext dc = setupDynamicContext(schema);
987
988 // min value of xs:unsignedByte is 0
989 // max value of xs:unsignedByte is 255
990 String xpath = "xs:unsignedByte('255') eq 255";
dacarver5f7e5d12009-06-09 14:30:40 +0000991 XPath path = compileXPath(dc, xpath);
dacarvered2c87e2009-06-09 14:54:33 +0000992
dacarver5f7e5d12009-06-09 14:30:40 +0000993 Evaluator eval = new DefaultEvaluator(dc, domDoc);
994 ResultSequence rs = eval.evaluate(path);
995
dacarvered2c87e2009-06-09 14:54:33 +0000996 XSBoolean result = (XSBoolean) rs.first();
dacarver5f7e5d12009-06-09 14:30:40 +0000997
998 String actual = result.string_value();
999
dacarvered2c87e2009-06-09 14:54:33 +00001000 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +00001001 }
dacarver23c40122009-11-13 23:26:23 +00001002
dacarver9cfaa8e2009-06-22 21:37:15 +00001003 public void testXSBase64Binary() throws Exception {
1004 // Bug 281046
dacarver23c40122009-11-13 23:26:23 +00001005 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver9cfaa8e2009-06-22 21:37:15 +00001006 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1007 loadDOMDocument(fileURL);
1008
1009 // Get XML Schema Information for the Document
1010 XSModel schema = getGrammar();
1011
1012 DynamicContext dc = setupDynamicContext(schema);
1013
1014 String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')";
1015 XPath path = compileXPath(dc, xpath);
1016
1017 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1018 ResultSequence rs = eval.evaluate(path);
1019
1020 XSBoolean result = (XSBoolean) rs.first();
1021
1022 String actual = result.string_value();
1023
1024 assertEquals("true", actual);
1025 }
dacarver23c40122009-11-13 23:26:23 +00001026
dacarver6018fcf2009-06-22 21:47:53 +00001027 public void testXSHexBinary() throws Exception {
1028 // Bug 281054
dacarver23c40122009-11-13 23:26:23 +00001029 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver6018fcf2009-06-22 21:47:53 +00001030 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1031 loadDOMDocument(fileURL);
1032
1033 // Get XML Schema Information for the Document
1034 XSModel schema = getGrammar();
1035
1036 DynamicContext dc = setupDynamicContext(schema);
1037
1038 String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')";
1039 XPath path = compileXPath(dc, xpath);
1040
1041 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1042 ResultSequence rs = eval.evaluate(path);
1043
1044 XSBoolean result = (XSBoolean) rs.first();
1045
1046 String actual = result.string_value();
1047
1048 assertEquals("true", actual);
1049 }
dacarver23c40122009-11-13 23:26:23 +00001050
mgandhiefe95742009-08-18 04:12:11 +00001051 public void testElementTypedValue() throws Exception {
1052 // test for fix in ElementType.java, involving incorrectly computing
1053 // typed value of element node, in case of validating element node,
1054 // with a user defined simple XSD type.
1055 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
dacarver23c40122009-11-13 23:26:23 +00001056 URL schemaURL = bundle
1057 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
mgandhiefe95742009-08-18 04:12:11 +00001058
1059 loadDOMDocument(fileURL, schemaURL);
1060
1061 // Get XSModel object for the Schema
1062 XSModel schema = getGrammar(schemaURL);
1063
1064 DynamicContext dc = setupDynamicContext(schema);
1065
1066 String xpath = "Example/Transportation/mode eq 'air'";
1067 XPath path = compileXPath(dc, xpath);
1068
1069 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1070 ResultSequence rs = eval.evaluate(path);
1071
1072 XSBoolean result = (XSBoolean) rs.first();
1073
1074 String actual = result.string_value();
1075
1076 assertEquals("true", actual);
1077
1078 }
dacarverf9402792009-08-22 01:14:10 +00001079
dacarver23c40122009-11-13 23:26:23 +00001080 public void testBug286061_quoted_string_literals_no_normalize()
1081 throws Exception {
dacarverf9402792009-08-22 01:14:10 +00001082
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
dacarver23c40122009-11-13 23:26:23 +00001092 String xpath = "'\"\"'"; // the expression '""' contains no escapes
dacarverf9402792009-08-22 01:14:10 +00001093
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("\"\"", resultValue);
1102 }
dacarver23c40122009-11-13 23:26:23 +00001103
dacarverf9402792009-08-22 01:14:10 +00001104 public void testBug286061_quoted_string_literals() throws Exception {
1105
dacarver23c40122009-11-13 23:26:23 +00001106 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001107 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1108 loadDOMDocument(fileURL);
1109
1110 // Get XML Schema Information for the Document
1111 XSModel schema = getGrammar();
1112
1113 DynamicContext dc = setupDynamicContext(schema);
1114
1115 String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )";
1116
1117 XPath path = compileXPath(dc, xpath);
1118
1119 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1120 ResultSequence rs = eval.evaluate(path);
1121
1122 String resultValue = rs.first().string_value();
1123
1124 assertEquals("Don't try this at \"home\", she said", resultValue);
1125 }
1126
jmollerb601eb02009-09-02 20:21:06 +00001127 public void testBug280555_collations() throws Exception {
1128 // Setup context
1129 DefaultDynamicContext dc = setupDynamicContext(null);
1130 dc.set_collation_provider(createLengthCollatorProvider());
1131 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1132
1133 // Parse expression
1134 XPath path = compileXPath(dc, " 'abc' < 'de' ");
1135
1136 // Evaluate once
1137 XSBoolean bval = (XSBoolean) eval.evaluate(path).first();
1138 assertTrue("'abc' < 'def' for normal collations", bval.value());
dacarver23c40122009-11-13 23:26:23 +00001139
jmollerb601eb02009-09-02 20:21:06 +00001140 // Evaluate again with the funny collator
1141 dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR);
1142 XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first();
1143 assertFalse("'abc' < 'def' for normal collations", bval2.value());
dacarver23c40122009-11-13 23:26:23 +00001144 }
1145
mgandhiae92c592009-09-19 12:58:06 +00001146 public void testXPathDefaultNamespace() throws Exception {
1147 // Test for the fix, for xpathDefaultNamespace
dacarver23c40122009-11-13 23:26:23 +00001148 URL fileURL = bundle
1149 .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml");
mgandhiae92c592009-09-19 12:58:06 +00001150 loadDOMDocument(fileURL);
1151
1152 // Get XML Schema Information for the Document
1153 XSModel schema = getGrammar();
1154
dacarver23c40122009-11-13 23:26:23 +00001155 // set up XPath default namespace in Dynamic Context
mgandhiae92c592009-09-19 12:58:06 +00001156 DynamicContext dc = setupDynamicContext(schema);
1157 addXPathDefaultNamespace("http://xyz");
1158
1159 String xpath = "X/message = 'hello'";
1160 XPath path = compileXPath(dc, xpath);
1161
1162 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1163 ResultSequence rs = eval.evaluate(path);
1164
1165 XSBoolean result = (XSBoolean) rs.first();
1166
1167 String actual = result.string_value();
1168
1169 assertEquals("true", actual);
1170 }
dacarver07849652009-11-28 00:09:27 +00001171
mgandhi80a468d2009-12-25 04:57:38 +00001172 public void testXPathInstanceOf1() throws Exception {
1173 // Bug 298267
1174 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1175 URL schemaURL = bundle
1176 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1177
1178 loadDOMDocument(fileURL, schemaURL);
1179
1180 // Get XSModel object for the Schema
1181 XSModel schema = getGrammar(schemaURL);
1182
1183 DynamicContext dc = setupDynamicContext(schema);
1184
1185 String xpath = "Example/Transportation/mode instance of element()";
1186 XPath path = compileXPath(dc, xpath);
1187
1188 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1189 ResultSequence rs = eval.evaluate(path);
1190
1191 XSBoolean result = (XSBoolean) rs.first();
1192
1193 String actual = result.string_value();
1194
1195 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001196 }
1197
1198 public void testXPathInstanceOf2() throws Exception {
1199 // Bug 298267
1200 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1201 URL schemaURL = bundle
1202 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1203
1204 loadDOMDocument(fileURL, schemaURL);
1205
1206 // Get XSModel object for the Schema
1207 XSModel schema = getGrammar(schemaURL);
1208
1209 DynamicContext dc = setupDynamicContext(schema);
1210
1211 String xpath = "Example/Transportation/mode instance of element(mode)";
1212 XPath path = compileXPath(dc, xpath);
1213
1214 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1215 ResultSequence rs = eval.evaluate(path);
1216
1217 XSBoolean result = (XSBoolean) rs.first();
1218
1219 String actual = result.string_value();
1220
1221 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001222 }
1223
mgandhi663fbd02009-12-27 11:23:35 +00001224 public void testXPathInstanceOf3() throws Exception {
mgandhi80a468d2009-12-25 04:57:38 +00001225 // Bug 298267
1226 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1227 URL schemaURL = bundle
1228 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1229
1230 loadDOMDocument(fileURL, schemaURL);
1231
1232 // Get XSModel object for the Schema
1233 XSModel schema = getGrammar(schemaURL);
1234
1235 DynamicContext dc = setupDynamicContext(schema);
1236
mgandhi663fbd02009-12-27 11:23:35 +00001237 String xpath = "Example/Transportation/mode instance of element(mode, modeType)";
mgandhi80a468d2009-12-25 04:57:38 +00001238 XPath path = compileXPath(dc, xpath);
1239
1240 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1241 ResultSequence rs = eval.evaluate(path);
1242
1243 XSBoolean result = (XSBoolean) rs.first();
1244
1245 String actual = result.string_value();
1246
dacarver5a6bbea2009-12-27 17:14:05 +00001247 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001248 }
1249
1250 public void testXPathInstanceOf4() throws Exception {
1251 // Bug 298267
1252 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1253 URL schemaURL = bundle
1254 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1255
1256 loadDOMDocument(fileURL, schemaURL);
1257
1258 // Get XSModel object for the Schema
1259 XSModel schema = getGrammar(schemaURL);
1260
1261 DynamicContext dc = setupDynamicContext(schema);
1262
1263 String xpath = "Example/Transportation/mode instance of element(mode, abc)";
1264 XPath path = compileXPath(dc, xpath);
1265
1266 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1267 ResultSequence rs = eval.evaluate(path);
1268
1269 XSBoolean result = (XSBoolean) rs.first();
1270
1271 String actual = result.string_value();
1272
1273 assertEquals("false", actual);
mgandhi247cdd82009-12-25 09:50:00 +00001274 }
1275
mgandhi663fbd02009-12-27 11:23:35 +00001276 public void testXPathInstanceOf5() throws Exception {
1277 // Bug 298267
1278 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1279 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1280
1281 loadDOMDocument(fileURL, schemaURL);
1282
1283 // Get XSModel object for the Schema
1284 XSModel schema = getGrammar(schemaURL);
1285
1286 DynamicContext dc = setupDynamicContext(schema);
1287
1288 String xpath = "Example/x instance of element(x, x_Type)*";
1289 XPath path = compileXPath(dc, xpath);
1290
1291 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1292 ResultSequence rs = eval.evaluate(path);
1293
1294 XSBoolean result = (XSBoolean) rs.first();
1295
1296 String actual = result.string_value();
1297
1298 assertEquals("true", actual);
1299 }
jmoller2c384ed2010-06-24 23:48:34 +00001300
1301 public void testXPathInstanceOf5_2() 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) 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 assertEquals(false, result.value());
1322 }
1323
1324 public void testXPathInstanceOf5_3() 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 assertFalse(result.value());
1345 }
1346
1347 public void testXPathInstanceOf5_4() 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, /Example/x) instance of element(x, x_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 assertTrue(result.value());
1368 }
1369
1370 public void testXPathInstanceOf5_5() 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
mgandhi13e689c2011-11-26 15:03:37 +00001382 assertXPathFalse("/Example/x instance of x_Type+", dc, domDoc);
1383 assertXPathTrue("/Example/x instance of element(*, x_Type)+", dc, domDoc);
jmollerccaf1912011-03-04 02:12:18 +00001384 assertXPathTrue("/Example/x instance of element(x, x_Type)+", dc, domDoc);
1385 assertXPathTrue("not (/Example/x instance of element(z, x_Type)+)", dc, domDoc);
mgandhi13e689c2011-11-26 15:03:37 +00001386 assertXPathFalse("/Example/x[2]/@mesg instance of mesg_Type", dc, domDoc);
jmollerccaf1912011-03-04 02:12:18 +00001387 assertXPathTrue("/Example/x[2]/@mesg instance of attribute(mesg, mesg_Type)", dc, domDoc);
1388 assertXPathTrue("not (/Example/x[2]/@mesg instance of attribute(cesc, mesg_Type))", dc, domDoc);
jmoller2c384ed2010-06-24 23:48:34 +00001389 }
1390
mgandhi663fbd02009-12-27 11:23:35 +00001391 public void testXPathInstanceOf6() throws Exception {
1392 // Bug 298267
1393 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1394 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1395
1396 loadDOMDocument(fileURL, schemaURL);
1397
1398 // Get XSModel object for the Schema
1399 XSModel schema = getGrammar(schemaURL);
1400
1401 DynamicContext dc = setupDynamicContext(schema);
1402
1403 String xpath = "Example/x instance of element(*, x_Type)*";
1404 XPath path = compileXPath(dc, xpath);
1405
1406 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1407 ResultSequence rs = eval.evaluate(path);
1408
1409 XSBoolean result = (XSBoolean) rs.first();
1410
1411 String actual = result.string_value();
1412
1413 assertEquals("true", actual);
1414 }
1415
1416 public void testXPathInstanceOf7() throws Exception {
1417 // Bug 298267
1418 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1419 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1420
1421 loadDOMDocument(fileURL, schemaURL);
1422
1423 // Get XSModel object for the Schema
1424 XSModel schema = getGrammar(schemaURL);
1425
1426 DynamicContext dc = setupDynamicContext(schema);
1427
1428 String xpath = "Example/x instance of element(x, x_Type)+";
1429 XPath path = compileXPath(dc, xpath);
1430
1431 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1432 ResultSequence rs = eval.evaluate(path);
1433
1434 XSBoolean result = (XSBoolean) rs.first();
1435
1436 String actual = result.string_value();
1437
dacarver3da20eb2009-12-29 14:29:45 +00001438 assertEquals("true", actual);
mgandhi663fbd02009-12-27 11:23:35 +00001439 }
1440
jmollerccaf1912011-03-04 02:12:18 +00001441 public void testXPathNotInstanceOf() throws Exception {
1442 // Bug 298267
1443 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1444 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1445
1446 loadDOMDocument(fileURL, schemaURL);
1447
1448 // Get XSModel object for the Schema
1449 XSModel schema = getGrammar(schemaURL);
1450
1451 DynamicContext dc = setupDynamicContext(schema);
1452
1453 String xpath = "/Example/x[1] instance of element(*, x_Type) and not (/Example/x[1] instance of element(*, y_Type))";
1454 XPath path = compileXPath(dc, xpath);
1455
1456 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1457 ResultSequence rs = eval.evaluate(path);
1458
1459 XSBoolean result = (XSBoolean) rs.first();
1460
1461 String actual = result.string_value();
1462
1463 assertEquals("true", actual);
1464 }
1465
mgandhi663fbd02009-12-27 11:23:35 +00001466 public void testXPathInstanceNonExistantElement() throws Exception {
1467 // Bug 298267
1468 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1469 URL schemaURL = bundle
1470 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1471
1472 loadDOMDocument(fileURL, schemaURL);
1473
1474 // Get XSModel object for the Schema
1475 XSModel schema = getGrammar(schemaURL);
1476
1477 DynamicContext dc = setupDynamicContext(schema);
1478
1479 String xpath = "Example/Transportation/mode instance of element(x)";
1480 XPath path = compileXPath(dc, xpath);
1481
1482 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1483 ResultSequence rs = eval.evaluate(path);
1484
1485 XSBoolean result = (XSBoolean) rs.first();
1486
1487 String actual = result.string_value();
1488
1489 assertEquals("false", actual);
1490 }
1491
mgandhi247cdd82009-12-25 09:50:00 +00001492 public void testFnNumber_Evaluation1() throws Exception {
1493 // Bug 298519
1494 URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml");
1495 URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd");
mgandhi80a468d2009-12-25 04:57:38 +00001496
mgandhi247cdd82009-12-25 09:50:00 +00001497 loadDOMDocument(fileURL, schemaURL);
1498
1499 // Get XSModel object for the Schema
1500 XSModel schema = getGrammar(schemaURL);
1501
1502 DynamicContext dc = setupDynamicContext(schema);
1503
1504 String xpath = "number(Example/x) ge 18";
1505 XPath path = compileXPath(dc, xpath);
1506
1507 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1508 ResultSequence rs = eval.evaluate(path);
1509
1510 XSBoolean result = (XSBoolean) rs.first();
1511
1512 String actual = result.string_value();
1513
1514 assertEquals("true", actual);
1515 }
1516
1517 public void testFnNumber_Evaluation2() throws Exception {
1518 // Bug 298519
1519 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1520 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1521 loadDOMDocument(fileURL);
1522
1523 // Get XML Schema Information for the Document
1524 XSModel schema = getGrammar();
1525
1526 DynamicContext dc = setupDynamicContext(schema);
1527
1528 String xpath = "number(xs:unsignedByte('20')) ge 18";
1529 XPath path = compileXPath(dc, xpath);
1530
1531 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1532 ResultSequence rs = eval.evaluate(path);
1533
1534 XSBoolean result = (XSBoolean) rs.first();
1535
1536 String actual = result.string_value();
1537
1538 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001539 }
mgandhie02bf582009-12-26 13:17:14 +00001540
1541 public void testAttrNode_Test1() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001542 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001543 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1544 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1545
1546 loadDOMDocument(fileURL, schemaURL);
1547
1548 // Get XSModel object for the Schema
1549 XSModel schema = getGrammar(schemaURL);
1550
1551 DynamicContext dc = setupDynamicContext(schema);
1552
1553 String xpath = "Example/x[1]/@mesg instance of attribute()";
1554 XPath path = compileXPath(dc, xpath);
1555
1556 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1557 ResultSequence rs = eval.evaluate(path);
1558
1559 XSBoolean result = (XSBoolean) rs.first();
1560
1561 String actual = result.string_value();
1562
1563 assertEquals("true", actual);
1564 }
1565
1566 public void testAttrNode_Test2() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001567 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001568 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1569 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1570
1571 loadDOMDocument(fileURL, schemaURL);
1572
1573 // Get XSModel object for the Schema
1574 XSModel schema = getGrammar(schemaURL);
1575
1576 DynamicContext dc = setupDynamicContext(schema);
1577
1578 String xpath = "Example/x[1]/@mesg instance of attribute(xx)";
1579 XPath path = compileXPath(dc, xpath);
1580
1581 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1582 ResultSequence rs = eval.evaluate(path);
1583
1584 XSBoolean result = (XSBoolean) rs.first();
1585
1586 String actual = result.string_value();
1587
1588 assertEquals("false", actual);
1589 }
1590
1591 public void testAttrNode_Test3() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001592 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001593 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1594 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1595
1596 loadDOMDocument(fileURL, schemaURL);
1597
1598 // Get XSModel object for the Schema
1599 XSModel schema = getGrammar(schemaURL);
1600
1601 DynamicContext dc = setupDynamicContext(schema);
1602
1603 String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)";
1604 XPath path = compileXPath(dc, xpath);
1605
1606 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1607 ResultSequence rs = eval.evaluate(path);
1608
1609 XSBoolean result = (XSBoolean) rs.first();
1610
1611 String actual = result.string_value();
1612
1613 assertEquals("true", actual);
1614 }
1615
1616 public void testAttrNode_Test4() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001617 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001618 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1619 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1620
1621 loadDOMDocument(fileURL, schemaURL);
1622
1623 // Get XSModel object for the Schema
1624 XSModel schema = getGrammar(schemaURL);
1625
1626 DynamicContext dc = setupDynamicContext(schema);
1627
1628 String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)";
1629 XPath path = compileXPath(dc, xpath);
1630
1631 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1632 ResultSequence rs = eval.evaluate(path);
1633
1634 XSBoolean result = (XSBoolean) rs.first();
1635
1636 String actual = result.string_value();
1637
1638 assertEquals("false", actual);
1639 }
1640
1641 public void testAttrNode_Test5() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001642 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001643 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1644 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1645
1646 loadDOMDocument(fileURL, schemaURL);
1647
1648 // Get XSModel object for the Schema
1649 XSModel schema = getGrammar(schemaURL);
1650
1651 DynamicContext dc = setupDynamicContext(schema);
1652
1653 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)";
1654 XPath path = compileXPath(dc, xpath);
1655
1656 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1657 ResultSequence rs = eval.evaluate(path);
1658
1659 XSBoolean result = (XSBoolean) rs.first();
1660
1661 String actual = result.string_value();
1662
1663 assertEquals("true", actual);
1664 }
1665
1666 public void testAttrNode_Test6() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001667 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001668 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1669 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1670
1671 loadDOMDocument(fileURL, schemaURL);
1672
1673 // Get XSModel object for the Schema
1674 XSModel schema = getGrammar(schemaURL);
1675
1676 DynamicContext dc = setupDynamicContext(schema);
1677
1678 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)";
1679 XPath path = compileXPath(dc, xpath);
1680
1681 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1682 ResultSequence rs = eval.evaluate(path);
1683
1684 XSBoolean result = (XSBoolean) rs.first();
1685
1686 String actual = result.string_value();
1687
1688 assertEquals("false", actual);
1689 }
1690
1691 public void testAttrNode_Test7() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001692 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001693 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1694 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1695
1696 loadDOMDocument(fileURL, schemaURL);
1697
1698 // Get XSModel object for the Schema
1699 XSModel schema = getGrammar(schemaURL);
1700
1701 DynamicContext dc = setupDynamicContext(schema);
1702
1703 String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*";
1704 XPath path = compileXPath(dc, xpath);
1705
1706 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1707 ResultSequence rs = eval.evaluate(path);
1708
1709 XSBoolean result = (XSBoolean) rs.first();
1710
1711 String actual = result.string_value();
1712
1713 assertEquals("true", actual);
1714 }
mgandhi1fc77412010-02-02 15:07:05 +00001715
1716 public void testFnNameContextUndefined() throws Exception {
1717 // Bug 301539
1718 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1719 loadDOMDocument(fileURL);
1720
1721 // Get XML Schema Information for the Document
1722 XSModel schema = getGrammar();
1723
1724 DynamicContext dc = setupDynamicContext(schema);
1725
1726 String xpath = "Example/*[1]/name() eq 'x'";
1727 XPath path = compileXPath(dc, xpath);
1728
1729 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1730 ResultSequence rs = eval.evaluate(path);
1731
1732 XSBoolean result = (XSBoolean) rs.first();
1733
1734 String actual = result.string_value();
1735
1736 assertEquals("true", actual);
1737 }
mgandhi13d897f2010-04-18 09:46:00 +00001738
1739 public void testXSNormalizedString() throws Exception {
1740 // Bug 309585
1741 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1742 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1743 loadDOMDocument(fileURL);
1744
1745 // Get XML Schema Information for the Document
1746 XSModel schema = getGrammar();
1747
1748 DynamicContext dc = setupDynamicContext(schema);
1749
1750 String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')";
1751 XPath path = compileXPath(dc, xpath);
1752
1753 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1754
1755 boolean testSuccess = false;
1756 try {
1757 ResultSequence rs = eval.evaluate(path);
1758 }
1759 catch(DynamicError ex) {
1760 // a 'DynamicError' exception indicates, that this test is a success
1761 testSuccess = true;
1762 }
1763
1764 assertTrue(testSuccess);
1765 }
jmollerb0289532010-06-24 23:16:07 +00001766
1767 public void testParseElementKeywordsAsNodes() throws Exception {
1768 // Bug 311480
1769 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1770 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1771 loadDOMDocument(fileURL);
1772
1773 // Get XML Schema Information for the Document
1774 XSModel schema = getGrammar();
1775
1776 DynamicContext dc = setupDynamicContext(schema);
1777
1778 String xpath = "/element/attribute";
1779 XPath path = compileXPath(dc, xpath);
1780 }
1781
mgandhi247b6e72010-07-07 11:50:37 +00001782 public void testTypedValueEnhancement_primitiveTypes() throws Exception {
1783 // Bug 318313
1784 URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml");
1785 URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd");
1786
1787 loadDOMDocument(fileURL, schemaURL);
1788
1789 // Get XSModel object for the Schema
1790 XSModel schema = getGrammar(schemaURL);
1791
1792 DynamicContext dc = setupDynamicContext(schema);
1793
1794 String xpath = "X gt 99";
1795 XPath path = compileXPath(dc, xpath);
1796
1797 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1798 ResultSequence rs = eval.evaluate(path);
1799
1800 XSBoolean result = (XSBoolean) rs.first();
1801
1802 String actual = result.string_value();
1803
1804 assertEquals("true", actual);
1805 }
1806
mgandhica745752010-09-27 12:42:00 +00001807 public void testTypedValueEnhancement_Bug323900_1() throws Exception {
1808 // Bug 323900
1809 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_1.xml");
1810 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_1.xsd");
1811
1812 loadDOMDocument(fileURL, schemaURL);
1813
1814 // Get XSModel object for the Schema
1815 XSModel schema = getGrammar(schemaURL);
1816
1817 DynamicContext dc = setupDynamicContext(schema);
1818
1819 String xpath = "data(X) instance of xs:integer+";
1820 XPath path = compileXPath(dc, xpath);
1821
1822 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1823 ResultSequence rs = eval.evaluate(path);
1824
1825 XSBoolean result = (XSBoolean) rs.first();
1826
1827 String actual = result.string_value();
1828
1829 assertEquals("true", actual);
1830 }
1831
1832 public void testTypedValueEnhancement_Bug323900_2() throws Exception {
1833 // Bug 323900
1834 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml");
1835 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd");
1836
1837 loadDOMDocument(fileURL, schemaURL);
1838
1839 // Get XSModel object for the Schema
1840 XSModel schema = getGrammar(schemaURL);
1841
1842 DynamicContext dc = setupDynamicContext(schema);
1843
1844 // 1st test
1845 String xpath = "data(X) instance of xs:integer+";
1846 XPath path = compileXPath(dc, xpath);
1847
1848 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1849 ResultSequence rs = eval.evaluate(path);
1850
1851 XSBoolean result = (XSBoolean) rs.first();
1852
1853 String actual = result.string_value();
1854
1855 assertEquals("false", actual);
1856 }
1857
1858 public void testTypedValueEnhancement_Bug323900_3() throws Exception {
1859 // Bug 323900
1860 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_2.xml");
1861 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_2.xsd");
1862
1863 loadDOMDocument(fileURL, schemaURL);
1864
1865 // Get XSModel object for the Schema
1866 XSModel schema = getGrammar(schemaURL);
1867
1868 DynamicContext dc = setupDynamicContext(schema);
1869 String xpath = "data(X)";
1870 XPath path = compileXPath(dc, xpath);
1871 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1872 ResultSequence rs = eval.evaluate(path);
1873
1874 boolean result1 = ((XSInteger) rs.get(0)).eq(new XSInteger(BigInteger.
1875 valueOf(1)), dc);
1876 boolean result2 = ((XSInteger) rs.get(1)).eq(new XSInteger(BigInteger.
1877 valueOf(2)), dc);
1878 boolean result3 = ((XSString) rs.get(2)).eq(new XSString("3.3"), dc);
1879
1880 assertEquals(true, result1 && result2 && result3);
1881 }
1882
mgandhied6ab1e2014-04-15 14:06:40 +05301883 public void testTypedValueEnhancement_Bug323900_4() throws Exception {
mgandhica745752010-09-27 12:42:00 +00001884 // Bug 323900
1885 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_3.xml");
1886 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd");
1887
1888 loadDOMDocument(fileURL, schemaURL);
1889
1890 // Get XSModel object for the Schema
1891 XSModel schema = getGrammar(schemaURL);
1892
1893 DynamicContext dc = setupDynamicContext(schema);
1894 String xpath = "data(X)";
1895 XPath path = compileXPath(dc, xpath);
1896 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1897 ResultSequence rs = eval.evaluate(path);
1898
1899 XSString result = (XSString) rs.get(0);
1900 assertEquals("3.3", result.string_value());
mgandhied6ab1e2014-04-15 14:06:40 +05301901 }
mgandhica745752010-09-27 12:42:00 +00001902
mgandhied6ab1e2014-04-15 14:06:40 +05301903 public void testTypedValueEnhancement_Bug323900_5() throws Exception {
mgandhica745752010-09-27 12:42:00 +00001904 // Bug 323900
1905 URL fileURL = bundle.getEntry("/bugTestFiles/bug323900_4.xml");
1906 URL schemaURL = bundle.getEntry("/bugTestFiles/bug323900_3.xsd");
1907
1908 loadDOMDocument(fileURL, schemaURL);
1909
1910 // Get XSModel object for the Schema
1911 XSModel schema = getGrammar(schemaURL);
1912
1913 DynamicContext dc = setupDynamicContext(schema);
1914 String xpath = "data(X)";
1915 XPath path = compileXPath(dc, xpath);
1916 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1917 ResultSequence rs = eval.evaluate(path);
1918
1919 XSInteger result = (XSInteger) rs.get(0);
1920 assertEquals("10", result.string_value());
mgandhied6ab1e2014-04-15 14:06:40 +05301921 }
mgandhica745752010-09-27 12:42:00 +00001922
1923 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_1()
1924 throws Exception {
1925 // Bug 325262
1926 DynamicContext dc = setupDynamicContext(null);
1927
1928 ResultSequence rs = ResultSequenceFactory.create_new();
1929 dc.set_variable(new QName("value"), rs);
1930
1931 String xpath = "deep-equal($value,())";
1932 XPath path = compileXPath(dc, xpath);
1933 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1934 ResultSequence rsRes = eval.evaluate(path);
1935
1936 XSBoolean result = (XSBoolean) rsRes.get(0);
1937 assertEquals("true", result.string_value());
1938 }
1939
1940 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_2()
1941 throws Exception {
1942 // Bug 325262
1943 DynamicContext dc = setupDynamicContext(null);
1944
1945 ResultSequence rs = ResultSequenceFactory.create_new();
1946 rs.add(new XSInteger(BigInteger.valueOf(2)));
1947 rs.add(new XSInteger(BigInteger.valueOf(4)));
1948 rs.add(new XSInteger(BigInteger.valueOf(6)));
1949 dc.set_variable(new QName("value"), rs);
1950
1951 // test a
1952 String xpath = "$value instance of xs:integer+";
1953 XPath path = compileXPath(dc, xpath);
1954 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1955 ResultSequence rsRes = eval.evaluate(path);
1956 XSBoolean result = (XSBoolean) rsRes.get(0);
1957 assertEquals("true", result.string_value());
1958
1959 // test b
1960 xpath = "deep-equal($value, (2, 4, 6))";
1961 path = compileXPath(dc, xpath);
1962 eval = new DefaultEvaluator(dc, domDoc);
1963 rsRes = eval.evaluate(path);
1964 result = (XSBoolean) rsRes.get(0);
1965 assertEquals("true", result.string_value());
1966 }
1967
1968 public void testTypedValueEnhancement_BugUsingSeqIntoVariable_3()
1969 throws Exception {
1970 // Bug 325262
1971 DynamicContext dc = setupDynamicContext(null);
1972
1973 ResultSequence rs = ResultSequenceFactory.create_new();
1974 rs.add(new XSInteger(BigInteger.valueOf(2)));
1975 rs.add(new XSInteger(BigInteger.valueOf(4)));
1976 rs.add(new XSInteger(BigInteger.valueOf(6)));
1977 dc.set_variable(new QName("value"), rs);
1978
1979 String xpath = "count(data($value)) = 3";
1980 XPath path = compileXPath(dc, xpath);
1981 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1982 ResultSequence rsRes = eval.evaluate(path);
1983 XSBoolean result = (XSBoolean) rsRes.get(0);
1984 assertEquals("true", result.string_value());
1985 }
1986
mgandhid2cb89c2011-01-16 11:59:19 +00001987 public void testXSToken() throws Exception {
1988 // Bug 334478
1989 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1990 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1991 loadDOMDocument(fileURL);
1992
1993 // Get XML Schema Information for the Document
1994 XSModel schema = getGrammar();
1995
1996 DynamicContext dc = setupDynamicContext(schema);
1997
1998 // the strings in below are not valid tokens (they contain 2 consecutive spaces)
1999 String xpath = "xs:token('abcs abcde') eq xs:token('abcs abcde')";
2000 XPath path = compileXPath(dc, xpath);
2001
2002 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2003
2004 boolean testSuccess = false;
2005 try {
2006 ResultSequence rs = eval.evaluate(path);
2007 }
2008 catch(DynamicError ex) {
2009 // a 'DynamicError' exception indicates, that this test is a success
2010 testSuccess = true;
2011 }
2012
2013 assertTrue(testSuccess);
2014 }
2015
mgandhi8ac9e1c2011-01-20 04:15:58 +00002016 public void testBug334842() throws Exception {
2017 // Bug 334842
2018 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2019 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2020 loadDOMDocument(fileURL);
2021
2022 // Get XML Schema Information for the Document
2023 XSModel schema = getGrammar();
2024
2025 DynamicContext dc = setupDynamicContext(schema);
2026
2027 // test a)
2028 String xpath = "xs:Name('x:abc') eq xs:Name('x:abc')";
2029 XPath path = compileXPath(dc, xpath);
2030 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2031 ResultSequence rsRes = eval.evaluate(path);
2032 XSBoolean result = (XSBoolean) rsRes.get(0);
2033 assertEquals("true", result.string_value());
2034
2035 // test b)
2036 xpath = "xs:NCName('x:abc') eq xs:NCName('x:abc')";
2037 path = compileXPath(dc, xpath);
2038 try {
2039 rsRes = eval.evaluate(path);
2040 assertTrue(false);
2041 }
2042 catch(DynamicError ex) {
2043 // a 'DynamicError' exception indicates, that this test is a success
2044 assertTrue(true);
2045 }
2046
2047 // test c)
2048 xpath = "xs:NCName('abc') eq xs:NCName('abc')";
2049 path = compileXPath(dc, xpath);
2050 rsRes = eval.evaluate(path);
2051 result = (XSBoolean) rsRes.get(0);
2052 assertEquals("true", result.string_value());
2053
2054 // test d)
2055 xpath = "xs:ID('x:abc') eq xs:ID('x:abc')";
2056 path = compileXPath(dc, xpath);
2057 try {
2058 rsRes = eval.evaluate(path);
2059 assertTrue(false);
2060 }
2061 catch(DynamicError ex) {
2062 // a 'DynamicError' exception indicates, that this test is a success
2063 assertTrue(true);
2064 }
2065
2066 // test e)
2067 xpath = "xs:ID('abc') eq xs:ID('abc')";
2068 path = compileXPath(dc, xpath);
2069 rsRes = eval.evaluate(path);
2070 result = (XSBoolean) rsRes.get(0);
2071 assertEquals("true", result.string_value());
2072 }
2073
mgandhib3af5cf2011-03-05 08:58:57 +00002074 public void testDefNamespaceOnbuiltInTypes() throws Exception {
mgandhi3727fd62011-03-01 00:59:09 +00002075 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2076 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2077 loadDOMDocument(fileURL);
2078
2079 // Get XML Schema Information for the Document
2080 XSModel schema = getGrammar();
2081
2082 // set up XPath default namespace in Dynamic Context
2083 DynamicContext dc = setupDynamicContext(schema);
2084 dc.set_variable(new QName("value"), new XSString("2.5"));
2085 addXPathDefaultNamespace("http://www.w3.org/2001/XMLSchema");
2086
2087 String xpath = "$value castable as double";
2088 XPath path = compileXPath(dc, xpath);
2089
mgandhi13e689c2011-11-26 15:03:37 +00002090 Evaluator eval = new DefaultEvaluator(dc, (Document)null);
mgandhi3727fd62011-03-01 00:59:09 +00002091 ResultSequence rs = eval.evaluate(path);
2092
2093 XSBoolean result = (XSBoolean) rs.first();
2094
2095 String actual = result.string_value();
2096
2097 assertEquals("true", actual);
2098 }
2099
mgandhib3af5cf2011-03-05 08:58:57 +00002100 public void testExprParsingBeginnigWithRootNode_bug338494() throws Exception {
2101 // Bug 338494
mgandhi3727fd62011-03-01 00:59:09 +00002102 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2103 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2104 loadDOMDocument(fileURL);
2105
2106 // Get XML Schema Information for the Document
2107 XSModel schema = getGrammar();
2108
2109 DynamicContext dc = setupDynamicContext(schema);
2110
2111 // test a)
2112 String xpath = "/x";
2113 XPath path = null;
2114 try {
2115 path = compileXPath(dc, xpath, true);
2116 // test fails
2117 assertTrue(false);
2118 }
2119 catch(XPathParserException ex) {
2120 if ("Expression starts with / or //".equals(ex.getMessage())) {
2121 // test passes
2122 assertTrue(true);
2123 }
2124 }
2125
2126 // test b)
2127 xpath = "//x";
2128 try {
2129 path = compileXPath(dc, xpath, true);
2130 // test fails
2131 assertTrue(false);
2132 }
2133 catch(XPathParserException ex) {
2134 if ("Expression starts with / or //".equals(ex.getMessage())) {
2135 // test passes
2136 assertTrue(true);
2137 }
2138 }
2139
2140 // test c)
2141 xpath = "/";
2142 try {
2143 path = compileXPath(dc, xpath, true);
2144 // test fails
2145 assertTrue(false);
2146 }
2147 catch(XPathParserException ex) {
2148 if ("Expression starts with / or //".equals(ex.getMessage())) {
2149 // test passes
2150 assertTrue(true);
2151 }
2152 }
2153
2154 // test d)
2155 xpath = "x/y[/a]";
2156 try {
2157 path = compileXPath(dc, xpath, true);
2158 // test fails
2159 assertTrue(false);
2160 }
2161 catch(XPathParserException ex) {
2162 if ("Expression starts with / or //".equals(ex.getMessage())) {
2163 // test passes
2164 assertTrue(true);
2165 }
2166 }
2167
2168 // test e)
2169 xpath = ".//x";
2170 try {
2171 path = compileXPath(dc, xpath, true);
2172 // test passes
2173 assertTrue(true);
2174 }
2175 catch(XPathParserException ex) {
2176 // test fails
2177 assertTrue(false);
2178 }
2179 }
2180
mgandhib3af5cf2011-03-05 08:58:57 +00002181 public void testBug338999_Fnsubsequence() throws Exception {
2182 // bug 338999
2183 URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml");
2184 URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd");
2185
2186 loadDOMDocument(fileURL, schemaURL);
2187
2188 // Get XSModel object for the Schema
2189 XSModel schema = getGrammar(schemaURL);
2190
2191 DynamicContext dc = setupDynamicContext(schema);
2192
2193 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2194
2195 // test a)
2196 String xpath = "count(subsequence(X/*, 2)) eq 2";
2197 XPath path = compileXPath(dc, xpath);
2198 ResultSequence rs = eval.evaluate(path);
2199 String actual = ((XSBoolean) rs.first()).string_value();
2200 assertEquals("true", actual);
2201
2202 // test b)
2203 xpath = "subsequence(X/*, 2) instance of element(*, xs:integer)+";
2204 path = compileXPath(dc, xpath);
2205 rs = eval.evaluate(path);
2206 actual = ((XSBoolean) rs.first()).string_value();
2207 assertEquals("true", actual);
2208
2209 // test c)
2210 xpath = "deep-equal(subsequence((1,2,3,4), 2), (2,3,4))";
2211 path = compileXPath(dc, xpath);
2212 rs = eval.evaluate(path);
2213 actual = ((XSBoolean) rs.first()).string_value();
2214 assertEquals("true", actual);
2215
2216 // test d)
2217 // hetrogeneous sequence as input. arity 3 mode.
2218 xpath = "deep-equal(subsequence(('a', 1, 1.5), 2, 2), (1, 1.5))";
2219 path = compileXPath(dc, xpath);
2220 rs = eval.evaluate(path);
2221 actual = ((XSBoolean) rs.first()).string_value();
2222 assertEquals("true", actual);
2223
2224 // test e)
2225 // hetrogeneous sequence as input. arity 3 mode (startingLoc is < 0).
2226 xpath = "deep-equal(subsequence(('a', 1, 1.5, 'b'), -2, 3), ())";
2227 path = compileXPath(dc, xpath);
2228 rs = eval.evaluate(path);
2229 actual = ((XSBoolean) rs.first()).string_value();
2230 assertEquals("true", actual);
2231 }
2232
mgandhi43d0fcf2011-03-06 01:46:48 +00002233 public void testBug339025_distinctValuesOnNodeSequence() throws Exception {
2234 // bug 339025
2235 URL fileURL = bundle.getEntry("/bugTestFiles/bug339025.xml");
2236 URL schemaURL = bundle.getEntry("/bugTestFiles/bug339025.xsd");
2237
2238 loadDOMDocument(fileURL, schemaURL);
2239
2240 // Get XSModel object for the Schema
2241 XSModel schema = getGrammar(schemaURL);
2242
2243 DynamicContext dc = setupDynamicContext(schema);;
2244 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2245
2246 // test a)
2247 String xpath = "count(//a) = count(distinct-values(//a))";
2248 XPath path = compileXPath(dc, xpath);
2249 ResultSequence rs = eval.evaluate(path);
2250 String actual = ((XSBoolean) rs.first()).string_value();
2251 assertEquals("true", actual);
2252
2253 // test b)
2254 xpath = "count(X/a) = count(distinct-values(X/a))";
2255 path = compileXPath(dc, xpath);
2256 rs = eval.evaluate(path);
2257 actual = ((XSBoolean) rs.first()).string_value();
2258 assertEquals("true", actual);
2259
2260 // test c)
2261 xpath = "count(//b) = count(distinct-values(//b))";
2262 path = compileXPath(dc, xpath);
2263 rs = eval.evaluate(path);
2264 actual = ((XSBoolean) rs.first()).string_value();
2265 assertEquals("false", actual);
2266 }
2267
mgandhi13e689c2011-11-26 15:03:37 +00002268 public void testBug341862_TypedBooleanNode() throws Exception {
2269 // bug 341862
2270 URL fileURL = bundle.getEntry("/bugTestFiles/bug341862.xml");
2271 URL schemaURL = bundle.getEntry("/bugTestFiles/bug341862.xsd");
2272
2273 loadDOMDocument(fileURL, schemaURL);
2274
2275 // Get XSModel object for the Schema
2276 XSModel schema = getGrammar(schemaURL);
2277
2278 DynamicContext dc = setupDynamicContext(schema);;
2279 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2280
2281 // test a)
2282 String xpath = "/X/a[1] = true()";
2283 XPath path = compileXPath(dc, xpath);
2284 ResultSequence rs = eval.evaluate(path);
2285 String actual = ((XSBoolean) rs.first()).string_value();
2286 assertEquals("true", actual);
2287
2288 // test b)
2289 xpath = "/X/a[1]/@att = true()";
2290 path = compileXPath(dc, xpath);
2291 rs = eval.evaluate(path);
2292 actual = ((XSBoolean) rs.first()).string_value();
2293 assertEquals("true", actual);
2294
2295 // test c)
2296 xpath = "/X/a[2] = true()";
2297 path = compileXPath(dc, xpath);
2298 rs = eval.evaluate(path);
2299 actual = ((XSBoolean) rs.first()).string_value();
2300 assertEquals("true", actual);
2301
2302 // test d)
2303 xpath = "/X/a[2]/@att = true()";
2304 path = compileXPath(dc, xpath);
2305 rs = eval.evaluate(path);
2306 actual = ((XSBoolean) rs.first()).string_value();
2307 assertEquals("true", actual);
2308
2309 // test e)
2310 xpath = "/X/a[3] = false()";
2311 path = compileXPath(dc, xpath);
2312 rs = eval.evaluate(path);
2313 actual = ((XSBoolean) rs.first()).string_value();
2314 assertEquals("true", actual);
2315
2316 // test f)
2317 xpath = "/X/a[3]/@att = false()";
2318 path = compileXPath(dc, xpath);
2319 rs = eval.evaluate(path);
2320 actual = ((XSBoolean) rs.first()).string_value();
2321 assertEquals("true", actual);
2322
2323 // test g)
2324 xpath = "/X/a[4] = false()";
2325 path = compileXPath(dc, xpath);
2326 rs = eval.evaluate(path);
2327 actual = ((XSBoolean) rs.first()).string_value();
2328 assertEquals("true", actual);
2329
2330 // test h)
2331 xpath = "/X/a[4]/@att = false()";
2332 path = compileXPath(dc, xpath);
2333 rs = eval.evaluate(path);
2334 actual = ((XSBoolean) rs.first()).string_value();
2335 assertEquals("true", actual);
2336 }
2337
mgandhied6ab1e2014-04-15 14:06:40 +05302338 public void testBug_343224() throws Exception {
mgandhi13e689c2011-11-26 15:03:37 +00002339 // bug 343224
2340 URL fileURL = bundle.getEntry("/bugTestFiles/bug343224.xml");
2341 URL schemaURL = bundle.getEntry("/bugTestFiles/bug343224.xsd");
2342
2343 loadDOMDocument(fileURL, schemaURL);
2344
2345 // Get XSModel object for the Schema
2346 XSModel schema = getGrammar(schemaURL);
2347
2348 DynamicContext dc = setupDynamicContext(schema);
2349
2350 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2351
2352 // test a)
2353 String xpath = "X/a[1] castable as STATUS";
2354 XPath path = compileXPath(dc, xpath);
2355 ResultSequence rs = eval.evaluate(path);
2356 String actual = ((XSBoolean) rs.first()).string_value();
2357 assertEquals("true", actual);
2358
2359 // test b)
2360 xpath = "X/a[2] castable as STATUS";
2361 path = compileXPath(dc, xpath);
2362 rs = eval.evaluate(path);
2363 actual = ((XSBoolean) rs.first()).string_value();
2364 assertEquals("true", actual);
2365
2366 // test c)
2367 xpath = "X/a[3] castable as STATUS";
2368 path = compileXPath(dc, xpath);
2369 rs = eval.evaluate(path);
2370 actual = ((XSBoolean) rs.first()).string_value();
2371 assertEquals("false", actual);
mgandhied6ab1e2014-04-15 14:06:40 +05302372 }
mgandhi13e689c2011-11-26 15:03:37 +00002373
2374 public void testReverse_axes() throws Exception {
2375 // Bug 353373
2376 URL fileURL = bundle.getEntry("/bugTestFiles/bug353373_1.xml");
2377 loadDOMDocument(fileURL);
2378
2379 // Get XML Schema Information for the Document
2380 XSModel schema = getGrammar();
2381
2382 DynamicContext dc = setupDynamicContext(schema);
2383
2384 // test (a)
2385 String xpath = "count(x/q/preceding-sibling::*) = 2";
2386 XPath path = compileXPath(dc, xpath);
2387 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2388 ResultSequence rs = eval.evaluate(path);
2389 XSBoolean result = (XSBoolean) rs.first();
2390 String actual = result.string_value();
2391 assertEquals("true", actual);
2392
2393 // test (b)
2394 xpath = "deep-equal((x/q/preceding-sibling::*[1]/name(),x/q/preceding-sibling::*[2]/name()),('p','uu'))";
2395 path = compileXPath(dc, xpath);
2396 eval = new DefaultEvaluator(dc, domDoc);
2397 rs = eval.evaluate(path);
2398 result = (XSBoolean) rs.first();
2399 actual = result.string_value();
2400 assertEquals("true", actual);
2401
2402 // test (c)
2403 xpath = "count(//u/preceding::*) = 7";
2404 path = compileXPath(dc, xpath);
2405 eval = new DefaultEvaluator(dc, domDoc);
2406 rs = eval.evaluate(path);
2407 result = (XSBoolean) rs.first();
2408 actual = result.string_value();
2409 assertEquals("true", actual);
2410
2411 // test (d)
2412 xpath = "deep-equal((//u/preceding::*[1]/name(),//u/preceding::*[2]/name(),//u/preceding::*[3]/name(),//u/preceding::*[4]/name(),//u/preceding::*[5]/name(),//u/preceding::*[6]/name(),//u/preceding::*[7]/name()), " +
2413 "('m2','m1','z','c','q','p','uu'))";
2414 path = compileXPath(dc, xpath);
2415 eval = new DefaultEvaluator(dc, domDoc);
2416 rs = eval.evaluate(path);
2417 result = (XSBoolean) rs.first();
2418 actual = result.string_value();
2419 assertEquals("true", actual);
2420
2421 // test (e)
2422 xpath = "count(//u/ancestor::*) = 2";
2423 path = compileXPath(dc, xpath);
2424 eval = new DefaultEvaluator(dc, domDoc);
2425 rs = eval.evaluate(path);
2426 result = (XSBoolean) rs.first();
2427 actual = result.string_value();
2428 assertEquals("true", actual);
2429
2430 // test (f)
2431 xpath = "deep-equal((//u/ancestor::*[1]/name(),//u/ancestor::*[2]/name()),('y','x'))";
2432 path = compileXPath(dc, xpath);
2433 eval = new DefaultEvaluator(dc, domDoc);
2434 rs = eval.evaluate(path);
2435 result = (XSBoolean) rs.first();
2436 actual = result.string_value();
2437 assertEquals("true", actual);
2438
2439 // test (g)
2440 xpath = "count(//u/ancestor-or-self::*) = 3";
2441 path = compileXPath(dc, xpath);
2442 eval = new DefaultEvaluator(dc, domDoc);
2443 rs = eval.evaluate(path);
2444 result = (XSBoolean) rs.first();
2445 actual = result.string_value();
2446 assertEquals("true", actual);
2447
2448 // test (h)
2449 xpath = "deep-equal((//u/ancestor-or-self::*[1]/name(),//u/ancestor-or-self::*[2]/name(),//u/ancestor-or-self::*[3]/name()),('u','y','x'))";
2450 path = compileXPath(dc, xpath);
2451 eval = new DefaultEvaluator(dc, domDoc);
2452 rs = eval.evaluate(path);
2453 result = (XSBoolean) rs.first();
2454 actual = result.string_value();
2455 assertEquals("true", actual);
2456 }
2457
2458 public void testForward_axes() throws Exception {
2459 // Bug 353373
2460 URL fileURL = bundle.getEntry("/bugTestFiles/bug353373_2.xml");
2461 loadDOMDocument(fileURL);
2462
2463 // Get XML Schema Information for the Document
2464 XSModel schema = getGrammar();
2465
2466 DynamicContext dc = setupDynamicContext(schema);
2467
2468 // test (a)
2469 String xpath = "count(x/q/following-sibling::*) = 2";
2470 XPath path = compileXPath(dc, xpath);
2471 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2472 ResultSequence rs = eval.evaluate(path);
2473 XSBoolean result = (XSBoolean) rs.first();
2474 String actual = result.string_value();
2475 assertEquals("true", actual);
2476
2477 // test (b)
2478 xpath = "deep-equal((x/q/following-sibling::*[1]/name(),x/q/following-sibling::*[2]/name()),('c','y'))";
2479 path = compileXPath(dc, xpath);
2480 eval = new DefaultEvaluator(dc, domDoc);
2481 rs = eval.evaluate(path);
2482 result = (XSBoolean) rs.first();
2483 actual = result.string_value();
2484 assertEquals("true", actual);
2485
2486 // test (c)
2487 xpath = "count(//a5/following::*) = 8";
2488 path = compileXPath(dc, xpath);
2489 eval = new DefaultEvaluator(dc, domDoc);
2490 rs = eval.evaluate(path);
2491 result = (XSBoolean) rs.first();
2492 actual = result.string_value();
2493 assertEquals("true", actual);
2494
2495 // test (d)
2496 xpath = "deep-equal((//n1/following::*[1]/name(),//n1/following::*[2]/name(),//n1/following::*[3]/name(),//n1/following::*[4]/name(),//n1/following::*[5]/name(),//n1/following::*[6]/name(),//n1/following::*[7]/name(),//n1/following::*[8]/name())," +
2497 "('p','q','c','y','z','m1','m2','u'))";
2498 path = compileXPath(dc, xpath);
2499 eval = new DefaultEvaluator(dc, domDoc);
2500 rs = eval.evaluate(path);
2501 result = (XSBoolean) rs.first();
2502 actual = result.string_value();
2503 assertEquals("true", actual);
2504 }
2505
2506 public void testInstanceOf_1() throws Exception {
mgandhi17941022011-11-26 15:45:14 +00002507 // improvements to "instance of" checks
2508
mgandhi13e689c2011-11-26 15:03:37 +00002509 // reusing files from another bug
2510 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
2511 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
2512
2513 loadDOMDocument(fileURL, schemaURL);
2514
2515 // Get XSModel object for the Schema
2516 XSModel schema = getGrammar(schemaURL);
2517
2518 DynamicContext dc = setupDynamicContext(schema);
2519
2520 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2521
2522 // test a)
2523 String xpath = "/person/@id instance of attribute(*, xs:integer)";
2524 XPath path = compileXPath(dc, xpath);
2525 ResultSequence rs = eval.evaluate(path);
2526 String actual = ((XSBoolean) rs.first()).string_value();
2527 assertEquals("true", actual);
2528
2529 // test b)
2530 xpath = "/person/@id instance of xs:integer";
2531 path = compileXPath(dc, xpath);
2532 rs = eval.evaluate(path);
2533 actual = ((XSBoolean) rs.first()).string_value();
2534 assertEquals("false", actual);
2535 }
2536
2537 public void testInstanceOf_2() throws Exception {
mgandhi17941022011-11-26 15:45:14 +00002538 // improvements to "instance of" checks
2539
mgandhi13e689c2011-11-26 15:03:37 +00002540 // reusing files from another bug
2541 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
2542 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
2543
2544 loadDOMDocument(fileURL, schemaURL);
2545
2546 // Get XSModel object for the Schema
2547 XSModel schema = getGrammar(schemaURL);
2548
2549 DynamicContext dc = setupDynamicContext(schema);
2550
2551 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2552
2553 // test a)
2554 String xpath = "/person/fname instance of element(*, xs:string)";
2555 XPath path = compileXPath(dc, xpath);
2556 ResultSequence rs = eval.evaluate(path);
2557 String actual = ((XSBoolean) rs.first()).string_value();
2558 assertEquals("true", actual);
2559
2560 // test b)
2561 xpath = "/person/fname instance of xs:string";
2562 path = compileXPath(dc, xpath);
2563 rs = eval.evaluate(path);
2564 actual = ((XSBoolean) rs.first()).string_value();
2565 assertEquals("false", actual);
2566 }
2567
2568 public void testResolveQName_1() throws Exception {
2569 // Bug 360306
2570 URL fileURL = bundle.getEntry("/bugTestFiles/resQName.xml");
2571 loadDOMDocument(fileURL);
2572
2573 // Get XML Schema Information for the Document
2574 XSModel schema = getGrammar();
2575
2576 DynamicContext dc = setupDynamicContext(schema);
2577
2578 // test (a)
2579 String xpath = "resolve-QName(/messages/message[1]/@kind, /messages) = xs:QName('xs:int')";
2580 XPath path = compileXPath(dc, xpath);
2581 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2582 ResultSequence rs = eval.evaluate(path);
2583 XSBoolean result = (XSBoolean) rs.first();
2584 String actual = result.string_value();
2585 assertEquals("true", actual);
2586 }
2587
mgandhi17941022011-11-26 15:45:14 +00002588 public void testBug_namespaceUriFromQName_1() throws Exception {
2589 // improving implementation of fn:namespace-uri-from-QName
2590
mgandhi13e689c2011-11-26 15:03:37 +00002591 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2592 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2593 loadDOMDocument(fileURL);
2594
2595 // Get XML Schema Information for the Document
2596 XSModel schema = getGrammar();
2597
2598 DynamicContext dc = setupDynamicContext(schema);
2599 dc.add_namespace("p", "http://cta023.com/p");
2600
2601 // test (a)
2602 String xpath = "namespace-uri-from-QName(xs:QName('p:ppp')) = 'http://cta023.com/p'";
2603 XPath path = compileXPath(dc, xpath);
2604 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2605 ResultSequence rs = eval.evaluate(path);
2606 XSBoolean result = (XSBoolean) rs.first();
2607 String actual = result.string_value();
2608 assertEquals("true", actual);
2609 }
2610
mgandhi17941022011-11-26 15:45:14 +00002611 public void testBug_namespaceUriFromQName_2() throws Exception {
2612 // improving implementation of fn:namespace-uri-from-QName
2613
2614 URL fileURL = bundle.getEntry("/bugTestFiles/namespaceUriFromQName_bug.xml");
mgandhi13e689c2011-11-26 15:03:37 +00002615 loadDOMDocument(fileURL);
2616
2617 // Get XML Schema Information for the Document
2618 XSModel schema = getGrammar();
2619
2620 DynamicContext dc = setupDynamicContext(schema);
2621 dc.add_namespace("a", "http://x.y");
2622
2623 String xpath = "namespace-uri-from-QName(node-name(a:X)) = 'http://x.y'";
2624 XPath path = compileXPath(dc, xpath);
2625 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2626 ResultSequence rs = eval.evaluate(path);
2627 XSBoolean result = (XSBoolean) rs.first();
2628 String actual = result.string_value();
2629 assertEquals("true", actual);
2630 }
2631
2632 public void testNonDocumentNodeAsRoot() throws Exception {
mgandhi17941022011-11-26 15:45:14 +00002633 // a non-document node as root node of the XDM tree. introducing a new argument to DefaultEvaluator.
2634
mgandhi13e689c2011-11-26 15:03:37 +00002635 // reusing files from another bug
2636 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
2637 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
2638
2639 loadDOMDocument(fileURL, schemaURL);
2640
2641 // Get XSModel object for the Schema
2642 XSModel schema = getGrammar(schemaURL);
2643
2644 DynamicContext dc = setupDynamicContext(schema);
2645
2646 Evaluator eval = new DefaultEvaluator(dc, domDoc, domDoc.getDocumentElement());
2647
2648 // test a)
2649 String xpath = ". is root()";
2650 XPath path = compileXPath(dc, xpath);
2651 ResultSequence rs = eval.evaluate(path);
2652 String actual = ((XSBoolean) rs.first()).string_value();
2653 assertEquals("true", actual);
2654
2655 // test b)
2656 xpath = "empty(..)";
2657 path = compileXPath(dc, xpath);
2658 rs = eval.evaluate(path);
2659 actual = ((XSBoolean) rs.first()).string_value();
2660 assertEquals("true", actual);
2661 }
2662
mgandhi17941022011-11-26 15:45:14 +00002663 public void testFnIndexOf_onQName1() throws Exception {
2664 // fn:index-of finding QName values
2665
mgandhi13e689c2011-11-26 15:03:37 +00002666 URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml");
2667 URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd");
2668
2669 loadDOMDocument(fileURL, schemaURL);
2670
2671 // Get XSModel object for the Schema
2672 XSModel schema = getGrammar(schemaURL);
2673
2674 DynamicContext dc = setupDynamicContext(schema);
2675
2676 String xpath = "index-of(for $e in X/* return node-name($e), node-name(X/b))";
2677 XPath path = compileXPath(dc, xpath);
2678 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2679 ResultSequence rs = eval.evaluate(path);
2680 assertTrue(rs.size() > 0);
2681 String actual = ((XSInteger) rs.first()).string_value();
2682 assertEquals("2", actual);
2683 }
2684
2685 public void testFnIndexOf_onQName2() throws Exception {
mgandhi17941022011-11-26 15:45:14 +00002686 // fn:index-of finding QName values
2687
mgandhi13e689c2011-11-26 15:03:37 +00002688 URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml");
2689 URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd");
2690
2691 loadDOMDocument(fileURL, schemaURL);
2692
2693 // Get XSModel object for the Schema
2694 XSModel schema = getGrammar(schemaURL);
2695
2696 DynamicContext dc = setupDynamicContext(schema);
2697
2698 String xpath = "index-of(for $e in X/* return node-name($e), xs:QName('b'))";
2699 XPath path = compileXPath(dc, xpath);
2700 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2701 ResultSequence rs = eval.evaluate(path);
2702 assertTrue(rs.size() > 0);
2703 String actual = ((XSInteger) rs.first()).string_value();
2704 assertEquals("2", actual);
2705 }
2706
2707 public void testFnIndexOf_onQName3() throws Exception {
mgandhi17941022011-11-26 15:45:14 +00002708 // fn:index-of finding QName values
2709
mgandhi13e689c2011-11-26 15:03:37 +00002710 URL fileURL = bundle.getEntry("/bugTestFiles/bug338999.xml");
2711 URL schemaURL = bundle.getEntry("/bugTestFiles/bug338999.xsd");
2712
2713 loadDOMDocument(fileURL, schemaURL);
2714
2715 // Get XSModel object for the Schema
2716 XSModel schema = getGrammar(schemaURL);
2717
2718 DynamicContext dc = setupDynamicContext(schema);
2719
2720 String xpath = "index-of(for $e in X/* return node-name($e), fn:QName('', 'b'))";
2721 XPath path = compileXPath(dc, xpath);
2722 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2723 ResultSequence rs = eval.evaluate(path);
2724 assertTrue(rs.size() > 0);
2725 String actual = ((XSInteger) rs.first()).string_value();
2726 assertEquals("2", actual);
2727 }
2728
mgandhi1e589ea2012-06-16 19:42:57 +00002729 public void testXSDateTimeCast() throws Exception {
2730 // test explicit casts on xs:dateTime node references
2731
2732 URL fileURL = bundle.getEntry("/bugTestFiles/dateTime1.xml");
2733 URL schemaURL = bundle.getEntry("/bugTestFiles/dateTime1.xsd");
2734
2735 loadDOMDocument(fileURL, schemaURL);
2736
2737 // Get XSModel object for the Schema
2738 XSModel schema = getGrammar(schemaURL);
2739
2740 DynamicContext dc = setupDynamicContext(schema);
2741
2742 // test a)
2743 String xpath = "exists(xs:dateTime(/test/@t1))";
2744 XPath path = compileXPath(dc, xpath);
2745
2746 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2747 ResultSequence rs = eval.evaluate(path);
2748
2749 XSBoolean result = (XSBoolean) rs.first();
2750 String actual = result.string_value();
2751 assertEquals("true", actual);
2752
2753 // test b)
2754 xpath = "/test/@t1 instance of attribute(t1, xs:dateTime)";
2755 path = compileXPath(dc, xpath);
2756
2757 eval = new DefaultEvaluator(dc, domDoc);
2758 rs = eval.evaluate(path);
2759
2760 result = (XSBoolean) rs.first();
2761 actual = result.string_value();
2762 assertEquals("true", actual);
2763
2764 // test c)
2765 xpath = "(xs:dateTime(/test/@t1) + xs:dayTimeDuration('P1D')) eq xs:dateTime('2010-10-06T10:05:05')";
2766 path = compileXPath(dc, xpath);
2767
2768 eval = new DefaultEvaluator(dc, domDoc);
2769 rs = eval.evaluate(path);
2770
2771 result = (XSBoolean) rs.first();
2772 actual = result.string_value();
2773 assertEquals("true", actual);
2774 }
2775
mgandhic4152f72012-09-29 09:15:53 +05302776 public void testBug_362026() throws Exception {
2777 // "instance of" must not atomize the LHS before the comparison check
2778
2779 URL fileURL = bundle.getEntry("/bugTestFiles/bug362026.xml");
2780 URL schemaURL = bundle.getEntry("/bugTestFiles/bug362026.xsd");
2781
2782 loadDOMDocument(fileURL, schemaURL);
2783
2784 // Get XSModel object for the Schema
2785 XSModel schema = getGrammar(schemaURL);
2786
2787 DynamicContext dc = setupDynamicContext(schema);
2788
2789 // test a)
2790 String xpath = "/X/Y instance of xs:integer";
2791 XPath path = compileXPath(dc, xpath);
2792
2793 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2794 ResultSequence rs = eval.evaluate(path);
2795
2796 XSBoolean result = (XSBoolean) rs.first();
2797 String actual = result.string_value();
2798 assertEquals("false", actual);
2799
2800 // test b)
2801 xpath = "/X/@att1 instance of xs:string";
2802 path = compileXPath(dc, xpath);
2803
2804 eval = new DefaultEvaluator(dc, domDoc);
2805 rs = eval.evaluate(path);
2806
2807 result = (XSBoolean) rs.first();
2808 actual = result.string_value();
2809 assertEquals("false", actual);
2810
2811 // test c)
2812 xpath = "/X/Y instance of element(*, xs:integer)";
2813 path = compileXPath(dc, xpath);
2814
2815 eval = new DefaultEvaluator(dc, domDoc);
2816 rs = eval.evaluate(path);
2817
2818 result = (XSBoolean) rs.first();
2819 actual = result.string_value();
2820 assertEquals("true", actual);
2821
2822 // test d)
2823 xpath = "/X/@att1 instance of attribute(*, xs:string)";
2824 path = compileXPath(dc, xpath);
2825
2826 eval = new DefaultEvaluator(dc, domDoc);
2827 rs = eval.evaluate(path);
2828
2829 result = (XSBoolean) rs.first();
2830 actual = result.string_value();
2831 assertEquals("true", actual);
2832 }
2833
mgandhied6ab1e2014-04-15 14:06:40 +05302834 public void testBugNonAsciiCharsHandling() throws Exception {
mgandhib936d572012-11-14 21:09:08 +05302835
2836 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2837 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2838 loadDOMDocument(fileURL);
2839
mgandhied6ab1e2014-04-15 14:06:40 +05302840 // Get XML Schema Information for the Document
2841 XSModel schema = getGrammar();
mgandhib936d572012-11-14 21:09:08 +05302842
mgandhied6ab1e2014-04-15 14:06:40 +05302843 DynamicContext dc = setupDynamicContext(schema);
2844
2845
2846 String xpath = "count(Einführung) le 1";
2847 try {
2848 XPath path = compileXPath(dc, xpath, true);
2849 }
2850 catch(Exception ex) {
2851 assertTrue(false);
2852 }
2853 }
2854
2855 public void testBugEQ() throws Exception {
2856 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2857 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2858 loadDOMDocument(fileURL);
2859
2860 // Get XML Schema Information for the Document
2861 XSModel schema = getGrammar();
2862
2863 DynamicContext dc = setupDynamicContext(schema);
2864
mgandhib936d572012-11-14 21:09:08 +05302865 String xpath = "1 eq '1'";
mgandhied6ab1e2014-04-15 14:06:40 +05302866 XPath path = compileXPath(dc, xpath);
2867 boolean successStatus = true;
mgandhib936d572012-11-14 21:09:08 +05302868 try {
mgandhied6ab1e2014-04-15 14:06:40 +05302869 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2870 ResultSequence rs = eval.evaluate(path);
2871 assertEquals(false, successStatus);
mgandhib936d572012-11-14 21:09:08 +05302872 }
2873 catch (DynamicError err) {
2874 if ("XPTY0004".equals(err.code())) {
mgandhied6ab1e2014-04-15 14:06:40 +05302875 successStatus = false;
mgandhib936d572012-11-14 21:09:08 +05302876 }
2877 }
mgandhib936d572012-11-14 21:09:08 +05302878 }
2879
mgandhied6ab1e2014-04-15 14:06:40 +05302880 public void testBugFnIndexOf() throws Exception {
mgandhib936d572012-11-14 21:09:08 +05302881
mgandhied6ab1e2014-04-15 14:06:40 +05302882 URL fileURL = bundle.getEntry("/bugTestFiles/indexOf1.xml");
2883 URL schemaURL = bundle.getEntry("/bugTestFiles/indexOf1.xsd");
mgandhiefde5e12012-11-24 08:09:38 +05302884
2885 loadDOMDocument(fileURL, schemaURL);
2886
2887 // Get XSModel object for the Schema
2888 XSModel schema = getGrammar(schemaURL);
2889
2890 DynamicContext dc = setupDynamicContext(schema);
2891
mgandhied6ab1e2014-04-15 14:06:40 +05302892 String xpath = "deep-equal(index-of(X/a, 2), (1,4))";
mgandhiefde5e12012-11-24 08:09:38 +05302893 XPath path = compileXPath(dc, xpath);
mgandhiefde5e12012-11-24 08:09:38 +05302894 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2895 ResultSequence rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302896 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhiefde5e12012-11-24 08:09:38 +05302897
mgandhied6ab1e2014-04-15 14:06:40 +05302898 xpath = "deep-equal(index-of(X/b, 1), (1,3))";
mgandhiefde5e12012-11-24 08:09:38 +05302899 path = compileXPath(dc, xpath);
mgandhiefde5e12012-11-24 08:09:38 +05302900 rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302901 assertEquals(true, ((XSBoolean) rs.first()).value());
2902
2903 xpath = "deep-equal(index-of(X/@attr, 5), (3,4,5))";
2904 path = compileXPath(dc, xpath);
2905 rs = eval.evaluate(path);
2906 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhiefde5e12012-11-24 08:09:38 +05302907 }
2908
mgandhied6ab1e2014-04-15 14:06:40 +05302909 public void testBugTypedValue() throws Exception {
mgandhi3d86c1b2012-11-26 22:02:50 +05302910
mgandhied6ab1e2014-04-15 14:06:40 +05302911 URL fileURL = bundle.getEntry("/bugTestFiles/bugTypedValue1.xml");
2912 URL schemaURL = bundle.getEntry("/bugTestFiles/bugTypedValue1.xsd");
mgandhi47f6a162012-12-12 19:15:08 +05302913
2914 loadDOMDocument(fileURL, schemaURL);
2915
2916 // Get XSModel object for the Schema
2917 XSModel schema = getGrammar(schemaURL);
2918
2919 DynamicContext dc = setupDynamicContext(schema);
2920
mgandhied6ab1e2014-04-15 14:06:40 +05302921 String xpath = "data(Z/X[1]/@val) instance of xs:date+";
mgandhi47f6a162012-12-12 19:15:08 +05302922 XPath path = compileXPath(dc, xpath);
mgandhi47f6a162012-12-12 19:15:08 +05302923 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2924 ResultSequence rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302925 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhi47f6a162012-12-12 19:15:08 +05302926
mgandhied6ab1e2014-04-15 14:06:40 +05302927 xpath = "count(data(Z/X[1]/@val)) eq 3";
mgandhi47f6a162012-12-12 19:15:08 +05302928 path = compileXPath(dc, xpath);
mgandhi47f6a162012-12-12 19:15:08 +05302929 rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302930 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhi47f6a162012-12-12 19:15:08 +05302931 }
2932
mgandhied6ab1e2014-04-15 14:06:40 +05302933 public void testBugFnSumOnDurationTypes() throws Exception {
mgandhi47f6a162012-12-12 19:15:08 +05302934
mgandhied6ab1e2014-04-15 14:06:40 +05302935 // use XSD 1.1 validation, for this test
2936
2937 URL fileURL = bundle.getEntry("/bugTestFiles/FnSum1.xml");
2938 URL schemaURL = bundle.getEntry("/bugTestFiles/FnSum1.xsd");
mgandhi47f6a162012-12-12 19:15:08 +05302939
mgandhied6ab1e2014-04-15 14:06:40 +05302940 loadDOMDocumentXS11(fileURL, schemaURL);
mgandhi47f6a162012-12-12 19:15:08 +05302941
2942 // Get XSModel object for the Schema
mgandhied6ab1e2014-04-15 14:06:40 +05302943 XSModel schema = getGrammarXS11(schemaURL);
mgandhi47f6a162012-12-12 19:15:08 +05302944
2945 DynamicContext dc = setupDynamicContext(schema);
mgandhied6ab1e2014-04-15 14:06:40 +05302946 dc.add_namespace("tst", "http://www.rackspace.com/test/duration");
mgandhi47f6a162012-12-12 19:15:08 +05302947
mgandhied6ab1e2014-04-15 14:06:40 +05302948 String xpath = "xsd:dayTimeDuration('PT24H') = sum(tst:test/tst:d)";
mgandhi47f6a162012-12-12 19:15:08 +05302949 XPath path = compileXPath(dc, xpath);
mgandhi47f6a162012-12-12 19:15:08 +05302950 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2951 ResultSequence rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302952 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhi47f6a162012-12-12 19:15:08 +05302953
mgandhied6ab1e2014-04-15 14:06:40 +05302954 xpath = "xsd:dayTimeDuration('PT24H') = sum(for $d in tst:test/tst:d return $d)";
mgandhi47f6a162012-12-12 19:15:08 +05302955 path = compileXPath(dc, xpath);
mgandhi47f6a162012-12-12 19:15:08 +05302956 rs = eval.evaluate(path);
mgandhied6ab1e2014-04-15 14:06:40 +05302957 assertEquals(true, ((XSBoolean) rs.first()).value());
mgandhi47f6a162012-12-12 19:15:08 +05302958 }
2959
mgandhi1e589ea2012-06-16 19:42:57 +00002960
IBM_ADMIN93f03432014-05-15 17:57:14 +05302961 public void testXSAnyURI_bug() throws Exception {
2962
2963 URL fileURL = bundle.getEntry("/bugTestFiles/dashboard.xml");
2964 loadDOMDocument(fileURL);
2965
2966 // Get XML Schema Information for the Document
2967 XSModel schema = getGrammar();
2968
2969 DynamicContext dc = setupDynamicContext(schema);
2970
2971 String xpath = "count(/dashboard/widget/*[namespace-uri() eq 'http://jaspersoft.com/highcharts']) eq 1";
2972 XPath path = compileXPath(dc, xpath);
2973 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2974 ResultSequence rs = eval.evaluate(path);
2975 XSBoolean result = (XSBoolean) rs.first();
2976 String actual = result.string_value();
2977 assertEquals("true", actual);
2978 }
2979
Mukul Gandhia2692d12014-08-07 20:44:39 +05302980 public void testfnMatches() throws Exception {
2981
2982 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
2983 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
2984 loadDOMDocument(fileURL);
2985
2986 // Get XML Schema Information for the Document
2987 XSModel schema = getGrammar();
2988
2989 DynamicContext dc = setupDynamicContext(schema);
2990
2991 String xpath = "matches('111-111-1111', '[0-9]{3}-[0-9]{3}-[0-9]{4}')";
2992 XPath path = compileXPath(dc, xpath);
2993 Evaluator eval = new DefaultEvaluator(dc, domDoc);
2994 ResultSequence rs = eval.evaluate(path);
2995 assertEquals(true, ((XSBoolean) rs.first()).value());
2996 }
IBM_ADMIN93f03432014-05-15 17:57:14 +05302997
mgandhi247b6e72010-07-07 11:50:37 +00002998 private CollationProvider createLengthCollatorProvider() {
2999 return new CollationProvider() {
3000 @SuppressWarnings("unchecked")
3001 public Comparator get_collation(String name) {
3002 if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) {
3003 return new Comparator<String>() {
3004 public int compare(String o1, String o2) {
3005 return o1.length() - o2.length();
3006 }
3007 };
3008 }
3009 return null;
3010 }
3011 };
3012 }
3013
dacarver879c37a2009-04-26 23:41:32 +00003014}