Search in sources :

Example 21 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method label_parameters.

/**
 * Escaped newlines should ONLY be unescaped in LABEL parameters of ADR
 * properties.
 */
@Test
public void label_parameters() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version.getVersion() + "\r\n" + "ADR;LABEL=one\\ntwo;PARAM=one\\ntwo:\r\n" + "PROP;LABEL=one\\ntwo;PARAM=one\\ntwo:\r\n" + "END:VCARD\r\n");
        asserter.next(version);
        asserter.address().label("one" + NEWLINE + "two").param("PARAM", "one\\ntwo").noMore();
        asserter.rawProperty("PROP").param("LABEL", "one\\ntwo").param("PARAM", "one\\ntwo").value("").noMore();
        asserter.done();
    // @formatter:on
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 22 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method extended_properties.

@Test
public void extended_properties() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "X-LUCKY-NUM:24\r\n" + "X-GENDER:ma\\,le\r\n" + "X-LUCKY-NUM:22\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new LuckyNumScribe());
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(3, vcard);
        // read a type that has a type class
        List<LuckyNumProperty> luckyNumTypes = vcard.getProperties(LuckyNumProperty.class);
        assertEquals(2, luckyNumTypes.size());
        assertEquals(24, luckyNumTypes.get(0).luckyNum);
        assertEquals(22, luckyNumTypes.get(1).luckyNum);
        assertTrue(vcard.getExtendedProperties("X-LUCKY-NUM").isEmpty());
        // read a type without a type class
        List<RawProperty> genderTypes = vcard.getExtendedProperties("X-GENDER");
        assertEquals(1, genderTypes.size());
        // raw type values are not unescaped
        assertEquals("ma\\,le", genderTypes.get(0).getValue());
        assertParseWarnings(reader);
        assertNoMoreVCards(reader);
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) VCardVersion(ezvcard.VCardVersion) LuckyNumProperty(ezvcard.io.LuckyNumProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 23 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method cannotParseException.

@Test
public void cannotParseException() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "group.CANNOTPARSE;PARAM=value;VALUE=text:value\r\n" + "X-FOO:value\r\n" + "END:VCARD\r\n";
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new CannotParseScribe());
        VCardAsserter asserter = new VCardAsserter(reader);
        asserter.next(version);
        asserter.rawProperty("X-FOO").value("value").noMore();
        asserter.rawProperty("CANNOTPARSE").group("group").param("PARAM", "value").dataType(VCardDataType.TEXT).value("value").noMore();
        asserter.warnings(25);
        asserter.done();
    // @formatter:on
    }
}
Also used : CannotParseScribe(ezvcard.io.scribe.CannotParseScribe) VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 24 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method type_parameter_enclosed_in_double_quotes.

/**
 * Account for an error in the 4.0 specification, which places multi-valued
 * TYPE parameters in double quotes.
 */
@Test
public void type_parameter_enclosed_in_double_quotes() throws Exception {
    VCardVersion version = V2_1;
    {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
        asserter.next(version);
        asserter.rawProperty("PROP").param("TYPE", "\"one,two,,three\"").param("FOO", "\"four,five,,six\"").value("").noMore();
        asserter.done();
    // @formatter:on
    }
    for (VCardVersion v : each(V3_0, V4_0)) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + v + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
        asserter.next(v);
        asserter.rawProperty("PROP").param("TYPE", "one", "two", "", "three").param("FOO", "four,five,,six").value("").noMore();
        asserter.done();
    // @formatter:on
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 25 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method property_warning.

@Test
public void property_warning() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "WARNINGS:foo\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new WarningsScribe());
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(1, vcard);
        assertParseWarnings(reader, (Integer) null);
        assertNoMoreVCards(reader);
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCardVersion (ezvcard.VCardVersion)36 Test (org.junit.Test)30 VCard (ezvcard.VCard)14 VCardAsserter (ezvcard.property.asserter.VCardAsserter)10 VCardParameters (ezvcard.parameter.VCardParameters)5 Label (ezvcard.property.Label)4 RawProperty (ezvcard.property.RawProperty)4 VCardProperty (ezvcard.property.VCardProperty)4 Address (ezvcard.property.Address)3 ProductId (ezvcard.property.ProductId)3 VCardDataType (ezvcard.VCardDataType)2 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)2 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)2 ArrayList (java.util.ArrayList)2 SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)1 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)1 ValidationWarning (ezvcard.ValidationWarning)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1