Refactor tests as well
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user