1
#import <Foundation/Foundation.h>
3
#import "ObjectTesting.h"
11
url = [NSURL URLWithString:
12
@"scheme://user:password@host.domain.org:888/path/absfile.htm"];
13
url = [NSURL URLWithString:
14
@"file%20name.htm;param1;param2?something=other&andmore=more#fragments"
17
PASS_EQUAL([url description],
18
@"file%20name.htm;param1;param2?something=other&andmore=more#fragments -- scheme://user:password@host.domain.org:888/path/absfile.htm",
21
PASS_EQUAL([url absoluteString],
22
@"scheme://user:password@host.domain.org:888/path/file%20name.htm;param1;param2?something=other&andmore=more#fragments",
23
"absolute string ok");
25
PASS_EQUAL([[url absoluteURL] description],
26
@"scheme://user:password@host.domain.org:888/path/file%20name.htm;param1;param2?something=other&andmore=more#fragments",
27
"absolute url description ok");
29
PASS_EQUAL([[url baseURL] description],
30
@"scheme://user:password@host.domain.org:888/path/absfile.htm",
31
"base url description ok");
33
PASS_EQUAL([url fragment], @"fragments", "fragment ok");
35
PASS_EQUAL([url host], @"host.domain.org", "host ok");
36
PASS (NO == [url isFileURL], "is not a file url");
37
PASS_EQUAL([url parameterString], @"param1;param2", "parameter string ok");
38
PASS_EQUAL([url password], @"password", "password ok");
39
PASS_EQUAL([url path], @"/path/file name.htm", "path ok");
40
PASS_EQUAL([url port], [NSNumber numberWithInt:888], "port ok");
41
PASS_EQUAL([url query], @"something=other&andmore=more", "query ok");
42
PASS_EQUAL([url relativePath], @"file name.htm", "relativePath ok");
43
PASS_EQUAL([url relativeString],
44
@"file%20name.htm;param1;param2?something=other&andmore=more#fragments",
46
PASS_EQUAL([url resourceSpecifier],
47
@"file%20name.htm;param1;param2?something=other&andmore=more#fragments",
48
"resourceSpecifier ok");
49
PASS_EQUAL([url scheme], @"scheme", "scheme ok");
50
PASS_EQUAL([[url standardizedURL] absoluteString],
51
@"scheme://user:password@host.domain.org:888/path/file%20name.htm;param1;param2?something=other&andmore=more#fragments",
52
"standardizedURL ok");
53
PASS_EQUAL([url user], @"user", "user ok");
58
NSURL *url = [NSURL URLWithString: @"data:,A%20brief%20note"];
59
PASS_EQUAL([url scheme], @"data", "test data");
60
PASS_EQUAL([url absoluteString], @"data:,A%20brief%20note",
61
"data absolute string ok");
65
NSURL *url = [NSURL URLWithString: @"data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7"];
66
PASS_EQUAL([url scheme], @"data", "longer base64 data url ok");
70
NSURL *url = [NSURL URLWithString: @"data:,A%20brief%20note"
71
relativeToURL: [NSURL URLWithString: @"data:other"]];
72
PASS_EQUAL([url scheme], @"data", "relative data url ok");
73
PASS_EQUAL([url absoluteString], @"data:,A%20brief%20note",
74
"data absoluteString");
78
NSURL *url = [NSURL URLWithString: @"data:,A%20brief%20note"
79
relativeToURL: [NSURL URLWithString: @"file://localhost/"]];
80
PASS_EQUAL([url absoluteString], @"data:,A%20brief%20note",
81
"data absoluteString");
85
NSURL *url = [NSURL fileURLWithPath: @"/this#is a Path with % < > ?"];
86
PASS_EQUAL([url scheme], @"file", "scheme");
87
PASS_EQUAL([url host], @"localhost", "host");
88
PASS(nil == [url user], "user");
89
PASS(nil == [url password], "password");
90
PASS_EQUAL([url resourceSpecifier],
91
@"//localhost/this%23is%20a%20Path%20with%20%25%20%3C%20%3E%20%3F",
93
PASS_EQUAL([url path], @"/this#is a Path with % < > ?", "path");
94
PASS(nil == [url query], "query");
95
PASS(nil == [url parameterString], "parameterString");
96
PASS(nil == [url fragment], "fragment");
97
PASS_EQUAL([url absoluteString],
98
@"file://localhost/this%23is%20a%20Path%20with%20%25%20%3C%20%3E%20%3F",
100
PASS_EQUAL([url relativePath], @"/this#is a Path with % < > ?",
102
PASS_EQUAL([url description],
103
@"file://localhost/this%23is%20a%20Path%20with%20%25%20%3C%20%3E%20%3F",
108
NSURL *url = [NSURL URLWithString:
109
@"file:///pathtofile;parameters?query#anchor"];
110
PASS([url isFileURL], "file url");
111
PASS_EQUAL([url scheme], @"file", "file scheme");
112
PASS(nil == [url host], "host");
113
PASS(nil == [url user], "user");
114
PASS(nil == [url password], "password");
115
PASS_EQUAL([url resourceSpecifier],
116
@"/pathtofile;parameters?query#anchor",
117
"resourceSpecifier");
118
PASS_EQUAL([url path], @"/pathtofile", "path");
119
PASS_EQUAL([url query], @"query", "query");
120
PASS_EQUAL([url parameterString], @"parameters", "parameterString");
121
PASS_EQUAL([url fragment], @"anchor", "fragment");
122
PASS_EQUAL([url absoluteString],
123
@"file:///pathtofile;parameters?query#anchor",
125
PASS_EQUAL([url relativePath], @"/pathtofile", "relativePath");
126
PASS_EQUAL([url description], @"file:///pathtofile;parameters?query#anchor",
131
// can't initialize with spaces (must be %20)
132
NSURL *url = [NSURL URLWithString:
133
@"file:///pathtofile; parameters? query #anchor"];
134
PASS(nil == url, "spaces not allowed in file url built with string");
138
NSURL *url = [NSURL URLWithString:
139
@"file:///pathtofile;%20parameters?%20query%20#anchor"];
140
PASS(nil != url, "url");
144
// empty string is invalid - should return nils
145
NSURL *url = [NSURL URLWithString: @""];
146
PASS(nil == [url path], "empty string gives nil");