Automated import from //branches/master/...@142460,142460

This commit is contained in:
Tadashi Takaoka 2009-03-24 22:52:06 -07:00 committed by The Android Open Source Project
parent ce4504b78e
commit 1d60657509
2 changed files with 24 additions and 3 deletions

View File

@ -374,14 +374,14 @@ public class EncoderUtil {
sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]);
sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]);
sb.append((char) BASE64_TABLE[data >> 6 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 6 & 0x3f]);
sb.append(BASE64_PAD); sb.append((char) BASE64_PAD);
} else if (idx == end - 1) { } else if (idx == end - 1) {
int data = (bytes[idx] & 0xff) << 16; int data = (bytes[idx] & 0xff) << 16;
sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]);
sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]);
sb.append(BASE64_PAD); sb.append((char) BASE64_PAD);
sb.append(BASE64_PAD); sb.append((char) BASE64_PAD);
} }
return sb.toString(); return sb.toString();

View File

@ -39,6 +39,14 @@ public class MimeUtilityTest extends TestCase {
private final String SHORT_UNICODE = "\u2191\u2193\u2190\u2192"; private final String SHORT_UNICODE = "\u2191\u2193\u2190\u2192";
private final String SHORT_UNICODE_ENCODED = "=?UTF-8?B?4oaR4oaT4oaQ4oaS?="; private final String SHORT_UNICODE_ENCODED = "=?UTF-8?B?4oaR4oaT4oaQ4oaS?=";
/** dollar and euro sign */
private final String PADDED2_UNICODE = "$\u20AC";
private final String PADDED2_UNICODE_ENCODED = "=?UTF-8?B?JOKCrA==?=";
private final String PADDED1_UNICODE = "$$\u20AC";
private final String PADDED1_UNICODE_ENCODED = "=?UTF-8?B?JCTigqw=?=";
private final String PADDED0_UNICODE = "$$$\u20AC";
private final String PADDED0_UNICODE_ENCODED = "=?UTF-8?B?JCQk4oKs?=";
/** a string without any unicode */ /** a string without any unicode */
private final String SHORT_PLAIN = "abcd"; private final String SHORT_PLAIN = "abcd";
@ -141,6 +149,19 @@ public class MimeUtilityTest extends TestCase {
assertSame(SHORT_PLAIN, result3); assertSame(SHORT_PLAIN, result3);
} }
/**
* Test about base64 padding variety.
*/
public void testPaddingOfFoldAndEncode2() {
String result1 = MimeUtility.foldAndEncode2(PADDED2_UNICODE, 0);
String result2 = MimeUtility.foldAndEncode2(PADDED1_UNICODE, 0);
String result3 = MimeUtility.foldAndEncode2(PADDED0_UNICODE, 0);
assertEquals("padding 2", PADDED2_UNICODE_ENCODED, result1);
assertEquals("padding 1", PADDED1_UNICODE_ENCODED, result2);
assertEquals("padding 0", PADDED0_UNICODE_ENCODED, result3);
}
// TODO: more tests for foldAndEncode(String s) // TODO: more tests for foldAndEncode(String s)
/** /**