Refactor tests as well

This commit is contained in:
Rainux Luo
2017-01-09 22:00:34 +08:00
parent dbc6ee92d5
commit dfb06cdf70
3 changed files with 103 additions and 153 deletions

View File

@ -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 {

View File

@ -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.
}
}
}