@@ -286,42 +286,42 @@ class AndroidCalendarTest {
286286 // event instances
287287
288288 @Test
289- fun testNumDirectInstances_SingleInstance () {
289+ fun testNumInstances_SingleInstance () {
290290 val id = calendar.addEvent(Entity (contentValuesOf(
291291 Events .CALENDAR_ID to calendar.id,
292292 Events .DTSTART to now,
293293 Events .DTEND to now + 3600000 ,
294294 Events .TITLE to " Event with 1 instance"
295295 )))
296- assertEquals(1 , calendar.numDirectInstances (id))
296+ assertEquals(1 , calendar.numInstances (id))
297297 }
298298
299299 @Test
300- fun testNumDirectInstances_Recurring () {
300+ fun testNumInstances_Recurring () {
301301 val id = calendar.addEvent(Entity (contentValuesOf(
302302 Events .CALENDAR_ID to calendar.id,
303303 Events .DTSTART to now,
304304 Events .DURATION to " PT1H" ,
305305 Events .TITLE to " Event with 5 instances" ,
306306 Events .RRULE to " FREQ=DAILY;COUNT=5"
307307 )))
308- assertEquals(5 , calendar.numDirectInstances (id))
308+ assertEquals(5 , calendar.numInstances (id))
309309 }
310310
311311 @Test
312- fun testNumDirectInstances_Recurring_Endless () {
312+ fun testNumInstances_Recurring_Endless () {
313313 val id = calendar.addEvent(Entity (contentValuesOf(
314314 Events .CALENDAR_ID to calendar.id,
315315 Events .DTSTART to now,
316316 Events .DURATION to " PT1H" ,
317317 Events .TITLE to " Event without end" ,
318318 Events .RRULE to " FREQ=DAILY"
319319 )))
320- assertNull(calendar.numDirectInstances (id))
320+ assertNull(calendar.numInstances (id))
321321 }
322322
323323 @Test
324- fun testNumDirectInstances_Recurring_LateEnd () {
324+ fun testNumInstances_Recurring_LateEnd () {
325325 val id = calendar.addEvent(Entity (contentValuesOf(
326326 Events .CALENDAR_ID to calendar.id,
327327 Events .DTSTART to 1642640523000 ,
@@ -331,13 +331,13 @@ class AndroidCalendarTest {
331331 )))
332332
333333 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R )
334- assertEquals(52 , calendar.numDirectInstances (id))
334+ assertEquals(52 , calendar.numInstances (id))
335335 else // year 2074 is not supported by Android <11 Calendar Storage
336- assertNull(calendar.numDirectInstances (id))
336+ assertNull(calendar.numInstances (id))
337337 }
338338
339339 @Test
340- fun testNumDirectInstances_Recurring_ManyInstances () {
340+ fun testNumInstances_Recurring_Until () {
341341 val id = calendar.addEvent(Entity (contentValuesOf(
342342 Events .CALENDAR_ID to calendar.id,
343343 Events .DTSTART to 1642640523000 ,
@@ -350,12 +350,12 @@ class AndroidCalendarTest {
350350 365 * 2 // Android <9: does not include UNTIL (incorrect!)
351351 else
352352 365 * 2 + 1 , // Android ≥9: includes UNTIL (correct)
353- calendar.numDirectInstances (id)
353+ calendar.numInstances (id)
354354 )
355355 }
356356
357357 @Test
358- fun testNumDirectInstances_RecurringWithExdate () {
358+ fun testNumInstances_RecurringWithExdate () {
359359 val id = calendar.addEvent(Entity (contentValuesOf(
360360 Events .CALENDAR_ID to calendar.id,
361361 Events .DTSTART to 1642640523000 ,
@@ -364,18 +364,18 @@ class AndroidCalendarTest {
364364 Events .RRULE to " FREQ=DAILY;COUNT=5" ,
365365 Events .EXDATE to " 20220121T010203Z"
366366 )))
367- assertEquals(4 , calendar.numDirectInstances (id))
367+ assertEquals(4 , calendar.numInstances (id))
368368 }
369369
370370 @Test
371- fun testNumDirectInstances_RecurringWithExceptions () {
371+ fun testNumInstances_RecurringWithExceptions_MatchingOrigInstanceTime () {
372372 val syncId = " recurring-with-exceptions"
373373 val id = calendar.addEvent(Entity (contentValuesOf(
374374 Events .CALENDAR_ID to calendar.id,
375375 Events ._SYNC_ID to syncId,
376376 Events .DTSTART to 1642640523000 ,
377377 Events .DURATION to " PT1H" ,
378- Events .TITLE to " Event with 5 instances, two of them excluded " ,
378+ Events .TITLE to " Event with 5 instances, two of them are exceptions " ,
379379 Events .RRULE to " FREQ=DAILY;COUNT=5"
380380 )))
381381 calendar.addEvent(Entity (contentValuesOf(
@@ -394,88 +394,19 @@ class AndroidCalendarTest {
394394 Events .DURATION to " PT1H" ,
395395 Events .TITLE to " Exception on 5th day" ,
396396 )))
397- assertEquals(5 - 2 , calendar.numDirectInstances(id))
398- }
399-
400- @Test
401- fun testNumInstances_SingleInstance () {
402- val id = calendar.addEvent(Entity (contentValuesOf(
403- Events .CALENDAR_ID to calendar.id,
404- Events .DTSTART to now,
405- Events .DTEND to now + 3600000 ,
406- Events .TITLE to " Event with 1 instance"
407- )))
408- assertEquals(1 , calendar.numInstances(id))
397+ assertEquals(5 - 2 , calendar.numInstances(id))
409398 }
410399
411400 @Test
412- fun testNumInstances_Recurring () {
413- val id = calendar.addEvent(Entity (contentValuesOf(
414- Events .CALENDAR_ID to calendar.id,
415- Events .DTSTART to now,
416- Events .DURATION to " PT1H" ,
417- Events .TITLE to " Event with 5 instances" ,
418- Events .RRULE to " FREQ=DAILY;COUNT=5"
419- )))
420- assertEquals(5 , calendar.numInstances(id))
421- }
422-
423- @Test
424- fun testNumInstances_Recurring_Endless () {
425- val id = calendar.addEvent(Entity (contentValuesOf(
426- Events .CALENDAR_ID to calendar.id,
427- Events .DTSTART to now,
428- Events .DURATION to " PT1H" ,
429- Events .TITLE to " Event without end" ,
430- Events .RRULE to " FREQ=DAILY"
431- )))
432- assertNull(calendar.numInstances(id))
433- }
434-
435- @Test
436- fun testNumInstances_Recurring_LateEnd () {
437- val id = calendar.addEvent(Entity (contentValuesOf(
438- Events .CALENDAR_ID to calendar.id,
439- Events .DTSTART to 1642640523000 ,
440- Events .DURATION to " PT1H" ,
441- Events .TITLE to " Event until 2074" ,
442- Events .RRULE to " FREQ=YEARLY;UNTIL=20740119T010203Z"
443- )))
444-
445- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R )
446- assertEquals(52 , calendar.numInstances(id))
447- else
448- assertNull(calendar.numInstances(id))
449- }
450-
451- @Test
452- fun testNumInstances_Recurring_ManyInstances () {
453- val id = calendar.addEvent(Entity (contentValuesOf(
454- Events .CALENDAR_ID to calendar.id,
455- Events .DTSTART to 1642640523000 ,
456- Events .DURATION to " PT1H" ,
457- Events .TITLE to " Event with 2 years" ,
458- Events .RRULE to " FREQ=DAILY;UNTIL=20240120T010203Z"
459- )))
460- assertEquals(
461- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .P )
462- 365 * 2 // Android <9: does not include UNTIL (incorrect!)
463- else
464- 365 * 2 + 1 , // Android ≥9: includes UNTIL (correct)
465- calendar.numInstances(id)
466- )
467- }
468-
469- @Test
470- fun testNumInstances_RecurringWithExceptions () {
401+ fun testNumInstances_RecurringWithExceptions_NotMatchingOrigInstanceTime () {
471402 val syncId = " recurring-with-exceptions"
472403 val id = calendar.addEvent(Entity (contentValuesOf(
473404 Events .CALENDAR_ID to calendar.id,
474405 Events ._SYNC_ID to syncId,
475406 Events .DTSTART to 1642640523000 ,
476407 Events .DURATION to " PT1H" ,
477- Events .TITLE to " Event with 6 instances" ,
478- Events .RRULE to " FREQ=DAILY;COUNT=6 "
408+ Events .TITLE to " Event with 5 instances, two of them are exceptions " ,
409+ Events .RRULE to " FREQ=DAILY;COUNT=5 "
479410 )))
480411 calendar.addEvent(Entity (contentValuesOf(
481412 Events .CALENDAR_ID to calendar.id,
@@ -488,13 +419,12 @@ class AndroidCalendarTest {
488419 calendar.addEvent(Entity (contentValuesOf(
489420 Events .CALENDAR_ID to calendar.id,
490421 Events .ORIGINAL_SYNC_ID to syncId,
491- Events .ORIGINAL_INSTANCE_TIME to 1642640523000 + 4 * 86400000 ,
422+ Events .ORIGINAL_INSTANCE_TIME to 1642640523000 + 4 * 86400000 + 100 , // doesn't match original instance time!
492423 Events .DTSTART to 1642640523000 + 4 * 86400000 + 3600000 , // one hour later
493424 Events .DURATION to " PT1H" ,
494- Events .TITLE to " Exception on 5th day" ,
425+ Events .TITLE to " Exception on 5th day (wrong instance time) " ,
495426 )))
496-
497- assertEquals(6 , calendar.numInstances(id))
427+ assertEquals(5 - 1 , calendar.numInstances(id))
498428 }
499429
500430}
0 commit comments