Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt

41 lines
1.2 KiB

package org.openrs2.protocol.js5
import io.netty.buffer.ByteBuf
import io.netty.buffer.PooledByteBufAllocator
import io.netty.channel.embedded.EmbeddedChannel
import org.openrs2.buffer.copiedBuffer
import org.openrs2.buffer.use
import org.openrs2.protocol.js5.downstream.XorDecoder
import kotlin.test.Test
import kotlin.test.assertEquals
class XorDecoderTest {
@Test
fun testDecode() {
testDecode(0, "OpenRS2", false)
testDecode(0, "OpenRS2", true)
testDecode(32, "oPENrs\u0012", false)
testDecode(32, "oPENrs\u0012", true)
}
private fun testDecode(key: Int, expected: String, direct: Boolean) {
val decoder = XorDecoder()
decoder.key = key
val channel = EmbeddedChannel(decoder)
if (direct) {
PooledByteBufAllocator.DEFAULT.ioBuffer().use { buf ->
buf.writeCharSequence("OpenRS2", Charsets.UTF_8)
channel.writeInbound(buf.retain())
}
} else {
channel.writeInbound(copiedBuffer("OpenRS2"))
}
channel.readInbound<ByteBuf>().use { actual ->
copiedBuffer(expected).use { expected ->
assertEquals(expected, actual)
}
}
}
}