|
| 1 | +package org.fossify.calendar.interfaces |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import androidx.room.Room |
| 5 | +import androidx.test.core.app.ApplicationProvider |
| 6 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 7 | +import org.fossify.calendar.databases.EventsDatabase |
| 8 | +import org.fossify.calendar.extensions.seconds |
| 9 | +import org.fossify.calendar.models.Event |
| 10 | +import org.fossify.calendar.testing.expectedFailure |
| 11 | +import org.joda.time.DateTime |
| 12 | +import org.junit.After |
| 13 | +import org.junit.Assert |
| 14 | +import org.junit.Before |
| 15 | +import org.junit.Test |
| 16 | +import org.junit.runner.RunWith |
| 17 | +import java.io.IOException |
| 18 | + |
| 19 | +@RunWith(AndroidJUnit4::class) |
| 20 | +class EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest { |
| 21 | + |
| 22 | + private lateinit var eventsDao: EventsDao |
| 23 | + private lateinit var db: EventsDatabase |
| 24 | + |
| 25 | + private val calendarId = 1L |
| 26 | + |
| 27 | + @Before |
| 28 | + fun createDb() { |
| 29 | + val context = ApplicationProvider.getApplicationContext<Context>() |
| 30 | + db = Room.inMemoryDatabaseBuilder( |
| 31 | + context, EventsDatabase::class.java).build() |
| 32 | + eventsDao = db.EventsDao() |
| 33 | + } |
| 34 | + |
| 35 | + @After |
| 36 | + @Throws(IOException::class) |
| 37 | + fun closeDb() { |
| 38 | + db.close() |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + @Throws(Exception::class) |
| 43 | + fun bug255_EventEndingAtMidnightShouldNotShowOnNextDay() { |
| 44 | + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/255") { |
| 45 | + val startDay = DateTime(2026, 1, 1, 0, 0) |
| 46 | + val startEvent = startDay.plusHours(23) |
| 47 | + val event = Event(id = 0, startTS = startEvent.seconds(), endTS = startEvent.plusHours(1).seconds(), calendarId = calendarId) |
| 48 | + eventsDao.insertOrUpdate(event) |
| 49 | + |
| 50 | + val eventsDayOne = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(1).seconds(), startDay.seconds(), listOf(calendarId)) |
| 51 | + val eventsDayTwo = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(2).seconds(), startDay.plusDays(1).seconds(), listOf(calendarId)) |
| 52 | + |
| 53 | + Assert.assertEquals(1, eventsDayOne.count()) |
| 54 | + Assert.assertEquals(emptyList<Event>(), eventsDayTwo) |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + @Throws(Exception::class) |
| 60 | + fun bug255_EventStartingAtMidnightWithoutDurationShouldOnlyShowOnSingleDay() { |
| 61 | + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/255") { |
| 62 | + val startDay = DateTime(2026, 1, 10, 0, 0) |
| 63 | + val event = Event(id = 0, startTS = startDay.seconds(), endTS = startDay.seconds(), calendarId = calendarId) |
| 64 | + eventsDao.insertOrUpdate(event) |
| 65 | + |
| 66 | + val eventsDayOne = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.seconds(), startDay.plusDays(-1).seconds(), listOf(calendarId)) |
| 67 | + val eventsDayTwo = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(1).seconds(), startDay.seconds(), listOf(calendarId)) |
| 68 | + |
| 69 | + Assert.assertEquals(1, eventsDayTwo.count()) |
| 70 | + Assert.assertEquals(emptyList<Event>(), eventsDayOne) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @Throws(Exception::class) |
| 76 | + fun bug440_EventAtMidnightOnFirstJan1970() { |
| 77 | + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/440") { |
| 78 | + eventsDao.insertOrUpdate(Event(id = 0, startTS = 0, endTS = 3600, calendarId = calendarId)) |
| 79 | + |
| 80 | + val eventsOnFirstJan1970 = eventsDao.getOneTimeEventsFromToWithCalendarIds(86400, 0, listOf(calendarId)) |
| 81 | + |
| 82 | + Assert.assertEquals(1, eventsOnFirstJan1970.count()) |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments