Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -49,11 +49,13 @@ SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ + ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} +SRCS_IPX = OFIPXSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m ADDED new_tests/OFIPXSocketTests.m Index: new_tests/OFIPXSocketTests.m ================================================================== --- new_tests/OFIPXSocketTests.m +++ new_tests/OFIPXSocketTests.m @@ -0,0 +1,91 @@ +/* + * 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 OFIPXSocketTests: OTTestCase +@end + +@implementation OFIPXSocketTests +- (void)testIPXSocket +{ + OFIPXSocket *sock = [OFIPXSocket socket]; + const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; + OFSocketAddress address1, address2; + OFDictionary *networkInterfaces; + char buffer[5]; + unsigned char node1[IPX_NODE_LEN], node2[IPX_NODE_LEN]; + unsigned char node[IPX_NODE_LEN]; + + @try { + address1 = [sock bindToNetwork: 0 + node: zeroNode + port: 0 + packetType: 0]; + } @catch (OFBindSocketFailedException *e) { + switch (e.errNo) { + case EAFNOSUPPORT: + OTSkip(@"IPX unsupported"); + case EADDRNOTAVAIL: + OTSkip(@"IPX not configured"); + default: + @throw e; + } + } + + /* + * Find any network interface with IPX and send to it. Any should be + * fine since we bound to 0.0. + */ + networkInterfaces = [OFSystemInfo networkInterfaces]; + for (OFString *name in networkInterfaces) { + OFNetworkInterface interface = [networkInterfaces + objectForKey: name]; + OFData *addresses = [interface + objectForKey: OFNetworkInterfaceIPXAddresses]; + + if (addresses.count == 0) + continue; + + OFSocketAddressSetIPXNetwork(&address1, + OFSocketAddressIPXNetwork([addresses itemAtIndex: 0])); + OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); + OFSocketAddressSetIPXNode(&address1, node); + } + + OFSocketAddressGetIPXNode(&address1, node); + if (OFSocketAddressIPXNetwork(&address1) == 0 && + memcmp(node, zeroNode, 6) == 0) + OTSkip(@"Could not determine own IPX address"); + + [sock sendBuffer: "Hello" length: 5 receiver: &address1]; + + OTAssertEqual([sock receiveIntoBuffer: buffer + length: 5 + sender: &address2], 5); + OTAssertEqual(memcmp(buffer, "Hello", 5), 0); + OFSocketAddressGetIPXNode(&address1, node1); + OFSocketAddressGetIPXNode(&address2, node2); + OTAssertEqual(memcmp(node1, node2, IPX_NODE_LEN), 0); + OTAssertEqual(OFSocketAddressIPXPort(&address1), + OFSocketAddressIPXPort(&address2)); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -35,12 +35,11 @@ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} SRCS_APPLETALK = OFDDPSocketTests.m -SRCS_IPX = OFIPXSocketTests.m \ - OFSPXSocketTests.m \ +SRCS_IPX = OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test DELETED tests/OFIPXSocketTests.m Index: tests/OFIPXSocketTests.m ================================================================== --- tests/OFIPXSocketTests.m +++ tests/OFIPXSocketTests.m @@ -1,112 +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 = @"OFIPXSocket"; - -@implementation TestsAppDelegate (OFIPXSocketTests) -- (void)IPXSocketTests -{ - const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; - void *pool = objc_autoreleasePoolPush(); - OFIPXSocket *sock; - OFSocketAddress address1, address2; - OFDictionary *networkInterfaces; - char buffer[5]; - unsigned char node1[IPX_NODE_LEN], node2[IPX_NODE_LEN]; - unsigned char node[IPX_NODE_LEN]; - - TEST(@"+[socket]", (sock = [OFIPXSocket socket])) - - @try { - TEST(@"-[bindToNetwork:node:port:packetType:]", - R(address1 = [sock bindToNetwork: 0 - node: zeroNode - port: 0 - packetType: 0])) - } @catch (OFBindSocketFailedException *e) { - switch (e.errNo) { - case EAFNOSUPPORT: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFIPXSocket] -[bindToNetwork:node:port:" - @"packetType:]: IPX unsupported, skipping tests"]; - break; - case EADDRNOTAVAIL: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFIPXSocket] -[bindToNetwork:node:port:" - @"packetType:]: IPX not configured, skipping " - @"tests"]; - break; - default: - @throw e; - } - - objc_autoreleasePoolPop(pool); - return; - } - - /* - * Find any network interface with IPX and send to it. Any should be - * fine since we bound to 0.0. - */ - networkInterfaces = [OFSystemInfo networkInterfaces]; - for (OFString *name in networkInterfaces) { - OFNetworkInterface interface = [networkInterfaces - objectForKey: name]; - OFData *addresses = [interface - objectForKey: OFNetworkInterfaceIPXAddresses]; - - if (addresses.count == 0) - continue; - - OFSocketAddressSetIPXNetwork(&address1, - OFSocketAddressIPXNetwork([addresses itemAtIndex: 0])); - OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); - OFSocketAddressSetIPXNode(&address1, node); - } - - OFSocketAddressGetIPXNode(&address1, node); - if (OFSocketAddressIPXNetwork(&address1) == 0 && - memcmp(node, zeroNode, 6) == 0) { - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"[OFIPXSocket] -[sendBuffer:length:receiver:]: " - @"Could not determine own address, skipping tests"]; - 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 && - R(OFSocketAddressGetIPXNode(&address1, node1)) && - R(OFSocketAddressGetIPXNode(&address2, node2)) && - memcmp(node1, node2, IPX_NODE_LEN) == 0 && - OFSocketAddressIPXPort(&address1) == - OFSocketAddressIPXPort(&address2)) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -81,14 +81,10 @@ @interface TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests; @end -@interface TestsAppDelegate (OFIPXSocketTests) -- (void)IPXSocketTests; -@end - @interface TestsAppDelegate (OFKernelEventObserverTests) - (void)kernelEventObserverTests; @end @interface TestsAppDelegate (OFListTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -382,11 +382,10 @@ [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_IPX - [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif # ifdef OF_HAVE_APPLETALK [self DDPSocketTests];