@capacitor-community/bluetooth-le 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ import XCTest
2
+ import CoreBluetooth
3
+ @testable import BluetoothLe
4
+
5
+ class ScanFiltersTests: XCTestCase {
6
+
7
+ // MARK: - Manufacturer Data Filter Tests
8
+
9
+ func testManufacturerDataFilter_InvalidMaskLength() {
10
+ // Test that when mask.count != dataPrefix.count, the filter is skipped
11
+ // and returns false (no match)
12
+
13
+ // Create manufacturer data: 2 bytes company ID + 4 bytes payload
14
+ var manufacturerData = Data()
15
+ manufacturerData.append(contentsOf: [0x4C, 0x00]) // Apple company ID (0x004C in little-endian)
16
+ manufacturerData.append(contentsOf: [0x01, 0x02, 0x03, 0x04]) // 4 bytes payload
17
+
18
+ let advertisementData: [String: Any] = [
19
+ CBAdvertisementDataManufacturerDataKey: manufacturerData
20
+ ]
21
+
22
+ // Create filter with dataPrefix of 4 bytes but mask of only 2 bytes
23
+ // This should be skipped due to invalid mask length
24
+ let dataPrefix = Data([0x01, 0x02, 0x03, 0x04]) // 4 bytes
25
+ let mask = Data([0xFF, 0xFF]) // Only 2 bytes - invalid!
26
+
27
+ let filter = ManufacturerDataFilter(
28
+ companyIdentifier: 0x004C,
29
+ dataPrefix: dataPrefix,
30
+ mask: mask
31
+ )
32
+
33
+ // Should return false because the filter is skipped due to invalid mask
34
+ let result = ScanFilterUtils.passesManufacturerDataFilter(advertisementData, filters: [filter])
35
+ XCTAssertFalse(result, "Should return false when mask length doesn't match dataPrefix length")
36
+ }
37
+
38
+ func testManufacturerDataFilter_ValidMaskLength() {
39
+ // Test the valid case where mask and dataPrefix have the same length
40
+ var manufacturerData = Data()
41
+ manufacturerData.append(contentsOf: [0x4C, 0x00]) // Apple company ID
42
+ manufacturerData.append(contentsOf: [0x01, 0x02, 0x03, 0x04])
43
+
44
+ let advertisementData: [String: Any] = [
45
+ CBAdvertisementDataManufacturerDataKey: manufacturerData
46
+ ]
47
+
48
+ // Mask and dataPrefix have the same length - should work correctly
49
+ let dataPrefix = Data([0x01, 0x02, 0x03, 0x04])
50
+ let mask = Data([0xFF, 0xFF, 0xFF, 0xFF]) // Same length as dataPrefix
51
+
52
+ let filter = ManufacturerDataFilter(
53
+ companyIdentifier: 0x004C,
54
+ dataPrefix: dataPrefix,
55
+ mask: mask
56
+ )
57
+
58
+ let result = ScanFilterUtils.passesManufacturerDataFilter(advertisementData, filters: [filter])
59
+ XCTAssertTrue(result, "Should match when mask and dataPrefix have same length")
60
+ }
61
+
62
+ func testManufacturerDataFilter_NoMask() {
63
+ // Test without a mask - should use simple prefix matching
64
+ var manufacturerData = Data()
65
+ manufacturerData.append(contentsOf: [0x4C, 0x00])
66
+ manufacturerData.append(contentsOf: [0x01, 0x02, 0x03, 0x04])
67
+
68
+ let advertisementData: [String: Any] = [
69
+ CBAdvertisementDataManufacturerDataKey: manufacturerData
70
+ ]
71
+
72
+ let dataPrefix = Data([0x01, 0x02])
73
+ let filter = ManufacturerDataFilter(
74
+ companyIdentifier: 0x004C,
75
+ dataPrefix: dataPrefix,
76
+ mask: nil // No mask
77
+ )
78
+
79
+ let result = ScanFilterUtils.passesManufacturerDataFilter(advertisementData, filters: [filter])
80
+ XCTAssertTrue(result, "Should match with prefix matching when no mask is provided")
81
+ }
82
+
83
+ // MARK: - Service Data Filter Tests
84
+
85
+ func testServiceDataFilter_InvalidMaskLength() {
86
+ // Test that when mask.count != dataPrefix.count, the filter is skipped
87
+ // and returns false (no match)
88
+
89
+ let serviceUUID = CBUUID(string: "1234")
90
+ let serviceData = Data([0x01, 0x02, 0x03, 0x04]) // 4 bytes
91
+
92
+ let advertisementData: [String: Any] = [
93
+ CBAdvertisementDataServiceDataKey: [serviceUUID: serviceData]
94
+ ]
95
+
96
+ // Create filter with dataPrefix of 4 bytes but mask of only 2 bytes
97
+ // This should be skipped due to invalid mask length
98
+ let dataPrefix = Data([0x01, 0x02, 0x03, 0x04]) // 4 bytes
99
+ let mask = Data([0xFF, 0xFF]) // Only 2 bytes - invalid!
100
+
101
+ let filter = ServiceDataFilter(
102
+ serviceUuid: serviceUUID,
103
+ dataPrefix: dataPrefix,
104
+ mask: mask
105
+ )
106
+
107
+ // Should return false because the filter is skipped due to invalid mask
108
+ let result = ScanFilterUtils.passesServiceDataFilter(advertisementData, filters: [filter])
109
+ XCTAssertFalse(result, "Should return false when mask length doesn't match dataPrefix length")
110
+ }
111
+
112
+ func testServiceDataFilter_ValidMaskLength() {
113
+ // Test the valid case where mask and dataPrefix have the same length
114
+ let serviceUUID = CBUUID(string: "1234")
115
+ let serviceData = Data([0x01, 0x02, 0x03, 0x04])
116
+
117
+ let advertisementData: [String: Any] = [
118
+ CBAdvertisementDataServiceDataKey: [serviceUUID: serviceData]
119
+ ]
120
+
121
+ let dataPrefix = Data([0x01, 0x02, 0x03, 0x04])
122
+ let mask = Data([0xFF, 0xFF, 0xFF, 0xFF]) // Same length
123
+
124
+ let filter = ServiceDataFilter(
125
+ serviceUuid: serviceUUID,
126
+ dataPrefix: dataPrefix,
127
+ mask: mask
128
+ )
129
+
130
+ let result = ScanFilterUtils.passesServiceDataFilter(advertisementData, filters: [filter])
131
+ XCTAssertTrue(result, "Should match when mask and dataPrefix have same length")
132
+ }
133
+
134
+ func testServiceDataFilter_NoMask() {
135
+ // Test without a mask
136
+ let serviceUUID = CBUUID(string: "1234")
137
+ let serviceData = Data([0x01, 0x02, 0x03, 0x04])
138
+
139
+ let advertisementData: [String: Any] = [
140
+ CBAdvertisementDataServiceDataKey: [serviceUUID: serviceData]
141
+ ]
142
+
143
+ let dataPrefix = Data([0x01, 0x02])
144
+ let filter = ServiceDataFilter(
145
+ serviceUuid: serviceUUID,
146
+ dataPrefix: dataPrefix,
147
+ mask: nil
148
+ )
149
+
150
+ let result = ScanFilterUtils.passesServiceDataFilter(advertisementData, filters: [filter])
151
+ XCTAssertTrue(result, "Should match with prefix matching when no mask is provided")
152
+ }
153
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/bluetooth-le",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Capacitor plugin for Bluetooth Low Energy ",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -8,7 +8,7 @@
8
8
  "unpkg": "dist/plugin.js",
9
9
  "scripts": {
10
10
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
11
- "verify:ios": "xcodebuild -scheme CapacitorCommunityBluetoothLe -destination generic/platform=iOS",
11
+ "verify:ios": "xcodebuild clean build test -scheme CapacitorCommunityBluetoothLe -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.5'",
12
12
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
13
13
  "verify:web": "npm run test:coverage && npm run build",
14
14
  "lint": "npm run eslint && npm run prettier -- --check && npm run lint:ios",
@@ -27,7 +27,6 @@
27
27
  "test": "jest",
28
28
  "test:coverage": "jest --coverage",
29
29
  "test:watch": "jest --watch",
30
- "test:ios": "xcodebuild test -scheme CapacitorCommunityBluetoothLe -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.5'",
31
30
  "version:dev": "npm version --no-git-tag-version $(git describe)",
32
31
  "release": "standard-version",
33
32
  "release:minor": "standard-version -r minor",