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 18, 2024
1 parent 316e753 commit e855eb1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
45 changes: 39 additions & 6 deletions Tests/BluetoothTests/AttributeProtocolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,25 @@ final class AttributeProtocolTests: XCTestCase {
}
}

func testReadByGroupType() {
func testReadByGroupTypeRequest() {

do {

let data = Data([0x10, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x28])

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

XCTAssert(pdu.startHandle == 0x0001)
XCTAssert(pdu.endHandle == 0xFFFF)
XCTAssert(pdu.type == .bit16(0x2800))
XCTAssert(pdu.data == data)
XCTAssertEqual(pdu.dataLength, data.count)

// correct values
XCTAssertEqual(pdu.type, BluetoothUUID.primaryService)
XCTAssertEqual(pdu.type, .bit16(0x2800))
}

do {

Expand All @@ -167,10 +185,6 @@ final class AttributeProtocolTests: XCTestCase {
XCTAssert(pdu.type == .bit16(0x0028))
XCTAssert(pdu.data == data)
XCTAssertEqual(pdu.dataLength, data.count)

// correct values
//XCTAssert(pdu.type == GATTUUID.PrimaryService.uuid, "\(pdu.type)")
//XCTAssert(pdu.type == .bit16(0x2800))
}

do {
Expand Down Expand Up @@ -203,6 +217,9 @@ final class AttributeProtocolTests: XCTestCase {
XCTAssertEqual(decoded.data, pdu.data)
XCTAssertEqual(decoded.dataLength, data.count)
}
}

func testReadByGroupTypeResponse() {

do {

Expand Down Expand Up @@ -293,7 +310,23 @@ final class AttributeProtocolTests: XCTestCase {
}
}

func testReadByType() {
func testReadByTypeRequest() {

// GATT database hash
// Read by Type (2B2A) (1 - 65535)
let data = Data([0x08, 0x01, 0x00, 0xFF, 0xFF, 0x2A, 0x2B])

guard let value = ATTReadByTypeRequest(data: data) else {
XCTFail()
return
}

XCTAssertEqual(value.startHandle, 1)
XCTAssertEqual(value.endHandle, 0xFFFF)
XCTAssertEqual(value.attributeType, .bit16(0x2B2A))
}

func testReadByTypeResponse() {

typealias DeclarationAttribute = GATTDatabase<Data>.CharacteristicDeclarationAttribute

Expand Down
2 changes: 1 addition & 1 deletion Tests/BluetoothTests/GATTDatabaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension GATTDatabase {
for attribute in self {

let value: String = BluetoothUUID(data: attribute.value)?.littleEndian.description
?? String(utf8: attribute.value)
?? ((attribute.value.count > 1) ? String(utf8: attribute.value) : attribute.value.toHexadecimal())
?? attribute.value.toHexadecimal()

print("\(attribute.handle) - \(attribute.uuid)")
Expand Down

0 comments on commit e855eb1

Please sign in to comment.