File: test01.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 (105 lines) | stat: -rw-r--r-- 2,268 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
103
104
105
/**
 *  The test makes connections to not-listening services.
 *  One for HTTP and one for HTTPS.
 *  The NSURLConnection delegate is supposed to catch an
 *  error in that two cases and sets it's ivars accordingly.
 */

#import <Foundation/Foundation.h>
#import "Testing.h"

@interface Delegate : NSObject
{
  BOOL _done;
  NSError *_error;
}
- (void) reset;
- (NSError *) error;
- (BOOL) done;
- (void) connection: (NSURLConnection *)connection
   didFailWithError: (NSError *)error;
@end

@implementation Delegate

- (void) reset
{
  _done = NO;
  _error = nil;
}

- (NSError *) error
{
  return _error;
}

- (BOOL) done
{
  return _done;
}

- (void) connection: (NSURLConnection *)connection
   didFailWithError: (NSError *)error
{
  _error = error;
  _done = YES;
}

@end

int main(int argc, char **argv, char **env)
{
  NSAutoreleasePool *arp = [NSAutoreleasePool new];
  NSTimeInterval timing;
  NSTimeInterval duration;

  NSString *urlString;
  NSURLRequest *req;
  Delegate *del;
  
  duration = 0.0;
  timing = 0.1;
  urlString = @"http://localhost:19750";
  req = [NSURLRequest requestWithURL: [NSURL URLWithString: urlString]];
  del = [[Delegate new] autorelease];
  [NSURLConnection connectionWithRequest: req
				delegate: del];
  while (![del done] && duration < 3.0)
    {
      [[NSRunLoop currentRunLoop]
        runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timing]];
      duration += timing;
    }
  PASS([del done], "http test completes");
  PASS([del done] && nil != [del error],
    "connection to dead(not-listening) HTTP service");
  [del reset];

#if !defined(HAVE_GNUTLS)
testHopeful = YES;
#endif

  duration = 0.0;
  urlString = @"https://localhost:19750";
  req = [NSURLRequest requestWithURL: [NSURL URLWithString: urlString]];
  [NSURLConnection connectionWithRequest: req
				delegate: del];
  while (![del done] && duration < 3.0)
    {
      [[NSRunLoop currentRunLoop]
        runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timing]];
      duration += timing;
    }
  PASS([del done], "https test completes");
  PASS([del done] && nil != [del error],
    "connection to dead(not-listening) HTTPS service");
  [del reset];

#if !defined(HAVE_GNUTLS)
testHopeful = NO;
#endif

  [arp release]; arp = nil;

  return 0;
}