Test the master index length validation code

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 4126abfaad
commit 8fcf7cae46
  1. 13
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt

@ -2,6 +2,7 @@ package org.openrs2.cache
import io.netty.buffer.ByteBufAllocator import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.junit.jupiter.api.assertThrows
import org.openrs2.buffer.use import org.openrs2.buffer.use
import java.nio.file.Path import java.nio.file.Path
import kotlin.test.Test import kotlin.test.Test
@ -61,6 +62,12 @@ object Js5MasterIndexTest {
val index = Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL) val index = Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL)
assertEquals(decodedOriginal, index) assertEquals(decodedOriginal, index)
} }
assertThrows<IllegalArgumentException> {
Unpooled.wrappedBuffer(byteArrayOf(0)).use { buf ->
Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL)
}
}
} }
@Test @Test
@ -80,6 +87,12 @@ object Js5MasterIndexTest {
val index = Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED) val index = Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED)
assertEquals(decodedVersioned, index) assertEquals(decodedVersioned, index)
} }
assertThrows<IllegalArgumentException> {
Unpooled.wrappedBuffer(byteArrayOf(0, 0, 0, 0)).use { buf ->
Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED)
}
}
} }
@Test @Test

Loading…
Cancel
Save