< prev index next >
test/jdk/java/nio/Buffer/Basic-X.java.template
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 85,94 ****
--- 85,106 ----
for (int i = 0; i < n; i++) {
ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
}
}
+ private static void absBulkGet($Type$Buffer b) {
+ int n = b.capacity();
+ int len = n - 7*2;
+ $type$[] a = new $type$[n + 7];
+ b.position(42);
+ b.get(7, a, 7, len);
+ ck(b, b.position() == 42);
+ for (int i = 0; i < len; i++) {
+ ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
+ }
+ }
+
private static void relPut($Type$Buffer b) {
int n = b.capacity();
b.clear();
for (int i = 0; i < n; i++)
b.put(($type$)ic(i));
*** 134,143 ****
--- 146,196 ----
+ " put into same buffer");
}
}
}
+ private static void absBulkPutArray($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ int lim = n - 7;
+ int len = lim - 7;
+ b.limit(lim);
+ $type$[] a = new $type$[len + 7];
+ for (int i = 0; i < len; i++)
+ a[i + 7] = ($type$)ic(i);
+ b.position(42);
+ b.put(7, a, 7, len);
+ ck(b, b.position() == 42);
+ }
+
+ private static void absBulkPutBuffer($Type$Buffer b, boolean direct) {
+ int n = b.capacity();
+ b.clear();
+ int lim = n - 7;
+ int len = lim - 7;
+ b.limit(lim);
+ $Type$Buffer c = direct ?
+ #if[byte]
+ ByteBuffer.allocateDirect(len + 7)
+ #else[byte]
+ ByteBuffer.allocateDirect($Fulltype$.BYTES*(len + 7))
+ .as$Type$Buffer()
+ #end[byte]
+ : $Type$Buffer.allocate(len + 7);
+ #if[!byte]
+ if (direct)
+ System.out.println("Direct buffer: " + c.getClass().getName());
+ #end[!byte]
+ for (int i = 0; i < len; i++)
+ c.put(i + 7, ($type$)ic(i));
+ b.position(42);
+ c.position(42);
+ b.put(7, c, 7, len);
+ ck(b, b.position() == 42);
+ ck(c, c.position() == 42);
+ }
+
//6231529
private static void callReset($Type$Buffer b) {
b.position(0);
b.mark();
*** 450,459 ****
--- 503,516 ----
$Type$Buffer xb, $Type$Buffer yb,
$type$ x, $type$ y) {
fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
}
+ private static void catchNullArgument(Buffer b, Runnable thunk) {
+ tryCatch(b, NullPointerException.class, thunk);
+ }
+
private static void catchIllegalArgument(Buffer b, Runnable thunk) {
tryCatch(b, IllegalArgumentException.class, thunk);
}
private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
*** 474,484 ****
thunk.run();
} catch (Throwable x) {
if (ex.isAssignableFrom(x.getClass())) {
caught = true;
} else {
! fail(x.getMessage() + " not expected");
}
}
if (!caught) {
fail(ex.getName() + " not thrown", b);
}
--- 531,544 ----
thunk.run();
} catch (Throwable x) {
if (ex.isAssignableFrom(x.getClass())) {
caught = true;
} else {
! String s = x.getMessage();
! if (s == null)
! s = x.getClass().getName();
! fail(s + " not expected");
}
}
if (!caught) {
fail(ex.getName() + " not thrown", b);
}
*** 511,520 ****
--- 571,589 ----
relGet(b);
bulkPutBuffer(b);
relGet(b);
+ absBulkPutArray(b);
+ absBulkGet(b);
+
+ absBulkPutBuffer(b, direct);
+ absBulkGet(b);
+
+ absBulkPutBuffer(b, !direct);
+ absBulkGet(b);
+
#if[char]
bulkPutString(b);
relGet(b);
b.position(1);
*** 610,619 ****
--- 679,719 ----
fail("Non-null IllegalArgumentException message expected for"
+ " negative limit");
}
}
+ // Exceptions in absolute bulk operations
+
+ catchNullArgument(b, () -> b.get(7, null, 0, 42));
+ catchNullArgument(b, () -> b.put(7, ($type$[])null, 0, 42));
+ catchNullArgument(b, () -> b.put(7, ($Type$Buffer)null, 0, 42));
+
+ $type$[] tmpa = new $type$[42];
+ catchIndexOutOfBounds(b, () -> b.get(7, tmpa, -1, 42));
+ catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 42, 1));
+ catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 41, -1));
+ catchIndexOutOfBounds(b, () -> b.get(-1, tmpa, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.get(b.limit(), tmpa, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.get(b.limit() - 41, tmpa, 0, 42));
+
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpa, -1, 42));
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 42, 1));
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 41, -1));
+ catchIndexOutOfBounds(b, () -> b.put(-1, tmpa, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
+
+ $Type$Buffer tmpb = $Type$Buffer.allocate(42);
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpb, -1, 42));
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, 1));
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, -1));
+ catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 41, 2));
+ catchIndexOutOfBounds(b, () -> b.put(-1, tmpb, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpb, 0, 1));
+ catchIndexOutOfBounds(b, () -> b.put(0, tmpb, 0, -1));
+ catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpb, 0, 42));
+
// Values
b.clear();
b.put(($type$)0);
b.put(($type$)-1);
*** 817,826 ****
--- 917,928 ----
catchReadOnlyBuffer(b, () -> relPut(rb));
catchReadOnlyBuffer(b, () -> absPut(rb));
catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
+ catchReadOnlyBuffer(b, () -> absBulkPutArray(rb));
+ catchReadOnlyBuffer(b, () -> absBulkPutBuffer(rb, direct));
// put($Type$Buffer) should not change source position
final $Type$Buffer src = $Type$Buffer.allocate(1);
catchReadOnlyBuffer(b, () -> rb.put(src));
ck(src, src.position(), 0);
< prev index next >