Minor new unit tests for backups and database busy timeout

This commit is contained in:
Sébastien Rombauts 2016-06-27 13:10:09 +02:00
parent ef26cf09a1
commit 69d9b0805c
3 changed files with 24 additions and 0 deletions

View File

@ -31,6 +31,7 @@ Backup::Backup(Database& aDestDatabase,
apSrcDatabaseName); apSrcDatabaseName);
if (NULL == mpSQLiteBackup) if (NULL == mpSQLiteBackup)
{ {
// If an error occurs, the error code and message are attached to the destination database connection.
throw SQLite::Exception(aDestDatabase.getHandle()); throw SQLite::Exception(aDestDatabase.getHandle());
} }
} }
@ -48,6 +49,7 @@ Backup::Backup(Database& aDestDatabase,
aSrcDatabaseName.c_str()); aSrcDatabaseName.c_str());
if (NULL == mpSQLiteBackup) if (NULL == mpSQLiteBackup)
{ {
// If an error occurs, the error code and message are attached to the destination database connection.
throw SQLite::Exception(aDestDatabase.getHandle()); throw SQLite::Exception(aDestDatabase.getHandle());
} }
} }
@ -62,6 +64,7 @@ Backup::Backup(Database &aDestDatabase, Database &aSrcDatabase) :
"main"); "main");
if (NULL == mpSQLiteBackup) if (NULL == mpSQLiteBackup)
{ {
// If an error occurs, the error code and message are attached to the destination database connection.
throw SQLite::Exception(aDestDatabase.getHandle()); throw SQLite::Exception(aDestDatabase.getHandle());
} }
} }

View File

@ -18,6 +18,16 @@
#include <cstdio> #include <cstdio>
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) { TEST(Backup, executeStep) {
remove("backup_test.db3"); remove("backup_test.db3");
remove("backup_test.db3.backup"); remove("backup_test.db3.backup");

View File

@ -114,6 +114,16 @@ TEST(Database, busyTimeout) {
SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE, 5000); SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE, 5000);
EXPECT_EQ(5000, db.execAndGet("PRAGMA busy_timeout").getInt()); 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 // Reset timeout to null
db.setBusyTimeout(0); db.setBusyTimeout(0);
EXPECT_EQ(0, db.execAndGet("PRAGMA busy_timeout").getInt()); EXPECT_EQ(0, db.execAndGet("PRAGMA busy_timeout").getInt());
@ -234,3 +244,4 @@ TEST(Database, execException) {
} }
// TODO: test Database::createFunction() // TODO: test Database::createFunction()
// TODO: test Database::loadExtension()