1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.xml.tracker; |
17 |
|
|
18 |
|
import java.io.ByteArrayOutputStream; |
19 |
|
import java.io.File; |
20 |
|
import java.io.PrintStream; |
21 |
|
|
22 |
|
import org.qedeq.base.test.QedeqTestCase; |
23 |
|
|
24 |
|
|
25 |
|
@link |
26 |
|
|
27 |
|
@author |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (90) |
Complexity: 14 |
Complexity Density: 0.18 |
|
29 |
|
public class XPathLocationFinderTest extends QedeqTestCase { |
30 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
31 |
9
|
protected void setUp() throws Exception {... |
32 |
9
|
super.setUp(); |
33 |
|
} |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
9
|
protected void tearDown() throws Exception {... |
36 |
9
|
super.tearDown(); |
37 |
|
} |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@throws |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
44 |
1
|
public final void testGetXPathLocation() throws Exception {... |
45 |
1
|
checkPosition("xpathLocationFinder.xml", |
46 |
|
"/QEDEQ", |
47 |
|
2, 1, 304, 9); |
48 |
1
|
checkPosition("xpathLocationFinder.xml", |
49 |
|
"/QEDEQ[1]", |
50 |
|
2, 1, 304, 9); |
51 |
1
|
checkPosition("xpathLocationFinder.xml", |
52 |
|
"/QEDEQ/CHAPTER/SECTION/NODE", |
53 |
|
100, 7, 139, 14); |
54 |
1
|
checkPosition("xpathLocationFinder.xml", |
55 |
|
"/QEDEQ/CHAPTER[1]/SECTION/NODE[1]", |
56 |
|
100, 7, 139, 14); |
57 |
1
|
checkPosition("xpathLocationFinder.xml", |
58 |
|
"/QEDEQ/CHAPTER/SECTION/NODE@label", |
59 |
|
100, 13, 100, 23); |
60 |
1
|
checkPosition("xpathLocationFinder.xml", |
61 |
|
"/QEDEQ/CHAPTER/SECTION/NODE[2]", |
62 |
|
140, 7, 212, 14); |
63 |
1
|
checkPosition("xpathLocationFinder.xml", |
64 |
|
"/QEDEQ/CHAPTER/SECTION/NODE[2]/AXIOM/FORMULA/FORALL/FORALL/IMPL/FORALL/VAR@id", |
65 |
|
165, 26, 165, 32); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
68 |
1
|
public void testHelp() throws Exception {... |
69 |
1
|
String result = executeError(new String[] {"-h"}); |
70 |
1
|
assertTrue(0 <= result.indexOf("Synopsis")); |
71 |
1
|
assertTrue(0 <= result.indexOf("Description")); |
72 |
1
|
assertTrue(0 <= result.indexOf("Options and Parameters")); |
73 |
1
|
assertTrue(0 <= result.indexOf("Example")); |
74 |
1
|
assertTrue(0 > result.indexOf("Unknown option")); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
77 |
1
|
public void testUnknownOption() throws Exception {... |
78 |
1
|
String result = executeError(new String[] {"-hs"}); |
79 |
1
|
assertTrue(0 <= result.indexOf("Synopsis")); |
80 |
1
|
assertTrue(0 <= result.indexOf("Description")); |
81 |
1
|
assertTrue(0 <= result.indexOf("Options and Parameters")); |
82 |
1
|
assertTrue(0 <= result.indexOf("Example")); |
83 |
1
|
assertTrue(0 <= result.indexOf("Unknown option")); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
86 |
1
|
public void testNoXPath() throws Exception {... |
87 |
1
|
String result = executeError(new String[] {"test.xml"}); |
88 |
1
|
assertTrue(0 <= result.indexOf("Synopsis")); |
89 |
1
|
assertTrue(0 <= result.indexOf("Description")); |
90 |
1
|
assertTrue(0 <= result.indexOf("Options and Parameters")); |
91 |
1
|
assertTrue(0 <= result.indexOf("Example")); |
92 |
1
|
assertTrue(0 > result.indexOf("Unknown option")); |
93 |
1
|
assertTrue(0 <= result.indexOf("XPath must be specified")); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
96 |
1
|
public void testFileNotSpecified() throws Exception {... |
97 |
1
|
String result = executeError(new String[] {"-xp", "none"}); |
98 |
1
|
assertTrue(0 <= result.indexOf("Synopsis")); |
99 |
1
|
assertTrue(0 <= result.indexOf("Description")); |
100 |
1
|
assertTrue(0 <= result.indexOf("Options and Parameters")); |
101 |
1
|
assertTrue(0 <= result.indexOf("Example")); |
102 |
1
|
assertTrue(0 > result.indexOf("Unknown option")); |
103 |
1
|
assertTrue(0 <= result.indexOf("XML file must be specified")); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
106 |
1
|
public void testXPathNotOk() throws Exception {... |
107 |
1
|
String result = executeError(new String[] {"-xp", "none", |
108 |
|
getFile("xpathLocationFinder.xml").toString()}); |
109 |
1
|
assertTrue(0 <= result.indexOf("XPath must start with '/'")); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
112 |
1
|
public void testXPathNotOk2() throws Exception {... |
113 |
1
|
String result = executeError(new String[] {"-xp", "", |
114 |
|
getFile("xpathLocationFinder.xml").toString()}); |
115 |
1
|
assertTrue(0 <= result.indexOf("XPath must not be empty")); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
118 |
1
|
public void testTagNotFound() throws Exception {... |
119 |
1
|
final boolean locationFailures = "true".equalsIgnoreCase( |
120 |
|
System.getProperty("qedeq.test.xmlLocationFailures", "false")); |
121 |
1
|
System.setProperty("qedeq.test.xmlLocationFailures", "false"); |
122 |
1
|
String result = execute(new String[] {"-xp", "/none", |
123 |
|
getFile("xpathLocationFinder.xml").toString()}); |
124 |
1
|
try { |
125 |
1
|
assertTrue(result.endsWith(":1:1:1:1")); |
126 |
|
} finally { |
127 |
1
|
System.setProperty("qedeq.test.xmlLocationFailures", |
128 |
|
Boolean.toString(locationFailures)); |
129 |
|
} |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
132 |
1
|
public void testFileNotOk() throws Exception {... |
133 |
1
|
executeError(new String[] {"-xp", "/none", "none"}); |
134 |
|
|
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@param |
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@param |
143 |
|
@param |
144 |
|
@throws |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
146 |
7
|
private void checkPosition(String fileName, String xpath, int startRow, int startCol,... |
147 |
|
int endRow, int endCol) throws Exception { |
148 |
7
|
final File file = getFile(fileName); |
149 |
|
|
150 |
7
|
final String[] args = new String[3]; |
151 |
7
|
args[0] = "-xp"; |
152 |
7
|
args[1] = xpath; |
153 |
7
|
args[2] = getFile(fileName).toString(); |
154 |
7
|
final String result = execute(args); |
155 |
7
|
assertTrue(result.endsWith(":" + startRow + ":" + startCol + ":" + endRow + ":" + endCol)); |
156 |
|
} |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
158 |
8
|
private String execute(final String[] args) throws Exception {... |
159 |
8
|
final ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); |
160 |
8
|
final PrintStream p = new PrintStream(byteOutput); |
161 |
8
|
final PrintStream old = System.out; |
162 |
8
|
System.setOut(p); |
163 |
8
|
try { |
164 |
8
|
XPathLocationFinder.main(args); |
165 |
8
|
p.flush(); |
166 |
8
|
final String result = byteOutput.toString(); |
167 |
8
|
return result.substring(result.indexOf("\n")).trim(); |
168 |
|
} finally { |
169 |
8
|
System.setOut(old); |
170 |
|
} |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
173 |
7
|
private String executeError(final String[] args) throws Exception {... |
174 |
7
|
final ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); |
175 |
7
|
final PrintStream p = new PrintStream(byteOutput); |
176 |
7
|
final PrintStream old1 = System.out; |
177 |
7
|
final PrintStream old2 = System.err; |
178 |
7
|
System.setOut(p); |
179 |
7
|
System.setErr(p); |
180 |
7
|
try { |
181 |
7
|
XPathLocationFinder.main(args); |
182 |
7
|
p.flush(); |
183 |
7
|
final String result = byteOutput.toString(); |
184 |
7
|
return result; |
185 |
|
} finally { |
186 |
7
|
System.setOut(old1); |
187 |
7
|
System.setErr(old2); |
188 |
|
|
189 |
|
} |
190 |
|
} |
191 |
|
|
192 |
|
} |