@@ -18,25 +18,31 @@ #include #include #import "OFHTTPClient.h" +#import "OFCondition.h" +#import "OFData.h" +#import "OFDate.h" +#import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" +#import "OFRunLoop.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFThread.h" -#import "OFCondition.h" #import "OFURL.h" -#import "OFDictionary.h" -#import "OFData.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" static OFString *module = @"OFHTTPClient"; static OFCondition *cond; +static OFHTTPResponse *response = nil; + +@interface TestsAppDelegate (HTTPClientTests) +@end @interface HTTPClientTestsServer: OFThread { @public uint16_t _port; @@ -83,18 +89,26 @@ return nil; } @end @implementation TestsAppDelegate (OFHTTPClientTests) +- (void)client: (OFHTTPClient *)client + didPerformRequest: (OFHTTPRequest *)request + response: (OFHTTPResponse *)response_ +{ + response = [response_ retain]; + + [[OFRunLoop mainRunLoop] stop]; +} + - (void)HTTPClientTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; HTTPClientTestsServer *server; OFURL *URL; OFHTTPClient *client; OFHTTPRequest *request; - OFHTTPResponse *response = nil; OFData *data; cond = [OFCondition condition]; [cond lock]; @@ -107,13 +121,19 @@ URL = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[performRequest:]", - (client = [OFHTTPClient client]) && + (client = [OFHTTPClient client]) && R([client setDelegate: self]) && R(request = [OFHTTPRequest requestWithURL: URL]) && - R(response = [client performRequest: request])) + R([client performRequest: request])) + + [[OFRunLoop mainRunLoop] runUntilDate: + [OFDate dateWithTimeIntervalSinceNow: 2]]; + [response autorelease]; + + TEST(@"Asynchronous handling of requests", response != nil) TEST(@"Normalization of server header keys", [[response headers] objectForKey: @"Content-Length"] != nil) TEST(@"Correct parsing of data",