View Javadoc
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   * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
18   * TESCASES PROFILE: <pre>Bjoern Hoehrmann via HST 2013-09-18</pre>
19   * XML test files base folder: <pre>xmlconf/eduni/misc/</pre>
20   *
21   * @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</a>
22   * @version $Id: $Id
23   * @since 3.4.0
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       * <p>setUp.</p>
33       */
34      @BeforeEach
35      void setUp() {
36          parser = new MXParser();
37      }
38  
39      /**
40       * Test ID: <pre>hst-bh-001</pre>
41       * Test URI: <pre>001.xml</pre>
42       * Comment: <pre>decimal charref &#38;#62; 10FFFF, indeed &#38;#62; max 32 bit integer, checking for recovery from possible overflow</pre>
43       * Sections: <pre>2.2 [2], 4.1 [66]</pre>
44       * Version:
45       *
46       * @throws java.io.IOException if there is an I/O error
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       * Test ID: <pre>hst-bh-002</pre>
62       * Test URI: <pre>002.xml</pre>
63       * Comment: <pre>hex charref &#38;#62; 10FFFF, indeed &#38;#62; max 32 bit integer, checking for recovery from possible overflow</pre>
64       * Sections: <pre>2.2 [2], 4.1 [66]</pre>
65       * Version:
66       *
67       * @throws java.io.IOException if there is an I/O error
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       * Test ID: <pre>hst-bh-003</pre>
83       * Test URI: <pre>003.xml</pre>
84       * Comment: <pre>decimal charref &#38;#62; 10FFFF, indeed &#38;#62; max 64 bit integer, checking for recovery from possible overflow</pre>
85       * Sections: <pre>2.2 [2], 4.1 [66]</pre>
86       * Version:
87       *
88       * @throws java.io.IOException if there is an I/O error
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      * Test ID: <pre>hst-bh-004</pre>
104      * Test URI: <pre>004.xml</pre>
105      * Comment: <pre>hex charref &#38;#62; 10FFFF, indeed &#38;#62; max 64 bit integer, checking for recovery from possible overflow</pre>
106      * Sections: <pre>2.2 [2], 4.1 [66]</pre>
107      * Version:
108      *
109      * @throws java.io.IOException if there is an I/O error
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      * Test ID: <pre>hst-bh-005</pre>
126      * Test URI: <pre>005.xml</pre>
127      * Comment: <pre>xmlns:xml is an attribute as far as validation is concerned and must be declared</pre>
128      * Sections: <pre>3.1 [41]</pre>
129      * Version:
130      *
131      * @throws java.io.IOException if there is an I/O error
132      *
133      * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing.
134      */
135     // @Test
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      * Test ID: <pre>hst-bh-006</pre>
149      * Test URI: <pre>006.xml</pre>
150      * Comment: <pre>xmlns:foo is an attribute as far as validation is concerned and must be declared</pre>
151      * Sections: <pre>3.1 [41]</pre>
152      * Version:
153      *
154      * @throws java.io.IOException if there is an I/O error
155      *
156      * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing.
157      */
158     // @Test
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      * Test ID: <pre>hst-lhs-007</pre>
172      * Test URI: <pre>007.xml</pre>
173      * Comment: <pre>UTF-8 BOM plus xml decl of iso-8859-1 incompatible</pre>
174      * Sections: <pre>4.3.3</pre>
175      * Version:
176      *
177      * @throws java.io.IOException if there is an I/O error
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      * Test ID: <pre>hst-lhs-008</pre>
193      * Test URI: <pre>008.xml</pre>
194      * Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible</pre>
195      * Sections: <pre>4.3.3</pre>
196      * Version:
197      *
198      * @throws java.io.IOException if there is an I/O error
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      * Test ID: <pre>hst-lhs-009</pre>
214      * Test URI: <pre>009.xml</pre>
215      * Comment: <pre>UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible</pre>
216      * Sections: <pre>4.3.3</pre>
217      * Version:
218      *
219      * @throws java.io.IOException if there is an I/O error
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 }