| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.qedeq.base.io; |
| 17 |
|
|
| 18 |
|
import java.io.ByteArrayOutputStream; |
| 19 |
|
import java.io.IOException; |
| 20 |
|
import java.io.OutputStream; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.lang.SystemUtils; |
| 23 |
|
import org.qedeq.base.test.QedeqTestCase; |
| 24 |
|
import org.qedeq.base.utility.StringUtility; |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
@link |
| 28 |
|
|
| 29 |
|
@author |
| 30 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (80) |
Complexity: 6 |
Complexity Density: 0.08 |
|
| 31 |
|
public class TextOutputTest extends QedeqTestCase { |
| 32 |
|
|
| 33 |
|
private static final String XML_DATA = |
| 34 |
|
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\012" |
| 35 |
|
+ "<QEDEQ \012" |
| 36 |
|
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" |
| 37 |
|
+ " xsi:noNamespaceSchemaLocation=\"http://www.qedeq.org/0_01_06/xml/qedeq.xsd\">\n" |
| 38 |
|
+ " <HEADER email=\"mime@qedeq.org\">\n" |
| 39 |
|
+ " <SPEC name=\"qedeq_sample1\" ruleVersion=\"1.00.00\">\n" |
| 40 |
|
+ " <LOCATIONS>\n" |
| 41 |
|
+ " \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>\n" |
| 42 |
|
+ " </LOCATIONS>\n" |
| 43 |
|
+ " </SPEC>\n" |
| 44 |
|
+ " <TITLE>\n" |
| 45 |
|
+ " <LATEX language=\"en\">\n" |
| 46 |
|
+ " Example1\n" |
| 47 |
|
+ " </LATEX>\n" |
| 48 |
|
+ " </TITLE>\n" |
| 49 |
|
+ " <ABSTRACT>\n" |
| 50 |
|
+ " <LATEX language=\"en\">\n" |
| 51 |
|
+ " 1789.01239In this very first qedeq module the XML specification is demonstrated.\n" |
| 52 |
|
+ " </LATEX>\n" |
| 53 |
|
+ " </ABSTRACT>\n" |
| 54 |
|
+ " <AUTHORS>\n" |
| 55 |
|
+ " <AUTHOR email=\"michael@meyling.com\">\n" |
| 56 |
|
+ " <LATEX language=\"de\">\n" |
| 57 |
|
+ " <![CDATA[Michael Meyling]]>\n" |
| 58 |
|
+ " </LATEX>\n" |
| 59 |
|
+ " </AUTHOR>\n" |
| 60 |
|
+ " </AUTHORS>\n" |
| 61 |
|
+ " </HEADER>\n" |
| 62 |
|
+ "</QEDEQ>\n"; |
| 63 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
3
|
protected void setUp() throws Exception {... |
| 65 |
3
|
super.setUp(); |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
3
|
protected void tearDown() throws Exception {... |
| 69 |
3
|
super.tearDown(); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@throws |
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (55) |
Complexity: 1 |
Complexity Density: 0.02 |
1
PASS
|
|
| 77 |
1
|
public void testComplete() throws Exception {... |
| 78 |
1
|
final ByteArrayOutputStream to = new ByteArrayOutputStream(); |
| 79 |
1
|
final TextOutput out = new TextOutput("flying toasters", to); |
| 80 |
1
|
out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); |
| 81 |
1
|
out.println("<QEDEQ "); |
| 82 |
1
|
out.pushLevel(); |
| 83 |
1
|
out.pushLevel(); |
| 84 |
1
|
out.levelPrint("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); |
| 85 |
1
|
out.println(); |
| 86 |
1
|
out.levelPrintln("xsi:noNamespaceSchemaLocation=\"http://www.qedeq.org/0_01_06/xml/qedeq.xsd\">"); |
| 87 |
1
|
out.popLevel(); |
| 88 |
1
|
out.levelPrintln("<HEADER email=\"mime@qedeq.org\">"); |
| 89 |
1
|
out.pushLevel(); |
| 90 |
1
|
out.levelPrint("<SPEC name=\"qedeq_sample1\" ruleVersion=\"1.00.00\">"); |
| 91 |
1
|
out.print(SystemUtils.LINE_SEPARATOR); |
| 92 |
1
|
out.pushLevel(); |
| 93 |
1
|
out.levelPrintln("<LOCATIONS>"); |
| 94 |
1
|
out.print((Object) (" \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>" |
| 95 |
|
+ SystemUtils.LINE_SEPARATOR)); |
| 96 |
1
|
out.levelPrintln("</LOCATIONS>"); |
| 97 |
1
|
out.popLevel(); |
| 98 |
1
|
out.levelPrintln("</SPEC>"); |
| 99 |
1
|
out.levelPrintln("<TITLE>"); |
| 100 |
1
|
out.pushLevel(); |
| 101 |
1
|
out.levelPrintln("<LATEX language=\"en\">"); |
| 102 |
1
|
out.levelPrintln(" Example1"); |
| 103 |
1
|
out.levelPrintln("</LATEX>"); |
| 104 |
1
|
out.popLevel(); |
| 105 |
1
|
out.levelPrintln("</TITLE>"); |
| 106 |
1
|
out.levelPrintln("<ABSTRACT>"); |
| 107 |
1
|
out.pushLevel(); |
| 108 |
1
|
out.levelPrintln("<LATEX language=\"en\">"); |
| 109 |
1
|
out.pushLevel(); |
| 110 |
1
|
out.levelPrintln(" 1789.01239In this very first qedeq module the XML specification is demonstrated."); |
| 111 |
1
|
out.popLevel(); |
| 112 |
1
|
out.levelPrintln("</LATEX>"); |
| 113 |
1
|
out.popLevel(); |
| 114 |
1
|
out.levelPrintln("</ABSTRACT>"); |
| 115 |
1
|
out.levelPrintln("<AUTHORS>"); |
| 116 |
1
|
out.pushLevel(); |
| 117 |
1
|
out.levelPrintln("<AUTHOR email=\"michael@meyling.com\">"); |
| 118 |
1
|
out.pushLevel(); |
| 119 |
1
|
out.levelPrintln("<LATEX language=\"de\">"); |
| 120 |
1
|
out.pushLevel(); |
| 121 |
1
|
out.levelPrintln(" <![CDATA[Michael Meyling]]>"); |
| 122 |
1
|
out.popLevel(); |
| 123 |
1
|
out.levelPrintln("</LATEX>"); |
| 124 |
1
|
out.popLevel(); |
| 125 |
1
|
out.levelPrintln("</AUTHOR>"); |
| 126 |
1
|
out.popLevel(); |
| 127 |
1
|
out.levelPrintln("</AUTHORS>"); |
| 128 |
1
|
out.println((Object) " </HEADER>"); |
| 129 |
1
|
out.pushLevel(); |
| 130 |
1
|
out.clearLevel(); |
| 131 |
1
|
out.levelPrintln("</QEDEQ>"); |
| 132 |
1
|
out.close(); |
| 133 |
|
|
| 134 |
|
|
| 135 |
1
|
assertEquals(StringUtility.string2Hex(StringUtility.replace(XML_DATA, |
| 136 |
|
"\n", SystemUtils.LINE_SEPARATOR), "ISO-8859-1"), |
| 137 |
|
StringUtility.byte2Hex(to.toByteArray())); |
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 140 |
1
|
public void testPushPop() throws Exception {... |
| 141 |
1
|
final ByteArrayOutputStream to = new ByteArrayOutputStream(); |
| 142 |
1
|
final TextOutput out = new TextOutput("jumper", to); |
| 143 |
1
|
out.popLevel(); |
| 144 |
1
|
out.popLevel(); |
| 145 |
1
|
out.levelPrint("James Bond"); |
| 146 |
1
|
assertEquals("James Bond", to.toString("UTF-8")); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@throws |
| 153 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 154 |
1
|
public void testErrorStream() throws Exception {... |
| 155 |
1
|
final OutputStream to = new OutputStream() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 156 |
2
|
public void write(int i) throws IOException {... |
| 157 |
2
|
throw new IOException("i have got you"); |
| 158 |
|
} |
| 159 |
|
}; |
| 160 |
1
|
TextOutput out = new TextOutput("flying toasters", to); |
| 161 |
1
|
assertFalse(out.checkError()); |
| 162 |
1
|
assertNull(out.getError()); |
| 163 |
1
|
out.flush(); |
| 164 |
1
|
assertFalse(out.checkError()); |
| 165 |
1
|
out.println("i am not written"); |
| 166 |
1
|
out.flush(); |
| 167 |
1
|
assertTrue(out.checkError()); |
| 168 |
|
|
| 169 |
1
|
assertEquals("Writing failed.", out.getError().getMessage()); |
| 170 |
|
|
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
|