Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
17   96   4   4,25
0   49   0,24   4
4     1  
1    
 
  XPathLocationParserTest       Line # 32 17 4 100% 1.0
 
  (1)
 
1    /* $Id: XPathLocationParserTest.java,v 1.1 2008/07/26 08:01:10 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.xml.tracker;
19   
20    import java.io.File;
21   
22    import org.qedeq.base.io.IoUtility;
23    import org.qedeq.base.test.QedeqTestCase;
24    import org.qedeq.base.trace.Trace;
25   
26    /**
27    * Test {@link org.qedeq.kernel.xml.tracker.XPathLocationFinder}.
28    *
29    * @version $Revision: 1.1 $
30    * @author Michael Meyling
31    */
 
32    public class XPathLocationParserTest extends QedeqTestCase {
33   
34    /** This class. */
35    private static final Class CLASS = XPathLocationParserTest.class;
36   
 
37  1 toggle protected void setUp() throws Exception {
38  1 super.setUp();
39    }
40   
 
41  1 toggle protected void tearDown() throws Exception {
42  1 super.tearDown();
43    }
44   
45    /**
46    * Test {@link XPathLocationFinder}.
47    *
48    * @throws Exception Test failed.
49    */
 
50  1 toggle public final void testGetXPathLocation() throws Exception {
51  1 checkPosition("xpathLocationFinder.xml",
52    "/QEDEQ",
53    2, 1, 304, 9);
54  1 checkPosition("xpathLocationFinder.xml",
55    "/QEDEQ[1]",
56    2, 1, 304, 9);
57  1 checkPosition("xpathLocationFinder.xml",
58    "/QEDEQ/CHAPTER/SECTION/NODE",
59    100, 7, 139, 14);
60  1 checkPosition("xpathLocationFinder.xml",
61    "/QEDEQ/CHAPTER[1]/SECTION/NODE[1]",
62    100, 7, 139, 14);
63  1 checkPosition("xpathLocationFinder.xml",
64    "/QEDEQ/CHAPTER/SECTION/NODE@label",
65    100, 13, 100, 23);
66  1 checkPosition("xpathLocationFinder.xml",
67    "/QEDEQ/CHAPTER/SECTION/NODE[2]",
68    140, 7, 212, 14);
69  1 checkPosition("xpathLocationFinder.xml",
70    "/QEDEQ/CHAPTER/SECTION/NODE[2]/AXIOM/FORMULA/FORALL/FORALL/IMPL/FORALL/VAR@id",
71    165, 26, 165, 32);
72    }
73   
74    /**
75    * @param fileName Test this XML file.
76    * @param xpath XPath to find.
77    * @param startRow Expected resulting starting line.
78    * @param startCol Expected resulting starting column.
79    * @param endRow Expected resulting ending line.
80    * @param endCol Expected resulting ending column.
81    * @throws Exception Test failed.
82    */
 
83  7 toggle private void checkPosition(String fileName, String xpath, int startRow, int startCol,
84    int endRow, int endCol) throws Exception {
85  7 final File file = getFile(fileName);
86  7 final SimpleXPath result = XPathLocationParser.getXPathLocation(file, xpath,
87    IoUtility.toUrl(file));
88  7 Trace.param(CLASS, this, "checkPosition", "Start position", result.getStartLocation());
89  7 assertEquals(startRow, result.getStartLocation().getLine());
90  7 assertEquals(startCol, result.getStartLocation().getColumn());
91  7 Trace.param(CLASS, this, "checkPosition", "End position", result.getEndLocation());
92  7 assertEquals(endRow, result.getEndLocation().getLine());
93  7 assertEquals(endCol, result.getEndLocation().getColumn());
94    }
95   
96    }