File: testTestWebServer.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (102 lines) | stat: -rw-r--r-- 3,039 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 *
 *  Author: Sergei Golovin <svgdev@mail.ru>
 *
 *  Runs two TestWebServer instances to check how the class TestWebServer
 *  behaves. Visit http://localhost:1234/index to see all supported resources.
 *  
 *  If you visit the main TestWebServer instance with the following command:
 *
 *       wget  -O - --user=login --password=password http://localhost:1234/301 2>&1
 *
 *  you should get a session log like this:
 *
 *       --2014-08-13 12:08:01--  http://localhost:1234/301
 *       Resolving 127.0.0.1 (localhost)... 127.0.0.1
 *       Connecting to 127.0.0.1 (localhost)|127.0.0.1|:1234... connected.
 *       HTTP request sent, awaiting response... 401 Unauthorized
 *       Reusing existing connection to 127.0.0.1:1234.
 *       HTTP request sent, awaiting response... 301 Moved Permanently
 *       Location: http://127.0.0.1:1235/ [following]
 *       --2014-08-13 12:08:01--  http://127.0.0.1:1235/
 *       Connecting to 127.0.0.1:1235... connected.
 *       HTTP request sent, awaiting response... 401 Unauthorized
 *       Reusing existing connection to 127.0.0.1:1235.
 *       HTTP request sent, awaiting response... 204 No Content
 *       Length: 0
 *       Saving to: ‘STDOUT’
 *
 *            0K                                                        0.00 =0s
 *
 *       2014-08-13 12:08:01 (0.00 B/s) - written to stdout [0/0]
 *
 */
#import <Foundation/Foundation.h>
#import "TestWebServer.h"
#import "NSURLConnectionTest.h"

#define TIMING 0.1

int main(int argc, char **argv, char **env)
{
  CREATE_AUTORELEASE_POOL(arp);
  NSFileManager *fm;
  NSBundle *bundle;
  BOOL loaded;
  NSString *helperPath;

  fm = [NSFileManager defaultManager];
  helperPath = [[fm currentDirectoryPath]
    stringByAppendingString: @"/TestConnection.bundle"];
  bundle = [NSBundle bundleWithPath: helperPath];
  loaded = [bundle load];

  if (loaded)
    {
      TestWebServer *server1;
      TestWebServer *server2;
      Class testClass;
      BOOL debug = YES;
      NSDictionary *d;

      testClass = [bundle principalClass]; // NSURLConnectionTest
      d = [NSDictionary dictionaryWithObjectsAndKeys:
        //			  @"https", @"Protocol",
        nil];
      server1 = [[[testClass testWebServerClass] alloc]
        initWithAddress: @"localhost"
        port: @"1234"
        mode: NO
        extra: d];
      [server1 setDebug: debug];
      [server1 start: d]; // localhost:1234 HTTP

      server2 = [[[testClass testWebServerClass] alloc]
        initWithAddress: @"localhost"
        port: @"1235"
        mode: NO
        extra: d];
      [server2 setDebug: debug];
      [server2 start: d]; // localhost:1235 HTTP
      
      while (YES)
	{
	  [[NSRunLoop currentRunLoop]
      		runUntilDate: [NSDate dateWithTimeIntervalSinceNow: TIMING]];
	}
      [server1 stop];
      DESTROY(server1);
      [server2 stop];
      DESTROY(server2);
    }
  else
    {
      [NSException raise: NSInternalInconsistencyException
		  format: @"can't load bundle TestConnection"];
    }


  DESTROY(arp);

  return 0;
}