mirror of https://github.com/etesync/android
* generalized InvalidResourceException for parsing errors * only iCals with both DtStart and DtEnd/Duration are processed (DtEnd will be derived by iCal4j when not present in .ics) * all-day events must last at least one day (fixes #166) * other DtEnd/Duration rewriting + testspull/2/head
parent
972da39e4a
commit
c7fe069b1f
@ -0,0 +1,13 @@
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
public class InvalidResourceException extends Exception {
|
||||
private static final long serialVersionUID = 1593585432655578220L;
|
||||
|
||||
public InvalidResourceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidResourceException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
|
||||
BEGIN:VEVENT
|
||||
UID:all-day-0sec@example.com
|
||||
DTSTAMP:20140101T000000Z
|
||||
DTSTART;VALUE=DATE:19970714
|
||||
DTEND;VALUE=DATE:19970714
|
||||
SUMMARY:0 Sec Event
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -0,0 +1,11 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
|
||||
BEGIN:VEVENT
|
||||
UID:all-day-10days@example.com
|
||||
DTSTAMP:20140101T000000Z
|
||||
DTSTART;VALUE=DATE:19970714
|
||||
DTEND;VALUE=DATE:19970724
|
||||
SUMMARY:All-Day 10 Days
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -0,0 +1,11 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
|
||||
BEGIN:VEVENT
|
||||
UID:all-day-1day@example.com
|
||||
DTSTAMP:20140101T000000Z
|
||||
DTSTART;VALUE=DATE:19970714
|
||||
DTEND;VALUE=DATE:19970714
|
||||
SUMMARY:All-Day 1 Day
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -0,0 +1,11 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
|
||||
BEGIN:VEVENT
|
||||
UID:event-on-that-day@example.com
|
||||
DTSTAMP:19970714T170000Z
|
||||
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
|
||||
DTSTART;VALUE=DATE:19970714
|
||||
SUMMARY:Bastille Day Party
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -0,0 +1,83 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard 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.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import lombok.Cleanup;
|
||||
import net.fortuna.ical4j.data.ParserException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.text.format.Time;
|
||||
import at.bitfire.davdroid.resource.Event;
|
||||
import at.bitfire.davdroid.resource.InvalidResourceException;
|
||||
|
||||
public class EventTest extends InstrumentationTestCase {
|
||||
AssetManager assetMgr;
|
||||
|
||||
Event eViennaEvolution,
|
||||
eOnThatDay, eAllDay1Day, eAllDay10Days, eAllDay0Sec;
|
||||
|
||||
public void setUp() throws IOException, InvalidResourceException {
|
||||
assetMgr = getInstrumentation().getContext().getResources().getAssets();
|
||||
|
||||
eViennaEvolution = parseCalendar("vienna-evolution.ics");
|
||||
eOnThatDay = parseCalendar("event-on-that-day.ics");
|
||||
eAllDay1Day = parseCalendar("all-day-1day.ics");
|
||||
eAllDay10Days = parseCalendar("all-day-10days.ics");
|
||||
eAllDay0Sec = parseCalendar("all-day-0sec.ics");
|
||||
|
||||
//assertEquals("Test-Ereignis im schönen Wien", e.getSummary());
|
||||
}
|
||||
|
||||
|
||||
public void testStartEndTimes() throws IOException, ParserException {
|
||||
// event with start+end date-time
|
||||
assertEquals(1381330800000L, eViennaEvolution.getDtStartInMillis());
|
||||
assertEquals("Europe/Vienna", eViennaEvolution.getDtStartTzID());
|
||||
assertEquals(1381334400000L, eViennaEvolution.getDtEndInMillis());
|
||||
assertEquals("Europe/Vienna", eViennaEvolution.getDtEndTzID());
|
||||
}
|
||||
|
||||
public void testStartEndTimesAllDay() throws IOException, ParserException {
|
||||
// event with start date only
|
||||
assertEquals(868838400000L, eOnThatDay.getDtStartInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eOnThatDay.getDtStartTzID());
|
||||
// DTEND missing in VEVENT, must have been set to DTSTART+1 day
|
||||
assertEquals(868838400000L + 86400000, eOnThatDay.getDtEndInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eOnThatDay.getDtEndTzID());
|
||||
|
||||
// event with start+end date for all-day event (one day)
|
||||
assertEquals(868838400000L, eAllDay1Day.getDtStartInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay1Day.getDtStartTzID());
|
||||
assertEquals(868838400000L + 86400000, eAllDay1Day.getDtEndInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay1Day.getDtEndTzID());
|
||||
|
||||
// event with start+end date for all-day event (ten days)
|
||||
assertEquals(868838400000L, eAllDay10Days.getDtStartInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay10Days.getDtStartTzID());
|
||||
assertEquals(868838400000L + 10*86400000, eAllDay10Days.getDtEndInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay10Days.getDtEndTzID());
|
||||
|
||||
// event with start+end date on some day (invalid 0 sec-event)
|
||||
assertEquals(868838400000L, eAllDay0Sec.getDtStartInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay0Sec.getDtStartTzID());
|
||||
// DTEND invalid in VEVENT, must have been set to DTSTART+1 day
|
||||
assertEquals(868838400000L + 86400000, eAllDay0Sec.getDtEndInMillis());
|
||||
assertEquals(Time.TIMEZONE_UTC, eAllDay0Sec.getDtEndTzID());
|
||||
}
|
||||
|
||||
|
||||
protected Event parseCalendar(String fname) throws IOException, InvalidResourceException {
|
||||
@Cleanup InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);
|
||||
Event e = new Event(fname, null);
|
||||
e.parseEntity(in);
|
||||
return e;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard 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.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.fortuna.ical4j.data.ParserException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import at.bitfire.davdroid.resource.Event;
|
||||
|
||||
public class CalendarTest extends InstrumentationTestCase {
|
||||
AssetManager assetMgr;
|
||||
|
||||
public void setUp() {
|
||||
assetMgr = getInstrumentation().getContext().getResources().getAssets();
|
||||
}
|
||||
|
||||
|
||||
public void testTimeZonesByEvolution() throws IOException, ParserException {
|
||||
Event e = parseCalendar("vienna-evolution.ics");
|
||||
assertEquals("Test-Ereignis im schönen Wien", e.getSummary());
|
||||
|
||||
//DTSTART;TZID=/freeassociation.sourceforge.net/Tzfile/Europe/Vienna:20131009T170000
|
||||
/*assertEquals(1381330800000L, e.getDtStartInMillis());
|
||||
assertEquals(1381334400000L, (long)e.getDtEndInMillis());*/
|
||||
}
|
||||
|
||||
|
||||
protected Event parseCalendar(String fname) throws IOException, ParserException {
|
||||
InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);
|
||||
Event e = new Event(fname, null);
|
||||
e.parseEntity(in);
|
||||
return e;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue