[Tests] Enforce uniform code style

All auxiliary functions are private instance, don't use `self.` to refer to properties or functions.
This commit is contained in:
Timofey Solomko committed 2026-06-27 17:46:34 +08:00
1 parent 74846cdf84
commit 2ef1453b40
16 files changed
+211 -209

No files matched your search

@@ -9,7 +9,7 @@ import SWCompression
struct BZip2CompressionTests {
func answerTest(_ testName: String) throws {
private func answerTest(_ testName: String) throws {
let answerData = try Constants.data(forAnswer: testName)
let compressedData = BZip2.compress(data: answerData)
let redecompressedData = try BZip2.decompress(data: compressedData)
@@ -20,7 +20,7 @@ struct BZip2CompressionTests {
}
}
func stringTest(_ string: String) throws {
private func stringTest(_ string: String) throws {
let answerData = Data(string.utf8)
let compressedData = BZip2.compress(data: answerData)
+19 -19
View File
@@ -9,10 +9,10 @@ import SWCompression
struct BZip2Tests {
private static let testType: String = "bz2"
private let testType: String = "bz2"
func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
private func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let decompressedData = try BZip2.decompress(data: testData)
let answerData = try Constants.data(forAnswer: testName)
@@ -20,44 +20,44 @@ struct BZip2Tests {
}
@Test func test1() throws {
try self.perform(test: "test1")
try perform(test: "test1")
}
@Test func test2() throws {
try self.perform(test: "test2")
try perform(test: "test2")
}
@Test func test3() throws {
try self.perform(test: "test3")
try perform(test: "test3")
}
@Test func test4() throws {
try self.perform(test: "test4")
try perform(test: "test4")
}
@Test func test5() throws {
try self.perform(test: "test5")
try perform(test: "test5")
}
@Test func test6() throws {
try self.perform(test: "test6")
try perform(test: "test6")
}
@Test func test7() throws {
try self.perform(test: "test7")
try perform(test: "test7")
}
@Test func test8() throws {
try self.perform(test: "test8")
try perform(test: "test8")
}
@Test func test9() throws {
try self.perform(test: "test9")
try perform(test: "test9")
}
@Test(.bug("https://github.com/tsolomko/SWCompression/issues/21", id: 21))
func nonStandardRunLength() throws {
try self.perform(test: "test_nonstandard_runlength")
try perform(test: "test_nonstandard_runlength")
}
@Test func shortInput() {
@@ -72,7 +72,7 @@ struct BZip2Tests {
@Test func truncatedInput() throws {
// This tests that encountering data truncated in the middle of a Huffman symbol correctly throws an error
// (and doesn't crash).
let testData = try Constants.data(forTest: "test1", withType: BZip2Tests.testType)[0...40]
let testData = try Constants.data(forTest: "test1", withType: testType)[0...40]
#expect(throws: (any Error).self) { try BZip2.decompress(data: testData) }
}
@@ -84,7 +84,7 @@ struct BZip2Tests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test1", withType: BZip2Tests.testType)
var testData = try Constants.data(forTest: "test1", withType: testType)
// The checksum is the last 4 bytes.
testData[testData.endIndex - 2] &+= 1
#if compiler(>=6.1)
@@ -112,7 +112,7 @@ struct BZip2Tests {
// is no #expect in this test.
for i in 1...9 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
// It would be better to increase amount of different truncations tested, but we hit runtime limits in CI.
for _ in 0..<5 {
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
@@ -125,7 +125,7 @@ struct BZip2Tests {
var input = Data()
for i in 1...5 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
input.append(testData)
}
let output = try BZip2.multiDecompress(data: input)
@@ -139,7 +139,7 @@ struct BZip2Tests {
@Test func multiDecompressSingleArchive() throws {
for i in 1...5 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
let answerData = try Constants.data(forAnswer: testName)
let output = try BZip2.multiDecompress(data: testData)
#expect(output.first! == answerData)
@@ -153,7 +153,7 @@ struct BZip2Tests {
var input = Data()
for i in 1...5 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
input.append(testData)
}
for _ in 0..<5 {
+2 -1
View File
@@ -5,7 +5,8 @@
import Foundation
class Constants {
// Has to be a class for `Bundle(for:)` to work.
final class Constants {
/* Contents of test files:
- test1: text file with "Hello, World!\n".
@@ -9,7 +9,7 @@ import SWCompression
struct DeflateCompressionTests {
func answerTest(_ testName: String) throws {
private func answerTest(_ testName: String) throws {
let answerData = try Constants.data(forAnswer: testName)
let compressedData = Deflate.compress(data: answerData)
let redecompressedData = try Deflate.decompress(data: compressedData)
@@ -20,7 +20,7 @@ struct DeflateCompressionTests {
}
}
func stringTest(_ string: String) throws {
private func stringTest(_ string: String) throws {
let answerData = Data(string.utf8)
let compressedData = Deflate.compress(data: answerData)
let redecompressedData = try Deflate.decompress(data: compressedData)
@@ -40,39 +40,39 @@ struct DeflateCompressionTests {
}
@Test func answer1() throws {
try self.answerTest("test1")
try answerTest("test1")
}
@Test func answer2() throws {
try self.answerTest("test2")
try answerTest("test2")
}
@Test func answer3() throws {
try self.answerTest("test3")
try answerTest("test3")
}
@Test func answer4() throws {
try self.answerTest("test4")
try answerTest("test4")
}
@Test func answer5() throws {
try self.answerTest("test5")
try answerTest("test5")
}
@Test func answer6() throws {
try self.answerTest("test6")
try answerTest("test6")
}
@Test func answer7() throws {
try self.answerTest("test7")
try answerTest("test7")
}
@Test func answer8() throws {
try self.answerTest("test8")
try answerTest("test8")
}
@Test func answer9() throws {
try self.answerTest("test9")
try answerTest("test9")
}
@Test func trickySequence() throws {
+2 -2
View File
@@ -10,7 +10,7 @@ import SWCompression
struct DeflateTests {
private static let testType: String = "deflate"
private let testType: String = "deflate"
@Test func randomInputTruncations() throws {
// In this test we check that there is no crash when dealing with the truncation in the middle of the Deflate
@@ -24,7 +24,7 @@ struct DeflateTests {
// test9 contains uncompressed Deflate block.
for testName in ["test6", "test8", "test9"] {
let testData = try Constants.data(forTest: testName, withType: DeflateTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
for _ in 0..<10 {
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
#expect(throws: (any Error).self, "No error thrown, \(testName), truncationIndex=\(truncationIndex)") {
+33 -33
View File
@@ -9,10 +9,10 @@ import SWCompression
struct GzipTests {
private static let testType: String = "gz"
private let testType: String = "gz"
func header(test testName: String, mtime: Int) throws {
let testData = try Constants.data(forTest: testName, withType: GzipTests.testType)
private func header(test testName: String, mtime: Int) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let testGzipHeader = try GzipHeader(archive: testData)
#expect(testGzipHeader.compressionMethod == .deflate)
@@ -23,15 +23,15 @@ struct GzipTests {
#expect(testGzipHeader.extraFields.isEmpty)
}
func unarchive(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: GzipTests.testType)
private func unarchive(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let decompressedData = try GzipArchive.unarchive(archive: testData)
let answerData = try Constants.data(forAnswer: testName)
#expect(decompressedData == answerData)
}
func archive(test testName: String) throws {
private func archive(test testName: String) throws {
let answerData = try Constants.data(forAnswer: testName)
// Options for archiving.
@@ -75,27 +75,27 @@ struct GzipTests {
}
@Test func test1() throws {
try self.header(test: "test1", mtime: 1482698300)
try self.unarchive(test: "test1")
try header(test: "test1", mtime: 1482698300)
try unarchive(test: "test1")
}
@Test func test2() throws {
try self.header(test: "test2", mtime: 1482698300)
try self.unarchive(test: "test2")
try header(test: "test2", mtime: 1482698300)
try unarchive(test: "test2")
}
@Test func test3() throws {
try self.header(test: "test3", mtime: 1482698301)
try self.unarchive(test: "test3")
try header(test: "test3", mtime: 1482698301)
try unarchive(test: "test3")
}
@Test func test4() throws {
try self.header(test: "test4", mtime: 1482698301)
try self.unarchive(test: "test4")
try header(test: "test4", mtime: 1482698301)
try unarchive(test: "test4")
}
@Test func test4ExtraField() throws {
let testData = try Constants.data(forTest: "test4_extra_field", withType: GzipTests.testType)
let testData = try Constants.data(forTest: "test4_extra_field", withType: testType)
let testGzipHeader = try GzipHeader(archive: testData)
#expect(testGzipHeader.compressionMethod == .deflate)
@@ -113,36 +113,36 @@ struct GzipTests {
}
@Test func test5() throws {
try self.header(test: "test5", mtime: 1482698242)
try self.unarchive(test: "test5")
try header(test: "test5", mtime: 1482698242)
try unarchive(test: "test5")
}
@Test func test6() throws {
try self.header(test: "test6", mtime: 1511554495)
try self.unarchive(test: "test6")
try header(test: "test6", mtime: 1511554495)
try unarchive(test: "test6")
}
@Test func test7() throws {
try self.header(test: "test7", mtime: 1511554611)
try self.unarchive(test: "test7")
try header(test: "test7", mtime: 1511554611)
try unarchive(test: "test7")
}
@Test func test8() throws {
try self.header(test: "test8", mtime: 1483040005)
try self.unarchive(test: "test8")
try header(test: "test8", mtime: 1483040005)
try unarchive(test: "test8")
}
@Test func test9() throws {
try self.header(test: "test9", mtime: 1483040005)
try self.unarchive(test: "test9")
try header(test: "test9", mtime: 1483040005)
try unarchive(test: "test9")
}
@Test func archive4() throws {
try self.archive(test: "test4")
try archive(test: "test4")
}
@Test func multiUnarchive() throws {
let testData = try Constants.data(forTest: "test_multi", withType: GzipTests.testType)
let testData = try Constants.data(forTest: "test_multi", withType: testType)
let members = try GzipArchive.multiUnarchive(archive: testData)
try #require(members.count == 4)
@@ -158,7 +158,7 @@ struct GzipTests {
}
@Test func multiUnarchiveRedundant() throws {
let testData = try Constants.data(forTest: "test1", withType: GzipTests.testType)
let testData = try Constants.data(forTest: "test1", withType: testType)
let members = try GzipArchive.multiUnarchive(archive: testData)
try #require(members.count == 1)
@@ -191,7 +191,7 @@ struct GzipTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test1", withType: GzipTests.testType)
var testData = try Constants.data(forTest: "test1", withType: testType)
// Here we modify the stored value of crc32.
testData[41] &+= 1
#if compiler(>=6.1)
@@ -218,7 +218,7 @@ struct GzipTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test_multi", withType: GzipTests.testType)
var testData = try Constants.data(forTest: "test_multi", withType: testType)
// Here we modify the stored value of crc32.
testData[2289] &+= 1
#if compiler(>=6.1)
@@ -249,7 +249,7 @@ struct GzipTests {
// - that the archive consisting only of the minimal header is successfully processed,
// - that the mtime field with the value 0 correctly results in a `GzipHeader.modificationTime == nil`,
// - that the `GzipArchive.multiUnarchive(archive:)` works on a single member archive.
let testData = try Constants.data(forTest: "minimal", withType: GzipTests.testType)
let testData = try Constants.data(forTest: "minimal", withType: testType)
let members = try GzipArchive.multiUnarchive(archive: testData)
try #require(members.count == 1)
if let member = members.first {
@@ -267,7 +267,7 @@ struct GzipTests {
// In this test we check the handling of truncation inside the optional elements (name, comment, "extra field",
// crc) of a GZip header, as well as in the "checksum" information of the archive (last 8 bytes). The sample
// file used is "test4_extra_field" since it contains a header which utilizes all format features.
let testData = try Constants.data(forTest: "test4_extra_field", withType: GzipTests.testType)
let testData = try Constants.data(forTest: "test4_extra_field", withType: testType)
// We test all possible truncation points since there are very few of them.
// The header takes first 79 bytes.
@@ -288,7 +288,7 @@ struct GzipTests {
@Test func randomInputTruncations() throws {
for i in 1...9 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: GzipTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
// It would be better to increase amount of different truncations tested, but we hit runtime limits in CI.
for _ in 0..<5 {
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
@@ -9,7 +9,7 @@ import SWCompression
struct LZ4CompressionTests {
func answerTest(_ testName: String) throws {
private func answerTest(_ testName: String) throws {
let answerData = try Constants.data(forAnswer: testName)
let compressedData = LZ4.compress(data: answerData)
let redecompressedData = try LZ4.decompress(data: compressedData)
@@ -20,7 +20,7 @@ struct LZ4CompressionTests {
}
}
func stringTest(_ string: String) throws {
private func stringTest(_ string: String) throws {
let answerData = Data(string.utf8)
let compressedData = LZ4.compress(data: answerData)
let redecompressedData = try LZ4.decompress(data: compressedData)
+35 -35
View File
@@ -9,21 +9,21 @@ import SWCompression
struct LZ4Tests {
private static let testType: String = "lz4"
private let testType: String = "lz4"
// These tests test frames with independent blocks (since they all have only one block). The frames also have
// additional features enabled, such as content size and block checksums. They also test legacy frame format.
func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: LZ4Tests.testType)
private func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
let answerData = try Constants.data(forAnswer: testName)
#expect(decompressedData == answerData)
}
private static func perform(legacyTest testName: String) throws {
let testData = try Constants.data(forTest: testName + "_legacy", withType: LZ4Tests.testType)
private func perform(legacyTest testName: String) throws {
let testData = try Constants.data(forTest: testName + "_legacy", withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
let answerData = try Constants.data(forAnswer: testName)
@@ -31,54 +31,54 @@ struct LZ4Tests {
}
@Test func test1() throws {
try self.perform(test: "test1")
try LZ4Tests.perform(legacyTest: "test1")
try perform(test: "test1")
try perform(legacyTest: "test1")
}
@Test func test2() throws {
try self.perform(test: "test2")
try LZ4Tests.perform(legacyTest: "test2")
try perform(test: "test2")
try perform(legacyTest: "test2")
}
@Test func test3() throws {
try self.perform(test: "test3")
try LZ4Tests.perform(legacyTest: "test3")
try perform(test: "test3")
try perform(legacyTest: "test3")
}
@Test func test4() throws {
try self.perform(test: "test4")
try LZ4Tests.perform(legacyTest: "test4")
try perform(test: "test4")
try perform(legacyTest: "test4")
}
@Test func test5() throws {
try self.perform(test: "test5")
try LZ4Tests.perform(legacyTest: "test5")
try perform(test: "test5")
try perform(legacyTest: "test5")
}
@Test func test6() throws {
try self.perform(test: "test6")
try LZ4Tests.perform(legacyTest: "test6")
try perform(test: "test6")
try perform(legacyTest: "test6")
}
@Test func test7() throws {
try self.perform(test: "test7")
try LZ4Tests.perform(legacyTest: "test7")
try perform(test: "test7")
try perform(legacyTest: "test7")
}
@Test func test8() throws {
try self.perform(test: "test8")
try LZ4Tests.perform(legacyTest: "test8")
try perform(test: "test8")
try perform(legacyTest: "test8")
}
@Test func test9() throws {
try self.perform(test: "test9")
try LZ4Tests.perform(legacyTest: "test9")
try perform(test: "test9")
try perform(legacyTest: "test9")
}
@Test func dependentBlocks() throws {
// This test contains dependent blocks (with the size of 64 kB), as well as has additional features enabled,
// such as content size and block checksums.
let testData = try Constants.data(forTest: "SWCompressionSourceCode.tar", withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: "SWCompressionSourceCode.tar", withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
let answerData = try Constants.data(forTest: "SWCompressionSourceCode", withType: "tar")
@@ -99,7 +99,7 @@ struct LZ4Tests {
}
@Test func skippableFrame() throws {
let testData = try Constants.data(forTest: "test_skippable_frame", withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: "test_skippable_frame", withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -107,7 +107,7 @@ struct LZ4Tests {
}
@Test func legacyFrameMultipleBlocks() throws {
let testData = try Constants.data(forTest: "zeros", withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: "zeros", withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
let answerData = Data(count: 18874368)
@@ -121,7 +121,7 @@ struct LZ4Tests {
for blockSize in ["4", "5", "6", "7", "1234"] {
for dep in ["", "_BD"] {
let testData = try Constants.data(forTest: "test_B" + blockSize + dep, withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: "test_B" + blockSize + dep, withType: testType)
let decompressedData = try LZ4.decompress(data: testData)
#expect(decompressedData == answerData)
}
@@ -134,15 +134,15 @@ struct LZ4Tests {
let answerData = try Constants.data(forTest: "SWCompressionSourceCode", withType: "tar")
let dictData = try Constants.data(forTest: "lz4_dict", withType: "")
var testData = try Constants.data(forTest: "test_dict_B5", withType: LZ4Tests.testType)
var testData = try Constants.data(forTest: "test_dict_B5", withType: testType)
var decompressedData = try LZ4.decompress(data: testData, dictionary: dictData)
#expect(decompressedData == answerData)
testData = try Constants.data(forTest: "test_dict_B5_BD", withType: LZ4Tests.testType)
testData = try Constants.data(forTest: "test_dict_B5_BD", withType: testType)
decompressedData = try LZ4.decompress(data: testData, dictionary: dictData)
#expect(decompressedData == answerData)
testData = try Constants.data(forTest: "test_dict_B5_dictID", withType: LZ4Tests.testType)
testData = try Constants.data(forTest: "test_dict_B5_dictID", withType: testType)
decompressedData = try LZ4.decompress(data: testData, dictionary: dictData, dictionaryID: 20000)
#expect(decompressedData == answerData)
}
@@ -152,11 +152,11 @@ struct LZ4Tests {
let answerData = try Constants.data(forTest: "SWCompressionSourceCode", withType: "tar")
let dictData = try Constants.data(forTest: "lz4_small_dict", withType: "")
var testData = try Constants.data(forTest: "test_small_dict_B5", withType: LZ4Tests.testType)
var testData = try Constants.data(forTest: "test_small_dict_B5", withType: testType)
var decompressedData = try LZ4.decompress(data: testData, dictionary: dictData)
#expect(decompressedData == answerData)
testData = try Constants.data(forTest: "test_small_dict_B5_BD", withType: LZ4Tests.testType)
testData = try Constants.data(forTest: "test_small_dict_B5_BD", withType: testType)
decompressedData = try LZ4.decompress(data: testData, dictionary: dictData)
#expect(decompressedData == answerData)
}
@@ -166,7 +166,7 @@ struct LZ4Tests {
// - Legacy frame format, compressed test1.answer,
// - Skippable frame with 1233 bytes of random data,
// - Normal frame with compressed test4.answer.
let testData = try Constants.data(forTest: "test_multi_frame", withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: "test_multi_frame", withType: testType)
let result = try LZ4.multiDecompress(data: testData)
try #require(result.count == 2)
@@ -180,7 +180,7 @@ struct LZ4Tests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test1", withType: LZ4Tests.testType)
var testData = try Constants.data(forTest: "test1", withType: testType)
// The content checksum is the last 4 bytes.
testData[testData.endIndex - 2] &+= 1
#if compiler(>=6.1)
@@ -206,7 +206,7 @@ struct LZ4Tests {
@Test func randomInputTruncations() throws {
for i in 1...9 {
let testName = "test\(i)"
let testData = try Constants.data(forTest: testName, withType: LZ4Tests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
for _ in 0..<100 {
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
_ = try? LZ4.decompress(data: testData[testData.startIndex..<truncationIndex])
+8 -8
View File
@@ -9,10 +9,10 @@ import SWCompression
struct LzmaTests {
private static let testType: String = "lzma"
private let testType: String = "lzma"
func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: LzmaTests.testType)
private func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let decompressedData = try LZMA.decompress(data: testData)
let answerData = try Constants.data(forAnswer: "test8")
@@ -20,23 +20,23 @@ struct LzmaTests {
}
@Test func lzma8() throws {
try self.perform(test: "test8")
try perform(test: "test8")
}
@Test func lzma9() throws {
try self.perform(test: "test9")
try perform(test: "test9")
}
@Test func lzma10() throws {
try self.perform(test: "test10")
try perform(test: "test10")
}
@Test func lzma11() throws {
try self.perform(test: "test11")
try perform(test: "test11")
}
@Test func lzmaEmpty() throws {
let testData = try Constants.data(forTest: "test_empty", withType: LzmaTests.testType)
let testData = try Constants.data(forTest: "test_empty", withType: testType)
#expect(try LZMA.decompress(data: testData) == Data())
}
+25 -25
View File
@@ -9,7 +9,7 @@ import SWCompression
struct SevenZipTests {
private static let testType: String = "7z"
private let testType: String = "7z"
@Test func shortInput() {
#expect(throws: (any Error).self) { try SevenZipContainer.open(container: Data([0, 1, 2])) }
@@ -26,7 +26,7 @@ struct SevenZipTests {
}
@Test func test1() throws {
let testData = try Constants.data(forTest: "test1", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test1", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test1")
@@ -50,7 +50,7 @@ struct SevenZipTests {
}
@Test func test2() throws {
let testData = try Constants.data(forTest: "test2", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test2", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 2)
@@ -93,13 +93,13 @@ struct SevenZipTests {
}
@Test func test3() throws {
let testData = try Constants.data(forTest: "test3", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test3", withType: testType)
#expect(throws: Never.self) { try SevenZipContainer.info(container: testData) }
#expect(throws: Never.self) { try SevenZipContainer.open(container: testData) }
}
@Test func antiFile() throws {
let testData = try Constants.data(forTest: "test_anti_file", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_anti_file", withType: testType)
_ = try SevenZipContainer.info(container: testData)
let entries = try SevenZipContainer.open(container: testData)
@@ -117,7 +117,7 @@ struct SevenZipTests {
@Test func multiBlocks() throws {
// Container was created with "solid" options set to "off" (-ms=off).
let testData = try Constants.data(forTest: "test_multi_blocks", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_multi_blocks", withType: testType)
_ = try SevenZipContainer.info(container: testData)
let entries = try SevenZipContainer.open(container: testData)
@@ -127,7 +127,7 @@ struct SevenZipTests {
@Test func allTimestamps() throws {
// Container was created with "-mtc=on" and "-mta=on" options.
let testData = try Constants.data(forTest: "test_all_timestamps", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_all_timestamps", withType: testType)
_ = try SevenZipContainer.info(container: testData)
let entries = try SevenZipContainer.open(container: testData)
@@ -144,7 +144,7 @@ struct SevenZipTests {
@Test func complicatedCodingScheme() throws {
// Container was created with these options: "-mf=BCJ -m0=Copy -m1=Deflate -m2=Delta -m3=LZMA -m4=LZMA2"
let testData = try Constants.data(forTest: "test_complicated_coding_scheme", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_complicated_coding_scheme", withType: testType)
// In this test case the most important thing is that information about entries must be read correctly.
_ = try SevenZipContainer.info(container: testData)
@@ -155,7 +155,7 @@ struct SevenZipTests {
@Test func encryptedHeader() throws {
// Container was created with "-mhe=on".
let testData = try Constants.data(forTest: "test_encrypted_header", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_encrypted_header", withType: testType)
#expect(throws: SevenZipError.encryptionNotSupported) { try SevenZipContainer.info(container: testData) }
@@ -165,21 +165,21 @@ struct SevenZipTests {
@Test func singleThread() throws {
// Container was created with disabled multithreading options.
// We check this just in case.
let testData = try Constants.data(forTest: "test_single_thread", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_single_thread", withType: testType)
#expect(try SevenZipContainer.info(container: testData).count == 6)
#expect(try SevenZipContainer.open(container: testData).count == 6)
}
@Test func bigContainer() throws {
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: testType)
#expect(throws: Never.self) { try SevenZipContainer.info(container: testData) }
#expect(throws: Never.self) { try SevenZipContainer.open(container: testData) }
}
@Test func bzip2() throws {
// File in container compressed with BZip2.
let testData = try Constants.data(forTest: "test_7z_bzip2", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_7z_bzip2", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -204,7 +204,7 @@ struct SevenZipTests {
@Test func deflate() throws {
// File in container compressed with Deflate.
let testData = try Constants.data(forTest: "test_7z_deflate", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_7z_deflate", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -229,7 +229,7 @@ struct SevenZipTests {
@Test func lz4() throws {
// File in container compressed with LZ4.
let testData = try Constants.data(forTest: "test_7z_lz4", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_7z_lz4", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -254,7 +254,7 @@ struct SevenZipTests {
@Test func copy() throws {
// File in container is explicitly uncompressed.
let testData = try Constants.data(forTest: "test_7z_copy", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_7z_copy", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -278,7 +278,7 @@ struct SevenZipTests {
}
@Test func unicode() throws {
let testData = try Constants.data(forTest: "test_unicode", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_unicode", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -298,7 +298,7 @@ struct SevenZipTests {
}
@Test func winContainer() throws {
let testData = try Constants.data(forTest: "test_win", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_win", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 2)
@@ -340,7 +340,7 @@ struct SevenZipTests {
func lzmaBigDict() throws {
// Verifying the issue fixed by PR #61.
// Previously, there was a crash, if LZMA dictionary size was encoded using all 4 bytes.
let testData = try Constants.data(forTest: "test_lzma_big_dict", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_lzma_big_dict", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
#expect(entries[0].info.name == "data")
@@ -349,7 +349,7 @@ struct SevenZipTests {
}
@Test func emptyFile() throws {
let testData = try Constants.data(forTest: "test_empty_file", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_file", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -371,7 +371,7 @@ struct SevenZipTests {
}
@Test func emptyDirectory() throws {
let testData = try Constants.data(forTest: "test_empty_dir", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_dir", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -393,14 +393,14 @@ struct SevenZipTests {
}
@Test func emptyContainer() throws {
let testData = try Constants.data(forTest: "test_empty_cont", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_cont", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
#expect(entries.isEmpty)
}
@Test func deltaFilter() throws {
let testData = try Constants.data(forTest: "test_delta_filter", withType: SevenZipTests.testType)
let testData = try Constants.data(forTest: "test_delta_filter", withType: testType)
let entries = try SevenZipContainer.open(container: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -426,7 +426,7 @@ struct SevenZipTests {
@Test func formatMinorVersions() throws {
let answerData = try Constants.data(forAnswer: "test2")
var testData = try Constants.data(forTest: "test_minor_version_2", withType: SevenZipTests.testType)
var testData = try Constants.data(forTest: "test_minor_version_2", withType: testType)
var entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -445,7 +445,7 @@ struct SevenZipTests {
#expect(entries[0].info.crc == 4168830779)
#expect(entries[0].data == answerData)
testData = try Constants.data(forTest: "test_minor_version_3", withType: SevenZipTests.testType)
testData = try Constants.data(forTest: "test_minor_version_3", withType: testType)
entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -464,7 +464,7 @@ struct SevenZipTests {
#expect(entries[0].info.crc == 4168830779)
#expect(entries[0].data == answerData)
testData = try Constants.data(forTest: "test_minor_version_4", withType: SevenZipTests.testType)
testData = try Constants.data(forTest: "test_minor_version_4", withType: testType)
entries = try SevenZipContainer.open(container: testData)
try #require(entries.count == 1)
+15 -15
View File
@@ -9,7 +9,7 @@ import SWCompression
struct TarReaderTests {
private static let testType: String = "tar"
private let testType: String = "tar"
@Test func invalidInput() throws {
// This is potentially a misleading test, since there is no way to guarantee that a file is not a TAR container.
@@ -21,7 +21,7 @@ struct TarReaderTests {
}
@Test func test() throws {
let testHandle = try Constants.handle(forTest: "test", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test", withType: testType)
var reader = TarReader(fileHandle: testHandle)
var isFinished = false
var entriesCount = 0
@@ -50,7 +50,7 @@ struct TarReaderTests {
@Test func pax() throws {
let testHandle = try Constants.handle(forTest: "full_test", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "full_test", withType: testType)
var reader = TarReader(fileHandle: testHandle)
var isFinished = false
var entriesCount = 0
@@ -86,7 +86,7 @@ struct TarReaderTests {
let answerData = try Constants.data(forAnswer: "test1")
for testName in formatTestNames {
let testHandle = try Constants.handle(forTest: testName, withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: testName, withType: testType)
var reader = TarReader(fileHandle: testHandle)
var isFinished = false
var entriesCount = 0
@@ -112,7 +112,7 @@ struct TarReaderTests {
@Test func longNames() throws {
let formatTestNames = ["long_test_gnu", "long_test_oldgnu", "long_test_pax"]
for testName in formatTestNames {
let testHandle = try Constants.handle(forTest: testName, withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: testName, withType: testType)
var reader = TarReader(fileHandle: testHandle)
var isFinished = false
var entriesCount = 0
@@ -132,7 +132,7 @@ struct TarReaderTests {
}
@Test func winContainer() throws {
let testHandle = try Constants.handle(forTest: "test_win", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_win", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -165,7 +165,7 @@ struct TarReaderTests {
}
@Test func emptyFile() throws {
let testHandle = try Constants.handle(forTest: "test_empty_file", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_empty_file", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -186,7 +186,7 @@ struct TarReaderTests {
}
@Test func emptyDirectory() throws {
let testHandle = try Constants.handle(forTest: "test_empty_dir", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_empty_dir", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -208,7 +208,7 @@ struct TarReaderTests {
@Test func onlyDirectoryHeader() throws {
// This tests the correct handling of the situation when there is nothing in the container but one basic header,
// even no EOF marker (two blocks of zeros).
let testHandle = try Constants.handle(forTest: "test_only_dir_header", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_only_dir_header", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -228,21 +228,21 @@ struct TarReaderTests {
}
@Test func emptyContainer() throws {
let testHandle = try Constants.handle(forTest: "test_empty_cont", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_empty_cont", withType: testType)
var reader = TarReader(fileHandle: testHandle)
#expect(try reader.read() == nil)
try testHandle.close()
}
@Test func bigContainer() throws {
let testHandle = try Constants.handle(forTest: "SWCompressionSourceCode", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "SWCompressionSourceCode", withType: testType)
var reader = TarReader(fileHandle: testHandle)
while try reader.read() != nil { }
try testHandle.close()
}
@Test func unicodeUstar() throws {
let testHandle = try Constants.handle(forTest: "test_unicode_ustar", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_unicode_ustar", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -262,7 +262,7 @@ struct TarReaderTests {
}
@Test func unicodePax() throws {
let testHandle = try Constants.handle(forTest: "test_unicode_pax", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_unicode_pax", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
@@ -282,7 +282,7 @@ struct TarReaderTests {
}
@Test func gnuIncrementalFormat() throws {
let testHandle = try Constants.handle(forTest: "test_gnu_inc_format", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_gnu_inc_format", withType: testType)
var reader = TarReader(fileHandle: testHandle)
var isFinished = false
var entriesCount = 0
@@ -310,7 +310,7 @@ struct TarReaderTests {
// @Test func bigNumField() throws { }
@Test func negativeMtime() throws {
let testHandle = try Constants.handle(forTest: "test_negative_mtime", withType: TarReaderTests.testType)
let testHandle = try Constants.handle(forTest: "test_negative_mtime", withType: testType)
var reader = TarReader(fileHandle: testHandle)
try reader.process { (entry: TarEntry?) in
try #require(entry != nil)
+17 -17
View File
@@ -9,7 +9,7 @@ import SWCompression
struct TarTests {
private static let testType: String = "tar"
private let testType: String = "tar"
@Test func shortInput() {
#expect(throws: (any Error).self) { try TarContainer.open(container: Data([0, 1, 2])) }
@@ -23,7 +23,7 @@ struct TarTests {
}
@Test func test() throws {
let testData = try Constants.data(forTest: "test", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -43,7 +43,7 @@ struct TarTests {
}
@Test func pax() throws {
let testData = try Constants.data(forTest: "full_test", withType: TarTests.testType)
let testData = try Constants.data(forTest: "full_test", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .pax)
@@ -72,7 +72,7 @@ struct TarTests {
@Test func paxRecordNewline() throws {
// In this test we check the handling of a PAX header record with a newline character inside a record value.
let testData = try Constants.data(forTest: "test_pax_record_newline", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_pax_record_newline", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .pax)
@@ -108,7 +108,7 @@ struct TarTests {
let answerData = try Constants.data(forAnswer: "test1")
for testName in formatTestNames {
let testData = try Constants.data(forTest: testName, withType: TarTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
if testName == "test_gnu" {
#expect(try TarContainer.formatOf(container: testData) == .gnu)
@@ -136,7 +136,7 @@ struct TarTests {
let formatTestNames = ["long_test_gnu", "long_test_oldgnu", "long_test_pax"]
for testName in formatTestNames {
let testData = try Constants.data(forTest: testName, withType: TarTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
if testName == "long_test_gnu" {
#expect(try TarContainer.formatOf(container: testData) == .gnu)
@@ -153,7 +153,7 @@ struct TarTests {
}
@Test func winContainer() throws {
let testData = try Constants.data(forTest: "test_win", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_win", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -185,7 +185,7 @@ struct TarTests {
}
@Test func emptyFile() throws {
let testData = try Constants.data(forTest: "test_empty_file", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_empty_file", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -205,7 +205,7 @@ struct TarTests {
}
@Test func emptyDirectory() throws {
let testData = try Constants.data(forTest: "test_empty_dir", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_empty_dir", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -227,7 +227,7 @@ struct TarTests {
@Test func onlyDirectoryHeader() throws {
// This tests the correct handling of the situation when there is nothing in the container but one basic header,
// even no EOF marker (two blocks of zeros).
let testData = try Constants.data(forTest: "test_only_dir_header", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_only_dir_header", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -247,7 +247,7 @@ struct TarTests {
}
@Test func emptyContainer() throws {
let testData = try Constants.data(forTest: "test_empty_cont", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_empty_cont", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .prePosix)
@@ -257,7 +257,7 @@ struct TarTests {
}
@Test func bigContainer() throws {
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: TarTests.testType)
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -266,7 +266,7 @@ struct TarTests {
}
@Test func unicodeUstar() throws {
let testData = try Constants.data(forTest: "test_unicode_ustar", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_unicode_ustar", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .ustar)
@@ -285,7 +285,7 @@ struct TarTests {
}
@Test func unicodePax() throws {
let testData = try Constants.data(forTest: "test_unicode_pax", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_unicode_pax", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .pax)
@@ -304,7 +304,7 @@ struct TarTests {
}
@Test func gnuIncrementalFormat() throws {
let testData = try Constants.data(forTest: "test_gnu_inc_format", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_gnu_inc_format", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .gnu)
@@ -324,7 +324,7 @@ struct TarTests {
@Test func bigNumField() throws {
// This file is truncated because of its size (8.6 GB): it doesn't contain any actual file data.
let testData = try Constants.data(forTest: "test_big_num_field", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_big_num_field", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .gnu)
@@ -343,7 +343,7 @@ struct TarTests {
}
@Test func negativeMtime() throws {
let testData = try Constants.data(forTest: "test_negative_mtime", withType: TarTests.testType)
let testData = try Constants.data(forTest: "test_negative_mtime", withType: testType)
#expect(try TarContainer.formatOf(container: testData) == .gnu)
@@ -7,6 +7,7 @@ import Foundation
import Testing
import SWCompression
// Has to be a class for `deinit()` to work.
final class TarWriterTests {
private let tempDir = URL(fileURLWithPath: NSTemporaryDirectory())
+18 -18
View File
@@ -9,10 +9,10 @@ import SWCompression
struct XZTests {
private static let testType: String = "xz"
private let testType: String = "xz"
func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: XZTests.testType)
private func perform(test testName: String) throws {
let testData = try Constants.data(forTest: testName, withType: testType)
let decompressedData = try XZArchive.unarchive(archive: testData)
let answerData = try Constants.data(forAnswer: testName)
@@ -20,45 +20,45 @@ struct XZTests {
}
@Test func xz1() throws {
try self.perform(test: "test1")
try perform(test: "test1")
}
@Test func xz2() throws {
try self.perform(test: "test2")
try perform(test: "test2")
}
@Test func xz3() throws {
try self.perform(test: "test3")
try perform(test: "test3")
}
@Test func xz4() throws {
// This test contains padding!
try self.perform(test: "test4")
try perform(test: "test4")
}
@Test func xz5() throws {
try self.perform(test: "test5")
try perform(test: "test5")
}
@Test func xz6() throws {
try self.perform(test: "test6")
try perform(test: "test6")
}
@Test func xz7() throws {
try self.perform(test: "test7")
try perform(test: "test7")
}
@Test func xz8() throws {
try self.perform(test: "test8")
try perform(test: "test8")
}
@Test func xz9() throws {
try self.perform(test: "test9")
try perform(test: "test9")
}
@Test func multiStreamNoPadding() throws {
// Doesn't contain any padding.
let testData = try Constants.data(forTest: "test_multi", withType: XZTests.testType)
let testData = try Constants.data(forTest: "test_multi", withType: testType)
let splitDecompressedData = try XZArchive.splitUnarchive(archive: testData)
try #require(splitDecompressedData.count == 4)
@@ -78,7 +78,7 @@ struct XZTests {
// After second - 4 bytes of padding.
// Third - 8 bytes.
// At the end - 4 bytes.
let testData = try Constants.data(forTest: "test_multi_pad", withType: XZTests.testType)
let testData = try Constants.data(forTest: "test_multi_pad", withType: testType)
let splitDecompressedData = try XZArchive.splitUnarchive(archive: testData)
try #require(splitDecompressedData.count == 4)
@@ -95,7 +95,7 @@ struct XZTests {
}
@Test func deltaFilter() throws {
let testData = try Constants.data(forTest: "test_delta_filter", withType: XZTests.testType)
let testData = try Constants.data(forTest: "test_delta_filter", withType: testType)
let decompressedData = try XZArchive.unarchive(archive: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -103,7 +103,7 @@ struct XZTests {
}
@Test func sha256Check() throws {
let testData = try Constants.data(forTest: "test_sha256", withType: XZTests.testType)
let testData = try Constants.data(forTest: "test_sha256", withType: testType)
let decompressedData = try XZArchive.unarchive(archive: testData)
let answerData = try Constants.data(forAnswer: "test4")
@@ -124,7 +124,7 @@ struct XZTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test1", withType: XZTests.testType)
var testData = try Constants.data(forTest: "test1", withType: testType)
// Here we modify the stored value of crc64.
testData[46] &+= 1
#if compiler(>=6.1)
@@ -151,7 +151,7 @@ struct XZTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test_multi", withType: XZTests.testType)
var testData = try Constants.data(forTest: "test_multi", withType: testType)
// Here we modify the stored value of crc64.
testData[2346] &+= 1
#if compiler(>=6.1)
+15 -15
View File
@@ -9,7 +9,7 @@ import SWCompression
struct ZipTests {
private static let testType: String = "zip"
private let testType: String = "zip"
@Test func shortInput() {
#expect(throws: (any Error).self) { try ZipContainer.open(container: Data([0, 1, 2, 3, 4, 5, 6, 7])) }
@@ -26,12 +26,12 @@ struct ZipTests {
}
@Test func bigContainer() throws {
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: testType)
#expect(throws: Never.self) { try ZipContainer.open(container: testData) }
}
@Test func customExtraField() throws {
let testData = try Constants.data(forTest: "test_custom_extra_field", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_custom_extra_field", withType: testType)
// First, we check that without enabling support for our custom extra field, ZipContainer doesn't recognize it.
var entries = try ZipContainer.open(container: testData)
@@ -66,7 +66,7 @@ struct ZipTests {
}
@Test func zip64() throws {
let testData = try Constants.data(forTest: "test_zip64", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_zip64", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 6)
@@ -84,7 +84,7 @@ struct ZipTests {
}
@Test func dataDescriptor() throws {
let testData = try Constants.data(forTest: "test_data_descriptor", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_data_descriptor", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 6)
@@ -109,7 +109,7 @@ struct ZipTests {
}
@Test func unicode() throws {
let testData = try Constants.data(forTest: "test_unicode", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_unicode", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -131,7 +131,7 @@ struct ZipTests {
}
@Test func zipLZMA() throws {
let testData = try Constants.data(forTest: "test_zip_lzma", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_zip_lzma", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -155,7 +155,7 @@ struct ZipTests {
}
@Test func zipBZip2() throws {
let testData = try Constants.data(forTest: "test_zip_bzip2", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_zip_bzip2", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -179,7 +179,7 @@ struct ZipTests {
}
@Test func winContainer() throws {
let testData = try Constants.data(forTest: "test_win", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_win", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 2)
@@ -222,7 +222,7 @@ struct ZipTests {
}
@Test func emptyFile() throws {
let testData = try Constants.data(forTest: "test_empty_file", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_file", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -246,7 +246,7 @@ struct ZipTests {
}
@Test func emptyDirectory() throws {
let testData = try Constants.data(forTest: "test_empty_dir", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_dir", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -270,7 +270,7 @@ struct ZipTests {
}
@Test func emptyContainer() throws {
let testData = try Constants.data(forTest: "test_empty_cont", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_empty_cont", withType: testType)
let entries = try ZipContainer.open(container: testData)
#expect(entries.isEmpty)
@@ -279,7 +279,7 @@ struct ZipTests {
@Test func badCdExtTs() throws {
// Tests ability to not crash when opening ZIP files with non well-formed Extended Timestamp extra field.
// Such fields are sometimes present in Central Directory of ZIP files created by Finder in some versions of macOS.
let testData = try Constants.data(forTest: "bad_cd_ext_ts", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "bad_cd_ext_ts", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 2)
let answerData = try Constants.data(forAnswer: "test4")
@@ -292,7 +292,7 @@ struct ZipTests {
// We introduced several CP437-specific characters from the 0x80-0xFF range into "test1.answer" to test this.
// Note, that we didn't used normal characters from the 0x00-0x7F range that don't match the characters from
// UTF-8 with the same codes, since they are interpreted as control characters by Foundation.
let testData = try Constants.data(forTest: "test_dos_latin_us", withType: ZipTests.testType)
let testData = try Constants.data(forTest: "test_dos_latin_us", withType: testType)
let entries = try ZipContainer.open(container: testData)
try #require(entries.count == 1)
@@ -319,7 +319,7 @@ struct ZipTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "test_unicode", withType: ZipTests.testType)
var testData = try Constants.data(forTest: "test_unicode", withType: testType)
// Here we modify the stored value of crc32.
testData[16] &+= 1
#if compiler(>=6.1)
+6 -6
View File
@@ -9,12 +9,12 @@ import SWCompression
struct ZlibTests {
private static let testType: String = "zlib"
private let testType: String = "zlib"
@Test func test() throws {
let testName = "test"
let testData = try Constants.data(forTest: testName, withType: ZlibTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
let testZlibHeader = try ZlibHeader(archive: testData)
#expect(testZlibHeader.compressionMethod == .deflate)
@@ -23,7 +23,7 @@ struct ZlibTests {
}
@Test func full() throws {
let testData = try Constants.data(forTest: "random_file", withType: ZlibTests.testType)
let testData = try Constants.data(forTest: "random_file", withType: testType)
let decompressedData = try ZlibArchive.unarchive(archive: testData)
let answerData = try Constants.data(forAnswer: "test9")
@@ -39,7 +39,7 @@ struct ZlibTests {
}
@Test func empty() throws {
let testData = try Constants.data(forTest: "test_empty", withType: ZlibTests.testType)
let testData = try Constants.data(forTest: "test_empty", withType: testType)
#expect((try ZlibArchive.unarchive(archive: testData)) == Data())
}
@@ -61,7 +61,7 @@ struct ZlibTests {
// Here we test that an error for checksum mismatch is thrown correctly and its associated value contains
// expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum,
// which makes it incorrect.
var testData = try Constants.data(forTest: "random_file", withType: ZlibTests.testType)
var testData = try Constants.data(forTest: "random_file", withType: testType)
// Here we modify the stored value of adler32.
testData[10249] &+= 1
#if compiler(>=6.1)
@@ -85,7 +85,7 @@ struct ZlibTests {
@Test func randomInputTruncations() throws {
for testName in ["test", "random_file", "test_empty"] {
let testData = try Constants.data(forTest: testName, withType: ZlibTests.testType)
let testData = try Constants.data(forTest: testName, withType: testType)
for _ in 0..<100 {
let truncationIndex = Int.random(in: (testData.startIndex + 1)..<testData.endIndex)
_ = try? ZlibArchive.unarchive(archive: testData[testData.startIndex..<truncationIndex])