Skip to content

Commit

Permalink
Update ContactMessage test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sashaweiss-signal authored Sep 9, 2024
1 parent 270dfdc commit 98dbb66
Show file tree
Hide file tree
Showing 86 changed files with 501 additions and 1,095 deletions.
7 changes: 7 additions & 0 deletions src/main/kotlin/Permutations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ object Generators {
contentTypeGenerator = Generators.list("image/jpeg", "image/png")
)

fun avatarFilePointer(): Generator<FilePointer> = filePointerInternal(
includeFileName = true,
includeMediaSize = true,
includeCaption = false,
contentTypeGenerator = Generators.list("image/jpeg", "image/png")
)

fun filePointer(
contentTypeGenerator: Generator<String> = Generators.list("image/jpeg", "image/png", "image/gif", "audio/mp3", "video/mp4")
): Generator<FilePointer> = filePointerInternal(
Expand Down
23 changes: 16 additions & 7 deletions src/main/kotlin/tests/ChatItemContactMessageTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import PermutationScope
import TestCase
import asList
import nullable
import oneOf
import org.thoughtcrime.securesms.backup.v2.proto.ChatItem
import org.thoughtcrime.securesms.backup.v2.proto.ContactAttachment
Expand Down Expand Up @@ -51,15 +52,18 @@ object ChatItemContactMessageTestCase : TestCase("chat_item_contact_message") {
} else {
StandardFrames.recipientAlice.recipient!!.id
},
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
incoming = incoming as ChatItem.IncomingMessageDetails?,
outgoing = outgoing as ChatItem.OutgoingMessageDetails?,
contactMessage = ContactMessage(
contact = Generators.permutation<ContactAttachment> {
frames += ContactAttachment(
name = ContactAttachment.Name(
givenName = someNonEmptyString(),
familyName = someNonEmptyString()
familyName = someNonEmptyString(),
middleName = someNonEmptyString(),
prefix = someNonEmptyString(),
suffix = someNonEmptyString()
),
number = Generators.permutation<ContactAttachment.Phone> {
frames += ContactAttachment.Phone(
Expand All @@ -82,25 +86,30 @@ object ChatItemContactMessageTestCase : TestCase("chat_item_contact_message") {
)
}.asList(0, 1, 2).let { some(it) },
address = Generators.permutation<ContactAttachment.PostalAddress> {
// All-empty addresses are invalid, so ensure that at least one
// address field has a non-null, non-empty string.
val streetGenerator = Generators.list(null, SeededRandom.string(), SeededRandom.string())
val poBoxGenerator = Generators.list(SeededRandom.string(), null, SeededRandom.string())

frames += ContactAttachment.PostalAddress(
type = someEnum(
ContactAttachment.PostalAddress.Type::class.java,
excluding = ContactAttachment.PostalAddress.Type.UNKNOWN
),
label = someNullableString(),
street = someNonEmptyString(),
pobox = someNullableString(),
street = some(streetGenerator),
pobox = some(poBoxGenerator),
neighborhood = someNullableString(),
city = someNonEmptyString(),
city = someNullableString(),
region = someNullableString(),
postcode = someNullableString(),
country = someNullableString()
)
}.asList(0, 1, 2).let { some(it) },
organization = someNullableString(),
avatar = someNullableFilePointer()
avatar = some(Generators.avatarFilePointer().nullable())
)
}.asList(1, 2).let { some(it) }
}.asList(1).let { some(it) }
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ChatItemExpirationTimerUpdateTestCase : TestCase("chat_item_expiration_ti
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
authorId = some(Generators.list(StandardFrames.recipientSelf.recipient!!.id, StandardFrames.recipientAlice.recipient!!.id)),
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
directionless = ChatItem.DirectionlessMessageDetails(),
updateMessage = ChatUpdateMessage(
expirationTimerChange = ExpirationTimerChatUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object ChatItemProfileChangeUpdateTestCase : TestCase("chat_item_profile_change_
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
authorId = StandardFrames.recipientAlice.recipient!!.id,
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
directionless = ChatItem.DirectionlessMessageDetails(),
updateMessage = ChatUpdateMessage(
profileChange = ProfileChangeChatUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object ChatItemSessionSwitchoverUpdateTestCase : TestCase("chat_item_session_swi
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
authorId = StandardFrames.recipientAlice.recipient!!.id,
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
directionless = ChatItem.DirectionlessMessageDetails(),
updateMessage = ChatUpdateMessage(
sessionSwitchover = SessionSwitchoverChatUpdate(
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ChatItemSimpleUpdatesTestCase : TestCase("chat_item_simple_updates") {
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
authorId = StandardFrames.recipientAlice.recipient!!.id,
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
directionless = ChatItem.DirectionlessMessageDetails(),
updateMessage = ChatUpdateMessage(
simpleUpdate = SimpleChatUpdate(
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/tests/ChatItemThreadMergeUpdateTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ChatItemThreadMergeUpdateTestCase : TestCase("chat_item_thread_merge_upda
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
authorId = StandardFrames.recipientAlice.recipient!!.id,
dateSent = someTimestamp(),
dateSent = someNonZeroTimestamp(),
directionless = ChatItem.DirectionlessMessageDetails(),
updateMessage = ChatUpdateMessage(
threadMerge = ThreadMergeChatUpdate(
Expand Down
3 changes: 1 addition & 2 deletions src/main/proto/Backup.proto
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ message ContactAttachment {
optional string prefix = 3;
optional string suffix = 4;
optional string middleName = 5;
optional string displayName = 6;
}

message Phone {
Expand Down Expand Up @@ -1150,4 +1149,4 @@ message ChatStyle {
}

bool dimWallpaperInDarkMode = 7;
}
}
Binary file modified test-cases/chat_item_contact_message_00.binproto
Binary file not shown.
4 changes: 4 additions & 0 deletions test-cases/chat_item_contact_message_00.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ Frame {
name = Name {
familyName = "wSQuECQWuuuEFC"
givenName = "iJZOYWfDTgpIJq"
middleName = "FXMOBqmCd"
prefix = "IBHCZ"
suffix = "nSfTgFokLHLmtL"
}
}
]
}
dateSent = 1680366577838
incoming = IncomingMessageDetails {
dateReceived = 1702291826269
dateServerSent = 1794124103201
Expand Down
Binary file modified test-cases/chat_item_contact_message_01.binproto
Binary file not shown.
93 changes: 11 additions & 82 deletions test-cases/chat_item_contact_message_01.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -121,114 +121,43 @@ Frame {
ContactAttachment {
address = [
PostalAddress {
city = "nZhuXJWXD"
street = "hyZCTrFaZqB"
pobox = "FzSlNk"
type = Type.HOME
}
]
avatar = FilePointer {
backupLocator = BackupLocator {
digest = <6b61c36c807559220985f14b0252e833>
key = <8d3cda32685e0086546218a42159dc48>
mediaName = "6b61c36c807559220985f14b0252e833"
size = 1465688382
digest = <245052a930af623c6f503cf7bbfd9a0d>
key = <1c3701139655d30267e5ccd3ede8adb0>
mediaName = "245052a930af623c6f503cf7bbfd9a0d"
size = 1120972837
}
contentType = "image/jpeg"
}
email = [
Email {
type = Type.HOME
value_ = "qaczwFdzHL@okMZPmjwqTJ.com"
value_ = "xHDjKnB@pjPVt.com"
}
]
name = Name {
familyName = "CqQNEWGrAzrHY"
givenName = "SkLQGER"
middleName = "WyYPnka"
prefix = "OtEhcCMeej"
suffix = "dKPNuFXypj"
}
number = [
Phone {
type = Type.HOME
value_ = "447700900133"
value_ = "447700900571"
}
]
organization = ""
},
ContactAttachment {
address = [
PostalAddress {
city = "xnqeB"
country = ""
label = ""
neighborhood = ""
pobox = ""
postcode = ""
region = ""
street = "UUiitmkHLv"
type = Type.WORK
},
PostalAddress {
city = "nZhuXJWXD"
country = "fCpzjVLQFQh"
label = "tAKtPVXV"
neighborhood = "FzSlNk"
pobox = "jrJToWuNQzhOBq"
postcode = "YQcczeJZd"
region = "rOHZwwEoKI"
street = "hyZCTrFaZqB"
type = Type.CUSTOM
}
]
avatar = FilePointer {
backupLocator = BackupLocator {
cdnNumber = 2
digest = <85e08d21245052a930af623c6f503cf7>
key = <c03df20a1c3701139655d30267e5ccd3>
mediaName = "85e08d21245052a930af623c6f503cf7"
size = 658677648
transitCdnKey = "NeUzkxb"
}
blurHash = "LfLh6Voa9NIW?wNF-ooL-;WAX8oy"
caption = ""
contentType = "image/png"
fileName = "TwOar"
height = 462
incrementalMac = <0891e5f69b302a9bf97a7ea0e423fd11>
incrementalMacChunkSize = 2048
width = 2972
}
email = [
Email {
label = ""
type = Type.MOBILE
value_ = "[email protected]"
},
Email {
label = "tWAZn"
type = Type.WORK
value_ = "[email protected]"
}
]
name = Name {
familyName = "wSQuECQWuuuEFC"
givenName = "iJZOYWfDTgpIJq"
}
number = [
Phone {
label = ""
type = Type.MOBILE
value_ = "19325550110"
},
Phone {
label = "qmCdYWyYPnka"
type = Type.WORK
value_ = "447700900133"
}
]
organization = "pKBuwAHesX"
}
]
}
dateSent = 1680366577838
dateSent = 1688484601889
incoming = IncomingMessageDetails {
dateReceived = 1702291826270
dateServerSent = 1794124103202
Expand Down
Binary file modified test-cases/chat_item_contact_message_02.binproto
Binary file not shown.
84 changes: 67 additions & 17 deletions test-cases/chat_item_contact_message_02.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,82 @@ Frame {
contactMessage = ContactMessage {
contact = [
ContactAttachment {
address = [
PostalAddress {
city = ""
country = ""
label = ""
neighborhood = ""
postcode = ""
region = ""
street = "jrJToWuNQzhOBq"
type = Type.WORK
},
PostalAddress {
city = "YQcczeJZd"
country = "fnyqwIJn"
label = "nZhuXJWXD"
neighborhood = "rOHZwwEoKI"
pobox = "ldxrj"
postcode = "bdigdRgXvkkw"
region = "fCpzjVLQFQh"
street = "unEEaAnFRLrvz"
type = Type.CUSTOM
}
]
avatar = FilePointer {
backupLocator = BackupLocator {
cdnNumber = 3
digest = <14d067b00a9b72659c04a5715eff403d>
key = <8eb83f1ec7d6521b7624aafb8f19d75e>
mediaName = "14d067b00a9b72659c04a5715eff403d"
size = 2122135182
transitCdnKey = "ISQpKbdZI"
transitCdnNumber = 2
cdnNumber = 2
digest = <8eb83f1ec7d6521b7624aafb8f19d75e>
key = <842db2adbe12faf29a852ad28dafc528>
mediaName = "8eb83f1ec7d6521b7624aafb8f19d75e"
size = 1518066505
transitCdnKey = "QSFzJCDXD"
}
blurHash = "LGG*f,-i.l-o?G$~?Zt7pHN1=tE3"
caption = "YOffzkwP"
contentType = "image/gif"
fileName = "eyxBcYxd"
height = 2696
width = 895
blurHash = "LfLh6Voa9NIW?wNF-ooL-;WAX8oy"
contentType = "image/png"
fileName = "wPOZvhLDS"
height = 4021
incrementalMac = <591eeb9b35c876bc7f5b1be8870f7902>
incrementalMacChunkSize = 2048
width = 2502
}
email = [
Email {
label = ""
type = Type.MOBILE
value_ = "[email protected]"
},
Email {
label = "VzsXSlnJDCHS"
type = Type.WORK
value_ = "[email protected]"
}
]
name = Name {
familyName = "CqQNEWGrAzrHY"
givenName = "SkLQGER"
familyName = "wSQuECQWuuuEFC"
givenName = "iJZOYWfDTgpIJq"
middleName = "FXMOBqmCd"
prefix = "IBHCZ"
suffix = "nSfTgFokLHLmtL"
}
organization = "yyKbzaMMpNLPKQ"
number = [
Phone {
label = ""
type = Type.MOBILE
value_ = "447700900496"
},
Phone {
label = "KGTWpTUETYz"
type = Type.WORK
value_ = "447700900571"
}
]
organization = "AUJhqwqw"
}
]
}
dateSent = 1688484601889
dateSent = 1680366577838
outgoing = OutgoingMessageDetails {
sendStatus = [
SendStatus {
Expand Down
Binary file modified test-cases/chat_item_contact_message_03.binproto
Binary file not shown.
Loading

0 comments on commit 98dbb66

Please sign in to comment.