/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6233345 6381699 6381702 6381705 6381706
* @summary Encode many char sequences in many ways
* @author Martin Buchholz
*/
public class FindEncoderBugs {
return false;
}
return list;
}
}
for (byte b : a) {
}
}
for (char c : a) {
}
}
static class Reporter {
// Some machinery to make sure only a small number of errors
// that are "too similar" are reported.
return count+1;
}
}
// signature = hideBytes.matcher(signature).replaceAll("\"??\"");
// signature = hideChars.matcher(signature).replaceAll("\\u????");
failed++;
return true;
}
return false;
}
void summarize() {
}
}
static class Result {
final int limit;
final int ipos;
final boolean direct;
final char[] ia;
final byte[] oa;
return bytes;
}
}
char[] a = new char[b.limit()];
b.position(0);
b.get(a);
return a;
}
byte[] a = new byte[b.position()];
b.position(0);
b.get(a);
return a;
}
return x == y ||
}
}
}
static class CharsetTester {
private final boolean hasBom;
// private static final long maxCharsetFailures = Long.MAX_VALUE;
// legend: r=regular d=direct In=Input Ou=Output
static {
for (int i = 0; i < maxBufSize; i++) {
}
}
this.hasBom =
}
}
static boolean hasBom(byte[] a) {
switch (a.length) {
case 2: case 4:
int sum = 0;
for (byte x : a)
sum += x;
default: return false;
}
}
void testSurrogates() {
int failures = 0;
for (int i = 0; i < 10; i++) {
if (r == null) break;
if (! (r.cr.isUnderflow() &&
r.ipos == 0))
bug("Lone high surrogate not UNDERFLOW: %s %s",
cs, r);
}
for (int i = 0; i < 10; i++) {
if (r == null) break;
bug("Lone low surrogate not MALFORMED[1]: %s %s",
cs, r);
}
char[] chars = new char[2];
for (int i = 0; i < 10; i++) {
if (r == null) break;
if (! (r.cr.isMalformed() &&
if (failures++ > 5) return;
bug("Unpaired low surrogate not MALFORMED[1]: %s %s",
cs, r);
}
}
for (int i = 0; i < 10; i++) {
do {
if (r == null) break;
if (! (r.cr.isMalformed() &&
if (failures++ > 5) return;
bug("Unpaired high surrogate not MALFORMED[1]: %s %s",
cs, r);
}
}
for (int i = 0; i < 1000; i++) {
if (r == null) break;
if (! ((r.cr.isUnmappable() &&
||
(r.cr.isUnderflow() &&
r.ipos == 2))) {
if (failures++ > 5) return;
bug("Legal supplementary character bug: %s %s",
cs, r);
}
}
}
// if (! (r.cr.isMalformed() &&
// r.cr.length() == 1 &&
// (rob.position() == 0 || hasBom(rob)))) {
// if (failures++ > 5) return;
// bug("Unpaired surrogate not malformed: %s %s",
// cs, r);
// }
// }
// dib.clear(); dib.put(chars); dib.flip();
// rib.position(0);
// rob.clear(); rob.limit(lim);
// for (CharBuffer ib : new CharBuffer[] { rib, dib }) {
// Result r = recode(ib, rob);
// if (! (r.cr.isMalformed() &&
// r.cr.length() == 1 &&
// (rob.position() == 0 || hasBom(rob)))) {
// if (failures++ > 5) return;
// bug("Unpaired surrogate not malformed: %s %s",
// cs, r);
// }
// }
// //}
// for (int i = 0; i < 10000; i++) {
// chars[0] = randomHighSurrogate();
// chars[1] = randomLowSurrogate();
// dib.clear(); dib.put(chars); dib.flip();
// rib.position(0);
// rob.clear(); rob.limit(lim);
// for (CharBuffer ib : new CharBuffer[] { rib, dib }) {
// Result r = recode(ib, rob);
// if (! ((r.cr.isUnmappable() &&
// r.cr.length() == 2 &&
// rob.position() == 0)
// ||
// (r.cr.isUnderflow() &&
// rob.position() > 0 &&
// ib.position() == 2))) {
// if (failures++ > 5) return;
// bug("Legal supplementary character bug: %s %s",
// cs, r);
// }
// }
// }
// }
// }
try {
byte canary = 22;
bug("OVERFLOW, but there's lots of room: %s %s",
cs, r);
// if (cr.isOverflow() && ib.remaining() == 0 && ! hasBom)
// bug("OVERFLOW, yet remaining() == 0: %s %s",
// cs, r);
bug("remaining() < CoderResult.length(): %s %s",
cs, r);
// if (ib.position() == 0
// && ob.position() > 0
// && ! hasBom(r.oa))
// bug("output only if input consumed: %s %s",
// cs, r);
bug("Coding operation not idempotent: %s%n %s%n %s",
bug("Buffer overrun: %s %s %s",
return r;
} catch (Throwable t) {
if (bug("Unexpected exception: %s %s %s",
t.printStackTrace();
return null;
}
}
bug("Results differ for direct buffers: %s%n %s%n %s",
return r1;
}
throw new TooManyFailures();
if (olen > 0) {
bug("Results differ: %s%n %s%n %s",
}
for (int i = 0; i < olen; i++) {
bug("Expected OVERFLOW: %s%n %s%n %s",
}
}
return roomy;
}
for (int i = 0; i < 0x10000; i++) {
if (n == 1)
else
}
}
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < n; j++)
}
}
// Can you spare a year of CPU time?
//testExhaustively(prefix, 2);
}
}
private static char randomChar() {
}
private static char randomHighSurrogate() {
}
private static char randomLowSurrogate() {
}
return;
return;
}
tester.testPrefix(new char[] {});
}
}
try {
} catch (TooManyFailures e) {
} catch (Throwable t) {
unexpected(t);
}
}
}
//--------------------- Infrastructure ---------------------------
else fail(x + " not equal to " + y);}
}