Add underflow/overflow tests

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 06cad72eaa
commit efc7ba9d2b
  1. 31
      cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt
  2. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/compressed-underflow.dat
  3. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-overflow.dat
  4. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-underflow.dat

@ -466,6 +466,37 @@ object Js5CompressionTest {
} }
} }
@Test
fun testCompressedUnderflow() {
read("compressed-underflow.dat").use { compressed ->
assertThrows<IOException> {
Js5Compression.uncompress(compressed.slice()).release()
}
assertThrows<IOException> {
Js5Compression.isKeyValid(compressed.slice(), XteaKey.ZERO)
}
}
}
@Test
fun testUncompressedOverflow() {
read("uncompressed-overflow.dat").use { compressed ->
assertThrows<IOException> {
Js5Compression.uncompress(compressed).release()
}
}
}
@Test
fun testUncompressedUnderflow() {
read("uncompressed-underflow.dat").use { compressed ->
assertThrows<IOException> {
Js5Compression.uncompress(compressed).release()
}
}
}
private fun read(name: String): ByteBuf { private fun read(name: String): ByteBuf {
Js5CompressionTest::class.java.getResourceAsStream("compression/$name").use { input -> Js5CompressionTest::class.java.getResourceAsStream("compression/$name").use { input ->
return Unpooled.wrappedBuffer(input.readAllBytes()) return Unpooled.wrappedBuffer(input.readAllBytes())

Loading…
Cancel
Save