mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-22 04:00:39 +00:00
Merge branch 'development' into sqlcipher-spm-upstream
This commit is contained in:
commit
a3036feb48
22 files changed
+152
-21
No files matched your search
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"editor.formatOnSave": false,
|
||||
"editor.insertSpaces": true,
|
||||
"editor.tabSize": 4,
|
||||
"editor.detectIndentation": false,
|
||||
"editor.trimAutoWhitespace": false
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
#if os(Linux)
|
||||
@preconcurrency import Dispatch
|
||||
#else
|
||||
import Dispatch
|
||||
#endif
|
||||
|
||||
/// An actor that runs in a DispatchQueue.
|
||||
///
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#if canImport(CoreGraphics)
|
||||
import CoreGraphics
|
||||
#elseif !canImport(Darwin)
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
/// CGFloat adopts DatabaseValueConvertible
|
||||
extension CGFloat: DatabaseValueConvertible {
|
||||
@@ -15,4 +18,3 @@ extension CGFloat: DatabaseValueConvertible {
|
||||
return CGFloat(double)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -12,7 +12,6 @@ import GRDBSQLite
|
||||
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux)
|
||||
/// NSDate is stored in the database using the format
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
extension NSDate: DatabaseValueConvertible {
|
||||
@@ -41,7 +40,6 @@ extension NSDate: DatabaseValueConvertible {
|
||||
return cast(date)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Date is stored in the database using the format
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#if !os(Linux)
|
||||
// Import C SQLite functions
|
||||
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
|
||||
import SQLCipher
|
||||
@@ -68,4 +67,3 @@ extension Decimal: StatementColumnConvertible {
|
||||
|
||||
@usableFromInline
|
||||
let _posixLocale = Locale(identifier: "en_US_POSIX")
|
||||
#endif
|
||||
@@ -1,4 +1,3 @@
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
|
||||
/// NSData is convertible to and from DatabaseValue.
|
||||
@@ -24,4 +23,3 @@ extension NSData: DatabaseValueConvertible {
|
||||
return cast(data)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !os(Linux) && !os(Windows)
|
||||
#if !os(Windows)
|
||||
import Foundation
|
||||
|
||||
private let integerRoundingBehavior = NSDecimalNumberHandler(
|
||||
@@ -81,10 +81,18 @@ extension NSNumber: DatabaseValueConvertible {
|
||||
/// Otherwise, returns nil.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
||||
switch dbValue.storage {
|
||||
case .int64(let int64) where self is NSDecimalNumber.Type:
|
||||
let number = NSDecimalNumber(value: int64)
|
||||
return number as? Self
|
||||
case .int64(let int64):
|
||||
return self.init(value: int64)
|
||||
let number = NSNumber(value: int64)
|
||||
return number as? Self
|
||||
case .double(let double) where self is NSDecimalNumber.Type:
|
||||
let number = NSDecimalNumber(value: double)
|
||||
return number as? Self
|
||||
case .double(let double):
|
||||
return self.init(value: double)
|
||||
let number = NSNumber(value: double)
|
||||
return number as? Self
|
||||
case let .string(string):
|
||||
// Must match Decimal.fromDatabaseValue(_:)
|
||||
guard let decimal = Decimal(string: string, locale: posixLocale) else { return nil }
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
|
||||
/// NSString adopts DatabaseValueConvertible
|
||||
@@ -24,4 +23,3 @@ extension NSString: DatabaseValueConvertible {
|
||||
return self.init(string: string)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +1,16 @@
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux) && !os(Windows)
|
||||
#if !os(Windows)
|
||||
/// NSURL stores its absoluteString in the database.
|
||||
extension NSURL: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a TEXT database value containing the absolute URL.
|
||||
public var databaseValue: DatabaseValue {
|
||||
absoluteString?.databaseValue ?? .null
|
||||
#if !canImport(Darwin)
|
||||
absoluteString.databaseValue
|
||||
#else
|
||||
absoluteString?.databaseValue ?? .null
|
||||
#endif
|
||||
}
|
||||
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
||||
|
||||
@@ -12,7 +12,7 @@ import GRDBSQLite
|
||||
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux) && !os(Windows)
|
||||
#if !os(Windows)
|
||||
/// NSUUID adopts DatabaseValueConvertible
|
||||
extension NSUUID: DatabaseValueConvertible {
|
||||
/// Returns a BLOB database value containing the uuid bytes.
|
||||
@@ -36,10 +36,17 @@ extension NSUUID: DatabaseValueConvertible {
|
||||
switch dbValue.storage {
|
||||
case .blob(let data) where data.count == 16:
|
||||
return data.withUnsafeBytes {
|
||||
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
|
||||
#if canImport(Darwin)
|
||||
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
|
||||
#else
|
||||
guard let uuidBytes = $0.bindMemory(to: UInt8.self).baseAddress else {
|
||||
return nil as Self?
|
||||
}
|
||||
return NSUUID(uuidBytes: uuidBytes) as? Self
|
||||
#endif
|
||||
}
|
||||
case .string(let string):
|
||||
return self.init(uuidString: string)
|
||||
return NSUUID(uuidString: string) as? Self
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -91,8 +98,8 @@ extension UUID: StatementColumnConvertible {
|
||||
self.init(uuid: uuid.uuid)
|
||||
case SQLITE_BLOB:
|
||||
guard sqlite3_column_bytes(sqliteStatement, index) == 16,
|
||||
let blob = sqlite3_column_blob(sqliteStatement, index) else
|
||||
{
|
||||
let blob = sqlite3_column_blob(sqliteStatement, index)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
self.init(uuid: blob.assumingMemoryBound(to: uuid_t.self).pointee)
|
||||
|
||||
@@ -15,6 +15,8 @@ let darwinPlatforms: [Platform] = [
|
||||
var swiftSettings: [SwiftSetting] = [
|
||||
.define("SQLITE_ENABLE_FTS5"),
|
||||
.define("SQLITE_ENABLE_SNAPSHOT"),
|
||||
// Not all Linux distributions have support for WAL snapshots.
|
||||
.define("SQLITE_DISABLE_SNAPSHOT", .when(platforms: [.linux])),
|
||||
]
|
||||
var cSettings: [CSetting] = []
|
||||
var dependencies: [PackageDescription.Package.Dependency] = []
|
||||
|
||||
@@ -100,7 +100,7 @@ try dbQueue.write { db in
|
||||
}
|
||||
|
||||
try dbQueue.read { db in
|
||||
let player = try Player.find(db, id: "1"))
|
||||
let player = try Player.find(db, id: "1")
|
||||
|
||||
let bestPlayers = try Player
|
||||
.order(\.score.desc)
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import XCTest
|
||||
import CoreGraphics
|
||||
import GRDB
|
||||
|
||||
#if canImport(CoreGraphics)
|
||||
import CoreGraphics
|
||||
#elseif !canImport(Darwin)
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
class CGFloatTests: GRDBTestCase {
|
||||
|
||||
func testCGFLoat() throws {
|
||||
|
||||
@@ -216,6 +216,9 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testNSErrorBridging() throws {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("NSError bridging not available on non-Darwin platforms")
|
||||
#else
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
|
||||
@@ -229,5 +232,6 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
XCTAssertNotNil(error.localizedFailureReason)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
func testEmptyMigratorSync() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let migrator = DatabaseMigrator()
|
||||
try migrator.migrate(writer)
|
||||
@@ -18,9 +21,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testEmptyMigratorAsync() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let expectation = self.expectation(description: "")
|
||||
let migrator = DatabaseMigrator()
|
||||
@@ -38,9 +45,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testEmptyMigratorPublisher() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let migrator = DatabaseMigrator()
|
||||
let publisher = migrator.migratePublisher(writer)
|
||||
@@ -51,9 +62,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testNonEmptyMigratorSync() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
@@ -95,9 +110,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testNonEmptyMigratorAsync() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
@@ -146,9 +165,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testNonEmptyMigratorPublisher() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
@@ -198,9 +221,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testEmptyMigratorPublisherIsAsynchronous() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let migrator = DatabaseMigrator()
|
||||
let expectation = self.expectation(description: "")
|
||||
@@ -220,9 +247,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testNonEmptyMigratorPublisherIsAsynchronous() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("first", migrate: { _ in })
|
||||
@@ -243,9 +274,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testMigratorPublisherDefaultScheduler() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test<Writer: DatabaseWriter>(writer: Writer) {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("first", migrate: { _ in })
|
||||
@@ -268,9 +303,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testMigratorPublisherCustomScheduler() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test<Writer: DatabaseWriter>(writer: Writer) {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("first", migrate: { _ in })
|
||||
@@ -294,9 +333,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testMigrateUpTo() throws {
|
||||
#if !canImport(Combine)
|
||||
throw XCTSkip("Combine not supported on this platform")
|
||||
#else
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("a") { db in
|
||||
@@ -345,6 +388,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
try Test(test).run { try DatabaseQueue() }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
#endif
|
||||
}
|
||||
|
||||
func testMigrationFailureTriggersRollback() throws {
|
||||
|
||||
@@ -877,10 +877,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabasePool.writer")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabasePool.writer")
|
||||
#endif
|
||||
}
|
||||
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
@@ -890,10 +892,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.1")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabasePool.reader.1")
|
||||
#endif
|
||||
|
||||
_ = s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -906,10 +910,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.2")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabasePool.reader.2")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -925,10 +931,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador.writer")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador.writer")
|
||||
#endif
|
||||
}
|
||||
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
@@ -938,10 +946,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador.reader.1")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador.reader.1")
|
||||
#endif
|
||||
|
||||
_ = s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -954,10 +964,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador.reader.2")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador.reader.2")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -1037,6 +1049,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testQoS() throws {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("__dispatch_get_global_queue unavailable")
|
||||
#else
|
||||
func test(qos: DispatchQoS) throws {
|
||||
// https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5
|
||||
//
|
||||
@@ -1072,6 +1087,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
try test(qos: .background)
|
||||
try test(qos: .userInitiated)
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - AsyncConcurrentRead
|
||||
@@ -1254,6 +1270,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// MARK: - Concurrent opening
|
||||
|
||||
func testConcurrentOpening() throws {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("NSFileCoordinator unavailable")
|
||||
#else
|
||||
for _ in 0..<50 {
|
||||
let dbDirectoryName = "DatabasePoolConcurrencyTests-\(ProcessInfo.processInfo.globallyUniqueString)"
|
||||
let directoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
@@ -1277,6 +1296,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTAssert(poolError ?? coordinatorError == nil)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - NSFileCoordinator sample code tests
|
||||
@@ -1284,6 +1304,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// Test for sample code in Documentation.docc/DatabaseSharing.md.
|
||||
// This test passes if this method compiles
|
||||
private func openSharedDatabase(at databaseURL: URL) throws -> DatabasePool {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("NSFileCoordinator unavailable")
|
||||
#else
|
||||
let coordinator = NSFileCoordinator(filePresenter: nil)
|
||||
var coordinatorError: NSError?
|
||||
var dbPool: DatabasePool?
|
||||
@@ -1299,6 +1322,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
throw error
|
||||
}
|
||||
return dbPool!
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test for sample code in Documentation.docc/DatabaseSharing.md.
|
||||
@@ -1313,6 +1337,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// Test for sample code in Documentation.docc/DatabaseSharing.md.
|
||||
// This test passes if this method compiles
|
||||
private func openSharedReadOnlyDatabase(at databaseURL: URL) throws -> DatabasePool? {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("NSFileCoordinator unavailable")
|
||||
#else
|
||||
let coordinator = NSFileCoordinator(filePresenter: nil)
|
||||
var coordinatorError: NSError?
|
||||
var dbPool: DatabasePool?
|
||||
@@ -1328,6 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
throw error
|
||||
}
|
||||
return dbPool
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test for sample code in Documentation.docc/DatabaseSharing.md.
|
||||
|
||||
@@ -129,10 +129,12 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabaseQueue")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabaseQueue")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,10 +146,12 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +225,9 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testQoS() throws {
|
||||
#if !canImport(Darwin)
|
||||
throw XCTSkip("__dispatch_get_global_queue not available on non-Darwin platforms")
|
||||
#else
|
||||
func test(qos: DispatchQoS) throws {
|
||||
// https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5
|
||||
//
|
||||
@@ -256,6 +263,7 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
|
||||
try test(qos: .background)
|
||||
try test(qos: .userInitiated)
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - SQLITE_BUSY prevention
|
||||
|
||||
@@ -4,12 +4,14 @@ import GRDB
|
||||
class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
// Test passes if it compiles.
|
||||
// See <https://github.com/groue/GRDB.swift/issues/1541>
|
||||
#if canImport(Combine)
|
||||
func testAnyDatabaseWriter(writer: any DatabaseWriter) throws {
|
||||
let observation = DatabaseRegionObservation(tracking: .fullDatabase)
|
||||
|
||||
_ = observation.start(in: writer, onError: { _ in }, onChange: { _ in })
|
||||
_ = observation.publisher(in: writer)
|
||||
}
|
||||
#endif
|
||||
|
||||
func testDatabaseRegionObservation_FullDatabase() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
@@ -230,10 +230,12 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabasePool.snapshot.1")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabasePool.snapshot.1")
|
||||
#endif
|
||||
}
|
||||
|
||||
let snapshot2 = try dbPool.makeSnapshot()
|
||||
@@ -241,10 +243,12 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, nil)
|
||||
XCTAssertEqual(db.description, "GRDB.DatabasePool.snapshot.2")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "GRDB.DatabasePool.snapshot.2")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,10 +261,12 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador.snapshot.1")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador.snapshot.1")
|
||||
#endif
|
||||
}
|
||||
|
||||
let snapshot2 = try dbPool.makeSnapshot()
|
||||
@@ -268,10 +274,12 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
XCTAssertEqual(db.configuration.label, "Toreador")
|
||||
XCTAssertEqual(db.description, "Toreador.snapshot.2")
|
||||
|
||||
#if canImport(Darwin)
|
||||
// This test CAN break in future releases: the dispatch queue labels
|
||||
// are documented to be a debug-only tool.
|
||||
let label = String(utf8String: __dispatch_queue_get_label(nil))
|
||||
XCTAssertEqual(label, "Toreador.snapshot.2")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#if canImport(Darwin)
|
||||
// Inspired by https://github.com/groue/CombineExpectations
|
||||
import XCTest
|
||||
|
||||
@@ -207,3 +208,4 @@ class FailureTestCaseTests: FailureTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if canImport(Darwin)
|
||||
import Dispatch
|
||||
import XCTest
|
||||
|
||||
@@ -781,3 +782,4 @@ class ValueObservationRecorderTests: FailureTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -926,6 +926,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
// MARK: - Async Await
|
||||
#if canImport(Combine)
|
||||
|
||||
func testAsyncAwait_values_prefix() async throws {
|
||||
func test(_ writer: some DatabaseWriter) async throws {
|
||||
@@ -1238,6 +1239,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
|
||||
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
|
||||
}
|
||||
#endif
|
||||
|
||||
// Regression test for <https://github.com/groue/GRDB.swift/issues/1383>
|
||||
func testIssue1383() throws {
|
||||
|
||||
Reference in new issue
Block a user