mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Fix warnings
This commit is contained in:
1 parent
4174896225
commit
111dcbcad4
4 files changed
+43
-25
No files matched your search
@@ -24,25 +24,24 @@ class DataMemoryTests: GRDBTestCase {
|
||||
|
||||
let rows = try Row.fetchCursor(db, "SELECT ?", arguments: [data])
|
||||
while let row = try rows.next() {
|
||||
let sqliteStatement = row.sqliteStatement
|
||||
let sqliteBytes = sqlite3_column_blob(sqliteStatement, 0)
|
||||
let blobPointer = sqlite3_column_blob(row.sqliteStatement, 0)
|
||||
|
||||
do {
|
||||
// This data should be copied:
|
||||
let copiedData: Data = row[0]
|
||||
copiedData.withUnsafeBytes { copiedBytes in
|
||||
XCTAssertNotEqual(copiedBytes, sqliteBytes)
|
||||
}
|
||||
XCTAssertEqual(copiedData, data)
|
||||
copiedData.withBaseAddress { dataPointer in
|
||||
XCTAssertNotEqual(dataPointer, blobPointer)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
// This data should not be copied
|
||||
let nonCopiedData = row.dataNoCopy(atIndex: 0)!
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, sqliteBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
nonCopiedData.withBaseAddress { dataPointer in
|
||||
XCTAssertEqual(dataPointer, blobPointer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,23 +49,23 @@ class DataMemoryTests: GRDBTestCase {
|
||||
let dbValue = row.first!.1 // TODO: think about exposing a (column:,databaseValue:) tuple
|
||||
switch dbValue.storage {
|
||||
case .blob(let data):
|
||||
data.withUnsafeBytes { (dataBytes: UnsafePointer<UInt8>) -> Void in
|
||||
data.withBaseAddress { dataPointer in
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData: Data = row[0]
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
nonCopiedData.withBaseAddress { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataPointer)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData = row.dataNoCopy(atIndex: 0)!
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
nonCopiedData.withBaseAddress { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataPointer)
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
@@ -75,3 +74,18 @@ class DataMemoryTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Data {
|
||||
// Helper for comparing data heap pointers, depending on the Swift version
|
||||
fileprivate func withBaseAddress(_ body: (UnsafeRawPointer?) -> Void) {
|
||||
#if swift(>=5.0)
|
||||
withUnsafeBytes {
|
||||
body($0.baseAddress)
|
||||
}
|
||||
#else
|
||||
withUnsafeBytes {
|
||||
body(UnsafeRawPointer($0))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,11 @@ private extension DatabaseValue {
|
||||
|
||||
private let emojiString = "'fooéı👨👨🏿🇫🇷🇨🇮'"
|
||||
private let emojiData = emojiString.data(using: .utf8)
|
||||
#if swift(>=5.0)
|
||||
private let nonUTF8Data = Data([0x80])
|
||||
#else
|
||||
private let nonUTF8Data = Data(bytes: [0x80])
|
||||
#endif
|
||||
private let invalidString = "\u{FFFD}" // decoded from nonUTF8Data
|
||||
// Until SPM tests can load resources, disable this test for SPM.
|
||||
#if !SWIFT_PACKAGE
|
||||
|
||||
@@ -36,14 +36,14 @@ class IndexInfoTests: GRDBTestCase {
|
||||
let indexes = try db.indexes(on: "citizenships")
|
||||
|
||||
XCTAssertEqual(indexes.count, 2)
|
||||
if let i = indexes.index(where: { $0.columns == ["year"] }) {
|
||||
if let i = indexes.firstIndex(where: { $0.columns == ["year"] }) {
|
||||
XCTAssertEqual(indexes[i].name, "citizenshipsOnYear")
|
||||
XCTAssertEqual(indexes[i].columns, ["year"])
|
||||
XCTAssertFalse(indexes[i].isUnique)
|
||||
} else {
|
||||
XCTFail()
|
||||
}
|
||||
if let i = indexes.index(where: { $0.columns == ["personId", "countryIsoCode"] }) {
|
||||
if let i = indexes.firstIndex(where: { $0.columns == ["personId", "countryIsoCode"] }) {
|
||||
XCTAssertEqual(indexes[i].name, "sqlite_autoindex_citizenships_1")
|
||||
XCTAssertEqual(indexes[i].columns, ["personId", "countryIsoCode"])
|
||||
XCTAssertTrue(indexes[i].isUnique)
|
||||
|
||||
@@ -48,9 +48,9 @@ class RowFromDictionaryLiteralTests : RowTestCase {
|
||||
func testRowValueAtIndex() {
|
||||
let row: Row = ["a": 0, "b": 1, "c": 2]
|
||||
|
||||
let aIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "a" })!)
|
||||
let bIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "b" })!)
|
||||
let cIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "c" })!)
|
||||
let aIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "a" })!)
|
||||
let bIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "b" })!)
|
||||
let cIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "c" })!)
|
||||
|
||||
// Raw extraction
|
||||
assertRowRawValueEqual(row, index: aIndex, value: 0 as Int64)
|
||||
@@ -140,11 +140,11 @@ class RowFromDictionaryLiteralTests : RowTestCase {
|
||||
func testRowDatabaseValueAtIndex() throws {
|
||||
let row: Row = ["null": nil, "int64": 1, "double": 1.1, "string": "foo", "blob": "SQLite".data(using: .utf8)]
|
||||
|
||||
let nullIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "null" })!)
|
||||
let int64Index = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "int64" })!)
|
||||
let doubleIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "double" })!)
|
||||
let stringIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "string" })!)
|
||||
let blobIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "blob" })!)
|
||||
let nullIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "null" })!)
|
||||
let int64Index = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "int64" })!)
|
||||
let doubleIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "double" })!)
|
||||
let stringIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "string" })!)
|
||||
let blobIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "blob" })!)
|
||||
|
||||
guard case .null = (row[nullIndex] as DatabaseValue).storage else { XCTFail(); return }
|
||||
guard case .int64(let int64) = (row[int64Index] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return }
|
||||
|
||||
Reference in new issue
Block a user