use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testGetSetUnsignedShort.
private void testGetSetUnsignedShort(boolean isLE) throws Exception {
int numShorts = 100;
Buffer b = Buffer.buffer(numShorts * 2);
for (short i = 0; i < numShorts; i++) {
if (isLE) {
b.setUnsignedShortLE(i * 2, (short) (Short.MAX_VALUE + (int) i));
} else {
b.setUnsignedShort(i * 2, (short) (Short.MAX_VALUE + (int) i));
}
}
for (short i = 0; i < numShorts; i++) {
if (isLE) {
assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShortLE(i * 2));
} else {
assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShort(i * 2));
}
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testGetBytesWithByteArray.
@Test
public void testGetBytesWithByteArray() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] sub = new byte[bytes.length / 2];
System.arraycopy(bytes, bytes.length / 4, sub, 0, bytes.length / 2);
byte[] result = new byte[bytes.length / 2];
b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result);
assertTrue(TestUtils.byteArraysEqual(sub, result));
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testAppendMedium.
@Test
public void testAppendMedium() {
Buffer b = Buffer.buffer(TestUtils.randomByteArray(100));
b.appendMedium(MEDIUM_MAX_VALUE);
assertEquals(103, b.length());
b.appendMediumLE(MEDIUM_MAX_VALUE);
assertEquals(106, b.length());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testGetDouble.
@Test
public void testGetDouble() throws Exception {
int numDoubles = 100;
Buffer b = Buffer.buffer(numDoubles * 8);
for (int i = 0; i < numDoubles; i++) {
b.setDouble(i * 8, i);
}
for (int i = 0; i < numDoubles; i++) {
assertEquals((double) i, b.getDouble(i * 8), 0);
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testGetBytesWithBadOffset.
@Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesWithBadOffset() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] result = new byte[bytes.length / 2];
b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result, -1);
}
Aggregations