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