test: add in contact merge tests

This commit is contained in:
0x330a 2022-12-16 10:56:59 +11:00
parent b792642477
commit 5383065636
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
2 changed files with 43 additions and 6 deletions

View File

@ -2,9 +2,12 @@ package network.loki.messenger.libsession_util
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import network.loki.messenger.libsession_util.util.Contact
import network.loki.messenger.libsession_util.util.KeyPair import network.loki.messenger.libsession_util.util.KeyPair
import network.loki.messenger.libsession_util.util.Sodium import network.loki.messenger.libsession_util.util.Sodium
import network.loki.messenger.libsession_util.util.UserPic import network.loki.messenger.libsession_util.util.UserPic
import org.hamcrest.CoreMatchers.not
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Assert.* import org.junit.Assert.*
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -112,6 +115,40 @@ class InstrumentedTests {
assertEquals(anotherId, contactList[1].id) assertEquals(anotherId, contactList[1].id)
assertEquals("Joey", contactList[0].nickname) assertEquals("Joey", contactList[0].nickname)
assertNull(contactList[1].nickname) assertNull(contactList[1].nickname)
contacts.erase(definitelyRealId)
val thirdId ="052222222222222222222222222222222222222222222222222222222222222222"
val third = Contact(
id = thirdId,
nickname = "Nickname 3",
approved = true,
blocked = true,
profilePicture = UserPic("http://example.com/huge.bmp", "qwerty".encodeToByteArray())
)
contacts2.set(third)
assertTrue(contacts.needsPush())
assertTrue(contacts2.needsPush())
val toPush = contacts.push()
val toPush2 = contacts2.push()
assertEquals(toPush.seqNo, toPush2.seqNo)
assertThat(toPush2.config, not(equals(toPush.config)))
contacts.confirmPushed(toPush.seqNo)
contacts2.confirmPushed(toPush2.seqNo)
contacts.merge(toPush2.config)
contacts2.merge(toPush.config)
assertTrue(contacts.needsPush())
assertTrue(contacts2.needsPush())
val mergePush = contacts.push()
val mergePush2 = contacts2.push()
assertEquals(mergePush.seqNo, mergePush2.seqNo)
assertArrayEquals(mergePush.config, mergePush2.config)
} }
@Test @Test

View File

@ -2,10 +2,10 @@ package network.loki.messenger.libsession_util.util
data class Contact( data class Contact(
val id: String, val id: String,
var name: String?, var name: String? = null,
var nickname: String?, var nickname: String? = null,
var approved: Boolean, var approved: Boolean = false,
var approvedMe: Boolean, var approvedMe: Boolean = false,
var blocked: Boolean, var blocked: Boolean = false,
var profilePicture: UserPic? var profilePicture: UserPic? = null
) )