0N/A/*
2362N/A * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @summary Unit test for buffers
0N/A * @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
0N/A * 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529
5468N/A * 6221101 6234263 6535542 6591971 6593946 6795561
0N/A * @author Mark Reinhold
0N/A */
0N/A
0N/A
0N/Aimport java.io.PrintStream;
0N/A
0N/Aimport java.nio.Buffer;
0N/Aimport java.nio.ByteBuffer;
0N/Aimport java.nio.CharBuffer;
0N/A
0N/A
0N/Apublic class Basic {
0N/A
0N/A static PrintStream out = System.err;
0N/A
0N/A static long ic(int i) {
0N/A int j = i % 54;
0N/A return j + 'a' + ((j > 26) ? 128 : 0);
0N/A }
0N/A
0N/A static String toString(Buffer b) {
0N/A return (b.getClass().getName()
0N/A + "[pos=" + b.position()
0N/A + " lim=" + b.limit()
0N/A + " cap=" + b.capacity()
0N/A + "]");
0N/A }
0N/A
0N/A static void show(int level, Buffer b) {
0N/A for (int i = 0; i < level; i++)
0N/A out.print(" ");
0N/A out.println(toString(b) + " " + Integer.toHexString(b.hashCode()));
0N/A }
0N/A
0N/A static void fail(String s) {
0N/A throw new RuntimeException(s);
0N/A }
0N/A
0N/A static void fail(String s, Buffer b) {
0N/A throw new RuntimeException(s + ": " + toString(b));
0N/A }
0N/A
0N/A static void fail(String s, Buffer b, Buffer b2) {
0N/A throw new RuntimeException(s + ": "
0N/A + toString(b) + ", " + toString(b2));
0N/A }
0N/A
0N/A static void fail(Buffer b,
0N/A String expected, char expectedChar,
0N/A String got, char gotChar)
0N/A {
0N/A if (b instanceof ByteBuffer) {
0N/A ByteBuffer bb = (ByteBuffer)b;
0N/A int n = Math.min(16, bb.limit());
0N/A for (int i = 0; i < n; i++)
0N/A out.print(" " + Integer.toHexString(bb.get(i) & 0xff));
0N/A out.println();
0N/A }
0N/A if (b instanceof CharBuffer) {
0N/A CharBuffer bb = (CharBuffer)b;
0N/A int n = Math.min(16, bb.limit());
0N/A for (int i = 0; i < n; i++)
0N/A out.print(" " + Integer.toHexString(bb.get(i) & 0xffff));
0N/A out.println();
0N/A }
0N/A throw new RuntimeException(toString(b)
0N/A + ": Expected '" + expectedChar + "'=0x"
0N/A + expected
0N/A + ", got '" + gotChar + "'=0x"
0N/A + got);
0N/A }
0N/A
0N/A static void fail(Buffer b, long expected, long got) {
0N/A fail(b,
0N/A Long.toHexString(expected), (char)expected,
0N/A Long.toHexString(got), (char)got);
0N/A }
0N/A
0N/A static void ck(Buffer b, boolean cond) {
0N/A if (!cond)
0N/A fail("Condition failed", b);
0N/A }
0N/A
0N/A static void ck(Buffer b, long got, long expected) {
0N/A if (expected != got)
0N/A fail(b, expected, got);
0N/A }
0N/A
0N/A static void ck(Buffer b, float got, float expected) {
0N/A if (expected != got)
0N/A fail(b,
0N/A Float.toString(expected), (char)expected,
0N/A Float.toString(got), (char)got);
0N/A }
0N/A
0N/A static void ck(Buffer b, double got, double expected) {
0N/A if (expected != got)
0N/A fail(b,
0N/A Double.toString(expected), (char)expected,
0N/A Double.toString(got), (char)got);
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A BasicByte.test();
0N/A BasicChar.test();
0N/A BasicShort.test();
0N/A BasicInt.test();
0N/A BasicLong.test();
0N/A BasicFloat.test();
0N/A BasicDouble.test();
0N/A }
0N/A
0N/A}