mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Add some tests for BZip2 compression
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
06393DFB1F1A858000A647A0 /* long_test_oldgnu.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = long_test_oldgnu.tar; sourceTree = "<group>"; };
|
||||
06393DFC1F1A858000A647A0 /* long_test_pax.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = long_test_pax.tar; sourceTree = "<group>"; };
|
||||
063D0CA11F5B17EB00D3464C /* BZip2CompressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BZip2CompressionTests.swift; sourceTree = "<group>"; };
|
||||
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 */,
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user