@@ -18,12 +18,12 @@ #include #include #import "TestsAppDelegate.h" -static OFString *module = @"OFHTTPClient"; -static OFCondition *cond; +static OFString *const module = @"OFHTTPClient"; +static OFCondition *condition; static OFHTTPResponse *response = nil; @interface TestsAppDelegate (HTTPClientTests) @end @@ -38,46 +38,35 @@ - (id)main { OFTCPSocket *listener, *client; char buffer[5]; - [cond lock]; + [condition lock]; listener = [OFTCPSocket socket]; - _port = [listener bindToHost: @"127.0.0.1" - port: 0]; + _port = [listener bindToHost: @"127.0.0.1" port: 0]; [listener listen]; - [cond signal]; - [cond unlock]; + [condition signal]; + [condition unlock]; client = [listener accept]; - if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) - OF_ENSURE(0); - - if (![[client readLine] hasPrefix: @"User-Agent:"]) - OF_ENSURE(0); - - if (![[client readLine] isEqual: @"Content-Length: 5"]) - OF_ENSURE(0); - - if (![[client readLine] isEqual: - @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]) - OF_ENSURE(0); + OFEnsure([[client readLine] isEqual: @"GET /foo HTTP/1.1"]); + OFEnsure([[client readLine] hasPrefix: @"User-Agent:"]); + OFEnsure([[client readLine] isEqual: @"Content-Length: 5"]); + OFEnsure([[client readLine] isEqual: + @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]); if (![[client readLine] isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) - OF_ENSURE(0); - - if (![[client readLine] isEqual: @""]) - OF_ENSURE(0); - - [client readIntoBuffer: buffer - exactLength: 5]; - if (memcmp(buffer, "Hello", 5) != 0) - OF_ENSURE(0); + OFEnsure(0); + + OFEnsure([[client readLine] isEqual: @""]); + + [client readIntoBuffer: buffer exactLength: 5]; + OFEnsure(memcmp(buffer, "Hello", 5) == 0); [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @@ -99,11 +88,11 @@ - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ exception: (id)exception { - OF_ENSURE(exception == nil); + OFEnsure(exception == nil); response = [response_ retain]; [[OFRunLoop mainRunLoop] stop]; } @@ -115,19 +104,19 @@ OFURL *URL; OFHTTPClient *client; OFHTTPRequest *request; OFData *data; - cond = [OFCondition condition]; - [cond lock]; + condition = [OFCondition condition]; + [condition lock]; server = [[[HTTPClientTestsServer alloc] init] autorelease]; server.supportsSockets = true; [server start]; - [cond wait]; - [cond unlock]; + [condition wait]; + [condition unlock]; URL = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]];