-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
614ad5c
commit 4fd7507
Showing
266 changed files
with
13,851 additions
and
5,115 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
BlueGeckoTests/ViewModels/ESLDemo/Model/Addresses/SILAddressTestSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// SILAddressTestSpec.swift | ||
// BlueGeckoTests | ||
// | ||
// Created by Kamil Czajka on 24.3.2023. | ||
// Copyright © 2023 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import CoreBluetooth | ||
import Mockingbird | ||
import RxSwift | ||
import RxCocoa | ||
@testable import BlueGecko | ||
|
||
class SILAddressTestSpec: QuickSpec { | ||
var sut: SILAddress! | ||
|
||
override func spec() { | ||
describe("init") { | ||
it("should init with esl unicast") { | ||
self.sut = SILAddress(rawValue: "12") | ||
expect(self.sut == .eslId(.unicast(id: 12))).to(beTrue()) | ||
} | ||
|
||
it("should init with esl all") { | ||
self.sut = SILAddress(rawValue: "all") | ||
expect(self.sut == .eslId(.broadcast)).to(beTrue()) | ||
} | ||
|
||
it("should init with btAddress") { | ||
let address = "00:01:02:03:04:05" | ||
self.sut = SILAddress(rawValue: address) | ||
expect(self.sut == .btAddress(SILBluetoothAddress(address: address, addressType: .public))).to(beTrue()) | ||
} | ||
} | ||
|
||
describe("rawValue") { | ||
it("should print esl unicast") { | ||
self.sut = SILAddress.eslId(.unicast(id: 10)) | ||
expect(self.sut.rawValue == "10").to(beTrue()) | ||
} | ||
|
||
it("should print esl all") { | ||
self.sut = SILAddress.eslId(.broadcast) | ||
expect(self.sut.rawValue == "all").to(beTrue()) | ||
} | ||
|
||
it("should print btAddress") { | ||
let address = "00:01:02:03:04:05" | ||
let btAddress = SILBluetoothAddress(address: address, addressType: .public) | ||
self.sut = SILAddress.btAddress(btAddress) | ||
expect(self.sut.rawValue == address).to(beTrue()) | ||
} | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
BlueGeckoTests/ViewModels/ESLDemo/Model/Addresses/SILBluetoothAddressTestSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// SILBluetoothAddressTestSpec.swift | ||
// BlueGeckoTests | ||
// | ||
// Created by Kamil Czajka on 24.3.2023. | ||
// Copyright © 2023 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import CoreBluetooth | ||
import Mockingbird | ||
import RxSwift | ||
import RxCocoa | ||
@testable import BlueGecko | ||
|
||
class SILBluetoothAddressTestSpec: QuickSpec { | ||
var sut: SILBluetoothAddress! | ||
|
||
|
||
override func spec() { | ||
describe("public address") { | ||
it("should be valid address") { | ||
let address = "8c:f6:81:b8:82:b2" | ||
self.sut = SILBluetoothAddress(address: address, addressType: .public) | ||
|
||
expect(self.sut.address).to(equal(address)) | ||
expect(self.sut.addressType).to(equal(.public)) | ||
expect(self.sut.isValid).to(beTrue()) | ||
} | ||
|
||
it("should be invalid address - too long") { | ||
let address = "8c:f6:81:b8:82:b2:" | ||
self.sut = SILBluetoothAddress(address: address, addressType: .public) | ||
|
||
expect(self.sut.address).to(equal(address)) | ||
expect(self.sut.addressType).to(equal(.public)) | ||
expect(self.sut.isValid).to(beFalse()) | ||
} | ||
|
||
it("should be invalid address - wrong format :") { | ||
let address = "8c:f6:81:b8:82::2" | ||
self.sut = SILBluetoothAddress(address: address, addressType: .public) | ||
|
||
expect(self.sut.address).to(equal(address)) | ||
expect(self.sut.addressType).to(equal(.public)) | ||
expect(self.sut.isValid).to(beFalse()) | ||
} | ||
|
||
it("should be invalid address - wrong format non hex") { | ||
let address = "8c:f6:r1:b8:82:b2" | ||
self.sut = SILBluetoothAddress(address: address, addressType: .public) | ||
|
||
expect(self.sut.address).to(equal(address)) | ||
expect(self.sut.addressType).to(equal(.public)) | ||
expect(self.sut.isValid).to(beFalse()) | ||
} | ||
|
||
it("should be invalid address - wrong format places") { | ||
let address = "8:cf:6b:1b:88:2b2" | ||
self.sut = SILBluetoothAddress(address: address, addressType: .public) | ||
|
||
expect(self.sut.address).to(equal(address)) | ||
expect(self.sut.addressType).to(equal(.public)) | ||
expect(self.sut.isValid).to(beFalse()) | ||
} | ||
} | ||
|
||
describe("non-public address") { | ||
it("isValid for static address") { | ||
self.sut = SILBluetoothAddress(address: "", addressType: .static) | ||
|
||
expect(self.sut.address).to(equal("")) | ||
expect(self.sut.addressType).to(equal(.static)) | ||
expect(self.sut.isValid).to(beTrue()) | ||
} | ||
|
||
it("isValid for rand_res address") { | ||
self.sut = SILBluetoothAddress(address: "", addressType: .rand_res) | ||
|
||
expect(self.sut.address).to(equal("")) | ||
expect(self.sut.addressType).to(equal(.rand_res)) | ||
expect(self.sut.isValid).to(beTrue()) | ||
} | ||
|
||
it("isValid for rand_nonres address") { | ||
self.sut = SILBluetoothAddress(address: "", addressType: .rand_nonres) | ||
|
||
expect(self.sut.address).to(equal("")) | ||
expect(self.sut.addressType).to(equal(.rand_nonres)) | ||
expect(self.sut.isValid).to(beTrue()) | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
BlueGeckoTests/ViewModels/ESLDemo/Model/Addresses/SILESLIdAddressTestSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// SILESLIdAddressTestSpec.swift | ||
// BlueGeckoTests | ||
// | ||
// Created by Kamil Czajka on 24.3.2023. | ||
// Copyright © 2023 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import CoreBluetooth | ||
import Mockingbird | ||
import RxSwift | ||
import RxCocoa | ||
@testable import BlueGecko | ||
|
||
class SILESLIdAddressTestSpec: QuickSpec { | ||
var sut: SILESLIdAddress! | ||
|
||
|
||
override func spec() { | ||
describe("broadcast") { | ||
it("should return correct raw value") { | ||
self.sut = SILESLIdAddress.broadcast | ||
|
||
expect(self.sut.rawValue).to(equal("all")) | ||
} | ||
|
||
it("should return correct case based on init") { | ||
self.sut = SILESLIdAddress(rawValue: "all") | ||
|
||
expect(self.sut == .broadcast).to(beTrue()) | ||
} | ||
} | ||
|
||
describe("unicast") { | ||
it("should return correct raw value") { | ||
self.sut = SILESLIdAddress.unicast(id: 5) | ||
|
||
expect(self.sut.rawValue).to(equal("5")) | ||
} | ||
|
||
it("should return correct case based on init") { | ||
self.sut = SILESLIdAddress(rawValue: "10") | ||
|
||
expect(self.sut == .unicast(id: 10)).to(beTrue()) | ||
} | ||
|
||
it("should return nil") { | ||
self.sut = SILESLIdAddress(rawValue: "-10") | ||
|
||
expect(self.sut).to(beNil()) | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
BlueGeckoTests/ViewModels/ESLDemo/Model/Commands/SILESLCommandConfigureTestSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// SILESLCommandConfigureTestSpec.swift | ||
// BlueGeckoTests | ||
// | ||
// Created by Kamil Czajka on 24.3.2023. | ||
// Copyright © 2023 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import CoreBluetooth | ||
import Mockingbird | ||
import RxSwift | ||
import RxCocoa | ||
@testable import BlueGecko | ||
|
||
class SILESLCommandConfigureTestSpec: QuickSpec { | ||
var sut: SILESLCommandConfigure! | ||
|
||
override func spec() { | ||
describe("config full") { | ||
it("should prepare correct data") { | ||
self.sut = SILESLCommandConfigure() | ||
|
||
let dataToSend = "config full".bytes | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
BlueGeckoTests/ViewModels/ESLDemo/Model/Commands/SILESLCommandConnectTestSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// SILESLCommandConnectTestSpec.swift | ||
// BlueGeckoTests | ||
// | ||
// Created by Kamil Czajka on 24.3.2023. | ||
// Copyright © 2023 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
import CoreBluetooth | ||
import Mockingbird | ||
import RxSwift | ||
import RxCocoa | ||
@testable import BlueGecko | ||
|
||
class SILESLCommandConnectTestSpec: QuickSpec { | ||
var address: SILAddress! | ||
var sut: SILESLCommandConnect! | ||
|
||
override func spec() { | ||
describe("connect bt_addr") { | ||
it("should prepare data for public address") { | ||
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 | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
|
||
it("should prepare data for public address with passcode") { | ||
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) | ||
|
||
let dataToSend = "connect \(btAddress) \(passcode)".bytes | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
|
||
it("should prepare data for static address with passcode") { | ||
let btAddress = "X" | ||
let passcode = "1234" | ||
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .static)) | ||
self.sut = SILESLCommandConnect(address: self.address, passcode: passcode) | ||
|
||
let dataToSend = "connect \(btAddress) static \(passcode)".bytes | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
|
||
it("should prepare data for rand_res address") { | ||
let btAddress = "XXXX" | ||
self.address = SILAddress.btAddress(SILBluetoothAddress(address: btAddress, addressType: .rand_res)) | ||
self.sut = SILESLCommandConnect(address: self.address) | ||
|
||
let dataToSend = "connect \(btAddress) rand_res".bytes | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
|
||
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) | ||
|
||
let dataToSend = "connect \(btAddress) rand_nonres \(passcode)".bytes | ||
|
||
expect(self.sut.dataToSend).to(equal(dataToSend)) | ||
} | ||
} | ||
|
||
describe("connect esl_id") { | ||
it("should prepare data for esl_id") { | ||
let eslId = 5 | ||
self.address = SILAddress.eslId(SILESLIdAddress.unicast(id: 5)) | ||
self.sut = SILESLCommandConnect(address: self.address) | ||
|
||
let dataToSend = "connect \(eslId)".bytes | ||
|
||
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)) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.