From 6f7350afa3070a577ff685b704f137dc05662f27 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 3 Apr 2022 21:51:14 +0100 Subject: [PATCH] Fix JagArchive tests if libbzip2 is available Signed-off-by: Graham --- .../org/openrs2/cache/JagArchiveTest.kt | 65 +++++++++++------- ... => duplicate-entries-commonscompress.jag} | Bin .../cache/jag/duplicate-entries-libbzip2.jag | Bin 0 -> 64 bytes .../openrs2/cache/jag/duplicate-entries.jag | Bin 113 -> 0 bytes ...ty-compressed-archive-commonscompress.jag} | Bin .../jag/empty-compressed-archive-libbzip2.jag | Bin 0 -> 39 bytes ...ty-compressed-entries-commonscompress.jag} | Bin .../jag/empty-compressed-entries-libbzip2.jag | Bin 0 -> 8 bytes ...le-compressed-archive-commonscompress.jag} | Bin .../multiple-compressed-archive-libbzip2.jag | Bin 0 -> 88 bytes ...le-compressed-entries-commonscompress.jag} | Bin .../multiple-compressed-entries-libbzip2.jag | Bin 0 -> 113 bytes ...le-compressed-archive-commonscompress.jag} | Bin .../single-compressed-archive-libbzip2.jag | Bin 0 -> 68 bytes ...gle-compressed-entries-commonscompress.jag | Bin 0 -> 64 bytes .../single-compressed-entries-libbzip2.jag | Bin 0 -> 64 bytes 16 files changed, 42 insertions(+), 23 deletions(-) rename cache/src/test/resources/org/openrs2/cache/jag/{single-compressed-entries.jag => duplicate-entries-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-libbzip2.jag delete mode 100644 cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries.jag rename cache/src/test/resources/org/openrs2/cache/jag/{empty-compressed-archive.jag => empty-compressed-archive-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-libbzip2.jag rename cache/src/test/resources/org/openrs2/cache/jag/{empty-compressed-entries.jag => empty-compressed-entries-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-libbzip2.jag rename cache/src/test/resources/org/openrs2/cache/jag/{multiple-compressed-archive.jag => multiple-compressed-archive-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-libbzip2.jag rename cache/src/test/resources/org/openrs2/cache/jag/{multiple-compressed-entries.jag => multiple-compressed-entries-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-libbzip2.jag rename cache/src/test/resources/org/openrs2/cache/jag/{single-compressed-archive.jag => single-compressed-archive-commonscompress.jag} (100%) create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/single-compressed-archive-libbzip2.jag create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-commonscompress.jag create mode 100644 cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-libbzip2.jag diff --git a/cache/src/test/kotlin/org/openrs2/cache/JagArchiveTest.kt b/cache/src/test/kotlin/org/openrs2/cache/JagArchiveTest.kt index 71740ce0..5e4fefa1 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/JagArchiveTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/JagArchiveTest.kt @@ -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 -> - archive.pack(compressedArchive).use { actual -> - assertEquals(expected, actual) + 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 -> + assertTrue(expectedSoftware == actual || expectedNative == actual) + } } } } private fun packBestTest(name: String, archive: JagArchive) { - Unpooled.wrappedBuffer(Files.readAllBytes(ROOT.resolve(name))).use { expected -> - archive.packBest().use { actual -> - assertEquals(expected, actual) + 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 -> + 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) } diff --git a/cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries.jag b/cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-commonscompress.jag similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries.jag rename to cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-commonscompress.jag diff --git a/cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..7a0beb97d2968489cc9d38164a7851cba3405a7c GIT binary patch literal 64 zcmZQzuwnor#>=PvUt(ZjXJF7Xbc|FBj%<%f&Sqd>=x-1Jk~0{X7#$cC7?h-v1KJo@ RGkh#p32x=&C_QGj0RZ7v5I6t; literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries.jag b/cache/src/test/resources/org/openrs2/cache/jag/duplicate-entries.jag deleted file mode 100644 index 2b23b63e47291d83940cb386d47fcb7cb0e5fdff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 113 zcmZQz$YuZ{rpu@PUt(ZjXJF8Suvi%w)D0aY)q*42W0HYN82TFofaDAYCPoJa1qMSN zMqa}eR~ssJPtrWp(qi>kIs&3vDkNnRP#sXa0~5;v27|LElFK@09=$WsPeg@ns-#K- E0Pr;+O#lD@ diff --git a/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive.jag b/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-commonscompress.jag similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive.jag rename to cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-commonscompress.jag diff --git a/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-archive-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..e1bb695c808c9afa1aa579097acb7fe2149bbc3f GIT binary patch literal 39 vcmZQzU}9iUG<1wq3y%EnF}sO@f#Cpy1A_vCqJ-O_cOJ{Rgydfe7dQX_uA~Y| literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries.jag b/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-commonscompress.jag similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries.jag rename to cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-commonscompress.jag diff --git a/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/empty-compressed-entries-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..3017d3b83e8bc43df51e04d3a8417a716a3d1c6c GIT binary patch literal 8 McmZQzU}69v000^Q1poj5 literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive.jag b/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-commonscompress.jag similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive.jag rename to cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-commonscompress.jag diff --git a/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-archive-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..e4681875457bbcfa036ed22d0ad4785175310322 GIT binary patch literal 88 zcmV-e0H^-|03rYYQZYeUCR14-tYrxR00M8P(trd25C8x`m;eF=zyJUN01y}eKmY&; upa3G802*oPX`x1pful@~5+Z3gxypF2He-N@1!Zox#oUoj6eI`h8A3pvzZq@- literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries.jag b/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-commonscompress.jag similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries.jag rename to cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-commonscompress.jag diff --git a/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/multiple-compressed-entries-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..c55b0cc7c23b0d8ab242fd1058af70c42f338bb5 GIT binary patch literal 113 zcmZQz$YuZ{rpu@PUt(ZjXJF9#{Xk?M0|P4qgSw$(q*`!fdrUG=2}6H_0Fa!)z{Kdl zpunIcl^oEefziM1L4yDT1H%jkCPoJa1_22mdjW$I=Zjgkj0_AK X79kV=3+3yZ#GVv+=;UO6{bB(CD_#<- literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-commonscompress.jag b/cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-commonscompress.jag new file mode 100644 index 0000000000000000000000000000000000000000..6beb638a572e944a8f3503e3bf0392d3efe79fe8 GIT binary patch literal 64 zcmZQzuwnor#>=PvUt(ZjXJF7Xbc|FBj%<%f&Sqd>=x-1Jk~0{X7#$cC7z}wBc@0-w RZK&8iN%K%ki`8T42mt8k5kdd} literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-libbzip2.jag b/cache/src/test/resources/org/openrs2/cache/jag/single-compressed-entries-libbzip2.jag new file mode 100644 index 0000000000000000000000000000000000000000..7a0beb97d2968489cc9d38164a7851cba3405a7c GIT binary patch literal 64 zcmZQzuwnor#>=PvUt(ZjXJF7Xbc|FBj%<%f&Sqd>=x-1Jk~0{X7#$cC7?h-v1KJo@ RGkh#p32x=&C_QGj0RZ7v5I6t; literal 0 HcmV?d00001