< prev index next >

test/jdk/java/foreign/TestIllegalLink.java

Print this page
@@ -30,83 +30,51 @@
  
  import jdk.incubator.foreign.CLinker;
  import jdk.incubator.foreign.FunctionDescriptor;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemoryLayout;
- import jdk.incubator.foreign.MemoryLayouts;
- import jdk.incubator.foreign.MemorySegment;
+ import jdk.incubator.foreign.NativeSymbol;
+ import jdk.incubator.foreign.ResourceScope;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
- import java.lang.invoke.MethodType;
- 
- import static jdk.incubator.foreign.CLinker.C_INT;
  import static org.testng.Assert.assertTrue;
  import static org.testng.Assert.fail;
  
- public class TestIllegalLink {
+ public class TestIllegalLink extends NativeTestHelper {
  
-     private static final MemoryAddress DUMMY_TARGET = MemoryAddress.ofLong(1);
-     private static final CLinker ABI = CLinker.getInstance();
+     private static final NativeSymbol DUMMY_TARGET = NativeSymbol.ofAddress("dummy", MemoryAddress.ofLong(1), ResourceScope.globalScope());
+     private static final CLinker ABI = CLinker.systemCLinker();
  
      @Test(dataProvider = "types")
-     public void testTypeMismatch(MethodType mt, FunctionDescriptor desc, String expectedExceptionMessage) {
+     public void testTypeMismatch(FunctionDescriptor desc, String expectedExceptionMessage) {
          try {
-             ABI.downcallHandle(DUMMY_TARGET, mt, desc);
+             ABI.downcallHandle(DUMMY_TARGET, desc);
              fail("Expected IllegalArgumentException was not thrown");
          } catch (IllegalArgumentException e) {
              assertTrue(e.getMessage().contains(expectedExceptionMessage));
          }
      }
  
      @DataProvider
      public static Object[][] types() {
          return new Object[][]{
              {
-                 MethodType.methodType(void.class),
-                 FunctionDescriptor.of(C_INT),
-                 "Return type mismatch"
-             },
-             {
-                 MethodType.methodType(void.class),
-                 FunctionDescriptor.ofVoid(C_INT),
-                 "Arity mismatch"
+                 FunctionDescriptor.of(MemoryLayout.paddingLayout(64)),
+                 "Unsupported layout: x64"
              },
              {
-                 MethodType.methodType(void.class, int.class),
-                 FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(32)),
-                 "Expected a ValueLayout"
-             },
-             {
-                 MethodType.methodType(void.class, boolean.class),
-                 FunctionDescriptor.ofVoid(MemoryLayouts.BITS_8_LE),
-                 "Unsupported carrier"
-             },
-             {
-                 MethodType.methodType(void.class, int.class),
-                 FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
-                 "Carrier size mismatch"
-             },
-             {
-                 MethodType.methodType(void.class, MemoryAddress.class),
                  FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(64)),
-                 "Expected a ValueLayout"
-             },
-             {
-                 MethodType.methodType(void.class, MemoryAddress.class),
-                 FunctionDescriptor.ofVoid(MemoryLayouts.BITS_16_LE),
-                 "Address size mismatch"
+                 "Unsupported layout: x64"
              },
              {
-                 MethodType.methodType(void.class, MemorySegment.class),
-                 FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
-                 "Expected a GroupLayout"
+                     FunctionDescriptor.of(MemoryLayout.sequenceLayout(C_INT)),
+                     "Unsupported layout: [:b32]"
              },
              {
-                 MethodType.methodType(void.class, String.class),
-                 FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
-                 "Unsupported carrier"
+                     FunctionDescriptor.ofVoid(MemoryLayout.sequenceLayout(C_INT)),
+                     "Unsupported layout: [:b32]"
              },
          };
      }
  
  }
< prev index next >