Skip to content

Commit cd71e72

Browse files
author
kirei
committed
Extend URLResponse tests
1 parent a733b6b commit cd71e72

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
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

+35-19
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@ class TestURLResponse : XCTestCase {
1313
("test_URL", test_URL),
1414
("test_MIMEType_1", test_MIMEType_1),
1515
("test_MIMEType_2", test_MIMEType_2),
16-
("test_ExpectedContentLength", test_ExpectedContentLength),
17-
("test_TextEncodingName", test_TextEncodingName),
18-
("test_suggestedFilename", test_suggestedFilename),
16+
("test_MIMEType_notAvailable", test_MIMEType_notAvailable),
17+
("test_ExpectedContentLength_positive", test_ExpectedContentLength_positive),
18+
("test_ExpectedContentLength_negative", test_ExpectedContentLength_negative),
19+
("test_TextEncodingName_positive", test_TextEncodingName_positive),
20+
("test_TextEncodingName_negative", test_TextEncodingName_negative),
21+
("test_suggestedFilename_1", test_suggestedFilename_1),
1922
("test_suggestedFilename_2", test_suggestedFilename_2),
2023
("test_suggestedFilename_3", test_suggestedFilename_3),
2124
("test_copywithzone", test_copyWithZone),
2225
("test_NSCoding", test_NSCoding),
2326
]
2427
}
2528

29+
let testURL = URL(string: "test")!
30+
2631
func test_URL() {
2732
let url = URL(string: "a/test/path")!
2833
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
@@ -31,36 +36,46 @@ class TestURLResponse : XCTestCase {
3136

3237
func test_MIMEType_1() {
3338
let mimetype = "text/plain"
34-
let res = URLResponse(url: URL(string: "test")!, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
39+
let res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
3540
XCTAssertEqual(res.mimeType, mimetype, "should be the passed in mimetype")
3641
}
3742

3843
func test_MIMEType_2() {
3944
let mimetype = "APPlication/wordperFECT"
40-
let res = URLResponse(url: URL(string: "test")!, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
45+
let res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
4146
XCTAssertEqual(res.mimeType, mimetype, "should be the other mimetype")
4247
}
43-
44-
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+
49+
func test_MIMEType_notAvailable() {
50+
let mimetype: String? = nil
51+
let res = URLResponse(url: testURL, mimeType: mimetype, expectedContentLength: 0, textEncodingName: nil)
52+
XCTAssertEqual(res.mimeType, mimetype, "should be the other mimetype")
53+
}
54+
55+
func test_ExpectedContentLength_positive() {
56+
let contentLength = 100
57+
let res1 = URLResponse(url: testURL, mimeType: "text/plain", expectedContentLength: contentLength, textEncodingName: nil)
58+
XCTAssertEqual(res1.expectedContentLength, Int64(contentLength), "should be positive Int64 content length")
5259
}
5360

54-
func test_TextEncodingName() {
61+
func test_ExpectedContentLength_negative() {
62+
let contentLength = -1
63+
let res2 = URLResponse(url: testURL, mimeType: nil, expectedContentLength: contentLength, textEncodingName: nil)
64+
XCTAssertEqual(res2.expectedContentLength, Int64(contentLength), "should be invalid (-1) Int64 content length")
65+
}
66+
67+
func test_TextEncodingName_positive() {
5568
let encoding = "utf8"
56-
let url = URL(string: "test")!
57-
let res1 = URLResponse(url: url, mimeType: nil, expectedContentLength: 0, textEncodingName: encoding)
69+
let res1 = URLResponse(url: testURL, mimeType: nil, expectedContentLength: 0, textEncodingName: encoding)
5870
XCTAssertEqual(res1.textEncodingName, encoding, "should be the utf8 encoding")
59-
let res2 = URLResponse(url: url, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
71+
}
72+
73+
func test_TextEncodingName_negative() {
74+
let res2 = URLResponse(url: testURL, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
6075
XCTAssertNil(res2.textEncodingName)
6176
}
6277

63-
func test_suggestedFilename() {
78+
func test_suggestedFilename_1() {
6479
let url = URL(string: "a/test/name.extension")!
6580
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
6681
XCTAssertEqual(res.suggestedFilename, "name.extension")
@@ -77,6 +92,7 @@ class TestURLResponse : XCTestCase {
7792
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)
7893
XCTAssertEqual(res.suggestedFilename, "Unknown")
7994
}
95+
8096
func test_copyWithZone() {
8197
let url = URL(string: "a/test/path")!
8298
let res = URLResponse(url: url, mimeType: "txt", expectedContentLength: 0, textEncodingName: nil)

0 commit comments

Comments
 (0)