[foreign-memaccess] Test for wrong first coordinate type
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Dec 20 21:38:29 UTC 2019
Looks good
Maurizio
On 20/12/2019 17:16, Paul Sandoz wrote:
> Here’s a simple test for a wrong first coordinate type i.e. something other than MemoryAddress.
>
> I don’t think we require anything more substantial given the type checking is consolidated in one place, and there are substantial negative tests in general for VarHandles. We could, as a follow on change to this test, choose to expand to all access modes just to be sure.
>
> Paul.
>
> diff -r 06dbd52de6a3 test/jdk/java/foreign/TestTypeAccess.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/jdk/java/foreign/TestTypeAccess.java Fri Dec 20 09:08:21 2019 -0800
> @@ -0,0 +1,54 @@
> +/*
> + * Copyright (c) 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.
> + *
> + * 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
> + * @run testng TestTypeAccess
> + */
> +
> +import jdk.incubator.foreign.MemorySegment;
> +import jdk.incubator.foreign.MemoryLayouts;
> +import org.testng.annotations.*;
> +
> +import java.lang.invoke.VarHandle;
> +import java.lang.invoke.WrongMethodTypeException;
> +
> +public class TestTypeAccess {
> +
> + static final VarHandle INT_HANDLE = MemoryLayouts.JAVA_INT.varHandle(int.class);
> +
> + @Test(expectedExceptions=ClassCastException.class)
> + public void testMemoryAddressCoordinateAsString() {
> + try (MemorySegment s = MemorySegment.allocateNative(8)) {
> + int v = (int)INT_HANDLE.get("string");
> + }
> + }
> +
> + @Test(expectedExceptions=WrongMethodTypeException.class)
> + public void testMemoryCoordinatePrimitive() {
> + try (MemorySegment s = MemorySegment.allocateNative(8)) {
> + int v = (int)INT_HANDLE.get(1);
> + }
> + }
> +}
>
More information about the panama-dev
mailing list