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