From 69d9b0805c300258230fdd8529edcb6bb8c33a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Mon, 27 Jun 2016 13:10:09 +0200 Subject: [PATCH] Minor new unit tests for backups and database busy timeout --- src/Backup.cpp | 3 +++ tests/Backup_test.cpp | 10 ++++++++++ tests/Database_test.cpp | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/Backup.cpp b/src/Backup.cpp index 5f6386a..f256116 100644 --- a/src/Backup.cpp +++ b/src/Backup.cpp @@ -31,6 +31,7 @@ Backup::Backup(Database& aDestDatabase, apSrcDatabaseName); if (NULL == mpSQLiteBackup) { + // If an error occurs, the error code and message are attached to the destination database connection. throw SQLite::Exception(aDestDatabase.getHandle()); } } @@ -48,6 +49,7 @@ Backup::Backup(Database& aDestDatabase, aSrcDatabaseName.c_str()); if (NULL == mpSQLiteBackup) { + // If an error occurs, the error code and message are attached to the destination database connection. throw SQLite::Exception(aDestDatabase.getHandle()); } } @@ -62,6 +64,7 @@ Backup::Backup(Database &aDestDatabase, Database &aSrcDatabase) : "main"); if (NULL == mpSQLiteBackup) { + // If an error occurs, the error code and message are attached to the destination database connection. throw SQLite::Exception(aDestDatabase.getHandle()); } } diff --git a/tests/Backup_test.cpp b/tests/Backup_test.cpp index 68888bd..e64f95c 100644 --- a/tests/Backup_test.cpp +++ b/tests/Backup_test.cpp @@ -18,6 +18,16 @@ #include +TEST(Backup, initException) { + remove("backup_test.db3"); + SQLite::Database srcDB("backup_test.db3", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); + srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)"); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, \"first\")")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, \"second\")")); + EXPECT_THROW(SQLite::Backup backup(srcDB, "src", srcDB, "src"), SQLite::Exception); + remove("backup_test.db3"); +} + TEST(Backup, executeStep) { remove("backup_test.db3"); remove("backup_test.db3.backup"); diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp index f465fb4..9269106 100644 --- a/tests/Database_test.cpp +++ b/tests/Database_test.cpp @@ -114,6 +114,16 @@ TEST(Database, busyTimeout) { SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE, 5000); EXPECT_EQ(5000, db.execAndGet("PRAGMA busy_timeout").getInt()); + // Reset timeout to null + db.setBusyTimeout(0); + EXPECT_EQ(0, db.execAndGet("PRAGMA busy_timeout").getInt()); + } + { + // Create a new database with a non null busy timeout + const std::string memory = ":memory:"; + SQLite::Database db(memory, SQLITE_OPEN_READWRITE, 5000); + EXPECT_EQ(5000, db.execAndGet("PRAGMA busy_timeout").getInt()); + // Reset timeout to null db.setBusyTimeout(0); EXPECT_EQ(0, db.execAndGet("PRAGMA busy_timeout").getInt()); @@ -234,3 +244,4 @@ TEST(Database, execException) { } // TODO: test Database::createFunction() +// TODO: test Database::loadExtension()