mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Integrate more variation in backup test generation.
This commit is contained in:
@@ -9,7 +9,6 @@ import android.Manifest
|
|||||||
import android.app.UiAutomation
|
import android.app.UiAutomation
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import io.mockk.InternalPlatformDsl.toArray
|
|
||||||
import okio.ByteString.Companion.toByteString
|
import okio.ByteString.Companion.toByteString
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@@ -220,6 +219,8 @@ class ImportExportTest {
|
|||||||
val numIndividualMessages = 500
|
val numIndividualMessages = 500
|
||||||
val numGroupMessagesPerPerson = 200
|
val numGroupMessagesPerPerson = 200
|
||||||
|
|
||||||
|
val random = Random(1516)
|
||||||
|
|
||||||
val recipients = ArrayList<Recipient>(1010)
|
val recipients = ArrayList<Recipient>(1010)
|
||||||
val chats = ArrayList<Chat>(1010)
|
val chats = ArrayList<Chat>(1010)
|
||||||
var id = 3L
|
var id = 3L
|
||||||
@@ -231,14 +232,14 @@ class ImportExportTest {
|
|||||||
contact = Contact(
|
contact = Contact(
|
||||||
aci = TestRecipientUtils.nextAci().toByteString(),
|
aci = TestRecipientUtils.nextAci().toByteString(),
|
||||||
pni = TestRecipientUtils.nextPni().toByteString(),
|
pni = TestRecipientUtils.nextPni().toByteString(),
|
||||||
username = "rec$i.01",
|
username = if (random.trueWithProbability(0.2f)) "rec$i.01" else null,
|
||||||
e164 = 14125550000 + i,
|
e164 = 14125550000 + i,
|
||||||
blocked = false,
|
blocked = random.trueWithProbability(0.1f),
|
||||||
hidden = false,
|
hidden = random.trueWithProbability(0.1f),
|
||||||
registered = Contact.Registered.REGISTERED,
|
registered = Contact.Registered.REGISTERED,
|
||||||
unregisteredTimestamp = 0L,
|
unregisteredTimestamp = 0L,
|
||||||
profileKey = TestRecipientUtils.generateProfileKey().toByteString(),
|
profileKey = TestRecipientUtils.generateProfileKey().toByteString(),
|
||||||
profileSharing = true,
|
profileSharing = random.trueWithProbability(0.9f),
|
||||||
profileGivenName = "Test",
|
profileGivenName = "Test",
|
||||||
profileFamilyName = "Recipient$i",
|
profileFamilyName = "Recipient$i",
|
||||||
hideStory = false
|
hideStory = false
|
||||||
@@ -258,9 +259,9 @@ class ImportExportTest {
|
|||||||
id = groupId,
|
id = groupId,
|
||||||
group = Group(
|
group = Group(
|
||||||
masterKey = TestRecipientUtils.generateGroupMasterKey().toByteString(),
|
masterKey = TestRecipientUtils.generateGroupMasterKey().toByteString(),
|
||||||
whitelisted = true,
|
whitelisted = random.trueWithProbability(0.9f),
|
||||||
hideStory = false,
|
hideStory = random.trueWithProbability(0.1f),
|
||||||
storySendMode = Group.StorySendMode.ENABLED,
|
storySendMode = if (random.trueWithProbability(0.9f)) Group.StorySendMode.ENABLED else Group.StorySendMode.DISABLED,
|
||||||
name = "Cool Group $i"
|
name = "Cool Group $i"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -315,7 +316,7 @@ class ImportExportTest {
|
|||||||
sms = false,
|
sms = false,
|
||||||
outgoing = ChatItem.OutgoingMessageDetails(
|
outgoing = ChatItem.OutgoingMessageDetails(
|
||||||
sendStatus = groupMembers.map { groupMember ->
|
sendStatus = groupMembers.map { groupMember ->
|
||||||
SendStatus(recipientId = groupMember.id, deliveryStatus = SendStatus.Status.READ, sealedSender = true)
|
SendStatus(recipientId = groupMember.id, deliveryStatus = if (random.trueWithProbability(0.8f)) SendStatus.Status.READ else SendStatus.Status.DELIVERED, sealedSender = true)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
standardMessage = StandardMessage(
|
standardMessage = StandardMessage(
|
||||||
@@ -337,7 +338,7 @@ class ImportExportTest {
|
|||||||
sms = false,
|
sms = false,
|
||||||
outgoing = ChatItem.OutgoingMessageDetails(
|
outgoing = ChatItem.OutgoingMessageDetails(
|
||||||
sendStatus = listOf(
|
sendStatus = listOf(
|
||||||
SendStatus(recipient.id, deliveryStatus = SendStatus.Status.READ, sealedSender = true)
|
SendStatus(recipient.id, deliveryStatus = if (random.trueWithProbability(0.8f)) SendStatus.Status.READ else SendStatus.Status.DELIVERED, sealedSender = true)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
standardMessage = StandardMessage(
|
standardMessage = StandardMessage(
|
||||||
@@ -1472,6 +1473,10 @@ class ImportExportTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Random.trueWithProbability(prob: Float): Boolean {
|
||||||
|
return nextFloat() < prob
|
||||||
|
}
|
||||||
|
|
||||||
private fun <T, R : Comparable<R>> prettyAssertEquals(import: List<T>, export: List<T>, selector: (T) -> R?) {
|
private fun <T, R : Comparable<R>> prettyAssertEquals(import: List<T>, export: List<T>, selector: (T) -> R?) {
|
||||||
if (import.size != export.size) {
|
if (import.size != export.size) {
|
||||||
var msg = StringBuilder()
|
var msg = StringBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user