From b9c664687dd720cf6ec0f9ea3925bbc65e6a3841 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 19 Feb 2016 12:43:41 -0500 Subject: [PATCH] Take delta updates in account and add tests for them --- Sparkle/SUBasicUpdateDriver.m | 24 ++++++++++++++-------- Tests/Resources/testappcast.xml | 15 ++++++++++++++ Tests/SUAppcastTest.swift | 19 +++++++++++++++-- Tests/Sparkle Unit Tests-Bridging-Header.h | 2 +- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 1362a57e..51ea4896 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -82,7 +82,7 @@ return comparator; } -+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { SUAppcastItem *item = nil; for(SUAppcastItem *candidate in appcastItems) { @@ -92,6 +92,14 @@ } } } + + if (item && deltaItem) { + SUAppcastItem *deltaUpdateItem = [item deltaUpdates][hostVersion]; + if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { + *deltaItem = deltaUpdateItem; + } + } + return item; } @@ -153,14 +161,12 @@ else // If not, we'll take care of it ourselves. { // Find the best supported update - item = [[self class] bestAppcastItemFromAppcastItems:ac.items withComparator:[self versionComparator]]; - - if (item) { - SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]]; - if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) { - self.nonDeltaUpdateItem = item; - item = deltaUpdateItem; - } + SUAppcastItem *deltaUpdateItem = nil; + item = [[self class] bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; + + if (item && deltaUpdateItem) { + self.nonDeltaUpdateItem = item; + item = deltaUpdateItem; } } diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index 18a256ac..e3894b41 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -12,6 +12,21 @@ Version 3.0 + + + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 097cf95b..14fa2978 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -39,9 +39,24 @@ class SUAppcastTest: XCTestCase { XCTAssertNil(items[3].itemDescription); XCTAssertNil(items[3].dateString) - let bestAppcastItem = SUBasicUpdateDriver.bestAppcastItemFromAppcastItems(items, withComparator: SUStandardVersionComparator.defaultComparator()) - + // Test best appcast item & a delta update item + var deltaItem: SUAppcastItem? = nil + let bestAppcastItem = SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.defaultComparator()) + 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.bestItemFromAppcastItems(items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch") + + // Test a delta item that does not exist + var nonexistantDeltaItem: SUAppcastItem? = nil + SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.defaultComparator()) + + XCTAssertNil(nonexistantDeltaItem) } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 8794e12b..d08dafb8 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -28,7 +28,7 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; @interface SUBasicUpdateDriver (Private) -+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id)comparator; ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator; @end