Files
GRDB.swift/Tests/Public/Core/DatabasePool/DatabasePoolCollationTests.swift
T
swiftlyfalling 30bc7e4f6c Replace most uses of #if SQLITE_HAS_CODEC with the appropriate USING_BUILTIN_SQLITE or USING_SQLCIPHER defines.
This enables easier compilation of a custom version of SQLite that
itself uses the SQLITE_HAS_CODEC define. (ex. If building SQLite with
the SQLite Encryption Extension.)
The SQLITE_HAS_CODEC define is now only used to guard use of the SQLite
encryption APIs.
GRDBCipher builds define USING_BUILTIN_SQLITE and USING_SQLCIPHER.
2016-05-30 18:19:45 -04:00

43 lines
1.7 KiB
Swift

import XCTest
#if USING_SQLCIPHER
import GRDBCipher
#elseif USING_CUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
class DatabasePoolCollationTests: GRDBTestCase {
func testCollationIsSharedBetweenWriterAndReaders() {
assertNoError {
let dbPool = try makeDatabasePool()
let collation1 = DatabaseCollation("collation1") { (string1, string2) in
return (string1 == string2) ? .OrderedSame : ((string1 < string2) ? .OrderedAscending : .OrderedDescending)
}
dbPool.addCollation(collation1)
try dbPool.write { db in
try db.execute("CREATE TABLE items (text TEXT COLLATE collation1)")
try db.execute("INSERT INTO items (text) VALUES ('a')")
try db.execute("INSERT INTO items (text) VALUES ('b')")
try db.execute("INSERT INTO items (text) VALUES ('c')")
}
dbPool.read { db in
XCTAssertEqual(String.fetchAll(db, "SELECT text FROM items ORDER BY text"), ["a", "b", "c"])
XCTAssertEqual(String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
}
let collation2 = DatabaseCollation("collation2") { (string1, string2) in
return (string1 == string2) ? .OrderedSame : ((string1 < string2) ? .OrderedDescending : .OrderedAscending)
}
dbPool.addCollation(collation2)
dbPool.read { db in
XCTAssertEqual(String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"])
}
}
}
}