796
|
1 |
/*
|
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6233345 6381699 6381702 6381705 6381706
|
|
27 |
* @summary Encode many char sequences in many ways
|
|
28 |
* @run main/timeout=1200 FindEncoderBugs
|
|
29 |
* @author Martin Buchholz
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.util.*;
|
|
33 |
import java.util.regex.*;
|
|
34 |
import java.nio.*;
|
|
35 |
import java.nio.charset.*;
|
|
36 |
|
|
37 |
public class FindEncoderBugs {
|
|
38 |
|
|
39 |
static boolean isBroken(String csn) {
|
|
40 |
if (csn.equals("x-COMPOUND_TEXT")) return true;
|
|
41 |
if (csn.equals("x-IBM834")) return true; // stateful korean
|
|
42 |
if (csn.equals("x-IBM933")) return true; // stateful korean
|
|
43 |
if (csn.equals("x-IBM970")) return true; // stateful korean
|
|
44 |
if (csn.equals("x-IBM949")) return true; // stateful korean
|
|
45 |
if (csn.equals("x-IBM949C")) return true; // stateful korean
|
|
46 |
return false;
|
|
47 |
}
|
|
48 |
|
|
49 |
static <T extends Comparable<? super T>> List<T> sort(Collection<T> c) {
|
|
50 |
List<T> list = new ArrayList<T>(c);
|
|
51 |
Collections.sort(list);
|
|
52 |
return list;
|
|
53 |
}
|
|
54 |
|
|
55 |
static class TooManyFailures extends RuntimeException {
|
|
56 |
private static final long serialVersionUID = 0L;
|
|
57 |
}
|
|
58 |
|
|
59 |
static String string(byte[] a) {
|
|
60 |
final StringBuilder sb = new StringBuilder();
|
|
61 |
for (byte b : a) {
|
|
62 |
if (sb.length() != 0) sb.append(' ');
|
|
63 |
sb.append(String.format("%02x", b & 0xff));
|
|
64 |
}
|
|
65 |
return sb.toString();
|
|
66 |
}
|
|
67 |
|
|
68 |
static String string(char[] a) {
|
|
69 |
final StringBuilder sb = new StringBuilder();
|
|
70 |
for (char c : a) {
|
|
71 |
if (sb.length() != 0) sb.append(' ');
|
|
72 |
sb.append(String.format("\\u%04x", (int) c));
|
|
73 |
}
|
|
74 |
return sb.toString();
|
|
75 |
}
|
|
76 |
|
|
77 |
static class Reporter {
|
|
78 |
// Some machinery to make sure only a small number of errors
|
|
79 |
// that are "too similar" are reported.
|
|
80 |
static class Counts extends HashMap<String, Long> {
|
|
81 |
private static final long serialVersionUID = -1;
|
|
82 |
long inc(String signature) {
|
|
83 |
Long count = get(signature);
|
|
84 |
if (count == null) count = 0L;
|
|
85 |
put(signature, count+1);
|
|
86 |
return count+1;
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
final Counts failureCounts = new Counts();
|
|
91 |
final static long maxFailures = 2;
|
|
92 |
|
|
93 |
final static Pattern hideBytes = Pattern.compile("\"[0-9a-f ]+\"");
|
|
94 |
final static Pattern hideChars = Pattern.compile("\\\\u[0-9a-f]{4}");
|
|
95 |
|
|
96 |
boolean bug(String format, Object... args) {
|
|
97 |
String signature = String.format(format, args);
|
|
98 |
// signature = hideBytes.matcher(signature).replaceAll("\"??\"");
|
|
99 |
// signature = hideChars.matcher(signature).replaceAll("\\u????");
|
|
100 |
failed++;
|
|
101 |
if (failureCounts.inc(signature) <= maxFailures) {
|
|
102 |
System.out.printf(format, args);
|
|
103 |
System.out.println();
|
|
104 |
return true;
|
|
105 |
}
|
|
106 |
return false;
|
|
107 |
}
|
|
108 |
|
|
109 |
void summarize() {
|
|
110 |
for (String key : sort(failureCounts.keySet()))
|
|
111 |
System.out.printf("-----%n%s%nfailures=%d%n",
|
|
112 |
key, failureCounts.get(key));
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
static final Reporter reporter = new Reporter();
|
|
117 |
|
|
118 |
static class Result {
|
|
119 |
final int limit;
|
|
120 |
final int ipos;
|
|
121 |
final boolean direct;
|
|
122 |
final char[] ia;
|
|
123 |
final byte[] oa;
|
|
124 |
final CoderResult cr;
|
|
125 |
|
|
126 |
private static byte[] toByteArray(ByteBuffer bb) {
|
|
127 |
byte[] bytes = new byte[bb.position()];
|
|
128 |
for (int i = 0; i < bytes.length; i++)
|
|
129 |
bytes[i] = bb.get(i);
|
|
130 |
return bytes;
|
|
131 |
}
|
|
132 |
|
|
133 |
Result(CharBuffer ib, ByteBuffer ob, CoderResult cr) {
|
|
134 |
ipos = ib.position();
|
|
135 |
ia = toArray(ib);
|
|
136 |
oa = toArray(ob);
|
|
137 |
direct = ib.isDirect();
|
|
138 |
limit = ob.limit();
|
|
139 |
this.cr = cr;
|
|
140 |
}
|
|
141 |
|
|
142 |
static char[] toArray(CharBuffer b) {
|
|
143 |
int pos = b.position();
|
|
144 |
char[] a = new char[b.limit()];
|
|
145 |
b.position(0);
|
|
146 |
b.get(a);
|
|
147 |
b.position(pos);
|
|
148 |
return a;
|
|
149 |
}
|
|
150 |
|
|
151 |
static byte[] toArray(ByteBuffer b) {
|
|
152 |
byte[] a = new byte[b.position()];
|
|
153 |
b.position(0);
|
|
154 |
b.get(a);
|
|
155 |
return a;
|
|
156 |
}
|
|
157 |
|
|
158 |
static boolean eq(Result x, Result y) {
|
|
159 |
return x == y ||
|
|
160 |
(x != null && y != null &&
|
|
161 |
(Arrays.equals(x.oa, y.oa) &&
|
|
162 |
x.ipos == y.ipos &&
|
|
163 |
x.cr == y.cr));
|
|
164 |
}
|
|
165 |
|
|
166 |
public String toString() {
|
|
167 |
return String.format("\"%s\"[%d/%d] => %s \"%s\"[%d/%d]%s",
|
|
168 |
string(ia), ipos, ia.length,
|
|
169 |
cr, string(oa), oa.length, limit,
|
|
170 |
(direct ? " (direct)" : ""));
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
static class CharsetTester {
|
|
175 |
private final Charset cs;
|
|
176 |
private final boolean hasBom;
|
|
177 |
private static final int maxFailures = 5;
|
|
178 |
private int failures = 0;
|
|
179 |
// private static final long maxCharsetFailures = Long.MAX_VALUE;
|
|
180 |
private static final long maxCharsetFailures = 10000L;
|
|
181 |
private final long failed0 = failed;
|
|
182 |
|
|
183 |
// legend: r=regular d=direct In=Input Ou=Output
|
|
184 |
static final int maxBufSize = 20;
|
|
185 |
static final CharBuffer[] rInBuffers = new CharBuffer[maxBufSize];
|
|
186 |
static final CharBuffer[] dInBuffers = new CharBuffer[maxBufSize];
|
|
187 |
|
|
188 |
static final ByteBuffer[] rOuBuffers = new ByteBuffer[maxBufSize];
|
|
189 |
static final ByteBuffer[] dOuBuffers = new ByteBuffer[maxBufSize];
|
|
190 |
static {
|
|
191 |
for (int i = 0; i < maxBufSize; i++) {
|
|
192 |
rInBuffers[i] = CharBuffer.allocate(i);
|
|
193 |
dInBuffers[i] = ByteBuffer.allocateDirect(i*2).asCharBuffer();
|
|
194 |
rOuBuffers[i] = ByteBuffer.allocate(i);
|
|
195 |
dOuBuffers[i] = ByteBuffer.allocateDirect(i);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
CharsetTester(Charset cs) {
|
|
200 |
this.cs = cs;
|
|
201 |
this.hasBom =
|
|
202 |
cs.name().matches(".*BOM.*") ||
|
|
203 |
cs.name().equals("UTF-16");
|
|
204 |
}
|
|
205 |
|
|
206 |
static boolean bug(String format, Object... args) {
|
|
207 |
return reporter.bug(format, args);
|
|
208 |
}
|
|
209 |
|
|
210 |
static boolean hasBom(byte[] a) {
|
|
211 |
switch (a.length) {
|
|
212 |
case 2: case 4:
|
|
213 |
int sum = 0;
|
|
214 |
for (byte x : a)
|
|
215 |
sum += x;
|
|
216 |
return sum == (byte) 0xfe + (byte) 0xff;
|
|
217 |
default: return false;
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
void testSurrogates() {
|
|
222 |
int failures = 0;
|
|
223 |
for (int i = 0; i < 10; i++) {
|
|
224 |
Result r = test(new char[] { randomHighSurrogate() });
|
|
225 |
if (r == null) break;
|
|
226 |
if (! (r.cr.isUnderflow() &&
|
|
227 |
r.ipos == 0))
|
|
228 |
bug("Lone high surrogate not UNDERFLOW: %s %s",
|
|
229 |
cs, r);
|
|
230 |
}
|
|
231 |
for (int i = 0; i < 10; i++) {
|
|
232 |
Result r = test(new char[] { randomLowSurrogate() });
|
|
233 |
if (r == null) break;
|
|
234 |
if (! (r.cr.isMalformed() && r.cr.length() == 1))
|
|
235 |
bug("Lone low surrogate not MALFORMED[1]: %s %s",
|
|
236 |
cs, r);
|
|
237 |
}
|
|
238 |
char[] chars = new char[2];
|
|
239 |
for (int i = 0; i < 10; i++) {
|
|
240 |
chars[0] = randomLowSurrogate(); // Always illegal
|
|
241 |
chars[1] = randomChar();
|
|
242 |
Result r = test(chars);
|
|
243 |
if (r == null) break;
|
|
244 |
if (! (r.cr.isMalformed() &&
|
|
245 |
r.cr.length() == 1 &&
|
|
246 |
(r.ipos == 0 || (hasBom && hasBom(r.oa))))) {
|
|
247 |
if (failures++ > 5) return;
|
|
248 |
bug("Unpaired low surrogate not MALFORMED[1]: %s %s",
|
|
249 |
cs, r);
|
|
250 |
}
|
|
251 |
}
|
|
252 |
for (int i = 0; i < 10; i++) {
|
|
253 |
chars[0] = randomHighSurrogate();
|
|
254 |
do {
|
|
255 |
chars[1] = randomChar();
|
|
256 |
} while (Character.isLowSurrogate(chars[1]));
|
|
257 |
Result r = test(chars);
|
|
258 |
if (r == null) break;
|
|
259 |
if (! (r.cr.isMalformed() &&
|
|
260 |
r.cr.length() == 1 &&
|
|
261 |
(r.ipos == 0 || (hasBom && hasBom(r.oa))))) {
|
|
262 |
if (failures++ > 5) return;
|
|
263 |
bug("Unpaired high surrogate not MALFORMED[1]: %s %s",
|
|
264 |
cs, r);
|
|
265 |
}
|
|
266 |
}
|
|
267 |
for (int i = 0; i < 1000; i++) {
|
|
268 |
chars[0] = randomHighSurrogate();
|
|
269 |
chars[1] = randomLowSurrogate();
|
|
270 |
Result r = test(chars);
|
|
271 |
if (r == null) break;
|
|
272 |
if (! ((r.cr.isUnmappable() &&
|
|
273 |
r.cr.length() == 2 &&
|
|
274 |
r.oa.length == 0)
|
|
275 |
||
|
|
276 |
(r.cr.isUnderflow() &&
|
|
277 |
r.oa.length > 0 &&
|
|
278 |
r.ipos == 2))) {
|
|
279 |
if (failures++ > 5) return;
|
|
280 |
bug("Legal supplementary character bug: %s %s",
|
|
281 |
cs, r);
|
|
282 |
}
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
// if (! (r.cr.isMalformed() &&
|
|
287 |
// r.cr.length() == 1 &&
|
|
288 |
// (rob.position() == 0 || hasBom(rob)))) {
|
|
289 |
// if (failures++ > 5) return;
|
|
290 |
// bug("Unpaired surrogate not malformed: %s %s",
|
|
291 |
// cs, r);
|
|
292 |
// }
|
|
293 |
// }
|
|
294 |
|
|
295 |
// dib.clear(); dib.put(chars); dib.flip();
|
|
296 |
// rib.position(0);
|
|
297 |
// rob.clear(); rob.limit(lim);
|
|
298 |
// for (CharBuffer ib : new CharBuffer[] { rib, dib }) {
|
|
299 |
// Result r = recode(ib, rob);
|
|
300 |
// if (! (r.cr.isMalformed() &&
|
|
301 |
// r.cr.length() == 1 &&
|
|
302 |
// (rob.position() == 0 || hasBom(rob)))) {
|
|
303 |
// if (failures++ > 5) return;
|
|
304 |
// bug("Unpaired surrogate not malformed: %s %s",
|
|
305 |
// cs, r);
|
|
306 |
// }
|
|
307 |
// }
|
|
308 |
// //}
|
|
309 |
// for (int i = 0; i < 10000; i++) {
|
|
310 |
// chars[0] = randomHighSurrogate();
|
|
311 |
// chars[1] = randomLowSurrogate();
|
|
312 |
// dib.clear(); dib.put(chars); dib.flip();
|
|
313 |
// rib.position(0);
|
|
314 |
// rob.clear(); rob.limit(lim);
|
|
315 |
// for (CharBuffer ib : new CharBuffer[] { rib, dib }) {
|
|
316 |
// Result r = recode(ib, rob);
|
|
317 |
// if (! ((r.cr.isUnmappable() &&
|
|
318 |
// r.cr.length() == 2 &&
|
|
319 |
// rob.position() == 0)
|
|
320 |
// ||
|
|
321 |
// (r.cr.isUnderflow() &&
|
|
322 |
// rob.position() > 0 &&
|
|
323 |
// ib.position() == 2))) {
|
|
324 |
// if (failures++ > 5) return;
|
|
325 |
// bug("Legal supplementary character bug: %s %s",
|
|
326 |
// cs, r);
|
|
327 |
// }
|
|
328 |
// }
|
|
329 |
// }
|
|
330 |
// }
|
|
331 |
// }
|
|
332 |
|
|
333 |
Result recode(CharBuffer ib, ByteBuffer ob) {
|
|
334 |
try {
|
|
335 |
byte canary = 22;
|
|
336 |
ib.clear(); // Prepare to read
|
|
337 |
ob.clear(); // Prepare to write
|
|
338 |
for (int i = 0; i < ob.limit(); i++)
|
|
339 |
ob.put(i, canary);
|
|
340 |
CharsetEncoder coder = cs.newEncoder();
|
|
341 |
CoderResult cr = coder.encode(ib, ob, false);
|
|
342 |
equal(ib.limit(), ib.capacity());
|
|
343 |
equal(ob.limit(), ob.capacity());
|
|
344 |
Result r = new Result(ib, ob, cr);
|
|
345 |
if (cr.isError())
|
|
346 |
check(cr.length() > 0);
|
|
347 |
if (cr.isOverflow() && ob.remaining() > 10)
|
|
348 |
bug("OVERFLOW, but there's lots of room: %s %s",
|
|
349 |
cs, r);
|
|
350 |
// if (cr.isOverflow() && ib.remaining() == 0 && ! hasBom)
|
|
351 |
// bug("OVERFLOW, yet remaining() == 0: %s %s",
|
|
352 |
// cs, r);
|
|
353 |
if (cr.isError() && ib.remaining() < cr.length())
|
|
354 |
bug("remaining() < CoderResult.length(): %s %s",
|
|
355 |
cs, r);
|
|
356 |
// if (ib.position() == 0
|
|
357 |
// && ob.position() > 0
|
|
358 |
// && ! hasBom(r.oa))
|
|
359 |
// bug("output only if input consumed: %s %s",
|
|
360 |
// cs, r);
|
|
361 |
CoderResult cr2 = coder.encode(ib, ob, false);
|
|
362 |
if (ib.position() != r.ipos ||
|
|
363 |
ob.position() != r.oa.length ||
|
|
364 |
cr != cr2)
|
|
365 |
bug("Coding operation not idempotent: %s%n %s%n %s",
|
|
366 |
cs, r, new Result(ib, ob, cr2));
|
|
367 |
if (ob.position() < ob.limit() &&
|
|
368 |
ob.get(ob.position()) != canary)
|
|
369 |
bug("Buffer overrun: %s %s %s",
|
|
370 |
cs, r, ob.get(ob.position()));
|
|
371 |
return r;
|
|
372 |
} catch (Throwable t) {
|
|
373 |
if (bug("Unexpected exception: %s %s %s",
|
|
374 |
cs, t.getClass().getSimpleName(),
|
|
375 |
new Result(ib, ob, null)))
|
|
376 |
t.printStackTrace();
|
|
377 |
return null;
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|
|
381 |
Result recode2(char[] ia, int n) {
|
|
382 |
int len = ia.length;
|
|
383 |
CharBuffer rib = CharBuffer.wrap(ia);
|
|
384 |
CharBuffer dib = dInBuffers[len];
|
|
385 |
dib.clear(); dib.put(ia); dib.clear();
|
|
386 |
ByteBuffer rob = rOuBuffers[n];
|
|
387 |
ByteBuffer dob = dOuBuffers[n];
|
|
388 |
equal(rob.limit(), n);
|
|
389 |
equal(dob.limit(), n);
|
|
390 |
check(dib.isDirect());
|
|
391 |
check(dob.isDirect());
|
|
392 |
Result r1 = recode(rib, rob);
|
|
393 |
Result r2 = recode(dib, dob);
|
|
394 |
if (r1 != null && r2 != null && ! Result.eq(r1, r2))
|
|
395 |
bug("Results differ for direct buffers: %s%n %s%n %s",
|
|
396 |
cs, r1, r2);
|
|
397 |
return r1;
|
|
398 |
}
|
|
399 |
|
|
400 |
Result test(char[] ia) {
|
|
401 |
if (failed - failed0 >= maxCharsetFailures)
|
|
402 |
throw new TooManyFailures();
|
|
403 |
|
|
404 |
Result roomy = recode2(ia, maxBufSize - 1);
|
|
405 |
if (roomy == null) return roomy;
|
|
406 |
int olen = roomy.oa.length;
|
|
407 |
if (olen > 0) {
|
|
408 |
if (roomy.ipos == roomy.ia.length) {
|
|
409 |
Result perfectFit = recode2(ia, olen);
|
|
410 |
if (! Result.eq(roomy, perfectFit))
|
|
411 |
bug("Results differ: %s%n %s%n %s",
|
|
412 |
cs, roomy, perfectFit);
|
|
413 |
}
|
|
414 |
for (int i = 0; i < olen; i++) {
|
|
415 |
Result claustrophobic = recode2(ia, i);
|
|
416 |
if (claustrophobic == null) return roomy;
|
|
417 |
if (roomy.cr.isUnderflow() &&
|
|
418 |
! claustrophobic.cr.isOverflow())
|
|
419 |
bug("Expected OVERFLOW: %s%n %s%n %s",
|
|
420 |
cs, roomy, claustrophobic);
|
|
421 |
}
|
|
422 |
}
|
|
423 |
return roomy;
|
|
424 |
}
|
|
425 |
|
|
426 |
void testExhaustively(char[] prefix, int n) {
|
|
427 |
int len = prefix.length;
|
|
428 |
char[] ia = Arrays.copyOf(prefix, len + 1);
|
|
429 |
for (int i = 0; i < 0x10000; i++) {
|
|
430 |
ia[len] = (char) i;
|
|
431 |
if (n == 1)
|
|
432 |
test(ia);
|
|
433 |
else
|
|
434 |
testExhaustively(ia, n - 1);
|
|
435 |
}
|
|
436 |
}
|
|
437 |
|
|
438 |
void testRandomly(char[] prefix, int n) {
|
|
439 |
int len = prefix.length;
|
|
440 |
char[] ia = Arrays.copyOf(prefix, len + n);
|
|
441 |
for (int i = 0; i < 10000; i++) {
|
|
442 |
for (int j = 0; j < n; j++)
|
|
443 |
ia[len + j] = randomChar();
|
|
444 |
test(ia);
|
|
445 |
}
|
|
446 |
}
|
|
447 |
|
|
448 |
void testPrefix(char[] prefix) {
|
|
449 |
if (prefix.length > 0)
|
|
450 |
System.out.printf("Testing prefix %s%n", string(prefix));
|
|
451 |
|
|
452 |
test(prefix);
|
|
453 |
|
|
454 |
testExhaustively(prefix, 1);
|
|
455 |
// Can you spare a year of CPU time?
|
|
456 |
//testExhaustively(prefix, 2);
|
|
457 |
|
|
458 |
testRandomly(prefix, 2);
|
|
459 |
testRandomly(prefix, 3);
|
|
460 |
}
|
|
461 |
}
|
|
462 |
|
|
463 |
private final static Random rnd = new Random();
|
|
464 |
private static char randomChar() {
|
|
465 |
return (char) rnd.nextInt(Character.MAX_VALUE);
|
|
466 |
}
|
|
467 |
private static char randomHighSurrogate() {
|
|
468 |
return (char) (Character.MIN_HIGH_SURROGATE + rnd.nextInt(1024));
|
|
469 |
}
|
|
470 |
private static char randomLowSurrogate() {
|
|
471 |
return (char) (Character.MIN_LOW_SURROGATE + rnd.nextInt(1024));
|
|
472 |
}
|
|
473 |
|
|
474 |
private static void testCharset(Charset cs) throws Throwable {
|
|
475 |
if (! cs.canEncode())
|
|
476 |
return;
|
|
477 |
|
|
478 |
final String csn = cs.name();
|
|
479 |
|
|
480 |
if (isBroken(csn)) {
|
|
481 |
System.out.printf("Skipping possibly broken charset %s%n", csn);
|
|
482 |
return;
|
|
483 |
}
|
|
484 |
System.out.println(csn);
|
|
485 |
|
|
486 |
CharsetTester tester = new CharsetTester(cs);
|
|
487 |
|
|
488 |
tester.testSurrogates();
|
|
489 |
|
|
490 |
tester.testPrefix(new char[] {});
|
|
491 |
|
|
492 |
if (csn.equals("x-ISCII91")) {
|
|
493 |
System.out.println("More ISCII testing...");
|
|
494 |
new CharsetTester(cs).testPrefix(new char[]{'\u094d'}); // Halant
|
|
495 |
new CharsetTester(cs).testPrefix(new char[]{'\u093c'}); // Nukta
|
|
496 |
}
|
|
497 |
}
|
|
498 |
|
|
499 |
private static void realMain(String[] args) {
|
|
500 |
for (Charset cs : sort(Charset.availableCharsets().values())) {
|
|
501 |
try {
|
|
502 |
testCharset(cs);
|
|
503 |
} catch (TooManyFailures e) {
|
|
504 |
System.out.printf("Too many failures for %s%n", cs);
|
|
505 |
} catch (Throwable t) {
|
|
506 |
unexpected(t);
|
|
507 |
}
|
|
508 |
}
|
|
509 |
reporter.summarize();
|
|
510 |
}
|
|
511 |
|
|
512 |
//--------------------- Infrastructure ---------------------------
|
|
513 |
static volatile long passed = 0, failed = 0;
|
|
514 |
static void pass() {passed++;}
|
|
515 |
static void fail() {failed++; Thread.dumpStack();}
|
|
516 |
static void fail(String format, Object... args) {
|
|
517 |
System.out.println(String.format(format, args)); failed++;}
|
|
518 |
static void fail(String msg) {System.out.println(msg); fail();}
|
|
519 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();}
|
|
520 |
static void check(boolean cond) {if (cond) pass(); else fail();}
|
|
521 |
static void equal(Object x, Object y) {
|
|
522 |
if (x == null ? y == null : x.equals(y)) pass();
|
|
523 |
else fail(x + " not equal to " + y);}
|
|
524 |
public static void main(String[] args) throws Throwable {
|
|
525 |
try {realMain(args);} catch (Throwable t) {unexpected(t);}
|
|
526 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
|
|
527 |
if (failed > 0) throw new AssertionError("Some tests failed");}
|
|
528 |
}
|