Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/invoke/LambdaFormTest.java
41149 views
1
/*
2
* Copyright (c) 2014, 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
/* @test
25
* @summary unit tests for java.lang.invoke.LambdaForm
26
* @modules java.base/java.lang.invoke:open
27
* @run junit/othervm test.java.lang.invoke.LambdaFormTest
28
*/
29
package test.java.lang.invoke;
30
31
import org.junit.Test;
32
import java.lang.reflect.Method;
33
import static org.junit.Assert.*;
34
35
public class LambdaFormTest {
36
static final Method M_shortenSignature;
37
static {
38
try {
39
Class<?> impl = Class.forName("java.lang.invoke.LambdaForm", false, null);
40
Method m = impl.getDeclaredMethod("shortenSignature", String.class);
41
m.setAccessible(true);
42
M_shortenSignature = m;
43
} catch(Exception e) {
44
throw new AssertionError(e);
45
}
46
}
47
48
public static String shortenSignature(String signature) throws ReflectiveOperationException {
49
return (String)M_shortenSignature.invoke(null, signature);
50
}
51
52
@Test
53
public void testShortenSignature() throws ReflectiveOperationException {
54
for (String s : new String[] {
55
// invariant strings:
56
"L", "LL", "ILL", "LIL", "LLI", "IILL", "ILIL", "ILLI",
57
// a few mappings:
58
"LLL=L3", "LLLL=L4", "LLLLLLLLLL=L10",
59
"IIIDDD=I3D3", "IDDD=ID3", "IIDDD=IID3", "IIID=I3D", "IIIDD=I3DD"
60
}) {
61
String s2 = s.substring(s.indexOf('=')+1);
62
String s1 = s.equals(s2) ? s : s.substring(0, s.length() - s2.length() - 1);
63
// mix the above cases with before and after reps of Z*
64
for (int k = -3; k <= 3; k++) {
65
String beg = (k < 0 ? "ZZZZ".substring(-k) : "");
66
String end = (k > 0 ? "ZZZZ".substring(+k) : "");
67
String ks1 = beg+s1+end;
68
String ks2 = shortenSignature(beg)+s2+shortenSignature(end);
69
String ks3 = shortenSignature(ks1);
70
assertEquals(ks2, ks3);
71
}
72
}
73
}
74
75
public static void main(String[] args) throws ReflectiveOperationException {
76
LambdaFormTest test = new LambdaFormTest();
77
test.testShortenSignature();
78
}
79
}
80
81