Skip to content

Commit

Permalink
Working on ATT PDU unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Dec 3, 2017
1 parent 22bf52d commit f1ef54b
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions Tests/BluetoothTests/BluetoothTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,21 @@ final class BluetoothTests: XCTestCase {
guard let errorResponse = ATTErrorResponse(byteValue: data)
else { XCTFail("Could not parse"); return }

XCTAssert(errorResponse.errorCode == .AttributeNotFound)
XCTAssert(errorResponse.requestOpcode == .ReadByGroupTypeRequest)
XCTAssert(errorResponse.attributeHandle == 0x0001)
XCTAssert(errorResponse.errorCode == .AttributeNotFound)
}

do {

let data: [UInt8] = [1, 8, 0, 0, 6]

guard let errorResponse = ATTErrorResponse(byteValue: data)
else { XCTFail("Could not parse"); return }

XCTAssert(errorResponse.requestOpcode == .ReadByTypeRequest)
XCTAssert(errorResponse.attributeHandle == 0x0000)
XCTAssert(errorResponse.errorCode == .RequestNotSupported)
}

do {
Expand All @@ -183,37 +195,38 @@ final class BluetoothTests: XCTestCase {

do {

let data: [UInt8] = [16, 1, 0, 255, 255, 40, 0]
let data: [UInt8] = [3, 23, 0]

guard let pdu = ATTReadByGroupTypeRequest(byteValue: data)
guard let pdu = ATTMaximumTransmissionUnitResponse(byteValue: data)
else { XCTFail("Could not parse"); return }

XCTAssert(pdu.startHandle == 0x0001)
XCTAssert(pdu.endHandle == 0xFFFF)
XCTAssert(pdu.type == GATT.UUID.PrimaryService.toUUID(), "\(pdu.type)")
XCTAssert(pdu.type == .bit16(0x2800))
XCTAssert(pdu.serverMTU == 23)
}

do {

let data: [UInt8] = [1, 8, 0, 0, 6]
// bad response
let data: [UInt8] = [16, 1, 0, 255, 255, 40, 0]

guard let errorResponse = ATTErrorResponse(byteValue: data)
guard let pdu = ATTReadByGroupTypeRequest(byteValue: data)
else { XCTFail("Could not parse"); return }

XCTAssert(errorResponse.requestOpcode == .ReadByTypeRequest)
XCTAssert(errorResponse.attributeHandle == 0x0000)
XCTAssert(errorResponse.errorCode == .RequestNotSupported)
XCTAssert(pdu.startHandle == 0x0001)
XCTAssert(pdu.endHandle == 0xFFFF)
//XCTAssert(pdu.type == GATT.UUID.PrimaryService.toUUID(), "\(pdu.type)")
//XCTAssert(pdu.type == .bit16(0x2800))
XCTAssert(pdu.type == .bit16(0x0028))
}

do {

let data: [UInt8] = [3, 23, 0]
let data: [UInt8] = [16, 1, 0, 255, 255, 40, 0]

guard let pdu = ATTMaximumTransmissionUnitResponse(byteValue: data)
guard let pdu = ATTReadByGroupTypeRequest(byteValue: data)
else { XCTFail("Could not parse"); return }

XCTAssert(pdu.serverMTU == 23)
XCTAssert(pdu.startHandle == 0x0001)
XCTAssert(pdu.endHandle == 0xFFFF)
}
}
}
Expand Down

0 comments on commit f1ef54b

Please sign in to comment.