From 4aa75c8fee4a944e46f62df845ec36683a8cd66e Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 24 Dec 2020 22:30:41 +0000 Subject: [PATCH] Improve Js5MasterIndex test coverage Signed-off-by: Graham --- .../org/openrs2/cache/Js5MasterIndexTest.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt index 49244d24..41f07abd 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt +++ b/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) + } + } + } }