File: basic.m

package info (click to toggle)
gnustep-base 1.24.9-3.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,844 kB
  • sloc: objc: 975,047; ansic: 31,533; makefile: 135; cpp: 122; sh: 102; xml: 32
file content (69 lines) | stat: -rw-r--r-- 2,561 bytes parent folder | download | duplicates (4)
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
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"

int main()
{
  NSAutoreleasePool   *arp = [NSAutoreleasePool new];
  NSMutableURLRequest *mutable;
  NSURLConnection *connection;
  NSURLResponse *response;
  NSURLRequest *request;
  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");

  response = nil;
  data = [NSURLConnection sendSynchronousRequest: mutable
                               returningResponse: &response
                                           error: &error];
  testHopeful = YES;
  PASS(data != nil && [data length] > 0,
    "NSURLConnection synchronously load data from an http URL");
  PASS(response != nil && [(NSHTTPURLResponse*)response statusCode] > 0,
    "NSURLConnection synchronous load returns a response");
  testHopeful = NO;

  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");

  request = [NSURLRequest requestWithURL:
    [NSURL URLWithString:@"https://www.google.com/"]];
  response = nil;
  error = nil;
  data = [NSURLConnection sendSynchronousRequest: request
                               returningResponse: &response
                                           error: &error];

  testHopeful = YES;
  PASS(nil == error, "https://www.google.com/ does not return an error")
  PASS(nil != data, "https://www.google.com/ returns data")
  testHopeful = NO;

  [arp release]; arp = nil;
  return 0;
}