Improve Js5MasterIndex code coverage

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent eca3a90c78
commit b0f1632105
  1. 50
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt
  2. BIN
      cache/src/test/resources/org/openrs2/cache/master-index/corrupt/main_file_cache.dat2
  3. BIN
      cache/src/test/resources/org/openrs2/cache/master-index/corrupt/main_file_cache.idx255

@ -10,6 +10,7 @@ import java.nio.file.Path
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertNull
class Js5MasterIndexTest { class Js5MasterIndexTest {
@Test @Test
@ -123,6 +124,35 @@ class Js5MasterIndexTest {
) )
} }
@Test
fun testCreateCorruptIndex() {
val index = Store.open(ROOT.resolve("corrupt")).use { store ->
Js5MasterIndex.create(store)
}
assertEquals(
Js5MasterIndex(
MasterIndexFormat.ORIGINAL,
mutableListOf(
Js5MasterIndex.Entry(
0, 609698396, 0, 0, ByteBufUtil.decodeHexDump(
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c"
)
),
Js5MasterIndex.Entry(0, 0, 0, 0, null),
Js5MasterIndex.Entry(
0, 609698396, 0, 0, ByteBufUtil.decodeHexDump(
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c"
)
)
)
),
index
)
}
@Test @Test
fun testReadOriginal() { fun testReadOriginal() {
Unpooled.wrappedBuffer(encodedOriginal).use { buf -> Unpooled.wrappedBuffer(encodedOriginal).use { buf ->
@ -283,6 +313,26 @@ class Js5MasterIndexTest {
} }
} }
@Test
fun testSetDigest() {
val entry = Js5MasterIndex.Entry(0, 0, 0, 0, null)
val digest = ByteArray(Whirlpool.DIGESTBYTES) { it.toByte() }
entry.digest = digest
assertEquals(digest, entry.digest)
entry.digest = null
assertNull(entry.digest)
assertFailsWith<IllegalArgumentException> {
entry.digest = ByteArray(Whirlpool.DIGESTBYTES - 1)
}
assertFailsWith<IllegalArgumentException> {
entry.digest = ByteArray(Whirlpool.DIGESTBYTES + 1)
}
}
private companion object { private companion object {
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI()) private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI())
private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key")) private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key"))

Loading…
Cancel
Save