Fix JagArchive tests if libbzip2 is available

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 3 years ago
parent 078b1f6197
commit 6f7350afa3
  1. 61
      cache/src/test/kotlin/org/openrs2/cache/JagArchiveTest.kt
  2. 0
      cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-commonscompress.jag
  3. BIN
      cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-libbzip2.jag
  4. BIN
      cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries.jag
  5. 0
      cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-commonscompress.jag
  6. BIN
      cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-libbzip2.jag
  7. 0
      cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-commonscompress.jag
  8. BIN
      cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-libbzip2.jag
  9. 0
      cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-commonscompress.jag
  10. BIN
      cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-libbzip2.jag
  11. 0
      cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-commonscompress.jag
  12. BIN
      cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-libbzip2.jag
  13. 0
      cache/src/test/resources/org/openrs2/cache/jag/single-compressed-archive-commonscompress.jag
  14. BIN
      cache/src/test/resources/org/openrs2/cache/jag/single-compressed-archive-libbzip2.jag
  15. BIN
      cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-commonscompress.jag
  16. BIN
      cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-libbzip2.jag

@ -18,12 +18,12 @@ class JagArchiveTest {
assertEquals(0, archive.size)
assertEquals(emptyList(), archive.list().asSequence().toList())
packTest("empty-compressed-archive.jag", archive, true)
packTest("empty-compressed-entries.jag", archive, false)
packBestTest("empty-compressed-entries.jag", archive)
packTest("empty-compressed-archive", archive, true)
packTest("empty-compressed-entries", archive, false)
packBestTest("empty-compressed-entries", archive)
unpackTest("empty-compressed-archive.jag", archive)
unpackTest("empty-compressed-entries.jag", archive)
unpackTest("empty-compressed-archive", archive)
unpackTest("empty-compressed-entries", archive)
}
}
@ -54,12 +54,12 @@ class JagArchiveTest {
assertFalse(archive.exists("HELLO.TXT"))
assertFalse(archive.existsNamed("HELLO.TXT".jagHashCode()))
packTest("single-compressed-archive.jag", archive, true)
packTest("single-compressed-entries.jag", archive, false)
packBestTest("single-compressed-entries.jag", archive)
packTest("single-compressed-archive", archive, true)
packTest("single-compressed-entries", archive, false)
packBestTest("single-compressed-entries", archive)
unpackTest("single-compressed-archive.jag", archive)
unpackTest("single-compressed-entries.jag", archive)
unpackTest("single-compressed-archive", archive)
unpackTest("single-compressed-entries", archive)
}
}
@ -111,12 +111,12 @@ class JagArchiveTest {
assertFalse(archive.exists("OTHER.TXT"))
assertFalse(archive.existsNamed("OTHER.TXT".jagHashCode()))
packTest("multiple-compressed-archive.jag", archive, true)
packTest("multiple-compressed-entries.jag", archive, false)
packBestTest("multiple-compressed-archive.jag", archive)
packTest("multiple-compressed-archive", archive, true)
packTest("multiple-compressed-entries", archive, false)
packBestTest("multiple-compressed-archive", archive)
unpackTest("multiple-compressed-archive.jag", archive)
unpackTest("multiple-compressed-entries.jag", archive)
unpackTest("multiple-compressed-archive", archive)
unpackTest("multiple-compressed-entries", archive)
archive.remove("TEST.TXT")
@ -164,28 +164,47 @@ class JagArchiveTest {
archive.write("TEST.TXT", buf)
}
unpackTest("duplicate-entries.jag", archive)
unpackTest("duplicate-entries", archive)
}
}
private fun packTest(name: String, archive: JagArchive, compressedArchive: Boolean) {
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(name))).use { expected ->
val softwareName = "$name-commonscompress.jag"
val nativeName = "$name-libbzip2.jag"
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(softwareName))).use { expectedSoftware ->
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(nativeName))).use { expectedNative ->
archive.pack(compressedArchive).use { actual ->
assertEquals(expected, actual)
assertTrue(expectedSoftware == actual || expectedNative == actual)
}
}
}
}
private fun packBestTest(name: String, archive: JagArchive) {
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(name))).use { expected ->
val softwareName = "$name-commonscompress.jag"
val nativeName = "$name-libbzip2.jag"
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(softwareName))).use { expectedSoftware ->
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(nativeName))).use { expectedNative ->
archive.packBest().use { actual ->
assertEquals(expected, actual)
assertTrue(expectedSoftware == actual || expectedNative == actual)
}
}
}
}
private fun unpackTest(name: String, expected: JagArchive) {
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(name))).use { buf ->
val softwareName = "$name-commonscompress.jag"
val nativeName = "$name-libbzip2.jag"
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(softwareName))).use { buf ->
JagArchive.unpack(buf).use { actual ->
assertEquals(expected, actual)
}
}
Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(nativeName))).use { buf ->
JagArchive.unpack(buf).use { actual ->
assertEquals(expected, actual)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 B

Loading…
Cancel
Save