Improve Js5Compression code coverage

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 3293454c17
commit eca3a90c78
  1. 27
      cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt

@ -217,6 +217,15 @@ class Js5CompressionTest {
assertEquals(expected, actual) assertEquals(expected, actual)
} }
} }
Js5Compression.compressBest(expected.slice(), enableLzma = true).use { compressed ->
assertNotEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
assert(compressed.readableBytes() < noneLen)
Js5Compression.uncompress(compressed).use { actual ->
assertEquals(expected, actual)
}
}
} }
} }
@ -302,7 +311,11 @@ class Js5CompressionTest {
fun testNoneEof() { fun testNoneEof() {
read("none-eof.dat").use { compressed -> read("none-eof.dat").use { compressed ->
assertFailsWith<IOException> { assertFailsWith<IOException> {
Js5Compression.uncompress(compressed).release() Js5Compression.uncompress(compressed.slice()).release()
}
assertFailsWith<IOException> {
Js5Compression.uncompressIfKeyValid(compressed.slice(), XteaKey.ZERO)?.release()
} }
} }
} }
@ -593,7 +606,11 @@ class Js5CompressionTest {
fun testUncompressedOverflow() { fun testUncompressedOverflow() {
read("uncompressed-overflow.dat").use { compressed -> read("uncompressed-overflow.dat").use { compressed ->
assertFailsWith<IOException> { assertFailsWith<IOException> {
Js5Compression.uncompress(compressed).release() Js5Compression.uncompress(compressed.slice()).release()
}
Js5Compression.uncompressIfKeyValid(compressed.slice(), XteaKey.ZERO).use { actual ->
assertNull(actual)
} }
} }
} }
@ -602,7 +619,11 @@ class Js5CompressionTest {
fun testUncompressedUnderflow() { fun testUncompressedUnderflow() {
read("uncompressed-underflow.dat").use { compressed -> read("uncompressed-underflow.dat").use { compressed ->
assertFailsWith<IOException> { assertFailsWith<IOException> {
Js5Compression.uncompress(compressed).release() Js5Compression.uncompress(compressed.slice()).release()
}
Js5Compression.uncompressIfKeyValid(compressed.slice(), XteaKey.ZERO).use { actual ->
assertNull(actual)
} }
} }
} }

Loading…
Cancel
Save