Index: base/NSURLConnection/basic.m =================================================================== --- base/NSURLConnection/basic.m (révision 0) +++ base/NSURLConnection/basic.m (révision 0) @@ -0,0 +1,48 @@ +#import +#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"); + + data = [NSURLConnection sendSynchronousRequest:mutable returningResponse:&response error:&error]; + pass(data != nil && [data length] > 0, + "NSURLConnection synchronously load data from an http URL"); + [data release]; + + 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"); + [data release]; + + [arp release]; arp = nil; + return 0; +} Index: base/NSURLProtocol/basic.m =================================================================== --- base/NSURLProtocol/basic.m (révision 0) +++ base/NSURLProtocol/basic.m (révision 0) @@ -0,0 +1,36 @@ +#import +#import "Testing.h" +#import "ObjectTesting.h" + +int main() +{ + NSAutoreleasePool *arp = [NSAutoreleasePool new]; + NSMutableURLRequest *mutable, *copy; + NSURLProtocol *protocol; + NSURL *httpURL; + + + httpURL = [NSURL URLWithString: @"http://www.gnustep.org"]; + + TEST_FOR_CLASS(@"NSURLProtocol", [NSURLProtocol alloc], + "NSURLProtocol +alloc returns an NSURLProtocol"); + + mutable = [[NSMutableURLRequest requestWithURL:httpURL] retain]; + TEST_EXCEPTION([NSURLProtocol canInitWithRequest:mutable], nil, YES, + "NSURLProtocol +canInitWithRequest throws an exeception (subclasses should be used)"); + + pass(mutable == [NSURLProtocol canonicalRequestForRequest:mutable], + "NSURLProtocol +canonicalRequestForRequest: return it argument"); + + copy = [mutable copy]; + pass([NSURLProtocol requestIsCacheEquivalent:mutable toRequest:copy], + "NSURLProtocol +requestIsCacheEquivalent:toRequest returns YES with a request and its copy"); + [copy setHTTPMethod:@"POST"]; + pass([NSURLProtocol requestIsCacheEquivalent:mutable toRequest:copy] == NO, + "NSURLProtocol +requestIsCacheEquivalent:toRequest returns NO after a method change"); + [copy release]; + [mutable release]; + + [arp release]; arp = nil; + return 0; +} Index: base/NSURLRequest/basic.m =================================================================== --- base/NSURLRequest/basic.m (révision 0) +++ base/NSURLRequest/basic.m (révision 0) @@ -0,0 +1,52 @@ +#import +#import "Testing.h" +#import "ObjectTesting.h" + +int main() +{ + NSAutoreleasePool *arp = [NSAutoreleasePool new]; + NSURLRequest *request; + NSMutableURLRequest *mutable; + NSURL *httpURL, *foobarURL; + + + httpURL = [NSURL URLWithString: @"http://www.gnustep.org"]; + foobarURL = [NSURL URLWithString: @"foobar://localhost/madeupscheme"]; + + TEST_FOR_CLASS(@"NSURLRequest", [NSURLRequest alloc], + "NSURLRequest +alloc returns an NSURLRequest"); + + request = [[NSURLRequest requestWithURL:httpURL] retain]; + pass(request != nil, + "NSURLRequest +requestWithURL returns a request from a valid URL"); + pass([[[request URL] absoluteString] isEqualToString:[httpURL absoluteString]], + "Request URL is equal to the URL used for creation"); + pass([@"GET" isEqualToString:[request HTTPMethod]], + "Request is initialized with a GET method"); + + request = [NSURLRequest requestWithURL:foobarURL]; + pass(request != nil, + "NSURLRequest +requestWithURL returns a request from an invalid URL (unknown scheme)"); + + mutable = [request mutableCopy]; + pass(mutable != nil && [mutable isKindOfClass:[NSMutableURLRequest class]], + "NSURLRequest -mutableCopy returns a mutable request"); + [mutable setHTTPMethod:@"POST"]; + pass([@"POST" isEqualToString:[mutable HTTPMethod]], + "Can setHTTPMethod of a mutable request (POST)"); + [mutable setHTTPMethod:@"NONHTTPMETHOD"]; + pass([@"NONHTTPMETHOD" isEqualToString:[mutable HTTPMethod]], + "Can setHTTPMethod of a mutable request (non existant NONHTTPMETHOD)"); + + [mutable addValue:@"value1" forHTTPHeaderField:@"gnustep"]; + pass([@"value1" isEqualToString:[mutable valueForHTTPHeaderField:@"gnustep"]], + "Can set and get a value for an HTTP header field"); + [mutable addValue:@"value2" forHTTPHeaderField:@"gnustep"]; + pass([@"value1,value2" isEqualToString:[mutable valueForHTTPHeaderField:@"gnustep"]], + "Handle multiple values for an HTTP header field"); + [mutable release]; + [request release]; + + [arp release]; arp = nil; + return 0; +}