Skip to content

Commit

Permalink
Branch release2.7.1 merge into master gitHub branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mantosh Kumar committed Jul 28, 2023
1 parent 533df99 commit a24d60e
Show file tree
Hide file tree
Showing 30 changed files with 254 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,34 @@ class SILESLCommandConnectTestSpec: QuickSpec {
var sut: SILESLCommandConnect!

override func spec() {
describe("connect bt_addr") {
it("should prepare data for public address") {
describe("raw data") {
it("should prepare connect from raw data") {
let btAddress = "8c:f6:81:b8:82:b2"
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .public))
self.sut = SILESLCommandConnect(address: self.address)

let dataToSend = "connect \(btAddress)".bytes

self.sut = SILESLCommandConnect(qrData: dataToSend)

expect(self.sut.dataToSend).to(equal(dataToSend))
}

it("should prepare data for public address with passcode") {
}

describe("connect bt_addr") {
it("should prepare data for public address") {
let btAddress = "8c:f6:81:b8:82:b2"
let passcode = "1234"
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .public))
self.sut = SILESLCommandConnect(address: self.address, passcode: passcode)
self.sut = SILESLCommandConnect(address: self.address)

let dataToSend = "connect \(btAddress) \(passcode)".bytes
let dataToSend = "connect \(btAddress)".bytes

expect(self.sut.dataToSend).to(equal(dataToSend))
}

it("should prepare data for static address with passcode") {
it("should prepare data for static address") {
let btAddress = "X"
let passcode = "1234"
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .static))
self.sut = SILESLCommandConnect(address: self.address, passcode: passcode)
self.sut = SILESLCommandConnect(address: self.address)

let dataToSend = "connect \(btAddress) static \(passcode)".bytes
let dataToSend = "connect \(btAddress) static".bytes

expect(self.sut.dataToSend).to(equal(dataToSend))
}
Expand All @@ -65,11 +64,10 @@ class SILESLCommandConnectTestSpec: QuickSpec {

it("should prepare data for rand_nonres address") {
let btAddress = "XXX"
let passcode = "4321"
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .rand_nonres))
self.sut = SILESLCommandConnect(address: self.address, passcode: passcode)
self.sut = SILESLCommandConnect(address: self.address)

let dataToSend = "connect \(btAddress) rand_nonres \(passcode)".bytes
let dataToSend = "connect \(btAddress) rand_nonres".bytes

expect(self.sut.dataToSend).to(equal(dataToSend))
}
Expand All @@ -85,17 +83,6 @@ class SILESLCommandConnectTestSpec: QuickSpec {

expect(self.sut.dataToSend).to(equal(dataToSend))
}

it("should prepare data for esl_id with passcode") {
let eslId = 55
let passcode = "56789"
self.address = SILAddress.eslId(SILESLIdAddress.unicast(id: 55))
self.sut = SILESLCommandConnect(address: self.address, passcode: passcode)

let dataToSend = "connect \(eslId) \(passcode)".bytes

expect(self.sut.dataToSend).to(equal(dataToSend))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SILESLProvisioningTagTestSpec: QuickSpec {
self.sut = SILESLProvisioningTag(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
commandRunnerFactory: self.commandRunnerFactoryMock,
address: .init(address: "", addressType: .public))
qrData: [UInt8]())
}

afterEach {
Expand All @@ -39,11 +39,10 @@ class SILESLProvisioningTagTestSpec: QuickSpec {

describe("perform(timeout:)") {
it("should call function and return success") {
let btAddress = SILBluetoothAddress(address: "", addressType: .public)
let connectCommandMock = mock(SILESLCommandConnect.self).initialize(address: .btAddress(btAddress), passcode: "1234")
let connectCommandMock = mock(SILESLCommandConnect.self).initialize(qrData: [UInt8]())
let connect = mock(SILESLCommandConnectRunner.self).initialize(peripheral: self.peripheralMock, peripheralReferences: self.peripheralReferencesMock, command: connectCommandMock)

given(self.commandRunnerFactoryMock.createCommandConnectRunner(peripheral: self.peripheralMock, peripheralReferences: any(), address: any(), passcode: any())).willReturn(connect)
given(self.commandRunnerFactoryMock.createCommandConnectRunner(peripheral: self.peripheralMock, peripheralReferences: any(), qrData: any(), address: nil)).willReturn(connect)

let publishRelay: PublishRelay<Result<Bool, SILESLCommandGenericError>> = PublishRelay()
given(connect.commandResult).willReturn(publishRelay)
Expand All @@ -62,11 +61,10 @@ class SILESLProvisioningTagTestSpec: QuickSpec {
}

it("should call function and return error") {
let btAddress = SILBluetoothAddress(address: "", addressType: .public)
let connectCommandMock = mock(SILESLCommandConnect.self).initialize(address: .btAddress(btAddress), passcode: "1234")
let connectCommandMock = mock(SILESLCommandConnect.self).initialize(qrData: [UInt8]())
let connect = mock(SILESLCommandConnectRunner.self).initialize(peripheral: self.peripheralMock, peripheralReferences: self.peripheralReferencesMock, command: connectCommandMock)

given(self.commandRunnerFactoryMock.createCommandConnectRunner(peripheral: self.peripheralMock, peripheralReferences: any(), address: any(), passcode: any())).willReturn(connect)
given(self.commandRunnerFactoryMock.createCommandConnectRunner(peripheral: self.peripheralMock, peripheralReferences: any(), qrData: any(), address: nil)).willReturn(connect)

let publishRelay: PublishRelay<Result<Bool, SILESLCommandGenericError>> = PublishRelay()
given(connect.commandResult).willReturn(publishRelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class SILESLCommandConnectRunnerTestSpec: QuickSpec {
override func spec() {
beforeEach {
self.address = .eslId(.broadcast)
self.commandMock = mock(SILESLCommandConnect.self).initialize(address: self.address, passcode: nil)
self.commandMock = mock(SILESLCommandConnect.self).initialize(address: self.address)
let defaultMock = SILESLPeripheralMockFactory().getDefault()
given(self.commandMock.getFullCommand()).willReturn("")
given(self.commandMock.getDataToSend()).willReturn([UInt8]())
self.eslDemoServiceMock = defaultMock.eslDemoServiceMock
self.eslControlPointMock = defaultMock.eslControlPointMock
self.peripheralMock = defaultMock.peripheralMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class SILESLCommandRunnerFactoryTestSpec: QuickSpec {
let provisioning = self.sut.createCommandProvisioning(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
commandRunnerFactory: self.sut,
address: SILBluetoothAddress(address: "", addressType: .public),
passcode: "12345")
qrData: [UInt8]())

expect(provisioning.isKind(of: SILESLProvisioningTag.self)).to(beTrue())
}
Expand All @@ -56,11 +55,18 @@ class SILESLCommandRunnerFactoryTestSpec: QuickSpec {
}

describe("createCommandConnectRunner") {
it("should create proper object") {
it("should create proper object with address") {
let connectRunner = self.sut.createCommandConnectRunner(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
address: self.addressMock)

expect(connectRunner.isKind(of: SILESLCommandConnectRunner.self)).to(beTrue())
}

it("should create proper object with qrCode") {
let connectRunner = self.sut.createCommandConnectRunner(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
address: self.addressMock,
passcode: "12345")
qrData: [UInt8]())

expect(connectRunner.isKind(of: SILESLCommandConnectRunner.self)).to(beTrue())
}
Expand Down
47 changes: 10 additions & 37 deletions BlueGeckoTests/ViewModels/ESLDemo/QRScannerViewModelTestSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,39 @@ class QRScannerViewModelTestSpec: QuickSpec {
describe("readQR - correct") {
it("should read correct two words") {
let address = "00:01:02:03:04:05"
let qrData = self.sut.readQR(metadata: "connect \(address)")
let full = "connect \(address)"
let qrData = self.sut.readQR(metadata: full)

expect(qrData).notTo(beNil())
expect(qrData?.bluetoothAddress.addressType).to(equal(.public))
expect(qrData?.bluetoothAddress.address).to(equal(address))
expect(qrData?.passcode).to(beNil())
expect(qrData?.rawData).to(equal(full.bytes))
}

it("should read correct three words") {
it("should read correct with more characters") {
let address = "00:01:02:03:04:05"
let qrData = self.sut.readQR(metadata: "connect \(address) static")
let full = "abc dconnect \(address) static"
let qrData = self.sut.readQR(metadata: full)

expect(qrData).notTo(beNil())
expect(qrData?.bluetoothAddress.addressType).to(equal(.static))
expect(qrData?.bluetoothAddress.address).to(equal(address))
expect(qrData?.passcode).to(beNil())
}

it("should read correct four words") {
let address = "00:01:02:03:04:05"
let passcode = "1234"
let qrData = self.sut.readQR(metadata: "connect \(address) rand_nonres \(passcode)")

expect(qrData).notTo(beNil())
expect(qrData?.bluetoothAddress.addressType).to(equal(.rand_nonres))
expect(qrData?.bluetoothAddress.addressType).to(equal(.public))
expect(qrData?.bluetoothAddress.address).to(equal(address))
expect(qrData?.passcode).to(equal(passcode))
expect(qrData?.rawData).to(equal(full.bytes))
}
}

describe("readQR - incorrect") {
it("return nil - words.count = 1") {
let qrData = self.sut.readQR(metadata: "connect")

expect(qrData).to(beNil())
}

it("return nil - words.count = 5") {
it("return nil - missing btAddress") {
let qrData = self.sut.readQR(metadata: "connect a b c d")

expect(qrData).to(beNil())
}

it("return nil - words[0] != connect") {
let qrData = self.sut.readQR(metadata: "connected 11:12:13:14:15:16")

expect(qrData).to(beNil())
}

it("return nil - words[1].isValid = false") {
it("return nil - btAddress wrong") {
let qrData = self.sut.readQR(metadata: "connect 100:12:13:14:15:16")

expect(qrData).to(beNil())
}

it("return nil - words[2] invalid type") {
let qrData = self.sut.readQR(metadata: "connect 11:12:13:14:15:16 nonpublic")

expect(qrData).to(beNil())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ class SILESLDemoViewModelTestSpec: QuickSpec {

describe("provisionTag") {
it("should call perform on runner and finish with success") {
let btAddress = SILBluetoothAddress(address: "", addressType: .public)
let provisionCommandMock = mock(SILESLProvisioningTag.self).initialize(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
commandRunnerFactory: self.commandRunnerFactoryMock,
address: btAddress,
passcode: nil)
qrData: [UInt8]())

given(self.commandRunnerFactoryMock.createCommandProvisioning(peripheral: self.peripheralMock, peripheralReferences: any(), commandRunnerFactory: self.commandRunnerFactoryMock, address: any(), passcode: any())).willReturn(provisionCommandMock)
given(self.commandRunnerFactoryMock.createCommandProvisioning(peripheral: self.peripheralMock, peripheralReferences: any(), commandRunnerFactory: self.commandRunnerFactoryMock, qrData: any())).willReturn(provisionCommandMock)

let publishRelay: PublishRelay<Result<SILESLDemoViewModelState, SILESLCommandGenericError>> = PublishRelay()
given(provisionCommandMock.commandResult).willReturn(publishRelay)
Expand All @@ -160,22 +158,20 @@ class SILESLDemoViewModelTestSpec: QuickSpec {
expectedState = commandState
}).disposed(by: self.disposeBag)

self.sut.provisionTag(with: btAddress, passcode: "1234")
self.sut.provisionTag(with: [UInt8]())
publishRelay.accept(.success(.provisioningInProgressConfig))

verify(provisionCommandMock.perform(timeout: 10.0)).wasCalled(1)
expect(expectedState == .provisioningInProgressConfig).to(beTrue())
}

it("should call perform on runner and finish with failure") {
let btAddress = SILBluetoothAddress(address: "", addressType: .public)
let provisionCommandMock = mock(SILESLProvisioningTag.self).initialize(peripheral: self.peripheralMock,
peripheralReferences: self.peripheralReferencesMock,
commandRunnerFactory: self.commandRunnerFactoryMock,
address: btAddress,
passcode: nil)
qrData: [UInt8]())

given(self.commandRunnerFactoryMock.createCommandProvisioning(peripheral: self.peripheralMock, peripheralReferences: any(), commandRunnerFactory: self.commandRunnerFactoryMock, address: any(), passcode: any())).willReturn(provisionCommandMock)
given(self.commandRunnerFactoryMock.createCommandProvisioning(peripheral: self.peripheralMock, peripheralReferences: any(), commandRunnerFactory: self.commandRunnerFactoryMock, qrData: any())).willReturn(provisionCommandMock)

let publishRelay: PublishRelay<Result<SILESLDemoViewModelState, SILESLCommandGenericError>> = PublishRelay()
given(provisionCommandMock.commandResult).willReturn(publishRelay)
Expand All @@ -185,7 +181,7 @@ class SILESLDemoViewModelTestSpec: QuickSpec {
expectedState = commandState
}).disposed(by: self.disposeBag)

self.sut.provisionTag(with: btAddress, passcode: "1234")
self.sut.provisionTag(with: [UInt8]())
publishRelay.accept(.failure(.timeout))

verify(provisionCommandMock.perform(timeout: 10.0)).wasCalled(1)
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def shared_pods
pod 'AEXML'
pod 'RxSwift', '~> 6.2.0'
pod 'RxCocoa', '~> 6.2.0'
pod 'Introspect'
end

def test_pods
Expand Down
10 changes: 7 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PODS:
- Crashlytics (3.12.0):
- Fabric (~> 1.9.0)
- Fabric (1.9.0)
- Introspect (0.1.4)
- IP-UIKit-Wisdom (0.0.10)
- KVOController (1.2.0)
- MockingbirdFramework (0.20.0)
Expand Down Expand Up @@ -43,6 +44,7 @@ DEPENDENCIES:
- Charts (~> 4.1.0)
- Crashlytics (~> 3.12.0)
- Fabric (~> 1.9.0)
- Introspect
- IP-UIKit-Wisdom (~> 0.0.10)
- KVOController (~> 1.2.0)
- MockingbirdFramework (~> 0.20)
Expand All @@ -68,6 +70,7 @@ SPEC REPOS:
- Charts
- Crashlytics
- Fabric
- Introspect
- IP-UIKit-Wisdom
- KVOController
- MockingbirdFramework
Expand Down Expand Up @@ -99,9 +102,10 @@ SPEC CHECKSUMS:
ActionSheetPicker-3.0: 2f5e3fde6b3205a7318f9338e4ec0f373ce7e75c
AEXML: 1e255ecc6597212f97a7454a69ebd3ede64ac1cf
ChameleonFramework: d21a3cc247abfe5e37609a283a8238b03575cf64
Charts: 354f86803d11d9c35de280587fef50d1af063978
Charts: ce0768268078eee0336f122c3c4ca248e4e204c5
Crashlytics: a33af323773f73904037dc2e684cd2f0d29f4fe2
Fabric: 09ef2d9b99b104702bede1acaf469fb8f20a9146
Introspect: b62c4dd2063072327c21d618ef2bedc3c87bc366
IP-UIKit-Wisdom: b395a065344071b33659e5f6b918043a97c48a44
KVOController: d72ace34afea42468329623b3379ab3cd1d286b6
MockingbirdFramework: 54e35fbbb47b806c1a1fae2cf3ef99f6eceb55e5
Expand All @@ -121,6 +125,6 @@ SPEC CHECKSUMS:
WYPopoverController: a9db25ac2841a686acdc0f3a99bdb21545db32f4
XMLDictionary: fa07b6ff422b3a91d47a5de9bc82e3fc04fbd167

PODFILE CHECKSUM: 2a7bf762833c9e5113333b740d5adcf2e3da73dc
PODFILE CHECKSUM: ccf13e60e9ab41471864f78e72f744756afc259a

COCOAPODS: 1.10.0
COCOAPODS: 1.12.1

0 comments on commit a24d60e

Please sign in to comment.