2020-08-28 14:02:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2020 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
2020-10-28 14:38:14 +01:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2020-08-28 14:02:51 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2020-07-24 19:38:48 +02:00
|
|
|
package io.netty.buffer.b2;
|
|
|
|
|
2020-08-28 12:17:41 +02:00
|
|
|
import org.junit.After;
|
2020-08-17 16:09:38 +02:00
|
|
|
import org.junit.AssumptionViolatedException;
|
2020-08-28 12:17:41 +02:00
|
|
|
import org.junit.Before;
|
2020-10-28 14:38:14 +01:00
|
|
|
import org.junit.Ignore;
|
2020-07-24 19:38:48 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2020-10-30 14:39:50 +01:00
|
|
|
import java.nio.ByteBuffer;
|
2020-10-06 16:30:49 +02:00
|
|
|
import java.nio.ByteOrder;
|
2020-11-05 15:15:34 +01:00
|
|
|
import java.util.NoSuchElementException;
|
2020-07-24 19:38:48 +02:00
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.SynchronousQueue;
|
2020-10-30 14:39:50 +01:00
|
|
|
import java.util.function.Function;
|
2020-07-24 19:38:48 +02:00
|
|
|
|
2020-10-14 15:59:10 +02:00
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
2020-10-30 14:21:20 +01:00
|
|
|
import static org.junit.Assert.assertFalse;
|
2020-10-14 15:59:10 +02:00
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assert.fail;
|
2020-07-24 19:38:48 +02:00
|
|
|
|
2020-10-06 16:37:20 +02:00
|
|
|
public abstract class BufTest {
|
2020-07-24 19:38:48 +02:00
|
|
|
protected abstract Allocator createAllocator();
|
|
|
|
|
2020-08-28 12:17:41 +02:00
|
|
|
private Allocator allocator;
|
|
|
|
private Buf buf;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
allocator = createAllocator();
|
2020-10-14 15:59:10 +02:00
|
|
|
buf = allocate(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Buf allocate(int size) {
|
|
|
|
return allocator.allocate(size);
|
2020-08-28 12:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() {
|
|
|
|
buf.close();
|
|
|
|
allocator.close();
|
|
|
|
}
|
|
|
|
|
2020-07-24 19:38:48 +02:00
|
|
|
@Test
|
|
|
|
public void allocateAndAccessingBuffer() {
|
2020-08-28 12:17:41 +02:00
|
|
|
buf.writeByte((byte) 1);
|
|
|
|
buf.writeByte((byte) 2);
|
|
|
|
try (Buf inner = buf.acquire()) {
|
|
|
|
inner.writeByte((byte) 3);
|
|
|
|
inner.writeByte((byte) 4);
|
|
|
|
inner.writeByte((byte) 5);
|
|
|
|
inner.writeByte((byte) 6);
|
|
|
|
inner.writeByte((byte) 7);
|
|
|
|
inner.writeByte((byte) 8);
|
|
|
|
try {
|
|
|
|
inner.writeByte((byte) 9);
|
|
|
|
fail("Expected to be out of bounds.");
|
|
|
|
} catch (RuntimeException re) {
|
|
|
|
assertThat(re.getMessage(), containsString("bound"));
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
|
|
|
try {
|
2020-08-28 12:17:41 +02:00
|
|
|
buf.writeByte((byte) 9);
|
2020-07-24 19:38:48 +02:00
|
|
|
fail("Expected to be out of bounds.");
|
|
|
|
} catch (RuntimeException re) {
|
|
|
|
assertThat(re.getMessage(), containsString("bound"));
|
|
|
|
}
|
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
assertEquals((byte) 1, buf.readByte());
|
|
|
|
assertEquals((byte) 2, buf.readByte());
|
|
|
|
assertEquals((byte) 3, buf.readByte());
|
|
|
|
assertEquals((byte) 4, buf.readByte());
|
|
|
|
assertEquals((byte) 5, buf.readByte());
|
|
|
|
assertEquals((byte) 6, buf.readByte());
|
|
|
|
assertEquals((byte) 7, buf.readByte());
|
|
|
|
assertEquals((byte) 8, buf.readByte());
|
|
|
|
try {
|
|
|
|
assertEquals((byte) 9, buf.readByte());
|
|
|
|
fail("Expected to be out of bounds.");
|
|
|
|
} catch (RuntimeException re) {
|
|
|
|
assertThat(re.getMessage(), containsString("bound"));
|
|
|
|
}
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertArrayEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, buf.copy());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void acquireOnClosedBufferMustThrow() {
|
2020-10-14 15:59:10 +02:00
|
|
|
var buf = allocate(8);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.close();
|
|
|
|
try {
|
|
|
|
buf.acquire();
|
|
|
|
fail("Expected acquire on closed buffer to throw.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void allocateAndSendToThread() throws Exception {
|
2020-08-28 12:17:41 +02:00
|
|
|
ArrayBlockingQueue<Send<Buf>> queue = new ArrayBlockingQueue<>(10);
|
|
|
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
|
|
Future<Byte> future = executor.submit(() -> {
|
|
|
|
try (Buf byteBuf = queue.take().receive()) {
|
|
|
|
return byteBuf.readByte();
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
});
|
|
|
|
executor.shutdown();
|
2020-07-24 19:38:48 +02:00
|
|
|
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf buf = allocate(8)) {
|
2020-08-28 12:17:41 +02:00
|
|
|
buf.writeByte((byte) 42);
|
|
|
|
assertTrue(queue.offer(buf.send()));
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
|
|
|
|
assertEquals((byte) 42, future.get().byteValue());
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void allocateAndSendToThreadViaSyncQueue() throws Exception {
|
2020-08-28 12:17:41 +02:00
|
|
|
SynchronousQueue<Send<Buf>> queue = new SynchronousQueue<>();
|
|
|
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
|
|
Future<Byte> future = executor.submit(() -> {
|
|
|
|
try (Buf byteBuf = queue.take().receive()) {
|
|
|
|
return byteBuf.readByte();
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
});
|
|
|
|
executor.shutdown();
|
2020-07-24 19:38:48 +02:00
|
|
|
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf buf = allocate(8)) {
|
2020-08-28 12:17:41 +02:00
|
|
|
assertSame(buf, buf.writeByte((byte) 42));
|
|
|
|
queue.put(buf.send());
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
|
|
|
|
assertEquals((byte) 42, future.get().byteValue());
|
2020-07-24 19:38:48 +02:00
|
|
|
}
|
2020-08-17 16:09:38 +02:00
|
|
|
|
2020-10-15 16:20:26 +02:00
|
|
|
@Test
|
|
|
|
public void sendMustThrowWhenBufIsAcquired() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.acquire()) {
|
2020-10-30 14:21:20 +01:00
|
|
|
assertFalse(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
try {
|
|
|
|
buf.send();
|
|
|
|
fail("Should not be able to send() a borrowed buffer.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now send() should work again.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
buf.send().receive().close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 16:09:38 +02:00
|
|
|
@Test
|
|
|
|
public void mustThrowWhenAllocatingZeroSizedBuffer() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
2020-10-14 15:59:10 +02:00
|
|
|
allocate(0);
|
2020-08-28 12:17:41 +02:00
|
|
|
fail("Expected to throw an IllegalArgumentException.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
2020-08-17 16:09:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void mustThrowWhenAllocatingNegativeSizedBuffer() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
2020-10-14 15:59:10 +02:00
|
|
|
allocate(-1);
|
2020-08-28 12:17:41 +02:00
|
|
|
fail("Expected to throw an IllegalArgumentException.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
2020-08-17 16:09:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 14:38:14 +01:00
|
|
|
@Ignore // This test uses too much memory.
|
2020-08-17 16:09:38 +02:00
|
|
|
@Test
|
|
|
|
public void mustThrowWhenAllocatingOverSizedBuffer() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
2020-10-14 15:59:10 +02:00
|
|
|
allocate(Integer.MAX_VALUE);
|
2020-08-28 12:17:41 +02:00
|
|
|
fail("Expected to throw an IllegalArgumentException.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
2020-08-17 16:09:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 14:38:14 +01:00
|
|
|
@Ignore // This test uses too much memory.
|
2020-08-17 16:09:38 +02:00
|
|
|
@Test
|
|
|
|
public void mustAllowAllocatingMaxArraySizedBuffer() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
2020-10-14 15:59:10 +02:00
|
|
|
allocate(Integer.MAX_VALUE - 8).close();
|
2020-08-28 12:17:41 +02:00
|
|
|
} catch (OutOfMemoryError oome) {
|
|
|
|
// Mark test as ignored if this happens.
|
|
|
|
throw new AssumptionViolatedException("JVM does not have enough memory for this test.", oome);
|
2020-08-17 16:09:38 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-24 16:03:02 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void setReaderIndexMustThrowOnNegativeIndex() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
|
|
|
buf.readerIndex(-1);
|
|
|
|
fail("Expected an exception to be thrown.");
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
// Good.
|
2020-08-24 16:03:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void setReaderIndexMustThrowOnOversizedIndex() {
|
2020-08-28 12:17:41 +02:00
|
|
|
try {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.readerIndex(1);
|
|
|
|
fail("Expected an exception to be thrown.");
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writeLong(0);
|
|
|
|
try {
|
|
|
|
buf.readerIndex(9);
|
2020-08-28 12:17:41 +02:00
|
|
|
fail("Expected an exception to be thrown.");
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
// Good.
|
2020-08-24 16:03:02 +02:00
|
|
|
}
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
|
|
|
|
buf.readerIndex(8);
|
|
|
|
try {
|
|
|
|
buf.readByte();
|
|
|
|
fail("Expected and exception to be thrown.");
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-08-24 16:03:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void setReaderIndexMustNotThrowWithinBounds() {
|
2020-08-28 12:17:41 +02:00
|
|
|
assertSame(buf, buf.readerIndex(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeLong(0);
|
2020-08-28 12:17:41 +02:00
|
|
|
assertSame(buf, buf.readerIndex(7));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertSame(buf, buf.readerIndex(8));
|
2020-08-28 12:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void capacityMustBeAllocatedSize() {
|
|
|
|
assertEquals(8, buf.capacity());
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf b = allocate(13)) {
|
2020-08-28 12:17:41 +02:00
|
|
|
assertEquals(13, b.capacity());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
|
|
|
public void fill() {
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf buf = allocate(16)) {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertSame(buf, buf.fill((byte) 0xA5));
|
|
|
|
buf.writerIndex(16);
|
|
|
|
assertEquals(0xA5A5A5A5_A5A5A5A5L, buf.readLong());
|
|
|
|
assertEquals(0xA5A5A5A5_A5A5A5A5L, buf.readLong());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 12:17:41 +02:00
|
|
|
@Test
|
|
|
|
public void readerWriterIndexUpdates() {
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf buf = allocate(22)) {
|
2020-08-28 12:17:41 +02:00
|
|
|
assertEquals(0, buf.writerIndex());
|
|
|
|
assertSame(buf, buf.writerIndex(1));
|
|
|
|
assertEquals(1, buf.writerIndex());
|
|
|
|
assertSame(buf, buf.writeByte((byte) 7));
|
|
|
|
assertEquals(2, buf.writerIndex());
|
|
|
|
assertSame(buf, buf.writeShort((short) 3003));
|
|
|
|
assertEquals(4, buf.writerIndex());
|
|
|
|
assertSame(buf, buf.writeInt(0x5A55_BA55));
|
|
|
|
assertEquals(8, buf.writerIndex());
|
|
|
|
assertSame(buf, buf.writeLong(0x123456789ABCDEF0L));
|
|
|
|
assertEquals(16, buf.writerIndex());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(6, buf.writableBytes());
|
2020-08-28 12:17:41 +02:00
|
|
|
assertEquals(16, buf.readableBytes());
|
|
|
|
|
|
|
|
assertEquals(0, buf.readerIndex());
|
|
|
|
assertSame(buf, buf.readerIndex(1));
|
|
|
|
assertEquals(1, buf.readerIndex());
|
|
|
|
assertEquals((byte) 7, buf.readByte());
|
|
|
|
assertEquals(2, buf.readerIndex());
|
|
|
|
assertEquals((short) 3003, buf.readShort());
|
|
|
|
assertEquals(4, buf.readerIndex());
|
|
|
|
assertEquals(0x5A55_BA55, buf.readInt());
|
|
|
|
assertEquals(8, buf.readerIndex());
|
|
|
|
assertEquals(0x123456789ABCDEF0L, buf.readLong());
|
|
|
|
assertEquals(16, buf.readerIndex());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
public void readAndWriteBoundsChecksWithIndexUpdates() {
|
2020-10-14 15:59:10 +02:00
|
|
|
try (Buf buf = allocate(8)) {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeLong(0);
|
|
|
|
|
|
|
|
buf.readLong(); // Fine.
|
|
|
|
buf.readerIndex(1);
|
|
|
|
try {
|
|
|
|
buf.readLong();
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.readerIndex(4);
|
|
|
|
buf.readInt(); // Fine.
|
|
|
|
buf.readerIndex(5);
|
|
|
|
|
|
|
|
try {
|
|
|
|
buf.readInt();
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-08-28 12:17:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 14:39:50 +01:00
|
|
|
@Test
|
|
|
|
public void resetMustSetReaderAndWriterOffsetsToTheirInitialPositions() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.writeInt(0).readShort();
|
|
|
|
buf.reset();
|
|
|
|
assertEquals(0, buf.readerIndex());
|
|
|
|
assertEquals(0, buf.writerIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-15 16:20:26 +02:00
|
|
|
@Test
|
|
|
|
public void sliceWithoutOffsetAndSizeMustReturnReadableRegion() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
for (byte b : new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }) {
|
|
|
|
buf.writeByte(b);
|
|
|
|
}
|
|
|
|
assertEquals(0x01, buf.readByte());
|
|
|
|
buf.writerIndex(buf.writerIndex() - 1);
|
|
|
|
try (Buf slice = buf.slice()) {
|
|
|
|
assertArrayEquals(new byte[] {0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, slice.copy());
|
|
|
|
assertEquals(0, slice.readerIndex());
|
|
|
|
assertEquals(6, slice.readableBytes());
|
|
|
|
assertEquals(6, slice.writerIndex());
|
|
|
|
assertEquals(6, slice.capacity());
|
|
|
|
assertEquals(0x02, slice.readByte());
|
|
|
|
assertEquals(0x03, slice.readByte());
|
|
|
|
assertEquals(0x04, slice.readByte());
|
|
|
|
assertEquals(0x05, slice.readByte());
|
|
|
|
assertEquals(0x06, slice.readByte());
|
|
|
|
assertEquals(0x07, slice.readByte());
|
|
|
|
try {
|
|
|
|
slice.readByte();
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithOffsetAndSizeMustReturnGivenRegion() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
for (byte b : new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }) {
|
|
|
|
buf.writeByte(b);
|
|
|
|
}
|
|
|
|
buf.readerIndex(3); // Reader and writer offsets must be ignored.
|
|
|
|
buf.writerIndex(6);
|
|
|
|
try (Buf slice = buf.slice(1, 6)) {
|
|
|
|
assertArrayEquals(new byte[] {0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, slice.copy());
|
|
|
|
assertEquals(0, slice.readerIndex());
|
|
|
|
assertEquals(6, slice.readableBytes());
|
|
|
|
assertEquals(6, slice.writerIndex());
|
|
|
|
assertEquals(6, slice.capacity());
|
|
|
|
assertEquals(0x02, slice.readByte());
|
|
|
|
assertEquals(0x03, slice.readByte());
|
|
|
|
assertEquals(0x04, slice.readByte());
|
|
|
|
assertEquals(0x05, slice.readByte());
|
|
|
|
assertEquals(0x06, slice.readByte());
|
|
|
|
assertEquals(0x07, slice.readByte());
|
|
|
|
try {
|
|
|
|
slice.readByte();
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithoutOffsetAndSizeWillIncreaseReferenceCount() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.slice()) {
|
2020-10-30 14:21:20 +01:00
|
|
|
assertFalse(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
buf.send();
|
|
|
|
fail("Should have refused send() of acquired buffer.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithOffsetAndSizeWillIncreaseReferenceCount() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.slice(0, 8)) {
|
2020-10-30 14:21:20 +01:00
|
|
|
assertFalse(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
buf.send();
|
|
|
|
fail("Should have refused send() of acquired buffer.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithoutOffsetAndSizeHasSameEndianAsParent() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
buf.writeLong(0x0102030405060708L);
|
|
|
|
try (Buf slice = buf.slice()) {
|
|
|
|
assertEquals(0x0102030405060708L, slice.readLong());
|
|
|
|
}
|
|
|
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
|
|
|
try (Buf slice = buf.slice()) {
|
|
|
|
assertEquals(0x0807060504030201L, slice.readLong());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithOffsetAndSizeHasSameEndianAsParent() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
buf.writeLong(0x0102030405060708L);
|
|
|
|
try (Buf slice = buf.slice(0, 8)) {
|
|
|
|
assertEquals(0x0102030405060708L, slice.readLong());
|
|
|
|
}
|
|
|
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
|
|
|
try (Buf slice = buf.slice(0, 8)) {
|
|
|
|
assertEquals(0x0807060504030201L, slice.readLong());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sendOnSliceWithoutOffsetAndSizeMustThrow() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf slice = buf.slice()) {
|
2020-10-30 14:21:20 +01:00
|
|
|
assertFalse(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
slice.send();
|
|
|
|
fail("Should not be able to send a slice.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
// Verify that the slice is closed properly afterwards.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
buf.send().receive().close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sendOnSliceWithOffsetAndSizeMustThrow() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf slice = buf.slice(0, 8)) {
|
2020-10-30 14:21:20 +01:00
|
|
|
assertFalse(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
slice.send();
|
|
|
|
fail("Should not be able to send a slice.");
|
|
|
|
} catch (IllegalStateException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
// Verify that the slice is closed properly afterwards.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithNegativeOffsetMustThrow() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.slice(-1, 1)) {
|
|
|
|
fail("Should not allow negative offsets to slice().");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
// Verify that the slice is closed properly afterwards.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithNegativeSizeMustThrow() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.slice(0, -1)) {
|
|
|
|
fail("Should not allow negative size to slice().");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
// Verify that the slice is closed properly afterwards.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void sliceWithSizeGreaterThanCapacityMustThrow() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
try (Buf ignored = buf.slice(0, 9)) {
|
|
|
|
fail("Should not allow slice() size greater than parent capacity.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.slice(0, 8).close(); // This is still fine.
|
|
|
|
try (Buf ignored = buf.slice(1, 8)) {
|
|
|
|
fail("Should not allow slice() size greater than parent capacity.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
// Verify that the slice is closed properly afterwards.
|
2020-10-30 14:21:20 +01:00
|
|
|
assertTrue(buf.isSendable());
|
2020-10-15 16:20:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 14:39:50 +01:00
|
|
|
@Test
|
|
|
|
public void copyIntoByteArray() {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
byte[] array = new byte[8];
|
|
|
|
buf.copyInto(0, array, 0, array.length);
|
|
|
|
assertArrayEquals(new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, array);
|
|
|
|
|
|
|
|
buf.writerIndex(0).order(ByteOrder.LITTLE_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
buf.copyInto(0, array, 0, array.length);
|
|
|
|
assertArrayEquals(new byte[]{0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}, array);
|
|
|
|
|
|
|
|
array = new byte[6];
|
|
|
|
buf.copyInto(1, array, 1, 3);
|
|
|
|
assertArrayEquals(new byte[] {0x00, 0x07, 0x06, 0x05, 0x00, 0x00}, array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoHeapByteBuffer() {
|
|
|
|
testCopyIntoByteBuffer(ByteBuffer::allocate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoDirectByteBuffer() {
|
|
|
|
testCopyIntoByteBuffer(ByteBuffer::allocateDirect);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testCopyIntoByteBuffer(Function<Integer, ByteBuffer> bbAlloc) {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
ByteBuffer buffer = bbAlloc.apply(8);
|
|
|
|
buf.copyInto(0, buffer, 0, buffer.capacity());
|
|
|
|
assertEquals((byte) 0x01, buffer.get());
|
|
|
|
assertEquals((byte) 0x02, buffer.get());
|
|
|
|
assertEquals((byte) 0x03, buffer.get());
|
|
|
|
assertEquals((byte) 0x04, buffer.get());
|
|
|
|
assertEquals((byte) 0x05, buffer.get());
|
|
|
|
assertEquals((byte) 0x06, buffer.get());
|
|
|
|
assertEquals((byte) 0x07, buffer.get());
|
|
|
|
assertEquals((byte) 0x08, buffer.get());
|
|
|
|
buffer.clear();
|
|
|
|
|
|
|
|
buf.writerIndex(0).order(ByteOrder.LITTLE_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
buf.copyInto(0, buffer, 0, buffer.capacity());
|
|
|
|
assertEquals((byte) 0x08, buffer.get());
|
|
|
|
assertEquals((byte) 0x07, buffer.get());
|
|
|
|
assertEquals((byte) 0x06, buffer.get());
|
|
|
|
assertEquals((byte) 0x05, buffer.get());
|
|
|
|
assertEquals((byte) 0x04, buffer.get());
|
|
|
|
assertEquals((byte) 0x03, buffer.get());
|
|
|
|
assertEquals((byte) 0x02, buffer.get());
|
|
|
|
assertEquals((byte) 0x01, buffer.get());
|
|
|
|
buffer.clear();
|
|
|
|
|
|
|
|
buffer = bbAlloc.apply(6);
|
|
|
|
buf.copyInto(1, buffer, 1, 3);
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
assertEquals((byte) 0x07, buffer.get());
|
|
|
|
assertEquals((byte) 0x06, buffer.get());
|
|
|
|
assertEquals((byte) 0x05, buffer.get());
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
buffer.clear();
|
|
|
|
|
|
|
|
buffer = bbAlloc.apply(6);
|
|
|
|
buffer.position(3).limit(3);
|
|
|
|
buf.copyInto(1, buffer, 1, 3);
|
|
|
|
assertEquals(3, buffer.position());
|
|
|
|
assertEquals(3, buffer.limit());
|
|
|
|
buffer.clear();
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
assertEquals((byte) 0x07, buffer.get());
|
|
|
|
assertEquals((byte) 0x06, buffer.get());
|
|
|
|
assertEquals((byte) 0x05, buffer.get());
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
assertEquals((byte) 0x00, buffer.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoOnHeapBuf() {
|
|
|
|
testCopyIntoBuf(Allocator.heap()::allocate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoOffHeapBuf() {
|
|
|
|
testCopyIntoBuf(Allocator.direct()::allocate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoOnHeapBufSlice() {
|
|
|
|
try (Scope scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> scope.add(Allocator.heap().allocate(size)).writerIndex(size).slice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoOffHeapBufSlice() {
|
|
|
|
try (Scope scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> scope.add(Allocator.direct().allocate(size)).writerIndex(size).slice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOnHeapOnHeapBuf() {
|
|
|
|
try (var a = Allocator.heap();
|
|
|
|
var b = Allocator.heap()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return Buf.compose(bufFirst, bufSecond);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOnHeapOffHeapBuf() {
|
|
|
|
try (var a = Allocator.heap();
|
|
|
|
var b = Allocator.direct()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return Buf.compose(bufFirst, bufSecond);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOffHeapOnHeapBuf() {
|
|
|
|
try (var a = Allocator.direct();
|
|
|
|
var b = Allocator.heap()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return Buf.compose(bufFirst, bufSecond);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOffHeapOffHeapBuf() {
|
|
|
|
try (var a = Allocator.direct();
|
|
|
|
var b = Allocator.direct()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return Buf.compose(bufFirst, bufSecond);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOnHeapOnHeapBufSlice() {
|
|
|
|
try (var a = Allocator.heap();
|
|
|
|
var b = Allocator.heap();
|
|
|
|
var scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return scope.add(Buf.compose(bufFirst, bufSecond)).writerIndex(size).slice();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOnHeapOffHeapBufSlice() {
|
|
|
|
try (var a = Allocator.heap();
|
|
|
|
var b = Allocator.direct();
|
|
|
|
var scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return scope.add(Buf.compose(bufFirst, bufSecond)).writerIndex(size).slice();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOffHeapOnHeapBufSlice() {
|
|
|
|
try (var a = Allocator.direct();
|
|
|
|
var b = Allocator.heap();
|
|
|
|
var scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return scope.add(Buf.compose(bufFirst, bufSecond)).writerIndex(size).slice();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void copyIntoCompositeOffHeapOffHeapBufSlice() {
|
|
|
|
try (var a = Allocator.direct();
|
|
|
|
var b = Allocator.direct();
|
|
|
|
var scope = new Scope()) {
|
|
|
|
testCopyIntoBuf(size -> {
|
|
|
|
int first = size / 2;
|
|
|
|
int second = size - first;
|
|
|
|
try (var bufFirst = a.allocate(first);
|
|
|
|
var bufSecond = b.allocate(second)) {
|
|
|
|
return scope.add(Buf.compose(bufFirst, bufSecond)).writerIndex(size).slice();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testCopyIntoBuf(Function<Integer, Buf> bbAlloc) {
|
|
|
|
try (Buf buf = allocate(8)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
Buf buffer = bbAlloc.apply(8);
|
|
|
|
buffer.writerIndex(8);
|
|
|
|
buf.copyInto(0, buffer, 0, buffer.capacity());
|
|
|
|
assertEquals((byte) 0x01, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x02, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x03, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x04, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x05, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x06, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x07, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x08, buffer.readByte());
|
|
|
|
buffer.reset();
|
|
|
|
|
|
|
|
buf.writerIndex(0).order(ByteOrder.LITTLE_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
buf.copyInto(0, buffer, 0, buffer.capacity());
|
|
|
|
buffer.writerIndex(8);
|
|
|
|
assertEquals((byte) 0x08, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x07, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x06, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x05, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x04, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x03, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x02, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x01, buffer.readByte());
|
|
|
|
buffer.reset();
|
|
|
|
|
|
|
|
buffer.close();
|
|
|
|
buffer = bbAlloc.apply(6);
|
|
|
|
buf.copyInto(1, buffer, 1, 3);
|
|
|
|
buffer.writerIndex(6);
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x07, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x06, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x05, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
|
|
|
|
buffer.close();
|
|
|
|
buffer = bbAlloc.apply(6);
|
|
|
|
buffer.writerIndex(3).readerIndex(3);
|
|
|
|
buf.copyInto(1, buffer, 1, 3);
|
|
|
|
assertEquals(3, buffer.readerIndex());
|
|
|
|
assertEquals(3, buffer.writerIndex());
|
|
|
|
buffer.reset();
|
|
|
|
buffer.writerIndex(6);
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x07, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x06, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x05, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
assertEquals((byte) 0x00, buffer.readByte());
|
|
|
|
buffer.close();
|
|
|
|
|
|
|
|
buf.reset();
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN).writeLong(0x0102030405060708L);
|
|
|
|
// Testing copyInto for overlapping writes:
|
|
|
|
//
|
|
|
|
// 0x0102030405060708
|
|
|
|
// └──┬──┬──┘ │
|
|
|
|
// └─▶└┬───────┘
|
|
|
|
// â–¼
|
|
|
|
// 0x0102030102030405
|
|
|
|
buf.copyInto(0, buf, 3, 5);
|
|
|
|
assertArrayEquals(new byte[] {0x01, 0x02, 0x03, 0x01, 0x02, 0x03, 0x04, 0x05}, buf.copy());
|
|
|
|
}
|
|
|
|
}
|
2020-11-05 15:15:34 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void readableBytesMustMatchWhatWasWritten() {
|
|
|
|
try (Buf buf = allocate(16)) {
|
|
|
|
buf.writeLong(0);
|
|
|
|
assertEquals(Long.BYTES, buf.readableBytes());
|
|
|
|
buf.readShort();
|
|
|
|
assertEquals(Long.BYTES - Short.BYTES, buf.readableBytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void byteIterationOfBigEndianBuffers() {
|
|
|
|
try (Buf buf = allocate(0x28)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN); // The byte order should have no impact.
|
|
|
|
checkByteIteration(buf);
|
|
|
|
buf.reset();
|
|
|
|
checkByteIterationOfRegion(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void byteIterationOfLittleEndianBuffers() {
|
|
|
|
try (Buf buf = allocate(0x28)) {
|
|
|
|
buf.order(ByteOrder.LITTLE_ENDIAN); // The byte order should have no impact.
|
|
|
|
checkByteIteration(buf);
|
|
|
|
buf.reset();
|
|
|
|
checkByteIterationOfRegion(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkByteIteration(Buf buf) {
|
|
|
|
var itr = buf.iterate();
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 0x27; i++) {
|
|
|
|
buf.writeByte((byte) (i + 1));
|
|
|
|
}
|
|
|
|
int roff = buf.readerIndex();
|
|
|
|
int woff = buf.writerIndex();
|
|
|
|
itr = buf.iterate();
|
|
|
|
assertEquals(0x27, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0102030405060708L, itr.nextLong());
|
|
|
|
assertEquals(0x1F, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x090A0B0C0D0E0F10L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x17, itr.bytesLeft());
|
|
|
|
assertEquals(0x1112131415161718L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0F, itr.bytesLeft());
|
|
|
|
assertEquals(0x191A1B1C1D1E1F20L, itr.nextLong());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(7, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals((byte) 0x21, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(6, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x22, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(5, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x23, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(4, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x24, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(3, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x25, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x26, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x27, itr.nextByte());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(roff, buf.readerIndex());
|
|
|
|
assertEquals(woff, buf.writerIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkByteIterationOfRegion(Buf buf) {
|
2020-11-06 13:39:21 +01:00
|
|
|
try {
|
|
|
|
buf.iterate(-1, 1);
|
|
|
|
fail("Should throw on negative offset.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterate(1, -1);
|
|
|
|
fail("Should throw on negative length.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterate(buf.capacity(), 1);
|
|
|
|
fail("Should throw on offset overflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterate(buf.capacity() - 1, 2);
|
|
|
|
fail("Should throw on offset + length overflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterate(buf.capacity() - 2, 3);
|
|
|
|
fail("Should throw on offset + length overflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
2020-11-05 15:15:34 +01:00
|
|
|
var itr = buf.iterate(1, 0);
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 0x27; i++) {
|
|
|
|
buf.writeByte((byte) (i + 1));
|
|
|
|
}
|
|
|
|
int roff = buf.readerIndex();
|
|
|
|
int woff = buf.writerIndex();
|
|
|
|
itr = buf.iterate(buf.readerIndex() + 1, buf.readableBytes() - 2);
|
|
|
|
assertEquals(0x25, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0203040506070809L, itr.nextLong());
|
|
|
|
assertEquals(0x1D, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0A0B0C0D0E0F1011L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x15, itr.bytesLeft());
|
|
|
|
assertEquals(0x1213141516171819L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0D, itr.bytesLeft());
|
|
|
|
assertEquals(0x1A1B1C1D1E1F2021L, itr.nextLong());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(5, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals((byte) 0x22, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(4, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x23, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(3, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x24, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x25, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x26, itr.nextByte());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
itr = buf.iterate(buf.readerIndex() + 1, 2);
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals((byte) 0x02, itr.nextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals((byte) 0x03, itr.nextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(roff, buf.readerIndex());
|
|
|
|
assertEquals(woff, buf.writerIndex());
|
|
|
|
}
|
2020-11-06 13:39:21 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void reverseByteIterationOfBigEndianBuffers() {
|
|
|
|
try (Buf buf = allocate(0x28)) {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN); // The byte order should have no impact.
|
|
|
|
checkReverseByteIteration(buf);
|
|
|
|
buf.reset();
|
|
|
|
checkReverseByteIterationOfRegion(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void reverseByteIterationOfLittleEndianBuffers() {
|
|
|
|
try (Buf buf = allocate(0x28)) {
|
|
|
|
buf.order(ByteOrder.LITTLE_ENDIAN); // The byte order should have no impact.
|
|
|
|
checkReverseByteIteration(buf);
|
|
|
|
buf.reset();
|
|
|
|
checkReverseByteIterationOfRegion(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkReverseByteIteration(Buf buf) {
|
|
|
|
var itr = buf.iterateReverse();
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 0x27; i++) {
|
|
|
|
buf.writeByte((byte) (i + 1));
|
|
|
|
}
|
|
|
|
int roff = buf.readerIndex();
|
|
|
|
int woff = buf.writerIndex();
|
|
|
|
itr = buf.iterateReverse();
|
|
|
|
assertEquals(0x27, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x2726252423222120L, itr.nextLong());
|
|
|
|
assertEquals(0x1F, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x1F1E1D1C1B1A1918L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x17, itr.bytesLeft());
|
|
|
|
assertEquals(0x1716151413121110L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0F, itr.bytesLeft());
|
|
|
|
assertEquals(0x0F0E0D0C0B0A0908L, itr.nextLong());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(7, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals((byte) 0x07, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(6, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x06, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(5, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x05, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(4, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x04, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(3, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x03, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x02, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x01, itr.nextByte());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(roff, buf.readerIndex());
|
|
|
|
assertEquals(woff, buf.writerIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkReverseByteIterationOfRegion(Buf buf) {
|
|
|
|
try {
|
|
|
|
buf.iterateReverse(-1, 0);
|
|
|
|
fail("Should throw on negative offset.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterateReverse(0, -1);
|
|
|
|
fail("Should throw on negative length.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterateReverse(0, 2);
|
|
|
|
fail("Should throw on offset + length underflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterateReverse(1, 3);
|
|
|
|
fail("Should throw on offset + length underflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
buf.iterateReverse(buf.capacity(), 0);
|
|
|
|
fail("Should throw on offset overflow.");
|
|
|
|
} catch (IllegalArgumentException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
var itr = buf.iterateReverse(1, 0);
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 0x27; i++) {
|
|
|
|
buf.writeByte((byte) (i + 1));
|
|
|
|
}
|
|
|
|
int roff = buf.readerIndex();
|
|
|
|
int woff = buf.writerIndex();
|
|
|
|
itr = buf.iterateReverse(buf.writerIndex() - 2, buf.readableBytes() - 2);
|
|
|
|
assertEquals(0x25, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x262524232221201FL, itr.nextLong());
|
|
|
|
assertEquals(0x1D, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x1E1D1C1B1A191817L, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x15, itr.bytesLeft());
|
|
|
|
assertEquals(0x161514131211100FL, itr.nextLong());
|
|
|
|
assertTrue(itr.hasNextLong());
|
|
|
|
assertEquals(0x0D, itr.bytesLeft());
|
|
|
|
assertEquals(0x0E0D0C0B0A090807L, itr.nextLong());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(5, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals((byte) 0x06, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(4, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x05, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(3, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x04, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x03, itr.nextByte());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertEquals((byte) 0x02, itr.nextByte());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
try {
|
|
|
|
itr.nextLong();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
itr.nextByte();
|
|
|
|
fail("Expected a no such element exception.");
|
|
|
|
} catch (NoSuchElementException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
|
|
|
|
itr = buf.iterateReverse(buf.readerIndex() + 2, 2);
|
|
|
|
assertEquals(2, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals((byte) 0x03, itr.nextByte());
|
|
|
|
assertEquals(1, itr.bytesLeft());
|
|
|
|
assertTrue(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals((byte) 0x02, itr.nextByte());
|
|
|
|
assertEquals(0, itr.bytesLeft());
|
|
|
|
assertFalse(itr.hasNextByte());
|
|
|
|
assertFalse(itr.hasNextLong());
|
|
|
|
assertEquals(roff, buf.readerIndex());
|
|
|
|
assertEquals(woff, buf.writerIndex());
|
|
|
|
}
|
2020-11-05 15:15:34 +01:00
|
|
|
|
2020-10-30 14:39:50 +01:00
|
|
|
// todo resize copying must preserve contents
|
|
|
|
// todo resize sharing
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
// ### CODEGEN START primitive accessors tests
|
Make cleaner in pooledDirectWithCleaner return segments to pool instead of deallocating
Motivation:
Allocating memory is expensive, which is why we pool our allocations.
The cleaner, when used with pooled memory, should then return that memory to the pool instead of deallocating it.
The purpose of the cleaner is, after all, to avoid having to track the reference counts so precisely.
Modification:
The NativeMemoryCleanerDrop is now able to either recover lost memory segments, when a buffer wasn't closed explicitly
and is being cleaned by the GC, or return the buffer to the pool via ordinary drop.
The GatedCleanable has been added, because buffer ownership transfer involves generating new memory segments,
and in those cases we need to invalidate the old cleanables without deallocating the tracked memory segment or returning
it to the pool more than once.
Result:
The pooledDirectWithCleaner allocator is now able to reuse memory segments, even when their references are forgotten and
they processed by the cleaner thread.
2020-09-25 12:15:45 +02:00
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated primitive accessors tests.">
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
|
2020-08-28 12:17:41 +02:00
|
|
|
@Test
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
public void relativeReadOfByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readByte());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void relativeReadOfByteMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
assertEquals(0x10, buf.readByte());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfByteMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
try {
|
|
|
|
buf.readByte();
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfByteMustBoundsCheckOnNegativeOffset() {
|
|
|
|
try {
|
|
|
|
buf.readByte(-1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
assertEquals(value, buf.readByte(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void offsettedReadOfByteMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(0x10, buf.readByte(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
try {
|
|
|
|
buf.readByte(1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
|
|
|
try {
|
|
|
|
buf.readByte(0);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfUnsignedByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readUnsignedByte());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void relativeReadOfUnsignedByteMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
assertEquals(0x10, buf.readUnsignedByte());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(7, buf.writableBytes());
|
|
|
|
try {
|
|
|
|
buf.readUnsignedByte();
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfUnsignedByteMustBoundsCheckOnNegativeOffset() {
|
|
|
|
try {
|
|
|
|
buf.readUnsignedByte(-1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfUnsignedByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
assertEquals(value, buf.readUnsignedByte(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void offsettedReadOfUnsignedByteMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(0x10, buf.readUnsignedByte(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
try {
|
|
|
|
buf.readUnsignedByte(1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfUnsignedByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
|
|
|
try {
|
|
|
|
buf.readUnsignedByte(0);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeWriteOfByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(8);
|
|
|
|
try {
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void relativeWriteOfByteMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfByteMustBoundsCheckWhenWriteOffsetIsNegative() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(-1, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(8, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void offsettedWriteOfByteMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
byte value = 0x01;
|
|
|
|
buf.writeByte(0, value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeWriteOfUnsignedByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(8);
|
|
|
|
try {
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void relativeWriteOfUnsignedByteMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfUnsignedByteMustBoundsCheckWhenWriteOffsetIsNegative() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(-1, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfUnsignedByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(8, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void offsettedWriteOfUnsignedByteMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
int value = 0x01;
|
|
|
|
buf.writeUnsignedByte(0, value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfCharMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readChar());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void relativeReadOfCharMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
|
|
|
assertEquals(0x1002, buf.readChar());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfCharMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
|
|
|
try {
|
|
|
|
buf.readChar();
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfCharMustBoundsCheckOnNegativeOffset() {
|
|
|
|
try {
|
|
|
|
buf.readChar(-1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfCharMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
assertEquals(value, buf.readChar(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-06 16:30:49 +02:00
|
|
|
public void offsettedReadOfCharMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(0x1002, buf.readChar(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfCharMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
try {
|
|
|
|
buf.readChar(1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfCharMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
|
|
|
try {
|
|
|
|
buf.readChar(0);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfCharMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(7);
|
|
|
|
try {
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeWriteOfCharMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfCharMustBoundsCheckWhenWriteOffsetIsNegative() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(-1, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfCharMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(7, value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfCharMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
char value = 0x0102;
|
|
|
|
buf.writeChar(0, value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(value, buf.readShort());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfShortMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x1002, buf.readShort());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfShortMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readShort();
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfShortMustBoundsCheckOnNegativeOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readShort(-1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
|
|
|
assertEquals(value, buf.readShort(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfShortMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(0x1002, buf.readShort(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readShort(1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readShort(0);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:30:49 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(value, buf.readUnsignedShort());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedShortMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x1002, buf.readUnsignedShort());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
assertEquals(6, buf.writableBytes());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedShort();
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(1, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedShortMustBoundsCheckOnNegativeOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedShort(-1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
|
|
|
assertEquals(value, buf.readUnsignedShort(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedShortMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x1002, buf.readUnsignedShort(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedShort(1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedShort(0);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(7);
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfShortMustHaveDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfShortMustBoundsCheckWhenWriteOffsetIsNegative() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(-1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
2020-08-24 16:03:02 +02:00
|
|
|
}
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
2020-08-24 16:03:02 +02:00
|
|
|
}
|
2020-07-24 19:38:48 +02:00
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(7, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfShortMustHaveDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
short value = 0x0102;
|
|
|
|
buf.writeShort(0, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(7);
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedShortMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedShortMustBoundsCheckWhenWriteOffsetIsNegative() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(-1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(7, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedShortMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x0102;
|
|
|
|
buf.writeUnsignedShort(0, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:30:49 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(5, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readMedium());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfMediumMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(5, buf.writableBytes());
|
|
|
|
assertEquals(0x100203, buf.readMedium());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void relativeReadOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(5, buf.writableBytes());
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readMedium();
|
|
|
|
fail("Expected a bounds check.");
|
2020-10-06 16:30:49 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfMediumMustBoundsCheckOnNegativeOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readMedium(-1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
|
|
|
assertEquals(value, buf.readMedium(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfMediumMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x100203, buf.readMedium(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readMedium(1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readMedium(0);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(5, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readUnsignedMedium());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedMediumMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(5, buf.writableBytes());
|
|
|
|
assertEquals(0x100203, buf.readUnsignedMedium());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.readerIndex(1);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
|
|
|
assertEquals(5, buf.writableBytes());
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedMedium();
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(2, buf.readableBytes());
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedMediumMustBoundsCheckOnNegativeOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedMedium(-1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
|
|
|
assertEquals(value, buf.readUnsignedMedium(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedMediumMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x100203, buf.readUnsignedMedium(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedMedium(1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedMedium(0);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(6);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfMediumMustHaveDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfMediumMustBoundsCheckWhenWriteOffsetIsNegative() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(-1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(6, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfMediumMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeMedium(0, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:30:49 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(6);
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedMediumMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedMediumMustBoundsCheckWhenWriteOffsetIsNegative() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(-1, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(6, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedMediumMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x010203;
|
|
|
|
buf.writeUnsignedMedium(0, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readInt());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfIntMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(0x10020304, buf.readInt());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfIntMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.readerIndex(1);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readInt();
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfIntMustBoundsCheckOnNegativeOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readInt(-1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
|
|
|
assertEquals(value, buf.readInt(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfIntMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x10020304, buf.readInt(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readInt(1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readInt(0);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readUnsignedInt());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedIntMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(0x10020304, buf.readUnsignedInt());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.readerIndex(1);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedInt();
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedIntMustBoundsCheckOnNegativeOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedInt(-1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
|
|
|
assertEquals(value, buf.readUnsignedInt(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedIntMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(0x10020304, buf.readUnsignedInt(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedInt(1);
|
|
|
|
fail("Expected a bounds check.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfUnsignedIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readUnsignedInt(0);
|
|
|
|
fail("Expected a bounds check.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(5);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfIntMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfIntMustBoundsCheckWhenWriteOffsetIsNegative() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(-1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(5, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfIntMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int value = 0x01020304;
|
|
|
|
buf.writeInt(0, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-06 16:30:49 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(5);
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfUnsignedIntMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedIntMustBoundsCheckWhenWriteOffsetIsNegative() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(-1, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(5, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfUnsignedIntMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
long value = 0x01020304;
|
|
|
|
buf.writeUnsignedInt(0, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfFloatMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readFloat());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfFloatMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(4, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
|
|
|
assertEquals(Float.intBitsToFloat(0x10020304), buf.readFloat());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.readerIndex(1);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
|
|
|
assertEquals(4, buf.writableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readFloat();
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(3, buf.readableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfFloatMustBoundsCheckOnNegativeOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readFloat(-1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfFloatMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
|
|
|
assertEquals(value, buf.readFloat(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfFloatMustReadWithDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(Float.intBitsToFloat(0x10020304), buf.readFloat(0));
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readFloat(1);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfFloatMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readFloat(0);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfFloatMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(5);
|
|
|
|
try {
|
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfFloatMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfFloatMustBoundsCheckWhenWriteOffsetIsNegative() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(-1, value);
|
|
|
|
fail("Should have bounds checked.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfFloatMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(5, value);
|
|
|
|
fail("Should have bounds checked.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedWriteOfFloatMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
float value = Float.intBitsToFloat(0x01020304);
|
|
|
|
buf.writeFloat(0, value);
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
|
|
|
assertEquals((byte) 0x00, buf.readByte());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-06 16:30:49 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfLongMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(8, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(value, buf.readLong());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfLongMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(8, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x1002030405060708L, buf.readLong());
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfLongMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(7, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readLong();
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
assertEquals(7, buf.readableBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfLongMustBoundsCheckOnNegativeOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readLong(-1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfLongMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
|
|
|
assertEquals(value, buf.readLong(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfLongMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writeByte(0, (byte) 0x10);
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(0x1002030405060708L, buf.readLong(0));
|
2020-10-06 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfLongMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readLong(1);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfLongMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
2020-10-06 16:30:49 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readLong(0);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfLongMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(1);
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfLongMustHaveDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x05, buf.readByte());
|
|
|
|
assertEquals((byte) 0x06, buf.readByte());
|
|
|
|
assertEquals((byte) 0x07, buf.readByte());
|
|
|
|
assertEquals((byte) 0x08, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfLongMustBoundsCheckWhenWriteOffsetIsNegative() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(-1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfLongMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(1, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfLongMustHaveDefaultEndianByteOrder() {
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-12 16:26:22 +02:00
|
|
|
long value = 0x0102030405060708L;
|
|
|
|
buf.writeLong(0, value);
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x05, buf.readByte());
|
|
|
|
assertEquals((byte) 0x06, buf.readByte());
|
|
|
|
assertEquals((byte) 0x07, buf.readByte());
|
|
|
|
assertEquals((byte) 0x08, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfDoubleMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
|
|
|
buf.writeDouble(value);
|
|
|
|
assertEquals(8, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
|
|
|
assertEquals(value, buf.readDouble());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfDoubleMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(8, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
|
|
|
assertEquals(Double.longBitsToDouble(0x1002030405060708L), buf.readDouble());
|
|
|
|
assertEquals(0, buf.readableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeReadOfDoubleMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset() {
|
|
|
|
assertEquals(0, buf.readableBytes());
|
|
|
|
assertEquals(Long.BYTES, buf.writableBytes());
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
|
|
|
buf.writeDouble(value);
|
|
|
|
buf.readerIndex(1);
|
|
|
|
assertEquals(7, buf.readableBytes());
|
|
|
|
assertEquals(0, buf.writableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readDouble();
|
|
|
|
fail("Expected a bounds check.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
2020-10-12 16:26:22 +02:00
|
|
|
assertEquals(7, buf.readableBytes());
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfDoubleMustBoundsCheckOnNegativeOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
try {
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.readDouble(-1);
|
|
|
|
fail("Expected a bounds check.");
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedReadOfDoubleMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset() {
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(value);
|
|
|
|
assertEquals(value, buf.readDouble(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfDoubleMustReadWithDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
|
|
|
buf.writeDouble(value);
|
|
|
|
buf.writeByte(0, (byte) 0x10);
|
|
|
|
assertEquals(Double.longBitsToDouble(0x1002030405060708L), buf.readDouble(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfDoubleMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset() {
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
|
|
|
buf.writeDouble(value);
|
|
|
|
try {
|
|
|
|
buf.readDouble(1);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void offsettedReadOfDoubleMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset() {
|
|
|
|
try {
|
|
|
|
buf.readDouble(0);
|
|
|
|
fail("Expected a bounds check.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
}
|
2020-10-06 16:30:49 +02:00
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfDoubleMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
buf.writerIndex(1);
|
|
|
|
try {
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void relativeWriteOfDoubleMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-06 16:30:49 +02:00
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x05, buf.readByte());
|
|
|
|
assertEquals((byte) 0x06, buf.readByte());
|
|
|
|
assertEquals((byte) 0x07, buf.readByte());
|
|
|
|
assertEquals((byte) 0x08, buf.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfDoubleMustBoundsCheckWhenWriteOffsetIsNegative() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(-1, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfDoubleMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity() {
|
2020-10-06 16:30:49 +02:00
|
|
|
assertEquals(Long.BYTES, buf.capacity());
|
|
|
|
try {
|
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(1, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
fail("Should have bounds checked.");
|
|
|
|
} catch (IndexOutOfBoundsException ignore) {
|
|
|
|
// Good.
|
|
|
|
}
|
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
// Verify contents are unchanged.
|
|
|
|
assertEquals(0, buf.readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-12 16:26:22 +02:00
|
|
|
public void offsettedWriteOfDoubleMustHaveDefaultEndianByteOrder() {
|
|
|
|
buf.order(ByteOrder.BIG_ENDIAN);
|
2020-10-06 16:30:49 +02:00
|
|
|
double value = Double.longBitsToDouble(0x0102030405060708L);
|
2020-10-12 16:26:22 +02:00
|
|
|
buf.writeDouble(0, value);
|
2020-10-06 16:30:49 +02:00
|
|
|
buf.writerIndex(Long.BYTES);
|
|
|
|
assertEquals((byte) 0x01, buf.readByte());
|
|
|
|
assertEquals((byte) 0x02, buf.readByte());
|
|
|
|
assertEquals((byte) 0x03, buf.readByte());
|
|
|
|
assertEquals((byte) 0x04, buf.readByte());
|
|
|
|
assertEquals((byte) 0x05, buf.readByte());
|
|
|
|
assertEquals((byte) 0x06, buf.readByte());
|
|
|
|
assertEquals((byte) 0x07, buf.readByte());
|
|
|
|
assertEquals((byte) 0x08, buf.readByte());
|
|
|
|
}
|
Make cleaner in pooledDirectWithCleaner return segments to pool instead of deallocating
Motivation:
Allocating memory is expensive, which is why we pool our allocations.
The cleaner, when used with pooled memory, should then return that memory to the pool instead of deallocating it.
The purpose of the cleaner is, after all, to avoid having to track the reference counts so precisely.
Modification:
The NativeMemoryCleanerDrop is now able to either recover lost memory segments, when a buffer wasn't closed explicitly
and is being cleaned by the GC, or return the buffer to the pool via ordinary drop.
The GatedCleanable has been added, because buffer ownership transfer involves generating new memory segments,
and in those cases we need to invalidate the old cleanables without deallocating the tracked memory segment or returning
it to the pool more than once.
Result:
The pooledDirectWithCleaner allocator is now able to reuse memory segments, even when their references are forgotten and
they processed by the cleaner thread.
2020-09-25 12:15:45 +02:00
|
|
|
// </editor-fold>
|
Generate complete and tested Buf API
Motivation:
The Buf API is wide, taking into account signedness, endian-ness, and so on, for all primitive
types.
Modification:
A code generator has been added which add API, implementation, and tests, to the Buf, BBuf,
and BBufTest files respectively.
Result:
We have a complete and fully tested accessor API in the Buf interface, which is still somewhat
easy to bulk-modify using the code generator.
2020-09-10 18:05:36 +02:00
|
|
|
// ### CODEGEN END primitive accessors tests
|
|
|
|
|
|
|
|
private static void assertEquals(byte expected, byte actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %1$s (0x%1$X) but was: %2$s (0x%2$X)", expected, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(char expected, char actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %s (0x%X) but was: %s (0x%X)",
|
|
|
|
expected, (int) expected, actual, (int) actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(short expected, short actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %1$s (0x%1$X) but was: %2$s (0x%2$X)", expected, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(int expected, int actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %1$s (0x%1$X) but was: %2$s (0x%2$X)", expected, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(long expected, long actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %1$s (0x%1$X) but was: %2$s (0x%2$X)", expected, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(float expected, float actual) {
|
|
|
|
//noinspection FloatingPointEquality
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %s (0x%X) but was: %s (0x%X)",
|
|
|
|
expected, Float.floatToRawIntBits(expected),
|
|
|
|
actual, Float.floatToRawIntBits(actual)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void assertEquals(double expected, double actual) {
|
|
|
|
//noinspection FloatingPointEquality
|
|
|
|
if (expected != actual) {
|
|
|
|
fail(String.format("expected: %s (0x%X) but was: %s (0x%X)",
|
|
|
|
expected, Double.doubleToRawLongBits(expected),
|
|
|
|
actual, Double.doubleToRawLongBits(actual)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|