@@ -14,21 +14,23 @@ */ #include "config.h" #include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFUNIXDatagramSocket"; - -@implementation TestsAppDelegate (OFUNIXDatagramSocketTests) -- (void)UNIXDatagramSocketTests -{ - void *pool = objc_autoreleasePoolPush(); - OFString *path; - OFUNIXDatagramSocket *sock; +#include + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFUNIXDatagramSocketTests: OTTestCase +@end + +@implementation OFUNIXDatagramSocketTests +- (void)testUNIXDatagramSockets +{ + OFUNIXDatagramSocket *sock = [OFUNIXDatagramSocket socket]; + OFString *path; OFSocketAddress address1, address2; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryIRI] @@ -44,47 +46,35 @@ */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif - TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket])) - @try { - TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path])) + address1 = [sock bindToPath: path]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut writeLine: - @"\r[OFUNIXDatagramSocket] -[bindToPath:]: " - @"UNIX datagram sockets unsupported, skipping " - @"tests"]; - - objc_autoreleasePoolPop(pool); + OTSkip(@"UNIX datagram sockets unsupported"); return; default: @throw e; } } @try { - 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)) + [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)); } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } - - objc_autoreleasePoolPop(pool); } @end