From 33cb74cdeb35f6586ff7a7b9300fafe15fcc3231 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 19 Sep 2021 17:19:05 +0300 Subject: [PATCH] [Tests] Add tests for different format minor versions of 7-Zip --- SWCompression.xcodeproj/project.pbxproj | 12 +++++ Tests/SevenZipTests.swift | 61 +++++++++++++++++++++++++ Tests/Test Files | 2 +- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index bb016374..a8508c56 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -220,6 +220,9 @@ E652D8F5263D678000FC229B /* test_nonstandard_runlength.answer in Resources */ = {isa = PBXBuildFile; fileRef = E652D8F4263D678000FC229B /* test_nonstandard_runlength.answer */; }; E66F36242538726E00076A6E /* test_empty.lzma in Resources */ = {isa = PBXBuildFile; fileRef = E66F36232538726E00076A6E /* test_empty.lzma */; }; E66F362C2538E2B700076A6E /* test_empty.zlib in Resources */ = {isa = PBXBuildFile; fileRef = E66F362B2538E2B700076A6E /* test_empty.zlib */; }; + E6EDD6A826F7767F00884532 /* test_minor_version_3.7z in Resources */ = {isa = PBXBuildFile; fileRef = E6EDD6A626F7767E00884532 /* test_minor_version_3.7z */; }; + E6EDD6A926F7767F00884532 /* test_minor_version_4.7z in Resources */ = {isa = PBXBuildFile; fileRef = E6EDD6A726F7767E00884532 /* test_minor_version_4.7z */; }; + E6EDD6AC26F77C0E00884532 /* test_minor_version_2.7z in Resources */ = {isa = PBXBuildFile; fileRef = E6EDD6AB26F77C0E00884532 /* test_minor_version_2.7z */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -447,6 +450,9 @@ E652D8F4263D678000FC229B /* test_nonstandard_runlength.answer */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_nonstandard_runlength.answer; sourceTree = ""; }; E66F36232538726E00076A6E /* test_empty.lzma */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_empty.lzma; sourceTree = ""; }; E66F362B2538E2B700076A6E /* test_empty.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_empty.zlib; sourceTree = ""; }; + E6EDD6A626F7767E00884532 /* test_minor_version_3.7z */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_minor_version_3.7z; sourceTree = ""; }; + E6EDD6A726F7767E00884532 /* test_minor_version_4.7z */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_minor_version_4.7z; sourceTree = ""; }; + E6EDD6AB26F77C0E00884532 /* test_minor_version_2.7z */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_minor_version_2.7z; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -883,6 +889,9 @@ 06F066061FFB763300312A82 /* test_win.7z */, 0627A4D220FE521B0023987C /* test_unicode.7z */, 068D070321368617002A6C3B /* test_delta_filter.7z */, + E6EDD6AB26F77C0E00884532 /* test_minor_version_2.7z */, + E6EDD6A626F7767E00884532 /* test_minor_version_3.7z */, + E6EDD6A726F7767E00884532 /* test_minor_version_4.7z */, 06F066071FFB763300312A82 /* SWCompressionSourceCode.7z */, ); path = 7z; @@ -991,6 +1000,7 @@ 06F066201FFB763300312A82 /* test1.answer in Resources */, 06F0664E1FFB763400312A82 /* test_v7.tar in Resources */, 06F0662E1FFB763400312A82 /* test2.gz in Resources */, + E6EDD6AC26F77C0E00884532 /* test_minor_version_2.7z in Resources */, 06F0665C1FFB763400312A82 /* test9.lzma in Resources */, 06F066661FFB763400312A82 /* test3.7z in Resources */, 06F0664B1FFB763400312A82 /* test.tar in Resources */, @@ -1073,6 +1083,7 @@ 06F066351FFB763400312A82 /* test5.xz in Resources */, 06F066631FFB763400312A82 /* test_complicated_coding_scheme.7z in Resources */, 06F066641FFB763400312A82 /* test_anti_file.7z in Resources */, + E6EDD6A826F7767F00884532 /* test_minor_version_3.7z in Resources */, 064D01AD20FD077D00CAE058 /* test_unicode_pax.tar in Resources */, 06F0665E1FFB763400312A82 /* test_empty_cont.7z in Resources */, 06F066731FFB763400312A82 /* test3.bz2 in Resources */, @@ -1083,6 +1094,7 @@ 06F066571FFB763400312A82 /* test_empty_file.tar in Resources */, 06F066441FFB763400312A82 /* test_data_descriptor.zip in Resources */, 06F066581FFB763400312A82 /* full_test.tar in Resources */, + E6EDD6A926F7767F00884532 /* test_minor_version_4.7z in Resources */, 06F0662B1FFB763400312A82 /* test3.gz in Resources */, 06F0664C1FFB763400312A82 /* test_pax.tar in Resources */, 06F0663A1FFB763400312A82 /* test_multi.xz in Resources */, diff --git a/Tests/SevenZipTests.swift b/Tests/SevenZipTests.swift index 8d7e4a42..e4d3bfa0 100644 --- a/Tests/SevenZipTests.swift +++ b/Tests/SevenZipTests.swift @@ -393,4 +393,65 @@ class SevenZipTests: XCTestCase { XCTAssertEqual(entries[0].data, answerData) } + func testFormatMinorVersions() throws { + let answerData = try Constants.data(forAnswer: "test2") + + var testData = try Constants.data(forTest: "test_minor_version_2", withType: SevenZipTests.testType) + var entries = try SevenZipContainer.open(container: testData) + + XCTAssertEqual(entries.count, 1) + XCTAssertEqual(entries[0].info.name, "test2.answer") + XCTAssertEqual(entries[0].info.type, .regular) + XCTAssertEqual(entries[0].info.size, answerData.count) + XCTAssertEqual(entries[0].info.permissions, Permissions(rawValue: 0)) + XCTAssertEqual(entries[0].info.dosAttributes, DosAttributes(rawValue: 0x20)) + // Checking times' values is a bit difficult since they are extremely precise. + XCTAssertNotNil(entries[0].info.modificationTime) + XCTAssertNil(entries[0].info.accessTime) + XCTAssertNil(entries[0].info.creationTime) + XCTAssertEqual(entries[0].info.hasStream, true) + XCTAssertEqual(entries[0].info.isEmpty, false) + XCTAssertEqual(entries[0].info.isAnti, false) + XCTAssertEqual(entries[0].info.crc, 4168830779) + XCTAssertEqual(entries[0].data, answerData) + + testData = try Constants.data(forTest: "test_minor_version_3", withType: SevenZipTests.testType) + entries = try SevenZipContainer.open(container: testData) + + XCTAssertEqual(entries.count, 1) + XCTAssertEqual(entries[0].info.name, "test2.answer") + XCTAssertEqual(entries[0].info.type, .regular) + XCTAssertEqual(entries[0].info.size, answerData.count) + XCTAssertEqual(entries[0].info.permissions, Permissions(rawValue: 420)) + XCTAssertEqual(entries[0].info.dosAttributes, DosAttributes(rawValue: 0x20)) + // Checking times' values is a bit difficult since they are extremely precise. + XCTAssertNotNil(entries[0].info.modificationTime) + XCTAssertNotNil(entries[0].info.accessTime) + XCTAssertNotNil(entries[0].info.creationTime) + XCTAssertEqual(entries[0].info.hasStream, true) + XCTAssertEqual(entries[0].info.isEmpty, false) + XCTAssertEqual(entries[0].info.isAnti, false) + XCTAssertEqual(entries[0].info.crc, 4168830779) + XCTAssertEqual(entries[0].data, answerData) + + testData = try Constants.data(forTest: "test_minor_version_4", withType: SevenZipTests.testType) + entries = try SevenZipContainer.open(container: testData) + + XCTAssertEqual(entries.count, 1) + XCTAssertEqual(entries[0].info.name, "test2.answer") + XCTAssertEqual(entries[0].info.type, .regular) + XCTAssertEqual(entries[0].info.size, answerData.count) + XCTAssertEqual(entries[0].info.permissions, Permissions(rawValue: 420)) + XCTAssertEqual(entries[0].info.dosAttributes, DosAttributes(rawValue: 0x20)) + // Checking times' values is a bit difficult since they are extremely precise. + XCTAssertNotNil(entries[0].info.modificationTime) + XCTAssertNotNil(entries[0].info.accessTime) + XCTAssertNotNil(entries[0].info.creationTime) + XCTAssertEqual(entries[0].info.hasStream, true) + XCTAssertEqual(entries[0].info.isEmpty, false) + XCTAssertEqual(entries[0].info.isAnti, false) + XCTAssertEqual(entries[0].info.crc, 4168830779) + XCTAssertEqual(entries[0].data, answerData) + } + } diff --git a/Tests/Test Files b/Tests/Test Files index fe35c32f..36e6d8fa 160000 --- a/Tests/Test Files +++ b/Tests/Test Files @@ -1 +1 @@ -Subproject commit fe35c32fdab1aab6becabc1ade18408a42e32113 +Subproject commit 36e6d8fa8e7468c4572206f40f6fe8c10fbd7a3e