as3corelib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +28 -0
  3. data/README.textile +79 -0
  4. data/Rakefile +3 -0
  5. data/as3corelib.gemspec +23 -0
  6. data/build/build.properties +48 -0
  7. data/build/build.xml +104 -0
  8. data/examples/JSONExample/JSONExample.mxml +73 -0
  9. data/lib/as3corelib.rb +15 -0
  10. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
  11. data/src/com/adobe/air/filesystem/FileMonitor.as +245 -0
  12. data/src/com/adobe/air/filesystem/FileUtil.as +63 -0
  13. data/src/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
  14. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
  15. data/src/com/adobe/air/logging/FileTarget.as +95 -0
  16. data/src/com/adobe/air/net/ResourceCache.as +165 -0
  17. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
  18. data/src/com/adobe/crypto/HMAC.as +127 -0
  19. data/src/com/adobe/crypto/MD5.as +281 -0
  20. data/src/com/adobe/crypto/MD5Stream.as +402 -0
  21. data/src/com/adobe/crypto/SHA1.as +289 -0
  22. data/src/com/adobe/crypto/SHA224.as +257 -0
  23. data/src/com/adobe/crypto/SHA256.as +261 -0
  24. data/src/com/adobe/crypto/WSSEUsernameToken.as +114 -0
  25. data/src/com/adobe/errors/IllegalStateError.as +63 -0
  26. data/src/com/adobe/fileformats/vcard/Address.as +47 -0
  27. data/src/com/adobe/fileformats/vcard/Email.as +39 -0
  28. data/src/com/adobe/fileformats/vcard/Phone.as +39 -0
  29. data/src/com/adobe/fileformats/vcard/VCard.as +54 -0
  30. data/src/com/adobe/fileformats/vcard/VCardParser.as +246 -0
  31. data/src/com/adobe/images/BitString.as +39 -0
  32. data/src/com/adobe/images/JPGEncoder.as +648 -0
  33. data/src/com/adobe/images/PNGEncoder.as +141 -0
  34. data/src/com/adobe/net/DynamicURLLoader.as +55 -0
  35. data/src/com/adobe/net/IURIResolver.as +76 -0
  36. data/src/com/adobe/net/MimeTypeMap.as +200 -0
  37. data/src/com/adobe/net/URI.as +2466 -0
  38. data/src/com/adobe/net/URIEncodingBitmap.as +139 -0
  39. data/src/com/adobe/net/proxies/RFC2817Socket.as +198 -0
  40. data/src/com/adobe/protocols/dict/Database.as +66 -0
  41. data/src/com/adobe/protocols/dict/Definition.as +71 -0
  42. data/src/com/adobe/protocols/dict/Dict.as +360 -0
  43. data/src/com/adobe/protocols/dict/DictionaryServer.as +60 -0
  44. data/src/com/adobe/protocols/dict/MatchStrategy.as +66 -0
  45. data/src/com/adobe/protocols/dict/Response.as +71 -0
  46. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +53 -0
  47. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +67 -0
  48. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +70 -0
  49. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +69 -0
  50. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +69 -0
  51. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +55 -0
  52. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +80 -0
  53. data/src/com/adobe/protocols/dict/events/MatchEvent.as +67 -0
  54. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +70 -0
  55. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +54 -0
  56. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +68 -0
  57. data/src/com/adobe/protocols/dict/util/SocketHelper.as +81 -0
  58. data/src/com/adobe/serialization/json/JSON.as +86 -0
  59. data/src/com/adobe/serialization/json/JSONDecoder.as +327 -0
  60. data/src/com/adobe/serialization/json/JSONEncoder.as +312 -0
  61. data/src/com/adobe/serialization/json/JSONParseError.as +87 -0
  62. data/src/com/adobe/serialization/json/JSONToken.as +104 -0
  63. data/src/com/adobe/serialization/json/JSONTokenType.as +69 -0
  64. data/src/com/adobe/serialization/json/JSONTokenizer.as +702 -0
  65. data/src/com/adobe/utils/ArrayUtil.as +187 -0
  66. data/src/com/adobe/utils/DateUtil.as +701 -0
  67. data/src/com/adobe/utils/DictionaryUtil.as +87 -0
  68. data/src/com/adobe/utils/IntUtil.as +99 -0
  69. data/src/com/adobe/utils/NumberFormatter.as +74 -0
  70. data/src/com/adobe/utils/StringUtil.as +239 -0
  71. data/src/com/adobe/utils/XMLUtil.as +168 -0
  72. data/src/com/adobe/webapis/ServiceBase.as +48 -0
  73. data/src/com/adobe/webapis/URLLoaderBase.as +108 -0
  74. data/src/com/adobe/webapis/events/ServiceEvent.as +82 -0
  75. data/tests/src/CoreLibTestRunner-app.xml +135 -0
  76. data/tests/src/CoreLibTestRunner.as +138 -0
  77. data/tests/src/CoreLibTestRunner.mxml +46 -0
  78. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +176 -0
  79. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +63 -0
  80. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +57 -0
  81. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +59 -0
  82. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +72 -0
  83. data/tests/src/com/adobe/crypto/HMACMD5Test.as +134 -0
  84. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +138 -0
  85. data/tests/src/com/adobe/crypto/MD5Test.as +82 -0
  86. data/tests/src/com/adobe/crypto/SHA1Test.as +151 -0
  87. data/tests/src/com/adobe/crypto/SHA224Test.as +104 -0
  88. data/tests/src/com/adobe/crypto/SHA256Test.as +116 -0
  89. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +87 -0
  90. data/tests/src/com/adobe/images/JPGEncoderTest.as +54 -0
  91. data/tests/src/com/adobe/images/PNGEncoderTest.as +54 -0
  92. data/tests/src/com/adobe/net/URITest.as +589 -0
  93. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +59 -0
  94. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +62 -0
  95. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +61 -0
  96. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +61 -0
  97. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +61 -0
  98. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +59 -0
  99. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +63 -0
  100. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +61 -0
  101. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +61 -0
  102. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +58 -0
  103. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +60 -0
  104. data/tests/src/com/adobe/serialization/json/JSONTest.as +522 -0
  105. data/tests/src/com/adobe/serialization/json/SimpleClass.as +85 -0
  106. data/tests/src/com/adobe/utils/ArrayUtilTest.as +173 -0
  107. data/tests/src/com/adobe/utils/DateUtilTest.as +436 -0
  108. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +93 -0
  109. data/tests/src/com/adobe/utils/IntUtilTest.as +73 -0
  110. data/tests/src/com/adobe/utils/NumberFormatterTest.as +70 -0
  111. data/tests/src/com/adobe/utils/StringUtilTest.as +304 -0
  112. data/tests/src/com/adobe/utils/XMLUtilTest.as +101 -0
  113. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +66 -0
  114. metadata +196 -0
@@ -0,0 +1,173 @@
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.utils
34
+ {
35
+ import flexunit.framework.TestCase;
36
+ import flexunit.framework.TestSuite;
37
+
38
+ import com.adobe.utils.ArrayUtil;
39
+
40
+ public class ArrayUtilTest extends TestCase
41
+ {
42
+ private var o:Object;
43
+ private var arr:Array;
44
+
45
+ public function ArrayUtilTest(methodName:String = null)
46
+ {
47
+ super(methodName);
48
+
49
+ o = {foo:"bar"};
50
+
51
+ arr = new Array();
52
+ arr.push("AAA");//0
53
+ arr.push(5);//1
54
+ arr.push("5");//2
55
+ arr.push({foo:"bar"});//3
56
+ arr.push(o);//4
57
+ arr.push(new String("AAA"));//5
58
+ arr.push("AAA");//6
59
+ arr.push("10");//7
60
+ }
61
+
62
+ public function testArraysAreEqual():void
63
+ {
64
+ var arr2:Array = ArrayUtil.copyArray(arr);
65
+
66
+ assertTrue("ArrayUtil.arraysAreEqual(arr, arr2)",
67
+ ArrayUtil.arraysAreEqual(arr, arr2));
68
+
69
+ assertTrue("!ArrayUtil.arraysAreEqual(arr, new Array())",
70
+ !ArrayUtil.arraysAreEqual(arr, new Array()));
71
+
72
+ var tArr:Array = new Array(arr.length);
73
+
74
+ assertTrue("!ArrayUtil.arraysAreEqual(arr, tArr)",
75
+ !ArrayUtil.arraysAreEqual(arr, tArr));
76
+ }
77
+
78
+ public function testCreateUniqueCopy():void
79
+ {
80
+ var arr2:Array = ArrayUtil.copyArray(arr);
81
+
82
+ var arr3:Array = ArrayUtil.createUniqueCopy(arr2);
83
+
84
+ assertTrue("arr3.length == 6", arr3.length == 6);
85
+ assertTrue("arr3.length != arr2.length", arr3.length != arr2.length);
86
+
87
+ var indexArr:Array = [0,1,2,3,4,7];
88
+
89
+ var len:uint = arr3.length;
90
+
91
+ for(var i:Number = 0; i < len; i++)
92
+ {
93
+ assertTrue("arr3["+i+"] === arr[indexArr["+i+"]]", arr3[i] === arr[indexArr[i]]);
94
+ }
95
+ }
96
+
97
+ public function testCopyArray():void
98
+ {
99
+ var len:uint = arr.length;
100
+ var arr2:Array = ArrayUtil.copyArray(arr);
101
+
102
+
103
+ var len2:uint = arr2.length;
104
+
105
+ assertTrue("len2 == arr.length", len2 == arr.length);
106
+
107
+ for(var i:uint = 0; i < len2; i++)
108
+ {
109
+ assertTrue("arr["+i+"] == arr2["+i+"]", arr[i] == arr2[i]);
110
+ }
111
+
112
+ ArrayUtil.removeValueFromArray(arr2, "AAA");
113
+
114
+ assertTrue("arr.length == len", arr.length == len);
115
+ }
116
+
117
+ public function testRemoveValueFromArray():void
118
+ {
119
+ var arr2:Array = ArrayUtil.copyArray(arr);
120
+
121
+ var len2:Number = arr2.length;
122
+
123
+ ArrayUtil.removeValueFromArray(arr2, o);
124
+
125
+ assertNotNull("arr2 is null", arr2);
126
+ assertTrue("(len2 - 1) == arr2.length", (len2 - 1) == arr2.length);
127
+ assertTrue("arr2[4] != o", arr2[4] != o);
128
+
129
+ assertTrue("!ArrayUtil.arrayContainsValue(arr3, o)",
130
+ !ArrayUtil.arrayContainsValue(arr2, o));
131
+
132
+ var arr3:Array = ArrayUtil.copyArray(arr);
133
+ var len3:Number = arr3.length;
134
+
135
+ ArrayUtil.removeValueFromArray(arr3, "AAA");
136
+
137
+ assertTrue("arr3.length == (len3 - 3)", arr3.length == (len3 - 3));
138
+ assertTrue("!ArrayUtil.arrayContainsValue(arr3, \"AAA\")",
139
+ !ArrayUtil.arrayContainsValue(arr3, "AAA"));
140
+
141
+ var arr4:Array = ArrayUtil.copyArray(arr);
142
+ var len4:Number = arr4.length;
143
+
144
+ ArrayUtil.removeValueFromArray(arr3, "XHJSDHKJHKJSD");
145
+
146
+ assertTrue("len4 == arr4.length", len4 == arr4.length);
147
+
148
+ }
149
+
150
+ public function testArrayContainsValue():void
151
+ {
152
+
153
+ assertTrue("ArrayUtil.arrayContainsValue(arr, \"AAA\")",
154
+ ArrayUtil.arrayContainsValue(arr, "AAA"));
155
+
156
+ assertTrue("ArrayUtil.arrayContainsValue(arr, 5)",
157
+ ArrayUtil.arrayContainsValue(arr, 5));
158
+
159
+ assertTrue("!ArrayUtil.arrayContainsValue(arr, new Object())",
160
+ !ArrayUtil.arrayContainsValue(arr, new Object()));
161
+
162
+ assertTrue("ArrayUtil.arrayContainsValue(arr, o)",
163
+ ArrayUtil.arrayContainsValue(arr, o));
164
+
165
+ assertTrue("!ArrayUtil.arrayContainsValue(arr, {foo:\"bar\"})",
166
+ !ArrayUtil.arrayContainsValue(arr, {foo:"bar"}));
167
+
168
+ assertTrue("!ArrayUtil.arrayContainsValue(arr, 10)",
169
+ !ArrayUtil.arrayContainsValue(arr, 10));
170
+ }
171
+
172
+ }
173
+ }
@@ -0,0 +1,436 @@
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.utils
34
+ {
35
+ import flexunit.framework.TestCase;
36
+
37
+ import mx.formatters.DateBase;
38
+
39
+ public class DateUtilTest extends TestCase
40
+ {
41
+
42
+ public function DateUtilTest(methodName:String = null)
43
+ {
44
+ super(methodName);
45
+
46
+ }
47
+
48
+ public function testToW3CDTF():void
49
+ {
50
+ var s:String = "1994-11-05T08:15:30-08:00";
51
+ var d:Date = DateUtil.parseW3CDTF(s);
52
+ assertTrue(s + " == 1994-11-05T16:15:30-00:00",
53
+ DateUtil.toW3CDTF(d) == "1994-11-05T16:15:30-00:00");
54
+ }
55
+
56
+ public function testToW3CDTFWithMilliseconds():void
57
+ {
58
+ var s1:String = "1994-11-05T08:15:30.345-00:00";
59
+
60
+ var d:Date = DateUtil.parseW3CDTF(s1);
61
+ var s2:String = DateUtil.toW3CDTF(d,false);
62
+ var s3:String = DateUtil.toW3CDTF(d,true);
63
+
64
+ assertTrue(s1 + " != " + s2, s1 != s2);
65
+ assertTrue(s1 + " == " + s3, s1 == s3);
66
+ }
67
+
68
+ public function testParseW3CDTF():void
69
+ {
70
+ //1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30
71
+ // am, US Eastern Standard Time.
72
+
73
+ var s:String = "1994-11-05T08:15:30.123456-08:00";
74
+
75
+ var d:Date = DateUtil.parseW3CDTF(s);
76
+
77
+ assertNotNull("d is null", d);
78
+ assertTrue("d.date == 5",d.date == 5);
79
+ assertTrue("d.month == 10", d.month == 10); // 10 is November
80
+ assertTrue("d.fullYear == 1994", d.fullYear == 1994);
81
+ // Fixes issue #12 - use UTC so time zone doesn't throw off hours
82
+ assertTrue("d.hoursUTC == 16", d.hoursUTC == 16 );
83
+ assertTrue("d.minutes == 15", d.minutes == 15);
84
+ assertTrue("d.seconds == 30", d.seconds == 30);
85
+ // Can't reliably test time zone offset since the date string's original
86
+ // time zone is converted to the local time zone of the computer running
87
+ // the unit tests.
88
+ //assertTrue("d.timezoneOffset/60 == 8", d.timezoneOffset/60 == 8);
89
+ }
90
+
91
+ public function testParseW3CDTFWithMilliseconds():void
92
+ {
93
+ //1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30
94
+ // am, US Eastern Standard Time.
95
+
96
+ var s:String = "1994-11-05T08:15:30.345-08:00";
97
+
98
+ var d:Date = DateUtil.parseW3CDTF(s);
99
+
100
+ assertNotNull("d is null", d);
101
+ assertTrue("d.date == 5",d.date == 5);
102
+ assertTrue("d.month == 10", d.month == 10); // 10 is November
103
+ assertTrue("d.fullYear == 1994", d.fullYear == 1994);
104
+ // Fixes issue #12 - use UTC so time zone doesn't throw off hours
105
+ assertTrue("d.hoursUTC == 16", d.hoursUTC == 16 );
106
+ assertTrue("d.minutes == 15", d.minutes == 15);
107
+ assertTrue("d.seconds == 30", d.seconds == 30);
108
+ assertTrue("d.milliseconds == 345", d.milliseconds == 345);
109
+ // Can't reliably test time zone offset since the date string's original
110
+ // time zone is converted to the local time zone of the computer running
111
+ // the unit tests.
112
+ //assertTrue("d.timezoneOffset/60 == 8", d.timezoneOffset/60 == 8);
113
+
114
+ // Now test without padding (date, month, offset)
115
+ var s2:String = "1994-9-5T8:15:30.345-8:00";
116
+
117
+ var d2:Date = DateUtil.parseW3CDTF(s2);
118
+
119
+ assertNotNull("d2 is null", d2);
120
+ assertTrue("d2.date == 5",d2.date == 5);
121
+ assertTrue("d2.month == 10", d2.month == 8); // 8 is september
122
+ assertTrue("d2.fullYear == 1994", d2.fullYear == 1994);
123
+ // Fixes issue #12 - use UTC so time zone doesn't throw off hours
124
+ assertTrue("d2.hoursUTC == 16", d2.hoursUTC == 16 );
125
+ assertTrue("d2.minutes == 15", d2.minutes == 15);
126
+ assertTrue("d2.seconds == 30", d2.seconds == 30);
127
+ assertTrue("d2.milliseconds == 345", d2.milliseconds == 345);
128
+
129
+ }
130
+
131
+ public function testW3CDTF():void
132
+ {
133
+ var d1:Date = new Date();
134
+
135
+ d1.setMilliseconds(0);
136
+
137
+ var s:String = DateUtil.toW3CDTF(d1);
138
+
139
+ var d2:Date = DateUtil.parseW3CDTF(s);
140
+
141
+ assertTrue("DateUtil.compareDates(d1, d2) == 0",
142
+ DateUtil.compareDates(d1, d2) == 0);
143
+ }
144
+
145
+ public function testRFC822():void
146
+ {
147
+ var d1:Date = new Date();
148
+
149
+ d1.setMilliseconds(0);
150
+
151
+ var s:String = DateUtil.toRFC822(d1);
152
+
153
+ var d2:Date = DateUtil.parseRFC822(s);
154
+
155
+ assertTrue("DateUtil.compareDates(d1, d2) == 0",
156
+ DateUtil.compareDates(d1, d2) == 0);
157
+ }
158
+
159
+ public function testToRFC822():void
160
+ {
161
+ // "Mon, 05 Dec 2005 14:55:43 -0800";
162
+
163
+ var d:Date = new Date(Date.UTC(2005,0,1,1,1,1,0));
164
+
165
+ assertTrue("DateUtil.toRFC822(d) == \"Sat, 01 Jan 2005 01:01:01 GMT\"",
166
+ DateUtil.toRFC822(d) == "Sat, 01 Jan 2005 01:01:01 GMT");
167
+ }
168
+
169
+ public function testGetAMPM():void
170
+ {
171
+ var d:Date = new Date(2005,1,1);
172
+
173
+ d.hours = 7;
174
+ assertTrue("DateUtil.getAMPM(d) == \"AM\"",
175
+ DateUtil.getAMPM(d) == "AM");
176
+
177
+ d.hours = 23;
178
+ assertTrue("DateUtil.getAMPM(d) == \"PM\"",
179
+ DateUtil.getAMPM(d) == "PM");
180
+
181
+ d.hours = 12;
182
+ assertTrue("DateUtil.getAMPM(d) == \"PM\"",
183
+ DateUtil.getAMPM(d) == "PM");
184
+
185
+ d.hours = 11;
186
+ assertTrue("DateUtil.getAMPM(d) == \"AM\"",
187
+ DateUtil.getAMPM(d) == "AM");
188
+
189
+ d.hours = 0;
190
+ assertTrue("DateUtil.getAMPM(d) == \"AM\"",
191
+ DateUtil.getAMPM(d) == "AM");
192
+
193
+ d.hours = 13;
194
+ assertTrue("DateUtil.getAMPM(d) == \"PM\"",
195
+ DateUtil.getAMPM(d) == "PM");
196
+ }
197
+
198
+ public function testGetShortHours():void
199
+ {
200
+ var d:Date = new Date(2005,1,1);
201
+
202
+ d.hours = 7;
203
+ assertTrue("DateUtil.getShortHour(d) == 7",
204
+ DateUtil.getShortHour(d) == 7);
205
+
206
+ d.hours = 23;
207
+ assertTrue("DateUtil.getShortHour(d) == 11",
208
+ DateUtil.getShortHour(d) == 11);
209
+
210
+ d.hours = 12;
211
+ assertTrue("DateUtil.getShortHour(d) == 12",
212
+ DateUtil.getShortHour(d) == 12);
213
+
214
+ d.hours = 0;
215
+ assertTrue("DateUtil.getShortHour(d) == 12",
216
+ DateUtil.getShortHour(d) == 12);
217
+
218
+ d.hours = 13;
219
+ assertTrue("DateUtil.getShortHour(d) == 1",
220
+ DateUtil.getShortHour(d) == 1);
221
+ }
222
+
223
+ public function testParseRFC822():void
224
+ {
225
+ var s:String = "Mon, 05 Dec 2005 14:55:43 -0800";
226
+
227
+ var d:Date = DateUtil.parseRFC822(s);
228
+
229
+ assertNotNull("d is null", d);
230
+ assertTrue("d.date == 5",d.date == 5);
231
+ assertTrue("d.month == 11", d.month == 11);
232
+ assertTrue("d.fullYear == 2005", d.fullYear == 2005);
233
+ // Fixes issue #12 - use UTC so time zone doesn't throw off hours
234
+ assertTrue("d.hoursUTC == 22", d.hoursUTC == 22 );
235
+ assertTrue("d.minutes == 55", d.minutes == 55);
236
+ assertTrue("d.seconds == 43", d.seconds == 43);
237
+
238
+ var exception:Boolean = false;
239
+ try
240
+ {
241
+ DateUtil.parseRFC822("foo");
242
+ }
243
+ catch(e:Error)
244
+ {
245
+ exception = true;
246
+ }
247
+
248
+ if(!exception)
249
+ {
250
+ assertTrue("DateUtil.parseRFC822(\"foo\") did not throw an exception.", false);
251
+ }
252
+
253
+ // Now try a string without padding (date and hour)
254
+ var s2:String = "Mon, 5 Dec 2005 9:55:43 -0800";
255
+
256
+ var d2:Date = DateUtil.parseRFC822(s2);
257
+
258
+ assertNotNull("d is null", d2);
259
+ assertTrue("d2.date == 5",d2.date == 5);
260
+ assertTrue("d2.month == 11", d2.month == 11);
261
+ assertTrue("d2.fullYear == 2005", d2.fullYear == 2005);
262
+ // Fixes issue #12 - use UTC so time zone doesn't throw off hours
263
+ assertTrue("d2.hoursUTC == 22", d2.hoursUTC == 17);
264
+ assertTrue("d2.minutes == 55", d2.minutes == 55);
265
+ assertTrue("d2.seconds == 43", d2.seconds == 43);
266
+
267
+ //var s3:String = "Wed, 2 Jan 2007 04:00:00 PST";
268
+ //var d3:Date = DateUtil.parseRFC822(s3);
269
+ //trace(d3);
270
+
271
+ }
272
+
273
+
274
+ public function testCompareDates():void
275
+ {
276
+ var d1:Date = new Date(2005,0,1,1,1,1,1);
277
+ var d2:Date = new Date(2006,0,1,1,1,1,1);
278
+ var d4:Date = new Date(2005,0,1,1,1,1,1);
279
+
280
+ assertTrue("DateUtil.compareDates(d1, d2) == 1",
281
+ DateUtil.compareDates(d1, d2) == 1);
282
+
283
+ assertTrue("DateUtil.compareDates(d2, d1) == -1",
284
+ DateUtil.compareDates(d2, d1) == -1);
285
+
286
+ assertTrue("DateUtil.compareDates(d1, d1) == 0",
287
+ DateUtil.compareDates(d1, d1) == 0);
288
+
289
+ assertTrue("DateUtil.compareDates(d1, d4) == 0",
290
+ DateUtil.compareDates(d1, d4) == 0);
291
+ }
292
+
293
+ public function testGetShortYear():void
294
+ {
295
+ var d:Date = new Date(2005);
296
+
297
+ d.fullYear = 2005;
298
+ assertTrue("DateUtil.getShortYear(d) == \"05\"",
299
+ DateUtil.getShortYear(d) == "05");
300
+
301
+ d.fullYear = 2000;
302
+ assertTrue("DateUtil.getShortYear(d) == \"00\"",
303
+ DateUtil.getShortYear(d) == "00");
304
+
305
+ d.fullYear = 1900;
306
+ assertTrue("DateUtil.getShortYear(d) == \"00\"",
307
+ DateUtil.getShortYear(d) == "00");
308
+
309
+ d.fullYear = 21501;
310
+ assertTrue("DateUtil.getShortYear(d) == \"01\"",
311
+ DateUtil.getShortYear(d) == "01");
312
+
313
+ d.fullYear = 10;
314
+ assertTrue("DateUtil.getShortYear(d) == \"10\"",
315
+ DateUtil.getShortYear(d) == "10");
316
+
317
+ d.fullYear = 7;
318
+ assertTrue("DateUtil.getShortYear(d) == \"7\"",
319
+ DateUtil.getShortYear(d) == "7");
320
+ }
321
+
322
+ public function testGetFullDayIndex():void
323
+ {
324
+
325
+ var len:int = DateBase.dayNamesLong.length;
326
+
327
+ for(var i:int = 0; i < len; i++)
328
+ {
329
+ assertTrue("DateUtil.getFullDayIndex(DateBase.dayNamesLong["+i+"]) == i",
330
+ DateUtil.getFullDayIndex(DateBase.dayNamesLong[i]) == i);
331
+ }
332
+ }
333
+
334
+ public function testGetFullMonthIndex():void
335
+ {
336
+ //var len:int = FULL_MONTH.length;
337
+ var len:int = DateBase.monthNamesLong.length;
338
+
339
+ for(var i:int = 0; i < len; i++)
340
+ {
341
+ assertTrue("DateUtil.getFullMonthIndex(DateBase.monthNamesLong["+i+"]) == i",
342
+ DateUtil.getFullMonthIndex(DateBase.monthNamesLong[i]) == i);
343
+ }
344
+ }
345
+
346
+ public function testGetFullDayName():void
347
+ {
348
+ var d:Date;
349
+
350
+ //var len:uint = FULL_DAY.length;
351
+ var len:int = DateBase.dayNamesLong.length;
352
+
353
+ for(var i:uint = 0; i < len; i++)
354
+ {
355
+ //12-04-2005 is a sunday
356
+ d = new Date(2005,11, i + 4);
357
+
358
+ assertTrue("DateUtil.getFullDayName(d) == DateBase.dayNamesLong["+i+"]",
359
+ DateUtil.getFullDayName(d) == DateBase.dayNamesLong[i]);
360
+ }
361
+ }
362
+
363
+ public function testGetFullMonthName():void
364
+ {
365
+ var d:Date;
366
+
367
+ //var len:uint = FULL_MONTH.length;
368
+ var len:int = DateBase.monthNamesLong.length;
369
+
370
+ for(var i:uint = 0; i < len; i++)
371
+ {
372
+ d = new Date(2005,i);
373
+
374
+ assertTrue("DateUtil.getFullMonthName(d) == DateBase.monthNamesLong["+i+"]",
375
+ DateUtil.getFullMonthName(d) == DateBase.monthNamesLong[i]);
376
+ }
377
+ }
378
+
379
+ public function testGetShortDayIndex():void
380
+ {
381
+ //var len:int = SHORT_DAY.length;
382
+ var len:int = DateBase.dayNamesShort.length;
383
+
384
+ for(var i:int = 0; i < len; i++)
385
+ {
386
+ assertTrue("DateUtil.getShortDayIndex(DateBase.dayNamesShort["+i+"]) == i",
387
+ DateUtil.getShortDayIndex(DateBase.dayNamesShort[i]) == i);
388
+ }
389
+ }
390
+
391
+ public function testGetShortMonthIndex():void
392
+ {
393
+ //var len:int = SHORT_MONTH.length;
394
+ var len:int = DateBase.monthNamesShort.length;
395
+
396
+ for(var i:int = 0; i < len; i++)
397
+ {
398
+ assertTrue("DateUtil.getShortMonthIndex(DateBase.monthNamesShort["+i+"]) == i",
399
+ DateUtil.getShortMonthIndex(DateBase.monthNamesShort[i]) == i);
400
+ }
401
+ }
402
+
403
+ public function testGetShortDayName():void
404
+ {
405
+ var d:Date;
406
+
407
+ //var len:uint = SHORT_DAY.length;
408
+ var len:int = DateBase.dayNamesShort.length;
409
+
410
+ for(var i:uint = 0; i < len; i++)
411
+ {
412
+ //12-04-2005 is a sunday
413
+ d = new Date(2005,11, i + 4);
414
+
415
+ assertTrue("DateUtil.getShortDayName(d) == DateBase.dayNamesShort["+i+"]",
416
+ DateUtil.getShortDayName(d) == DateBase.dayNamesShort[i]);
417
+ }
418
+ }
419
+
420
+ public function testGetShortMonthName():void
421
+ {
422
+ var d:Date;
423
+
424
+ //var len:uint = SHORT_MONTH.length;
425
+ var len:int = DateBase.monthNamesShort.length;
426
+
427
+ for(var i:uint = 0; i < len; i++)
428
+ {
429
+ d = new Date(2005,i);
430
+
431
+ assertTrue("DateUtil.getShortMonthName(d) == DateBase.monthNamesShort["+i+"]",
432
+ DateUtil.getShortMonthName(d) == DateBase.monthNamesShort[i]);
433
+ }
434
+ }
435
+ }
436
+ }
@@ -0,0 +1,93 @@
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.utils
34
+ {
35
+
36
+ import flexunit.framework.TestCase;
37
+ import flexunit.framework.TestSuite;
38
+
39
+ import com.adobe.utils.DictionaryUtil;
40
+ import flash.utils.Dictionary;
41
+ import com.adobe.utils.ArrayUtil;
42
+
43
+ public class DictionaryUtilTest extends TestCase {
44
+
45
+ private var d:Dictionary;
46
+ private var objectKey:Object = {};
47
+ private var objectValue:Object = {};
48
+
49
+ public function DictionaryUtilTest( methodName:String = null) {
50
+ super( methodName );
51
+
52
+ d = new Dictionary();
53
+ d.keyA = "valueA";
54
+ d.keyB = "valueB";
55
+ d[1] = 2;
56
+ d[objectKey] = objectValue;
57
+
58
+ }
59
+
60
+ public function testGetKeys():void {
61
+
62
+ var keys:Array = DictionaryUtil.getKeys(d);
63
+
64
+ assertTrue( "keys.length == 4", keys.length == 4 );
65
+ assertTrue("ArrayUtil.arrayContainsValue(keys, \"keyA\")",
66
+ ArrayUtil.arrayContainsValue(keys, "keyA"));
67
+ assertTrue("ArrayUtil.arrayContainsValue(keys, \"keyB\")",
68
+ ArrayUtil.arrayContainsValue(keys, "keyB"));
69
+ assertTrue("ArrayUtil.arrayContainsValue(keys, 1)",
70
+ ArrayUtil.arrayContainsValue(keys, 1));
71
+ assertTrue("ArrayUtil.arrayContainsValue(keys, objectKey)",
72
+ ArrayUtil.arrayContainsValue(keys, objectKey));
73
+
74
+
75
+ }
76
+
77
+ public function testGetValues():void {
78
+ var values:Array = DictionaryUtil.getValues(d);
79
+
80
+ assertTrue( "values.length == 4", values.length == 4 );
81
+
82
+ assertTrue("ArrayUtil.arrayContainsValue(values, \"valueA\")",
83
+ ArrayUtil.arrayContainsValue(values, "valueA"));
84
+ assertTrue("ArrayUtil.arrayContainsValue(values, \"keyB\")",
85
+ ArrayUtil.arrayContainsValue(values, "valueB"));
86
+ assertTrue("ArrayUtil.arrayContainsValue(values, 2)",
87
+ ArrayUtil.arrayContainsValue(values, 2));
88
+ assertTrue("ArrayUtil.arrayContainsValue(values, objectValue)",
89
+ ArrayUtil.arrayContainsValue(values, objectValue));
90
+ }
91
+
92
+ }
93
+ }