Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -54,11 +54,12 @@ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m -SRCS_SOCKETS = OFDNSResolverTests.m \ +SRCS_SOCKETS = OFHTTPCookieTests.m \ + OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} \ ADDED new_tests/OFHTTPCookieTests.m Index: new_tests/OFHTTPCookieTests.m ================================================================== --- new_tests/OFHTTPCookieTests.m +++ new_tests/OFHTTPCookieTests.m @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFHTTPCookieTests: OTTestCase +@end + +@implementation OFHTTPCookieTests +- (void)testCookiesWithResponseHeaderFieldsForIRI +{ + OFIRI *IRI = [OFIRI IRIWithString: @"http://nil.im"]; + OFHTTPCookie *cookie1 = [OFHTTPCookie cookieWithName: @"foo" + value: @"bar" + domain: @"nil.im"]; + OFHTTPCookie *cookie2 = [OFHTTPCookie cookieWithName: @"qux" + value: @"cookie" + domain: @"nil.im"]; + OFDictionary *headers; + + headers = [OFDictionary dictionaryWithObject: @"foo=bar" + forKey: @"Set-Cookie"]; + OTAssertEqualObjects( + [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], + [OFArray arrayWithObject: cookie1]); + + headers = [OFDictionary dictionaryWithObject: @"foo=bar,qux=cookie" + forKey: @"Set-Cookie"]; + OTAssertEqualObjects( + [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], + ([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"]; + + headers = [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"]; + OTAssertEqualObjects( + [OFHTTPCookie cookiesWithResponseHeaderFields: headers forIRI: IRI], + ([OFArray arrayWithObjects: cookie1, cookie2, nil])); +} + +- (void)testRequestHeaderFieldsWithCookies +{ + OFHTTPCookie *cookie1 = [OFHTTPCookie cookieWithName: @"foo" + value: @"bar" + domain: @"nil.im"]; + OFHTTPCookie *cookie2 = [OFHTTPCookie cookieWithName: @"qux" + value: @"cookie" + domain: @"nil.im"]; + + OTAssertEqualObjects([OFHTTPCookie requestHeaderFieldsWithCookies: + ([OFArray arrayWithObjects: cookie1, cookie2, nil])], + [OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie" + forKey: @"Cookie"]); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -23,11 +23,10 @@ OFXMLParserTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ - OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test DELETED tests/OFHTTPCookieTests.m Index: tests/OFHTTPCookieTests.m ================================================================== --- tests/OFHTTPCookieTests.m +++ tests/OFHTTPCookieTests.m @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFHTTPCookie"; - -@implementation TestsAppDelegate (OFHTTPCookieTests) -- (void)HTTPCookieTests -{ - void *pool = objc_autoreleasePoolPush(); - OFIRI *IRI = [OFIRI IRIWithString: @"http://nil.im"]; - OFHTTPCookie *cookie1, *cookie2; - OFArray OF_GENERIC(OFHTTPCookie *) *cookies; - - cookie1 = [OFHTTPCookie cookieWithName: @"foo" - value: @"bar" - domain: @"nil.im"]; - TEST(@"+[cookiesWithResponseHeaderFields:forIRI:] #1", - [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary - dictionaryWithObject: @"foo=bar" - forKey: @"Set-Cookie"] forIRI: IRI] - isEqual: [OFArray arrayWithObject: cookie1]]) - - cookie2 = [OFHTTPCookie cookieWithName: @"qux" - value: @"cookie" - domain: @"nil.im"]; - TEST(@"+[cookiesWithResponseHeaderFields:forIRI:] #2", - [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary - dictionaryWithObject: @"foo=bar,qux=cookie" - forKey: @"Set-Cookie"] forIRI: IRI] - 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:forIRI:] #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"] forIRI: IRI]) isEqual: - [OFArray arrayWithObjects: cookie1, cookie2, nil]]) - - TEST(@"+[requestHeaderFieldsWithCookies:]", - [[OFHTTPCookie requestHeaderFieldsWithCookies: cookies] isEqual: - [OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie" - forKey: @"Cookie"]]) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -69,14 +69,10 @@ @interface TestsAppDelegate (OFHTTPClientTests) - (void)HTTPClientTests; @end -@interface TestsAppDelegate (OFHTTPCookieTests) -- (void)HTTPCookieTests; -@end - @interface TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests; @end @interface TestsAppDelegate (OFKernelEventObserverTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -381,11 +381,10 @@ #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif #ifdef OF_HAVE_SOCKETS - [self HTTPCookieTests]; [self HTTPCookieManagerTests]; #endif [self XMLParserTests]; [self XMLNodeTests];