4
4
import static org .junit .Assert .fail ;
5
5
6
6
import java .io .File ;
7
+ import java .io .FileInputStream ;
7
8
import java .io .FileReader ;
8
9
import java .io .IOException ;
10
+ import java .io .InputStream ;
9
11
import java .io .Reader ;
10
12
import java .nio .charset .StandardCharsets ;
11
13
@@ -206,24 +208,21 @@ public void testhst_bh_006()
206
208
* Version:
207
209
*
208
210
* @throws java.io.IOException if there is an I/O error
209
- *
210
- * NOTE: This test is SKIPPED as the MXParser object alone is unable to detect whether UTF-8 file
211
- * has a BOM or not
212
211
*/
213
- // @Test
212
+ @ Test
214
213
public void testhst_lhs_007 ()
215
214
throws IOException
216
215
{
217
- try ( Reader reader = ReaderFactory . newXmlReader ( new File ( testResourcesDir , "007.xml" ) ) )
216
+ try ( InputStream is = new FileInputStream ( new File ( testResourcesDir , "007.xml" ) ) )
218
217
{
219
- parser .setInput ( reader );
218
+ parser .setInput ( is , null );
220
219
while ( parser .nextToken () != XmlPullParser .END_DOCUMENT )
221
220
;
222
- fail ( "UTF-8 BOM plus xml decl of iso -8859-1 incompatible" );
221
+ fail ( "UTF-8 BOM plus xml decl of ISO -8859-1 incompatible" );
223
222
}
224
223
catch ( XmlPullParserException e )
225
224
{
226
- assertTrue ( e .getMessage ().contains ( "UTF-8 BOM plus xml decl of iso -8859-1 is incompatible" ) );
225
+ assertTrue ( e .getMessage ().contains ( "UTF-8 BOM plus xml decl of ISO -8859-1 is incompatible" ) );
227
226
}
228
227
}
229
228
@@ -235,57 +234,24 @@ public void testhst_lhs_007()
235
234
* Version:
236
235
*
237
236
* @throws java.io.IOException if there is an I/O error
238
- *
239
- * NOTE: This test is SKIPPED as the MXParser object alone is unable to detect whether UTF-16 file
240
- * has a BOM or not
241
237
*/
242
- // @Test
243
- public void testhst_lhs_008_newReader ()
238
+ @ Test
239
+ public void testhst_lhs_008 ()
244
240
throws IOException
245
241
{
246
- try ( Reader reader =
247
- ReaderFactory .newReader ( new File ( testResourcesDir , "008.xml" ), StandardCharsets .UTF_16 .name () ) )
242
+ try ( InputStream is = new FileInputStream ( new File ( testResourcesDir , "008.xml" ) ) )
248
243
{
249
- parser .setInput ( reader );
244
+ parser .setInput ( is , null );
250
245
while ( parser .nextToken () != XmlPullParser .END_DOCUMENT )
251
246
;
252
- fail ( "UTF-16 BOM plus xml decl of utf -8 (using UTF-16 coding) incompatible" );
247
+ fail ( "UTF-16 BOM plus xml decl of UTF -8 (using UTF-16 coding) incompatible" );
253
248
}
254
249
catch ( XmlPullParserException e )
255
250
{
256
251
assertTrue ( e .getMessage ().contains ( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) );
257
252
}
258
253
}
259
254
260
- /**
261
- * Test ID: <pre>hst-lhs-008</pre>
262
- * Test URI: <pre>008.xml</pre>
263
- * Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible</pre>
264
- * Sections: <pre>4.3.3</pre>
265
- * Version:
266
- *
267
- * @throws java.io.IOException if there is an I/O error
268
- *
269
- * NOTE: This test is SKIPPED as MXParser is unable to detect UTF-16 BOM detection when chars are read as
270
- * UTF-8, and XmlReader in lenient mode does not throw exception.
271
- */
272
- // @Test
273
- public void testhst_lhs_008_XmlReader ()
274
- throws IOException
275
- {
276
- try ( Reader reader = ReaderFactory .newXmlReader ( new File ( testResourcesDir , "008.xml" ) ) )
277
- {
278
- parser .setInput ( reader );
279
- while ( parser .nextToken () != XmlPullParser .END_DOCUMENT )
280
- ;
281
- fail ( "UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible" );
282
- }
283
- catch ( XmlPullParserException e )
284
- {
285
- assertTrue ( e .getMessage ().contains ( "UTF-16 BOM plus xml decl of utf-8 is incompatible" ) );
286
- }
287
- }
288
-
289
255
/**
290
256
* Test ID: <pre>hst-lhs-009</pre>
291
257
* Test URI: <pre>009.xml</pre>
@@ -298,52 +264,20 @@ public void testhst_lhs_008_XmlReader()
298
264
* NOTE: This test is SKIPPED as MXParser is unable to detect UTF-16 BOM detection when chars are read as
299
265
* UTF-8.
300
266
*/
301
- // @Test
302
- public void testhst_lhs_009_newReader ()
303
- throws IOException
304
- {
305
- try ( Reader reader =
306
- ReaderFactory .newReader ( new File ( testResourcesDir , "009.xml" ), StandardCharsets .UTF_16 .name () ) )
307
- {
308
- parser .setInput ( reader );
309
- while ( parser .nextToken () != XmlPullParser .END_DOCUMENT )
310
- ;
311
- fail ( "UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible" );
312
- }
313
- catch ( XmlPullParserException e )
314
- {
315
- assertTrue ( e .getMessage ().contains ( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) );
316
- }
317
- }
318
-
319
- /**
320
- * Test ID: <pre>hst-lhs-009</pre>
321
- * Test URI: <pre>009.xml</pre>
322
- * Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible</pre>
323
- * Sections: <pre>4.3.3</pre>
324
- * Version:
325
- *
326
- * @throws java.io.IOException if there is an I/O error
327
- */
328
267
@ Test
329
- public void testhst_lhs_009_XmlReader ()
268
+ public void testhst_lhs_009 ()
330
269
throws IOException
331
270
{
332
- try ( Reader reader = ReaderFactory . newXmlReader ( new File ( testResourcesDir , "009.xml" ) ) )
271
+ try ( InputStream is = new FileInputStream ( new File ( testResourcesDir , "009.xml" ) ) )
333
272
{
334
- parser .setInput ( reader );
273
+ parser .setInput ( is , null );
335
274
while ( parser .nextToken () != XmlPullParser .END_DOCUMENT )
336
275
;
337
- fail ( "UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible" );
338
- }
339
- catch ( IOException e )
340
- {
341
- // even when XmlReader is in lenient mode, it throws an IOException
342
- assertTrue ( e .getMessage ().contains ( "Invalid encoding, BOM [UTF-16BE] XML guess [UTF-8] XML prolog [UTF-8] encoding mismatch" ) );
276
+ fail ( "UTF-16 BOM plus xml decl of UTF-8 (using UTF-8 coding) incompatible" );
343
277
}
344
278
catch ( XmlPullParserException e )
345
279
{
346
- fail ( "Encoding problem should be detected by the XmlReader" );
280
+ assertTrue ( e . getMessage (), e . getMessage (). contains ( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) );
347
281
}
348
282
}
349
283
0 commit comments