Sealed sender certificates come in two flavors: one with our local phone number, and one without. Add an automated test for picking the right one based on our phone number sharing mode (everybody, contacts-only, nobody). This commit also adds a convenience helper for tests that want to wait on promises that might run on the main thread.
69 lines
1.7 KiB
Swift
69 lines
1.7 KiB
Swift
//
|
|
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import SignalServiceKit
|
|
import CocoaLumberjack
|
|
|
|
extension Thenable {
|
|
func expect(timeout: TimeInterval, file: StaticString = #file, line: UInt = #line) -> Value {
|
|
let expectation = XCTestExpectation(description: "\(file):\(line)")
|
|
var result: Value?
|
|
self.done {
|
|
result = $0
|
|
expectation.fulfill()
|
|
}.catch {
|
|
XCTFail("\($0)", file: file, line: line)
|
|
}
|
|
_ = XCTWaiter.wait(for: [expectation], timeout: timeout)
|
|
return try! XCTUnwrap(result, file: file, line: line)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
public class SSKBaseTestSwift: XCTestCase {
|
|
|
|
@objc
|
|
public override func setUp() {
|
|
super.setUp()
|
|
|
|
DDLog.add(DDTTYLogger.sharedInstance!)
|
|
|
|
ClearCurrentAppContextForTests()
|
|
SetCurrentAppContext(TestAppContext())
|
|
|
|
MockSSKEnvironment.activate()
|
|
|
|
GroupManager.forceV1Groups()
|
|
}
|
|
|
|
@objc
|
|
public override func tearDown() {
|
|
AssertIsOnMainThread()
|
|
|
|
// Spin the main run loop to flush any remaining async work.
|
|
var done = false
|
|
DispatchQueue.main.async { done = true }
|
|
while !done {
|
|
CFRunLoopRunInMode(.defaultMode, 0.0, true)
|
|
}
|
|
|
|
super.tearDown()
|
|
}
|
|
|
|
@objc
|
|
public func read(_ block: (SDSAnyReadTransaction) -> Void) {
|
|
return databaseStorage.read(block: block)
|
|
}
|
|
|
|
public func write<T>(_ block: (SDSAnyWriteTransaction) -> T) -> T {
|
|
return databaseStorage.write(block: block)
|
|
}
|
|
|
|
@objc
|
|
public func asyncWrite(_ block: @escaping (SDSAnyWriteTransaction) -> Void) {
|
|
return databaseStorage.asyncWrite(block: block)
|
|
}
|
|
}
|