Differences From Artifact [9c917ec780]:
- File tests/OFHTTPClientTests.m — part of check-in [c8f7b90082] at 2017-07-22 20:50:27 on branch trunk — Split OFDataArray into OFData and OFMutableData (user: js, size: 2900) [annotate] [blame] [check-ins using]
To Artifact [a00a732f44]:
- File
tests/OFHTTPClientTests.m
— part of check-in
[56a18442e2]
at
2017-09-24 00:59:12
on branch trunk
— Make OFHTTPClient asynchronous
This does not make OFHTTPClientResponse completely asynchronous yet.
Since -[initWithURL:] does not work well with an asynchronous API, it no
longer supports HTTP URLs. However, a new, asynchronous API will be
added as a replacement later on. (user: js, size: 3423) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 | #include "config.h" #include <inttypes.h> #include <string.h> #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFThread.h" | > > > > > < < < > > > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include "config.h" #include <inttypes.h> #include <string.h> #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 "OFURL.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" static OFString *module = @"OFHTTPClient"; static OFCondition *cond; static OFHTTPResponse *response = nil; @interface TestsAppDelegate (HTTPClientTests) <OFHTTPClientDelegate> @end @interface HTTPClientTestsServer: OFThread { @public uint16_t _port; } @end |
︙ | ︙ | |||
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | [client close]; return nil; } @end @implementation TestsAppDelegate (OFHTTPClientTests) - (void)HTTPClientTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; HTTPClientTestsServer *server; OFURL *URL; OFHTTPClient *client; OFHTTPRequest *request; | > > > > > > > > > < | | > > > > > > | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | [client close]; 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; OFData *data; cond = [OFCondition condition]; [cond lock]; server = [[[HTTPClientTestsServer alloc] init] autorelease]; [server start]; [cond wait]; [cond unlock]; URL = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[performRequest:]", (client = [OFHTTPClient client]) && R([client setDelegate: self]) && R(request = [OFHTTPRequest requestWithURL: URL]) && 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", (data = [response readDataUntilEndOfStream]) && [data count] == 7 && memcmp([data items], "foo\nbar", 7) == 0) [server join]; [pool drain]; } @end |