mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Reorganized tests and added missing tests for zlib/gz.
This commit is contained in:
@@ -54,9 +54,14 @@
|
||||
066204851DD9840000353639 /* test1.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 066204791DD9840000353639 /* test1.zlib */; };
|
||||
066204861DD9840000353639 /* test2.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0662047A1DD9840000353639 /* test2.zlib */; };
|
||||
066204871DD9840000353639 /* test3.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0662047B1DD9840000353639 /* test3.zlib */; };
|
||||
0680E1A01DDA2C3F005C05EB /* test3.gz in Resources */ = {isa = PBXBuildFile; fileRef = 0680E19E1DDA2C3F005C05EB /* test3.gz */; };
|
||||
0680E1A11DDA2C3F005C05EB /* test2.gz in Resources */ = {isa = PBXBuildFile; fileRef = 0680E19F1DDA2C3F005C05EB /* test2.gz */; };
|
||||
0680E1A41DDA2C5B005C05EB /* test4.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A21DDA2C5B005C05EB /* test4.zlib */; };
|
||||
0680E1A51DDA2C5B005C05EB /* test5.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A31DDA2C5B005C05EB /* test5.zlib */; };
|
||||
0680E1B11DDA2D7C005C05EB /* ZlibTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */; };
|
||||
0680E1B31DDA3D0A005C05EB /* GzipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0680E1B21DDA3D0A005C05EB /* GzipTests.swift */; };
|
||||
06AC9B0D1DC1027900A5066B /* HuffmanLength.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AC9B0C1DC1027900A5066B /* HuffmanLength.swift */; };
|
||||
06BE1AD21DB410F100EE0F59 /* SWCompression.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06BE1AC81DB410F100EE0F59 /* SWCompression.framework */; };
|
||||
06BE1AD71DB410F100EE0F59 /* SWCompressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06BE1AD61DB410F100EE0F59 /* SWCompressionTests.swift */; };
|
||||
06BE1AD91DB410F100EE0F59 /* SWCompression.h in Headers */ = {isa = PBXBuildFile; fileRef = 06BE1ACB1DB410F100EE0F59 /* SWCompression.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
06E961CA1DBD5FA1008C47F2 /* HuffmanTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */; };
|
||||
06FED40C1DD7717E0013DFB2 /* BZip2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FED40B1DD7717E0013DFB2 /* BZip2.swift */; };
|
||||
@@ -102,12 +107,17 @@
|
||||
066204791DD9840000353639 /* test1.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test1.zlib; sourceTree = "<group>"; };
|
||||
0662047A1DD9840000353639 /* test2.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test2.zlib; sourceTree = "<group>"; };
|
||||
0662047B1DD9840000353639 /* test3.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test3.zlib; sourceTree = "<group>"; };
|
||||
0680E19E1DDA2C3F005C05EB /* test3.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = test3.gz; sourceTree = "<group>"; };
|
||||
0680E19F1DDA2C3F005C05EB /* test2.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = test2.gz; sourceTree = "<group>"; };
|
||||
0680E1A21DDA2C5B005C05EB /* test4.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test4.zlib; sourceTree = "<group>"; };
|
||||
0680E1A31DDA2C5B005C05EB /* test5.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test5.zlib; sourceTree = "<group>"; };
|
||||
0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZlibTests.swift; sourceTree = "<group>"; };
|
||||
0680E1B21DDA3D0A005C05EB /* GzipTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GzipTests.swift; sourceTree = "<group>"; };
|
||||
06AC9B0C1DC1027900A5066B /* HuffmanLength.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HuffmanLength.swift; sourceTree = "<group>"; };
|
||||
06BE1AC81DB410F100EE0F59 /* SWCompression.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SWCompression.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
06BE1ACB1DB410F100EE0F59 /* SWCompression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SWCompression.h; sourceTree = "<group>"; };
|
||||
06BE1ACC1DB410F100EE0F59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
06BE1AD11DB410F100EE0F59 /* SWCompressionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SWCompressionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
06BE1AD61DB410F100EE0F59 /* SWCompressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SWCompressionTests.swift; sourceTree = "<group>"; };
|
||||
06BE1AD81DB410F100EE0F59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
06E961C91DBD5FA1008C47F2 /* HuffmanTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HuffmanTable.swift; sourceTree = "<group>"; };
|
||||
06FED40B1DD7717E0013DFB2 /* BZip2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BZip2.swift; sourceTree = "<group>"; };
|
||||
@@ -156,10 +166,10 @@
|
||||
0662046B1DD983FF00353639 /* Test Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
066204771DD9840000353639 /* performance_test1.gz */,
|
||||
0662046C1DD983FF00353639 /* Answers */,
|
||||
066204721DD9840000353639 /* BZip2 */,
|
||||
066204731DD9840000353639 /* GZip */,
|
||||
066204771DD9840000353639 /* performance_test1.gz */,
|
||||
066204781DD9840000353639 /* Zlib */,
|
||||
);
|
||||
path = "Test Files";
|
||||
@@ -188,6 +198,8 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
066204741DD9840000353639 /* test1.gz */,
|
||||
0680E19F1DDA2C3F005C05EB /* test2.gz */,
|
||||
0680E19E1DDA2C3F005C05EB /* test3.gz */,
|
||||
066204751DD9840000353639 /* test4.gz */,
|
||||
066204761DD9840000353639 /* test5.gz */,
|
||||
);
|
||||
@@ -200,6 +212,8 @@
|
||||
066204791DD9840000353639 /* test1.zlib */,
|
||||
0662047A1DD9840000353639 /* test2.zlib */,
|
||||
0662047B1DD9840000353639 /* test3.zlib */,
|
||||
0680E1A21DDA2C5B005C05EB /* test4.zlib */,
|
||||
0680E1A31DDA2C5B005C05EB /* test5.zlib */,
|
||||
);
|
||||
path = Zlib;
|
||||
sourceTree = "<group>";
|
||||
@@ -250,9 +264,10 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0662046B1DD983FF00353639 /* Test Files */,
|
||||
06BE1AD61DB410F100EE0F59 /* SWCompressionTests.swift */,
|
||||
0661F06E1DC92391006C3D35 /* PerformanceTests.swift */,
|
||||
0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */,
|
||||
0680E1B21DDA3D0A005C05EB /* GzipTests.swift */,
|
||||
061FCE2C1DBCC6A30052F7BE /* Constants.swift */,
|
||||
0661F06E1DC92391006C3D35 /* PerformanceTests.swift */,
|
||||
06BE1AD81DB410F100EE0F59 /* Info.plist */,
|
||||
);
|
||||
path = Tests;
|
||||
@@ -481,14 +496,18 @@
|
||||
066204871DD9840000353639 /* test3.zlib in Resources */,
|
||||
066204821DD9840000353639 /* test4.gz in Resources */,
|
||||
066204811DD9840000353639 /* test1.gz in Resources */,
|
||||
0680E1A11DDA2C3F005C05EB /* test2.gz in Resources */,
|
||||
066204841DD9840000353639 /* performance_test1.gz in Resources */,
|
||||
0662047E1DD9840000353639 /* test3.answer in Resources */,
|
||||
0680E1A01DDA2C3F005C05EB /* test3.gz in Resources */,
|
||||
0662047D1DD9840000353639 /* test2.answer in Resources */,
|
||||
066204831DD9840000353639 /* test5.gz in Resources */,
|
||||
066204861DD9840000353639 /* test2.zlib in Resources */,
|
||||
0662047F1DD9840000353639 /* test4.answer in Resources */,
|
||||
0662047C1DD9840000353639 /* test1.answer in Resources */,
|
||||
066204851DD9840000353639 /* test1.zlib in Resources */,
|
||||
0680E1A41DDA2C5B005C05EB /* test4.zlib in Resources */,
|
||||
0680E1A51DDA2C5B005C05EB /* test5.zlib in Resources */,
|
||||
066204801DD9840000353639 /* test5.answer in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -564,8 +583,9 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
06BE1AD71DB410F100EE0F59 /* SWCompressionTests.swift in Sources */,
|
||||
061FCE2D1DBCC6A30052F7BE /* Constants.swift in Sources */,
|
||||
0680E1B11DDA2D7C005C05EB /* ZlibTests.swift in Sources */,
|
||||
0680E1B31DDA3D0A005C05EB /* GzipTests.swift in Sources */,
|
||||
0661F06F1DC92391006C3D35 /* PerformanceTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
+7
-24
@@ -10,32 +10,15 @@ import Foundation
|
||||
|
||||
struct Constants {
|
||||
|
||||
static let testBundle = Bundle(for: SWCompressionTests.self)
|
||||
static func url(forTest name: String, withType ext: String) -> URL {
|
||||
return testBundle.url(forResource: name, withExtension: ext)!
|
||||
}
|
||||
|
||||
static let helloWorldArchivePath = testBundle.url(forResource: "test1",
|
||||
withExtension: "gz")!
|
||||
|
||||
static let secondTestArchivePath = testBundle.url(forResource: "test4",
|
||||
withExtension: "gz")!
|
||||
static let secondTestAnswerPath = testBundle.url(forResource: "test4",
|
||||
withExtension: "answer")!
|
||||
|
||||
static let emptyFileArchivePath = testBundle.url(forResource: "test5",
|
||||
withExtension: "gz")!
|
||||
|
||||
static let helloWorldZlibPath = testBundle.url(forResource: "test1",
|
||||
withExtension: "zlib")!
|
||||
|
||||
static let secondZlibTestPath = testBundle.url(forResource: "test2",
|
||||
withExtension: "zlib")!
|
||||
static let secondZlibTestAnswerPath = testBundle.url(forResource: "test2",
|
||||
withExtension: "answer")!
|
||||
|
||||
static let thirdZlibTestPath = testBundle.url(forResource: "test3",
|
||||
withExtension: "zlib")!
|
||||
static let thirdZlibTestAnswerPath = testBundle.url(forResource: "test3",
|
||||
withExtension: "answer")!
|
||||
static func url(forAnswer name: String) -> URL {
|
||||
return testBundle.url(forResource: name, withExtension: "answer")!
|
||||
}
|
||||
|
||||
static let testBundle = Bundle(for: ZlibTests.self)
|
||||
|
||||
static let relativelyBigFilePath = testBundle.url(forResource: "performance_test1",
|
||||
withExtension: "gz")!
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// GzipTests.swift
|
||||
// SWCompression
|
||||
//
|
||||
// Created by Timofey Solomko on 14.11.16.
|
||||
// Copyright © 2016 tsolomko. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import SWCompression
|
||||
|
||||
class GzipTests: XCTestCase {
|
||||
|
||||
static let testType: String = "gz"
|
||||
|
||||
func testGzip1() {
|
||||
let testName = "test1"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: GzipTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? GzipArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testGzip2() {
|
||||
let testName = "test2"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: GzipTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? GzipArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
|
||||
}
|
||||
|
||||
func testGzip3() {
|
||||
let testName = "test3"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: GzipTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? GzipArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
|
||||
}
|
||||
|
||||
func testGzip4() {
|
||||
let testName = "test4"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: GzipTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? GzipArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
|
||||
}
|
||||
|
||||
func testGzip5() {
|
||||
let testName = "test5"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: GzipTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? GzipArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// SWCompressionTests.swift
|
||||
// SWCompressionTests
|
||||
//
|
||||
// Created by Timofey Solomko on 16.10.16.
|
||||
// Copyright © 2016 Timofey Solomko. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import SWCompression
|
||||
|
||||
class SWCompressionTests: XCTestCase {
|
||||
|
||||
func testHelloWorldFile() {
|
||||
let testData = try? Data(contentsOf: Constants.helloWorldArchivePath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? GzipArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
XCTAssertEqual(decompressedString!, "Hello, World!\n", "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testSecondTestFile() {
|
||||
let testData = try? Data(contentsOf: Constants.secondTestArchivePath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? GzipArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
let answerString = try? String(contentsOf: Constants.secondTestAnswerPath, encoding: .utf8)
|
||||
XCTAssertNotNil(answerString, "Failed to get the answer")
|
||||
guard answerString != nil else { return }
|
||||
XCTAssertEqual(decompressedString!, answerString!, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testEmptyFile() {
|
||||
let testData = try? Data(contentsOf: Constants.emptyFileArchivePath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? GzipArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
XCTAssertEqual(decompressedString!, "")
|
||||
}
|
||||
|
||||
func testHelloWorldZlibFile() {
|
||||
let testData = try? Data(contentsOf: Constants.helloWorldZlibPath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? ZlibArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
XCTAssertEqual(decompressedString!, "Hello, World!\n", "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testSecondZlibFile() {
|
||||
let testData = try? Data(contentsOf: Constants.secondZlibTestPath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? ZlibArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
let answerString = try? String(contentsOf: Constants.secondZlibTestAnswerPath, encoding: .utf8)
|
||||
XCTAssertNotNil(answerString, "Failed to get the answer")
|
||||
guard answerString != nil else { return }
|
||||
XCTAssertEqual(decompressedString!, answerString!, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testThirdZlibFile() {
|
||||
let testData = try? Data(contentsOf: Constants.thirdZlibTestPath)
|
||||
XCTAssertNotNil(testData, "Failed to load test archive")
|
||||
let decompressedData = try? ZlibArchive.unarchive(archiveData: testData!)
|
||||
XCTAssertNotNil(decompressedData, "Failed to decompress")
|
||||
guard decompressedData != nil else { return }
|
||||
let decompressedString = String(data: decompressedData!, encoding: .utf8)
|
||||
XCTAssertNotNil(decompressedString, "Failed to convert decompressed data to string")
|
||||
let answerString = try? String(contentsOf: Constants.thirdZlibTestAnswerPath, encoding: .utf8)
|
||||
XCTAssertNotNil(answerString, "Failed to get the answer")
|
||||
guard answerString != nil else { return }
|
||||
XCTAssertEqual(decompressedString!, answerString!, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// ZlibTests.swift
|
||||
// SWCompression
|
||||
//
|
||||
// Created by Timofey Solomko on 14.11.16.
|
||||
// Copyright © 2016 Timofey Solomko. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import SWCompression
|
||||
|
||||
class ZlibTests: XCTestCase {
|
||||
|
||||
static let testType: String = "zlib"
|
||||
|
||||
func testZlib1() {
|
||||
let testName = "test1"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: ZlibTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? ZlibArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testZlib2() {
|
||||
let testName = "test2"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: ZlibTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? ZlibArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testZlib3() {
|
||||
let testName = "test3"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: ZlibTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? ZlibArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testZlib4() {
|
||||
let testName = "test4"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: ZlibTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? ZlibArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
func testZlib5() {
|
||||
let testName = "test5"
|
||||
guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: ZlibTests.testType)) else {
|
||||
XCTFail("Failed to load test archive")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedData = try? ZlibArchive.unarchive(archiveData: testData) else {
|
||||
XCTFail("Failed to decompress")
|
||||
return
|
||||
}
|
||||
|
||||
guard let decompressedString = String(data: decompressedData, encoding: .utf8) else {
|
||||
XCTFail("Failed to convert decompressed data to string")
|
||||
return
|
||||
}
|
||||
|
||||
guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else {
|
||||
XCTFail("Failed to get the answer")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user