19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
static OFString *const module = @"OFHTTPCookie";
@implementation TestsAppDelegate (OFHTTPCookieTests)
- (void)HTTPCookieTests
{
void *pool = objc_autoreleasePoolPush();
OFURL *URL = [OFURL URLWithString: @"http://nil.im"];
OFURI *URI = [OFURI URIWithString: @"http://nil.im"];
OFHTTPCookie *cookie1, *cookie2;
OFArray OF_GENERIC(OFHTTPCookie *) *cookies;
cookie1 = [OFHTTPCookie cookieWithName: @"foo"
value: @"bar"
domain: @"nil.im"];
TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #1",
TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #1",
[[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary
dictionaryWithObject: @"foo=bar"
forKey: @"Set-Cookie"] forURL: URL]
forKey: @"Set-Cookie"] forURI: URI]
isEqual: [OFArray arrayWithObject: cookie1]])
cookie2 = [OFHTTPCookie cookieWithName: @"qux"
value: @"cookie"
domain: @"nil.im"];
TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #2",
TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #2",
[[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary
dictionaryWithObject: @"foo=bar,qux=cookie"
forKey: @"Set-Cookie"] forURL: URL]
forKey: @"Set-Cookie"] forURI: URI]
isEqual: [OFArray arrayWithObjects: cookie1, cookie2, nil]])
cookie1.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890];
cookie2.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890];
cookie1.path = @"/x";
cookie2.domain = @"webkeks.org";
cookie2.path = @"/objfw";
cookie2.secure = true;
cookie2.HTTPOnly = true;
[cookie2.extensions addObject: @"foo"];
[cookie2.extensions addObject: @"bar"];
TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #3",
TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #3",
[(cookies = [OFHTTPCookie cookiesWithResponseHeaderFields:
[OFDictionary dictionaryWithObject:
@"foo=bar; Expires=Fri, 13 Feb 2009 23:31:30 GMT; Path=/x,"
@"qux=cookie; Expires=Fri, 13 Feb 2009 23:31:30 GMT; "
@"Domain=webkeks.org; Path=/objfw; Secure; HTTPOnly; foo; bar"
forKey: @"Set-Cookie"] forURL: URL]) isEqual:
forKey: @"Set-Cookie"] forURI: URI]) isEqual:
[OFArray arrayWithObjects: cookie1, cookie2, nil]])
TEST(@"+[requestHeaderFieldsWithCookies:]",
[[OFHTTPCookie requestHeaderFieldsWithCookies: cookies] isEqual:
[OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie"
forKey: @"Cookie"]])
objc_autoreleasePoolPop(pool);
}
@end
|