mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 04:45:20 +00:00
Raise protocol coverage to 99 percent (#1058)
* Expand protocol coverage with edge-case tests * Stabilize read receipt transport test * Stabilize BLE duplicate packet test --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -44,4 +44,33 @@ final class BitchatFilePacketTests: XCTestCase {
|
||||
XCTAssertEqual(decoded.fileSize, UInt64(content.count))
|
||||
XCTAssertEqual(decoded.content, content)
|
||||
}
|
||||
|
||||
func testDecodeSupportsLegacyEightByteFileSizeTLV() throws {
|
||||
let content = Data([0x01, 0x02, 0x03, 0x04])
|
||||
var data = Data()
|
||||
|
||||
data.append(0x02)
|
||||
data.append(contentsOf: [0x00, 0x08])
|
||||
data.append(contentsOf: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00])
|
||||
data.append(0x04)
|
||||
data.append(contentsOf: [0x00, 0x00, 0x00, 0x04])
|
||||
data.append(content)
|
||||
|
||||
let decoded = try XCTUnwrap(BitchatFilePacket.decode(data))
|
||||
XCTAssertEqual(decoded.fileSize, 256)
|
||||
XCTAssertEqual(decoded.content, content)
|
||||
}
|
||||
|
||||
func testDecodeUsesContentCountWhenFileSizeTLVIsMissing() throws {
|
||||
let content = Data([0xAA, 0xBB, 0xCC])
|
||||
var data = Data()
|
||||
|
||||
data.append(0x04)
|
||||
data.append(contentsOf: [0x00, 0x00, 0x00, 0x03])
|
||||
data.append(content)
|
||||
|
||||
let decoded = try XCTUnwrap(BitchatFilePacket.decode(data))
|
||||
XCTAssertEqual(decoded.fileSize, UInt64(content.count))
|
||||
XCTAssertEqual(decoded.content, content)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user