Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/foreign/TestLayoutConstants.java
41145 views
1
/*
2
* Copyright (c) 2019, 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
* @test
26
* @run testng TestLayoutConstants
27
*/
28
29
import jdk.incubator.foreign.FunctionDescriptor;
30
import jdk.incubator.foreign.MemoryLayouts;
31
import jdk.incubator.foreign.MemoryLayout;
32
33
import java.lang.invoke.MethodHandles;
34
35
import org.testng.annotations.*;
36
import static org.testng.Assert.*;
37
38
public class TestLayoutConstants {
39
40
@Test(dataProvider = "layouts")
41
public void testDescribeResolve(MemoryLayout expected) {
42
try {
43
MemoryLayout actual = expected.describeConstable().get()
44
.resolveConstantDesc(MethodHandles.lookup());
45
assertEquals(actual, expected);
46
} catch (ReflectiveOperationException ex) {
47
throw new AssertionError(ex);
48
}
49
}
50
51
@Test(dataProvider = "functions")
52
public void testDescribeResolveFunction(MemoryLayout layout, boolean isVoid) {
53
FunctionDescriptor expected = isVoid ?
54
FunctionDescriptor.ofVoid(layout) :
55
FunctionDescriptor.of(layout, layout);
56
try {
57
FunctionDescriptor actual = expected.describeConstable().get()
58
.resolveConstantDesc(MethodHandles.lookup());
59
assertEquals(actual, expected);
60
} catch (ReflectiveOperationException ex) {
61
throw new AssertionError(ex);
62
}
63
}
64
65
@DataProvider(name = "layouts")
66
public Object[][] createLayouts() {
67
return new Object[][] {
68
//padding
69
{ MemoryLayouts.PAD_32 },
70
{ MemoryLayout.sequenceLayout(MemoryLayouts.PAD_32) },
71
{ MemoryLayout.sequenceLayout(5, MemoryLayouts.PAD_32) },
72
{ MemoryLayout.structLayout(MemoryLayouts.PAD_32, MemoryLayouts.PAD_32) },
73
{ MemoryLayout.unionLayout(MemoryLayouts.PAD_32, MemoryLayouts.PAD_32) },
74
//values, big endian
75
{ MemoryLayouts.BITS_32_BE },
76
{ MemoryLayout.structLayout(
77
MemoryLayouts.BITS_32_BE,
78
MemoryLayouts.BITS_32_BE) },
79
{ MemoryLayout.unionLayout(
80
MemoryLayouts.BITS_32_BE,
81
MemoryLayouts.BITS_32_BE) },
82
//values, little endian
83
{ MemoryLayouts.BITS_32_LE },
84
{ MemoryLayout.structLayout(
85
MemoryLayouts.BITS_32_LE,
86
MemoryLayouts.BITS_32_LE) },
87
{ MemoryLayout.unionLayout(
88
MemoryLayouts.BITS_32_LE,
89
MemoryLayouts.BITS_32_LE) },
90
//deeply nested
91
{ MemoryLayout.structLayout(
92
MemoryLayouts.PAD_16,
93
MemoryLayout.structLayout(
94
MemoryLayouts.PAD_8,
95
MemoryLayouts.BITS_32_BE)) },
96
{ MemoryLayout.unionLayout(
97
MemoryLayouts.PAD_16,
98
MemoryLayout.structLayout(
99
MemoryLayouts.PAD_8,
100
MemoryLayouts.BITS_32_BE)) },
101
{ MemoryLayout.sequenceLayout(
102
MemoryLayout.structLayout(
103
MemoryLayouts.PAD_8,
104
MemoryLayouts.BITS_32_BE)) },
105
{ MemoryLayout.sequenceLayout(5,
106
MemoryLayout.structLayout(
107
MemoryLayouts.PAD_8,
108
MemoryLayouts.BITS_32_BE)) },
109
{ MemoryLayouts.BITS_32_LE.withName("myInt") },
110
{ MemoryLayouts.BITS_32_LE.withBitAlignment(8) },
111
{ MemoryLayouts.BITS_32_LE.withAttribute("xyz", "abc") },
112
};
113
}
114
115
@DataProvider(name = "functions")
116
public Object[][] createFunctions() {
117
Object[][] layouts = createLayouts();
118
Object[][] functions = new Object[layouts.length * 2][];
119
boolean[] values = new boolean[] { true, false };
120
for (int i = 0 ; i < layouts.length ; i++) {
121
for (boolean isVoid : values) {
122
int offset = 0;
123
if (isVoid) {
124
offset += 1;
125
}
126
functions[i * 2 + offset] = new Object[] { layouts[i][0], isVoid };
127
}
128
}
129
return functions;
130
}
131
}
132
133