KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jaxen > XPathTestBase


1 /*
2  * $Header: /home/projects/jaxen/scm/jaxen/src/java/test/org/jaxen/XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $
3  * $Revision: 1.36 $
4  * $Date: 2005/06/17 13:22:31 $
5  *
6  * ====================================================================
7  *
8  * Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions, and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions, and the disclaimer that follows
20  * these conditions in the documentation and/or other materials
21  * provided with the distribution.
22  *
23  * 3. The name "Jaxen" must not be used to endorse or promote products
24  * derived from this software without prior written permission. For
25  * written permission, please contact license@jaxen.org.
26  *
27  * 4. Products derived from this software may not be called "Jaxen", nor
28  * may "Jaxen" appear in their name, without prior written permission
29  * from the Jaxen Project Management (pm@jaxen.org).
30  *
31  * In addition, we request (but do not require) that you include in the
32  * end-user documentation provided with the redistribution and/or in the
33  * software itself an acknowledgement equivalent to the following:
34  * "This product includes software developed by the
35  * Jaxen Project (http://www.jaxen.org/)."
36  * Alternatively, the acknowledgment may be graphical using the logos
37  * available at http://www.jaxen.org/
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
43  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * ====================================================================
53  * This software consists of voluntary contributions made by many
54  * individuals on behalf of the Jaxen Project and was originally
55  * created by bob mcwhirter <bob@werken.com> and
56  * James Strachan <jstrachan@apache.org>. For more information on the
57  * Jaxen Project, please see <http://www.jaxen.org/>.
58  *
59  * $Id: XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $
60  */

61
62
63 package org.jaxen;
64
65 import junit.framework.TestCase;
66 import org.jaxen.function.StringFunction;
67 import org.jaxen.saxpath.helpers.XPathReaderFactory;
68 import org.jaxen.pattern.Pattern;
69
70 import java.util.ArrayList JavaDoc;
71 import java.util.Iterator JavaDoc;
72 import java.util.List JavaDoc;
73
74 public abstract class XPathTestBase extends TestCase
75 {
76     protected static String JavaDoc VAR_URI = "http://jaxen.org/test-harness/var";
77     protected static String JavaDoc TESTS_XML = "xml/test/tests.xml";
78
79     protected static boolean verbose = false;
80     protected static boolean debug = false;
81     private ContextSupport contextSupport;
82
83     public XPathTestBase(String JavaDoc name)
84     {
85         super(name);
86     }
87
88     public void setUp()
89     {
90         this.contextSupport = null;
91         System.setProperty(XPathReaderFactory.DRIVER_PROPERTY,
92                 "");
93         log("-----------------------------");
94     }
95
96     public void log(String JavaDoc text)
97     {
98         log(verbose,
99                 text);
100     }
101
102     public void log(boolean actualVerbose,
103                     String JavaDoc text)
104     {
105         if (actualVerbose) System.out.println(text);
106     }
107
108     protected void assertCountXPath(int expectedSize, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
109     {
110         assertCountXPath2(expectedSize, context, xpathStr);
111     }
112
113     protected Object JavaDoc assertCountXPath2(int expectedSize, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
114     {
115         log(debug,
116                 " Select :: " + xpathStr);
117         BaseXPath xpath = new BaseXPath(xpathStr);
118         List JavaDoc results = xpath.selectNodes(getContext(context));
119         log(debug,
120                 " Expected Size :: " + expectedSize);
121         log(debug,
122                 " Result Size :: " + results.size());
123         if (expectedSize != results.size())
124         {
125             log(debug,
126                     " ## FAILED");
127             log(debug,
128                     " ## xpath: " + xpath + " = " + xpath.debug());
129             Iterator JavaDoc resultIter = results.iterator();
130             while (resultIter.hasNext())
131             {
132                 log(debug,
133                         " --> " + resultIter.next());
134             }
135         }
136         assertEquals(xpathStr,
137                 expectedSize,
138                 results.size());
139         if (expectedSize > 0)
140         {
141             return results.get(0);
142         }
143         return null;
144     }
145
146     protected void assertInvalidXPath(Object JavaDoc context, String JavaDoc xpathStr)
147     {
148         try
149         {
150             log(debug,
151                     " Select :: " + xpathStr);
152             BaseXPath xpath = new BaseXPath(xpathStr);
153             List JavaDoc results = xpath.selectNodes(getContext(context));
154             log(debug,
155                     " Result Size :: " + results.size());
156             fail("An exception was expected.");
157         }
158         catch (UnsupportedAxisException e)
159         {
160             log(debug,
161                     " ## SKIPPED -- Unsupported Axis");
162         }
163         catch (JaxenException e)
164         {
165             log(debug, " Caught expected exception " + e.getMessage());
166         }
167     }
168
169     protected void assertValueOfXPath(String JavaDoc expected, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
170     {
171         try
172         {
173             BaseXPath xpath = new BaseXPath(xpathStr);
174             Object JavaDoc node = xpath.evaluate(getContext(context));
175             String JavaDoc result = StringFunction.evaluate(node,
176                     getNavigator());
177             log(debug,
178                     " Select :: " + xpathStr);
179             log(debug,
180                     " Expected :: " + expected);
181             log(debug,
182                     " Result :: " + result);
183             if (!expected.equals(result))
184             {
185                 log(debug,
186                         " ## FAILED");
187                 log(debug,
188                         " ## xpath: " + xpath + " = " + xpath.debug());
189             }
190             assertEquals(xpathStr,
191                     expected,
192                     result);
193         }
194         catch (UnsupportedAxisException e)
195         {
196             log(debug,
197                     " ## SKIPPED -- Unsupported Axis ");
198         }
199     }
200
201     protected Context getContext(Object JavaDoc contextNode)
202     {
203         Context context = new Context(getContextSupport());
204         List JavaDoc list = new ArrayList JavaDoc(1);
205         list.add(contextNode);
206         context.setNodeSet(list);
207         return context;
208     }
209
210     public ContextSupport getContextSupport()
211     {
212         if (this.contextSupport == null)
213         {
214             this.contextSupport = new ContextSupport(new SimpleNamespaceContext(),
215                     XPathFunctionContext.getInstance(),
216                     new SimpleVariableContext(),
217                     getNavigator());
218         }
219         return this.contextSupport;
220     }
221
222     public abstract Navigator getNavigator();
223
224     public abstract Object JavaDoc getDocument(String JavaDoc url) throws Exception JavaDoc;
225
226     public void testGetNodeType() throws FunctionCallException, UnsupportedAxisException
227     {
228         Navigator nav = getNavigator();
229         Object JavaDoc document = nav.getDocument("xml/testNamespaces.xml");
230         int count = 0;
231         Iterator JavaDoc descendantOrSelfAxisIterator = nav.getDescendantOrSelfAxisIterator(document);
232         while (descendantOrSelfAxisIterator.hasNext())
233         {
234             Object JavaDoc node = descendantOrSelfAxisIterator.next();
235             Iterator JavaDoc namespaceAxisIterator = nav.getNamespaceAxisIterator(node);
236             while (namespaceAxisIterator.hasNext())
237             {
238                 count++;
239                 assertEquals("Node type mismatch", Pattern.NAMESPACE_NODE, nav.getNodeType(namespaceAxisIterator.next()));
240             }
241         }
242         assertEquals(25, count);
243     }
244
245
246     /* test for jaxen-24
247     */

248     public void testid53371() throws JaxenException
249     {
250         Navigator nav = getNavigator();
251         String JavaDoc url = "xml/jaxen24.xml";
252         log("Document [" + url + "]");
253         Object JavaDoc document = nav.getDocument(url);
254         XPath contextpath = new BaseXPath("/body/div", nav);
255         log("Initial Context :: " + contextpath);
256         List JavaDoc list = contextpath.selectNodes(document);
257         Iterator JavaDoc iter = list.iterator();
258         while (iter.hasNext())
259         {
260             Object JavaDoc context = iter.next();
261             assertCountXPath(1, context, "preceding::*[1]");
262             assertValueOfXPath("span", context, "local-name(preceding::*[1])");
263         }
264     }
265
266     /* jaxen-58
267     */

268     public void testid53391() throws JaxenException
269     {
270         Navigator nav = getNavigator();
271         String JavaDoc url = "xml/jaxen24.xml";
272         log("Document [" + url + "]");
273         Object JavaDoc document = nav.getDocument(url);
274         XPath contextpath = new BaseXPath("/", nav);
275         log("Initial Context :: " + contextpath);
276         List JavaDoc list = contextpath.selectNodes(document);
277         Iterator JavaDoc iter = list.iterator();
278         while (iter.hasNext())
279         {
280             Object JavaDoc context = iter.next();
281             assertCountXPath(0, context, "//preceding::x");
282             assertCountXPath(0, context, "//following::x");
283             assertCountXPath(0, context, "/descendant::*/preceding::x");
284             assertCountXPath(0, context, "/descendant::node()/preceding::x");
285         }
286     }
287
288     /* test for jaxen-3
289     */

290     public void testid53430() throws JaxenException
291     {
292         Navigator nav = getNavigator();
293         String JavaDoc url = "xml/simple.xml";
294         log("Document [" + url + "]");
295         Object JavaDoc document = nav.getDocument(url);
296         XPath contextpath = new BaseXPath("/", nav);
297         log("Initial Context :: " + contextpath);
298         List JavaDoc list = contextpath.selectNodes(document);
299         Iterator JavaDoc iter = list.iterator();
300         while (iter.hasNext())
301         {
302             Object JavaDoc context = iter.next();
303             assertValueOfXPath("abd", context, "string()");
304         }
305     }
306
307     public void testid53441() throws JaxenException
308     {
309         Navigator nav = getNavigator();
310         String JavaDoc url = "xml/simple.xml";
311         log("Document [" + url + "]");
312         Object JavaDoc document = nav.getDocument(url);
313         XPath contextpath = new BaseXPath("/root", nav);
314         log("Initial Context :: " + contextpath);
315         List JavaDoc list = contextpath.selectNodes(document);
316         Iterator JavaDoc iter = list.iterator();
317         while (iter.hasNext())
318         {
319             Object JavaDoc context = iter.next();
320             assertValueOfXPath("abd", context, "string()");
321         }
322     }
323
324     public void testid53452() throws JaxenException
325     {
326         Navigator nav = getNavigator();
327         String JavaDoc url = "xml/simple.xml";
328         log("Document [" + url + "]");
329         Object JavaDoc document = nav.getDocument(url);
330         XPath contextpath = new BaseXPath("/root/a", nav);
331         log("Initial Context :: " + contextpath);
332         List JavaDoc list = contextpath.selectNodes(document);
333         Iterator JavaDoc iter = list.iterator();
334         while (iter.hasNext())
335         {
336             Object JavaDoc context = iter.next();
337             assertValueOfXPath("a", context, "string()");
338         }
339     }
340
341     public void testid53463() throws JaxenException
342     {
343         Navigator nav = getNavigator();
344         String JavaDoc url = "xml/simple.xml";
345         log("Document [" + url + "]");
346         Object JavaDoc document = nav.getDocument(url);
347         XPath contextpath = new BaseXPath("/root/c", nav);
348         log("Initial Context :: " + contextpath);
349         List JavaDoc list = contextpath.selectNodes(document);
350         Iterator JavaDoc iter = list.iterator();
351         while (iter.hasNext())
352         {
353             Object JavaDoc context = iter.next();
354             assertValueOfXPath("d", context, "string()");
355         }
356     }
357
358     /* test for jaxen-3
359     */

360     public void testid53482() throws JaxenException
361     {
362         Navigator nav = getNavigator();
363         String JavaDoc url = "xml/jaxen3.xml";
364         log("Document [" + url + "]");
365         Object JavaDoc document = nav.getDocument(url);
366         XPath contextpath = new BaseXPath("/", nav);
367         log("Initial Context :: " + contextpath);
368         List JavaDoc list = contextpath.selectNodes(document);
369         Iterator JavaDoc iter = list.iterator();
370         while (iter.hasNext())
371         {
372             Object JavaDoc context = iter.next();
373             assertCountXPath(1, context, "/Configuration/hostname/attrlist/hostname[. = 'CE-A'] ");
374         }
375     }
376
377     /* parser test cases all of which should fail
378     */

379     public void testid53502() throws JaxenException
380     {
381         Navigator nav = getNavigator();
382         String JavaDoc url = "xml/numbers.xml";
383         log("Document [" + url + "]");
384         Object JavaDoc document = nav.getDocument(url);
385         XPath contextpath = new BaseXPath("/", nav);
386         log("Initial Context :: " + contextpath);
387         List JavaDoc list = contextpath.selectNodes(document);
388         Iterator JavaDoc iter = list.iterator();
389         while (iter.hasNext())
390         {
391             Object JavaDoc context = iter.next();
392             /* repeated xpaths, jaxen-35
393             */

394             assertInvalidXPath(context, "/numbers numbers");
395             /* invalid xpath, jaxen-34
396             */

397             assertInvalidXPath(context, "/a/b[c > d]efg");
398             /* invalid xpath, jaxen-27
399             */

400             assertInvalidXPath(context, "/inv/child::");
401             /* invalid xpath, jaxen-26
402             */

403             assertInvalidXPath(context, "/invoice/@test[abcd");
404             assertInvalidXPath(context, "/invoice/@test[abcd > x");
405             /* unterminated string
406             */

407             assertInvalidXPath(context, "string-length('a");
408             /* various edge cases where code threw no exception
409             */

410             assertInvalidXPath(context, "/descendant::()");
411             assertInvalidXPath(context, "(1 + 1");
412         }
413     }
414
415     /* test cases for the use of underscores in names
416     */

417     public void testid53602() throws JaxenException
418     {
419         Navigator nav = getNavigator();
420         String JavaDoc url = "xml/underscore.xml";
421         log("Document [" + url + "]");
422         Object JavaDoc document = nav.getDocument(url);
423         XPath contextpath = new BaseXPath("/", nav);
424         log("Initial Context :: " + contextpath);
425         List JavaDoc list = contextpath.selectNodes(document);
426         Iterator JavaDoc iter = list.iterator();
427         while (iter.hasNext())
428         {
429             Object JavaDoc context = iter.next();
430             assertCountXPath(1, context, "/root/@a");
431             assertCountXPath(1, context, "/root/@_a");
432             assertCountXPath(1, context, "/root/b");
433             assertCountXPath(1, context, "/root/_b");
434             assertValueOfXPath("1", context, "/root/@a");
435             assertValueOfXPath("2", context, "/root/@_a");
436             assertValueOfXPath("1", context, "/root/b");
437             assertValueOfXPath("2", context, "/root/_b");
438         }
439     }
440
441     /* test cases for the use of = with node-sets
442     */

443     public void testid53662() throws JaxenException
444     {
445         Navigator nav = getNavigator();
446         String JavaDoc url = "xml/web.xml";
447         log("Document [" + url + "]");
448         Object JavaDoc document = nav.getDocument(url);
449         XPath contextpath = new BaseXPath("/", nav);
450         log("Initial Context :: " + contextpath);
451         List JavaDoc list = contextpath.selectNodes(document);
452         Iterator JavaDoc iter = list.iterator();
453         while (iter.hasNext())
454         {
455             Object JavaDoc context = iter.next();
456             assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'file'");
457             assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'snoop'");
458         }
459     }
460
461     public void testid53685() throws JaxenException
462     {
463         Navigator nav = getNavigator();
464         String JavaDoc url = "xml/numbers.xml";
465         log("Document [" + url + "]");
466         Object JavaDoc document = nav.getDocument(url);
467         XPath contextpath = new BaseXPath("/", nav);
468         log("Initial Context :: " + contextpath);
469         List JavaDoc list = contextpath.selectNodes(document);
470         Iterator JavaDoc iter = list.iterator();
471         while (iter.hasNext())
472         {
473             Object JavaDoc context = iter.next();
474             assertValueOfXPath("true", context, "/numbers/set/nr = '-3'");
475             assertValueOfXPath("true", context, "/numbers/set/nr = -3");
476             assertValueOfXPath("true", context, "/numbers/set/nr = 24");
477             assertValueOfXPath("true", context, "/numbers/set/nr/@value = '9999'");
478             assertValueOfXPath("true", context, "/numbers/set/nr/@value = 9999.0");
479             assertValueOfXPath("true", context, "/numbers/set/nr/@value = 66");
480         }
481     }
482
483     /* test basic math...
484     */

485     public void testid53733() throws JaxenException
486     {
487         Navigator nav = getNavigator();
488         String JavaDoc url = "xml/numbers.xml";
489         log("Document [" + url + "]");
490         Object JavaDoc document = nav.getDocument(url);
491         XPath contextpath = new BaseXPath("/", nav);
492         log("Initial Context :: " + contextpath);
493         List JavaDoc list = contextpath.selectNodes(document);
494         Iterator JavaDoc iter = list.iterator();
495         while (iter.hasNext())
496         {
497             Object JavaDoc context = iter.next();
498             assertValueOfXPath("true", context, "(8 * 2 + 1) = 17");
499             assertValueOfXPath("true", context, "(1 + 8 * 2) = 17");
500             assertValueOfXPath("true", context, "(7 - 3 + 1) = 5");
501             assertValueOfXPath("true", context, "(8 - 4 + 5 - 6) = 3");
502             /* left-assoc tests, comments show WRONG evaluation
503             */

504             /* 3 - 2 - 1 != 2
505             */

506             assertValueOfXPath("0", context, "3 - 2 - 1");
507             /* 8 div 4 div 2 != 4
508             */

509             assertValueOfXPath("1", context, "8 div 4 div 2");
510             /* 3 mod 5 mod 7 != 1
511             */

512             assertValueOfXPath("3", context, "3 mod 7 mod 5");
513             /* 1=(2=2) is true
514             */

515             assertValueOfXPath("false", context, "1 = 2 = 2");
516             /* 2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false
517             */

518             assertValueOfXPath("false", context, "2 != 3 != 1");
519             /* 3 > (2 > 1) is true
520             */

521             assertValueOfXPath("false", context, "3 > 2 > 1");
522             /* 3 >= (2 >= 2) is true
523             */

524             assertValueOfXPath("false", context, "3 >= 2 >= 2");
525             /* 1 < (2 < 3) is false
526             */

527             assertValueOfXPath("true", context, "1 < 2 < 3");
528             /* 0 <= (2 <= 3) is true
529             */

530             assertValueOfXPath("true", context, "2 <= 2 <= 3");
531         }
532     }
533
534     /* test cases for preceding axis with different node types
535     */

536     public void testid53850() throws JaxenException
537     {
538         Navigator nav = getNavigator();
539         String JavaDoc url = "xml/pi2.xml";
540         log("Document [" + url + "]");
541         Object JavaDoc document = nav.getDocument(url);
542         XPath contextpath = new BaseXPath("/a/c", nav);
543         log("Initial Context :: " + contextpath);
544         List JavaDoc list = contextpath.selectNodes(document);
545         Iterator JavaDoc iter = list.iterator();
546         while (iter.hasNext())
547         {
548             Object JavaDoc context = iter.next();
549             assertCountXPath(1, context, "//processing-instruction()");
550             assertCountXPath(1, context, "preceding-sibling::*");
551             assertCountXPath(5, context, "preceding-sibling::node()");
552             assertCountXPath(1, context, "preceding-sibling::*[1]");
553             assertCountXPath(1, context, "preceding-sibling::processing-instruction()");
554             assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::processing-instruction()");
555             assertValueOfXPath("foo", context, "preceding-sibling::*[1]");
556             assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::node()[2]");
557         }
558     }
559
560     public void testid53911() throws JaxenException
561     {
562         Navigator nav = getNavigator();
563         String JavaDoc url = "xml/id.xml";
564         log("Document [" + url + "]");
565         Object JavaDoc document = nav.getDocument(url);
566         XPath contextpath = new BaseXPath("/", nav);
567         log("Initial Context :: " + contextpath);
568         List JavaDoc list = contextpath.selectNodes(document);
569         SimpleVariableContext varContext = new SimpleVariableContext();
570         varContext.setVariableValue(null, "foobar", "foobar");
571         varContext.setVariableValue(null, "foo", "foo");
572         getContextSupport().setVariableContext(varContext);
573         Iterator JavaDoc iter = list.iterator();
574         while (iter.hasNext())
575         {
576             Object JavaDoc context = iter.next();
577             assertValueOfXPath("foobar", context, "$foobar");
578             assertCountXPath(1, context, "/foo[@id=$foobar]");
579             assertCountXPath(0, context, "/foo[@id='$foobar']");
580             assertCountXPath(1, context, "/foo[concat($foo, 'bar')=@id]");
581             assertCountXPath(0, context, "CD_Library/artist[@name=$artist]");
582         }
583     }
584
585     public void testid53957() throws JaxenException
586     {
587         Navigator nav = getNavigator();
588         String JavaDoc url = "xml/id.xml";
589         log("Document [" + url + "]");
590         Object JavaDoc document = nav.getDocument(url);
591         XPath contextpath = new BaseXPath("/", nav);
592         log("Initial Context :: " + contextpath);
593         List JavaDoc list = contextpath.selectNodes(document);
594         Iterator JavaDoc iter = list.iterator();
595         while (iter.hasNext())
596         {
597             Object JavaDoc context = iter.next();
598             /* attributes have a parent: their element
599             */

600             assertCountXPath(1, context, "/foo/@id/parent::foo");
601         }
602     }
603
604     /* attributes can also be used as context nodes
605     */

606     public void testid53975() throws JaxenException
607     {
608         Navigator nav = getNavigator();
609         String JavaDoc url = "xml/id.xml";
610         log("Document [" + url + "]");
611         Object JavaDoc document = nav.getDocument(url);
612         XPath contextpath = new BaseXPath("/foo/@id", nav);
613         log("Initial Context :: " + contextpath);
614         List JavaDoc list = contextpath.selectNodes(document);
615         Iterator JavaDoc iter = list.iterator();
616         while (iter.hasNext())
617         {
618             Object JavaDoc context = iter.next();
619             assertCountXPath(1, context, "parent::foo");
620         }
621     }
622
623     public void testid53992() throws JaxenException
624     {
625         Navigator nav = getNavigator();
626         String JavaDoc url = "xml/pi.xml";
627         log("Document [" + url + "]");
628         Object JavaDoc document = nav.getDocument(url);
629         XPath contextpath = new BaseXPath("/", nav);
630         log("Initial Context :: " + contextpath);
631         List JavaDoc list = contextpath.selectNodes(document);
632         Iterator JavaDoc iter = list.iterator();
633         while (iter.hasNext())
634         {
635             Object JavaDoc context = iter.next();
636             assertCountXPath(3, context, "//processing-instruction()");
637             assertCountXPath(2, context, "//processing-instruction('cheese')");
638             try
639             {
640                 Object JavaDoc result = assertCountXPath2(1, context, "//processing-instruction('toast')");
641                 assertValueOfXPath("is tasty", result, "string()");
642             }
643             catch (UnsupportedAxisException e)
644             {
645                 log(debug, " ## SKIPPED -- Unsupported Axis");
646             }
647         }
648     }
649
650     /* test evaluate() extension function
651     */

652     public void testid54032() throws JaxenException
653     {
654         Navigator nav = getNavigator();
655         String JavaDoc url = "xml/evaluate.xml";
656         log("Document [" + url + "]");
657         Object JavaDoc document = nav.getDocument(url);
658         XPath contextpath = new BaseXPath("/", nav);
659         log("Initial Context :: " + contextpath);
660         List JavaDoc list = contextpath.selectNodes(document);
661         Iterator JavaDoc iter = list.iterator();
662         while (iter.hasNext())
663         {
664             Object JavaDoc context = iter.next();
665             assertCountXPath(3, context, "evaluate('//jumps/*')");
666             assertCountXPath(1, context, "evaluate('//jumps/object/dog')");
667             assertCountXPath(0, context, "evaluate('//jumps/object')/evaluate");
668             assertCountXPath(1, context, "evaluate('//jumps/object')/dog");
669             assertCountXPath(1, context, "evaluate('//jumps/*')/dog");
670             assertCountXPath(1, context, "//metatest[ evaluate(@select) = . ]");
671         }
672     }
673
674     public void testid54082() throws JaxenException
675     {
676         Navigator nav = getNavigator();
677         String JavaDoc url = "xml/numbers.xml";
678         log("Document [" + url + "]");
679         Object JavaDoc document = nav.getDocument(url);
680         XPath contextpath = new BaseXPath("/numbers/set[1]", nav);
681         log("Initial Context :: " + contextpath);
682         List JavaDoc list = contextpath.selectNodes(document);
683         Iterator JavaDoc iter = list.iterator();
684         while (iter.hasNext())
685         {
686             Object JavaDoc context = iter.next();
687             assertCountXPath(1, context, "*[-3 = .]");
688             assertValueOfXPath("true", context, "54 < *");
689             assertValueOfXPath("true", context, "55 <= *");
690             assertValueOfXPath("false", context, "69 < *");
691             assertValueOfXPath("true", context, "-2 > *");
692             assertValueOfXPath("true", context, "-3 >= *");
693             assertValueOfXPath("false", context, "-4 >= *");
694         }
695     }
696
697     /* TODO
698     This context should work, but needs a fixed version of saxpath to parse the right-hand side
699     of the greater-than expression.
700     <context select="/numbers/set[2]">
701       <valueOf select="1 &gt; nr/@value">false</valueOf>
702       <valueOf select="55 &gt; nr/@value">false</valueOf>
703       <valueOf select="55 &gt;= nr/@value">true</valueOf>
704       <valueOf select="1000000 &gt; nr/@value">true</valueOf>
705     </context>
706     
707     */

708     /* test sibling axes
709     */

710     public void testid54145() throws JaxenException
711     {
712         Navigator nav = getNavigator();
713         String JavaDoc url = "xml/axis.xml";
714         log("Document [" + url + "]");
715         Object JavaDoc document = nav.getDocument(url);
716         XPath contextpath = new BaseXPath("/root", nav);
717         log("Initial Context :: " + contextpath);
718         List JavaDoc list = contextpath.selectNodes(document);
719         Iterator JavaDoc iter = list.iterator();
720         while (iter.hasNext())
721         {
722             Object JavaDoc context = iter.next();
723             assertCountXPath(0, context, "preced