1 2 3 4 5 6 7 8 9 10 11 12 13 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
|
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableURLRequest *mutable;
NSURLConnection *connection;
NSURLResponse *response;
NSURLRequest *request;
NSError *error;
NSData *data;
NSURL *httpURL;
NSString *path;
httpURL = [NSURL URLWithString: @"http://www.gnustep.org"];
TEST_FOR_CLASS(@"NSURLConnection", AUTORELEASE([NSURLConnection alloc]),
"NSURLConnection +alloc returns an NSURLConnection");
mutable = [NSMutableURLRequest requestWithURL: httpURL];
PASS([NSURLConnection canHandleRequest: mutable],
"NSURLConnection can handle an valid HTTP request (GET)");
[mutable setHTTPMethod: @"WRONGMETHOD"];
PASS([NSURLConnection canHandleRequest: mutable],
"NSURLConnection can handle an invalid HTTP request (WRONGMETHOD)");
[mutable setHTTPMethod: @"GET"];
connection = [NSURLConnection connectionWithRequest: mutable delegate: nil];
PASS(connection != nil,
"NSURLConnection +connectionWithRequest: delegate: with nil as delegate returns a instance");
response = nil;
#if defined(_WIN32)
testHopeful = YES;
#endif
data = [NSURLConnection sendSynchronousRequest: mutable
returningResponse: &response
error: &error];
testHopeful = YES;
PASS(data != nil && [data length] > 0,
"NSURLConnection synchronously load data from an http URL");
PASS(response != nil && [(NSHTTPURLResponse*)response statusCode] > 0,
"NSURLConnection synchronous load returns a response");
testHopeful = NO;
#if defined(_WIN32)
testHopeful = NO;
#endif
path = [[NSFileManager defaultManager] currentDirectoryPath];
path = [path stringByAppendingPathComponent: @"basic.m"];
[mutable setURL: [NSURL fileURLWithPath: path]];
data = [NSURLConnection sendSynchronousRequest: mutable
returningResponse: &response
error: &error];
PASS(data != nil && [data length] > 0,
"NSURLConnection synchronously load data from a local file");
request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"https://www.google.com/"]];
response = nil;
error = nil;
data = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
testHopeful = YES;
PASS(nil == error, "https://www.google.com/ does not return an error")
PASS(nil != data, "https://www.google.com/ returns data")
testHopeful = NO;
[arp release]; arp = nil;
return 0;
}
|