Files
GRDB.swift/Tests/Public/Core/DatabasePool/DatabasePoolFileAttributesTests.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

83 lines
3.7 KiB
Swift

import XCTest
#if USING_SQLCIPHER
import GRDBCipher
#elseif USING_CUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
class DatabasePoolFileAttributesTests: GRDBTestCase {
func testDefaultFileAttributes() {
assertNoError {
let dbPool = try makeDatabasePool()
let fm = NSFileManager.defaultManager()
try dbPool.write { db in
try db.execute("CREATE TABLE foo (bar INTEGER)")
}
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-shm")
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
}
}
func testExplicitFileAttributesOnExistingFile() {
assertNoError {
let fm = NSFileManager.defaultManager()
do {
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute("CREATE TABLE foo (bar INTEGER)")
}
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-shm")
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
}
do {
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
let dbPool = try makeDatabasePool()
// TODO: this test is fragile: we have to wait until the database
// store has been notified of file creation.
NSThread.sleepForTimeInterval(0.1)
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-shm")
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
}
}
}
func testExplicitFileAttributesOnNewFile() {
assertNoError {
let fm = NSFileManager.defaultManager()
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute("CREATE TABLE foo (bar INTEGER)")
}
// TODO: this test is fragile: we have to wait until the database
// store has been notified of file creation.
NSThread.sleepForTimeInterval(0.1)
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-shm")
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
}
}
}