mirror of
https://github.com/etesync/android
synced 2025-07-06 14:52:35 +00:00

* new Settings activity * Settings: display/change user name, password, preemptive auth. * Settings: display/change sync. interval for contacts and calendars * requires permission GET_ACCOUNTS to list accounts in Settings * requires permission READ_SYNC_SETTINGS to display current sync intervals * remove obsolete files from res/ * update copyright notices * version bump to 0.7
83 lines
3.1 KiB
Java
83 lines
3.1 KiB
Java
/*
|
||
* Copyright (c) 2013 – 2015 Ricki Hirner (bitfire web engineering).
|
||
* All rights reserved. This program and the accompanying materials
|
||
* are made available under the terms of the GNU Public License v3.0
|
||
* which accompanies this distribution, and is available at
|
||
* http://www.gnu.org/licenses/gpl.html
|
||
*/
|
||
package at.bitfire.davdroid.resource;
|
||
|
||
import java.io.IOException;
|
||
import java.io.InputStream;
|
||
import java.net.URI;
|
||
import java.net.URISyntaxException;
|
||
import java.util.Arrays;
|
||
|
||
import at.bitfire.davdroid.webdav.DavException;
|
||
import at.bitfire.davdroid.webdav.HttpException;
|
||
import ezvcard.property.Email;
|
||
import ezvcard.property.Telephone;
|
||
import lombok.Cleanup;
|
||
import android.content.res.AssetManager;
|
||
import android.test.InstrumentationTestCase;
|
||
|
||
import org.apache.commons.io.IOUtils;
|
||
|
||
import at.bitfire.davdroid.resource.Contact;
|
||
import at.bitfire.davdroid.resource.InvalidResourceException;
|
||
|
||
public class ContactTest extends InstrumentationTestCase {
|
||
AssetManager assetMgr;
|
||
|
||
public void setUp() throws IOException, InvalidResourceException {
|
||
assetMgr = getInstrumentation().getContext().getResources().getAssets();
|
||
}
|
||
|
||
public void testReferenceVCard() throws IOException, InvalidResourceException {
|
||
Contact c = parseVCF("reference.vcf");
|
||
assertEquals("Gump", c.getFamilyName());
|
||
assertEquals("Forrest", c.getGivenName());
|
||
assertEquals("Forrest Gump", c.getDisplayName());
|
||
assertEquals("Bubba Gump Shrimp Co.", c.getOrganization().getValues().get(0));
|
||
assertEquals("Shrimp Man", c.getJobTitle());
|
||
|
||
Telephone phone1 = c.getPhoneNumbers().get(0);
|
||
assertEquals("(111) 555-1212", phone1.getText());
|
||
assertEquals("WORK", phone1.getParameters("TYPE").get(0));
|
||
assertEquals("VOICE", phone1.getParameters("TYPE").get(1));
|
||
|
||
Telephone phone2 = c.getPhoneNumbers().get(1);
|
||
assertEquals("(404) 555-1212", phone2.getText());
|
||
assertEquals("HOME", phone2.getParameters("TYPE").get(0));
|
||
assertEquals("VOICE", phone2.getParameters("TYPE").get(1));
|
||
|
||
Email email = c.getEmails().get(0);
|
||
assertEquals("forrestgump@example.com", email.getValue());
|
||
assertEquals("PREF", email.getParameters("TYPE").get(0));
|
||
assertEquals("INTERNET", email.getParameters("TYPE").get(1));
|
||
|
||
@Cleanup InputStream photoStream = assetMgr.open("davdroid-logo-192.png", AssetManager.ACCESS_STREAMING);
|
||
byte[] expectedPhoto = IOUtils.toByteArray(photoStream);
|
||
assertTrue(Arrays.equals(c.getPhoto(), expectedPhoto));
|
||
}
|
||
|
||
public void testParseInvalidUnknownProperties() throws IOException, InvalidResourceException {
|
||
Contact c = parseVCF("invalid-unknown-properties.vcf");
|
||
assertEquals("VCard with invalid unknown properties", c.getDisplayName());
|
||
assertNull(c.getUnknownProperties());
|
||
}
|
||
|
||
|
||
protected Contact parseVCF(String fname) throws IOException, InvalidResourceException {
|
||
@Cleanup InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);
|
||
Contact c = new Contact(fname, null);
|
||
c.parseEntity(in, new Resource.AssetDownloader() {
|
||
@Override
|
||
public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException {
|
||
return IOUtils.toByteArray(uri);
|
||
}
|
||
});
|
||
return c;
|
||
}
|
||
}
|