1 /* 2 * Copyright (c) 2015, 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 import java.nicl.metadata.C; 24 import static java.lang.annotation.ElementType.TYPE_USE; 25 import java.lang.annotation.Retention; 26 import static java.lang.annotation.RetentionPolicy.RUNTIME; 27 import java.lang.annotation.Target; 28 import java.util.function.Predicate; 29 import static org.testng.Assert.assertEquals; 30 import static org.testng.Assert.assertTrue; 31 import org.testng.annotations.Test; 32 import com.sun.tools.jextract.JType; 33 import com.sun.tools.jextract.TypeAlias; 34 35 /* 36 * @test 37 * @summary Unit test for JType 38 * @modules jdk.jextract/com.sun.tools.jextract 39 * @run testng JTypeTest 40 */ 41 public class JTypeTest { 42 43 static class Inner {}; 44 static interface InnerIf {}; 45 46 @Target(TYPE_USE) 47 @Retention(RUNTIME) 48 @C(file="", line=1, column=1, USR="") 49 static @interface Alias {}; 50 51 public JTypeTest() { 52 } 53 54 @Test 55 /** 56 * Primitive types defined in JVMS 2.2 57 */ 58 public void testOfPrimitives() { 59 assertEquals(JType.of(byte.class), JType.Byte); 60 assertEquals(JType.of(short.class), JType.Short); 61 assertEquals(JType.of(int.class), JType.Int); 62 assertEquals(JType.of(long.class), JType.Long); 63 assertEquals(JType.of(char.class), JType.Char); 64 assertEquals(JType.of(float.class), JType.Float); 65 assertEquals(JType.of(double.class), JType.Double); 66 assertEquals(JType.of(boolean.class), JType.Bool); 67 assertEquals(JType.of(void.class), JType.Void); 68 } 69 70 @Test 71 public void testOfReference() { 72 assertEquals(JType.of(Object.class), JType.Object); 73 int[] ar = new int[0]; 74 assertTrue(JType.of(ar.getClass()) instanceof JType.Array); 75 assertTrue(JType.of(getClass()) instanceof JType.ObjectRef); 76 // FIXME: the follwing cases fail. 77 // assertTrue(JType.of(Alias.class) instanceof TypeAlias); 78 // assertTrue(JType.of(Predicate.class) instanceof JType.FnIf); 79 // assertTrue(JType.of(Inner.class) instanceof JType.InnerType); 80 // assertTrue(JType.of(InnerIf.class) instanceof JType.InnerType); 81 82 } 83 }