mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2024-10-07 08:32:16 +08:00
Updated run APIs to use options
This commit is contained in:
parent
f0c63f4776
commit
099b2a03e6
@ -83,7 +83,8 @@ extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground; //
|
||||
@property(nonatomic, readonly) NSURL* serverURL; // Only non-nil if server is running
|
||||
@property(nonatomic, readonly) NSURL* bonjourServerURL; // Only non-nil if server is running and Bonjour registration is active
|
||||
#if !TARGET_OS_IPHONE
|
||||
- (BOOL)runWithPort:(NSUInteger)port; // Starts then automatically stops on SIGINT i.e. Ctrl-C (use on main thread only)
|
||||
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
|
||||
- (BOOL)runWithOptions:(NSDictionary*)options; // Starts then automatically stops on SIGINT i.e. Ctrl-C (use on main thread only)
|
||||
#endif
|
||||
@end
|
||||
|
||||
@ -113,7 +114,7 @@ extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground; //
|
||||
|
||||
@interface GCDWebServer (Testing)
|
||||
@property(nonatomic, getter=isRecordingEnabled) BOOL recordingEnabled; // Creates files in the current directory containing the raw data for all requests and responses (directory most NOT contain prior recordings)
|
||||
- (NSInteger)runTestsInDirectory:(NSString*)path withPort:(NSUInteger)port; // Returns number of failed tests or -1 if server failed to start
|
||||
- (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path; // Returns number of failed tests or -1 if server failed to start
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
@ -596,13 +596,20 @@ static inline id _GetOption(NSDictionary* options, NSString* key, id defaultValu
|
||||
|
||||
#if !TARGET_OS_IPHONE
|
||||
|
||||
- (BOOL)runWithPort:(NSUInteger)port {
|
||||
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name {
|
||||
NSMutableDictionary* options = [NSMutableDictionary dictionary];
|
||||
[options setObject:[NSNumber numberWithInteger:port] forKey:GCDWebServerOption_Port];
|
||||
[options setValue:name forKey:GCDWebServerOption_BonjourName];
|
||||
return [self runWithOptions:options];
|
||||
}
|
||||
|
||||
- (BOOL)runWithOptions:(NSDictionary*)options {
|
||||
DCHECK([NSThread isMainThread]);
|
||||
BOOL success = NO;
|
||||
_run = YES;
|
||||
void (*handler)(int) = signal(SIGINT, _SignalHandler);
|
||||
if (handler != SIG_ERR) {
|
||||
if ([self startWithPort:port bonjourName:@""]) {
|
||||
if ([self startWithOptions:options]) {
|
||||
while (_run) {
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, true);
|
||||
}
|
||||
@ -899,10 +906,10 @@ static void _LogResult(NSString* format, ...) {
|
||||
ARC_RELEASE(message);
|
||||
}
|
||||
|
||||
- (NSInteger)runTestsInDirectory:(NSString*)path withPort:(NSUInteger)port {
|
||||
- (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path {
|
||||
NSArray* ignoredHeaders = @[@"Date", @"Etag"]; // Dates are always different by definition and ETags depend on file system node IDs
|
||||
NSInteger result = -1;
|
||||
if ([self startWithPort:port bonjourName:nil]) {
|
||||
if ([self startWithOptions:options]) {
|
||||
|
||||
result = 0;
|
||||
NSArray* files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
|
||||
@ -927,7 +934,7 @@ static void _LogResult(NSString* format, ...) {
|
||||
if (responseData) {
|
||||
CFHTTPMessageRef expectedResponse = _CreateHTTPMessageFromData(responseData, NO);
|
||||
if (expectedResponse) {
|
||||
CFHTTPMessageRef actualResponse = _CreateHTTPMessageFromPerformingRequest(requestData, port);
|
||||
CFHTTPMessageRef actualResponse = _CreateHTTPMessageFromPerformingRequest(requestData, self.port);
|
||||
if (actualResponse) {
|
||||
success = YES;
|
||||
|
||||
|
@ -274,14 +274,17 @@ int main(int argc, const char* argv[]) {
|
||||
webServer.delegate = delegate;
|
||||
if (testDirectory) {
|
||||
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);
|
||||
result = (int)[webServer runTestsInDirectory:testDirectory withPort:8080];
|
||||
result = (int)[webServer runTestsWithOptions:@{GCDWebServerOption_Port: @8080} inDirectory:testDirectory];
|
||||
} else {
|
||||
if (recording) {
|
||||
fprintf(stdout, "<RECORDING ENABLED>\n");
|
||||
webServer.recordingEnabled = YES;
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
if ([webServer runWithPort:8080]) {
|
||||
NSMutableDictionary* options = [NSMutableDictionary dictionary];
|
||||
[options setObject:@8080 forKey:GCDWebServerOption_Port];
|
||||
[options setObject:@"" forKey:GCDWebServerOption_BonjourName];
|
||||
if ([webServer runWithOptions:options]) {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user