-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few more unit tests for backups, statement and database
- should get us to 100% on Backup
- Loading branch information
Showing
3 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
* @ingroup tests | ||
* @brief Test of a SQLite Backup. | ||
* | ||
* Copyright (c) 2015-2015 Shibao HONG ([email protected]) | ||
* Copyright (c) 2015 Shibao HONG ([email protected]) | ||
* Copyright (c) 2016 Sebastien Rombauts ([email protected]) | ||
* | ||
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt | ||
* or copy at http://opensource.org/licenses/MIT) | ||
|
@@ -24,11 +25,46 @@ TEST(Backup, initException) { | |
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); | ||
EXPECT_THROW(SQLite::Backup backup(srcDB, srcDB), SQLite::Exception); | ||
EXPECT_THROW(SQLite::Backup backup(srcDB, "main", srcDB, "main"), SQLite::Exception); | ||
const std::string name("main"); | ||
EXPECT_THROW(SQLite::Backup backup(srcDB, name, srcDB, name), SQLite::Exception); | ||
remove("backup_test.db3"); | ||
} | ||
|
||
TEST(Backup, executeStep) { | ||
TEST(Backup, executeStepOne) { | ||
remove("backup_test.db3"); | ||
remove("backup_test.db3.backup"); | ||
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\")")); | ||
|
||
SQLite::Database destDB("backup_test.db3.backup", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); | ||
SQLite::Backup backup(destDB, "main", srcDB, "main"); | ||
int res = backup.executeStep(1); // backup only one page at a time | ||
ASSERT_EQ(SQLITE_OK, res); | ||
const int total = backup.totalPageCount(); | ||
ASSERT_EQ(2, total); | ||
int remaining = backup.remainingPageCount(); | ||
ASSERT_EQ(1, remaining); | ||
res = backup.executeStep(1); // backup the second and last page | ||
ASSERT_EQ(SQLITE_DONE, res); | ||
remaining = backup.remainingPageCount(); | ||
ASSERT_EQ(0, remaining); | ||
|
||
SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC"); | ||
ASSERT_TRUE(query.executeStep()); | ||
EXPECT_EQ(1, query.getColumn(0).getInt()); | ||
EXPECT_STREQ("first", query.getColumn(1)); | ||
ASSERT_TRUE(query.executeStep()); | ||
EXPECT_EQ(2, query.getColumn(0).getInt()); | ||
EXPECT_STREQ("second", query.getColumn(1)); | ||
remove("backup_test.db3"); | ||
remove("backup_test.db3.backup"); | ||
} | ||
|
||
TEST(Backup, executeStepAll) { | ||
remove("backup_test.db3"); | ||
remove("backup_test.db3.backup"); | ||
SQLite::Database srcDB("backup_test.db3", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); | ||
|
@@ -38,8 +74,12 @@ TEST(Backup, executeStep) { | |
|
||
SQLite::Database destDB("backup_test.db3.backup", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); | ||
SQLite::Backup backup(destDB, srcDB); | ||
const int res = backup.executeStep(); | ||
const int res = backup.executeStep(); // uses default argument "-1" => execute all steps at once | ||
ASSERT_EQ(res, SQLITE_DONE); | ||
const int total = backup.totalPageCount(); | ||
ASSERT_EQ(2, total); | ||
const int remaining = backup.remainingPageCount(); | ||
ASSERT_EQ(0, remaining); | ||
|
||
SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC"); | ||
ASSERT_TRUE(query.executeStep()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters