diff --git a/ShadowsocksX-NG.xcodeproj/project.pbxproj b/ShadowsocksX-NG.xcodeproj/project.pbxproj index 792c650..8bd7cc7 100755 --- a/ShadowsocksX-NG.xcodeproj/project.pbxproj +++ b/ShadowsocksX-NG.xcodeproj/project.pbxproj @@ -59,7 +59,6 @@ C6E28E951DA79705004F8330 /* HTTPPreferencesWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6E28E971DA79705004F8330 /* HTTPPreferencesWindowController.xib */; }; C8E42A6C1D4F270A0074C7EA /* UserRulesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */; }; C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */; }; - D829DB3F1E20262300FB5E1E /* UtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D829DB3E1E20262300FB5E1E /* UtilsTests.swift */; }; D8E3630B1E2072980027449B /* ServerProfileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8E3630A1E2072980027449B /* ServerProfileTests.swift */; }; E0E57CCA7EB34B90F9D340F2 /* Pods_ShadowsocksX_NGTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 388120F062D7EB7DD0D8DDCA /* Pods_ShadowsocksX_NGTests.framework */; }; F0809FF1595BE2966343D3C7 /* libPods-proxy_conf_helper.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E7783AEDB4A3BDDC9FF16AC /* libPods-proxy_conf_helper.a */; }; @@ -178,7 +177,6 @@ C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserRulesController.swift; sourceTree = ""; }; C8E42A6F1D4F2CAF0074C7EA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/UserRulesController.xib; sourceTree = ""; }; C8E42A721D4F2CB10074C7EA /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/UserRulesController.strings"; sourceTree = ""; }; - D829DB3E1E20262300FB5E1E /* UtilsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UtilsTests.swift; sourceTree = ""; }; D8E3630A1E2072980027449B /* ServerProfileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerProfileTests.swift; sourceTree = ""; }; E9E9FB3855DA55D0710EE7BD /* Pods-ShadowsocksX-NG.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.release.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.release.xcconfig"; sourceTree = ""; }; FE3237E9FB24D9B924A0E630 /* Pods-ShadowsocksX-NG.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.debug.xcconfig"; sourceTree = ""; }; @@ -314,7 +312,6 @@ isa = PBXGroup; children = ( D8E3630A1E2072980027449B /* ServerProfileTests.swift */, - D829DB3E1E20262300FB5E1E /* UtilsTests.swift */, 9B0BFFF81D0460A70040E62B /* ShadowsocksX_NGTests.swift */, 9B0BFFFA1D0460A70040E62B /* Info.plist */, ); @@ -672,7 +669,6 @@ buildActionMask = 2147483647; files = ( 9B0BFFF91D0460A70040E62B /* ShadowsocksX_NGTests.swift in Sources */, - D829DB3F1E20262300FB5E1E /* UtilsTests.swift in Sources */, D8E3630B1E2072980027449B /* ServerProfileTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ShadowsocksX-NGTests/ServerProfileTests.swift b/ShadowsocksX-NGTests/ServerProfileTests.swift index 63b9a50..d942895 100644 --- a/ShadowsocksX-NGTests/ServerProfileTests.swift +++ b/ShadowsocksX-NGTests/ServerProfileTests.swift @@ -11,12 +11,6 @@ import XCTest class ServerProfileTests: XCTestCase { - // "ss://aes-256-cfb:password@example.com:8388" - let profileUrl = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OA") - - // "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true" - let profileFullUrl = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OD9SZW1hcms9UHJpc20mT1RBPXRydWU") - var profile: ServerProfile! override func setUp() { @@ -36,20 +30,7 @@ class ServerProfileTests: XCTestCase { super.tearDown() } - func testServerProfileURL() { - let parsed = ServerProfile(url: profile.URL())?.toDictionary() - - XCTAssertNotNil(parsed) - - XCTAssertEqual(parsed?["ServerHost"] as? String, profile.serverHost) - XCTAssertEqual(parsed?["ServerPort"] as? UInt16, profile.serverPort) - XCTAssertEqual(parsed?["Method"] as? String, profile.method) - XCTAssertEqual(parsed?["Password"] as? String, profile.password) - XCTAssertEqual(parsed?["Remark"] as? String, profile.remark) - XCTAssertEqual(parsed?["OTA"] as? Bool, profile.ota) - } - - func testServerProfileInitFromURL() { + func testInitWithSelfGeneratedURL() { let newProfile = ServerProfile.init(url: profile.URL()) XCTAssertEqual(newProfile?.serverHost, profile.serverHost) @@ -60,6 +41,108 @@ class ServerProfileTests: XCTestCase { XCTAssertEqual(newProfile?.ota, profile.ota) } + func testInitWithPlainURL() { + let url = URL(string: "ss://aes-256-cfb:password@example.com:8388") + + let profile = ServerProfile(url: url) + + XCTAssertNotNil(profile) + + XCTAssertEqual(profile?.serverHost, "example.com") + XCTAssertEqual(profile?.serverPort, 8388) + XCTAssertEqual(profile?.method, "aes-256-cfb") + XCTAssertEqual(profile?.password, "password") + XCTAssertEqual(profile?.remark, "") + XCTAssertEqual(profile?.ota, false) + } + + func testInitWithPlainURLandQuery() { + let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true") + + let profile = ServerProfile(url: url) + + XCTAssertNotNil(profile) + + XCTAssertEqual(profile?.serverHost, "example.com") + XCTAssertEqual(profile?.serverPort, 8388) + XCTAssertEqual(profile?.method, "aes-256-cfb") + XCTAssertEqual(profile?.password, "password") + XCTAssertEqual(profile?.remark, "Prism") + XCTAssertEqual(profile?.ota, true) + } + + func testInitWithPlainURLandAnotherQuery() { + let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=0") + + let profile = ServerProfile(url: url) + + XCTAssertNotNil(profile) + + XCTAssertEqual(profile?.serverHost, "example.com") + XCTAssertEqual(profile?.serverPort, 8388) + XCTAssertEqual(profile?.method, "aes-256-cfb") + XCTAssertEqual(profile?.password, "password") + XCTAssertEqual(profile?.remark, "Prism") + XCTAssertEqual(profile?.ota, false) + } + + func testInitWithBase64EncodedURL() { + // "ss://aes-256-cfb:password@example.com:8388" + let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OA") + + let profile = ServerProfile(url: url) + + XCTAssertNotNil(profile) + + XCTAssertEqual(profile?.serverHost, "example.com") + XCTAssertEqual(profile?.serverPort, 8388) + XCTAssertEqual(profile?.method, "aes-256-cfb") + XCTAssertEqual(profile?.password, "password") + XCTAssertEqual(profile?.remark, "") + XCTAssertEqual(profile?.ota, false) + } + + func testInitWithBase64EncodedURLandQuery() { + // "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true" + let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OD9SZW1hcms9UHJpc20mT1RBPXRydWU") + + let profile = ServerProfile(url: url) + + XCTAssertNotNil(profile) + + XCTAssertEqual(profile?.serverHost, "example.com") + XCTAssertEqual(profile?.serverPort, 8388) + XCTAssertEqual(profile?.method, "aes-256-cfb") + XCTAssertEqual(profile?.password, "password") + XCTAssertEqual(profile?.remark, "Prism") + XCTAssertEqual(profile?.ota, true) + } + + func testInitWithEmptyURL() { + let url = URL(string: "ss://") + + let profile = ServerProfile(url: url) + + XCTAssertNil(profile) + } + + func testInitWithInvalidURL() { + let url = URL(string: "ss://invalid url") + + let profile = ServerProfile(url: url) + + XCTAssertNil(profile) + } + + func testInitWithBase64EncodedInvalidURL() { + // "ss://invalid url" + let url = URL(string: "ss://aW52YWxpZCB1cmw") + + let profile = ServerProfile(url: url) + + XCTAssertNil(profile) + } + func testPerformanceExample() { // This is an example of a performance test case. self.measure { diff --git a/ShadowsocksX-NGTests/UtilsTests.swift b/ShadowsocksX-NGTests/UtilsTests.swift deleted file mode 100644 index 36297ad..0000000 --- a/ShadowsocksX-NGTests/UtilsTests.swift +++ /dev/null @@ -1,129 +0,0 @@ -// -// UtilsTests.swift -// ShadowsocksX-NG -// -// Created by Rainux Luo on 07/01/2017. -// Copyright © 2017 qiuyuzhou. All rights reserved. -// - -import XCTest -@testable import ShadowsocksX_NG - -class UtilsTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testParseSSURLwithPlainURL() { - let url = URL(string: "ss://aes-256-cfb:password@example.com:8388") - - let profile = ServerProfile(url: url)?.toDictionary() - - XCTAssertNotNil(profile) - - XCTAssertEqual(profile?["ServerHost"] as? String, "example.com") - XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388) - XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb") - XCTAssertEqual(profile?["Password"] as? String, "password") - } - - func testParseSSURLwithPlainURLandQuery() { - let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true") - - let profile = ServerProfile(url: url)?.toDictionary() - - XCTAssertNotNil(profile) - - XCTAssertEqual(profile?["ServerHost"] as? String, "example.com") - XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388) - XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb") - XCTAssertEqual(profile?["Password"] as? String, "password") - XCTAssertEqual(profile?["Remark"] as? String, "Prism") - XCTAssertEqual(profile?["OTA"] as? Bool, true) - } - - func testParseSSURLwithPlainURLandAnotherQuery() { - let url = URL(string: "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=0") - - let profile = ServerProfile(url: url)?.toDictionary() - - XCTAssertNotNil(profile) - - XCTAssertEqual(profile?["ServerHost"] as? String, "example.com") - XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388) - XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb") - XCTAssertEqual(profile?["Password"] as? String, "password") - XCTAssertEqual(profile?["Remark"] as? String, "Prism") - XCTAssertEqual(profile?["OTA"] as? Bool, false) - } - - func testParseSSURLwithBase64EncodedURL() { - // "ss://aes-256-cfb:password@example.com:8388" - let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OA") - - let profile = ServerProfile(url: url)?.toDictionary() - - XCTAssertNotNil(profile) - - XCTAssertEqual(profile?["ServerHost"] as? String, "example.com") - XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388) - XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb") - XCTAssertEqual(profile?["Password"] as? String, "password") - } - - func testParseSSURLwithBase64EncodedURLandQuery() { - // "ss://aes-256-cfb:password@example.com:8388?Remark=Prism&OTA=true" - let url = URL(string: "ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmRAZXhhbXBsZS5jb206ODM4OD9SZW1hcms9UHJpc20mT1RBPXRydWU") - - let profile = ServerProfile(url: url)?.toDictionary() - - XCTAssertNotNil(profile) - - XCTAssertEqual(profile?["ServerHost"] as? String, "example.com") - XCTAssertEqual(profile?["ServerPort"] as? UInt16, 8388) - XCTAssertEqual(profile?["Method"] as? String, "aes-256-cfb") - XCTAssertEqual(profile?["Password"] as? String, "password") - XCTAssertEqual(profile?["Remark"] as? String, "Prism") - XCTAssertEqual(profile?["OTA"] as? Bool, true) - } - - func testParseSSURLwithEmptyURL() { - let url = URL(string: "ss://") - - let profile = ServerProfile(url: url) - - XCTAssertNil(profile) - } - - func testParseSSURLwithInvalidURL() { - let url = URL(string: "ss://invalid url") - - let profile = ServerProfile(url: url) - - XCTAssertNil(profile) - } - - func testParseSSURLwithBase64EncodedInvalidURL() { - // "ss://invalid url" - let url = URL(string: "ss://aW52YWxpZCB1cmw") - - let profile = ServerProfile(url: url) - - XCTAssertNil(profile) - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } - -}