|
|
|
@ -8,39 +8,60 @@ import kotlin.test.assertEquals |
|
|
|
|
import kotlin.test.assertFalse |
|
|
|
|
|
|
|
|
|
object ByteBufExtensionsTest { |
|
|
|
|
@Test |
|
|
|
|
fun testWrappedBuffer() { |
|
|
|
|
wrappedBuffer(1, 2, 3).use { actual -> |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(1, 2, 3)).use { expected -> |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
copiedBuffer("ØpenRS2").use { actual -> |
|
|
|
|
Unpooled.wrappedBuffer("ØpenRS2".toByteArray()).use { expected -> |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
copiedBuffer("ØpenRS2", Charsets.UTF_16BE).use { actual -> |
|
|
|
|
Unpooled.wrappedBuffer("ØpenRS2".toByteArray(Charsets.UTF_16BE)).use { expected -> |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testReadShortSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x00).use { buf -> |
|
|
|
|
assertEquals(-0x40, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { buf -> |
|
|
|
|
wrappedBuffer(0x40).use { buf -> |
|
|
|
|
assertEquals(0, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { buf -> |
|
|
|
|
wrappedBuffer(0x7F).use { buf -> |
|
|
|
|
assertEquals(0x3F, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00).use { buf -> |
|
|
|
|
assertEquals(-0x4000, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xBF.toByte(), 0xBF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xBF.toByte(), 0xBF.toByte()).use { buf -> |
|
|
|
|
assertEquals(-0x41, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x40.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x40.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x40, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x3FFF, buf.readShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
@ -48,49 +69,49 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testWriteShortSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(-0x40) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected -> |
|
|
|
|
wrappedBuffer(0x40).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(0) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected -> |
|
|
|
|
wrappedBuffer(0x7F).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(0x3F) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(-0x4000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xBF.toByte(), 0xBF.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0xBF.toByte(), 0xBF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(-0x41) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x40.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x40.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(0x40) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeShortSmart(0x3FFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
@ -112,32 +133,32 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testReadUnsignedShortSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x00).use { buf -> |
|
|
|
|
assertEquals(0, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { buf -> |
|
|
|
|
wrappedBuffer(0x40).use { buf -> |
|
|
|
|
assertEquals(0x40, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { buf -> |
|
|
|
|
wrappedBuffer(0x7F).use { buf -> |
|
|
|
|
assertEquals(0x7F, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x80.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x80.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x80, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00).use { buf -> |
|
|
|
|
assertEquals(0x4000, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x7FFF, buf.readUnsignedShortSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
@ -145,42 +166,42 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testWriteUnsignedShortSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected -> |
|
|
|
|
wrappedBuffer(0x40).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0x40) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected -> |
|
|
|
|
wrappedBuffer(0x7F).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0x7F) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x80.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x80.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0x80) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0x4000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedShortSmart(0x7FFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
@ -202,37 +223,37 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testReadIntSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x00, 0x00).use { buf -> |
|
|
|
|
assertEquals(-0x4000, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x40, 0x00).use { buf -> |
|
|
|
|
assertEquals(0, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0x7F, 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x3FFF, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x00, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00, 0x00, 0x00).use { buf -> |
|
|
|
|
assertEquals(-0x40000000, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(-0x4001, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00).use { buf -> |
|
|
|
|
assertEquals(0x4000, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x3FFFFFFF, buf.readIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
@ -240,53 +261,49 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testWriteIntSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x00, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(-0x4000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x40, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(0) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0x7F, 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(0x3FFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x00, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00, 0x00, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(-0x40000000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer( |
|
|
|
|
byteArrayOf(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte()) |
|
|
|
|
).use { expected -> |
|
|
|
|
wrappedBuffer(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(-0x4001) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(0x4000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer( |
|
|
|
|
byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()) |
|
|
|
|
).use { expected -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeIntSmart(0x3FFFFFFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
@ -308,32 +325,32 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testReadUnsignedIntSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x00, 0x00).use { buf -> |
|
|
|
|
assertEquals(0, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x40, 0x00).use { buf -> |
|
|
|
|
assertEquals(0x4000, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0x7F, 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x7FFF, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x80.toByte(), 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00, 0x80.toByte(), 0x00).use { buf -> |
|
|
|
|
assertEquals(0x8000, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x00, 0x00)).use { buf -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00, 0x00, 0x00).use { buf -> |
|
|
|
|
assertEquals(0x40000000, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte())).use { buf -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()).use { buf -> |
|
|
|
|
assertEquals(0x7FFFFFFF, buf.readUnsignedIntSmart()) |
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
} |
|
|
|
@ -341,44 +358,42 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testWriteUnsignedIntSmart() { |
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x00, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x40, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0x4000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected -> |
|
|
|
|
wrappedBuffer(0x7F, 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0x7FFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x80.toByte(), 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0x80.toByte(), 0x00, 0x80.toByte(), 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0x8000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x00, 0x00)).use { expected -> |
|
|
|
|
wrappedBuffer(0xC0.toByte(), 0x00, 0x00, 0x00).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0x40000000) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer( |
|
|
|
|
byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()) |
|
|
|
|
).use { expected -> |
|
|
|
|
wrappedBuffer(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()).use { expected -> |
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
actual.writeUnsignedIntSmart(0x7FFFFFFF) |
|
|
|
|
assertEquals(expected, actual) |
|
|
|
@ -400,15 +415,15 @@ object ByteBufExtensionsTest { |
|
|
|
|
* Tests the hasArray() case. The slicedBuf trickery is to allow us |
|
|
|
|
* to test a non-zero arrayOffset(). |
|
|
|
|
*/ |
|
|
|
|
Unpooled.wrappedBuffer(s.toByteArray()).use { buf -> |
|
|
|
|
copiedBuffer(s).use { buf -> |
|
|
|
|
val slicedBuf = buf.slice(1, buf.readableBytes() - 1) |
|
|
|
|
assertEquals(0x414FA339, slicedBuf.crc32(1, slicedBuf.writerIndex() - 2)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests the nioBufferCount() == 1 case. |
|
|
|
|
Unpooled.wrappedBuffer(s.toByteArray()).use { buf -> |
|
|
|
|
copiedBuffer(s).use { buf -> |
|
|
|
|
ByteBufAllocator.DEFAULT.directBuffer().use { directBuf -> |
|
|
|
|
directBuf.writeBytes(buf, 0, buf.capacity()) |
|
|
|
|
directBuf.writeBytes(buf) |
|
|
|
|
|
|
|
|
|
assertEquals(0x414FA339, directBuf.crc32(2, directBuf.writerIndex() - 3)) |
|
|
|
|
} |
|
|
|
@ -416,8 +431,8 @@ object ByteBufExtensionsTest { |
|
|
|
|
|
|
|
|
|
// Tests the nioBufferCount() > 1 case. |
|
|
|
|
Unpooled.wrappedBuffer( |
|
|
|
|
Unpooled.wrappedBuffer("AAThe quick brown fox ".toByteArray()), |
|
|
|
|
Unpooled.wrappedBuffer("jumps over the lazy dogA".toByteArray()) |
|
|
|
|
copiedBuffer("AAThe quick brown fox "), |
|
|
|
|
copiedBuffer("jumps over the lazy dogA") |
|
|
|
|
).use { buf -> |
|
|
|
|
assertEquals(0x414FA339, buf.crc32(2, buf.writerIndex() - 3)) |
|
|
|
|
} |
|
|
|
@ -426,7 +441,7 @@ object ByteBufExtensionsTest { |
|
|
|
|
* Check the crc32() method (with no arguments) sets the index/length |
|
|
|
|
* correctly. |
|
|
|
|
*/ |
|
|
|
|
Unpooled.wrappedBuffer(s.toByteArray()).use { buf -> |
|
|
|
|
copiedBuffer(s).use { buf -> |
|
|
|
|
buf.readerIndex(2) |
|
|
|
|
buf.writerIndex(buf.writerIndex() - 1) |
|
|
|
|
assertEquals(0x414FA339, buf.crc32()) |
|
|
|
|