|
|
@ -2,6 +2,7 @@ package org.openrs2.buffer |
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBufAllocator |
|
|
|
import io.netty.buffer.ByteBufAllocator |
|
|
|
import io.netty.buffer.Unpooled |
|
|
|
import io.netty.buffer.Unpooled |
|
|
|
|
|
|
|
import org.openrs2.util.charset.ModifiedUtf8Charset |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.assertEquals |
|
|
|
import kotlin.test.assertEquals |
|
|
|
import kotlin.test.assertFailsWith |
|
|
|
import kotlin.test.assertFailsWith |
|
|
@ -433,6 +434,33 @@ class ByteBufExtensionsTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testReadStringCharset() { |
|
|
|
|
|
|
|
wrappedBuffer(0).use { buf -> |
|
|
|
|
|
|
|
assertEquals("", buf.readString(ModifiedUtf8Charset)) |
|
|
|
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wrappedBuffer( |
|
|
|
|
|
|
|
0xC3.toByte(), |
|
|
|
|
|
|
|
0x96.toByte(), |
|
|
|
|
|
|
|
'p'.code.toByte(), |
|
|
|
|
|
|
|
'e'.code.toByte(), |
|
|
|
|
|
|
|
'n'.code.toByte(), |
|
|
|
|
|
|
|
'R'.code.toByte(), |
|
|
|
|
|
|
|
'S'.code.toByte(), |
|
|
|
|
|
|
|
'2'.code.toByte(), |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
).use { buf -> |
|
|
|
|
|
|
|
assertEquals("ÖpenRS2", buf.readString(ModifiedUtf8Charset)) |
|
|
|
|
|
|
|
assertFalse(buf.isReadable) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
|
|
|
|
Unpooled.EMPTY_BUFFER.readString(ModifiedUtf8Charset) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testWriteString() { |
|
|
|
fun testWriteString() { |
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
@ -461,6 +489,35 @@ class ByteBufExtensionsTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testWriteStringCharset() { |
|
|
|
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
|
|
|
actual.writeString("", ModifiedUtf8Charset) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wrappedBuffer(0).use { expected -> |
|
|
|
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
|
|
|
actual.writeString("ÖpenRS2", ModifiedUtf8Charset) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wrappedBuffer( |
|
|
|
|
|
|
|
0xC3.toByte(), |
|
|
|
|
|
|
|
0x96.toByte(), |
|
|
|
|
|
|
|
'p'.code.toByte(), |
|
|
|
|
|
|
|
'e'.code.toByte(), |
|
|
|
|
|
|
|
'n'.code.toByte(), |
|
|
|
|
|
|
|
'R'.code.toByte(), |
|
|
|
|
|
|
|
'S'.code.toByte(), |
|
|
|
|
|
|
|
'2'.code.toByte(), |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
).use { expected -> |
|
|
|
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testReadVersionedString() { |
|
|
|
fun testReadVersionedString() { |
|
|
|
wrappedBuffer(0, 0).use { buf -> |
|
|
|
wrappedBuffer(0, 0).use { buf -> |
|
|
|