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