Skip to content

Commit 78cacf8

Browse files
authored
LocalCalendar/LocalEvent: provide all fields for DAVx5 (#15)
* Update color insertion logic to use Css3Color.entries * Add access level to AndroidCalendar * Add methods to get and set calendar sync state * [WIP] AndroidEvent: add more sync columns * Tests * Let new AndroidEvents have public setters for now * Update AndroidEvent constructor to accept new fields * Minor changes * Update sync state methods to use read and write semantics * Move companion objects to end of class declarations
1 parent 366184e commit 78cacf8

File tree

7 files changed

+463
-344
lines changed

7 files changed

+463
-344
lines changed

lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidCalendarTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ class AndroidCalendarTest {
9191
@Test
9292
fun testInsertColors() {
9393
AndroidCalendar.insertColors(provider, testAccount)
94-
assertEquals(Css3Color.values().size, countColors(testAccount))
94+
assertEquals(Css3Color.entries.size, countColors(testAccount))
9595
}
9696

9797
@Test
9898
fun testInsertColors_AlreadyThere() {
9999
AndroidCalendar.insertColors(provider, testAccount)
100100
AndroidCalendar.insertColors(provider, testAccount)
101-
assertEquals(Css3Color.values().size, countColors(testAccount))
101+
assertEquals(Css3Color.entries.size, countColors(testAccount))
102102
}
103103

104104
@Test

lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt

Lines changed: 101 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ import java.net.URI
6363
import java.time.Duration
6464
import java.time.Period
6565
import java.util.logging.Logger
66-
import kotlin.collections.Map
67-
import kotlin.collections.component1
68-
import kotlin.collections.component2
69-
import kotlin.collections.emptyMap
70-
import kotlin.collections.first
71-
import kotlin.collections.firstOrNull
72-
import kotlin.collections.iterator
73-
import kotlin.collections.mapOf
7466
import kotlin.collections.plusAssign
7567

7668
class AndroidEventTest {
@@ -126,6 +118,25 @@ class AndroidEventTest {
126118
}
127119

128120

121+
@Test
122+
fun testConstructor_ContentValues() {
123+
val e = AndroidEvent(
124+
calendar, contentValuesOf(
125+
Events._ID to 123,
126+
Events._SYNC_ID to "some-ical.ics",
127+
AndroidEvent.COLUMN_ETAG to "some-etag",
128+
AndroidEvent.COLUMN_SCHEDULE_TAG to "some-schedule-tag",
129+
AndroidEvent.COLUMN_FLAGS to 45
130+
)
131+
)
132+
assertEquals(123L, e.id)
133+
assertEquals("some-ical.ics", e.syncId)
134+
assertEquals("some-etag", e.eTag)
135+
assertEquals("some-schedule-tag", e.scheduleTag)
136+
assertEquals(45, e.flags)
137+
}
138+
139+
129140
/**
130141
* buildEvent() BASIC TEST MATRIX:
131142
*
@@ -1522,6 +1533,87 @@ class AndroidEventTest {
15221533
).event!!
15231534
}
15241535

1536+
@Test
1537+
fun testPopulateEvent_Uid_iCalUid() {
1538+
populateEvent(
1539+
true,
1540+
extendedProperties = mapOf(
1541+
AndroidEvent.EXTNAME_ICAL_UID to "[email protected]"
1542+
)
1543+
).let { result ->
1544+
assertEquals("[email protected]", result.uid)
1545+
}
1546+
}
1547+
1548+
@Test
1549+
fun testPopulateEvent_Uid_UID_2445() {
1550+
populateEvent(true) {
1551+
put(Events.UID_2445, "[email protected]")
1552+
}.let { result ->
1553+
assertEquals("[email protected]", result.uid)
1554+
}
1555+
}
1556+
1557+
@Test
1558+
fun testPopulateEvent_Uid_UID_2445_and_iCalUid() {
1559+
populateEvent(
1560+
true,
1561+
extendedProperties = mapOf(
1562+
AndroidEvent.EXTNAME_ICAL_UID to "[email protected]"
1563+
)
1564+
) {
1565+
put(Events.UID_2445, "[email protected]")
1566+
}.let { result ->
1567+
assertEquals("[email protected]", result.uid)
1568+
}
1569+
}
1570+
1571+
1572+
@Test
1573+
fun testPopulateEvent_Sequence_Int() {
1574+
populateEvent(true, asSyncAdapter = true) {
1575+
put(AndroidEvent.COLUMN_SEQUENCE, 5)
1576+
}.let { result ->
1577+
assertEquals(5, result.sequence)
1578+
}
1579+
}
1580+
1581+
@Test
1582+
fun testPopulateEvent_Sequence_Null() {
1583+
populateEvent(true, asSyncAdapter = true) {
1584+
putNull(AndroidEvent.COLUMN_SEQUENCE)
1585+
}.let { result ->
1586+
assertNull(result.sequence)
1587+
}
1588+
}
1589+
1590+
@Test
1591+
fun testPopulateEvent_IsOrganizer_False() {
1592+
populateEvent(true, asSyncAdapter = true) {
1593+
put(Events.IS_ORGANIZER, "0")
1594+
}.let { result ->
1595+
assertFalse(result.isOrganizer!!)
1596+
}
1597+
}
1598+
1599+
@Test
1600+
fun testPopulateEvent_IsOrganizer_Null() {
1601+
populateEvent(true, asSyncAdapter = true) {
1602+
putNull(Events.IS_ORGANIZER)
1603+
}.let { result ->
1604+
assertNull(result.isOrganizer)
1605+
}
1606+
}
1607+
1608+
@Test
1609+
fun testPopulateEvent_IsOrganizer_True() {
1610+
populateEvent(true, asSyncAdapter = true) {
1611+
put(Events.IS_ORGANIZER, "1")
1612+
}.let { result ->
1613+
assertTrue(result.isOrganizer!!)
1614+
}
1615+
}
1616+
15251617
@Test
15261618
fun testPopulateEvent_NonAllDay_NonRecurring() {
15271619
populateEvent(false) {
@@ -1886,39 +1978,6 @@ class AndroidEventTest {
18861978
}
18871979
}
18881980

1889-
@Test
1890-
fun testPopulateEvent_Uid_iCalUid() {
1891-
populateEvent(
1892-
true,
1893-
extendedProperties = mapOf(
1894-
AndroidEvent.EXTNAME_ICAL_UID to "[email protected]"
1895-
)
1896-
).let { result ->
1897-
assertEquals("[email protected]", result.uid)
1898-
}
1899-
}
1900-
1901-
@Test
1902-
fun testPopulateEvent_Uid_UID_2445() {
1903-
populateEvent(true) {
1904-
put(Events.UID_2445, "[email protected]")
1905-
}.let { result ->
1906-
assertEquals("[email protected]", result.uid)
1907-
}
1908-
}
1909-
1910-
@Test
1911-
fun testPopulateEvent_Uid_UID_2445_and_iCalUid() {
1912-
populateEvent(true,
1913-
extendedProperties = mapOf(
1914-
AndroidEvent.EXTNAME_ICAL_UID to "[email protected]"
1915-
)) {
1916-
put(Events.UID_2445, "[email protected]")
1917-
}.let { result ->
1918-
assertEquals("[email protected]", result.uid)
1919-
}
1920-
}
1921-
19221981

19231982
private fun populateReminder(destinationCalendar: TestCalendar = calendar, builder: ContentValues.() -> Unit): VAlarm? {
19241983
populateEvent(true, destinationCalendar = destinationCalendar, insertCallback = { id ->
@@ -2340,7 +2399,6 @@ class AndroidEventTest {
23402399
}
23412400

23422401

2343-
23442402
@Test
23452403
fun testUpdateEvent() {
23462404
// add test event without reminder
@@ -2480,4 +2538,4 @@ class AndroidEventTest {
24802538
}
24812539
}
24822540

2483-
}
2541+
}

lib/src/androidTest/kotlin/at/bitfire/ical4android/impl/TestCalendar.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import at.bitfire.ical4android.AndroidCalendar
1515
import at.bitfire.ical4android.AndroidCalendarFactory
1616

1717
class TestCalendar(
18-
account: Account,
19-
providerClient: ContentProviderClient,
20-
id: Long
18+
account: Account,
19+
providerClient: ContentProviderClient,
20+
id: Long
2121
): AndroidCalendar<TestEvent>(account, providerClient, TestEvent.Factory, id) {
2222

2323
companion object {

lib/src/androidTest/kotlin/at/bitfire/ical4android/impl/TestEvent.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
package at.bitfire.ical4android.impl
88

99
import android.content.ContentValues
10-
import android.provider.CalendarContract.Events
1110
import at.bitfire.ical4android.AndroidCalendar
1211
import at.bitfire.ical4android.AndroidEvent
1312
import at.bitfire.ical4android.AndroidEventFactory
1413
import at.bitfire.ical4android.Event
15-
import at.bitfire.synctools.storage.BatchOperation
1614
import java.util.UUID
1715

1816
class TestEvent: AndroidEvent {
@@ -21,19 +19,7 @@ class TestEvent: AndroidEvent {
2119
: super(calendar, values)
2220

2321
constructor(calendar: TestCalendar, event: Event)
24-
: super(calendar, event)
25-
26-
val syncId by lazy { UUID.randomUUID().toString() }
27-
28-
29-
override fun buildEvent(recurrence: Event?, builder: BatchOperation.CpoBuilder) {
30-
if (recurrence != null)
31-
builder.withValue(Events.ORIGINAL_SYNC_ID, syncId)
32-
else
33-
builder.withValue(Events._SYNC_ID, syncId)
34-
35-
super.buildEvent(recurrence, builder)
36-
}
22+
: super(calendar, event, UUID.randomUUID().toString(), null, null, 0)
3723

3824

3925
object Factory: AndroidEventFactory<TestEvent> {

0 commit comments

Comments
 (0)