@@ -28,11 +28,11 @@ # import "OFSelectKernelEventObserver.h" #endif #import "TestsAppDelegate.h" -#define EXPECTED_EVENTS 3 +static const size_t numExpectedEvents = 3; static OFString *module; @interface ObserverTest: OFObject { @@ -56,20 +56,16 @@ uint16_t port; _testsAppDelegate = testsAppDelegate; _server = [[OFTCPSocket alloc] init]; - port = [_server bindToHost: @"127.0.0.1" - port: 0]; + port = [_server bindToHost: @"127.0.0.1" port: 0]; [_server listen]; _client = [[OFTCPSocket alloc] init]; - [_client connectToHost: @"127.0.0.1" - port: port]; - - [_client writeBuffer: "0" - length: 1]; + [_client connectToHost: @"127.0.0.1" port: port]; + [_client writeBuffer: "0" length: 1]; } @catch (id e) { [self release]; @throw e; } @@ -92,11 +88,11 @@ [_testsAppDelegate outputTesting: @"-[observe] with listening socket" inModule: module]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; - while (_events < EXPECTED_EVENTS) { + while (_events < numExpectedEvents) { if (deadline.timeIntervalSinceNow < 0) { deadlineExceeded = true; break; } @@ -112,11 +108,11 @@ outputFailure: @"-[observe] not exceeding deadline" inModule: module]; _fails++; } - if (_events == EXPECTED_EVENTS) + if (_events == numExpectedEvents) [_testsAppDelegate outputSuccess: @"-[observe] handling all events" inModule: module]; else { [_testsAppDelegate @@ -126,11 +122,11 @@ } } - (void)objectIsReadyForReading: (id)object { - char buf; + char buffer; switch (_events++) { case 0: if (object == _server) [_testsAppDelegate @@ -151,12 +147,12 @@ inModule: module]; break; case 1: if (object == _accepted && - [object readIntoBuffer: &buf - length: 1] == 1 && buf == '0') + [object readIntoBuffer: &buffer length: 1] == 1 && + buffer == '0') [_testsAppDelegate outputSuccess: @"-[observe] with data ready to read" inModule: module]; else { [_testsAppDelegate @@ -172,12 +168,11 @@ inModule: module]; break; case 2: if (object == _accepted && - [object readIntoBuffer: &buf - length: 1] == 0) + [object readIntoBuffer: &buffer length: 1] == 0) [_testsAppDelegate outputSuccess: @"-[observe] with closed connection" inModule: module]; else { [_testsAppDelegate @@ -186,11 +181,11 @@ _fails++; } break; default: - OF_ENSURE(0); + OFEnsure(0); } } @end @implementation TestsAppDelegate (OFKernelEventObserverTests)