< prev index next >

test/jdk/com/sun/tools/jextract/testStruct/LibStructTest.java

Print this page




  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.foreign.Libraries;
  25 import java.foreign.Library;
  26 import java.foreign.NativeTypes;
  27 import java.foreign.Scope;
  28 import java.foreign.memory.LayoutType;
  29 import java.foreign.memory.Pointer;
  30 import java.lang.invoke.MethodHandles;
  31 import org.testng.annotations.Test;
  32 import test.jextract.struct.struct;
  33 
  34 import static org.testng.Assert.assertEquals;
  35 import static org.testng.Assert.fail;
  36 import static test.jextract.struct.struct.*;
  37 
  38 /*
  39  * @test
  40  * @library ..
  41  * @run driver JtregJextract -t test.jextract.struct -- struct.h
  42  * @run testng LibStructTest
  43  */
  44 public class LibStructTest {
  45     static final struct libStruct;
  46 
  47     static {
  48         Library lib = Libraries.loadLibrary(MethodHandles.lookup(), "Struct");
  49         libStruct = Libraries.bind(struct.class, lib);
  50     }
  51 
  52     @Test
  53     public void testDerefUndefined() {
  54         Pointer<UndefinedStruct> ptr = libStruct.allocateUndefinedStruct();
  55         try {
  56             UndefinedStruct x = ptr.get();
  57             fail("Should not be able to dereference a Pointer to undefined struct");
  58         } catch (IllegalStateException ex) {
  59             // ignore expected
  60         }
  61 
  62         try (Scope scope = Scope.globalScope().fork()) {
  63             UndefinedStruct x = scope.allocateStruct(UndefinedStruct.class);
  64             fail("Should not be able to allocate an undefined struct");
  65         } catch (UnsupportedOperationException ex) {
  66             // ignore expected
  67         }
  68     }
  69 




  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.foreign.Libraries;
  25 import java.foreign.Library;
  26 import java.foreign.NativeTypes;
  27 import java.foreign.Scope;
  28 import java.foreign.memory.LayoutType;
  29 import java.foreign.memory.Pointer;
  30 import java.lang.invoke.MethodHandles;
  31 import org.testng.annotations.Test;
  32 import test.jextract.struct.struct_h;
  33 
  34 import static org.testng.Assert.assertEquals;
  35 import static org.testng.Assert.fail;
  36 import static test.jextract.struct.struct_h.*;
  37 
  38 /*
  39  * @test
  40  * @library ..
  41  * @run driver JtregJextract -t test.jextract.struct -- struct.h
  42  * @run testng LibStructTest
  43  */
  44 public class LibStructTest {
  45     static final struct_h libStruct;
  46 
  47     static {
  48         Library lib = Libraries.loadLibrary(MethodHandles.lookup(), "Struct");
  49         libStruct = Libraries.bind(struct_h.class, lib);
  50     }
  51 
  52     @Test
  53     public void testDerefUndefined() {
  54         Pointer<UndefinedStruct> ptr = libStruct.allocateUndefinedStruct();
  55         try {
  56             UndefinedStruct x = ptr.get();
  57             fail("Should not be able to dereference a Pointer to undefined struct");
  58         } catch (IllegalStateException ex) {
  59             // ignore expected
  60         }
  61 
  62         try (Scope scope = Scope.globalScope().fork()) {
  63             UndefinedStruct x = scope.allocateStruct(UndefinedStruct.class);
  64             fail("Should not be able to allocate an undefined struct");
  65         } catch (UnsupportedOperationException ex) {
  66             // ignore expected
  67         }
  68     }
  69 


< prev index next >