]> git.ipfire.org Git - thirdparty/gcc.git/blob
d7a52b51be91616cdb73c55125e12fcf67680d15
[thirdparty/gcc.git] /
1 /* HTML_randomTable.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 import java.util.Random;
42
43 /**
44 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
45 */
46 public class HTML_randomTable
47 extends TestCase
48 {
49 class table
50 {
51 final String[][] rows;
52 final boolean caption = r.nextBoolean();
53
54 table()
55 {
56 int nrows = r.nextInt(5) + 1;
57 rows = new String[ nrows ][];
58 for (int i = 0; i < rows.length; i++)
59 {
60 int ncol = r.nextInt(5) + 1;
61 rows [ i ] = new String[ ncol ];
62 for (int j = 0; j < rows [ i ].length; j++)
63 {
64 rows [ i ] [ j ] = "C_" + i + "_" + j;
65 }
66 }
67 }
68
69 public String getHtml()
70 {
71 StringBuffer b = new StringBuffer("<html><head></head><body><table>");
72 if (caption)
73 b.append("<caption>capt</caption>");
74 if (r.nextBoolean())
75 b.append("<" + s() + "tbody" + s() + ">");
76 for (int row = 0; row < rows.length; row++)
77 {
78 b.append("<" + s() + "tr" + s() + ">");
79 for (int col = 0; col < rows [ row ].length; col++)
80 {
81 b.append("<" + s() + "td" + s() + ">");
82 b.append(rows [ row ] [ col ]);
83 if (r.nextBoolean())
84 b.append("<" + s() + "/" + "td" + s() + ">");
85 }
86 if (r.nextBoolean())
87 b.append("<" + s() + "/" + "tr" + s() + ">");
88 }
89 b.append("</tbody></table></body></html>");
90 return b.toString();
91 }
92
93 public String getTrace()
94 {
95 StringBuffer b = new StringBuffer("<html><head></head><body><table>");
96 if (caption)
97 b.append("<caption>'capt'</caption>");
98 b.append("<tbody>");
99 for (int row = 0; row < rows.length; row++)
100 {
101 b.append("<tr>");
102 for (int col = 0; col < rows [ row ].length; col++)
103 {
104 b.append("<td>'" + rows [ row ] [ col ] + "'</td>");
105 }
106 b.append("</tr>");
107 }
108 b.append("</tbody></table></body></html>");
109 return b.toString();
110 }
111
112 void test()
113 throws Exception
114 {
115 String trace = getTrace();
116 String html = getHtml();
117 v.verify(html, trace);
118 }
119 }
120
121 Parser_Test v = new Parser_Test();
122 Random r = new Random();
123
124 public HTML_randomTable()
125 throws Exception
126 {
127 }
128
129 public String s()
130 {
131 if (r.nextBoolean())
132 return "";
133
134 StringBuffer b = new StringBuffer();
135 int spc = r.nextInt(4);
136 for (int i = 0; i < spc; i++)
137 {
138 b.append(' ');
139 }
140 return b.toString();
141 }
142
143 /**
144 * Try 1001 variable randomly generated table.
145 */
146 public void testTableParsing()
147 throws Exception
148 {
149 v.hideImplied = true;
150 for (int i = 0; i < 1001; i++)
151 {
152 new table().test();
153 }
154 }
155 }