Skip to content

Commit 9529acf

Browse files
authored
ical4j tests as unit tests; add test for timezone with RDATE/PERIOD (#103) (#104)
* Move Ical4jTest.kt to synctools.icalendar package and update imports Add test for unparseable timezone with RDATE and PERIOD * Update test to focus on unparseable event with timezone and RDATE with PERIOD * Reduce imports; remove unused line
1 parent 0bb546b commit 9529acf

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

lib/src/test/kotlin/at/bitfire/ical4android/Ical4jTest.kt renamed to lib/src/test/kotlin/at/bitfire/synctools/icalendar/Ical4jTest.kt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
66

7-
package at.bitfire.ical4android
7+
package at.bitfire.synctools.icalendar
88

9+
import at.bitfire.ical4android.EventReader
910
import net.fortuna.ical4j.data.CalendarBuilder
11+
import net.fortuna.ical4j.data.ParserException
1012
import net.fortuna.ical4j.model.Component
1113
import net.fortuna.ical4j.model.DateTime
1214
import net.fortuna.ical4j.model.Parameter
@@ -68,8 +70,7 @@ class Ical4jTest {
6870
val darwin = tzReg.getTimeZone("Australia/Darwin")
6971

7072
val ts1 = 1616720400000
71-
val dt1 = DateTime(ts1).apply { isUtc = true }
72-
assertEquals(9.5, darwin.getOffset(ts1)/3600000.0, .01)
73+
assertEquals(9.5, darwin.getOffset(ts1) / 3600000.0, .01)
7374

7475
val dt2 = DateTime("20210326T103000", darwin)
7576
assertEquals(1616720400000, dt2.time)
@@ -113,11 +114,37 @@ class Ical4jTest {
113114
val karachi = tzReg.getTimeZone("Asia/Karachi")
114115

115116
val ts1 = 1609945200000
116-
val dt1 = DateTime(ts1).apply { isUtc = true }
117-
assertEquals(5, karachi.getOffset(ts1)/3600000)
117+
assertEquals(5, karachi.getOffset(ts1) / 3600000)
118118

119119
val dt2 = DateTime("20210106T200000", karachi)
120120
assertEquals(1609945200000, dt2.time)
121121
}
122122

123+
@Test(expected = ParserException::class)
124+
fun `Unparseable event with timezone with RDATE with PERIOD`() {
125+
CalendarBuilder().build(
126+
StringReader(
127+
"BEGIN:VCALENDAR\n" +
128+
"VERSION:2.0\n" +
129+
"BEGIN:VTIMEZONE\n" +
130+
"TZID:Europe/Berlin\n" +
131+
"X-TZINFO:Europe/Berlin[2025b]\n" +
132+
"BEGIN:STANDARD\n" +
133+
"DTSTART:18930401T000000\n" +
134+
"RDATE;VALUE=PERIOD:18930401T000000/18930402T000000\n" +
135+
"TZNAME:Europe/Berlin(STD)\n" +
136+
"TZOFFSETFROM:+005328\n" +
137+
"TZOFFSETTO:+0100\n" +
138+
"END:STANDARD\n" +
139+
"END:VTIMEZONE\n" +
140+
"BEGIN:VEVENT\n" +
141+
"UID:3b3c1b0e-e74c-48ef-ada8-33afc543648d\n" +
142+
"DTSTART;TZID=Europe/Berlin:20250917T122000\n" +
143+
"DTEND;TZID=Europe/Berlin:20250917T124500\n" +
144+
"END:VEVENT\n" +
145+
"END:VCALENDAR"
146+
)
147+
)
148+
}
149+
123150
}

0 commit comments

Comments
 (0)