Skip to content

Commit e764480

Browse files
authored
Merge pull request #2035 from matis-schotte/master
Extend URLResponse tests
2 parents bbd2588 + 5cace9d commit e764480

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

Docs/Status.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ There is no _Complete_ status for test coverage because there are always additio
5656
| `URLProtocolClient` | Unimplemented | None | |
5757
| `NSURLRequest` | Complete | Incomplete | |
5858
| `NSMutableURLRequest` | Complete | Incomplete | |
59-
| `URLResponse` | Complete | Incomplete | |
59+
| `URLResponse` | Complete | Substantial | |
6060
| `NSHTTPURLResponse` | Complete | Substantial | |
6161
| `NSURL` | Mostly Complete | Substantial | Resource values remain unimplemented |
6262
| `NSURLQueryItem` | Complete | N/A | |

TestFoundation/TestURLResponse.swift

+33-25
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,63 @@ class TestURLResponse : XCTestCase {
1111
static var allTests: [(String, (TestURLResponse) -> () throws -> Void)] {
1212
return [
1313
("test_URL", test_URL),
14-
("test_MIMEType_1", test_MIMEType_1),
15-
("test_MIMEType_2", test_MIMEType_2),
14+
("test_MIMEType", test_MIMEType),
1615
("test_ExpectedContentLength", test_ExpectedContentLength),
1716
("test_TextEncodingName", test_TextEncodingName),
18-
("test_suggestedFilename", test_suggestedFilename),
17+
("test_suggestedFilename_1", test_suggestedFilename_1),
1918
("test_suggestedFilename_2", test_suggestedFilename_2),
2019
("test_suggestedFilename_3", test_suggestedFilename_3),
2120
("test_copywithzone", test_copyWithZone),
2221
("test_NSCoding", test_NSCoding),
2322
]
2423
}
2524

25+
let testURL = URL(string: "test")!
26+
2627
func test_URL() {
2728
let url = URL(string: "a/test/path")!
2829
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
2930
XCTAssertEqual(res.url, url, "should be the expected url")
3031
}
3132

32-
func test_MIMEType_1() {
33-
let mimetype = "text/plain"
34-
let res = URLResponse(url: URL(string: "test")!, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
33+
func test_MIMEType() {
34+
var mimetype: String? = "text/plain"
35+
var res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
3536
XCTAssertEqual(res.mimeType, mimetype, "should be the passed in mimetype")
36-
}
37-
38-
func test_MIMEType_2() {
39-
let mimetype = "APPlication/wordperFECT"
40-
let res = URLResponse(url: URL(string: "test")!, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
37+
38+
mimetype = "APPlication/wordperFECT"
39+
res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
40+
XCTAssertEqual(res.mimeType, mimetype, "should be the other mimetype")
41+
42+
mimetype = nil
43+
res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
4144
XCTAssertEqual(res.mimeType, mimetype, "should be the other mimetype")
4245
}
43-
46+
4447
func test_ExpectedContentLength() {
45-
let zeroContentLength = 0
46-
let positiveContentLength = 100
47-
let url = URL(string: "test")!
48-
let res1 = URLResponse(url: url, mimeType: "text/plain", expectedContentLength: zeroContentLength, textEncodingName: nil)
49-
XCTAssertEqual(res1.expectedContentLength, Int64(zeroContentLength), "should be Int65 of the zero length")
50-
let res2 = URLResponse(url: url, mimeType: "text/plain", expectedContentLength: positiveContentLength, textEncodingName: nil)
51-
XCTAssertEqual(res2.expectedContentLength, Int64(positiveContentLength), "should be Int64 of the positive content length")
48+
var contentLength = 100
49+
var res = URLResponse(url: testURL, mimeType: "text/plain", expectedContentLength: contentLength, textEncodingName: nil)
50+
XCTAssertEqual(res.expectedContentLength, Int64(contentLength), "should be positive Int64 content length")
51+
52+
contentLength = 0
53+
res = URLResponse(url: testURL, mimeType: nil, expectedContentLength: contentLength, textEncodingName: nil)
54+
XCTAssertEqual(res.expectedContentLength, Int64(contentLength), "should be zero Int64 content length")
55+
56+
contentLength = -1
57+
res = URLResponse(url: testURL, mimeType: nil, expectedContentLength: contentLength, textEncodingName: nil)
58+
XCTAssertEqual(res.expectedContentLength, Int64(contentLength), "should be invalid (-1) Int64 content length")
5259
}
5360

5461
func test_TextEncodingName() {
5562
let encoding = "utf8"
56-
let url = URL(string: "test")!
57-
let res1 = URLResponse(url: url, mimeType: nil, expectedContentLength: 0, textEncodingName: encoding)
58-
XCTAssertEqual(res1.textEncodingName, encoding, "should be the utf8 encoding")
59-
let res2 = URLResponse(url: url, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
60-
XCTAssertNil(res2.textEncodingName)
63+
var res = URLResponse(url: testURL, mimeType: nil, expectedContentLength: 0, textEncodingName: encoding)
64+
XCTAssertEqual(res.textEncodingName, encoding, "should be the utf8 encoding")
65+
66+
res = URLResponse(url: testURL, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
67+
XCTAssertNil(res.textEncodingName)
6168
}
6269

63-
func test_suggestedFilename() {
70+
func test_suggestedFilename_1() {
6471
let url = URL(string: "a/test/name.extension")!
6572
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
6673
XCTAssertEqual(res.suggestedFilename, "name.extension")
@@ -77,6 +84,7 @@ class TestURLResponse : XCTestCase {
7784
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
7885
XCTAssertEqual(res.suggestedFilename, "Unknown")
7986
}
87+
8088
func test_copyWithZone() {
8189
let url = URL(string: "a/test/path")!
8290
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)

0 commit comments

Comments
 (0)