2011-02-16 08:21:17 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "Testing.h"
|
|
|
|
#import "ObjectTesting.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSMutableURLRequest *mutable;
|
|
|
|
NSURLConnection *connection;
|
|
|
|
NSURLResponse *response;
|
|
|
|
NSError *error;
|
|
|
|
NSData *data;
|
|
|
|
NSURL *httpURL;
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
httpURL = [NSURL URLWithString: @"http://www.gnustep.org"];
|
|
|
|
|
|
|
|
TEST_FOR_CLASS(@"NSURLConnection", [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");
|
|
|
|
|
2011-10-07 09:17:14 +00:00
|
|
|
response = nil;
|
2011-02-16 08:21:17 +00:00
|
|
|
data = [NSURLConnection sendSynchronousRequest: mutable
|
|
|
|
returningResponse: &response
|
|
|
|
error: &error];
|
|
|
|
PASS(data != nil && [data length] > 0,
|
|
|
|
"NSURLConnection synchronously load data from an http URL");
|
2011-10-07 09:17:14 +00:00
|
|
|
PASS(response != nil && [response statusCode] > 0,
|
|
|
|
"NSURLConnection synchronous load returns a response");
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|