Use default ByteBufAllocator in unit tests

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent 4fdedf298b
commit ec4f8b59c9
  1. 67
      buffer/src/test/java/dev/openrs2/buffer/ByteBufExtensionsTest.kt
  2. 47
      cache/src/test/java/dev/openrs2/cache/BufferedFileChannelTest.kt
  3. 23
      cache/src/test/java/dev/openrs2/cache/Js5IndexTest.kt

@ -1,5 +1,6 @@
package dev.openrs2.buffer package dev.openrs2.buffer
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import kotlin.test.Test import kotlin.test.Test
@ -48,61 +49,61 @@ object ByteBufExtensionsTest {
@Test @Test
fun testWriteShortSmart() { fun testWriteShortSmart() {
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(-0x40) actual.writeShortSmart(-0x40)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(0) actual.writeShortSmart(0)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(0x3F) actual.writeShortSmart(0x3F)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(-0x4000) actual.writeShortSmart(-0x4000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xBF.toByte(), 0xBF.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xBF.toByte(), 0xBF.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(-0x41) actual.writeShortSmart(-0x41)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x40.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x40.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(0x40) actual.writeShortSmart(0x40)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeShortSmart(0x3FFF) actual.writeShortSmart(0x3FFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeShortSmart(-0x4001) buf.writeShortSmart(-0x4001)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeShortSmart(0x4000) buf.writeShortSmart(0x4000)
} }
@ -145,54 +146,54 @@ object ByteBufExtensionsTest {
@Test @Test
fun testWriteUnsignedShortSmart() { fun testWriteUnsignedShortSmart() {
Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0) actual.writeUnsignedShortSmart(0)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x40)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0x40) actual.writeUnsignedShortSmart(0x40)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x7F)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0x7F) actual.writeUnsignedShortSmart(0x7F)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x80.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x80.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0x80) actual.writeUnsignedShortSmart(0x80)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0x4000) actual.writeUnsignedShortSmart(0x4000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xFF.toByte(), 0xFF.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedShortSmart(0x7FFF) actual.writeUnsignedShortSmart(0x7FFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeUnsignedShortSmart(-0x1) buf.writeUnsignedShortSmart(-0x1)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeUnsignedShortSmart(0x10000) buf.writeUnsignedShortSmart(0x10000)
} }
@ -240,28 +241,28 @@ object ByteBufExtensionsTest {
@Test @Test
fun testWriteIntSmart() { fun testWriteIntSmart() {
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(-0x4000) actual.writeIntSmart(-0x4000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(0) actual.writeIntSmart(0)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(0x3FFF) actual.writeIntSmart(0x3FFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x00, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x00, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(-0x40000000) actual.writeIntSmart(-0x40000000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
@ -270,14 +271,14 @@ object ByteBufExtensionsTest {
Unpooled.wrappedBuffer( Unpooled.wrappedBuffer(
byteArrayOf(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte()) byteArrayOf(0xBF.toByte(), 0xFF.toByte(), 0xBF.toByte(), 0xFF.toByte())
).use { expected -> ).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(-0x4001) actual.writeIntSmart(-0x4001)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x40.toByte(), 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(0x4000) actual.writeIntSmart(0x4000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
@ -286,19 +287,19 @@ object ByteBufExtensionsTest {
Unpooled.wrappedBuffer( Unpooled.wrappedBuffer(
byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()) byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte())
).use { expected -> ).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeIntSmart(0x3FFFFFFF) actual.writeIntSmart(0x3FFFFFFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeIntSmart(-0x40000001) buf.writeIntSmart(-0x40000001)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeIntSmart(0x40000000) buf.writeIntSmart(0x40000000)
} }
@ -341,35 +342,35 @@ object ByteBufExtensionsTest {
@Test @Test
fun testWriteUnsignedIntSmart() { fun testWriteUnsignedIntSmart() {
Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x00, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0) actual.writeUnsignedIntSmart(0)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x40, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0x4000) actual.writeUnsignedIntSmart(0x4000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x7F, 0xFF.toByte())).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0x7FFF) actual.writeUnsignedIntSmart(0x7FFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x80.toByte(), 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0x80.toByte(), 0x00, 0x80.toByte(), 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0x8000) actual.writeUnsignedIntSmart(0x8000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x00, 0x00)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0xC0.toByte(), 0x00, 0x00, 0x00)).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0x40000000) actual.writeUnsignedIntSmart(0x40000000)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
@ -378,13 +379,13 @@ object ByteBufExtensionsTest {
Unpooled.wrappedBuffer( Unpooled.wrappedBuffer(
byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()) byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte())
).use { expected -> ).use { expected ->
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
actual.writeUnsignedIntSmart(0x7FFFFFFF) actual.writeUnsignedIntSmart(0x7FFFFFFF)
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
buf.writeUnsignedIntSmart(0x80000000.toInt()) buf.writeUnsignedIntSmart(0x80000000.toInt())
} }

@ -3,6 +3,7 @@ package dev.openrs2.cache
import com.google.common.jimfs.Configuration import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs import com.google.common.jimfs.Jimfs
import dev.openrs2.buffer.use import dev.openrs2.buffer.use
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
@ -155,7 +156,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel -> BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel ->
Unpooled.buffer(7, 7).use { actual -> ByteBufAllocator.DEFAULT.buffer(7, 7).use { actual ->
Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { expected ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
assertEquals(expected, actual) assertEquals(expected, actual)
@ -177,7 +178,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel -> BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel ->
Unpooled.buffer(14, 14).use { actual -> ByteBufAllocator.DEFAULT.buffer(14, 14).use { actual ->
Unpooled.wrappedBuffer("OpenRS2OpenRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenRS2OpenRS2".toByteArray()).use { expected ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
assertEquals(expected, actual) assertEquals(expected, actual)
@ -193,7 +194,7 @@ object BufferedFileChannelTest {
val path = fs.getPath("/test.dat") val path = fs.getPath("/test.dat")
BufferedFileChannel(FileChannel.open(path, CREATE, READ, WRITE), 8, 8).use { channel -> BufferedFileChannel(FileChannel.open(path, CREATE, READ, WRITE), 8, 8).use { channel ->
Unpooled.buffer(1, 1).use { buf -> ByteBufAllocator.DEFAULT.buffer(1, 1).use { buf ->
assertThrows<EOFException> { assertThrows<EOFException> {
channel.read(0, buf, buf.writableBytes()) channel.read(0, buf, buf.writableBytes())
} }
@ -209,7 +210,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel -> BufferedFileChannel(FileChannel.open(path, READ), 8, 8).use { channel ->
Unpooled.buffer(15, 15).use { buf -> ByteBufAllocator.DEFAULT.buffer(15, 15).use { buf ->
assertThrows<EOFException> { assertThrows<EOFException> {
channel.read(0, buf, buf.writableBytes()) channel.read(0, buf, buf.writableBytes())
} }
@ -228,7 +229,7 @@ object BufferedFileChannelTest {
channel.write(7, buf, buf.readableBytes()) channel.write(7, buf, buf.readableBytes())
} }
Unpooled.buffer(8, 8).use { actual -> ByteBufAllocator.DEFAULT.buffer(8, 8).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer(byteArrayOf(0, 0, 0, 0, 0, 0, 0, 1)).use { expected -> Unpooled.wrappedBuffer(byteArrayOf(0, 0, 0, 0, 0, 0, 0, 1)).use { expected ->
@ -249,7 +250,7 @@ object BufferedFileChannelTest {
channel.write(0, buf, buf.readableBytes()) channel.write(0, buf, buf.readableBytes())
} }
Unpooled.buffer(7, 7).use { actual -> ByteBufAllocator.DEFAULT.buffer(7, 7).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { expected ->
@ -270,7 +271,7 @@ object BufferedFileChannelTest {
channel.write(0, buf, buf.readableBytes()) channel.write(0, buf, buf.readableBytes())
} }
Unpooled.buffer(6, 6).use { actual -> ByteBufAllocator.DEFAULT.buffer(6, 6).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer("OpenRS".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenRS".toByteArray()).use { expected ->
@ -291,7 +292,7 @@ object BufferedFileChannelTest {
channel.write(0, buf, buf.readableBytes()) channel.write(0, buf, buf.readableBytes())
} }
Unpooled.buffer(6, 6).use { actual -> ByteBufAllocator.DEFAULT.buffer(6, 6).use { actual ->
channel.read(1, actual, actual.writableBytes()) channel.read(1, actual, actual.writableBytes())
Unpooled.wrappedBuffer("penRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("penRS2".toByteArray()).use { expected ->
@ -314,7 +315,7 @@ object BufferedFileChannelTest {
channel.write(4, buf, buf.readableBytes()) channel.write(4, buf, buf.readableBytes())
} }
Unpooled.buffer(14, 14).use { actual -> ByteBufAllocator.DEFAULT.buffer(14, 14).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer("OpenHelloenRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenHelloenRS2".toByteArray()).use { expected ->
@ -337,7 +338,7 @@ object BufferedFileChannelTest {
channel.write(4, buf, buf.readableBytes()) channel.write(4, buf, buf.readableBytes())
} }
Unpooled.buffer(7, 7).use { actual -> ByteBufAllocator.DEFAULT.buffer(7, 7).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer("OpenHel".toByteArray()).use { expected -> Unpooled.wrappedBuffer("OpenHel".toByteArray()).use { expected ->
@ -360,7 +361,7 @@ object BufferedFileChannelTest {
channel.write(4, buf, buf.readableBytes()) channel.write(4, buf, buf.readableBytes())
} }
Unpooled.buffer(7, 7).use { actual -> ByteBufAllocator.DEFAULT.buffer(7, 7).use { actual ->
channel.read(7, actual, actual.writableBytes()) channel.read(7, actual, actual.writableBytes())
Unpooled.wrappedBuffer("loenRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("loenRS2".toByteArray()).use { expected ->
@ -383,7 +384,7 @@ object BufferedFileChannelTest {
channel.write(4, buf, buf.readableBytes()) channel.write(4, buf, buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(0, actual, actual.writableBytes()) channel.read(0, actual, actual.writableBytes())
Unpooled.wrappedBuffer("Open".toByteArray()).use { expected -> Unpooled.wrappedBuffer("Open".toByteArray()).use { expected ->
@ -391,7 +392,7 @@ object BufferedFileChannelTest {
} }
} }
Unpooled.buffer(5, 5).use { actual -> ByteBufAllocator.DEFAULT.buffer(5, 5).use { actual ->
channel.read(9, actual, actual.writableBytes()) channel.read(9, actual, actual.writableBytes())
Unpooled.wrappedBuffer("enRS2".toByteArray()).use { expected -> Unpooled.wrappedBuffer("enRS2".toByteArray()).use { expected ->
@ -410,7 +411,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel -> BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel ->
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected ->
@ -422,7 +423,7 @@ object BufferedFileChannelTest {
channel.write(4, buf.slice(), buf.readableBytes()) channel.write(4, buf.slice(), buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected -> Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected ->
@ -441,7 +442,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel -> BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel ->
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected ->
@ -453,7 +454,7 @@ object BufferedFileChannelTest {
channel.write(4, buf.slice(), buf.readableBytes()) channel.write(4, buf.slice(), buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("ABCO".toByteArray()).use { expected -> Unpooled.wrappedBuffer("ABCO".toByteArray()).use { expected ->
@ -472,7 +473,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel -> BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel ->
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected ->
@ -484,7 +485,7 @@ object BufferedFileChannelTest {
channel.write(5, buf.slice(), buf.readableBytes()) channel.write(5, buf.slice(), buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RBCD".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RBCD".toByteArray()).use { expected ->
@ -503,7 +504,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel -> BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel ->
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected ->
@ -515,7 +516,7 @@ object BufferedFileChannelTest {
channel.write(3, buf.slice(), buf.readableBytes()) channel.write(3, buf.slice(), buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected -> Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected ->
@ -534,7 +535,7 @@ object BufferedFileChannelTest {
Files.write(path, "OpenRS2OpenRS2".toByteArray()) Files.write(path, "OpenRS2OpenRS2".toByteArray())
BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel -> BufferedFileChannel(FileChannel.open(path, READ, WRITE), 4, 0).use { channel ->
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected -> Unpooled.wrappedBuffer("RS2O".toByteArray()).use { expected ->
@ -546,7 +547,7 @@ object BufferedFileChannelTest {
channel.write(4, buf.slice(), buf.readableBytes()) channel.write(4, buf.slice(), buf.readableBytes())
} }
Unpooled.buffer(4, 4).use { actual -> ByteBufAllocator.DEFAULT.buffer(4, 4).use { actual ->
channel.read(4, actual, actual.writableBytes()) channel.read(4, actual, actual.writableBytes())
Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected -> Unpooled.wrappedBuffer("ABCD".toByteArray()).use { expected ->

@ -3,6 +3,7 @@ package dev.openrs2.cache
import dev.openrs2.buffer.use import dev.openrs2.buffer.use
import dev.openrs2.util.krHashCode import dev.openrs2.util.krHashCode
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.ByteBufUtil import io.netty.buffer.ByteBufUtil
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
@ -116,7 +117,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteEmpty() { fun testWriteEmpty() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
emptyIndex.write(actual) emptyIndex.write(actual)
read("empty.dat").use { expected -> read("empty.dat").use { expected ->
@ -151,7 +152,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteVersioned() { fun testWriteVersioned() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
versionedIndex.write(actual) versionedIndex.write(actual)
read("versioned.dat").use { expected -> read("versioned.dat").use { expected ->
@ -171,7 +172,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteNoFlags() { fun testWriteNoFlags() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
noFlagsIndex.write(actual) noFlagsIndex.write(actual)
read("no-flags.dat").use { expected -> read("no-flags.dat").use { expected ->
@ -191,7 +192,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteNamed() { fun testWriteNamed() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
namedIndex.write(actual) namedIndex.write(actual)
read("named.dat").use { expected -> read("named.dat").use { expected ->
@ -211,7 +212,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteSmart() { fun testWriteSmart() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
smartIndex.write(actual) smartIndex.write(actual)
read("smart.dat").use { expected -> read("smart.dat").use { expected ->
@ -225,7 +226,7 @@ object Js5IndexTest {
val index = Js5Index(Js5Protocol.ORIGINAL) val index = Js5Index(Js5Protocol.ORIGINAL)
index.createOrGet(65536) index.createOrGet(65536)
Unpooled.buffer().use { buf -> ByteBufAllocator.DEFAULT.buffer().use { buf ->
assertThrows<IllegalStateException> { assertThrows<IllegalStateException> {
index.write(buf) index.write(buf)
} }
@ -243,7 +244,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteDigest() { fun testWriteDigest() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
digestIndex.write(actual) digestIndex.write(actual)
read("digest.dat").use { expected -> read("digest.dat").use { expected ->
@ -254,7 +255,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteNullDigest() { fun testWriteNullDigest() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
nullDigestIndex.write(actual) nullDigestIndex.write(actual)
read("null-digest.dat").use { expected -> read("null-digest.dat").use { expected ->
@ -274,7 +275,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteLengths() { fun testWriteLengths() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
lengthsIndex.write(actual) lengthsIndex.write(actual)
read("lengths.dat").use { expected -> read("lengths.dat").use { expected ->
@ -294,7 +295,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteUncompressedChecksum() { fun testWriteUncompressedChecksum() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
uncompressedChecksumIndex.write(actual) uncompressedChecksumIndex.write(actual)
read("uncompressed-checksum.dat").use { expected -> read("uncompressed-checksum.dat").use { expected ->
@ -314,7 +315,7 @@ object Js5IndexTest {
@Test @Test
fun testWriteAllFlags() { fun testWriteAllFlags() {
Unpooled.buffer().use { actual -> ByteBufAllocator.DEFAULT.buffer().use { actual ->
allFlagsIndex.write(actual) allFlagsIndex.write(actual)
read("all-flags.dat").use { expected -> read("all-flags.dat").use { expected ->

Loading…
Cancel
Save