mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
new teestcase by Sergei Golovin
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39503 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
aaf7f02758
commit
353810e7a9
2 changed files with 73 additions and 0 deletions
|
@ -582,6 +582,7 @@
|
|||
_URLString, @"507"];
|
||||
[response setContent: index];
|
||||
[response setHeader: @"content-type" value: @"text/html" parameters: nil];
|
||||
[response setHeader: @"HTTP" value: @"HTTP/1.1 200 OK" parameters:nil];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
72
Tests/base/NSURLConnection/test06.m
Normal file
72
Tests/base/NSURLConnection/test06.m
Normal file
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Tests for HTTP synchronous requests.
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Helpers/NSURLConnectionTest.h"
|
||||
#import "Helpers/TestWebServer.h"
|
||||
#import <Testing.h>
|
||||
|
||||
int main(int argc, char **argv, char **env)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
NSFileManager *fm;
|
||||
NSBundle *bundle;
|
||||
BOOL loaded;
|
||||
NSString *helperPath;
|
||||
|
||||
// load the test suite's classes
|
||||
fm = [NSFileManager defaultManager];
|
||||
helperPath = [[fm currentDirectoryPath]
|
||||
stringByAppendingString: @"/Helpers/TestConnection.bundle"];
|
||||
bundle = [NSBundle bundleWithPath: helperPath];
|
||||
loaded = [bundle load];
|
||||
|
||||
if (loaded)
|
||||
{
|
||||
Class testClass;
|
||||
TestWebServer *server;
|
||||
BOOL debug = NO;
|
||||
NSURL *url;
|
||||
NSError *error = nil;
|
||||
NSURLRequest *request;
|
||||
NSURLResponse *response = nil;
|
||||
NSData *data;
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
||||
// create a shared TestWebServer instance for performance
|
||||
// by default it requires the basic authentication with the pair
|
||||
// login:password
|
||||
server = [[testClass testWebServerClass] new];
|
||||
[server setDebug: debug];
|
||||
[server start: nil]; // 127.0.0.1:1234 HTTP
|
||||
|
||||
/*
|
||||
* Simple GET via HTTP with some response's body and
|
||||
* the response's status code 200
|
||||
*/
|
||||
url = [NSURL
|
||||
URLWithString: @"http://login:password@localhost:1234/index"];
|
||||
request = [NSURLRequest requestWithURL: url];
|
||||
data = [NSURLConnection sendSynchronousRequest: request
|
||||
returningResponse: &response
|
||||
error: &error];
|
||||
PASS(nil != data && [(NSHTTPURLResponse*)response statusCode] == 200,
|
||||
"NSURLConnection synchronous load with authentication returns a response");
|
||||
|
||||
// cleaning
|
||||
[server stop];
|
||||
DESTROY(server);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no classes no tests
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"can't load bundle TestConnection"];
|
||||
}
|
||||
|
||||
|
||||
DESTROY(arp);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue