Skip to content

Commit

Permalink
Merge pull request #29 from NordicSemiconductor/develop
Browse files Browse the repository at this point in the history
Version 0.12.0
  • Loading branch information
philips77 authored Oct 2, 2020
2 parents 1562143 + c710301 commit af28b32
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 303 deletions.
10 changes: 7 additions & 3 deletions CoreBluetoothMock.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CoreBluetoothMock'
s.version = '0.11.1'
s.version = '0.12.0'
s.summary = 'Mocking library for CoreBluetooth.'

s.description = <<-DESC
Expand All @@ -14,12 +14,16 @@ device and test the app on simulator.
s.source = { :git => 'https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/nordictweets'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.13'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'
s.swift_versions = ['4.2', '5.0', '5.1', '5.2']
s.swift_versions = ['4.2', '5.0', '5.1', '5.2', '5.3']
s.pod_target_xcconfig = { 'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES' }

s.source_files = 'CoreBluetoothMock/Classes/**/*'

# Regarding the lines below see: https://stackoverflow.com/a/63955114/2115352
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
end
64 changes: 32 additions & 32 deletions CoreBluetoothMock/Classes/CBMCentralManagerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import CoreBluetooth

public class CBMCentralManagerMock: NSObject, CBMCentralManager {
open class CBMCentralManagerMock: NSObject, CBMCentralManager {
/// Mock RSSI deviation.
///
/// Returned RSSI values will be in range
Expand Down Expand Up @@ -67,11 +67,11 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public weak var delegate: CBMCentralManagerDelegate?
public var state: CBMManagerState {
open weak var delegate: CBMCentralManagerDelegate?
open var state: CBMManagerState {
return initialized ? CBMCentralManagerMock.managerState : .unknown
}
public private(set) var isScanning: Bool
open private(set) var isScanning: Bool
private var scanFilter: [CBMUUID]?
private var scanOptions: [String : Any]?

Expand Down Expand Up @@ -438,7 +438,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public func scanForPeripherals(withServices serviceUUIDs: [CBMUUID]?,
open func scanForPeripherals(withServices serviceUUIDs: [CBMUUID]?,
options: [String : Any]?) {
// Central manager must be in powered on state.
guard ensurePoweredOn() else { return }
Expand Down Expand Up @@ -479,15 +479,15 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public func stopScan() {
open func stopScan() {
// Central manager must be in powered on state.
guard ensurePoweredOn() else { return }
isScanning = false
scanFilter = nil
scanOptions = nil
}

public func connect(_ peripheral: CBMPeripheral,
open func connect(_ peripheral: CBMPeripheral,
options: [String : Any]?) {
// Central manager must be in powered on state.
guard ensurePoweredOn() else { return }
Expand Down Expand Up @@ -516,7 +516,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public func cancelPeripheralConnection(_ peripheral: CBMPeripheral) {
open func cancelPeripheralConnection(_ peripheral: CBMPeripheral) {
// Central manager must be in powered on state.
guard ensurePoweredOn() else { return }
// Ignore peripherals that are not mocks.
Expand All @@ -534,7 +534,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public func retrievePeripherals(withIdentifiers identifiers: [UUID]) -> [CBMPeripheral] {
open func retrievePeripherals(withIdentifiers identifiers: [UUID]) -> [CBMPeripheral] {
// Starting from iOS 13, this method returns peripherals only in ON state.
guard ensurePoweredOn() else { return [] }
// Get the peripherals already known to this central manager.
Expand Down Expand Up @@ -564,7 +564,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}
}

public func retrieveConnectedPeripherals(withServices serviceUUIDs: [CBMUUID]) -> [CBMPeripheral] {
open func retrieveConnectedPeripherals(withServices serviceUUIDs: [CBMUUID]) -> [CBMPeripheral] {
// Starting from iOS 13, this method returns peripherals only in ON state.
guard ensurePoweredOn() else { return [] }
// Get the connected peripherals with at least one of the given services
Expand Down Expand Up @@ -607,7 +607,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {
}

@available(iOS 13.0, *)
public func registerForConnectionEvents(options: [CBMConnectionEventMatchingOption : Any]?) {
open func registerForConnectionEvents(options: [CBMConnectionEventMatchingOption : Any]?) {
fatalError("Mock connection events are not implemented")
}

Expand All @@ -623,7 +623,7 @@ public class CBMCentralManagerMock: NSObject, CBMCentralManager {

// MARK: - CBPeripheralMock implementation

public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
open class CBMPeripheralMock: CBMPeer, CBMPeripheral {

/// The parent central manager.
private let manager: CBMCentralManagerMock
Expand Down Expand Up @@ -652,12 +652,12 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
/// and iOS had chance to read device name.
fileprivate var wasConnected: Bool = false

public var delegate: CBMPeripheralDelegate?
open var delegate: CBMPeripheralDelegate?

public override var identifier: UUID {
open override var identifier: UUID {
return mock.identifier
}
public var name: String? {
open var name: String? {
// If the device wasn't connected and has just been scanned first time,
// return nil. When scanning continued, the Local Name from the
// advertisement data is returned. When the device was connected, the
Expand All @@ -669,12 +669,12 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
nil
}
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
public var canSendWriteWithoutResponse: Bool {
open var canSendWriteWithoutResponse: Bool {
return _canSendWriteWithoutResponse
}
public private(set) var ancsAuthorized: Bool = false
public private(set) var state: CBMPeripheralState = .disconnected
public private(set) var services: [CBMService]? = nil
open private(set) var ancsAuthorized: Bool = false
open private(set) var state: CBMPeripheralState = .disconnected
open private(set) var services: [CBMService]? = nil

// MARK: Initializers

Expand Down Expand Up @@ -852,7 +852,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

// MARK: Service discovery

public func discoverServices(_ serviceUUIDs: [CBMUUID]?) {
open func discoverServices(_ serviceUUIDs: [CBMUUID]?) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
guard state == .connected,
Expand Down Expand Up @@ -893,7 +893,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}
}

public func discoverIncludedServices(_ includedServiceUUIDs: [CBMUUID]?,
open func discoverIncludedServices(_ includedServiceUUIDs: [CBMUUID]?,
for service: CBMService) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
Expand Down Expand Up @@ -951,7 +951,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

}

public func discoverCharacteristics(_ characteristicUUIDs: [CBMUUID]?,
open func discoverCharacteristics(_ characteristicUUIDs: [CBMUUID]?,
for service: CBMService) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
Expand Down Expand Up @@ -1008,7 +1008,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}
}

public func discoverDescriptors(for characteristic: CBMCharacteristic) {
open func discoverDescriptors(for characteristic: CBMCharacteristic) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
guard state == .connected,
Expand Down Expand Up @@ -1066,7 +1066,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

// MARK: Read requests

public func readValue(for characteristic: CBMCharacteristic) {
open func readValue(for characteristic: CBMCharacteristic) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
guard state == .connected,
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}
}

public func readValue(for descriptor: CBMDescriptor) {
open func readValue(for descriptor: CBMDescriptor) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
guard state == .connected,
Expand Down Expand Up @@ -1136,7 +1136,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

// MARK: Write requests

public func writeValue(_ data: Data,
open func writeValue(_ data: Data,
for characteristic: CBMCharacteristic,
type: CBMCharacteristicWriteType) {
// Central manager must be in powered on state.
Expand Down Expand Up @@ -1215,7 +1215,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}
}

public func writeValue(_ data: Data, for descriptor: CBMDescriptor) {
open func writeValue(_ data: Data, for descriptor: CBMDescriptor) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
guard state == .connected,
Expand Down Expand Up @@ -1251,7 +1251,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}

@available(iOS 9.0, *)
public func maximumWriteValueLength(for type: CBMCharacteristicWriteType) -> Int {
open func maximumWriteValueLength(for type: CBMCharacteristicWriteType) -> Int {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return 0 }
guard state == .connected, let mtu = mock.mtu else {
Expand All @@ -1262,7 +1262,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

// MARK: Enabling notifications and indications

public func setNotifyValue(_ enabled: Bool,
open func setNotifyValue(_ enabled: Bool,
for characteristic: CBMCharacteristic) {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
Expand Down Expand Up @@ -1304,7 +1304,7 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {

// MARK: Other

public func readRSSI() {
open func readRSSI() {
// Central manager must be in powered on state.
guard manager.ensurePoweredOn() else { return }
queue.async { [weak self] in
Expand All @@ -1319,11 +1319,11 @@ public class CBMPeripheralMock: CBMPeer, CBMPeripheral {
}

@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
public func openL2CAPChannel(_ PSM: CBML2CAPPSM) {
open func openL2CAPChannel(_ PSM: CBML2CAPPSM) {
fatalError("L2CAP mock is not implemented")
}

public override var hash: Int {
open override var hash: Int {
return mock.identifier.hashValue
}
}
Expand Down
Loading

0 comments on commit af28b32

Please sign in to comment.