as3corelib 0.1.0 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/Gemfile +1 -4
  2. data/Gemfile.lock +7 -4
  3. data/README.textile +20 -10
  4. data/Rakefile +32 -2
  5. data/as3corelib.gemspec +13 -11
  6. data/lib/as3corelib.rb +10 -4
  7. data/lib/as3corelib/version.rb +4 -0
  8. metadata +31 -121
  9. data/build/build.properties +0 -48
  10. data/build/build.xml +0 -104
  11. data/examples/JSONExample/JSONExample.mxml +0 -73
  12. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
  13. data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
  14. data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
  15. data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
  16. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
  17. data/src/com/adobe/air/logging/FileTarget.as +0 -95
  18. data/src/com/adobe/air/net/ResourceCache.as +0 -165
  19. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
  20. data/src/com/adobe/crypto/HMAC.as +0 -127
  21. data/src/com/adobe/crypto/MD5.as +0 -281
  22. data/src/com/adobe/crypto/MD5Stream.as +0 -402
  23. data/src/com/adobe/crypto/SHA1.as +0 -289
  24. data/src/com/adobe/crypto/SHA224.as +0 -257
  25. data/src/com/adobe/crypto/SHA256.as +0 -261
  26. data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
  27. data/src/com/adobe/errors/IllegalStateError.as +0 -63
  28. data/src/com/adobe/fileformats/vcard/Address.as +0 -47
  29. data/src/com/adobe/fileformats/vcard/Email.as +0 -39
  30. data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
  31. data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
  32. data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
  33. data/src/com/adobe/images/BitString.as +0 -39
  34. data/src/com/adobe/images/JPGEncoder.as +0 -648
  35. data/src/com/adobe/images/PNGEncoder.as +0 -141
  36. data/src/com/adobe/net/DynamicURLLoader.as +0 -55
  37. data/src/com/adobe/net/IURIResolver.as +0 -76
  38. data/src/com/adobe/net/MimeTypeMap.as +0 -200
  39. data/src/com/adobe/net/URI.as +0 -2466
  40. data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
  41. data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
  42. data/src/com/adobe/protocols/dict/Database.as +0 -66
  43. data/src/com/adobe/protocols/dict/Definition.as +0 -71
  44. data/src/com/adobe/protocols/dict/Dict.as +0 -360
  45. data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
  46. data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
  47. data/src/com/adobe/protocols/dict/Response.as +0 -71
  48. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
  49. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
  50. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
  51. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
  52. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
  53. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
  54. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
  55. data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
  56. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
  57. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
  58. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
  59. data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
  60. data/src/com/adobe/serialization/json/JSON.as +0 -86
  61. data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
  62. data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
  63. data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
  64. data/src/com/adobe/serialization/json/JSONToken.as +0 -104
  65. data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
  66. data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
  67. data/src/com/adobe/utils/ArrayUtil.as +0 -187
  68. data/src/com/adobe/utils/DateUtil.as +0 -701
  69. data/src/com/adobe/utils/DictionaryUtil.as +0 -87
  70. data/src/com/adobe/utils/IntUtil.as +0 -99
  71. data/src/com/adobe/utils/NumberFormatter.as +0 -74
  72. data/src/com/adobe/utils/StringUtil.as +0 -239
  73. data/src/com/adobe/utils/XMLUtil.as +0 -168
  74. data/src/com/adobe/webapis/ServiceBase.as +0 -48
  75. data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
  76. data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
  77. data/tests/src/CoreLibTestRunner-app.xml +0 -135
  78. data/tests/src/CoreLibTestRunner.as +0 -138
  79. data/tests/src/CoreLibTestRunner.mxml +0 -46
  80. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
  81. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
  82. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
  83. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
  84. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
  85. data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
  86. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
  87. data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
  88. data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
  89. data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
  90. data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
  91. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
  92. data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
  93. data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
  94. data/tests/src/com/adobe/net/URITest.as +0 -589
  95. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
  96. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
  97. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
  98. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
  99. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
  100. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
  101. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
  102. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
  103. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
  104. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
  105. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
  106. data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
  107. data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
  108. data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
  109. data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
  110. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
  111. data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
  112. data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
  113. data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
  114. data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
  115. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,54 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.images
34
- {
35
- import flexunit.framework.TestCase;
36
- import flexunit.framework.TestSuite;
37
- import com.adobe.images.JPGEncoder;
38
-
39
-
40
-
41
- public class JPGEncoderTest extends TestCase
42
- {
43
- public function JPGEncoderTest(methodName:String = null)
44
- {
45
- super(methodName);
46
- }
47
-
48
- public function testConstructor():void
49
- {
50
- var j:JPGEncoder = new JPGEncoder();
51
- }
52
-
53
- }
54
- }
@@ -1,54 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.images
34
- {
35
- import flexunit.framework.TestCase;
36
- import flexunit.framework.TestSuite;
37
- import com.adobe.images.PNGEncoder;
38
-
39
-
40
-
41
- public class PNGEncoderTest extends TestCase
42
- {
43
- public function PNGEncoderTest(methodName:String = null)
44
- {
45
- super(methodName);
46
- }
47
-
48
- public function testConstructor():void
49
- {
50
- var p:PNGEncoder = new PNGEncoder();
51
- }
52
-
53
- }
54
- }
@@ -1,589 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.net
34
- {
35
- import flexunit.framework.TestCase;
36
- import flexunit.framework.TestSuite;
37
-
38
- import com.adobe.net.URI;
39
- import com.adobe.net.IURIResolver;
40
-
41
- public class URITest extends TestCase implements IURIResolver
42
- {
43
- public function URITest( methodName:String=null )
44
- {
45
- super( methodName );
46
- }
47
-
48
- /**
49
- *
50
- */
51
- public function testParsing() : void
52
- {
53
- var mt:String = "";
54
-
55
- parseAndTest("http://test.com", "http", mt, mt, "test.com",
56
- mt, mt, mt, mt, mt);
57
-
58
- parseAndTest("http://test.com/", "http", mt, mt, "test.com",
59
- mt, "/", mt, mt, mt);
60
-
61
- parseAndTest("http://test.com:80", "http", mt, mt, "test.com",
62
- "80", mt, mt, mt, mt);
63
-
64
- parseAndTest("http://www.test.com/my/path/file.html",
65
- "http", mt, mt, "www.test.com", mt, "/my/path/file.html", mt, mt, mt);
66
-
67
- parseAndTest("http://www.test.com/?query=yes&name=bob",
68
- "http", mt, mt, "www.test.com", mt, "/", "query=yes&name=bob", mt, mt);
69
-
70
- parseAndTest("http://www.test.com/index.html#foo",
71
- "http", mt, mt, "www.test.com", mt, "/index.html", mt, "foo", mt);
72
-
73
- parseAndTest("http://www.test.com/#foo", "http",
74
- mt, mt, "www.test.com", mt, "/", mt, "foo", mt);
75
-
76
- parseAndTest("http://www.test.com/?test=1&copy=yes",
77
- "http", mt, mt, "www.test.com", mt, "/", "test=1&copy=yes", mt, mt);
78
-
79
- // Test everything
80
- parseAndTest("https://bobarino:password37$%25@test.com:9100/path/to/file.html?param1=foo&param2=bar#anchor",
81
- "https", "bobarino", "password37$%", "test.com", "9100",
82
- "/path/to/file.html", "param1=foo&param2=bar", "anchor", mt);
83
-
84
- // Test everything with escaped characters and characters that
85
- // may be considered borderline.
86
- parseAndTest("https://bobarino%3A:pass%3Aword37$@test.com:9100/pa%3Fth/to/fi:le.html?param1=:&param2=?#anchor%23",
87
- "https", "bobarino:", "pass:word37$", "test.com", "9100",
88
- "/pa?th/to/fi:le.html", "param1=:&param2=?", "anchor#", mt);
89
-
90
- // Test the common case where people embed another URI in the
91
- // query part of the base URI. This is often used when
92
- // communicating through a proxy. We don't want to break or
93
- // escape more characters than needed.
94
- parseAndTest("http://jim:%25password%25@someproxy.com:8877/proxy.php?url=http://othersite.com/path/to/file.html&proxyparam=doit#proxyanchor",
95
- "http", "jim", "%password%", "someproxy.com", "8877",
96
- "/proxy.php", "url=http://othersite.com/path/to/file.html&proxyparam=doit",
97
- "proxyanchor", mt);
98
- }
99
-
100
- public function testRelativeParsing() : void
101
- {
102
- var mt:String = "";
103
-
104
- // Yes, "www.test.com" is a relative URI. To us, it seems natural that
105
- // it should be the host name, but without a scheme, its relative.
106
- // For example, "www.tar.gz" is a UNIX tar/gzip file and is relative.
107
- // Whats the difference between "www.test.com" and "www.tar.gz"? If it
108
- // has no scheme, it is relative. Period. URI::UnknownToURI tries to
109
- // be smart, but the problem is that it could make a wrong guess in
110
- // certain situations.
111
- parseAndTest("www.test.com", mt, mt, mt, mt, mt,
112
- "www.test.com", mt, mt, mt);
113
-
114
- // Just a fragment (anchor)
115
- parseAndTest("#foo", mt, mt, mt, mt, mt, mt, mt,
116
- "foo", mt);
117
-
118
- // queries can have ';' as an alternative separator to '&'
119
- parseAndTest("?query=yes;this=that#foo",
120
- mt, mt, mt, mt, mt, mt, "query=yes;this=that", "foo", mt);
121
-
122
- parseAndTest("/images?blah:somequery",
123
- mt, mt, mt, mt, mt, "/images", "blah:somequery", mt, mt);
124
-
125
- parseAndTest("/images?blah:somequery#anchor",
126
- mt, mt, mt, mt, mt, "/images", "blah:somequery", "anchor", mt);
127
- }
128
-
129
-
130
- public function testUnknownParsing() : void
131
- {
132
- var mt:String = "";
133
-
134
- // Something missing the scheme
135
- parseUnknownAndTest(
136
- "www.somesite.com", // input
137
- "http://www.somesite.com", // expected
138
- "http", mt, mt, "www.somesite.com", mt, mt, mt ,mt ,mt);
139
-
140
- // URI missing a scheme, but has slashes
141
- parseUnknownAndTest(
142
- "//server/path/to/file.html", // input
143
- "http://server/path/to/file.html", // expected
144
- "http", mt, mt, "server", mt, "/path/to/file.html", mt, mt, mt);
145
-
146
- // Missing scheme with everything else
147
- parseUnknownAndTest(
148
- "://user:pass@server:8080/path/to/file.html?param1=value1#anchor",
149
- "http://user:pass@server:8080/path/to/file.html?param1=value1#anchor",
150
- "http", "user", "pass", "server", "8080",
151
- "/path/to/file.html", "param1=value1", "anchor", mt);
152
-
153
- // Make sure the unknown handles the case of a real and valid URI
154
- parseUnknownAndTest(
155
- "http://user:pass@www.somesite.com:200/path/to/file.html?query#foo",
156
- "http://user:pass@www.somesite.com:200/path/to/file.html?query#foo",
157
- "http", "user", "pass", "www.somesite.com", "200",
158
- "/path/to/file.html", "query", "foo", mt);
159
-
160
- // A valid non-hierarchical URI
161
- parseUnknownAndTest("mailto:bob@smith.com",
162
- "mailto:bob@smith.com",
163
- "mailto", mt, mt, mt, mt, mt, mt, mt, "bob@smith.com");
164
-
165
- // malformed URI. Some people like to type backslashes
166
- // instead of forward slashes.
167
- parseUnknownAndTest(
168
- "http:\\\\somesite.com\\path\\to\\file.html",
169
- "http://somesite.com/path/to/file.html",
170
- "http", mt, mt, "somesite.com", mt, "/path/to/file.html", mt, mt, mt);
171
-
172
- // A valid relative URI. Note that UnknownToURI will only detect
173
- // relative paths that start with ".", or "..". Otherwise, it will
174
- // guess that the path is just something missing the scheme.
175
- parseUnknownAndTest(
176
- "../../images/logo.gif",
177
- "../../images/logo.gif",
178
- mt, mt, mt, mt, mt, "../../images/logo.gif", mt, mt, mt);
179
- }
180
-
181
- public function testNonHierarchical() : void
182
- {
183
- var mt:String = "";
184
-
185
- parseAndTest("mailto:bob@smith.com",
186
- "mailto", mt, mt, mt, mt, mt, mt, mt, "bob@smith.com");
187
-
188
- parseAndTest("about:blank?foo=bar#baz",
189
- "about", mt, mt, mt, mt, mt, "foo=bar", "baz", "blank");
190
- }
191
-
192
- /**
193
- * This tests the getRelation() method of URI. Given two URI's,
194
- * determine the relation of the two relative to the object that
195
- * getRelation() is called on.
196
- */
197
- public function testEquivalence() : void
198
- {
199
- // The same
200
- parseAndCompare("http://a/b/c/d", "http://a/b/c/d", URI.EQUAL, URI.EQUAL);
201
-
202
- // Parent/child
203
- parseAndCompare("http://a/b/c/d/", "http://a/b/c/d/e/f/", URI.PARENT, URI.CHILD);
204
-
205
- // Not related. They are in different branches.
206
- parseAndCompare("http://a/b/c/g", "http://a/b/c/d/e/f/", URI.NOT_RELATED, URI.NOT_RELATED);
207
-
208
- // special case
209
- parseAndCompare("http://somesite.com/", "http://somesite.com", URI.EQUAL, URI.EQUAL);
210
-
211
- // non-hierarchical
212
- parseAndCompare("mailto:bob@smith.com", "mailto:bob@smith.com", URI.EQUAL, URI.EQUAL);
213
- parseAndCompare("mailto:bob@smith.com", "mailto:sue@company.com", URI.NOT_RELATED, URI.NOT_RELATED);
214
- parseAndCompare("mailto:bob@smith.com", "http://test.com", URI.NOT_RELATED, URI.NOT_RELATED);
215
-
216
- // different schemes
217
- parseAndCompare("http://test.com", "https://test.com", URI.NOT_RELATED, URI.NOT_RELATED);
218
-
219
- // test default port
220
- parseAndCompare("http://test.com:80", "http://test.com", URI.EQUAL, URI.EQUAL);
221
- parseAndCompare("http://test.com:81", "http://test.com", URI.NOT_RELATED, URI.NOT_RELATED);
222
-
223
- // test dynamic resolution.
224
- URI.resolver = this;
225
- parseAndCompare("http://test.com", "http://test.org", URI.EQUAL, URI.EQUAL);
226
-
227
- // GetRelation() does not take into account query and fragment
228
- // parts. This is probably an edge case that we do not handle
229
- // at this time. If we ever modify GetRelation() to handle
230
- // that case, we need to add test cases here.
231
- }
232
-
233
- public function testEscaping() : void
234
- {
235
- var uri:URI = new URI();
236
-
237
- uri.setParts("http", "test.com", "80", "/my path/with %weird/chars",
238
- "search=~&name={bob}", "five%");
239
-
240
- assertEquals("Characters not properly escaped.",
241
- "http://test.com:80/my%20path/with%20%25weird/chars?search=~&name={bob}#five%25",
242
- uri.toString());
243
-
244
- var test:String = "http://test.com/ funky/{path}";
245
-
246
- uri = new URI(test);
247
- uri.forceEscape();
248
-
249
- assertEquals("Characters not properly escaped.",
250
- "http://test.com/%20%20funky/{path}", uri.toString());
251
-
252
- // Make sure the display version does not include escaped chars.
253
- assertEquals("toDisplayString() failed.", test, uri.toDisplayString());
254
- }
255
-
256
- public function parseAndCompare(str1:String, str2:String, rel1:int, rel2:int) : void
257
- {
258
- var uri1:URI, uri2:URI;
259
- var result1:int, result2:int;
260
-
261
- uri1 = new URI(str1);
262
- uri2 = new URI(str2);
263
-
264
- result1 = uri1.getRelation(uri2);
265
- result2 = uri2.getRelation(uri1); // swapped
266
-
267
- assertTrue("Relation check failed.", result1 == rel1);
268
- assertTrue("Relation check failed.", result2 == rel2);
269
-
270
- // Make sure nothing got modified.
271
- assertEquals("getRelation() modified uri1.", str1, uri1.toString());
272
- assertEquals("getRelation() modified uri2.", str2, uri2.toString());
273
- }
274
-
275
-
276
- protected function parseUnknownAndTest(
277
- inURI:String, expectedURI:String, scheme:String,
278
- username:String, password:String, authority:String,
279
- port:String, path:String, query:String, fragment:String,
280
- nonHierarchical:String) : void
281
- {
282
- var uri:URI = new URI();
283
-
284
- uri.unknownToURI(inURI);
285
-
286
- // We expect all cases to produce a valid URI
287
- assertTrue("URI is invalid.", uri.isValid());
288
-
289
- // Make sure we get out what we expect
290
- assertEquals("URI.toString() should output what we input.", expectedURI, uri.toString());
291
-
292
- if (uri.isHierarchical())
293
- {
294
- assertEquals("URI.scheme should be the same.", scheme, uri.scheme);
295
- assertEquals("URI.username should be the same.", username, uri.username);
296
- assertEquals("URI.password should be the same.", password, uri.password);
297
- assertEquals("URI.authority should be the same.", authority, uri.authority);
298
- assertEquals("URI.port should be the same.", port, uri.port);
299
- assertEquals("URI.path should be the same.", path, uri.path);
300
- assertEquals("URI.query should be the same.", query, uri.query);
301
- assertEquals("URI.fragment should be the same.", fragment, uri.fragment);
302
- }
303
- else
304
- {
305
- assertEquals("URI.scheme should be the same.", scheme, uri.scheme);
306
- assertEquals("URI.nonHierarchical should be the same.", nonHierarchical, uri.nonHierarchical);
307
- assertEquals("URI.query should be the same.", query, uri.query);
308
- assertEquals("URI.fragment should be the same.", fragment, uri.fragment);
309
- }
310
- }
311
-
312
- /**
313
- * This function takes a URI in string form and a set
314
- * of expected results for each of the URI parts. This
315
- * function loads the 'inURI' string into a URI object
316
- * and then compares the resulting object parts to the
317
- * given expected result strings.
318
- */
319
- protected function parseAndTest(inURI:String,
320
- scheme:String, username:String, password:String,
321
- authority:String, port:String,
322
- path:String, query:String, fragment:String,
323
- nonHierarchical:String) : void
324
- {
325
- var result:Boolean = true;
326
-
327
- // Construct our test URI
328
- var uri:URI = new URI(inURI);
329
-
330
- // Make sure we get out what we put in.
331
- assertEquals("URI.toString() should output what we input.", inURI, uri.toString());
332
-
333
- if (uri.isHierarchical())
334
- {
335
- assertEquals("URI.scheme should be the same.", scheme, uri.scheme);
336
- assertEquals("URI.username should be the same.", username, uri.username);
337
- assertEquals("URI.password should be the same.", password, uri.password);
338
- assertEquals("URI.authority should be the same.", authority, uri.authority);
339
- assertEquals("URI.port should be the same.", port, uri.port);
340
- assertEquals("URI.path should be the same.", path, uri.path);
341
- assertEquals("URI.query should be the same.", query, uri.query);
342
- assertEquals("URI.fragment should be the same.", fragment, uri.fragment);
343
- }
344
- else
345
- {
346
- assertEquals("URI.scheme should be the same.", scheme, uri.scheme);
347
- assertEquals("URI.nonHierarchical should be the same.", nonHierarchical, uri.nonHierarchical);
348
- assertEquals("URI.query should be the same.", query, uri.query);
349
- assertEquals("URI.fragment should be the same.", fragment, uri.fragment);
350
- }
351
-
352
- // Now perform the test the other way. Set all the members
353
- // and compare the toString() to the given URI.
354
- if (nonHierarchical.length > 0)
355
- {
356
- uri = new URI();
357
-
358
- uri.scheme = scheme;
359
- uri.nonHierarchical = nonHierarchical;
360
- uri.query = query;
361
- uri.fragment = fragment;
362
-
363
- assertEquals("URI.toString() should be the same.", uri.toString(), inURI);
364
- }
365
- else
366
- {
367
- uri = new URI();
368
-
369
- uri.scheme = scheme;
370
- uri.username = username;
371
- uri.password = password;
372
- uri.authority = authority;
373
- uri.port = port;
374
- uri.path = path;
375
- uri.query = query;
376
- uri.fragment = fragment;
377
-
378
- assertEquals("URI.toString() should be the same.", inURI, uri.toString());
379
- }
380
- }
381
-
382
- /**
383
- * This test case runs through a large number of cases that exercises
384
- * the chdir(), makeAbsolute(), and makeRelative() functions.
385
- */
386
- public function testAbsRelChDir() : void
387
- {
388
- // ***
389
- // These tests are taken directly from the URI RFC.
390
- // ***
391
-
392
- // Note that the ';' is part of the file name. It's not
393
- // some special character.
394
- var base:String = "http://a/b/c/d;p?q";
395
-
396
- // A full URI completely replaces the old one. The RFC used "g:h" for
397
- // their example, but we use "gj:hk" because we assume that a single
398
- // character scheme is most likely a "C:\" style path. The test is
399
- // the same.
400
- doTestChDir(base, "gj:hk", "gj:hk", true);
401
-
402
- doTestChDir(base, "g", "http://a/b/c/g");
403
- doTestChDir(base, "./g", "http://a/b/c/g");
404
- doTestChDir(base, "g/", "http://a/b/c/g/");
405
- doTestChDir(base, "/g", "http://a/g");
406
-
407
- // The "//" is the delimiter for an authority.
408
- // This kind of "path" replaces everything after
409
- // the scheme.
410
- doTestChDir(base, "//g", "http://g", true);
411
-
412
- doTestChDir(base, "?y", "http://a/b/c/?y");
413
- doTestChDir(base, "g?y", "http://a/b/c/g?y");
414
- doTestChDir(base, "#s", "http://a/b/c/d;p?q#s");
415
- doTestChDir(base, "g#s", "http://a/b/c/g#s");
416
- doTestChDir(base, "g?y#s", "http://a/b/c/g?y#s");
417
- doTestChDir(base, ";x", "http://a/b/c/;x");
418
- doTestChDir(base, "g;x", "http://a/b/c/g;x");
419
- doTestChDir(base, "g;x?y#s", "http://a/b/c/g;x?y#s");
420
- doTestChDir(base, ".", "http://a/b/c/");
421
- doTestChDir(base, "./", "http://a/b/c/");
422
- doTestChDir(base, "..", "http://a/b/");
423
- doTestChDir(base, "../", "http://a/b/");
424
- doTestChDir(base, "../g", "http://a/b/g");
425
- doTestChDir(base, "../..", "http://a/");
426
- doTestChDir(base, "../../", "http://a/");
427
- doTestChDir(base, "../../g", "http://a/g");
428
-
429
- // *** Abnormal cases ***
430
- // These are cases where the input goes beyond the scope of the URI.
431
- // We need to handle these gracefully if possible.
432
- doTestChDir(base, "../../../g", "http://a/g");
433
- doTestChDir(base, "../../../../g", "http://a/g");
434
-
435
- // These are absolute. Notice that the "." and ".." are not
436
- // collapsed here. We won't do Abs/Rel tests on them (the true)
437
- // because they just too abnormal. Just make sure ChDir works.
438
- doTestChDir(base, "/./g", "http://a/./g", true);
439
- doTestChDir(base, "/../g", "http://a/../g", true);
440
-
441
- doTestChDir(base, "g.", "http://a/b/c/g.");
442
- doTestChDir(base, ".g", "http://a/b/c/.g");
443
- doTestChDir(base, "g..", "http://a/b/c/g..");
444
- doTestChDir(base, "..g", "http://a/b/c/..g");
445
- doTestChDir(base, "./../g", "http://a/b/g");
446
- doTestChDir(base, "./g/.", "http://a/b/c/g/");
447
- doTestChDir(base, "g/./h", "http://a/b/c/g/h");
448
- doTestChDir(base, "g/../h", "http://a/b/c/h");
449
- doTestChDir(base, "g;x=1/./y", "http://a/b/c/g;x=1/y");
450
- doTestChDir(base, "g;x=1/../y", "http://a/b/c/y");
451
-
452
- // All client applications remove the query component from the base URI
453
- // before resolving relative URI. However, some applications fail to
454
- // separate the reference's query and/or fragment components from a
455
- // relative path before merging it with the base path. This error is
456
- // rarely noticed, since typical usage of a fragment never includes the
457
- // hierarchy ("/") character, and the query component is not normally
458
- // used within relative references.
459
- doTestChDir(base, "g?y/./x", "http://a/b/c/g?y/./x");
460
- doTestChDir(base, "g?y/../x","http://a/b/c/g?y/../x");
461
- doTestChDir(base, "g#s/./x", "http://a/b/c/g#s/./x");
462
- doTestChDir(base, "g#s/../x","http://a/b/c/g#s/../x");
463
-
464
- // Custom checks dealing with relative URI's as the base.
465
- base = "../../a/b/c";
466
-
467
- doTestChDir(base, "d", "../../a/b/d", true);
468
- doTestChDir(base, "../d", "../../a/d", true);
469
- doTestChDir(base, "../../d", "../../d", true);
470
- doTestChDir(base, "../../../d", "../../../d", true);
471
-
472
- // One last crazy relative path
473
- base = "../../../a";
474
- doTestChDir(base, "../../../../d", "../../../../../../../d", true);
475
-
476
-
477
- // Lastly, a specific check for known edge case
478
- base = "http://a/b/c/";
479
- var uri:URI = new URI(base);
480
- var baseURI:URI = new URI(base);
481
-
482
- // Making a URI relative to itself
483
- uri.makeRelativeURI(baseURI);
484
- assertEquals("makeRelativeURI() failed for identity case.", "./", uri.toString());
485
- }
486
-
487
-
488
- /**
489
- * The main guts of testAbsRelChDir(). This takes an initial
490
- * URI, a chdir path, and an expected result URI. It constructs
491
- * a URI object using the initial URI string, then chdirs to
492
- * the directory specified by 'chPath'. The expected result is
493
- * in 'expectedURI'. This also performs some tests using
494
- * makeAbsoluteURI() and makeRelativeURI() because we have all
495
- * the necessary data to exercise all of these.
496
- *
497
- * @param inURI the initial URI
498
- * @param chPath the path to "cd" to.
499
- * @param expectedURI the expected result of executing the "cd" on inURI.
500
- * @param skipAbsRelTests if true, this will skip the makeAbsolute
501
- * and makeRelative tests. The only time you would want to pass
502
- * true is when inURI is relative.
503
- */
504
- private function doTestChDir(inURI:String, chPath:String,
505
- expectedURI:String, skipAbsRelTests:Boolean = false) : void
506
- {
507
- var uri:URI = new URI(inURI);
508
-
509
- assertEquals("chdir() sanity check", inURI, uri.toString());
510
-
511
- uri.chdir(chPath);
512
-
513
- assertEquals("chdir() failed.", expectedURI, uri.toString());
514
-
515
- // We have enough info to do absolute and relative operations, so
516
- // lets do those too, but only if it makes sense to do them.
517
- // This function may be called with all relative paths (testing
518
- // chdir for cases using only relative paths). We don't want to
519
- // do makeAbsoluteURI() and makeRelativeURI() tests in that case.
520
- if (skipAbsRelTests)
521
- {
522
- // Caller knows the input is not appropriate for makeRelative and
523
- // makeAbsolute. Just stop here.
524
- return;
525
- }
526
-
527
- /////////////////////////////////////////////////////////////////
528
- // Test makeAbsoluteURI
529
- var abs:URI = new URI(inURI);
530
- var rel:URI = new URI(chPath);
531
-
532
- // Make sure we get out what we put in
533
- assertEquals("Absolute URI failed to parse.", inURI, abs.toString());
534
- assertEquals("chPath failed to parse.", chPath, rel.toString());
535
-
536
- rel.makeAbsoluteURI(abs);
537
- assertEquals("makeAbsoluteURI() failed.", expectedURI, rel.toString());
538
-
539
- // Make sure the passed URI didn't get modified.
540
- assertEquals("ERROR! makeAbsoluteURI() modified the passed URI.", inURI, abs.toString());
541
-
542
-
543
- /////////////////////////////////////////////////////////////////
544
- // Test makeRelativeURI
545
- var toRel:URI = new URI(expectedURI);
546
- var base:URI = new URI(inURI);
547
- var path:URI = new URI(chPath);
548
-
549
- // Make sure we get out what we put in
550
- assertEquals("expectedURI failed to parse.", expectedURI, toRel.toString());
551
-
552
- toRel.makeRelativeURI(base);
553
-
554
- // verification that makeRelativeURI() did what it was supposed to
555
- // do is handled below.
556
-
557
- // Make sure the passed URI didn't get modified
558
- assertEquals("ERROR! makeRelativeURI modified the passed URI.", inURI, base.toString());
559
-
560
- /////////////////////////////////////////////////////////////////
561
- // We should be back to the relative path we were given.
562
- // To test this, we ChDir on the inURI with the relative
563
- // path we generated and the one we were given. If the
564
- // result is the same, we are good. The reason we can't
565
- // directly compare the two is because often we are given
566
- // "./file" as the chPath, but we will generate "file"
567
- var test1:URI = new URI(inURI);
568
- var test2:URI = new URI(inURI);
569
-
570
- test1.chdir(toRel.toString());
571
- test2.chdir(chPath);
572
-
573
- assertTrue("Relative path verification failed.", test1.getRelation(test2) == URI.EQUAL);
574
- }
575
-
576
- // Interface for IURIResolver
577
- public function resolve(uri:URI) : URI
578
- {
579
- if (uri == null)
580
- return null;
581
-
582
- if (uri.authority == "test.org")
583
- uri.authority = "test.com";
584
-
585
- return uri;
586
- }
587
-
588
- } // end class
589
- } // end package