| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // SwifterTests.swift
- // SwifterTests
- //
- // Copyright © 2016 Damian Kołakowski. All rights reserved.
- //
- import XCTest
- import Swifter
- class SwifterTestsSQLite: XCTestCase {
-
- func testSQLite() {
-
- print(try? File.currentWorkingDirectory())
-
- guard let databsePath = try? File.currentWorkingDirectory() + "/" + "test_\(Int64(Date().timeIntervalSince1970*1000)).db" else {
- XCTAssert(false, "Could not find a path for a database file.")
- return
- }
-
- do {
- let database = try SQLite.open(databsePath)
- XCTAssert(true, "Opening the database should not throw any exceptions.")
- database.close()
- } catch {
- XCTAssert(false, "Opening the database should not throw any exceptions.")
- }
-
- do {
- let database = try SQLite.open(databsePath)
- try database.exec("CREATE TABLE swifter_tests (title TEXT, description TEXT);")
- try database.exec("INSERT INTO swifter_tests VALUES (\"Test1\", \"Test1 Description\");")
- try database.exec("INSERT INTO swifter_tests VALUES (\"Test2\", \"Test2 Description\");")
- database.close()
- } catch {
- XCTAssert(false, "Database manipulation should not throw any exceptions: \(error).")
- }
-
- do {
- let database = try SQLite.open(databsePath)
-
- var counter = 0
- for _ in try database.enumerate("SELECT * FROM swifter_tests;") {
- counter = counter + 1
- }
- XCTAssert(counter == 2, "Database should have two rows.")
-
- counter = 0
- try database.exec("SELECT * FROM swifter_tests;") { content in
- counter = counter + 1
- }
- XCTAssert(counter == 2, "Database should have two rows.")
-
- database.close()
- } catch {
- XCTAssert(false, "Database manipulation should not throw any exceptions.")
- }
- }
- }
|