Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/constant/NameValidationTest.java
41149 views
1
/*
2
* Copyright (c) 2018, 2019, 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
/**
25
* @test
26
* @bug 8215510
27
* @compile NameValidationTest.java
28
* @run testng NameValidationTest
29
* @summary unit tests for verifying member names
30
*/
31
32
import java.lang.constant.*;
33
import java.lang.invoke.*;
34
35
import org.testng.annotations.Test;
36
37
import static java.lang.constant.DirectMethodHandleDesc.*;
38
import static java.lang.constant.ConstantDescs.*;
39
import static java.lang.constant.DirectMethodHandleDesc.Kind.VIRTUAL;
40
41
import static org.testng.Assert.fail;
42
43
@Test
44
public class NameValidationTest {
45
46
private static final String[] badMemberNames = new String[] {"xx.xx", "zz;zz", "[l", "aa/aa", "<cinit>"};
47
private static final String[] goodMemberNames = new String[] {"<clinit>", "<init>", "3", "~", "$", "qq"};
48
49
private static final String[] badClassNames = new String[] {"zz;zz", "[l", "aa/aa", ".", "a..b"};
50
private static final String[] goodClassNames = new String[] {"3", "~", "$", "qq", "a.a"};
51
52
public void testMemberNames() {
53
DirectMethodHandleDesc mh = MethodHandleDesc.of(Kind.VIRTUAL, CD_String, "isEmpty", "()Z");
54
for (String badName : badMemberNames) {
55
try {
56
memberNamesHelper(badName, mh, CD_int, null);
57
fail("Expected failure for name " + badName);
58
} catch (IllegalArgumentException iae) {
59
// expected
60
}
61
try {
62
memberNamesHelper(badName, mh, CD_int, new ConstantDesc[0]);
63
fail("Expected failure for name " + badName);
64
} catch (IllegalArgumentException iae) {
65
// expected
66
}
67
}
68
69
for (String badName : goodMemberNames) {
70
memberNamesHelper(badName, mh, CD_int, null);
71
memberNamesHelper(badName, mh, CD_int, new ConstantDesc[0]);
72
}
73
}
74
75
private void memberNamesHelper(String constantName,
76
DirectMethodHandleDesc bootstrapMethod,
77
ClassDesc constantType,
78
ConstantDesc... bootstrapArgs) {
79
if (bootstrapArgs == null) {
80
DynamicConstantDesc.ofNamed(bootstrapMethod, constantName, constantType);
81
} else {
82
DynamicConstantDesc.ofNamed(bootstrapMethod, constantName, constantType, bootstrapArgs);
83
}
84
}
85
86
public void testClassNames() {
87
for (String badName : badClassNames) {
88
try {
89
ClassDesc.of(badName);
90
fail("Expected failure for name " + badName);
91
} catch (IllegalArgumentException iae) {
92
// expected
93
}
94
}
95
96
for (String goodName : goodClassNames) {
97
ClassDesc.of(goodName);
98
}
99
}
100
}
101
102