OSDN Git Service

PR target/27599
[pf3gnuchains/gcc-fork.git] / libjava / classpath / testsuite / javax.swing.text.html.parser / test / gnu / javax / swing / text / html / parser / HTML_parsing.java
1 /* HTML_parsing.java --
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package test.gnu.javax.swing.text.html.parser;
40
41
42 /**
43  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
44  */
45 public class HTML_parsing
46   extends TestCase
47 {
48   /**
49    * This is used for profiling.
50    */
51   public static void main(String[] args)
52   {
53     long t = System.currentTimeMillis();
54     try
55       {
56         HTML_parsing p = new HTML_parsing();
57         for (int i = 0; i < 2000; i++)
58           {
59             p.testHTMLParsing();
60             if (i % 10 == 0)
61               System.out.print('.');
62           }
63       }
64     catch (Exception ex)
65       {
66       }
67     System.out.println("TIME " + (System.currentTimeMillis() - t));
68   }
69
70   public void testHTMLParsing()
71                        throws Exception
72   {
73     Parser_Test v = new Parser_Test();
74     v.hideImplied = false;
75
76     // Test  subsequent tags.
77     v.verify("<b><i><u>text</b><i></u>",
78              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><i><u>'text'</b><i></u></i></i></body></html>"
79             );
80
81     // Test entities.
82     v.verify("hex: &#x55; eqdec: &#61; ampnamed: &amp;",
83              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'hex: U eqdec: = ampnamed: &'</body></html>"
84             );
85
86     // Test comments.
87     v.verify("<html><head></head><body><!--a-->< !--b--><! --c--><!-- d--><!--e --><!--f-- ><!--g--><!---h---><!-- i --><!--- j ---><!-- -- --> <b> <!---------->",
88              "<html><head></head><body>{a}{b}{c}{ d}{e }{f}{g}{-h-}{ i }{- j -}{ -- }<b>{------}</b></body></html>"
89             );
90
91     // Test unclosed tags.
92     v.verify("<hr id = 1 class = c<hr id=2>",
93              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='c' id='1'/><hr id='2'/></body></html>"
94             );
95
96     // Test errors and unclosed tags.
97     v.verify("<b#r><hr id = 1 # class = c<hr id=2>",
98              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><hr id='1'/>'# class = c'<hr id='2'/></b></body></html>"
99             );
100
101     // Test script.
102     v.verify("<hr id=1><script a=b c=d><hr id=1></script><hr id=1>",
103              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr id='1'/><script a='b' c='d'>'<hr id=1>'</script><hr id='1'/></body></html>"
104             );
105
106     // Test valid attributes.
107     v.verify("<hr id='i' title=\"tit\" class=cl><hr><hr id = 2>",
108              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='cl' id='i' title='tit'/><hr/><hr id='2'/></body></html>"
109             );
110
111     // Test unknown attribute without value.
112     v.verify("<hr audrius title=\"tit\">",
113              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr audrius='#DEFAULT' title='tit'/></body></html>"
114             );
115
116     // Test known attributes witout value.
117     v.verify("<option id=a selected><option id=b selected = selected class=cC><input checked>",
118              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><option id='a' selected='selected'></option></body><body _implied_='true'><option class='cC' id='b' selected='selected'></option><input checked='checked'/></body></html>"
119             );
120
121     // Test table content model.
122     v.verify("<table>a</table>",
123              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>"
124             );
125
126     // Test table content model.
127     v.verify("<table><caption>cap</caption>a</table>",
128              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><caption>'cap'</caption><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>"
129             );
130
131     // Test typical table.
132     v.verify("<table><tr><td>x</td><td>y</td><td>z</td></table>",
133              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>"
134             );
135
136     // Test nested table.
137     v.verify("<table><tr><td><table>nested</table>x</td><td>y</td><td>z</td></table>",
138              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'nested'</td></tr></tbody></table>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>"
139             );
140
141     // Test simple nested list.
142     v.verify("<ul><li>a</li><ul><li>na</li><li>nb</li></ul><li>b</li></ul>",
143              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><ul><li>'na'</li><li>'nb'</li></ul><li>'b'</li></ul></body></html>"
144             );
145
146     // Test simple non-nested list.
147     v.verify("<ul><li>a</li><li>na</li><li>nb</li><li>b</li></ul>",
148              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>"
149             );
150
151     // Test list without closing tags (obsolete list form).
152     v.verify("<ul><li>a<li>na<li>nb<li>b</ul>",
153              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>"
154             );
155
156     // Test list without closing tags (obsolete list form).
157     v.verify("<ul><li>a<ul><li>na<li>nb</ul><li>b</ul>",
158              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'<ul><li>'na'</li><li>'nb'</li></ul></li><li>'b'</li></ul></body></html>"
159             );
160
161     // Test Obsolete table.
162     v.verify("<table><tr><td>a<td>b<td>c</tr>",
163              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>"
164             );
165
166     // Test html no head no body.
167     v.verify("<html>text</html>",
168              "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>"
169             );
170
171     // Test head only.
172     v.verify("<head></head>text",
173              "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>"
174             );
175
176     // Test head and body.
177     v.verify("<head><title>ti</title></head><body>text",
178              "<html _implied_='true'><head><title>'ti'</title></head><body>'text'</body></html>"
179             );
180
181     // Test title and text.
182     v.verify("<title>title</title>text",
183              "<html _implied_='true'><head _implied_='true'><title>'title'</title></head><body _implied_='true'>'text'</body></html>"
184             );
185
186     // Test html only.
187     v.verify("<html>text</html>",
188              "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>"
189             );
190
191     // Test body only.
192     v.verify("<body>text</body>",
193              "<html _implied_='true'><head _implied_='true'></head><body>'text'</body></html>"
194             );
195
196     // Test head only.
197     v.verify("<head></head>text",
198              "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>"
199             );
200
201     // Test obsolete table.
202     v.verify("<table><tr><td>a</td><tr><td>a</td>",
203              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td></tr><tr><td>'a'</td></tr></tbody></table></body></html>"
204             );
205
206     // Test obsolete table.
207     v.verify("<table><tr><td>a<td>b<tr><td>a<td>b<td>c",
208              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td></tr><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>"
209             );
210
211     // Test style.
212     v.verify("<html><head><style><hr id=2></style></head><hr id = b>",
213              "<html><head><style>'<hr id=2>'</style></head><body _implied_='true'><hr id='b'/></body></html>"
214             );
215
216     // Test style.
217     v.verify("<style><hr id=2></style>x",
218              "<html _implied_='true'><head _implied_='true'><style>'<hr id=2>'</style></head><body _implied_='true'>'x'</body></html>"
219             );
220
221     // Test entities in attributes.
222     v.verify("<hr id='id_&#x41;&#90' class= \"&#89;_&amp;\" >",
223              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='Y_&' id='id_AZ'/></body></html>"
224             );
225
226     // Test colgroup.
227     v.verify("<table><COLGROUP width=\"25\"><COL span=\"45\"><COL id=\"identifier\"></COLGROUP><td>a<td>b<tr>x",
228              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><colgroup width='25'><col span='45'/><col id='identifier'/></colgroup><tbody _implied_='true'><tr _implied_='true'><td>'a'</td><td>'b'</td></tr><tr><td _implied_='true'>'x'</td></tr></tbody></table></body></html>"
229             );
230
231     // Test definition list, obsolete.
232     v.verify("<dl><dt>ha<dd>a<dt>hb<dd>b",
233              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>"
234             );
235
236     // Test definition list.
237     v.verify("<html><head></head><body><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>",
238              "<html><head></head><body><dl><dt>''ha''</dt><dd>''a''</dd><dt>''hb''</dt><dd>''b''</dd></dl></body></html>"
239             );
240
241     // Test paragraphs.
242     v.verify("<p>b<p>c<p>d",
243              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>'b'</p><p>'c'</p><p>'d'</p></body></html>"
244             );
245
246     // Test paragraphs.
247     v.verify("<p>'b'</p><p>'c'</p><p>'d'</p>",
248              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>''b''</p><p>''c''</p><p>''d''</p></body></html>"
249             );
250
251     // Test select obsolete.
252     v.verify("<form><select><option value='hi' disabled>a<option selected>b<option>normal",
253              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option disabled='disabled' value='hi'>'a'</option><option selected='selected'>'b'</option><option>'normal'</option></select></form></body></html>"
254             );
255
256     // Test select current.
257     v.verify("<form><select><option>'a'</option><option SELECTED='selected'>'b'</option></select></form>",
258              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>''a''</option><option selected='selected'>''b''</option></select></form></body></html>"
259             );
260
261     // Test select current.
262     v.verify("<form><select><option>after<optgroup><option>'a'</option><option SELECTED='selected'>'b'</option></optgroup></select></form>",
263              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>'after'</option><optgroup><option>''a''</option><option selected='selected'>''b''</option></optgroup></select></form></body></html>"
264             );
265
266     // Test << antihang.
267     v.verify("<<i>text",
268              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>"
269             );
270
271     // Test << antihang with spaces.
272     v.verify(" < < i>text",
273              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>"
274             );
275
276     // Test Standalone <.
277     v.verify("Text <wrong tag is it! <b> text ",
278              "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'Text''<wrong tag is it!'<b>'text'</b></body></html>"
279             );
280   }
281 }