From eca3a90c7847ed7d7eeab3c9ffc9802699617645 Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 9 Apr 2021 14:09:13 +0100 Subject: [PATCH] Improve Js5Compression code coverage Signed-off-by: Graham --- .../org/openrs2/cache/Js5CompressionTest.kt | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt index 1919b7df..321d4362 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt @@ -217,6 +217,15 @@ class Js5CompressionTest { 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() { read("none-eof.dat").use { compressed -> assertFailsWith { - Js5Compression.uncompress(compressed).release() + Js5Compression.uncompress(compressed.slice()).release() + } + + assertFailsWith { + Js5Compression.uncompressIfKeyValid(compressed.slice(), XteaKey.ZERO)?.release() } } } @@ -593,7 +606,11 @@ class Js5CompressionTest { fun testUncompressedOverflow() { read("uncompressed-overflow.dat").use { compressed -> assertFailsWith { - 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() { read("uncompressed-underflow.dat").use { compressed -> assertFailsWith { - Js5Compression.uncompress(compressed).release() + Js5Compression.uncompress(compressed.slice()).release() + } + + Js5Compression.uncompressIfKeyValid(compressed.slice(), XteaKey.ZERO).use { actual -> + assertNull(actual) } } }