summaryrefslogtreecommitdiff
path: root/tests/dbfixture.cpp
diff options
context:
space:
mode:
authorJanusz Kozerski <j.kozerski@samsung.com>2015-07-20 16:09:12 +0200
committerJanusz Kozerski <j.kozerski@samsung.com>2015-08-03 16:14:30 +0200
commit4373c73514186ce90d71a0486447fa66dcf0a6c1 (patch)
tree7c5bd75cc6655094b865fdffc0db37ec59c574e0 /tests/dbfixture.cpp
parent9c839946822cbf84b8f6d4edebca8bc678941c85 (diff)
downloadcert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.tar.gz
cert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.tar.bz2
cert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.zip
Restore test DB from copy instead of clearing it
Change-Id: Ia82a764c764f28f78d5c6f6a6d511c67459804b7
Diffstat (limited to 'tests/dbfixture.cpp')
-rw-r--r--tests/dbfixture.cpp44
1 files changed, 18 insertions, 26 deletions
diff --git a/tests/dbfixture.cpp b/tests/dbfixture.cpp
index 2fb73b5..2e99009 100644
--- a/tests/dbfixture.cpp
+++ b/tests/dbfixture.cpp
@@ -19,43 +19,35 @@
* @version 1.0
* @brief Implementation of DB test class
*/
+#include <boost/test/unit_test.hpp>
#include <tzplatform_config.h>
+#include <fstream>
#include <dbfixture.h>
using namespace CCHECKER;
namespace {
-const char *TEST_DB_PATH = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test.db");
-
-const char *DB_CMD_CLEAR_URL =
- "DELETE FROM ocsp_urls;";
-
-const char *DB_CMD_CLEAR_TO_CHECK =
- "DELETE FROM to_check;";
-
-const char *DB_CMD_CLEAR_CERTS_TO_CHECK =
- "DELETE FROM certs_to_check;";
+const char *TEST_DB_PATH = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test.db");
+const char *TEST_DB_PATH_TEMP = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test-temp.db");
} // anonymus namespace
DBFixture::DBFixture() :
- DB::SqlQuery(TEST_DB_PATH)
-{};
-
-DBFixture::~DBFixture()
-{};
-
-void DBFixture::clear_database ()
+ DB::SqlQuery()
{
- // TODO: Restore DB from copy instead of removing all data from it.
+ // Remove temporary databse
+ BOOST_CHECK(unlink(TEST_DB_PATH_TEMP) == 0 || errno == ENOENT);
- DB::SqlConnection::DataCommandAutoPtr getUrlCommand =
- m_connection->PrepareDataCommand(DB_CMD_CLEAR_URL);
- getUrlCommand->Step();
+ // Restore original database
+ std::ifstream f1(TEST_DB_PATH, std::fstream::binary);
+ std::ofstream f2(TEST_DB_PATH_TEMP, std::fstream::trunc|std::fstream::binary);
+ f2 << f1.rdbuf();
+ f2.close();
+ f1.close();
- getUrlCommand = m_connection->PrepareDataCommand(DB_CMD_CLEAR_CERTS_TO_CHECK);
- getUrlCommand->Step();
+ // Open temporary database
+ BOOST_REQUIRE(connect(TEST_DB_PATH_TEMP));
+};
- getUrlCommand = m_connection->PrepareDataCommand(DB_CMD_CLEAR_TO_CHECK);
- getUrlCommand->Step();
-}
+DBFixture::~DBFixture()
+{};