Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
17   92   4   4.25
0   48   0.24   4
4     1  
1    
 
  XPathLocationParserTest       Line # 29 17 4 100% 1.0
 
  (1)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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.XPathLocationParser}.
26    *
27    * @author Michael Meyling
28    */
 
29    public class XPathLocationParserTest extends QedeqTestCase {
30   
31    /** This class. */
32    private static final Class CLASS = XPathLocationParserTest.class;
33   
 
34  1 toggle protected void setUp() throws Exception {
35  1 super.setUp();
36    }
37   
 
38  1 toggle protected void tearDown() throws Exception {
39  1 super.tearDown();
40    }
41   
42    /**
43    * Test {@link XPathLocationParser}.
44    *
45    * @throws Exception Test failed.
46    */
 
47  1 toggle public final void testGetXPathLocation() throws Exception {
48  1 checkPosition("xpathLocationFinder.xml",
49    "/QEDEQ",
50    2, 1, 304, 9);
51  1 checkPosition("xpathLocationFinder.xml",
52    "/QEDEQ[1]",
53    2, 1, 304, 9);
54  1 checkPosition("xpathLocationFinder.xml",
55    "/QEDEQ/CHAPTER/SECTION/NODE",
56    100, 7, 139, 14);
57  1 checkPosition("xpathLocationFinder.xml",
58    "/QEDEQ/CHAPTER[1]/SECTION/NODE[1]",
59    100, 7, 139, 14);
60  1 checkPosition("xpathLocationFinder.xml",
61    "/QEDEQ/CHAPTER/SECTION/NODE@label",
62    100, 13, 100, 23);
63  1 checkPosition("xpathLocationFinder.xml",
64    "/QEDEQ/CHAPTER/SECTION/NODE[2]",
65    140, 7, 212, 14);
66  1 checkPosition("xpathLocationFinder.xml",
67    "/QEDEQ/CHAPTER/SECTION/NODE[2]/AXIOM/FORMULA/FORALL/FORALL/IMPL/FORALL/VAR@id",
68    165, 26, 165, 32);
69    }
70   
71    /**
72    * @param fileName Test this XML file.
73    * @param xpath XPath to find.
74    * @param startRow Expected resulting starting line.
75    * @param startCol Expected resulting starting column.
76    * @param endRow Expected resulting ending line.
77    * @param endCol Expected resulting ending column.
78    * @throws Exception Test failed.
79    */
 
80  7 toggle private void checkPosition(String fileName, String xpath, int startRow, int startCol,
81    int endRow, int endCol) throws Exception {
82  7 final File file = getFile(fileName);
83  7 final SourceArea result = XPathLocationParser.findSourceArea(file, new SimpleXPath(xpath));
84  7 Trace.param(CLASS, this, "checkPosition", "Start position", result.getStartPosition());
85  7 assertEquals(startRow, result.getStartPosition().getRow());
86  7 assertEquals(startCol, result.getStartPosition().getColumn());
87  7 Trace.param(CLASS, this, "checkPosition", "End position", result.getEndPosition());
88  7 assertEquals(endRow, result.getEndPosition().getRow());
89  7 assertEquals(endCol, result.getEndPosition().getColumn());
90    }
91   
92    }