Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 12, 2024
1 parent f78154d commit 81296ef
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions Tests/BluetoothTests/GATTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ final class GATTTests: XCTestCase {
// server
let serverAddress = BluetoothAddress.min
let clientAddress = BluetoothAddress.max
let serverSocket = try await TestL2CAPSocket.lowEnergyServer(
let serverSocket = try TestL2CAPSocket.lowEnergyServer(
address: serverAddress,
isRandom: false,
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand All @@ -131,7 +131,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand Down Expand Up @@ -441,13 +441,13 @@ final class GATTTests: XCTestCase {
// server
let serverAddress = BluetoothAddress.min
let clientAddress = BluetoothAddress.max
let serverSocket = try await TestL2CAPSocket.lowEnergyServer(
let serverSocket = try TestL2CAPSocket.lowEnergyServer(
address: serverAddress,
isRandom: false,
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand All @@ -459,7 +459,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand Down Expand Up @@ -594,7 +594,7 @@ final class GATTTests: XCTestCase {
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand Down Expand Up @@ -643,8 +643,8 @@ final class GATTTests: XCTestCase {

// validate GATT PDUs
let mockData = split(pdu: testPDUs.map { $1 })
let serverCache = await (server.connection.socket as! TestL2CAPSocket).cache
let clientCache = await clientSocket.cache
let serverCache = await server.connection.socket.cache
let clientCache = clientSocket.cache
XCTAssertEqual(serverCache, mockData.server)
XCTAssertEqual(clientCache, mockData.client)
}
Expand All @@ -668,13 +668,13 @@ final class GATTTests: XCTestCase {
// server
let serverAddress = BluetoothAddress.min
let clientAddress = BluetoothAddress.max
let serverSocket = try await TestL2CAPSocket.lowEnergyServer(
let serverSocket = try TestL2CAPSocket.lowEnergyServer(
address: serverAddress,
isRandom: false,
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand All @@ -686,7 +686,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand Down Expand Up @@ -759,13 +759,13 @@ final class GATTTests: XCTestCase {
// server
let serverAddress = BluetoothAddress.min
let clientAddress = BluetoothAddress.max
let serverSocket = try await TestL2CAPSocket.lowEnergyServer(
let serverSocket = try TestL2CAPSocket.lowEnergyServer(
address: serverAddress,
isRandom: false,
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand All @@ -777,7 +777,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand Down Expand Up @@ -878,7 +878,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand Down Expand Up @@ -952,7 +952,7 @@ final class GATTTests: XCTestCase {
XCTAssertEqual(finalServerMTU, .default)
XCTAssertEqual(finalClientMTU, .default)
}
/*

func testNotification() async throws {

func test(with characteristics: [GATTAttribute<Data>.Characteristic], newData: [Data]) async throws {
Expand All @@ -968,13 +968,13 @@ final class GATTTests: XCTestCase {
// server
let serverAddress = BluetoothAddress.min
let clientAddress = BluetoothAddress.max
let serverSocket = try await TestL2CAPSocket.lowEnergyServer(
let serverSocket = try TestL2CAPSocket.lowEnergyServer(
address: serverAddress,
isRandom: false,
backlog: 1
)
let serverAcceptTask = Task<GATTServer, Error> {
let newConnection = try await serverSocket.accept()
let newConnection = try serverSocket.accept()
print("GATTServer: New connection")
return await GATTServer(
socket: newConnection,
Expand All @@ -986,7 +986,7 @@ final class GATTTests: XCTestCase {
}

// client
let clientSocket = try await TestL2CAPSocket.lowEnergyClient(
let clientSocket = try TestL2CAPSocket.lowEnergyClient(
address: clientAddress,
destination: serverAddress,
isRandom: false
Expand All @@ -998,6 +998,19 @@ final class GATTTests: XCTestCase {
)
let server = try await serverAcceptTask.value

Task { [weak client] in
while let client {
try await Task.sleep(nanoseconds: 10_000)
try await client.run()
}
}
Task { [weak server] in
while let server {
try await Task.sleep(nanoseconds: 10_000)
try await server.run()
}
}

// discover service
let foundServices = try await client.discoverPrimaryServices(by: service.uuid)
guard foundServices.count == 1,
Expand Down Expand Up @@ -1040,7 +1053,7 @@ final class GATTTests: XCTestCase {
await server.writeValue(data, forCharacteristic: notificationCharacteristic.uuid)
}

try await Task.sleep(nanoseconds: 1_000_000_000)
try await Task.sleep(nanoseconds: 1_000_000)

// stop notifications
try await client.clientCharacteristicConfiguration(
Expand Down Expand Up @@ -1069,7 +1082,7 @@ final class GATTTests: XCTestCase {
//try await test(with: [TestProfile.Indicate], newData: [Data(repeating: 1, count: 20)])
//try await test(with: [TestProfile.Notify], newData: [Data(repeating: 1, count: Int(ATTMaximumTransmissionUnit.max.rawValue))])
//try await test(with: [TestProfile.Indicate], newData: [Data(repeating: 1, count: Int(ATTMaximumTransmissionUnit.max.rawValue))])
}*/
}
}

private extension GATTTests {
Expand Down

0 comments on commit 81296ef

Please sign in to comment.