| 9 |
lars |
1 |
/*
|
|
|
2 |
Copyright (c) 2006 Steve Webster
|
|
|
3 |
|
|
|
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
5 |
this software and associated documentation files (the "Software"), to deal in
|
|
|
6 |
the Software without restriction, including without limitation the rights to
|
|
|
7 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
8 |
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
9 |
subject to the following conditions:
|
|
|
10 |
|
|
|
11 |
The above copyright notice and this permission notice shall be included in all
|
|
|
12 |
copies or substantial portions of the Software.
|
|
|
13 |
|
|
|
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
16 |
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
17 |
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
18 |
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
package com.dynamicflash.util.tests {
|
|
|
23 |
|
|
|
24 |
import flexunit.framework.TestCase;
|
|
|
25 |
import flexunit.framework.TestSuite;
|
|
|
26 |
import flash.utils.ByteArray;
|
|
|
27 |
|
|
|
28 |
import com.dynamicflash.util.Base64;
|
|
|
29 |
|
|
|
30 |
public class Base64Test extends TestCase {
|
|
|
31 |
|
|
|
32 |
public function Base64Test(methodName:String = null) {
|
|
|
33 |
super(methodName);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function testEncode():void {
|
|
|
37 |
assertEquals("VGhpcyBpcyBhIHRlc3Q=",Base64.encode("This is a test"));
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function testEncodeDecodeBytes():void {
|
|
|
41 |
var obj:Object = {name:"Dynamic Flash", url:"http://dynamicflash.com"};
|
|
|
42 |
var source:ByteArray = new ByteArray();
|
|
|
43 |
source.writeObject(obj);
|
|
|
44 |
var encoded:String = Base64.encodeByteArray(source);
|
|
|
45 |
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
|
|
|
46 |
var obj2:Object = decoded.readObject();
|
|
|
47 |
assertEquals(obj.name, obj2.name);
|
|
|
48 |
assertEquals(obj.url, obj2.url);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public function testDecode():void {
|
|
|
52 |
assertEquals("This is a test",Base64.decode("VGhpcyBpcyBhIHRlc3Q="));
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function testEncodeDecode():void {
|
|
|
56 |
var string:String = "The quick brown fox jumped over the lazy dogs";
|
|
|
57 |
assertEquals(string, Base64.decode(Base64.encode(string)));
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|