Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/invoke/LambdaFormTest.java
47216 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @summary unit tests for java.lang.invoke.LambdaForm25* @run junit/othervm test.java.lang.invoke.LambdaFormTest26*/27package test.java.lang.invoke;2829import org.junit.Test;30import java.lang.reflect.Method;31import static org.junit.Assert.*;3233public class LambdaFormTest {34static final Method M_shortenSignature;35static {36try {37Class<?> impl = Class.forName("java.lang.invoke.LambdaForm", false, null);38Method m = impl.getDeclaredMethod("shortenSignature", String.class);39m.setAccessible(true);40M_shortenSignature = m;41} catch(Exception e) {42throw new AssertionError(e);43}44}4546public static String shortenSignature(String signature) throws ReflectiveOperationException {47return (String)M_shortenSignature.invoke(null, signature);48}4950@Test51public void testShortenSignature() throws ReflectiveOperationException {52for (String s : new String[] {53// invariant strings:54"L", "LL", "ILL", "LIL", "LLI", "IILL", "ILIL", "ILLI",55// a few mappings:56"LLL=L3", "LLLL=L4", "LLLLLLLLLL=L10",57"IIIDDD=I3D3", "IDDD=ID3", "IIDDD=IID3", "IIID=I3D", "IIIDD=I3DD"58}) {59String s2 = s.substring(s.indexOf('=')+1);60String s1 = s.equals(s2) ? s : s.substring(0, s.length() - s2.length() - 1);61// mix the above cases with before and after reps of Z*62for (int k = -3; k <= 3; k++) {63String beg = (k < 0 ? "ZZZZ".substring(-k) : "");64String end = (k > 0 ? "ZZZZ".substring(+k) : "");65String ks1 = beg+s1+end;66String ks2 = shortenSignature(beg)+s2+shortenSignature(end);67String ks3 = shortenSignature(ks1);68assertEquals(ks2, ks3);69}70}71}7273public static void main(String[] args) throws ReflectiveOperationException {74LambdaFormTest test = new LambdaFormTest();75test.testShortenSignature();76}77}787980