1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.incubator.foreign.*;
  25 import org.testng.annotations.Test;
  26 import test.jextract.struct.struct_h;
  27 
  28 import static org.testng.Assert.assertEquals;
  29 import static org.testng.Assert.fail;
  30 import static test.jextract.struct.struct_h.*;
  31 
  32 /*
  33  * @test
  34  * @library ..
  35  * @modules jdk.incubator.jextract
  36  * @run driver JtregJextract -l Struct -t test.jextract.struct -- struct.h
  37  * @run testng LibStructTest
  38  */
  39 public class LibStructTest {
  40     @Test
  41     public void func() {}
  42 
  43     /*
  44     @Test
  45     public void testVoidArguments() {
  46         libStruct.voidArguments();
  47         assertEquals(Pointer.toString(libStruct.LastCalledMethod$get()), "voidArguments");
  48     }
  49 
  50     @Test
  51     public void testEmptyArguments() {
  52         libStruct.emptyArguments(1);
  53         assertEquals(Pointer.toString(libStruct.LastCalledMethod$get()), "emptyArguments");
  54     }
  55 
  56     @Test
  57     public void testCastAndAccess() {
  58         Pointer<UndefinedStruct> ptr = libStruct.allocateUndefinedStruct();
  59         Plain pt = libStruct.fromUndefinedStruct(ptr);
  60         assertEquals(pt.x$get(), 0x1234);
  61         assertEquals(pt.y$get(), 0x3412);
  62 
  63         try {
  64             Plain tmp = ptr.cast(LayoutType.ofStruct(Plain.class)).get();
  65             fail("Should not be able to cast incompatible layout directly");
  66         } catch (ClassCastException ex) {
  67             // ignore expected
  68         }
  69 
  70         // This is working now as an escape, but should it really?
  71         Plain tmp = ptr.cast(NativeTypes.VOID).cast(LayoutType.ofStruct(Plain.class)).get();
  72         assertEquals(tmp.x$get(), 0x1234);
  73         assertEquals(tmp.y$get(), 0x3412);
  74     }*/
  75 }