Add tests for different 7z compression methods

This commit is contained in:
Timofey Solomko
2017-08-10 16:48:36 +03:00
parent 88398c4be9
commit 59a0896fa5
4 changed files with 90 additions and 6 deletions
+72
View File
@@ -238,6 +238,78 @@ class SevenZipTests: XCTestCase {
#endif
}
func test7zBZip2() throws {
// File in container compressed with BZip2.
guard let testURL = Constants.url(forTest: "test_7z_bzip2", withType: SevenZipTests.testType) else {
XCTFail("Unable to get test's URL.")
return
}
let testData = try Data(contentsOf: testURL, options: .mappedIfSafe)
let entries = try SevenZipContainer.open(container: testData)
XCTAssertEqual(entries.count, 1)
XCTAssertEqual(entries[0].name, "test4.answer")
XCTAssertEqual(entries[0].isDirectory, false)
guard let answerURL = Constants.url(forAnswer: "test4") else {
XCTFail("Unable to get answer's URL.")
return
}
let answerData = try? Data(contentsOf: answerURL, options: .mappedIfSafe)
XCTAssertEqual(try entries[0].data(), answerData)
}
func test7zDeflate() throws {
// File in container compressed with Deflate.
guard let testURL = Constants.url(forTest: "test_7z_deflate", withType: SevenZipTests.testType) else {
XCTFail("Unable to get test's URL.")
return
}
let testData = try Data(contentsOf: testURL, options: .mappedIfSafe)
let entries = try SevenZipContainer.open(container: testData)
XCTAssertEqual(entries.count, 1)
XCTAssertEqual(entries[0].name, "test4.answer")
XCTAssertEqual(entries[0].isDirectory, false)
guard let answerURL = Constants.url(forAnswer: "test4") else {
XCTFail("Unable to get answer's URL.")
return
}
let answerData = try? Data(contentsOf: answerURL, options: .mappedIfSafe)
XCTAssertEqual(try entries[0].data(), answerData)
}
func test7zCopy() throws {
// File in container is explicitly uncompressed.
guard let testURL = Constants.url(forTest: "test_7z_copy", withType: SevenZipTests.testType) else {
XCTFail("Unable to get test's URL.")
return
}
let testData = try Data(contentsOf: testURL, options: .mappedIfSafe)
let entries = try SevenZipContainer.open(container: testData)
XCTAssertEqual(entries.count, 1)
XCTAssertEqual(entries[0].name, "test4.answer")
XCTAssertEqual(entries[0].isDirectory, false)
guard let answerURL = Constants.url(forAnswer: "test4") else {
XCTFail("Unable to get answer's URL.")
return
}
let answerData = try? Data(contentsOf: answerURL, options: .mappedIfSafe)
XCTAssertEqual(try entries[0].data(), answerData)
}
func testWinContainer() throws {
guard let testURL = Constants.url(forTest: "test_win", withType: SevenZipTests.testType) else {
XCTFail("Unable to get test's URL.")