@@ -14,19 +14,21 @@ */ #include "config.h" #include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFUNIXStreamSocket"; - -@implementation TestsAppDelegate (OFUNIXStreamSocketTests) -- (void)UNIXStreamSocketTests -{ - void *pool = objc_autoreleasePoolPush(); +#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) @@ -43,52 +45,40 @@ */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif - TEST(@"+[socket]", (sockClient = [OFUNIXStreamSocket socket]) && - (sockServer = [OFUNIXStreamSocket socket])) + sockClient = [OFUNIXStreamSocket socket]; + sockServer = [OFUNIXStreamSocket socket]; @try { - TEST(@"-[bindToPath:]", R([sockServer bindToPath: path])) + [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; + OTSkip(@"UNIX stream sockets unsupported"); 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) + [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 } - - objc_autoreleasePoolPop(pool); } @end