diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 34fae351..1904c153 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -188,6 +188,7 @@ 723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */; }; 723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; }; 723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; }; + 723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */ = {isa = PBXBuildFile; fileRef = 723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */; }; 72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; @@ -1082,6 +1083,7 @@ 723B5DA51CF7AB0100365F95 /* SPUDownloaderProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUDownloaderProtocol.h; path = Downloader/SPUDownloaderProtocol.h; sourceTree = SOURCE_ROOT; }; 723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTouchBarButtonGroup.h; sourceTree = ""; }; 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTouchBarButtonGroup.m; sourceTree = ""; }; + 723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_channels.xml; sourceTree = ""; }; 7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStandardUpdaterController.h; sourceTree = ""; }; 7246E0A21C83B685003B4E75 /* SPUStandardUpdaterController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUStandardUpdaterController.m; sourceTree = ""; }; 724BB36C1D31D0B7005D534A /* org.sparkle-project.InstallerConnection.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = "org.sparkle-project.InstallerConnection.xpc"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1685,6 +1687,7 @@ 14958C6C19AEBC610061B14F /* test-pubkey.pem */, 5AF6C74E1AEA46D10014A3AB /* test.pkg */, 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */, + 723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */, 725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */, 722545B526805FF80036465C /* testappcast_info_updates.xml */, 5F1510A11C96E591006E1629 /* testnamespaces.xml */, @@ -2936,6 +2939,7 @@ files = ( 725B3A82263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml in Resources */, 14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */, + 723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */, 72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */, C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */, 72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */, diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 4406e813..c848fa34 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -173,22 +173,7 @@ allowedChannels = [NSSet set]; } - SUAppcast *macOSAppcast = [loadedAppcast copyByFilteringItems:^(SUAppcastItem *item) { - // We will never care about other OS's - BOOL macOSUpdate = [item isMacOsUpdate]; - if (!macOSUpdate) { - return NO; - } - - NSSet *channels = item.channels; - if (channels.count == 0) { - // Item is on the default channel - return YES; - } - - // Item channels and allowed channels must have one channel in common - return [channels intersectsSet:allowedChannels]; - }]; + SUAppcast *macOSAppcast = [[self class] filterAppcast:loadedAppcast forMacOSAndAllowedChannels:allowedChannels]; id applicationVersionComparator = [self versionComparator]; @@ -240,6 +225,27 @@ } } +// This method is used by unit tests ++ (SUAppcast *)filterAppcast:(SUAppcast *)appcast forMacOSAndAllowedChannels:(NSSet *)allowedChannels +{ + return [appcast copyByFilteringItems:^(SUAppcastItem *item) { + // We will never care about other OS's + BOOL macOSUpdate = [item isMacOsUpdate]; + if (!macOSUpdate) { + return NO; + } + + NSSet *channels = item.channels; + if (channels.count == 0) { + // Item is on the default channel + return YES; + } + + // Item channels and allowed channels must have one channel in common + return [channels intersectsSet:allowedChannels]; + }]; +} + // This method is used by unit tests + (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion { diff --git a/Tests/Resources/testappcast_channels.xml b/Tests/Resources/testappcast_channels.xml new file mode 100644 index 00000000..db0f1b73 --- /dev/null +++ b/Tests/Resources/testappcast_channels.xml @@ -0,0 +1,69 @@ + + + + For unit test only + + + Version 2.0 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + + + + + + Version 3.0 + 86400 + + + + + + + + + + + + + + Version 4.0 + 4.0 + Sat, 26 Jul 2014 15:20:13 +0000 + + + + + + + + Version 5.0 + 5.0 + + + + + + + + + Version 6.0 + 6.0 + + + + + + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index d3c25fd9..b27c35bb 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -76,6 +76,65 @@ class SUAppcastTest: XCTestCase { } } + func testChannelsAndMacOSReleases() { + let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_channels", withExtension: "xml")! + + do { + let testData = try Data(contentsOf: testURL) + + let versionComparator = SUStandardVersionComparator.default() + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + XCTAssertEqual(5, appcast.items.count) + + do { + let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:beta", "sparkle:nightly"]) + XCTAssertEqual(4, filteredAppcast.items.count) + + XCTAssertEqual("2.0", filteredAppcast.items[0].versionString) + XCTAssertEqual("3.0", filteredAppcast.items[1].versionString) + XCTAssertEqual("4.0", filteredAppcast.items[2].versionString) + XCTAssertEqual("5.0", filteredAppcast.items[3].versionString) + } + + do { + let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: []) + XCTAssertEqual(2, filteredAppcast.items.count) + XCTAssertEqual("2.0", filteredAppcast.items[0].versionString) + XCTAssertEqual("3.0", filteredAppcast.items[1].versionString) + } + + do { + let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:beta"]) + XCTAssertEqual(4, filteredAppcast.items.count) + XCTAssertEqual("2.0", filteredAppcast.items[0].versionString) + XCTAssertEqual("3.0", filteredAppcast.items[1].versionString) + XCTAssertEqual("4.0", filteredAppcast.items[2].versionString) + XCTAssertEqual("5.0", filteredAppcast.items[3].versionString) + } + + do { + let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:nightly"]) + XCTAssertEqual(3, filteredAppcast.items.count) + XCTAssertEqual("2.0", filteredAppcast.items[0].versionString) + XCTAssertEqual("3.0", filteredAppcast.items[1].versionString) + XCTAssertEqual("5.0", filteredAppcast.items[2].versionString) + } + + do { + let filteredAppcast = SUAppcastDriver.filterAppcast(appcast, forMacOSAndAllowedChannels: ["sparkle:madeup"]) + XCTAssertEqual("2.0", filteredAppcast.items[0].versionString) + XCTAssertEqual("3.0", filteredAppcast.items[1].versionString) + XCTAssertEqual(2, filteredAppcast.items.count) + } + } catch let err as NSError { + NSLog("%@", err) + XCTFail(err.localizedDescription) + } + } + func testCriticalUpdateVersion() { let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast", withExtension: "xml")! diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index d0e9251e..395426db 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -42,6 +42,8 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; + (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; ++ (SUAppcast *)filterAppcast:(SUAppcast *)appcast forMacOSAndAllowedChannels:(NSSet *)allowedChannels; + @end @interface SUBinaryDeltaUnarchiver (Private)