24
24
/*
25
25
* @test
26
26
* @bug 8299576
27
+ * @modules java.base/jdk.internal.util
27
28
* @summary Verify that reads and writes of primitives are correct
28
- * @compile/module=java.base java/io/BitsProxy.java
29
29
* @run junit ReadWriteValues
30
30
*/
31
31
32
- import java .io .BitsProxy ;
32
+ import jdk .internal .util .ByteArray ;
33
+ import org .junit .jupiter .api .*;
34
+
33
35
import java .util .concurrent .ThreadLocalRandom ;
34
36
import java .util .stream .DoubleStream ;
35
37
import java .util .stream .LongStream ;
36
38
import java .util .stream .Stream ;
37
39
38
- import org .junit .jupiter .api .*;
39
-
40
40
import static org .junit .jupiter .api .Assertions .*;
41
41
42
42
final class ReadWriteValues {
@@ -53,7 +53,7 @@ void testGetShort() {
53
53
longs ().forEach (l -> {
54
54
short expected = (short ) l ;
55
55
RefImpl .putShort (BUFF , OFFSET , expected );
56
- short actual = BitsProxy .getShort (BUFF , OFFSET );
56
+ short actual = ByteArray .getShort (BUFF , OFFSET );
57
57
assertEquals (expected , actual );
58
58
});
59
59
}
@@ -62,7 +62,7 @@ void testGetShort() {
62
62
void testPutShort () {
63
63
longs ().forEach (l -> {
64
64
short expected = (short ) l ;
65
- BitsProxy . putShort (BUFF , OFFSET , expected );
65
+ ByteArray . setShort (BUFF , OFFSET , expected );
66
66
short actual = RefImpl .getShort (BUFF , OFFSET );
67
67
assertEquals (expected , actual );
68
68
});
@@ -73,7 +73,7 @@ void testGetChar() {
73
73
longs ().forEach (l -> {
74
74
char expected = (char ) l ;
75
75
RefImpl .putChar (BUFF , OFFSET , expected );
76
- char actual = BitsProxy .getChar (BUFF , OFFSET );
76
+ char actual = ByteArray .getChar (BUFF , OFFSET );
77
77
assertEquals (expected , actual );
78
78
});
79
79
}
@@ -82,7 +82,7 @@ void testGetChar() {
82
82
void testPutChar () {
83
83
longs ().forEach (l -> {
84
84
char expected = (char ) l ;
85
- BitsProxy . putChar (BUFF , OFFSET , expected );
85
+ ByteArray . setChar (BUFF , OFFSET , expected );
86
86
char actual = RefImpl .getChar (BUFF , OFFSET );
87
87
assertEquals (expected , actual );
88
88
});
@@ -93,7 +93,7 @@ void testGetInt() {
93
93
longs ().forEach (l -> {
94
94
int expected = (int ) l ;
95
95
RefImpl .putInt (BUFF , OFFSET , expected );
96
- int actual = BitsProxy .getInt (BUFF , OFFSET );
96
+ int actual = ByteArray .getInt (BUFF , OFFSET );
97
97
assertEquals (expected , actual );
98
98
});
99
99
}
@@ -102,7 +102,7 @@ void testGetInt() {
102
102
void testPutInt () {
103
103
longs ().forEach (l -> {
104
104
int expected = (int ) l ;
105
- BitsProxy . putInt (BUFF , OFFSET , expected );
105
+ ByteArray . setInt (BUFF , OFFSET , expected );
106
106
int actual = RefImpl .getInt (BUFF , OFFSET );
107
107
assertEquals (expected , actual );
108
108
});
@@ -112,15 +112,15 @@ void testPutInt() {
112
112
void testGetLong () {
113
113
longs ().forEach (expected -> {
114
114
RefImpl .putLong (BUFF , OFFSET , expected );
115
- long actual = BitsProxy .getLong (BUFF , OFFSET );
115
+ long actual = ByteArray .getLong (BUFF , OFFSET );
116
116
assertEquals (expected , actual );
117
117
});
118
118
}
119
119
120
120
@ Test
121
121
void testPutLong () {
122
122
longs ().forEach (expected -> {
123
- BitsProxy . putLong (BUFF , OFFSET , expected );
123
+ ByteArray . setLong (BUFF , OFFSET , expected );
124
124
long actual = RefImpl .getLong (BUFF , OFFSET );
125
125
assertEquals (expected , actual );
126
126
});
@@ -130,15 +130,15 @@ void testPutLong() {
130
130
void testGetFloat () {
131
131
floats ().forEach (expected -> {
132
132
RefImpl .putFloat (BUFF , OFFSET , expected );
133
- float actual = BitsProxy .getFloat (BUFF , OFFSET );
133
+ float actual = ByteArray .getFloat (BUFF , OFFSET );
134
134
assertEquals (expected , actual );
135
135
});
136
136
}
137
137
138
138
@ Test
139
139
void testPutFloat () {
140
140
floats ().forEach (expected -> {
141
- BitsProxy . putFloat (BUFF , OFFSET , expected );
141
+ ByteArray . setFloat (BUFF , OFFSET , expected );
142
142
float actual = RefImpl .getFloat (BUFF , OFFSET );
143
143
assertEquals (expected , actual );
144
144
});
@@ -148,40 +148,192 @@ void testPutFloat() {
148
148
void testGetDouble () {
149
149
doubles ().forEach (expected -> {
150
150
RefImpl .putDouble (BUFF , OFFSET , expected );
151
- double actual = BitsProxy .getDouble (BUFF , OFFSET );
151
+ double actual = ByteArray .getDouble (BUFF , OFFSET );
152
152
assertEquals (expected , actual );
153
153
});
154
154
}
155
155
156
156
@ Test
157
157
void testPutDouble () {
158
158
doubles ().forEach (expected -> {
159
- BitsProxy . putDouble (BUFF , OFFSET , expected );
159
+ ByteArray . setDouble (BUFF , OFFSET , expected );
160
160
double actual = RefImpl .getDouble (BUFF , OFFSET );
161
161
assertEquals (expected , actual );
162
162
});
163
163
}
164
164
165
+ @ Test
166
+ void testPutUnsignedShort () {
167
+ longs ().forEach (l -> {
168
+ int expected = Short .toUnsignedInt ((short ) l );
169
+ ByteArray .setUnsignedShort (BUFF , OFFSET , expected );
170
+ int actual = Short .toUnsignedInt (RefImpl .getShort (BUFF , OFFSET ));
171
+ assertEquals (expected , actual );
172
+ });
173
+ }
174
+
175
+
165
176
// Unusual cases
166
177
167
178
@ Test
168
179
void testNullArray () {
169
- assertThrowsOriginal (NullPointerException .class , () -> BitsProxy .getInt (null , OFFSET ));
170
- assertThrowsOriginal (NullPointerException .class , () -> BitsProxy . putInt (null , OFFSET , 1 ));
180
+ assertThrowsOriginal (NullPointerException .class , () -> ByteArray .getInt (null , OFFSET ));
181
+ assertThrowsOriginal (NullPointerException .class , () -> ByteArray . setInt (null , OFFSET , 1 ));
171
182
}
172
183
173
184
@ Test
174
185
void testNegArg () {
175
- assertThrowsOriginal (IndexOutOfBoundsException .class , () -> BitsProxy .getInt (BUFF , -1 ));
176
- assertThrowsOriginal (IndexOutOfBoundsException .class , () -> BitsProxy . putInt (BUFF , -1 , 1 ));
186
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray .getInt (BUFF , -1 ));
187
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray . setInt (BUFF , -1 , 1 ));
177
188
}
178
189
179
190
@ Test
180
191
void testOutOfBounds () {
181
- assertThrowsOriginal (IndexOutOfBoundsException .class , () -> BitsProxy .getInt (BUFF , BUFF .length ));
182
- assertThrowsOriginal (IndexOutOfBoundsException .class , () -> BitsProxy .putInt (BUFF , BUFF .length , 1 ));
192
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray .getInt (BUFF , BUFF .length ));
193
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray .setInt (BUFF , BUFF .length , 1 ));
194
+ }
195
+
196
+ // At-zero methods
197
+
198
+ @ Test
199
+ void testGetShortAtZero () {
200
+ longs ().forEach (l -> {
201
+ short expected = (short ) l ;
202
+ RefImpl .putShort (BUFF , 0 , expected );
203
+ short actual = ByteArray .getShort (BUFF );
204
+ assertEquals (expected , actual );
205
+ });
206
+ }
207
+
208
+ @ Test
209
+ void testPutShortAtZero () {
210
+ longs ().forEach (l -> {
211
+ short expected = (short ) l ;
212
+ ByteArray .setShort (BUFF , expected );
213
+ short actual = RefImpl .getShort (BUFF , 0 );
214
+ assertEquals (expected , actual );
215
+ });
216
+ }
217
+
218
+ @ Test
219
+ void testGetCharAtZero () {
220
+ longs ().forEach (l -> {
221
+ char expected = (char ) l ;
222
+ RefImpl .putChar (BUFF , 0 , expected );
223
+ char actual = ByteArray .getChar (BUFF );
224
+ assertEquals (expected , actual );
225
+ });
226
+ }
227
+
228
+ @ Test
229
+ void testPutCharAtZero () {
230
+ longs ().forEach (l -> {
231
+ char expected = (char ) l ;
232
+ ByteArray .setChar (BUFF , expected );
233
+ char actual = RefImpl .getChar (BUFF , 0 );
234
+ assertEquals (expected , actual );
235
+ });
236
+ }
237
+
238
+ @ Test
239
+ void testGetIntAtZero () {
240
+ longs ().forEach (l -> {
241
+ int expected = (int ) l ;
242
+ RefImpl .putInt (BUFF , 0 , expected );
243
+ int actual = ByteArray .getInt (BUFF );
244
+ assertEquals (expected , actual );
245
+ });
246
+ }
247
+
248
+ @ Test
249
+ void testPutIntAtZero () {
250
+ longs ().forEach (l -> {
251
+ int expected = (int ) l ;
252
+ ByteArray .setInt (BUFF , expected );
253
+ int actual = RefImpl .getInt (BUFF , 0 );
254
+ assertEquals (expected , actual );
255
+ });
256
+ }
257
+
258
+ @ Test
259
+ void testGetLongAtZero () {
260
+ longs ().forEach (expected -> {
261
+ RefImpl .putLong (BUFF , 0 , expected );
262
+ long actual = ByteArray .getLong (BUFF );
263
+ assertEquals (expected , actual );
264
+ });
183
265
}
184
266
267
+ @ Test
268
+ void testPutLongAtZero () {
269
+ longs ().forEach (expected -> {
270
+ ByteArray .setLong (BUFF , expected );
271
+ long actual = RefImpl .getLong (BUFF , 0 );
272
+ assertEquals (expected , actual );
273
+ });
274
+ }
275
+
276
+ @ Test
277
+ void testGetFloatAtZero () {
278
+ floats ().forEach (expected -> {
279
+ RefImpl .putFloat (BUFF , 0 , expected );
280
+ float actual = ByteArray .getFloat (BUFF );
281
+ assertEquals (expected , actual );
282
+ });
283
+ }
284
+
285
+ @ Test
286
+ void testPutFloatAtZero () {
287
+ floats ().forEach (expected -> {
288
+ ByteArray .setFloat (BUFF , expected );
289
+ float actual = RefImpl .getFloat (BUFF , 0 );
290
+ assertEquals (expected , actual );
291
+ });
292
+ }
293
+
294
+ @ Test
295
+ void testGetDoubleAtZero () {
296
+ doubles ().forEach (expected -> {
297
+ RefImpl .putDouble (BUFF , 0 , expected );
298
+ double actual = ByteArray .getDouble (BUFF );
299
+ assertEquals (expected , actual );
300
+ });
301
+ }
302
+
303
+ @ Test
304
+ void testPutDoubleAtZero () {
305
+ doubles ().forEach (expected -> {
306
+ ByteArray .setDouble (BUFF , expected );
307
+ double actual = RefImpl .getDouble (BUFF , 0 );
308
+ assertEquals (expected , actual );
309
+ });
310
+ }
311
+
312
+ @ Test
313
+ void testPutUnsignedShortAtZero () {
314
+ longs ().forEach (l -> {
315
+ int expected = Short .toUnsignedInt ((short ) l );
316
+ ByteArray .setUnsignedShort (BUFF , expected );
317
+ int actual = Short .toUnsignedInt (RefImpl .getShort (BUFF , 0 ));
318
+ assertEquals (expected , actual );
319
+ });
320
+ }
321
+
322
+ // Unusual cases
323
+
324
+ @ Test
325
+ void testNullArrayAtZero () {
326
+ assertThrowsOriginal (NullPointerException .class , () -> ByteArray .getInt (null ));
327
+ assertThrowsOriginal (NullPointerException .class , () -> ByteArray .setInt (null , 1 ));
328
+ }
329
+
330
+ @ Test
331
+ void testOutOfBoundsAtZero () {
332
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray .getInt (new byte [1 ]));
333
+ assertThrowsOriginal (IndexOutOfBoundsException .class , () -> ByteArray .setInt (new byte [1 ],1 ));
334
+ }
335
+
336
+
185
337
static LongStream longs () {
186
338
return ThreadLocalRandom .current ().longs (ITERATIONS );
187
339
}
@@ -315,5 +467,4 @@ static void putDouble(byte[] b, int off, double val) {
315
467
putLong (b , off , Double .doubleToLongBits (val ));
316
468
}
317
469
}
318
-
319
470
}
0 commit comments