Skip to content

Commit 53ab451

Browse files
committed
Check iBeacon fields against hand-computed values
1 parent eb99aeb commit 53ab451

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

Tests/BluetoothExplorerPluginEngineTests/IBeaconPluginTests.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// BluetoothExplorerPluginEngineTests
44
//
55
// Exercises the advertisement (manufacturer-data) path end to end: the bundled Embedded Swift
6-
// iBeacon module runs under the interpreter and its output is diffed field-by-field against
7-
// NativeIBeaconParser. This is the only coverage of `bleplug_parse_manufacturer`.
6+
// iBeacon module runs under the interpreter and its decoded fields are checked against
7+
// hand-computed values. This is the only coverage of `bleplug_parse_manufacturer`.
88
//
99

1010
import Foundation
@@ -57,10 +57,9 @@ struct IBeaconPluginTests {
5757
#expect(result.fields.first(where: { $0.key == "uuid" })?.value == .uuid(expectedUUID))
5858
}
5959

60-
@Test("WASM output matches the native parser field for field")
61-
func matchesNativeParser() async throws {
60+
@Test("Decodes major, minor and measured power across values")
61+
func decodesFields() async throws {
6262
let plugin = try loadPlugin()
63-
let native = NativeIBeaconParser()
6463

6564
let cases: [(UInt16, UInt16, Int8)] = [
6665
(0, 0, 0),
@@ -75,24 +74,18 @@ struct IBeaconPluginTests {
7574
companyID: 0x004C,
7675
payload: payload(major: major, minor: minor, measuredPower: power)
7776
)
78-
let wasmResult = try #require(await plugin.parse(request), "wasm declined \(major)/\(minor)")
79-
let nativeResult = try #require(await native.parse(request))
80-
81-
#expect(wasmResult.title == nativeResult.title, "major \(major)")
82-
#expect(wasmResult.fields.count == nativeResult.fields.count, "major \(major)")
83-
for (wasmField, nativeField) in zip(wasmResult.fields, nativeResult.fields) {
84-
#expect(wasmField.key == nativeField.key)
85-
#expect(wasmField.label == nativeField.label)
86-
#expect(wasmField.value == nativeField.value, "field \(wasmField.key), major \(major)")
87-
#expect(wasmField.unit == nativeField.unit)
88-
}
77+
let result = try #require(await plugin.parse(request), "declined \(major)/\(minor)")
78+
#expect(result.title == "iBeacon", "major \(major)")
79+
#expect(result.fields.first { $0.key == "major" }?.value == .uint(UInt64(major)), "major \(major)")
80+
#expect(result.fields.first { $0.key == "minor" }?.value == .uint(UInt64(minor)), "minor \(minor)")
81+
#expect(result.fields.first { $0.key == "tx_power" }?.value == .int(Int64(power)), "power \(power)")
82+
#expect(result.fields.first { $0.key == "tx_power" }?.unit == "dBm")
8983
}
9084
}
9185

92-
@Test("Non-iBeacon Apple payloads are declined, like the native parser")
86+
@Test("Non-iBeacon Apple payloads are declined")
9387
func declinesNonBeacon() async throws {
9488
let plugin = try loadPlugin()
95-
let native = NativeIBeaconParser()
9689

9790
// Apple uses this company id for many formats; only 0x02/0x15 is an iBeacon.
9891
let notBeacons: [Data] = [
@@ -104,8 +97,7 @@ struct IBeaconPluginTests {
10497
]
10598
for data in notBeacons {
10699
let request = ParseRequest(kind: .manufacturerData, companyID: 0x004C, payload: data)
107-
#expect(await plugin.parse(request) == nil, "wasm accepted \(data as NSData)")
108-
#expect(await native.parse(request) == nil, "native accepted \(data as NSData)")
100+
#expect(await plugin.parse(request) == nil, "accepted \(data as NSData)")
109101
}
110102
}
111103

0 commit comments

Comments
 (0)