Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed May 13, 2023
1 parent e38e75f commit e5eb0d4
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions Tests/BluetoothLinuxTests/L2CAPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,40 @@ final class L2CAPTests: XCTestCase {
return
}
let address = try await controller.readDeviceAddress()
NSLog("Will create server socket")
let server = try await BluetoothLinux.L2CAPSocket.lowEnergyServer(
NSLog("Will create server socket \(address)")
let serverSocket = try await BluetoothLinux.L2CAPSocket.lowEnergyServer(
address: address
)
NSLog("Created server socket")
let newConnection = try await server.accept()
let newConnection = try await serverSocket.accept()
NSLog("Server Connected")
let recievedData = try await newConnection.recieve(256)
NSLog("Server recieved")
XCTAssertEqual(recievedData, Data("test-client-1234".utf8))
try await newConnection.send(Data("test-server-1234".utf8))
NSLog("Server sent")
try? await Task.sleep(nanoseconds: 1_000_000_000)
}

func testClientConnection() async throws {
guard let serverAddress = ProcessInfo.processInfo.environment["SWIFT_BLUETOOTH_HARDWARE_TEST_CLIENT"].flatMap({ BluetoothAddress(rawValue: $0) }) else {
return
}
guard let controller = await BluetoothLinux.HostController.default else {
XCTFail()
return
}
let address = try await controller.readDeviceAddress()
NSLog("Will create client socket")
let client = try await BluetoothLinux.L2CAPSocket.lowEnergyClient(
address: address,
destination: serverAddress,
type: .public
let characteristic = GATTAttribute.Characteristic(
uuid: GATTManufacturerNameString.uuid,
value: GATTManufacturerNameString(rawValue: "PureSwift").data,
permissions: [.read],
properties: [.read],
descriptors: []
)
NSLog("Client Connected")
try await client.send(Data("test-client-1234".utf8))
NSLog("Client sent")
let recievedData = try await client.recieve(256)
NSLog("Client recieved")
XCTAssertEqual(recievedData, Data("test-server-1234".utf8))
try? await Task.sleep(nanoseconds: 1_000_000_000)
let service = GATTAttribute.Service(
uuid: .deviceInformation,
primary: true,
characteristics: [characteristic]
)
let database = GATTDatabase(services: [service])
var logs = [String]()
let server = await GATTServer(
socket: newConnection,
maximumTransmissionUnit: .max,
maximumPreparedWrites: 1000,
database: database,
log: {
NSLog("Server: \($0)")
logs.append($0)
}
)
//
for await event in newConnection.event {
NSLog("Server: \(event)")
}
}
}

0 comments on commit e5eb0d4

Please sign in to comment.