Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/foreign/TestIllegalLink.java
41144 views
1
/*
2
* Copyright (c) 2020, 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
/*
26
* @test
27
* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
28
* @run testng/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink
29
*/
30
31
import jdk.incubator.foreign.CLinker;
32
import jdk.incubator.foreign.FunctionDescriptor;
33
import jdk.incubator.foreign.MemoryAddress;
34
import jdk.incubator.foreign.MemoryLayout;
35
import jdk.incubator.foreign.MemoryLayouts;
36
import jdk.incubator.foreign.MemorySegment;
37
import org.testng.annotations.DataProvider;
38
import org.testng.annotations.Test;
39
40
import java.lang.invoke.MethodType;
41
42
import static jdk.incubator.foreign.CLinker.C_INT;
43
import static org.testng.Assert.assertTrue;
44
import static org.testng.Assert.fail;
45
46
public class TestIllegalLink {
47
48
private static final MemoryAddress DUMMY_TARGET = MemoryAddress.ofLong(1);
49
private static final CLinker ABI = CLinker.getInstance();
50
51
@Test(dataProvider = "types")
52
public void testTypeMismatch(MethodType mt, FunctionDescriptor desc, String expectedExceptionMessage) {
53
try {
54
ABI.downcallHandle(DUMMY_TARGET, mt, desc);
55
fail("Expected IllegalArgumentException was not thrown");
56
} catch (IllegalArgumentException e) {
57
assertTrue(e.getMessage().contains(expectedExceptionMessage));
58
}
59
}
60
61
@DataProvider
62
public static Object[][] types() {
63
return new Object[][]{
64
{
65
MethodType.methodType(void.class),
66
FunctionDescriptor.of(C_INT),
67
"Return type mismatch"
68
},
69
{
70
MethodType.methodType(void.class),
71
FunctionDescriptor.ofVoid(C_INT),
72
"Arity mismatch"
73
},
74
{
75
MethodType.methodType(void.class, int.class),
76
FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(32)),
77
"Expected a ValueLayout"
78
},
79
{
80
MethodType.methodType(void.class, boolean.class),
81
FunctionDescriptor.ofVoid(MemoryLayouts.BITS_8_LE),
82
"Unsupported carrier"
83
},
84
{
85
MethodType.methodType(void.class, int.class),
86
FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
87
"Carrier size mismatch"
88
},
89
{
90
MethodType.methodType(void.class, MemoryAddress.class),
91
FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(64)),
92
"Expected a ValueLayout"
93
},
94
{
95
MethodType.methodType(void.class, MemoryAddress.class),
96
FunctionDescriptor.ofVoid(MemoryLayouts.BITS_16_LE),
97
"Address size mismatch"
98
},
99
{
100
MethodType.methodType(void.class, MemorySegment.class),
101
FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
102
"Expected a GroupLayout"
103
},
104
{
105
MethodType.methodType(void.class, String.class),
106
FunctionDescriptor.ofVoid(MemoryLayouts.BITS_64_LE),
107
"Unsupported carrier"
108
},
109
};
110
}
111
112
}
113
114