FileDocCategorySizeDatePackage
VCardUtilsTests.javaAPI DocAndroid 5.1 API7460Thu Mar 12 22:22:54 GMT 2015com.android.vcard.tests

VCardUtilsTests

public class VCardUtilsTests extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestAppearsLikeAndroidVCardQuotedPrintableByContent()

        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("==="));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("===="));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("======="));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=12="));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=34="));

        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=123"));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=123="));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("_12="));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12_"));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=34_56="));
    
public voidtestAppearsLikeAndroidVCardQuotedPrintableByLength()

        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("="));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=1"));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12"));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12="));
        assertFalse(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=1"));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=12"));
        assertTrue(VCardUtils.appearsLikeAndroidVCardQuotedPrintable("=12=12="));
    
public voidtestContainsOnlyAlphaDigitHyphen()

        assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen((String)null));
        assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen((String[])null));
        assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen((List<String>)null));
        assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen(""));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("0123456789-"));
        for (int i = 0; i < 0x30; i++) {
            if (i == 0x2D) {  // -
                continue;
            }
            assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
        }
        for (int i = 0x3A; i < 0x41; i++) {
            assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
        }
        for (int i = 0x5B; i < 0x61; i++) {
            assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
        }
        for (int i = 0x7B; i < 0x100; i++) {
            assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
        }
    
public voidtestContainsOnlyNonCrLfPrintableAscii()

        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii((String)null));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii((String[])null));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii((List<String>)null));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii(""));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
        StringBuilder builder = new StringBuilder();
        for (int i = 0x20; i < 0x7F; i++) {
            builder.append((char)i);
        }
        assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii(builder.toString()));
        assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\u0019"));
        assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\u007F"));
        assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\r"));
        assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\n"));
    
public voidtestContainsOnlyPrintableAscii()

        assertTrue(VCardUtils.containsOnlyPrintableAscii((String)null));
        assertTrue(VCardUtils.containsOnlyPrintableAscii((String[])null));
        assertTrue(VCardUtils.containsOnlyPrintableAscii((List<String>)null));
        assertTrue(VCardUtils.containsOnlyPrintableAscii(""));
        assertTrue(VCardUtils.containsOnlyPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
        assertTrue(VCardUtils.containsOnlyPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
        StringBuilder builder = new StringBuilder();
        for (int i = 0x20; i < 0x7F; i++) {
            builder.append((char)i);
        }
        assertTrue(VCardUtils.containsOnlyPrintableAscii(builder.toString()));
        assertTrue(VCardUtils.containsOnlyPrintableAscii("\r\n"));
        assertFalse(VCardUtils.containsOnlyPrintableAscii("\u0019"));
        assertFalse(VCardUtils.containsOnlyPrintableAscii("\u007F"));
    
public voidtestToStringAvailableAsV30ParamValue()

        // Smoke tests.
        assertEquals("HOME", VCardUtils.toStringAsV30ParamValue("HOME"));
        assertEquals("TEL", VCardUtils.toStringAsV30ParamValue("TEL"));
        assertEquals("PAGER", VCardUtils.toStringAsV30ParamValue("PAGER"));

        assertTrue(TextUtils.isEmpty(VCardUtils.toStringAsV30ParamValue("")));
        assertTrue(TextUtils.isEmpty(VCardUtils.toStringAsV30ParamValue(null)));
        assertTrue(TextUtils.isEmpty(VCardUtils.toStringAsV30ParamValue(" \t")));

        // non-Ascii must be allowed
        assertEquals("\u4E8B\u52D9\u6240",
                VCardUtils.toStringAsV30ParamValue("\u4E8B\u52D9\u6240"));
        // Reported as bug report.
        assertEquals("\u8D39", VCardUtils.toStringAsV30ParamValue("\u8D39"));
        assertEquals("\"comma,separated\"",
                VCardUtils.toStringAsV30ParamValue("comma,separated"));
        assertEquals("\"colon:aware\"",
                VCardUtils.toStringAsV30ParamValue("colon:aware"));
        // CTL characters.
        assertEquals("CTLExample",
                VCardUtils.toStringAsV30ParamValue("CTL\u0001Example"));
        assertTrue(TextUtils.isEmpty(
                VCardUtils.toStringAsV30ParamValue("\u0001\u0002\u0003")));
        // DQUOTE must be removed.
        assertEquals("quoted",
                VCardUtils.toStringAsV30ParamValue("\"quoted\""));
        // DQUOTE must be removed basically, but we should detect a space, which
        // require us to use DQUOTE again.
        // Right-side has one more illegal dquote to test quote-handle code thoroughly.
        assertEquals("\"Already quoted\"",
                VCardUtils.toStringAsV30ParamValue("\"Already quoted\"\""));