1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.qedeq.kernel.xml.parser; |
16 |
|
|
17 |
|
import java.io.IOException; |
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.apache.commons.lang.ArrayUtils; |
22 |
|
import org.qedeq.base.io.TextInput; |
23 |
|
import org.qedeq.base.utility.StringUtility; |
24 |
|
import org.qedeq.kernel.bo.test.QedeqBoTestCase; |
25 |
|
import org.qedeq.kernel.se.common.ModuleAddress; |
26 |
|
import org.qedeq.kernel.se.common.SourceFileException; |
27 |
|
import org.qedeq.kernel.se.common.SourceFileExceptionList; |
28 |
|
|
29 |
|
|
30 |
|
@link |
31 |
|
@link |
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 95.7% |
Uncovered Elements: 2 (46) |
Complexity: 7 |
Complexity Density: 0.19 |
|
35 |
|
public class CharsetParserTest extends QedeqBoTestCase { |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@throws |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
42 |
1
|
public void testParse1() throws Exception {... |
43 |
1
|
final ModuleAddress address = getServices() |
44 |
|
.getModuleAddress(getFile("charset/qedeq_utf8_with_errors_01.xml")); |
45 |
1
|
getServices().loadModule(address); |
46 |
1
|
assertFalse(getServices().checkWellFormedness(address)); |
47 |
1
|
final String[] errors = getSourceFileExceptionList(address); |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
1
|
assertEquals(2, errors.length); |
52 |
1
|
String[] lines = errors[0].split("\n"); |
53 |
1
|
assertTrue(lines[0].endsWith(":105:28:105:50")); |
54 |
1
|
assertTrue(lines[1].endsWith("\"\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df\u00e8\u00e9" |
55 |
|
+ "\u00ea\u00eb\u00c8\u00c9\u00ca\u00cb\u20ac\" [2]")); |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@throws |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
63 |
1
|
public void testParse2() throws Exception {... |
64 |
1
|
final ModuleAddress address = getServices() |
65 |
|
.getModuleAddress(getFile("charset/qedeq_utf16_with_errors_01.xml")); |
66 |
1
|
getServices().loadModule(address); |
67 |
1
|
assertFalse(getServices().checkWellFormedness(address)); |
68 |
1
|
final String[] errors = getSourceFileExceptionList(address); |
69 |
1
|
assertEquals(2, errors.length); |
70 |
1
|
String[] lines = errors[0].split("\n"); |
71 |
1
|
assertTrue(lines[0].endsWith(":105:28:105:50")); |
72 |
1
|
assertTrue(lines[1].endsWith("\"\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df\u00e8\u00e9" |
73 |
|
+ "\u00ea\u00eb\u00c8\u00c9\u00ca\u00cb\u20ac\" [2]")); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@param |
80 |
|
@return |
81 |
|
@throws |
82 |
|
|
|
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 5 |
Complexity Density: 0.24 |
|
83 |
2
|
public String[] getSourceFileExceptionList(final ModuleAddress address) throws IOException {... |
84 |
2
|
final List list = new ArrayList(); |
85 |
2
|
final SourceFileExceptionList sfl = getServices().getQedeqBo(address) |
86 |
|
.getErrors(); |
87 |
2
|
if (sfl != null) { |
88 |
2
|
final StringBuffer buffer |
89 |
|
= new StringBuffer(getServices().getSource(address)); |
90 |
2
|
final TextInput input = new TextInput(buffer); |
91 |
2
|
input.setPosition(0); |
92 |
2
|
final StringBuffer buf = new StringBuffer(); |
93 |
6
|
for (int i = 0; i < sfl.size(); i++) { |
94 |
4
|
buf.setLength(0); |
95 |
4
|
final SourceFileException sf = sfl.get(i); |
96 |
4
|
buf.append(sf.getDescription()); |
97 |
4
|
if (sf.getSourceArea() != null && sf.getSourceArea().getStartPosition() |
98 |
|
!= null) { |
99 |
4
|
buf.append("\n"); |
100 |
4
|
input.setRow(sf.getSourceArea().getStartPosition().getRow()); |
101 |
4
|
buf.append(StringUtility.replace(input.getLine(), "\t", " ")); |
102 |
4
|
buf.append("\n"); |
103 |
4
|
final StringBuffer whitespace = StringUtility.getSpaces( |
104 |
|
sf.getSourceArea().getStartPosition().getColumn() - 1); |
105 |
4
|
buffer.append(whitespace); |
106 |
4
|
buffer.append("^"); |
107 |
|
} |
108 |
4
|
list.add(buf.toString()); |
109 |
|
} |
110 |
|
} |
111 |
2
|
return (String[]) list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
} |