Add NSConnectionDataDelegate protocol and NSRequestNetworkServiceType

This commit is contained in:
Gregory John Casamento 2021-11-21 02:17:55 -05:00
commit d8b2e969ef
8 changed files with 373 additions and 232 deletions

View file

@ -4,6 +4,22 @@
NSURLConnectionDataDelegate protocol.
* Headers/Foundation/NSURLRequest.h: Add enum for
NSURLNetworkServiceType.
2021-11-19 Richard Frith-Macdonald <rfm@gnu.org>
* Helpers/Launch.h:
* Helpers/capture.m:
* Helpers/keepalive.m:
* Helpers/respond.m:
* test00.m:
* test01.m:
* test02.m:
Rewrite helper launching so that the test process waits for up to
ten seconds for the helper to tell it that it's ready to accept
requests. This should make tests run a bit quicker (no longer
waiting a fixed interval for the helper to start) while allowing
longer for the helpers to start on slow systems, and thus making
the tests more reliable.
>>>>>>> b7d82408a6fba871ce9e51f249aefc398fcd3bce
2021-11-11 Frederik Seiffert <frederik@algoriddim.com>

View file

@ -0,0 +1,84 @@
/* Code to start up a helper and wait for it to confirm it's ready to proceed
* The helper must write someting to stdout to indicate its readiness.
*/
#if GNUSTEP
@interface HelperListener : NSObject
{
@public
BOOL done;
BOOL active;
}
- (void) helperRead: (NSNotification*)n;
@end
@implementation HelperListener
- (void) helperRead: (NSNotification*)n
{
NSDictionary *u = [n userInfo];
NSData *d;
d = [u objectForKey: NSFileHandleNotificationDataItem];
if ([d length] > 0)
{
active = YES;
}
done = YES;
}
@end
@implementation NSTask (TestHelper)
+ (NSTask*) launchedHelperWithLaunchPath: (NSString*)_path
arguments: (NSArray*)_args
timeout: (NSTimeInterval)_wait
{
NSTask *t = [NSTask new];
ENTER_POOL
NSNotificationCenter *c = [NSNotificationCenter defaultCenter];
NSPipe *p = [NSPipe pipe];
NSFileHandle *h = [p fileHandleForReading];
HelperListener *l = AUTORELEASE([HelperListener new]);
NSDate *d;
if (_wait <= 0.0)
{
_wait = 5.0;
}
d = [NSDate dateWithTimeIntervalSinceNow: _wait];
[t setLaunchPath: _path];
[t setArguments: _args];
[t setStandardOutput: p];
[t launch];
[c addObserver: l
selector: @selector(helperRead:)
name: NSFileHandleReadCompletionNotification
object: h];
[h readInBackgroundAndNotify];
while (NO == l->done && [d timeIntervalSinceNow] > 0.0)
{
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: d];
}
[c removeObserver: l
name: NSFileHandleReadCompletionNotification
object: h];
[h closeFile];
if (NO == l->done)
{
NSLog(@"Helper task %@ failed to start up in time.", _path);
[t terminate];
[t waitUntilExit];
t = nil;
}
else if (NO == l->active)
{
NSLog(@"Helper task %@ failed to start (and ended).", _path);
[t terminate];
[t waitUntilExit];
t = nil;
}
LEAVE_POOL
return AUTORELEASE(t);
}
@end
#endif /* GNUSTEP */

View file

@ -14,7 +14,7 @@
BOOL done; /* the response is written */
NSString *file; /* the file to write the captured request */
}
- (id)initWithSecure:(BOOL)flag;
- (id) initWithSecure:(BOOL)flag;
- (int) runTest;
@end
@ -29,9 +29,9 @@
[super dealloc];
}
- (id)initWithSecure:(BOOL)flag
- (id) initWithSecure:(BOOL)flag
{
if((self = [super init]) != nil)
if ((self = [super init]) != nil)
{
isSecure = flag;
capture = [NSMutableData new];
@ -70,7 +70,7 @@
NSLog(@"Failed to create server stream");
return 1;
}
if(isSecure)
if (isSecure)
{
[serverStream setProperty: NSStreamSocketSecurityLevelTLSv1 forKey: NSStreamSocketSecurityLevelKey];
[serverStream setProperty: @"testCert.pem" forKey: GSTLSCertificateFile];
@ -81,7 +81,12 @@
[serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[serverStream open];
while(!done)
/* Tell main test program we are ready to handle a request
*/
[[NSFileHandle fileHandleWithStandardOutput] writeData:
[@"Ready" dataUsingEncoding: NSASCIIStringEncoding]];
while (!done)
{
[rl runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
}
@ -151,18 +156,18 @@
tmp1 = [[NSString alloc] initWithData: capture
encoding: NSUTF8StringEncoding];
// whether the headers are read
if((r1 = [tmp1 rangeOfString: @"\r\n\r\n"]).location != NSNotFound)
if ((r1 = [tmp1 rangeOfString: @"\r\n\r\n"]).location != NSNotFound)
{
headers = [tmp1 substringToIndex: r1.location + 2];
if((r2 = [[headers lowercaseString] rangeOfString: @"content-length:"]).location != NSNotFound)
if ((r2 = [[headers lowercaseString] rangeOfString: @"content-length:"]).location != NSNotFound)
{
tmp2 = [headers substringFromIndex: r2.location + r2.length]; // content-length:<tmp2><end of headers>
if((r2 = [tmp2 rangeOfString: @"\r\n"]).location != NSNotFound)
if ((r2 = [tmp2 rangeOfString: @"\r\n"]).location != NSNotFound)
{
// full line with content-length is present
tmp2 = [tmp2 substringToIndex: r2.location]; // number of content's bytes
contentLength = [tmp2 intValue];
if(r1.location + 4 + contentLength == [capture length]) // Did we get headers + body?
if (r1.location + 4 + contentLength == [capture length]) // Did we get headers + body?
{
// full request is read so write it
if ([capture writeToFile: file atomically: YES] == NO)
@ -178,11 +183,11 @@
}
DESTROY(tmp1);
}
if(!doRespond) break;
if (!doRespond) break;
}
case NSStreamEventHasSpaceAvailable:
{
if(doRespond)
if (doRespond)
{
// if we have read all request's bytes
NSData *data;

View file

@ -81,6 +81,11 @@
[serverStream scheduleInRunLoop: runLoop forMode: NSDefaultRunLoopMode];
[serverStream open];
/* Tell main test program we are ready to handle a request
*/
[[NSFileHandle fileHandleWithStandardOutput] writeData:
[@"Ready" dataUsingEncoding: NSASCIIStringEncoding]];
// only run for a fixed time anyway
[runLoop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: lifetime]];
@ -220,8 +225,9 @@
case NSStreamEventErrorOccurred:
{
int code = [[theStream streamError] code];
NSLog(@"Received error %d on stream %p", code, theStream);
NSError *err = [theStream streamError];
int code = [err code];
NSLog(@"Received error %@ (%d) on stream %p", err, code, theStream);
[theStream close];
[theStream removeFromRunLoop: runLoop forMode: NSDefaultRunLoopMode];
if (theStream == inStream) inStream = nil;

View file

@ -75,6 +75,11 @@
[serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[serverStream open];
/* Tell main test program we are ready to handle a request
*/
[[NSFileHandle fileHandleWithStandardOutput] writeData:
[@"Ready" dataUsingEncoding: NSASCIIStringEncoding]];
/* Run for up to 5 minutes to allow slow/large tests to complete.
*/
[rl runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 300]];

View file

@ -1,13 +1,14 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
#import "Helpers/Launch.h"
int main()
{
#if GNUSTEP
NSAutoreleasePool *arp = [NSAutoreleasePool new];
ENTER_POOL
unsigned i, j;
NSTimeInterval wake = 10.0;
NSURL *url;
NSURL *u;
NSData *data;
@ -26,73 +27,78 @@ int main()
keepalive = [helpers stringByAppendingPathComponent: @"keepalive"];
respond = [helpers stringByAppendingPathComponent: @"respond"];
t = [NSTask launchedTaskWithLaunchPath: keepalive
START_SET("-resourceDataUsingCache")
const char *lit = "This is the data in the first chunk\r\n"
"and this is the second one\r\n"
"consequence";
t = [NSTask launchedHelperWithLaunchPath: keepalive
arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"1234",
@"-Count", @"1",
nil]];
if (t != nil)
{
const char *lit = "This is the data in the first chunk\r\n"
"and this is the second one\r\n"
"consequence";
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"1234",
@"-Count", @"1",
nil]
timeout: wake];
cont = [NSData dataWithBytes: lit length: strlen(lit)];
NEED(testPassed = (t != nil))
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code
str = [u propertyForKey: NSHTTPPropertyStatusCodeKey];
PASS_EQUAL(data, cont, "NSURL chunked test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
}
cont = [NSData dataWithBytes: lit length: strlen(lit)];
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code
str = [u propertyForKey: NSHTTPPropertyStatusCodeKey];
PASS_EQUAL(data, cont, "NSURL chunked test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
t = [NSTask launchedTaskWithLaunchPath: keepalive
END_SET("-resourceDataUsingCache")
START_SET("-sendSynchronousRequest:returningResponse:error:")
NSURLRequest *request;
NSHTTPURLResponse *response;
NSError *error;
const char *lit = "This is the data in the first chunk\r\n"
"and this is the second one\r\n"
"consequence";
t = [NSTask launchedHelperWithLaunchPath: keepalive
arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"1234",
@"-Count", @"1",
nil]];
if (t != nil)
{
NSURLRequest *request;
NSHTTPURLResponse *response;
NSError *error;
const char *lit = "This is the data in the first chunk\r\n"
"and this is the second one\r\n"
"consequence";
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"1234",
@"-Count", @"1",
nil]
timeout: wake];
cont = [NSData dataWithBytes: lit length: strlen(lit)];
NEED(testPassed = (t != nil))
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
cont = [NSData dataWithBytes: lit length: strlen(lit)];
request = [NSURLRequest requestWithURL: u];
response = nil;
data = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
// Get status code
PASS(response != nil && [response statusCode] > 0,
"NSURLConnection synchronous load returns a response");
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
PASS([data isEqual: cont], "NSURLConnection chunked test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
}
request = [NSURLRequest requestWithURL: u];
response = nil;
data = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
// Get status code
PASS(response != nil && [response statusCode] > 0,
"NSURLConnection synchronous load returns a response");
PASS([data isEqual: cont], "NSURLConnection chunked test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
END_SET("-sendSynchronousRequest:returningResponse:error:")
url = [NSURL URLWithString: @"http://localhost:1234/"];
START_SET("Shrink")
/* Ask the 'respond' helper to send back a response containing
* 'hello' and to shrink the write buffer size it uses on each
* request. We do as many requests as the total response size
@ -112,42 +118,44 @@ int main()
[resp appendData: cont];
[resp writeToFile: @"SimpleResponse.dat" atomically: YES];
str = [NSString stringWithFormat: @"%u", [resp length]];
t = [NSTask launchedTaskWithLaunchPath: respond
str = [NSString stringWithFormat: @"%lu", (unsigned long)[resp length]];
t = [NSTask launchedHelperWithLaunchPath: respond
arguments: [NSArray arrayWithObjects:
@"-FileName", @"SimpleResponse.dat",
@"-Shrink", @"YES",
@"-Count", str,
nil]];
if (t != nil)
{
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
i = [resp length];
while (i-- > 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
char buf[128];
@"-FileName", @"SimpleResponse.dat",
@"-Shrink", @"YES",
@"-Count", str,
nil]
timeout: wake];
/* Just to test caching of url handles, we use eighteen
* different URLs (we know the cache size is 16) to ensure
* that loads work when handles are flushed from the cache.
*/
u = [NSURL URLWithString: [NSString stringWithFormat:
@"http://localhost:1234/%d", i % 18]];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code
str = [u propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "respond test %d OK", i);
PASS([data isEqual: cont], "%s", buf)
[pool release];
}
// Wait for server termination
[t terminate];
[t waitUntilExit];
NEED(testPassed = (t != nil))
i = [resp length];
while (i-- > 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
char buf[128];
/* Just to test caching of url handles, we use eighteen
* different URLs (we know the cache size is 16) to ensure
* that loads work when handles are flushed from the cache.
*/
u = [NSURL URLWithString: [NSString stringWithFormat:
@"http://localhost:1234/%d", i % 18]];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code
str = [u propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "respond test %d OK", i);
PASS([data isEqual: cont], "%s", buf)
[pool release];
}
// Wait for server termination
[t terminate];
[t waitUntilExit];
END_SET("Shrink")
/* Now build a response which pretends to be an HTTP1.1 server and should
* support connection keepalive ... so we can test that the keeplive code
* correctly handles the case where the remote end drops the connection.
@ -158,44 +166,49 @@ int main()
[resp appendData: cont];
[resp writeToFile: @"SimpleResponse.dat" atomically: YES];
str = [NSString stringWithFormat: @"%u", [resp length]];
str = [NSString stringWithFormat: @"%lu", (unsigned long)[resp length]];
for (j = 0; j < 13 ; j += 4)
{
NSString *delay = [NSString stringWithFormat: @"%u", j];
NSString *delay = [NSString stringWithFormat: @"%u", j];
NSString *name = [NSString stringWithFormat: @"Keepalive drop %u", j];
t = [NSTask launchedTaskWithLaunchPath: respond
START_SET([name UTF8String])
t = [NSTask launchedHelperWithLaunchPath: respond
arguments: [NSArray arrayWithObjects:
@"-FileName", @"SimpleResponse.dat",
@"-Count", @"2", @"-Pause", delay,
nil]];
if (t != nil)
{
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
for (i = 0; i < 2; i++)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
char buf[128];
@"-FileName", @"SimpleResponse.dat",
@"-Count", @"2",
@"-Pause", delay,
nil]
timeout: wake];
// Talk to server.
data = [url resourceDataUsingCache: NO];
// Get status code
str = [url propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "respond with keepalive %d (pause %d) OK", i, j);
PASS([data isEqual: cont], "%s", buf)
[pool release];
/* Allow remote end time to close socket.
*/
[NSThread sleepUntilDate:
[NSDate dateWithTimeIntervalSinceNow: 0.1]];
}
/* Kill helper task and wait for it to finish */
[t terminate];
[t waitUntilExit];
}
NEED(testPassed = (t != nil))
for (i = 0; i < 2; i++)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
char buf[128];
// Talk to server.
data = [url resourceDataUsingCache: NO];
// Get status code
str = [url propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "respond with keepalive %d (pause %d) OK", i, j);
PASS([data isEqual: cont], "%s", buf)
[pool release];
/* Allow remote end time to close socket.
*/
[NSThread sleepUntilDate:
[NSDate dateWithTimeIntervalSinceNow: 0.1]];
}
/* Kill helper task and wait for it to finish */
[t terminate];
[t waitUntilExit];
END_SET([name UTF8String])
}
[arp release]; arp = nil;
LEAVE_POOL
#endif
return 0;
}

View file

@ -1,17 +1,19 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
#import "Helpers/Launch.h"
int main()
{
#if GNUSTEP
NSAutoreleasePool *arp = [NSAutoreleasePool new];
ENTER_POOL
unsigned i;
NSURL *url;
NSData *data;
NSData *resp;
NSString *str;
NSTimeInterval wake = 10.0;
NSMutableString *m;
NSTask *t;
NSString *helpers;
@ -22,6 +24,7 @@ int main()
helpers = [helpers stringByAppendingPathComponent: @"obj"];
keepalive = [helpers stringByAppendingPathComponent: @"keepalive"];
START_SET("Keepalive")
url = [NSURL URLWithString: @"http://localhost:4322/"];
m = [NSMutableString stringWithCapacity: 2048];
@ -32,34 +35,34 @@ int main()
resp = [m dataUsingEncoding: NSASCIIStringEncoding];
[resp writeToFile: @"KAResponse.dat" atomically: YES];
t = [NSTask launchedTaskWithLaunchPath: keepalive
t = [NSTask launchedHelperWithLaunchPath: keepalive
arguments: [NSArray arrayWithObjects:
@"-FileName", @"KAResponse.dat",
@"-CloseFreq", @"3",
@"-Count", @"10",
nil]];
if (t != nil)
{
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
for (i = 0; i < 10; i++)
{
/*we just get the response every time. It should be the
*same every time, even though the headers change and
*sometimes the connection gets dropped
*/
char buf[BUFSIZ];
data = [url resourceDataUsingCache: NO];
str = [url propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "keep-alive test %d OK",i);
PASS([data isEqual:resp], "%s", buf)
}
[t terminate];
[t waitUntilExit];
}
@"-FileName", @"KAResponse.dat",
@"-CloseFreq", @"3",
@"-Count", @"10",
nil]
timeout: wake];
[arp release]; arp = nil;
NEED(testPassed = (t != nil))
for (i = 0; i < 10; i++)
{
/*we just get the response every time. It should be the
*same every time, even though the headers change and
*sometimes the connection gets dropped
*/
char buf[BUFSIZ];
data = [url resourceDataUsingCache: NO];
str = [url propertyForKey: NSHTTPPropertyStatusCodeKey];
sprintf(buf, "keep-alive test %d OK",i);
PASS([data isEqual:resp], "%s", buf)
}
[t terminate];
[t waitUntilExit];
END_SET("Keepalive")
LEAVE_POOL
#endif
return 0;
}

View file

@ -1,22 +1,24 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
#import "Helpers/Launch.h"
int main()
{
#if GNUSTEP
NSAutoreleasePool *arp = [NSAutoreleasePool new];
ENTER_POOL
unsigned i;
NSURL *url;
NSMutableString *m;
NSData *data;
NSString *str;
NSTask *t;
NSTimeInterval wake = 10.0;
NSString *helpers;
NSString *capture;
NSMutableURLRequest *request;
NSHTTPURLResponse *response = nil;
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSFileManager *fm;
NSRange r;
@ -34,87 +36,94 @@ int main()
[m appendFormat: @"Hello %d\r\n", i];
}
t = [NSTask launchedTaskWithLaunchPath: capture
arguments: [NSArray arrayWithObjects:
nil]];
if (t != nil)
{
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
// remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL];
// making a POST request
url = [NSURL URLWithString: @"http://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
[request setHTTPMethod: @"POST"];
START_SET("Capture")
// sending the request
[NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
t = [NSTask launchedHelperWithLaunchPath: capture
arguments: [NSArray arrayWithObjects: nil]
timeout: wake];
// analyzing the response
PASS(response != nil && [response statusCode] == 204,
"NSURLConnection synchronous load returns a response");
NEED(testPassed = (t != nil))
data = [NSData dataWithContentsOfFile: @"Capture.dat"];
str = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
r = [str rangeOfString: m];
PASS(r.location != NSNotFound,
"NSURLConnection capture test OK");
// remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL];
// making a POST request
url = [NSURL URLWithString: @"http://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
[request setHTTPMethod: @"POST"];
// Wait for server termination
[t terminate];
[t waitUntilExit];
DESTROY(str);
response = nil;
error = nil;
}
// sending the request
[NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
// analyzing the response
PASS(response != nil && [response statusCode] == 204,
"NSURLConnection synchronous load returns a response");
data = [NSData dataWithContentsOfFile: file];
str = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
r = [str rangeOfString: m];
PASS(r.location != NSNotFound,
"NSURLConnection capture test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
DESTROY(str);
response = nil;
error = nil;
END_SET("Capture")
START_SET("Secure")
// the same but with secure connection (HTTPS)
t = [NSTask launchedTaskWithLaunchPath: capture
arguments: [NSArray arrayWithObjects:
@"-Secure", @"YES",
nil]];
if (t != nil)
{
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
// remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL];
// making a POST request
url = [NSURL URLWithString: @"https://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
[request setHTTPMethod: @"POST"];
t = [NSTask launchedHelperWithLaunchPath: capture
arguments: [NSArray arrayWithObjects:
@"-Secure", @"YES",
nil]
timeout: wake];
// sending the request
[NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
NEED(testPassed = (t != nil))
// sending the request
PASS(response != nil && [response statusCode] == 204,
"NSURLConnection synchronous load returns a response");
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
// remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL];
// making a POST request
url = [NSURL URLWithString: @"https://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
[request setHTTPMethod: @"POST"];
data = [NSData dataWithContentsOfFile: @"Capture.dat"];
str = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
r = [str rangeOfString: m];
PASS(r.location != NSNotFound,
"NSURLConnection capture test OK");
// sending the request
[NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
// Wait for server termination
[t terminate];
[t waitUntilExit];
DESTROY(str);
}
// sending the request
PASS(response != nil && [response statusCode] == 204,
"NSURLConnection synchronous load returns a response");
[arp release]; arp = nil;
data = [NSData dataWithContentsOfFile: file];
str = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
r = [str rangeOfString: m];
PASS(r.location != NSNotFound,
"NSURLConnection capture test OK");
// Wait for server termination
[t terminate];
[t waitUntilExit];
DESTROY(str);
END_SET("Secure")
LEAVE_POOL
#endif
return 0;
}