Overview
Comment: | Migrate OFHTTPClientTests to ObjFWTest |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | objfwtest |
Files: | files | file ages | folders |
SHA3-256: |
851f6138bf97bf38d6a85208fd94610f |
User & Date: | js on 2024-02-18 10:11:41 |
Other Links: | branch diff | manifest | tags |
Context
2024-02-18
| ||
11:08 | Migrate OFKernelEventObserverTests to ObjFWTest check-in: aa56dd6d2a user: js tags: objfwtest | |
10:11 | Migrate OFHTTPClientTests to ObjFWTest check-in: 851f6138bf user: js tags: objfwtest | |
2024-02-17
| ||
22:23 | Migrate OFHTTPCookieManagerTests to ObjFWTest check-in: 2aad218748 user: js tags: objfwtest | |
Changes
Modified new_tests/Makefile from [87e80c1e61] to [2da97fd19f].
︙ | ︙ | |||
52 53 54 55 56 57 58 | ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m | > | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieManagerTests.m \ OFHTTPCookieTests.m \ OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} \ |
︙ | ︙ |
Renamed and modified tests/OFHTTPClientTests.m [8ae0f89264] to new_tests/OFHTTPClientTests.m [d3dab1d884].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <inttypes.h> #include <string.h> | | > | < > | | < | < < < < < < < | < | < < < < | < < < | < < < < < | < < < | < | < < < < < < < < | < < < | > | | < < > > > | | < < | | | < < | | | | > > > | > > > > > > > > > > > > > > > > > > > > > > > | > | | > | | > > > | > > > > > > > > > > > > > > > > > > > > | > > | > > | > > > > > > > > > > | | > > > > > > > > > > | > > > > > > > > > > > > | 14 15 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | */ #include "config.h" #include <inttypes.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHTTPClientTests: OTTestCase <OFHTTPClientDelegate> { OFHTTPResponse *_response; } @end @interface HTTPClientTestsServer: OFThread { OFCondition *_condition; uint16_t _port; } @property (readonly, nonatomic) OFCondition *condition; @property (readonly) uint16_t port; @end @implementation OFHTTPClientTests - (void)dealloc { [_response release]; [super dealloc]; } - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { [body writeString: @"Hello"]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ exception: (id)exception { OTAssertNil(exception); [_response release]; _response = [response_ retain]; [[OFRunLoop mainRunLoop] stop]; } - (void)testClient { HTTPClientTestsServer *server; OFIRI *IRI; OFHTTPRequest *request; OFHTTPClient *client; OFData *data; server = [[[HTTPClientTestsServer alloc] init] autorelease]; server.supportsSockets = true; [server.condition lock]; [server start]; [server.condition wait]; [server.condition unlock]; IRI = [OFIRI IRIWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server.port]]; request = [OFHTTPRequest requestWithIRI: IRI]; request.headers = [OFDictionary dictionaryWithObject: @"5" forKey: @"Content-Length"]; client = [OFHTTPClient client]; client.delegate = self; [client asyncPerformRequest: request]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertNotNil(_response); OTAssertNotNil([_response.headers objectForKey: @"Content-Length"]); data = [_response readDataUntilEndOfStream]; OTAssertEqual(data.count, 7); OTAssertEqual(data.itemSize, 1); OTAssertEqual(memcmp(data.items, "foo\nbar", 7), 0); OTAssertNil([server join]); } @end @implementation HTTPClientTestsServer @synthesize condition = _condition, port = _port; - (instancetype)init { self = [super init]; @try { _condition = [[OFCondition alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_condition release]; [super dealloc]; } - (id)main { OFTCPSocket *listener, *client; OFSocketAddress address; bool sawHost = false, sawContentLength = false, sawContentType = false; bool sawUserAgent = false; 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]; if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) return @"Wrong request"; for (size_t i = 0; i < 4; i++) { OFString *line = [client readLine]; if ([line isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) sawHost = true; else if ([line isEqual: @"Content-Length: 5"]) sawContentLength = true; if ([line isEqual: @"Content-Type: application/" @"x-www-form-urlencoded; charset=UTF-8"]) sawContentType = true; else if ([line hasPrefix: @"User-Agent:"]) sawUserAgent = true; } if (!sawHost) return @"Missing host"; if (!sawContentLength) return @"Missing content length"; if (!sawContentType) return @"Missing content type"; if (!sawUserAgent) return @"Missing user agent"; if (![[client readLine] isEqual: @""]) return @"Missing empty line"; [client readIntoBuffer: buffer exactLength: 5]; if (memcmp(buffer, "Hello", 5) != 0) return @"Missing body"; [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @"bar"]; [client close]; return nil; } @end |
Modified tests/Makefile from [4c633051dc] to [9ffa7ba9ba].
︙ | ︙ | |||
20 21 22 23 24 25 26 | OFStreamTests.m \ OFValueTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} | < | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | OFStreamTests.m \ OFValueTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} SRCS_SOCKETS = OFKernelEventObserverTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk .PHONY: run run-on-ios run-on-android |
︙ | ︙ |
Modified tests/TestsAppDelegate.h from [33a2e645a0] to [32ce471abe].
︙ | ︙ | |||
63 64 65 66 67 68 69 | - (void)dataTests; @end @interface TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTests; @end | < < < < | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | - (void)dataTests; @end @interface TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTests; @end @interface TestsAppDelegate (OFKernelEventObserverTests) - (void)kernelEventObserverTests; @end @interface TestsAppDelegate (OFListTests) - (void)listTests; @end |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [fbab5e01e9] to [bc05260f0b].
︙ | ︙ | |||
375 376 377 378 379 380 381 | [self listTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; #ifdef OF_HAVE_SOCKETS [self kernelEventObserverTests]; #endif | < < < | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | [self listTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; #ifdef OF_HAVE_SOCKETS [self kernelEventObserverTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails]; |
︙ | ︙ |