Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -46,11 +46,12 @@ ${USE_SRCS_THREADS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ - OFSocketTests.m + OFSocketTests.m \ + OFTCPSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m include ../buildsys.mk ADDED new_tests/OFTCPSocketTests.m Index: new_tests/OFTCPSocketTests.m ================================================================== --- new_tests/OFTCPSocketTests.m +++ new_tests/OFTCPSocketTests.m @@ -0,0 +1,51 @@ +/* + * 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" + +#include + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFTCPSocketTests: OTTestCase +@end + +@implementation OFTCPSocketTests +- (void)testTCPSocket +{ + OFTCPSocket *server, *client, *accepted; + OFSocketAddress address; + char buffer[6]; + + server = [OFTCPSocket socket]; + client = [OFTCPSocket socket]; + + address = [server bindToHost: @"127.0.0.1" port: 0]; + [server listen]; + + [client connectToHost: @"127.0.0.1" + port: OFSocketAddressIPPort(&address)]; + + accepted = [server accept]; + OTAssertEqualObjects(OFSocketAddressString(accepted.remoteAddress), + @"127.0.0.1"); + + [client writeString: @"Hello!"]; + + [accepted readIntoBuffer: buffer exactLength: 6]; + OTAssertEqual(memcmp(buffer, "Hello!", 6), 0); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -32,11 +32,10 @@ ${USE_SRCS_WINDOWS} SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ - OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocketTests.m DELETED tests/OFTCPSocketTests.m Index: tests/OFTCPSocketTests.m ================================================================== --- tests/OFTCPSocketTests.m +++ tests/OFTCPSocketTests.m @@ -1,58 +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" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFTCPSocket"; - -@implementation TestsAppDelegate (OFTCPSocketTests) -- (void)TCPSocketTests -{ - void *pool = objc_autoreleasePoolPush(); - OFTCPSocket *server, *client = nil, *accepted; - OFSocketAddress address; - char buffer[6]; - - TEST(@"+[socket]", (server = [OFTCPSocket socket]) && - (client = [OFTCPSocket socket])) - - TEST(@"-[bindToHost:port:]", - R(address = [server bindToHost: @"127.0.0.1" port: 0])) - - TEST(@"-[listen]", R([server listen])) - - TEST(@"-[connectToHost:port:]", - R([client connectToHost: @"127.0.0.1" - port: OFSocketAddressIPPort(&address)])) - - TEST(@"-[accept]", (accepted = [server accept])) - - TEST(@"-[remoteAddress]", - [OFSocketAddressString(accepted.remoteAddress) - isEqual: @"127.0.0.1"]) - - TEST(@"-[writeString:]", R([client writeString: @"Hello!"])) - - TEST(@"-[readIntoBuffer:length:]", - [accepted readIntoBuffer: buffer length: 6] && - !memcmp(buffer, "Hello!", 6)) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -125,14 +125,10 @@ @interface TestsAppDelegate (OFStringTests) - (void)stringTests; @end -@interface TestsAppDelegate (OFTCPSocketTests) -- (void)TCPSocketTests; -@end - @interface TestsAppDelegate (OFUDPSocketTests) - (void)UDPSocketTests; @end @interface TestsAppDelegate (OFUNIXDatagramSocketTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -381,11 +381,10 @@ [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; #ifdef OF_HAVE_SOCKETS - [self TCPSocketTests]; [self UDPSocketTests]; # ifdef OF_HAVE_UNIX_SOCKETS [self UNIXDatagramSocketTests]; [self UNIXStreamSocketTests]; # endif