Improve Js5MasterIndex test coverage

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent f1433ec97f
commit 4aa75c8fee
  1. 28
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt

@ -1,11 +1,20 @@
package org.openrs2.cache
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled
import org.openrs2.buffer.use
import java.nio.file.Paths
import kotlin.test.Test
import kotlin.test.assertEquals
object Js5MasterIndexTest {
private val ROOT = Paths.get(FlatFileStoreTest::class.java.getResource("master-index").toURI())
private val encoded = byteArrayOf(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4)
private val decoded = Js5MasterIndex(mutableListOf(
Js5MasterIndex.Entry(0, 1),
Js5MasterIndex.Entry(2, 3),
Js5MasterIndex.Entry(4, 5)
))
@Test
fun testCreate() {
@ -23,4 +32,23 @@ object Js5MasterIndexTest {
Js5MasterIndex.Entry(0xAA55AA55.toInt(), -627983571)
)), index)
}
@Test
fun testRead() {
Unpooled.wrappedBuffer(encoded).use { buf ->
val index = Js5MasterIndex.read(buf)
assertEquals(decoded, index)
}
}
@Test
fun testWrite() {
ByteBufAllocator.DEFAULT.buffer().use { actual ->
decoded.write(actual)
Unpooled.wrappedBuffer(encoded).use { expected ->
assertEquals(expected, actual)
}
}
}
}

Loading…
Cancel
Save