From 06be4cb66d1477674f9eafc280515ea2d68079d7 Mon Sep 17 00:00:00 2001 From: Eitot Date: Sat, 31 Aug 2024 10:56:16 +0200 Subject: [PATCH] Resolve Vienna Test build warnings --- Vienna Tests/CriteriaTests.swift | 8 ++--- Vienna Tests/UnarchiverTests.swift | 53 ++++++++++++++++-------------- Vienna.xcodeproj/project.pbxproj | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Vienna Tests/CriteriaTests.swift b/Vienna Tests/CriteriaTests.swift index 045efd76d2..8fc243d6cd 100644 --- a/Vienna Tests/CriteriaTests.swift +++ b/Vienna Tests/CriteriaTests.swift @@ -35,8 +35,6 @@ class CriteriaTests: XCTestCase { // Only called by the Database class when loading smart folders let criteriaTreeString = "1Yes" - let treeStringUnformatted: String = criteriaTreeString.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "") - let testCriteriaTree = genericConversionChecks(criteriaTreeString) XCTAssertTrue(testCriteriaTree.criteriaTree.first is Criteria, "Pass") @@ -132,10 +130,7 @@ class CriteriaTests: XCTestCase { """ - let testCriteriaTree = genericConversionChecks(criteriaTreeString) - - let treeStringUnformatted: String = criteriaTreeString.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "") - XCTAssertEqual(treeStringUnformatted, testCriteriaTree.string, "XML reproducible") + genericConversionChecks(criteriaTreeString) } func testNestedCriteriaSQLConversion() { @@ -254,6 +249,7 @@ class CriteriaTests: XCTestCase { genericConversionChecks(testCriteriaString) } + @discardableResult private func genericConversionChecks(_ criteriaTreeString: String) -> CriteriaTree { guard let testCriteriaTree = CriteriaTree(string: criteriaTreeString) else { XCTAssert(false) diff --git a/Vienna Tests/UnarchiverTests.swift b/Vienna Tests/UnarchiverTests.swift index f2e55d5425..af9320673c 100644 --- a/Vienna Tests/UnarchiverTests.swift +++ b/Vienna Tests/UnarchiverTests.swift @@ -26,28 +26,19 @@ class UnarchiverTests: XCTestCase { item.filename = "Test" item.size = 100 - // NSArchiver (deprecated) - var data = NSArchiver.archivedData(withRootObject: item) - XCTAssertNotNil(NSUnarchiver.unarchiveObject(with: data) as? DownloadItem) - XCTAssertNil(NSKeyedUnarchiver.unarchiveObject(with: data)) - XCTAssertThrowsError(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) - // NSKeyedArchiver without secure coding (deprecated; macOS 10.12 only) - data = NSKeyedArchiver.archivedData(withRootObject: item) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) + var data = NSKeyedArchiver.archivedData(withRootObject: item) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? DownloadItem) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) // NSKeyedArchiver with secure coding (macOS 10.13+) data = try NSKeyedArchiver.archivedData(withRootObject: item, requiringSecureCoding: false) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? DownloadItem) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) data = try NSKeyedArchiver.archivedData(withRootObject: item, requiringSecureCoding: true) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? DownloadItem) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: DownloadItem.self, from: data)) @@ -62,6 +53,34 @@ class UnarchiverTests: XCTestCase { field.type = .string field.visible = true + // NSKeyedArchiver without secure coding (deprecated; macOS 10.12 only) + var data = NSKeyedArchiver.archivedData(withRootObject: field) + XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) + XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + + // NSKeyedArchiver with secure coding (macOS 10.13+) + data = try NSKeyedArchiver.archivedData(withRootObject: field, requiringSecureCoding: false) + XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) + XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + + data = try NSKeyedArchiver.archivedData(withRootObject: field, requiringSecureCoding: true) + XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) + XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) + } + + @available(*, deprecated) + func testUnarchivingFieldWithUnkeyedArchive() throws { + let field = Field() + field.name = "Name" + field.displayName = "Display Name" + field.sqlField = "SQL Field" + field.tag = 1 + field.type = .string + field.visible = true + // NSArchiver (deprecated) var data = NSArchiver.archivedData(withRootObject: field) XCTAssertNotNil(NSUnarchiver.unarchiveObject(with: data) as? Field) @@ -71,39 +90,26 @@ class UnarchiverTests: XCTestCase { // NSKeyedArchiver without secure coding (deprecated; macOS 10.12 only) data = NSKeyedArchiver.archivedData(withRootObject: field) XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) - XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) - XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) - XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) // NSKeyedArchiver with secure coding (macOS 10.13+) data = try NSKeyedArchiver.archivedData(withRootObject: field, requiringSecureCoding: false) XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) - XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) - XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) - XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) data = try NSKeyedArchiver.archivedData(withRootObject: field, requiringSecureCoding: true) XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) - XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? Field) - XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) - XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: Field.self, from: data)) } func testUnarchivingSearchMethod() throws { let method = try XCTUnwrap(SearchMethod.allArticles) - // Note: SearchMethod has never supported NSArchiver, thus no testing for it needed. - // NSKeyedArchiver without secure coding (deprecated; macOS 10.12 only) var data = NSKeyedArchiver.archivedData(withRootObject: method) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? SearchMethod) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) // NSKeyedArchiver with secure coding (macOS 10.13+) data = try NSKeyedArchiver.archivedData(withRootObject: method, requiringSecureCoding: false) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? SearchMethod) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) @@ -113,7 +119,6 @@ class UnarchiverTests: XCTestCase { XCTAssertNotNil(unarchiver.decodeObject(of: SearchMethod.self, forKey: NSKeyedArchiveRootObjectKey)) data = try NSKeyedArchiver.archivedData(withRootObject: method, requiringSecureCoding: true) - XCTAssertNil(NSUnarchiver.unarchiveObject(with: data)) XCTAssertNotNil(NSKeyedUnarchiver.unarchiveObject(with: data) as? SearchMethod) XCTAssertNotNil(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) XCTAssertNoThrow(try NSKeyedUnarchiver.unarchivedObject(ofClass: SearchMethod.self, from: data)) diff --git a/Vienna.xcodeproj/project.pbxproj b/Vienna.xcodeproj/project.pbxproj index 379a25fc92..3ad9b03133 100644 --- a/Vienna.xcodeproj/project.pbxproj +++ b/Vienna.xcodeproj/project.pbxproj @@ -190,7 +190,7 @@ F68792872700A678009B7BB5 /* SecurityScopedBookmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68792862700A678009B7BB5 /* SecurityScopedBookmark.swift */; }; F689820A281DD62B0010F4C5 /* XMLFeed.m in Sources */ = {isa = PBXBuildFile; fileRef = F6898209281DD62B0010F4C5 /* XMLFeed.m */; }; F68DEBF82A35091600421FAB /* DispatchTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68DEBF72A35091600421FAB /* DispatchTimer.swift */; }; - F68FE3A6270F6DC700C89D16 /* UnarchiverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68FE3A5270F6DC700C89D16 /* UnarchiverTests.swift */; settings = {COMPILER_FLAGS = "-Wno-deprecated-type -Wno-deprecated-declarations"; }; }; + F68FE3A6270F6DC700C89D16 /* UnarchiverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68FE3A5270F6DC700C89D16 /* UnarchiverTests.swift */; }; F69140E41E71B94200D51BFF /* AppController+Notifications.m in Sources */ = {isa = PBXBuildFile; fileRef = F69140E31E71B94200D51BFF /* AppController+Notifications.m */; }; F692559A2572A32900D387D8 /* MMTabBarView in Frameworks */ = {isa = PBXBuildFile; productRef = F69255992572A32900D387D8 /* MMTabBarView */; }; F696D23E2561F9FC003DF0C0 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = F696D23D2561F9FC003DF0C0 /* Sparkle */; };