mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:25:19 +00:00
Convert the remaining tests to Swift Testing (#781)
* SwiftTesting: NoiseProtocolTests + BinaryProtocolPaddingTests * SwiftTesting: `NotificationStreamAssemblerTests` * SwiftTesting: `NostrProtocolTests` * SwiftTesting: `BinaryProtocolTests` * SwiftTesting: `PeerIDTests` * SwiftTesting: `BLEServiceTests` * SwiftTesting: `CommandProcessorTests` * SwiftTesting: `GCSFilterTests` * SwiftTesting: `GeohashBookmarksStoreTests` * Remove `peerID` test constants * Remove PeerID + String interop from tests * Refactor IntegrationTests to extract state management * Refactor global state management of MockBLEService * NoiseProtocolSwiftTests: `actor` -> `struct` * Remove measurement tests w/ no benchmark * `NoiseProtocolSwiftTests` -> `NoiseProtocolTests` * SwiftTesting: `LocationChannelsTests` * SwiftTesting: `GossipSyncManagerTests` * SwiftTesting: `LocationNotesManagerTests` * Global `sleep` function for tests * SwiftTesting: `IntegrationTests` --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -5,30 +5,29 @@
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Testing
|
||||
@testable import bitchat
|
||||
|
||||
final class BinaryProtocolPaddingTests: XCTestCase {
|
||||
func test_padded_vs_unpadded_length() throws {
|
||||
struct BinaryProtocolPaddingTests {
|
||||
@Test func padded_vs_unpadded_length() throws {
|
||||
// Use helper to create a small test packet
|
||||
let packet = TestHelpers.createTestPacket()
|
||||
guard let padded = BinaryProtocol.encode(packet, padding: true) else { return XCTFail("encode padded") }
|
||||
guard let unpadded = BinaryProtocol.encode(packet, padding: false) else { return XCTFail("encode unpadded") }
|
||||
XCTAssertGreaterThanOrEqual(padded.count, unpadded.count, "Padded frame should be >= unpadded")
|
||||
let padded = try #require(BinaryProtocol.encode(packet, padding: true), "encode padded")
|
||||
let unpadded = try #require(BinaryProtocol.encode(packet, padding: false), "encode unpadded")
|
||||
#expect(padded.count >= unpadded.count, "Padded frame should be >= unpadded")
|
||||
}
|
||||
|
||||
func test_decode_padded_and_unpadded_round_trip() throws {
|
||||
@Test func decode_padded_and_unpadded_round_trip() throws {
|
||||
let packet = TestHelpers.createTestPacket()
|
||||
// Padded
|
||||
guard let padded = BinaryProtocol.encode(packet, padding: true) else { return XCTFail("encode padded") }
|
||||
guard let dec1 = BinaryProtocol.decode(padded) else { return XCTFail("decode padded") }
|
||||
XCTAssertEqual(dec1.type, packet.type)
|
||||
XCTAssertEqual(dec1.payload, packet.payload)
|
||||
// Unpadded
|
||||
guard let unpadded = BinaryProtocol.encode(packet, padding: false) else { return XCTFail("encode unpadded") }
|
||||
guard let dec2 = BinaryProtocol.decode(unpadded) else { return XCTFail("decode unpadded") }
|
||||
XCTAssertEqual(dec2.type, packet.type)
|
||||
XCTAssertEqual(dec2.payload, packet.payload)
|
||||
|
||||
let padded = try #require(BinaryProtocol.encode(packet, padding: true), "encode padded")
|
||||
let dec1 = try #require(BinaryProtocol.decode(padded), "decode padded")
|
||||
#expect(dec1.type == packet.type)
|
||||
#expect(dec1.payload == packet.payload)
|
||||
|
||||
let unpadded = try #require(BinaryProtocol.encode(packet, padding: false), "encode unpadded")
|
||||
let dec2 = try #require(BinaryProtocol.decode(unpadded), "decode unpadded")
|
||||
#expect(dec2.type == packet.type)
|
||||
#expect(dec2.payload == packet.payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user