< prev index next >

test/jdk/valhalla/valuetypes/QTypeDescriptorTest.java

Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd


  44 public class QTypeDescriptorTest {
  45     static final Point P0 = Point.makePoint(10, 20);
  46     static final Point P1 = Point.makePoint(30, 40);
  47     static final NonFlattenValue NFV = NonFlattenValue.make(30, 40);
  48 
  49     @Test
  50     public static void testLambda() {
  51         newArray(Point[]::new, 2);
  52         newArray(Point[][]::new, 1);
  53 
  54         newArray(NonFlattenValue[]::new, 3);
  55         newArray(MutablePath[]::new, 4);
  56 
  57         Function<Point[], T> f =
  58             (points) -> { return new T(points); };
  59         f.apply(new Point[] { P0, P1});
  60     }
  61 
  62     @Test
  63     public static void testMethodInvoke() throws Exception {
  64         Class<?> pointQType = Point.class.asValueType();
  65         Class<?> nonFlattenValueQType = NonFlattenValue.class.asValueType();
  66         Method m = QTypeDescriptorTest.class
  67             .getDeclaredMethod("toLine", pointQType, nonFlattenValueQType);
  68         makeLine(m, P0, NFV);
  69 
  70         m = QTypeDescriptorTest.class
  71                 .getDeclaredMethod("toLine", Point[].class);
  72         makeLine(m, (Object) new Point[] { P0, P1});
  73     }
  74 
  75     private static void makeLine(Method m, Object... args) throws Exception {
  76         Line l = (Line) m.invoke(null, args);
  77         assertEquals(l.p1, P0);
  78         assertEquals(l.p2, NFV.pointValue());
  79     }
  80 
  81     @Test
  82     public static void testStaticMethod() throws Throwable {
  83         // static method in an inline type with no parameter and void return type
  84         Runnable r = () -> ValueTest.run();
  85         r.run();


 110     public static void testProxy() throws Exception {
 111         InvocationHandler handler = new InvocationHandler() {
 112             @Override
 113             public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 114                 if (method.getName().equals("toLine")) {
 115                     return toLine((Point)args[0], (NonFlattenValue)args[1]);
 116                 }
 117                 throw new UnsupportedOperationException(method.toString());
 118             }
 119         };
 120 
 121         Class<?>[] intfs = new Class<?>[] { I.class };
 122         I intf = (I) Proxy.newProxyInstance(QTypeDescriptorTest.class.getClassLoader(), intfs, handler);
 123         Line l = intf.toLine(P0, NFV);
 124         assertEquals(l.p1, P0);
 125         assertEquals(l.p2, NFV.pointValue());
 126     }
 127 
 128     @DataProvider
 129     static Object[][] descriptors() {
 130         Class<?> pointLType = Point.class.asBoxType();
 131         Class<?> pointQType = Point.class.asValueType();
 132         Class<?> nonFlattenValueLType = NonFlattenValue.class.asBoxType();
 133         Class<?> nonFlattenValueQType = NonFlattenValue.class.asValueType();
 134         return new Object[][]{
 135             { QTypeDescriptorTest.class, "toLine", new Class<?>[] {pointQType, nonFlattenValueQType}, true},
 136             { QTypeDescriptorTest.class, "toLine", new Class<?>[] {pointLType, nonFlattenValueQType}, false},
 137             { QTypeDescriptorTest.class, "toLine", new Class<?>[] { Point[].class },                  true},
 138             { NonFlattenValue.class, "point",      null,                                              true},
 139             { NonFlattenValue.class, "pointValue", null,                                              true},
 140             { NonFlattenValue.class, "has",        new Class<?>[] {pointQType, pointLType},           true},
 141             { NonFlattenValue.class, "has",        new Class<?>[] {pointQType, pointQType},           false},
 142         };
 143     }
 144 
 145     @Test(dataProvider = "descriptors")
 146     public static void testDescriptors(Class<?> defc, String name, Class<?>[] params, boolean found) throws Exception {
 147         try {
 148             defc.getDeclaredMethod(name, params);
 149             if (!found) throw new AssertionError("Expected NoSuchMethodException");
 150         } catch (NoSuchMethodException e) {
 151             if (found) throw e;
 152         }
 153     }
 154 
 155     @DataProvider
 156     static Object[][] methodTypes() {
 157         Class<?> pointLType = Point.class.asBoxType();
 158         Class<?> pointQType = Point.class.asValueType();
 159         ClassLoader loader = QTypeDescriptorTest.class.getClassLoader();
 160         return new Object[][]{
 161             { "point",      MethodType.methodType(pointLType),                            true },
 162             { "pointValue", MethodType.methodType(pointQType),                            true },
 163             { "has",        MethodType.methodType(boolean.class, pointQType, pointLType), true },
 164             { "point",      MethodType.methodType(pointQType),                            false },
 165             { "pointValue", MethodType.methodType(pointLType),                            false },
 166             { "has",        MethodType.methodType(boolean.class, pointLType, pointQType), false },
 167             { "point",      MethodType.fromMethodDescriptorString("()LPoint;", loader),         true },
 168             { "point",      MethodType.fromMethodDescriptorString("()QPoint;", loader),         false },
 169             { "pointValue", MethodType.fromMethodDescriptorString("()QPoint;", loader),         true },
 170             { "pointValue", MethodType.fromMethodDescriptorString("()LPoint;", loader),         false },
 171             { "has",        MethodType.fromMethodDescriptorString("(QPoint;LPoint;)Z", loader), true },
 172             { "has",        MethodType.fromMethodDescriptorString("(LPoint;LPoint;)Z", loader), false },
 173         };
 174     }
 175 
 176     @Test(dataProvider = "methodTypes")
 177     public static void methodHandleLookup(String name, MethodType mtype, boolean found) throws Throwable {
 178         try {




  44 public class QTypeDescriptorTest {
  45     static final Point P0 = Point.makePoint(10, 20);
  46     static final Point P1 = Point.makePoint(30, 40);
  47     static final NonFlattenValue NFV = NonFlattenValue.make(30, 40);
  48 
  49     @Test
  50     public static void testLambda() {
  51         newArray(Point[]::new, 2);
  52         newArray(Point[][]::new, 1);
  53 
  54         newArray(NonFlattenValue[]::new, 3);
  55         newArray(MutablePath[]::new, 4);
  56 
  57         Function<Point[], T> f =
  58             (points) -> { return new T(points); };
  59         f.apply(new Point[] { P0, P1});
  60     }
  61 
  62     @Test
  63     public static void testMethodInvoke() throws Exception {
  64         Class<?> pointQType = Point.class;
  65         Class<?> nonFlattenValueQType = NonFlattenValue.class;
  66         Method m = QTypeDescriptorTest.class
  67             .getDeclaredMethod("toLine", pointQType, nonFlattenValueQType);
  68         makeLine(m, P0, NFV);
  69 
  70         m = QTypeDescriptorTest.class
  71                 .getDeclaredMethod("toLine", Point[].class);
  72         makeLine(m, (Object) new Point[] { P0, P1});
  73     }
  74 
  75     private static void makeLine(Method m, Object... args) throws Exception {
  76         Line l = (Line) m.invoke(null, args);
  77         assertEquals(l.p1, P0);
  78         assertEquals(l.p2, NFV.pointValue());
  79     }
  80 
  81     @Test
  82     public static void testStaticMethod() throws Throwable {
  83         // static method in an inline type with no parameter and void return type
  84         Runnable r = () -> ValueTest.run();
  85         r.run();


 110     public static void testProxy() throws Exception {
 111         InvocationHandler handler = new InvocationHandler() {
 112             @Override
 113             public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 114                 if (method.getName().equals("toLine")) {
 115                     return toLine((Point)args[0], (NonFlattenValue)args[1]);
 116                 }
 117                 throw new UnsupportedOperationException(method.toString());
 118             }
 119         };
 120 
 121         Class<?>[] intfs = new Class<?>[] { I.class };
 122         I intf = (I) Proxy.newProxyInstance(QTypeDescriptorTest.class.getClassLoader(), intfs, handler);
 123         Line l = intf.toLine(P0, NFV);
 124         assertEquals(l.p1, P0);
 125         assertEquals(l.p2, NFV.pointValue());
 126     }
 127 
 128     @DataProvider
 129     static Object[][] descriptors() {
 130         Class<?> pointLType = Point.class.asNullableType();
 131         Class<?> pointQType = Point.class;
 132         Class<?> nonFlattenValueLType = NonFlattenValue.class.asNullableType();
 133         Class<?> nonFlattenValueQType = NonFlattenValue.class;
 134         return new Object[][]{
 135             { QTypeDescriptorTest.class, "toLine", new Class<?>[] {pointQType, nonFlattenValueQType}, true},
 136             { QTypeDescriptorTest.class, "toLine", new Class<?>[] {pointLType, nonFlattenValueQType}, false},
 137             { QTypeDescriptorTest.class, "toLine", new Class<?>[] { Point[].class },                  true},
 138             { NonFlattenValue.class, "point",      null,                                              true},
 139             { NonFlattenValue.class, "pointValue", null,                                              true},
 140             { NonFlattenValue.class, "has",        new Class<?>[] {pointQType, pointLType},           true},
 141             { NonFlattenValue.class, "has",        new Class<?>[] {pointQType, pointQType},           false},
 142         };
 143     }
 144 
 145     @Test(dataProvider = "descriptors")
 146     public static void testDescriptors(Class<?> defc, String name, Class<?>[] params, boolean found) throws Exception {
 147         try {
 148             defc.getDeclaredMethod(name, params);
 149             if (!found) throw new AssertionError("Expected NoSuchMethodException");
 150         } catch (NoSuchMethodException e) {
 151             if (found) throw e;
 152         }
 153     }
 154 
 155     @DataProvider
 156     static Object[][] methodTypes() {
 157         Class<?> pointLType = Point.class.asNullableType();
 158         Class<?> pointQType = Point.class;
 159         ClassLoader loader = QTypeDescriptorTest.class.getClassLoader();
 160         return new Object[][]{
 161             { "point",      MethodType.methodType(pointLType),                            true },
 162             { "pointValue", MethodType.methodType(pointQType),                            true },
 163             { "has",        MethodType.methodType(boolean.class, pointQType, pointLType), true },
 164             { "point",      MethodType.methodType(pointQType),                            false },
 165             { "pointValue", MethodType.methodType(pointLType),                            false },
 166             { "has",        MethodType.methodType(boolean.class, pointLType, pointQType), false },
 167             { "point",      MethodType.fromMethodDescriptorString("()LPoint;", loader),         true },
 168             { "point",      MethodType.fromMethodDescriptorString("()QPoint;", loader),         false },
 169             { "pointValue", MethodType.fromMethodDescriptorString("()QPoint;", loader),         true },
 170             { "pointValue", MethodType.fromMethodDescriptorString("()LPoint;", loader),         false },
 171             { "has",        MethodType.fromMethodDescriptorString("(QPoint;LPoint;)Z", loader), true },
 172             { "has",        MethodType.fromMethodDescriptorString("(LPoint;LPoint;)Z", loader), false },
 173         };
 174     }
 175 
 176     @Test(dataProvider = "methodTypes")
 177     public static void methodHandleLookup(String name, MethodType mtype, boolean found) throws Throwable {
 178         try {


< prev index next >