1 /*
   2  * Copyright (c) 2018, 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 org.testng.annotations.Test;
  25 
  26 import java.foreign.layout.Layout;
  27 import java.foreign.annotations.NativeStruct;
  28 import java.nio.file.Path;
  29 
  30 import static org.testng.Assert.assertEquals;
  31 import static org.testng.Assert.assertNotNull;
  32 import static org.testng.Assert.assertTrue;
  33 
  34 /*
  35  * @test
  36  * @modules jdk.jextract
  37  * @build JextractToolRunner
  38  * @run testng EmptyStructTest
  39  */
  40 public class EmptyStructTest extends JextractToolRunner {
  41     @Test
  42     public void emptyStruct() {
  43         Path clzPath = getOutputFilePath("EmptyStructTest.jar");
  44         run("-o", clzPath.toString(),
  45                 getInputFilePath("emptyStruct.h").toString()).checkSuccess();
  46         Class<?> cls = loadClass("emptyStruct", clzPath);
  47         Class<?>[] inners = cls.getDeclaredClasses();
  48         assertEquals(inners.length, 3);
  49         Class<?> emptyStruct = findClass(inners, "EmptyStruct");
  50         Class<?> nothing = findClass(inners, "Nothing");
  51         assertTrue(nothing.isAnnotation());
  52         NativeStruct ns = emptyStruct.getAnnotation(NativeStruct.class);
  53         assertNotNull(ns);
  54         Layout layout = Layout.of(ns.value());
  55         assertEquals(layout.bitsSize(), 0);
  56         deleteFile(clzPath);
  57     }
  58 }
--- EOF ---