Files
Sparkle/Tests/SUAppcastTest.swift
Thomas Tempelmann c1488b0515 Adds test cases for "sparkle:criticalUpdate" tag. (#999)
* Adds a test case for the "criticalUpdate" appcast tag (not as a XCTest but simply as an assert inside the test app, because I was lazy and am working on an older Xcode version that does not support the currently needed swift version for the XCTest in SUAppcastTest.swift).

* Tests the "criticalUpdate" appcast tag, using the proper XCTest swift class. I haven't tested this, though, due to the lack of the needed Xcode version.

* Test case for Appcast now checks all 4 items for the correct "criticalUpdate" state.

* Adds a test case for the "criticalUpdate" appcast tag (not as a XCTest but simply as an assert inside the test app, because I was lazy and am working on an older Xcode version that does not support the currently needed swift version for the XCTest in SUAppcastTest.swift). (reverted from commit 3ce1c9790b)
2017-01-16 00:02:32 +00:00

92 lines
3.8 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 testFileUrl = URL(fileURLWithPath: testFile);
XCTAssertNotNil(testFileUrl);
do {
let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) 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 = SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.default())
XCTAssertEqual(bestAppcastItem, items[1])
XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch")
// Test latest delta update item available
var latestDeltaItem: SUAppcastItem? = nil
SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.default())
XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch")
// Test a delta item that does not exist
var nonexistantDeltaItem: SUAppcastItem? = nil
SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.default())
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 testFileUrl = URL(fileURLWithPath: testFile);
XCTAssertNotNil(testFileUrl);
do {
let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) 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);
}
}
}