1 /*
2 * Copyright (c) 2000, 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 /* Type-specific source code for unit test
25 *
26 * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
27 * We check in the generated source files so that the test tree can be used
28 * independently of the rest of the source tree.
29 */
30
31 // -- This file was mechanically generated: Do not edit! -- //
32
33 import java.nio.*;
34
35
36 public class BasicByte
37 extends Basic
38 {
39
40 private static final byte[] VALUES = {
41 Byte.MIN_VALUE,
42 (byte) -1,
43 (byte) 0,
44 (byte) 1,
45 Byte.MAX_VALUE,
46
47
48
49
50
51
52
53
54
452
453 if (as.alignmentOffset(0, us) != 0)
454 fail("Buffer not correctly aligned at index 0", as);
455
456 if (as.alignmentOffset(as.limit(), us) != 0)
457 fail("Buffer not correctly aligned at limit", as);
458
459 int p_mod = ab.alignmentOffset(p, us);
460 int l_mod = ab.alignmentOffset(l, us);
461 // Round up position
462 p = (p_mod > 0) ? p + (us - p_mod) : p;
463 // Round down limit
464 l = l - l_mod;
465
466 int ec = l - p;
467 if (as.limit() != ec) {
468 fail("Buffer capacity incorrect, expected: " + ec, as);
469 }
470 }
471 }
472 }
473
474
475 private static void fail(String problem,
476 ByteBuffer xb, ByteBuffer yb,
477 byte x, byte y) {
478 fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
479 }
480
481 private static void catchNullArgument(Buffer b, Runnable thunk) {
482 tryCatch(b, NullPointerException.class, thunk);
483 }
484
485 private static void catchIllegalArgument(Buffer b, Runnable thunk) {
486 tryCatch(b, IllegalArgumentException.class, thunk);
487 }
488
489 private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
490 tryCatch(b, ReadOnlyBufferException.class, thunk);
491 }
|
1 /*
2 * Copyright (c) 2000, 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 /* Type-specific source code for unit test
25 *
26 * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
27 * We check in the generated source files so that the test tree can be used
28 * independently of the rest of the source tree.
29 */
30
31 // -- This file was mechanically generated: Do not edit! -- //
32
33
34 import java.io.IOException;
35 import java.io.UncheckedIOException;
36
37 import java.nio.*;
38
39 import java.nio.channels.FileChannel;
40 import java.nio.file.Files;
41 import java.nio.file.Path;
42
43
44
45 public class BasicByte
46 extends Basic
47 {
48
49 private static final byte[] VALUES = {
50 Byte.MIN_VALUE,
51 (byte) -1,
52 (byte) 0,
53 (byte) 1,
54 Byte.MAX_VALUE,
55
56
57
58
59
60
61
62
63
461
462 if (as.alignmentOffset(0, us) != 0)
463 fail("Buffer not correctly aligned at index 0", as);
464
465 if (as.alignmentOffset(as.limit(), us) != 0)
466 fail("Buffer not correctly aligned at limit", as);
467
468 int p_mod = ab.alignmentOffset(p, us);
469 int l_mod = ab.alignmentOffset(l, us);
470 // Round up position
471 p = (p_mod > 0) ? p + (us - p_mod) : p;
472 // Round down limit
473 l = l - l_mod;
474
475 int ec = l - p;
476 if (as.limit() != ec) {
477 fail("Buffer capacity incorrect, expected: " + ec, as);
478 }
479 }
480 }
481
482 // mapped buffers
483 try {
484 for (MappedByteBuffer bb : mappedBuffers()) {
485 try {
486 int offset = bb.alignmentOffset(1, 4);
487 ck(bb, offset >= 0);
488 } catch (UnsupportedOperationException e) {
489 System.out.println("Not applicable, UOE thrown: ");
490 }
491 }
492 } catch (IOException e) {
493 throw new UncheckedIOException(e);
494 }
495 }
496
497 private static MappedByteBuffer[] mappedBuffers() throws IOException {
498 return new MappedByteBuffer[]{
499 createMappedBuffer(new byte[]{0, 1, 2, 3}),
500 createMappedBuffer(new byte[]{0, 1, 2, -3,
501 45, 6, 7, 78, 3, -7, 6, 7, -128, 127}),
502 };
503 }
504
505 private static MappedByteBuffer createMappedBuffer(byte[] contents)
506 throws IOException {
507 Path tempFile = Files.createTempFile("mbb", null);
508 tempFile.toFile().deleteOnExit();
509 Files.write(tempFile, contents);
510 try (FileChannel fc = FileChannel.open(tempFile)) {
511 MappedByteBuffer map =
512 fc.map(FileChannel.MapMode.READ_ONLY, 0, contents.length);
513 map.load();
514 return map;
515 }
516 }
517
518
519 private static void fail(String problem,
520 ByteBuffer xb, ByteBuffer yb,
521 byte x, byte y) {
522 fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
523 }
524
525 private static void catchNullArgument(Buffer b, Runnable thunk) {
526 tryCatch(b, NullPointerException.class, thunk);
527 }
528
529 private static void catchIllegalArgument(Buffer b, Runnable thunk) {
530 tryCatch(b, IllegalArgumentException.class, thunk);
531 }
532
533 private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
534 tryCatch(b, ReadOnlyBufferException.class, thunk);
535 }
|