Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -47,11 +47,12 @@ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ - OFTCPSocketTests.m + OFTCPSocketTests.m \ + OFUDPSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m include ../buildsys.mk Index: new_tests/OFSocketTests.m ================================================================== --- new_tests/OFSocketTests.m +++ new_tests/OFSocketTests.m @@ -226,6 +226,27 @@ address.sockaddr.in6.sin6_scope_id = 123; OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:0:0%123"); } + +- (void)testAddressEqual +{ + OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); + OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); + OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); + + OTAssertTrue(OFSocketAddressEqual(&addr1, &addr2)); + OTAssertFalse(OFSocketAddressEqual(&addr1, &addr3)); +} + +- (void)testAddressHash +{ + OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); + OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); + OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); + + OTAssertEqual(OFSocketAddressHash(&addr1), OFSocketAddressHash(&addr2)); + OTAssertNotEqual(OFSocketAddressHash(&addr1), + OFSocketAddressHash(&addr3)); +} @end ADDED new_tests/OFUDPSocketTests.m Index: new_tests/OFUDPSocketTests.m ================================================================== --- new_tests/OFUDPSocketTests.m +++ new_tests/OFUDPSocketTests.m @@ -0,0 +1,46 @@ +/* + * 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 OFUDPSocketTests: OTTestCase +@end + +@implementation OFUDPSocketTests +- (void)testUDPSocket +{ + OFUDPSocket *sock = [OFUDPSocket socket]; + OFSocketAddress addr1, addr2; + char buffer[6]; + + sock = [OFUDPSocket socket]; + + addr1 = [sock bindToHost: @"127.0.0.1" port: 0]; + OTAssertEqualObjects(OFSocketAddressString(&addr1), @"127.0.0.1"); + + [sock sendBuffer: "Hello" length: 6 receiver: &addr1]; + + [sock receiveIntoBuffer: buffer length: 6 sender: &addr2]; + OTAssertEqual(memcmp(buffer, "Hello", 6), 0); + OTAssertEqualObjects(OFSocketAddressString(&addr2), @"127.0.0.1"); + OTAssertEqual(OFSocketAddressIPPort(&addr2), + OFSocketAddressIPPort(&addr1)); +} +@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 \ - OFUDPSocketTests.m \ ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ DELETED tests/OFUDPSocketTests.m Index: tests/OFUDPSocketTests.m ================================================================== --- tests/OFUDPSocketTests.m +++ tests/OFUDPSocketTests.m @@ -1,59 +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 = @"OFUDPSocket"; - -@implementation TestsAppDelegate (OFUDPSocketTests) -- (void)UDPSocketTests -{ - void *pool = objc_autoreleasePoolPush(); - OFUDPSocket *sock; - OFSocketAddress addr1, addr2, addr3; - char buf[6]; - - TEST(@"+[socket]", (sock = [OFUDPSocket socket])) - - TEST(@"-[bindToHost:port:]", - R(addr1 = [sock bindToHost: @"127.0.0.1" port: 0])) - - TEST(@"-[sendBuffer:length:receiver:]", - R([sock sendBuffer: "Hello" length: 6 receiver: &addr1])) - - TEST(@"-[receiveIntoBuffer:length:sender:]", - [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 && - !memcmp(buf, "Hello", 6) && - [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] && - OFSocketAddressIPPort(&addr2) == OFSocketAddressIPPort(&addr1)) - - addr3 = OFSocketAddressParseIP(@"127.0.0.1", - OFSocketAddressIPPort(&addr1) + 1); - - TEST(@"OFSocketAddressEqual()", - OFSocketAddressEqual(&addr1, &addr2) && - !OFSocketAddressEqual(&addr1, &addr3)) - - TEST(@"OFSocketAddressHash()", - OFSocketAddressHash(&addr1) == OFSocketAddressHash(&addr2) && - OFSocketAddressHash(&addr1) != OFSocketAddressHash(&addr3)) - - 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 (OFUDPSocketTests) -- (void)UDPSocketTests; -@end - @interface TestsAppDelegate (OFUNIXDatagramSocketTests) - (void)UNIXDatagramSocketTests; @end @interface TestsAppDelegate (OFUNIXStreamSocketTests) 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 UDPSocketTests]; # ifdef OF_HAVE_UNIX_SOCKETS [self UNIXDatagramSocketTests]; [self UNIXStreamSocketTests]; # endif # ifdef OF_HAVE_IPX