Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -50,11 +50,13 @@ SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ - ${USE_SRCS_UNIX_SOCKETS} + ${USE_SRCS_UNIX_SOCKETS} \ + ${USE_SRCS_APPLETALK} +SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m ADDED new_tests/OFDDPSocketTests.m Index: new_tests/OFDDPSocketTests.m ================================================================== --- /dev/null +++ new_tests/OFDDPSocketTests.m @@ -0,0 +1,63 @@ +/* + * 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 OFDDPSocketTests: OTTestCase +@end + +@implementation OFDDPSocketTests +- (void)testDDPSocket +{ + OFDDPSocket *sock; + OFSocketAddress address1, address2; + char buffer[5]; + + sock = [OFDDPSocket socket]; + + @try { + address1 = [sock bindToNetwork: 0 + node: 0 + port: 0 + protocolType: 11]; + } @catch (OFBindSocketFailedException *e) { + switch (e.errNo) { + case EAFNOSUPPORT: + case EPROTONOSUPPORT: + OTSkip(@"AppleTalk unsupported"); + case EADDRNOTAVAIL: + OTSkip(@"AppleTalk not configured"); + default: + @throw e; + } + } + + [sock sendBuffer: "Hello" length: 5 receiver: &address1]; + + OTAssertEqual([sock receiveIntoBuffer: buffer + length: 5 + sender: &address2], 5); + OTAssertEqual(memcmp(buffer, "Hello", 5), 0); + OTAssertTrue(OFSocketAddressEqual(&address1, &address2)); + OTAssertEqual(OFSocketAddressHash(&address1), + OFSocketAddressHash(&address2)); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -31,13 +31,11 @@ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_WINDOWS} SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ - OFKernelEventObserverTests.m \ - ${USE_SRCS_APPLETALK} -SRCS_APPLETALK = OFDDPSocketTests.m + OFKernelEventObserverTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test DELETED tests/OFDDPSocketTests.m Index: tests/OFDDPSocketTests.m ================================================================== --- tests/OFDDPSocketTests.m +++ /dev/null @@ -1,76 +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 = @"OFDDPSocket"; - -@implementation TestsAppDelegate (OFDDPSocketTests) -- (void)DDPSocketTests -{ - void *pool = objc_autoreleasePoolPush(); - OFDDPSocket *sock; - OFSocketAddress address1, address2; - char buffer[5]; - - TEST(@"+[socket]", (sock = [OFDDPSocket socket])) - - @try { - TEST(@"-[bindToNetwork:node:port:]", - R(address1 = [sock bindToNetwork: 0 - node: 0 - port: 0 - protocolType: 11])) - } @catch (OFBindSocketFailedException *e) { - switch (e.errNo) { - case EAFNOSUPPORT: - case EPROTONOSUPPORT: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFDDPSocket] -[bindToNetwork:node:port:" - @"protocolType:] AppleTalk unsupported, skipping " - @"tests"]; - break; - case EADDRNOTAVAIL: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFDDPSocket] -[bindToNetwork:node:port:" - @"protocolType:] AppleTalk not configured, " - @"skipping tests"]; - break; - default: - @throw e; - } - - objc_autoreleasePoolPop(pool); - return; - } - - TEST(@"-[sendBuffer:length:receiver:]", - R([sock sendBuffer: "Hello" length: 5 receiver: &address1])) - - TEST(@"-[receiveIntoBuffer:length:sender:]", - [sock receiveIntoBuffer: buffer length: 5 sender: &address2] == 5 && - memcmp(buffer, "Hello", 5) == 0 && - OFSocketAddressEqual(&address1, &address2) && - OFSocketAddressHash(&address1) == OFSocketAddressHash(&address2)) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -57,14 +57,10 @@ - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end -@interface TestsAppDelegate (OFDDPSocketTests) -- (void)DDPSocketTests; -@end - @interface TestsAppDelegate (OFDataTests) - (void)dataTests; @end @interface TestsAppDelegate (OFDictionaryTests) 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_APPLETALK - [self DDPSocketTests]; -# endif [self kernelEventObserverTests]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif