Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -50,11 +50,12 @@ SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_UNIX_SOCKETS} -SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m +SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ + OFUNIXStreamSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m include ../buildsys.mk Index: new_tests/OFUNIXDatagramSocketTests.m ================================================================== --- new_tests/OFUNIXDatagramSocketTests.m +++ new_tests/OFUNIXDatagramSocketTests.m @@ -23,11 +23,11 @@ @interface OFUNIXDatagramSocketTests: OTTestCase @end @implementation OFUNIXDatagramSocketTests -- (void)testUNIXDatagramSockets +- (void)testUNIXDatagramSocket { OFUNIXDatagramSocket *sock = [OFUNIXDatagramSocket socket]; OFString *path; OFSocketAddress address1, address2; char buffer[5]; @@ -53,11 +53,10 @@ } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: OTSkip(@"UNIX datagram sockets unsupported"); - return; default: @throw e; } } ADDED new_tests/OFUNIXStreamSocketTests.m Index: new_tests/OFUNIXStreamSocketTests.m ================================================================== --- new_tests/OFUNIXStreamSocketTests.m +++ new_tests/OFUNIXStreamSocketTests.m @@ -0,0 +1,84 @@ +/* + * 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 +#include + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFUNIXStreamSocketTests: OTTestCase +@end + +@implementation OFUNIXStreamSocketTests +- (void)testUNIXStreamSocket +{ + OFString *path; + OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; + char buffer[5]; + +#if defined(OF_HAVE_FILES) && !defined(OF_IOS) + path = [[OFSystemInfo temporaryDirectoryIRI] + IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] + .fileSystemRepresentation; +#else + /* + * We can have sockets, including UNIX sockets, while file support is + * disabled. + * + * We also use this code path for iOS, as the temporaryDirectory:RI is + * too long on the iOS simulator. + */ + path = [OFString stringWithFormat: @"/tmp/%@", + [[OFUUID UUID] UUIDString]]; +#endif + + sockClient = [OFUNIXStreamSocket socket]; + sockServer = [OFUNIXStreamSocket socket]; + + @try { + [sockServer bindToPath: path]; + } @catch (OFBindSocketFailedException *e) { + switch (e.errNo) { + case EAFNOSUPPORT: + case EPERM: + OTSkip(@"UNIX stream sockets unsupported"); + default: + @throw e; + } + } + + @try { + [sockServer listen]; + + [sockClient connectToPath: path]; + + sockAccepted = [sockServer accept]; + [sockAccepted writeBuffer: "Hello" length: 5]; + + OTAssertEqual([sockClient readIntoBuffer: buffer length: 5], 5); + OTAssertEqual(memcmp(buffer, "Hello", 5), 0); + + OTAssertEqual(OFSocketAddressUNIXPath( + sockAccepted.remoteAddress).length, 0); + } @finally { +#ifdef OF_HAVE_FILES + [[OFFileManager defaultManager] removeItemAtPath: path]; +#endif + } +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -33,17 +33,15 @@ SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ ${USE_SRCS_APPLETALK} \ - ${USE_SRCS_IPX} \ - ${USE_SRCS_UNIX_SOCKETS} + ${USE_SRCS_IPX} SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m -SRCS_UNIX_SOCKETS = OFUNIXStreamSocketTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test DELETED tests/OFUNIXStreamSocketTests.m Index: tests/OFUNIXStreamSocketTests.m ================================================================== --- tests/OFUNIXStreamSocketTests.m +++ tests/OFUNIXStreamSocketTests.m @@ -1,94 +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 = @"OFUNIXStreamSocket"; - -@implementation TestsAppDelegate (OFUNIXStreamSocketTests) -- (void)UNIXStreamSocketTests -{ - void *pool = objc_autoreleasePoolPush(); - OFString *path; - OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; - char buffer[5]; - -#if defined(OF_HAVE_FILES) && !defined(OF_IOS) - path = [[OFSystemInfo temporaryDirectoryIRI] - IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] - .fileSystemRepresentation; -#else - /* - * We can have sockets, including UNIX sockets, while file support is - * disabled. - * - * We also use this code path for iOS, as the temporaryDirectory:RI is - * too long on the iOS simulator. - */ - path = [OFString stringWithFormat: @"/tmp/%@", - [[OFUUID UUID] UUIDString]]; -#endif - - TEST(@"+[socket]", (sockClient = [OFUNIXStreamSocket socket]) && - (sockServer = [OFUNIXStreamSocket socket])) - - @try { - TEST(@"-[bindToPath:]", R([sockServer bindToPath: path])) - } @catch (OFBindSocketFailedException *e) { - switch (e.errNo) { - case EAFNOSUPPORT: - case EPERM: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFUNIXStreamSocket] -[bindToPath:]: " - @"UNIX stream sockets unsupported, skipping tests"]; - - objc_autoreleasePoolPop(pool); - return; - default: - @throw e; - } - } - - @try { - TEST(@"-[listen]", R([sockServer listen])) - - TEST(@"-[connectToPath:]", - R([sockClient connectToPath: path])) - - TEST(@"-[accept]", (sockAccepted = [sockServer accept])) - - TEST(@"-[writeBuffer:length:]", - R([sockAccepted writeBuffer: "Hello" length: 5])) - - TEST(@"-[readIntoBuffer:length:]", - [sockClient readIntoBuffer: buffer length: 5] == 5 && - memcmp(buffer, "Hello", 5) == 0) - - TEST(@"-[remoteAddress]", OFSocketAddressUNIXPath( - sockAccepted.remoteAddress).length == 0) - } @finally { -#ifdef OF_HAVE_FILES - [[OFFileManager defaultManager] removeItemAtPath: path]; -#endif - } - - 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 (OFUNIXStreamSocketTests) -- (void)UNIXStreamSocketTests; -@end - @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end @interface TestsAppDelegate (OFWindowsRegistryKeyTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -381,13 +381,10 @@ [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; #ifdef OF_HAVE_SOCKETS -# ifdef OF_HAVE_UNIX_SOCKETS - [self UNIXStreamSocketTests]; -# endif # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif