mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Split gzip tests.
This commit is contained in:
+35
-25
@@ -11,13 +11,13 @@ import SWCompression
|
||||
|
||||
class GzipTests: XCTestCase {
|
||||
|
||||
func perform(test testName: String, mtime: Date) {
|
||||
// Loading archive.
|
||||
func header(test testName: String, mtime: Int) {
|
||||
// Load archive.
|
||||
guard let archiveData = try? Data(contentsOf: Constants.url(forTest: testName,
|
||||
withType: "gz"),
|
||||
options: .mappedIfSafe) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
withType: "gz"),
|
||||
options: .mappedIfSafe) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
// Test GZip header parsing
|
||||
@@ -27,10 +27,20 @@ class GzipTests: XCTestCase {
|
||||
}
|
||||
|
||||
XCTAssertEqual(testGzipHeader.compressionMethod, .deflate, "Incorrect compression method")
|
||||
XCTAssertEqual(testGzipHeader.modificationTime, mtime, "Incorrect mtime")
|
||||
XCTAssertEqual(testGzipHeader.modificationTime, Date(timeIntervalSince1970: TimeInterval(mtime)), "Incorrect mtime")
|
||||
XCTAssertEqual(testGzipHeader.osType, .unix, "Incorrect os type")
|
||||
XCTAssertEqual(testGzipHeader.originalFileName, "\(testName).answer", "Incorrect original file name")
|
||||
XCTAssertEqual(testGzipHeader.comment, nil, "Incorrect comment")
|
||||
}
|
||||
|
||||
func unarchive(test testName: String) {
|
||||
// Load archive.
|
||||
guard let archiveData = try? Data(contentsOf: Constants.url(forTest: testName,
|
||||
withType: "gz"),
|
||||
options: .mappedIfSafe) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
// Test GZip unarchiving.
|
||||
let decompressedData = try? GzipArchive.unarchive(archiveData: archiveData)
|
||||
@@ -56,48 +66,48 @@ class GzipTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testGzip1() {
|
||||
self.perform(test: "test1",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698300)))
|
||||
self.header(test: "test1", mtime: 1482698300)
|
||||
self.unarchive(test: "test1")
|
||||
}
|
||||
|
||||
func testGzip2() {
|
||||
self.perform(test: "test2",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698300)))
|
||||
self.header(test: "test2", mtime: 1482698300)
|
||||
self.unarchive(test: "test2")
|
||||
}
|
||||
|
||||
func testGzip3() {
|
||||
self.perform(test: "test3",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698301)))
|
||||
self.header(test: "test3", mtime: 1482698301)
|
||||
self.unarchive(test: "test3")
|
||||
}
|
||||
|
||||
func testGzip4() {
|
||||
self.perform(test: "test4",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698301)))
|
||||
self.header(test: "test4", mtime: 1482698301)
|
||||
self.unarchive(test: "test4")
|
||||
}
|
||||
|
||||
func testGzip5() {
|
||||
self.perform(test: "test5",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698242)))
|
||||
self.header(test: "test5", mtime: 1482698242)
|
||||
self.unarchive(test: "test5")
|
||||
}
|
||||
|
||||
func testGzip6() {
|
||||
self.perform(test: "test6",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698305)))
|
||||
self.header(test: "test6", mtime: 1482698305)
|
||||
self.unarchive(test: "test6")
|
||||
}
|
||||
|
||||
func testGzip7() {
|
||||
self.perform(test: "test7",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1482698304)))
|
||||
self.header(test: "test7", mtime: 1482698304)
|
||||
self.unarchive(test: "test7")
|
||||
}
|
||||
|
||||
func testGzip8() {
|
||||
self.perform(test: "test8",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1483040005)))
|
||||
self.header(test: "test8", mtime: 1483040005)
|
||||
self.unarchive(test: "test8")
|
||||
}
|
||||
|
||||
func testGzip9() {
|
||||
self.perform(test: "test9",
|
||||
mtime: Date(timeIntervalSince1970: TimeInterval(1483040005)))
|
||||
self.header(test: "test9", mtime: 1483040005)
|
||||
self.unarchive(test: "test9")
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user