1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
}
@end
@implementation HTTPClientTestsServer
- (id)main
{
OFTCPSocket *listener, *client;
char buffer[5];
[condition lock];
listener = [OFTCPSocket socket];
_port = [listener bindToHost: @"127.0.0.1" port: 0];
[listener listen];
[condition signal];
[condition unlock];
client = [listener accept];
|
>
|
>
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
}
@end
@implementation HTTPClientTestsServer
- (id)main
{
OFTCPSocket *listener, *client;
OFSocketAddress address;
char buffer[5];
[condition lock];
listener = [OFTCPSocket socket];
address = [listener bindToHost: @"127.0.0.1" port: 0];
_port = OFSocketAddressIPPort(&address);
[listener listen];
[condition signal];
[condition unlock];
client = [listener accept];
|
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
|
[[OFRunLoop mainRunLoop] stop];
}
- (void)HTTPClientTests
{
void *pool = objc_autoreleasePoolPush();
HTTPClientTestsServer *server;
OFURI *URI;
OFHTTPClient *client;
OFHTTPRequest *request;
OFData *data;
condition = [OFCondition condition];
[condition lock];
server = [[[HTTPClientTestsServer alloc] init] autorelease];
server.supportsSockets = true;
[server start];
[condition wait];
[condition unlock];
URI = [OFURI URIWithString:
[OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo",
server->_port]];
TEST(@"-[asyncPerformRequest:]",
(client = [OFHTTPClient client]) && (client.delegate = self) &&
(request = [OFHTTPRequest requestWithURI: URI]) &&
(request.headers =
[OFDictionary dictionaryWithObject: @"5"
forKey: @"Content-Length"]) &&
R([client asyncPerformRequest: request]))
[[OFRunLoop mainRunLoop] runUntilDate:
[OFDate dateWithTimeIntervalSinceNow: 2]];
|
|
|
|
|
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
|
[[OFRunLoop mainRunLoop] stop];
}
- (void)HTTPClientTests
{
void *pool = objc_autoreleasePoolPush();
HTTPClientTestsServer *server;
OFIRI *IRI;
OFHTTPClient *client;
OFHTTPRequest *request;
OFData *data;
condition = [OFCondition condition];
[condition lock];
server = [[[HTTPClientTestsServer alloc] init] autorelease];
server.supportsSockets = true;
[server start];
[condition wait];
[condition unlock];
IRI = [OFIRI IRIWithString:
[OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo",
server->_port]];
TEST(@"-[asyncPerformRequest:]",
(client = [OFHTTPClient client]) && (client.delegate = self) &&
(request = [OFHTTPRequest requestWithIRI: IRI]) &&
(request.headers =
[OFDictionary dictionaryWithObject: @"5"
forKey: @"Content-Length"]) &&
R([client asyncPerformRequest: request]))
[[OFRunLoop mainRunLoop] runUntilDate:
[OFDate dateWithTimeIntervalSinceNow: 2]];
|