< prev index next > test/jdk/java/foreign/TestTypeAccess.java
Print this page
*
*/
/*
* @test
- * @enablePreview
* @run testng TestTypeAccess
*/
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
static final VarHandle INT_HANDLE = ValueLayout.JAVA_INT.varHandle();
static final VarHandle ADDR_HANDLE = ValueLayout.ADDRESS.varHandle();
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressCoordinateAsString() {
! int v = (int)INT_HANDLE.get("string");
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryCoordinatePrimitive() {
int v = (int)INT_HANDLE.get(1);
}
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressValueGetAsString() {
try (Arena arena = Arena.ofConfined()) {
! MemorySegment s = arena.allocate(8, 8);;
! String address = (String)ADDR_HANDLE.get(s);
}
}
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressValueSetAsString() {
try (Arena arena = Arena.ofConfined()) {
MemorySegment s = arena.allocate(8, 8);;
! ADDR_HANDLE.set(s, "string");
}
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryAddressValueGetAsPrimitive() {
try (Arena arena = Arena.ofConfined()) {
! MemorySegment s = arena.allocate(8, 8);;
! int address = (int)ADDR_HANDLE.get(s);
}
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryAddressValueSetAsPrimitive() {
static final VarHandle INT_HANDLE = ValueLayout.JAVA_INT.varHandle();
static final VarHandle ADDR_HANDLE = ValueLayout.ADDRESS.varHandle();
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressCoordinateAsString() {
! int v = (int)INT_HANDLE.get("string", 0L);
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryCoordinatePrimitive() {
int v = (int)INT_HANDLE.get(1);
}
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressValueGetAsString() {
try (Arena arena = Arena.ofConfined()) {
! MemorySegment s = arena.allocate(8, 8);
! String address = (String)ADDR_HANDLE.get(s, 0L);
}
}
@Test(expectedExceptions=ClassCastException.class)
public void testMemoryAddressValueSetAsString() {
try (Arena arena = Arena.ofConfined()) {
MemorySegment s = arena.allocate(8, 8);;
! ADDR_HANDLE.set(s, 0L, "string");
}
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryAddressValueGetAsPrimitive() {
try (Arena arena = Arena.ofConfined()) {
! MemorySegment s = arena.allocate(8, 8);
! int address = (int)ADDR_HANDLE.get(s, 0L);
}
}
@Test(expectedExceptions=WrongMethodTypeException.class)
public void testMemoryAddressValueSetAsPrimitive() {
< prev index next >