mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Take delta updates in account and add tests for them
This commit is contained in:
1 parent
2a3e88bf96
commit
b9c664687d
4 files changed
+48
-12
No files matched your search
Vendored
+15
-9
@@ -82,7 +82,7 @@
|
||||
return comparator;
|
||||
}
|
||||
|
||||
+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id<SUVersionComparison>)comparator
|
||||
+ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id<SUVersionComparison>)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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,21 @@
|
||||
<item>
|
||||
<title>Version 3.0</title>
|
||||
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" sparkle:version="3.0" />
|
||||
<sparkle:deltas>
|
||||
<enclosure url="http://0.0.0.0:1337/3.0_from_2.0.patch"
|
||||
sparkle:version="3.0"
|
||||
sparkle:deltaFrom="2.0"
|
||||
length="1235"
|
||||
type="application/octet-stream"
|
||||
sparkle:dsaSignature="..." />
|
||||
|
||||
<enclosure url="http://0.0.0.0:1337/3.0_from_1.0.patch"
|
||||
sparkle:version="3.0"
|
||||
sparkle:deltaFrom="1.0"
|
||||
length="1485"
|
||||
type="application/octet-stream"
|
||||
sparkle:dsaSignature="..." />
|
||||
</sparkle:deltas>
|
||||
</item>
|
||||
<!-- A release testing minimumSystemVersion -->
|
||||
<item>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -28,7 +28,7 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
|
||||
|
||||
@interface SUBasicUpdateDriver (Private)
|
||||
|
||||
+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id<SUVersionComparison>)comparator;
|
||||
+ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id<SUVersionComparison>)comparator;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in new issue
Block a user