From ce1c64ebcd3bc7f2f41dde65a636193213e54515 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 10 Sep 2017 13:10:51 +0300 Subject: [PATCH] Add some tests for BZip2 compression --- SWCompression.xcodeproj/project.pbxproj | 4 ++ Tests/BZip2CompressionTests.swift | 55 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Tests/BZip2CompressionTests.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 600a98f8..89a551c0 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -81,6 +81,7 @@ 06393DFD1F1A858000A647A0 /* long_test_gnu.tar in Resources */ = {isa = PBXBuildFile; fileRef = 06393DFA1F1A858000A647A0 /* long_test_gnu.tar */; }; 06393DFE1F1A858000A647A0 /* long_test_oldgnu.tar in Resources */ = {isa = PBXBuildFile; fileRef = 06393DFB1F1A858000A647A0 /* long_test_oldgnu.tar */; }; 06393DFF1F1A858000A647A0 /* long_test_pax.tar in Resources */ = {isa = PBXBuildFile; fileRef = 06393DFC1F1A858000A647A0 /* long_test_pax.tar */; }; + 063D0CA21F5B17EB00D3464C /* BZip2CompressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063D0CA11F5B17EB00D3464C /* BZip2CompressionTests.swift */; }; 063DF10A1DE1F07800F38082 /* DataWithPointer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063DF1051DE1F07800F38082 /* DataWithPointer.swift */; }; 063DF10B1DE1F07800F38082 /* DataWithPointer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063DF1051DE1F07800F38082 /* DataWithPointer.swift */; }; 063DF10C1DE1F07800F38082 /* DataWithPointer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063DF1051DE1F07800F38082 /* DataWithPointer.swift */; }; @@ -383,6 +384,7 @@ 06393DFA1F1A858000A647A0 /* long_test_gnu.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = long_test_gnu.tar; sourceTree = ""; }; 06393DFB1F1A858000A647A0 /* long_test_oldgnu.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = long_test_oldgnu.tar; sourceTree = ""; }; 06393DFC1F1A858000A647A0 /* long_test_pax.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = long_test_pax.tar; sourceTree = ""; }; + 063D0CA11F5B17EB00D3464C /* BZip2CompressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BZip2CompressionTests.swift; sourceTree = ""; }; 063DF1051DE1F07800F38082 /* DataWithPointer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DataWithPointer.swift; path = Sources/DataWithPointer.swift; sourceTree = SOURCE_ROOT; }; 063DF1061DE1F07800F38082 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Extensions.swift; path = Sources/Extensions.swift; sourceTree = SOURCE_ROOT; }; 063DF1081DE1F07800F38082 /* DecodingHuffmanTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DecodingHuffmanTree.swift; path = Sources/DecodingHuffmanTree.swift; sourceTree = SOURCE_ROOT; }; @@ -821,6 +823,7 @@ 069AC2111E02DDAF0041AC13 /* LzmaTests.swift */, 06E2347F1E069ABD00F18798 /* XzTests.swift */, 0680E1B41DDA4075005C05EB /* BZip2Tests.swift */, + 063D0CA11F5B17EB00D3464C /* BZip2CompressionTests.swift */, 06CC187E1DE35607003532F5 /* DeflateTests.swift */, 0680E1B21DDA3D0A005C05EB /* GzipTests.swift */, 0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */, @@ -1495,6 +1498,7 @@ 0680E1B51DDA4076005C05EB /* BZip2Tests.swift in Sources */, 06CC187F1DE35607003532F5 /* DeflateTests.swift in Sources */, 061FCE2D1DBCC6A30052F7BE /* Constants.swift in Sources */, + 063D0CA21F5B17EB00D3464C /* BZip2CompressionTests.swift in Sources */, 069AC2121E02DDAF0041AC13 /* LzmaTests.swift in Sources */, 0680E1B11DDA2D7C005C05EB /* ZlibTests.swift in Sources */, 0680E1B31DDA3D0A005C05EB /* GzipTests.swift in Sources */, diff --git a/Tests/BZip2CompressionTests.swift b/Tests/BZip2CompressionTests.swift new file mode 100644 index 00000000..fe80b7b4 --- /dev/null +++ b/Tests/BZip2CompressionTests.swift @@ -0,0 +1,55 @@ +// Copyright (c) 2017 Timofey Solomko +// Licensed under MIT License +// +// See LICENSE for license information + +import XCTest +import SWCompression + +class BZip2CompressTests: XCTestCase { + + static let testType: String = "bz2" + + func answerTest(_ answerName: String) throws { + guard let answerURL = Constants.url(forAnswer: answerName) else { + XCTFail("Unable to get asnwer's URL.") + return + } + + let answerData = try Data(contentsOf: answerURL, options: .mappedIfSafe) + + let compressedData = BZip2.compress(data: answerData) + let redecompressedData = try BZip2.decompress(data: compressedData) + + XCTAssertEqual(redecompressedData, answerData) + } + + func stringTest(_ string: String) throws { + guard let stringData = string.data(using: .utf8) else { + XCTFail("Unable to convert String to Data.") + return + } + + let compressedData = BZip2.compress(data: stringData) + let redecompressedData = try BZip2.decompress(data: compressedData) + + XCTAssertEqual(redecompressedData, stringData) + } + + func test1BZip2Compress() throws { + try stringTest("Hello, World!\n") + } + + func test2BZip2Compress() throws { + try stringTest("AAAAAAABBBBCCCD") + } + + func test3BZip2Compress() throws { + try stringTest("AAAAAAA") + } + + func test4BZip2Compress() throws { + try stringTest("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") + } + +}