Add PromiseKit dependency
- Added PromiseKit dependency
This commit is contained in:
12
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/Entitlements.plist
vendored
Normal file
12
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/Entitlements.plist
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.private.tcc.allow</key>
|
||||
<array>
|
||||
<string>kTCCServiceAddressBook</string>
|
||||
<string>kTCCServiceCalendar</string>
|
||||
<string>kTCCServicePhotos</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
84
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/HMAccessoryBrowserTests.swift
vendored
Normal file
84
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/HMAccessoryBrowserTests.swift
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// HMAccessoryBrowserTests.swift
|
||||
// PMKHKTests
|
||||
//
|
||||
// Created by Chris Chares on 7/25/18.
|
||||
// Copyright © 2018 Max Howell. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import PromiseKit
|
||||
import HomeKit
|
||||
@testable import PMKHomeKit
|
||||
|
||||
#if os(iOS)
|
||||
|
||||
class HMAccessoryBrowserTests: XCTestCase {
|
||||
|
||||
func testBrowserScanReturningFirst() {
|
||||
swizzle(HMAccessoryBrowser.self, #selector(HMAccessoryBrowser.startSearchingForNewAccessories)) {
|
||||
let ex = expectation(description: "")
|
||||
|
||||
HMPromiseAccessoryBrowser().start(scanInterval: .returnFirst(timeout: 0.5))
|
||||
.done { accessories in
|
||||
XCTAssertEqual(accessories.count, 1)
|
||||
ex.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func testBrowserScanReturningTimeout() {
|
||||
let ex = expectation(description: "")
|
||||
|
||||
HMPromiseAccessoryBrowser().start(scanInterval: .returnFirst(timeout: 0.5))
|
||||
.catch { error in
|
||||
// Why would we have discovered anything?
|
||||
ex.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension HMAccessoryBrowser {
|
||||
@objc func pmk_startSearchingForNewAccessories() {
|
||||
after(.milliseconds(100))
|
||||
.done { swag in
|
||||
self.delegate!.accessoryBrowser?(self, didFindNewAccessory: MockAccessory())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Mocks
|
||||
class MockAccessory: HMAccessory {
|
||||
var _uniqueID: UUID = UUID()
|
||||
override var uniqueIdentifier: UUID { return _uniqueID }
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
// Utilty taken from https://github.com/PromiseKit/CoreLocation/blob/master/Tests/CLLocationManagerTests.swift
|
||||
import ObjectiveC
|
||||
|
||||
func swizzle(_ foo: AnyClass, _ from: Selector, isClassMethod: Bool = false, body: () -> Void) {
|
||||
let originalMethod: Method
|
||||
let swizzledMethod: Method
|
||||
|
||||
if isClassMethod {
|
||||
originalMethod = class_getClassMethod(foo, from)!
|
||||
swizzledMethod = class_getClassMethod(foo, Selector("pmk_\(from)"))!
|
||||
} else {
|
||||
originalMethod = class_getInstanceMethod(foo, from)!
|
||||
swizzledMethod = class_getInstanceMethod(foo, Selector("pmk_\(from)"))!
|
||||
}
|
||||
|
||||
method_exchangeImplementations(originalMethod, swizzledMethod)
|
||||
body()
|
||||
method_exchangeImplementations(swizzledMethod, originalMethod)
|
||||
}
|
||||
|
||||
#endif
|
||||
63
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/UtilsTests.swift
vendored
Normal file
63
Carthage/Checkouts/PromiseKit/Extensions/HomeKit/Tests/UtilsTests.swift
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// UtilsTests.swift
|
||||
// PMKHKTests
|
||||
//
|
||||
// Created by Chris Chares on 7/25/18.
|
||||
// Copyright © 2018 Max Howell. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import PromiseKit
|
||||
@testable import PMKHomeKit
|
||||
|
||||
class UtilsTests: XCTestCase {
|
||||
|
||||
var strongProxy: PromiseProxy<Int>? = PromiseProxy()
|
||||
|
||||
override func setUp() {
|
||||
strongProxy = PromiseProxy()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
strongProxy = nil
|
||||
}
|
||||
|
||||
// The proxy should create a retain cycle until the promise is resolved
|
||||
func testRetainCycle() {
|
||||
weak var weakVar = strongProxy
|
||||
XCTAssertNotNil(weakVar)
|
||||
|
||||
let exp = expectation(description: "")
|
||||
strongProxy = nil
|
||||
after(.milliseconds(50))
|
||||
.done {
|
||||
XCTAssertNotNil(weakVar)
|
||||
exp.fulfill()
|
||||
}
|
||||
waitForExpectations(timeout: 1.0, handler: nil)
|
||||
}
|
||||
|
||||
// Once resolved, the proxy should break the retain cycle
|
||||
func testRelease() {
|
||||
weak var weakVar = strongProxy
|
||||
XCTAssertNotNil(weakVar)
|
||||
|
||||
let exp = expectation(description: "")
|
||||
strongProxy!.fulfill(42)
|
||||
strongProxy = nil
|
||||
|
||||
after(.milliseconds(50))
|
||||
.done {
|
||||
XCTAssertNil(weakVar)
|
||||
exp.fulfill()
|
||||
}
|
||||
waitForExpectations(timeout: 1.0, handler: nil)
|
||||
}
|
||||
|
||||
// Cancel should reject with a PMKError
|
||||
func testCancel() {
|
||||
let proxy = strongProxy!
|
||||
proxy.cancel()
|
||||
XCTAssertNotNil(proxy.promise.error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user