Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Vienna Test build warnings #1806

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Vienna Tests/CriteriaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class CriteriaTests: XCTestCase {
// Only called by the Database class when loading smart folders
let criteriaTreeString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><criteriagroup condition=\"all\"><criteria field=\"\(flaggedField.name!)\"><operator>1</operator><value>Yes</value></criteria></criteriagroup>"

let treeStringUnformatted: String = criteriaTreeString.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "")

let testCriteriaTree = genericConversionChecks(criteriaTreeString)

XCTAssertTrue(testCriteriaTree.criteriaTree.first is Criteria, "Pass")
Expand Down Expand Up @@ -132,10 +130,7 @@ class CriteriaTests: XCTestCase {
</criteriagroup>
"""

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() {
Expand Down Expand Up @@ -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)
Expand Down
53 changes: 29 additions & 24 deletions Vienna Tests/UnarchiverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion Vienna.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down