as3corelib 0.1.0 → 0.85.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -4
- data/Gemfile.lock +7 -4
- data/README.textile +20 -10
- data/Rakefile +32 -2
- data/as3corelib.gemspec +13 -11
- data/lib/as3corelib.rb +10 -4
- data/lib/as3corelib/version.rb +4 -0
- metadata +31 -121
- data/build/build.properties +0 -48
- data/build/build.xml +0 -104
- data/examples/JSONExample/JSONExample.mxml +0 -73
- data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
- data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
- data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
- data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
- data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
- data/src/com/adobe/air/logging/FileTarget.as +0 -95
- data/src/com/adobe/air/net/ResourceCache.as +0 -165
- data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
- data/src/com/adobe/crypto/HMAC.as +0 -127
- data/src/com/adobe/crypto/MD5.as +0 -281
- data/src/com/adobe/crypto/MD5Stream.as +0 -402
- data/src/com/adobe/crypto/SHA1.as +0 -289
- data/src/com/adobe/crypto/SHA224.as +0 -257
- data/src/com/adobe/crypto/SHA256.as +0 -261
- data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
- data/src/com/adobe/errors/IllegalStateError.as +0 -63
- data/src/com/adobe/fileformats/vcard/Address.as +0 -47
- data/src/com/adobe/fileformats/vcard/Email.as +0 -39
- data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
- data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
- data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
- data/src/com/adobe/images/BitString.as +0 -39
- data/src/com/adobe/images/JPGEncoder.as +0 -648
- data/src/com/adobe/images/PNGEncoder.as +0 -141
- data/src/com/adobe/net/DynamicURLLoader.as +0 -55
- data/src/com/adobe/net/IURIResolver.as +0 -76
- data/src/com/adobe/net/MimeTypeMap.as +0 -200
- data/src/com/adobe/net/URI.as +0 -2466
- data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
- data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
- data/src/com/adobe/protocols/dict/Database.as +0 -66
- data/src/com/adobe/protocols/dict/Definition.as +0 -71
- data/src/com/adobe/protocols/dict/Dict.as +0 -360
- data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
- data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
- data/src/com/adobe/protocols/dict/Response.as +0 -71
- data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
- data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
- data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
- data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
- data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
- data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
- data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
- data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
- data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
- data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
- data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
- data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
- data/src/com/adobe/serialization/json/JSON.as +0 -86
- data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
- data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
- data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
- data/src/com/adobe/serialization/json/JSONToken.as +0 -104
- data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
- data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
- data/src/com/adobe/utils/ArrayUtil.as +0 -187
- data/src/com/adobe/utils/DateUtil.as +0 -701
- data/src/com/adobe/utils/DictionaryUtil.as +0 -87
- data/src/com/adobe/utils/IntUtil.as +0 -99
- data/src/com/adobe/utils/NumberFormatter.as +0 -74
- data/src/com/adobe/utils/StringUtil.as +0 -239
- data/src/com/adobe/utils/XMLUtil.as +0 -168
- data/src/com/adobe/webapis/ServiceBase.as +0 -48
- data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
- data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
- data/tests/src/CoreLibTestRunner-app.xml +0 -135
- data/tests/src/CoreLibTestRunner.as +0 -138
- data/tests/src/CoreLibTestRunner.mxml +0 -46
- data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
- data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
- data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
- data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
- data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
- data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
- data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
- data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
- data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
- data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
- data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
- data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
- data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
- data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
- data/tests/src/com/adobe/net/URITest.as +0 -589
- data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
- data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
- data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
- data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
- data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
- data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
- data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
- data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
- data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
- data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
- data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
- data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
- data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
- data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
- data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
- data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,85 +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.serialization.json
|
34
|
-
{
|
35
|
-
|
36
|
-
/**
|
37
|
-
* This is just a simple class with some properties
|
38
|
-
* so that we can test converting the class instance
|
39
|
-
* to a JSON string.
|
40
|
-
*/
|
41
|
-
public class SimpleClass
|
42
|
-
{
|
43
|
-
|
44
|
-
public var publicVar1:int = 17;
|
45
|
-
public var publicVar2:int = 20;
|
46
|
-
|
47
|
-
protected var protectedVar:int = 0;
|
48
|
-
|
49
|
-
private var privateVar:int = -17;
|
50
|
-
|
51
|
-
public function get accessor1():int
|
52
|
-
{
|
53
|
-
return 25;
|
54
|
-
}
|
55
|
-
|
56
|
-
public function get accessor2():int
|
57
|
-
{
|
58
|
-
return 30;
|
59
|
-
}
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Constructor
|
63
|
-
*/
|
64
|
-
public function SimpleClass()
|
65
|
-
{
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
public function method():Boolean
|
70
|
-
{
|
71
|
-
return false;
|
72
|
-
}
|
73
|
-
|
74
|
-
[Transient]
|
75
|
-
public var transientVar:String;
|
76
|
-
|
77
|
-
/** Write-only property */
|
78
|
-
public function set writeOnlyProp( value:Number ):void
|
79
|
-
{
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
}
|
@@ -1,173 +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.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
|
-
}
|
@@ -1,436 +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.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
|
-
}
|