blob: 43df3383d1ca731b9fab56a481680393cf473bee [file] [log] [blame]
dacarver879c37a2009-04-26 23:41:32 +00001/*******************************************************************************
jmollerb0289532010-06-24 23:16:07 +00002 * Copyright (c) 2009-2010 Standards for Technology in Automotive Retail and others.
dacarver879c37a2009-04-26 23:41:32 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * David Carver (STAR) - initial API and implementation
dacarver2b291392009-05-23 00:47:49 +000010 * Mukul Gandhi - bug 273719 - improvements to fn:string-length function
11 * Mukul Gandhi - bug 273795 - improvements to fn:substring function
12 * Mukul Gandhi - bug 274471 - improvements to fn:string function
dacarvercde26452009-05-25 22:48:28 +000013 * Mukul Gandhi - bug 274725 - improvements to fn:base-uri function
14 * Mukul Gandhi - bug 274731 - improvements to fn:document-uri function
dacarver2b291392009-05-23 00:47:49 +000015 * Mukul Gandhi - bug 274784 - improvements to xs:boolean data type
dacarver41c7f742009-05-23 02:10:24 +000016 * Mukul Gandhi - bug 274805 - improvements to xs:integer data type
dacarver47328e82009-05-23 02:22:26 +000017 * Mukul Gandhi - bug 274952 - implements xs:long data type
dacarver9ebaa6f2009-05-25 03:16:50 +000018 * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type
dacarverca9bc132009-05-25 03:31:41 +000019 * Mukul Gandhi - bug 277602 - implements xs:negativeInteger data type
20 * Mukul Gandhi - bug 277599 - implements xs:nonPositiveInteger data type
dacarverc9ccc722009-05-25 04:21:43 +000021 * Mukul Gandhi - bug 277608 implements xs:short data type
22 * bug 277609 implements xs:nonNegativeInteger data type
dacarvercde26452009-05-25 22:48:28 +000023 * bug 277629 implements xs:unsignedLong data type
dacarver2673f012009-05-25 23:08:56 +000024 * bug 277632 implements xs:positiveInteger data type
dacarver28cff4b2009-05-25 23:19:36 +000025 * bug 277639 implements xs:byte data type
dacarver3cc95782009-05-25 23:33:47 +000026 * bug 277642 implements xs:unsignedInt data type
dacarver68d6e6c2009-05-25 23:43:42 +000027 * bug 277645 implements xs:unsignedShort data type
dacarver76b66582009-06-09 14:08:05 +000028 * bug 277650 implements xs:unsignedByte data type
29 * bug 279373 improvements to multiply operation on xs:yearMonthDuration
30 * data type.
dacarver9cfaa8e2009-06-22 21:37:15 +000031 * bug 279376 improvements to xs:yearMonthDuration division operation
32 * bug 281046 implementation of xs:base64Binary data type
dacarverf9402792009-08-22 01:14:10 +000033 * Jesper S Moller - bug 286061 correct handling of quoted string
jmollerb601eb02009-09-02 20:21:06 +000034 * Jesper S Moller - bug 280555 - Add pluggable collation support
jmolleraaedb5f2009-12-16 14:18:49 +000035 * Jesper S Moller - bug 297958 Fix fn:nilled for elements
mgandhi247cdd82009-12-25 09:50:00 +000036 * Mukul Gandhi - bug 298519 improvements to fn:number implementation, catering
37 * to node arguments.
mgandhi1fc77412010-02-02 15:07:05 +000038 * Mukul Gandhi - bug 301539 fix for "context undefined" bug in case of zero
mgandhi13d897f2010-04-18 09:46:00 +000039 * arity of fn:name function.
40 * Mukul Gandhi - bug 309585 implementation of xs:normalizedString data type
jmollerb0289532010-06-24 23:16:07 +000041 * Jesper S Moller - bug 311480 - fix problem with name matching on keywords
jmoller2c384ed2010-06-24 23:48:34 +000042 * Jesper S Moller - bug 312191 - instance of test fails with partial matches
mgandhi247b6e72010-07-07 11:50:37 +000043 * Mukul Gandhi - bug 318313 - improvements to computation of typed values of nodes,
44 * when validated by XML Schema primitive types
dacarver879c37a2009-04-26 23:41:32 +000045 *******************************************************************************/
46package org.eclipse.wst.xml.xpath2.processor.test;
47
48import java.net.URL;
jmollerb601eb02009-09-02 20:21:06 +000049import java.util.Comparator;
dacarver879c37a2009-04-26 23:41:32 +000050
dacarver2b291392009-05-23 00:47:49 +000051import javax.xml.parsers.DocumentBuilder;
52import javax.xml.parsers.DocumentBuilderFactory;
53
dacarver879c37a2009-04-26 23:41:32 +000054import org.apache.xerces.xs.XSModel;
dacarver7d5e2922009-11-08 15:40:36 +000055import org.eclipse.core.runtime.Platform;
jmollerb601eb02009-09-02 20:21:06 +000056import org.eclipse.wst.xml.xpath2.processor.CollationProvider;
57import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
dacarver879c37a2009-04-26 23:41:32 +000058import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
59import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
mgandhi13d897f2010-04-18 09:46:00 +000060import org.eclipse.wst.xml.xpath2.processor.DynamicError;
dacarver879c37a2009-04-26 23:41:32 +000061import org.eclipse.wst.xml.xpath2.processor.Evaluator;
dacarver6018fcf2009-06-22 21:47:53 +000062import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
63import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
64import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
dacarver2915e2f2009-06-09 14:41:36 +000065import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal;
dacarvered2c87e2009-06-09 14:54:33 +000066import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble;
dacarverae395262009-07-02 04:30:16 +000067import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
dacarvered2c87e2009-06-09 14:54:33 +000068import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat;
dacarver7d5e2922009-11-08 15:40:36 +000069import org.osgi.framework.Bundle;
dacarver879c37a2009-04-26 23:41:32 +000070
71public class TestBugs extends AbstractPsychoPathTest {
dacarver23c40122009-11-13 23:26:23 +000072
jmollerb601eb02009-09-02 20:21:06 +000073 private static final String URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR = "urn:x-eclipse:xpath20:funky-collator";
dacarver23c40122009-11-13 23:26:23 +000074
75 private Bundle bundle;
76
dacarver7d5e2922009-11-08 15:40:36 +000077 @Override
78 protected void setUp() throws Exception {
79 // TODO Auto-generated method stub
80 super.setUp();
81 bundle = Platform
dacarver23c40122009-11-13 23:26:23 +000082 .getBundle("org.eclipse.wst.xml.xpath2.processor.tests");
dacarver7d5e2922009-11-08 15:40:36 +000083
84 }
jmollerb601eb02009-09-02 20:21:06 +000085
jmollerb0289532010-06-24 23:16:07 +000086 public void testNamesWhichAreKeywords() throws Exception {
87 // Bug 273719
88 URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml");
89 loadDOMDocument(fileURL);
90
91 // Get XML Schema Information for the Document
92 XSModel schema = getGrammar();
93
94 DynamicContext dc = setupDynamicContext(schema);
95
96// String xpath = "($input-context/atomic:root/atomic:integer) union ($input-context/atomic:root/atomic:integer)";
97 String xpath = "(/element/eq eq 'eq') or //child::xs:*";
98 XPath path = compileXPath(dc, xpath);
99
100 Evaluator eval = new DefaultEvaluator(dc, domDoc);
101 ResultSequence rs = eval.evaluate(path);
102
103 XSBoolean result = (XSBoolean) rs.first();
104
105 String actual = result.string_value();
106
107 assertEquals("true", actual);
108 }
109
dacarver879c37a2009-04-26 23:41:32 +0000110 public void testStringLengthWithElementArg() throws Exception {
111 // Bug 273719
112 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
113 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000114
dacarver879c37a2009-04-26 23:41:32 +0000115 // Get XML Schema Information for the Document
116 XSModel schema = getGrammar();
117
118 DynamicContext dc = setupDynamicContext(schema);
119
120 String xpath = "string-length(x) > 2";
121 XPath path = compileXPath(dc, xpath);
122
123 Evaluator eval = new DefaultEvaluator(dc, domDoc);
124 ResultSequence rs = eval.evaluate(path);
125
126 XSBoolean result = (XSBoolean) rs.first();
127
128 String actual = result.string_value();
129
130 assertEquals("true", actual);
dacarver84e43f52009-04-28 19:25:30 +0000131 }
dacarver6c9a7722009-05-24 01:16:07 +0000132
dacarver84e43f52009-04-28 19:25:30 +0000133 public void testBug273795Arity2() throws Exception {
134 // Bug 273795
135 URL fileURL = bundle.getEntry("/bugTestFiles/bug273795.xml");
136 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000137
dacarver84e43f52009-04-28 19:25:30 +0000138 // Get XML Schema Information for the Document
139 XSModel schema = getGrammar();
140
141 DynamicContext dc = setupDynamicContext(schema);
142
143 // test with arity 2
144 String xpath = "substring(x, 3) = 'happy'";
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);
155 }
dacarver6c9a7722009-05-24 01:16:07 +0000156
dacarver84e43f52009-04-28 19:25:30 +0000157 public void testBug273795Arity3() 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 3
168 String xpath = "substring(x, 3, 4) = 'happ'";
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
dacarver2b291392009-05-23 00:47:49 +0000181 public void testStringFunctionBug274471() throws Exception {
182 // Bug 274471
183 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
184 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000185
dacarver2b291392009-05-23 00:47:49 +0000186 // Get XML Schema Information for the Document
187 XSModel schema = getGrammar();
188
189 DynamicContext dc = setupDynamicContext(schema);
190
191 String xpath = "x/string() = 'unhappy'";
192 XPath path = compileXPath(dc, xpath);
193
194 Evaluator eval = new DefaultEvaluator(dc, domDoc);
195 ResultSequence rs = eval.evaluate(path);
196
197 XSBoolean result = (XSBoolean) rs.first();
198
199 String actual = result.string_value();
200
201 assertEquals("true", actual);
202 }
dacarver6c9a7722009-05-24 01:16:07 +0000203
dacarver2b291392009-05-23 00:47:49 +0000204 public void testStringLengthFunctionBug274471() throws Exception {
205 // Bug 274471. string-length() with arity 0
206 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
207 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000208
dacarver2b291392009-05-23 00:47:49 +0000209 // Get XML Schema Information for the Document
210 XSModel schema = getGrammar();
211
212 DynamicContext dc = setupDynamicContext(schema);
213
214 String xpath = "x/string-length() = 7";
215 XPath path = compileXPath(dc, xpath);
216
217 Evaluator eval = new DefaultEvaluator(dc, domDoc);
218 ResultSequence rs = eval.evaluate(path);
219
220 XSBoolean result = (XSBoolean) rs.first();
221
222 String actual = result.string_value();
223
dacarver9bffb272009-09-03 01:28:58 +0000224 assertEquals("false", actual);
dacarver2b291392009-05-23 00:47:49 +0000225 }
dacarver6c9a7722009-05-24 01:16:07 +0000226
dacarver2b291392009-05-23 00:47:49 +0000227 public void testNormalizeSpaceFunctionBug274471() throws Exception {
228 // Bug 274471. normalize-space() with arity 0
229 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
230 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000231
dacarver2b291392009-05-23 00:47:49 +0000232 // Get XML Schema Information for the Document
233 XSModel schema = getGrammar();
234
235 DynamicContext dc = setupDynamicContext(schema);
236
237 String xpath = "x/normalize-space() = 'unhappy'";
238 XPath path = compileXPath(dc, xpath);
239
240 Evaluator eval = new DefaultEvaluator(dc, domDoc);
241 ResultSequence rs = eval.evaluate(path);
242
243 XSBoolean result = (XSBoolean) rs.first();
244
245 String actual = result.string_value();
246
247 assertEquals("true", actual);
248 }
dacarver6c9a7722009-05-24 01:16:07 +0000249
dacarver9cd5a342009-05-23 01:05:06 +0000250 public void testAnyUriEqualityBug() throws Exception {
251 // Bug 274719
252 // reusing the XML document from another bug
253 URL fileURL = bundle.getEntry("/bugTestFiles/bug274471.xml");
254 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000255
dacarver9cd5a342009-05-23 01:05:06 +0000256 // Get XML Schema Information for the Document
257 XSModel schema = getGrammar();
258
259 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000260
dacarver9cd5a342009-05-23 01:05:06 +0000261 String xpath = "xs:anyURI('abc') eq xs:anyURI('abc')";
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 }
273
dacarverf585d0c2009-05-23 01:13:44 +0000274 public void testBaseUriBug() throws Exception {
dacarver2915e2f2009-06-09 14:41:36 +0000275 // Bug 274725
dacarver6c9a7722009-05-24 01:16:07 +0000276
dacarver23c40122009-11-13 23:26:23 +0000277 // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
278 // DocumentBuilder docBuilder = dbf.newDocumentBuilder();
dacarver3d638292009-07-15 21:19:37 +0000279 loadDOMDocument(new URL("http://www.w3schools.com/xml/note.xml"));
dacarver6c9a7722009-05-24 01:16:07 +0000280
281 // for testing this bug, we read the XML document from the web.
dacarverf585d0c2009-05-23 01:13:44 +0000282 // this ensures, that base-uri property of DOM is not null.
dacarver23c40122009-11-13 23:26:23 +0000283 // domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml");
dacarverf585d0c2009-05-23 01:13:44 +0000284
285 // we pass XSModel as null for this test case. Otherwise, we would
286 // get an exception.
287 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000288
dacarverf585d0c2009-05-23 01:13:44 +0000289 String xpath = "base-uri(note) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000290
291 // please note: The below XPath would also work, with base-uri using
292 // arity 0.
293 // String xpath =
294 // "note/base-uri() eq xs:anyURI('http://www.w3schools.com/xml/note.xml')";
295
dacarverf585d0c2009-05-23 01:13:44 +0000296 XPath path = compileXPath(dc, xpath);
297
298 Evaluator eval = new DefaultEvaluator(dc, domDoc);
299 ResultSequence rs = eval.evaluate(path);
300
301 XSBoolean result = (XSBoolean) rs.first();
302
303 String actual = result.string_value();
304
dacarveracf5e122009-08-05 02:48:43 +0000305 assertEquals("true", actual);
dacarverf585d0c2009-05-23 01:13:44 +0000306 }
dacarverf79d73e2009-05-23 01:28:16 +0000307
308 public void testDocumentUriBug() throws Exception {
309 // Bug 274731
310 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
311 DocumentBuilder docBuilder = dbf.newDocumentBuilder();
dacarver6c9a7722009-05-24 01:16:07 +0000312
dacarverf79d73e2009-05-23 01:28:16 +0000313 domDoc = docBuilder.parse("http://www.w3schools.com/xml/note.xml");
314
315 DynamicContext dc = setupDynamicContext(null);
dacarver6c9a7722009-05-24 01:16:07 +0000316
dacarverf79d73e2009-05-23 01:28:16 +0000317 String xpath = "document-uri(/) eq xs:anyURI('http://www.w3schools.com/xml/note.xml')";
dacarver6c9a7722009-05-24 01:16:07 +0000318
dacarverf79d73e2009-05-23 01:28:16 +0000319 XPath path = compileXPath(dc, xpath);
320
321 Evaluator eval = new DefaultEvaluator(dc, domDoc);
322 ResultSequence rs = eval.evaluate(path);
323
324 XSBoolean result = (XSBoolean) rs.first();
325
326 String actual = "false";
dacarver6c9a7722009-05-24 01:16:07 +0000327
dacarverf79d73e2009-05-23 01:28:16 +0000328 if (result != null) {
dacarver6c9a7722009-05-24 01:16:07 +0000329 actual = result.string_value();
dacarverf79d73e2009-05-23 01:28:16 +0000330 }
331
332 assertEquals("true", actual);
333 }
dacarver6c9a7722009-05-24 01:16:07 +0000334
dacarver2b291392009-05-23 00:47:49 +0000335 public void testBooleanTypeBug() throws Exception {
336 // Bug 274784
337 // reusing the XML document from another bug
338 URL fileURL = bundle.getEntry("/bugTestFiles/bug273719.xml");
339 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000340
dacarver2b291392009-05-23 00:47:49 +0000341 // Get XML Schema Information for the Document
342 XSModel schema = getGrammar();
343
344 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000345
dacarver2b291392009-05-23 00:47:49 +0000346 String xpath = "xs:boolean('1') eq xs:boolean('true')";
347 XPath path = compileXPath(dc, xpath);
348
349 Evaluator eval = new DefaultEvaluator(dc, domDoc);
350 ResultSequence rs = eval.evaluate(path);
351
352 XSBoolean result = (XSBoolean) rs.first();
353
354 String actual = result.string_value();
355
356 assertEquals("true", actual);
357 }
dacarver879c37a2009-04-26 23:41:32 +0000358
dacarver1d62b032009-05-23 01:39:15 +0000359 public void testDateConstructorBug() throws Exception {
360 // Bug 274792
361 URL fileURL = bundle.getEntry("/bugTestFiles/bug274792.xml");
362 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000363
dacarver1d62b032009-05-23 01:39:15 +0000364 // Get XML Schema Information for the Document
365 XSModel schema = getGrammar();
366
367 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000368
dacarver1d62b032009-05-23 01:39:15 +0000369 String xpath = "xs:date(x) eq xs:date('2009-01-01')";
370 XPath path = compileXPath(dc, xpath);
371
372 Evaluator eval = new DefaultEvaluator(dc, domDoc);
373 ResultSequence rs = eval.evaluate(path);
374
375 XSBoolean result = (XSBoolean) rs.first();
376
377 String actual = result.string_value();
378
379 assertEquals("true", actual);
380 }
dacarver6c9a7722009-05-24 01:16:07 +0000381
dacarver41c7f742009-05-23 02:10:24 +0000382 public void testIntegerDataTypeBug() throws Exception {
383 // Bug 274805
384 URL fileURL = bundle.getEntry("/bugTestFiles/bug274805.xml");
385 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000386
dacarver41c7f742009-05-23 02:10:24 +0000387 // Get XML Schema Information for the Document
388 XSModel schema = getGrammar();
389
390 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000391
dacarver41c7f742009-05-23 02:10:24 +0000392 String xpath = "xs:integer(x) gt 100";
393 XPath path = compileXPath(dc, xpath);
394
395 Evaluator eval = new DefaultEvaluator(dc, domDoc);
396 ResultSequence rs = eval.evaluate(path);
397
398 XSBoolean result = (XSBoolean) rs.first();
399
400 String actual = result.string_value();
401
402 assertEquals("true", actual);
dacarver6c9a7722009-05-24 01:16:07 +0000403 }
dacarver47328e82009-05-23 02:22:26 +0000404
405 public void testLongDataType() throws Exception {
406 // Bug 274952
dacarver23c40122009-11-13 23:26:23 +0000407 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver47328e82009-05-23 02:22:26 +0000408 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
409 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000410
dacarver47328e82009-05-23 02:22:26 +0000411 // Get XML Schema Information for the Document
412 XSModel schema = getGrammar();
413
414 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000415
dacarver47328e82009-05-23 02:22:26 +0000416 // long min value is -9223372036854775808
417 // and max value can be 9223372036854775807
418 String xpath = "xs:long('9223372036854775807') gt 0";
419 XPath path = compileXPath(dc, xpath);
420
421 Evaluator eval = new DefaultEvaluator(dc, domDoc);
422 ResultSequence rs = eval.evaluate(path);
423
424 XSBoolean result = (XSBoolean) rs.first();
425
426 String actual = result.string_value();
427
428 assertEquals("true", actual);
429 }
dacarver6c9a7722009-05-24 01:16:07 +0000430
dacarver10f28f12009-05-23 02:35:22 +0000431 public void testIntDataType() throws Exception {
432 // Bug 275105
dacarver23c40122009-11-13 23:26:23 +0000433 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver10f28f12009-05-23 02:35:22 +0000434 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
435 loadDOMDocument(fileURL);
dacarver6c9a7722009-05-24 01:16:07 +0000436
dacarver10f28f12009-05-23 02:35:22 +0000437 // Get XML Schema Information for the Document
438 XSModel schema = getGrammar();
439
440 DynamicContext dc = setupDynamicContext(schema);
dacarver6c9a7722009-05-24 01:16:07 +0000441
dacarver10f28f12009-05-23 02:35:22 +0000442 // int min value is -2147483648
443 // and max value can be 2147483647
444 String xpath = "xs:int('2147483647') gt 0";
445 XPath path = compileXPath(dc, xpath);
446
447 Evaluator eval = new DefaultEvaluator(dc, domDoc);
448 ResultSequence rs = eval.evaluate(path);
449
450 XSBoolean result = (XSBoolean) rs.first();
451
452 String actual = result.string_value();
453
454 assertEquals("true", actual);
455 }
dacarver6c9a7722009-05-24 01:16:07 +0000456
457 public void testSchemaAwarenessForAttributes() throws Exception {
458 // Bug 276134
459 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134.xml");
460 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134.xsd");
461
462 loadDOMDocument(fileURL, schemaURL);
463
464 // Get XSModel object for the Schema
465 XSModel schema = getGrammar(schemaURL);
466
467 DynamicContext dc = setupDynamicContext(schema);
468
469 String xpath = "person/@dob eq xs:date('2006-12-10')";
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
481 }
482
483 public void testSchemaAwarenessForElements() throws Exception {
484 // Bug 276134
485 URL fileURL = bundle.getEntry("/bugTestFiles/bug276134_2.xml");
486 URL schemaURL = bundle.getEntry("/bugTestFiles/bug276134_2.xsd");
487
488 loadDOMDocument(fileURL, schemaURL);
489
490 // Get XSModel object for the Schema
491 XSModel schema = getGrammar(schemaURL);
492
493 DynamicContext dc = setupDynamicContext(schema);
494
495 String xpath = "person/dob eq xs:date('2006-12-10')";
496 XPath path = compileXPath(dc, xpath);
497
498 Evaluator eval = new DefaultEvaluator(dc, domDoc);
499 ResultSequence rs = eval.evaluate(path);
500
501 XSBoolean result = (XSBoolean) rs.first();
502
503 String actual = result.string_value();
504
505 assertEquals("true", actual);
506 }
dacarver5f7e5d12009-06-09 14:30:40 +0000507
jmolleraaedb5f2009-12-16 14:18:49 +0000508 public void testNilled() throws Exception {
509 // This is a terrible shortcoming in the test suite, I'd say
510 URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml");
511 URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.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 assertTrue(evaluateBoolean(dc, "empty( nilled( / ) )"));
521 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/@attr1 ) )"));
522 assertTrue(evaluateBoolean(dc, "empty( nilled( /root/element1/text() ) )"));
523
524 assertFalse(evaluateBoolean(dc, "nilled(/root/element1)"));
525 assertTrue(evaluateBoolean(dc, "nilled(/root/element2)"));
526 assertFalse(evaluateBoolean(dc, "nilled(/root/element3)"));
527 assertFalse(evaluateBoolean(dc, "nilled(/root/element4)"));
528 }
529
530 // I can't stand to see so much duplicated code!!!
531 private boolean evaluateBoolean(DynamicContext dc, String xpath) throws Exception {
532 XPath path = compileXPath(dc, xpath);
533
534 Evaluator eval = new DefaultEvaluator(dc, domDoc);
535 ResultSequence rs = eval.evaluate(path);
536
537 XSBoolean result = (XSBoolean) rs.first();
538
539 return result.value();
540 }
541
dacarver9ebaa6f2009-05-25 03:16:50 +0000542 public void testXSNonPositiveInteger() throws Exception {
543 // Bug 277599
dacarver23c40122009-11-13 23:26:23 +0000544 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
545
dacarver9ebaa6f2009-05-25 03:16:50 +0000546 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
547 loadDOMDocument(fileURL);
548
549 // Get XML Schema Information for the Document
550 XSModel schema = getGrammar();
551
552 DynamicContext dc = setupDynamicContext(schema);
553
554 // min value of xs:nonPositiveInteger is -INF
555 // max value is 0
556 String xpath = "xs:nonPositiveInteger('0') eq 0";
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 String actual = result.string_value();
565
566 assertEquals("true", actual);
567 }
dacarver5f7e5d12009-06-09 14:30:40 +0000568
dacarverca9bc132009-05-25 03:31:41 +0000569 public void testXSNegativeInteger() throws Exception {
570 // Bug 277602
dacarver23c40122009-11-13 23:26:23 +0000571 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
572
dacarverca9bc132009-05-25 03:31:41 +0000573 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
574 loadDOMDocument(fileURL);
575
576 // Get XML Schema Information for the Document
577 XSModel schema = getGrammar();
578
579 DynamicContext dc = setupDynamicContext(schema);
580
581 // min value of xs:negativeInteger is -INF
582 // max value is -1
583 String xpath = "xs:negativeInteger('-1') eq -1";
584 XPath path = compileXPath(dc, xpath);
585
586 Evaluator eval = new DefaultEvaluator(dc, domDoc);
587 ResultSequence rs = eval.evaluate(path);
588
589 XSBoolean result = (XSBoolean) rs.first();
590
591 String actual = result.string_value();
592
593 assertEquals("true", actual);
594 }
dacarver5f7e5d12009-06-09 14:30:40 +0000595
dacarver72e78ba2009-05-25 03:40:46 +0000596 public void testXSShort() throws Exception {
597 // Bug 277608
dacarver23c40122009-11-13 23:26:23 +0000598 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000599
dacarver72e78ba2009-05-25 03:40:46 +0000600 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
601 loadDOMDocument(fileURL);
602
603 // Get XML Schema Information for the Document
604 XSModel schema = getGrammar();
605
606 DynamicContext dc = setupDynamicContext(schema);
607
608 // min value of xs:short is -32768
609 // max value of xs:short is 32767
610 String xpath = "xs:short('-32768') eq -32768";
611 XPath path = compileXPath(dc, xpath);
612
613 Evaluator eval = new DefaultEvaluator(dc, domDoc);
614 ResultSequence rs = eval.evaluate(path);
615
616 XSBoolean result = (XSBoolean) rs.first();
617
618 String actual = result.string_value();
619
620 assertEquals("true", actual);
621 }
dacarver5f7e5d12009-06-09 14:30:40 +0000622
dacarver1bb092e2009-05-25 04:02:48 +0000623 public void testXSNonNegativeInteger() throws Exception {
624 // Bug 277609
dacarver23c40122009-11-13 23:26:23 +0000625 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000626
dacarver1bb092e2009-05-25 04:02:48 +0000627 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
628 loadDOMDocument(fileURL);
629
630 // Get XML Schema Information for the Document
631 XSModel schema = getGrammar();
632
633 DynamicContext dc = setupDynamicContext(schema);
634
635 // min value of xs:nonNegativeInteger is 0
636 // max value of xs:nonNegativeInteger is INF
637 String xpath = "xs:nonNegativeInteger('0') eq 0";
638 XPath path = compileXPath(dc, xpath);
639
640 Evaluator eval = new DefaultEvaluator(dc, domDoc);
641 ResultSequence rs = eval.evaluate(path);
642
643 XSBoolean result = (XSBoolean) rs.first();
644
645 String actual = result.string_value();
646
647 assertEquals("true", actual);
648 }
dacarver5f7e5d12009-06-09 14:30:40 +0000649
dacarverc9ccc722009-05-25 04:21:43 +0000650 public void testXSUnsignedLong() throws Exception {
651 // Bug 277629
dacarver23c40122009-11-13 23:26:23 +0000652 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000653
dacarverc9ccc722009-05-25 04:21:43 +0000654 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
655 loadDOMDocument(fileURL);
656
657 // Get XML Schema Information for the Document
658 XSModel schema = getGrammar();
659
660 DynamicContext dc = setupDynamicContext(schema);
661
662 // min value of xs:unsignedLong is 0
663 // max value of xs:unsignedLong is 18446744073709551615
664 String xpath = "xs:unsignedLong('0') eq 0";
665 XPath path = compileXPath(dc, xpath);
666
667 Evaluator eval = new DefaultEvaluator(dc, domDoc);
668 ResultSequence rs = eval.evaluate(path);
669
670 XSBoolean result = (XSBoolean) rs.first();
671
672 String actual = result.string_value();
673
674 assertEquals("true", actual);
675 }
dacarver5f7e5d12009-06-09 14:30:40 +0000676
dacarvercde26452009-05-25 22:48:28 +0000677 public void testXSPositiveInteger() throws Exception {
678 // Bug 277632
dacarver23c40122009-11-13 23:26:23 +0000679 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000680
dacarvercde26452009-05-25 22:48:28 +0000681 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
682 loadDOMDocument(fileURL);
683
684 // Get XML Schema Information for the Document
685 XSModel schema = getGrammar();
686
687 DynamicContext dc = setupDynamicContext(schema);
688
689 // min value of xs:positiveInteger is 1
690 // max value of xs:positiveInteger is INF
691 String xpath = "xs:positiveInteger('1') eq 1";
692 XPath path = compileXPath(dc, xpath);
693
694 Evaluator eval = new DefaultEvaluator(dc, domDoc);
695 ResultSequence rs = eval.evaluate(path);
696
697 XSBoolean result = (XSBoolean) rs.first();
698
699 String actual = result.string_value();
700
701 assertEquals("true", actual);
702 }
dacarver5f7e5d12009-06-09 14:30:40 +0000703
dacarver2673f012009-05-25 23:08:56 +0000704 public void testXSByte() throws Exception {
705 // Bug 277639
dacarver23c40122009-11-13 23:26:23 +0000706 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000707
dacarver2673f012009-05-25 23:08:56 +0000708 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
709 loadDOMDocument(fileURL);
710
711 // Get XML Schema Information for the Document
712 XSModel schema = getGrammar();
713
714 DynamicContext dc = setupDynamicContext(schema);
715
716 // min value of xs:byte is -128
717 // max value of xs:byte is 127
718 String xpath = "xs:byte('-128') eq -128";
719 XPath path = compileXPath(dc, xpath);
720
721 Evaluator eval = new DefaultEvaluator(dc, domDoc);
722 ResultSequence rs = eval.evaluate(path);
723
724 XSBoolean result = (XSBoolean) rs.first();
725
726 String actual = result.string_value();
727
728 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000729 }
730
dacarver28cff4b2009-05-25 23:19:36 +0000731 public void testXSUnsignedInt() throws Exception {
732 // Bug 277642
dacarver23c40122009-11-13 23:26:23 +0000733 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver7d5e2922009-11-08 15:40:36 +0000734
dacarver28cff4b2009-05-25 23:19:36 +0000735 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
736 loadDOMDocument(fileURL);
737
738 // Get XML Schema Information for the Document
739 XSModel schema = getGrammar();
740
741 DynamicContext dc = setupDynamicContext(schema);
742
743 // min value of xs:unsignedInt is 0
744 // max value of xs:unsignedInt is 4294967295
745 String xpath = "xs:unsignedInt('4294967295') eq xs:unsignedInt('4294967295')";
746 XPath path = compileXPath(dc, xpath);
747
748 Evaluator eval = new DefaultEvaluator(dc, domDoc);
749 ResultSequence rs = eval.evaluate(path);
750
751 XSBoolean result = (XSBoolean) rs.first();
752
753 String actual = result.string_value();
754
755 assertEquals("true", actual);
dacarver2673f012009-05-25 23:08:56 +0000756 }
dacarver5f7e5d12009-06-09 14:30:40 +0000757
dacarver3cc95782009-05-25 23:33:47 +0000758 public void testXSUnsignedShort() throws Exception {
759 // Bug 277645
dacarver23c40122009-11-13 23:26:23 +0000760 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver3cc95782009-05-25 23:33:47 +0000761 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
762 loadDOMDocument(fileURL);
763
764 // Get XML Schema Information for the Document
765 XSModel schema = getGrammar();
766
767 DynamicContext dc = setupDynamicContext(schema);
768
769 // min value of xs:unsignedShort is 0
770 // max value of xs:unsignedShort is 65535
771 String xpath = "xs:unsignedShort('65535') eq 65535";
772 XPath path = compileXPath(dc, xpath);
773
774 Evaluator eval = new DefaultEvaluator(dc, domDoc);
775 ResultSequence rs = eval.evaluate(path);
776
777 XSBoolean result = (XSBoolean) rs.first();
778
779 String actual = result.string_value();
780
781 assertEquals("true", actual);
782 }
dacarver23c40122009-11-13 23:26:23 +0000783
dacarvered2c87e2009-06-09 14:54:33 +0000784 public void testXSYearMonthDurationMultiply() throws Exception {
785 // Bug 279373
dacarver23c40122009-11-13 23:26:23 +0000786 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver68d6e6c2009-05-25 23:43:42 +0000787 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
788 loadDOMDocument(fileURL);
789
790 // Get XML Schema Information for the Document
791 XSModel schema = getGrammar();
792
793 DynamicContext dc = setupDynamicContext(schema);
794
dacarvered2c87e2009-06-09 14:54:33 +0000795 String xpath = "xs:yearMonthDuration('P2Y11M') * 2.3";
dacarver68d6e6c2009-05-25 23:43:42 +0000796 XPath path = compileXPath(dc, xpath);
797
798 Evaluator eval = new DefaultEvaluator(dc, domDoc);
799 ResultSequence rs = eval.evaluate(path);
800
dacarverae395262009-07-02 04:30:16 +0000801 XSDuration result = (XSDuration) rs.first();
dacarver68d6e6c2009-05-25 23:43:42 +0000802
803 String actual = result.string_value();
804
dacarvered2c87e2009-06-09 14:54:33 +0000805 assertEquals("P6Y9M", actual);
dacarver68d6e6c2009-05-25 23:43:42 +0000806 }
dacarver23c40122009-11-13 23:26:23 +0000807
dacarvered2c87e2009-06-09 14:54:33 +0000808 public void testXSYearMonthDurationDivide1() throws Exception {
809 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000810 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000811 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
812 loadDOMDocument(fileURL);
813
814 // Get XML Schema Information for the Document
815 XSModel schema = getGrammar();
816
817 DynamicContext dc = setupDynamicContext(schema);
818
819 String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5";
820 XPath path = compileXPath(dc, xpath);
821
822 Evaluator eval = new DefaultEvaluator(dc, domDoc);
823 ResultSequence rs = eval.evaluate(path);
824
dacarverae395262009-07-02 04:30:16 +0000825 XSDuration result = (XSDuration) rs.first();
dacarvered2c87e2009-06-09 14:54:33 +0000826
827 String actual = result.string_value();
828
829 assertEquals("P1Y11M", actual);
830 }
dacarver23c40122009-11-13 23:26:23 +0000831
dacarvered2c87e2009-06-09 14:54:33 +0000832 public void testXSYearMonthDurationDivide2() throws Exception {
833 // Bug 279376
dacarver23c40122009-11-13 23:26:23 +0000834 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarvered2c87e2009-06-09 14:54:33 +0000835 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
836 loadDOMDocument(fileURL);
837
838 // Get XML Schema Information for the Document
839 XSModel schema = getGrammar();
840
841 DynamicContext dc = setupDynamicContext(schema);
842
843 String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')";
844 XPath path = compileXPath(dc, xpath);
845
846 Evaluator eval = new DefaultEvaluator(dc, domDoc);
847 ResultSequence rs = eval.evaluate(path);
848
849 XSDecimal result = (XSDecimal) rs.first();
850
851 String actual = result.string_value();
852
853 assertEquals("-2.5", actual);
854 }
dacarver23c40122009-11-13 23:26:23 +0000855
dacarver2915e2f2009-06-09 14:41:36 +0000856 public void testXSDayTimeDurationMultiply() throws Exception {
857 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000858 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000859 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
860 loadDOMDocument(fileURL);
861
862 // Get XML Schema Information for the Document
863 XSModel schema = getGrammar();
864
865 DynamicContext dc = setupDynamicContext(schema);
866
867 String xpath = "xs:dayTimeDuration('PT2H10M') * 2.1";
868 XPath path = compileXPath(dc, xpath);
869
870 Evaluator eval = new DefaultEvaluator(dc, domDoc);
871 ResultSequence rs = eval.evaluate(path);
872
dacarverae395262009-07-02 04:30:16 +0000873 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000874
875 String actual = result.string_value();
876
877 assertEquals("PT4H33M", actual);
878 }
dacarver23c40122009-11-13 23:26:23 +0000879
dacarver2915e2f2009-06-09 14:41:36 +0000880 public void testXSDayTimeDurationDivide() throws Exception {
881 // Bug 279377
dacarver23c40122009-11-13 23:26:23 +0000882 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver2915e2f2009-06-09 14:41:36 +0000883 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
884 loadDOMDocument(fileURL);
885
886 // Get XML Schema Information for the Document
887 XSModel schema = getGrammar();
888
889 DynamicContext dc = setupDynamicContext(schema);
890
891 String xpath = "xs:dayTimeDuration('P1DT2H30M10.5S') div 1.5";
892 XPath path = compileXPath(dc, xpath);
893
894 Evaluator eval = new DefaultEvaluator(dc, domDoc);
895 ResultSequence rs = eval.evaluate(path);
896
dacarverae395262009-07-02 04:30:16 +0000897 XSDuration result = (XSDuration) rs.first();
dacarver2915e2f2009-06-09 14:41:36 +0000898
899 String actual = result.string_value();
900
901 assertEquals("PT17H40M7S", actual);
902 }
dacarver23c40122009-11-13 23:26:23 +0000903
dacarvered2c87e2009-06-09 14:54:33 +0000904 public void testNegativeZeroDouble() throws Exception {
905 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000906 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver76b66582009-06-09 14:08:05 +0000907 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
908 loadDOMDocument(fileURL);
909
910 // Get XML Schema Information for the Document
911 XSModel schema = getGrammar();
912
913 DynamicContext dc = setupDynamicContext(schema);
914
dacarvered2c87e2009-06-09 14:54:33 +0000915 String xpath = "-(xs:double('0'))";
dacarver76b66582009-06-09 14:08:05 +0000916 XPath path = compileXPath(dc, xpath);
917
918 Evaluator eval = new DefaultEvaluator(dc, domDoc);
919 ResultSequence rs = eval.evaluate(path);
920
dacarvered2c87e2009-06-09 14:54:33 +0000921 XSDouble result = (XSDouble) rs.first();
dacarver76b66582009-06-09 14:08:05 +0000922
923 String actual = result.string_value();
924
dacarvered2c87e2009-06-09 14:54:33 +0000925 assertEquals("-0", actual);
dacarver76b66582009-06-09 14:08:05 +0000926 }
dacarver23c40122009-11-13 23:26:23 +0000927
dacarvered2c87e2009-06-09 14:54:33 +0000928 public void testNegativeZeroFloat() throws Exception {
929 // Bug 279406
dacarver23c40122009-11-13 23:26:23 +0000930 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000931 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
932 loadDOMDocument(fileURL);
933
934 // Get XML Schema Information for the Document
935 XSModel schema = getGrammar();
936
937 DynamicContext dc = setupDynamicContext(schema);
938
dacarvered2c87e2009-06-09 14:54:33 +0000939 String xpath = "-(xs:float('0'))";
dacarver5f7e5d12009-06-09 14:30:40 +0000940 XPath path = compileXPath(dc, xpath);
941
942 Evaluator eval = new DefaultEvaluator(dc, domDoc);
943 ResultSequence rs = eval.evaluate(path);
dacarvered2c87e2009-06-09 14:54:33 +0000944
945 XSFloat result = (XSFloat) rs.first();
946
dacarver5f7e5d12009-06-09 14:30:40 +0000947 String actual = result.string_value();
948
dacarvered2c87e2009-06-09 14:54:33 +0000949 assertEquals("-0", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000950 }
951
dacarvered2c87e2009-06-09 14:54:33 +0000952 public void testXSUnsignedByte() throws Exception {
953 // Bug 277650
dacarver23c40122009-11-13 23:26:23 +0000954 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver5f7e5d12009-06-09 14:30:40 +0000955 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
956 loadDOMDocument(fileURL);
957
958 // Get XML Schema Information for the Document
dacarver5f7e5d12009-06-09 14:30:40 +0000959 XSModel schema = getGrammar();
dacarver5f7e5d12009-06-09 14:30:40 +0000960
dacarvered2c87e2009-06-09 14:54:33 +0000961 DynamicContext dc = setupDynamicContext(schema);
962
963 // min value of xs:unsignedByte is 0
964 // max value of xs:unsignedByte is 255
965 String xpath = "xs:unsignedByte('255') eq 255";
dacarver5f7e5d12009-06-09 14:30:40 +0000966 XPath path = compileXPath(dc, xpath);
dacarvered2c87e2009-06-09 14:54:33 +0000967
dacarver5f7e5d12009-06-09 14:30:40 +0000968 Evaluator eval = new DefaultEvaluator(dc, domDoc);
969 ResultSequence rs = eval.evaluate(path);
970
dacarvered2c87e2009-06-09 14:54:33 +0000971 XSBoolean result = (XSBoolean) rs.first();
dacarver5f7e5d12009-06-09 14:30:40 +0000972
973 String actual = result.string_value();
974
dacarvered2c87e2009-06-09 14:54:33 +0000975 assertEquals("true", actual);
dacarver5f7e5d12009-06-09 14:30:40 +0000976 }
dacarver23c40122009-11-13 23:26:23 +0000977
dacarver9cfaa8e2009-06-22 21:37:15 +0000978 public void testXSBase64Binary() throws Exception {
979 // Bug 281046
dacarver23c40122009-11-13 23:26:23 +0000980 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver9cfaa8e2009-06-22 21:37:15 +0000981 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
982 loadDOMDocument(fileURL);
983
984 // Get XML Schema Information for the Document
985 XSModel schema = getGrammar();
986
987 DynamicContext dc = setupDynamicContext(schema);
988
989 String xpath = "xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q') eq xs:base64Binary('cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q')";
990 XPath path = compileXPath(dc, xpath);
991
992 Evaluator eval = new DefaultEvaluator(dc, domDoc);
993 ResultSequence rs = eval.evaluate(path);
994
995 XSBoolean result = (XSBoolean) rs.first();
996
997 String actual = result.string_value();
998
999 assertEquals("true", actual);
1000 }
dacarver23c40122009-11-13 23:26:23 +00001001
dacarver6018fcf2009-06-22 21:47:53 +00001002 public void testXSHexBinary() throws Exception {
1003 // Bug 281054
dacarver23c40122009-11-13 23:26:23 +00001004 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarver6018fcf2009-06-22 21:47:53 +00001005 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1006 loadDOMDocument(fileURL);
1007
1008 // Get XML Schema Information for the Document
1009 XSModel schema = getGrammar();
1010
1011 DynamicContext dc = setupDynamicContext(schema);
1012
1013 String xpath = "xs:hexBinary('767479716c6a647663') eq xs:hexBinary('767479716c6a647663')";
1014 XPath path = compileXPath(dc, xpath);
1015
1016 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1017 ResultSequence rs = eval.evaluate(path);
1018
1019 XSBoolean result = (XSBoolean) rs.first();
1020
1021 String actual = result.string_value();
1022
1023 assertEquals("true", actual);
1024 }
dacarver23c40122009-11-13 23:26:23 +00001025
mgandhiefe95742009-08-18 04:12:11 +00001026 public void testElementTypedValue() throws Exception {
1027 // test for fix in ElementType.java, involving incorrectly computing
1028 // typed value of element node, in case of validating element node,
1029 // with a user defined simple XSD type.
1030 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
dacarver23c40122009-11-13 23:26:23 +00001031 URL schemaURL = bundle
1032 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
mgandhiefe95742009-08-18 04:12:11 +00001033
1034 loadDOMDocument(fileURL, schemaURL);
1035
1036 // Get XSModel object for the Schema
1037 XSModel schema = getGrammar(schemaURL);
1038
1039 DynamicContext dc = setupDynamicContext(schema);
1040
1041 String xpath = "Example/Transportation/mode eq 'air'";
1042 XPath path = compileXPath(dc, xpath);
1043
1044 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1045 ResultSequence rs = eval.evaluate(path);
1046
1047 XSBoolean result = (XSBoolean) rs.first();
1048
1049 String actual = result.string_value();
1050
1051 assertEquals("true", actual);
1052
1053 }
dacarverf9402792009-08-22 01:14:10 +00001054
dacarver23c40122009-11-13 23:26:23 +00001055 public void testBug286061_quoted_string_literals_no_normalize()
1056 throws Exception {
dacarverf9402792009-08-22 01:14:10 +00001057
dacarver23c40122009-11-13 23:26:23 +00001058 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001059 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1060 loadDOMDocument(fileURL);
1061
1062 // Get XML Schema Information for the Document
1063 XSModel schema = getGrammar();
1064
1065 DynamicContext dc = setupDynamicContext(schema);
1066
dacarver23c40122009-11-13 23:26:23 +00001067 String xpath = "'\"\"'"; // the expression '""' contains no escapes
dacarverf9402792009-08-22 01:14:10 +00001068
1069 XPath path = compileXPath(dc, xpath);
1070
1071 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1072 ResultSequence rs = eval.evaluate(path);
1073
1074 String resultValue = rs.first().string_value();
1075
1076 assertEquals("\"\"", resultValue);
1077 }
dacarver23c40122009-11-13 23:26:23 +00001078
dacarverf9402792009-08-22 01:14:10 +00001079 public void testBug286061_quoted_string_literals() throws Exception {
1080
dacarver23c40122009-11-13 23:26:23 +00001081 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
dacarverf9402792009-08-22 01:14:10 +00001082 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1083 loadDOMDocument(fileURL);
1084
1085 // Get XML Schema Information for the Document
1086 XSModel schema = getGrammar();
1087
1088 DynamicContext dc = setupDynamicContext(schema);
1089
1090 String xpath = "concat( 'Don''t try this' , \" at \"\"home\"\",\" , ' she said' )";
1091
1092 XPath path = compileXPath(dc, xpath);
1093
1094 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1095 ResultSequence rs = eval.evaluate(path);
1096
1097 String resultValue = rs.first().string_value();
1098
1099 assertEquals("Don't try this at \"home\", she said", resultValue);
1100 }
1101
jmollerb601eb02009-09-02 20:21:06 +00001102 public void testBug280555_collations() throws Exception {
1103 // Setup context
1104 DefaultDynamicContext dc = setupDynamicContext(null);
1105 dc.set_collation_provider(createLengthCollatorProvider());
1106 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1107
1108 // Parse expression
1109 XPath path = compileXPath(dc, " 'abc' < 'de' ");
1110
1111 // Evaluate once
1112 XSBoolean bval = (XSBoolean) eval.evaluate(path).first();
1113 assertTrue("'abc' < 'def' for normal collations", bval.value());
dacarver23c40122009-11-13 23:26:23 +00001114
jmollerb601eb02009-09-02 20:21:06 +00001115 // Evaluate again with the funny collator
1116 dc.set_default_collation(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR);
1117 XSBoolean bval2 = (XSBoolean) eval.evaluate(path).first();
1118 assertFalse("'abc' < 'def' for normal collations", bval2.value());
dacarver23c40122009-11-13 23:26:23 +00001119 }
1120
mgandhiae92c592009-09-19 12:58:06 +00001121 public void testXPathDefaultNamespace() throws Exception {
1122 // Test for the fix, for xpathDefaultNamespace
dacarver23c40122009-11-13 23:26:23 +00001123 URL fileURL = bundle
1124 .getEntry("/bugTestFiles/xpathDefNamespaceTest.xml");
mgandhiae92c592009-09-19 12:58:06 +00001125 loadDOMDocument(fileURL);
1126
1127 // Get XML Schema Information for the Document
1128 XSModel schema = getGrammar();
1129
dacarver23c40122009-11-13 23:26:23 +00001130 // set up XPath default namespace in Dynamic Context
mgandhiae92c592009-09-19 12:58:06 +00001131 DynamicContext dc = setupDynamicContext(schema);
1132 addXPathDefaultNamespace("http://xyz");
1133
1134 String xpath = "X/message = 'hello'";
1135 XPath path = compileXPath(dc, xpath);
1136
1137 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1138 ResultSequence rs = eval.evaluate(path);
1139
1140 XSBoolean result = (XSBoolean) rs.first();
1141
1142 String actual = result.string_value();
1143
1144 assertEquals("true", actual);
1145 }
dacarver07849652009-11-28 00:09:27 +00001146
mgandhi80a468d2009-12-25 04:57:38 +00001147 public void testXPathInstanceOf1() throws Exception {
1148 // Bug 298267
1149 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1150 URL schemaURL = bundle
1151 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1152
1153 loadDOMDocument(fileURL, schemaURL);
1154
1155 // Get XSModel object for the Schema
1156 XSModel schema = getGrammar(schemaURL);
1157
1158 DynamicContext dc = setupDynamicContext(schema);
1159
1160 String xpath = "Example/Transportation/mode instance of element()";
1161 XPath path = compileXPath(dc, xpath);
1162
1163 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1164 ResultSequence rs = eval.evaluate(path);
1165
1166 XSBoolean result = (XSBoolean) rs.first();
1167
1168 String actual = result.string_value();
1169
1170 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001171 }
1172
1173 public void testXPathInstanceOf2() throws Exception {
1174 // Bug 298267
1175 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1176 URL schemaURL = bundle
1177 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1178
1179 loadDOMDocument(fileURL, schemaURL);
1180
1181 // Get XSModel object for the Schema
1182 XSModel schema = getGrammar(schemaURL);
1183
1184 DynamicContext dc = setupDynamicContext(schema);
1185
1186 String xpath = "Example/Transportation/mode instance of element(mode)";
1187 XPath path = compileXPath(dc, xpath);
1188
1189 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1190 ResultSequence rs = eval.evaluate(path);
1191
1192 XSBoolean result = (XSBoolean) rs.first();
1193
1194 String actual = result.string_value();
1195
1196 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001197 }
1198
mgandhi663fbd02009-12-27 11:23:35 +00001199 public void testXPathInstanceOf3() throws Exception {
mgandhi80a468d2009-12-25 04:57:38 +00001200 // Bug 298267
1201 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1202 URL schemaURL = bundle
1203 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1204
1205 loadDOMDocument(fileURL, schemaURL);
1206
1207 // Get XSModel object for the Schema
1208 XSModel schema = getGrammar(schemaURL);
1209
1210 DynamicContext dc = setupDynamicContext(schema);
1211
mgandhi663fbd02009-12-27 11:23:35 +00001212 String xpath = "Example/Transportation/mode instance of element(mode, modeType)";
mgandhi80a468d2009-12-25 04:57:38 +00001213 XPath path = compileXPath(dc, xpath);
1214
1215 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1216 ResultSequence rs = eval.evaluate(path);
1217
1218 XSBoolean result = (XSBoolean) rs.first();
1219
1220 String actual = result.string_value();
1221
dacarver5a6bbea2009-12-27 17:14:05 +00001222 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001223 }
1224
1225 public void testXPathInstanceOf4() throws Exception {
1226 // Bug 298267
1227 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1228 URL schemaURL = bundle
1229 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1230
1231 loadDOMDocument(fileURL, schemaURL);
1232
1233 // Get XSModel object for the Schema
1234 XSModel schema = getGrammar(schemaURL);
1235
1236 DynamicContext dc = setupDynamicContext(schema);
1237
1238 String xpath = "Example/Transportation/mode instance of element(mode, abc)";
1239 XPath path = compileXPath(dc, xpath);
1240
1241 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1242 ResultSequence rs = eval.evaluate(path);
1243
1244 XSBoolean result = (XSBoolean) rs.first();
1245
1246 String actual = result.string_value();
1247
1248 assertEquals("false", actual);
mgandhi247cdd82009-12-25 09:50:00 +00001249 }
1250
mgandhi663fbd02009-12-27 11:23:35 +00001251 public void testXPathInstanceOf5() throws Exception {
1252 // Bug 298267
1253 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1254 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.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/x instance of element(x, x_Type)*";
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("true", actual);
1274 }
jmoller2c384ed2010-06-24 23:48:34 +00001275
1276 public void testXPathInstanceOf5_2() 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, /Example) 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 assertEquals(false, result.value());
1297 }
1298
1299 public void testXPathInstanceOf5_3() throws Exception {
1300 // Bug 298267
1301 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1302 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1303
1304 loadDOMDocument(fileURL, schemaURL);
1305
1306 // Get XSModel object for the Schema
1307 XSModel schema = getGrammar(schemaURL);
1308
1309 DynamicContext dc = setupDynamicContext(schema);
1310
1311 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)";
1312 XPath path = compileXPath(dc, xpath);
1313
1314 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1315 ResultSequence rs = eval.evaluate(path);
1316
1317 XSBoolean result = (XSBoolean) rs.first();
1318
1319 assertFalse(result.value());
1320 }
1321
1322 public void testXPathInstanceOf5_4() throws Exception {
1323 // Bug 298267
1324 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1325 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1326
1327 loadDOMDocument(fileURL, schemaURL);
1328
1329 // Get XSModel object for the Schema
1330 XSModel schema = getGrammar(schemaURL);
1331
1332 DynamicContext dc = setupDynamicContext(schema);
1333
1334 String xpath = "(/Example/x, /Example/x) instance of element(x, x_Type)+";
1335 XPath path = compileXPath(dc, xpath);
1336
1337 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1338 ResultSequence rs = eval.evaluate(path);
1339
1340 XSBoolean result = (XSBoolean) rs.first();
1341
1342 assertTrue(result.value());
1343 }
1344
1345 public void testXPathInstanceOf5_5() throws Exception {
1346 // Bug 298267
1347 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1348 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1349
1350 loadDOMDocument(fileURL, schemaURL);
1351
1352 // Get XSModel object for the Schema
1353 XSModel schema = getGrammar(schemaURL);
1354
1355 DynamicContext dc = setupDynamicContext(schema);
1356
1357 String xpath = "(/Example/x instance of x_Type+) and (/Example/x[2]/@mesg instance of mesg_Type)";
1358 XPath path = compileXPath(dc, xpath);
1359
1360 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1361 ResultSequence rs = eval.evaluate(path);
1362
1363 XSBoolean result = (XSBoolean) rs.first();
1364
1365 assertEquals(true, result.value());
1366 }
1367
mgandhi663fbd02009-12-27 11:23:35 +00001368 public void testXPathInstanceOf6() throws Exception {
1369 // Bug 298267
1370 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1371 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1372
1373 loadDOMDocument(fileURL, schemaURL);
1374
1375 // Get XSModel object for the Schema
1376 XSModel schema = getGrammar(schemaURL);
1377
1378 DynamicContext dc = setupDynamicContext(schema);
1379
1380 String xpath = "Example/x instance of element(*, x_Type)*";
1381 XPath path = compileXPath(dc, xpath);
1382
1383 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1384 ResultSequence rs = eval.evaluate(path);
1385
1386 XSBoolean result = (XSBoolean) rs.first();
1387
1388 String actual = result.string_value();
1389
1390 assertEquals("true", actual);
1391 }
1392
1393 public void testXPathInstanceOf7() throws Exception {
1394 // Bug 298267
1395 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1396 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1397
1398 loadDOMDocument(fileURL, schemaURL);
1399
1400 // Get XSModel object for the Schema
1401 XSModel schema = getGrammar(schemaURL);
1402
1403 DynamicContext dc = setupDynamicContext(schema);
1404
1405 String xpath = "Example/x instance of element(x, x_Type)+";
1406 XPath path = compileXPath(dc, xpath);
1407
1408 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1409 ResultSequence rs = eval.evaluate(path);
1410
1411 XSBoolean result = (XSBoolean) rs.first();
1412
1413 String actual = result.string_value();
1414
dacarver3da20eb2009-12-29 14:29:45 +00001415 assertEquals("true", actual);
mgandhi663fbd02009-12-27 11:23:35 +00001416 }
1417
1418 public void testXPathInstanceNonExistantElement() throws Exception {
1419 // Bug 298267
1420 URL fileURL = bundle.getEntry("/bugTestFiles/elementTypedValueBug.xml");
1421 URL schemaURL = bundle
1422 .getEntry("/bugTestFiles/elementTypedValueBug.xsd");
1423
1424 loadDOMDocument(fileURL, schemaURL);
1425
1426 // Get XSModel object for the Schema
1427 XSModel schema = getGrammar(schemaURL);
1428
1429 DynamicContext dc = setupDynamicContext(schema);
1430
1431 String xpath = "Example/Transportation/mode instance of element(x)";
1432 XPath path = compileXPath(dc, xpath);
1433
1434 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1435 ResultSequence rs = eval.evaluate(path);
1436
1437 XSBoolean result = (XSBoolean) rs.first();
1438
1439 String actual = result.string_value();
1440
1441 assertEquals("false", actual);
1442 }
1443
mgandhi247cdd82009-12-25 09:50:00 +00001444 public void testFnNumber_Evaluation1() throws Exception {
1445 // Bug 298519
1446 URL fileURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xml");
1447 URL schemaURL = bundle.getEntry("/bugTestFiles/fnNumberBug.xsd");
mgandhi80a468d2009-12-25 04:57:38 +00001448
mgandhi247cdd82009-12-25 09:50:00 +00001449 loadDOMDocument(fileURL, schemaURL);
1450
1451 // Get XSModel object for the Schema
1452 XSModel schema = getGrammar(schemaURL);
1453
1454 DynamicContext dc = setupDynamicContext(schema);
1455
1456 String xpath = "number(Example/x) ge 18";
1457 XPath path = compileXPath(dc, xpath);
1458
1459 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1460 ResultSequence rs = eval.evaluate(path);
1461
1462 XSBoolean result = (XSBoolean) rs.first();
1463
1464 String actual = result.string_value();
1465
1466 assertEquals("true", actual);
1467 }
1468
1469 public void testFnNumber_Evaluation2() throws Exception {
1470 // Bug 298519
1471 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1472 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1473 loadDOMDocument(fileURL);
1474
1475 // Get XML Schema Information for the Document
1476 XSModel schema = getGrammar();
1477
1478 DynamicContext dc = setupDynamicContext(schema);
1479
1480 String xpath = "number(xs:unsignedByte('20')) ge 18";
1481 XPath path = compileXPath(dc, xpath);
1482
1483 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1484 ResultSequence rs = eval.evaluate(path);
1485
1486 XSBoolean result = (XSBoolean) rs.first();
1487
1488 String actual = result.string_value();
1489
1490 assertEquals("true", actual);
mgandhi80a468d2009-12-25 04:57:38 +00001491 }
mgandhie02bf582009-12-26 13:17:14 +00001492
1493 public void testAttrNode_Test1() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001494 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001495 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1496 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1497
1498 loadDOMDocument(fileURL, schemaURL);
1499
1500 // Get XSModel object for the Schema
1501 XSModel schema = getGrammar(schemaURL);
1502
1503 DynamicContext dc = setupDynamicContext(schema);
1504
1505 String xpath = "Example/x[1]/@mesg instance of attribute()";
1506 XPath path = compileXPath(dc, xpath);
1507
1508 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1509 ResultSequence rs = eval.evaluate(path);
1510
1511 XSBoolean result = (XSBoolean) rs.first();
1512
1513 String actual = result.string_value();
1514
1515 assertEquals("true", actual);
1516 }
1517
1518 public void testAttrNode_Test2() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001519 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001520 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1521 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1522
1523 loadDOMDocument(fileURL, schemaURL);
1524
1525 // Get XSModel object for the Schema
1526 XSModel schema = getGrammar(schemaURL);
1527
1528 DynamicContext dc = setupDynamicContext(schema);
1529
1530 String xpath = "Example/x[1]/@mesg instance of attribute(xx)";
1531 XPath path = compileXPath(dc, xpath);
1532
1533 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1534 ResultSequence rs = eval.evaluate(path);
1535
1536 XSBoolean result = (XSBoolean) rs.first();
1537
1538 String actual = result.string_value();
1539
1540 assertEquals("false", actual);
1541 }
1542
1543 public void testAttrNode_Test3() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001544 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001545 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1546 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1547
1548 loadDOMDocument(fileURL, schemaURL);
1549
1550 // Get XSModel object for the Schema
1551 XSModel schema = getGrammar(schemaURL);
1552
1553 DynamicContext dc = setupDynamicContext(schema);
1554
1555 String xpath = "Example/x[1]/@mesg instance of attribute(*, mesg_Type)";
1556 XPath path = compileXPath(dc, xpath);
1557
1558 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1559 ResultSequence rs = eval.evaluate(path);
1560
1561 XSBoolean result = (XSBoolean) rs.first();
1562
1563 String actual = result.string_value();
1564
1565 assertEquals("true", actual);
1566 }
1567
1568 public void testAttrNode_Test4() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001569 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001570 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1571 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1572
1573 loadDOMDocument(fileURL, schemaURL);
1574
1575 // Get XSModel object for the Schema
1576 XSModel schema = getGrammar(schemaURL);
1577
1578 DynamicContext dc = setupDynamicContext(schema);
1579
1580 String xpath = "Example/x[1]/@mesg instance of attribute(*, abc)";
1581 XPath path = compileXPath(dc, xpath);
1582
1583 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1584 ResultSequence rs = eval.evaluate(path);
1585
1586 XSBoolean result = (XSBoolean) rs.first();
1587
1588 String actual = result.string_value();
1589
1590 assertEquals("false", actual);
1591 }
1592
1593 public void testAttrNode_Test5() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001594 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001595 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1596 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1597
1598 loadDOMDocument(fileURL, schemaURL);
1599
1600 // Get XSModel object for the Schema
1601 XSModel schema = getGrammar(schemaURL);
1602
1603 DynamicContext dc = setupDynamicContext(schema);
1604
1605 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, mesg_Type)";
1606 XPath path = compileXPath(dc, xpath);
1607
1608 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1609 ResultSequence rs = eval.evaluate(path);
1610
1611 XSBoolean result = (XSBoolean) rs.first();
1612
1613 String actual = result.string_value();
1614
1615 assertEquals("true", actual);
1616 }
1617
1618 public void testAttrNode_Test6() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001619 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001620 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1621 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1622
1623 loadDOMDocument(fileURL, schemaURL);
1624
1625 // Get XSModel object for the Schema
1626 XSModel schema = getGrammar(schemaURL);
1627
1628 DynamicContext dc = setupDynamicContext(schema);
1629
1630 String xpath = "Example/x[1]/@mesg instance of attribute(mesg, abc)";
1631 XPath path = compileXPath(dc, xpath);
1632
1633 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1634 ResultSequence rs = eval.evaluate(path);
1635
1636 XSBoolean result = (XSBoolean) rs.first();
1637
1638 String actual = result.string_value();
1639
1640 assertEquals("false", actual);
1641 }
1642
1643 public void testAttrNode_Test7() throws Exception {
mgandhid52c9a32009-12-26 13:19:26 +00001644 // Bug 298535
mgandhie02bf582009-12-26 13:17:14 +00001645 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1646 URL schemaURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xsd");
1647
1648 loadDOMDocument(fileURL, schemaURL);
1649
1650 // Get XSModel object for the Schema
1651 XSModel schema = getGrammar(schemaURL);
1652
1653 DynamicContext dc = setupDynamicContext(schema);
1654
1655 String xpath = "Example/x/@mesg instance of attribute(mesg, mesg_Type)*";
1656 XPath path = compileXPath(dc, xpath);
1657
1658 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1659 ResultSequence rs = eval.evaluate(path);
1660
1661 XSBoolean result = (XSBoolean) rs.first();
1662
1663 String actual = result.string_value();
1664
1665 assertEquals("true", actual);
1666 }
mgandhi1fc77412010-02-02 15:07:05 +00001667
1668 public void testFnNameContextUndefined() throws Exception {
1669 // Bug 301539
1670 URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
1671 loadDOMDocument(fileURL);
1672
1673 // Get XML Schema Information for the Document
1674 XSModel schema = getGrammar();
1675
1676 DynamicContext dc = setupDynamicContext(schema);
1677
1678 String xpath = "Example/*[1]/name() eq 'x'";
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("true", actual);
1689 }
mgandhi13d897f2010-04-18 09:46:00 +00001690
1691 public void testXSNormalizedString() throws Exception {
1692 // Bug 309585
1693 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1694 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1695 loadDOMDocument(fileURL);
1696
1697 // Get XML Schema Information for the Document
1698 XSModel schema = getGrammar();
1699
1700 DynamicContext dc = setupDynamicContext(schema);
1701
1702 String xpath = "xs:normalizedString('abcs\t') eq xs:normalizedString('abcs')";
1703 XPath path = compileXPath(dc, xpath);
1704
1705 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1706
1707 boolean testSuccess = false;
1708 try {
1709 ResultSequence rs = eval.evaluate(path);
1710 }
1711 catch(DynamicError ex) {
1712 // a 'DynamicError' exception indicates, that this test is a success
1713 testSuccess = true;
1714 }
1715
1716 assertTrue(testSuccess);
1717 }
jmollerb0289532010-06-24 23:16:07 +00001718
1719 public void testParseElementKeywordsAsNodes() throws Exception {
1720 // Bug 311480
1721 bundle = Platform.getBundle("org.w3c.xqts.testsuite");
1722 URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
1723 loadDOMDocument(fileURL);
1724
1725 // Get XML Schema Information for the Document
1726 XSModel schema = getGrammar();
1727
1728 DynamicContext dc = setupDynamicContext(schema);
1729
1730 String xpath = "/element/attribute";
1731 XPath path = compileXPath(dc, xpath);
1732 }
1733
mgandhi247b6e72010-07-07 11:50:37 +00001734 public void testTypedValueEnhancement_primitiveTypes() throws Exception {
1735 // Bug 318313
1736 URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml");
1737 URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd");
1738
1739 loadDOMDocument(fileURL, schemaURL);
1740
1741 // Get XSModel object for the Schema
1742 XSModel schema = getGrammar(schemaURL);
1743
1744 DynamicContext dc = setupDynamicContext(schema);
1745
1746 String xpath = "X gt 99";
1747 XPath path = compileXPath(dc, xpath);
1748
1749 Evaluator eval = new DefaultEvaluator(dc, domDoc);
1750 ResultSequence rs = eval.evaluate(path);
1751
1752 XSBoolean result = (XSBoolean) rs.first();
1753
1754 String actual = result.string_value();
1755
1756 assertEquals("true", actual);
1757 }
1758
1759 private CollationProvider createLengthCollatorProvider() {
1760 return new CollationProvider() {
1761 @SuppressWarnings("unchecked")
1762 public Comparator get_collation(String name) {
1763 if (name.equals(URN_X_ECLIPSE_XPATH20_FUNKY_COLLATOR)) {
1764 return new Comparator<String>() {
1765 public int compare(String o1, String o2) {
1766 return o1.length() - o2.length();
1767 }
1768 };
1769 }
1770 return null;
1771 }
1772 };
1773 }
1774
dacarver879c37a2009-04-26 23:41:32 +00001775}