1 package org.codehaus.plexus.util.xml.pull;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileReader;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.Reader;
9
10 import org.junit.jupiter.api.BeforeEach;
11 import org.junit.jupiter.api.Test;
12
13 import static org.junit.jupiter.api.Assertions.assertTrue;
14 import static org.junit.jupiter.api.Assertions.fail;
15
16
17
18
19
20
21
22
23
24
25 public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test {
26
27 static final File testResourcesDir = new File("src/test/resources/", "xmlconf/eduni/misc/");
28
29 MXParser parser;
30
31
32
33
34 @BeforeEach
35 void setUp() {
36 parser = new MXParser();
37 }
38
39
40
41
42
43
44
45
46
47
48 @Test
49 void testhst_bh_001() throws IOException {
50 try (Reader reader = new FileReader(new File(testResourcesDir, "001.xml"))) {
51 parser.setInput(reader);
52 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
53 ;
54 fail("decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow");
55 } catch (XmlPullParserException e) {
56 assertTrue(e.getMessage().contains("character reference (with hex value FF000000F6) is invalid"));
57 }
58 }
59
60
61
62
63
64
65
66
67
68
69 @Test
70 void testhst_bh_002() throws IOException {
71 try (Reader reader = new FileReader(new File(testResourcesDir, "002.xml"))) {
72 parser.setInput(reader);
73 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
74 ;
75 fail("hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow");
76 } catch (XmlPullParserException e) {
77 assertTrue(e.getMessage().contains("character reference (with decimal value 4294967542) is invalid"));
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90 @Test
91 void testhst_bh_003() throws IOException {
92 try (Reader reader = new FileReader(new File(testResourcesDir, "003.xml"))) {
93 parser.setInput(reader);
94 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
95 ;
96 fail("decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow");
97 } catch (XmlPullParserException e) {
98 assertTrue(e.getMessage().contains("character reference (with hex value FFFFFFFF000000F6) is invalid"));
99 }
100 }
101
102
103
104
105
106
107
108
109
110
111 @Test
112 void testhst_bh_004() throws IOException {
113 try (Reader reader = new FileReader(new File(testResourcesDir, "004.xml"))) {
114 parser.setInput(reader);
115 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
116 ;
117 fail("hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow");
118 } catch (XmlPullParserException e) {
119 assertTrue(e.getMessage()
120 .contains("character reference (with decimal value 18446744073709551862) is invalid"));
121 }
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136 public void testhst_bh_005() throws IOException {
137 try (Reader reader = new FileReader(new File(testResourcesDir, "005.xml"))) {
138 parser.setInput(reader);
139 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
140 ;
141 fail("xmlns:xml is an attribute as far as validation is concerned and must be declared");
142 } catch (XmlPullParserException e) {
143 assertTrue(true);
144 }
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159 public void testhst_bh_006() throws IOException {
160 try (Reader reader = new FileReader(new File(testResourcesDir, "006.xml"))) {
161 parser.setInput(reader);
162 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
163 ;
164 fail("xmlns:foo is an attribute as far as validation is concerned and must be declared");
165 } catch (XmlPullParserException e) {
166 assertTrue(true);
167 }
168 }
169
170
171
172
173
174
175
176
177
178
179 @Test
180 void testhst_lhs_007() throws IOException {
181 try (InputStream is = new FileInputStream(new File(testResourcesDir, "007.xml"))) {
182 parser.setInput(is, null);
183 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
184 ;
185 fail("UTF-8 BOM plus xml decl of ISO-8859-1 incompatible");
186 } catch (XmlPullParserException e) {
187 assertTrue(e.getMessage().contains("UTF-8 BOM plus xml decl of ISO-8859-1 is incompatible"));
188 }
189 }
190
191
192
193
194
195
196
197
198
199
200 @Test
201 void testhst_lhs_008() throws IOException {
202 try (InputStream is = new FileInputStream(new File(testResourcesDir, "008.xml"))) {
203 parser.setInput(is, null);
204 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
205 ;
206 fail("UTF-16 BOM plus xml decl of UTF-8 (using UTF-16 coding) incompatible");
207 } catch (XmlPullParserException e) {
208 assertTrue(e.getMessage().contains("UTF-16 BOM in a UTF-8 encoded file is incompatible"));
209 }
210 }
211
212
213
214
215
216
217
218
219
220
221 @Test
222 void testhst_lhs_009() throws IOException {
223 try (InputStream is = new FileInputStream(new File(testResourcesDir, "009.xml"))) {
224 parser.setInput(is, null);
225 while (parser.nextToken() != XmlPullParser.END_DOCUMENT)
226 ;
227 fail("UTF-16 BOM plus xml decl of UTF-8 (using UTF-8 coding) incompatible");
228 } catch (XmlPullParserException e) {
229 assertTrue(e.getMessage().contains("UTF-16 BOM in a UTF-8 encoded file is incompatible"), e.getMessage());
230 }
231 }
232 }