Convert all test objects to classes

This is required for IDEA to display the run test icon in the gutter.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 91d4e46c89
commit 359891c01e
  1. 2
      buffer/src/test/kotlin/org/openrs2/buffer/ByteBufExtensionsTest.kt
  2. 2
      cache/src/test/kotlin/org/openrs2/cache/BufferedFileChannelTest.kt
  3. 8
      cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt
  4. 8
      cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt
  5. 10
      cache/src/test/kotlin/org/openrs2/cache/FlatFileStoreTest.kt
  6. 26
      cache/src/test/kotlin/org/openrs2/cache/GroupTest.kt
  7. 10
      cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt
  8. 188
      cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt
  9. 162
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt
  10. 2
      cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt
  11. 10
      cache/src/test/kotlin/org/openrs2/cache/StoreTest.kt
  12. 2
      cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt
  13. 40
      crypto/src/test/kotlin/org/openrs2/crypto/IsaacRandomTest.kt
  14. 76
      crypto/src/test/kotlin/org/openrs2/crypto/RsaTest.kt
  15. 132
      crypto/src/test/kotlin/org/openrs2/crypto/WhirlpoolTest.kt
  16. 42
      crypto/src/test/kotlin/org/openrs2/crypto/XteaTest.kt
  17. 2
      db/src/test/kotlin/org/openrs2/db/BackoffStrategyTest.kt
  18. 32
      db/src/test/kotlin/org/openrs2/db/DatabaseTest.kt
  19. 2
      db/src/test/kotlin/org/openrs2/db/DeadlockDetectorTest.kt
  20. 2
      protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt
  21. 2
      protocol/src/test/kotlin/org/openrs2/protocol/Rs2EncoderTest.kt
  22. 2
      protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestDecoderTest.kt
  23. 2
      protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestEncoderTest.kt
  24. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestDecoderTest.kt
  25. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt
  26. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt
  27. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt
  28. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt
  29. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/XorEncoderTest.kt
  30. 2
      util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt
  31. 2
      util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt
  32. 2
      util/src/test/kotlin/org/openrs2/util/charset/ModifiedUtf8CharsetTest.kt
  33. 2
      util/src/test/kotlin/org/openrs2/util/collect/ForestDisjointSetTest.kt
  34. 2
      util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt
  35. 9
      util/src/test/kotlin/org/openrs2/util/io/DeterministicJarOutputStreamTest.kt
  36. 2
      util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt

@ -7,7 +7,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
object ByteBufExtensionsTest {
class ByteBufExtensionsTest {
@Test
fun testWrappedBuffer() {
wrappedBuffer(1, 2, 3).use { actual ->

@ -17,7 +17,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object BufferedFileChannelTest {
class BufferedFileChannelTest {
@Test
fun testEmpty() {
Jimfs.newFileSystem(Configuration.unix()).use { fs ->

@ -15,9 +15,7 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
object DiskStoreTest {
private val ROOT = Path.of(DiskStoreTest::class.java.getResource("disk-store").toURI())
class DiskStoreTest {
@Test
fun testBounds() {
readTest("empty") { store ->
@ -758,4 +756,8 @@ object DiskStoreTest {
assertTrue(expected.recursiveEquals(actual))
}
}
private companion object {
private val ROOT = Path.of(DiskStoreTest::class.java.getResource("disk-store").toURI())
}
}

@ -14,9 +14,7 @@ import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
object DiskStoreZipWriterTest {
private val ROOT = Path.of(DiskStoreZipWriterTest::class.java.getResource("zip").toURI())
class DiskStoreZipWriterTest {
@Test
fun testBounds() {
DiskStoreZipWriter(ZipOutputStream(OutputStream.nullOutputStream())).use { store ->
@ -118,4 +116,8 @@ object DiskStoreZipWriterTest {
assertTrue(ROOT.recursiveEquals(actual))
}
}
private companion object {
private val ROOT = Path.of(DiskStoreZipWriterTest::class.java.getResource("zip").toURI())
}
}

@ -15,10 +15,7 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
object FlatFileStoreTest {
private val IGNORE_GIT_EMPTY = { path: Path -> path.fileName.toString() != ".gitempty" }
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("flat-file-store").toURI())
class FlatFileStoreTest {
@Test
fun testBounds() {
readTest("empty") { store ->
@ -273,4 +270,9 @@ object FlatFileStoreTest {
assertTrue(expected.recursiveEquals(actual, filter = IGNORE_GIT_EMPTY))
}
}
private companion object {
private val IGNORE_GIT_EMPTY = { path: Path -> path.fileName.toString() != ".gitempty" }
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("flat-file-store").toURI())
}
}

@ -10,18 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object GroupTest {
private val index = Js5Index(Js5Protocol.ORIGINAL)
private val zeroFiles = index.createOrGet(0)
private val oneFile = index.createOrGet(1).apply {
createOrGet(1)
}
private val multipleFiles = index.createOrGet(2).apply {
createOrGet(0)
createOrGet(1)
createOrGet(3)
}
class GroupTest {
@Test
fun testPackEmpty() {
assertFailsWith<IllegalArgumentException> {
@ -177,4 +166,17 @@ object GroupTest {
expected.values.forEach(ByteBuf::release)
}
}
private companion object {
private val index = Js5Index(Js5Protocol.ORIGINAL)
private val zeroFiles = index.createOrGet(0)
private val oneFile = index.createOrGet(1).apply {
createOrGet(1)
}
private val multipleFiles = index.createOrGet(2).apply {
createOrGet(0)
createOrGet(1)
createOrGet(3)
}
}
}

@ -13,10 +13,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
object Js5CompressionTest {
private val KEY = XteaKey.fromHex("00112233445566778899AABBCCDDEEFF")
private val INVALID_KEY = XteaKey.fromHex("0123456789ABCDEF0123456789ABCDEF")
class Js5CompressionTest {
@Test
fun testCompressNone() {
read("none.dat").use { expected ->
@ -503,4 +500,9 @@ object Js5CompressionTest {
return Unpooled.wrappedBuffer(input.readAllBytes())
}
}
private companion object {
private val KEY = XteaKey.fromHex("00112233445566778899AABBCCDDEEFF")
private val INVALID_KEY = XteaKey.fromHex("0123456789ABCDEF0123456789ABCDEF")
}
}

@ -14,99 +14,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
object Js5IndexTest {
private val emptyIndex = Js5Index(Js5Protocol.ORIGINAL)
private val versionedIndex = Js5Index(Js5Protocol.VERSIONED, version = 0x12345678)
private val noFlagsIndex = Js5Index(Js5Protocol.ORIGINAL).apply {
val group0 = createOrGet(0)
group0.checksum = 0x01234567
group0.version = 0
group0.createOrGet(0)
val group1 = createOrGet(1)
group1.checksum = 0x89ABCDEF.toInt()
group1.version = 10
val group2 = createOrGet(3)
group2.checksum = 0xAAAA5555.toInt()
group2.version = 20
group2.createOrGet(1)
group2.createOrGet(3)
}
private val namedIndex = Js5Index(Js5Protocol.ORIGINAL, hasNames = true).apply {
val group0 = createOrGet("hello")
group0.checksum = 0x01234567
group0.version = 0x89ABCDEF.toInt()
group0.createOrGet("world")
}
private val smartIndex = Js5Index(Js5Protocol.SMART).apply {
val group0 = createOrGet(0)
group0.checksum = 0x01234567
group0.version = 0x89ABCDEF.toInt()
group0.createOrGet(0)
group0.createOrGet(100000)
val group1 = createOrGet(100000)
group1.checksum = 0xAAAA5555.toInt()
group1.version = 0x5555AAAA
}
private val digestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = ByteBufUtil.decodeHexDump(
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
)
}
private val nullDigestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = null
}
private val lengthsIndex = Js5Index(Js5Protocol.ORIGINAL, hasLengths = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.length = 1000
group.uncompressedLength = 2000
}
private val uncompressedChecksumIndex = Js5Index(Js5Protocol.ORIGINAL, hasUncompressedChecksums = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.uncompressedChecksum = 0xAAAA5555.toInt()
}
private val allFlagsIndex = Js5Index(
Js5Protocol.ORIGINAL,
hasNames = true,
hasDigests = true,
hasLengths = true,
hasUncompressedChecksums = true
).apply {
val group = createOrGet("hello")
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = ByteBufUtil.decodeHexDump(
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
)
group.length = 1000
group.uncompressedLength = 2000
group.uncompressedChecksum = 0xAAAA5555.toInt()
group.createOrGet("world")
}
class Js5IndexTest {
@Test
fun testReadEmpty() {
read("empty.dat").use { buf ->
@ -412,4 +320,98 @@ object Js5IndexTest {
return Unpooled.wrappedBuffer(input.readAllBytes())
}
}
private companion object {
private val emptyIndex = Js5Index(Js5Protocol.ORIGINAL)
private val versionedIndex = Js5Index(Js5Protocol.VERSIONED, version = 0x12345678)
private val noFlagsIndex = Js5Index(Js5Protocol.ORIGINAL).apply {
val group0 = createOrGet(0)
group0.checksum = 0x01234567
group0.version = 0
group0.createOrGet(0)
val group1 = createOrGet(1)
group1.checksum = 0x89ABCDEF.toInt()
group1.version = 10
val group2 = createOrGet(3)
group2.checksum = 0xAAAA5555.toInt()
group2.version = 20
group2.createOrGet(1)
group2.createOrGet(3)
}
private val namedIndex = Js5Index(Js5Protocol.ORIGINAL, hasNames = true).apply {
val group0 = createOrGet("hello")
group0.checksum = 0x01234567
group0.version = 0x89ABCDEF.toInt()
group0.createOrGet("world")
}
private val smartIndex = Js5Index(Js5Protocol.SMART).apply {
val group0 = createOrGet(0)
group0.checksum = 0x01234567
group0.version = 0x89ABCDEF.toInt()
group0.createOrGet(0)
group0.createOrGet(100000)
val group1 = createOrGet(100000)
group1.checksum = 0xAAAA5555.toInt()
group1.version = 0x5555AAAA
}
private val digestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = ByteBufUtil.decodeHexDump(
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
)
}
private val nullDigestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = null
}
private val lengthsIndex = Js5Index(Js5Protocol.ORIGINAL, hasLengths = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.length = 1000
group.uncompressedLength = 2000
}
private val uncompressedChecksumIndex = Js5Index(Js5Protocol.ORIGINAL, hasUncompressedChecksums = true).apply {
val group = createOrGet(0)
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.uncompressedChecksum = 0xAAAA5555.toInt()
}
private val allFlagsIndex = Js5Index(
Js5Protocol.ORIGINAL,
hasNames = true,
hasDigests = true,
hasLengths = true,
hasUncompressedChecksums = true
).apply {
val group = createOrGet("hello")
group.checksum = 0x01234567
group.version = 0x89ABCDEF.toInt()
group.digest = ByteBufUtil.decodeHexDump(
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
)
group.length = 1000
group.uncompressedLength = 2000
group.uncompressedChecksum = 0xAAAA5555.toInt()
group.createOrGet("world")
}
}
}

@ -10,86 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Js5MasterIndexTest {
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI())
private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key"))
private val PUBLIC_KEY = Rsa.readPublicKey(ROOT.resolve("public.key"))
private val encodedOriginal = ByteBufUtil.decodeHexDump("000000010000000300000005")
private val decodedOriginal = Js5MasterIndex(
MasterIndexFormat.ORIGINAL,
mutableListOf(
Js5MasterIndex.Entry(0, 1, null),
Js5MasterIndex.Entry(0, 3, null),
Js5MasterIndex.Entry(0, 5, null)
)
)
private val encodedVersioned = ByteBufUtil.decodeHexDump("000000010000000000000003000000020000000500000004")
private val decodedVersioned = Js5MasterIndex(
MasterIndexFormat.VERSIONED,
mutableListOf(
Js5MasterIndex.Entry(0, 1, null),
Js5MasterIndex.Entry(2, 3, null),
Js5MasterIndex.Entry(4, 5, null)
)
)
private val encodedWhirlpool = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" +
"0a" +
"ee8f66a2ce0b07de4d2b792eed26ae7a6c307b763891d085c63ea55b4c003bc0" +
"b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671"
)
private val decodedWhirlpool = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL,
mutableListOf(
Js5MasterIndex.Entry(
0x01234567, 0x89ABCDEF.toInt(), ByteBufUtil.decodeHexDump(
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c"
)
)
)
)
private val encodedWhirlpoolNullDigest = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0a" +
"4a0e22540fb0a9bc06fe84bfb35f9281ba9fbd30288c3375c508ad741c4d4491" +
"8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d"
)
private val decodedWhirlpoolNullDigest = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL,
mutableListOf(
Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), null)
)
)
private val encodedSigned = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" +
"2134b1e637d4c9f3b7bdd446ad40cedb6d824cfb48f937ae0d6e2ba3977881ea" +
"ed02adae179ed89cea56e98772186bb569bb24a4951e441716df0d5d7199c088" +
"28974d43c3644e74bf29ec1435e425f6cb05aca14a84163c5b46b6e6a9362f22" +
"4f69f4a5888b3fe7aec0141da25b17c7f65069eed59f3be134fa1ade4e191b41" +
"d561447446cd1cc4d11e6499c49e00066173908491d8d2ff282aefa86e6c6b15" +
"dceb437d0436b6195ef60d4128e1e0184bf6929b73abd1a8aa2a047e3cb90d03" +
"57707ce3f4f5a7af8471eda5c0c0748454a9cbb48c25ebe4e7fd94e3881b6461" +
"d06e2bce128dc96decb537b8e9611591d445d7dfd3701d25ac05f8d091581aef"
)
class Js5MasterIndexTest {
@Test
fun testCreateOriginal() {
val index = Store.open(ROOT.resolve("original")).use { store ->
@ -320,4 +241,85 @@ object Js5MasterIndexTest {
}
}
}
private companion object {
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI())
private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key"))
private val PUBLIC_KEY = Rsa.readPublicKey(ROOT.resolve("public.key"))
private val encodedOriginal = ByteBufUtil.decodeHexDump("000000010000000300000005")
private val decodedOriginal = Js5MasterIndex(
MasterIndexFormat.ORIGINAL,
mutableListOf(
Js5MasterIndex.Entry(0, 1, null),
Js5MasterIndex.Entry(0, 3, null),
Js5MasterIndex.Entry(0, 5, null)
)
)
private val encodedVersioned = ByteBufUtil.decodeHexDump("000000010000000000000003000000020000000500000004")
private val decodedVersioned = Js5MasterIndex(
MasterIndexFormat.VERSIONED,
mutableListOf(
Js5MasterIndex.Entry(0, 1, null),
Js5MasterIndex.Entry(2, 3, null),
Js5MasterIndex.Entry(4, 5, null)
)
)
private val encodedWhirlpool = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" +
"0a" +
"ee8f66a2ce0b07de4d2b792eed26ae7a6c307b763891d085c63ea55b4c003bc0" +
"b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671"
)
private val decodedWhirlpool = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL,
mutableListOf(
Js5MasterIndex.Entry(
0x01234567, 0x89ABCDEF.toInt(), ByteBufUtil.decodeHexDump(
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c"
)
)
)
)
private val encodedWhirlpoolNullDigest = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0a" +
"4a0e22540fb0a9bc06fe84bfb35f9281ba9fbd30288c3375c508ad741c4d4491" +
"8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d"
)
private val decodedWhirlpoolNullDigest = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL,
mutableListOf(
Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), null)
)
)
private val encodedSigned = ByteBufUtil.decodeHexDump(
"01" +
"89abcdef" +
"01234567" +
"0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" +
"4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" +
"2134b1e637d4c9f3b7bdd446ad40cedb6d824cfb48f937ae0d6e2ba3977881ea" +
"ed02adae179ed89cea56e98772186bb569bb24a4951e441716df0d5d7199c088" +
"28974d43c3644e74bf29ec1435e425f6cb05aca14a84163c5b46b6e6a9362f22" +
"4f69f4a5888b3fe7aec0141da25b17c7f65069eed59f3be134fa1ade4e191b41" +
"d561447446cd1cc4d11e6499c49e00066173908491d8d2ff282aefa86e6c6b15" +
"dceb437d0436b6195ef60d4128e1e0184bf6929b73abd1a8aa2a047e3cb90d03" +
"57707ce3f4f5a7af8471eda5c0c0748454a9cbb48c25ebe4e7fd94e3881b6461" +
"d06e2bce128dc96decb537b8e9611591d445d7dfd3701d25ac05f8d091581aef"
)
}
}

@ -8,7 +8,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
object NamedEntryCollectionTest {
class NamedEntryCollectionTest {
private class TestEntry(
parent: NamedEntryCollection<TestEntry>,
override val id: Int

@ -4,10 +4,7 @@ import java.nio.file.Path
import kotlin.test.Test
import kotlin.test.assertTrue
object StoreTest {
private val DISK_ROOT = Path.of(StoreTest::class.java.getResource("disk-store/empty").toURI())
private val FLAT_FILE_ROOT = Path.of(StoreTest::class.java.getResource("flat-file-store/empty").toURI())
class StoreTest {
@Test
fun testOpen() {
Store.open(DISK_ROOT).use { store ->
@ -18,4 +15,9 @@ object StoreTest {
assertTrue(store is FlatFileStore)
}
}
private companion object {
private val DISK_ROOT = Path.of(StoreTest::class.java.getResource("disk-store/empty").toURI())
private val FLAT_FILE_ROOT = Path.of(StoreTest::class.java.getResource("flat-file-store/empty").toURI())
}
}

@ -7,7 +7,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
object VersionTrailerTest {
class VersionTrailerTest {
@Test
fun testStrip() {
assertNull(VersionTrailer.strip(Unpooled.EMPTY_BUFFER))

@ -5,16 +5,7 @@ import java.nio.ByteOrder
import kotlin.test.Test
import kotlin.test.assertEquals
object IsaacRandomTest {
// test vector from https://burtleburtle.net/bob/rand/randvect.txt
private val ZERO_SEED_VECTOR = readVector("randvect.txt")
// generated by changing randinit(1) to randinit(0) in readable.c
private val NO_SEED_VECTOR = readVector("noseedvect.txt")
// generated with https://burtleburtle.net/bob/c/randtest.c
private val SEED_VECTOR = readVector("seedvect.txt")
class IsaacRandomTest {
@Test
fun testZeroSeed() {
val random = IsaacRandom(IntArray(256))
@ -58,18 +49,29 @@ object IsaacRandomTest {
}
}
private fun readVector(file: String): IntArray {
val input = IsaacRandomTest::class.java.getResourceAsStream("isaac/$file")
return input.bufferedReader().useLines { lines ->
val elements = mutableListOf<Int>()
private companion object {
// test vector from https://burtleburtle.net/bob/rand/randvect.txt
private val ZERO_SEED_VECTOR = readVector("randvect.txt")
// generated by changing randinit(1) to randinit(0) in readable.c
private val NO_SEED_VECTOR = readVector("noseedvect.txt")
for (line in lines) {
for (i in line.indices step 8) {
elements += Integer.parseUnsignedInt(line, i, i + 8, 16)
// generated with https://burtleburtle.net/bob/c/randtest.c
private val SEED_VECTOR = readVector("seedvect.txt")
private fun readVector(file: String): IntArray {
val input = IsaacRandomTest::class.java.getResourceAsStream("isaac/$file")
return input.bufferedReader().useLines { lines ->
val elements = mutableListOf<Int>()
for (line in lines) {
for (i in line.indices step 8) {
elements += Integer.parseUnsignedInt(line, i, i + 8, 16)
}
}
}
elements.toIntArray()
elements.toIntArray()
}
}
}
}

@ -15,37 +15,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
object RsaTest {
private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod"
// example data from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example
private val PUBLIC_KEY = allowUnsafeMod { RSAKeyParameters(false, BigInteger("3233"), BigInteger("17")) }
private val PRIVATE_KEY = allowUnsafeMod { RSAKeyParameters(true, BigInteger("3233"), BigInteger("413")) }
private val PRIVATE_KEY_CRT = allowUnsafeMod {
RSAPrivateCrtKeyParameters(
BigInteger("3233"), // modulus
BigInteger("17"), // public exponent
BigInteger("413"), // private exponent
BigInteger("61"), // p
BigInteger("53"), // q
BigInteger("53"), // dP
BigInteger("49"), // dQ
BigInteger("38") // qInv
)
}
private val PUBLIC_KEY_PEM = listOf(
"-----BEGIN PUBLIC KEY-----",
"MBswDQYJKoZIhvcNAQEBBQADCgAwBwICDKECARE=",
"-----END PUBLIC KEY-----"
)
private val PRIVATE_KEY_PEM = listOf(
"-----BEGIN PRIVATE KEY-----",
"MDMCAQAwDQYJKoZIhvcNAQEBBQAEHzAdAgEAAgIMoQIBEQICAZ0CAT0CATUCATUC",
"ATECASY=",
"-----END PRIVATE KEY-----"
)
class RsaTest {
@Test
fun testGenerateKeyPair() {
val (public, private) = Rsa.generateKeyPair(Rsa.CLIENT_KEY_LENGTH)
@ -160,12 +130,44 @@ object RsaTest {
assertEquals(PUBLIC_KEY.exponent, public.exponent)
}
private fun <T> allowUnsafeMod(f: () -> T): T {
Properties.setThreadOverride(ALLOW_UNSAFE_MOD, true)
try {
return f()
} finally {
Properties.setThreadOverride(ALLOW_UNSAFE_MOD, false)
private companion object {
private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod"
// example data from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example
private val PUBLIC_KEY = allowUnsafeMod { RSAKeyParameters(false, BigInteger("3233"), BigInteger("17")) }
private val PRIVATE_KEY = allowUnsafeMod { RSAKeyParameters(true, BigInteger("3233"), BigInteger("413")) }
private val PRIVATE_KEY_CRT = allowUnsafeMod {
RSAPrivateCrtKeyParameters(
BigInteger("3233"), // modulus
BigInteger("17"), // public exponent
BigInteger("413"), // private exponent
BigInteger("61"), // p
BigInteger("53"), // q
BigInteger("53"), // dP
BigInteger("49"), // dQ
BigInteger("38") // qInv
)
}
private val PUBLIC_KEY_PEM = listOf(
"-----BEGIN PUBLIC KEY-----",
"MBswDQYJKoZIhvcNAQEBBQADCgAwBwICDKECARE=",
"-----END PUBLIC KEY-----"
)
private val PRIVATE_KEY_PEM = listOf(
"-----BEGIN PRIVATE KEY-----",
"MDMCAQAwDQYJKoZIhvcNAQEBBQAEHzAdAgEAAgIMoQIBEQICAZ0CAT0CATUCATUC",
"ATECASY=",
"-----END PRIVATE KEY-----"
)
private fun <T> allowUnsafeMod(f: () -> T): T {
Properties.setThreadOverride(ALLOW_UNSAFE_MOD, true)
try {
return f()
} finally {
Properties.setThreadOverride(ALLOW_UNSAFE_MOD, false)
}
}
}
}

@ -10,76 +10,12 @@ import kotlin.streams.toList
import kotlin.test.Test
import kotlin.test.assertFailsWith
object WhirlpoolTest {
class WhirlpoolTest {
private class IsoTestVector(input: String, expected: String) {
val input = input.toByteArray(Charsets.US_ASCII)
val expected: ByteArray = ByteBufUtil.decodeHexDump(expected)
}
private val ISO_TEST_VECTORS = listOf(
IsoTestVector(
"",
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
),
IsoTestVector(
"a",
"8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42" +
"D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A"
),
IsoTestVector(
"abc",
"4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C" +
"7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5"
),
IsoTestVector(
"message digest",
"378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B" +
"8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E"
),
IsoTestVector(
"abcdefghijklmnopqrstuvwxyz",
"F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B" +
"08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B"
),
IsoTestVector(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E" +
"08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467"
),
IsoTestVector(
"1234567890".repeat(8),
"466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB601429" +
"4D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B"
),
IsoTestVector(
"abcdbcdecdefdefgefghfghighijhijk",
"2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C69" +
"16BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD"
),
IsoTestVector(
"a".repeat(1000000),
"0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF5" +
"1FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01"
)
)
private val NESSIE_ZERO_VECTORS = readVectors("nessie-zero-vectors.txt")
private val NESSIE_ONE_VECTORS = readVectors("nessie-one-vectors.txt")
private val QUICK_BROWN_FOX = ByteBufUtil.decodeHexDump(
"B97DE512E91E3828B40D2B0FDCE9CEB3C4A71F9BEA8D88E75C4FA854DF36725F" +
"D2B52EB6544EDCACD6F8BEDDFEA403CB55AE31F03AD62A5EF54E42EE82C3FB35"
)
private fun readVectors(file: String): List<ByteArray> {
val input = WhirlpoolTest::class.java.getResourceAsStream("whirlpool/$file")
return input.bufferedReader().use { reader ->
reader.lines()
.map(ByteBufUtil::decodeHexDump)
.toList()
}
}
@Test
fun testIsoVectors() {
for (vector in ISO_TEST_VECTORS) {
@ -163,4 +99,70 @@ object WhirlpoolTest {
Unpooled.EMPTY_BUFFER.whirlpool(0, 1)
}
}
private companion object {
private val ISO_TEST_VECTORS = listOf(
IsoTestVector(
"",
"19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" +
"3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3"
),
IsoTestVector(
"a",
"8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42" +
"D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A"
),
IsoTestVector(
"abc",
"4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C" +
"7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5"
),
IsoTestVector(
"message digest",
"378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B" +
"8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E"
),
IsoTestVector(
"abcdefghijklmnopqrstuvwxyz",
"F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B" +
"08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B"
),
IsoTestVector(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E" +
"08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467"
),
IsoTestVector(
"1234567890".repeat(8),
"466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB601429" +
"4D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B"
),
IsoTestVector(
"abcdbcdecdefdefgefghfghighijhijk",
"2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C69" +
"16BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD"
),
IsoTestVector(
"a".repeat(1000000),
"0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF5" +
"1FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01"
)
)
private val NESSIE_ZERO_VECTORS = readVectors("nessie-zero-vectors.txt")
private val NESSIE_ONE_VECTORS = readVectors("nessie-one-vectors.txt")
private val QUICK_BROWN_FOX = ByteBufUtil.decodeHexDump(
"B97DE512E91E3828B40D2B0FDCE9CEB3C4A71F9BEA8D88E75C4FA854DF36725F" +
"D2B52EB6544EDCACD6F8BEDDFEA403CB55AE31F03AD62A5EF54E42EE82C3FB35"
)
private fun readVectors(file: String): List<ByteArray> {
val input = WhirlpoolTest::class.java.getResourceAsStream("whirlpool/$file")
return input.bufferedReader().use { reader ->
reader.lines()
.map(ByteBufUtil::decodeHexDump)
.toList()
}
}
}
}

@ -6,32 +6,13 @@ import org.openrs2.buffer.use
import kotlin.test.Test
import kotlin.test.assertEquals
object XteaTest {
class XteaTest {
private class TestVector(key: String, plaintext: String, ciphertext: String) {
val key = XteaKey.fromHex(key)
val plaintext: ByteArray = ByteBufUtil.decodeHexDump(plaintext)
val ciphertext: ByteArray = ByteBufUtil.decodeHexDump(ciphertext)
}
private val TEST_VECTORS = listOf(
// empty
TestVector("00000000000000000000000000000000", "", ""),
// standard single block test vectors
TestVector("000102030405060708090a0b0c0d0e0f", "4142434445464748", "497df3d072612cb5"),
TestVector("000102030405060708090a0b0c0d0e0f", "4141414141414141", "e78f2d13744341d8"),
TestVector("000102030405060708090a0b0c0d0e0f", "5a5b6e278948d77f", "4141414141414141"),
TestVector("00000000000000000000000000000000", "4142434445464748", "a0390589f8b8efa5"),
TestVector("00000000000000000000000000000000", "4141414141414141", "ed23375a821a8c2d"),
TestVector("00000000000000000000000000000000", "70e1225d6e4e7655", "4141414141414141"),
// two blocks
TestVector(
"00000000000000000000000000000000", "70e1225d6e4e76554141414141414141",
"4141414141414141ed23375a821a8c2d"
)
)
@Test
fun testEncrypt() {
for (vector in TEST_VECTORS) {
@ -71,4 +52,25 @@ object XteaTest {
}
}
}
private companion object {
private val TEST_VECTORS = listOf(
// empty
TestVector("00000000000000000000000000000000", "", ""),
// standard single block test vectors
TestVector("000102030405060708090a0b0c0d0e0f", "4142434445464748", "497df3d072612cb5"),
TestVector("000102030405060708090a0b0c0d0e0f", "4141414141414141", "e78f2d13744341d8"),
TestVector("000102030405060708090a0b0c0d0e0f", "5a5b6e278948d77f", "4141414141414141"),
TestVector("00000000000000000000000000000000", "4142434445464748", "a0390589f8b8efa5"),
TestVector("00000000000000000000000000000000", "4141414141414141", "ed23375a821a8c2d"),
TestVector("00000000000000000000000000000000", "70e1225d6e4e7655", "4141414141414141"),
// two blocks
TestVector(
"00000000000000000000000000000000", "70e1225d6e4e76554141414141414141",
"4141414141414141ed23375a821a8c2d"
)
)
}
}

@ -4,7 +4,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object BackoffStrategyTest {
class BackoffStrategyTest {
@Test
fun testFixedBackoff() {
val strategy = FixedBackoffStrategy(1000)

@ -10,7 +10,7 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ExperimentalCoroutinesApi
object DatabaseTest {
class DatabaseTest {
private class TestException : Exception {
constructor() : super()
constructor(cause: Throwable) : super(cause)
@ -19,20 +19,6 @@ object DatabaseTest {
private class DeadlockException : SQLException(null, null, 40001)
private class NonDeadlockException : SQLException()
private const val DELAY = 10L
private const val ATTEMPTS = 5
private val dataSource = JdbcDataSource().apply {
setUrl("jdbc:h2:mem:")
}
private val database = Database(
dataSource,
deadlockDetector = H2DeadlockDetector,
backoffStrategy = FixedBackoffStrategy(DELAY),
attempts = ATTEMPTS
)
@Test
fun testBounds() {
assertFailsWith<IllegalArgumentException> {
@ -182,4 +168,20 @@ object DatabaseTest {
assertEquals(1, attempts)
}
private companion object {
private const val DELAY = 10L
private const val ATTEMPTS = 5
private val dataSource = JdbcDataSource().apply {
setUrl("jdbc:h2:mem:")
}
private val database = Database(
dataSource,
deadlockDetector = H2DeadlockDetector,
backoffStrategy = FixedBackoffStrategy(DELAY),
attempts = ATTEMPTS
)
}
}

@ -5,7 +5,7 @@ import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
object DeadlockDetectorTest {
class DeadlockDetectorTest {
@Test
fun testDefault() {
assertTrue(DefaultDeadlockDetector.isDeadlock(SQLException()))

@ -8,7 +8,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Rs2DecoderTest {
class Rs2DecoderTest {
@Test
fun testDecode() {
testDecode(byteArrayOf(0, 0x11, 0x22, 0x33, 0x44), FixedPacket(0x11223344))

@ -10,7 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Rs2EncoderTest {
class Rs2EncoderTest {
@Test
fun testEncode() {
testEncode(FixedPacket(0x11223344), byteArrayOf(0, 0x11, 0x22, 0x33, 0x44))

@ -6,7 +6,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object JaggrabRequestDecoderTest {
class JaggrabRequestDecoderTest {
@Test
fun testDecode() {
val channel = EmbeddedChannel(JaggrabRequestDecoder)

@ -4,7 +4,7 @@ import io.netty.channel.embedded.EmbeddedChannel
import kotlin.test.Test
import kotlin.test.assertEquals
object JaggrabRequestEncoderTest {
class JaggrabRequestEncoderTest {
@Test
fun testEncode() {
val channel = EmbeddedChannel(JaggrabRequestEncoder)

@ -8,7 +8,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Js5RequestDecoderTest {
class Js5RequestDecoderTest {
@Test
fun testDecode() {
testDecode(byteArrayOf(0, 2, 0, 3), Js5Request.Group(true, 2, 3))

@ -7,7 +7,7 @@ import org.openrs2.buffer.use
import kotlin.test.Test
import kotlin.test.assertEquals
object Js5RequestEncoderTest {
class Js5RequestEncoderTest {
@Test
fun testEncode() {
testEncode(Js5Request.Group(true, 2, 3), byteArrayOf(0, 2, 0, 3))

@ -11,7 +11,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Js5ResponseDecoderTest {
class Js5ResponseDecoderTest {
@Test
fun testDecode() {
testDecode("509.dat", "509-prefetch.dat", true)

@ -9,7 +9,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object Js5ResponseEncoderTest {
class Js5ResponseEncoderTest {
@Test
fun testEncode() {
testEncode("509.dat", "509-prefetch.dat", true)

@ -8,7 +8,7 @@ import org.openrs2.buffer.use
import kotlin.test.Test
import kotlin.test.assertEquals
object XorDecoderTest {
class XorDecoderTest {
@Test
fun testDecode() {
testDecode(0, "OpenRS2", false)

@ -8,7 +8,7 @@ import org.openrs2.buffer.use
import kotlin.test.Test
import kotlin.test.assertEquals
object XorEncoderTest {
class XorEncoderTest {
@Test
fun testEncode() {
testEncode(0, "OpenRS2", false)

@ -4,7 +4,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
object StringUtilsTest {
class StringUtilsTest {
@Test
fun testIndefiniteArticle() {
assertEquals("a", "book".indefiniteArticle())

@ -6,7 +6,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
object Cp1252CharsetTest {
class Cp1252CharsetTest {
@Test
fun testEncodeChar() {
// edge cases

@ -5,7 +5,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
object ModifiedUtf8CharsetTest {
class ModifiedUtf8CharsetTest {
@Test
fun testEncode() {
assertArrayEquals(byteArrayOf(0xC0.toByte(), 0x80.toByte()), "\u0000".toByteArray(ModifiedUtf8Charset))

@ -5,7 +5,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
object ForestDisjointSetTest {
class ForestDisjointSetTest {
@Test
fun testAdd() {
val set = ForestDisjointSet<Int>()

@ -7,7 +7,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
object IterableUtilsTest {
class IterableUtilsTest {
@Test
fun testRemoveFirst() {
val list = mutableListOf(1, 2, 3)

@ -12,9 +12,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
object DeterministicJarOutputStreamTest {
private val UNIX_EPOCH = FileTime.fromMillis(0)
private val Y2K = FileTime.fromMillis(946684800)
class DeterministicJarOutputStreamTest {
private val manifest = Manifest().apply {
mainAttributes[Attributes.Name.MANIFEST_VERSION] = "1.0"
mainAttributes[Attributes.Name.MAIN_CLASS] = "Hello"
@ -60,4 +58,9 @@ object DeterministicJarOutputStreamTest {
}
}
}
private companion object {
private val UNIX_EPOCH = FileTime.fromMillis(0)
private val Y2K = FileTime.fromMillis(946684800)
}
}

@ -7,7 +7,7 @@ import java.io.OutputStream
import kotlin.test.Test
import kotlin.test.assertTrue
object SkipOutputStreamTest {
class SkipOutputStreamTest {
@Test
fun testSkipBytes() {
for (n in 0..5) {

Loading…
Cancel
Save