@@ -13,16 +13,21 @@ class TestURLResponse : XCTestCase {
13
13
( " test_URL " , test_URL) ,
14
14
( " test_MIMEType_1 " , test_MIMEType_1) ,
15
15
( " 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) ,
19
22
( " test_suggestedFilename_2 " , test_suggestedFilename_2) ,
20
23
( " test_suggestedFilename_3 " , test_suggestedFilename_3) ,
21
24
( " test_copywithzone " , test_copyWithZone) ,
22
25
( " test_NSCoding " , test_NSCoding) ,
23
26
]
24
27
}
25
28
29
+ let testURL = URL ( string: " test " ) !
30
+
26
31
func test_URL( ) {
27
32
let url = URL ( string: " a/test/path " ) !
28
33
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
@@ -31,36 +36,46 @@ class TestURLResponse : XCTestCase {
31
36
32
37
func test_MIMEType_1( ) {
33
38
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 )
35
40
XCTAssertEqual ( res. mimeType, mimetype, " should be the passed in mimetype " )
36
41
}
37
42
38
43
func test_MIMEType_2( ) {
39
44
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 )
41
46
XCTAssertEqual ( res. mimeType, mimetype, " should be the other mimetype " )
42
47
}
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 " )
52
59
}
53
60
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( ) {
55
68
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)
58
70
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 )
60
75
XCTAssertNil ( res2. textEncodingName)
61
76
}
62
77
63
- func test_suggestedFilename ( ) {
78
+ func test_suggestedFilename_1 ( ) {
64
79
let url = URL ( string: " a/test/name.extension " ) !
65
80
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
66
81
XCTAssertEqual ( res. suggestedFilename, " name.extension " )
@@ -77,6 +92,7 @@ class TestURLResponse : XCTestCase {
77
92
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
78
93
XCTAssertEqual ( res. suggestedFilename, " Unknown " )
79
94
}
95
+
80
96
func test_copyWithZone( ) {
81
97
let url = URL ( string: " a/test/path " ) !
82
98
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
0 commit comments