mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
* Quiet warnings from Swift compiler: "Using '!' here is deprecated and will be removed in a future release" * Ignore diagnostics that yield 'messaging unqualified id' warnings when calling XCTAssertNotEqualObjects. I have filed a bug with Apple, Radar #45968630, requesting that they quiet the warning internally to the macro implementation. * When setting the access time on a directory and its contents, set the access time on the directory last so that it will be guaranteed to match the expected value. There is a side-effect of calling getFileSystemRepresentation that it sets the access time of its container folder, presumably because of an implementatiton detail of how Foundation builds up the path. Note there is another problem here that the order of items from NSDirectoryEnumerator is undefined, so some of the interior items of a directory will undoubtedly end up getting slightly varying access times set upon them. However, for the purposes of Sparkle's use of this method to "keep things alive" in /tmp, I don't think there is an issue. This fix addresses a failing unit test testUpdateFileAccessTime, which was failing because of very slight differences in access time created by the problem described.
90 lines
3.7 KiB
Swift
90 lines
3.7 KiB
Swift
//
|
|
// SUAppcastTest.swift
|
|
// Sparkle
|
|
//
|
|
// Created by Kornel on 17/02/2016.
|
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
import Sparkle;
|
|
|
|
class SUAppcastTest: XCTestCase {
|
|
|
|
func testParseAppcast() {
|
|
let appcast = SUAppcast();
|
|
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testappcast", ofType: "xml")!;
|
|
let testData = NSData(contentsOfFile: testFile)!
|
|
|
|
do {
|
|
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem];
|
|
|
|
XCTAssertEqual(4, items.count);
|
|
|
|
XCTAssertEqual("Version 2.0", items[0].title);
|
|
XCTAssertEqual("desc", items[0].itemDescription);
|
|
XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString)
|
|
XCTAssertTrue(items[0].isCriticalUpdate);
|
|
|
|
// This is the best release matching our system version
|
|
XCTAssertEqual("Version 3.0", items[1].title);
|
|
XCTAssertNil(items[1].itemDescription);
|
|
XCTAssertNil(items[1].dateString)
|
|
XCTAssertFalse(items[1].isCriticalUpdate);
|
|
|
|
XCTAssertEqual("Version 4.0", items[2].title);
|
|
XCTAssertNil(items[2].itemDescription);
|
|
XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString)
|
|
XCTAssertFalse(items[2].isCriticalUpdate);
|
|
|
|
XCTAssertEqual("Version 5.0", items[3].title);
|
|
XCTAssertNil(items[3].itemDescription);
|
|
XCTAssertNil(items[3].dateString)
|
|
XCTAssertFalse(items[3].isCriticalUpdate);
|
|
|
|
// Test best appcast item & a delta update item
|
|
var deltaItem: SUAppcastItem? = nil
|
|
let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator())
|
|
|
|
XCTAssertEqual(bestAppcastItem, items[1])
|
|
XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch")
|
|
|
|
// Test latest delta update item available
|
|
var latestDeltaItem: SUAppcastItem? = nil
|
|
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator())
|
|
|
|
XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch")
|
|
|
|
// Test a delta item that does not exist
|
|
var nonexistantDeltaItem: SUAppcastItem? = nil
|
|
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator())
|
|
|
|
XCTAssertNil(nonexistantDeltaItem)
|
|
} catch let err as NSError {
|
|
NSLog("%@", err);
|
|
XCTFail(err.localizedDescription);
|
|
}
|
|
}
|
|
|
|
func testNamespaces() {
|
|
let appcast = SUAppcast();
|
|
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testnamespaces", ofType: "xml")!;
|
|
let testData = NSData(contentsOfFile: testFile)!
|
|
|
|
do {
|
|
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem];
|
|
|
|
XCTAssertEqual(2, items.count);
|
|
|
|
XCTAssertEqual("Version 2.0", items[1].title);
|
|
XCTAssertEqual("desc", items[1].itemDescription);
|
|
XCTAssertNotNil(items[0].releaseNotesURL);
|
|
XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString);
|
|
} catch let err as NSError {
|
|
NSLog("%@", err);
|
|
XCTFail(err.localizedDescription);
|
|
}
|
|
}
|
|
|
|
}
|