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 |
|
import java.io.PrintStream; |
22 |
|
|
23 |
|
import org.qedeq.base.test.QedeqTestCase; |
24 |
|
import org.qedeq.base.utility.StringUtility; |
25 |
|
|
26 |
|
|
27 |
|
@link |
28 |
|
|
29 |
|
@author |
30 |
|
|
|
|
| 99% |
Uncovered Elements: 1 (104) |
Complexity: 9 |
Complexity Density: 0.09 |
|
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 |
5
|
protected void setUp() throws Exception {... |
65 |
5
|
super.setUp(); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
5
|
protected void tearDown() throws Exception {... |
69 |
5
|
super.tearDown(); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@throws |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
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, "ISO-8859-1"); |
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.print("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); |
85 |
1
|
out.println(); |
86 |
1
|
out.println("xsi:noNamespaceSchemaLocation=\"http://www.qedeq.org/0_01_06/xml/qedeq.xsd\">"); |
87 |
1
|
out.popLevel(); |
88 |
1
|
out.println("<HEADER email=\"mime@qedeq.org\">"); |
89 |
1
|
out.pushLevel(); |
90 |
1
|
out.print("<SPEC name=\"qedeq_sample1\" ruleVersion=\"1.00.00\">"); |
91 |
1
|
out.println(); |
92 |
1
|
out.pushLevel(); |
93 |
1
|
out.println("<LOCATIONS>"); |
94 |
1
|
out.print((Object) (" \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>")); |
95 |
1
|
out.println(); |
96 |
1
|
out.println("</LOCATIONS>"); |
97 |
1
|
out.popLevel(); |
98 |
1
|
out.println("</SPEC>"); |
99 |
1
|
out.println("<TITLE>"); |
100 |
1
|
out.pushLevel(); |
101 |
1
|
out.println("<LATEX language=\"en\">"); |
102 |
1
|
out.println(" Example1"); |
103 |
1
|
out.println("</LATEX>"); |
104 |
1
|
out.popLevel(); |
105 |
1
|
out.println("</TITLE>"); |
106 |
1
|
out.println("<ABSTRACT>"); |
107 |
1
|
out.pushLevel(); |
108 |
1
|
out.println("<LATEX language=\"en\">"); |
109 |
1
|
out.pushLevel(); |
110 |
1
|
out.println(" 1789.01239In this very first qedeq module the XML specification is demonstrated."); |
111 |
1
|
out.popLevel(); |
112 |
1
|
out.println("</LATEX>"); |
113 |
1
|
out.popLevel(); |
114 |
1
|
out.println("</ABSTRACT>"); |
115 |
1
|
out.println("<AUTHORS>"); |
116 |
1
|
out.pushLevel(); |
117 |
1
|
out.println("<AUTHOR email=\"michael@meyling.com\">"); |
118 |
1
|
out.pushLevel(); |
119 |
1
|
out.println("<LATEX language=\"de\">"); |
120 |
1
|
out.pushLevel(); |
121 |
1
|
out.println(" <![CDATA[Michael Meyling]]>"); |
122 |
1
|
out.popLevel(); |
123 |
1
|
out.println("</LATEX>"); |
124 |
1
|
out.popLevel(); |
125 |
1
|
out.println("</AUTHOR>"); |
126 |
1
|
out.popLevel(); |
127 |
1
|
out.println("</AUTHORS>"); |
128 |
1
|
out.println((Object) " </HEADER>"); |
129 |
1
|
out.pushLevel(); |
130 |
1
|
out.clearLevel(); |
131 |
1
|
out.println("</QEDEQ>"); |
132 |
1
|
out.close(); |
133 |
|
|
134 |
|
|
135 |
1
|
assertEquals(XML_DATA, to.toString()); |
136 |
|
|
137 |
1
|
assertEquals(StringUtility.string2Hex(XML_DATA, "ISO-8859-1"), |
138 |
|
StringUtility.byte2Hex(to.toByteArray())); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
141 |
1
|
public void testPushPop() throws Exception {... |
142 |
1
|
final ByteArrayOutputStream to = new ByteArrayOutputStream(); |
143 |
1
|
final TextOutput out = new TextOutput("jumper", to, "UTF-8"); |
144 |
1
|
out.popLevel(); |
145 |
1
|
out.popLevel(); |
146 |
1
|
out.print("James Bond"); |
147 |
1
|
assertEquals("James Bond", to.toString("UTF-8")); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@throws |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
155 |
1
|
public void testErrorStream() throws Exception {... |
156 |
1
|
final OutputStream to = new OutputStream() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
8
|
public void write(final int i) throws IOException {... |
158 |
8
|
throw new IOException("i have got you"); |
159 |
|
} |
160 |
|
}; |
161 |
1
|
TextOutput out = new TextOutput("flying toasters", to, "UTF-8"); |
162 |
1
|
assertEquals("flying toasters", out.getName()); |
163 |
1
|
assertFalse(out.checkError()); |
164 |
1
|
assertNull(out.getError()); |
165 |
1
|
out.flush(); |
166 |
1
|
assertFalse(out.checkError()); |
167 |
1
|
out.println("i am not written"); |
168 |
1
|
out.flush(); |
169 |
1
|
assertTrue(out.checkError()); |
170 |
|
|
171 |
1
|
assertEquals("Writing failed.", out.getError().getMessage()); |
172 |
|
|
173 |
|
} |
174 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
175 |
1
|
public void testConstructorAndGetName() throws Exception {... |
176 |
1
|
final ByteArrayOutputStream to = new ByteArrayOutputStream(); |
177 |
1
|
final TextOutput out = new TextOutput("jumper", to, "UTF-8"); |
178 |
1
|
assertEquals("jumper", out.getName()); |
179 |
1
|
assertFalse(out.checkError()); |
180 |
1
|
assertNull(out.getError()); |
181 |
1
|
try { |
182 |
1
|
new TextOutput("jumper", to, "i do not exist"); |
183 |
0
|
fail("Exception expected"); |
184 |
|
} catch (RuntimeException e) { |
185 |
|
|
186 |
|
} |
187 |
1
|
final TextOutput out2 = new TextOutput("jumper", new PrintStream(to)); |
188 |
1
|
assertEquals("jumper", out2.getName()); |
189 |
1
|
assertFalse(out2.checkError()); |
190 |
1
|
assertNull(out2.getError()); |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
193 |
1
|
public void testGetPosition() throws Exception {... |
194 |
1
|
final ByteArrayOutputStream to = new ByteArrayOutputStream(); |
195 |
1
|
final TextOutput out = new TextOutput("heaven", to, "UTF-16"); |
196 |
1
|
assertEquals(0, out.getPosition()); |
197 |
1
|
out.append("1234567890"); |
198 |
1
|
assertEquals(10, out.getPosition()); |
199 |
1
|
out.print("hi"); |
200 |
1
|
assertEquals(12, out.getPosition()); |
201 |
|
} |
202 |
|
|
203 |
|
} |
204 |
|
|