01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.components;
04:
05: import junit.framework.TestCase;
06:
07: /*
08: RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
09: section 6.8. Base64 Content-Transfer-Encoding
10: The encoding process represents 24-bit groups of input bits as output
11: strings of 4 encoded characters. Proceeding from left to right, a
12: 24-bit input group is formed by concatenating 3 8bit input groups.
13: These 24 bits are then treated as 4 concatenated 6-bit groups, each
14: of which is translated into a single digit in the base64 alphabet.
15: When encoding a bit stream via the base64 encoding, the bit stream
16: must be presumed to be ordered with the most-significant-bit first.
17: That is, the first bit in the stream will be the high-order bit in
18: the first 8bit byte, and the eighth bit will be the low-order bit in
19: the first 8bit byte, and so on.
20: */
21:
22: public class Base64Test extends TestCase {
23: public void setUp() throws Exception {
24: }
25:
26: public void tearDown() throws Exception {
27: }
28:
29: public void testGetValueFor() throws Exception {
30: assertEquals(0, Base64.getValueFor((byte) 'A'));
31: assertEquals(26, Base64.getValueFor((byte) 'a'));
32: assertEquals(52, Base64.getValueFor((byte) '0'));
33: }
34:
35: public void testDecodeNothing() throws Exception {
36: assertEquals("", Base64.decode(""));
37: }
38:
39: public void testDecodeOneChar() throws Exception {
40: assertEquals("a", Base64.decode("YQ=="));
41: }
42:
43: public void testDecodeTwoChars() throws Exception {
44: assertEquals("a:", Base64.decode("YTo="));
45: }
46:
47: public void testDecodeLongSample() throws Exception {
48: assertEquals("Aladdin:open sesame", Base64
49: .decode("QWxhZGRpbjpvcGVuIHNlc2FtZQ=="));
50: }
51:
52: public void testEncodeNothing() throws Exception {
53: assertEquals("", Base64.encode(""));
54: }
55:
56: public void testEncodeOneChar() throws Exception {
57: assertEquals("YQ==", Base64.encode("a"));
58: }
59:
60: public void testEncodeTwoChars() throws Exception {
61: assertEquals("YTo=", Base64.encode("a:"));
62: }
63:
64: public void testEncodeThreeChars() throws Exception {
65: assertEquals("YWJj", Base64.encode("abc"));
66: }
67:
68: public void testEncodeLongSample() throws Exception {
69: assertEquals("QWxhZGRpbjpvcGVuIHNlc2FtZQ==", Base64
70: .encode("Aladdin:open sesame"));
71: }
72: }
|