|
|
@ -32,20 +32,16 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
error?.deallocate()
|
|
|
|
error?.deallocate()
|
|
|
|
|
|
|
|
|
|
|
|
// Empty contacts shouldn't have an existing contact
|
|
|
|
// Empty contacts shouldn't have an existing contact
|
|
|
|
var definitelyRealId: [CChar] = "055000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
let definitelyRealId: String = "055000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
.bytes
|
|
|
|
var cDefinitelyRealId: [CChar] = definitelyRealId.cArray
|
|
|
|
.map { CChar(bitPattern: $0) }
|
|
|
|
|
|
|
|
var oneToOne1: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var oneToOne1: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
expect(convo_info_volatile_get_1to1(conf, &oneToOne1, &definitelyRealId)).to(beFalse())
|
|
|
|
expect(convo_info_volatile_get_1to1(conf, &oneToOne1, &cDefinitelyRealId)).to(beFalse())
|
|
|
|
expect(convo_info_volatile_size(conf)).to(equal(0))
|
|
|
|
expect(convo_info_volatile_size(conf)).to(equal(0))
|
|
|
|
|
|
|
|
|
|
|
|
var oneToOne2: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var oneToOne2: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
expect(convo_info_volatile_get_or_construct_1to1(conf, &oneToOne2, definitelyRealId))
|
|
|
|
expect(convo_info_volatile_get_or_construct_1to1(conf, &oneToOne2, &cDefinitelyRealId))
|
|
|
|
.to(beTrue())
|
|
|
|
.to(beTrue())
|
|
|
|
|
|
|
|
expect(String(libSessionVal: oneToOne2.session_id)).to(equal(definitelyRealId))
|
|
|
|
let oneToOne2SessionId: [CChar] = withUnsafeBytes(of: oneToOne2.session_id) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
expect(oneToOne2SessionId).to(equal(definitelyRealId.nullTerminated()))
|
|
|
|
|
|
|
|
expect(oneToOne2.last_read).to(equal(0))
|
|
|
|
expect(oneToOne2.last_read).to(equal(0))
|
|
|
|
expect(oneToOne2.unread).to(beFalse())
|
|
|
|
expect(oneToOne2.unread).to(beFalse())
|
|
|
|
|
|
|
|
|
|
|
@ -62,37 +58,37 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
|
|
|
|
|
|
|
|
var legacyGroup1: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
var legacyGroup1: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
var oneToOne3: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var oneToOne3: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
expect(convo_info_volatile_get_legacy_group(conf, &legacyGroup1, &definitelyRealId))
|
|
|
|
expect(convo_info_volatile_get_legacy_group(conf, &legacyGroup1, &cDefinitelyRealId))
|
|
|
|
.to(beFalse())
|
|
|
|
.to(beFalse())
|
|
|
|
expect(convo_info_volatile_get_1to1(conf, &oneToOne3, &definitelyRealId)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_get_1to1(conf, &oneToOne3, &cDefinitelyRealId)).to(beTrue())
|
|
|
|
expect(oneToOne3.last_read).to(equal(nowTimestampMs))
|
|
|
|
expect(oneToOne3.last_read).to(equal(nowTimestampMs))
|
|
|
|
|
|
|
|
|
|
|
|
expect(config_needs_push(conf)).to(beTrue())
|
|
|
|
expect(config_needs_push(conf)).to(beTrue())
|
|
|
|
expect(config_needs_dump(conf)).to(beTrue())
|
|
|
|
expect(config_needs_dump(conf)).to(beTrue())
|
|
|
|
|
|
|
|
|
|
|
|
var openGroupBaseUrl: [CChar] = "http://Example.ORG:5678".cArray
|
|
|
|
let openGroupBaseUrl: String = "http://Example.ORG:5678"
|
|
|
|
let openGroupBaseUrlResult: [CChar] = ("http://Example.ORG:5678"
|
|
|
|
var cOpenGroupBaseUrl: [CChar] = openGroupBaseUrl.cArray
|
|
|
|
.lowercased()
|
|
|
|
let openGroupBaseUrlResult: String = openGroupBaseUrl.lowercased()
|
|
|
|
.cArray +
|
|
|
|
// ("http://Example.ORG:5678"
|
|
|
|
[CChar](repeating: 0, count: (268 - openGroupBaseUrl.count))
|
|
|
|
// .lowercased()
|
|
|
|
)
|
|
|
|
// .cArray +
|
|
|
|
var openGroupRoom: [CChar] = "SudokuRoom".cArray
|
|
|
|
// [CChar](repeating: 0, count: (268 - openGroupBaseUrl.count))
|
|
|
|
let openGroupRoomResult: [CChar] = ("SudokuRoom"
|
|
|
|
// )
|
|
|
|
.lowercased()
|
|
|
|
let openGroupRoom: String = "SudokuRoom"
|
|
|
|
.cArray +
|
|
|
|
var cOpenGroupRoom: [CChar] = openGroupRoom.cArray
|
|
|
|
[CChar](repeating: 0, count: (65 - openGroupRoom.count))
|
|
|
|
let openGroupRoomResult: String = openGroupRoom.lowercased()
|
|
|
|
)
|
|
|
|
// ("SudokuRoom"
|
|
|
|
var openGroupPubkey: [UInt8] = Data(hex: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
|
|
|
|
// .lowercased()
|
|
|
|
|
|
|
|
// .cArray +
|
|
|
|
|
|
|
|
// [CChar](repeating: 0, count: (65 - openGroupRoom.count))
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
var cOpenGroupPubkey: [UInt8] = Data(hex: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
|
|
|
|
.bytes
|
|
|
|
.bytes
|
|
|
|
var community1: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
var community1: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
expect(convo_info_volatile_get_or_construct_community(conf, &community1, &openGroupBaseUrl, &openGroupRoom, &openGroupPubkey)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_get_or_construct_community(conf, &community1, &cOpenGroupBaseUrl, &cOpenGroupRoom, &cOpenGroupPubkey)).to(beTrue())
|
|
|
|
expect(withUnsafeBytes(of: community1.base_url) { [UInt8]($0) }
|
|
|
|
expect(String(libSessionVal: community1.base_url)).to(equal(openGroupBaseUrlResult))
|
|
|
|
.map { CChar($0) }
|
|
|
|
expect(String(libSessionVal: community1.room)).to(equal(openGroupRoomResult))
|
|
|
|
).to(equal(openGroupBaseUrlResult))
|
|
|
|
expect(Data(libSessionVal: community1.pubkey, count: 32).toHexString())
|
|
|
|
expect(withUnsafeBytes(of: community1.room) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
).to(equal(openGroupRoomResult))
|
|
|
|
|
|
|
|
expect(withUnsafePointer(to: community1.pubkey) { Data(bytes: $0, count: 32).toHexString() })
|
|
|
|
|
|
|
|
.to(equal("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
|
|
|
.to(equal("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
|
|
|
community1.unread = true
|
|
|
|
community1.unread = true
|
|
|
|
|
|
|
|
|
|
|
@ -106,7 +102,6 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
let seqno: Int64 = config_push(conf, &toPush, &toPushLen)
|
|
|
|
let seqno: Int64 = config_push(conf, &toPush, &toPushLen)
|
|
|
|
expect(toPush).toNot(beNil())
|
|
|
|
expect(toPush).toNot(beNil())
|
|
|
|
expect(seqno).to(equal(1))
|
|
|
|
expect(seqno).to(equal(1))
|
|
|
|
expect(toPushLen).to(equal(512))
|
|
|
|
|
|
|
|
toPush?.deallocate()
|
|
|
|
toPush?.deallocate()
|
|
|
|
|
|
|
|
|
|
|
|
// Pretend we uploaded it
|
|
|
|
// Pretend we uploaded it
|
|
|
@ -128,39 +123,30 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
expect(config_needs_push(conf2)).to(beFalse())
|
|
|
|
expect(config_needs_push(conf2)).to(beFalse())
|
|
|
|
|
|
|
|
|
|
|
|
var oneToOne4: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var oneToOne4: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
expect(convo_info_volatile_get_1to1(conf2, &oneToOne4, &definitelyRealId)).to(equal(true))
|
|
|
|
expect(convo_info_volatile_get_1to1(conf2, &oneToOne4, &cDefinitelyRealId)).to(equal(true))
|
|
|
|
expect(oneToOne4.last_read).to(equal(nowTimestampMs))
|
|
|
|
expect(oneToOne4.last_read).to(equal(nowTimestampMs))
|
|
|
|
expect(
|
|
|
|
expect(String(libSessionVal: oneToOne4.session_id)).to(equal(definitelyRealId))
|
|
|
|
withUnsafeBytes(of: oneToOne4.session_id) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
.nullTerminated()
|
|
|
|
|
|
|
|
).to(equal(definitelyRealId.nullTerminated()))
|
|
|
|
|
|
|
|
expect(oneToOne4.unread).to(beFalse())
|
|
|
|
expect(oneToOne4.unread).to(beFalse())
|
|
|
|
|
|
|
|
|
|
|
|
var community2: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
var community2: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
expect(convo_info_volatile_get_community(conf2, &community2, &openGroupBaseUrl, &openGroupRoom)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_get_community(conf2, &community2, &cOpenGroupBaseUrl, &cOpenGroupRoom)).to(beTrue())
|
|
|
|
expect(withUnsafeBytes(of: community2.base_url) { [UInt8]($0) }
|
|
|
|
expect(String(libSessionVal: community2.base_url)).to(equal(openGroupBaseUrlResult))
|
|
|
|
.map { CChar($0) }
|
|
|
|
expect(String(libSessionVal: community2.room)).to(equal(openGroupRoomResult))
|
|
|
|
).to(equal(openGroupBaseUrlResult))
|
|
|
|
expect(Data(libSessionVal: community2.pubkey, count: 32).toHexString())
|
|
|
|
expect(withUnsafeBytes(of: community2.room) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
).to(equal(openGroupRoomResult))
|
|
|
|
|
|
|
|
expect(withUnsafePointer(to: community2.pubkey) { Data(bytes: $0, count: 32).toHexString() })
|
|
|
|
|
|
|
|
.to(equal("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
|
|
|
.to(equal("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
|
|
|
community2.unread = true
|
|
|
|
community2.unread = true
|
|
|
|
|
|
|
|
|
|
|
|
var anotherId: [CChar] = "051111111111111111111111111111111111111111111111111111111111111111"
|
|
|
|
let anotherId: String = "051111111111111111111111111111111111111111111111111111111111111111"
|
|
|
|
.bytes
|
|
|
|
var cAnotherId: [CChar] = anotherId.cArray
|
|
|
|
.map { CChar(bitPattern: $0) }
|
|
|
|
|
|
|
|
var oneToOne5: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var oneToOne5: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
expect(convo_info_volatile_get_or_construct_1to1(conf2, &oneToOne5, &anotherId)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_get_or_construct_1to1(conf2, &oneToOne5, &cAnotherId)).to(beTrue())
|
|
|
|
|
|
|
|
oneToOne5.unread = true
|
|
|
|
convo_info_volatile_set_1to1(conf2, &oneToOne5)
|
|
|
|
convo_info_volatile_set_1to1(conf2, &oneToOne5)
|
|
|
|
|
|
|
|
|
|
|
|
var thirdId: [CChar] = "05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
|
|
|
|
let thirdId: String = "05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
|
|
|
|
.bytes
|
|
|
|
var cThirdId: [CChar] = thirdId.cArray
|
|
|
|
.map { CChar(bitPattern: $0) }
|
|
|
|
|
|
|
|
var legacyGroup2: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
var legacyGroup2: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
expect(convo_info_volatile_get_or_construct_legacy_group(conf2, &legacyGroup2, &thirdId)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_get_or_construct_legacy_group(conf2, &legacyGroup2, &cThirdId)).to(beTrue())
|
|
|
|
legacyGroup2.last_read = (nowTimestampMs - 50)
|
|
|
|
legacyGroup2.last_read = (nowTimestampMs - 50)
|
|
|
|
convo_info_volatile_set_legacy_group(conf2, &legacyGroup2)
|
|
|
|
convo_info_volatile_set_legacy_group(conf2, &legacyGroup2)
|
|
|
|
expect(config_needs_push(conf2)).to(beTrue())
|
|
|
|
expect(config_needs_push(conf2)).to(beTrue())
|
|
|
@ -239,23 +225,20 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
expect(config_needs_push(conf)).to(beFalse())
|
|
|
|
expect(config_needs_push(conf)).to(beFalse())
|
|
|
|
convo_info_volatile_erase_1to1(conf, &fourthId)
|
|
|
|
convo_info_volatile_erase_1to1(conf, &fourthId)
|
|
|
|
expect(config_needs_push(conf)).to(beFalse())
|
|
|
|
expect(config_needs_push(conf)).to(beFalse())
|
|
|
|
convo_info_volatile_erase_1to1(conf, &definitelyRealId)
|
|
|
|
convo_info_volatile_erase_1to1(conf, &cDefinitelyRealId)
|
|
|
|
expect(config_needs_push(conf)).to(beTrue())
|
|
|
|
expect(config_needs_push(conf)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_size(conf)).to(equal(3))
|
|
|
|
expect(convo_info_volatile_size(conf)).to(equal(3))
|
|
|
|
expect(convo_info_volatile_size_1to1(conf)).to(equal(1))
|
|
|
|
expect(convo_info_volatile_size_1to1(conf)).to(equal(1))
|
|
|
|
|
|
|
|
|
|
|
|
// Check the single-type iterators:
|
|
|
|
// Check the single-type iterators:
|
|
|
|
var seen1: [String] = []
|
|
|
|
var seen1: [String?] = []
|
|
|
|
var c1: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
var c1: convo_info_volatile_1to1 = convo_info_volatile_1to1()
|
|
|
|
let it1: OpaquePointer = convo_info_volatile_iterator_new_1to1(conf)
|
|
|
|
let it1: OpaquePointer = convo_info_volatile_iterator_new_1to1(conf)
|
|
|
|
|
|
|
|
|
|
|
|
while !convo_info_volatile_iterator_done(it1) {
|
|
|
|
while !convo_info_volatile_iterator_done(it1) {
|
|
|
|
expect(convo_info_volatile_it_is_1to1(it1, &c1)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_it_is_1to1(it1, &c1)).to(beTrue())
|
|
|
|
let sessionId: String = String(cString: withUnsafeBytes(of: c1.session_id) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
seen1.append(String(libSessionVal: c1.session_id))
|
|
|
|
.nullTerminated()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
seen1.append(sessionId)
|
|
|
|
|
|
|
|
convo_info_volatile_iterator_advance(it1)
|
|
|
|
convo_info_volatile_iterator_advance(it1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -264,18 +247,14 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
"051111111111111111111111111111111111111111111111111111111111111111"
|
|
|
|
"051111111111111111111111111111111111111111111111111111111111111111"
|
|
|
|
]))
|
|
|
|
]))
|
|
|
|
|
|
|
|
|
|
|
|
var seen2: [String] = []
|
|
|
|
var seen2: [String?] = []
|
|
|
|
var c2: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
var c2: convo_info_volatile_community = convo_info_volatile_community()
|
|
|
|
let it2: OpaquePointer = convo_info_volatile_iterator_new_communities(conf)
|
|
|
|
let it2: OpaquePointer = convo_info_volatile_iterator_new_communities(conf)
|
|
|
|
|
|
|
|
|
|
|
|
while !convo_info_volatile_iterator_done(it2) {
|
|
|
|
while !convo_info_volatile_iterator_done(it2) {
|
|
|
|
expect(convo_info_volatile_it_is_community(it2, &c2)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_it_is_community(it2, &c2)).to(beTrue())
|
|
|
|
let baseUrl: String = String(cString: withUnsafeBytes(of: c2.base_url) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
.nullTerminated()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seen2.append(baseUrl)
|
|
|
|
seen2.append(String(libSessionVal: c2.base_url))
|
|
|
|
convo_info_volatile_iterator_advance(it2)
|
|
|
|
convo_info_volatile_iterator_advance(it2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -284,18 +263,14 @@ class ConfigConvoInfoVolatileSpec: QuickSpec {
|
|
|
|
"http://example.org:5678"
|
|
|
|
"http://example.org:5678"
|
|
|
|
]))
|
|
|
|
]))
|
|
|
|
|
|
|
|
|
|
|
|
var seen3: [String] = []
|
|
|
|
var seen3: [String?] = []
|
|
|
|
var c3: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
var c3: convo_info_volatile_legacy_group = convo_info_volatile_legacy_group()
|
|
|
|
let it3: OpaquePointer = convo_info_volatile_iterator_new_legacy_groups(conf)
|
|
|
|
let it3: OpaquePointer = convo_info_volatile_iterator_new_legacy_groups(conf)
|
|
|
|
|
|
|
|
|
|
|
|
while !convo_info_volatile_iterator_done(it3) {
|
|
|
|
while !convo_info_volatile_iterator_done(it3) {
|
|
|
|
expect(convo_info_volatile_it_is_legacy_group(it3, &c3)).to(beTrue())
|
|
|
|
expect(convo_info_volatile_it_is_legacy_group(it3, &c3)).to(beTrue())
|
|
|
|
let groupId: String = String(cString: withUnsafeBytes(of: c3.group_id) { [UInt8]($0) }
|
|
|
|
|
|
|
|
.map { CChar($0) }
|
|
|
|
|
|
|
|
.nullTerminated()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seen3.append(groupId)
|
|
|
|
seen3.append(String(libSessionVal: c3.group_id))
|
|
|
|
convo_info_volatile_iterator_advance(it3)
|
|
|
|
convo_info_volatile_iterator_advance(it3)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|